@univerjs/sheets-drawing-ui 0.1.13 → 0.1.14

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var je=Object.defineProperty;var Le=(i,n,e)=>n in i?je(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var H=(i,n,e)=>(Le(i,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@univerjs/core"),B=require("@wendellhu/redi"),x=require("@univerjs/engine-render"),te=require("@univerjs/drawing-ui"),z=require("@univerjs/sheets-ui"),ne=require("rxjs"),E=require("@univerjs/drawing"),W=require("@univerjs/ui"),k=require("@wendellhu/redi/react-bindings"),m=require("@univerjs/sheets-drawing"),C=require("@univerjs/sheets"),A=require("react"),J=require("@univerjs/design"),se=require("clsx"),L={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(i,n)=>{const e=i.get(x.IRenderManagerService);return n.forEach(t=>{var r,o;(o=(r=e.getRenderById(t))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},we={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(w=>{const{unitId:f}=w;s.push(f)});const a=r.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:h}=a;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.REMOVE})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:h,type:m.DrawingApplyType.INSERT}},{id:L.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:s}]}),!0):!1}},De="COMPONENT_SHEET_DRAWING_PANEL",Ie={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(W.ISidebarService),t=i.get(p.LocaleService),r=i.get(p.IUniverInstanceService),o=i.get(E.IDrawingManagerService);if(!C.getSheetCommandTarget(r))return!1;switch(n.value){case"open":e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:De},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},ye={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(i,n)=>{const e=i.get(E.IDrawingManagerService),t=i.get(p.ICommandService);return n==null?!1:(e.focusDrawing([n]),t.executeCommand(Ie.id,{value:"open"}),!0)}},We="univer-upload-loading",Ge="univer-upload-loading-body",Be="univer-upload-loading-body-animation",xe="univer-UniverCircleAnimation",Fe="univer-upload-loading-body-text",ae={uploadLoading:We,uploadLoadingBody:Ge,uploadLoadingBodyAnimation:Be,univerCircleAnimation:xe,uploadLoadingBodyText:Fe},Ve=()=>{const i=k.useDependency(E.IImageIoService),n=k.useDependency(p.LocaleService),[e,t]=A.useState(0);return A.useEffect(()=>{const r=i.change$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[i]),A.createElement("div",{style:{display:e>0?"block":"none"},className:ae.uploadLoading},A.createElement("div",{className:ae.uploadLoadingBody},A.createElement("div",{className:ae.uploadLoadingBodyAnimation}),A.createElement("div",{className:ae.uploadLoadingBodyText},`${n.t("uploadLoading.loading")}: ${e}`)))};var $e=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ye=(i,n,e,t)=>{for(var r=t>1?void 0:t?He(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&$e(n,e,r),r},Z=(i,n)=>(e,t)=>n(e,t,i);let le=class extends p.RxDisposable{constructor(n,e,t,r,o,s,a){super();H(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=e,this._canvasPopManagerService=t,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(W.BuiltInUIPart.CONTENT,()=>k.connectInjector(Ve,this._injector))}_dispose(n){const e=n.getUnitId();this._renderManagerService.removeRender(e)}_create(n){if(!n)return;const e=n.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(n){const e=n.getAllObjects();for(const t of e)if(t instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const e=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;const r=[];this.disposeWithMe(p.toDisposable(t.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=t.getSelectedObjectMap();if(s.size>1){r.forEach(g=>g.dispose());return}const a=s.values().next().value;if(!a)return;const c=a.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:l,subUnitId:d,drawingId:h}=u;r.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,d,h)}}))),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:d,drawingId:h}])}))),this.disposeWithMe(p.toDisposable(t.onClearControlObservable.add(()=>{r.forEach(s=>s.dispose()),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(p.toDisposable(t.onChangingObservable.add(()=>{r.forEach(s=>s.dispose())})))}_getImageMenuItems(n,e,t){return[{label:"image-popup.edit",index:0,commandId:ye.id,commandParams:{unitId:n,subUnitId:e,drawingId:t},disable:!1},{label:"image-popup.delete",index:1,commandId:we.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:e,drawingId:t},disable:!1},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:e,drawingId:t}],disable:!1}]}};le=Ye([p.OnLifecycle(p.LifecycleStages.Steady,le),Z(0,B.Inject(B.Injector)),Z(1,E.IDrawingManagerService),Z(2,B.Inject(z.SheetCanvasPopManagerService)),Z(3,x.IRenderManagerService),Z(4,p.IUniverInstanceService),Z(5,p.IContextService),Z(6,B.Inject(W.IUIPartsService))],le);const he={id:"sheet.operation.insert-float-image",type:p.CommandType.OPERATION,handler:(i,n)=>!0},me={id:"sheet.operation.insert-cell-image",type:p.CommandType.OPERATION,handler:(i,n)=>!0},Se={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(w=>w.unitId),a=r.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:l,redo:d,objects:h}=a;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT})?(t.pushUndoRedo({unitID:c,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}},{id:L.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},{id:L.id,params:s}]}),!0):!1}},pe={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:l,objects:d,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}]}),!0):!1}},Re={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService);if(!n)return!1;const r=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=n,u={unitId:o,subUnitId:s,drawingIds:a};let l;if(c===E.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(u)),l==null)return!1;const{objects:d,redo:h,undo:g}=l;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}};function Xe(i){const n=[];return i.forEach(e=>{const{parent:t,children:r}=e,{unitId:o,subUnitId:s,drawingId:a}=t,c=x.getGroupState(0,0,r.map(d=>d.transform||{})),u=r.map(d=>{const h=d.transform||{left:0,top:0},{unitId:g,subUnitId:w,drawingId:f}=d;return{unitId:g,subUnitId:w,drawingId:f,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:a}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};n.push({parent:l,children:u})}),n}function ke(i){const n=[];return i.forEach(e=>{const{parent:t,children:r}=e,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=t;if(c==null)return;const u=r.map(d=>{const{transform:h}=d,{unitId:g,subUnitId:w,drawingId:f}=d,_=x.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:g,subUnitId:w,drawingId:f,transform:_,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:u})}),n}const Me={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:w})=>{o.push(g.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:ke(d),type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}]}),!0):!1}},Te={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(p.IUndoRedoService),r=i.get(m.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:w})=>{o.push(g.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:l,objects:d}=s;return e.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Xe(d),type:m.DrawingApplyType.GROUP}},{id:L.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:l,unitId:a,subUnitId:c,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:L.id,params:o}]}),!0):!1}};function V(i,n){const{from:e,to:t}=i,{column:r,columnOffset:o,row:s,rowOffset:a}=e,{column:c,columnOffset:u,row:l,rowOffset:d}=t,h=n.attachRangeWithCoord({startColumn:r,endColumn:r,startRow:s,endRow:s});if(h==null)return;const g=n.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:l,endRow:l});if(g==null)return;const{startX:w,startY:f}=h,{startX:_,startY:M}=g,I=x.precisionTo(w+o,1),D=x.precisionTo(f+a,1);let R=x.precisionTo(_+u-I,1),v=x.precisionTo(M+d-D,1);return h.startX===g.endX&&(R=0),h.startY===g.endY&&(v=0),{left:I,top:D,width:R,height:v}}function j(i,n){const{left:e=0,top:t=0,width:r=0,height:o=0}=i,s=n.getSelectionCellByPosition(e,t);if(s==null)return;const a={column:s.actualColumn,columnOffset:x.precisionTo(e-s.startX,1),row:s.actualRow,rowOffset:x.precisionTo(t-s.startY,1)},c=n.getSelectionCellByPosition(e+r,t+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:x.precisionTo(e+r-c.startX,1),row:c.actualRow,rowOffset:x.precisionTo(t+o-c.startY,1)};return{from:a,to:u}}var ze=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&ze(n,e,r),r},Y=(i,n)=>(e,t)=>n(e,t,i);let de=class extends p.Disposable{constructor(i,n,e,t,r,o,s,a,c,u,l){super(),this._commandService=i,this._univerInstanceService=n,this._selectionManagerService=e,this._selectionRenderService=t,this._imageIoService=r,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,this._messageService=c,this._localeService=u,this._renderManagerService=l,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async i=>{if(i.id===me.id||i.id===he.id){const n=i.params;if(n.files==null)return;const e=n.files.length;if(e>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),i.id===me.id?n.files.forEach(async t=>{await this._insertCellImage(t)}):n.files.forEach(async t=>{await this._insertFloatImage(t)})}}))}async _insertCellImage(i){}async _insertFloatImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const D=I.message;D===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:t,subUnitId:r}=e,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:u,height:l,image:d}=await E.getImageSize(c||""),h=this._renderManagerService.getRenderById(t);if(h==null)return;const{width:g,height:w}=h.scene;this._imageIoService.addImageSourceCache(a,s,d);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||l>E.DRAWING_IMAGE_HEIGHT_LIMIT){const I=E.DRAWING_IMAGE_WIDTH_LIMIT/u,D=E.DRAWING_IMAGE_HEIGHT_LIMIT/l;f=Math.max(I,D)}const _=this._getImagePosition(u*f,l*f,g,w);if(_==null)return;const M={unitId:t,subUnitId:r,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:V(_,this._selectionRenderService),sheetTransform:_};this._commandService.executeCommand(Se.id,{unitId:t,drawings:[M]})}_getUnitInfo(){const i=this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET);if(i==null)return;const n=i.getActiveSheet();if(n==null)return;const e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const r=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};r&&r.length>0&&(o=r[r.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:l}=s,d=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),d=!0),l+n>t&&(l=t-n,l<0&&(l=0,n=t),d=!0),d){const f=this._selectionRenderService.getSelectionCellByPosition(u,l);if(f==null)return;u=f.startX,l=f.startY,a=f.actualColumn,c=f.actualRow}const h={column:a,columnOffset:0,row:c,rowOffset:0},g=this._selectionRenderService.getSelectionCellByPosition(u+i,l+n);if(g==null)return;const w={column:g.actualColumn,columnOffset:u+i-g.startX,row:g.actualRow,rowOffset:l+n-g.startY};return{from:h,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:r}=i;this._commandService.executeCommand(Re.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:r})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:r,drawingId:o,drawingType:s,transform:a}=e;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:r,drawingId:o});if(c==null)return;const u=j({...c.transform,...a},this._selectionRenderService);if(u==null)return;const l={...e,transform:{...c.transform,...a,...V(u,this._selectionRenderService)},sheetTransform:{...u}};n.push(l)}),n.length>0&&this._commandService.executeCommand(pe.id,{unitId:i[0].unitId,drawings:n}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Me.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(Te.id,i)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};de=qe([p.OnLifecycle(p.LifecycleStages.Rendered,de),Y(0,p.ICommandService),Y(1,p.IUniverInstanceService),Y(2,B.Inject(C.SelectionManagerService)),Y(3,z.ISelectionRenderService),Y(4,E.IImageIoService),Y(5,m.ISheetDrawingService),Y(6,E.IDrawingManagerService),Y(7,p.IContextService),Y(8,W.IMessageService),Y(9,B.Inject(p.LocaleService)),Y(10,x.IRenderManagerService)],de);var $=function(){return $=Object.assign||function(i){for(var n,e=1,t=arguments.length;e<t;e++){n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(i[r]=n[r])}return i},$.apply(this,arguments)},Je=function(i,n){var e={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&n.indexOf(t)<0&&(e[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(i);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(i,t[r])&&(e[t[r]]=i[t[r]]);return e},Oe=A.forwardRef(function(i,n){var e=i.icon,t=i.id,r=i.className,o=i.extend,s=Je(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),c=A.useRef("_".concat(et()));return Ae(e,"".concat(t),{defIds:e.defIds,idSuffix:c.current},$({ref:n,className:a},s),o)});function Ae(i,n,e,t,r){return A.createElement(i.tag,$($({key:n},Ze(i,e,r)),t),(Qe(i,e).children||[]).map(function(o,s){return Ae(o,"".concat(n,"-").concat(i.tag,"-").concat(s),e,void 0,r)}))}function Ze(i,n,e){var t=$({},i.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var r=n.defIds;return!r||r.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(t[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Qe(i,n){var e,t=n.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?$($({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?$($({},r),{attrs:$($({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):i}function et(){return Math.random().toString(36).substring(2,8)}Oe.displayName="UniverIcon";var tt={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"}}]},be=A.forwardRef(function(i,n){return A.createElement(Oe,Object.assign({},i,{id:"add-image-single",ref:n,icon:tt}))});be.displayName="AddImageSingle";const nt="univer-upload-file-menu",rt="univer-upload-file-menu-input",_e={uploadFileMenu:nt,uploadFileMenuInput:rt},Ee="COMPONENT_UPLOAD_FILE_MENU";var ge=(i=>(i[i.cellImage=0]="cellImage",i[i.floatImage=1]="floatImage",i))(ge||{});const it=i=>{const{type:n}=i,e=k.useDependency(p.ICommandService),t=A.useRef(null),r=()=>{var a;(a=t.current)==null||a.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);n===ge.floatImage?e.executeCommand(he.id,{files:u}):n===ge.cellImage&&e.executeCommand(me.id,{files:u}),t.current&&(t.current.value="")};return A.createElement("div",{onClick:r,className:_e.uploadFileMenu},A.createElement("input",{type:"file",className:_e.uploadFileMenuInput,ref:t,onChange:s,accept:o,multiple:!0}))},Pe="addition-and-subtraction-single",Ue="sheet.menu.image";function ot(i){return{id:Ue,type:W.MenuItemType.SUBITEMS,positions:[W.MenuPosition.TOOLBAR_START],group:W.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Pe,tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET)}}function st(i){return{id:he.id,title:"sheetImage.upload.float",type:W.MenuItemType.SELECTOR,label:{name:Ee,props:{type:ge.floatImage}},positions:[Ue],hidden$:W.getMenuHiddenObservable(i,p.UniverInstanceType.UNIVER_SHEET)}}const at="univer-image-common-panel",ct="univer-image-common-panel-grid",lt="univer-image-common-panel-border",dt="univer-image-common-panel-title",ut="univer-image-common-panel-row",mt="univer-image-common-panel-row-vertical",gt="univer-image-common-panel-column",ht="univer-image-common-panel-column-center",pt="univer-image-common-panel-inline",ft="univer-image-common-panel-span2",wt="univer-image-common-panel-span3",St="univer-image-common-panel-input",vt="univer-sheet-image-menu",_t="univer-sheet-image-menu-input",q={imageCommonPanel:at,imageCommonPanelGrid:ct,imageCommonPanelBorder:lt,imageCommonPanelTitle:dt,imageCommonPanelRow:ut,imageCommonPanelRowVertical:mt,imageCommonPanelColumn:gt,imageCommonPanelColumnCenter:ht,imageCommonPanelInline:pt,imageCommonPanelSpan2:ft,imageCommonPanelSpan3:wt,imageCommonPanelInput:St,sheetImageMenu:vt,sheetImageMenuInput:_t},Ct=i=>{var D;const n=k.useDependency(p.ICommandService),e=k.useDependency(p.LocaleService),t=k.useDependency(E.IDrawingManagerService),r=k.useDependency(x.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,c=r.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const l=u.getTransformerByCreate(),[d,h]=A.useState(!0),g=(D=s.anchorType)!=null?D:m.SheetDrawingAnchorType.Position,[w,f]=A.useState(g);function _(R,v){const O=[];return R.forEach(S=>{const{oKey:U}=S,T=v.getDrawingOKey(U);if(T==null)return O.push(null),!0;const{unitId:G,subUnitId:P,drawingId:b,drawingType:y,anchorType:N,sheetTransform:X}=T;O.push({unitId:G,subUnitId:P,drawingId:b,anchorType:N,sheetTransform:X,drawingType:y})}),O}A.useEffect(()=>{const R=l.onClearControlObservable.add(O=>{O===!0&&h(!1)}),v=l.onChangeStartObservable.add(O=>{var T;const{objects:S}=O,U=_(S,t);if(U.length===0)h(!1);else if(U.length>=1){h(!0);const G=((T=U[0])==null?void 0:T.anchorType)||m.SheetDrawingAnchorType.Position;f(G)}});return()=>{v==null||v.dispose(),R==null||R.dispose()}},[]);function M(R){f(R);const v=t.getFocusDrawings();if(v.length===0)return;const O=v.map(S=>({unitId:S.unitId,subUnitId:S.subUnitId,drawingId:S.drawingId,anchorType:R}));n.executeCommand(pe.id,{unitId:v[0].unitId,drawings:O})}const I=R=>R?"block":"none";return A.createElement("div",{className:se(q.imageCommonPanelGrid,q.imageCommonPanelBorder),style:{display:I(d)}},A.createElement("div",{className:q.imageCommonPanelRow},A.createElement("div",{className:se(q.imageCommonPanelColumn,q.imageCommonPanelTitle)},A.createElement("div",null,e.t("drawing-anchor.title")))),A.createElement("div",{className:se(q.imageCommonPanelRow)},A.createElement("div",{className:se(q.imageCommonPanelColumn)},A.createElement(J.RadioGroup,{value:w,onChange:M,direction:"vertical"},A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),A.createElement(J.Radio,{value:m.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},Dt=()=>{const i=k.useDependency(E.IDrawingManagerService),n=i.getFocusDrawings();if(n==null||n.length===0)return;const[e,t]=A.useState(n);return A.useEffect(()=>{const r=i.focus$.subscribe(o=>{t(o)});return()=>{r.unsubscribe()}},[]),A.createElement("div",{className:q.imageCommonPanel},A.createElement(te.DrawingCommonPanel,{drawings:e}),A.createElement(Ct,{drawings:e}))},ie={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(p.ICommandService),t=i.get(m.ISheetDrawingService),r=i.get(z.ISelectionRenderService),{direction:o}=n,s=t.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,c=s.map(l=>{const{transform:d}=l;if(d==null)return null;const h={...d},{left:g=0,top:w=0}=d;return o===p.Direction.UP?h.top=w-1:o===p.Direction.DOWN?h.top=w+1:o===p.Direction.LEFT?h.left=g-1:o===p.Direction.RIGHT&&(h.left=g+1),{...l,transform:h,sheetTransform:j(h,r)}}).filter(l=>l!=null);return e.syncExecuteCommand(pe.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(L.id,[a]),!0):!1}},Ne={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:i=>{const n=i.get(p.ICommandService),t=i.get(m.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const r=t[0].unitId,o=t.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:l}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:l}});return n.executeCommand(we.id,{unitId:r,drawings:o})}};function oe(i){return!i.getContextValue(p.FOCUSING_FORMULA_EDITOR)&&!i.getContextValue(p.EDITOR_ACTIVATED)&&i.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const It={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.DOWN}},yt={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.UP}},Rt={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.LEFT}},Mt={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.RIGHT}},Tt={id:Ne.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:oe,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Ot=Object.defineProperty,At=Object.getOwnPropertyDescriptor,bt=(i,n,e,t)=>{for(var r=t>1?void 0:t?At(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Ot(n,e,r),r},ee=(i,n)=>(e,t)=>n(e,t,i);const Et={};let re=class extends p.Disposable{constructor(i,n,e,t,r,o){super(),this._config=i,this._injector=n,this._componentManager=e,this._menuService=t,this._commandService=r,this._shortcutService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Pe,be)),this.disposeWithMe(i.register(Ee,it)),this.disposeWithMe(i.register(De,Dt))}_initMenus(){const{menu:i={}}=this._config;[ot,st].forEach(n=>{this._menuService.addMenuItem(n(this._injector),i)})}_initCommands(){[he,me,Se,we,pe,Ie,L,ye,Me,Te,ie,Ne,Re].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[It,yt,Rt,Mt,Tt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};re=bt([p.OnLifecycle(p.LifecycleStages.Rendered,re),ee(1,B.Inject(B.Injector)),ee(2,B.Inject(W.ComponentManager)),ee(3,W.IMenuService),ee(4,p.ICommandService),ee(5,W.IShortcutService)],re);var Pt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ut(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Pt(n,e,r),r},Q=(i,n)=>(e,t)=>n(e,t,i);const jt=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id],Lt=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let ue=class extends p.Disposable{constructor(i,n,e,t,r,o){super(),this._commandService=i,this._sheetInterceptorService=n,this._sheetDrawingService=e,this._drawingManagerService=t,this._selectionRenderService=r,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!jt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===C.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if(n===C.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===C.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===C.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===C.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(n===C.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(n===C.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(n===C.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(n===C.SetRowHiddenCommand.id||n===C.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,r,o)}else if(n===C.SetSpecificColsVisibleCommand.id||n===C.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e;return this._getDrawingUndoForColVisible(t,r,o)}else if(n===C.DeltaRowHeightCommand.id||n===C.SetRowHeightCommand.id||n===C.DeltaColumnWidthCommand.id||n===C.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:r,ranges:o}=e,s=n===C.DeltaRowHeightCommand.id||n===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const e=C.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,r=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(t,r),c=[],u=[];if(Object.keys(a).forEach(l=>{const d=a[l],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,n,d);c.push(...h),u.push(...g)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:h,objects:g}=l;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:h,objects:g,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:d,objects:g,type:m.DrawingApplyType.UPDATE}})}if(u.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(u),d=l.undo,h=l.redo,g=l.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:h,objects:g,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:d,objects:g,type:m.DrawingApplyType.INSERT}})}return o.push({id:L.id,params:[t]}),s.push({id:L.id,params:[t]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,n,e){const t=[],r=[],{sheetTransform:o,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:l}=e,{from:d,to:h}=o,{row:g,column:w}=d,{row:f,column:_}=h;if(o==null||a==null)return{updateDrawings:t,deleteDrawings:r};const{startRow:M,endRow:I,startColumn:D,endColumn:R}=i;let v=null,O=null;if(n===0&&g>=M&&f<=I)if(w>=D&&_<=R)r.push({unitId:c,subUnitId:u,drawingId:l});else{const S=this._shrinkCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===1&&w>=D&&_<=R)if(g>=M&&f<=I)r.push({unitId:c,subUnitId:u,drawingId:l});else{const S=this._shrinkRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===2){const S=this._expandRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(n===3){const S=this._expandCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}if(v!=null&&O!=null){const S=V(v,this._selectionRenderService);t.push({...e,sheetTransform:v,transform:S})}return{updateDrawings:t,deleteDrawings:r}}_remainDrawingSize(i,n,e){const t=j({...i},this._selectionRenderService);t!=null&&n.push({...e,sheetTransform:t})}_getDrawingUndoForColVisible(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(t).forEach(l=>{const d=t[l],{sheetTransform:h,transform:g,anchorType:w=m.SheetDrawingAnchorType.Position}=d;if(w===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,r,d);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(R<T)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,N=null;if(I>=T&&I<=G){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(X==null)return;N={...g,left:X.startX}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){r.push({...d,sheetTransform:y,transform:N});break}this._remainDrawingSize(g,r,d);continue}if(I>=T&&R<=G)continue;let P=null,b=null;if(I>=T&&I<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;b={...g,left:(y==null?void 0:y.startX)||0,width:((g==null?void 0:g.width)||0)-y.endX+y.startX}}else if(R>=T&&R<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:R,startRow:f.row,endRow:_.row});if(y==null)return;b={...g,left:y.startX-((g==null?void 0:g.width)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;if(b={...g,width:((g==null?void 0:g.width)||0)-y.endX+y.startX},P=j(b,this._selectionRenderService),P!=null&&b!=null){o.push({...d,sheetTransform:P,transform:b});break}}if(b!=null&&(P=j(b,this._selectionRenderService)),b!=null&&P!=null){r.push({...d,sheetTransform:P,transform:b});break}else this._remainDrawingSize(g,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,n,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(i,n,o);c.push(...l),u.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(i,n,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:r,redo:o,objects:s}=t,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:s,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}],c=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:r,objects:s,type:m.DrawingApplyType.UPDATE}},{id:L.id,params:[i]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(t).forEach(l=>{const d=t[l],{sheetTransform:h,transform:g,anchorType:w=m.SheetDrawingAnchorType.Position}=d;if(w===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,r,d);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(D<S)continue;if(w===m.SheetDrawingAnchorType.Position){let y=null,N=null;if(M>=S&&M<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(X==null)return;N={...g,top:X.startY}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){r.push({...d,sheetTransform:y,transform:N});break}this._remainDrawingSize(g,r,d);continue}if(M>=S&&D<=U)continue;let P=null,b=null;if(M>=S&&M<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(y==null)return;b={...g,top:(y==null?void 0:y.startY)||0,height:((g==null?void 0:g.height)||0)-y.endY+y.startY}}else if(D>=S&&D<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:D});if(y==null)return;b={...g,top:y.startY-((g==null?void 0:g.height)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:U});if(y==null)return;if(b={...g,height:((g==null?void 0:g.height)||0)-y.endY+y.startY},P=j(b,this._selectionRenderService),P!=null&&b!=null){o.push({...d,sheetTransform:P,transform:b});break}}if(b!=null&&(P=j(b,this._selectionRenderService)),b!=null&&P!=null){r.push({...d,sheetTransform:P,transform:b});break}else this._remainDrawingSize(g,r,d)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,n,r),c=[],u=[];if(o.length>0){const{redos:l,undos:d}=this._createUndoAndRedoMutation(i,n,o);c.push(...l),u.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(i,n,e,t){const r=this._drawingManagerService.getDrawingData(i,n),o=[];return Object.keys(r).forEach(s=>{const a=r[s],{sheetTransform:c,transform:u,anchorType:l=m.SheetDrawingAnchorType.Position}=a;if(l===m.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:d,to:h}=c,{row:g,column:w}=d,{row:f,column:_}=h;for(let M=0;M<e.length;M++){const I=e[M],{startRow:D,endRow:R,startColumn:v,endColumn:O}=I;if(f<D||_<v)continue;if(l===m.SheetDrawingAnchorType.Position&&(g<=D&&f>=R||w<=v&&_>=O)){this._remainDrawingSize(u,o,a);continue}const S=V({...c},this._selectionRenderService);if(S!=null){o.push({...a,transform:S});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,n,o)}_getUnitIdAndSubUnitId(i,n){let e,t;if(n==="insert")e=i.unitId,t=i.subUnitId;else{const r=C.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;e=r.unitId,t=r.subUnitId}return{unitId:e,subUnitId:t}}_moveRowInterceptor(i,n){const e=this._getUnitIdAndSubUnitId(i,n);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:r}=e,{range:o}=i,s=o.startRow,a=o.endRow,c=[],u=[],l=this._sheetDrawingService.getDrawingData(t,r),d=[],h=[];if(Object.keys(l).forEach(g=>{const w=l[g],{sheetTransform:f,transform:_,anchorType:M=m.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(n==="insert"){const v=this._expandRow(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{row:S}=v,{row:U}=O;if(S>=s&&U<=a)h.push({unitId:t,subUnitId:r,drawingId:g});else{const T=this._shrinkRow(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:t,subUnitId:r,drawingId:g,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:w,redo:f,objects:_}=g;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),w=g.undo,f=g.redo,_=g.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[t]}),u.push({id:L.id,params:[t]}),{redos:c,undos:u}}_moveColInterceptor(i,n){const e=this._getUnitIdAndSubUnitId(i,n);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:r}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,c=[],u=[],l=this._sheetDrawingService.getDrawingData(t,r),d=[],h=[];if(Object.keys(l).forEach(g=>{const w=l[g],{sheetTransform:f,transform:_,anchorType:M=m.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(n==="insert"){const v=this._expandCol(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{column:S}=v,{column:U}=O;if(S>=s&&U<=a)h.push({unitId:t,subUnitId:r,drawingId:g});else{const T=this._shrinkCol(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:t,subUnitId:r,drawingId:g,transform:D,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:w,redo:f,objects:_}=g;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.UPDATE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),w=g.undo,f=g.redo,_=g.objects;c.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:f,objects:_,type:m.DrawingApplyType.REMOVE}}),u.push({id:m.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:r,op:w,objects:_,type:m.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[t]}),u.push({id:L.id,params:[t]}),{redos:c,undos:u}}_expandCol(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:s.row,endRow:a.row});if(h==null)return;d={...n,left:(n.left||0)+h.endX-h.startX},l=j(d,this._selectionRenderService)}else if(u>=t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u+o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkCol(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>t)l={from:{...s,column:c-o},to:{...a,column:u-o}},d=V(l,this._selectionRenderService);else{if(c>=e&&u<=t)return null;if(c<e&&u>t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,column:u-o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};else if(c>=e&&c<=t){if(c===e)d={...n,left:(n.left||0)-i.from.columnOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:s.row,endRow:a.row});if(h==null)return;d={...n,left:(n.left||0)-h.endX+h.startX-i.from.columnOffset}}l=j(d,this._selectionRenderService)}else if(u>=e&&u<=t&&r===m.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(h==null)return;l={from:{...s},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},d=V(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_expandRow(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...n,top:(n.top||0)+h.endY-h.startY},l=j(d,this._selectionRenderService)}else if(u>=t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u+o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_shrinkRow(i,n,e,t,r=m.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:u}=a;if(r===m.SheetDrawingAnchorType.None)return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};let l=null,d=null;if(c>t)l={from:{...s,row:c-o},to:{...a,row:u-o}},d=V(l,this._selectionRenderService);else{if(c>=e&&u<=t)return null;if(c<e&&u>t)if(r===m.SheetDrawingAnchorType.Both)l={from:{...s},to:{...a,row:u-o}},d=V(l,this._selectionRenderService);else return{newSheetTransform:j({...n},this._selectionRenderService),newTransform:n};else if(c>=e&&c<=t){if(c===e)d={...n,top:(n.top||0)-i.from.rowOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...n,top:(n.top||0)-h.endY+h.startY-i.from.rowOffset}}l=j(d,this._selectionRenderService)}else if(u>=e&&u<=t&&r===m.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(h==null)return;l={from:{...s},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},d=V(l,this._selectionRenderService)}}return l!=null&&d!=null?{newSheetTransform:l,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===C.SetWorksheetActiveOperation.id){const n=i.params,{unitId:e,subUnitId:t}=n,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(a=>{const c=r[a];Object.keys(c).forEach(u=>{const l=c[u].data;l!=null&&Object.keys(l).forEach(d=>{a===e&&u===t?o.push(l[d]):s.push(l[d])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Lt.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:e,subUnitId:t,ranges:r}=n;this._refreshDrawingTransform(e,t,r)})}))}_refreshDrawingTransform(i,n,e){const t=this._drawingManagerService.getDrawingData(i,n),r=[];Object.keys(t).forEach(o=>{const s=t[o],{sheetTransform:a,anchorType:c=m.SheetDrawingAnchorType.Position}=s;if(c===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:l}=a,{row:d,column:h}=u,{row:g,column:w}=l;for(let f=0;f<e.length;f++){const _=e[f],{startRow:M,endRow:I,startColumn:D,endColumn:R}=_;if(p.Rectangle.intersects({startRow:M,endRow:I,startColumn:D,endColumn:R},{startRow:d,endRow:g,startColumn:h,endColumn:w})||d>I||h>R){r.push({...s,transform:V(a,this._selectionRenderService)});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(L.id,[i]))}};ue=Nt([p.OnLifecycle(p.LifecycleStages.Rendered,ue),Q(0,p.ICommandService),Q(1,B.Inject(C.SheetInterceptorService)),Q(2,m.ISheetDrawingService),Q(3,E.IDrawingManagerService),Q(4,z.ISelectionRenderService),Q(5,p.IUniverInstanceService)],ue);var Wt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Bt=(i,n,e,t)=>{for(var r=t>1?void 0:t?Gt(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Wt(n,e,r),r},K=(i,n)=>(e,t)=>n(e,t,i);function xt(i,n,e,t){const{scaleX:r,scaleY:o}=n.getAncestorScale(),s=n.getViewport(z.VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...i,absolute:a};const{left:c,right:u,top:l,bottom:d}=i,h=t.getFreeze(),{startColumn:g,startRow:w,xSplit:f,ySplit:_}=h,M=e.getNoMergeCellPositionByIndexWithNoHeader(w-_,g-f),I=e.getNoMergeCellPositionByIndexWithNoHeader(w,g),{rowHeaderWidth:D,columnHeaderHeight:R}=e,v=I.startX-M.startX,O=I.startY-M.startY,{top:S,left:U,viewportScrollX:T,viewportScrollY:G}=s;let P,b;c<U?(a.left=!0,P=(v+D+(c-U))*r,b=Math.max(Math.min((v+D+(u-U))*r,(v+D)*r),(u-T)*r)):(a.left=!1,P=Math.max((c-T)*r,(v+D)*r),b=Math.max((u-T)*r,(v+D)*r));let y,N;return l<S?(a.top=!0,y=(O+R+(l-S))*o,N=Math.max(Math.min((O+R+(u-S))*o,(O+R)*o),(d-G)*o)):(a.top=!1,y=Math.max((l-G)*o,(O+R)*o),N=Math.max((d-G)*o,(O+R)*o)),{left:P,right:b,top:y,bottom:N,absolute:a}}const fe=(i,n,e,t)=>{const{scene:r}=n,{left:o,top:s,width:a,height:c,angle:u}=i,l={left:o,right:o+a,top:s,bottom:s+c},d=xt(l,r,e,t);return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:u,width:a,height:c,absolute:d.absolute}};exports.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(e,t,r,o,s,a,c,u){super();H(this,"_domLayerMap",new Map);H(this,"_domLayerInfoMap",new Map);H(this,"_transformChange$",new ne.Subject);H(this,"transformChange$",this._transformChange$.asObservable());H(this,"_remove$",new ne.Subject);H(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._sheetSkeletonManagerService=r,this._commandService=o,this._drawingManagerService=s,this._selectionRenderService=a,this._canvasFloatDomService=c,this._sheetDrawingService=u,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,t){let r=this._domLayerMap.get(e);r||(r=new Map,this._domLayerMap.set(e,r));let o=r.get(t);return o||(o=new Map,r.set(t,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),r=t==null?void 0:t.scene;if(t==null||r==null)return null;const o=r.getTransformerByCreate(),s=t.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:t,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{const{unitId:r,subUnitId:o,drawingId:s}=t,a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(t),u=this._sheetSkeletonManagerService.getUnitSkeleton(r,o);if(c==null||a==null||u==null)return;const{transform:l,drawingType:d}=c;if(d!==p.DrawingTypeEnum.DRAWING_DOM)return;const h=this._getSceneAndTransformerByDrawingSearch(r);if(h==null)return;const{scene:g,canvas:w}=h;if(l==null)return!0;const{left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S}=l,U=E.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),T=g.getObject(U);if(T!=null){T.transformByState({left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S});return}const G={left:f,top:_,width:M,height:I,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},P=new x.Rect(U,G);g.addObject(P,x.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(P);const b=new p.DisposableCollection,y=fe(P,h.renderObject,u.skeleton,a.worksheet),N=new ne.BehaviorSubject(y),X={dispose:b,rect:P,position$:N,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:N,id:s,componentKey:c.componentKey,onPointerDown:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{w.dispatchEvent(new WheelEvent(F.type,F))}});const ve=P.onTransformChangeObservable.add(()=>{const F=fe(P,h.renderObject,u.skeleton,a.worksheet);N.next(F)});b.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ve&&b.add(ve),this._domLayerInfoMap.set(s,X)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;const t=(s,a)=>{const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),l=Array.from(u.keys()),d=C.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),h=this._sheetSkeletonManagerService.getUnitSkeleton(s,a);!c||!d||!h||l.forEach(g=>{const w=this._domLayerInfoMap.get(g);if(w){const f=fe(w.rect,c.renderObject,h.skeleton,d.worksheet);w.position$.next(f)}})};if(e.id===z.SetScrollOperation.id){const s=e.params,{unitId:a,sheetId:c}=s;t(a,c)}else if(e.id===z.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(r=this._domLayerMap.get(a))==null?void 0:r.keys())!=null?o:[]).forEach(u=>{t(a,u)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;t(s,a)}}))}_getPosition(e){const{startX:t,endX:r,startY:o,endY:s}=e,a=this._selectionRenderService.getSelectionCellByPosition(t,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:t-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(r,s);if(u==null)return;const l={column:u.actualColumn,columnOffset:r-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:l}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const r=this._drawingManagerService.getDrawingByParam(t);if(!r||r.drawingType!==p.DrawingTypeEnum.DRAWING_DOM)return;const o={...r.transform};this._transformChange$.next({id:t.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e){const t=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:r,subUnitId:o}=t,{initPosition:s,componentKey:a}=e,c=p.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;const l={unitId:r,subUnitId:o,drawingId:c,drawingType:p.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:u,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY}};return this._commandService.executeCommand(Se.id,{unitId:r,drawings:[l]}),this._ensureMap(r,o).set(c,e),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(e,t=!1){const r=this._domLayerInfoMap.get(e);if(!r)return;const{unitId:o,subUnitId:s}=r,a=this._ensureMap(o,s);this._domLayerInfoMap.delete(e),a.delete(e),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),t){const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!u)return;const l=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:d,objects:h}=l;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:d,objects:h,type:m.DrawingApplyType.REMOVE})}}};exports.SheetCanvasFloatDomManagerService=Bt([K(0,B.Inject(x.IRenderManagerService)),K(1,p.IUniverInstanceService),K(2,B.Inject(z.SheetSkeletonManagerService)),K(3,B.Inject(p.ICommandService)),K(4,E.IDrawingManagerService),K(5,z.ISelectionRenderService),K(6,B.Inject(W.CanvasFloatDomService)),K(7,m.ISheetDrawingService)],exports.SheetCanvasFloatDomManagerService);var Ft=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,$t=(i,n,e,t)=>{for(var r=t>1?void 0:t?Vt(n,e):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(t?s(n,e,r):s(r))||r);return t&&r&&Ft(n,e,r),r},Ce=(i,n)=>(e,t)=>n(e,t,i);const Ht="SHEETS_IMAGE_UI_PLUGIN";var ce;exports.UniverSheetsDrawingUIPlugin=(ce=class extends p.Plugin{constructor(e={},t,r){super();H(this,"_pluginConfig");this._injector=t,this._localeService=r,this._pluginConfig=p.Tools.deepMerge({},Et,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}_initDependencies(e){[[exports.SheetCanvasFloatDomManagerService],[re,{useFactory:()=>this._injector.createInstance(re,this._pluginConfig)}],[de],[le],[ue]].forEach(r=>e.add(r))}},H(ce,"type",p.UniverInstanceType.UNIVER_SHEET),H(ce,"pluginName",Ht),ce);exports.UniverSheetsDrawingUIPlugin=$t([Ce(1,B.Inject(B.Injector)),Ce(2,B.Inject(p.LocaleService))],exports.UniverSheetsDrawingUIPlugin);
1
+ "use strict";var Be=Object.defineProperty;var xe=(r,t,e)=>t in r?Be(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var k=(r,t,e)=>(xe(r,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@univerjs/core"),B=require("@wendellhu/redi"),Q=require("@univerjs/drawing-ui"),g=require("@univerjs/sheets-drawing"),b=require("@univerjs/drawing"),x=require("@univerjs/engine-render"),V=require("@univerjs/sheets-ui"),ne=require("rxjs"),W=require("@univerjs/ui"),z=require("@wendellhu/redi/react-bindings"),C=require("@univerjs/sheets"),A=require("react"),q=require("@univerjs/design"),se=require("clsx"),L={id:"sheet.operation.clear-drawing-transformer",type:p.CommandType.MUTATION,handler:(r,t)=>{const e=r.get(x.IRenderManagerService);return t.forEach(n=>{var i,o;(o=(i=e.getRenderById(n))==null?void 0:i.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Se={id:"sheet.command.remove-sheet-image",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService),i=r.get(g.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=[];o.forEach(w=>{const{unitId:f}=w;s.push(f)});const a=i.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:h}=a;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:l,objects:h,type:g.DrawingApplyType.REMOVE})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:h,type:g.DrawingApplyType.INSERT}},{id:L.id,params:s}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:h,type:g.DrawingApplyType.REMOVE}},{id:L.id,params:s}]}),!0):!1}},ye="COMPONENT_SHEET_DRAWING_PANEL",Re={id:"sidebar.operation.sheet-image",type:p.CommandType.COMMAND,handler:async(r,t)=>{const e=r.get(W.ISidebarService),n=r.get(p.LocaleService),i=r.get(p.IUniverInstanceService),o=r.get(b.IDrawingManagerService);if(!C.getSheetCommandTarget(i))return!1;switch(t.value){case"open":e.open({header:{title:n.t("sheetImage.panel.title")},children:{label:ye},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:e.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:p.CommandType.OPERATION,handler:(r,t)=>{const e=r.get(b.IDrawingManagerService),n=r.get(p.ICommandService);return t==null?!1:(e.focusDrawing([t]),n.executeCommand(Re.id,{value:"open"}),!0)}},Fe="univer-upload-loading",$e="univer-upload-loading-body",Ve="univer-upload-loading-body-animation",He="univer-UniverCircleAnimation",Ye="univer-upload-loading-body-text",ae={uploadLoading:Fe,uploadLoadingBody:$e,uploadLoadingBodyAnimation:Ve,univerCircleAnimation:He,uploadLoadingBodyText:Ye},Xe=()=>{const r=z.useDependency(b.IImageIoService),t=z.useDependency(p.LocaleService),[e,n]=A.useState(0);return A.useEffect(()=>{const i=r.change$.subscribe(o=>{n(o)});return()=>{i.unsubscribe()}},[r]),A.createElement("div",{style:{display:e>0?"block":"none"},className:ae.uploadLoading},A.createElement("div",{className:ae.uploadLoadingBody},A.createElement("div",{className:ae.uploadLoadingBodyAnimation}),A.createElement("div",{className:ae.uploadLoadingBodyText},`${t.t("uploadLoading.loading")}: ${e}`)))};var ke=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?ze(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&ke(t,e,i),i},J=(r,t)=>(e,n)=>t(e,n,r);let le=class extends p.RxDisposable{constructor(t,e,n,i,o,s,a){super();k(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(p.UniverInstanceType.UNIVER_SHEET).pipe(ne.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(p.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(W.BuiltInUIPart.CONTENT,()=>z.connectInjector(Xe,this._injector))}_dispose(t){const e=t.getUnitId();this._renderManagerService.removeRender(e)}_create(t){if(!t)return;const e=t.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(t){const e=t.getAllObjects();for(const n of e)if(n instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const e=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!e)return;const n=e.getTransformerByCreate();if(!n)return;const i=[];this.disposeWithMe(p.toDisposable(n.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=n.getSelectedObjectMap();if(s.size>1){i.forEach(m=>m.dispose());return}const a=s.values().next().value;if(!a)return;const c=a.oKey,u=this._drawingManagerService.getDrawingOKey(c);if(!u)return;const{unitId:d,subUnitId:l,drawingId:h}=u;i.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,l,h)}}))),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:l,drawingId:h}])}))),this.disposeWithMe(p.toDisposable(n.onClearControlObservable.add(()=>{i.forEach(s=>s.dispose()),this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(p.toDisposable(n.onChangingObservable.add(()=>{i.forEach(s=>s.dispose())})))}_getImageMenuItems(t,e,n){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.delete",index:1,commandId:Se.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:e,drawingId:n}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:e,drawingId:n},disable:!1},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:e,drawingId:n}],disable:!1}]}};le=Ke([p.OnLifecycle(p.LifecycleStages.Steady,le),J(0,B.Inject(B.Injector)),J(1,b.IDrawingManagerService),J(2,B.Inject(V.SheetCanvasPopManagerService)),J(3,x.IRenderManagerService),J(4,p.IUniverInstanceService),J(5,p.IContextService),J(6,B.Inject(W.IUIPartsService))],le);const pe={id:"sheet.operation.insert-float-image",type:p.CommandType.OPERATION,handler:(r,t)=>!0},ge={id:"sheet.operation.insert-cell-image",type:p.CommandType.OPERATION,handler:(r,t)=>!0},ve={id:"sheet.command.insert-sheet-image",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService),i=r.get(g.ISheetDrawingService);if(!t)return!1;const o=t.drawings,s=o.map(w=>w.unitId),a=i.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:h}=a;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.INSERT})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.REMOVE}},{id:L.id,params:s}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:h,type:g.DrawingApplyType.INSERT}},{id:L.id,params:s}]}),!0):!1}},fe={id:"sheet.command.set-sheet-image",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService),i=r.get(g.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=i.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:d,objects:l,type:g.DrawingApplyType.UPDATE})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:l,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:d,objects:l,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[a]}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService);if(!t)return!1;const i=r.get(g.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=t,u={unitId:o,subUnitId:s,drawingIds:a};let d;if(c===b.ArrangeTypeEnum.forward?d=i.getForwardDrawingsOp(u):c===b.ArrangeTypeEnum.backward?d=i.getBackwardDrawingOp(u):c===b.ArrangeTypeEnum.front?d=i.getFrontDrawingsOp(u):c===b.ArrangeTypeEnum.back&&(d=i.getBackDrawingsOp(u)),d==null)return!1;const{objects:l,redo:h,undo:m}=d;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:l,type:g.DrawingApplyType.ARRANGE})?(n.pushUndoRedo({unitID:o,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:l,type:g.DrawingApplyType.ARRANGE}}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:l,type:g.DrawingApplyType.ARRANGE}}]}),!0):!1}};function qe(r){const t=[];return r.forEach(e=>{const{parent:n,children:i}=e,{unitId:o,subUnitId:s,drawingId:a}=n,c=x.getGroupState(0,0,i.map(l=>l.transform||{})),u=i.map(l=>{const h=l.transform||{left:0,top:0},{unitId:m,subUnitId:w,drawingId:f}=l;return{unitId:m,subUnitId:w,drawingId:f,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:a}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:b.DrawingTypeEnum.DRAWING_GROUP,transform:c};t.push({parent:d,children:u})}),t}function Je(r){const t=[];return r.forEach(e=>{const{parent:n,children:i}=e,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=n;if(c==null)return;const u=i.map(l=>{const{transform:h}=l,{unitId:m,subUnitId:w,drawingId:f}=l,_=x.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:m,subUnitId:w,drawingId:f,transform:_,groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:b.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:d,children:u})}),t}const Oe={id:"sheet.command.group-sheet-image",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService),i=r.get(g.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:m,children:w})=>{o.push(m.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=i.getGroupDrawingOp(t),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:g.DrawingApplyType.GROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Je(l),type:g.DrawingApplyType.UNGROUP}},{id:L.id,params:o}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:g.DrawingApplyType.GROUP}},{id:L.id,params:o}]}),!0):!1}},be={id:"sheet.command.ungroup-sheet-image",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(p.IUndoRedoService),i=r.get(g.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:m,children:w})=>{o.push(m.unitId),w.forEach(f=>{o.push(f.unitId)})});const s=i.getUngroupDrawingOp(t),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return e.syncExecuteCommand(g.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:g.DrawingApplyType.UNGROUP})?(n.pushUndoRedo({unitID:a,undoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:qe(l),type:g.DrawingApplyType.GROUP}},{id:L.id,params:o}],redoMutations:[{id:g.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:g.DrawingApplyType.UNGROUP}},{id:L.id,params:o}]}),!0):!1}};function $(r,t){const{from:e,to:n}=r,{column:i,columnOffset:o,row:s,rowOffset:a}=e,{column:c,columnOffset:u,row:d,rowOffset:l}=n,h=t.attachRangeWithCoord({startColumn:i,endColumn:i,startRow:s,endRow:s});if(h==null)return;const m=t.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:d,endRow:d});if(m==null)return;const{startX:w,startY:f}=h,{startX:_,startY:M}=m,I=x.precisionTo(w+o,1),D=x.precisionTo(f+a,1);let R=x.precisionTo(_+u-I,1),v=x.precisionTo(M+l-D,1);return h.startX===m.endX&&(R=0),h.startY===m.endY&&(v=0),{left:I,top:D,width:R,height:v}}function j(r,t){const{left:e=0,top:n=0,width:i=0,height:o=0}=r,s=t.getSelectionCellByPosition(e,n);if(s==null)return;const a={column:s.actualColumn,columnOffset:x.precisionTo(e-s.startX,1),row:s.actualRow,rowOffset:x.precisionTo(n-s.startY,1)},c=t.getSelectionCellByPosition(e+i,n+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:x.precisionTo(e+i-c.startX,1),row:c.actualRow,rowOffset:x.precisionTo(n+o-c.startY,1)};return{from:a,to:u}}var Ze=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,et=(r,t,e,n)=>{for(var i=n>1?void 0:n?Qe(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Ze(t,e,i),i},Y=(r,t)=>(e,n)=>t(e,n,r);let de=class extends p.Disposable{constructor(r,t,e,n,i,o,s,a,c,u,d){super(),this._commandService=r,this._univerInstanceService=t,this._selectionManagerService=e,this._selectionRenderService=n,this._imageIoService=i,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,this._messageService=c,this._localeService=u,this._renderManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async r=>{if(r.id===ge.id||r.id===pe.id){const t=r.params;if(t.files==null)return;const e=t.files.length;if(e>b.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(b.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(e),r.id===ge.id?t.files.forEach(async n=>{await this._insertCellImage(n)}):t.files.forEach(async n=>{await this._insertFloatImage(n)})}}))}async _insertCellImage(r){}async _insertFloatImage(r){let t;try{t=await this._imageIoService.saveImage(r)}catch(I){const D=I.message;D===b.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(b.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===b.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===b.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo();if(e==null)return;const{unitId:n,subUnitId:i}=e,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=t,{width:u,height:d,image:l}=await b.getImageSize(c||""),h=this._renderManagerService.getRenderById(n);if(h==null)return;const{width:m,height:w}=h.scene;this._imageIoService.addImageSourceCache(a,s,l);let f=1;if(u>b.DRAWING_IMAGE_WIDTH_LIMIT||d>b.DRAWING_IMAGE_HEIGHT_LIMIT){const I=b.DRAWING_IMAGE_WIDTH_LIMIT/u,D=b.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(I,D)}const _=this._getImagePosition(u*f,d*f,m,w);if(_==null)return;const M={unitId:n,subUnitId:i,drawingId:o,drawingType:b.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:$(_,this._selectionRenderService),sheetTransform:_};this._commandService.executeCommand(ve.id,{unitId:n,drawings:[M]})}_getUnitInfo(){const r=this._univerInstanceService.getCurrentUnitForType(p.UniverInstanceType.UNIVER_SHEET);if(r==null)return;const t=r.getActiveSheet();if(t==null)return;const e=r.getUnitId(),n=t.getSheetId();return{unitId:e,subUnitId:n}}_getImagePosition(r,t,e,n){const i=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};i&&i.length>0&&(o=i[i.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:d}=s,l=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),l=!0),d+t>n&&(d=n-t,d<0&&(d=0,t=n),l=!0),l){const f=this._selectionRenderService.getSelectionCellByPosition(u,d);if(f==null)return;u=f.startX,d=f.startY,a=f.actualColumn,c=f.actualRow}const h={column:a,columnOffset:0,row:c,rowOffset:0},m=this._selectionRenderService.getSelectionCellByPosition(u+r,d+t);if(m==null)return;const w={column:m.actualColumn,columnOffset:u+r-m.startX,row:m.actualRow,rowOffset:d+t-m.startY};return{from:h,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:i}=r;this._commandService.executeCommand(Te.id,{unitId:t,subUnitId:e,drawingIds:n,arrangeType:i})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const t=[];r.length!==0&&(r.forEach(e=>{const{unitId:n,subUnitId:i,drawingId:o,drawingType:s,transform:a}=e;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:n,subUnitId:i,drawingId:o});if(c==null)return;const u=j({...c.transform,...a},this._selectionRenderService);if(u==null)return;const d={...e,transform:{...c.transform,...a,...$(u,this._selectionRenderService)},sheetTransform:{...u}};t.push(d)}),t.length>0&&this._commandService.executeCommand(fe.id,{unitId:r[0].unitId,drawings:t}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Oe.id,r);const{unitId:t,subUnitId:e,drawingId:n}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:n}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(be.id,r)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(p.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};de=et([p.OnLifecycle(p.LifecycleStages.Rendered,de),Y(0,p.ICommandService),Y(1,p.IUniverInstanceService),Y(2,B.Inject(C.SelectionManagerService)),Y(3,V.ISelectionRenderService),Y(4,b.IImageIoService),Y(5,g.ISheetDrawingService),Y(6,b.IDrawingManagerService),Y(7,p.IContextService),Y(8,W.IMessageService),Y(9,B.Inject(p.LocaleService)),Y(10,x.IRenderManagerService)],de);var H=function(){return H=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i])}return r},H.apply(this,arguments)},tt=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e},Ae=A.forwardRef(function(r,t){var e=r.icon,n=r.id,i=r.className,o=r.extend,s=tt(r,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=A.useRef("_".concat(it()));return Pe(e,"".concat(n),{defIds:e.defIds,idSuffix:c.current},H({ref:t,className:a},s),o)});function Pe(r,t,e,n,i){return A.createElement(r.tag,H(H({key:t},nt(r,e,i)),n),(rt(r,e).children||[]).map(function(o,s){return Pe(o,"".concat(t,"-").concat(r.tag,"-").concat(s),e,void 0,i)}))}function nt(r,t,e){var n=H({},r.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1);var i=t.defIds;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function rt(r,t){var e,n=t.defIds;return!n||n.length===0?r:r.tag==="defs"&&(!((e=r.children)===null||e===void 0)&&e.length)?H(H({},r),{children:r.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?H(H({},i),{attrs:H(H({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):r}function it(){return Math.random().toString(36).substring(2,8)}Ae.displayName="UniverIcon";var ot={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"}}]},Ee=A.forwardRef(function(r,t){return A.createElement(Ae,Object.assign({},r,{id:"add-image-single",ref:t,icon:ot}))});Ee.displayName="AddImageSingle";const st="univer-upload-file-menu",at="univer-upload-file-menu-input",De={uploadFileMenu:st,uploadFileMenuInput:at},Ue="COMPONENT_UPLOAD_FILE_MENU";var he=(r=>(r[r.cellImage=0]="cellImage",r[r.floatImage=1]="floatImage",r))(he||{});const ct=r=>{const{type:t}=r,e=z.useDependency(p.ICommandService),n=A.useRef(null),i=()=>{var a;(a=n.current)==null||a.click()},o=b.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);t===he.floatImage?e.executeCommand(pe.id,{files:u}):t===he.cellImage&&e.executeCommand(ge.id,{files:u}),n.current&&(n.current.value="")};return A.createElement("div",{onClick:i,className:De.uploadFileMenu},A.createElement("input",{type:"file",className:De.uploadFileMenuInput,ref:n,onChange:s,accept:o,multiple:!0}))},Ne="addition-and-subtraction-single",je="sheet.menu.image";function lt(r){return{id:je,type:W.MenuItemType.SUBITEMS,positions:[W.MenuPosition.TOOLBAR_START],group:W.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ne,tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(r,p.UniverInstanceType.UNIVER_SHEET),disabled$:V.getCurrentRangeDisable$(r,{workbookTypes:[C.WorkbookEditablePermission],worksheetTypes:[C.WorksheetEditPermission],rangeTypes:[C.RangeProtectionPermissionEditPoint]})}}function dt(r){return{id:pe.id,title:"sheetImage.upload.float",type:W.MenuItemType.SELECTOR,label:{name:Ue,props:{type:he.floatImage}},positions:[je],hidden$:W.getMenuHiddenObservable(r,p.UniverInstanceType.UNIVER_SHEET)}}const ut="univer-image-common-panel",mt="univer-image-common-panel-grid",gt="univer-image-common-panel-border",ht="univer-image-common-panel-title",pt="univer-image-common-panel-row",ft="univer-image-common-panel-row-vertical",wt="univer-image-common-panel-column",St="univer-image-common-panel-column-center",vt="univer-image-common-panel-inline",_t="univer-image-common-panel-span2",Ct="univer-image-common-panel-span3",Dt="univer-image-common-panel-input",It="univer-sheet-image-menu",yt="univer-sheet-image-menu-input",K={imageCommonPanel:ut,imageCommonPanelGrid:mt,imageCommonPanelBorder:gt,imageCommonPanelTitle:ht,imageCommonPanelRow:pt,imageCommonPanelRowVertical:ft,imageCommonPanelColumn:wt,imageCommonPanelColumnCenter:St,imageCommonPanelInline:vt,imageCommonPanelSpan2:_t,imageCommonPanelSpan3:Ct,imageCommonPanelInput:Dt,sheetImageMenu:It,sheetImageMenuInput:yt},Rt=r=>{var D;const t=z.useDependency(p.ICommandService),e=z.useDependency(p.LocaleService),n=z.useDependency(b.IDrawingManagerService),i=z.useDependency(x.IRenderManagerService),{drawings:o}=r,s=o[0];if(s==null)return;const{unitId:a}=s,c=i.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const d=u.getTransformerByCreate(),[l,h]=A.useState(!0),m=(D=s.anchorType)!=null?D:g.SheetDrawingAnchorType.Position,[w,f]=A.useState(m);function _(R,v){const O=[];return R.forEach(S=>{const{oKey:U}=S,T=v.getDrawingOKey(U);if(T==null)return O.push(null),!0;const{unitId:G,subUnitId:E,drawingId:P,drawingType:y,anchorType:N,sheetTransform:X}=T;O.push({unitId:G,subUnitId:E,drawingId:P,anchorType:N,sheetTransform:X,drawingType:y})}),O}A.useEffect(()=>{const R=d.onClearControlObservable.add(O=>{O===!0&&h(!1)}),v=d.onChangeStartObservable.add(O=>{var T;const{objects:S}=O,U=_(S,n);if(U.length===0)h(!1);else if(U.length>=1){h(!0);const G=((T=U[0])==null?void 0:T.anchorType)||g.SheetDrawingAnchorType.Position;f(G)}});return()=>{v==null||v.dispose(),R==null||R.dispose()}},[]);function M(R){f(R);const v=n.getFocusDrawings();if(v.length===0)return;const O=v.map(S=>({unitId:S.unitId,subUnitId:S.subUnitId,drawingId:S.drawingId,anchorType:R}));t.executeCommand(fe.id,{unitId:v[0].unitId,drawings:O})}const I=R=>R?"block":"none";return A.createElement("div",{className:se(K.imageCommonPanelGrid,K.imageCommonPanelBorder),style:{display:I(l)}},A.createElement("div",{className:K.imageCommonPanelRow},A.createElement("div",{className:se(K.imageCommonPanelColumn,K.imageCommonPanelTitle)},A.createElement("div",null,e.t("drawing-anchor.title")))),A.createElement("div",{className:se(K.imageCommonPanelRow)},A.createElement("div",{className:se(K.imageCommonPanelColumn)},A.createElement(q.RadioGroup,{value:w,onChange:M,direction:"vertical"},A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.Both},e.t("drawing-anchor.both")),A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.Position},e.t("drawing-anchor.position")),A.createElement(q.Radio,{value:g.SheetDrawingAnchorType.None},e.t("drawing-anchor.none"))))))},Mt=()=>{const r=z.useDependency(b.IDrawingManagerService),t=r.getFocusDrawings();if(t==null||t.length===0)return;const[e,n]=A.useState(t);return A.useEffect(()=>{const i=r.focus$.subscribe(o=>{n(o)});return()=>{i.unsubscribe()}},[]),A.createElement("div",{className:K.imageCommonPanel},A.createElement(Q.DrawingCommonPanel,{drawings:e}),A.createElement(Rt,{drawings:e}))},ie={id:"sheet.command.move-drawing",type:p.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(p.ICommandService),n=r.get(g.ISheetDrawingService),i=r.get(V.ISelectionRenderService),{direction:o}=t,s=n.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,c=s.map(d=>{const{transform:l}=d;if(l==null)return null;const h={...l},{left:m=0,top:w=0}=l;return o===p.Direction.UP?h.top=w-1:o===p.Direction.DOWN?h.top=w+1:o===p.Direction.LEFT?h.left=m-1:o===p.Direction.RIGHT&&(h.left=m+1),{...d,transform:h,sheetTransform:j(h,i)}}).filter(d=>d!=null);return e.syncExecuteCommand(fe.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(L.id,[a]),!0):!1}},Le={id:"sheet.command.delete-drawing",type:p.CommandType.COMMAND,handler:r=>{const t=r.get(p.ICommandService),n=r.get(g.ISheetDrawingService).getFocusDrawings();if(n.length===0)return!1;const i=n[0].unitId,o=n.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:d}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:d}});return t.executeCommand(Se.id,{unitId:i,drawings:o})}};function oe(r){return!r.getContextValue(p.FOCUSING_FORMULA_EDITOR)&&!r.getContextValue(p.EDITOR_ACTIVATED)&&r.getContextValue(p.FOCUSING_COMMON_DRAWINGS)}const Tt={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.DOWN}},Ot={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.UP}},bt={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.LEFT}},At={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:oe,staticParameters:{direction:p.Direction.RIGHT}},Pt={id:Le.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:oe,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Et=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Nt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ut(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Et(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);const jt={};let re=class extends p.Disposable{constructor(r,t,e,n,i,o){super(),this._config=r,this._injector=t,this._componentManager=e,this._menuService=n,this._commandService=i,this._shortcutService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Ne,Ee)),this.disposeWithMe(r.register(Ue,ct)),this.disposeWithMe(r.register(ye,Mt))}_initMenus(){const{menu:r={}}=this._config;[lt,dt].forEach(t=>{this._menuService.addMenuItem(t(this._injector),r)})}_initCommands(){[pe,ge,ve,Se,fe,Re,L,Me,Oe,be,ie,Le,Te].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Tt,Ot,bt,At,Pt].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};re=Nt([p.OnLifecycle(p.LifecycleStages.Rendered,re),te(1,B.Inject(B.Injector)),te(2,B.Inject(W.ComponentManager)),te(3,W.IMenuService),te(4,p.ICommandService),te(5,W.IShortcutService)],re);var Lt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,Gt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Wt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Lt(t,e,i),i},ee=(r,t)=>(e,n)=>t(e,n,r);const Bt=[C.InsertRowCommand.id,C.InsertColCommand.id,C.RemoveRowCommand.id,C.RemoveColCommand.id,C.DeleteRangeMoveLeftCommand.id,C.DeleteRangeMoveUpCommand.id,C.InsertRangeMoveDownCommand.id,C.InsertRangeMoveRightCommand.id,C.DeltaRowHeightCommand.id,C.SetRowHeightCommand.id,C.DeltaColumnWidthCommand.id,C.SetColWidthCommand.id,C.SetRowHiddenCommand.id,C.SetSpecificRowsVisibleCommand.id,C.SetSpecificColsVisibleCommand.id,C.SetColHiddenCommand.id],xt=[C.SetRowVisibleMutation.id,C.SetRowHiddenMutation.id,C.SetColVisibleMutation.id,C.SetColHiddenMutation.id,C.SetWorksheetRowHeightMutation.id,C.SetWorksheetColWidthMutation.id];let ue=class extends p.Disposable{constructor(r,t,e,n,i,o){super(),this._commandService=r,this._sheetInterceptorService=t,this._sheetDrawingService=e,this._drawingManagerService=n,this._selectionRenderService=i,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!Bt.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const t=r.id;if(t===C.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if(t===C.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(t===C.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(t===C.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(t===C.DeleteRangeMoveLeftCommand.id){const{range:e}=r.params;return this._getRangeMoveUndo(e,0)}else if(t===C.DeleteRangeMoveUpCommand.id){const{range:e}=r.params;return this._getRangeMoveUndo(e,1)}else if(t===C.InsertRangeMoveDownCommand.id){const{range:e}=r.params;return this._getRangeMoveUndo(e,2)}else if(t===C.InsertRangeMoveRightCommand.id){const{range:e}=r.params;return this._getRangeMoveUndo(e,3)}else if(t===C.SetRowHiddenCommand.id||t===C.SetSpecificRowsVisibleCommand.id){const e=r.params,{unitId:n,subUnitId:i,ranges:o}=e;return this._getDrawingUndoForRowVisible(n,i,o)}else if(t===C.SetSpecificColsVisibleCommand.id||t===C.SetColHiddenCommand.id){const e=r.params,{unitId:n,subUnitId:i,ranges:o}=e;return this._getDrawingUndoForColVisible(n,i,o)}else if(t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id||t===C.DeltaColumnWidthCommand.id||t===C.SetColWidthCommand.id){const e=r.params,{unitId:n,subUnitId:i,ranges:o}=e,s=t===C.DeltaRowHeightCommand.id||t===C.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(n,i,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,t){const e=C.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const n=e.unitId,i=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(n,i),c=[],u=[];if(Object.keys(a).forEach(d=>{const l=a[d],{updateDrawings:h,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(r,t,l);c.push(...h),u.push(...m)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(c),{undo:l,redo:h,objects:m}=d;o.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:h,objects:m,type:g.DrawingApplyType.UPDATE}}),s.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:l,objects:m,type:g.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),l=d.undo,h=d.redo,m=d.objects;o.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:h,objects:m,type:g.DrawingApplyType.REMOVE}}),s.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:l,objects:m,type:g.DrawingApplyType.INSERT}})}return o.push({id:L.id,params:[n]}),s.push({id:L.id,params:[n]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(r,t,e){const n=[],i=[],{sheetTransform:o,anchorType:s=g.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:d}=e,{from:l,to:h}=o,{row:m,column:w}=l,{row:f,column:_}=h;if(o==null||a==null)return{updateDrawings:n,deleteDrawings:i};const{startRow:M,endRow:I,startColumn:D,endColumn:R}=r;let v=null,O=null;if(t===0&&m>=M&&f<=I)if(w>=D&&_<=R)i.push({unitId:c,subUnitId:u,drawingId:d});else{const S=this._shrinkCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(t===1&&w>=D&&_<=R)if(m>=M&&f<=I)i.push({unitId:c,subUnitId:u,drawingId:d});else{const S=this._shrinkRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(t===2){const S=this._expandRow(o,a,M,I,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}else if(t===3){const S=this._expandCol(o,a,D,R,s);v=S==null?void 0:S.newSheetTransform,O=S==null?void 0:S.newTransform}if(v!=null&&O!=null){const S=$(v,this._selectionRenderService);n.push({...e,sheetTransform:v,transform:S})}return{updateDrawings:n,deleteDrawings:i}}_remainDrawingSize(r,t,e){const n=j({...r},this._selectionRenderService);n!=null&&t.push({...e,sheetTransform:n})}_getDrawingUndoForColVisible(r,t,e){const n=this._drawingManagerService.getDrawingData(r,t),i=[],o=[];if(Object.keys(n).forEach(d=>{const l=n[d],{sheetTransform:h,transform:m,anchorType:w=g.SheetDrawingAnchorType.Position}=l;if(w===g.SheetDrawingAnchorType.None)this._remainDrawingSize(m,i,l);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(R<T)continue;if(w===g.SheetDrawingAnchorType.Position){let y=null,N=null;if(I>=T&&I<=G){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(X==null)return;N={...m,left:X.startX}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){i.push({...l,sheetTransform:y,transform:N});break}this._remainDrawingSize(m,i,l);continue}if(I>=T&&R<=G)continue;let E=null,P=null;if(I>=T&&I<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:I,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;P={...m,left:(y==null?void 0:y.startX)||0,width:((m==null?void 0:m.width)||0)-y.endX+y.startX}}else if(R>=T&&R<=G){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:R,startRow:f.row,endRow:_.row});if(y==null)return;P={...m,left:y.startX-((m==null?void 0:m.width)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:T,endColumn:G,startRow:f.row,endRow:_.row});if(y==null)return;if(P={...m,width:((m==null?void 0:m.width)||0)-y.endX+y.startX},E=j(P,this._selectionRenderService),E!=null&&P!=null){o.push({...l,sheetTransform:E,transform:P});break}}if(P!=null&&(E=j(P,this._selectionRenderService)),P!=null&&E!=null){i.push({...l,sheetTransform:E,transform:P});break}else this._remainDrawingSize(m,i,l)}}}),i.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,t,i),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,t,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(r,t,e){const n=this._sheetDrawingService.getBatchUpdateOp(e),{undo:i,redo:o,objects:s}=n,a=[{id:g.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:t,op:o,objects:s,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[r]}],c=[{id:g.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:t,op:i,objects:s,type:g.DrawingApplyType.UPDATE}},{id:L.id,params:[r]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(r,t,e){const n=this._drawingManagerService.getDrawingData(r,t),i=[],o=[];if(Object.keys(n).forEach(d=>{const l=n[d],{sheetTransform:h,transform:m,anchorType:w=g.SheetDrawingAnchorType.Position}=l;if(w===g.SheetDrawingAnchorType.None)this._remainDrawingSize(m,i,l);else{const{from:f,to:_}=h,{row:M,column:I}=f,{row:D,column:R}=_;for(let v=0;v<e.length;v++){const O=e[v],{startRow:S,endRow:U,startColumn:T,endColumn:G}=O;if(D<S)continue;if(w===g.SheetDrawingAnchorType.Position){let y=null,N=null;if(M>=S&&M<=U){const X=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(X==null)return;N={...m,top:X.startY}}if(N!=null&&(y=j(N,this._selectionRenderService),y!=null&&N!=null)){i.push({...l,sheetTransform:y,transform:N});break}this._remainDrawingSize(m,i,l);continue}if(M>=S&&D<=U)continue;let E=null,P=null;if(M>=S&&M<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:M,endRow:U});if(y==null)return;P={...m,top:(y==null?void 0:y.startY)||0,height:((m==null?void 0:m.height)||0)-y.endY+y.startY}}else if(D>=S&&D<=U){const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:D});if(y==null)return;P={...m,top:y.startY-((m==null?void 0:m.height)||0)}}else{const y=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:_.column,startRow:S,endRow:U});if(y==null)return;if(P={...m,height:((m==null?void 0:m.height)||0)-y.endY+y.startY},E=j(P,this._selectionRenderService),E!=null&&P!=null){o.push({...l,sheetTransform:E,transform:P});break}}if(P!=null&&(E=j(P,this._selectionRenderService)),P!=null&&E!=null){i.push({...l,sheetTransform:E,transform:P});break}else this._remainDrawingSize(m,i,l)}}}),i.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,t,i),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,t,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(r,t,e,n){const i=this._drawingManagerService.getDrawingData(r,t),o=[];return Object.keys(i).forEach(s=>{const a=i[s],{sheetTransform:c,transform:u,anchorType:d=g.SheetDrawingAnchorType.Position}=a;if(d===g.SheetDrawingAnchorType.None)this._remainDrawingSize(u,o,a);else{const{from:l,to:h}=c,{row:m,column:w}=l,{row:f,column:_}=h;for(let M=0;M<e.length;M++){const I=e[M],{startRow:D,endRow:R,startColumn:v,endColumn:O}=I;if(f<D||_<v)continue;if(d===g.SheetDrawingAnchorType.Position&&(m<=D&&f>=R||w<=v&&_>=O)){this._remainDrawingSize(u,o,a);continue}const S=$({...c},this._selectionRenderService);if(S!=null){o.push({...a,transform:S});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,t,o)}_getUnitIdAndSubUnitId(r,t){let e,n;if(t==="insert")e=r.unitId,n=r.subUnitId;else{const i=C.getSheetCommandTarget(this._univerInstanceService);if(i==null)return;e=i.unitId,n=i.subUnitId}return{unitId:e,subUnitId:n}}_moveRowInterceptor(r,t){const e=this._getUnitIdAndSubUnitId(r,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,{range:o}=r,s=o.startRow,a=o.endRow,c=[],u=[],d=this._sheetDrawingService.getDrawingData(n,i),l=[],h=[];if(Object.keys(d).forEach(m=>{const w=d[m],{sheetTransform:f,transform:_,anchorType:M=g.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(t==="insert"){const v=this._expandRow(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{row:S}=v,{row:U}=O;if(S>=s&&U<=a)h.push({unitId:n,subUnitId:i,drawingId:m});else{const T=this._shrinkRow(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:n,subUnitId:i,drawingId:m,transform:D,sheetTransform:I};l.push(R)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(l),{undo:w,redo:f,objects:_}=m;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:f,objects:_,type:g.DrawingApplyType.UPDATE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:w,objects:_,type:g.DrawingApplyType.UPDATE}})}if(h.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(h),w=m.undo,f=m.redo,_=m.objects;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:f,objects:_,type:g.DrawingApplyType.REMOVE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:w,objects:_,type:g.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[n]}),u.push({id:L.id,params:[n]}),{redos:c,undos:u}}_moveColInterceptor(r,t){const e=this._getUnitIdAndSubUnitId(r,t);if(e==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,{range:o}=r,s=o.startColumn,a=o.endColumn,c=[],u=[],d=this._sheetDrawingService.getDrawingData(n,i),l=[],h=[];if(Object.keys(d).forEach(m=>{const w=d[m],{sheetTransform:f,transform:_,anchorType:M=g.SheetDrawingAnchorType.Position}=w;if(f==null||_==null)return;let I,D;if(t==="insert"){const v=this._expandCol(f,_,s,a,M);I=v==null?void 0:v.newSheetTransform,D=v==null?void 0:v.newTransform}else{const{from:v,to:O}=f,{column:S}=v,{column:U}=O;if(S>=s&&U<=a)h.push({unitId:n,subUnitId:i,drawingId:m});else{const T=this._shrinkCol(f,_,s,a,M);I=T==null?void 0:T.newSheetTransform,D=T==null?void 0:T.newTransform}}if(!I||!D)return;const R={unitId:n,subUnitId:i,drawingId:m,transform:D,sheetTransform:I};l.push(R)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(l),{undo:w,redo:f,objects:_}=m;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:f,objects:_,type:g.DrawingApplyType.UPDATE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:w,objects:_,type:g.DrawingApplyType.UPDATE}})}if(h.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(h),w=m.undo,f=m.redo,_=m.objects;c.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:f,objects:_,type:g.DrawingApplyType.REMOVE}}),u.push({id:g.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:w,objects:_,type:g.DrawingApplyType.INSERT}})}return c.push({id:L.id,params:[n]}),u.push({id:L.id,params:[n]}),{redos:c,undos:u}}_expandCol(r,t,e,n,i=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(i===g.SheetDrawingAnchorType.None)return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:n,startRow:s.row,endRow:a.row});if(h==null)return;l={...t,left:(t.left||0)+h.endX-h.startX},d=j(l,this._selectionRenderService)}else if(u>=n)if(i===g.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u+o}},l=$(d,this._selectionRenderService);else return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkCol(r,t,e,n,i=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(i===g.SheetDrawingAnchorType.None)return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>n)d={from:{...s,column:c-o},to:{...a,column:u-o}},l=$(d,this._selectionRenderService);else{if(c>=e&&u<=n)return null;if(c<e&&u>n)if(i===g.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u-o}},l=$(d,this._selectionRenderService);else return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};else if(c>=e&&c<=n){if(c===e)l={...t,left:(t.left||0)-r.from.columnOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:s.row,endRow:a.row});if(h==null)return;l={...t,left:(t.left||0)-h.endX+h.startX-r.from.columnOffset}}d=j(l,this._selectionRenderService)}else if(u>=e&&u<=n&&i===g.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(h==null)return;d={from:{...s},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},l=$(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_expandRow(r,t,e,n,i=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(i===g.SheetDrawingAnchorType.None)return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>=e){const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:n,startColumn:s.column,endColumn:a.column});if(h==null)return;l={...t,top:(t.top||0)+h.endY-h.startY},d=j(l,this._selectionRenderService)}else if(u>=n)if(i===g.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u+o}},l=$(d,this._selectionRenderService);else return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkRow(r,t,e,n,i=g.SheetDrawingAnchorType.Position){const o=n-e+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(i===g.SheetDrawingAnchorType.None)return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};let d=null,l=null;if(c>n)d={from:{...s,row:c-o},to:{...a,row:u-o}},l=$(d,this._selectionRenderService);else{if(c>=e&&u<=n)return null;if(c<e&&u>n)if(i===g.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u-o}},l=$(d,this._selectionRenderService);else return{newSheetTransform:j({...t},this._selectionRenderService),newTransform:t};else if(c>=e&&c<=n){if(c===e)l={...t,top:(t.top||0)-r.from.rowOffset};else{const h=this._selectionRenderService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:s.column,endColumn:a.column});if(h==null)return;l={...t,top:(t.top||0)-h.endY+h.startY-r.from.rowOffset}}d=j(l,this._selectionRenderService)}else if(u>=e&&u<=n&&i===g.SheetDrawingAnchorType.Both){const h=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(h==null)return;d={from:{...s},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},l=$(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===C.SetWorksheetActiveOperation.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(i).forEach(a=>{const c=i[a];Object.keys(c).forEach(u=>{const d=c[u].data;d!=null&&Object.keys(d).forEach(l=>{a===e&&u===n?o.push(d[l]):s.push(d[l])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{xt.includes(r.id)&&requestIdleCallback(()=>{const t=r.params,{unitId:e,subUnitId:n,ranges:i}=t;this._refreshDrawingTransform(e,n,i)})}))}_refreshDrawingTransform(r,t,e){const n=this._drawingManagerService.getDrawingData(r,t),i=[];Object.keys(n).forEach(o=>{const s=n[o],{sheetTransform:a,anchorType:c=g.SheetDrawingAnchorType.Position}=s;if(c===g.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:l,column:h}=u,{row:m,column:w}=d;for(let f=0;f<e.length;f++){const _=e[f],{startRow:M,endRow:I,startColumn:D,endColumn:R}=_;if(p.Rectangle.intersects({startRow:M,endRow:I,startColumn:D,endColumn:R},{startRow:l,endRow:m,startColumn:h,endColumn:w})||l>I||h>R){i.push({...s,transform:$(a,this._selectionRenderService)});break}}}),i.length!==0&&(this._drawingManagerService.refreshTransform(i),this._commandService.syncExecuteCommand(L.id,[r]))}};ue=Gt([p.OnLifecycle(p.LifecycleStages.Rendered,ue),ee(0,p.ICommandService),ee(1,B.Inject(C.SheetInterceptorService)),ee(2,g.ISheetDrawingService),ee(3,b.IDrawingManagerService),ee(4,V.ISelectionRenderService),ee(5,p.IUniverInstanceService)],ue);var Ft=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Vt=(r,t,e,n)=>{for(var i=n>1?void 0:n?$t(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Ft(t,e,i),i},Z=(r,t)=>(e,n)=>t(e,n,r);function Ht(r,t,e,n){const{scaleX:i,scaleY:o}=t.getAncestorScale(),s=t.getViewport(V.VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...r,absolute:a};const{left:c,right:u,top:d,bottom:l}=r,h=n.getFreeze(),{startColumn:m,startRow:w,xSplit:f,ySplit:_}=h,M=e.getNoMergeCellPositionByIndexWithNoHeader(w-_,m-f),I=e.getNoMergeCellPositionByIndexWithNoHeader(w,m),{rowHeaderWidth:D,columnHeaderHeight:R}=e,v=I.startX-M.startX,O=I.startY-M.startY,{top:S,left:U,viewportScrollX:T,viewportScrollY:G}=s;let E,P;c<U?(a.left=!0,E=(v+D+(c-U))*i,P=Math.max(Math.min((v+D+(u-U))*i,(v+D)*i),(u-T)*i)):(a.left=!1,E=Math.max((c-T)*i,(v+D)*i),P=Math.max((u-T)*i,(v+D)*i));let y,N;return d<S?(a.top=!0,y=(O+R+(d-S))*o,N=Math.max(Math.min((O+R+(u-S))*o,(O+R)*o),(l-G)*o)):(a.top=!1,y=Math.max((d-G)*o,(O+R)*o),N=Math.max((l-G)*o,(O+R)*o)),{left:E,right:P,top:y,bottom:N,absolute:a}}const we=(r,t,e,n)=>{const{scene:i}=t,{left:o,top:s,width:a,height:c,angle:u}=r,d={left:o,right:o+a,top:s,bottom:s+c},l=Ht(d,i,e,n);return{startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:u,width:a,height:c,absolute:l.absolute}};exports.SheetCanvasFloatDomManagerService=class extends p.Disposable{constructor(e,n,i,o,s,a,c){super();k(this,"_domLayerMap",new Map);k(this,"_domLayerInfoMap",new Map);k(this,"_transformChange$",new ne.Subject);k(this,"transformChange$",this._transformChange$.asObservable());k(this,"_remove$",new ne.Subject);k(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=n,this._commandService=i,this._drawingManagerService=o,this._selectionRenderService=s,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(e,n){let i=this._domLayerMap.get(e);i||(i=new Map,this._domLayerMap.set(e,i));let o=i.get(n);return o||(o=new Map,i.set(n,o)),o}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const n=this._renderManagerService.getRenderById(e),i=n==null?void 0:n.scene;if(n==null||i==null)return null;const o=i.getTransformerByCreate(),s=n.engine.getCanvasElement();return{scene:i,transformer:o,renderObject:n,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(n=>{var Ce;const{unitId:i,subUnitId:o,drawingId:s}=n,a=C.getSheetCommandTarget(this._univerInstanceService,{unitId:i,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(n),u=(Ce=this._renderManagerService.getRenderById(i))==null?void 0:Ce.with(V.SheetSkeletonManagerService).getUnitSkeleton(i,o);if(c==null||a==null||u==null)return;const{transform:d,drawingType:l}=c;if(l!==p.DrawingTypeEnum.DRAWING_DOM)return;const h=this._getSceneAndTransformerByDrawingSearch(i);if(h==null)return;const{scene:m,canvas:w}=h;if(d==null)return!0;const{left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S}=d,U=b.getDrawingShapeKeyByDrawingSearch({unitId:i,subUnitId:o,drawingId:s}),T=m.getObject(U);if(T!=null){T.transformByState({left:f,top:_,width:M,height:I,angle:D,flipX:R,flipY:v,skewX:O,skewY:S});return}const G={left:f,top:_,width:M,height:I,zIndex:this._drawingManagerService.getDrawingOrder(i,o).length-1},E=new x.Rect(U,G);m.addObject(E,x.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(E);const P=new p.DisposableCollection,y=we(E,h.renderObject,u.skeleton,a.worksheet),N=new ne.BehaviorSubject(y),X={dispose:P,rect:E,position$:N,unitId:i,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:N,id:s,componentKey:c.componentKey,onPointerDown:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{w.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{w.dispatchEvent(new WheelEvent(F.type,F))}});const _e=E.onTransformChangeObservable.add(()=>{const F=we(E,h.renderObject,u.skeleton,a.worksheet);N.next(F)});P.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),_e&&P.add(_e),this._domLayerInfoMap.set(s,X)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var i,o;const n=(s,a)=>{var m;const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),d=Array.from(u.keys()),l=C.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),h=(m=this._renderManagerService.getRenderById(s))==null?void 0:m.with(V.SheetSkeletonManagerService).getUnitSkeleton(s,a);!c||!l||!h||d.forEach(w=>{const f=this._domLayerInfoMap.get(w);if(f){const _=we(f.rect,c.renderObject,h.skeleton,l.worksheet);f.position$.next(_)}})};if(e.id===V.SetScrollOperation.id){const s=e.params,{unitId:a,sheetId:c}=s;n(a,c)}else if(e.id===V.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(i=this._domLayerMap.get(a))==null?void 0:i.keys())!=null?o:[]).forEach(u=>{n(a,u)})}else if(e.id===C.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;n(s,a)}}))}_getPosition(e){const{startX:n,endX:i,startY:o,endY:s}=e,a=this._selectionRenderService.getSelectionCellByPosition(n,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:n-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(i,s);if(u==null)return;const d={column:u.actualColumn,columnOffset:i-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(n=>{const i=this._drawingManagerService.getDrawingByParam(n);if(!i||i.drawingType!==p.DrawingTypeEnum.DRAWING_DOM)return;const o={...i.transform};this._transformChange$.next({id:n.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(n=>{this._removeDom(n.drawingId)})}))}addFloatDomToPosition(e){const n=C.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:o}=n,{initPosition:s,componentKey:a}=e,c=p.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;const d={unitId:i,subUnitId:o,drawingId:c,drawingType:p.DrawingTypeEnum.DRAWING_DOM,componentKey:a,sheetTransform:u,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY}};return this._commandService.executeCommand(ve.id,{unitId:i,drawings:[d]}),this._ensureMap(i,o).set(c,e),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(e,n=!1){const i=this._domLayerInfoMap.get(e);if(!i)return;const{unitId:o,subUnitId:s}=i,a=this._ensureMap(o,s);this._domLayerInfoMap.delete(e),a.delete(e),i.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(i.rect),n){const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:l,objects:h}=d;this._commandService.syncExecuteCommand(g.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:l,objects:h,type:g.DrawingApplyType.REMOVE})}}};exports.SheetCanvasFloatDomManagerService=Vt([Z(0,B.Inject(x.IRenderManagerService)),Z(1,p.IUniverInstanceService),Z(2,B.Inject(p.ICommandService)),Z(3,b.IDrawingManagerService),Z(4,V.ISelectionRenderService),Z(5,B.Inject(W.CanvasFloatDomService)),Z(6,g.ISheetDrawingService)],exports.SheetCanvasFloatDomManagerService);var Yt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,kt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Xt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&Yt(t,e,i),i},ce=(r,t)=>(e,n)=>t(e,n,r);let me=class extends p.Disposable{constructor(r,t,e,n){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=t,this._drawingManagerService=e,this._renderManagerService=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,t,e)=>{const{unitId:n,scene:i,subUnitId:o}=t,s=this._drawingManagerService.getDrawingDataForUnit(n),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{this._drawingRenderService.renderDrawing(a.data[c],i)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,t,e)=>{const{unitId:n,subUnitId:i}=t,o=this._renderManagerService.getRenderById(n);if(!o)return e(r);const s=o.with(V.SheetSkeletonManagerService).getUnitSkeleton(n,i);if(!s)return e(r);const a=this._drawingManagerService.getDrawingDataForUnit(n),c=a==null?void 0:a[t.subUnitId];if(!c)return e(r);const{scaleX:u,scaleY:d}=o.scene,l=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=c.order.map(m=>c.data[m]).filter(m=>m.drawingType!==b.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(m=>{if(!m.groupId&&m.transform&&p.Tools.isDefine(m.transform.left)&&p.Tools.isDefine(m.transform.top)&&p.Tools.isDefine(m.transform.width)&&p.Tools.isDefine(m.transform.height)){const w=s.skeleton.getCellPositionByOffset(m.transform.left,m.transform.top,u,d,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,u,d,{x:0,y:0});w.column<l.startColumn&&(l.startColumn=w.column),w.row<l.startRow&&(l.startRow=w.row),l.endRow<f.row&&(l.endRow=f.row),l.endColumn<f.column&&(l.endColumn=f.column)}}),e(l)):e(r)}}))}};me=kt([p.OnLifecycle(p.LifecycleStages.Rendered,me),ce(0,B.Inject(V.SheetPrintInterceptorService)),ce(1,B.Inject(Q.DrawingRenderService)),ce(2,b.IDrawingManagerService),ce(3,x.IRenderManagerService)],me);var We=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Kt=(r,t,e)=>t in r?We(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,qt=(r,t,e,n)=>{for(var i=n>1?void 0:n?zt(t,e):t,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=(n?s(t,e,i):s(i))||i);return n&&i&&We(t,e,i),i},Ie=(r,t)=>(e,n)=>t(e,n,r),Ge=(r,t,e)=>(Kt(r,typeof t!="symbol"?t+"":t,e),e);const Jt="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends p.Plugin{constructor(e={},n,i){super();k(this,"_pluginConfig");this._injector=n,this._localeService=i,this._pluginConfig=p.Tools.deepMerge({},jt,e)}onStarting(e){super.onStarting(e),this._initDependencies(e)}_initDependencies(e){[[exports.SheetCanvasFloatDomManagerService],[re,{useFactory:()=>this._injector.createInstance(re,this._pluginConfig)}],[de],[le],[ue],[me]].forEach(i=>e.add(i))}};Ge(exports.UniverSheetsDrawingUIPlugin,"type",p.UniverInstanceType.UNIVER_SHEET);Ge(exports.UniverSheetsDrawingUIPlugin,"pluginName",Jt);exports.UniverSheetsDrawingUIPlugin=qt([p.DependentOn(b.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,g.UniverSheetsDrawingPlugin),Ie(1,B.Inject(B.Injector)),Ie(2,B.Inject(p.LocaleService))],exports.UniverSheetsDrawingUIPlugin);