@univerjs/sheets-drawing-ui 0.5.5-nightly.202501210925 → 0.5.5-nightly.202501220324

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/umd/index.js CHANGED
@@ -1,9 +1 @@
1
- (function(O,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),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","@univerjs/docs-ui","@univerjs/design"],l):(O=typeof globalThis<"u"?globalThis:O||self,l(O.UniverSheetsDrawingUi={},O.UniverCore,O.UniverDocsDrawing,O.UniverDrawing,O.UniverDrawingUi,O.UniverEngineRender,O.UniverSheetsDrawing,O.UniverSheetsUi,O.UniverUi,O.rxjs,O.UniverSheets,O.React,O.UniverDocsUi,O.UniverDesign))})(this,function(O,l,Se,P,ge,N,w,b,$,W,v,J,bt,ee){"use strict";var hi=Object.defineProperty;var mi=(O,l,Se)=>l in O?hi(O,l,{enumerable:!0,configurable:!0,writable:!0,value:Se}):O[l]=Se;var z=(O,l,Se)=>mi(O,typeof l!="symbol"?l+"":l,Se);const Kt="sheets-drawing-ui.config",Et={},H={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(N.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ce={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,R;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(v.SheetInterceptorService),o=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:a}=i,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const c=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=t.onCommandExecute({id:Ce.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:d,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},Ot="COMPONENT_SHEET_DRAWING_PANEL",ht={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{const n=r.get($.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!v.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ot},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},mt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(r,i)=>{const n=r.get(l.ICommandService);return i==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[i]),n.executeCommand(ht.id,{value:"open"}),!0)}};var pt={exports:{}},Pe={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var Pt;function zt(){if(Pt)return Pe;Pt=1;var r=J,i=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(s,c,m){var u,d={},h=null,g=null;m!==void 0&&(h=""+m),c.key!==void 0&&(h=""+c.key),c.ref!==void 0&&(g=c.ref);for(u in c)e.call(c,u)&&!o.hasOwnProperty(u)&&(d[u]=c[u]);if(s&&s.defaultProps)for(u in c=s.defaultProps,c)d[u]===void 0&&(d[u]=c[u]);return{$$typeof:i,type:s,key:h,ref:g,props:d,_owner:t.current}}return Pe.Fragment=n,Pe.jsx=a,Pe.jsxs=a,Pe}var At;function Jt(){return At||(At=1,pt.exports=zt()),pt.exports}var x=Jt();const Fe={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Zt=()=>{const r=l.useDependency(P.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=J.useState(0);return J.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),x.jsx("div",{style:{display:n>0?"block":"none"},className:Fe.uploadLoading,children:x.jsxs("div",{className:Fe.uploadLoadingBody,children:[x.jsx("div",{className:Fe.uploadLoadingBodyAnimation}),x.jsx("div",{className:Fe.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var qt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,i,n,e)=>{for(var t=e>1?void 0:e?Qt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&qt(i,n,t),t},he=(r,i)=>(n,e)=>i(n,e,r);let $e=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,c){super();z(this,"_initImagePopupMenu",new Set);this._injector=i,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent($.BuiltInUIPart.CONTENT,()=>l.connectInjector(Zt,this._injector))}_dispose(i){const n=i.getUnitId();this._renderManagerService.removeRender(n)}_create(i){if(!i)return;const n=i.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(i){const n=i.getAllObjectsByOrder();for(const e of n)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(i){var o;const n=(o=this._renderManagerService.getRenderById(i))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const c=s.oKey,m=this._drawingManagerService.getDrawingOKey(c);if(!m)return;const{unitId:u,subUnitId:d,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(i,n,e,t){return[{label:"image-popup.edit",index:0,commandId:mt.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ce.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};$e=en([he(0,l.Inject(l.Injector)),he(1,P.IDrawingManagerService),he(2,l.Inject(b.SheetCanvasPopManagerService)),he(3,N.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject($.IUIPartsService)),he(7,l.ICommandService)],$e);function X(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:c=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const d=b.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=d;const f=n.getCurrentSkeleton(),_=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return h+p>_&&(h=_-p),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:c,skewY:m,left:h,top:g,width:p,height:S}}function V(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:c=0,skewX:m=0,skewY:u=0}=r,d=i.getCellWithCoordByOffset(n,e);if(d==null)return;const h={column:d.actualColumn,columnOffset:N.precisionTo(n-d.startX,1),row:d.actualRow,rowOffset:N.precisionTo(e-d.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:c,skewX:m,skewY:u,from:h,to:p}}var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(r,i,n,e)=>{for(var t=e>1?void 0:e?nn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&tn(i,n,t),t},He=(r,i)=>(n,e)=>i(n,e,r);let ft=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._context=r,this._sheetDrawingService=i,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const r=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const i in r){const n=r[i];for(const e in n.data){const t=n.data[e];t.transform=X(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ft=rn([He(1,w.ISheetDrawingService),He(2,P.IDrawingManagerService),He(3,l.Inject(b.ISheetSelectionRenderService)),He(4,l.Inject(b.SheetSkeletonManagerService))],ft);function on(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,c=N.getGroupState(0,0,t.map(d=>d.transform||{})),m=t.map(d=>{const h=d.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=d;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-c.left,top:h.top-c.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};i.push({parent:u,children:m})}),i}function an(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:c={width:0,height:0}}=e;if(c==null)return;const m=t.map(d=>{const{transform:h}=d,{unitId:g,subUnitId:p,drawingId:S}=d,f=N.transformObjectOutOfGroup(h||{},c,c.width||0,c.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};i.push({parent:u,children:m})}),i}const St={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:an(d),type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}]}),!0):!1}},Ae={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,R;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService),o=r.get(v.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),c=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:d,redo:h,objects:g}=c,p=o.onCommandExecute({id:Ae.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},wt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService);if(!i)return!1;const t=r.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:c}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(c===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):c===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):c===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):c===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:d,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ue={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:o}=i,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:m,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,op:u,objects:d,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}]}),!0):!1}},_t={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:c,undo:m,redo:u,objects:d}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:c,objects:on(d),type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}]}),!0):!1}};var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(r,i,n,e)=>{for(var t=e>1?void 0:e?cn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&sn(i,n,t),t},Z=(r,i)=>(n,e)=>i(n,e,r);function ln(r,i,n){const e=n*Math.PI/180,t=Math.abs(r*Math.cos(e))+Math.abs(i*Math.sin(e)),o=Math.abs(r*Math.sin(e))+Math.abs(i*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ut(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=ln(n,e,t),c=r.get(N.IRenderManagerService).getRenderById(i.unitId);if(!c)return!1;const u=(I=c.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(i.row,i.col),h=d.mergeInfo.endX-d.mergeInfo.startX-2,g=d.mergeInfo.endY-d.mergeInfo.startY-2,p=a/o,f=Math.ceil(Math.min(h,g*p))/a,_=!f||Number.isNaN(f)?.001:f;return{width:n*_,height:e*_}}let Ne=class extends l.Disposable{constructor(i,n,e,t,o,a,s,c,m,u,d,h,g){super();z(this,"_workbookSelections");this._context=i,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=c,this._contextService=m,this._messageService=u,this._localeService=d,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const i=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async insertFloatImageByFile(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const M=I.message;M===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:c,base64Cache:m}=n,{width:u,height:d,image:h}=await P.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(c,s,h);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||d>P.DRAWING_IMAGE_HEIGHT_LIMIT){const I=P.DRAWING_IMAGE_WIDTH_LIMIT/u,M=P.DRAWING_IMAGE_HEIGHT_LIMIT/d;S=Math.max(I,M)}const f=this._getImagePosition(u*S,d*S,g,p);if(f==null)return;const _={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:c,transform:X(f,this._selectionRenderService,this._skeletonManagerService),sheetTransform:f};return this._commandService.executeCommand(Ae.id,{unitId:t,drawings:[_]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(f){const _=f.message;_===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):_===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):_===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:c,image:m}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const d=l.createDocumentModelWithStyle("",{}),h=Ut(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,c,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:bt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(d.apply(S),this._commandService.syncExecuteCommand(v.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const i=this._context.unit,n=i.getActiveSheet(),e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=b.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:c,startRow:m,startX:u,startY:d}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),d+n>t&&(d=t-n,d<0&&(d=0,n=t),h=!0),h){const f=this._selectionRenderService.getCellWithCoordByOffset(u,d);if(f==null)return;u=f.startX,d=f.startY,c=f.actualColumn,m=f.actualRow}const g={column:c,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+i,d+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+i-p.startX,row:p.actualRow,rowOffset:d+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=i;this._commandService.executeCommand(wt.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:c}=e;if(c==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=V({...m.transform,...c},this._selectionRenderService);if(u==null)return;const d={...e,transform:{...m.transform,...c,...X(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(d)}),n.length>0&&this._commandService.executeCommand(Ue.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(St.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(_t.id,i)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};Ne=dn([Z(1,l.Inject(b.SheetSkeletonManagerService)),Z(2,l.ICommandService),Z(3,b.ISheetSelectionRenderService),Z(4,P.IImageIoService),Z(5,$.ILocalFileService),Z(6,w.ISheetDrawingService),Z(7,P.IDrawingManagerService),Z(8,l.IContextService),Z(9,$.IMessageService),Z(10,l.Inject(l.LocaleService)),Z(11,l.Inject(v.SheetsSelectionsService)),Z(12,l.Inject(l.Injector))],Ne);var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,hn=(r,i,n,e)=>{for(var t=e>1?void 0:e?gn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&un(i,n,t),t},we=(r,i)=>(n,e)=>i(n,e,r);function vt(r,i,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],c=Ut(r,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(c)return s.transform.width=c.width,s.transform.height=c.height,s.docTransform.size.width=c.width,s.docTransform.size.height=c.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Ve=class extends l.Disposable{constructor(r,i,n,e,t,o,a){super(),this._commandService=r,this._sheetInterceptorService=i,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let i,n=[];if(r.id===v.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(r.id===v.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===v.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}i&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,i.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:o,col:a},i.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(r=>{r.visible?r.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===bt.ReplaceSnapshotCommand.id&&r.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(v.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(vt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:v.InterceptCellContentPriority.CELL_IMAGE,handler:(r,i,n)=>{var e;return r!=null&&r.p&&((e=r.p.drawingsOrder)!=null&&e.length)&&(r.interceptorStyle||(r.interceptorStyle={}),r.interceptorStyle.tr={a:0}),n(r)}}))}};Ve=hn([we(0,l.ICommandService),we(1,l.Inject(v.SheetInterceptorService)),we(2,l.IUniverInstanceService),we(3,l.Inject(l.Injector)),we(4,P.IDrawingManagerService),we(5,l.Inject(Se.DocDrawingController)),we(6,l.Inject(b.IEditorBridgeService))],Ve);var mn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(r,i,n,e)=>{for(var t=e>1?void 0:e?pn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&mn(i,n,t),t},Nt=(r,i)=>(n,e)=>i(n,e,r);let xe=class extends l.Disposable{constructor(r,i){super(),this._autoFillService=r,this._injector=i,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(r,i,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{vt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};xe=fn([Nt(0,l.Inject(b.IAutoFillService)),Nt(1,l.Inject(l.Injector))],xe);var Sn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,_n=(r,i,n,e)=>{for(var t=e>1?void 0:e?wn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Sn(i,n,t),t},Xe=(r,i)=>(n,e)=>i(n,e,r);let Ke=class extends l.Disposable{constructor(i,n,e,t){super();z(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};Ke=_n([Xe(0,l.Inject(b.HoverManagerService)),Xe(1,l.Inject(N.IRenderManagerService)),Xe(2,l.Inject(v.SheetsSelectionsService)),Xe(3,l.Inject(ge.DrawingRenderService))],Ke);const je={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{var o,a;const e=(o=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ne);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.map(c=>e.insertFloatImageByFile(c));return(await Promise.all(s)).every(c=>c)}else return(a=e.insertFloatImage())!=null?a:!1}},It={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:r=>{var n,e;return(e=(n=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ne).insertCellImage())!=null?e:!1}};var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(r,i,n,e)=>{for(var t=e>1?void 0:e?In(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&vn(i,n,t),t},We=(r,i)=>(n,e)=>i(n,e,r);const jt="image/png";function yn(r){const i=r.split(","),n=atob(i[1]),e=n.length,t=new Uint8Array(e);for(let o=0;o<e;o++)t[o]=n.charCodeAt(o);return new Blob([t],{type:jt})}function Dn(r){const i=new ClipboardItem({[jt]:yn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}function Mn(){function r(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const i=document.activeElement,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),i instanceof HTMLElement&&i.focus()}}const Wt=[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 l.Disposable{constructor(i,n,e,t,o){super();z(this,"_copyInfo");this._sheetClipboardService=i,this._renderManagerService=n,this._drawingService=e,this._clipboardInterfaceService=t,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(i,n,e,t)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(t===b.COPY_TYPE.CUT){const c={unitId:i,drawings:[a]};this._commandService.executeCommand(Ce.id,c)}setTimeout(()=>{const c=Mn();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===P.ImageSourceType.BASE64?Dn(a.source):this._clipboardInterfaceService.writeText(""),c()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(i,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=b.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:c,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:c},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},b.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({undos:[],redos:[]}),onPasteUnrecognized:i=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(i,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:b.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},b.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:je.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(i,n,e){var h;const t=(h=this._renderManagerService.getRenderById(i))==null?void 0:h.with(b.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:c,endY:m}=o,u=this._drawingService.getDrawingData(i,n),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:_=0,width:I=0,height:M=0}=S,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:f,drawingEndX:f+I,drawingStartY:_,drawingEndY:_+M};a<=R&&y<=s&&c<=T&&C<=m&&d.push(p)}),d.length)return{copyRange:e,drawings:d,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(Wt.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,c=this._renderManagerService.getRenderById(o),m=c==null?void 0:c.with(b.SheetSkeletonManagerService),u=c==null?void 0:c.with(b.ISheetSelectionRenderService),d=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=d,g=b.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===b.COPY_TYPE.CUT,getTransform:(p,S)=>{var I;const f=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),_={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:_,sheetTransform:(I=V(_,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],c=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:d,sheetTransform:h}=u;if(!d)return;const g=o(d,h),p={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:f,objects:_}=m.getBatchUpdateOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:f,objects:_}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:_}})}else{const{undo:S,redo:f,objects:_}=m.getBatchAddOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:_,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:c}}_generateRangeDrawingsPasteMutations(i,n){var j;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:c}=n;if(Wt.includes(o))return{redos:[],undos:[]};const m=(j=this._renderManagerService.getRenderById(e))==null?void 0:j.with(b.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:b.discreteRangeToRange(a)},pasteType:o},c);const{ranges:[d,h],mapFunc:g}=b.virtualizeDiscreteRanges([s,a]),{row:p,col:S}=g(d.startRow,d.startColumn),{row:f,col:_}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:_,endColumn:_});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const R=M.startX-I.startX,y=M.startY-I.startY,T=f-p,C=_-S;return this._generateMutations(u,{unitId:e,subUnitId:t,getTransform:(E,L)=>{var U,A;return{transform:{...E,left:((U=E==null?void 0:E.left)!=null?U:0)+R,top:((A=E==null?void 0:E.top)!=null?A:0)+y},sheetTransform:{...L,to:{...L.to,row:L.to.row+T,column:L.to.column+C},from:{...L.from,row:L.from.row+T,column:L.from.column+C}}}},isCut:c===b.COPY_TYPE.CUT})}};ze=Cn([We(0,b.ISheetClipboardService),We(1,N.IRenderManagerService),We(2,P.IDrawingManagerService),We(3,$.IClipboardInterfaceService),We(4,l.ICommandService)],ze);var Tn=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,bn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Rn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Tn(i,n,t),t},Be=(r,i)=>(n,e)=>i(n,e,r);let Je=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._drawingManagerService=r,this._renderManagerService=i,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),c=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,c),u=Object.values(m),d=this._renderManagerService.getRenderById(s),h=d==null?void 0:d.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.removeObject(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var d;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),c=s==null?void 0:s.scene;if(c==null)return;const m=c.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=c.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.attachTransformerTo(f)}),this._drawingManagerService.addNotification(S)):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>f.oKey.includes(_.drawingId))&&c.detachTransformerFrom(f)}),m.clearSelectedObjects())}}),(d=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(t,o).id))==null||d.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),f=this._renderManagerService.getRenderById(h),_=f==null?void 0:f.scene;if(_==null)return;this._drawingManagerService.setDrawingEditable(!0),_.getAllObjectsByOrder().forEach(M=>{M.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(R=>M.oKey.includes(R.drawingId))&&_.detachTransformerFrom(M)})}})})}))}};Je=bn([Be(0,P.IDrawingManagerService),Be(1,N.IRenderManagerService),Be(2,l.IPermissionService),Be(3,l.IUniverInstanceService),Be(4,l.Inject(l.UserManagerService))],Je);var En=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Pn=(r,i,n,e)=>{for(var t=e>1?void 0:e?On(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&En(i,n,t),t},Ze=(r,i)=>(n,e)=>i(n,e,r);let qe=class extends l.Disposable{constructor(r,i,n,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=i,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,i,n)=>{const{unitId:e,scene:t,subUnitId:o}=i,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(c=>{this._drawingRenderService.renderDrawing(s.data[c],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,i,n)=>{const{unitId:e,subUnitId:t}=i,o=this._renderManagerService.getRenderById(e);if(!o)return n(r);const a=o.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[i.subUnitId];if(!c)return n(r);const{scaleX:m,scaleY:u}=o.scene,d=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=c.order.map(g=>c.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),n(d)):n(r)}}))}};qe=Pn([Ze(0,l.Inject(b.SheetPrintInterceptorService)),Ze(1,l.Inject(ge.DrawingRenderService)),Ze(2,P.IDrawingManagerService),Ze(3,N.IRenderManagerService)],qe);var An=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,Nn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Un(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&An(i,n,t),t},me=(r,i)=>(n,e)=>i(n,e,r);const jn=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id],Wn=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let Ct=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,c){super(),this._context=r,this._renderManagerService=i,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!jn.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const i=r.id;if(i===v.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===v.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===v.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===v.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===v.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===v.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===v.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===v.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===v.SetRowHiddenCommand.id||i===v.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===v.SetSpecificColsVisibleCommand.id||i===v.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id||i===v.DeltaColumnWidthCommand.id||i===v.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===v.DeltaRowHeightCommand.id||i===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),c=[],m=[];if(Object.keys(s).forEach(u=>{const d=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,d);c.push(...h),m.push(...g)}),c.length===0&&m.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:h,objects:g}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.UPDATE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),d=u.undo,h=u.redo,g=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.REMOVE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:d,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:H.id,params:[e]}),a.push({id:H.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:c,subUnitId:m,drawingId:u}=n,{from:d,to:h}=o,{row:g,column:p}=d,{row:S,column:f}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:_,endRow:I,startColumn:M,endColumn:R}=r;let y=null,T=null;if(i===0&&g>=_&&S<=I)if(p>=M&&f<=R)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkCol(o,s,M,R,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===1&&p>=M&&f<=R)if(g>=_&&S<=I)t.push({unitId:c,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===2){const C=this._expandRow(o,s,_,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===3){const C=this._expandCol(o,s,M,R,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}if(y!=null&&T!=null){const C=X(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=V({...r},this._selectionRenderService);e!=null&&i.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:R}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:E,endColumn:L}=T;if(R<E)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(I>=E&&I<=L){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(k==null)return;B={...g,left:k.startX}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(I>=E&&R<=L)continue;let U=null,A=null;if(I>=E&&I<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(R>=E&&R<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;if(A={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_createUndoAndRedoMutation(r,i,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}];return{redos:s,undos:c}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const d=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,d);else{const{from:S,to:f}=h,{row:_,column:I}=S,{row:M,column:R}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:E,endColumn:L}=T;if(M<C)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(_>=C&&_<=j){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(k==null)return;B={...g,top:k.startY}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...d,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,d);continue}if(_>=C&&M<=j)continue;let U=null,A=null;if(_>=C&&_<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:_,endRow:j});if(D==null)return;A={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(M>=C&&M<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:M});if(D==null)return;A={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:j});if(D==null)return;if(A={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...d,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...d,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,d)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),c=[],m=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(r,i,o);c.push(...u),m.push(...d)}return{redos:a,undos:s,preRedos:c,preUndos:m}}_getDrawingUndoForRowAndColSize(r,i,n,e){const t=this._drawingManagerService.getDrawingData(r,i),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:c,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:d,to:h}=c,{row:g,column:p}=d,{row:S,column:f}=h;for(let _=0;_<n.length;_++){const I=n[_],{startRow:M,endRow:R,startColumn:y,endColumn:T}=I;if(S<M||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=R||p<=y&&f>=T)){this._remainDrawingSize(m,o,s);continue}const C=X({...c},this._selectionRenderService,this._skeletonManagerService);if(C!=null){o.push({...s,transform:C});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,i,o)}_getUnitIdAndSubUnitId(r,i){let n,e;if(i==="insert")n=r.unitId,e=r.subUnitId;else{const t=v.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(r){var M,R;const{toRange:i,fromRange:n}=r,e=v.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(b.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=b.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:c,endX:m,startY:u,endY:d}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(y=>{const T=h[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:C}=T;if(!C)return;const{left:j=0,top:E=0,width:L=0,height:U=0}=C,{drawingStartX:A,drawingEndX:D,drawingStartY:B,drawingEndY:k}={drawingStartX:j,drawingEndX:j+L,drawingStartY:E,drawingEndY:E+U};c<=A&&D<=m&&u<=B&&k<=d&&g.push(T)});const p=[],S=[],f=i.startRow-n.startRow,_=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+f,column:T.to.column+_},from:{...T.from,row:T.from.row+f,column:T.from.column+_}},j=X(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:j,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:j}=y;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:j,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:j,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startRow,s=o.endRow,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:C}=y,{row:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkRow(S,f,a,s,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_moveColInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startColumn,s=o.endColumn,c=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:_=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,f,a,s,_);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:C}=y,{column:j}=T;if(_===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const E=this._shrinkCol(S,f,a,s,_);I=E==null?void 0:E.newSheetTransform,M=E==null?void 0:E.newTransform}}if(!I||!M)return;const R={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};d.push(R)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=g;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:c,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)+h.endX-h.startX},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:c}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,column:c-o},to:{...s,column:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:c-1,startRow:a.row,endRow:s.row});if(h==null)return;d={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},d=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)+h.endY-h.startY},u=V(d,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_shrinkRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:c}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,d=null;if(c>e)u={from:{...a,row:c-o},to:{...s,row:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=n&&m<=e)return null;if(c<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},d=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(c>=n&&c<=e){if(c===n)d={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:c-1,startColumn:a.column,endColumn:s.column});if(h==null)return;d={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=V(d,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},d=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const i=r.params,{unitId:n,subUnitId:e}=i,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(s=>{const c=t[s];c!=null&&Object.keys(c).forEach(m=>{const u=c[m].data;u!=null&&Object.keys(u).forEach(d=>{if(s===n&&m===e){const h=u[d];h.transform=X(h.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[d])}else a.push(u[d])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{Wn.includes(r.id)&&requestIdleCallback(()=>{const i=r.params,{unitId:n,subUnitId:e,ranges:t}=i;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:c,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=s,{row:h,column:g}=u,{row:p,column:S}=d;for(let f=0;f<n.length;f++){const _=n[f],{startRow:I,endRow:M,startColumn:R,endColumn:y}=_;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:R,endColumn:y},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=X(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?c==null?void 0:c.width:C==null?void 0:C.width,height:T?c==null?void 0:c.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(H.id,[r]))}};Ct=Nn([me(1,N.IRenderManagerService),me(2,l.ICommandService),me(3,b.ISheetSelectionRenderService),me(4,l.Inject(b.SheetSkeletonManagerService)),me(5,l.Inject(v.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,P.IDrawingManagerService),me(8,l.IUniverInstanceService)],Ct);var q=function(){return q=Object.assign||function(r){for(var i,n=1,e=arguments.length;n<e;n++){i=arguments[n];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(r[t]=i[t])}return r},q.apply(this,arguments)},Bn=function(r,i){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&i.indexOf(e)<0&&(n[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)i.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(n[e[t]]=r[e[t]]);return n},Bt=J.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Bn(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),c=J.useRef("_".concat(Yn()));return kt(n,"".concat(e),{defIds:n.defIds,idSuffix:c.current},q({ref:i,className:s},a),o)});function kt(r,i,n,e,t){return J.createElement(r.tag,q(q({key:i},kn(r,n,t)),e),(Ln(r,n).children||[]).map(function(o,a){return kt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function kn(r,i,n){var e=q({},r.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=i.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+i.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),e}function Ln(r,i){var n,e=i.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((n=r.children)===null||n===void 0)&&n.length)?q(q({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?q(q({},t),{attrs:q(q({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Yn(){return Math.random().toString(36).substring(2,8)}Bt.displayName="UniverIcon";var Gn={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=J.forwardRef(function(r,i){return J.createElement(Bt,Object.assign({},r,{id:"add-image-single",ref:i,icon:Gn}))});Lt.displayName="AddImageSingle";const yt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:r=>{const i=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:c,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:c,drawingId:m,drawingType:u}});return i.executeCommand(Ce.id,{unitId:t,drawings:o})}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService),t=r.get(b.ISheetSelectionRenderService),{direction:o}=i,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,c=a.map(u=>{const{transform:d}=u;if(d==null)return null;const h={...d},{left:g=0,top:p=0}=d;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:V(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ue.id,{unitId:s,drawings:c})?(n.syncExecuteCommand(H.id,[s]),!0):!1}},Yt="addition-and-subtraction-single",Dt="sheet.menu.image";function Fn(r){return{id:Dt,type:$.MenuItemType.SUBITEMS,icon:Yt,tooltip:"sheetImage.title",hidden$:$.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(r,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function $n(r){return{id:je.id,title:"sheetImage.upload.float",type:$.MenuItemType.BUTTON,hidden$:$.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function Hn(r){return{id:It.id,title:"sheetImage.upload.cell",type:$.MenuItemType.BUTTON}}const pe={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Gt(r){var i,n,e="";if(typeof r=="string"||typeof r=="number")e+=r;else if(typeof r=="object")if(Array.isArray(r)){var t=r.length;for(i=0;i<t;i++)r[i]&&(n=Gt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Qe(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Gt(r))&&(e&&(e+=" "),e+=i);return e}const Vn=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),t=l.useDependency(N.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,c=t.getRenderById(s),m=c==null?void 0:c.scene;if(m==null)return;const u=m.getTransformerByCreate(),[d,h]=J.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[p,S]=J.useState(g);function f(R,y){const T=[];return R.forEach(C=>{const{oKey:j}=C,E=y.getDrawingOKey(j);if(E==null)return T.push(null),!0;const{unitId:L,subUnitId:U,drawingId:A,drawingType:D,anchorType:B,sheetTransform:k}=E;T.push({unitId:L,subUnitId:U,drawingId:A,anchorType:B,sheetTransform:k,drawingType:D})}),T}J.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var E;const{objects:C}=T,j=f(C,e);if(j.length===0)h(!1);else if(j.length>=1){h(!0);const L=((E=j[0])==null?void 0:E.anchorType)||w.SheetDrawingAnchorType.Position;S(L)}});return()=>{y.unsubscribe(),R.unsubscribe()}},[]);function _(R){S(R);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:R}));i.executeCommand(Ue.id,{unitId:y[0].unitId,drawings:T})}const I=R=>R?"block":"none";return x.jsxs("div",{className:Qe(pe.imageCommonPanelGrid,pe.imageCommonPanelBorder),style:{display:I(d)},children:[x.jsx("div",{className:pe.imageCommonPanelRow,children:x.jsx("div",{className:Qe(pe.imageCommonPanelColumn,pe.imageCommonPanelTitle),children:x.jsx("div",{children:n.t("drawing-anchor.title")})})}),x.jsx("div",{className:Qe(pe.imageCommonPanelRow),children:x.jsx("div",{className:Qe(pe.imageCommonPanelColumn),children:x.jsxs(ee.RadioGroup,{value:p,onChange:_,direction:"vertical",children:[x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),x.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},xn=()=>{const r=l.useDependency(P.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=J.useState(i);return J.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&x.jsxs("div",{className:pe.imageCommonPanel,children:[x.jsx(ge.DrawingCommonPanel,{drawings:n}),x.jsx(Vn,{drawings:n})]})},Xn={[$.RibbonStartGroup.FORMULAS_INSERT]:{[Dt]:{order:3,menuItemFactory:Fn,[je.id]:{order:0,menuItemFactory:$n},[It.id]:{order:1,menuItemFactory:Hn}}}};function ke(r){return!r.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!r.getContextValue(l.EDITOR_ACTIVATED)&&!r.getContextValue(l.FOCUSING_PANEL_EDITOR)&&r.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Kn={id:ye.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_DOWN,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.DOWN}},zn={id:ye.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_UP,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.UP}},Jn={id:ye.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_LEFT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.LEFT}},Zn={id:ye.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:$.KeyCode.ARROW_RIGHT,priority:100,preconditions:ke,staticParameters:{direction:l.Direction.RIGHT}},qn={id:yt.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ke,binding:$.KeyCode.DELETE,mac:$.KeyCode.BACKSPACE};var Qn=Object.defineProperty,ei=Object.getOwnPropertyDescriptor,ti=(r,i,n,e)=>{for(var t=e>1?void 0:e?ei(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Qn(i,n,t),t},De=(r,i)=>(n,e)=>i(n,e,r);let et=class extends l.Disposable{constructor(r,i,n,e,t,o){super(),this._componentManager=r,this._menuManagerService=i,this._commandService=n,this._shortcutService=e,this._drawingManagerService=t,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Yt,Lt)),this.disposeWithMe(r.register(Ot,xn))}_initMenus(){this._menuManagerService.mergeMenu(Xn)}_initCommands(){[je,It,Ae,Ce,Ue,ht,H,mt,St,_t,ye,yt,wt].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Kn,zn,Jn,Zn,qn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=ti([De(0,l.Inject($.ComponentManager)),De(1,$.IMenuManagerService),De(2,l.ICommandService),De(3,$.IShortcutService),De(4,P.IDrawingManagerService),De(5,l.Inject(v.SheetsSelectionsService))],et);var ni=Object.defineProperty,ii=Object.getOwnPropertyDescriptor,ri=(r,i,n,e)=>{for(var t=e>1?void 0:e?ii(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&ni(i,n,t),t},_e=(r,i)=>(n,e)=>i(n,e,r);function oi(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...r,absolute:c};const{left:m,right:u,top:d,bottom:h}=r;let{top:g,left:p,viewportScrollX:S,viewportScrollY:f}=s;const{boundsOfViewArea:_,scrollDirectionResponse:I}=t||{};_&&(l.Tools.isDefine(_.top)&&(g=_.top),l.Tools.isDefine(_.left)&&(p=_.left)),I==="HORIZONTAL"&&(f=0),I==="VERTICAL"&&(S=0);let M,R;m<p?(c.left=!0,M=(p+(m-p))*o,R=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(c.left=!1,M=Math.max((m-S)*o,p*o),R=Math.max((u-S)*o,p*o));let y,T;return d<g?(c.top=!0,y=(g+(d-g))*a,T=Math.max(Math.min((g+(u-g))*a,g*a),(h-f)*a)):(c.top=!1,y=Math.max((d-f)*a,g*a),T=Math.max((h-f)*a,g*a)),{left:M,right:R,top:y,bottom:T,absolute:c}}const se=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:c,height:m,angle:u}=r,d={left:a,right:a+c,top:s,bottom:s+m},h=oi(d,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:c*g,height:m*p,absolute:h.absolute}};O.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,c){super();z(this,"_domLayerMap",new Map);z(this,"_domLayerInfoMap",new Map);z(this,"_transformChange$",new W.Subject);z(this,"transformChange$",this._transformChange$.asObservable());z(this,"_add$",new W.Subject);z(this,"add$",this._add$.asObservable());z(this,"_remove$",new W.Subject);z(this,"remove$",this._remove$.asObservable());z(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=c,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===l.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ne,ie,K;const{unitId:t,subUnitId:o,drawingId:a}=e,s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!c||!s)return;const d=(ne=this._renderManagerService.getRenderById(t))==null?void 0:ne.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!d)return;const{transform:h,drawingType:g,data:p}=c;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:f,canvas:_}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:R,height:y,angle:T,flipX:C,flipY:j,skewX:E,skewY:L}=h,U=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),A=f.getObject(U);if(A!=null){A.transformByState({left:I,top:M,width:R,height:y,angle:T,flipX:C,flipY:j,skewX:E,skewY:L});return}const D={left:I,top:M,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=g===l.DrawingTypeEnum.DRAWING_CHART;if(B){const F=p?p.backgroundColor:"white";D.fill=F,D.rotateEnabled=!1,p&&p.border&&(D.stroke=p.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const k=new N.Rect(U,D);B&&k.setObjectType(N.ObjectType.CHART),f.addObject(k,N.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(k);const te=this._ensureMap(t,o),oe=new l.DisposableCollection,ve=se(k,S.renderUnit,d.skeleton,s.worksheet),ae=new W.BehaviorSubject(ve),Ie={dispose:oe,rect:k,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:c.componentKey,onPointerDown: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:(K=(ie=te.get(a))==null?void 0:ie.props)!=null?K:this._getFloatDomProps(a),data:p,unitId:t});const ce=k.onTransformChange$.subscribeEvent(()=>{const F=se(k,S.renderUnit,d.skeleton,s.worksheet);ae.next(F)});oe.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ce&&oe.add(ce),this._domLayerInfoMap.set(a,Ie),te.set(a,{...te.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),c=this._getSceneAndTransformerByDrawingSearch(t);if(c==null)return;const{transformer:m,scene:u}=c,d=u.getObject(s);d!=null&&d.oKey&&m.clearControlByIds([d==null?void 0:d.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),c=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!c||!m||s.forEach(d=>{const h=this._domLayerInfoMap.get(d);if(h){const g=se(h.rect,o.renderUnit,m.skeleton,c.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===b.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===v.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,c=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(b.ISheetSelectionRenderService);if(c==null)return;const m=c.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},d=c.getCellWithCoordByOffset(o,s);if(d==null)return;const h={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:s-d.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:c}=s,m=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=c.getObject(m);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:c,data:m,allowTransform:u=!0}=n,d=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(d,n);const p={unitId:o,subUnitId:a,drawingId:d,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:d,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:d,objects:h,type:w.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var j,E,L,U,A;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(j=this._renderManagerService.getRenderById(s))==null?void 0:j.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver(n,u,d.skeleton),I=this._getPosition(f,s);if(I==null)return;this._ensureMap(s,c).set(S,e);const R=m.scene,{scaleX:y}=R.getAncestorScale(),T=tt(f,t,y),C={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:I,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:p};{const{unitId:D,subUnitId:B,drawingId:k}=C,te=v.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:B}),oe=C,ve=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!ve)return;const ae=ve.getActiveSheet().getSheetId();if(!oe||!te)return;const Ie=(E=this._renderManagerService.getRenderById(D))==null?void 0:E.with(b.SheetSkeletonManagerService);if(!Ie)return;const ce=Ie.getWorksheetSkeleton(B);if(!ce)return;const{transform:ne,drawingType:ie,data:K}=oe;if(ie!==l.DrawingTypeEnum.DRAWING_DOM&&ie!==l.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(D);if(F==null)return;const{scene:Me,canvas:Te}=F;if(ne==null||ae!==B)return;const{left:it,top:rt,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Re}=ne,dt=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),de=Me.getObject(dt);if(de!=null){de.transformByState({left:it,top:rt,width:ot,height:at,angle:Tt,flipX:Rt,flipY:st,skewX:ct,skewY:Re});return}const Q={left:it,top:rt,width:ot,height:at,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1},be=ie===l.DrawingTypeEnum.DRAWING_CHART;if(be){const Y=K?K.backgroundColor:"white";Q.fill=Y,Q.rotateEnabled=!1,K&&K.border&&(Q.stroke=K.border),Q.paintFirst="stroke",Q.strokeWidth=1,Q.borderEnabled=!1,Q.radius=8}const re=new N.Rect(dt,Q);be&&re.setObjectType(N.ObjectType.CHART),Me.addObject(re,N.DRAWING_OBJECT_LAYER_INDEX),oe.allowTransform!==!1&&Me.attachTransformerTo(re);const Ye=this._ensureMap(D,B),le=new l.DisposableCollection,Ee=Me.getMainViewport(),Oe={top:Ee.top,left:Ee.left,bottom:Ee.bottom,right:Ee.right},ue={dispose:le,rect:re,boundsOfViewArea:Oe,domAnchor:t,unitId:D,subUnitId:B},lt=se(re,F.renderUnit,ce.skeleton,te.worksheet,ue),fe=new W.BehaviorSubject(lt);ue.position$=fe;let G={position$:fe,id:k,componentKey:oe.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{Te.dispatchEvent(new WheelEvent(Y.type,Y))},props:(U=(L=Ye.get(k))==null?void 0:L.props)!=null?U:this._getFloatDomProps(k),data:K,unitId:D};e.eventPassThrough&&(G={...G,onPointerDown:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{Te.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(G),this.disposeWithMe(_.subscribe(Y=>{var Ht,Vt,xt,Xt;const gt=tt({rotate:0,startX:Y.startX,startY:Y.startY,endX:Y.endX,endY:Y.endY,width:(Ht=t.width)!=null?Ht:Y.width,height:(Vt=t.height)!=null?Vt:Y.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),li=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),ui=new N.Rect(li,{left:gt.startX,top:gt.startY,width:(xt=t.width)!=null?xt:Y.width,height:(Xt=t.height)!=null?Xt:Y.height,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1}),gi=se(ui,F.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(gi)}));const Ge=(A=this._renderManagerService.getRenderById(D))==null?void 0:A.with(b.SheetSkeletonManagerService);Ge==null||Ge.currentSkeleton$.subscribe(Y=>{Y&&d.sheetId!==Y.sheetId&&this._removeDom(S,!0)});const ut=re.onTransformChange$.subscribeEvent(()=>{const Y=se(re,F.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(Y)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),ut&&le.add(ut),this._domLayerInfoMap.set(k,ue),Ye.set(k,{...Ye.get(k)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,j,E,L;const a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:c}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const d=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,d.skeleton),I=f;I.startY=0;const M=this._getPosition(f,s);if(M==null)return;this._ensureMap(s,c).set(S,e);const y={unitId:s,subUnitId:c,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:g,allowTransform:p};{const{unitId:U,subUnitId:A,drawingId:D}=y,B=v.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:A}),k=y,te=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!te)return;const oe=te.getActiveSheet().getSheetId();if(!k||!B)return;const ve=(C=this._renderManagerService.getRenderById(U))==null?void 0:C.with(b.SheetSkeletonManagerService);if(!ve)return;const ae=ve.getWorksheetSkeleton(A);if(!ae)return;const{transform:Ie,data:ce}=k,ne=this._getSceneAndTransformerByDrawingSearch(U);if(ne==null)return;const{scene:ie,canvas:K}=ne;if(Ie==null||oe!==A)return;const{left:F,top:Me,width:Te,height:it,angle:rt,flipX:ot,flipY:at,skewX:Tt,skewY:Rt}=Ie,st=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),ct=ie.getObject(st);if(ct!=null){ct.transformByState({left:F,top:Me,width:Te,height:it,angle:rt,flipX:ot,flipY:at,skewX:Tt,skewY:Rt});return}const Re=tt({rotate:0,startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),dt={left:Re.startX,top:Re.startY,width:Re.width,height:Re.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1},de=new N.Rect(st,dt);ie.addObject(de,N.DRAWING_OBJECT_LAYER_INDEX),k.allowTransform!==!1&&ie.attachTransformerTo(de);const Q=this._ensureMap(U,A),be=new l.DisposableCollection,re=ie.getMainViewport(),Ye={top:0,left:re.left,bottom:re.bottom,right:re.right},le={dispose:be,rect:de,unitId:U,subUnitId:A,boundsOfViewArea:Ye,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},Ee=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le),Oe=new W.BehaviorSubject(Ee);le.position$=Oe;let ue={position$:Oe,id:D,componentKey:k.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:G=>{K.dispatchEvent(new WheelEvent(G.type,G))},props:(E=(j=Q.get(D))==null?void 0:j.props)!=null?E:this._getFloatDomProps(D),data:ce,unitId:U};e.eventPassThrough&&(ue={...ue,onPointerDown:G=>{K.dispatchEvent(new PointerEvent(G.type,G))},onPointerMove:G=>{K.dispatchEvent(new PointerEvent(G.type,G))},onPointerUp:G=>{K.dispatchEvent(new PointerEvent(G.type,G))}}),this._canvasFloatDomService.addFloatDom(ue);const lt=de.onTransformChange$.subscribeEvent(()=>{const G=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(G)});this.disposeWithMe(_.subscribe(G=>{const Ge=tt({rotate:0,startX:G.startX,startY:0,endX:G.endX,endY:G.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ut=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),Y=new N.Rect(ut,{left:Ge.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1}),gt=se(Y,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(gt)}));const fe=(L=this._renderManagerService.getRenderById(U))==null?void 0:L.with(b.SheetSkeletonManagerService);fe==null||fe.currentSkeleton$.subscribe(G=>{G&&d.sheetId!==G.sheetId&&this._removeDom(S,!0)}),be.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),lt&&be.add(lt),this._domLayerInfoMap.set(D,le),Q.set(D,{...Q.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=Le(o,a,t),c=new W.BehaviorSubject(s),m=Le(n.endRow,n.endColumn,t),u=new W.BehaviorSubject(m),d=()=>{const _=Le(o,a,t),I=Le(n.endRow,n.endColumn,t);c.next(_),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>d())),h.add(this._commandService.onCommandExecuted(_=>{if(_.id===v.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){d();return}(v.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===b.SetScrollOperation.id||_.id===b.SetZoomRatioOperation.id)&&d()}));const g=(_,I)=>{o=_,a=I,d()},p=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=c.pipe(W.map(_=>{const I=Le(n.endRow,n.endColumn,t);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:g,topLeftPos$:c,rightBottomPos$:u,disposable:h}}},O.SheetCanvasFloatDomManagerService=ri([_e(0,l.Inject(N.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,P.IDrawingManagerService),_e(4,l.Inject($.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],O.SheetCanvasFloatDomManagerService);function Le(r,i,n){const e=n.getCellWithCoordByIndex(r,i),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function tt(r,i,n){var m,u;n=n!=null?n:1;const e=r.endX-r.startX,t=r.endY-r.startY,o=(m=i==null?void 0:i.width)!=null?m:e,a=(u=i==null?void 0:i.height)!=null?u:t;let s=0,c=0;if(i){if(i.horizonOffsetAlign==="right"){const d=nt(i.marginX,e*n);s=r.endX-d-o}else s=r.startX+nt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const d=nt(i.marginY,t*n);c=r.endY-d-a}else c=r.startY+nt(i.marginY,t)}return{rotate:0,startX:s,startY:c,endX:r.endX,endY:r.endY,width:o,height:a,absolute:{left:r.absolute.left,top:r.absolute.top}}}function nt(r,i){if(r===void 0)return 0;if(typeof r=="number")return r;const n=Number.parseFloat(r);return i*n/100}var Ft=Object.defineProperty,ai=Object.getOwnPropertyDescriptor,si=(r,i,n)=>i in r?Ft(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ci=(r,i,n,e)=>{for(var t=e>1?void 0:e?ai(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Ft(i,n,t),t},Mt=(r,i)=>(n,e)=>i(n,e,r),$t=(r,i,n)=>si(r,typeof i!="symbol"?i+"":i,n);const di="SHEET_IMAGE_UI_PLUGIN";O.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=Et,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},Et,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Kt,a)}onStarting(){l.registerDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService],[et],[$e],[qe],[Je],[ze],[Ve],[Ke],[xe]]),l.touchDependencies(this._injector,[[O.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ze]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[Je],[qe],[et],[Ve],[Ke],[xe]])}onSteady(){this._injector.get($e)}_registerRenderModules(){[[Ne],[Ct],[ft]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},$t(O.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),$t(O.UniverSheetsDrawingUIPlugin,"pluginName",di),O.UniverSheetsDrawingUIPlugin=ci([l.DependentOn(P.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),Mt(1,l.Inject(l.Injector)),Mt(2,N.IRenderManagerService),Mt(3,l.IConfigService)],O.UniverSheetsDrawingUIPlugin),O.ClearSheetDrawingTransformerOperation=H,O.DeleteDrawingsCommand=yt,O.EditSheetDrawingOperation=mt,O.GroupSheetDrawingCommand=St,O.InsertFloatImageCommand=je,O.InsertSheetDrawingCommand=Ae,O.MoveDrawingsCommand=ye,O.RemoveSheetDrawingCommand=Ce,O.SHEETS_IMAGE_MENU_ID=Dt,O.SetDrawingArrangeCommand=wt,O.SetSheetDrawingCommand=Ue,O.SidebarSheetDrawingOperation=ht,O.UngroupSheetDrawingCommand=_t,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(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"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsDrawingUi={},global.UniverCore,global.UniverDocsDrawing,global.UniverDrawing,global.UniverDrawingUi,global.UniverEngineRender,global.UniverSheetsDrawing,global.UniverSheetsUi,global.UniverUi,global.rxjs,global.UniverSheets,global.React,global.React,global.UniverDocsUi,global.UniverDesign))})(this,function(exports2,core,docsDrawing,drawing,drawingUi,engineRender,sheetsDrawing,sheetsUi,ui,rxjs,sheets,jsxRuntime,React,docsUi,design){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m;const SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY="sheets-drawing-ui.config",defaultPluginConfig={},ClearSheetDrawingTransformerOperation={id:"sheet.operation.clear-drawing-transformer",type:core.CommandType.MUTATION,handler:__name((accessor,params)=>{const renderManagerService=accessor.get(engineRender.IRenderManagerService);return params.forEach(unitId=>{var _a2,_b2;(_b2=(_a2=renderManagerService.getRenderById(unitId))==null?void 0:_a2.scene.getTransformer())==null||_b2.debounceRefreshControls()}),!0},"handler")},RemoveSheetDrawingCommand={id:"sheet.command.remove-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{var _a2,_b2,_c2;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetInterceptorService=accessor.get(sheets.SheetInterceptorService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const{drawings}=params,unitIds=[];drawings.forEach(param=>{const{unitId:unitId2}=param;unitIds.push(unitId2)});const jsonOp=sheetDrawingService.getBatchRemoveOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp,intercepted=sheetInterceptorService.onCommandExecute({id:RemoveSheetDrawingCommand.id,params}),removeMutation={id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}},undoRemoveMutation={id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.INSERT}};return core.sequenceExecute([...(_a2=intercepted.preRedos)!=null?_a2:[],removeMutation,...intercepted.redos],commandService)?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[...(_b2=intercepted.preUndos)!=null?_b2:[],undoRemoveMutation,...intercepted.undos,{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[...(_c2=intercepted.preRedos)!=null?_c2:[],removeMutation,...intercepted.redos,{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},COMPONENT_SHEET_DRAWING_PANEL="COMPONENT_SHEET_DRAWING_PANEL",SidebarSheetDrawingOperation={id:"sidebar.operation.sheet-image",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const sidebarService=accessor.get(ui.ISidebarService),localeService=accessor.get(core.LocaleService),univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService);if(!sheets.getSheetCommandTarget(univerInstanceService))return!1;switch(params.value){case"open":sidebarService.open({header:{title:localeService.t("sheetImage.panel.title")},children:{label:COMPONENT_SHEET_DRAWING_PANEL},onClose:__name(()=>{commandService.syncExecuteCommand(drawing.SetDrawingSelectedOperation.id,[])},"onClose"),width:360});break;case"close":default:sidebarService.close();break}return!0},"handler")},EditSheetDrawingOperation={id:"sheet.operation.edit-sheet-image",type:core.CommandType.OPERATION,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService);return params==null?!1:(commandService.syncExecuteCommand(drawing.SetDrawingSelectedOperation.id,[params]),commandService.executeCommand(SidebarSheetDrawingOperation.id,{value:"open"}),!0)},"handler")},styles$1={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},UploadLoading=__name(()=>{const imageIoService=core.useDependency(drawing.IImageIoService),localeService=core.useDependency(core.LocaleService),[remain,setRemain]=React.useState(0);return React.useEffect(()=>{const sub=imageIoService.change$.subscribe(count=>{setRemain(count)});return()=>{sub.unsubscribe()}},[imageIoService]),jsxRuntime.jsx("div",{style:{display:remain>0?"block":"none"},className:styles$1.uploadLoading,children:jsxRuntime.jsxs("div",{className:styles$1.uploadLoadingBody,children:[jsxRuntime.jsx("div",{className:styles$1.uploadLoadingBodyAnimation}),jsxRuntime.jsx("div",{className:styles$1.uploadLoadingBodyText,children:`${localeService.t("uploadLoading.loading")}: ${remain}`})]})})},"UploadLoading");var __defProp$c=Object.defineProperty,__getOwnPropDesc$c=Object.getOwnPropertyDescriptor,__decorateClass$c=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$c(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$c(target,key,result),result},"__decorateClass$c"),__decorateParam$c=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$c");let DrawingPopupMenuController=(_a=class extends core.RxDisposable{constructor(_injector,_drawingManagerService,_canvasPopManagerService,_renderManagerService,_univerInstanceService,_contextService,_uiPartsService,_commandService){super();__publicField(this,"_initImagePopupMenu",new Set);this._injector=_injector,this._drawingManagerService=_drawingManagerService,this._canvasPopManagerService=_canvasPopManagerService,this._renderManagerService=_renderManagerService,this._univerInstanceService=_univerInstanceService,this._contextService=_contextService,this._uiPartsService=_uiPartsService,this._commandService=_commandService,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.takeUntil(this.dispose$)).subscribe(workbook=>this._create(workbook)),this._univerInstanceService.getTypeOfUnitDisposed$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.takeUntil(this.dispose$)).subscribe(workbook=>this._dispose(workbook)),this._univerInstanceService.getAllUnitsForType(core.UniverInstanceType.UNIVER_SHEET).forEach(workbook=>this._create(workbook)),this._uiPartsService.registerComponent(ui.BuiltInUIPart.CONTENT,()=>core.connectInjector(UploadLoading,this._injector))}_dispose(workbook){const unitId=workbook.getUnitId();this._renderManagerService.removeRender(unitId)}_create(workbook){if(!workbook)return;const unitId=workbook.getUnitId();this._renderManagerService.has(unitId)&&!this._initImagePopupMenu.has(unitId)&&(this._popupMenuListener(unitId),this._initImagePopupMenu.add(unitId))}_hasCropObject(scene){const objects=scene.getAllObjectsByOrder();for(const object of objects)if(object instanceof drawingUi.ImageCropperObject)return!0;return!1}_popupMenuListener(unitId){var _a2;const scene=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.scene;if(!scene)return;const transformer=scene.getTransformerByCreate();if(!transformer)return;let singletonPopupDisposer;this.disposeWithMe(core.toDisposable(transformer.createControl$.subscribe(()=>{if(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(scene))return;const selectedObjects=transformer.getSelectedObjectMap();if(selectedObjects.size>1){singletonPopupDisposer==null||singletonPopupDisposer.dispose();return}const object=selectedObjects.values().next().value;if(!object)return;const oKey=object.oKey,drawingParam=this._drawingManagerService.getDrawingOKey(oKey);if(!drawingParam)return;const{unitId:unitId2,subUnitId,drawingId,drawingType}=drawingParam,data=drawingParam.data;if(data&&data.disablePopup)return;singletonPopupDisposer==null||singletonPopupDisposer.dispose();const menus=this._canvasPopManagerService.getFeatureMenu(unitId2,subUnitId,drawingId,drawingType);singletonPopupDisposer=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(object,{componentKey:drawingUi.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:menus||this._getImageMenuItems(unitId2,subUnitId,drawingId,drawingType)}}))}))),this.disposeWithMe(transformer.clearControl$.subscribe(()=>{singletonPopupDisposer==null||singletonPopupDisposer.dispose(),this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(drawing.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(event=>{event[core.FOCUSING_COMMON_DRAWINGS]===!1&&(singletonPopupDisposer==null||singletonPopupDisposer.dispose())})),this.disposeWithMe(transformer.changing$.subscribe(()=>{singletonPopupDisposer==null||singletonPopupDisposer.dispose()}))}_getImageMenuItems(unitId,subUnitId,drawingId,drawingType){return[{label:"image-popup.edit",index:0,commandId:EditSheetDrawingOperation.id,commandParams:{unitId,subUnitId,drawingId},disable:drawingType===core.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:RemoveSheetDrawingCommand.id,commandParams:{unitId,drawings:[{unitId,subUnitId,drawingId}]},disable:!1},{label:"image-popup.crop",index:2,commandId:drawingUi.OpenImageCropOperation.id,commandParams:{unitId,subUnitId,drawingId},disable:drawingType===core.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:drawingUi.ImageResetSizeOperation.id,commandParams:[{unitId,subUnitId,drawingId}],disable:drawingType===core.DrawingTypeEnum.DRAWING_DOM}]}},__name(_a,"DrawingPopupMenuController"),_a);DrawingPopupMenuController=__decorateClass$c([__decorateParam$c(0,core.Inject(core.Injector)),__decorateParam$c(1,drawing.IDrawingManagerService),__decorateParam$c(2,core.Inject(sheetsUi.SheetCanvasPopManagerService)),__decorateParam$c(3,engineRender.IRenderManagerService),__decorateParam$c(4,core.IUniverInstanceService),__decorateParam$c(5,core.IContextService),__decorateParam$c(6,core.Inject(ui.IUIPartsService)),__decorateParam$c(7,core.ICommandService)],DrawingPopupMenuController);function drawingPositionToTransform(position,selectionRenderService,sheetSkeletonManagerService){const{from,to,flipY=!1,flipX=!1,angle=0,skewX=0,skewY=0}=position,skeletonParam=sheetSkeletonManagerService.getCurrent();if(skeletonParam==null)return;const absolutePosition=sheetsUi.convertPositionSheetOverGridToAbsolute(skeletonParam.unitId,skeletonParam.sheetId,{from,to},sheetSkeletonManagerService);let{left,top,width,height}=absolutePosition;const skeleton=sheetSkeletonManagerService.getCurrentSkeleton(),sheetWidth=skeleton.rowHeaderWidth+skeleton.columnTotalWidth,sheetHeight=skeleton.columnHeaderHeight+skeleton.rowTotalHeight;return left+width>sheetWidth&&(left=sheetWidth-width),top+height>sheetHeight&&(top=sheetHeight-height),{flipY,flipX,angle,skewX,skewY,left,top,width,height}}__name(drawingPositionToTransform,"drawingPositionToTransform");function transformToDrawingPosition(transform,selectionRenderService){const{left=0,top=0,width=0,height=0,flipY=!1,flipX=!1,angle=0,skewX=0,skewY=0}=transform,startSelectionCell=selectionRenderService.getCellWithCoordByOffset(left,top);if(startSelectionCell==null)return;const from={column:startSelectionCell.actualColumn,columnOffset:engineRender.precisionTo(left-startSelectionCell.startX,1),row:startSelectionCell.actualRow,rowOffset:engineRender.precisionTo(top-startSelectionCell.startY,1)},endSelectionCell=selectionRenderService.getCellWithCoordByOffset(left+width,top+height);if(endSelectionCell==null)return;const to={column:endSelectionCell.actualColumn,columnOffset:engineRender.precisionTo(left+width-endSelectionCell.startX,1),row:endSelectionCell.actualRow,rowOffset:engineRender.precisionTo(top+height-endSelectionCell.startY,1)};return{flipY,flipX,angle,skewX,skewY,from,to}}__name(transformToDrawingPosition,"transformToDrawingPosition");var __defProp$b=Object.defineProperty,__getOwnPropDesc$b=Object.getOwnPropertyDescriptor,__decorateClass$b=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$b(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$b(target,key,result),result},"__decorateClass$b"),__decorateParam$b=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$b");let SheetsDrawingRenderController=(_b=class extends core.Disposable{constructor(_context,_sheetDrawingService,_drawingManagerService,_sheetSelectionRenderService,_sheetSkeletonManagerService){super(),this._context=_context,this._sheetDrawingService=_sheetDrawingService,this._drawingManagerService=_drawingManagerService,this._sheetSelectionRenderService=_sheetSelectionRenderService,this._sheetSkeletonManagerService=_sheetSkeletonManagerService,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const data=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const subUnit in data){const subUnitData=data[subUnit];for(const drawingId in subUnitData.data){const drawingData=subUnitData.data[drawingId];drawingData.transform=drawingPositionToTransform(drawingData.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}},__name(_b,"SheetsDrawingRenderController"),_b);SheetsDrawingRenderController=__decorateClass$b([__decorateParam$b(1,sheetsDrawing.ISheetDrawingService),__decorateParam$b(2,drawing.IDrawingManagerService),__decorateParam$b(3,core.Inject(sheetsUi.ISheetSelectionRenderService)),__decorateParam$b(4,core.Inject(sheetsUi.SheetSkeletonManagerService))],SheetsDrawingRenderController);function ungroupToGroup(ungroupParams){const newGroupParams=[];return ungroupParams.forEach(ungroupParam=>{const{parent,children}=ungroupParam,{unitId,subUnitId,drawingId:groupId}=parent,groupTransform=engineRender.getGroupState(0,0,children.map(o=>o.transform||{})),newChildren=children.map(drawing2=>{const transform=drawing2.transform||{left:0,top:0},{unitId:unitId2,subUnitId:subUnitId2,drawingId}=drawing2;return{unitId:unitId2,subUnitId:subUnitId2,drawingId,transform:{...transform,left:transform.left-groupTransform.left,top:transform.top-groupTransform.top},groupId}}),groupParam={unitId,subUnitId,drawingId:groupId,drawingType:core.DrawingTypeEnum.DRAWING_GROUP,transform:groupTransform};newGroupParams.push({parent:groupParam,children:newChildren})}),newGroupParams}__name(ungroupToGroup,"ungroupToGroup");function groupToUngroup(groupParams){const newGroupParams=[];return groupParams.forEach(groupParam=>{const{parent,children}=groupParam,{unitId,subUnitId,drawingId:groupId,transform:groupTransform={width:0,height:0}}=parent;if(groupTransform==null)return;const newChildren=children.map(object=>{const{transform}=object,{unitId:unitId2,subUnitId:subUnitId2,drawingId}=object,newTransform=engineRender.transformObjectOutOfGroup(transform||{},groupTransform,groupTransform.width||0,groupTransform.height||0);return{unitId:unitId2,subUnitId:subUnitId2,drawingId,transform:newTransform,groupId:void 0}}),ungroupParam={unitId,subUnitId,drawingId:groupId,drawingType:core.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};newGroupParams.push({parent:ungroupParam,children:newChildren})}),newGroupParams}__name(groupToUngroup,"groupToUngroup");const GroupSheetDrawingCommand={id:"sheet.command.group-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const unitIds=[];params.forEach(({parent,children})=>{unitIds.push(parent.unitId),children.forEach(child=>{unitIds.push(child.unitId)})});const jsonOp=sheetDrawingService.getGroupDrawingOp(params),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.GROUP})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects:groupToUngroup(objects),type:sheetsDrawing.DrawingApplyType.UNGROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.GROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},InsertSheetDrawingCommand={id:"sheet.command.insert-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{var _a2,_b2,_c2;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService),sheetInterceptorService=accessor.get(sheets.SheetInterceptorService);if(!params)return!1;const drawings=params.drawings,unitIds=drawings.map(param=>param.unitId),jsonOp=sheetDrawingService.getBatchAddOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp,intercepted=sheetInterceptorService.onCommandExecute({id:InsertSheetDrawingCommand.id,params}),insertMutation={id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.INSERT}},undoInsertMutation={id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}};return core.sequenceExecute([...(_a2=intercepted.preRedos)!=null?_a2:[],insertMutation,...intercepted.redos],commandService)?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[...(_b2=intercepted.preUndos)!=null?_b2:[],undoInsertMutation,...intercepted.undos,{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[...(_c2=intercepted.preRedos)!=null?_c2:[],insertMutation,...intercepted.redos,{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")},SetDrawingArrangeCommand={id:"sheet.command.set-drawing-arrange",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService);if(!params)return!1;const sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService),{unitId,subUnitId,drawingIds,arrangeType}=params,drawingOrderMapParam={unitId,subUnitId,drawingIds};let jsonOp;if(arrangeType===core.ArrangeTypeEnum.forward?jsonOp=sheetDrawingService.getForwardDrawingsOp(drawingOrderMapParam):arrangeType===core.ArrangeTypeEnum.backward?jsonOp=sheetDrawingService.getBackwardDrawingOp(drawingOrderMapParam):arrangeType===core.ArrangeTypeEnum.front?jsonOp=sheetDrawingService.getFrontDrawingsOp(drawingOrderMapParam):arrangeType===core.ArrangeTypeEnum.back&&(jsonOp=sheetDrawingService.getBackDrawingsOp(drawingOrderMapParam)),jsonOp==null)return!1;const{objects,redo,undo}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE}}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.ARRANGE}}]}),!0):!1},"handler")},SetSheetDrawingCommand={id:"sheet.command.set-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const{drawings}=params,jsonOp=sheetDrawingService.getBatchUpdateOp(drawings),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}]}),!0):!1},"handler")},UngroupSheetDrawingCommand={id:"sheet.command.ungroup-sheet-image",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),sheetDrawingService=accessor.get(sheetsDrawing.ISheetDrawingService);if(!params)return!1;const unitIds=[];params.forEach(({parent,children})=>{unitIds.push(parent.unitId),children.forEach(child=>{unitIds.push(child.unitId)})});const jsonOp=sheetDrawingService.getUngroupDrawingOp(params),{unitId,subUnitId,undo,redo,objects}=jsonOp;return commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.UNGROUP})?(undoRedoService.pushUndoRedo({unitID:unitId,undoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects:ungroupToGroup(objects),type:sheetsDrawing.DrawingApplyType.GROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}],redoMutations:[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.UNGROUP}},{id:ClearSheetDrawingTransformerOperation.id,params:unitIds}]}),!0):!1},"handler")};var __defProp$a=Object.defineProperty,__getOwnPropDesc$a=Object.getOwnPropertyDescriptor,__decorateClass$a=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$a(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$a(target,key,result),result},"__decorateClass$a"),__decorateParam$a=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$a");function rotatedBoundingBox(width,height,angleDegrees){const angle=angleDegrees*Math.PI/180,rotatedWidth=Math.abs(width*Math.cos(angle))+Math.abs(height*Math.sin(angle)),rotatedHeight=Math.abs(width*Math.sin(angle))+Math.abs(height*Math.cos(angle));return{rotatedWidth,rotatedHeight}}__name(rotatedBoundingBox,"rotatedBoundingBox");function getDrawingSizeByCell(accessor,location,originImageWidth,originImageHeight,angle){var _a2;const{rotatedHeight,rotatedWidth}=rotatedBoundingBox(originImageWidth,originImageHeight,angle),currentRender=accessor.get(engineRender.IRenderManagerService).getRenderById(location.unitId);if(!currentRender)return!1;const skeleton=(_a2=currentRender.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(location.subUnitId))==null?void 0:_a2.skeleton;if(skeleton==null)return!1;const cellInfo=skeleton.getCellByIndex(location.row,location.col),cellWidth=cellInfo.mergeInfo.endX-cellInfo.mergeInfo.startX-2,cellHeight=cellInfo.mergeInfo.endY-cellInfo.mergeInfo.startY-2,imageRatio=rotatedWidth/rotatedHeight,scale=Math.ceil(Math.min(cellWidth,cellHeight*imageRatio))/rotatedWidth,realScale=!scale||Number.isNaN(scale)?.001:scale;return{width:originImageWidth*realScale,height:originImageHeight*realScale}}__name(getDrawingSizeByCell,"getDrawingSizeByCell");let SheetDrawingUpdateController=(_c=class extends core.Disposable{constructor(_context,_skeletonManagerService,_commandService,_selectionRenderService,_imageIoService,_fileOpenerService,_sheetDrawingService,_drawingManagerService,_contextService,_messageService,_localeService,selectionManagerService,_injector){super();__publicField(this,"_workbookSelections");this._context=_context,this._skeletonManagerService=_skeletonManagerService,this._commandService=_commandService,this._selectionRenderService=_selectionRenderService,this._imageIoService=_imageIoService,this._fileOpenerService=_fileOpenerService,this._sheetDrawingService=_sheetDrawingService,this._drawingManagerService=_drawingManagerService,this._contextService=_contextService,this._messageService=_messageService,this._localeService=_localeService,this._injector=_injector,this._workbookSelections=selectionManagerService.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const files=await this._fileOpenerService.openFile({multiple:!0,accept:drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(image=>`.${image.replace("image/","")}`).join(",")}),fileLength=files.length;return fileLength>drawing.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(drawing.DRAWING_IMAGE_COUNT_LIMIT))}),!1):fileLength===0?!1:(files.forEach(async file=>await this.insertFloatImageByFile(file)),!0)}async insertCellImage(){const file=(await this._fileOpenerService.openFile({multiple:!1,accept:drawing.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(image=>`.${image.replace("image/","")}`).join(",")}))[0];return file?(await this._insertCellImage(file),!0):!1}async insertFloatImageByFile(file){let imageParam;try{imageParam=await this._imageIoService.saveImage(file)}catch(error){const type=error.message;type===drawing.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(drawing.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):type===drawing.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):type===drawing.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(imageParam==null)return;const info=this._getUnitInfo(),{unitId,subUnitId}=info,{imageId,imageSourceType,source,base64Cache}=imageParam,{width,height,image}=await drawing.getImageSize(base64Cache||""),{width:sceneWidth,height:sceneHeight}=this._context.scene;this._imageIoService.addImageSourceCache(source,imageSourceType,image);let scale=1;if(width>drawing.DRAWING_IMAGE_WIDTH_LIMIT||height>drawing.DRAWING_IMAGE_HEIGHT_LIMIT){const scaleWidth=drawing.DRAWING_IMAGE_WIDTH_LIMIT/width,scaleHeight=drawing.DRAWING_IMAGE_HEIGHT_LIMIT/height;scale=Math.max(scaleWidth,scaleHeight)}const sheetTransform=this._getImagePosition(width*scale,height*scale,sceneWidth,sceneHeight);if(sheetTransform==null)return;const sheetDrawingParam={unitId,subUnitId,drawingId:imageId,drawingType:core.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType,source,transform:drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService),sheetTransform};return this._commandService.executeCommand(InsertSheetDrawingCommand.id,{unitId,drawings:[sheetDrawingParam]})}async _insertCellImage(file){let imageParam;try{imageParam=await this._imageIoService.saveImage(file)}catch(error){const type=error.message;type===drawing.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(drawing.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):type===drawing.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):type===drawing.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:design.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(imageParam==null)return;const{imageId,imageSourceType,source,base64Cache}=imageParam,{width,height,image}=await drawing.getImageSize(base64Cache||"");this._imageIoService.addImageSourceCache(source,imageSourceType,image);const selection=this._workbookSelections.getCurrentLastSelection();if(!selection)return!1;const docDataModel=core.createDocumentModelWithStyle("",{}),imageSize=getDrawingSizeByCell(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:selection.primary.actualRow,col:selection.primary.actualColumn},width,height,0);if(!imageSize)return!1;const docTransform={size:{width:imageSize.width,height:imageSize.height},positionH:{relativeFrom:core.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:core.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},docDrawingParam={unitId:docDataModel.getUnitId(),subUnitId:docDataModel.getUnitId(),drawingId:imageId,drawingType:core.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType,source,transform:docsUi.docDrawingPositionToTransform(docTransform),docTransform,behindDoc:core.BooleanNumber.FALSE,title:"",description:"",layoutType:core.PositionedObjectLayoutType.INLINE,wrapText:core.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},jsonXActions=core.BuildTextUtils.drawing.add({documentDataModel:docDataModel,drawings:[docDrawingParam],selection:{collapsed:!0,startOffset:0,endOffset:0}});return jsonXActions?(docDataModel.apply(jsonXActions),this._commandService.syncExecuteCommand(sheets.SetRangeValuesCommand.id,{value:{[selection.primary.actualRow]:{[selection.primary.actualColumn]:{p:docDataModel.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const workbook=this._context.unit,worksheet=workbook.getActiveSheet(),unitId=workbook.getUnitId(),subUnitId=worksheet.getSheetId();return{unitId,subUnitId}}_getImagePosition(imageWidth,imageHeight,sceneWidth,sceneHeight){const selections=this._workbookSelections.getCurrentSelections();let range={startRow:0,endRow:0,startColumn:0,endColumn:0};selections&&selections.length>0&&(range=selections[selections.length-1].range);const rangeWithCoord=sheetsUi.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,range);if(rangeWithCoord==null)return;let{startColumn,startRow,startX,startY}=rangeWithCoord,isChangeStart=!1;if(startX+imageWidth>sceneWidth&&(startX=sceneWidth-imageWidth,startX<0&&(startX=0,imageWidth=sceneWidth),isChangeStart=!0),startY+imageHeight>sceneHeight&&(startY=sceneHeight-imageHeight,startY<0&&(startY=0,imageHeight=sceneHeight),isChangeStart=!0),isChangeStart){const newCoord=this._selectionRenderService.getCellWithCoordByOffset(startX,startY);if(newCoord==null)return;startX=newCoord.startX,startY=newCoord.startY,startColumn=newCoord.actualColumn,startRow=newCoord.actualRow}const from={column:startColumn,columnOffset:0,row:startRow,rowOffset:0},endSelectionCell=this._selectionRenderService.getCellWithCoordByOffset(startX+imageWidth,startY+imageHeight);if(endSelectionCell==null)return;const to={column:endSelectionCell.actualColumn,columnOffset:startX+imageWidth-endSelectionCell.startX,row:endSelectionCell.actualRow,rowOffset:startY+imageHeight-endSelectionCell.startY};return{from,to}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(params=>{const{unitId,subUnitId,drawingIds,arrangeType}=params;this._commandService.executeCommand(SetDrawingArrangeCommand.id,{unitId,subUnitId,drawingIds,arrangeType})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(params=>{const drawings=[];params.length!==0&&(params.forEach(param=>{const{unitId,subUnitId,drawingId,drawingType,transform}=param;if(transform==null)return;const sheetDrawing=this._sheetDrawingService.getDrawingByParam({unitId,subUnitId,drawingId});if(sheetDrawing==null||sheetDrawing.unitId!==this._context.unitId)return;const sheetTransform=transformToDrawingPosition({...sheetDrawing.transform,...transform},this._selectionRenderService);if(sheetTransform==null)return;const newDrawing={...param,transform:{...sheetDrawing.transform,...transform,...drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...sheetTransform}};drawings.push(newDrawing)}),drawings.length>0&&this._commandService.executeCommand(SetSheetDrawingCommand.id,{unitId:params[0].unitId,drawings}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(params=>{this._commandService.executeCommand(GroupSheetDrawingCommand.id,params);const{unitId,subUnitId,drawingId}=params[0].parent;this._commandService.syncExecuteCommand(drawing.SetDrawingSelectedOperation.id,[{unitId,subUnitId,drawingId}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(params=>{this._commandService.executeCommand(UngroupSheetDrawingCommand.id,params)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(params=>{params==null||params.length===0?(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(core.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(params))}))}},__name(_c,"SheetDrawingUpdateController"),_c);SheetDrawingUpdateController=__decorateClass$a([__decorateParam$a(1,core.Inject(sheetsUi.SheetSkeletonManagerService)),__decorateParam$a(2,core.ICommandService),__decorateParam$a(3,sheetsUi.ISheetSelectionRenderService),__decorateParam$a(4,drawing.IImageIoService),__decorateParam$a(5,ui.ILocalFileService),__decorateParam$a(6,sheetsDrawing.ISheetDrawingService),__decorateParam$a(7,drawing.IDrawingManagerService),__decorateParam$a(8,core.IContextService),__decorateParam$a(9,ui.IMessageService),__decorateParam$a(10,core.Inject(core.LocaleService)),__decorateParam$a(11,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$a(12,core.Inject(core.Injector))],SheetDrawingUpdateController);var __defProp$9=Object.defineProperty,__getOwnPropDesc$9=Object.getOwnPropertyDescriptor,__decorateClass$9=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$9(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$9(target,key,result),result},"__decorateClass$9"),__decorateParam$9=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$9");function resizeImageByCell(injector,location,cell){var _a2,_b2,_c2,_d2;if(((_b2=(_a2=cell==null?void 0:cell.p)==null?void 0:_a2.body)==null?void 0:_b2.dataStream.length)===3&&((_d2=(_c2=cell.p)==null?void 0:_c2.drawingsOrder)==null?void 0:_d2.length)===1){const image=cell.p.drawings[cell.p.drawingsOrder[0]],imageSize=getDrawingSizeByCell(injector,{unitId:location.unitId,subUnitId:location.subUnitId,row:location.row,col:location.col},image.docTransform.size.width,image.docTransform.size.height,image.docTransform.angle);if(imageSize)return image.transform.width=imageSize.width,image.transform.height=imageSize.height,image.docTransform.size.width=imageSize.width,image.docTransform.size.height=imageSize.height,image.transform.left=0,image.transform.top=0,image.docTransform.positionH.posOffset=0,image.docTransform.positionV.posOffset=0,cell.p.documentStyle.pageSize.width=1/0,cell.p.documentStyle.pageSize.height=1/0,!0}return!1}__name(resizeImageByCell,"resizeImageByCell");let SheetCellImageController=(_d=class extends core.Disposable{constructor(_commandService,_sheetInterceptorService,_univerInstanceService,_injector,_drawingManagerService,_docDrawingController,_editorBridgeService){super(),this._commandService=_commandService,this._sheetInterceptorService=_sheetInterceptorService,this._univerInstanceService=_univerInstanceService,this._injector=_injector,this._drawingManagerService=_drawingManagerService,this._docDrawingController=_docDrawingController,this._editorBridgeService=_editorBridgeService,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{let sheetTarget,ranges=[];if(commandInfo.id===sheets.SetWorksheetRowHeightMutation.id){const params=commandInfo.params;ranges=params.ranges,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId})}else if(commandInfo.id===sheets.SetWorksheetColWidthMutation.id){const params=commandInfo.params;ranges=params.ranges,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId})}else if(commandInfo.id===sheets.SetWorksheetRowIsAutoHeightMutation.id){const params=commandInfo.params;ranges=params.ranges,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId})}else if(commandInfo.id===sheets.SetWorksheetRowAutoHeightMutation.id){const params=commandInfo.params;sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId}),ranges=params.rowsAutoHeightInfo.map(info=>({startRow:info.row,endRow:info.row,startColumn:0,endColumn:9999}))}else if(commandInfo.id===sheets.AddWorksheetMergeMutation.id){const params=commandInfo.params;ranges=params.ranges,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId})}else if(commandInfo.id===sheets.RemoveWorksheetMergeMutation.id){const params=commandInfo.params;ranges=params.ranges,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:params.unitId,subUnitId:params.subUnitId})}sheetTarget&&ranges.length&&ranges.forEach(range=>{const normalizedRange=core.Range.transformRange(range,sheetTarget.worksheet);for(let row=normalizedRange.startRow;row<=normalizedRange.endRow;row++)for(let col=normalizedRange.startColumn;col<=normalizedRange.endColumn;col++)resizeImageByCell(this._injector,{unitId:sheetTarget.unitId,subUnitId:sheetTarget.subUnitId,row,col},sheetTarget.worksheet.getCellRaw(row,col))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(param=>{param.visible?param.visible&&(this._drawingManagerService.removeDrawingDataForUnit(core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{commandInfo.id===docsUi.ReplaceSnapshotCommand.id&&commandInfo.params.unitId===core.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(core.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(core.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(core.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(sheets.AFTER_CELL_EDIT,{priority:9999,handler:__name((cell,context,next)=>(resizeImageByCell(this._injector,{unitId:context.unitId,subUnitId:context.subUnitId,row:context.row,col:context.col},cell),next(cell)),"handler")}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{effect:core.InterceptorEffectEnum.Style,priority:sheets.InterceptCellContentPriority.CELL_IMAGE,handler:__name((cell,pos,next)=>{var _a2;return cell!=null&&cell.p&&((_a2=cell.p.drawingsOrder)!=null&&_a2.length)&&(cell.interceptorStyle||(cell.interceptorStyle={}),cell.interceptorStyle.tr={a:0}),next(cell)},"handler")}))}},__name(_d,"SheetCellImageController"),_d);SheetCellImageController=__decorateClass$9([__decorateParam$9(0,core.ICommandService),__decorateParam$9(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$9(2,core.IUniverInstanceService),__decorateParam$9(3,core.Inject(core.Injector)),__decorateParam$9(4,drawing.IDrawingManagerService),__decorateParam$9(5,core.Inject(docsDrawing.DocDrawingController)),__decorateParam$9(6,core.Inject(sheetsUi.IEditorBridgeService))],SheetCellImageController);var __defProp$8=Object.defineProperty,__getOwnPropDesc$8=Object.getOwnPropertyDescriptor,__decorateClass$8=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$8(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$8(target,key,result),result},"__decorateClass$8"),__decorateParam$8=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$8");let SheetCellImageAutofillController=(_e=class extends core.Disposable{constructor(_autoFillService,_injector){super(),this._autoFillService=_autoFillService,this._injector=_injector,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:__name((location,direction,applyType,cellValue)=>{new core.ObjectMatrix(cellValue).forValue((row,col,cell)=>{resizeImageByCell(this._injector,{unitId:location.unitId,subUnitId:location.subUnitId,row,col},cell)})},"onBeforeSubmit")}))}},__name(_e,"SheetCellImageAutofillController"),_e);SheetCellImageAutofillController=__decorateClass$8([__decorateParam$8(0,core.Inject(sheetsUi.IAutoFillService)),__decorateParam$8(1,core.Inject(core.Injector))],SheetCellImageAutofillController);var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$7(target,key,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$7");let SheetCellImageHoverController=(_f=class extends core.Disposable{constructor(_hoverManagerService,_renderManagerService,_selectionsService,_drawingRenderService){super();__publicField(this,"_isSetCursor",!1);this._hoverManagerService=_hoverManagerService,this._renderManagerService=_renderManagerService,this._selectionsService=_selectionsService,this._drawingRenderService=_drawingRenderService}_initHover(){}_initImageClick(){}},__name(_f,"SheetCellImageHoverController"),_f);SheetCellImageHoverController=__decorateClass$7([__decorateParam$7(0,core.Inject(sheetsUi.HoverManagerService)),__decorateParam$7(1,core.Inject(engineRender.IRenderManagerService)),__decorateParam$7(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$7(3,core.Inject(drawingUi.DrawingRenderService))],SheetCellImageHoverController);const InsertFloatImageCommand={id:"sheet.command.insert-float-image",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{var _a2,_b2;const sheetDrawingUpdateController=(_a2=accessor.get(engineRender.IRenderManagerService).getCurrentTypeOfRenderer(core.UniverInstanceType.UNIVER_SHEET))==null?void 0:_a2.with(SheetDrawingUpdateController);if(!sheetDrawingUpdateController)return!1;const files=params==null?void 0:params.files;if(files){const awaitFiles=files.map(file=>sheetDrawingUpdateController.insertFloatImageByFile(file));return(await Promise.all(awaitFiles)).every(result=>result)}else return(_b2=sheetDrawingUpdateController.insertFloatImage())!=null?_b2:!1},"handler")},InsertCellImageCommand={id:"sheet.command.insert-cell-image",type:core.CommandType.COMMAND,handler:__name(accessor=>{var _a2,_b2;return(_b2=(_a2=accessor.get(engineRender.IRenderManagerService).getCurrentTypeOfRenderer(core.UniverInstanceType.UNIVER_SHEET))==null?void 0:_a2.with(SheetDrawingUpdateController).insertCellImage())!=null?_b2:!1},"handler")};var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$6");const IMAGE_PNG_MIME_TYPE="image/png";function base64ToBlob(base64){const arr=base64.split(","),binStr=atob(arr[1]),len=binStr.length,bytes=new Uint8Array(len);for(let i=0;i<len;i++)bytes[i]=binStr.charCodeAt(i);return new Blob([bytes],{type:IMAGE_PNG_MIME_TYPE})}__name(base64ToBlob,"base64ToBlob");function copyBase64ToClipboard(base64){const item=new ClipboardItem({[IMAGE_PNG_MIME_TYPE]:base64ToBlob(base64)});navigator.clipboard.write([item]).catch(err=>{console.error("Could not copy image using clipboard API: ",err)})}__name(copyBase64ToClipboard,"copyBase64ToClipboard");function focusDocument(){function createInputElement(){const input2=document.createElement("input");return input2.style.position="absolute",input2.style.height="1px",input2.style.width="1px",input2.style.opacity="0",input2}__name(createInputElement,"createInputElement");const activeElement=document.activeElement,input=createInputElement();return document.body.appendChild(input),input.focus(),()=>{input.blur(),document.body.removeChild(input),activeElement instanceof HTMLElement&&activeElement.focus()}}__name(focusDocument,"focusDocument");const specialPastes=[sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,sheetsUi.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let SheetsDrawingCopyPasteController=(_g=class extends core.Disposable{constructor(_sheetClipboardService,_renderManagerService,_drawingService,_clipboardInterfaceService,_commandService){super();__publicField(this,"_copyInfo");this._sheetClipboardService=_sheetClipboardService,this._renderManagerService=_renderManagerService,this._drawingService=_drawingService,this._clipboardInterfaceService=_clipboardInterfaceService,this._commandService=_commandService,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:__name((unitId,subUnitId,range,copyType)=>{const focusDrawings=this._focusedDrawings;if(focusDrawings.length>0){const[drawing$1]=focusDrawings;if(copyType===sheetsUi.COPY_TYPE.CUT){const params={unitId,drawings:[drawing$1]};this._commandService.executeCommand(RemoveSheetDrawingCommand.id,params)}setTimeout(()=>{const dispose=focusDocument();drawing$1.drawingType===core.DrawingTypeEnum.DRAWING_IMAGE&&drawing$1.imageSourceType===drawing.ImageSourceType.BASE64?copyBase64ToClipboard(drawing$1.source):this._clipboardInterfaceService.writeText(""),dispose()},200);const newCopyInfo={unitId:drawing$1.unitId,subUnitId:drawing$1.subUnitId,drawings:[drawing$1]};this._copyInfo=newCopyInfo}else{const newCopyInfo=this._createDrawingsCopyInfoByRange(unitId,subUnitId,range);this._copyInfo=newCopyInfo}},"onBeforeCopy"),onPasteCells:__name((pasteFrom,pasteTo,data,payload)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType=sheetsUi.COPY_TYPE.COPY,pasteType}=payload,{range:copyRange}=pasteFrom||{},{range:pasteRange,unitId,subUnitId}=pasteTo;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType,unitId,subUnitId,pasteRange},{copyRange,copyType}):this._generateSingleDrawingPasteMutations({pasteTo,pasteType},sheetsUi.COPY_TYPE.COPY)},"onPasteCells"),onPastePlainText:__name((pasteTo,clipText)=>({undos:[],redos:[]}),"onPastePlainText"),onPasteUnrecognized:__name(pasteTo=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo,pasteType:sheetsUi.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},sheetsUi.COPY_TYPE.COPY):{undos:[],redos:[]},"onPasteUnrecognized"),onPasteFiles:__name((pasteTo,files)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo,pasteType:sheetsUi.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},sheetsUi.COPY_TYPE.COPY);{const images=files.filter(file=>file.type.includes("image"));if(images.length)return{undos:[],redos:[{id:InsertFloatImageCommand.id,params:{files:images}}]}}return{undos:[],redos:[]}},"onPasteFiles")})}_createDrawingsCopyInfoByRange(unitId,subUnitId,range){var _a2;const skeletonManagerService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService);if(!skeletonManagerService)return;const selectionRect=skeletonManagerService.attachRangeWithCoord(range);if(!selectionRect)return;const{startX,endX,startY,endY}=selectionRect,drawings=this._drawingService.getDrawingData(unitId,subUnitId),containedDrawings=this._focusedDrawings.slice();if(Object.keys(drawings).forEach(drawingId=>{const drawing2=drawings[drawingId],{transform}=drawing2;if(drawing2.anchorType!==sheetsDrawing.SheetDrawingAnchorType.Both||!transform)return;const{left=0,top=0,width=0,height=0}=transform,{drawingStartX,drawingEndX,drawingStartY,drawingEndY}={drawingStartX:left,drawingEndX:left+width,drawingStartY:top,drawingEndY:top+height};startX<=drawingStartX&&drawingEndX<=endX&&startY<=drawingStartY&&drawingEndY<=endY&&containedDrawings.push(drawing2)}),containedDrawings.length)return{copyRange:range,drawings:containedDrawings,unitId,subUnitId}}_generateSingleDrawingPasteMutations(pasteContext,copyType){const{pasteType,pasteTo}=pasteContext;if(specialPastes.includes(pasteType))return{redos:[],undos:[]};const{unitId,subUnitId,range}=pasteTo,render2=this._renderManagerService.getRenderById(unitId),skeletonManagerService=render2==null?void 0:render2.with(sheetsUi.SheetSkeletonManagerService),selectionRenderService=render2==null?void 0:render2.with(sheetsUi.ISheetSelectionRenderService),copyInfo=this._copyInfo;if(!skeletonManagerService||!selectionRenderService)return{redos:[],undos:[]};const{drawings}=copyInfo,pasteRange=sheetsUi.discreteRangeToRange(range);return this._generateMutations(drawings,{unitId,subUnitId,isCut:copyType===sheetsUi.COPY_TYPE.CUT,getTransform:__name((transform,sheetTransform)=>{var _a2;const pasteRect=skeletonManagerService.attachRangeWithCoord({startRow:pasteRange.startRow,endRow:pasteRange.endRow,startColumn:pasteRange.startColumn,endColumn:pasteRange.endColumn}),newTransform={...transform,left:pasteRect==null?void 0:pasteRect.startX,top:pasteRect==null?void 0:pasteRect.startY};return{transform:newTransform,sheetTransform:(_a2=transformToDrawingPosition(newTransform,selectionRenderService))!=null?_a2:sheetTransform}},"getTransform")})}_generateMutations(drawings,payload){const{unitId,subUnitId,getTransform,isCut}=payload,redos=[],undos=[],{_drawingService}=this;return drawings.forEach(drawing2=>{const{transform,sheetTransform}=drawing2;if(!transform)return;const transformContext=getTransform(transform,sheetTransform),drawingObject={...drawing2,unitId,subUnitId,drawingId:isCut?drawing2.drawingId:core.Tools.generateRandomId(),transform:transformContext.transform,sheetTransform:transformContext.sheetTransform};if(isCut){const{undo,redo,objects}=_drawingService.getBatchUpdateOp([drawingObject]);redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,type:sheetsDrawing.DrawingApplyType.UPDATE,op:redo,objects}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,type:sheetsDrawing.DrawingApplyType.UPDATE,op:undo,objects}})}else{const{undo,redo,objects}=_drawingService.getBatchAddOp([drawingObject]);redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:redo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.INSERT}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{op:undo,unitId,subUnitId,objects,type:sheetsDrawing.DrawingApplyType.REMOVE}})}}),{redos,undos}}_generateRangeDrawingsPasteMutations(pasteContext,copyContext){var _a2;const{unitId,subUnitId,pasteType,pasteRange}=pasteContext,{copyRange,copyType}=copyContext;if(specialPastes.includes(pasteType))return{redos:[],undos:[]};const skeletonManagerService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService);if(!skeletonManagerService||!this._copyInfo)return{redos:[],undos:[]};const{drawings}=this._copyInfo;if(!copyRange)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId,subUnitId,range:sheetsUi.discreteRangeToRange(pasteRange)},pasteType},copyType);const{ranges:[vCopyRange,vPastedRange],mapFunc}=sheetsUi.virtualizeDiscreteRanges([copyRange,pasteRange]),{row:copyRow,col:copyCol}=mapFunc(vCopyRange.startRow,vCopyRange.startColumn),{row:pasteRow,col:pasteCol}=mapFunc(vPastedRange.startRow,vPastedRange.startColumn),copyRect=skeletonManagerService.attachRangeWithCoord({startRow:copyRow,endRow:copyRow,startColumn:copyCol,endColumn:copyCol}),pasteRect=skeletonManagerService.attachRangeWithCoord({startRow:pasteRow,endRow:pasteRow,startColumn:pasteCol,endColumn:pasteCol});if(!copyRect||!pasteRect||!this._copyInfo)return{redos:[],undos:[]};const leftOffset=pasteRect.startX-copyRect.startX,topOffset=pasteRect.startY-copyRect.startY,rowOffset=pasteRow-copyRow,columnOffset=pasteCol-copyCol;return this._generateMutations(drawings,{unitId,subUnitId,getTransform:__name((transform,sheetTransform)=>{var _a3,_b2;return{transform:{...transform,left:((_a3=transform==null?void 0:transform.left)!=null?_a3:0)+leftOffset,top:((_b2=transform==null?void 0:transform.top)!=null?_b2:0)+topOffset},sheetTransform:{...sheetTransform,to:{...sheetTransform.to,row:sheetTransform.to.row+rowOffset,column:sheetTransform.to.column+columnOffset},from:{...sheetTransform.from,row:sheetTransform.from.row+rowOffset,column:sheetTransform.from.column+columnOffset}}}},"getTransform"),isCut:copyType===sheetsUi.COPY_TYPE.CUT})}},__name(_g,"SheetsDrawingCopyPasteController"),_g);SheetsDrawingCopyPasteController=__decorateClass$6([__decorateParam$6(0,sheetsUi.ISheetClipboardService),__decorateParam$6(1,engineRender.IRenderManagerService),__decorateParam$6(2,drawing.IDrawingManagerService),__decorateParam$6(3,ui.IClipboardInterfaceService),__decorateParam$6(4,core.ICommandService)],SheetsDrawingCopyPasteController);var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");let SheetDrawingPermissionController=(_h=class extends core.Disposable{constructor(_drawingManagerService,_renderManagerService,_permissionService,_univerInstanceService,_userManagerService){super(),this._drawingManagerService=_drawingManagerService,this._renderManagerService=_renderManagerService,this._permissionService=_permissionService,this._univerInstanceService=_univerInstanceService,this._userManagerService=_userManagerService,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{if(!workbook){this._drawingManagerService.setDrawingVisible(!1);return}workbook.activeSheet$.subscribe(sheet=>{if(!sheet){this._drawingManagerService.setDrawingVisible(!1);return}const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();if(this._permissionService.composePermission([new sheets.WorkbookViewPermission(unitId).id,new sheets.WorksheetViewPermission(unitId,subUnitId).id]).every(permission=>permission.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject=this._renderManagerService.getRenderById(unitId2),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;scene.getAllObjectsByOrder().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.removeObject(object)})}})}))}_initDrawingEditable(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{if(!workbook){this._drawingManagerService.setDrawingEditable(!1);return}workbook.activeSheet$.subscribe(sheet=>{if(!sheet){this._drawingManagerService.setDrawingEditable(!1);return}const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();if(this._permissionService.composePermission([new sheets.WorkbookEditablePermission(unitId).id,new sheets.WorksheetEditPermission(unitId,subUnitId).id]).every(permission=>permission.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject=this._renderManagerService.getRenderById(unitId2),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;scene.getAllObjectsByOrder().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.detachTransformerFrom(object)})}})}))}_initViewPermissionChange(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{workbook&&workbook.activeSheet$.subscribe(sheet=>{var _a2;if(!sheet)return;const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();let initialViewPermission=!0;const renderObject=this._renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),worksheetViewPermission$=this._permissionService.composePermission$([new sheets.WorkbookViewPermission(unitId).id,new sheets.WorksheetViewPermission(unitId,subUnitId).id]).pipe(rxjs.map(permissions=>permissions.every(item=>item.value)));worksheetViewPermission$==null||worksheetViewPermission$.pipe(rxjs.filter(permission=>permission!==initialViewPermission),rxjs.distinctUntilChanged()).subscribe({next:__name(permission=>{initialViewPermission=permission,this._drawingManagerService.setDrawingVisible(permission);const objects=scene.getAllObjectsByOrder(),drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);permission?this._drawingManagerService.addNotification(drawingDataValues):(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.removeObject(object)}),transformer.clearSelectedObjects())},"next")}),(_a2=this._permissionService.getPermissionPoint$(new sheets.WorksheetViewPermission(unitId,subUnitId).id))==null||_a2.pipe(rxjs.filter(permission=>permission.value!==initialViewPermission),rxjs.distinctUntilChanged()).subscribe({complete:__name(()=>{initialViewPermission=!0,this._drawingManagerService.setDrawingVisible(!0);const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);this._drawingManagerService.addNotification(drawingDataValues)},"complete")})})}))}_initEditPermissionChange(){const workbook$=this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(rxjs.combineLatest([workbook$,this._userManagerService.currentUser$]).subscribe(([workbook,_])=>{workbook&&workbook.activeSheet$.subscribe(sheet=>{var _a2;if(!sheet)return;const unitId=workbook.getUnitId(),subUnitId=sheet.getSheetId();let initialEditPermission=!0;const renderObject=this._renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),composeWorksheetEditPermission=this._permissionService.composePermission$([new sheets.WorkbookEditablePermission(unitId).id,new sheets.WorksheetEditPermission(unitId,subUnitId).id]).pipe(rxjs.map(permissions=>permissions.every(item=>item.value)));composeWorksheetEditPermission==null||composeWorksheetEditPermission.pipe(rxjs.filter(permission=>permission!==initialEditPermission),rxjs.distinctUntilChanged()).subscribe({next:__name(permission=>{initialEditPermission=permission,this._drawingManagerService.setDrawingEditable(permission);const objects=scene.getAllObjectsByOrder(),drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),drawingDataValues=Object.values(drawingData);permission?(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.attachTransformerTo(object)}),this._drawingManagerService.addNotification(drawingDataValues)):(objects.forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene.detachTransformerFrom(object)}),transformer.clearSelectedObjects())},"next")}),(_a2=this._permissionService.getPermissionPoint$(new sheets.WorksheetEditPermission(unitId,subUnitId).id))==null||_a2.pipe(rxjs.filter(permission=>permission.value!==initialEditPermission),rxjs.distinctUntilChanged()).subscribe({complete:__name(()=>{initialEditPermission=!0;const unitId2=workbook.getUnitId(),subUnitId2=sheet.getSheetId(),drawingData=this._drawingManagerService.getDrawingData(unitId2,subUnitId2),drawingDataValues=Object.values(drawingData),renderObject2=this._renderManagerService.getRenderById(unitId2),scene2=renderObject2==null?void 0:renderObject2.scene;if(scene2==null)return;this._drawingManagerService.setDrawingEditable(!0),scene2.getAllObjectsByOrder().forEach(object=>{object.classType===engineRender.RENDER_CLASS_TYPE.IMAGE&&drawingDataValues.some(item=>object.oKey.includes(item.drawingId))&&scene2.detachTransformerFrom(object)})},"complete")})})}))}},__name(_h,"SheetDrawingPermissionController"),_h);SheetDrawingPermissionController=__decorateClass$5([__decorateParam$5(0,drawing.IDrawingManagerService),__decorateParam$5(1,engineRender.IRenderManagerService),__decorateParam$5(2,core.IPermissionService),__decorateParam$5(3,core.IUniverInstanceService),__decorateParam$5(4,core.Inject(core.UserManagerService))],SheetDrawingPermissionController);var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");let SheetDrawingPrintingController=(_i=class extends core.Disposable{constructor(_sheetPrintInterceptorService,_drawingRenderService,_drawingManagerService,_renderManagerService){super(),this._sheetPrintInterceptorService=_sheetPrintInterceptorService,this._drawingRenderService=_drawingRenderService,this._drawingManagerService=_drawingManagerService,this._renderManagerService=_renderManagerService,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:__name((_param,pos,next)=>{const{unitId,scene,subUnitId}=pos,unitData=this._drawingManagerService.getDrawingDataForUnit(unitId),subUnitData=unitData==null?void 0:unitData[subUnitId];return subUnitData&&subUnitData.order.forEach(id=>{this._drawingRenderService.renderDrawing(subUnitData.data[id],scene)}),next()},"handler")})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:__name((range,pos,next)=>{const{unitId,subUnitId}=pos,renderer=this._renderManagerService.getRenderById(unitId);if(!renderer)return next(range);const skeleton=renderer.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(!skeleton)return next(range);const unitData=this._drawingManagerService.getDrawingDataForUnit(unitId),subUnitData=unitData==null?void 0:unitData[pos.subUnitId];if(!subUnitData)return next(range);const{scaleX,scaleY}=renderer.scene,newRange=range?{...range}:{startColumn:0,endColumn:0,endRow:0,startRow:0},data=subUnitData.order.map(key=>subUnitData.data[key]).filter(item=>item.drawingType!==core.DrawingTypeEnum.DRAWING_DOM);return data.length?(data.forEach(param=>{if(!param.groupId&&param.transform&&core.Tools.isDefine(param.transform.left)&&core.Tools.isDefine(param.transform.top)&&core.Tools.isDefine(param.transform.width)&&core.Tools.isDefine(param.transform.height)){const start=skeleton.skeleton.getCellIndexByOffset(param.transform.left,param.transform.top,scaleX,scaleY,{x:0,y:0}),end=skeleton.skeleton.getCellIndexByOffset(param.transform.left+param.transform.width,param.transform.top+param.transform.height,scaleX,scaleY,{x:0,y:0});start.column<newRange.startColumn&&(newRange.startColumn=start.column),start.row<newRange.startRow&&(newRange.startRow=start.row),newRange.endRow<end.row&&(newRange.endRow=end.row),newRange.endColumn<end.column&&(newRange.endColumn=end.column)}}),next(newRange)):next(range)},"handler")}))}},__name(_i,"SheetDrawingPrintingController"),_i);SheetDrawingPrintingController=__decorateClass$4([__decorateParam$4(0,core.Inject(sheetsUi.SheetPrintInterceptorService)),__decorateParam$4(1,core.Inject(drawingUi.DrawingRenderService)),__decorateParam$4(2,drawing.IDrawingManagerService),__decorateParam$4(3,engineRender.IRenderManagerService)],SheetDrawingPrintingController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");const UPDATE_COMMANDS=[sheets.InsertRowCommand.id,sheets.InsertColCommand.id,sheets.RemoveRowCommand.id,sheets.RemoveColCommand.id,sheets.DeleteRangeMoveLeftCommand.id,sheets.DeleteRangeMoveUpCommand.id,sheets.InsertRangeMoveDownCommand.id,sheets.InsertRangeMoveRightCommand.id,sheets.DeltaRowHeightCommand.id,sheets.SetRowHeightCommand.id,sheets.DeltaColumnWidthCommand.id,sheets.SetColWidthCommand.id,sheets.SetRowHiddenCommand.id,sheets.SetSpecificRowsVisibleCommand.id,sheets.SetSpecificColsVisibleCommand.id,sheets.SetColHiddenCommand.id,sheets.MoveColsCommand.id,sheets.MoveRowsCommand.id,sheets.MoveRangeCommand.id],REFRESH_MUTATIONS=[sheets.SetRowVisibleMutation.id,sheets.SetRowHiddenMutation.id,sheets.SetColVisibleMutation.id,sheets.SetColHiddenMutation.id,sheets.SetWorksheetRowHeightMutation.id,sheets.SetWorksheetColWidthMutation.id];let SheetDrawingTransformAffectedController=(_j=class extends core.Disposable{constructor(_context,_renderManagerService,_commandService,_selectionRenderService,_skeletonManagerService,_sheetInterceptorService,_sheetDrawingService,_drawingManagerService,_univerInstanceService){super(),this._context=_context,this._renderManagerService=_renderManagerService,this._commandService=_commandService,this._selectionRenderService=_selectionRenderService,this._skeletonManagerService=_skeletonManagerService,this._sheetInterceptorService=_sheetInterceptorService,this._sheetDrawingService=_sheetDrawingService,this._drawingManagerService=_drawingManagerService,this._univerInstanceService=_univerInstanceService,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(commandInfo=>{if(!UPDATE_COMMANDS.includes(commandInfo.id))return{redos:[],undos:[]};if(commandInfo.params==null)return{redos:[],undos:[]};const cId=commandInfo.id;if(cId===sheets.InsertRowCommand.id)return this._moveRowInterceptor(commandInfo.params,"insert");if([sheets.MoveColsCommand.id,sheets.MoveRowsCommand.id,sheets.MoveRangeCommand.id].includes(cId))return this._moveRangeInterceptor(commandInfo.params);if(cId===sheets.InsertColCommand.id)return this._moveColInterceptor(commandInfo.params,"insert");if(cId===sheets.RemoveRowCommand.id)return this._moveRowInterceptor(commandInfo.params,"remove");if(cId===sheets.RemoveColCommand.id)return this._moveColInterceptor(commandInfo.params,"remove");if(cId===sheets.DeleteRangeMoveLeftCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,0)}else if(cId===sheets.DeleteRangeMoveUpCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,1)}else if(cId===sheets.InsertRangeMoveDownCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,2)}else if(cId===sheets.InsertRangeMoveRightCommand.id){const{range}=commandInfo.params;return this._getRangeMoveUndo(range,3)}else if(cId===sheets.SetRowHiddenCommand.id||cId===sheets.SetSpecificRowsVisibleCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params;return this._getDrawingUndoForRowVisible(unitId,subUnitId,ranges)}else if(cId===sheets.SetSpecificColsVisibleCommand.id||cId===sheets.SetColHiddenCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params;return this._getDrawingUndoForColVisible(unitId,subUnitId,ranges)}else if(cId===sheets.DeltaRowHeightCommand.id||cId===sheets.SetRowHeightCommand.id||cId===sheets.DeltaColumnWidthCommand.id||cId===sheets.SetColWidthCommand.id){const params=commandInfo.params,{unitId,subUnitId,ranges}=params,isRow=cId===sheets.DeltaRowHeightCommand.id||cId===sheets.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(unitId,subUnitId,ranges,isRow)}return{redos:[],undos:[]}},"getMutations")}))}_getRangeMoveUndo(range,type){const newParams=sheets.getSheetCommandTarget(this._univerInstanceService);if(newParams==null)return{redos:[],undos:[]};const unitId=newParams.unitId,subUnitId=newParams.subUnitId,redos=[],undos=[],drawingData=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{updateDrawings:updateDrawingsPart,deleteDrawings:deleteDrawingsPart}=this._getUpdateOrDeleteDrawings(range,type,drawing2);updateDrawings.push(...updateDrawingsPart),deleteDrawings.push(...deleteDrawingsPart)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_getUpdateOrDeleteDrawings(range,type,drawing2){const updateDrawings=[],deleteDrawings=[],{sheetTransform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position,transform,unitId,subUnitId,drawingId}=drawing2,{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;if(sheetTransform==null||transform==null)return{updateDrawings,deleteDrawings};const{startRow,endRow,startColumn,endColumn}=range;let newSheetTransform=null,newTransform=null;if(type===0&&fromRow>=startRow&&toRow<=endRow)if(fromColumn>=startColumn&&toColumn<=endColumn)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkCol(sheetTransform,transform,startColumn,endColumn,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===1&&fromColumn>=startColumn&&toColumn<=endColumn)if(fromRow>=startRow&&toRow<=endRow)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkRow(sheetTransform,transform,startRow,endRow,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===2){const param=this._expandRow(sheetTransform,transform,startRow,endRow,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else if(type===3){const param=this._expandCol(sheetTransform,transform,startColumn,endColumn,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}if(newSheetTransform!=null&&newTransform!=null){const newTransform2=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform2})}return{updateDrawings,deleteDrawings}}_remainDrawingSize(transform,updateDrawings,drawing2){const newSheetTransform=transformToDrawingPosition({...transform},this._selectionRenderService);newSheetTransform!=null&&updateDrawings.push({...drawing2,sheetTransform:newSheetTransform})}_getDrawingUndoForColVisible(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[],preUpdateDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toColumn<startColumn)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position){let newSheetTransform2=null,newTransform2=null;if(fromColumn>=startColumn&&fromColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:fromColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform2={...transform,left:selectionCell.startX}}if(newTransform2!=null&&(newSheetTransform2=transformToDrawingPosition(newTransform2,this._selectionRenderService),newSheetTransform2!=null&&newTransform2!=null)){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform2,transform:newTransform2});break}this._remainDrawingSize(transform,updateDrawings,drawing2);continue}if(fromColumn>=startColumn&&toColumn<=endColumn)continue;let newSheetTransform=null,newTransform=null;if(fromColumn>=startColumn&&fromColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:fromColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(selectionCell==null?void 0:selectionCell.startX)||0,width:((transform==null?void 0:transform.width)||0)-selectionCell.endX+selectionCell.startX}}else if(toColumn>=startColumn&&toColumn<=endColumn){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn,endColumn:toColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:selectionCell.startX-((transform==null?void 0:transform.width)||0)}}else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn,endColumn,startRow:from.row,endRow:to.row});if(selectionCell==null)return;if(newTransform={...transform,width:((transform==null?void 0:transform.width)||0)-selectionCell.endX+selectionCell.startX},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService),newSheetTransform!=null&&newTransform!=null){preUpdateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}}if(newTransform!=null&&(newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)),newTransform!=null&&newSheetTransform!=null){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}else this._remainDrawingSize(transform,updateDrawings,drawing2)}}}),updateDrawings.length===0&&preUpdateDrawings.length===0)return{redos:[],undos:[]};const{redos,undos}=this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings),preRedos=[],preUndos=[];if(preUpdateDrawings.length>0){const{redos:redos2,undos:undos2}=this._createUndoAndRedoMutation(unitId,subUnitId,preUpdateDrawings);preRedos.push(...redos2),preUndos.push(...undos2)}return{redos,undos,preRedos,preUndos}}_createUndoAndRedoMutation(unitId,subUnitId,updateDrawings){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp,redos=[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}],undos=[{id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}},{id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}];return{redos,undos}}_getDrawingUndoForRowVisible(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[],preUpdateDrawings=[];if(Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toRow<startRow)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position){let newSheetTransform2=null,newTransform2=null;if(fromRow>=startRow&&fromRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow:fromRow,endRow});if(selectionCell==null)return;newTransform2={...transform,top:selectionCell.startY}}if(newTransform2!=null&&(newSheetTransform2=transformToDrawingPosition(newTransform2,this._selectionRenderService),newSheetTransform2!=null&&newTransform2!=null)){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform2,transform:newTransform2});break}this._remainDrawingSize(transform,updateDrawings,drawing2);continue}if(fromRow>=startRow&&toRow<=endRow)continue;let newSheetTransform=null,newTransform=null;if(fromRow>=startRow&&fromRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow:fromRow,endRow});if(selectionCell==null)return;newTransform={...transform,top:(selectionCell==null?void 0:selectionCell.startY)||0,height:((transform==null?void 0:transform.height)||0)-selectionCell.endY+selectionCell.startY}}else if(toRow>=startRow&&toRow<=endRow){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow,endRow:toRow});if(selectionCell==null)return;newTransform={...transform,top:selectionCell.startY-((transform==null?void 0:transform.height)||0)}}else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:to.column,startRow,endRow});if(selectionCell==null)return;if(newTransform={...transform,height:((transform==null?void 0:transform.height)||0)-selectionCell.endY+selectionCell.startY},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService),newSheetTransform!=null&&newTransform!=null){preUpdateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}}if(newTransform!=null&&(newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)),newTransform!=null&&newSheetTransform!=null){updateDrawings.push({...drawing2,sheetTransform:newSheetTransform,transform:newTransform});break}else this._remainDrawingSize(transform,updateDrawings,drawing2)}}}),updateDrawings.length===0&&preUpdateDrawings.length===0)return{redos:[],undos:[]};const{redos,undos}=this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings),preRedos=[],preUndos=[];if(preUpdateDrawings.length>0){const{redos:redos2,undos:undos2}=this._createUndoAndRedoMutation(unitId,subUnitId,preUpdateDrawings);preRedos.push(...redos2),preUndos.push(...undos2)}return{redos,undos,preRedos,preUndos}}_getDrawingUndoForRowAndColSize(unitId,subUnitId,ranges,isRow){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[];return Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)this._remainDrawingSize(transform,updateDrawings,drawing2);else{const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(toRow<startRow||toColumn<startColumn)continue;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Position&&(fromRow<=startRow&&toRow>=endRow||fromColumn<=startColumn&&toColumn>=endColumn)){this._remainDrawingSize(transform,updateDrawings,drawing2);continue}const newTransform=drawingPositionToTransform({...sheetTransform},this._selectionRenderService,this._skeletonManagerService);if(newTransform!=null){updateDrawings.push({...drawing2,transform:newTransform});break}}}}),updateDrawings.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(unitId,subUnitId,updateDrawings)}_getUnitIdAndSubUnitId(params,type){let unitId,subUnitId;if(type==="insert")unitId=params.unitId,subUnitId=params.subUnitId;else{const newParams=sheets.getSheetCommandTarget(this._univerInstanceService);if(newParams==null)return;unitId=newParams.unitId,subUnitId=newParams.subUnitId}return{unitId,subUnitId}}_moveRangeInterceptor(params){var _a2,_b2;const{toRange,fromRange}=params,target=sheets.getSheetCommandTarget(this._univerInstanceService);if(!target)return{redos:[],undos:[]};const{unitId,subUnitId}=target,skeleton=(_b2=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService))==null?void 0:_b2.getCurrentSkeleton();if(!skeleton)return{redos:[],undos:[]};const selectionRect=sheetsUi.attachRangeWithCoord(skeleton,fromRange);if(!selectionRect)return{redos:[],undos:[]};const{startX,endX,startY,endY}=selectionRect,drawings=this._sheetDrawingService.getDrawingData(unitId,subUnitId),containedDrawings=[];Object.keys(drawings).forEach(drawingId=>{const drawing2=drawings[drawingId];if(drawing2.anchorType!==sheetsDrawing.SheetDrawingAnchorType.Both)return;const{transform}=drawing2;if(!transform)return;const{left=0,top=0,width=0,height=0}=transform,{drawingStartX,drawingEndX,drawingStartY,drawingEndY}={drawingStartX:left,drawingEndX:left+width,drawingStartY:top,drawingEndY:top+height};startX<=drawingStartX&&drawingEndX<=endX&&startY<=drawingStartY&&drawingEndY<=endY&&containedDrawings.push(drawing2)});const redos=[],undos=[],rowOffset=toRange.startRow-fromRange.startRow,colOffset=toRange.startColumn-fromRange.startColumn,updateDrawings=containedDrawings.map(drawing2=>{const oldSheetTransform=drawing2.sheetTransform,sheetTransform={to:{...oldSheetTransform.to,row:oldSheetTransform.to.row+rowOffset,column:oldSheetTransform.to.column+colOffset},from:{...oldSheetTransform.from,row:oldSheetTransform.from.row+rowOffset,column:oldSheetTransform.from.column+colOffset}},transform=drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService);return{unitId,subUnitId,drawingId:drawing2.drawingId,transform,sheetTransform}});if(updateDrawings.length){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}return{redos,undos}}_moveRowInterceptor(params,type){const ids=this._getUnitIdAndSubUnitId(params,type);if(ids==null)return{redos:[],undos:[]};const{unitId,subUnitId}=ids,{range}=params,rowStartIndex=range.startRow,rowEndIndex=range.endRow,redos=[],undos=[],data=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(data).forEach(drawingId=>{const drawing2=data[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(sheetTransform==null||transform==null)return;let newSheetTransform,newTransform;if(type==="insert"){const param=this._expandRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else{const{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both&&fromRow>=rowStartIndex&&toRow<=rowEndIndex)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}}if(!newSheetTransform||!newTransform)return;const params2={unitId,subUnitId,drawingId,transform:newTransform,sheetTransform:newSheetTransform};updateDrawings.push(params2)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_moveColInterceptor(params,type){const ids=this._getUnitIdAndSubUnitId(params,type);if(ids==null)return{redos:[],undos:[]};const{unitId,subUnitId}=ids,{range}=params,colStartIndex=range.startColumn,colEndIndex=range.endColumn,redos=[],undos=[],data=this._sheetDrawingService.getDrawingData(unitId,subUnitId),updateDrawings=[],deleteDrawings=[];if(Object.keys(data).forEach(drawingId=>{const drawing2=data[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(sheetTransform==null||transform==null)return;let newSheetTransform,newTransform;if(type==="insert"){const param=this._expandCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}else{const{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both&&fromColumn>=colStartIndex&&toColumn<=colEndIndex)deleteDrawings.push({unitId,subUnitId,drawingId});else{const param=this._shrinkCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType);newSheetTransform=param==null?void 0:param.newSheetTransform,newTransform=param==null?void 0:param.newTransform}}if(!newSheetTransform||!newTransform)return;const params2={unitId,subUnitId,drawingId,transform:newTransform,sheetTransform:newSheetTransform};updateDrawings.push(params2)}),updateDrawings.length===0&&deleteDrawings.length===0)return{redos:[],undos:[]};if(updateDrawings.length>0){const updateJsonOp=this._sheetDrawingService.getBatchUpdateOp(updateDrawings),{undo,redo,objects}=updateJsonOp;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:undo,objects,type:sheetsDrawing.DrawingApplyType.UPDATE}})}if(deleteDrawings.length>0){const deleteJsonOp=this._sheetDrawingService.getBatchRemoveOp(deleteDrawings),deleteUndo=deleteJsonOp.undo,deleteRedo=deleteJsonOp.redo,deleteObjects=deleteJsonOp.objects;redos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteRedo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.REMOVE}}),undos.push({id:sheetsDrawing.SetDrawingApplyMutation.id,params:{unitId,subUnitId,op:deleteUndo,objects:deleteObjects,type:sheetsDrawing.DrawingApplyType.INSERT}})}return redos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),undos.push({id:ClearSheetDrawingTransformerOperation.id,params:[unitId]}),{redos,undos}}_expandCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const colCount=colEndIndex-colStartIndex+1,{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromColumn>=colStartIndex){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex,endColumn:colEndIndex,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(transform.left||0)+selectionCell.endX-selectionCell.startX},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toColumn>=colEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,column:toColumn+colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_shrinkCol(sheetTransform,transform,colStartIndex,colEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const colCount=colEndIndex-colStartIndex+1,{from,to}=sheetTransform,{column:fromColumn}=from,{column:toColumn}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromColumn>colEndIndex)newSheetTransform={from:{...from,column:fromColumn-colCount},to:{...to,column:toColumn-colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else{if(fromColumn>=colStartIndex&&toColumn<=colEndIndex)return null;if(fromColumn<colStartIndex&&toColumn>colEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,column:toColumn-colCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};else if(fromColumn>=colStartIndex&&fromColumn<=colEndIndex){if(fromColumn===colStartIndex)newTransform={...transform,left:(transform.left||0)-sheetTransform.from.columnOffset};else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex,endColumn:fromColumn-1,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newTransform={...transform,left:(transform.left||0)-selectionCell.endX+selectionCell.startX-sheetTransform.from.columnOffset}}newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toColumn>=colStartIndex&&toColumn<=colEndIndex&&anchorType===sheetsDrawing.SheetDrawingAnchorType.Both){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:colStartIndex-1,endColumn:colStartIndex-1,startRow:from.row,endRow:to.row});if(selectionCell==null)return;newSheetTransform={from:{...from},to:{...to,column:colStartIndex-1,columnOffset:selectionCell.endX-selectionCell.startX}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService)}}return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_expandRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const rowCount=rowEndIndex-rowStartIndex+1,{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromRow>=rowStartIndex){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startRow:rowStartIndex,endRow:rowEndIndex,startColumn:from.column,endColumn:to.column});if(selectionCell==null)return;newTransform={...transform,top:(transform.top||0)+selectionCell.endY-selectionCell.startY},newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toRow>=rowEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,row:toRow+rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_shrinkRow(sheetTransform,transform,rowStartIndex,rowEndIndex,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position){const rowCount=rowEndIndex-rowStartIndex+1,{from,to}=sheetTransform,{row:fromRow}=from,{row:toRow}=to;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};let newSheetTransform=null,newTransform=null;if(fromRow>rowEndIndex)newSheetTransform={from:{...from,row:fromRow-rowCount},to:{...to,row:toRow-rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else{if(fromRow>=rowStartIndex&&toRow<=rowEndIndex)return null;if(fromRow<rowStartIndex&&toRow>rowEndIndex)if(anchorType===sheetsDrawing.SheetDrawingAnchorType.Both)newSheetTransform={from:{...from},to:{...to,row:toRow-rowCount}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:transformToDrawingPosition({...transform},this._selectionRenderService),newTransform:transform};else if(fromRow>=rowStartIndex&&fromRow<=rowEndIndex){if(fromRow===rowStartIndex)newTransform={...transform,top:(transform.top||0)-sheetTransform.from.rowOffset};else{const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startRow:rowStartIndex,endRow:fromRow-1,startColumn:from.column,endColumn:to.column});if(selectionCell==null)return;newTransform={...transform,top:(transform.top||0)-selectionCell.endY+selectionCell.startY-sheetTransform.from.rowOffset}}newSheetTransform=transformToDrawingPosition(newTransform,this._selectionRenderService)}else if(toRow>=rowStartIndex&&toRow<=rowEndIndex&&anchorType===sheetsDrawing.SheetDrawingAnchorType.Both){const selectionCell=this._skeletonManagerService.attachRangeWithCoord({startColumn:from.column,endColumn:from.column,startRow:rowStartIndex-1,endRow:rowStartIndex-1});if(selectionCell==null)return;newSheetTransform={from:{...from},to:{...to,row:rowStartIndex-1,rowOffset:selectionCell.endY-selectionCell.startY}},newTransform=drawingPositionToTransform(newSheetTransform,this._selectionRenderService,this._skeletonManagerService)}}return newSheetTransform!=null&&newTransform!=null?{newSheetTransform,newTransform}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(command=>{command.id===sheets.SetWorksheetActiveOperation.id&&setTimeout(()=>{const params=command.params,{unitId:showUnitId,subUnitId:showSubunitId}=params,drawingMap=this._drawingManagerService.drawingManagerData,insertDrawings=[],removeDrawings=[];Object.keys(drawingMap).forEach(unitId=>{const subUnitMap=drawingMap[unitId];subUnitMap!=null&&Object.keys(subUnitMap).forEach(subUnitId=>{const drawingData=subUnitMap[subUnitId].data;drawingData!=null&&Object.keys(drawingData).forEach(drawingId=>{if(unitId===showUnitId&&subUnitId===showSubunitId){const drawing2=drawingData[drawingId];drawing2.transform=drawingPositionToTransform(drawing2.sheetTransform,this._selectionRenderService,this._skeletonManagerService),insertDrawings.push(drawingData[drawingId])}else removeDrawings.push(drawingData[drawingId])})})}),this._drawingManagerService.removeNotification(removeDrawings),this._drawingManagerService.addNotification(insertDrawings)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(command=>{REFRESH_MUTATIONS.includes(command.id)&&requestIdleCallback(()=>{const params=command.params,{unitId,subUnitId,ranges}=params;this._refreshDrawingTransform(unitId,subUnitId,ranges)})}))}_refreshDrawingTransform(unitId,subUnitId,ranges){const drawingData=this._drawingManagerService.getDrawingData(unitId,subUnitId),updateDrawings=[];Object.keys(drawingData).forEach(drawingId=>{const drawing2=drawingData[drawingId],{sheetTransform,transform,anchorType=sheetsDrawing.SheetDrawingAnchorType.Position}=drawing2;if(anchorType===sheetsDrawing.SheetDrawingAnchorType.None)return!0;const{from,to}=sheetTransform,{row:fromRow,column:fromColumn}=from,{row:toRow,column:toColumn}=to;for(let i=0;i<ranges.length;i++){const range=ranges[i],{startRow,endRow,startColumn,endColumn}=range;if(core.Rectangle.intersects({startRow,endRow,startColumn,endColumn},{startRow:fromRow,endRow:toRow,startColumn:fromColumn,endColumn:toColumn})||fromRow>endRow||fromColumn>endColumn){const isPositionAnchor=anchorType===sheetsDrawing.SheetDrawingAnchorType.Position,newTransform=drawingPositionToTransform(sheetTransform,this._selectionRenderService,this._skeletonManagerService);updateDrawings.push({...drawing2,transform:{...newTransform,width:isPositionAnchor?transform==null?void 0:transform.width:newTransform==null?void 0:newTransform.width,height:isPositionAnchor?transform==null?void 0:transform.height:newTransform==null?void 0:newTransform.height}});break}}}),updateDrawings.length!==0&&(this._drawingManagerService.refreshTransform(updateDrawings),this._commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id,[unitId]))}},__name(_j,"SheetDrawingTransformAffectedController"),_j);SheetDrawingTransformAffectedController=__decorateClass$3([__decorateParam$3(1,engineRender.IRenderManagerService),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,sheetsUi.ISheetSelectionRenderService),__decorateParam$3(4,core.Inject(sheetsUi.SheetSkeletonManagerService)),__decorateParam$3(5,core.Inject(sheets.SheetInterceptorService)),__decorateParam$3(6,sheetsDrawing.ISheetDrawingService),__decorateParam$3(7,drawing.IDrawingManagerService),__decorateParam$3(8,core.IUniverInstanceService)],SheetDrawingTransformAffectedController);var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element={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"}}]},AddImageSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"add-image-single",ref,icon:element}))});AddImageSingle.displayName="AddImageSingle";const DeleteDrawingsCommand={id:"sheet.command.delete-drawing",type:core.CommandType.COMMAND,handler:__name(accessor=>{const commandService=accessor.get(core.ICommandService),drawings=accessor.get(sheetsDrawing.ISheetDrawingService).getFocusDrawings();if(drawings.length===0)return!1;const unitId=drawings[0].unitId,newDrawings=drawings.map(drawing2=>{const{unitId:unitId2,subUnitId,drawingId,drawingType}=drawing2;return{unitId:unitId2,subUnitId,drawingId,drawingType}});return commandService.executeCommand(RemoveSheetDrawingCommand.id,{unitId,drawings:newDrawings})},"handler")},MoveDrawingsCommand={id:"sheet.command.move-drawing",type:core.CommandType.COMMAND,handler:__name((accessor,params)=>{const commandService=accessor.get(core.ICommandService),drawingManagerService=accessor.get(sheetsDrawing.ISheetDrawingService),selectionRenderService=accessor.get(sheetsUi.ISheetSelectionRenderService),{direction}=params,drawings=drawingManagerService.getFocusDrawings();if(drawings.length===0)return!1;const unitId=drawings[0].unitId,newDrawings=drawings.map(drawing2=>{const{transform}=drawing2;if(transform==null)return null;const newTransform={...transform},{left=0,top=0}=transform;return direction===core.Direction.UP?newTransform.top=top-1:direction===core.Direction.DOWN?newTransform.top=top+1:direction===core.Direction.LEFT?newTransform.left=left-1:direction===core.Direction.RIGHT&&(newTransform.left=left+1),{...drawing2,transform:newTransform,sheetTransform:transformToDrawingPosition(newTransform,selectionRenderService)}}).filter(drawing2=>drawing2!=null);return commandService.syncExecuteCommand(SetSheetDrawingCommand.id,{unitId,drawings:newDrawings})?(commandService.syncExecuteCommand(ClearSheetDrawingTransformerOperation.id,[unitId]),!0):!1},"handler")},IMAGE_UPLOAD_ICON="addition-and-subtraction-single",SHEETS_IMAGE_MENU_ID="sheet.menu.image";function ImageMenuFactory(accessor){return{id:SHEETS_IMAGE_MENU_ID,type:ui.MenuItemType.SUBITEMS,icon:IMAGE_UPLOAD_ICON,tooltip:"sheetImage.title",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}}__name(ImageMenuFactory,"ImageMenuFactory");function UploadFloatImageMenuFactory(_accessor){return{id:InsertFloatImageCommand.id,title:"sheetImage.upload.float",type:ui.MenuItemType.BUTTON,hidden$:ui.getMenuHiddenObservable(_accessor,core.UniverInstanceType.UNIVER_SHEET)}}__name(UploadFloatImageMenuFactory,"UploadFloatImageMenuFactory");function UploadCellImageMenuFactory(_accessor){return{id:InsertCellImageCommand.id,title:"sheetImage.upload.cell",type:ui.MenuItemType.BUTTON}}__name(UploadCellImageMenuFactory,"UploadCellImageMenuFactory");const styles={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}__name(r,"r");function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}__name(clsx,"clsx");const SheetDrawingAnchor=__name(props=>{var _a2;const commandService=core.useDependency(core.ICommandService),localeService=core.useDependency(core.LocaleService),drawingManagerService=core.useDependency(drawing.IDrawingManagerService),renderManagerService=core.useDependency(engineRender.IRenderManagerService),{drawings}=props,drawingParam=drawings[0];if(drawingParam==null)return;const{unitId}=drawingParam,renderObject=renderManagerService.getRenderById(unitId),scene=renderObject==null?void 0:renderObject.scene;if(scene==null)return;const transformer=scene.getTransformerByCreate(),[anchorShow,setAnchorShow]=React.useState(!0),type=(_a2=drawingParam.anchorType)!=null?_a2:sheetsDrawing.SheetDrawingAnchorType.Position,[value,setValue]=React.useState(type);function getUpdateParams(objects,drawingManagerService2){const params=[];return objects.forEach(object=>{const{oKey}=object,searchParam=drawingManagerService2.getDrawingOKey(oKey);if(searchParam==null)return params.push(null),!0;const{unitId:unitId2,subUnitId,drawingId,drawingType,anchorType,sheetTransform}=searchParam;params.push({unitId:unitId2,subUnitId,drawingId,anchorType,sheetTransform,drawingType})}),params}__name(getUpdateParams,"getUpdateParams"),React.useEffect(()=>{const onClearControlObserver=transformer.clearControl$.subscribe(changeSelf=>{changeSelf===!0&&setAnchorShow(!1)}),onChangeStartObserver=transformer.changeStart$.subscribe(state=>{var _a3;const{objects}=state,params=getUpdateParams(objects,drawingManagerService);if(params.length===0)setAnchorShow(!1);else if(params.length>=1){setAnchorShow(!0);const anchorType=((_a3=params[0])==null?void 0:_a3.anchorType)||sheetsDrawing.SheetDrawingAnchorType.Position;setValue(anchorType)}});return()=>{onChangeStartObserver.unsubscribe(),onClearControlObserver.unsubscribe()}},[]);function handleChange(value2){setValue(value2);const focusDrawings=drawingManagerService.getFocusDrawings();if(focusDrawings.length===0)return;const updateParams=focusDrawings.map(drawing2=>({unitId:drawing2.unitId,subUnitId:drawing2.subUnitId,drawingId:drawing2.drawingId,anchorType:value2}));commandService.executeCommand(SetSheetDrawingCommand.id,{unitId:focusDrawings[0].unitId,drawings:updateParams})}__name(handleChange,"handleChange");const gridDisplay=__name(isShow=>isShow?"block":"none","gridDisplay");return jsxRuntime.jsxs("div",{className:clsx(styles.imageCommonPanelGrid,styles.imageCommonPanelBorder),style:{display:gridDisplay(anchorShow)},children:[jsxRuntime.jsx("div",{className:styles.imageCommonPanelRow,children:jsxRuntime.jsx("div",{className:clsx(styles.imageCommonPanelColumn,styles.imageCommonPanelTitle),children:jsxRuntime.jsx("div",{children:localeService.t("drawing-anchor.title")})})}),jsxRuntime.jsx("div",{className:clsx(styles.imageCommonPanelRow),children:jsxRuntime.jsx("div",{className:clsx(styles.imageCommonPanelColumn),children:jsxRuntime.jsxs(design.RadioGroup,{value,onChange:handleChange,direction:"vertical",children:[jsxRuntime.jsx(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.Both,children:localeService.t("drawing-anchor.both")}),jsxRuntime.jsx(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.Position,children:localeService.t("drawing-anchor.position")}),jsxRuntime.jsx(design.Radio,{value:sheetsDrawing.SheetDrawingAnchorType.None,children:localeService.t("drawing-anchor.none")})]})})})]})},"SheetDrawingAnchor"),SheetDrawingPanel=__name(()=>{const drawingManagerService=core.useDependency(drawing.IDrawingManagerService),focusDrawings=drawingManagerService.getFocusDrawings(),[drawings,setDrawings]=React.useState(focusDrawings);return React.useEffect(()=>{const focusDispose=drawingManagerService.focus$.subscribe(drawings2=>{setDrawings(drawings2)});return()=>{focusDispose.unsubscribe()}},[]),!!(drawings!=null&&drawings.length)&&jsxRuntime.jsxs("div",{className:styles.imageCommonPanel,children:[jsxRuntime.jsx(drawingUi.DrawingCommonPanel,{drawings}),jsxRuntime.jsx(SheetDrawingAnchor,{drawings})]})},"SheetDrawingPanel"),menuSchema={[ui.RibbonStartGroup.FORMULAS_INSERT]:{[SHEETS_IMAGE_MENU_ID]:{order:3,menuItemFactory:ImageMenuFactory,[InsertFloatImageCommand.id]:{order:0,menuItemFactory:UploadFloatImageMenuFactory},[InsertCellImageCommand.id]:{order:1,menuItemFactory:UploadCellImageMenuFactory}}}};function whenSheetDrawingFocused(contextService){return!contextService.getContextValue(core.FOCUSING_FX_BAR_EDITOR)&&!contextService.getContextValue(core.EDITOR_ACTIVATED)&&!contextService.getContextValue(core.FOCUSING_PANEL_EDITOR)&&contextService.getContextValue(core.FOCUSING_COMMON_DRAWINGS)}__name(whenSheetDrawingFocused,"whenSheetDrawingFocused");const MoveDrawingDownShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_DOWN,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.DOWN}},MoveDrawingUpShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_UP,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.UP}},MoveDrawingLeftShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_LEFT,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.LEFT}},MoveDrawingRightShortcutItem={id:MoveDrawingsCommand.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:ui.KeyCode.ARROW_RIGHT,priority:100,preconditions:whenSheetDrawingFocused,staticParameters:{direction:core.Direction.RIGHT}},DeleteDrawingsShortcutItem={id:DeleteDrawingsCommand.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:whenSheetDrawingFocused,binding:ui.KeyCode.DELETE,mac:ui.KeyCode.BACKSPACE};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetDrawingUIController=(_k=class extends core.Disposable{constructor(_componentManager,_menuManagerService,_commandService,_shortcutService,_drawingManagerService,_sheetsSelectionsService){super(),this._componentManager=_componentManager,this._menuManagerService=_menuManagerService,this._commandService=_commandService,this._shortcutService=_shortcutService,this._drawingManagerService=_drawingManagerService,this._sheetsSelectionsService=_sheetsSelectionsService,this._init()}_initCustomComponents(){const componentManager=this._componentManager;this.disposeWithMe(componentManager.register(IMAGE_UPLOAD_ICON,AddImageSingle)),this.disposeWithMe(componentManager.register(COMPONENT_SHEET_DRAWING_PANEL,SheetDrawingPanel))}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}_initCommands(){[InsertFloatImageCommand,InsertCellImageCommand,InsertSheetDrawingCommand,RemoveSheetDrawingCommand,SetSheetDrawingCommand,SidebarSheetDrawingOperation,ClearSheetDrawingTransformerOperation,EditSheetDrawingOperation,GroupSheetDrawingCommand,UngroupSheetDrawingCommand,MoveDrawingsCommand,DeleteDrawingsCommand,SetDrawingArrangeCommand].forEach(command=>this.disposeWithMe(this._commandService.registerCommand(command)))}_initShortcuts(){[MoveDrawingDownShortcutItem,MoveDrawingUpShortcutItem,MoveDrawingLeftShortcutItem,MoveDrawingRightShortcutItem,DeleteDrawingsShortcutItem].forEach(item=>{this.disposeWithMe(this._shortcutService.registerShortcut(item))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}},__name(_k,"SheetDrawingUIController"),_k);SheetDrawingUIController=__decorateClass$2([__decorateParam$2(0,core.Inject(ui.ComponentManager)),__decorateParam$2(1,ui.IMenuManagerService),__decorateParam$2(2,core.ICommandService),__decorateParam$2(3,ui.IShortcutService),__decorateParam$2(4,drawing.IDrawingManagerService),__decorateParam$2(5,core.Inject(sheets.SheetsSelectionsService))],SheetDrawingUIController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");function transformBound2DOMBound(posOfFloatObject,scene,skeleton,worksheet,floatDomInfo){const{scaleX,scaleY}=scene.getAncestorScale(),viewMain=scene.getViewport(engineRender.SHEET_VIEWPORT_KEY.VIEW_MAIN),absolute={left:!0,top:!0};if(!viewMain)return{...posOfFloatObject,absolute};const{left,right,top,bottom}=posOfFloatObject;let{top:topBoundOfViewArea,left:leftBoundViewArea,viewportScrollX,viewportScrollY}=viewMain;const{boundsOfViewArea,scrollDirectionResponse}=floatDomInfo||{};boundsOfViewArea&&(core.Tools.isDefine(boundsOfViewArea.top)&&(topBoundOfViewArea=boundsOfViewArea.top),core.Tools.isDefine(boundsOfViewArea.left)&&(leftBoundViewArea=boundsOfViewArea.left)),scrollDirectionResponse==="HORIZONTAL"&&(viewportScrollY=0),scrollDirectionResponse==="VERTICAL"&&(viewportScrollX=0);let offsetLeft,offsetRight;left<leftBoundViewArea?(absolute.left=!0,offsetLeft=(leftBoundViewArea+(left-leftBoundViewArea))*scaleX,offsetRight=Math.max(Math.min((leftBoundViewArea+(right-leftBoundViewArea))*scaleX,leftBoundViewArea*scaleX),(right-viewportScrollX)*scaleX)):(absolute.left=!1,offsetLeft=Math.max((left-viewportScrollX)*scaleX,leftBoundViewArea*scaleX),offsetRight=Math.max((right-viewportScrollX)*scaleX,leftBoundViewArea*scaleX));let offsetTop,offsetBottom;return top<topBoundOfViewArea?(absolute.top=!0,offsetTop=(topBoundOfViewArea+(top-topBoundOfViewArea))*scaleY,offsetBottom=Math.max(Math.min((topBoundOfViewArea+(right-topBoundOfViewArea))*scaleY,topBoundOfViewArea*scaleY),(bottom-viewportScrollY)*scaleY)):(absolute.top=!1,offsetTop=Math.max((top-viewportScrollY)*scaleY,topBoundOfViewArea*scaleY),offsetBottom=Math.max((bottom-viewportScrollY)*scaleY,topBoundOfViewArea*scaleY)),{left:offsetLeft,right:offsetRight,top:offsetTop,bottom:offsetBottom,absolute}}__name(transformBound2DOMBound,"transformBound2DOMBound");const calcPosition=__name((floatObject,renderUnit,skeleton,worksheet,floatDomInfo)=>{const{scene}=renderUnit,{left,top,width,height,angle}=floatObject,boundOfFloatObject={left,right:left+width,top,bottom:top+height},offsetBound=transformBound2DOMBound(boundOfFloatObject,scene,skeleton,worksheet,floatDomInfo),{scaleX,scaleY}=scene.getAncestorScale();return{startX:offsetBound.left,endX:offsetBound.right,startY:offsetBound.top,endY:offsetBound.bottom,rotate:angle,width:width*scaleX,height:height*scaleY,absolute:offsetBound.absolute}},"calcPosition");exports2.SheetCanvasFloatDomManagerService=(_l=class extends core.Disposable{constructor(_renderManagerService,_univerInstanceService,_commandService,_drawingManagerService,_canvasFloatDomService,_sheetDrawingService,_lifecycleService){super();__publicField(this,"_domLayerMap",new Map);__publicField(this,"_domLayerInfoMap",new Map);__publicField(this,"_transformChange$",new rxjs.Subject);__publicField(this,"transformChange$",this._transformChange$.asObservable());__publicField(this,"_add$",new rxjs.Subject);__publicField(this,"add$",this._add$.asObservable());__publicField(this,"_remove$",new rxjs.Subject);__publicField(this,"remove$",this._remove$.asObservable());__publicField(this,"_hooks",[]);this._renderManagerService=_renderManagerService,this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._drawingManagerService=_drawingManagerService,this._canvasFloatDomService=_canvasFloatDomService,this._sheetDrawingService=_sheetDrawingService,this._lifecycleService=_lifecycleService,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(rxjs.filter(s=>s===core.LifecycleStages.Rendered),rxjs.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(unitId,subUnitId){let unitMap=this._domLayerMap.get(unitId);unitMap||(unitMap=new Map,this._domLayerMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}getFloatDomInfo(id){return this._domLayerInfoMap.get(id)}_getSceneAndTransformerByDrawingSearch(unitId){if(unitId==null)return;const renderUnit=this._renderManagerService.getRenderById(unitId),scene=renderUnit==null?void 0:renderUnit.scene;if(renderUnit==null||scene==null)return null;const transformer=scene.getTransformerByCreate(),canvas=renderUnit.engine.getCanvasElement();return{scene,transformer,renderUnit,canvas}}_getFloatDomProps(id){let props;return this._hooks.forEach(hook=>{props=hook.onGetFloatDomProps(id)}),props}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(params=>{params.forEach(param=>{var _a2,_b2,_c2;const{unitId,subUnitId,drawingId}=param,target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId,subUnitId}),floatDomParam=this._drawingManagerService.getDrawingByParam(param),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return;const activeSheetId=workbook.getActiveSheet().getSheetId();if(!floatDomParam||!target)return;const skeleton=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(!skeleton)return;const{transform,drawingType,data}=floatDomParam;if(drawingType!==core.DrawingTypeEnum.DRAWING_DOM&&drawingType!==core.DrawingTypeEnum.DRAWING_CHART)return;const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(renderObject==null)return;const{scene,canvas}=renderObject;if(transform==null)return!0;if(activeSheetId!==subUnitId)return;const{left,top,width,height,angle,flipX,flipY,skewX,skewY}=transform,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId}),rectShape=scene.getObject(rectShapeKey);if(rectShape!=null){rectShape.transformByState({left,top,width,height,angle,flipX,flipY,skewX,skewY});return}const imageConfig={left,top,width,height,zIndex:this._drawingManagerService.getDrawingOrder(unitId,subUnitId).length-1},isChart=drawingType===core.DrawingTypeEnum.DRAWING_CHART;if(isChart){const backgroundColor=data?data.backgroundColor:"white";imageConfig.fill=backgroundColor,imageConfig.rotateEnabled=!1,data&&data.border&&(imageConfig.stroke=data.border),imageConfig.paintFirst="stroke",imageConfig.strokeWidth=1,imageConfig.borderEnabled=!1,imageConfig.radius=8}const rect=new engineRender.Rect(rectShapeKey,imageConfig);isChart&&rect.setObjectType(engineRender.ObjectType.CHART),scene.addObject(rect,engineRender.DRAWING_OBJECT_LAYER_INDEX),floatDomParam.allowTransform!==!1&&scene.attachTransformerTo(rect);const map2=this._ensureMap(unitId,subUnitId),disposableCollection=new core.DisposableCollection,initPosition=calcPosition(rect,renderObject.renderUnit,skeleton.skeleton,target.worksheet),position$=new rxjs.BehaviorSubject(initPosition),info={dispose:disposableCollection,rect,position$,unitId,subUnitId};this._canvasFloatDomService.addFloatDom({position$,id:drawingId,componentKey:floatDomParam.componentKey,onPointerDown:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerDown"),onPointerMove:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerMove"),onPointerUp:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerUp"),onWheel:__name(evt=>{canvas.dispatchEvent(new WheelEvent(evt.type,evt))},"onWheel"),props:(_c2=(_b2=map2.get(drawingId))==null?void 0:_b2.props)!=null?_c2:this._getFloatDomProps(drawingId),data,unitId});const listener=rect.onTransformChange$.subscribeEvent(()=>{const newPosition=calcPosition(rect,renderObject.renderUnit,skeleton.skeleton,target.worksheet);position$.next(newPosition)});disposableCollection.add(()=>{this._canvasFloatDomService.removeFloatDom(drawingId)}),listener&&disposableCollection.add(listener),this._domLayerInfoMap.set(drawingId,info),map2.set(drawingId,{...map2.get(drawingId)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(params=>{params.forEach(param=>{const{unitId,subUnitId,drawingId}=param,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId}),renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(renderObject==null)return;const{transformer,scene}=renderObject,rectShape=scene.getObject(rectShapeKey);rectShape!=null&&rectShape.oKey&&transformer.clearControlByIds([rectShape==null?void 0:rectShape.oKey])})}))}_scrollUpdateListener(){const updateSheet=__name((unitId,subUnitId)=>{var _a2;const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId),map2=this._ensureMap(unitId,subUnitId),ids=Array.from(map2.keys()),target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId,subUnitId}),skeleton=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);!renderObject||!target||!skeleton||ids.forEach(id=>{const floatDomInfo=this._domLayerInfoMap.get(id);if(floatDomInfo){const position=calcPosition(floatDomInfo.rect,renderObject.renderUnit,skeleton.skeleton,target.worksheet,floatDomInfo);floatDomInfo.position$.next(position)}})},"updateSheet");this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(core.UniverInstanceType.UNIVER_SHEET).pipe(rxjs.filter(workbook=>!!workbook),rxjs.switchMap(workbook=>workbook.activeSheet$),rxjs.filter(sheet=>!!sheet),rxjs.map(sheet=>{const render2=this._renderManagerService.getRenderById(sheet.getUnitId());return render2?{render:render2,unitId:sheet.getUnitId(),subUnitId:sheet.getSheetId()}:null}),rxjs.filter(render2=>!!render2),rxjs.switchMap(render2=>core.fromEventSubject(render2.render.scene.getViewport(engineRender.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(rxjs.map(()=>({unitId:render2.unitId,subUnitId:render2.subUnitId}))))).subscribe(({unitId,subUnitId})=>{updateSheet(unitId,subUnitId)})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a2,_b2;if(commandInfo.id===sheetsUi.SetZoomRatioOperation.id){const params=commandInfo.params,{unitId}=params;Array.from((_b2=(_a2=this._domLayerMap.get(unitId))==null?void 0:_a2.keys())!=null?_b2:[]).forEach(subUnitId=>{updateSheet(unitId,subUnitId)})}else if(commandInfo.id===sheets.SetFrozenMutation.id){const{unitId,subUnitId}=commandInfo.params;updateSheet(unitId,subUnitId)}}))}_getPosition(position,unitId){var _a2;const{startX,endX,startY,endY}=position,selectionRenderService=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.ISheetSelectionRenderService);if(selectionRenderService==null)return;const start=selectionRenderService.getCellWithCoordByOffset(startX,startY);if(start==null)return;const from={column:start.actualColumn,columnOffset:startX-start.startX,row:start.actualRow,rowOffset:startY-start.startY},end=selectionRenderService.getCellWithCoordByOffset(endX,endY);if(end==null)return;const to={column:end.actualColumn,columnOffset:endX-end.startX,row:end.actualRow,rowOffset:endY-end.startY};return{from,to}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(params=>{params.forEach(data=>{const sheetDrawing=this._drawingManagerService.getDrawingByParam(data);if(!sheetDrawing||sheetDrawing.drawingType!==core.DrawingTypeEnum.DRAWING_DOM&&sheetDrawing.drawingType!==core.DrawingTypeEnum.DRAWING_CHART)return;const newValue={...sheetDrawing.transform};this._transformChange$.next({id:data.drawingId,value:newValue})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(params=>{params.forEach(param=>{this._removeDom(param.drawingId)})}))}updateFloatDomProps(unitId,subUnitId,id,props){const info=this._domLayerInfoMap.get(id),renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(info&&renderObject){const{scene}=renderObject,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId,subUnitId,drawingId:id}),rectShape=scene.getObject(rectShapeKey);rectShape&&rectShape instanceof engineRender.Rect&&rectShape.setProps(props)}}addFloatDomToPosition(layer,propId){const target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:layer.unitId,subUnitId:layer.subUnitId});if(!target)throw new Error("cannot find current target!");const{unitId,subUnitId}=target,{initPosition,componentKey,data,allowTransform=!0}=layer,id=propId!=null?propId:core.generateRandomId(),sheetTransform=this._getPosition(initPosition,unitId);if(sheetTransform==null)return;this._ensureMap(unitId,subUnitId).set(id,layer);const sheetDrawingParam={unitId,subUnitId,drawingId:id,drawingType:layer.type||core.DrawingTypeEnum.DRAWING_DOM,componentKey,sheetTransform,transform:{left:initPosition.startX,top:initPosition.startY,width:initPosition.endX-initPosition.startX,height:initPosition.endY-initPosition.startY},data,allowTransform};return this._commandService.executeCommand(InsertSheetDrawingCommand.id,{unitId,drawings:[sheetDrawingParam]}),this._add$.next({unitId,subUnitId,id}),{id,dispose:__name(()=>{this._removeDom(id,!0)},"dispose")}}_removeDom(id,removeDrawing=!1){const info=this._domLayerInfoMap.get(id);if(!info)return;const{unitId,subUnitId}=info;this._domLayerInfoMap.delete(id),info.dispose.dispose();const renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(renderObject&&renderObject.scene.removeObject(info.rect),removeDrawing){this._ensureMap(unitId,subUnitId).delete(id);const param=this._drawingManagerService.getDrawingByParam({unitId,subUnitId,drawingId:id});if(!param)return;const jsonOp=this._sheetDrawingService.getBatchRemoveOp([param]),{redo,objects}=jsonOp;this._commandService.syncExecuteCommand(sheetsDrawing.SetDrawingApplyMutation.id,{unitId,subUnitId,op:redo,objects,type:sheetsDrawing.DrawingApplyType.REMOVE})}}addHook(hook){return this._hooks.push(hook),{dispose:__name(()=>{const index=this._hooks.findIndex(h=>h===hook);this._hooks.splice(index,1)},"dispose")}}addFloatDomToRange(range,config,domAnchor,propId){var _a2,_b2,_c2,_d2,_e2;const target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:config.unitId,subUnitId:config.subUnitId});if(!target)throw new Error("cannot find current target!");const{unitId,subUnitId}=target,renderObject=this._getSceneAndTransformerByDrawingSearch(unitId);if(!renderObject)return;const currentRender=this._renderManagerService.getRenderById(unitId);if(!currentRender)return;const skeletonParam=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(!skeletonParam)return;const{componentKey,data,allowTransform=!0}=config,id=propId!=null?propId:core.generateRandomId(),{position:rangePosition,position$:rangePos$}=this._createRangePositionObserver(range,currentRender,skeletonParam.skeleton),sheetTransform=this._getPosition(rangePosition,unitId);if(sheetTransform==null)return;this._ensureMap(unitId,subUnitId).set(id,config);const scene=renderObject.scene,{scaleX}=scene.getAncestorScale(),domPosFromRange=calcDomPositionByAnchor(rangePosition,domAnchor,scaleX),sheetDrawingParam={unitId,subUnitId,drawingId:id,drawingType:config.type||core.DrawingTypeEnum.DRAWING_DOM,componentKey,sheetTransform,transform:{left:domPosFromRange.startX,top:domPosFromRange.startY,width:domPosFromRange.width,height:domPosFromRange.height},data,allowTransform};{const{unitId:unitId2,subUnitId:subUnitId2,drawingId}=sheetDrawingParam,target2=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:unitId2,subUnitId:subUnitId2}),floatDomParam=sheetDrawingParam,workbook=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return;const activeSheetId=workbook.getActiveSheet().getSheetId();if(!floatDomParam||!target2)return;const skMangerService=(_b2=this._renderManagerService.getRenderById(unitId2))==null?void 0:_b2.with(sheetsUi.SheetSkeletonManagerService);if(!skMangerService)return;const skeleton=skMangerService.getWorksheetSkeleton(subUnitId2);if(!skeleton)return;const{transform,drawingType,data:data2}=floatDomParam;if(drawingType!==core.DrawingTypeEnum.DRAWING_DOM&&drawingType!==core.DrawingTypeEnum.DRAWING_CHART)return;const renderObject2=this._getSceneAndTransformerByDrawingSearch(unitId2);if(renderObject2==null)return;const{scene:scene2,canvas}=renderObject2;if(transform==null||activeSheetId!==subUnitId2)return;const{left,top,width,height,angle,flipX,flipY,skewX,skewY}=transform,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId:unitId2,subUnitId:subUnitId2,drawingId}),rectShape=scene2.getObject(rectShapeKey);if(rectShape!=null){rectShape.transformByState({left,top,width,height,angle,flipX,flipY,skewX,skewY});return}const domConfig={left,top,width,height,zIndex:this._drawingManagerService.getDrawingOrder(unitId2,subUnitId2).length-1},isChart=drawingType===core.DrawingTypeEnum.DRAWING_CHART;if(isChart){const backgroundColor=data2?data2.backgroundColor:"white";domConfig.fill=backgroundColor,domConfig.rotateEnabled=!1,data2&&data2.border&&(domConfig.stroke=data2.border),domConfig.paintFirst="stroke",domConfig.strokeWidth=1,domConfig.borderEnabled=!1,domConfig.radius=8}const domRect=new engineRender.Rect(rectShapeKey,domConfig);isChart&&domRect.setObjectType(engineRender.ObjectType.CHART),scene2.addObject(domRect,engineRender.DRAWING_OBJECT_LAYER_INDEX),floatDomParam.allowTransform!==!1&&scene2.attachTransformerTo(domRect);const map3=this._ensureMap(unitId2,subUnitId2),disposableCollection=new core.DisposableCollection,viewMain=scene2.getMainViewport(),boundsOfViewArea={top:viewMain.top,left:viewMain.left,bottom:viewMain.bottom,right:viewMain.right},floatDomInfo={dispose:disposableCollection,rect:domRect,boundsOfViewArea,domAnchor,unitId:unitId2,subUnitId:subUnitId2},initedPosition=calcPosition(domRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo),position$=new rxjs.BehaviorSubject(initedPosition);floatDomInfo.position$=position$;let floatDomCfg={position$,id:drawingId,componentKey:floatDomParam.componentKey,onPointerDown:__name(()=>{},"onPointerDown"),onPointerMove:__name(()=>{},"onPointerMove"),onPointerUp:__name(()=>{},"onPointerUp"),onWheel:__name(evt=>{canvas.dispatchEvent(new WheelEvent(evt.type,evt))},"onWheel"),props:(_d2=(_c2=map3.get(drawingId))==null?void 0:_c2.props)!=null?_d2:this._getFloatDomProps(drawingId),data:data2,unitId:unitId2};config.eventPassThrough&&(floatDomCfg={...floatDomCfg,onPointerDown:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerDown"),onPointerMove:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerMove"),onPointerUp:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerUp")}),this._canvasFloatDomService.addFloatDom(floatDomCfg),this.disposeWithMe(rangePos$.subscribe(newRangePos=>{var _a3,_b3,_c3,_d3;const calcOffsetPos=calcDomPositionByAnchor({rotate:0,startX:newRangePos.startX,startY:newRangePos.startY,endX:newRangePos.endX,endY:newRangePos.endY,width:(_a3=domAnchor.width)!=null?_a3:newRangePos.width,height:(_b3=domAnchor.height)!=null?_b3:newRangePos.height,absolute:{left:rangePosition.absolute.left,top:rangePosition.absolute.top}},domAnchor),rectShapeKey2=drawing.getDrawingShapeKeyByDrawingSearch({unitId:unitId2,subUnitId:subUnitId2,drawingId}),newRect=new engineRender.Rect(rectShapeKey2,{left:calcOffsetPos.startX,top:calcOffsetPos.startY,width:(_c3=domAnchor.width)!=null?_c3:newRangePos.width,height:(_d3=domAnchor.height)!=null?_d3:newRangePos.height,zIndex:this._drawingManagerService.getDrawingOrder(unitId2,subUnitId2).length-1}),newPos=calcPosition(newRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo);position$.next(newPos)}));const skm=(_e2=this._renderManagerService.getRenderById(unitId2))==null?void 0:_e2.with(sheetsUi.SheetSkeletonManagerService);skm==null||skm.currentSkeleton$.subscribe(skeleton2=>{skeleton2&&skeletonParam.sheetId!==skeleton2.sheetId&&this._removeDom(id,!0)});const listener=domRect.onTransformChange$.subscribeEvent(()=>{const newPosition=calcPosition(domRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo);position$.next(newPosition)});disposableCollection.add(()=>{this._canvasFloatDomService.removeFloatDom(drawingId)}),listener&&disposableCollection.add(listener),this._domLayerInfoMap.set(drawingId,floatDomInfo),map3.set(drawingId,{...map3.get(drawingId)})}return{id,dispose:__name(()=>{this._removeDom(id,!0)},"dispose")}}addFloatDomToColumnHeader(column,config,domLayoutParam,propId){var _a2,_b2,_c2,_d2,_e2;const target=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:config.unitId,subUnitId:config.subUnitId});if(!target)throw new Error("cannot find current target!");const{unitId,subUnitId}=target;if(!this._getSceneAndTransformerByDrawingSearch(unitId))return;const currentRender=this._renderManagerService.getRenderById(unitId);if(!currentRender)return;const skeletonParam=(_a2=this._renderManagerService.getRenderById(unitId))==null?void 0:_a2.with(sheetsUi.SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);if(!skeletonParam)return;const{componentKey,data,allowTransform=!0}=config,id=propId!=null?propId:core.generateRandomId(),{position:rangePosition,position$:rangePos$}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:column,endColumn:column},currentRender,skeletonParam.skeleton),headerCellPosition=rangePosition;headerCellPosition.startY=0;const sheetTransform=this._getPosition(rangePosition,unitId);if(sheetTransform==null)return;this._ensureMap(unitId,subUnitId).set(id,config);const sheetDrawingParam={unitId,subUnitId,drawingId:id,drawingType:config.type||core.DrawingTypeEnum.DRAWING_DOM,componentKey,sheetTransform,transform:{left:headerCellPosition.startX,top:headerCellPosition.startY,width:headerCellPosition.width,height:headerCellPosition.height},data,allowTransform};{const{unitId:unitId2,subUnitId:subUnitId2,drawingId}=sheetDrawingParam,target2=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId:unitId2,subUnitId:subUnitId2}),floatDomParam=sheetDrawingParam,workbook=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return;const activeSheetId=workbook.getActiveSheet().getSheetId();if(!floatDomParam||!target2)return;const skMangerService=(_b2=this._renderManagerService.getRenderById(unitId2))==null?void 0:_b2.with(sheetsUi.SheetSkeletonManagerService);if(!skMangerService)return;const skeleton=skMangerService.getWorksheetSkeleton(subUnitId2);if(!skeleton)return;const{transform,data:data2}=floatDomParam,renderObject2=this._getSceneAndTransformerByDrawingSearch(unitId2);if(renderObject2==null)return;const{scene,canvas}=renderObject2;if(transform==null||activeSheetId!==subUnitId2)return;const{left,top,width,height,angle,flipX,flipY,skewX,skewY}=transform,rectShapeKey=drawing.getDrawingShapeKeyByDrawingSearch({unitId:unitId2,subUnitId:subUnitId2,drawingId}),rectShape=scene.getObject(rectShapeKey);if(rectShape!=null){rectShape.transformByState({left,top,width,height,angle,flipX,flipY,skewX,skewY});return}const calcOffsetPos=calcDomPositionByAnchor({rotate:0,startX:headerCellPosition.startX,startY:0,endX:rangePosition.endX,endY:rangePosition.endY,width:domLayoutParam.width,height:domLayoutParam.height,absolute:{left:rangePosition.absolute.left,top:rangePosition.absolute.top}},domLayoutParam),headerRectConfig={left:calcOffsetPos.startX,top:calcOffsetPos.startY,width:calcOffsetPos.width,height:calcOffsetPos.height,zIndex:this._drawingManagerService.getDrawingOrder(unitId2,subUnitId2).length-1},domRect=new engineRender.Rect(rectShapeKey,headerRectConfig);scene.addObject(domRect,engineRender.DRAWING_OBJECT_LAYER_INDEX),floatDomParam.allowTransform!==!1&&scene.attachTransformerTo(domRect);const map3=this._ensureMap(unitId2,subUnitId2),disposableCollection=new core.DisposableCollection,viewMain=scene.getMainViewport(),boundsOfViewArea={top:0,left:viewMain.left,bottom:viewMain.bottom,right:viewMain.right},floatDomInfo={dispose:disposableCollection,rect:domRect,unitId:unitId2,subUnitId:subUnitId2,boundsOfViewArea,domAnchor:domLayoutParam,scrollDirectionResponse:"HORIZONTAL"},initedPosition=calcPosition(domRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo),position$=new rxjs.BehaviorSubject(initedPosition);floatDomInfo.position$=position$;let floatDomCfg={position$,id:drawingId,componentKey:floatDomParam.componentKey,onPointerDown:__name(()=>{},"onPointerDown"),onPointerMove:__name(()=>{},"onPointerMove"),onPointerUp:__name(()=>{},"onPointerUp"),onWheel:__name(evt=>{canvas.dispatchEvent(new WheelEvent(evt.type,evt))},"onWheel"),props:(_d2=(_c2=map3.get(drawingId))==null?void 0:_c2.props)!=null?_d2:this._getFloatDomProps(drawingId),data:data2,unitId:unitId2};config.eventPassThrough&&(floatDomCfg={...floatDomCfg,onPointerDown:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerDown"),onPointerMove:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerMove"),onPointerUp:__name(evt=>{canvas.dispatchEvent(new PointerEvent(evt.type,evt))},"onPointerUp")}),this._canvasFloatDomService.addFloatDom(floatDomCfg);const listener=domRect.onTransformChange$.subscribeEvent(()=>{const newPosition=calcPosition(domRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo);position$.next(newPosition)});this.disposeWithMe(rangePos$.subscribe(newHeaderPos=>{const calcOffsetPos2=calcDomPositionByAnchor({rotate:0,startX:newHeaderPos.startX,startY:0,endX:newHeaderPos.endX,endY:newHeaderPos.endY,width:domLayoutParam.width,height:domLayoutParam.height,absolute:{left:rangePosition.absolute.left,top:rangePosition.absolute.top}},domLayoutParam),rectShapeKey2=drawing.getDrawingShapeKeyByDrawingSearch({unitId:unitId2,subUnitId:subUnitId2,drawingId}),newRect=new engineRender.Rect(rectShapeKey2,{left:calcOffsetPos2.startX,top:0,width:domLayoutParam.width,height:domLayoutParam.height,zIndex:this._drawingManagerService.getDrawingOrder(unitId2,subUnitId2).length-1}),newPos=calcPosition(newRect,renderObject2.renderUnit,skeleton.skeleton,target2.worksheet,floatDomInfo);position$.next(newPos)}));const skm=(_e2=this._renderManagerService.getRenderById(unitId2))==null?void 0:_e2.with(sheetsUi.SheetSkeletonManagerService);skm==null||skm.currentSkeleton$.subscribe(skeleton2=>{skeleton2&&skeletonParam.sheetId!==skeleton2.sheetId&&this._removeDom(id,!0)}),disposableCollection.add(()=>{this._canvasFloatDomService.removeFloatDom(drawingId)}),listener&&disposableCollection.add(listener),this._domLayerInfoMap.set(drawingId,floatDomInfo),map3.set(drawingId,{...map3.get(drawingId)})}return{id,dispose:__name(()=>{this._removeDom(id,!0)},"dispose")}}_createRangePositionObserver(range,currentRender,skeleton){let{startRow,startColumn}=range;const topLeftCoord=calcCellPositionByCell(startRow,startColumn,skeleton),topLeftPos$=new rxjs.BehaviorSubject(topLeftCoord),rightBottomCoord=calcCellPositionByCell(range.endRow,range.endColumn,skeleton),rightBottomPos$=new rxjs.BehaviorSubject(rightBottomCoord),updatePosition=__name(()=>{const topLeftCoord2=calcCellPositionByCell(startRow,startColumn,skeleton),rightBottomCoord2=calcCellPositionByCell(range.endRow,range.endColumn,skeleton);topLeftPos$.next(topLeftCoord2),rightBottomPos$.next(rightBottomCoord2)},"updatePosition"),disposable=new core.DisposableCollection;disposable.add(currentRender.engine.clientRect$.subscribe(()=>updatePosition())),disposable.add(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetWorksheetRowAutoHeightMutation.id&&commandInfo.params.rowsAutoHeightInfo.findIndex(item=>item.row===startRow)>-1){updatePosition();return}(sheets.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(commandInfo.id)>-1||commandInfo.id===sheetsUi.SetScrollOperation.id||commandInfo.id===sheetsUi.SetZoomRatioOperation.id)&&updatePosition()}));const updateRowCol=__name((newRow,newCol)=>{startRow=newRow,startColumn=newCol,updatePosition()},"updateRowCol"),genPosition=__name(()=>({rotate:0,width:rightBottomCoord.right-topLeftCoord.left,height:rightBottomCoord.bottom-topLeftCoord.top,absolute:{left:!0,top:!0},startX:topLeftCoord.left,startY:topLeftCoord.top,endX:rightBottomCoord.right,endY:rightBottomCoord.bottom}),"genPosition"),position$=topLeftPos$.pipe(rxjs.map(topLeft=>{const rightBottomCoord2=calcCellPositionByCell(range.endRow,range.endColumn,skeleton);return{rotate:0,width:rightBottomCoord2.right-topLeft.left,height:rightBottomCoord2.bottom-topLeft.top,absolute:{left:!0,top:!0},startX:topLeft.left,startY:topLeft.top,endX:rightBottomCoord2.right,endY:rightBottomCoord2.bottom}})),position=genPosition();return{position$,position,updateRowCol,topLeftPos$,rightBottomPos$,disposable}}},__name(_l,"SheetCanvasFloatDomManagerService"),_l),exports2.SheetCanvasFloatDomManagerService=__decorateClass$1([__decorateParam$1(0,core.Inject(engineRender.IRenderManagerService)),__decorateParam$1(1,core.IUniverInstanceService),__decorateParam$1(2,core.Inject(core.ICommandService)),__decorateParam$1(3,drawing.IDrawingManagerService),__decorateParam$1(4,core.Inject(ui.CanvasFloatDomService)),__decorateParam$1(5,sheetsDrawing.ISheetDrawingService),__decorateParam$1(6,core.Inject(core.LifecycleService))],exports2.SheetCanvasFloatDomManagerService);function calcCellPositionByCell(row,col,skeleton){const primaryWithCoord=skeleton.getCellWithCoordByIndex(row,col),cellInfo=primaryWithCoord.isMergedMainCell?primaryWithCoord.mergeInfo:primaryWithCoord;return{left:cellInfo.startX,right:cellInfo.endX,top:cellInfo.startY,bottom:cellInfo.endY}}__name(calcCellPositionByCell,"calcCellPositionByCell");function calcDomPositionByAnchor(rangePosition,domAnchor,scale){var _a2,_b2;scale=scale!=null?scale:1;const rangeWidth=rangePosition.endX-rangePosition.startX,rangeHeight=rangePosition.endY-rangePosition.startY,domWidth=(_a2=domAnchor==null?void 0:domAnchor.width)!=null?_a2:rangeWidth,domHeight=(_b2=domAnchor==null?void 0:domAnchor.height)!=null?_b2:rangeHeight;let domLeft=0,domTop=0;if(domAnchor){if(domAnchor.horizonOffsetAlign==="right"){const offsetX=calculateOffset(domAnchor.marginX,rangeWidth*scale);domLeft=rangePosition.endX-offsetX-domWidth}else domLeft=rangePosition.startX+calculateOffset(domAnchor.marginX,rangeWidth);if(domAnchor.verticalOffsetAlign==="bottom"){const offsetY=calculateOffset(domAnchor.marginY,rangeHeight*scale);domTop=rangePosition.endY-offsetY-domHeight}else domTop=rangePosition.startY+calculateOffset(domAnchor.marginY,rangeHeight)}return{rotate:0,startX:domLeft,startY:domTop,endX:rangePosition.endX,endY:rangePosition.endY,width:domWidth,height:domHeight,absolute:{left:rangePosition.absolute.left,top:rangePosition.absolute.top}}}__name(calcDomPositionByAnchor,"calcDomPositionByAnchor");function calculateOffset(value,rangeWidth){if(value===void 0)return 0;if(typeof value=="number")return value;const percentage=Number.parseFloat(value);return rangeWidth*percentage/100}__name(calculateOffset,"calculateOffset");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");const PLUGIN_NAME="SHEET_IMAGE_UI_PLUGIN";exports2.UniverSheetsDrawingUIPlugin=(_m=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerService,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerService=_renderManagerService,this._configService=_configService;const{menu,...rest}=core.merge({},defaultPluginConfig,this._config);menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(SHEETS_DRAWING_UI_PLUGIN_CONFIG_KEY,rest)}onStarting(){core.registerDependencies(this._injector,[[exports2.SheetCanvasFloatDomManagerService],[SheetDrawingUIController],[DrawingPopupMenuController],[SheetDrawingPrintingController],[SheetDrawingPermissionController],[SheetsDrawingCopyPasteController],[SheetCellImageController],[SheetCellImageHoverController],[SheetCellImageAutofillController]]),core.touchDependencies(this._injector,[[exports2.SheetCanvasFloatDomManagerService]])}onReady(){core.touchDependencies(this._injector,[[SheetsDrawingCopyPasteController]])}onRendered(){this._registerRenderModules(),core.touchDependencies(this._injector,[[SheetDrawingPermissionController],[SheetDrawingPrintingController],[SheetDrawingUIController],[SheetCellImageController],[SheetCellImageHoverController],[SheetCellImageAutofillController]])}onSteady(){this._injector.get(DrawingPopupMenuController)}_registerRenderModules(){[[SheetDrawingUpdateController],[SheetDrawingTransformAffectedController],[SheetsDrawingRenderController]].forEach(m=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(core.UniverInstanceType.UNIVER_SHEET,m))})}},__name(_m,"UniverSheetsDrawingUIPlugin"),_m),__publicField2(exports2.UniverSheetsDrawingUIPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),__publicField2(exports2.UniverSheetsDrawingUIPlugin,"pluginName",PLUGIN_NAME),exports2.UniverSheetsDrawingUIPlugin=__decorateClass([core.DependentOn(drawing.UniverDrawingPlugin,docsDrawing.UniverDocsDrawingPlugin,drawingUi.UniverDrawingUIPlugin,sheetsDrawing.UniverSheetsDrawingPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports2.UniverSheetsDrawingUIPlugin),exports2.ClearSheetDrawingTransformerOperation=ClearSheetDrawingTransformerOperation,exports2.DeleteDrawingsCommand=DeleteDrawingsCommand,exports2.EditSheetDrawingOperation=EditSheetDrawingOperation,exports2.GroupSheetDrawingCommand=GroupSheetDrawingCommand,exports2.InsertFloatImageCommand=InsertFloatImageCommand,exports2.InsertSheetDrawingCommand=InsertSheetDrawingCommand,exports2.MoveDrawingsCommand=MoveDrawingsCommand,exports2.RemoveSheetDrawingCommand=RemoveSheetDrawingCommand,exports2.SHEETS_IMAGE_MENU_ID=SHEETS_IMAGE_MENU_ID,exports2.SetDrawingArrangeCommand=SetDrawingArrangeCommand,exports2.SetSheetDrawingCommand=SetSheetDrawingCommand,exports2.SidebarSheetDrawingOperation=SidebarSheetDrawingOperation,exports2.UngroupSheetDrawingCommand=UngroupSheetDrawingCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});