@univerjs/sheets-drawing-ui 0.1.16 → 0.2.0

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