@univerjs/sheets-drawing-ui 0.6.10-nightly.202504141607 → 0.6.10-nightly.202504151606
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 +2 -2
- package/lib/index.js +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Vt=Object.defineProperty;var Xt=(i,r,t)=>r in i?Vt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var Q=(i,r,t)=>Xt(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),Nt=require("@univerjs/docs-drawing"),A=require("@univerjs/drawing"),fe=require("@univerjs/drawing-ui"),j=require("@univerjs/engine-render"),m=require("@univerjs/sheets-drawing"),b=require("@univerjs/sheets-ui"),x=require("@univerjs/ui"),P=require("rxjs"),D=require("@univerjs/sheets"),V=require("react/jsx-runtime"),ie=require("react"),nt=require("@univerjs/docs-ui"),q=require("@univerjs/design"),Kt="sheets-drawing-ui.config",Ut={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(j.IRenderManagerService);return r.forEach(e=>{var n,s;(s=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||s.debounceRefreshControls()}),!0}},Te={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(D.SheetInterceptorService),s=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(C=>{const{unitId:R}=C;a.push(R)});const d=s.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:Te.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},jt="COMPONENT_SHEET_DRAWING_PANEL",St={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(x.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),s=i.get(l.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:jt},onClose:()=>{s.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},_t={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[r]),t.executeCommand(St.id,{value:"open"}),!0)}},zt="univer-upload-loading",Zt="univer-upload-loading-body",qt="univer-upload-loading-body-animation",Jt="univer-upload-loading-body-text",Ze={uploadLoading:zt,uploadLoadingBody:Zt,uploadLoadingBodyAnimation:qt,uploadLoadingBodyText:Jt},Qt=()=>{const i=x.useDependency(A.IImageIoService),r=x.useDependency(l.LocaleService),[t,e]=ie.useState(0);return ie.useEffect(()=>{const n=i.change$.subscribe(s=>{e(s)});return()=>{n.unsubscribe()}},[i]),V.jsx("div",{style:{display:t>0?"block":"none"},className:Ze.uploadLoading,children:V.jsxs("div",{className:Ze.uploadLoadingBody,children:[V.jsx("div",{className:Ze.uploadLoadingBodyAnimation}),V.jsx("div",{className:Ze.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);let rt=class extends l.RxDisposable{constructor(r,t,e,n,s,o,a,d){super();Q(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=s,this._contextService=o,this._uiPartsService=a,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(x.BuiltInUIPart.CONTENT,()=>x.connectInjector(Qt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof fe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var s;const t=(s=this._renderManagerService.getRenderById(r))==null?void 0:s.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const o=e.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:fe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:_t.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Te.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:fe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:fe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};rt=tn([he(0,l.Inject(l.Injector)),he(1,A.IDrawingManagerService),he(2,l.Inject(b.SheetCanvasPopManagerService)),he(3,j.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject(x.IUIPartsService)),he(7,l.ICommandService)],rt);var nn=Object.getOwnPropertyDescriptor,rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?nn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},qe=(i,r)=>(t,e)=>r(t,e,i);let pt=class extends l.Disposable{constructor(r,t,e,n,s){super();Q(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=s,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(P.throttleTime(33)).subscribe(r=>{var e,n;const t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections();(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(j.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};pt=rn([qe(1,l.Inject(b.HoverManagerService)),qe(2,l.Inject(D.SheetsSelectionsService)),qe(3,l.Inject(fe.DrawingRenderService)),qe(4,l.Inject(b.SheetSkeletonManagerService))],pt);function K(i,r,t){const{from:e,to:n,flipY:s=!1,flipX:o=!1,angle:a=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,I=S.columnHeaderHeight+S.rowTotalHeight;return p+f>_&&(p=_-f),h+w>I&&(h=I-w),{flipY:s,flipX:o,angle:a,skewX:d,skewY:g,left:p,top:h,width:f,height:w}}function F(i,r){const{left:t=0,top:e=0,width:n=0,height:s=0,flipY:o=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:j.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:j.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+s);if(h==null)return;const f={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+s-h.startY,1)};return{flipY:o,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:f}}var sn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?sn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Je=(i,r)=>(t,e)=>r(t,e,i);let mt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};mt=on([Je(1,m.ISheetDrawingService),Je(2,A.IDrawingManagerService),Je(3,l.Inject(b.ISheetSelectionRenderService)),Je(4,l.Inject(b.SheetSkeletonManagerService))],mt);function an(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a}=e,d=j.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function cn(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=j.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const vt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:cn(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}]}),!0):!1}},ke={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),s=i.get(D.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(C=>C.unitId),d=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=s.onCommandExecute({id:ke.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},S={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},It={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:s,subUnitId:o,drawingIds:a,arrangeType:d}=r,g={unitId:s,subUnitId:o,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},We={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,o=n.getBatchUpdateOp(s),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},Dt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:an(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}]}),!0):!1}};var dn=Object.getOwnPropertyDescriptor,ln=(i,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ne=(i,r)=>(t,e)=>r(t,e,i);function un(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),s=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:s}}function ft(i,r,t,e,n){var I;const{rotatedHeight:s,rotatedWidth:o}=un(t,e,n),d=i.get(j.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(I=d.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=o/s,S=Math.ceil(Math.min(p,h*f))/o,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,s,o,a,d,g,u,c,p,h,f){super();Q(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=s,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:s,subUnitId:o}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await A.getImageSize(u||""),{width:f,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>A.DRAWING_IMAGE_WIDTH_LIMIT||p>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/c,T=A.DRAWING_IMAGE_HEIGHT_LIMIT/p;S=Math.max(M,T)}const _=this._getImagePosition(c*S,p*S,f,w);if(_==null)return;const I={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(ke.id,{unitId:s,drawings:[I]})}async _insertCellImage(t,e){var I,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const C=T.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:s,imageSourceType:o,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await A.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,o,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const w={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},S={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:nt.docDrawingPositionToTransform(w),docTransform:w,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[S],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(I=e==null?void 0:e.row)!=null?I:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:s,image:o}=await A.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,o);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,s,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:nt.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:a.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),s=e.getSheetId();return{unitId:n,subUnitId:s}}_getImagePosition(t,e,n,s){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const d=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>s&&(p=s-e,p<0&&(p=0,e=s),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:p+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o}=t;this._commandService.executeCommand(It.id,{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:s,subUnitId:o,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=F({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(We.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(vt.id,t);const{unitId:e,subUnitId:n,drawingId:s}=t[0].parent;this._commandService.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:s}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(Dt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};exports.SheetDrawingUpdateController=ln([ne(1,l.Inject(b.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,b.ISheetSelectionRenderService),ne(4,A.IImageIoService),ne(5,x.ILocalFileService),ne(6,m.ISheetDrawingService),ne(7,A.IDrawingManagerService),ne(8,l.IContextService),ne(9,x.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(D.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);var gn=Object.getOwnPropertyDescriptor,hn=(i,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);function kt(i,r,t){var e,n,s,o;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((o=(s=t.p)==null?void 0:s.drawingsOrder)==null?void 0:o.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=ft(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let it=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=s,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===nt.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},kt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};it=hn([ye(0,l.ICommandService),ye(1,l.Inject(D.SheetInterceptorService)),ye(2,l.Inject(l.Injector)),ye(3,A.IDrawingManagerService),ye(4,l.Inject(Nt.DocDrawingController)),ye(5,l.Inject(b.IEditorBridgeService))],it);var pn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Pt=(i,r)=>(t,e)=>r(t,e,i);let st=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,s,o)=>{kt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:s},o)})}}))}};st=mn([Pt(0,l.Inject(b.IAutoFillService)),Pt(1,l.Inject(l.Injector))],st);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Pe=(i,r)=>(t,e)=>r(t,e,i);const Sn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ot=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),t=(n=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===nt.InnerPasteCommand.id){const e=i.params,{doc:n}=e,s=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(s==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=s.getUnitId();if(Sn.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=s.getBody())==null?void 0:t.dataStream)===`\r
|
|
1
|
+
"use strict";var Vt=Object.defineProperty;var Xt=(i,r,t)=>r in i?Vt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var Q=(i,r,t)=>Xt(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),Nt=require("@univerjs/docs-drawing"),A=require("@univerjs/drawing"),fe=require("@univerjs/drawing-ui"),j=require("@univerjs/engine-render"),m=require("@univerjs/sheets-drawing"),b=require("@univerjs/sheets-ui"),x=require("@univerjs/ui"),P=require("rxjs"),D=require("@univerjs/sheets"),V=require("react/jsx-runtime"),ie=require("react"),nt=require("@univerjs/docs-ui"),q=require("@univerjs/design"),Kt="sheets-drawing-ui.config",Ut={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(j.IRenderManagerService);return r.forEach(e=>{var n,s;(s=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||s.debounceRefreshControls()}),!0}},Te={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(D.SheetInterceptorService),s=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(C=>{const{unitId:R}=C;a.push(R)});const d=s.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:Te.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},jt="COMPONENT_SHEET_DRAWING_PANEL",St={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(x.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),s=i.get(l.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:jt},onClose:()=>{s.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},_t={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[r]),t.executeCommand(St.id,{value:"open"}),!0)}},zt="univer-upload-loading",Zt="univer-upload-loading-body",qt="univer-upload-loading-body-animation",Jt="univer-upload-loading-body-text",Ze={uploadLoading:zt,uploadLoadingBody:Zt,uploadLoadingBodyAnimation:qt,uploadLoadingBodyText:Jt},Qt=()=>{const i=x.useDependency(A.IImageIoService),r=x.useDependency(l.LocaleService),[t,e]=ie.useState(0);return ie.useEffect(()=>{const n=i.change$.subscribe(s=>{e(s)});return()=>{n.unsubscribe()}},[i]),V.jsx("div",{style:{display:t>0?"block":"none"},className:Ze.uploadLoading,children:V.jsxs("div",{className:Ze.uploadLoadingBody,children:[V.jsx("div",{className:Ze.uploadLoadingBodyAnimation}),V.jsx("div",{className:Ze.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},he=(i,r)=>(t,e)=>r(t,e,i);let rt=class extends l.RxDisposable{constructor(r,t,e,n,s,o,a,d){super();Q(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=s,this._contextService=o,this._uiPartsService=a,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(x.BuiltInUIPart.CONTENT,()=>x.connectInjector(Qt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof fe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var s;const t=(s=this._renderManagerService.getRenderById(r))==null?void 0:s.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const o=e.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:fe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:_t.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Te.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:fe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:fe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};rt=tn([he(0,l.Inject(l.Injector)),he(1,A.IDrawingManagerService),he(2,l.Inject(b.SheetCanvasPopManagerService)),he(3,j.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject(x.IUIPartsService)),he(7,l.ICommandService)],rt);var nn=Object.getOwnPropertyDescriptor,rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?nn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},qe=(i,r)=>(t,e)=>r(t,e,i);let pt=class extends l.Disposable{constructor(r,t,e,n,s){super();Q(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=s,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(P.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(j.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};pt=rn([qe(1,l.Inject(b.HoverManagerService)),qe(2,l.Inject(D.SheetsSelectionsService)),qe(3,l.Inject(fe.DrawingRenderService)),qe(4,l.Inject(b.SheetSkeletonManagerService))],pt);function K(i,r,t){const{from:e,to:n,flipY:s=!1,flipX:o=!1,angle:a=0,skewX:d=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const c=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,I=S.columnHeaderHeight+S.rowTotalHeight;return p+f>_&&(p=_-f),h+w>I&&(h=I-w),{flipY:s,flipX:o,angle:a,skewX:d,skewY:g,left:p,top:h,width:f,height:w}}function F(i,r){const{left:t=0,top:e=0,width:n=0,height:s=0,flipY:o=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:j.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:j.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+s);if(h==null)return;const f={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+s-h.startY,1)};return{flipY:o,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:f}}var sn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?sn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Je=(i,r)=>(t,e)=>r(t,e,i);let mt=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};mt=on([Je(1,m.ISheetDrawingService),Je(2,A.IDrawingManagerService),Je(3,l.Inject(b.ISheetSelectionRenderService)),Je(4,l.Inject(b.SheetSkeletonManagerService))],mt);function an(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a}=e,d=j.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function cn(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:s,subUnitId:o,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=j.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const vt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:cn(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}]}),!0):!1}},ke={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,M,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService),s=i.get(D.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(C=>C.unitId),d=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=s.onCommandExecute({id:ke.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},S={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},It={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:s,subUnitId:o,drawingIds:a,arrangeType:d}=r,g={unitId:s,subUnitId:o,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:s,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},We={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,o=n.getBatchUpdateOp(s),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},Dt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:f})=>{s.push(h.unitId),f.forEach(w=>{s.push(w.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:an(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:s}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:s}]}),!0):!1}};var dn=Object.getOwnPropertyDescriptor,ln=(i,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ne=(i,r)=>(t,e)=>r(t,e,i);function un(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),s=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:s}}function ft(i,r,t,e,n){var I;const{rotatedHeight:s,rotatedWidth:o}=un(t,e,n),d=i.get(j.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(I=d.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=o/s,S=Math.ceil(Math.min(p,h*f))/o,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,s,o,a,d,g,u,c,p,h,f){super();Q(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=s,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:s,subUnitId:o}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await A.getImageSize(u||""),{width:f,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>A.DRAWING_IMAGE_WIDTH_LIMIT||p>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/c,T=A.DRAWING_IMAGE_HEIGHT_LIMIT/p;S=Math.max(M,T)}const _=this._getImagePosition(c*S,p*S,f,w);if(_==null)return;const I={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(ke.id,{unitId:s,drawings:[I]})}async _insertCellImage(t,e){var I,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const C=T.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:s,imageSourceType:o,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await A.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,o,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=l.createDocumentModelWithStyle("",{}),f=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const w={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},S={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:nt.docDrawingPositionToTransform(w),docTransform:w,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=l.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[S],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(I=e==null?void 0:e.row)!=null?I:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:s,image:o}=await A.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,o);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=ft(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,s,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:nt.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:a.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),s=e.getSheetId();return{unitId:n,subUnitId:s}}_getImagePosition(t,e,n,s){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const d=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>s&&(p=s-e,p<0&&(p=0,e=s),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:p+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o}=t;this._commandService.executeCommand(It.id,{unitId:e,subUnitId:n,drawingIds:s,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:s,subUnitId:o,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=F({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(We.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(vt.id,t);const{unitId:e,subUnitId:n,drawingId:s}=t[0].parent;this._commandService.syncExecuteCommand(A.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:s}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(Dt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};exports.SheetDrawingUpdateController=ln([ne(1,l.Inject(b.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,b.ISheetSelectionRenderService),ne(4,A.IImageIoService),ne(5,x.ILocalFileService),ne(6,m.ISheetDrawingService),ne(7,A.IDrawingManagerService),ne(8,l.IContextService),ne(9,x.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(D.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);var gn=Object.getOwnPropertyDescriptor,hn=(i,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);function kt(i,r,t){var e,n,s,o;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((o=(s=t.p)==null?void 0:s.drawingsOrder)==null?void 0:o.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=ft(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let it=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=s,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===nt.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},kt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};it=hn([ye(0,l.ICommandService),ye(1,l.Inject(D.SheetInterceptorService)),ye(2,l.Inject(l.Injector)),ye(3,A.IDrawingManagerService),ye(4,l.Inject(Nt.DocDrawingController)),ye(5,l.Inject(b.IEditorBridgeService))],it);var pn=Object.getOwnPropertyDescriptor,mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Pt=(i,r)=>(t,e)=>r(t,e,i);let st=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,s,o)=>{kt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:s},o)})}}))}};st=mn([Pt(0,l.Inject(b.IAutoFillService)),Pt(1,l.Inject(l.Injector))],st);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Pe=(i,r)=>(t,e)=>r(t,e,i);const Sn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ot=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),t=(n=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===nt.InnerPasteCommand.id){const e=i.params,{doc:n}=e,s=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(s==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=s.getUnitId();if(Sn.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=s.getBody())==null?void 0:t.dataStream)===`\r
|
|
2
2
|
`?(this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};ot=wn([Pe(0,l.ICommandService),Pe(1,l.IUniverInstanceService),Pe(2,x.IDialogService),Pe(3,j.IRenderManagerService),Pe(4,l.Inject(l.LocaleService))],ot);const Be={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var o,a;const t=i.get(l.IUniverInstanceService),e=i.get(j.IRenderManagerService),n=(o=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:o.with(exports.SheetDrawingUpdateController);if(!n)return!1;const s=r==null?void 0:r.files;if(s){const d=s.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},Ct={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(l.IUniverInstanceService),t=i.get(j.IRenderManagerService);return(n=(e=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var _n=Object.getOwnPropertyDescriptor,vn=(i,r,t,e)=>{for(var n=e>1?void 0:e?_n(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const Wt="image/png";function In(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);return new Blob([n],{type:Wt})}function Dn(i){const r=new ClipboardItem({[Wt]:In(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function Cn(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const At=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let at=class extends l.Disposable{constructor(r,t,e,n,s){super();Q(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=s,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const s=this._focusedDrawings;if(s.length>0){const[o]=s;if(n===b.COPY_TYPE.CUT){const d={unitId:r,drawings:[o]};this._commandService.executeCommand(Te.id,d)}setTimeout(()=>{const d=Cn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===A.ImageSourceType.BASE64?Dn(o.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=o}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:s=b.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:s}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:o},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Be.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(b.SheetSkeletonManagerService);if(!n)return;const s=n.attachRangeWithCoord(e);if(!s)return;const{startX:o,endX:a,startY:d,endY:g}=s,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:w}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:_=0,width:I=0,height:M=0}=w,{drawingStartX:T,drawingEndX:C,drawingStartY:R,drawingEndY:v}={drawingStartX:S,drawingEndX:S+I,drawingStartY:_,drawingEndY:_+M};o<=T&&C<=a&&d<=R&&v<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(At.includes(e))return{redos:[],undos:[]};const{unitId:s,subUnitId:o,range:a}=n,d=this._renderManagerService.getRenderById(s),g=d==null?void 0:d.with(b.SheetSkeletonManagerService),u=d==null?void 0:d.with(b.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=b.discreteRangeToRange(a);return this._generateMutations(p,{unitId:s,subUnitId:o,isCut:t===b.COPY_TYPE.CUT,getTransform:(f,w)=>{var I;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:_,sheetTransform:(I=F(_,u))!=null?I:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:s,isCut:o}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=s(c,p),f={...u,unitId:e,subUnitId:n,drawingId:o?u.drawingId:l.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(o){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var N;const{unitId:e,subUnitId:n,pasteType:s,pasteRange:o}=r,{copyRange:a,copyType:d}=t;if(At.includes(s))return{redos:[],undos:[]};const g=(N=this._renderManagerService.getRenderById(e))==null?void 0:N.with(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(o)},pasteType:s},d);const{ranges:[c,p],mapFunc:h}=b.virtualizeDiscreteRanges([a,o]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:w,endColumn:w}),M=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:_,endColumn:_});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const T=M.startX-I.startX,C=M.startY-I.startY,R=S-f,v=_-w;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(E,k)=>{var U,O;return{transform:{...E,left:((U=E==null?void 0:E.left)!=null?U:0)+T,top:((O=E==null?void 0:E.top)!=null?O:0)+C},sheetTransform:{...k,to:{...k.to,row:k.to.row+R,column:k.to.column+v},from:{...k.from,row:k.from.row+R,column:k.from.column+v}}}},isCut:d===b.COPY_TYPE.CUT})}};at=vn([Ae(0,b.ISheetClipboardService),Ae(1,j.IRenderManagerService),Ae(2,A.IDrawingManagerService),Ae(3,x.IClipboardInterfaceService),Ae(4,l.ICommandService)],at);var yn=Object.getOwnPropertyDescriptor,Mn=(i,r,t,e)=>{for(var n=e>1?void 0:e?yn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ne=(i,r)=>(t,e)=>r(t,e,i);let ct=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.tap(s=>{if(!s){this._drawingManagerService.setDrawingVisible(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(o).id,new D.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,s)})):(this._drawingManagerService.setDrawingVisible(!1),P.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=P.combineLatest([i,r]);this.disposeWithMe(t.pipe(P.switchMap(([e,n])=>e?e.activeSheet$.pipe(P.tap(s=>{if(!s){this._drawingManagerService.setDrawingEditable(!1);return}const o=e.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(o).id,new D.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,s)})):(this._drawingManagerService.setDrawingEditable(!1),P.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),s=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return P.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,o).id]).pipe(P.map(c=>c.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):P.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),s=e==null?void 0:e.getSheetId();if(!n||!s)return;const o=this._drawingManagerService.getDrawingData(n,s),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(P.combineLatest([i,r]).pipe(P.switchMap(([t,e])=>t?t.activeSheet$.pipe(P.switchMap(n=>{if(!n)return P.EMPTY;const s=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),d=a==null?void 0:a.scene;if(!d)return P.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,o).id]).pipe(P.map(c=>c.every(p=>p.value)),P.distinctUntilChanged()).pipe(P.map(c=>({permission:c,scene:d,transformer:g,unitId:s,subUnitId:o})))})):P.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(s,o),g=Object.values(d);t?(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const s=n.getSheetId(),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,s),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};ct=Mn([Ne(0,A.IDrawingManagerService),Ne(1,j.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],ct);var Tn=Object.getOwnPropertyDescriptor,Rn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Tn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Qe=(i,r)=>(t,e)=>r(t,e,i);let dt=class extends l.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:s}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[s];return a&&a.order.forEach(d=>{this._drawingRenderService.renderDrawing(a.data[d],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,s=this._renderManagerService.getRenderById(e);if(!s)return t(i);const o=s.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return t(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(i);const{scaleX:g,scaleY:u}=s.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<w.row&&(c.endRow=w.row),c.endColumn<w.column&&(c.endColumn=w.column)}}),t(c)):t(i)}}))}};dt=Rn([Qe(0,l.Inject(b.SheetPrintInterceptorService)),Qe(1,l.Inject(fe.DrawingRenderService)),Qe(2,A.IDrawingManagerService),Qe(3,j.IRenderManagerService)],dt);var bn=Object.getOwnPropertyDescriptor,En=(i,r,t,e)=>{for(var n=e>1?void 0:e?bn(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},pe=(i,r)=>(t,e)=>r(t,e,i);const On=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],Un=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let wt=class extends l.Disposable{constructor(i,r,t,e,n,s,o,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=s,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!On.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForRowVisible(e,n,s)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t;return this._getDrawingUndoForColVisible(e,n,s)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:s}=t,o=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,s,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,s=[],o=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return s.push({id:G.id,params:[e]}),o.push({id:G.id,params:[e]}),{redos:s,undos:o}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:s,anchorType:o=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=s,{row:h,column:f}=c,{row:w,column:S}=p;if(s==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:M,endColumn:T}=i;let C=null,R=null;if(r===0&&h>=_&&w<=I)if(f>=M&&S<=T)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(s,a,M,T,o);C=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===1&&f>=M&&S<=T)if(h>=_&&w<=I)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(s,a,_,I,o);C=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(s,a,_,I,o);C=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(s,a,M,T,o);C=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}if(C!=null&&R!=null){const v=K(C,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:C,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:M,column:T}=S;for(let C=0;C<t.length;C++){const R=t[C],{startRow:v,endRow:N,startColumn:E,endColumn:k}=R;if(T<E)continue;if(f===m.SheetDrawingAnchorType.Position){let y=null,B=null;if(I>=E&&I<=k){const W=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:w.row,endRow:S.row});if(W==null)return;B={...h,left:W.startX}}if(B!=null&&(y=F(B,this._selectionRenderService),y!=null&&B!=null)){n.push({...c,sheetTransform:y,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(I>=E&&T<=k)continue;let U=null,O=null;if(I>=E&&I<=k){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:w.row,endRow:S.row});if(y==null)return;O={...h,left:(y==null?void 0:y.startX)||0,width:((h==null?void 0:h.width)||0)-y.endX+y.startX}}else if(T>=E&&T<=k){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:w.row,endRow:S.row});if(y==null)return;O={...h,left:y.startX-((h==null?void 0:h.width)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:k,startRow:w.row,endRow:S.row});if(y==null)return;if(O={...h,width:((h==null?void 0:h.width)||0)-y.endX+y.startX},U=F(O,this._selectionRenderService),U!=null&&O!=null){s.push({...c,sheetTransform:U,transform:O});break}}if(O!=null&&(U=F(O,this._selectionRenderService)),O!=null&&U!=null){n.push({...c,sheetTransform:U,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:s,objects:o}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:s,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:M,column:T}=S;for(let C=0;C<t.length;C++){const R=t[C],{startRow:v,endRow:N,startColumn:E,endColumn:k}=R;if(M<v)continue;if(f===m.SheetDrawingAnchorType.Position){let y=null,B=null;if(_>=v&&_<=N){const W=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:N});if(W==null)return;B={...h,top:W.startY}}if(B!=null&&(y=F(B,this._selectionRenderService),y!=null&&B!=null)){n.push({...c,sheetTransform:y,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(_>=v&&M<=N)continue;let U=null,O=null;if(_>=v&&_<=N){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:N});if(y==null)return;O={...h,top:(y==null?void 0:y.startY)||0,height:((h==null?void 0:h.height)||0)-y.endY+y.startY}}else if(M>=v&&M<=N){const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:M});if(y==null)return;O={...h,top:y.startY-((h==null?void 0:h.height)||0)}}else{const y=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:N});if(y==null)return;if(O={...h,height:((h==null?void 0:h.height)||0)-y.endY+y.startY},U=F(O,this._selectionRenderService),U!=null&&O!=null){s.push({...c,sheetTransform:U,transform:O});break}}if(O!=null&&(U=F(O,this._selectionRenderService)),O!=null&&U!=null){n.push({...c,sheetTransform:U,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],g=[];if(s.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,s);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),s=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,s,a);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:w,column:S}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:M,endRow:T,startColumn:C,endColumn:R}=I;if(w<M||S<C)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=M&&w>=T||f<=C&&S>=R)){this._remainDrawingSize(g,s,a);continue}const v=K({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){s.push({...a,transform:v});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,s)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var M,T;const{toRange:r,fromRange:t}=i,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:s}=e,o=(T=(M=this._renderManagerService.getRenderById(n))==null?void 0:M.with(b.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=b.attachRangeWithCoord(o,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,s),h=[];Object.keys(p).forEach(C=>{const R=p[C];if(R.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=R;if(!v)return;const{left:N=0,top:E=0,width:k=0,height:U=0}=v,{drawingStartX:O,drawingEndX:y,drawingStartY:B,drawingEndY:W}={drawingStartX:N,drawingEndX:N+k,drawingStartY:E,drawingEndY:E+U};d<=O&&y<=g&&u<=B&&W<=c&&h.push(R)});const f=[],w=[],S=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(C=>{const R=C.sheetTransform,v={to:{...R.to,row:R.to.row+S,column:R.to.column+_},from:{...R.from,row:R.from.row+S,column:R.from.column+_}},N=K(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:s,drawingId:C.drawingId,transform:N,sheetTransform:v}});if(I.length){const C=this._sheetDrawingService.getBatchUpdateOp(I),{undo:R,redo:v,objects:N}=C;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:v,objects:N,type:m.DrawingApplyType.UPDATE}}),w.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:R,objects:N,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startRow,a=s.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,M;if(r==="insert"){const C=this._expandRow(w,S,o,a,_);I=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:R}=w,{row:v}=C,{row:N}=R;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&N<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkRow(w,S,o,a,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:I};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:s}=i,o=s.startColumn,a=s.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,M;if(r==="insert"){const C=this._expandCol(w,S,o,a,_);I=C==null?void 0:C.newSheetTransform,M=C==null?void 0:C.newTransform}else{const{from:C,to:R}=w,{column:v}=C,{column:N}=R;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&N<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const E=this._shrinkCol(w,S,o,a,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:I};c.push(T)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,column:d-s},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:o.row,endRow:a.row});if(p==null)return;u={from:{...o},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=F(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const s=e-t+1,{from:o,to:a}=i,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,row:d-s},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-s}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=F(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...o},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(s=>{const o=n[s].data;o!=null&&Object.keys(o).forEach(a=>{e===i&&t.push(o[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(s=>{const o=t[s];o!=null&&Object.keys(o).forEach(a=>{const d=o[a].data;d!=null&&Object.keys(d).forEach(g=>{if(s===i&&a===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Un.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(s=>{const o=e[s],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=o;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:f,column:w}=c;for(let S=0;S<t.length;S++){const _=t[S],{startRow:I,endRow:M,startColumn:T,endColumn:C}=_;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:T,endColumn:C},{startRow:p,endRow:f,startColumn:h,endColumn:w})||p>M||h>C){const R=g===m.SheetDrawingAnchorType.Position,v=K(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...v,width:R?d==null?void 0:d.width:v==null?void 0:v.width,height:R?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};wt=En([pe(1,j.IRenderManagerService),pe(2,l.ICommandService),pe(3,b.ISheetSelectionRenderService),pe(4,l.Inject(b.SheetSkeletonManagerService)),pe(5,l.Inject(D.SheetInterceptorService)),pe(6,m.ISheetDrawingService),pe(7,A.IDrawingManagerService),pe(8,l.IUniverInstanceService)],wt);var re=function(){return re=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},re.apply(this,arguments)},Pn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},Bt=ie.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,s=i.extend,o=Pn(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=ie.useRef("_".concat(jn()));return xt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},re({ref:r,className:a},o),s)});function xt(i,r,t,e,n){return ie.createElement(i.tag,re(re({key:r},An(i,t,n)),e),(Nn(i,t).children||[]).map(function(s,o){return xt(s,"".concat(r,"-").concat(i.tag,"-").concat(o),t,void 0,n)}))}function An(i,r,t){var e=re({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(s){var o=s[0],a=s[1];o==="mask"&&typeof a=="string"&&(e[o]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(s){var o=s[0],a=s[1];typeof a=="string"&&(e[o]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Nn(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?re(re({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?re(re({},n),{attrs:re(re({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function jn(){return Math.random().toString(36).substring(2,8)}Bt.displayName="UniverIcon";var kn={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"}}]},Lt=ie.forwardRef(function(i,r){return ie.createElement(Bt,Object.assign({},i,{id:"add-image-single",ref:r,icon:kn}))});Lt.displayName="AddImageSingle";const yt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,s=e.map(o=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=o;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(Te.id,{unitId:n,drawings:s})}},Re={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(b.ISheetSelectionRenderService),{direction:s}=r,o=e.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,d=o.map(u=>{const{transform:c}=u;if(c==null)return null;const p={...c},{left:h=0,top:f=0}=c;return s===l.Direction.UP?p.top=f-1:s===l.Direction.DOWN?p.top=f+1:s===l.Direction.LEFT?p.left=h-1:s===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:F(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(We.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Yt="addition-and-subtraction-single",Mt="sheet.menu.image";function Wn(i){return{id:Mt,type:x.MenuItemType.SUBITEMS,icon:Yt,tooltip:"sheetImage.title",hidden$:x.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function Bn(i){return{id:Be.id,title:"sheetImage.upload.float",type:x.MenuItemType.BUTTON,hidden$:x.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function xn(i){return{id:Ct.id,title:"sheetImage.upload.cell",type:x.MenuItemType.BUTTON,hidden$:x.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}const Ln="univer-image-common-panel",Yn="univer-image-common-panel-grid",$n="univer-image-common-panel-border",Fn="univer-image-common-panel-title",Gn="univer-image-common-panel-row",Hn="univer-image-common-panel-column",me={imageCommonPanel:Ln,imageCommonPanelGrid:Yn,imageCommonPanelBorder:$n,imageCommonPanelTitle:Fn,imageCommonPanelRow:Gn,imageCommonPanelColumn:Hn},Vn=i=>{var M;const r=x.useDependency(l.ICommandService),t=x.useDependency(l.LocaleService),e=x.useDependency(A.IDrawingManagerService),n=x.useDependency(j.IRenderManagerService),{drawings:s}=i,o=s[0];if(o==null)return;const{unitId:a}=o,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=ie.useState(!0),h=(M=o.anchorType)!=null?M:m.SheetDrawingAnchorType.Position,[f,w]=ie.useState(h);function S(T,C){const R=[];return T.forEach(v=>{const{oKey:N}=v,E=C.getDrawingOKey(N);if(E==null)return R.push(null),!0;const{unitId:k,subUnitId:U,drawingId:O,drawingType:y,anchorType:B,sheetTransform:W}=E;R.push({unitId:k,subUnitId:U,drawingId:O,anchorType:B,sheetTransform:W,drawingType:y})}),R}ie.useEffect(()=>{const T=u.clearControl$.subscribe(R=>{R===!0&&p(!1)}),C=u.changeStart$.subscribe(R=>{var E;const{objects:v}=R,N=S(v,e);if(N.length===0)p(!1);else if(N.length>=1){p(!0);const k=((E=N[0])==null?void 0:E.anchorType)||m.SheetDrawingAnchorType.Position;w(k)}});return()=>{C.unsubscribe(),T.unsubscribe()}},[]);function _(T){w(T);const C=e.getFocusDrawings();if(C.length===0)return;const R=C.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));r.executeCommand(We.id,{unitId:C[0].unitId,drawings:R})}const I=T=>T?"block":"none";return V.jsxs("div",{className:q.clsx(me.imageCommonPanelGrid,me.imageCommonPanelBorder),style:{display:I(c)},children:[V.jsx("div",{className:me.imageCommonPanelRow,children:V.jsx("div",{className:q.clsx(me.imageCommonPanelColumn,me.imageCommonPanelTitle),children:V.jsx("div",{children:t.t("drawing-anchor.title")})})}),V.jsx("div",{className:q.clsx(me.imageCommonPanelRow),children:V.jsx("div",{className:q.clsx(me.imageCommonPanelColumn),children:V.jsxs(q.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[V.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),V.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),V.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Xn=()=>{const i=x.useDependency(A.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ie.useState(r);return ie.useEffect(()=>{const n=i.focus$.subscribe(s=>{e(s)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&V.jsxs("div",{className:me.imageCommonPanel,children:[V.jsx(fe.DrawingCommonPanel,{drawings:t}),V.jsx(Vn,{drawings:t})]})},Kn={[x.RibbonStartGroup.FORMULAS_INSERT]:{[Mt]:{order:3,menuItemFactory:Wn,[Be.id]:{order:0,menuItemFactory:Bn},[Ct.id]:{order:1,menuItemFactory:xn}}}};function xe(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const zn={id:Re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:x.KeyCode.ARROW_DOWN,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.DOWN}},Zn={id:Re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:x.KeyCode.ARROW_UP,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.UP}},qn={id:Re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:x.KeyCode.ARROW_LEFT,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.LEFT}},Jn={id:Re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:x.KeyCode.ARROW_RIGHT,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.RIGHT}},Qn={id:yt.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:xe,binding:x.KeyCode.DELETE,mac:x.KeyCode.BACKSPACE};var er=Object.getOwnPropertyDescriptor,tr=(i,r,t,e)=>{for(var n=e>1?void 0:e?er(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Me=(i,r)=>(t,e)=>r(t,e,i);let lt=class extends l.Disposable{constructor(i,r,t,e,n,s){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Yt,Lt)),this.disposeWithMe(i.register(jt,Xn))}_initMenus(){this._menuManagerService.mergeMenu(Kn)}_initCommands(){[Be,Ct,ke,Te,We,St,G,_t,vt,Dt,Re,yt,It].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zn,Zn,qn,Jn,Qn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};lt=tr([Me(0,l.Inject(x.ComponentManager)),Me(1,x.IMenuManagerService),Me(2,l.ICommandService),Me(3,x.IShortcutService),Me(4,A.IDrawingManagerService),Me(5,l.Inject(D.SheetsSelectionsService))],lt);var nr=Object.getOwnPropertyDescriptor,rr=(i,r,t,e)=>{for(var n=e>1?void 0:e?nr(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},we=(i,r)=>(t,e)=>r(t,e,i);function ir(i,r,t,e,n){const{scaleX:s,scaleY:o}=r.getAncestorScale(),a=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),d=e.getFreeze(),{startColumn:g,startRow:u,xSplit:c,ySplit:p}=d,h={left:!0,top:!0};if(!a)return{...i,absolute:h};const{left:f,right:w,top:S,bottom:_}=i;let{top:I,left:M,viewportScrollX:T,viewportScrollY:C}=a;const{boundsOfViewArea:R,scrollDirectionResponse:v}=n||{},{rowHeaderWidth:N,columnHeaderHeight:E}=t,k={top:E,left:N};R&&(l.Tools.isDefine(k.top)&&(k.top=R.top),l.Tools.isDefine(k.left)&&(k.left=R.left)),v==="HORIZONTAL"&&(C=0),v==="VERTICAL"&&(T=0);let U=0,O=0;const y=t.rowStartY(u-p)+E,B=t.colStartX(g-c)+N,W=t.rowStartY(u)+E,X=t.colStartX(g)+N;if(c===0)h.left=!1,U=(f-T)*s,O=(w-T)*s;else{const ee=f-(B-N),Z=w-(B-N);w<X?(U=ee*s,O=Z*s):f<=X&&w>=X?(U=ee*s,O=Math.max(M,(w-T)*s)):f>X&&(h.left=!1,U=Math.max((f-T)*s,M),O=Math.max((w-T)*s,M))}let H=0,z=0;if(p===0)h.top=!1,H=(S-C)*o,z=(_-C)*o;else{const ee=S-(y-E),Z=_-(y-E);_<W?(H=ee*o,z=Z*o):S<=W&&_>=W?(H=ee*o,z=Math.max(I,(_-C)*o)):S>W&&(h.top=!1,H=Math.max((S-C)*o,I),z=Math.max((_-C)*o,I))}return U=Math.max(U,k.left),H=Math.max(H,k.top),O=Math.max(O,k.left),z=Math.max(z,k.top),{left:U,right:O,top:H,bottom:z,absolute:h}}const ge=(i,r,t,e,n)=>{const{scene:s}=r,{left:o,top:a,width:d,height:g,angle:u}=i,c={left:o,right:o+d,top:a,bottom:a+g},p=ir(c,s,t,e,n),{scaleX:h,scaleY:f}=s.getAncestorScale();return{startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:u,width:d*h,height:g*f,absolute:p.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,s,o,a,d){super();Q(this,"_domLayerMap",new Map);Q(this,"_domLayerInfoMap",new Map);Q(this,"_transformChange$",new P.Subject);Q(this,"transformChange$",this._transformChange$.asObservable());Q(this,"_add$",new P.Subject);Q(this,"add$",this._add$.asObservable());Q(this,"_remove$",new P.Subject);Q(this,"remove$",this._remove$.asObservable());Q(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=s,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(P.filter(t=>t===l.LifecycleStages.Rendered),P.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let s=n.get(e);return s||(s=new Map,n.set(e,s)),s}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const s=n.getTransformerByCreate(),o=e.engine.getCanvasElement();return{scene:n,transformer:s,renderUnit:e,canvas:o}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var oe,ae,J;const{unitId:n,subUnitId:s,drawingId:o}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:s}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(oe=this._renderManagerService.getRenderById(n))==null?void 0:oe.with(b.SheetSkeletonManagerService).getSkeletonParam(s);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:_}=w;if(p==null)return!0;if(u!==s)return;const{left:I,top:M,width:T,height:C,angle:R,flipX:v,flipY:N,skewX:E,skewY:k}=p,U=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),O=S.getObject(U);if(O!=null){O.transformByState({left:I,top:M,width:T,height:C,angle:R,flipX:v,flipY:N,skewX:E,skewY:k});return}const y={left:I,top:M,width:T,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,s).length-1},B=h===l.DrawingTypeEnum.DRAWING_CHART;if(B){const Y=f?f.backgroundColor:"white";y.fill=Y,y.rotateEnabled=!1,f&&f.border&&(y.stroke=f.border),y.paintFirst="stroke",y.strokeWidth=1,y.borderEnabled=!1,y.radius=8}const W=new j.Rect(U,y);B&&W.setObjectType(j.ObjectType.CHART),S.addObject(W,j.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(W);const X=this._ensureMap(n,s),H=new l.DisposableCollection,z=ge(W,w.renderUnit,c.skeleton,a.worksheet),se=new P.BehaviorSubject(z),ee={dispose:H,rect:W,position$:se,unitId:n,subUnitId:s};this._canvasFloatDomService.addFloatDom({position$:se,id:o,componentKey:d.componentKey,onPointerDown:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{_.dispatchEvent(new WheelEvent(Y.type,Y))},props:(J=(ae=X.get(o))==null?void 0:ae.props)!=null?J:this._getFloatDomProps(o),data:f,unitId:n});const Z=W.onTransformChange$.subscribeEvent(()=>{const Y=ge(W,w.renderUnit,c.skeleton,a.worksheet);se.next(Y)});H.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),Z&&H.add(Z),this._domLayerInfoMap.set(o,ee),X.set(o,{...X.get(o)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:s,drawingId:o}=e,a=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&g.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var u;const s=this._getSceneAndTransformerByDrawingSearch(e),o=this._ensureMap(e,n),a=Array.from(o.keys()),d=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),g=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!s||!d||!g||a.forEach(c=>{const p=this._domLayerInfoMap.get(c);if(p){const h=ge(p.rect,s.renderUnit,g.skeleton,d.worksheet,p);p.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(P.switchMap(e=>e?e.activeSheet$:P.of(null)),P.map(e=>{if(!e)return null;const n=e.getUnitId(),s=this._renderManagerService.getRenderById(n);return s?{render:s,unitId:n,subUnitId:e.getSheetId()}:null}),P.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(P.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):P.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:s}=e;t(n,s)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,s;if(e.id===b.SetZoomRatioOperation.id){const o=e.params,{unitId:a}=o;Array.from((s=(n=this._domLayerMap.get(a))==null?void 0:n.keys())!=null?s:[]).forEach(g=>{t(a,g)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:o,subUnitId:a}=e.params;t(o,a)}}))}_getPosition(t,e){var h;const{startX:n,endX:s,startY:o,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(b.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},c=d.getCellWithCoordByOffset(s,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:s-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const s={...n.transform};this._transformChange$.next({id:e.drawingId,value:s})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,s){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(o&&a){const{scene:d}=a,g=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof j.Rect&&u.setProps(s)}}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:s,subUnitId:o}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,s);if(p==null)return;this._ensureMap(s,o).set(c,t);const f={unitId:s,subUnitId:o,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(ke.id,{unitId:s,drawings:[f]}),this._add$.next({unitId:s,subUnitId:o,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:s,subUnitId:o}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(s);if(a&&a.scene.removeObject(n.rect),e){this._ensureMap(s,o).delete(t);const g=this._drawingManagerService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:t});if(!g)return;const u=this._sheetDrawingService.getBatchRemoveOp([g]),{redo:c,objects:p}=u;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:o,op:c,objects:p,type:m.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}addFloatDomToRange(t,e,n,s){var N,E,k,U,O;const o=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(N=this._renderManagerService.getRenderById(a))==null?void 0:N.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(S,a)==null)return;this._ensureMap(a,d).set(w,e);const T=g.scene,{scaleX:C}=T.getAncestorScale(),R=et(S,n,C),v={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:R.startX,top:R.startY,width:R.width,height:R.height},data:h,allowTransform:f};{const{unitId:y,subUnitId:B,drawingId:W}=v,X=D.getSheetCommandTarget(this._univerInstanceService,{unitId:y,subUnitId:B}),H=v,z=this._univerInstanceService.getUnit(y,l.UniverInstanceType.UNIVER_SHEET);if(!z)return;const se=z.getActiveSheet().getSheetId();if(!H||!X)return;const ee=(E=this._renderManagerService.getRenderById(y))==null?void 0:E.with(b.SheetSkeletonManagerService);if(!ee)return;const Z=ee.getWorksheetSkeleton(B);if(!Z)return;const{transform:oe,drawingType:ae,data:J}=H;if(ae!==l.DrawingTypeEnum.DRAWING_DOM&&ae!==l.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(y);if(Y==null)return;const{scene:Se,canvas:_e}=Y;if(oe==null||se!==B)return;const{left:Le,top:Ye,width:$e,height:Fe,angle:ut,flipX:gt,flipY:Ge,skewX:He,skewY:ve}=oe,Ve=A.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:B,drawingId:W}),de=Se.getObject(Ve);if(de!=null){de.transformByState({left:Le,top:Ye,width:$e,height:Fe,angle:ut,flipX:gt,flipY:Ge,skewX:He,skewY:ve});return}const te={left:Le,top:Ye,width:$e,height:Fe,zIndex:this._drawingManagerService.getDrawingOrder(y,B).length-1},Ie=ae===l.DrawingTypeEnum.DRAWING_CHART;if(Ie){const L=J?J.backgroundColor:"white";te.fill=L,te.rotateEnabled=!1,J&&J.border&&(te.stroke=J.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const ce=new j.Rect(Ve,te);Ie&&ce.setObjectType(j.ObjectType.CHART),Se.addObject(ce,j.DRAWING_OBJECT_LAYER_INDEX),H.allowTransform!==!1&&Se.attachTransformerTo(ce);const be=this._ensureMap(y,B),le=new l.DisposableCollection,Xe=Se.getMainViewport(),{rowHeaderWidth:De,columnHeaderHeight:Ee}=Z.skeleton,Ke={top:Ee,left:De,bottom:Xe.bottom,right:Xe.right},ue={dispose:le,rect:ce,boundsOfViewArea:Ke,domAnchor:n,unitId:y,subUnitId:B},$=ge(ce,Y.renderUnit,Z.skeleton,X.worksheet,ue),Ce=new P.BehaviorSubject($);ue.position$=Ce;let Oe={position$:Ce,id:W,componentKey:H.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{_e.dispatchEvent(new WheelEvent(L.type,L))},props:(U=(k=be.get(W))==null?void 0:k.props)!=null?U:this._getFloatDomProps(W),data:J,unitId:y};e.eventPassThrough&&(Oe={...Oe,onPointerDown:L=>{_e.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{_e.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{_e.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Oe),this.disposeWithMe(_.subscribe(L=>{var Rt,bt,Et,Ot;const Tt=et({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(Rt=n.width)!=null?Rt:L.width,height:(bt=n.height)!=null?bt:L.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Ft=A.getDrawingShapeKeyByDrawingSearch({unitId:y,subUnitId:B,drawingId:W}),Gt=new j.Rect(Ft,{left:Tt.startX,top:Tt.startY,width:(Et=n.width)!=null?Et:L.width,height:(Ot=n.height)!=null?Ot:L.height,zIndex:this._drawingManagerService.getDrawingOrder(y,B).length-1}),Ht=ge(Gt,Y.renderUnit,Z.skeleton,X.worksheet,ue);Ce.next(Ht)}));const Ue=(O=this._renderManagerService.getRenderById(y))==null?void 0:O.with(b.SheetSkeletonManagerService);Ue==null||Ue.currentSkeleton$.subscribe(L=>{L&&Z.sheetId!==L.sheetId&&this._removeDom(w,!0)});const ze=ce.onTransformChange$.subscribeEvent(()=>{const L=ge(ce,Y.renderUnit,Z.skeleton,X.worksheet,ue);Ce.next(L)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(W)}),ze&&le.add(ze),this._domLayerInfoMap.set(W,ue),be.set(W,{...be.get(W)})}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,s){var R,v,N,E,k;const o=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(R=this._renderManagerService.getRenderById(a))==null?void 0:R.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=s!=null?s:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),I=S;if(I.startY=0,this._getPosition(S,a)==null)return;this._ensureMap(a,d).set(w,e);const C={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:O,drawingId:y}=C,B=D.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:O}),W=C,X=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!X)return;const H=X.getActiveSheet().getSheetId();if(!W||!B)return;const z=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(b.SheetSkeletonManagerService);if(!z)return;const se=z.getWorksheetSkeleton(O);if(!se)return;const{transform:ee,data:Z}=W,oe=this._getSceneAndTransformerByDrawingSearch(U);if(oe==null)return;const{scene:ae,canvas:J}=oe;if(ee==null||H!==O)return;const{left:Y,top:Se,width:_e,height:Le,angle:Ye,flipX:$e,flipY:Fe,skewX:ut,skewY:gt}=ee,Ge=A.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:y}),He=ae.getObject(Ge);if(He!=null){He.transformByState({left:Y,top:Se,width:_e,height:Le,angle:Ye,flipX:$e,flipY:Fe,skewX:ut,skewY:gt});return}const ve=et({startX:I.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Ve={left:ve.startX,top:ve.startY,width:ve.width,height:ve.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1},de=new j.Rect(Ge,Ve);ae.addObject(de,j.DRAWING_OBJECT_LAYER_INDEX),W.allowTransform!==!1&&ae.attachTransformerTo(de);const te=this._ensureMap(U,O),Ie=new l.DisposableCollection,ce=ae.getMainViewport(),be={top:0,left:ce.left,bottom:ce.bottom,right:ce.right},le={dispose:Ie,rect:de,unitId:U,subUnitId:O,boundsOfViewArea:be,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Xe=ge(de,oe.renderUnit,se.skeleton,B.worksheet,le),De=new P.BehaviorSubject(Xe);le.position$=De;let Ee={position$:De,id:y,componentKey:W.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{J.dispatchEvent(new WheelEvent($.type,$))},props:(E=(N=te.get(y))==null?void 0:N.props)!=null?E:this._getFloatDomProps(y),data:Z,unitId:U};e.eventPassThrough&&(Ee={...Ee,onPointerDown:$=>{J.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{J.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{J.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Ee);const Ke=de.onTransformChange$.subscribeEvent(()=>{const $=ge(de,oe.renderUnit,se.skeleton,B.worksheet,le);De.next($)});this.disposeWithMe(_.subscribe($=>{const Ce=et({startX:$.startX,startY:0,endX:$.endX,endY:$.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Oe=A.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:y}),Ue=new j.Rect(Oe,{left:Ce.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1}),ze=ge(Ue,oe.renderUnit,se.skeleton,B.worksheet,le);De.next(ze)}));const ue=(k=this._renderManagerService.getRenderById(U))==null?void 0:k.with(b.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe($=>{$&&c.sheetId!==$.sheetId&&this._removeDom(w,!0)}),Ie.add(()=>{this._canvasFloatDomService.removeFloatDom(y)}),Ke&&Ie.add(Ke),this._domLayerInfoMap.set(y,le),te.set(y,{...te.get(y)})}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:s,startColumn:o}=t;const a=je(s,o,n),d=new P.BehaviorSubject(a),g=je(t.endRow,t.endColumn,n),u=new P.BehaviorSubject(g),c=()=>{const _=je(s,o,n),I=je(t.endRow,t.endColumn,n);d.next(_),u.next(I)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===s)>-1){c();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&c()}));const h=(_,I)=>{s=_,o=I,c()},f=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),w=d.pipe(P.map(_=>{const I=je(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}};exports.SheetCanvasFloatDomManagerService=rr([we(0,l.Inject(j.IRenderManagerService)),we(1,l.IUniverInstanceService),we(2,l.Inject(l.ICommandService)),we(3,A.IDrawingManagerService),we(4,l.Inject(x.CanvasFloatDomService)),we(5,m.ISheetDrawingService),we(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function je(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function et(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,s=(g=r==null?void 0:r.width)!=null?g:e,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=tt(r.marginX,e*t);a=i.endX-c-s}else a=i.startX+tt(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=tt(r.marginY,n*t);d=i.endY-c-o}else d=i.startY+tt(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:i.endX,endY:i.endY,width:s,height:o,absolute:{left:i.absolute.left,top:i.absolute.top}}}function tt(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}var sr=Object.defineProperty,or=Object.getOwnPropertyDescriptor,ar=(i,r,t)=>r in i?sr(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,cr=(i,r,t,e)=>{for(var n=e>1?void 0:e?or(r,t):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ht=(i,r)=>(t,e)=>r(t,e,i),$t=(i,r,t)=>ar(i,typeof r!="symbol"?r+"":r,t);const dr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Ut,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:s,...o}=l.merge({},Ut,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Kt,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[lt],[rt],[dt],[ct],[at],[it],[st],[ot]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[at],[ot]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ct],[dt],[lt],[it],[st]])}onSteady(){this._injector.get(rt)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[wt],[mt],[pt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};$t(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);$t(exports.UniverSheetsDrawingUIPlugin,"pluginName",dr);exports.UniverSheetsDrawingUIPlugin=cr([l.DependentOn(A.UniverDrawingPlugin,Nt.UniverDocsDrawingPlugin,fe.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),ht(1,l.Inject(l.Injector)),ht(2,j.IRenderManagerService),ht(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=yt;exports.EditSheetDrawingOperation=_t;exports.GroupSheetDrawingCommand=vt;exports.InsertFloatImageCommand=Be;exports.InsertSheetDrawingCommand=ke;exports.MoveDrawingsCommand=Re;exports.RemoveSheetDrawingCommand=Te;exports.SHEETS_IMAGE_MENU_ID=Mt;exports.SetDrawingArrangeCommand=It;exports.SetSheetDrawingCommand=We;exports.SidebarSheetDrawingOperation=St;exports.UngroupSheetDrawingCommand=Dt;
|
package/lib/es/index.js
CHANGED
|
@@ -246,8 +246,8 @@ let dn = class extends se {
|
|
|
246
246
|
_initHover() {
|
|
247
247
|
this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(Gi(33)).subscribe((t) => {
|
|
248
248
|
var n, r;
|
|
249
|
-
|
|
250
|
-
(t == null ? void 0 : t.unitId) === this._context.unitId && (t != null && t.drawing) && e.length === 1 && ((n = e[0].primary) == null ? void 0 : n.actualRow) === t.row && ((r = e[0].primary) == null ? void 0 : r.actualColumn) === t.col ? (this._isSetCursor = !0, this._context.scene.setCursor(pi.ZOOM_IN)) : this._isSetCursor && (this._isSetCursor = !1, this._context.scene.resetCursor());
|
|
249
|
+
let e = [];
|
|
250
|
+
t !== null && (e = this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()), e.length > 0 && (t == null ? void 0 : t.unitId) === this._context.unitId && (t != null && t.drawing) && e.length === 1 && ((n = e[0].primary) == null ? void 0 : n.actualRow) === t.row && ((r = e[0].primary) == null ? void 0 : r.actualColumn) === t.col ? (this._isSetCursor = !0, this._context.scene.setCursor(pi.ZOOM_IN)) : this._isSetCursor && (this._isSetCursor = !1, this._context.scene.resetCursor());
|
|
251
251
|
}));
|
|
252
252
|
}
|
|
253
253
|
_initImageClick() {
|
package/lib/index.js
CHANGED
|
@@ -246,8 +246,8 @@ let dn = class extends se {
|
|
|
246
246
|
_initHover() {
|
|
247
247
|
this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(Gi(33)).subscribe((t) => {
|
|
248
248
|
var n, r;
|
|
249
|
-
|
|
250
|
-
(t == null ? void 0 : t.unitId) === this._context.unitId && (t != null && t.drawing) && e.length === 1 && ((n = e[0].primary) == null ? void 0 : n.actualRow) === t.row && ((r = e[0].primary) == null ? void 0 : r.actualColumn) === t.col ? (this._isSetCursor = !0, this._context.scene.setCursor(pi.ZOOM_IN)) : this._isSetCursor && (this._isSetCursor = !1, this._context.scene.resetCursor());
|
|
249
|
+
let e = [];
|
|
250
|
+
t !== null && (e = this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()), e.length > 0 && (t == null ? void 0 : t.unitId) === this._context.unitId && (t != null && t.drawing) && e.length === 1 && ((n = e[0].primary) == null ? void 0 : n.actualRow) === t.row && ((r = e[0].primary) == null ? void 0 : r.actualColumn) === t.col ? (this._isSetCursor = !0, this._context.scene.setCursor(pi.ZOOM_IN)) : this._isSetCursor && (this._isSetCursor = !1, this._context.scene.resetCursor());
|
|
251
251
|
}));
|
|
252
252
|
}
|
|
253
253
|
_initImageClick() {
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(E,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],c):(E=typeof globalThis<"u"?globalThis:E||self,c(E.UniverSheetsDrawingUi={},E.UniverCore,E.UniverDocsDrawing,E.UniverDrawing,E.UniverDrawingUi,E.UniverEngineRender,E.UniverSheetsDrawing,E.UniverSheetsUi,E.UniverUi,E.rxjs,E.UniverSheets,E.React,E.React,E.UniverDocsUi,E.UniverDesign))})(this,function(E,c,we,U,pe,B,m,b,Y,N,I,x,ne,Fe,Z){"use strict";var Qn=Object.defineProperty;var er=(E,c,we)=>c in E?Qn(E,c,{enumerable:!0,configurable:!0,writable:!0,value:we}):E[c]=we;var ee=(E,c,we)=>er(E,typeof c!="symbol"?c+"":c,we);const Ht="sheets-drawing-ui.config",bt={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(B.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ve={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(I.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:R}=y;s.push(R)});const l=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=n.onCommandExecute({id:ve.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.INSERT}};return c.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",ht={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(Y.ISidebarService),e=i.get(c.LocaleService),n=i.get(c.IUniverInstanceService),o=i.get(c.ICommandService);if(!I.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},pt={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[r]),t.executeCommand(ht.id,{value:"open"}),!0)}},Ge={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Vt=()=>{const i=Y.useDependency(U.IImageIoService),r=Y.useDependency(c.LocaleService),[t,e]=ne.useState(0);return ne.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),x.jsx("div",{style:{display:t>0?"block":"none"},className:Ge.uploadLoading,children:x.jsxs("div",{className:Ge.uploadLoadingBody,children:[x.jsx("div",{className:Ge.uploadLoadingBodyAnimation}),x.jsx("div",{className:Ge.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Xt=Object.getOwnPropertyDescriptor,xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);let He=class extends c.RxDisposable{constructor(r,t,e,n,o,a,s,l){super();ee(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Y.connectInjector(Vt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof pe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(c.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:pe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:pt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ve.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:pe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:pe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};He=xt([me(0,c.Inject(c.Injector)),me(1,U.IDrawingManagerService),me(2,c.Inject(b.SheetCanvasPopManagerService)),me(3,B.IRenderManagerService),me(4,c.IUniverInstanceService),me(5,c.IContextService),me(6,c.Inject(Y.IUIPartsService)),me(7,c.ICommandService)],He);var Kt=Object.getOwnPropertyDescriptor,zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ve=(i,r)=>(t,e)=>r(t,e,i);let mt=class extends c.Disposable{constructor(r,t,e,n,o){super();ee(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;const t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections();(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(B.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};mt=zt([Ve(1,c.Inject(b.HoverManagerService)),Ve(2,c.Inject(I.SheetsSelectionsService)),Ve(3,c.Inject(pe.DrawingRenderService)),Ve(4,c.Inject(b.SheetSkeletonManagerService))],mt);function K(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,C=w.columnHeaderHeight+w.rowTotalHeight;return p+f>_&&(p=_-f),h+S>C&&(h=C-S),{flipY:o,flipX:a,angle:s,skewX:l,skewY:g,left:p,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:B.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:B.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:B.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:B.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:g,skewY:u,from:p,to:f}}var Zt=Object.getOwnPropertyDescriptor,qt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Zt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let ft=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ft=qt([Xe(1,m.ISheetDrawingService),Xe(2,U.IDrawingManagerService),Xe(3,c.Inject(b.ISheetSelectionRenderService)),Xe(4,c.Inject(b.SheetSkeletonManagerService))],ft);function Jt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,l=B.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=d;return{unitId:h,subUnitId:f,drawingId:S,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Qt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:p}=d,{unitId:h,subUnitId:f,drawingId:S}=d,w=B.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const St={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Qt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),l=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=o.onCommandExecute({id:Oe.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},wt={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:g,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},_t={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Jt(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);function nn(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function vt(i,r,t,e,n){var C;const{rotatedHeight:o,rotatedWidth:a}=nn(t,e,n),l=i.get(B.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(C=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:C.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),p=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(p,h*f))/a,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}E.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,o,a,s,l,g,u,d,p,h,f){super();ee(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>U.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(U.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await U.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>U.DRAWING_IMAGE_WIDTH_LIMIT||p>U.DRAWING_IMAGE_HEIGHT_LIMIT){const M=U.DRAWING_IMAGE_WIDTH_LIMIT/d,T=U.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(M,T)}const _=this._getImagePosition(d*w,p*w,f,S);if(_==null)return;const C={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[C]})}async _insertCellImage(t,e){var C,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const y=T.message;y===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:l}=n,{width:g,height:u,image:d}=await U.getImageSize(l||"");this._imageIoService.addImageSourceCache(s,a,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=c.createDocumentModelWithStyle("",{}),f=vt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:Fe.docDrawingPositionToTransform(S),docTransform:S,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(C=e==null?void 0:e.row)!=null?C:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await U.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const l=c.createDocumentModelWithStyle("",{}),g=vt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:Fe.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(l.apply(p),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const l=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:p}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),p+e>o&&(p=o-e,p<0&&(p=0,e=o),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:d+t-S.startX,row:S.actualRow,rowOffset:p+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(wt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const p={...n,transform:{...u.transform,...g,...K(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(St.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(_t.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},E.SheetDrawingUpdateController=tn([re(1,c.Inject(b.SheetSkeletonManagerService)),re(2,c.ICommandService),re(3,b.ISheetSelectionRenderService),re(4,U.IImageIoService),re(5,Y.ILocalFileService),re(6,m.ISheetDrawingService),re(7,U.IDrawingManagerService),re(8,c.IContextService),re(9,Y.IMessageService),re(10,c.Inject(c.LocaleService)),re(11,c.Inject(I.SheetsSelectionsService)),re(12,c.Inject(c.Injector))],E.SheetDrawingUpdateController);var rn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],l=vt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(l)return s.transform.width=l.width,s.transform.height=l.height,s.docTransform.size.width=l.width,s.docTransform.size.height=l.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let xe=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Fe.ReplaceSnapshotCommand.id&&i.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:I.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Ot(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};xe=on([Ie(0,c.ICommandService),Ie(1,c.Inject(I.SheetInterceptorService)),Ie(2,c.Inject(c.Injector)),Ie(3,U.IDrawingManagerService),Ie(4,c.Inject(we.DocDrawingController)),Ie(5,c.Inject(b.IEditorBridgeService))],xe);var an=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Pt=(i,r)=>(t,e)=>r(t,e,i);let Ke=class extends c.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,o,a)=>{Ot(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Ke=sn([Pt(0,c.Inject(b.IAutoFillService)),Pt(1,c.Inject(c.Injector))],Ke);var cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const ln=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ze=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=B.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===Fe.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const a=o.getUnitId();if(ln.includes(a)){if(a!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
|
|
1
|
+
(function(E,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],c):(E=typeof globalThis<"u"?globalThis:E||self,c(E.UniverSheetsDrawingUi={},E.UniverCore,E.UniverDocsDrawing,E.UniverDrawing,E.UniverDrawingUi,E.UniverEngineRender,E.UniverSheetsDrawing,E.UniverSheetsUi,E.UniverUi,E.rxjs,E.UniverSheets,E.React,E.React,E.UniverDocsUi,E.UniverDesign))})(this,function(E,c,we,U,pe,B,m,b,Y,N,I,x,ne,Fe,Z){"use strict";var Qn=Object.defineProperty;var er=(E,c,we)=>c in E?Qn(E,c,{enumerable:!0,configurable:!0,writable:!0,value:we}):E[c]=we;var ee=(E,c,we)=>er(E,typeof c!="symbol"?c+"":c,we);const Ht="sheets-drawing-ui.config",bt={},G={id:"sheet.operation.clear-drawing-transformer",type:c.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(B.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ve={id:"sheet.command.remove-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(I.SheetInterceptorService),o=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:R}=y;s.push(R)});const l=o.getBatchRemoveOp(a),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=n.onCommandExecute({id:ve.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:m.DrawingApplyType.INSERT}};return c.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",ht={id:"sidebar.operation.sheet-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(Y.ISidebarService),e=i.get(c.LocaleService),n=i.get(c.IUniverInstanceService),o=i.get(c.ICommandService);if(!I.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{o.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},pt={id:"sheet.operation.edit-sheet-image",type:c.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(c.ICommandService);return r==null?!1:(t.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[r]),t.executeCommand(ht.id,{value:"open"}),!0)}},Ge={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Vt=()=>{const i=Y.useDependency(U.IImageIoService),r=Y.useDependency(c.LocaleService),[t,e]=ne.useState(0);return ne.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),x.jsx("div",{style:{display:t>0?"block":"none"},className:Ge.uploadLoading,children:x.jsxs("div",{className:Ge.uploadLoadingBody,children:[x.jsx("div",{className:Ge.uploadLoadingBodyAnimation}),x.jsx("div",{className:Ge.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Xt=Object.getOwnPropertyDescriptor,xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},me=(i,r)=>(t,e)=>r(t,e,i);let He=class extends c.RxDisposable{constructor(r,t,e,n,o,a,s,l){super();ee(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(c.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>Y.connectInjector(Vt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof pe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(c.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const a=e.getSelectedObjectMap();if(a.size>1){n==null||n.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,g=this._drawingManagerService.getDrawingOKey(l);if(!g)return;const{unitId:u,subUnitId:d,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:pe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,p,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[c.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:pt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ve.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:pe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===c.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:pe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===c.DrawingTypeEnum.DRAWING_DOM}]}};He=xt([me(0,c.Inject(c.Injector)),me(1,U.IDrawingManagerService),me(2,c.Inject(b.SheetCanvasPopManagerService)),me(3,B.IRenderManagerService),me(4,c.IUniverInstanceService),me(5,c.IContextService),me(6,c.Inject(Y.IUIPartsService)),me(7,c.ICommandService)],He);var Kt=Object.getOwnPropertyDescriptor,zt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ve=(i,r)=>(t,e)=>r(t,e,i);let mt=class extends c.Disposable{constructor(r,t,e,n,o){super();ee(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(B.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};mt=zt([Ve(1,c.Inject(b.HoverManagerService)),Ve(2,c.Inject(I.SheetsSelectionsService)),Ve(3,c.Inject(pe.DrawingRenderService)),Ve(4,c.Inject(b.SheetSkeletonManagerService))],mt);function K(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:g=0}=i,u=t.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:S}=d;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,C=w.columnHeaderHeight+w.rowTotalHeight;return p+f>_&&(p=_-f),h+S>C&&(h=C-S),{flipY:o,flipX:a,angle:s,skewX:l,skewY:g,left:p,top:h,width:f,height:S}}function H(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(t,e);if(d==null)return;const p={column:d.actualColumn,columnOffset:B.precisionTo(t-d.startX,1),row:d.actualRow,rowOffset:B.precisionTo(e-d.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:B.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:B.precisionTo(e+o-h.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:g,skewY:u,from:p,to:f}}var Zt=Object.getOwnPropertyDescriptor,qt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Zt(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Xe=(i,r)=>(t,e)=>r(t,e,i);let ft=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ft=qt([Xe(1,m.ISheetDrawingService),Xe(2,U.IDrawingManagerService),Xe(3,c.Inject(b.ISheetSelectionRenderService)),Xe(4,c.Inject(b.SheetSkeletonManagerService))],ft);function Jt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s}=e,l=B.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const p=d.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=d;return{unitId:h,subUnitId:f,drawingId:S,transform:{...p,left:p.left-l.left,top:p.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:g})}),r}function Qt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const g=n.map(d=>{const{transform:p}=d,{unitId:h,subUnitId:f,drawingId:S}=d,w=B.transformObjectOutOfGroup(p||{},l,l.width||0,l.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const St={id:"sheet.command.group-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Qt(d),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Oe={id:"sheet.command.insert-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{var C,M,T;const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService),o=i.get(I.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),l=n.getBatchAddOp(a),{unitId:g,subUnitId:u,undo:d,redo:p,objects:h}=l,f=o.onCommandExecute({id:Oe.id,params:r}),S={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return c.sequenceExecute([...(C=f.preRedos)!=null?C:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(M=f.preUndos)!=null?M:[],w,...f.undos,{id:G.id,params:s}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:s}]}),!0):!1}},wt={id:"sheet.command.set-drawing-arrange",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService);if(!r)return!1;const n=i.get(m.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,g={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===c.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):l===c.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):l===c.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):l===c.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:o,subUnitId:a,objects:d,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Pe={id:"sheet.command.set-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:g,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:d,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}]}),!0):!1}},_t={id:"sheet.command.ungroup-sheet-image",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(c.IUndoRedoService),n=i.get(m.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=n.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:g,redo:u,objects:d}=a;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:s,subUnitId:l,objects:Jt(d),type:m.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:d,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var en=Object.getOwnPropertyDescriptor,tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},re=(i,r)=>(t,e)=>r(t,e,i);function nn(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function vt(i,r,t,e,n){var C;const{rotatedHeight:o,rotatedWidth:a}=nn(t,e,n),l=i.get(B.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(C=l.with(b.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:C.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),p=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,f=a/o,w=Math.ceil(Math.min(p,h*f))/a,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}E.SheetDrawingUpdateController=class extends c.Disposable{constructor(t,e,n,o,a,s,l,g,u,d,p,h,f){super();ee(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=o,this._imageIoService=a,this._fileOpenerService=s,this._sheetDrawingService=l,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>U.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(U.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:U.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(M){const T=M.message;T===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):T===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):T===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:a}=n,{imageId:s,imageSourceType:l,source:g,base64Cache:u}=e,{width:d,height:p,image:h}=await U.getImageSize(u||""),{width:f,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,l,h);let w=1;if(d>U.DRAWING_IMAGE_WIDTH_LIMIT||p>U.DRAWING_IMAGE_HEIGHT_LIMIT){const M=U.DRAWING_IMAGE_WIDTH_LIMIT/d,T=U.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(M,T)}const _=this._getImagePosition(d*w,p*w,f,S);if(_==null)return;const C={unitId:o,subUnitId:a,drawingId:s,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[C]})}async _insertCellImage(t,e){var C,M;let n;try{n=await this._imageIoService.saveImage(t)}catch(T){const y=T.message;y===U.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(U.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===U.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===U.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:a,source:s,base64Cache:l}=n,{width:g,height:u,image:d}=await U.getImageSize(l||"");this._imageIoService.addImageSourceCache(s,a,d);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;const h=c.createDocumentModelWithStyle("",{}),f=vt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:p.primary.actualRow,col:p.primary.actualColumn},g,u,0);if(!f)return!1;const S={size:{width:f.width,height:f.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},w={unitId:h.getUnitId(),subUnitId:h.getUnitId(),drawingId:o,drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:s,transform:Fe.docDrawingPositionToTransform(S),docTransform:S,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=c.BuildTextUtils.drawing.add({documentDataModel:h,drawings:[w],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(h.apply(_),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(C=e==null?void 0:e.row)!=null?C:p.primary.actualRow]:{[(M=e==null?void 0:e.col)!=null?M:p.primary.actualColumn]:{p:h.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:o,image:a}=await U.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,c.ImageSourceType.URL,a);const s=this._workbookSelections.getCurrentLastSelection();if(!s)return!1;const l=c.createDocumentModelWithStyle("",{}),g=vt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:s.primary.actualRow,col:s.primary.actualColumn},n,o,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:c.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:c.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},d={unitId:l.getUnitId(),subUnitId:l.getUnitId(),drawingId:c.generateRandomId(),drawingType:c.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c.ImageSourceType.URL,source:t,transform:Fe.docDrawingPositionToTransform(u),docTransform:u,behindDoc:c.BooleanNumber.FALSE,title:"",description:"",layoutType:c.PositionedObjectLayoutType.INLINE,wrapText:c.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=c.BuildTextUtils.drawing.add({documentDataModel:l,drawings:[d],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(l.apply(p),this._commandService.syncExecuteCommand(I.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:s.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:s.primary.actualColumn]:{p:l.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),o=e.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(t,e,n,o){const a=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(s=a[a.length-1].range);const l=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(l==null)return;let{startColumn:g,startRow:u,startX:d,startY:p}=l,h=!1;if(d+t>n&&(d=n-t,d<0&&(d=0,t=n),h=!0),p+e>o&&(p=o-e,p<0&&(p=0,e=o),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(d,p);if(_==null)return;d=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+t,p+e);if(S==null)return;const w={column:S.actualColumn,columnOffset:d+t-S.startX,row:S.actualRow,rowOffset:p+e-S.startY};return{from:f,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a}=t;this._commandService.executeCommand(wt.id,{unitId:e,subUnitId:n,drawingIds:o,arrangeType:a})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:o,subUnitId:a,drawingId:s,drawingType:l,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:s});if(u==null||u.unitId!==this._context.unitId)return;const d=H({...u.transform,...g},this._selectionRenderService);if(d==null)return;const p={...n,transform:{...u.transform,...g,...K(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Pe.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(St.id,t);const{unitId:e,subUnitId:n,drawingId:o}=t[0].parent;this._commandService.syncExecuteCommand(U.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:o}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(_t.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(c.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},E.SheetDrawingUpdateController=tn([re(1,c.Inject(b.SheetSkeletonManagerService)),re(2,c.ICommandService),re(3,b.ISheetSelectionRenderService),re(4,U.IImageIoService),re(5,Y.ILocalFileService),re(6,m.ISheetDrawingService),re(7,U.IDrawingManagerService),re(8,c.IContextService),re(9,Y.IMessageService),re(10,c.Inject(c.LocaleService)),re(11,c.Inject(I.SheetsSelectionsService)),re(12,c.Inject(c.Injector))],E.SheetDrawingUpdateController);var rn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ie=(i,r)=>(t,e)=>r(t,e,i);function Ot(i,r,t){var e,n,o,a;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((a=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=t.p.drawings[t.p.drawingsOrder[0]],l=vt(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(l)return s.transform.width=l.width,s.transform.height=l.height,s.docTransform.size.width=l.width,s.docTransform.size.height=l.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let xe=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Fe.ReplaceSnapshotCommand.id&&i.params.unitId===c.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(c.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:I.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Ot(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),t(i)}}))}};xe=on([Ie(0,c.ICommandService),Ie(1,c.Inject(I.SheetInterceptorService)),Ie(2,c.Inject(c.Injector)),Ie(3,U.IDrawingManagerService),Ie(4,c.Inject(we.DocDrawingController)),Ie(5,c.Inject(b.IEditorBridgeService))],xe);var an=Object.getOwnPropertyDescriptor,sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Pt=(i,r)=>(t,e)=>r(t,e,i);let Ke=class extends c.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new c.ObjectMatrix(e).forValue((n,o,a)=>{Ot(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},a)})}}))}};Ke=sn([Pt(0,c.Inject(b.IAutoFillService)),Pt(1,c.Inject(c.Injector))],Ke);var cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ae=(i,r)=>(t,e)=>r(t,e,i);const ln=[c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,c.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,c.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ze=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=c.createDocumentModelWithStyle("",{}),t=(n=B.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(b.EditingRenderController),e=c.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,t;if(i.id===Fe.InnerPasteCommand.id){const e=i.params,{doc:n}=e,o=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const a=o.getUnitId();if(ln.includes(a)){if(a!==c.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const s=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1})};((t=o.getBody())==null?void 0:t.dataStream)===`\r
|
|
2
2
|
`?(this._commandService.syncExecuteCommand(b.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:s,showOk:!0,showCancel:!0,onOk:()=>{s(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:s})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};ze=dn([Ae(0,c.ICommandService),Ae(1,c.IUniverInstanceService),Ae(2,Y.IDialogService),Ae(3,B.IRenderManagerService),Ae(4,c.Inject(c.LocaleService))],ze);const Ue={id:"sheet.command.insert-float-image",type:c.CommandType.COMMAND,handler:async(i,r)=>{var a,s;const t=i.get(c.IUniverInstanceService),e=i.get(B.IRenderManagerService),n=(a=B.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:a.with(E.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const l=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(l)).every(g=>g)}else return(s=n.insertFloatImage())!=null?s:!1}},It={id:"sheet.command.insert-cell-image",type:c.CommandType.COMMAND,handler:i=>{var e,n;const r=i.get(c.IUniverInstanceService),t=i.get(B.IRenderManagerService);return(n=(e=B.getCurrentTypeOfRenderer(c.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(E.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}};var un=Object.getOwnPropertyDescriptor,gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Ne=(i,r)=>(t,e)=>r(t,e,i);const At="image/png";function hn(i){const r=i.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:At})}function pn(i){const r=new ClipboardItem({[At]:hn(i)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function mn(){function i(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=i();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Ut=[b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,b.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ze=class extends c.Disposable{constructor(r,t,e,n,o){super();ee(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(n===b.COPY_TYPE.CUT){const l={unitId:r,drawings:[a]};this._commandService.executeCommand(ve.id,l)}setTimeout(()=>{const l=mn();a.drawingType===c.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===U.ImageSourceType.BASE64?pn(a.source):this._clipboardInterfaceService.writeText(""),l()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=a}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:a}=n,{range:s}=r||{},{range:l,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:g,subUnitId:u,pasteRange:l},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},b.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ue.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(b.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:g}=o,u=this._drawingService.getDrawingData(r,t),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:_=0,width:C=0,height:M=0}=S,{drawingStartX:T,drawingEndX:y,drawingStartY:R,drawingEndY:v}={drawingStartX:w,drawingEndX:w+C,drawingStartY:_,drawingEndY:_+M};a<=T&&y<=s&&l<=R&&v<=g&&d.push(f)}),d.length)return{copyRange:e,drawings:d,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Ut.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=n,l=this._renderManagerService.getRenderById(o),g=l==null?void 0:l.with(b.SheetSkeletonManagerService),u=l==null?void 0:l.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=d,h=b.discreteRangeToRange(s);return this._generateMutations(p,{unitId:o,subUnitId:a,isCut:t===b.COPY_TYPE.CUT,getTransform:(f,S)=>{var C;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(C=H(_,u))!=null?C:S}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:o,isCut:a}=t,s=[],l=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:p}=u;if(!d)return;const h=o(d,p),f={...u,unitId:e,subUnitId:n,drawingId:a?u.drawingId:c.Tools.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(a){const{undo:S,redo:w,objects:_}=g.getBatchUpdateOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}})}else{const{undo:S,redo:w,objects:_}=g.getBatchAddOp([f]);s.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),l.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:s,undos:l}}_generateRangeDrawingsPasteMutations(r,t){var k;const{unitId:e,subUnitId:n,pasteType:o,pasteRange:a}=r,{copyRange:s,copyType:l}=t;if(Ut.includes(o))return{redos:[],undos:[]};const g=(k=this._renderManagerService.getRenderById(e))==null?void 0:k.with(b.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:b.discreteRangeToRange(a)},pasteType:o},l);const{ranges:[d,p],mapFunc:h}=b.virtualizeDiscreteRanges([s,a]),{row:f,col:S}=h(d.startRow,d.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),C=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:S,endColumn:S}),M=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!C||!M||!this._copyInfo)return{redos:[],undos:[]};const T=M.startX-C.startX,y=M.startY-C.startY,R=w-f,v=_-S;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(O,W)=>{var A,P;return{transform:{...O,left:((A=O==null?void 0:O.left)!=null?A:0)+T,top:((P=O==null?void 0:O.top)!=null?P:0)+y},sheetTransform:{...W,to:{...W.to,row:W.to.row+R,column:W.to.column+v},from:{...W.from,row:W.from.row+R,column:W.from.column+v}}}},isCut:l===b.COPY_TYPE.CUT})}};Ze=gn([Ne(0,b.ISheetClipboardService),Ne(1,B.IRenderManagerService),Ne(2,U.IDrawingManagerService),Ne(3,Y.IClipboardInterfaceService),Ne(4,c.ICommandService)],Ze);var fn=Object.getOwnPropertyDescriptor,Sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?fn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ke=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends c.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new I.WorkbookViewPermission(a).id,new I.WorksheetViewPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===B.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([i,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const a=e.getUnitId(),s=o.getSheetId();this._permissionService.composePermission([new I.WorkbookEditablePermission(a).id,new I.WorksheetEditPermission(a,s).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const t=i.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),o=Object.values(n),a=this._renderManagerService.getRenderById(t),s=a==null?void 0:a.scene;if(!s)return;s.getAllObjectsByOrder().forEach(g=>{g.classType===B.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&s.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new I.WorkbookViewPermission(o).id,new I.WorksheetViewPermission(o,a).id]).pipe(N.map(d=>d.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingVisible(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?this._drawingManagerService.addNotification(g):(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),o=e==null?void 0:e.getSheetId();if(!n||!o)return;const a=this._drawingManagerService.getDrawingData(n,o),s=Object.values(a);this._drawingManagerService.addNotification(s)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=t.getUnitId(),a=n.getSheetId(),s=this._renderManagerService.getRenderById(o),l=s==null?void 0:s.scene;if(!l)return N.EMPTY;const g=l.getTransformerByCreate();return this._permissionService.composePermission$([new I.WorkbookEditablePermission(o).id,new I.WorksheetEditPermission(o,a).id]).pipe(N.map(d=>d.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:l,transformer:g,unitId:o,subUnitId:a})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:o,subUnitId:a})=>{this._drawingManagerService.setDrawingEditable(t);const s=e.getAllObjectsByOrder(),l=this._drawingManagerService.getDrawingData(o,a),g=Object.values(l);t?(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(s.forEach(u=>{u.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const o=n.getSheetId(),a=this._renderManagerService.getRenderById(e),s=a==null?void 0:a.scene;if(!s)return;const l=this._drawingManagerService.getDrawingData(e,o),g=Object.values(l);this._drawingManagerService.setDrawingEditable(!0),s.getAllObjectsByOrder().forEach(d=>{d.classType===B.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>d.oKey.includes(p.drawingId))&&s.detachTransformerFrom(d)})}}))}};qe=Sn([ke(0,U.IDrawingManagerService),ke(1,B.IRenderManagerService),ke(2,c.IPermissionService),ke(3,c.IUniverInstanceService),ke(4,c.Inject(c.UserManagerService))],qe);var wn=Object.getOwnPropertyDescriptor,_n=(i,r,t,e)=>{for(var n=e>1?void 0:e?wn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Je=(i,r)=>(t,e)=>r(t,e,i);let Qe=class extends c.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const a=o.with(b.SheetSkeletonManagerService).getSkeletonParam(n);if(!a)return t(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return t(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=l.order.map(h=>l.data[h]).filter(h=>h.drawingType!==c.DrawingTypeEnum.DRAWING_DOM);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&c.Tools.isDefine(h.transform.left)&&c.Tools.isDefine(h.transform.top)&&c.Tools.isDefine(h.transform.width)&&c.Tools.isDefine(h.transform.height)){const f=a.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<d.startColumn&&(d.startColumn=f.column),f.row<d.startRow&&(d.startRow=f.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),t(d)):t(i)}}))}};Qe=_n([Je(0,c.Inject(b.SheetPrintInterceptorService)),Je(1,c.Inject(pe.DrawingRenderService)),Je(2,U.IDrawingManagerService),Je(3,B.IRenderManagerService)],Qe);var vn=Object.getOwnPropertyDescriptor,In=(i,r,t,e)=>{for(var n=e>1?void 0:e?vn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},fe=(i,r)=>(t,e)=>r(t,e,i);const Cn=[I.InsertRowCommand.id,I.InsertColCommand.id,I.RemoveRowCommand.id,I.RemoveColCommand.id,I.DeleteRangeMoveLeftCommand.id,I.DeleteRangeMoveUpCommand.id,I.InsertRangeMoveDownCommand.id,I.InsertRangeMoveRightCommand.id,I.DeltaRowHeightCommand.id,I.SetRowHeightCommand.id,I.DeltaColumnWidthCommand.id,I.SetColWidthCommand.id,I.SetRowHiddenCommand.id,I.SetSpecificRowsVisibleCommand.id,I.SetSpecificColsVisibleCommand.id,I.SetColHiddenCommand.id,I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id],yn=[I.SetRowVisibleMutation.id,I.SetRowHiddenMutation.id,I.SetColVisibleMutation.id,I.SetColHiddenMutation.id,I.SetWorksheetRowHeightMutation.id,I.SetWorksheetColWidthMutation.id];let Ct=class extends c.Disposable{constructor(i,r,t,e,n,o,a,s,l){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Cn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===I.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([I.MoveColsCommand.id,I.MoveRowsCommand.id,I.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===I.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===I.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===I.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===I.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===I.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===I.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===I.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===I.SetRowHiddenCommand.id||r===I.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===I.SetSpecificColsVisibleCommand.id||r===I.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id||r===I.DeltaColumnWidthCommand.id||r===I.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,a=r===I.DeltaRowHeightCommand.id||r===I.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=I.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,n),l=[],g=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);l.push(...p),g.push(...h)}),l.length===0&&g.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:d,redo:p,objects:h}=u;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,p=u.redo,h=u.objects;o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:d,objects:h,type:m.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:a=m.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:g,drawingId:u}=t,{from:d,to:p}=o,{row:h,column:f}=d,{row:S,column:w}=p;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:C,startColumn:M,endColumn:T}=i;let y=null,R=null;if(r===0&&h>=_&&S<=C)if(f>=M&&w<=T)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(o,s,M,T,a);y=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===1&&f>=M&&w<=T)if(h>=_&&S<=C)n.push({unitId:l,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(o,s,_,C,a);y=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(o,s,_,C,a);y=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(o,s,M,T,a);y=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}if(y!=null&&R!=null){const v=K(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=H({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=d;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=p,{row:_,column:C}=S,{row:M,column:T}=w;for(let y=0;y<t.length;y++){const R=t[y],{startRow:v,endRow:k,startColumn:O,endColumn:W}=R;if(T<O)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(C>=O&&C<=W){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:W,startRow:S.row,endRow:w.row});if(j==null)return;L={...h,left:j.startX}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...d,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(C>=O&&T<=W)continue;let A=null,P=null;if(C>=O&&C<=W){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:W,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:(D==null?void 0:D.startX)||0,width:((h==null?void 0:h.width)||0)-D.endX+D.startX}}else if(T>=O&&T<=W){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:T,startRow:S.row,endRow:w.row});if(D==null)return;P={...h,left:D.startX-((h==null?void 0:h.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:W,startRow:S.row,endRow:w.row});if(D==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-D.endX+D.startX},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...d,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...d,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:a}=e,s=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:m.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:a,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=d;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:w}=p,{row:_,column:C}=S,{row:M,column:T}=w;for(let y=0;y<t.length;y++){const R=t[y],{startRow:v,endRow:k,startColumn:O,endColumn:W}=R;if(M<v)continue;if(f===m.SheetDrawingAnchorType.Position){let D=null,L=null;if(_>=v&&_<=k){const j=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:k});if(j==null)return;L={...h,top:j.startY}}if(L!=null&&(D=H(L,this._selectionRenderService),D!=null&&L!=null)){n.push({...d,sheetTransform:D,transform:L});break}this._remainDrawingSize(h,n,d);continue}if(_>=v&&M<=k)continue;let A=null,P=null;if(_>=v&&_<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:k});if(D==null)return;P={...h,top:(D==null?void 0:D.startY)||0,height:((h==null?void 0:h.height)||0)-D.endY+D.startY}}else if(M>=v&&M<=k){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:M});if(D==null)return;P={...h,top:D.startY-((h==null?void 0:h.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:k});if(D==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-D.endY+D.startY},A=H(P,this._selectionRenderService),A!=null&&P!=null){o.push({...d,sheetTransform:A,transform:P});break}}if(P!=null&&(A=H(P,this._selectionRenderService)),P!=null&&A!=null){n.push({...d,sheetTransform:A,transform:P});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,n),l=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),g.push(...d)}return{redos:a,undos:s,preRedos:l,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(a=>{const s=n[a],{sheetTransform:l,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=s;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,s);else{const{from:d,to:p}=l,{row:h,column:f}=d,{row:S,column:w}=p;for(let _=0;_<t.length;_++){const C=t[_],{startRow:M,endRow:T,startColumn:y,endColumn:R}=C;if(S<M||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=M&&S>=T||f<=y&&w>=R)){this._remainDrawingSize(g,o,s);continue}const v=K({...l},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...s,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=I.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var M,T;const{toRange:r,fromRange:t}=i,e=I.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,a=(T=(M=this._renderManagerService.getRenderById(n))==null?void 0:M.with(b.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=b.attachRangeWithCoord(a,t);if(!s)return{redos:[],undos:[]};const{startX:l,endX:g,startY:u,endY:d}=s,p=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(p).forEach(y=>{const R=p[y];if(R.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=R;if(!v)return;const{left:k=0,top:O=0,width:W=0,height:A=0}=v,{drawingStartX:P,drawingEndX:D,drawingStartY:L,drawingEndY:j}={drawingStartX:k,drawingEndX:k+W,drawingStartY:O,drawingEndY:O+A};l<=P&&D<=g&&u<=L&&j<=d&&h.push(R)});const f=[],S=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,C=h.map(y=>{const R=y.sheetTransform,v={to:{...R.to,row:R.to.row+w,column:R.to.column+_},from:{...R.from,row:R.from.row+w,column:R.from.column+_}},k=K(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:y.drawingId,transform:k,sheetTransform:v}});if(C.length){const y=this._sheetDrawingService.getBatchUpdateOp(C),{undo:R,redo:v,objects:k}=y;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:v,objects:k,type:m.DrawingApplyType.UPDATE}}),S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:R,objects:k,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startRow,s=o.endRow,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let C,M;if(r==="insert"){const y=this._expandRow(S,w,a,s,_);C=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:R}=S,{row:v}=y,{row:k}=R;if(_===m.SheetDrawingAnchorType.Both&&v>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(S,w,a,s,_);C=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!C||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:C};d.push(T)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_moveColInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),d=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let C,M;if(r==="insert"){const y=this._expandCol(S,w,a,s,_);C=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:R}=S,{column:v}=y,{column:k}=R;if(_===m.SheetDrawingAnchorType.Both&&v>=a&&k<=s)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(S,w,a,s,_);C=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!C||!M)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:M,sheetTransform:C};d.push(T)}),d.length===0&&p.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:f,redo:S,objects:w}=h;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,S=h.redo,w=h.objects;l.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:l,undos:g}}_expandCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:a.row,endRow:s.row});if(p==null)return;d={...r,left:(r.left||0)+p.endX-p.startX},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g+o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{column:l}=a,{column:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,column:l-o},to:{...s,column:g-o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:g-o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,left:(r.left||0)-i.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:l-1,startRow:a.row,endRow:s.row});if(p==null)return;d={...r,left:(r.left||0)-p.endX+p.startX-i.from.columnOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:a.row,endRow:s.row});if(p==null)return;u={from:{...a},to:{...s,column:t-1,columnOffset:p.endX-p.startX}},d=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:a.column,endColumn:s.column});if(p==null)return;d={...r,top:(r.top||0)+p.endY-p.startY},u=H(d,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g+o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(i,r,t,e,n=m.SheetDrawingAnchorType.Position){const o=e-t+1,{from:a,to:s}=i,{row:l}=a,{row:g}=s;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};let u=null,d=null;if(l>e)u={from:{...a,row:l-o},to:{...s,row:g-o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=t&&g<=e)return null;if(l<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:g-o}},d=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:H({...r},this._selectionRenderService),newTransform:r};else if(l>=t&&l<=e){if(l===t)d={...r,top:(r.top||0)-i.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:l-1,startColumn:a.column,endColumn:s.column});if(p==null)return;d={...r,top:(r.top||0)-p.endY+p.startY-i.from.rowOffset}}u=H(d,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...a},to:{...s,row:t-1,rowOffset:p.endY-p.startY}},d=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===I.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=i.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:t}=this._context;if(i){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(o=>{const a=n[o].data;a!=null&&Object.keys(a).forEach(s=>{e===i&&t.push(a[s])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(i,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(o=>{const a=t[o];a!=null&&Object.keys(a).forEach(s=>{const l=a[s].data;l!=null&&Object.keys(l).forEach(g=>{if(o===i&&s===r){const u=l[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(l[g])}else n.push(l[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{yn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:l,anchorType:g=m.SheetDrawingAnchorType.Position}=a;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:p,column:h}=u,{row:f,column:S}=d;for(let w=0;w<t.length;w++){const _=t[w],{startRow:C,endRow:M,startColumn:T,endColumn:y}=_;if(c.Rectangle.intersects({startRow:C,endRow:M,startColumn:T,endColumn:y},{startRow:p,endRow:f,startColumn:h,endColumn:S})||p>M||h>y){const R=g===m.SheetDrawingAnchorType.Position,v=K(s,this._selectionRenderService,this._skeletonManagerService);n.push({...a,transform:{...v,width:R?l==null?void 0:l.width:v==null?void 0:v.width,height:R?l==null?void 0:l.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};Ct=In([fe(1,B.IRenderManagerService),fe(2,c.ICommandService),fe(3,b.ISheetSelectionRenderService),fe(4,c.Inject(b.SheetSkeletonManagerService)),fe(5,c.Inject(I.SheetInterceptorService)),fe(6,m.ISheetDrawingService),fe(7,U.IDrawingManagerService),fe(8,c.IUniverInstanceService)],Ct);var ie=function(){return ie=Object.assign||function(i){for(var r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},ie.apply(this,arguments)},Dn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},Nt=ne.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,a=Dn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),l=ne.useRef("_".concat(Rn()));return kt(t,"".concat(e),{defIds:t.defIds,idSuffix:l.current},ie({ref:r,className:s},a),o)});function kt(i,r,t,e,n){return ne.createElement(i.tag,ie(ie({key:r},Mn(i,t,n)),e),(Tn(i,t).children||[]).map(function(o,a){return kt(o,"".concat(r,"-").concat(i.tag,"-").concat(a),t,void 0,n)}))}function Mn(i,r,t){var e=ie({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1),i.tag==="mask"&&e.id&&(e.id=e.id+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];a==="mask"&&typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))});var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Tn(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?ie(ie({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?ie(ie({},n),{attrs:ie(ie({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function Rn(){return Math.random().toString(36).substring(2,8)}Nt.displayName="UniverIcon";var bn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},Bt=ne.forwardRef(function(i,r){return ne.createElement(Nt,Object.assign({},i,{id:"add-image-single",ref:r,icon:bn}))});Bt.displayName="AddImageSingle";const yt={id:"sheet.command.delete-drawing",type:c.CommandType.COMMAND,handler:i=>{const r=i.get(c.ICommandService),e=i.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:g,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:g,drawingType:u}});return r.executeCommand(ve.id,{unitId:n,drawings:o})}},Ce={id:"sheet.command.move-drawing",type:c.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(c.ICommandService),e=i.get(m.ISheetDrawingService),n=i.get(b.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:d}=u;if(d==null)return null;const p={...d},{left:h=0,top:f=0}=d;return o===c.Direction.UP?p.top=f-1:o===c.Direction.DOWN?p.top=f+1:o===c.Direction.LEFT?p.left=h-1:o===c.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:H(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Pe.id,{unitId:s,drawings:l})?(t.syncExecuteCommand(G.id,[s]),!0):!1}},Wt="addition-and-subtraction-single",Dt="sheet.menu.image";function En(i){return{id:Dt,type:Y.MenuItemType.SUBITEMS,icon:Wt,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[I.WorkbookEditablePermission],worksheetTypes:[I.WorksheetEditPermission],rangeTypes:[I.RangeProtectionPermissionEditPoint]})}}function On(i){return{id:Ue.id,title:"sheetImage.upload.float",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}function Pn(i){return{id:It.id,title:"sheetImage.upload.cell",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET)}}const Se={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelColumn:"univer-image-common-panel-column"},An=i=>{var M;const r=Y.useDependency(c.ICommandService),t=Y.useDependency(c.LocaleService),e=Y.useDependency(U.IDrawingManagerService),n=Y.useDependency(B.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=n.getRenderById(s),g=l==null?void 0:l.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,p]=ne.useState(!0),h=(M=a.anchorType)!=null?M:m.SheetDrawingAnchorType.Position,[f,S]=ne.useState(h);function w(T,y){const R=[];return T.forEach(v=>{const{oKey:k}=v,O=y.getDrawingOKey(k);if(O==null)return R.push(null),!0;const{unitId:W,subUnitId:A,drawingId:P,drawingType:D,anchorType:L,sheetTransform:j}=O;R.push({unitId:W,subUnitId:A,drawingId:P,anchorType:L,sheetTransform:j,drawingType:D})}),R}ne.useEffect(()=>{const T=u.clearControl$.subscribe(R=>{R===!0&&p(!1)}),y=u.changeStart$.subscribe(R=>{var O;const{objects:v}=R,k=w(v,e);if(k.length===0)p(!1);else if(k.length>=1){p(!0);const W=((O=k[0])==null?void 0:O.anchorType)||m.SheetDrawingAnchorType.Position;S(W)}});return()=>{y.unsubscribe(),T.unsubscribe()}},[]);function _(T){S(T);const y=e.getFocusDrawings();if(y.length===0)return;const R=y.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));r.executeCommand(Pe.id,{unitId:y[0].unitId,drawings:R})}const C=T=>T?"block":"none";return x.jsxs("div",{className:Z.clsx(Se.imageCommonPanelGrid,Se.imageCommonPanelBorder),style:{display:C(d)},children:[x.jsx("div",{className:Se.imageCommonPanelRow,children:x.jsx("div",{className:Z.clsx(Se.imageCommonPanelColumn,Se.imageCommonPanelTitle),children:x.jsx("div",{children:t.t("drawing-anchor.title")})})}),x.jsx("div",{className:Z.clsx(Se.imageCommonPanelRow),children:x.jsx("div",{className:Z.clsx(Se.imageCommonPanelColumn),children:x.jsxs(Z.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[x.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),x.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),x.jsx(Z.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Un=()=>{const i=Y.useDependency(U.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=ne.useState(r);return ne.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&x.jsxs("div",{className:Se.imageCommonPanel,children:[x.jsx(pe.DrawingCommonPanel,{drawings:t}),x.jsx(An,{drawings:t})]})},Nn={[Y.RibbonStartGroup.FORMULAS_INSERT]:{[Dt]:{order:3,menuItemFactory:En,[Ue.id]:{order:0,menuItemFactory:On},[It.id]:{order:1,menuItemFactory:Pn}}}};function Be(i){return!i.getContextValue(c.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(c.EDITOR_ACTIVATED)&&!i.getContextValue(c.FOCUSING_PANEL_EDITOR)&&i.getContextValue(c.FOCUSING_COMMON_DRAWINGS)}const kn={id:Ce.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:Be,staticParameters:{direction:c.Direction.DOWN}},Bn={id:Ce.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:Be,staticParameters:{direction:c.Direction.UP}},Wn={id:Ce.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:Be,staticParameters:{direction:c.Direction.LEFT}},jn={id:Ce.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:Be,staticParameters:{direction:c.Direction.RIGHT}},Ln={id:yt.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:Be,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var Yn=Object.getOwnPropertyDescriptor,$n=(i,r,t,e)=>{for(var n=e>1?void 0:e?Yn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},ye=(i,r)=>(t,e)=>r(t,e,i);let et=class extends c.Disposable{constructor(i,r,t,e,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Wt,Bt)),this.disposeWithMe(i.register(Et,Un))}_initMenus(){this._menuManagerService.mergeMenu(Nn)}_initCommands(){[Ue,It,Oe,ve,Pe,ht,G,pt,St,_t,Ce,yt,wt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,Bn,Wn,jn,Ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=$n([ye(0,c.Inject(Y.ComponentManager)),ye(1,Y.IMenuManagerService),ye(2,c.ICommandService),ye(3,Y.IShortcutService),ye(4,U.IDrawingManagerService),ye(5,c.Inject(I.SheetsSelectionsService))],et);var Fn=Object.getOwnPropertyDescriptor,Gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Fn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},_e=(i,r)=>(t,e)=>r(t,e,i);function Hn(i,r,t,e,n){const{scaleX:o,scaleY:a}=r.getAncestorScale(),s=r.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN),l=e.getFreeze(),{startColumn:g,startRow:u,xSplit:d,ySplit:p}=l,h={left:!0,top:!0};if(!s)return{...i,absolute:h};const{left:f,right:S,top:w,bottom:_}=i;let{top:C,left:M,viewportScrollX:T,viewportScrollY:y}=s;const{boundsOfViewArea:R,scrollDirectionResponse:v}=n||{},{rowHeaderWidth:k,columnHeaderHeight:O}=t,W={top:O,left:k};R&&(c.Tools.isDefine(W.top)&&(W.top=R.top),c.Tools.isDefine(W.left)&&(W.left=R.left)),v==="HORIZONTAL"&&(y=0),v==="VERTICAL"&&(T=0);let A=0,P=0;const D=t.rowStartY(u-p)+O,L=t.colStartX(g-d)+k,j=t.rowStartY(u)+O,z=t.colStartX(g)+k;if(d===0)h.left=!1,A=(f-T)*o,P=(S-T)*o;else{const te=f-(L-k),J=S-(L-k);S<z?(A=te*o,P=J*o):f<=z&&S>=z?(A=te*o,P=Math.max(M,(S-T)*o)):f>z&&(h.left=!1,A=Math.max((f-T)*o,M),P=Math.max((S-T)*o,M))}let X=0,q=0;if(p===0)h.top=!1,X=(w-y)*a,q=(_-y)*a;else{const te=w-(D-O),J=_-(D-O);_<j?(X=te*a,q=J*a):w<=j&&_>=j?(X=te*a,q=Math.max(C,(_-y)*a)):w>j&&(h.top=!1,X=Math.max((w-y)*a,C),q=Math.max((_-y)*a,C))}return A=Math.max(A,W.left),X=Math.max(X,W.top),P=Math.max(P,W.left),q=Math.max(q,W.top),{left:A,right:P,top:X,bottom:q,absolute:h}}const le=(i,r,t,e,n)=>{const{scene:o}=r,{left:a,top:s,width:l,height:g,angle:u}=i,d={left:a,right:a+l,top:s,bottom:s+g},p=Hn(d,o,t,e,n),{scaleX:h,scaleY:f}=o.getAncestorScale();return{startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:u,width:l*h,height:g*f,absolute:p.absolute}};E.SheetCanvasFloatDomManagerService=class extends c.Disposable{constructor(t,e,n,o,a,s,l){super();ee(this,"_domLayerMap",new Map);ee(this,"_domLayerInfoMap",new Map);ee(this,"_transformChange$",new N.Subject);ee(this,"transformChange$",this._transformChange$.asObservable());ee(this,"_add$",new N.Subject);ee(this,"add$",this._add$.asObservable());ee(this,"_remove$",new N.Subject);ee(this,"remove$",this._remove$.asObservable());ee(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===c.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var se,ce,Q;const{unitId:n,subUnitId:o,drawingId:a}=e,s=I.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,c.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!l||!s)return;const d=(se=this._renderManagerService.getRenderById(n))==null?void 0:se.with(b.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:p,drawingType:h,data:f}=l;if(h!==c.DrawingTypeEnum.DRAWING_DOM&&h!==c.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:_}=S;if(p==null)return!0;if(u!==o)return;const{left:C,top:M,width:T,height:y,angle:R,flipX:v,flipY:k,skewX:O,skewY:W}=p,A=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),P=w.getObject(A);if(P!=null){P.transformByState({left:C,top:M,width:T,height:y,angle:R,flipX:v,flipY:k,skewX:O,skewY:W});return}const D={left:C,top:M,width:T,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},L=h===c.DrawingTypeEnum.DRAWING_CHART;if(L){const F=f?f.backgroundColor:"white";D.fill=F,D.rotateEnabled=!1,f&&f.border&&(D.stroke=f.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const j=new B.Rect(A,D);L&&j.setObjectType(B.ObjectType.CHART),w.addObject(j,B.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&w.attachTransformerTo(j);const z=this._ensureMap(n,o),X=new c.DisposableCollection,q=le(j,S.renderUnit,d.skeleton,s.worksheet),ae=new N.BehaviorSubject(q),te={dispose:X,rect:j,position$:ae,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:l.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},props:(Q=(ce=z.get(a))==null?void 0:ce.props)!=null?Q:this._getFloatDomProps(a),data:f,unitId:n});const J=j.onTransformChange$.subscribeEvent(()=>{const F=le(j,S.renderUnit,d.skeleton,s.worksheet);ae.next(F)});X.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),J&&X.add(J),this._domLayerInfoMap.set(a,te),z.set(a,{...z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:a}=e,s=U.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(n);if(l==null)return;const{transformer:g,scene:u}=l,d=u.getObject(s);d!=null&&d.oKey&&g.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,n),s=Array.from(a.keys()),l=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),g=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(b.SheetSkeletonManagerService).getSkeletonParam(n);!o||!l||!g||s.forEach(d=>{const p=this._domLayerInfoMap.get(d);if(p){const h=le(p.rect,o.renderUnit,g.skeleton,l.worksheet,p);p.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?c.fromEventSubject(e.render.scene.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:o}=e;t(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,o;if(e.id===b.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(n=this._domLayerMap.get(s))==null?void 0:n.keys())!=null?o:[]).forEach(g=>{t(s,g)})}else if(e.id===I.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;t(a,s)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:a,endY:s}=t,l=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(b.ISheetSelectionRenderService);if(l==null)return;const g=l.getCellWithCoordByOffset(n,a);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:a-g.startY},d=l.getCellWithCoordByOffset(o,s);if(d==null)return;const p={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==c.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==c.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(t);if(a&&s){const{scene:l}=s,g=U.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=l.getObject(g);u&&u instanceof B.Rect&&u.setProps(o)}}addFloatDomToPosition(t,e){const n=I.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=n,{initPosition:s,componentKey:l,data:g,allowTransform:u=!0}=t,d=e!=null?e:c.generateRandomId(),p=this._getPosition(s,o);if(p==null)return;this._ensureMap(o,a).set(d,t);const f={unitId:o,subUnitId:a,drawingId:d,drawingType:t.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:a}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(n.rect),e){this._ensureMap(o,a).delete(t);const g=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:t});if(!g)return;const u=this._sheetDrawingService.getBatchRemoveOp([g]),{redo:d,objects:p}=u;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:d,objects:p,type:m.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}addFloatDomToRange(t,e,n,o){var k,O,W,A,P;const a=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a,g=this._getSceneAndTransformerByDrawingSearch(s);if(!g)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(k=this._renderManagerService.getRenderById(s))==null?void 0:k.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,d.skeleton);if(this._getPosition(w,s)==null)return;this._ensureMap(s,l).set(S,e);const T=g.scene,{scaleX:y}=T.getAncestorScale(),R=tt(w,n,y),v={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:R.startX,top:R.startY,width:R.width,height:R.height},data:h,allowTransform:f};{const{unitId:D,subUnitId:L,drawingId:j}=v,z=I.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:L}),X=v,q=this._univerInstanceService.getUnit(D,c.UniverInstanceType.UNIVER_SHEET);if(!q)return;const ae=q.getActiveSheet().getSheetId();if(!X||!z)return;const te=(O=this._renderManagerService.getRenderById(D))==null?void 0:O.with(b.SheetSkeletonManagerService);if(!te)return;const J=te.getWorksheetSkeleton(L);if(!J)return;const{transform:se,drawingType:ce,data:Q}=X;if(ce!==c.DrawingTypeEnum.DRAWING_DOM&&ce!==c.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(D);if(F==null)return;const{scene:De,canvas:Me}=F;if(se==null||ae!==L)return;const{left:rt,top:it,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Te}=se,dt=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),ue=De.getObject(dt);if(ue!=null){ue.transformByState({left:rt,top:it,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Te});return}const oe={left:rt,top:it,width:ot,height:at,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1},Re=ce===c.DrawingTypeEnum.DRAWING_CHART;if(Re){const $=Q?Q.backgroundColor:"white";oe.fill=$,oe.rotateEnabled=!1,Q&&Q.border&&(oe.stroke=Q.border),oe.paintFirst="stroke",oe.strokeWidth=1,oe.borderEnabled=!1,oe.radius=8}const de=new B.Rect(dt,oe);Re&&de.setObjectType(B.ObjectType.CHART),De.addObject(de,B.DRAWING_OBJECT_LAYER_INDEX),X.allowTransform!==!1&&De.attachTransformerTo(de);const je=this._ensureMap(D,L),ge=new c.DisposableCollection,lt=De.getMainViewport(),{rowHeaderWidth:be,columnHeaderHeight:Le}=J.skeleton,ut={top:Le,left:be,bottom:lt.bottom,right:lt.right},he={dispose:ge,rect:de,boundsOfViewArea:ut,domAnchor:n,unitId:D,subUnitId:L},V=le(de,F.renderUnit,J.skeleton,z.worksheet,he),Ee=new N.BehaviorSubject(V);he.position$=Ee;let Ye={position$:Ee,id:j,componentKey:X.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Me.dispatchEvent(new WheelEvent($.type,$))},props:(A=(W=je.get(j))==null?void 0:W.props)!=null?A:this._getFloatDomProps(j),data:Q,unitId:D};e.eventPassThrough&&(Ye={...Ye,onPointerDown:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Me.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Me.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Ye),this.disposeWithMe(_.subscribe($=>{var Yt,$t,Ft,Gt;const Lt=tt({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Yt=n.width)!=null?Yt:$.width,height:($t=n.height)!=null?$t:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Zn=U.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:L,drawingId:j}),qn=new B.Rect(Zn,{left:Lt.startX,top:Lt.startY,width:(Ft=n.width)!=null?Ft:$.width,height:(Gt=n.height)!=null?Gt:$.height,zIndex:this._drawingManagerService.getDrawingOrder(D,L).length-1}),Jn=le(qn,F.renderUnit,J.skeleton,z.worksheet,he);Ee.next(Jn)}));const $e=(P=this._renderManagerService.getRenderById(D))==null?void 0:P.with(b.SheetSkeletonManagerService);$e==null||$e.currentSkeleton$.subscribe($=>{$&&J.sheetId!==$.sheetId&&this._removeDom(S,!0)});const gt=de.onTransformChange$.subscribeEvent(()=>{const $=le(de,F.renderUnit,J.skeleton,z.worksheet,he);Ee.next($)});ge.add(()=>{this._canvasFloatDomService.removeFloatDom(j)}),gt&&ge.add(gt),this._domLayerInfoMap.set(j,he),je.set(j,{...je.get(j)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var R,v,k,O,W;const a=I.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(R=this._renderManagerService.getRenderById(s))==null?void 0:R.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!d)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,S=o!=null?o:c.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,d.skeleton),C=w;if(C.startY=0,this._getPosition(w,s)==null)return;this._ensureMap(s,l).set(S,e);const y={unitId:s,subUnitId:l,drawingId:S,drawingType:e.type||c.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:C.startX,top:C.startY,width:C.width,height:C.height},data:h,allowTransform:f};{const{unitId:A,subUnitId:P,drawingId:D}=y,L=I.getSheetCommandTarget(this._univerInstanceService,{unitId:A,subUnitId:P}),j=y,z=this._univerInstanceService.getUnit(A,c.UniverInstanceType.UNIVER_SHEET);if(!z)return;const X=z.getActiveSheet().getSheetId();if(!j||!L)return;const q=(v=this._renderManagerService.getRenderById(A))==null?void 0:v.with(b.SheetSkeletonManagerService);if(!q)return;const ae=q.getWorksheetSkeleton(P);if(!ae)return;const{transform:te,data:J}=j,se=this._getSceneAndTransformerByDrawingSearch(A);if(se==null)return;const{scene:ce,canvas:Q}=se;if(te==null||X!==P)return;const{left:F,top:De,width:Me,height:rt,angle:it,flipX:ot,flipY:at,skewX:Tt,skewY:Rt}=te,st=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),ct=ce.getObject(st);if(ct!=null){ct.transformByState({left:F,top:De,width:Me,height:rt,angle:it,flipX:ot,flipY:at,skewX:Tt,skewY:Rt});return}const Te=tt({startX:C.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),dt={left:Te.startX,top:Te.startY,width:Te.width,height:Te.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1},ue=new B.Rect(st,dt);ce.addObject(ue,B.DRAWING_OBJECT_LAYER_INDEX),j.allowTransform!==!1&&ce.attachTransformerTo(ue);const oe=this._ensureMap(A,P),Re=new c.DisposableCollection,de=ce.getMainViewport(),je={top:0,left:de.left,bottom:de.bottom,right:de.right},ge={dispose:Re,rect:ue,unitId:A,subUnitId:P,boundsOfViewArea:je,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},lt=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge),be=new N.BehaviorSubject(lt);ge.position$=be;let Le={position$:be,id:D,componentKey:j.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{Q.dispatchEvent(new WheelEvent(V.type,V))},props:(O=(k=oe.get(D))==null?void 0:k.props)!=null?O:this._getFloatDomProps(D),data:J,unitId:A};e.eventPassThrough&&(Le={...Le,onPointerDown:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{Q.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(Le);const ut=ue.onTransformChange$.subscribeEvent(()=>{const V=le(ue,se.renderUnit,ae.skeleton,L.worksheet,ge);be.next(V)});this.disposeWithMe(_.subscribe(V=>{const Ee=tt({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Ye=U.getDrawingShapeKeyByDrawingSearch({unitId:A,subUnitId:P,drawingId:D}),$e=new B.Rect(Ye,{left:Ee.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(A,P).length-1}),gt=le($e,se.renderUnit,ae.skeleton,L.worksheet,ge);be.next(gt)}));const he=(W=this._renderManagerService.getRenderById(A))==null?void 0:W.with(b.SheetSkeletonManagerService);he==null||he.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),Re.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),ut&&Re.add(ut),this._domLayerInfoMap.set(D,ge),oe.set(D,{...oe.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:a}=t;const s=We(o,a,n),l=new N.BehaviorSubject(s),g=We(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const _=We(o,a,n),C=We(t.endRow,t.endColumn,n);l.next(_),u.next(C)},p=new c.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>d())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===I.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){d();return}(I.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const h=(_,C)=>{o=_,a=C,d()},f=()=>({rotate:0,width:g.right-s.left,height:g.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:g.right,endY:g.bottom}),S=l.pipe(N.map(_=>{const C=We(t.endRow,t.endColumn,n);return{rotate:0,width:C.right-_.left,height:C.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:C.right,endY:C.bottom}})),w=f();return{position$:S,position:w,updateRowCol:h,topLeftPos$:l,rightBottomPos$:u,disposable:p}}},E.SheetCanvasFloatDomManagerService=Gn([_e(0,c.Inject(B.IRenderManagerService)),_e(1,c.IUniverInstanceService),_e(2,c.Inject(c.ICommandService)),_e(3,U.IDrawingManagerService),_e(4,c.Inject(Y.CanvasFloatDomService)),_e(5,m.ISheetDrawingService),_e(6,c.Inject(c.LifecycleService))],E.SheetCanvasFloatDomManagerService);function We(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function tt(i,r,t){var g,u;t=t!=null?t:1;const e=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:e,a=(u=r==null?void 0:r.height)!=null?u:n;let s=0,l=0;if(r){if(r.horizonOffsetAlign==="right"){const d=nt(r.marginX,e*t);s=i.endX-d-o}else s=i.startX+nt(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const d=nt(r.marginY,n*t);l=i.endY-d-a}else l=i.startY+nt(r.marginY,n)}return{rotate:0,startX:s,startY:l,endX:i.endX,endY:i.endY,width:o,height:a,absolute:{left:i.absolute.left,top:i.absolute.top}}}function nt(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}var Vn=Object.defineProperty,Xn=Object.getOwnPropertyDescriptor,xn=(i,r,t)=>r in i?Vn(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Kn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Xn(r,t):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(n=a(n)||n);return n},Mt=(i,r)=>(t,e)=>r(t,e,i),jt=(i,r,t)=>xn(i,typeof r!="symbol"?r+"":r,t);const zn="SHEET_IMAGE_UI_PLUGIN";E.UniverSheetsDrawingUIPlugin=class extends c.Plugin{constructor(r=bt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...a}=c.merge({},bt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ht,a)}onStarting(){c.registerDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService],[et],[He],[Qe],[qe],[Ze],[xe],[Ke],[ze]]),c.touchDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService]])}onReady(){c.touchDependencies(this._injector,[[Ze],[ze]])}onRendered(){this._registerRenderModules(),c.touchDependencies(this._injector,[[qe],[Qe],[et],[xe],[Ke]])}onSteady(){this._injector.get(He)}_registerRenderModules(){[[E.SheetDrawingUpdateController],[Ct],[ft],[mt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}},jt(E.UniverSheetsDrawingUIPlugin,"type",c.UniverInstanceType.UNIVER_SHEET),jt(E.UniverSheetsDrawingUIPlugin,"pluginName",zn),E.UniverSheetsDrawingUIPlugin=Kn([c.DependentOn(U.UniverDrawingPlugin,we.UniverDocsDrawingPlugin,pe.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),Mt(1,c.Inject(c.Injector)),Mt(2,B.IRenderManagerService),Mt(3,c.IConfigService)],E.UniverSheetsDrawingUIPlugin),E.ClearSheetDrawingTransformerOperation=G,E.DeleteDrawingsCommand=yt,E.EditSheetDrawingOperation=pt,E.GroupSheetDrawingCommand=St,E.InsertFloatImageCommand=Ue,E.InsertSheetDrawingCommand=Oe,E.MoveDrawingsCommand=Ce,E.RemoveSheetDrawingCommand=ve,E.SHEETS_IMAGE_MENU_ID=Dt,E.SetDrawingArrangeCommand=wt,E.SetSheetDrawingCommand=Pe,E.SidebarSheetDrawingOperation=ht,E.UngroupSheetDrawingCommand=_t,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.6.10-nightly.
|
|
3
|
+
"version": "0.6.10-nightly.202504151606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@univerjs/icons": "^0.2.35",
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/docs-
|
|
65
|
-
"@univerjs/drawing-ui": "0.6.10-nightly.
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
69
|
-
"@univerjs/sheets-
|
|
70
|
-
"@univerjs/ui": "0.6.10-nightly.
|
|
71
|
-
"@univerjs/sheets-
|
|
61
|
+
"@univerjs/design": "0.6.10-nightly.202504151606",
|
|
62
|
+
"@univerjs/core": "0.6.10-nightly.202504151606",
|
|
63
|
+
"@univerjs/docs-ui": "0.6.10-nightly.202504151606",
|
|
64
|
+
"@univerjs/docs-drawing": "0.6.10-nightly.202504151606",
|
|
65
|
+
"@univerjs/drawing-ui": "0.6.10-nightly.202504151606",
|
|
66
|
+
"@univerjs/drawing": "0.6.10-nightly.202504151606",
|
|
67
|
+
"@univerjs/engine-render": "0.6.10-nightly.202504151606",
|
|
68
|
+
"@univerjs/sheets": "0.6.10-nightly.202504151606",
|
|
69
|
+
"@univerjs/sheets-ui": "0.6.10-nightly.202504151606",
|
|
70
|
+
"@univerjs/ui": "0.6.10-nightly.202504151606",
|
|
71
|
+
"@univerjs/sheets-drawing": "0.6.10-nightly.202504151606"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"less": "^4.3.0",
|