@univerjs/sheets-drawing-ui 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +285 -292
- package/lib/types/views/sheet-image-panel/SheetDrawingPanel.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +20 -20
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.UniverSheetsDrawingUi={},b.UniverCore,b["@wendellhu/redi"],b.UniverDrawingUi,b.UniverSheetsDrawing,b.UniverDrawing,b.UniverEngineRender,b.UniverSheetsUi,b.rxjs,b.UniverUi,b["@wendellhu/redi/react-bindings"],b.UniverSheets,b.React,b.UniverDesign,b.clsx))})(this,function(b,g,j,Q,h,E,U,X,B,$,z,w,O,J,ce){"use strict";var Gn=Object.defineProperty;var $n=(b,g,j)=>g in b?Gn(b,g,{enumerable:!0,configurable:!0,writable:!0,value:j}):b[g]=j;var q=(b,g,j)=>$n(b,typeof g!="symbol"?g+"":g,j);const W={id:"sheet.operation.clear-drawing-transformer",type:g.CommandType.MUTATION,handler:(r,n)=>{const i=r.get(U.IRenderManagerService);return n.forEach(e=>{var t,o;(o=(t=i.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},_e={id:"sheet.command.remove-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(S=>{const{unitId:f}=S;s.push(f)});const a=t.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}]}),!0):!1}},ye="COMPONENT_SHEET_DRAWING_PANEL",De={id:"sidebar.operation.sheet-image",type:g.CommandType.COMMAND,handler:async(r,n)=>{const i=r.get($.ISidebarService),e=r.get(g.LocaleService),t=r.get(g.IUniverInstanceService),o=r.get(E.IDrawingManagerService);if(!w.getSheetCommandTarget(t))return!1;switch(n.value){case"open":i.open({header:{title:e.t("sheetImage.panel.title")},children:{label:ye},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:i.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:g.CommandType.OPERATION,handler:(r,n)=>{const i=r.get(E.IDrawingManagerService),e=r.get(g.ICommandService);return n==null?!1:(i.focusDrawing([n]),e.executeCommand(De.id,{value:"open"}),!0)}},le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},He=()=>{const r=z.useDependency(E.IImageIoService),n=z.useDependency(g.LocaleService),[i,e]=O.useState(0);return O.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),O.createElement("div",{style:{display:i>0?"block":"none"},className:le.uploadLoading},O.createElement("div",{className:le.uploadLoadingBody},O.createElement("div",{className:le.uploadLoadingBodyAnimation}),O.createElement("div",{className:le.uploadLoadingBodyText},`${n.t("uploadLoading.loading")}: ${i}`)))};var Ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,xe=(r,n,i,e)=>{for(var t=e>1?void 0:e?Xe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Ye(n,i,t),t},ee=(r,n)=>(i,e)=>n(i,e,r);let de=class extends g.RxDisposable{constructor(n,i,e,t,o,s,a){super();q(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=i,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(g.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent($.BuiltInUIPart.CONTENT,()=>z.connectInjector(He,this._injector))}_dispose(n){const i=n.getUnitId();this._renderManagerService.removeRender(i)}_create(n){if(!n)return;const i=n.getUnitId();this._renderManagerService.has(i)&&!this._initImagePopupMenu.has(i)&&(this._popupMenuListener(i),this._initImagePopupMenu.add(i))}_hasCropObject(n){const i=n.getAllObjects();for(const e of i)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const i=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!i)return;const e=i.getTransformerByCreate();if(!e)return;const t=[];this.disposeWithMe(g.toDisposable(e.onCreateControlObservable.add(()=>{if(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(i))return;const s=e.getSelectedObjectMap();if(s.size>1){t.forEach(p=>p.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:m}=u;t.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,l,m)}}))),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:l,drawingId:m}])}))),this.disposeWithMe(g.toDisposable(e.onClearControlObservable.add(()=>{t.forEach(s=>s.dispose()),this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}))),this.disposeWithMe(g.toDisposable(e.onChangingObservable.add(()=>{t.forEach(s=>s.dispose())})))}_getImageMenuItems(n,i,e){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.delete",index:1,commandId:_e.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:i,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:i,drawingId:e}],disable:!1}]}};de=xe([g.OnLifecycle(g.LifecycleStages.Steady,de),ee(0,j.Inject(j.Injector)),ee(1,E.IDrawingManagerService),ee(2,j.Inject(X.SheetCanvasPopManagerService)),ee(3,U.IRenderManagerService),ee(4,g.IUniverInstanceService),ee(5,g.IContextService),ee(6,j.Inject($.IUIPartsService))],de);const ue={id:"sheet.operation.insert-float-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},me={id:"sheet.operation.insert-cell-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},Ie={id:"sheet.command.insert-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(S=>S.unitId),a=t.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}]}),!0):!1}},pe={id:"sheet.command.set-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=t.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService);if(!n)return!1;const t=r.get(h.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=n,u={unitId:o,subUnitId:s,drawingIds:a};let d;if(c===E.ArrangeTypeEnum.forward?d=t.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?d=t.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?d=t.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(d=t.getBackDrawingsOp(u)),d==null)return!1;const{objects:l,redo:m,undo:p}=d;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}};function ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a}=e,c=U.getGroupState(0,0,t.map(l=>l.transform||{})),u=t.map(l=>{const m=l.transform||{left:0,top:0},{unitId:p,subUnitId:S,drawingId:f}=l;return{unitId:p,subUnitId:S,drawingId:f,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};n.push({parent:d,children:u})}),n}function Ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=e;if(c==null)return;const u=t.map(l=>{const{transform:m}=l,{unitId:p,subUnitId:S,drawingId:f}=l,v=U.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:p,subUnitId:S,drawingId:f,transform:v,groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}const Re={id:"sheet.command.group-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getGroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Ke(l),type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}]}),!0):!1}},be={id:"sheet.command.ungroup-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getUngroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:ke(l),type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}]}),!0):!1}};function H(r,n){const{from:i,to:e}=r,{column:t,columnOffset:o,row:s,rowOffset:a}=i,{column:c,columnOffset:u,row:d,rowOffset:l}=e,m=n.attachRangeWithCoord({startColumn:t,endColumn:t,startRow:s,endRow:s});if(m==null)return;const p=n.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:d,endRow:d});if(p==null)return;const{startX:S,startY:f}=m,{startX:v,startY:y}=p,M=U.precisionTo(S+o,1),C=U.precisionTo(f+a,1);let T=U.precisionTo(v+u-M,1),I=U.precisionTo(y+l-C,1);return m.startX===p.endX&&(T=0),m.startY===p.endY&&(I=0),{left:M,top:C,width:T,height:I}}function G(r,n){const{left:i=0,top:e=0,width:t=0,height:o=0}=r,s=n.getSelectionCellByPosition(i,e);if(s==null)return;const a={column:s.actualColumn,columnOffset:U.precisionTo(i-s.startX,1),row:s.actualRow,rowOffset:U.precisionTo(e-s.startY,1)},c=n.getSelectionCellByPosition(i+t,e+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:U.precisionTo(i+t-c.startX,1),row:c.actualRow,rowOffset:U.precisionTo(e+o-c.startY,1)};return{from:a,to:u}}var ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(r,n,i,e)=>{for(var t=e>1?void 0:e?qe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&ze(n,i,t),t},k=(r,n)=>(i,e)=>n(i,e,r);let ge=class extends g.Disposable{constructor(r,n,i,e,t,o,s,a,c,u,d){super(),this._commandService=r,this._univerInstanceService=n,this._selectionManagerService=i,this._selectionRenderService=e,this._imageIoService=t,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,this._messageService=c,this._localeService=u,this._renderManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async r=>{if(r.id===me.id||r.id===ue.id){const n=r.params;if(n.files==null)return;const i=n.files.length;if(i>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(i),r.id===me.id?n.files.forEach(async e=>{await this._insertCellImage(e)}):n.files.forEach(async e=>{await this._insertFloatImage(e)})}}))}async _insertCellImage(r){}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const C=M.message;C===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const i=this._getUnitInfo();if(i==null)return;const{unitId:e,subUnitId:t}=i,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:u,height:d,image:l}=await E.getImageSize(c||""),m=this._renderManagerService.getRenderById(e);if(m==null)return;const{width:p,height:S}=m.scene;this._imageIoService.addImageSourceCache(a,s,l);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||d>E.DRAWING_IMAGE_HEIGHT_LIMIT){const M=E.DRAWING_IMAGE_WIDTH_LIMIT/u,C=E.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(M,C)}const v=this._getImagePosition(u*f,d*f,p,S);if(v==null)return;const y={unitId:e,subUnitId:t,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:H(v,this._selectionRenderService),sheetTransform:v};this._commandService.executeCommand(Ie.id,{unitId:e,drawings:[y]})}_getUnitInfo(){const r=this._univerInstanceService.getCurrentUnitForType(g.UniverInstanceType.UNIVER_SHEET);if(r==null)return;const n=r.getActiveSheet();if(n==null)return;const i=r.getUnitId(),e=n.getSheetId();return{unitId:i,subUnitId:e}}_getImagePosition(r,n,i,e){const t=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};t&&t.length>0&&(o=t[t.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:d}=s,l=!1;if(u+r>i&&(u=i-r,u<0&&(u=0,r=i),l=!0),d+n>e&&(d=e-n,d<0&&(d=0,n=e),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 m={column:a,columnOffset:0,row:c,rowOffset:0},p=this._selectionRenderService.getSelectionCellByPosition(u+r,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:m,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t}=r;this._commandService.executeCommand(Te.id,{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(i=>{const{unitId:e,subUnitId:t,drawingId:o,drawingType:s,transform:a}=i;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:o});if(c==null)return;const u=G({...c.transform,...a},this._selectionRenderService);if(u==null)return;const d={...i,transform:{...c.transform,...a,...H(u,this._selectionRenderService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(pe.id,{unitId:r[0].unitId,drawings:n}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Re.id,r);const{unitId:n,subUnitId:i,drawingId:e}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:i,drawingId:e}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(be.id,r)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};ge=Je([g.OnLifecycle(g.LifecycleStages.Rendered,ge),k(0,g.ICommandService),k(1,g.IUniverInstanceService),k(2,j.Inject(w.SelectionManagerService)),k(3,X.ISelectionRenderService),k(4,E.IImageIoService),k(5,h.ISheetDrawingService),k(6,E.IDrawingManagerService),k(7,g.IContextService),k(8,$.IMessageService),k(9,j.Inject(g.LocaleService)),k(10,U.IRenderManagerService)],ge);var x=function(){return x=Object.assign||function(r){for(var n,i=1,e=arguments.length;i<e;i++){n=arguments[i];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},x.apply(this,arguments)},Ze=function(r,n){var i={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&n.indexOf(e)<0&&(i[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(i[e[t]]=r[e[t]]);return i},Ee=O.forwardRef(function(r,n){var i=r.icon,e=r.id,t=r.className,o=r.extend,s=Ze(r,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=O.useRef("_".concat(nn()));return Pe(i,"".concat(e),{defIds:i.defIds,idSuffix:c.current},x({ref:n,className:a},s),o)});function Pe(r,n,i,e,t){return O.createElement(r.tag,x(x({key:n},Qe(r,i,t)),e),(en(r,i).children||[]).map(function(o,s){return Pe(o,"".concat(n,"-").concat(r.tag,"-").concat(s),i,void 0,t)}))}function Qe(r,n,i){var e=x({},r.attrs);i!=null&&i.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=i.colorChannel1);var t=n.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function en(r,n){var i,e=n.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((i=r.children)===null||i===void 0)&&i.length)?x(x({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?x(x({},t),{attrs:x(x({},t.attrs),{id:t.attrs.id+n.idSuffix})}):t})}):r}function nn(){return Math.random().toString(36).substring(2,8)}Ee.displayName="UniverIcon";var tn={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"}}]},Oe=O.forwardRef(function(r,n){return O.createElement(Ee,Object.assign({},r,{id:"add-image-single",ref:n,icon:tn}))});Oe.displayName="AddImageSingle";const Ae={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ue="COMPONENT_UPLOAD_FILE_MENU";var he=(r=>(r[r.cellImage=0]="cellImage",r[r.floatImage=1]="floatImage",r))(he||{});const rn=r=>{const{type:n}=r,i=z.useDependency(g.ICommandService),e=O.useRef(null),t=()=>{var a;(a=e.current)==null||a.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);n===he.floatImage?i.executeCommand(ue.id,{files:u}):n===he.cellImage&&i.executeCommand(me.id,{files:u}),e.current&&(e.current.value="")};return O.createElement("div",{onClick:t,className:Ae.uploadFileMenu},O.createElement("input",{type:"file",className:Ae.uploadFileMenuInput,ref:e,onChange:s,accept:o,multiple:!0}))},Ne="addition-and-subtraction-single",Le="sheet.menu.image";function on(r){return{id:Le,type:$.MenuItemType.SUBITEMS,positions:[$.MenuPosition.TOOLBAR_START],group:$.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ne,tooltip:"sheetImage.title",hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET),disabled$:X.getCurrentRangeDisable$(r,{workbookTypes:[w.WorkbookEditablePermission],worksheetTypes:[w.WorksheetEditPermission],rangeTypes:[w.RangeProtectionPermissionEditPoint]})}}function sn(r){return{id:ue.id,title:"sheetImage.upload.float",type:$.MenuItemType.SELECTOR,label:{name:Ue,props:{type:he.floatImage}},positions:[Le],hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET)}}const Z={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},an=r=>{var C;const n=z.useDependency(g.ICommandService),i=z.useDependency(g.LocaleService),e=z.useDependency(E.IDrawingManagerService),t=z.useDependency(U.IRenderManagerService),{drawings:o}=r,s=o[0];if(s==null)return;const{unitId:a}=s,c=t.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const d=u.getTransformerByCreate(),[l,m]=O.useState(!0),p=(C=s.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[S,f]=O.useState(p);function v(T,I){const P=[];return T.forEach(_=>{const{oKey:L}=_,R=I.getDrawingOKey(L);if(R==null)return P.push(null),!0;const{unitId:F,subUnitId:N,drawingId:A,drawingType:D,anchorType:V,sheetTransform:K}=R;P.push({unitId:F,subUnitId:N,drawingId:A,anchorType:V,sheetTransform:K,drawingType:D})}),P}O.useEffect(()=>{const T=d.onClearControlObservable.add(P=>{P===!0&&m(!1)}),I=d.onChangeStartObservable.add(P=>{var R;const{objects:_}=P,L=v(_,e);if(L.length===0)m(!1);else if(L.length>=1){m(!0);const F=((R=L[0])==null?void 0:R.anchorType)||h.SheetDrawingAnchorType.Position;f(F)}});return()=>{I==null||I.dispose(),T==null||T.dispose()}},[]);function y(T){f(T);const I=e.getFocusDrawings();if(I.length===0)return;const P=I.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:T}));n.executeCommand(pe.id,{unitId:I[0].unitId,drawings:P})}const M=T=>T?"block":"none";return O.createElement("div",{className:ce(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:M(l)}},O.createElement("div",{className:Z.imageCommonPanelRow},O.createElement("div",{className:ce(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle)},O.createElement("div",null,i.t("drawing-anchor.title")))),O.createElement("div",{className:ce(Z.imageCommonPanelRow)},O.createElement("div",{className:ce(Z.imageCommonPanelColumn)},O.createElement(J.RadioGroup,{value:S,onChange:y,direction:"vertical"},O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Both},i.t("drawing-anchor.both")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Position},i.t("drawing-anchor.position")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.None},i.t("drawing-anchor.none"))))))},cn=()=>{const r=z.useDependency(E.IDrawingManagerService),n=r.getFocusDrawings();if(n==null||n.length===0)return;const[i,e]=O.useState(n);return O.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),O.createElement("div",{className:Z.imageCommonPanel},O.createElement(Q.DrawingCommonPanel,{drawings:i}),O.createElement(an,{drawings:i}))},ie={id:"sheet.command.move-drawing",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService),t=r.get(X.ISelectionRenderService),{direction:o}=n,s=e.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 m={...l},{left:p=0,top:S=0}=l;return o===g.Direction.UP?m.top=S-1:o===g.Direction.DOWN?m.top=S+1:o===g.Direction.LEFT?m.left=p-1:o===g.Direction.RIGHT&&(m.left=p+1),{...d,transform:m,sheetTransform:G(m,t)}}).filter(d=>d!=null);return i.syncExecuteCommand(pe.id,{unitId:a,drawings:c})?(i.syncExecuteCommand(W.id,[a]),!0):!1}},je={id:"sheet.command.delete-drawing",type:g.CommandType.COMMAND,handler:r=>{const n=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:d}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:d}});return n.executeCommand(_e.id,{unitId:t,drawings:o})}};function re(r){return!r.getContextValue(g.FOCUSING_FORMULA_EDITOR)&&!r.getContextValue(g.EDITOR_ACTIVATED)&&r.getContextValue(g.FOCUSING_COMMON_DRAWINGS)}const ln={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_DOWN,priority:100,preconditions:re,staticParameters:{direction:g.Direction.DOWN}},dn={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_UP,priority:100,preconditions:re,staticParameters:{direction:g.Direction.UP}},un={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_LEFT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.LEFT}},mn={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_RIGHT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.RIGHT}},pn={id:je.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:re,binding:$.KeyCode.DELETE,mac:$.KeyCode.BACKSPACE};var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,fn=(r,n,i,e)=>{for(var t=e>1?void 0:e?hn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&gn(n,i,t),t},oe=(r,n)=>(i,e)=>n(i,e,r);const Sn={};let se=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._config=r,this._injector=n,this._componentManager=i,this._menuService=e,this._commandService=t,this._shortcutService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Ne,Oe)),this.disposeWithMe(r.register(Ue,rn)),this.disposeWithMe(r.register(ye,cn))}_initMenus(){const{menu:r={}}=this._config;[on,sn].forEach(n=>{this._menuService.addMenuItem(n(this._injector),r)})}_initCommands(){[ue,me,Ie,_e,pe,De,W,Me,Re,be,ie,je,Te].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[ln,dn,un,mn,pn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};se=fn([g.OnLifecycle(g.LifecycleStages.Rendered,se),oe(1,j.Inject(j.Injector)),oe(2,j.Inject($.ComponentManager)),oe(3,$.IMenuService),oe(4,g.ICommandService),oe(5,$.IShortcutService)],se);var vn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,_n=(r,n,i,e)=>{for(var t=e>1?void 0:e?wn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&vn(n,i,t),t},te=(r,n)=>(i,e)=>n(i,e,r);const In=[w.InsertRowCommand.id,w.InsertColCommand.id,w.RemoveRowCommand.id,w.RemoveColCommand.id,w.DeleteRangeMoveLeftCommand.id,w.DeleteRangeMoveUpCommand.id,w.InsertRangeMoveDownCommand.id,w.InsertRangeMoveRightCommand.id,w.DeltaRowHeightCommand.id,w.SetRowHeightCommand.id,w.DeltaColumnWidthCommand.id,w.SetColWidthCommand.id,w.SetRowHiddenCommand.id,w.SetSpecificRowsVisibleCommand.id,w.SetSpecificColsVisibleCommand.id,w.SetColHiddenCommand.id],Cn=[w.SetRowVisibleMutation.id,w.SetRowHiddenMutation.id,w.SetColVisibleMutation.id,w.SetColHiddenMutation.id,w.SetWorksheetRowHeightMutation.id,w.SetWorksheetColWidthMutation.id];let fe=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._commandService=r,this._sheetInterceptorService=n,this._sheetDrawingService=i,this._drawingManagerService=e,this._selectionRenderService=t,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!In.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const n=r.id;if(n===w.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if(n===w.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(n===w.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(n===w.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(n===w.DeleteRangeMoveLeftCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,0)}else if(n===w.DeleteRangeMoveUpCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,1)}else if(n===w.InsertRangeMoveDownCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,2)}else if(n===w.InsertRangeMoveRightCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,3)}else if(n===w.SetRowHiddenCommand.id||n===w.SetSpecificRowsVisibleCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===w.SetSpecificColsVisibleCommand.id||n===w.SetColHiddenCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id||n===w.DeltaColumnWidthCommand.id||n===w.SetColWidthCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i,s=n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,n){const i=w.getSheetCommandTarget(this._univerInstanceService);if(i==null)return{redos:[],undos:[]};const e=i.unitId,t=i.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,t),c=[],u=[];if(Object.keys(a).forEach(d=>{const l=a[d],{updateDrawings:m,deleteDrawings:p}=this._getUpdateOrDeleteDrawings(r,n,l);c.push(...m),u.push(...p)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(c),{undo:l,redo:m,objects:p}=d;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.UPDATE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),l=d.undo,m=d.redo,p=d.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.REMOVE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.INSERT}})}return o.push({id:W.id,params:[e]}),s.push({id:W.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(r,n,i){const e=[],t=[],{sheetTransform:o,anchorType:s=h.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:d}=i,{from:l,to:m}=o,{row:p,column:S}=l,{row:f,column:v}=m;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:T}=r;let I=null,P=null;if(n===0&&p>=y&&f<=M)if(S>=C&&v<=T)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===1&&S>=C&&v<=T)if(p>=y&&f<=M)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===2){const _=this._expandRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===3){const _=this._expandCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(I!=null&&P!=null){const _=H(I,this._selectionRenderService);e.push({...i,sheetTransform:I,transform:_})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,n,i){const e=G({...r},this._selectionRenderService);e!=null&&n.push({...i,sheetTransform:e})}_getDrawingUndoForColVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(T<R)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(M>=R&&M<=F){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(K==null)return;V={...p,left:K.startX}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(M>=R&&T<=F)continue;let N=null,A=null;if(M>=R&&M<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:(D==null?void 0:D.startX)||0,width:((p==null?void 0:p.width)||0)-D.endX+D.startX}}else if(T>=R&&T<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:D.startX-((p==null?void 0:p.width)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;if(A={...p,width:((p==null?void 0:p.width)||0)-D.endX+D.startX},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(r,n,i){const e=this._sheetDrawingService.getBatchUpdateOp(i),{undo:t,redo:o,objects:s}=e,a=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:o,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}],c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:t,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(C<_)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(y>=_&&y<=L){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(K==null)return;V={...p,top:K.startY}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(y>=_&&C<=L)continue;let N=null,A=null;if(y>=_&&y<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(D==null)return;A={...p,top:(D==null?void 0:D.startY)||0,height:((p==null?void 0:p.height)||0)-D.endY+D.startY}}else if(C>=_&&C<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:C});if(D==null)return;A={...p,top:D.startY-((p==null?void 0:p.height)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:L});if(D==null)return;if(A={...p,height:((p==null?void 0:p.height)||0)-D.endY+D.startY},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(r,n,i,e){const t=this._drawingManagerService.getDrawingData(r,n),o=[];return Object.keys(t).forEach(s=>{const a=t[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:m}=c,{row:p,column:S}=l,{row:f,column:v}=m;for(let y=0;y<i.length;y++){const M=i[y],{startRow:C,endRow:T,startColumn:I,endColumn:P}=M;if(f<C||v<I)continue;if(d===h.SheetDrawingAnchorType.Position&&(p<=C&&f>=T||S<=I&&v>=P)){this._remainDrawingSize(u,o,a);continue}const _=H({...c},this._selectionRenderService);if(_!=null){o.push({...a,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,n,o)}_getUnitIdAndSubUnitId(r,n){let i,e;if(n==="insert")i=r.unitId,e=r.subUnitId;else{const t=w.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;i=t.unitId,e=t.subUnitId}return{unitId:i,subUnitId:e}}_moveRowInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startRow,a=o.endRow,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandRow(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{row:_}=I,{row:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkRow(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_moveColInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startColumn,a=o.endColumn,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandCol(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{column:_}=I,{column:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkCol(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_expandCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:e,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)+m.endX-m.startX},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,column:c-o},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,left:(n.left||0)-r.from.columnOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:c-1,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)-m.endX+m.startX-r.from.columnOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i-1,endColumn:i-1,startRow:s.row,endRow:a.row});if(m==null)return;d={from:{...s},to:{...a,column:i-1,columnOffset:m.endX-m.startX}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_expandRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:e,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)+m.endY-m.startY},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,row:c-o},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,top:(n.top||0)-r.from.rowOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:c-1,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)-m.endY+m.startY-r.from.rowOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:i-1,endRow:i-1});if(m==null)return;d={from:{...s},to:{...a,row:i-1,rowOffset:m.endY-m.startY}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===w.SetWorksheetActiveOperation.id){const n=r.params,{unitId:i,subUnitId:e}=n,t=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(t).forEach(a=>{const c=t[a];Object.keys(c).forEach(u=>{const d=c[u].data;d!=null&&Object.keys(d).forEach(l=>{a===i&&u===e?o.push(d[l]):s.push(d[l])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{Cn.includes(r.id)&&requestIdleCallback(()=>{const n=r.params,{unitId:i,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(i,e,t)})}))}_refreshDrawingTransform(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[];Object.keys(e).forEach(o=>{const s=e[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:m}=u,{row:p,column:S}=d;for(let f=0;f<i.length;f++){const v=i[f],{startRow:y,endRow:M,startColumn:C,endColumn:T}=v;if(g.Rectangle.intersects({startRow:y,endRow:M,startColumn:C,endColumn:T},{startRow:l,endRow:p,startColumn:m,endColumn:S})||l>M||m>T){t.push({...s,transform:H(a,this._selectionRenderService)});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(W.id,[r]))}};fe=_n([g.OnLifecycle(g.LifecycleStages.Rendered,fe),te(0,g.ICommandService),te(1,j.Inject(w.SheetInterceptorService)),te(2,h.ISheetDrawingService),te(3,E.IDrawingManagerService),te(4,X.ISelectionRenderService),te(5,g.IUniverInstanceService)],fe);var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Mn=(r,n,i,e)=>{for(var t=e>1?void 0:e?Dn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&yn(n,i,t),t},ne=(r,n)=>(i,e)=>n(i,e,r);function Tn(r,n,i,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),s=n.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...r,absolute:a};const{left:c,right:u,top:d,bottom:l}=r,m=e.getFreeze(),{startColumn:p,startRow:S,xSplit:f,ySplit:v}=m,y=i.getNoMergeCellPositionByIndexWithNoHeader(S-v,p-f),M=i.getNoMergeCellPositionByIndexWithNoHeader(S,p),{rowHeaderWidth:C,columnHeaderHeight:T}=i,I=M.startX-y.startX,P=M.startY-y.startY,{top:_,left:L,viewportScrollX:R,viewportScrollY:F}=s;let N,A;c<L?(a.left=!0,N=(I+C+(c-L))*t,A=Math.max(Math.min((I+C+(u-L))*t,(I+C)*t),(u-R)*t)):(a.left=!1,N=Math.max((c-R)*t,(I+C)*t),A=Math.max((u-R)*t,(I+C)*t));let D,V;return d<_?(a.top=!0,D=(P+T+(d-_))*o,V=Math.max(Math.min((P+T+(u-_))*o,(P+T)*o),(l-F)*o)):(a.top=!1,D=Math.max((d-F)*o,(P+T)*o),V=Math.max((l-F)*o,(P+T)*o)),{left:N,right:A,top:D,bottom:V,absolute:a}}const Ce=(r,n,i,e)=>{const{scene:t}=n,{left:o,top:s,width:a,height:c,angle:u}=r,d={left:o,right:o+a,top:s,bottom:s+c},l=Tn(d,t,i,e);return{startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:u,width:a,height:c,absolute:l.absolute}};b.SheetCanvasFloatDomManagerService=class extends g.Disposable{constructor(i,e,t,o,s,a,c){super();q(this,"_domLayerMap",new Map);q(this,"_domLayerInfoMap",new Map);q(this,"_transformChange$",new B.Subject);q(this,"transformChange$",this._transformChange$.asObservable());q(this,"_remove$",new B.Subject);q(this,"remove$",this._remove$.asObservable());this._renderManagerService=i,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._selectionRenderService=s,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(i,e){let t=this._domLayerMap.get(i);t||(t=new Map,this._domLayerMap.set(i,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}_getSceneAndTransformerByDrawingSearch(i){if(i==null)return;const e=this._renderManagerService.getRenderById(i),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(i=>{i.forEach(e=>{var Ve,Fe;const{unitId:t,subUnitId:o,drawingId:s}=e,a=w.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),u=(Ve=this._renderManagerService.getRenderById(t))==null?void 0:Ve.with(X.SheetSkeletonManagerService).getUnitSkeleton(t,o);if(c==null||a==null||u==null)return;const{transform:d,drawingType:l}=c;if(l!==g.DrawingTypeEnum.DRAWING_DOM)return;const m=this._getSceneAndTransformerByDrawingSearch(t);if(m==null)return;const{scene:p,canvas:S}=m;if(d==null)return!0;const{left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_}=d,L=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),R=p.getObject(L);if(R!=null){R.transformByState({left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_});return}const F={left:f,top:v,width:y,height:M,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},N=new U.Rect(L,F);p.addObject(N,U.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(N);const A=this._ensureMap(t,o),D=new g.DisposableCollection,V=Ce(N,m.renderObject,u.skeleton,a.worksheet),K=new B.BehaviorSubject(V),Wn={dispose:D,rect:N,position$:K,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:K,id:s,componentKey:c.componentKey,onPointerDown:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{S.dispatchEvent(new WheelEvent(Y.type,Y))},props:(Fe=A.get(s))==null?void 0:Fe.props});const Be=N.onTransformChangeObservable.add(()=>{const Y=Ce(N,m.renderObject,u.skeleton,a.worksheet);K.next(Y)});D.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Be&&D.add(Be),this._domLayerInfoMap.set(s,Wn)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{var t,o;const e=(s,a)=>{var p;const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),d=Array.from(u.keys()),l=w.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),m=(p=this._renderManagerService.getRenderById(s))==null?void 0:p.with(X.SheetSkeletonManagerService).getUnitSkeleton(s,a);!c||!l||!m||d.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const v=Ce(f.rect,c.renderObject,m.skeleton,l.worksheet);f.position$.next(v)}})};if(i.id===X.SetScrollOperation.id){const s=i.params,{unitId:a,sheetId:c}=s;e(a,c)}else if(i.id===X.SetZoomRatioOperation.id){const s=i.params,{unitId:a}=s;Array.from((o=(t=this._domLayerMap.get(a))==null?void 0:t.keys())!=null?o:[]).forEach(u=>{e(a,u)})}else if(i.id===w.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=i.params;e(s,a)}}))}_getPosition(i){const{startX:e,endX:t,startY:o,endY:s}=i,a=this._selectionRenderService.getSelectionCellByPosition(e,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:e-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(t,s);if(u==null)return;const d={column:u.actualColumn,columnOffset:t-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==g.DrawingTypeEnum.DRAWING_DOM)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(i=>{i.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(i){const e=w.getSheetCommandTarget(this._univerInstanceService,{unitId:i.unitId,subUnitId:i.subUnitId});if(!e)throw new Error("cannot find current target!");const{unitId:t,subUnitId:o}=e,{initPosition:s,componentKey:a}=i,c=g.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;this._ensureMap(t,o).set(c,i);const l={unitId:t,subUnitId:o,drawingId:c,drawingType:g.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:t,drawings:[l]}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(i,e=!1){const t=this._domLayerInfoMap.get(i);if(!t)return;const{unitId:o,subUnitId:s}=t;this._domLayerInfoMap.delete(i),t.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(t.rect),e){this._ensureMap(o,s).delete(i);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:i});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:l,objects:m}=d;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:l,objects:m,type:h.DrawingApplyType.REMOVE})}}},b.SheetCanvasFloatDomManagerService=Mn([ne(0,j.Inject(U.IRenderManagerService)),ne(1,g.IUniverInstanceService),ne(2,j.Inject(g.ICommandService)),ne(3,E.IDrawingManagerService),ne(4,X.ISelectionRenderService),ne(5,j.Inject($.CanvasFloatDomService)),ne(6,h.ISheetDrawingService)],b.SheetCanvasFloatDomManagerService);var Rn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,En=(r,n,i,e)=>{for(var t=e>1?void 0:e?bn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Rn(n,i,t),t},Se=(r,n)=>(i,e)=>n(i,e,r);let ve=class extends g.Disposable{constructor(r,n,i,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=n,this._drawingManagerService=i,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,n,i)=>{const{unitId:e,scene:t,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{this._drawingRenderService.renderDrawing(a.data[c],t)}),i()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,n,i)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return i(r);const s=o.with(X.SheetSkeletonManagerService).getUnitSkeleton(e,t);if(!s)return i(r);const a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[n.subUnitId];if(!c)return i(r);const{scaleX:u,scaleY:d}=o.scene,l=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(p=>c.data[p]).filter(p=>p.drawingType!==E.DrawingTypeEnum.DRAWING_DOM);return m.length?(m.forEach(p=>{if(!p.groupId&&p.transform&&g.Tools.isDefine(p.transform.left)&&g.Tools.isDefine(p.transform.top)&&g.Tools.isDefine(p.transform.width)&&g.Tools.isDefine(p.transform.height)){const S=s.skeleton.getCellPositionByOffset(p.transform.left,p.transform.top,u,d,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(p.transform.left+p.transform.width,p.transform.top+p.transform.height,u,d,{x:0,y:0});S.column<l.startColumn&&(l.startColumn=S.column),S.row<l.startRow&&(l.startRow=S.row),l.endRow<f.row&&(l.endRow=f.row),l.endColumn<f.column&&(l.endColumn=f.column)}}),i(l)):i(r)}}))}};ve=En([g.OnLifecycle(g.LifecycleStages.Rendered,ve),Se(0,j.Inject(X.SheetPrintInterceptorService)),Se(1,j.Inject(Q.DrawingRenderService)),Se(2,E.IDrawingManagerService),Se(3,U.IRenderManagerService)],ve);var Pn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(r,n,i,e)=>{for(var t=e>1?void 0:e?On(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Pn(n,i,t),t},ae=(r,n)=>(i,e)=>n(i,e,r);let we=class extends g.Disposable{constructor(r,n,i,e,t){super(),this._drawingManagerService=r,this._renderManagerService=n,this._permissionService=i,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.removeObject(S)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingVisible(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?this._drawingManagerService.addNotification(f):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.removeObject(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetViewPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const m=this._drawingManagerService.getDrawingData(t,o),p=Object.values(m);this._drawingManagerService.addNotification(p)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingEditable(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.attachTransformerTo(v)}),this._drawingManagerService.addNotification(f)):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.detachTransformerFrom(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetEditPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const m=n.getUnitId(),p=e.getSheetId(),S=this._drawingManagerService.getDrawingData(m,p),f=Object.values(S),v=this._renderManagerService.getRenderById(m),y=v==null?void 0:v.scene;if(y==null)return;this._drawingManagerService.setDrawingEditable(!0),y.getAllObjects().forEach(C=>{C.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(T=>C.oKey.includes(T.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};we=An([g.OnLifecycle(g.LifecycleStages.Rendered,we),ae(0,E.IDrawingManagerService),ae(1,U.IRenderManagerService),ae(2,g.IPermissionService),ae(3,g.IUniverInstanceService),ae(4,j.Inject(g.UserManagerService))],we);var We=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Nn=(r,n,i)=>n in r?We(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i,Ln=(r,n,i,e)=>{for(var t=e>1?void 0:e?Un(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&We(n,i,t),t},Ge=(r,n)=>(i,e)=>n(i,e,r),$e=(r,n,i)=>Nn(r,typeof n!="symbol"?n+"":n,i);const jn="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends g.Plugin{constructor(i={},e,t){super();q(this,"_pluginConfig");this._injector=e,this._localeService=t,this._pluginConfig=g.Tools.deepMerge({},Sn,i)}onStarting(i){super.onStarting(i),this._initDependencies(i)}_initDependencies(i){[[b.SheetCanvasFloatDomManagerService],[se,{useFactory:()=>this._injector.createInstance(se,this._pluginConfig)}],[ge],[de],[fe],[ve],[we]].forEach(t=>i.add(t))}},$e(b.UniverSheetsDrawingUIPlugin,"type",g.UniverInstanceType.UNIVER_SHEET),$e(b.UniverSheetsDrawingUIPlugin,"pluginName",jn),b.UniverSheetsDrawingUIPlugin=Ln([g.DependentOn(E.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ge(1,j.Inject(j.Injector)),Ge(2,j.Inject(g.LocaleService))],b.UniverSheetsDrawingUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/drawing-ui"),require("@univerjs/sheets-drawing"),require("@univerjs/drawing"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi/react-bindings"),require("@univerjs/sheets"),require("react"),require("@univerjs/design"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/drawing-ui","@univerjs/sheets-drawing","@univerjs/drawing","@univerjs/engine-render","@univerjs/sheets-ui","rxjs","@univerjs/ui","@wendellhu/redi/react-bindings","@univerjs/sheets","react","@univerjs/design","clsx"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.UniverSheetsDrawingUi={},b.UniverCore,b["@wendellhu/redi"],b.UniverDrawingUi,b.UniverSheetsDrawing,b.UniverDrawing,b.UniverEngineRender,b.UniverSheetsUi,b.rxjs,b.UniverUi,b["@wendellhu/redi/react-bindings"],b.UniverSheets,b.React,b.UniverDesign,b.clsx))})(this,function(b,g,j,Q,h,E,U,X,B,$,z,w,O,J,ce){"use strict";var Gn=Object.defineProperty;var $n=(b,g,j)=>g in b?Gn(b,g,{enumerable:!0,configurable:!0,writable:!0,value:j}):b[g]=j;var q=(b,g,j)=>$n(b,typeof g!="symbol"?g+"":g,j);const W={id:"sheet.operation.clear-drawing-transformer",type:g.CommandType.MUTATION,handler:(r,n)=>{const i=r.get(U.IRenderManagerService);return n.forEach(e=>{var t,o;(o=(t=i.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},_e={id:"sheet.command.remove-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=[];o.forEach(S=>{const{unitId:f}=S;s.push(f)});const a=t.getBatchRemoveOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:d,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:u,op:l,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}]}),!0):!1}},ye="COMPONENT_SHEET_DRAWING_PANEL",De={id:"sidebar.operation.sheet-image",type:g.CommandType.COMMAND,handler:async(r,n)=>{const i=r.get($.ISidebarService),e=r.get(g.LocaleService),t=r.get(g.IUniverInstanceService),o=r.get(E.IDrawingManagerService);if(!w.getSheetCommandTarget(t))return!1;switch(n.value){case"open":i.open({header:{title:e.t("sheetImage.panel.title")},children:{label:ye},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:i.close();break}return!0}},Me={id:"sheet.operation.edit-sheet-image",type:g.CommandType.OPERATION,handler:(r,n)=>{const i=r.get(E.IDrawingManagerService),e=r.get(g.ICommandService);return n==null?!1:(i.focusDrawing([n]),e.executeCommand(De.id,{value:"open"}),!0)}},le={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},He=()=>{const r=z.useDependency(E.IImageIoService),n=z.useDependency(g.LocaleService),[i,e]=O.useState(0);return O.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),O.createElement("div",{style:{display:i>0?"block":"none"},className:le.uploadLoading},O.createElement("div",{className:le.uploadLoadingBody},O.createElement("div",{className:le.uploadLoadingBodyAnimation}),O.createElement("div",{className:le.uploadLoadingBodyText},`${n.t("uploadLoading.loading")}: ${i}`)))};var Ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,xe=(r,n,i,e)=>{for(var t=e>1?void 0:e?Xe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Ye(n,i,t),t},ee=(r,n)=>(i,e)=>n(i,e,r);let de=class extends g.RxDisposable{constructor(n,i,e,t,o,s,a){super();q(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=i,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(g.UniverInstanceType.UNIVER_SHEET).pipe(B.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(g.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent($.BuiltInUIPart.CONTENT,()=>z.connectInjector(He,this._injector))}_dispose(n){const i=n.getUnitId();this._renderManagerService.removeRender(i)}_create(n){if(!n)return;const i=n.getUnitId();this._renderManagerService.has(i)&&!this._initImagePopupMenu.has(i)&&(this._popupMenuListener(i),this._initImagePopupMenu.add(i))}_hasCropObject(n){const i=n.getAllObjects();for(const e of i)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const i=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!i)return;const e=i.getTransformerByCreate();if(!e)return;const t=[];this.disposeWithMe(g.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(i))return;const s=e.getSelectedObjectMap();if(s.size>1){t.forEach(p=>p.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:m}=u;t.push(this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(d,l,m)}}))),this._drawingManagerService.focusDrawing([{unitId:d,subUnitId:l,drawingId:m}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t.forEach(s=>s.dispose()),this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{t.forEach(s=>s.dispose())}))}_getImageMenuItems(n,i,e){return[{label:"image-popup.edit",index:0,commandId:Me.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.delete",index:1,commandId:_e.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:i,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:i,drawingId:e},disable:!1},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:i,drawingId:e}],disable:!1}]}};de=xe([g.OnLifecycle(g.LifecycleStages.Steady,de),ee(0,j.Inject(j.Injector)),ee(1,E.IDrawingManagerService),ee(2,j.Inject(X.SheetCanvasPopManagerService)),ee(3,U.IRenderManagerService),ee(4,g.IUniverInstanceService),ee(5,g.IContextService),ee(6,j.Inject($.IUIPartsService))],de);const ue={id:"sheet.operation.insert-float-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},me={id:"sheet.operation.insert-cell-image",type:g.CommandType.OPERATION,handler:(r,n)=>!0},Ie={id:"sheet.command.insert-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=n.drawings,s=o.map(S=>S.unitId),a=t.getBatchAddOp(o),{unitId:c,subUnitId:u,undo:d,redo:l,objects:m}=a;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.REMOVE}},{id:W.id,params:s}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:u,objects:m,type:h.DrawingApplyType.INSERT}},{id:W.id,params:s}]}),!0):!1}},pe={id:"sheet.command.set-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=t.getBatchUpdateOp(o),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:u,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:c,op:d,objects:l,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[a]}]}),!0):!1}},Te={id:"sheet.command.set-drawing-arrange",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService);if(!n)return!1;const t=r.get(h.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=n,u={unitId:o,subUnitId:s,drawingIds:a};let d;if(c===E.ArrangeTypeEnum.forward?d=t.getForwardDrawingsOp(u):c===E.ArrangeTypeEnum.backward?d=t.getBackwardDrawingOp(u):c===E.ArrangeTypeEnum.front?d=t.getFrontDrawingsOp(u):c===E.ArrangeTypeEnum.back&&(d=t.getBackDrawingsOp(u)),d==null)return!1;const{objects:l,redo:m,undo:p}=d;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:l,type:h.DrawingApplyType.ARRANGE}}]}),!0):!1}};function ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a}=e,c=U.getGroupState(0,0,t.map(l=>l.transform||{})),u=t.map(l=>{const m=l.transform||{left:0,top:0},{unitId:p,subUnitId:S,drawingId:f}=l;return{unitId:p,subUnitId:S,drawingId:f,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:c};n.push({parent:d,children:u})}),n}function Ke(r){const n=[];return r.forEach(i=>{const{parent:e,children:t}=i,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=e;if(c==null)return;const u=t.map(l=>{const{transform:m}=l,{unitId:p,subUnitId:S,drawingId:f}=l,v=U.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:p,subUnitId:S,drawingId:f,transform:v,groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:a,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}const Re={id:"sheet.command.group-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getGroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:Ke(l),type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}]}),!0):!1}},be={id:"sheet.command.ungroup-sheet-image",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(g.IUndoRedoService),t=r.get(h.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:p,children:S})=>{o.push(p.unitId),S.forEach(f=>{o.push(f.unitId)})});const s=t.getUngroupDrawingOp(n),{unitId:a,subUnitId:c,undo:u,redo:d,objects:l}=s;return i.syncExecuteCommand(h.SetDrawingApplyMutation.id,{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:ke(l),type:h.DrawingApplyType.GROUP}},{id:W.id,params:o}],redoMutations:[{id:h.SetDrawingApplyMutation.id,params:{op:d,unitId:a,subUnitId:c,objects:l,type:h.DrawingApplyType.UNGROUP}},{id:W.id,params:o}]}),!0):!1}};function H(r,n){const{from:i,to:e}=r,{column:t,columnOffset:o,row:s,rowOffset:a}=i,{column:c,columnOffset:u,row:d,rowOffset:l}=e,m=n.attachRangeWithCoord({startColumn:t,endColumn:t,startRow:s,endRow:s});if(m==null)return;const p=n.attachRangeWithCoord({startColumn:c,endColumn:c,startRow:d,endRow:d});if(p==null)return;const{startX:S,startY:f}=m,{startX:v,startY:y}=p,M=U.precisionTo(S+o,1),C=U.precisionTo(f+a,1);let T=U.precisionTo(v+u-M,1),I=U.precisionTo(y+l-C,1);return m.startX===p.endX&&(T=0),m.startY===p.endY&&(I=0),{left:M,top:C,width:T,height:I}}function G(r,n){const{left:i=0,top:e=0,width:t=0,height:o=0}=r,s=n.getSelectionCellByPosition(i,e);if(s==null)return;const a={column:s.actualColumn,columnOffset:U.precisionTo(i-s.startX,1),row:s.actualRow,rowOffset:U.precisionTo(e-s.startY,1)},c=n.getSelectionCellByPosition(i+t,e+o);if(c==null)return;const u={column:c.actualColumn,columnOffset:U.precisionTo(i+t-c.startX,1),row:c.actualRow,rowOffset:U.precisionTo(e+o-c.startY,1)};return{from:a,to:u}}var ze=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(r,n,i,e)=>{for(var t=e>1?void 0:e?qe(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&ze(n,i,t),t},k=(r,n)=>(i,e)=>n(i,e,r);let ge=class extends g.Disposable{constructor(r,n,i,e,t,o,s,a,c,u,d){super(),this._commandService=r,this._univerInstanceService=n,this._selectionManagerService=i,this._selectionRenderService=e,this._imageIoService=t,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=a,this._messageService=c,this._localeService=u,this._renderManagerService=d,this._init()}_init(){this._initCommandListeners(),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}_initCommandListeners(){this.disposeWithMe(this._commandService.onCommandExecuted(async r=>{if(r.id===me.id||r.id===ue.id){const n=r.params;if(n.files==null)return;const i=n.files.length;if(i>E.DRAWING_IMAGE_COUNT_LIMIT){this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))});return}this._imageIoService.setWaitCount(i),r.id===me.id?n.files.forEach(async e=>{await this._insertCellImage(e)}):n.files.forEach(async e=>{await this._insertFloatImage(e)})}}))}async _insertCellImage(r){}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const C=M.message;C===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const i=this._getUnitInfo();if(i==null)return;const{unitId:e,subUnitId:t}=i,{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:u,height:d,image:l}=await E.getImageSize(c||""),m=this._renderManagerService.getRenderById(e);if(m==null)return;const{width:p,height:S}=m.scene;this._imageIoService.addImageSourceCache(a,s,l);let f=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||d>E.DRAWING_IMAGE_HEIGHT_LIMIT){const M=E.DRAWING_IMAGE_WIDTH_LIMIT/u,C=E.DRAWING_IMAGE_HEIGHT_LIMIT/d;f=Math.max(M,C)}const v=this._getImagePosition(u*f,d*f,p,S);if(v==null)return;const y={unitId:e,subUnitId:t,drawingId:o,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:H(v,this._selectionRenderService),sheetTransform:v};this._commandService.executeCommand(Ie.id,{unitId:e,drawings:[y]})}_getUnitInfo(){const r=this._univerInstanceService.getCurrentUnitForType(g.UniverInstanceType.UNIVER_SHEET);if(r==null)return;const n=r.getActiveSheet();if(n==null)return;const i=r.getUnitId(),e=n.getSheetId();return{unitId:i,subUnitId:e}}_getImagePosition(r,n,i,e){const t=this._selectionManagerService.getSelections();let o={startRow:0,endRow:0,startColumn:0,endColumn:0};t&&t.length>0&&(o=t[t.length-1].range);const s=this._selectionRenderService.attachRangeWithCoord(o);if(s==null)return;let{startColumn:a,startRow:c,startX:u,startY:d}=s,l=!1;if(u+r>i&&(u=i-r,u<0&&(u=0,r=i),l=!0),d+n>e&&(d=e-n,d<0&&(d=0,n=e),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 m={column:a,columnOffset:0,row:c,rowOffset:0},p=this._selectionRenderService.getSelectionCellByPosition(u+r,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:m,to:S}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t}=r;this._commandService.executeCommand(Te.id,{unitId:n,subUnitId:i,drawingIds:e,arrangeType:t})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(i=>{const{unitId:e,subUnitId:t,drawingId:o,drawingType:s,transform:a}=i;if(a==null)return;const c=this._sheetDrawingService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:o});if(c==null)return;const u=G({...c.transform,...a},this._selectionRenderService);if(u==null)return;const d={...i,transform:{...c.transform,...a,...H(u,this._selectionRenderService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(pe.id,{unitId:r[0].unitId,drawings:n}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Re.id,r);const{unitId:n,subUnitId:i,drawingId:e}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:i,drawingId:e}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(be.id,r)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(g.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};ge=Je([g.OnLifecycle(g.LifecycleStages.Rendered,ge),k(0,g.ICommandService),k(1,g.IUniverInstanceService),k(2,j.Inject(w.SelectionManagerService)),k(3,X.ISelectionRenderService),k(4,E.IImageIoService),k(5,h.ISheetDrawingService),k(6,E.IDrawingManagerService),k(7,g.IContextService),k(8,$.IMessageService),k(9,j.Inject(g.LocaleService)),k(10,U.IRenderManagerService)],ge);var x=function(){return x=Object.assign||function(r){for(var n,i=1,e=arguments.length;i<e;i++){n=arguments[i];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},x.apply(this,arguments)},Ze=function(r,n){var i={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&n.indexOf(e)<0&&(i[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(i[e[t]]=r[e[t]]);return i},Ee=O.forwardRef(function(r,n){var i=r.icon,e=r.id,t=r.className,o=r.extend,s=Ze(r,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=O.useRef("_".concat(nn()));return Pe(i,"".concat(e),{defIds:i.defIds,idSuffix:c.current},x({ref:n,className:a},s),o)});function Pe(r,n,i,e,t){return O.createElement(r.tag,x(x({key:n},Qe(r,i,t)),e),(en(r,i).children||[]).map(function(o,s){return Pe(o,"".concat(n,"-").concat(r.tag,"-").concat(s),i,void 0,t)}))}function Qe(r,n,i){var e=x({},r.attrs);i!=null&&i.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=i.colorChannel1);var t=n.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function en(r,n){var i,e=n.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((i=r.children)===null||i===void 0)&&i.length)?x(x({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?x(x({},t),{attrs:x(x({},t.attrs),{id:t.attrs.id+n.idSuffix})}):t})}):r}function nn(){return Math.random().toString(36).substring(2,8)}Ee.displayName="UniverIcon";var tn={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"}}]},Oe=O.forwardRef(function(r,n){return O.createElement(Ee,Object.assign({},r,{id:"add-image-single",ref:n,icon:tn}))});Oe.displayName="AddImageSingle";const Ae={uploadFileMenu:"univer-upload-file-menu",uploadFileMenuInput:"univer-upload-file-menu-input"},Ue="COMPONENT_UPLOAD_FILE_MENU";var he=(r=>(r[r.cellImage=0]="cellImage",r[r.floatImage=1]="floatImage",r))(he||{});const rn=r=>{const{type:n}=r,i=z.useDependency(g.ICommandService),e=O.useRef(null),t=()=>{var a;(a=e.current)==null||a.click()},o=E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(a=>`.${a.replace("image/","")}`).join(","),s=a=>{const c=a.target.files;if(c==null)return;const u=Array.from(c);n===he.floatImage?i.executeCommand(ue.id,{files:u}):n===he.cellImage&&i.executeCommand(me.id,{files:u}),e.current&&(e.current.value="")};return O.createElement("div",{onClick:t,className:Ae.uploadFileMenu},O.createElement("input",{type:"file",className:Ae.uploadFileMenuInput,ref:e,onChange:s,accept:o,multiple:!0}))},Ne="addition-and-subtraction-single",Le="sheet.menu.image";function on(r){return{id:Le,type:$.MenuItemType.SUBITEMS,positions:[$.MenuPosition.TOOLBAR_START],group:$.MenuGroup.TOOLBAR_FORMULAS_INSERT,icon:Ne,tooltip:"sheetImage.title",hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET),disabled$:X.getCurrentRangeDisable$(r,{workbookTypes:[w.WorkbookEditablePermission],worksheetTypes:[w.WorksheetEditPermission],rangeTypes:[w.RangeProtectionPermissionEditPoint]})}}function sn(r){return{id:ue.id,title:"sheetImage.upload.float",type:$.MenuItemType.SELECTOR,label:{name:Ue,props:{type:he.floatImage}},positions:[Le],hidden$:$.getMenuHiddenObservable(r,g.UniverInstanceType.UNIVER_SHEET)}}const Z={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"},an=r=>{var C;const n=z.useDependency(g.ICommandService),i=z.useDependency(g.LocaleService),e=z.useDependency(E.IDrawingManagerService),t=z.useDependency(U.IRenderManagerService),{drawings:o}=r,s=o[0];if(s==null)return;const{unitId:a}=s,c=t.getRenderById(a),u=c==null?void 0:c.scene;if(u==null)return;const d=u.getTransformerByCreate(),[l,m]=O.useState(!0),p=(C=s.anchorType)!=null?C:h.SheetDrawingAnchorType.Position,[S,f]=O.useState(p);function v(T,I){const P=[];return T.forEach(_=>{const{oKey:L}=_,R=I.getDrawingOKey(L);if(R==null)return P.push(null),!0;const{unitId:F,subUnitId:N,drawingId:A,drawingType:D,anchorType:V,sheetTransform:K}=R;P.push({unitId:F,subUnitId:N,drawingId:A,anchorType:V,sheetTransform:K,drawingType:D})}),P}O.useEffect(()=>{const T=d.clearControl$.subscribe(P=>{P===!0&&m(!1)}),I=d.changeStart$.subscribe(P=>{var R;const{objects:_}=P,L=v(_,e);if(L.length===0)m(!1);else if(L.length>=1){m(!0);const F=((R=L[0])==null?void 0:R.anchorType)||h.SheetDrawingAnchorType.Position;f(F)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function y(T){f(T);const I=e.getFocusDrawings();if(I.length===0)return;const P=I.map(_=>({unitId:_.unitId,subUnitId:_.subUnitId,drawingId:_.drawingId,anchorType:T}));n.executeCommand(pe.id,{unitId:I[0].unitId,drawings:P})}const M=T=>T?"block":"none";return O.createElement("div",{className:ce(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:M(l)}},O.createElement("div",{className:Z.imageCommonPanelRow},O.createElement("div",{className:ce(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle)},O.createElement("div",null,i.t("drawing-anchor.title")))),O.createElement("div",{className:ce(Z.imageCommonPanelRow)},O.createElement("div",{className:ce(Z.imageCommonPanelColumn)},O.createElement(J.RadioGroup,{value:S,onChange:y,direction:"vertical"},O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Both},i.t("drawing-anchor.both")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.Position},i.t("drawing-anchor.position")),O.createElement(J.Radio,{value:h.SheetDrawingAnchorType.None},i.t("drawing-anchor.none"))))))},cn=()=>{const r=z.useDependency(E.IDrawingManagerService),n=r.getFocusDrawings(),[i,e]=O.useState(n);return O.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(i!=null&&i.length)&&O.createElement("div",{className:Z.imageCommonPanel},O.createElement(Q.DrawingCommonPanel,{drawings:i}),O.createElement(an,{drawings:i}))},ie={id:"sheet.command.move-drawing",type:g.CommandType.COMMAND,handler:(r,n)=>{const i=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService),t=r.get(X.ISelectionRenderService),{direction:o}=n,s=e.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 m={...l},{left:p=0,top:S=0}=l;return o===g.Direction.UP?m.top=S-1:o===g.Direction.DOWN?m.top=S+1:o===g.Direction.LEFT?m.left=p-1:o===g.Direction.RIGHT&&(m.left=p+1),{...d,transform:m,sheetTransform:G(m,t)}}).filter(d=>d!=null);return i.syncExecuteCommand(pe.id,{unitId:a,drawings:c})?(i.syncExecuteCommand(W.id,[a]),!0):!1}},je={id:"sheet.command.delete-drawing",type:g.CommandType.COMMAND,handler:r=>{const n=r.get(g.ICommandService),e=r.get(h.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:c,drawingId:u,drawingType:d}=s;return{unitId:a,subUnitId:c,drawingId:u,drawingType:d}});return n.executeCommand(_e.id,{unitId:t,drawings:o})}};function re(r){return!r.getContextValue(g.FOCUSING_FORMULA_EDITOR)&&!r.getContextValue(g.EDITOR_ACTIVATED)&&r.getContextValue(g.FOCUSING_COMMON_DRAWINGS)}const ln={id:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_DOWN,priority:100,preconditions:re,staticParameters:{direction:g.Direction.DOWN}},dn={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_UP,priority:100,preconditions:re,staticParameters:{direction:g.Direction.UP}},un={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_LEFT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.LEFT}},mn={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_RIGHT,priority:100,preconditions:re,staticParameters:{direction:g.Direction.RIGHT}},pn={id:je.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:re,binding:$.KeyCode.DELETE,mac:$.KeyCode.BACKSPACE};var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,fn=(r,n,i,e)=>{for(var t=e>1?void 0:e?hn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&gn(n,i,t),t},oe=(r,n)=>(i,e)=>n(i,e,r);const Sn={};let se=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._config=r,this._injector=n,this._componentManager=i,this._menuService=e,this._commandService=t,this._shortcutService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Ne,Oe)),this.disposeWithMe(r.register(Ue,rn)),this.disposeWithMe(r.register(ye,cn))}_initMenus(){const{menu:r={}}=this._config;[on,sn].forEach(n=>{this._menuService.addMenuItem(n(this._injector),r)})}_initCommands(){[ue,me,Ie,_e,pe,De,W,Me,Re,be,ie,je,Te].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[ln,dn,un,mn,pn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};se=fn([g.OnLifecycle(g.LifecycleStages.Rendered,se),oe(1,j.Inject(j.Injector)),oe(2,j.Inject($.ComponentManager)),oe(3,$.IMenuService),oe(4,g.ICommandService),oe(5,$.IShortcutService)],se);var vn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,_n=(r,n,i,e)=>{for(var t=e>1?void 0:e?wn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&vn(n,i,t),t},te=(r,n)=>(i,e)=>n(i,e,r);const In=[w.InsertRowCommand.id,w.InsertColCommand.id,w.RemoveRowCommand.id,w.RemoveColCommand.id,w.DeleteRangeMoveLeftCommand.id,w.DeleteRangeMoveUpCommand.id,w.InsertRangeMoveDownCommand.id,w.InsertRangeMoveRightCommand.id,w.DeltaRowHeightCommand.id,w.SetRowHeightCommand.id,w.DeltaColumnWidthCommand.id,w.SetColWidthCommand.id,w.SetRowHiddenCommand.id,w.SetSpecificRowsVisibleCommand.id,w.SetSpecificColsVisibleCommand.id,w.SetColHiddenCommand.id],Cn=[w.SetRowVisibleMutation.id,w.SetRowHiddenMutation.id,w.SetColVisibleMutation.id,w.SetColHiddenMutation.id,w.SetWorksheetRowHeightMutation.id,w.SetWorksheetColWidthMutation.id];let fe=class extends g.Disposable{constructor(r,n,i,e,t,o){super(),this._commandService=r,this._sheetInterceptorService=n,this._sheetDrawingService=i,this._drawingManagerService=e,this._selectionRenderService=t,this._univerInstanceService=o,this._init()}_init(){this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!In.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const n=r.id;if(n===w.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if(n===w.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(n===w.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(n===w.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(n===w.DeleteRangeMoveLeftCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,0)}else if(n===w.DeleteRangeMoveUpCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,1)}else if(n===w.InsertRangeMoveDownCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,2)}else if(n===w.InsertRangeMoveRightCommand.id){const{range:i}=r.params;return this._getRangeMoveUndo(i,3)}else if(n===w.SetRowHiddenCommand.id||n===w.SetSpecificRowsVisibleCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===w.SetSpecificColsVisibleCommand.id||n===w.SetColHiddenCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id||n===w.DeltaColumnWidthCommand.id||n===w.SetColWidthCommand.id){const i=r.params,{unitId:e,subUnitId:t,ranges:o}=i,s=n===w.DeltaRowHeightCommand.id||n===w.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,n){const i=w.getSheetCommandTarget(this._univerInstanceService);if(i==null)return{redos:[],undos:[]};const e=i.unitId,t=i.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,t),c=[],u=[];if(Object.keys(a).forEach(d=>{const l=a[d],{updateDrawings:m,deleteDrawings:p}=this._getUpdateOrDeleteDrawings(r,n,l);c.push(...m),u.push(...p)}),c.length===0&&u.length===0)return{redos:[],undos:[]};if(c.length>0){const d=this._sheetDrawingService.getBatchUpdateOp(c),{undo:l,redo:m,objects:p}=d;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.UPDATE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.UPDATE}})}if(u.length>0){const d=this._sheetDrawingService.getBatchRemoveOp(u),l=d.undo,m=d.redo,p=d.objects;o.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:m,objects:p,type:h.DrawingApplyType.REMOVE}}),s.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:l,objects:p,type:h.DrawingApplyType.INSERT}})}return o.push({id:W.id,params:[e]}),s.push({id:W.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(r,n,i){const e=[],t=[],{sheetTransform:o,anchorType:s=h.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:u,drawingId:d}=i,{from:l,to:m}=o,{row:p,column:S}=l,{row:f,column:v}=m;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:y,endRow:M,startColumn:C,endColumn:T}=r;let I=null,P=null;if(n===0&&p>=y&&f<=M)if(S>=C&&v<=T)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===1&&S>=C&&v<=T)if(p>=y&&f<=M)t.push({unitId:c,subUnitId:u,drawingId:d});else{const _=this._shrinkRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===2){const _=this._expandRow(o,a,y,M,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}else if(n===3){const _=this._expandCol(o,a,C,T,s);I=_==null?void 0:_.newSheetTransform,P=_==null?void 0:_.newTransform}if(I!=null&&P!=null){const _=H(I,this._selectionRenderService);e.push({...i,sheetTransform:I,transform:_})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,n,i){const e=G({...r},this._selectionRenderService);e!=null&&n.push({...i,sheetTransform:e})}_getDrawingUndoForColVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(T<R)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(M>=R&&M<=F){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(K==null)return;V={...p,left:K.startX}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(M>=R&&T<=F)continue;let N=null,A=null;if(M>=R&&M<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:M,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:(D==null?void 0:D.startX)||0,width:((p==null?void 0:p.width)||0)-D.endX+D.startX}}else if(T>=R&&T<=F){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:T,startRow:f.row,endRow:v.row});if(D==null)return;A={...p,left:D.startX-((p==null?void 0:p.width)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:R,endColumn:F,startRow:f.row,endRow:v.row});if(D==null)return;if(A={...p,width:((p==null?void 0:p.width)||0)-D.endX+D.startX},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_createUndoAndRedoMutation(r,n,i){const e=this._sheetDrawingService.getBatchUpdateOp(i),{undo:t,redo:o,objects:s}=e,a=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:o,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}],c=[{id:h.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:n,op:t,objects:s,type:h.DrawingApplyType.UPDATE}},{id:W.id,params:[r]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[],o=[];if(Object.keys(e).forEach(d=>{const l=e[d],{sheetTransform:m,transform:p,anchorType:S=h.SheetDrawingAnchorType.Position}=l;if(S===h.SheetDrawingAnchorType.None)this._remainDrawingSize(p,t,l);else{const{from:f,to:v}=m,{row:y,column:M}=f,{row:C,column:T}=v;for(let I=0;I<i.length;I++){const P=i[I],{startRow:_,endRow:L,startColumn:R,endColumn:F}=P;if(C<_)continue;if(S===h.SheetDrawingAnchorType.Position){let D=null,V=null;if(y>=_&&y<=L){const K=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(K==null)return;V={...p,top:K.startY}}if(V!=null&&(D=G(V,this._selectionRenderService),D!=null&&V!=null)){t.push({...l,sheetTransform:D,transform:V});break}this._remainDrawingSize(p,t,l);continue}if(y>=_&&C<=L)continue;let N=null,A=null;if(y>=_&&y<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:y,endRow:L});if(D==null)return;A={...p,top:(D==null?void 0:D.startY)||0,height:((p==null?void 0:p.height)||0)-D.endY+D.startY}}else if(C>=_&&C<=L){const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:C});if(D==null)return;A={...p,top:D.startY-((p==null?void 0:p.height)||0)}}else{const D=this._selectionRenderService.attachRangeWithCoord({startColumn:f.column,endColumn:v.column,startRow:_,endRow:L});if(D==null)return;if(A={...p,height:((p==null?void 0:p.height)||0)-D.endY+D.startY},N=G(A,this._selectionRenderService),N!=null&&A!=null){o.push({...l,sheetTransform:N,transform:A});break}}if(A!=null&&(N=G(A,this._selectionRenderService)),A!=null&&N!=null){t.push({...l,sheetTransform:N,transform:A});break}else this._remainDrawingSize(p,t,l)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(r,n,t),c=[],u=[];if(o.length>0){const{redos:d,undos:l}=this._createUndoAndRedoMutation(r,n,o);c.push(...d),u.push(...l)}return{redos:s,undos:a,preRedos:c,preUndos:u}}_getDrawingUndoForRowAndColSize(r,n,i,e){const t=this._drawingManagerService.getDrawingData(r,n),o=[];return Object.keys(t).forEach(s=>{const a=t[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:m}=c,{row:p,column:S}=l,{row:f,column:v}=m;for(let y=0;y<i.length;y++){const M=i[y],{startRow:C,endRow:T,startColumn:I,endColumn:P}=M;if(f<C||v<I)continue;if(d===h.SheetDrawingAnchorType.Position&&(p<=C&&f>=T||S<=I&&v>=P)){this._remainDrawingSize(u,o,a);continue}const _=H({...c},this._selectionRenderService);if(_!=null){o.push({...a,transform:_});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,n,o)}_getUnitIdAndSubUnitId(r,n){let i,e;if(n==="insert")i=r.unitId,e=r.subUnitId;else{const t=w.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;i=t.unitId,e=t.subUnitId}return{unitId:i,subUnitId:e}}_moveRowInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startRow,a=o.endRow,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandRow(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{row:_}=I,{row:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkRow(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_moveColInterceptor(r,n){const i=this._getUnitIdAndSubUnitId(r,n);if(i==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=i,{range:o}=r,s=o.startColumn,a=o.endColumn,c=[],u=[],d=this._sheetDrawingService.getDrawingData(e,t),l=[],m=[];if(Object.keys(d).forEach(p=>{const S=d[p],{sheetTransform:f,transform:v,anchorType:y=h.SheetDrawingAnchorType.Position}=S;if(f==null||v==null)return;let M,C;if(n==="insert"){const I=this._expandCol(f,v,s,a,y);M=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:P}=f,{column:_}=I,{column:L}=P;if(_>=s&&L<=a)m.push({unitId:e,subUnitId:t,drawingId:p});else{const R=this._shrinkCol(f,v,s,a,y);M=R==null?void 0:R.newSheetTransform,C=R==null?void 0:R.newTransform}}if(!M||!C)return;const T={unitId:e,subUnitId:t,drawingId:p,transform:C,sheetTransform:M};l.push(T)}),l.length===0&&m.length===0)return{redos:[],undos:[]};if(l.length>0){const p=this._sheetDrawingService.getBatchUpdateOp(l),{undo:S,redo:f,objects:v}=p;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.UPDATE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.UPDATE}})}if(m.length>0){const p=this._sheetDrawingService.getBatchRemoveOp(m),S=p.undo,f=p.redo,v=p.objects;c.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:h.DrawingApplyType.REMOVE}}),u.push({id:h.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:h.DrawingApplyType.INSERT}})}return c.push({id:W.id,params:[e]}),u.push({id:W.id,params:[e]}),{redos:c,undos:u}}_expandCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:e,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)+m.endX-m.startX},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkCol(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{column:c}=s,{column:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,column:c-o},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,column:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,left:(n.left||0)-r.from.columnOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i,endColumn:c-1,startRow:s.row,endRow:a.row});if(m==null)return;l={...n,left:(n.left||0)-m.endX+m.startX-r.from.columnOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:i-1,endColumn:i-1,startRow:s.row,endRow:a.row});if(m==null)return;d={from:{...s},to:{...a,column:i-1,columnOffset:m.endX-m.startX}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_expandRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>=i){const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:e,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)+m.endY-m.startY},d=G(l,this._selectionRenderService)}else if(u>=e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u+o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_shrinkRow(r,n,i,e,t=h.SheetDrawingAnchorType.Position){const o=e-i+1,{from:s,to:a}=r,{row:c}=s,{row:u}=a;if(t===h.SheetDrawingAnchorType.None)return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};let d=null,l=null;if(c>e)d={from:{...s,row:c-o},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else{if(c>=i&&u<=e)return null;if(c<i&&u>e)if(t===h.SheetDrawingAnchorType.Both)d={from:{...s},to:{...a,row:u-o}},l=H(d,this._selectionRenderService);else return{newSheetTransform:G({...n},this._selectionRenderService),newTransform:n};else if(c>=i&&c<=e){if(c===i)l={...n,top:(n.top||0)-r.from.rowOffset};else{const m=this._selectionRenderService.attachRangeWithCoord({startRow:i,endRow:c-1,startColumn:s.column,endColumn:a.column});if(m==null)return;l={...n,top:(n.top||0)-m.endY+m.startY-r.from.rowOffset}}d=G(l,this._selectionRenderService)}else if(u>=i&&u<=e&&t===h.SheetDrawingAnchorType.Both){const m=this._selectionRenderService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:i-1,endRow:i-1});if(m==null)return;d={from:{...s},to:{...a,row:i-1,rowOffset:m.endY-m.startY}},l=H(d,this._selectionRenderService)}}return d!=null&&l!=null?{newSheetTransform:d,newTransform:l}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===w.SetWorksheetActiveOperation.id){const n=r.params,{unitId:i,subUnitId:e}=n,t=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(t).forEach(a=>{const c=t[a];Object.keys(c).forEach(u=>{const d=c[u].data;d!=null&&Object.keys(d).forEach(l=>{a===i&&u===e?o.push(d[l]):s.push(d[l])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)}}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{Cn.includes(r.id)&&requestIdleCallback(()=>{const n=r.params,{unitId:i,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(i,e,t)})}))}_refreshDrawingTransform(r,n,i){const e=this._drawingManagerService.getDrawingData(r,n),t=[];Object.keys(e).forEach(o=>{const s=e[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:m}=u,{row:p,column:S}=d;for(let f=0;f<i.length;f++){const v=i[f],{startRow:y,endRow:M,startColumn:C,endColumn:T}=v;if(g.Rectangle.intersects({startRow:y,endRow:M,startColumn:C,endColumn:T},{startRow:l,endRow:p,startColumn:m,endColumn:S})||l>M||m>T){t.push({...s,transform:H(a,this._selectionRenderService)});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(W.id,[r]))}};fe=_n([g.OnLifecycle(g.LifecycleStages.Rendered,fe),te(0,g.ICommandService),te(1,j.Inject(w.SheetInterceptorService)),te(2,h.ISheetDrawingService),te(3,E.IDrawingManagerService),te(4,X.ISelectionRenderService),te(5,g.IUniverInstanceService)],fe);var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Mn=(r,n,i,e)=>{for(var t=e>1?void 0:e?Dn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&yn(n,i,t),t},ne=(r,n)=>(i,e)=>n(i,e,r);function Tn(r,n,i,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),s=n.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),a={left:!0,top:!0};if(!s)return{...r,absolute:a};const{left:c,right:u,top:d,bottom:l}=r,m=e.getFreeze(),{startColumn:p,startRow:S,xSplit:f,ySplit:v}=m,y=i.getNoMergeCellPositionByIndexWithNoHeader(S-v,p-f),M=i.getNoMergeCellPositionByIndexWithNoHeader(S,p),{rowHeaderWidth:C,columnHeaderHeight:T}=i,I=M.startX-y.startX,P=M.startY-y.startY,{top:_,left:L,viewportScrollX:R,viewportScrollY:F}=s;let N,A;c<L?(a.left=!0,N=(I+C+(c-L))*t,A=Math.max(Math.min((I+C+(u-L))*t,(I+C)*t),(u-R)*t)):(a.left=!1,N=Math.max((c-R)*t,(I+C)*t),A=Math.max((u-R)*t,(I+C)*t));let D,V;return d<_?(a.top=!0,D=(P+T+(d-_))*o,V=Math.max(Math.min((P+T+(u-_))*o,(P+T)*o),(l-F)*o)):(a.top=!1,D=Math.max((d-F)*o,(P+T)*o),V=Math.max((l-F)*o,(P+T)*o)),{left:N,right:A,top:D,bottom:V,absolute:a}}const Ce=(r,n,i,e)=>{const{scene:t}=n,{left:o,top:s,width:a,height:c,angle:u}=r,d={left:o,right:o+a,top:s,bottom:s+c},l=Tn(d,t,i,e);return{startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:u,width:a,height:c,absolute:l.absolute}};b.SheetCanvasFloatDomManagerService=class extends g.Disposable{constructor(i,e,t,o,s,a,c){super();q(this,"_domLayerMap",new Map);q(this,"_domLayerInfoMap",new Map);q(this,"_transformChange$",new B.Subject);q(this,"transformChange$",this._transformChange$.asObservable());q(this,"_remove$",new B.Subject);q(this,"remove$",this._remove$.asObservable());this._renderManagerService=i,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._selectionRenderService=s,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._drawingAddListener(),this._scrollUpdateListener(),this._featureUpdateListener(),this._deleteListener()}_ensureMap(i,e){let t=this._domLayerMap.get(i);t||(t=new Map,this._domLayerMap.set(i,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}_getSceneAndTransformerByDrawingSearch(i){if(i==null)return;const e=this._renderManagerService.getRenderById(i),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(i=>{i.forEach(e=>{var Ve,Fe;const{unitId:t,subUnitId:o,drawingId:s}=e,a=w.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),u=(Ve=this._renderManagerService.getRenderById(t))==null?void 0:Ve.with(X.SheetSkeletonManagerService).getUnitSkeleton(t,o);if(c==null||a==null||u==null)return;const{transform:d,drawingType:l}=c;if(l!==g.DrawingTypeEnum.DRAWING_DOM)return;const m=this._getSceneAndTransformerByDrawingSearch(t);if(m==null)return;const{scene:p,canvas:S}=m;if(d==null)return!0;const{left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_}=d,L=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),R=p.getObject(L);if(R!=null){R.transformByState({left:f,top:v,width:y,height:M,angle:C,flipX:T,flipY:I,skewX:P,skewY:_});return}const F={left:f,top:v,width:y,height:M,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},N=new U.Rect(L,F);p.addObject(N,U.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(N);const A=this._ensureMap(t,o),D=new g.DisposableCollection,V=Ce(N,m.renderObject,u.skeleton,a.worksheet),K=new B.BehaviorSubject(V),Wn={dispose:D,rect:N,position$:K,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:K,id:s,componentKey:c.componentKey,onPointerDown:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{S.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{S.dispatchEvent(new WheelEvent(Y.type,Y))},props:(Fe=A.get(s))==null?void 0:Fe.props});const Be=N.onTransformChange$.subscribeEvent(()=>{const Y=Ce(N,m.renderObject,u.skeleton,a.worksheet);K.next(Y)});D.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Be&&D.add(Be),this._domLayerInfoMap.set(s,Wn)})}))}_scrollUpdateListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{var t,o;const e=(s,a)=>{var p;const c=this._getSceneAndTransformerByDrawingSearch(s),u=this._ensureMap(s,a),d=Array.from(u.keys()),l=w.getSheetCommandTarget(this._univerInstanceService,{unitId:s,subUnitId:a}),m=(p=this._renderManagerService.getRenderById(s))==null?void 0:p.with(X.SheetSkeletonManagerService).getUnitSkeleton(s,a);!c||!l||!m||d.forEach(S=>{const f=this._domLayerInfoMap.get(S);if(f){const v=Ce(f.rect,c.renderObject,m.skeleton,l.worksheet);f.position$.next(v)}})};if(i.id===X.SetScrollOperation.id){const s=i.params,{unitId:a,sheetId:c}=s;e(a,c)}else if(i.id===X.SetZoomRatioOperation.id){const s=i.params,{unitId:a}=s;Array.from((o=(t=this._domLayerMap.get(a))==null?void 0:t.keys())!=null?o:[]).forEach(u=>{e(a,u)})}else if(i.id===w.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=i.params;e(s,a)}}))}_getPosition(i){const{startX:e,endX:t,startY:o,endY:s}=i,a=this._selectionRenderService.getSelectionCellByPosition(e,o);if(a==null)return;const c={column:a.actualColumn,columnOffset:e-a.startX,row:a.actualRow,rowOffset:o-a.startY},u=this._selectionRenderService.getSelectionCellByPosition(t,s);if(u==null)return;const d={column:u.actualColumn,columnOffset:t-u.startX,row:u.actualRow,rowOffset:s-u.startY};return{from:c,to:d}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(i=>{i.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==g.DrawingTypeEnum.DRAWING_DOM)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(i=>{i.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(i){const e=w.getSheetCommandTarget(this._univerInstanceService,{unitId:i.unitId,subUnitId:i.subUnitId});if(!e)throw new Error("cannot find current target!");const{unitId:t,subUnitId:o}=e,{initPosition:s,componentKey:a}=i,c=g.Tools.generateRandomId(),u=this._getPosition(s);if(u==null)return;this._ensureMap(t,o).set(c,i);const l={unitId:t,subUnitId:o,drawingId:c,drawingType:g.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:t,drawings:[l]}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(i,e=!1){const t=this._domLayerInfoMap.get(i);if(!t)return;const{unitId:o,subUnitId:s}=t;this._domLayerInfoMap.delete(i),t.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(t.rect),e){this._ensureMap(o,s).delete(i);const u=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:i});if(!u)return;const d=this._sheetDrawingService.getBatchRemoveOp([u]),{redo:l,objects:m}=d;this._commandService.syncExecuteCommand(h.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:l,objects:m,type:h.DrawingApplyType.REMOVE})}}},b.SheetCanvasFloatDomManagerService=Mn([ne(0,j.Inject(U.IRenderManagerService)),ne(1,g.IUniverInstanceService),ne(2,j.Inject(g.ICommandService)),ne(3,E.IDrawingManagerService),ne(4,X.ISelectionRenderService),ne(5,j.Inject($.CanvasFloatDomService)),ne(6,h.ISheetDrawingService)],b.SheetCanvasFloatDomManagerService);var Rn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,En=(r,n,i,e)=>{for(var t=e>1?void 0:e?bn(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Rn(n,i,t),t},Se=(r,n)=>(i,e)=>n(i,e,r);let ve=class extends g.Disposable{constructor(r,n,i,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=n,this._drawingManagerService=i,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,n,i)=>{const{unitId:e,scene:t,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{this._drawingRenderService.renderDrawing(a.data[c],t)}),i()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,n,i)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return i(r);const s=o.with(X.SheetSkeletonManagerService).getUnitSkeleton(e,t);if(!s)return i(r);const a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[n.subUnitId];if(!c)return i(r);const{scaleX:u,scaleY:d}=o.scene,l=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(p=>c.data[p]).filter(p=>p.drawingType!==E.DrawingTypeEnum.DRAWING_DOM);return m.length?(m.forEach(p=>{if(!p.groupId&&p.transform&&g.Tools.isDefine(p.transform.left)&&g.Tools.isDefine(p.transform.top)&&g.Tools.isDefine(p.transform.width)&&g.Tools.isDefine(p.transform.height)){const S=s.skeleton.getCellPositionByOffset(p.transform.left,p.transform.top,u,d,{x:0,y:0}),f=s.skeleton.getCellPositionByOffset(p.transform.left+p.transform.width,p.transform.top+p.transform.height,u,d,{x:0,y:0});S.column<l.startColumn&&(l.startColumn=S.column),S.row<l.startRow&&(l.startRow=S.row),l.endRow<f.row&&(l.endRow=f.row),l.endColumn<f.column&&(l.endColumn=f.column)}}),i(l)):i(r)}}))}};ve=En([g.OnLifecycle(g.LifecycleStages.Rendered,ve),Se(0,j.Inject(X.SheetPrintInterceptorService)),Se(1,j.Inject(Q.DrawingRenderService)),Se(2,E.IDrawingManagerService),Se(3,U.IRenderManagerService)],ve);var Pn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(r,n,i,e)=>{for(var t=e>1?void 0:e?On(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&Pn(n,i,t),t},ae=(r,n)=>(i,e)=>n(i,e,r);let we=class extends g.Disposable{constructor(r,n,i,e,t){super(),this._drawingManagerService=r,this._renderManagerService=n,this._permissionService=i,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.removeObject(S)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=n.getUnitId(),c=e.getSheetId(),u=this._drawingManagerService.getDrawingData(a,c),d=Object.values(u),l=this._renderManagerService.getRenderById(a),m=l==null?void 0:l.scene;if(m==null)return;m.getAllObjects().forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&d.some(f=>S.oKey.includes(f.drawingId))&&m.detachTransformerFrom(S)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingVisible(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?this._drawingManagerService.addNotification(f):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.removeObject(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetViewPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const m=this._drawingManagerService.getDrawingData(t,o),p=Object.values(m);this._drawingManagerService.addNotification(p)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(g.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(B.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([n,i])=>{n&&n.activeSheet$.subscribe(e=>{var l;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),c=a==null?void 0:a.scene;if(c==null)return;const u=c.getTransformerByCreate(),d=this._permissionService.composePermission$([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).pipe(B.map(m=>m.every(p=>p.value)));d==null||d.pipe(B.filter(m=>m!==s),B.distinctUntilChanged()).subscribe({next:m=>{s=m,this._drawingManagerService.setDrawingEditable(m);const p=c.getAllObjects(),S=this._drawingManagerService.getDrawingData(t,o),f=Object.values(S);m?(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.attachTransformerTo(v)}),this._drawingManagerService.addNotification(f)):(p.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(y=>v.oKey.includes(y.drawingId))&&c.detachTransformerFrom(v)}),u.clearSelectedObjects())}}),(l=this._permissionService.getPermissionPoint$(new w.WorksheetEditPermission(t,o).id))==null||l.pipe(B.filter(m=>m.value!==s),B.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const m=n.getUnitId(),p=e.getSheetId(),S=this._drawingManagerService.getDrawingData(m,p),f=Object.values(S),v=this._renderManagerService.getRenderById(m),y=v==null?void 0:v.scene;if(y==null)return;this._drawingManagerService.setDrawingEditable(!0),y.getAllObjects().forEach(C=>{C.classType===U.RENDER_CLASS_TYPE.IMAGE&&f.some(T=>C.oKey.includes(T.drawingId))&&y.detachTransformerFrom(C)})}})})}))}};we=An([g.OnLifecycle(g.LifecycleStages.Rendered,we),ae(0,E.IDrawingManagerService),ae(1,U.IRenderManagerService),ae(2,g.IPermissionService),ae(3,g.IUniverInstanceService),ae(4,j.Inject(g.UserManagerService))],we);var We=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Nn=(r,n,i)=>n in r?We(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i,Ln=(r,n,i,e)=>{for(var t=e>1?void 0:e?Un(n,i):n,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(e?s(n,i,t):s(t))||t);return e&&t&&We(n,i,t),t},Ge=(r,n)=>(i,e)=>n(i,e,r),$e=(r,n,i)=>Nn(r,typeof n!="symbol"?n+"":n,i);const jn="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends g.Plugin{constructor(i={},e,t){super();q(this,"_pluginConfig");this._injector=e,this._localeService=t,this._pluginConfig=g.Tools.deepMerge({},Sn,i)}onStarting(i){super.onStarting(i),this._initDependencies(i)}_initDependencies(i){[[b.SheetCanvasFloatDomManagerService],[se,{useFactory:()=>this._injector.createInstance(se,this._pluginConfig)}],[ge],[de],[fe],[ve],[we]].forEach(t=>i.add(t))}},$e(b.UniverSheetsDrawingUIPlugin,"type",g.UniverInstanceType.UNIVER_SHEET),$e(b.UniverSheetsDrawingUIPlugin,"pluginName",jn),b.UniverSheetsDrawingUIPlugin=Ln([g.DependentOn(E.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,h.UniverSheetsDrawingPlugin),Ge(1,j.Inject(j.Injector)),Ge(2,j.Inject(g.LocaleService))],b.UniverSheetsDrawingUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -52,15 +52,15 @@
|
|
|
52
52
|
"clsx": ">=2.0.0",
|
|
53
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
54
54
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/design": "0.1.
|
|
57
|
-
"@univerjs/drawing": "0.1.
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/sheets-
|
|
62
|
-
"@univerjs/ui": "0.1.
|
|
63
|
-
"@univerjs/
|
|
55
|
+
"@univerjs/drawing": "0.1.17",
|
|
56
|
+
"@univerjs/design": "0.1.17",
|
|
57
|
+
"@univerjs/drawing-ui": "0.1.17",
|
|
58
|
+
"@univerjs/sheets": "0.1.17",
|
|
59
|
+
"@univerjs/core": "0.1.17",
|
|
60
|
+
"@univerjs/engine-render": "0.1.17",
|
|
61
|
+
"@univerjs/sheets-drawing": "0.1.17",
|
|
62
|
+
"@univerjs/sheets-ui": "0.1.17",
|
|
63
|
+
"@univerjs/ui": "0.1.17"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@univerjs/icons": "^0.1.57"
|
|
@@ -74,16 +74,16 @@
|
|
|
74
74
|
"typescript": "^5.4.5",
|
|
75
75
|
"vite": "^5.3.1",
|
|
76
76
|
"vitest": "^1.6.0",
|
|
77
|
-
"@univerjs/core": "0.1.
|
|
78
|
-
"@univerjs/
|
|
79
|
-
"@univerjs/
|
|
80
|
-
"@univerjs/
|
|
81
|
-
"@univerjs/
|
|
82
|
-
"@univerjs/
|
|
83
|
-
"@univerjs/
|
|
84
|
-
"@univerjs/sheets-drawing": "0.1.
|
|
85
|
-
"@univerjs/sheets-ui": "0.1.
|
|
86
|
-
"@univerjs/ui": "0.1.
|
|
77
|
+
"@univerjs/core": "0.1.17",
|
|
78
|
+
"@univerjs/drawing": "0.1.17",
|
|
79
|
+
"@univerjs/design": "0.1.17",
|
|
80
|
+
"@univerjs/drawing-ui": "0.1.17",
|
|
81
|
+
"@univerjs/engine-render": "0.1.17",
|
|
82
|
+
"@univerjs/shared": "0.1.17",
|
|
83
|
+
"@univerjs/sheets": "0.1.17",
|
|
84
|
+
"@univerjs/sheets-drawing": "0.1.17",
|
|
85
|
+
"@univerjs/sheets-ui": "0.1.17",
|
|
86
|
+
"@univerjs/ui": "0.1.17"
|
|
87
87
|
},
|
|
88
88
|
"univerSpace": {
|
|
89
89
|
".": {
|