@univerjs/sheets-drawing-ui 0.5.1-nightly.202412011605 → 0.5.1-nightly.202412021606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +181 -181
- package/lib/umd/index.js +2 -2
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var dt=Object.defineProperty;var lt=(i,n,t)=>n in i?dt(i,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[n]=t;var H=(i,n,t)=>lt(i,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),qe=require("@univerjs/docs-drawing"),A=require("@univerjs/drawing"),Q=require("@univerjs/drawing-ui"),P=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),N=require("@univerjs/sheets-ui"),G=require("@univerjs/ui"),L=require("rxjs"),_=require("@univerjs/sheets"),Y=require("react"),Je=require("@univerjs/docs-ui"),K=require("@univerjs/design"),ut="sheets-drawing-ui.config",gt={},x={id:"sheet.operation.clear-drawing-transformer",type:u.CommandType.MUTATION,handler:(i,n)=>{const t=i.get(P.IRenderManagerService);return n.forEach(e=>{var r,o;(o=(r=t.getRenderById(e))==null?void 0:r.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ae={id:"sheet.command.remove-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{var y,C,T;const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(_.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!n)return!1;const{drawings:s}=n,c=[];s.forEach(I=>{const{unitId:M}=I;c.push(M)});const d=o.getBatchRemoveOp(s),{unitId:m,subUnitId:l,undo:a,redo:g,objects:h}=d,f=r.onCommandExecute({id:ae.id,params:n}),w={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:g,objects:h,type:p.DrawingApplyType.REMOVE}},S={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:a,objects:h,type:p.DrawingApplyType.INSERT}};return u.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:m,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},Ze="COMPONENT_SHEET_DRAWING_PANEL",je={id:"sidebar.operation.sheet-image",type:u.CommandType.COMMAND,handler:async(i,n)=>{const t=i.get(G.ISidebarService),e=i.get(u.LocaleService),r=i.get(u.IUniverInstanceService),o=i.get(A.IDrawingManagerService);if(!_.getSheetCommandTarget(r))return!1;switch(n.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Ze},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:t.close();break}return!0}},We={id:"sheet.operation.edit-sheet-image",type:u.CommandType.OPERATION,handler:(i,n)=>{const t=i.get(A.IDrawingManagerService),e=i.get(u.ICommandService);return n==null?!1:(t.focusDrawing([n]),e.executeCommand(je.id,{value:"open"}),!0)}};var be={exports:{}},ie={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Xe;function ht(){if(Xe)return ie;Xe=1;var i=Y,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,r=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(c,d,m){var l,a={},g=null,h=null;m!==void 0&&(g=""+m),d.key!==void 0&&(g=""+d.key),d.ref!==void 0&&(h=d.ref);for(l in d)e.call(d,l)&&!o.hasOwnProperty(l)&&(a[l]=d[l]);if(c&&c.defaultProps)for(l in d=c.defaultProps,d)a[l]===void 0&&(a[l]=d[l]);return{$$typeof:n,type:c,key:g,ref:h,props:a,_owner:r.current}}return ie.Fragment=t,ie.jsx=s,ie.jsxs=s,ie}var ze;function mt(){return ze||(ze=1,be.exports=ht()),be.exports}var k=mt();const pt="univer-upload-loading",ft="univer-upload-loading-body",wt="univer-upload-loading-body-animation",St="univer-UniverCircleAnimation",_t="univer-upload-loading-body-text",ue={uploadLoading:pt,uploadLoadingBody:ft,uploadLoadingBodyAnimation:wt,univerCircleAnimation:St,uploadLoadingBodyText:_t},vt=()=>{const i=u.useDependency(A.IImageIoService),n=u.useDependency(u.LocaleService),[t,e]=Y.useState(0);return Y.useEffect(()=>{const r=i.change$.subscribe(o=>{e(o)});return()=>{r.unsubscribe()}},[i]),k.jsx("div",{style:{display:t>0?"block":"none"},className:ue.uploadLoading,children:k.jsxs("div",{className:ue.uploadLoadingBody,children:[k.jsx("div",{className:ue.uploadLoadingBodyAnimation}),k.jsx("div",{className:ue.uploadLoadingBodyText,children:`${n.t("uploadLoading.loading")}: ${t}`})]})})};var It=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Ct=(i,n,t,e)=>{for(var r=e>1?void 0:e?Dt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&It(n,t,r),r},ee=(i,n)=>(t,e)=>n(t,e,i);let we=class extends u.RxDisposable{constructor(n,t,e,r,o,s,c){super();H(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(u.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>u.connectInjector(vt,this._injector))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjectsByOrder();for(const e of t)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let r;this.disposeWithMe(u.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){r==null||r.dispose();return}const c=s.values().next().value;if(!c)return;const d=c.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:l,subUnitId:a,drawingId:g,drawingType:h}=m,f=m.data;if(f&&f.disablePopup)return;r==null||r.dispose();const w=this._canvasPopManagerService.getFeatureMenu(l,a,g,h);r=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(l,a,g,h)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:a,drawingId:g}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{r==null||r.dispose(),this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{r==null||r.dispose()}))}_getImageMenuItems(n,t,e,r){return[{label:"image-popup.edit",index:0,commandId:We.id,commandParams:{unitId:n,subUnitId:t,drawingId:e},disable:r===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:e},disable:r===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:e}],disable:r===u.DrawingTypeEnum.DRAWING_DOM}]}};we=Ct([ee(0,u.Inject(u.Injector)),ee(1,A.IDrawingManagerService),ee(2,u.Inject(N.SheetCanvasPopManagerService)),ee(3,P.IRenderManagerService),ee(4,u.IUniverInstanceService),ee(5,u.IContextService),ee(6,u.Inject(G.IUIPartsService))],we);function F(i,n,t){const{from:e,to:r,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:d=0,skewY:m=0}=i,{column:l,columnOffset:a,row:g,rowOffset:h}=e,{column:f,columnOffset:w,row:S,rowOffset:D}=r,y=t.getCurrentSkeleton(),C=N.attachRangeWithCoord(y,{startColumn:l,endColumn:l,startRow:g,endRow:g});if(C==null)return;const T=N.attachRangeWithCoord(y,{startColumn:f,endColumn:f,startRow:S,endRow:S});if(T==null)return;const{startX:I,startY:M}=C,{startX:v,startY:O}=T;let b=P.precisionTo(I+a,1),j=P.precisionTo(M+h,1),U=P.precisionTo(v+w-b,1),E=P.precisionTo(O+D-j,1);C.startX===T.endX&&(U=0),C.startY===T.endY&&(E=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return b+U>R&&(b=R-U),j+E>W&&(j=W-E),{flipY:o,flipX:s,angle:c,skewX:d,skewY:m,left:b,top:j,width:U,height:E}}function $(i,n){const{left:t=0,top:e=0,width:r=0,height:o=0,flipY:s=!1,flipX:c=!1,angle:d=0,skewX:m=0,skewY:l=0}=i,a=n.getCellWithCoordByOffset(t,e);if(a==null)return;const g={column:a.actualColumn,columnOffset:P.precisionTo(t-a.startX,1),row:a.actualRow,rowOffset:P.precisionTo(e-a.startY,1)},h=n.getCellWithCoordByOffset(t+r,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:P.precisionTo(t+r-h.startX,1),row:h.actualRow,rowOffset:P.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:m,skewY:l,from:g,to:f}}var yt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Rt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Mt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&yt(n,t,r),r},ge=(i,n)=>(t,e)=>n(t,e,i);let Pe=class extends u.Disposable{constructor(i,n,t,e,r){super(),this._context=i,this._sheetDrawingService=n,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const n in i){const t=i[n];for(const e in t.data){const r=t.data[e];r.transform=F(r.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=Rt([ge(1,p.ISheetDrawingService),ge(2,A.IDrawingManagerService),ge(3,u.Inject(N.ISheetSelectionRenderService)),ge(4,u.Inject(N.SheetSkeletonManagerService))],Pe);function Tt(i){const n=[];return i.forEach(t=>{const{parent:e,children:r}=t,{unitId:o,subUnitId:s,drawingId:c}=e,d=P.getGroupState(0,0,r.map(a=>a.transform||{})),m=r.map(a=>{const g=a.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=a;return{unitId:h,subUnitId:f,drawingId:w,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:u.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:m})}),n}function bt(i){const n=[];return i.forEach(t=>{const{parent:e,children:r}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const m=r.map(a=>{const{transform:g}=a,{unitId:h,subUnitId:f,drawingId:w}=a,S=P.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:u.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:m})}),n}const Le={id:"sheet.command.group-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:c,subUnitId:d,objects:bt(a),type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{var y,C,T;const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!n)return!1;const s=n.drawings,c=s.map(I=>I.unitId),d=r.getBatchAddOp(s),{unitId:m,subUnitId:l,undo:a,redo:g,objects:h}=d,f=o.onCommandExecute({id:ce.id,params:n}),w={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:m,subUnitId:l,objects:h,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:m,subUnitId:l,objects:h,type:p.DrawingApplyType.REMOVE}};return u.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:m,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},xe={id:"sheet.command.set-drawing-arrange",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService);if(!n)return!1;const r=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,m={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===u.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(m):d===u.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(m):d===u.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(m):d===u.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(m)),l==null)return!1;const{objects:a,redo:g,undo:h}=l;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:m,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}]}),!0):!1}},Be={id:"sheet.command.ungroup-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:c,subUnitId:d,objects:Tt(a),type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}]}),!0):!1}};var Et=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,At=(i,n,t,e)=>{for(var r=e>1?void 0:e?Ot(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Et(n,t,r),r},X=(i,n)=>(t,e)=>n(t,e,i);function Pt(i,n,t){const e=t*Math.PI/180,r=Math.abs(i*Math.cos(e))+Math.abs(n*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(n*Math.cos(e));return{rotatedWidth:r,rotatedHeight:o}}function Ze(i,n,t,e,r){var y;const{rotatedHeight:o,rotatedWidth:s}=Pt(t,e,r),d=i.get(P.IRenderManagerService).getRenderById(n.unitId);if(!d)return!1;const l=(y=d.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(n.subUnitId))==null?void 0:y.skeleton;if(l==null)return!1;const a=l.getCellByIndex(n.row,n.col),g=a.mergeInfo.endX-a.mergeInfo.startX-2,h=a.mergeInfo.endY-a.mergeInfo.startY-2,f=s/o,S=Math.ceil(Math.min(g,h*f))/s,D=!S||Number.isNaN(S)?.001:S;return{width:t*D,height:e*D}}let se=class extends u.Disposable{constructor(n,t,e,r,o,s,c,d,m,l,a,g,h){super();H(this,"_workbookSelections");this._context=n,this._skeletonManagerService=t,this._commandService=e,this._selectionRenderService=r,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=m,this._messageService=l,this._localeService=a,this._injector=h,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const n=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=n.length;return t>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(n.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}async _insertFloatImage(n){let t;try{t=await this._imageIoService.saveImage(n)}catch(y){const C=y.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo(),{unitId:r,subUnitId:o}=e,{imageId:s,imageSourceType:c,source:d,base64Cache:m}=t,{width:l,height:a,image:g}=await A.getImageSize(m||""),{width:h,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,g);let w=1;if(l>A.DRAWING_IMAGE_WIDTH_LIMIT||a>A.DRAWING_IMAGE_HEIGHT_LIMIT){const y=A.DRAWING_IMAGE_WIDTH_LIMIT/l,C=A.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,C)}const S=this._getImagePosition(l*w,a*w,h,f);if(S==null)return;const D={unitId:r,subUnitId:o,drawingId:s,drawingType:u.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:F(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(ce.id,{unitId:r,drawings:[D]})}async _insertCellImage(n){let t;try{t=await this._imageIoService.saveImage(n)}catch(S){const D=S.message;D===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const{imageId:e,imageSourceType:r,source:o,base64Cache:s}=t,{width:c,height:d,image:m}=await A.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,r,m);const l=this._workbookSelections.getCurrentLastSelection();if(!l)return!1;const a=u.createDocumentModelWithStyle("",{}),g=Ze(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:l.primary.actualRow,col:l.primary.actualColumn},c,d,0);if(!g)return!1;const h={size:{width:g.width,height:g.height},positionH:{relativeFrom:u.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:u.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:a.getUnitId(),subUnitId:a.getUnitId(),drawingId:e,drawingType:u.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:r,source:o,transform:qe.docDrawingPositionToTransform(h),docTransform:h,behindDoc:u.BooleanNumber.FALSE,title:"",description:"",layoutType:u.PositionedObjectLayoutType.INLINE,wrapText:u.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},w=u.BuildTextUtils.drawing.add({documentDataModel:a,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return w?(a.apply(w),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[l.primary.actualRow]:{[l.primary.actualColumn]:{p:a.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const n=this._context.unit,t=n.getActiveSheet(),e=n.getUnitId(),r=t.getSheetId();return{unitId:e,subUnitId:r}}_getImagePosition(n,t,e,r){const o=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(s=o[o.length-1].range);const c=N.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:m,startX:l,startY:a}=c,g=!1;if(l+n>e&&(l=e-n,l<0&&(l=0,n=e),g=!0),a+t>r&&(a=r-t,a<0&&(a=0,t=r),g=!0),g){const S=this._selectionRenderService.getCellWithCoordByOffset(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,m=S.actualRow}const h={column:d,columnOffset:0,row:m,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(l+n,a+t);if(f==null)return;const w={column:f.actualColumn,columnOffset:l+n-f.startX,row:f.actualRow,rowOffset:a+t-f.startY};return{from:h,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(n=>{const{unitId:t,subUnitId:e,drawingIds:r,arrangeType:o}=n;this._commandService.executeCommand(xe.id,{unitId:t,subUnitId:e,drawingIds:r,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(n=>{const t=[];n.length!==0&&(n.forEach(e=>{const{unitId:r,subUnitId:o,drawingId:s,drawingType:c,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:o,drawingId:s});if(m==null||m.unitId!==this._context.unitId)return;const l=$({...m.transform,...d},this._selectionRenderService);if(l==null)return;const a={...e,transform:{...m.transform,...d,...F(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};t.push(a)}),t.length>0&&this._commandService.executeCommand(de.id,{unitId:n[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Le.id,n);const{unitId:t,subUnitId:e,drawingId:r}=n[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:r}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Be.id,n)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(n=>{n==null||n.length===0?(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(n))}))}};se=At([X(1,u.Inject(N.SheetSkeletonManagerService)),X(2,u.ICommandService),X(3,N.ISheetSelectionRenderService),X(4,A.IImageIoService),X(5,G.ILocalFileService),X(6,p.ISheetDrawingService),X(7,A.IDrawingManagerService),X(8,u.IContextService),X(9,G.IMessageService),X(10,u.Inject(u.LocaleService)),X(11,u.Inject(_.SheetsSelectionsService)),X(12,u.Inject(u.Injector))],se);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,jt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Nt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Ut(n,t,r),r},te=(i,n)=>(t,e)=>n(t,e,i);function Ue(i,n,t){var e,r,o,s;if(((r=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:r.dataStream.length)===3&&((s=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const c=t.p.drawings[t.p.drawingsOrder[0]],d=Ze(i,{unitId:n.unitId,subUnitId:n.subUnitId,row:n.row,col:n.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(d)return c.transform.width=d.width,c.transform.height=d.height,c.docTransform.size.width=d.width,c.docTransform.size.height=d.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Se=class extends u.Disposable{constructor(i,n,t,e,r,o,s){super(),this._commandService=i,this._sheetInterceptorService=n,this._univerInstanceService=t,this._injector=e,this._drawingManagerService=r,this._docDrawingController=o,this._editorBridgeService=s,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let n,t=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),t=e.rowsAutoHeightInfo.map(r=>({startRow:r.row,endRow:r.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}n&&t.length&&t.forEach(e=>{const r=u.Range.transformRange(e,n.worksheet);for(let o=r.startRow;o<=r.endRow;o++)for(let s=r.startColumn;s<=r.endColumn;s++)Ue(this._injector,{unitId:n.unitId,subUnitId:n.subUnitId,row:o,col:s},n.worksheet.getCellRaw(o,s))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===qe.ReplaceSnapshotCommand.id&&i.params.unitId===u.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,n,t)=>(Ue(this._injector,{unitId:n.unitId,subUnitId:n.subUnitId,row:n.row,col:n.col},i),t(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,n,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),t(i)}}))}};Se=jt([te(0,u.ICommandService),te(1,u.Inject(_.SheetInterceptorService)),te(2,u.IUniverInstanceService),te(3,u.Inject(u.Injector)),te(4,A.IDrawingManagerService),te(5,u.Inject(lt.DocDrawingController)),te(6,u.Inject(N.IEditorBridgeService))],Se);var Wt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,xt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Lt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Wt(n,t,r),r},Ke=(i,n)=>(t,e)=>n(t,e,i);let _e=class extends u.Disposable{constructor(i,n){super(),this._autoFillService=i,this._injector=n,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,n,t,e)=>{new u.ObjectMatrix(e).forValue((r,o,s)=>{Ue(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:r,col:o},s)})}}))}};_e=xt([Ke(0,u.Inject(N.IAutoFillService)),Ke(1,u.Inject(u.Injector))],_e);var Bt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Gt=(i,n,t,e)=>{for(var r=e>1?void 0:e?$t(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Bt(n,t,r),r},he=(i,n)=>(t,e)=>n(t,e,i);let ve=class extends u.Disposable{constructor(n,t,e,r){super();H(this,"_isSetCursor",!1);this._hoverManagerService=n,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=r}_initHover(){}_initImageClick(){}};ve=Gt([he(0,u.Inject(N.HoverManagerService)),he(1,u.Inject(P.IRenderManagerService)),he(2,u.Inject(_.SheetsSelectionsService)),he(3,u.Inject(Q.DrawingRenderService))],ve);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ht=(i,n,t,e)=>{for(var r=e>1?void 0:e?Ft(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&kt(n,t,r),r},Ee=(i,n)=>(t,e)=>n(t,e,i);let Ie=class extends u.Disposable{constructor(n,t,e){super();H(this,"_copyInfo");this._sheetClipboardService=n,this._renderManagerService=t,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(n,t,e)=>this._collect(n,t,e),onPasteCells:(n,t,e,r)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:s}=r,{range:c}=n||{},{range:d,unitId:m,subUnitId:l}=t;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:c,unitId:m,subUnitId:l})},onPastePlainText:(n,t)=>({undos:[],redos:[]})})}_collect(n,t,e){var g;const r=(g=this._renderManagerService.getRenderById(n))==null?void 0:g.with(N.SheetSkeletonManagerService);if(!r)return;const o=r.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:c,startY:d,endY:m}=o,l=this._sheetDrawingService.getDrawingData(n,t),a=[];Object.keys(l).forEach(h=>{const f=l[h],{transform:w}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:D=0,width:y=0,height:C=0}=w,{drawingStartX:T,drawingEndX:I,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:D,drawingEndY:D+C};s<=T&&I<=c&&d<=M&&v<=m&&a.push(f)}),a.length&&(this._copyInfo={drawings:a,unitId:n,subUnitId:t})}_generateMutations(n,t){var b;if(!this._copyInfo)return{redos:[],undos:[]};if([N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};const{copyRange:e}=t;if(!e)return{redos:[],undos:[]};const{drawings:r,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[c,d],mapFunc:m}=N.virtualizeDiscreteRanges([e,n]),{row:l,col:a}=m(c.startRow,c.startColumn),{row:g,col:h}=m(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(N.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const w=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:a,endColumn:a}),S=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:h,endColumn:h});if(!w||!S)return{redos:[],undos:[]};const D=[],y=[],C=S.startX-w.startX,T=S.startY-w.startY,I=g-l,M=h-a,v=t.copyType===N.COPY_TYPE.CUT,{_sheetDrawingService:O}=this;return r.forEach(j=>{const{transform:U,sheetTransform:E}=j;if(!U)return;const R={...j,unitId:o,subUnitId:s,drawingId:v?j.drawingId:u.Tools.generateRandomId(),transform:{...U,left:U.left+C,top:U.top+T},sheetTransform:{to:{...E.to,row:E.to.row+I,column:E.to.column+M},from:{...E.from,row:E.from.row+I,column:E.from.column+M}}};if(v){const{undo:W,redo:B,objects:q}=O.getBatchUpdateOp([R]);D.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:B,objects:q}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:W,objects:q}})}else{const{undo:W,redo:B,objects:q}=O.getBatchAddOp([R]);D.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.REMOVE}})}}),{redos:D,undos:y}}};Ie=Ht([Ee(0,N.ISheetClipboardService),Ee(1,P.IRenderManagerService),Ee(2,p.ISheetDrawingService)],Ie);var Vt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Xt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Yt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Vt(n,t,r),r},oe=(i,n)=>(t,e)=>n(t,e,i);let De=class extends u.Disposable{constructor(i,n,t,e,r){super(),this._drawingManagerService=i,this._renderManagerService=n,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=r,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const r=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=n.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(c,d),l=Object.values(m),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===P.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const r=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=n.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(c,d),l=Object.values(m),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===P.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const r=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(r),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).pipe(L.map(g=>g.every(h=>h.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(r,o),w=Object.values(f);g?this._drawingManagerService.addNotification(w):(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.removeObject(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(r,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(r,o),h=Object.values(g);this._drawingManagerService.addNotification(h)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const r=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(r),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).pipe(L.map(g=>g.every(h=>h.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(r,o),w=Object.values(f);g?(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.detachTransformerFrom(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(r,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=n.getUnitId(),h=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,h),w=Object.values(f),S=this._renderManagerService.getRenderById(g),D=S==null?void 0:S.scene;if(D==null)return;this._drawingManagerService.setDrawingEditable(!0),D.getAllObjectsByOrder().forEach(C=>{C.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>C.oKey.includes(T.drawingId))&&D.detachTransformerFrom(C)})}})})}))}};De=Xt([oe(0,A.IDrawingManagerService),oe(1,P.IRenderManagerService),oe(2,u.IPermissionService),oe(3,u.IUniverInstanceService),oe(4,u.Inject(u.UserManagerService))],De);var zt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,qt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Kt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&zt(n,t,r),r},me=(i,n)=>(t,e)=>n(t,e,i);let Ce=class extends u.Disposable{constructor(i,n,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=n,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,n,t)=>{const{unitId:e,scene:r,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],r)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,n,t)=>{const{unitId:e,subUnitId:r}=n,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r);if(!s)return t(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[n.subUnitId];if(!d)return t(i);const{scaleX:m,scaleY:l}=o.scene,a=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==u.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(h=>{if(!h.groupId&&h.transform&&u.Tools.isDefine(h.transform.left)&&u.Tools.isDefine(h.transform.top)&&u.Tools.isDefine(h.transform.width)&&u.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,m,l,{x:0,y:0}),w=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,m,l,{x:0,y:0});f.column<a.startColumn&&(a.startColumn=f.column),f.row<a.startRow&&(a.startRow=f.row),a.endRow<w.row&&(a.endRow=w.row),a.endColumn<w.column&&(a.endColumn=w.column)}}),t(a)):t(i)}}))}};Ce=qt([me(0,u.Inject(N.SheetPrintInterceptorService)),me(1,u.Inject(Q.DrawingRenderService)),me(2,A.IDrawingManagerService),me(3,P.IRenderManagerService)],Ce);var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Qt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Zt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Jt(n,t,r),r},J=(i,n)=>(t,e)=>n(t,e,i);const en=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],tn=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Ne=class extends u.Disposable{constructor(i,n,t,e,r,o,s,c,d){super(),this._context=i,this._renderManagerService=n,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=r,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!en.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(n))return this._moveRangeInterceptor(i.params);if(n===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===_.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(n===_.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(n===_.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(n===_.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(n===_.SetRowHiddenCommand.id||n===_.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,r,o)}else if(n===_.SetSpecificColsVisibleCommand.id||n===_.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t;return this._getDrawingUndoForColVisible(e,r,o)}else if(n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id||n===_.DeltaColumnWidthCommand.id||n===_.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t,s=n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,r=t.subUnitId,o=[],s=[],c=this._sheetDrawingService.getDrawingData(e,r),d=[],m=[];if(Object.keys(c).forEach(l=>{const a=c[l],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,n,a);d.push(...g),m.push(...h)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:g,objects:h}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:a,objects:h,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(m),a=l.undo,g=l.redo,h=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:a,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:x.id,params:[e]}),s.push({id:x.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,n,t){const e=[],r=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:m,drawingId:l}=t,{from:a,to:g}=o,{row:h,column:f}=a,{row:w,column:S}=g;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:r};const{startRow:D,endRow:y,startColumn:C,endColumn:T}=i;let I=null,M=null;if(n===0&&h>=D&&w<=y)if(f>=C&&S<=T)r.push({unitId:d,subUnitId:m,drawingId:l});else{const v=this._shrinkCol(o,c,C,T,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===1&&f>=C&&S<=T)if(h>=D&&w<=y)r.push({unitId:d,subUnitId:m,drawingId:l});else{const v=this._shrinkRow(o,c,D,y,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===2){const v=this._expandRow(o,c,D,y,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===3){const v=this._expandCol(o,c,C,T,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(I!=null&&M!=null){const v=F(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:v})}return{updateDrawings:e,deleteDrawings:r}}_remainDrawingSize(i,n,t){const e=$({...i},this._selectionRenderService);e!=null&&n.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,a);else{const{from:w,to:S}=g,{row:D,column:y}=w,{row:C,column:T}=S;for(let I=0;I<t.length;I++){const M=t[I],{startRow:v,endRow:O,startColumn:b,endColumn:j}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=b&&y<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(B==null)return;W={...h,left:B.startX}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){r.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,r,a);continue}if(y>=b&&T<=j)continue;let U=null,E=null;if(y>=b&&y<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;E={...h,left:(R==null?void 0:R.startX)||0,width:((h==null?void 0:h.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(R==null)return;E={...h,left:R.startX-((h==null?void 0:h.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;if(E={...h,width:((h==null?void 0:h.width)||0)-R.endX+R.startX},U=$(E,this._selectionRenderService),U!=null&&E!=null){o.push({...a,sheetTransform:U,transform:E});break}}if(E!=null&&(U=$(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...a,sheetTransform:U,transform:E});break}else this._remainDrawingSize(h,r,a)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,r),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,n,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:r,redo:o,objects:s}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:r,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,a);else{const{from:w,to:S}=g,{row:D,column:y}=w,{row:C,column:T}=S;for(let I=0;I<t.length;I++){const M=t[I],{startRow:v,endRow:O,startColumn:b,endColumn:j}=M;if(C<v)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(D>=v&&D<=O){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:O});if(B==null)return;W={...h,top:B.startY}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){r.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,r,a);continue}if(D>=v&&C<=O)continue;let U=null,E=null;if(D>=v&&D<=O){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:O});if(R==null)return;E={...h,top:(R==null?void 0:R.startY)||0,height:((h==null?void 0:h.height)||0)-R.endY+R.startY}}else if(C>=v&&C<=O){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(R==null)return;E={...h,top:R.startY-((h==null?void 0:h.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:O});if(R==null)return;if(E={...h,height:((h==null?void 0:h.height)||0)-R.endY+R.startY},U=$(E,this._selectionRenderService),U!=null&&E!=null){o.push({...a,sheetTransform:U,transform:E});break}}if(E!=null&&(U=$(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...a,sheetTransform:U,transform:E});break}else this._remainDrawingSize(h,r,a)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,r),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,n,t,e){const r=this._drawingManagerService.getDrawingData(i,n),o=[];return Object.keys(r).forEach(s=>{const c=r[s],{sheetTransform:d,transform:m,anchorType:l=p.SheetDrawingAnchorType.Position}=c;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,c);else{const{from:a,to:g}=d,{row:h,column:f}=a,{row:w,column:S}=g;for(let D=0;D<t.length;D++){const y=t[D],{startRow:C,endRow:T,startColumn:I,endColumn:M}=y;if(w<C||S<I)continue;if(l===p.SheetDrawingAnchorType.Position&&(h<=C&&w>=T||f<=I&&S>=M)){this._remainDrawingSize(m,o,c);continue}const v=F({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...c,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,n,o)}_getUnitIdAndSubUnitId(i,n){let t,e;if(n==="insert")t=i.unitId,e=i.subUnitId;else{const r=_.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;t=r.unitId,e=r.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:n,fromRange:t}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:r,subUnitId:o}=e,s=(T=(C=this._renderManagerService.getRenderById(r))==null?void 0:C.with(N.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=N.attachRangeWithCoord(s,t);if(!c)return{redos:[],undos:[]};const{startX:d,endX:m,startY:l,endY:a}=c,g=this._sheetDrawingService.getDrawingData(r,o),h=[];Object.keys(g).forEach(I=>{const M=g[I];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:O=0,top:b=0,width:j=0,height:U=0}=v,{drawingStartX:E,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:O,drawingEndX:O+j,drawingStartY:b,drawingEndY:b+U};d<=E&&R<=m&&l<=W&&B<=a&&h.push(M)});const f=[],w=[],S=n.startRow-t.startRow,D=n.startColumn-t.startColumn,y=h.map(I=>{const M=I.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+D},from:{...M.from,row:M.from.row+S,column:M.from.column+D}},O=F(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:r,subUnitId:o,drawingId:I.drawingId,transform:O,sheetTransform:v}});if(y.length){const I=this._sheetDrawingService.getBatchUpdateOp(y),{undo:M,redo:v,objects:O}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:o,op:v,objects:O,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:o,op:M,objects:O,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,n){const t=this._getUnitIdAndSubUnitId(i,n);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:r}=t,{range:o}=i,s=o.startRow,c=o.endRow,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,r),a=[],g=[];if(Object.keys(l).forEach(h=>{const f=l[h],{sheetTransform:w,transform:S,anchorType:D=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(n==="insert"){const I=this._expandRow(w,S,s,c,D);y=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:M}=w,{row:v}=I,{row:O}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&O<=c)g.push({unitId:e,subUnitId:r,drawingId:h});else{const b=this._shrinkRow(w,S,s,c,D);y=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:r,drawingId:h,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),m.push({id:x.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(i,n){const t=this._getUnitIdAndSubUnitId(i,n);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:r}=t,{range:o}=i,s=o.startColumn,c=o.endColumn,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,r),a=[],g=[];if(Object.keys(l).forEach(h=>{const f=l[h],{sheetTransform:w,transform:S,anchorType:D=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(n==="insert"){const I=this._expandCol(w,S,s,c,D);y=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:M}=w,{column:v}=I,{column:O}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&O<=c)g.push({unitId:e,subUnitId:r,drawingId:h});else{const b=this._shrinkCol(w,S,s,c,D);y=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:r,drawingId:h,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),m.push({id:x.id,params:[e]}),{redos:d,undos:m}}_expandCol(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:c.row});if(g==null)return;a={...n,left:(n.left||0)+g.endX-g.startX},l=$(a,this._selectionRenderService)}else if(m>=e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkCol(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,column:d-o},to:{...c,column:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=t&&d<=e){if(d===t)a={...n,left:(n.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:c.row});if(g==null)return;a={...n,left:(n.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:c.row});if(g==null)return;l={from:{...s},to:{...c,column:t-1,columnOffset:g.endX-g.startX}},a=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_expandRow(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...n,top:(n.top||0)+g.endY-g.startY},l=$(a,this._selectionRenderService)}else if(m>=e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkRow(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,row:d-o},to:{...c,row:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=t&&d<=e){if(d===t)a={...n,top:(n.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...n,top:(n.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(g==null)return;l={from:{...s},to:{...c,row:t-1,rowOffset:g.endY-g.startY}},a=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const n=i.params,{unitId:t,subUnitId:e}=n,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(c=>{const d=r[c];d!=null&&Object.keys(d).forEach(m=>{const l=d[m].data;l!=null&&Object.keys(l).forEach(a=>{if(c===t&&m===e){const g=l[a];g.transform=F(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[a])}else s.push(l[a])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{tn.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:t,subUnitId:e,ranges:r}=n;this._refreshDrawingTransform(t,e,r)})}))}_refreshDrawingTransform(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:c,transform:d,anchorType:m=p.SheetDrawingAnchorType.Position}=s;if(m===p.SheetDrawingAnchorType.None)return!0;const{from:l,to:a}=c,{row:g,column:h}=l,{row:f,column:w}=a;for(let S=0;S<t.length;S++){const D=t[S],{startRow:y,endRow:C,startColumn:T,endColumn:I}=D;if(u.Rectangle.intersects({startRow:y,endRow:C,startColumn:T,endColumn:I},{startRow:g,endRow:f,startColumn:h,endColumn:w})||g>C||h>I){const M=m===p.SheetDrawingAnchorType.Position,v=F(c,this._selectionRenderService,this._skeletonManagerService);r.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(x.id,[i]))}};Ne=Qt([J(1,P.IRenderManagerService),J(2,u.ICommandService),J(3,N.ISheetSelectionRenderService),J(4,u.Inject(N.SheetSkeletonManagerService)),J(5,u.Inject(_.SheetInterceptorService)),J(6,p.ISheetDrawingService),J(7,A.IDrawingManagerService),J(8,u.IUniverInstanceService)],Ne);var z=function(){return z=Object.assign||function(i){for(var n,t=1,e=arguments.length;t<e;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(i[r]=n[r])}return i},z.apply(this,arguments)},nn=function(i,n){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&n.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(i);r<e.length;r++)n.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(i,e[r])&&(t[e[r]]=i[e[r]]);return t},Qe=Y.forwardRef(function(i,n){var t=i.icon,e=i.id,r=i.className,o=i.extend,s=nn(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),d=Y.useRef("_".concat(sn()));return et(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},z({ref:n,className:c},s),o)});function et(i,n,t,e,r){return Y.createElement(i.tag,z(z({key:n},rn(i,t,r)),e),(on(i,t).children||[]).map(function(o,s){return et(o,"".concat(n,"-").concat(i.tag,"-").concat(s),t,void 0,r)}))}function rn(i,n,t){var e=z({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function on(i,n){var t,e=n.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?z(z({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?z(z({},r),{attrs:z(z({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):i}function sn(){return Math.random().toString(36).substring(2,8)}Qe.displayName="UniverIcon";var an={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"}}]},tt=Y.forwardRef(function(i,n){return Y.createElement(Qe,Object.assign({},i,{id:"add-image-single",ref:n,icon:an}))});tt.displayName="AddImageSingle";const $e={id:"sheet.command.delete-drawing",type:u.CommandType.COMMAND,handler:i=>{const n=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const r=e[0].unitId,o=e.map(s=>{const{unitId:c,subUnitId:d,drawingId:m,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:m,drawingType:l}});return n.executeCommand(ae.id,{unitId:r,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:u.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(P.IRenderManagerService).getCurrentTypeOfRenderer(u.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(se).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:u.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(P.IRenderManagerService).getCurrentTypeOfRenderer(u.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(se).insertCellImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService),r=i.get(N.ISheetSelectionRenderService),{direction:o}=n,s=e.getFocusDrawings();if(s.length===0)return!1;const c=s[0].unitId,d=s.map(l=>{const{transform:a}=l;if(a==null)return null;const g={...a},{left:h=0,top:f=0}=a;return o===u.Direction.UP?g.top=f-1:o===u.Direction.DOWN?g.top=f+1:o===u.Direction.LEFT?g.left=h-1:o===u.Direction.RIGHT&&(g.left=h+1),{...l,transform:g,sheetTransform:$(g,r)}}).filter(l=>l!=null);return t.syncExecuteCommand(de.id,{unitId:c,drawings:d})?(t.syncExecuteCommand(x.id,[c]),!0):!1}},nt="addition-and-subtraction-single",ke="sheet.menu.image";function cn(i){return{id:ke,type:G.MenuItemType.SUBITEMS,icon:nt,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function dn(i){return{id:Me.id,title:"sheetImage.upload.float",type:G.MenuItemType.BUTTON,hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET)}}function ln(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:G.MenuItemType.BUTTON}}const un="univer-image-common-panel",gn="univer-image-common-panel-grid",hn="univer-image-common-panel-border",mn="univer-image-common-panel-title",pn="univer-image-common-panel-subtitle",fn="univer-image-common-panel-row",wn="univer-image-common-panel-row-vertical",Sn="univer-image-common-panel-column",_n="univer-image-common-panel-column-center",vn="univer-image-common-panel-inline",In="univer-image-common-panel-span2",Dn="univer-image-common-panel-span3",Cn="univer-image-common-panel-input",yn="univer-sheet-image-menu",Mn="univer-sheet-image-menu-input",Z={imageCommonPanel:un,imageCommonPanelGrid:gn,imageCommonPanelBorder:hn,imageCommonPanelTitle:mn,imageCommonPanelSubtitle:pn,imageCommonPanelRow:fn,imageCommonPanelRowVertical:wn,imageCommonPanelColumn:Sn,imageCommonPanelColumnCenter:_n,imageCommonPanelInline:vn,imageCommonPanelSpan2:In,imageCommonPanelSpan3:Dn,imageCommonPanelInput:Cn,sheetImageMenu:yn,sheetImageMenuInput:Mn};function rt(i){var n,t,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var r=i.length;for(n=0;n<r;n++)i[n]&&(t=rt(i[n]))&&(e&&(e+=" "),e+=t)}else for(t in i)i[t]&&(e&&(e+=" "),e+=t);return e}function pe(){for(var i,n,t=0,e="",r=arguments.length;t<r;t++)(i=arguments[t])&&(n=rt(i))&&(e&&(e+=" "),e+=n);return e}const Rn=i=>{var C;const n=u.useDependency(u.ICommandService),t=u.useDependency(u.LocaleService),e=u.useDependency(A.IDrawingManagerService),r=u.useDependency(P.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:c}=s,d=r.getRenderById(c),m=d==null?void 0:d.scene;if(m==null)return;const l=m.getTransformerByCreate(),[a,g]=Y.useState(!0),h=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=Y.useState(h);function S(T,I){const M=[];return T.forEach(v=>{const{oKey:O}=v,b=I.getDrawingOKey(O);if(b==null)return M.push(null),!0;const{unitId:j,subUnitId:U,drawingId:E,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:j,subUnitId:U,drawingId:E,anchorType:W,sheetTransform:B,drawingType:R})}),M}Y.useEffect(()=>{const T=l.clearControl$.subscribe(M=>{M===!0&&g(!1)}),I=l.changeStart$.subscribe(M=>{var b;const{objects:v}=M,O=S(v,e);if(O.length===0)g(!1);else if(O.length>=1){g(!0);const j=((b=O[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(j)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function D(T){w(T);const I=e.getFocusDrawings();if(I.length===0)return;const M=I.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));n.executeCommand(de.id,{unitId:I[0].unitId,drawings:M})}const y=T=>T?"block":"none";return k.jsxs("div",{className:pe(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:y(a)},children:[k.jsx("div",{className:Z.imageCommonPanelRow,children:k.jsx("div",{className:pe(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle),children:k.jsx("div",{children:t.t("drawing-anchor.title")})})}),k.jsx("div",{className:pe(Z.imageCommonPanelRow),children:k.jsx("div",{className:pe(Z.imageCommonPanelColumn),children:k.jsxs(K.RadioGroup,{value:f,onChange:D,direction:"vertical",children:[k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Tn=()=>{const i=u.useDependency(A.IDrawingManagerService),n=i.getFocusDrawings(),[t,e]=Y.useState(n);return Y.useEffect(()=>{const r=i.focus$.subscribe(o=>{e(o)});return()=>{r.unsubscribe()}},[]),!!(t!=null&&t.length)&&k.jsxs("div",{className:Z.imageCommonPanel,children:[k.jsx(Q.DrawingCommonPanel,{drawings:t}),k.jsx(Rn,{drawings:t})]})},bn={[G.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:cn,[Me.id]:{order:0,menuItemFactory:dn},[Ge.id]:{order:1,menuItemFactory:ln}}}};function le(i){return!i.getContextValue(u.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(u.EDITOR_ACTIVATED)&&!i.getContextValue(u.FOCUSING_PANEL_EDITOR)&&i.getContextValue(u.FOCUSING_COMMON_DRAWINGS)}const En={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:le,staticParameters:{direction:u.Direction.DOWN}},On={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:le,staticParameters:{direction:u.Direction.UP}},An={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:le,staticParameters:{direction:u.Direction.LEFT}},Pn={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:le,staticParameters:{direction:u.Direction.RIGHT}},Un={id:$e.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:le,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var Nn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Wn=(i,n,t,e)=>{for(var r=e>1?void 0:e?jn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Nn(n,t,r),r},fe=(i,n)=>(t,e)=>n(t,e,i);let ye=class extends u.Disposable{constructor(i,n,t,e){super(),this._componentManager=i,this._menuManagerService=n,this._commandService=t,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(nt,tt)),this.disposeWithMe(i.register(Je,Tn))}_initMenus(){this._menuManagerService.mergeMenu(bn)}_initCommands(){[Me,Ge,ce,ae,de,je,x,We,Le,Be,re,$e,xe].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[En,On,An,Pn,Un].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ye=Wn([fe(0,u.Inject(G.ComponentManager)),fe(1,G.IMenuManagerService),fe(2,u.ICommandService),fe(3,G.IShortcutService)],ye);var Ln=Object.defineProperty,xn=Object.getOwnPropertyDescriptor,Bn=(i,n,t,e)=>{for(var r=e>1?void 0:e?xn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Ln(n,t,r),r},ne=(i,n)=>(t,e)=>n(t,e,i);function $n(i,n,t,e){const{scaleX:r,scaleY:o}=n.getAncestorScale(),s=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...i,absolute:c};const{left:d,right:m,top:l,bottom:a}=i,g=e.getFreeze(),{startColumn:h,startRow:f,xSplit:w,ySplit:S}=g,D=t.getNoMergeCellPositionByIndexWithNoHeader(f-S,h-w),y=t.getNoMergeCellPositionByIndexWithNoHeader(f,h),{rowHeaderWidth:C,columnHeaderHeight:T}=t,I=y.startX-D.startX,M=y.startY-D.startY,{top:v,left:O,viewportScrollX:b,viewportScrollY:j}=s;let U,E;d<O?(c.left=!0,U=(I+C+(d-O))*r,E=Math.max(Math.min((I+C+(m-O))*r,(I+C)*r),(m-b)*r)):(c.left=!1,U=Math.max((d-b)*r,(I+C)*r),E=Math.max((m-b)*r,(I+C)*r));let R,W;return l<v?(c.top=!0,R=(M+T+(l-v))*o,W=Math.max(Math.min((M+T+(m-v))*o,(M+T)*o),(a-j)*o)):(c.top=!1,R=Math.max((l-j)*o,(M+T)*o),W=Math.max((a-j)*o,(M+T)*o)),{left:U,right:E,top:R,bottom:W,absolute:c}}const Oe=(i,n,t,e)=>{const{scene:r}=n,{left:o,top:s,width:c,height:d,angle:m}=i,l={left:o,right:o+c,top:s,bottom:s+d},a=$n(l,r,t,e),{scaleX:g,scaleY:h}=r.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:m,width:c*g,height:d*h,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends u.Disposable{constructor(t,e,r,o,s,c,d){super();H(this,"_domLayerMap",new Map);H(this,"_domLayerInfoMap",new Map);H(this,"_transformChange$",new L.Subject);H(this,"transformChange$",this._transformChange$.asObservable());H(this,"_add$",new L.Subject);H(this,"add$",this._add$.asObservable());H(this,"_remove$",new L.Subject);H(this,"remove$",this._remove$.asObservable());H(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=r,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(L.filter(t=>t===u.LifecycleStages.Rendered),L.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let r=this._domLayerMap.get(t);r||(r=new Map,this._domLayerMap.set(t,r));let o=r.get(e);return o||(o=new Map,r.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),r=e==null?void 0:e.scene;if(e==null||r==null)return null;const o=r.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:e,canvas:s}}_getFloatDomProps(t){let e;return this._hooks.forEach(r=>{e=r.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var He,Ve,Ye;const{unitId:r,subUnitId:o,drawingId:s}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(r,u.UniverInstanceType.UNIVER_SHEET);if(!m)return;const l=m.getActiveSheet().getSheetId();if(!d||!c)return;const a=(He=this._renderManagerService.getRenderById(r))==null?void 0:He.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:g,drawingType:h,data:f}=d;if(h!==u.DrawingTypeEnum.DRAWING_DOM&&h!==u.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(r);if(w==null)return;const{scene:S,canvas:D}=w;if(g==null)return!0;if(l!==o)return;const{left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:O,skewX:b,skewY:j}=g,U=A.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),E=S.getObject(U);if(E!=null){E.transformByState({left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:O,skewX:b,skewY:j});return}const R={left:y,top:C,width:T,height:I,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},W=h===u.DrawingTypeEnum.DRAWING_CHART;W&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const B=new P.Rect(U,R);W&&B.setObjectType(P.ObjectType.CHART),S.addObject(B,P.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const q=this._ensureMap(r,o),Re=new u.DisposableCollection,st=Oe(B,w.renderObject,a.skeleton,c.worksheet),Te=new L.BehaviorSubject(st),at={dispose:Re,rect:B,position$:Te,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Te,id:s,componentKey:d.componentKey,onPointerDown:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onWheel:V=>{D.dispatchEvent(new WheelEvent(V.type,V))},props:(Ye=(Ve=q.get(s))==null?void 0:Ve.props)!=null?Ye:this._getFloatDomProps(s),data:f,unitId:r});const Fe=B.onTransformChange$.subscribeEvent(()=>{const V=Oe(B,w.renderObject,a.skeleton,c.worksheet);Te.next(V)});Re.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Fe&&Re.add(Fe),this._domLayerInfoMap.set(s,at),q.set(s,{...q.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:r,subUnitId:o,drawingId:s}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(r);if(d==null)return;const{transformer:m,scene:l}=d,a=l.getObject(c);a!=null&&a.oKey&&m.clearControlByIds([a==null?void 0:a.oKey])})}))}_scrollUpdateListener(){const t=(e,r)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,r),c=Array.from(s.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:r}),m=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r);!o||!d||!m||c.forEach(a=>{const g=this._domLayerInfoMap.get(a);if(g){const h=Oe(g.rect,o.renderObject,m.skeleton,d.worksheet);g.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.filter(e=>!!e),L.switchMap(e=>e.activeSheet$),L.filter(e=>!!e),L.map(e=>{const r=this._renderManagerService.getRenderById(e.getUnitId());return r?{render:r,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),L.filter(e=>!!e),L.switchMap(e=>u.fromEventSubject(e.render.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(L.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:r})=>{t(e,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;if(e.id===N.SetZoomRatioOperation.id){const s=e.params,{unitId:c}=s;Array.from((o=(r=this._domLayerMap.get(c))==null?void 0:r.keys())!=null?o:[]).forEach(m=>{t(c,m)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:s,subUnitId:c}=e.params;t(s,c)}}))}_getPosition(t,e){var h;const{startX:r,endX:o,startY:s,endY:c}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(N.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(r,s);if(m==null)return;const l={column:m.actualColumn,columnOffset:r-m.startX,row:m.actualRow,rowOffset:s-m.startY},a=d.getCellWithCoordByOffset(o,c);if(a==null)return;const g={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const r=this._drawingManagerService.getDrawingByParam(e);if(!r||r.drawingType!==u.DrawingTypeEnum.DRAWING_DOM&&r.drawingType!==u.DrawingTypeEnum.DRAWING_CHART)return;const o={...r.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,r,o){const s=this._domLayerInfoMap.get(r),c=this._getSceneAndTransformerByDrawingSearch(t);if(s&&c){const{scene:d}=c,m=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:r}),l=d.getObject(m);l&&l instanceof P.Rect&&l.setProps(o)}}addFloatDomToPosition(t,e){const r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!r)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=r,{initPosition:c,componentKey:d,data:m,allowTransform:l=!0}=t,a=e!=null?e:u.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,s).set(a,t);const f={unitId:o,subUnitId:s,drawingId:a,drawingType:t.type||u.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:m,allowTransform:l};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:s,id:a}),{id:a,dispose:()=>{this._removeDom(a,!0)}}}_removeDom(t,e=!1){const r=this._domLayerInfoMap.get(t);if(!r)return;const{unitId:o,subUnitId:s}=r;this._domLayerInfoMap.delete(t),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),e){this._ensureMap(o,s).delete(t);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:t});if(!m)return;const l=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:a,objects:g}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(r=>r===t);this._hooks.splice(e,1)}}}};exports.SheetCanvasFloatDomManagerService=Bn([ne(0,u.Inject(P.IRenderManagerService)),ne(1,u.IUniverInstanceService),ne(2,u.Inject(u.ICommandService)),ne(3,A.IDrawingManagerService),ne(4,u.Inject(G.CanvasFloatDomService)),ne(5,p.ISheetDrawingService),ne(6,u.Inject(u.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var it=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,kn=(i,n,t)=>n in i?it(i,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[n]=t,Fn=(i,n,t,e)=>{for(var r=e>1?void 0:e?Gn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&it(n,t,r),r},Ae=(i,n)=>(t,e)=>n(t,e,i),ot=(i,n,t)=>kn(i,typeof n!="symbol"?n+"":n,t);const Hn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends u.Plugin{constructor(n=gt,t,e,r){super(),this._config=n,this._injector=t,this._renderManagerService=e,this._configService=r;const{menu:o,...s}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ut,s)}onStarting(){u.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[ye],[we],[Ce],[De],[Ie],[Se],[ve],[_e]]),u.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){u.touchDependencies(this._injector,[[Ie]])}onRendered(){this._registerRenderModules(),u.touchDependencies(this._injector,[[De],[Ce],[ye],[Se],[ve],[_e]])}onSteady(){this._injector.get(we)}_registerRenderModules(){[[se],[Ne],[Pe]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,n))})}};ot(exports.UniverSheetsDrawingUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);ot(exports.UniverSheetsDrawingUIPlugin,"pluginName",Hn);exports.UniverSheetsDrawingUIPlugin=Fn([u.DependentOn(A.UniverDrawingPlugin,Q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ae(1,u.Inject(u.Injector)),Ae(2,P.IRenderManagerService),Ae(3,u.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=x;exports.DeleteDrawingsCommand=$e;exports.EditSheetDrawingOperation=We;exports.GroupSheetDrawingCommand=Le;exports.InsertFloatImageCommand=Me;exports.InsertSheetDrawingCommand=ce;exports.MoveDrawingsCommand=re;exports.RemoveSheetDrawingCommand=ae;exports.SHEETS_IMAGE_MENU_ID=ke;exports.SetDrawingArrangeCommand=xe;exports.SetSheetDrawingCommand=de;exports.SidebarSheetDrawingOperation=je;exports.UngroupSheetDrawingCommand=Be;
|
|
9
|
+
*/var Xe;function ht(){if(Xe)return ie;Xe=1;var i=Y,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,r=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(c,d,m){var l,a={},g=null,h=null;m!==void 0&&(g=""+m),d.key!==void 0&&(g=""+d.key),d.ref!==void 0&&(h=d.ref);for(l in d)e.call(d,l)&&!o.hasOwnProperty(l)&&(a[l]=d[l]);if(c&&c.defaultProps)for(l in d=c.defaultProps,d)a[l]===void 0&&(a[l]=d[l]);return{$$typeof:n,type:c,key:g,ref:h,props:a,_owner:r.current}}return ie.Fragment=t,ie.jsx=s,ie.jsxs=s,ie}var ze;function mt(){return ze||(ze=1,be.exports=ht()),be.exports}var k=mt();const pt="univer-upload-loading",ft="univer-upload-loading-body",wt="univer-upload-loading-body-animation",St="univer-UniverCircleAnimation",_t="univer-upload-loading-body-text",ue={uploadLoading:pt,uploadLoadingBody:ft,uploadLoadingBodyAnimation:wt,univerCircleAnimation:St,uploadLoadingBodyText:_t},vt=()=>{const i=u.useDependency(A.IImageIoService),n=u.useDependency(u.LocaleService),[t,e]=Y.useState(0);return Y.useEffect(()=>{const r=i.change$.subscribe(o=>{e(o)});return()=>{r.unsubscribe()}},[i]),k.jsx("div",{style:{display:t>0?"block":"none"},className:ue.uploadLoading,children:k.jsxs("div",{className:ue.uploadLoadingBody,children:[k.jsx("div",{className:ue.uploadLoadingBodyAnimation}),k.jsx("div",{className:ue.uploadLoadingBodyText,children:`${n.t("uploadLoading.loading")}: ${t}`})]})})};var It=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Ct=(i,n,t,e)=>{for(var r=e>1?void 0:e?Dt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&It(n,t,r),r},ee=(i,n)=>(t,e)=>n(t,e,i);let we=class extends u.RxDisposable{constructor(n,t,e,r,o,s,c){super();H(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=r,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(u.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>u.connectInjector(vt,this._injector))}_dispose(n){const t=n.getUnitId();this._renderManagerService.removeRender(t)}_create(n){if(!n)return;const t=n.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(n){const t=n.getAllObjectsByOrder();for(const e of t)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const t=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let r;this.disposeWithMe(u.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){r==null||r.dispose();return}const c=s.values().next().value;if(!c)return;const d=c.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:l,subUnitId:a,drawingId:g,drawingType:h}=m,f=m.data;if(f&&f.disablePopup)return;r==null||r.dispose();const w=this._canvasPopManagerService.getFeatureMenu(l,a,g,h);r=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:Q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(l,a,g,h)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:a,drawingId:g}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{r==null||r.dispose(),this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{r==null||r.dispose()}))}_getImageMenuItems(n,t,e,r){return[{label:"image-popup.edit",index:0,commandId:We.id,commandParams:{unitId:n,subUnitId:t,drawingId:e},disable:r===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:t,drawingId:e},disable:r===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:t,drawingId:e}],disable:r===u.DrawingTypeEnum.DRAWING_DOM}]}};we=Ct([ee(0,u.Inject(u.Injector)),ee(1,A.IDrawingManagerService),ee(2,u.Inject(N.SheetCanvasPopManagerService)),ee(3,P.IRenderManagerService),ee(4,u.IUniverInstanceService),ee(5,u.IContextService),ee(6,u.Inject(G.IUIPartsService))],we);function F(i,n,t){const{from:e,to:r,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:d=0,skewY:m=0}=i,{column:l,columnOffset:a,row:g,rowOffset:h}=e,{column:f,columnOffset:w,row:S,rowOffset:D}=r,y=t.getCurrentSkeleton(),C=N.attachRangeWithCoord(y,{startColumn:l,endColumn:l,startRow:g,endRow:g});if(C==null)return;const T=N.attachRangeWithCoord(y,{startColumn:f,endColumn:f,startRow:S,endRow:S});if(T==null)return;const{startX:I,startY:M}=C,{startX:v,startY:O}=T;let b=P.precisionTo(I+a,1),j=P.precisionTo(M+h,1),U=P.precisionTo(v+w-b,1),E=P.precisionTo(O+D-j,1);C.startX===T.endX&&(U=0),C.startY===T.endY&&(E=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return b+U>R&&(b=R-U),j+E>W&&(j=W-E),{flipY:o,flipX:s,angle:c,skewX:d,skewY:m,left:b,top:j,width:U,height:E}}function $(i,n){const{left:t=0,top:e=0,width:r=0,height:o=0,flipY:s=!1,flipX:c=!1,angle:d=0,skewX:m=0,skewY:l=0}=i,a=n.getCellWithCoordByOffset(t,e);if(a==null)return;const g={column:a.actualColumn,columnOffset:P.precisionTo(t-a.startX,1),row:a.actualRow,rowOffset:P.precisionTo(e-a.startY,1)},h=n.getCellWithCoordByOffset(t+r,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:P.precisionTo(t+r-h.startX,1),row:h.actualRow,rowOffset:P.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:m,skewY:l,from:g,to:f}}var yt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,Rt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Mt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&yt(n,t,r),r},ge=(i,n)=>(t,e)=>n(t,e,i);let Pe=class extends u.Disposable{constructor(i,n,t,e,r){super(),this._context=i,this._sheetDrawingService=n,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const n in i){const t=i[n];for(const e in t.data){const r=t.data[e];r.transform=F(r.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=Rt([ge(1,p.ISheetDrawingService),ge(2,A.IDrawingManagerService),ge(3,u.Inject(N.ISheetSelectionRenderService)),ge(4,u.Inject(N.SheetSkeletonManagerService))],Pe);function Tt(i){const n=[];return i.forEach(t=>{const{parent:e,children:r}=t,{unitId:o,subUnitId:s,drawingId:c}=e,d=P.getGroupState(0,0,r.map(a=>a.transform||{})),m=r.map(a=>{const g=a.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=a;return{unitId:h,subUnitId:f,drawingId:w,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:u.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:m})}),n}function bt(i){const n=[];return i.forEach(t=>{const{parent:e,children:r}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const m=r.map(a=>{const{transform:g}=a,{unitId:h,subUnitId:f,drawingId:w}=a,S=P.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:u.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:m})}),n}const Le={id:"sheet.command.group-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=r.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:c,subUnitId:d,objects:bt(a),type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{var y,C,T;const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!n)return!1;const s=n.drawings,c=s.map(I=>I.unitId),d=r.getBatchAddOp(s),{unitId:m,subUnitId:l,undo:a,redo:g,objects:h}=d,f=o.onCommandExecute({id:ce.id,params:n}),w={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:m,subUnitId:l,objects:h,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:m,subUnitId:l,objects:h,type:p.DrawingApplyType.REMOVE}};return u.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:m,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},xe={id:"sheet.command.set-drawing-arrange",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService);if(!n)return!1;const r=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,m={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===u.ArrangeTypeEnum.forward?l=r.getForwardDrawingsOp(m):d===u.ArrangeTypeEnum.backward?l=r.getBackwardDrawingOp(m):d===u.ArrangeTypeEnum.front?l=r.getFrontDrawingsOp(m):d===u.ArrangeTypeEnum.back&&(l=r.getBackDrawingsOp(m)),l==null)return!1;const{objects:a,redo:g,undo:h}=l;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=r.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:m,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}]}),!0):!1}},Be={id:"sheet.command.ungroup-sheet-image",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),r=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=r.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:m,redo:l,objects:a}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:c,subUnitId:d,objects:Tt(a),type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}]}),!0):!1}};var Et=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,At=(i,n,t,e)=>{for(var r=e>1?void 0:e?Ot(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Et(n,t,r),r},X=(i,n)=>(t,e)=>n(t,e,i);function Pt(i,n,t){const e=t*Math.PI/180,r=Math.abs(i*Math.cos(e))+Math.abs(n*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(n*Math.cos(e));return{rotatedWidth:r,rotatedHeight:o}}function Qe(i,n,t,e,r){var y;const{rotatedHeight:o,rotatedWidth:s}=Pt(t,e,r),d=i.get(P.IRenderManagerService).getRenderById(n.unitId);if(!d)return!1;const l=(y=d.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(n.subUnitId))==null?void 0:y.skeleton;if(l==null)return!1;const a=l.getCellByIndex(n.row,n.col),g=a.mergeInfo.endX-a.mergeInfo.startX-2,h=a.mergeInfo.endY-a.mergeInfo.startY-2,f=s/o,S=Math.ceil(Math.min(g,h*f))/s,D=!S||Number.isNaN(S)?.001:S;return{width:t*D,height:e*D}}let se=class extends u.Disposable{constructor(n,t,e,r,o,s,c,d,m,l,a,g,h){super();H(this,"_workbookSelections");this._context=n,this._skeletonManagerService=t,this._commandService=e,this._selectionRenderService=r,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=m,this._messageService=l,this._localeService=a,this._injector=h,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const n=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=n.length;return t>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(n.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}async _insertFloatImage(n){let t;try{t=await this._imageIoService.saveImage(n)}catch(y){const C=y.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const e=this._getUnitInfo(),{unitId:r,subUnitId:o}=e,{imageId:s,imageSourceType:c,source:d,base64Cache:m}=t,{width:l,height:a,image:g}=await A.getImageSize(m||""),{width:h,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,g);let w=1;if(l>A.DRAWING_IMAGE_WIDTH_LIMIT||a>A.DRAWING_IMAGE_HEIGHT_LIMIT){const y=A.DRAWING_IMAGE_WIDTH_LIMIT/l,C=A.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,C)}const S=this._getImagePosition(l*w,a*w,h,f);if(S==null)return;const D={unitId:r,subUnitId:o,drawingId:s,drawingType:u.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:F(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(ce.id,{unitId:r,drawings:[D]})}async _insertCellImage(n){let t;try{t=await this._imageIoService.saveImage(n)}catch(S){const D=S.message;D===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const{imageId:e,imageSourceType:r,source:o,base64Cache:s}=t,{width:c,height:d,image:m}=await A.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,r,m);const l=this._workbookSelections.getCurrentLastSelection();if(!l)return!1;const a=u.createDocumentModelWithStyle("",{}),g=Qe(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:l.primary.actualRow,col:l.primary.actualColumn},c,d,0);if(!g)return!1;const h={size:{width:g.width,height:g.height},positionH:{relativeFrom:u.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:u.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:a.getUnitId(),subUnitId:a.getUnitId(),drawingId:e,drawingType:u.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:r,source:o,transform:Je.docDrawingPositionToTransform(h),docTransform:h,behindDoc:u.BooleanNumber.FALSE,title:"",description:"",layoutType:u.PositionedObjectLayoutType.INLINE,wrapText:u.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},w=u.BuildTextUtils.drawing.add({documentDataModel:a,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return w?(a.apply(w),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[l.primary.actualRow]:{[l.primary.actualColumn]:{p:a.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const n=this._context.unit,t=n.getActiveSheet(),e=n.getUnitId(),r=t.getSheetId();return{unitId:e,subUnitId:r}}_getImagePosition(n,t,e,r){const o=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(s=o[o.length-1].range);const c=N.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:m,startX:l,startY:a}=c,g=!1;if(l+n>e&&(l=e-n,l<0&&(l=0,n=e),g=!0),a+t>r&&(a=r-t,a<0&&(a=0,t=r),g=!0),g){const S=this._selectionRenderService.getCellWithCoordByOffset(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,m=S.actualRow}const h={column:d,columnOffset:0,row:m,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(l+n,a+t);if(f==null)return;const w={column:f.actualColumn,columnOffset:l+n-f.startX,row:f.actualRow,rowOffset:a+t-f.startY};return{from:h,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(n=>{const{unitId:t,subUnitId:e,drawingIds:r,arrangeType:o}=n;this._commandService.executeCommand(xe.id,{unitId:t,subUnitId:e,drawingIds:r,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(n=>{const t=[];n.length!==0&&(n.forEach(e=>{const{unitId:r,subUnitId:o,drawingId:s,drawingType:c,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:o,drawingId:s});if(m==null||m.unitId!==this._context.unitId)return;const l=$({...m.transform,...d},this._selectionRenderService);if(l==null)return;const a={...e,transform:{...m.transform,...d,...F(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};t.push(a)}),t.length>0&&this._commandService.executeCommand(de.id,{unitId:n[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Le.id,n);const{unitId:t,subUnitId:e,drawingId:r}=n[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:r}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Be.id,n)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(n=>{n==null||n.length===0?(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(n))}))}};se=At([X(1,u.Inject(N.SheetSkeletonManagerService)),X(2,u.ICommandService),X(3,N.ISheetSelectionRenderService),X(4,A.IImageIoService),X(5,G.ILocalFileService),X(6,p.ISheetDrawingService),X(7,A.IDrawingManagerService),X(8,u.IContextService),X(9,G.IMessageService),X(10,u.Inject(u.LocaleService)),X(11,u.Inject(_.SheetsSelectionsService)),X(12,u.Inject(u.Injector))],se);var Ut=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,jt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Nt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Ut(n,t,r),r},te=(i,n)=>(t,e)=>n(t,e,i);function Ue(i,n,t){var e,r,o,s;if(((r=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:r.dataStream.length)===3&&((s=(o=t.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const c=t.p.drawings[t.p.drawingsOrder[0]],d=Qe(i,{unitId:n.unitId,subUnitId:n.subUnitId,row:n.row,col:n.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(d)return c.transform.width=d.width,c.transform.height=d.height,c.docTransform.size.width=d.width,c.docTransform.size.height=d.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Se=class extends u.Disposable{constructor(i,n,t,e,r,o,s){super(),this._commandService=i,this._sheetInterceptorService=n,this._univerInstanceService=t,this._injector=e,this._drawingManagerService=r,this._docDrawingController=o,this._editorBridgeService=s,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let n,t=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),t=e.rowsAutoHeightInfo.map(r=>({startRow:r.row,endRow:r.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;t=e.ranges,n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}n&&t.length&&t.forEach(e=>{const r=u.Range.transformRange(e,n.worksheet);for(let o=r.startRow;o<=r.endRow;o++)for(let s=r.startColumn;s<=r.endColumn;s++)Ue(this._injector,{unitId:n.unitId,subUnitId:n.subUnitId,row:o,col:s},n.worksheet.getCellRaw(o,s))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Je.ReplaceSnapshotCommand.id&&i.params.unitId===u.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(u.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,n,t)=>(Ue(this._injector,{unitId:n.unitId,subUnitId:n.subUnitId,row:n.row,col:n.col},i),t(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,n,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),t(i)}}))}};Se=jt([te(0,u.ICommandService),te(1,u.Inject(_.SheetInterceptorService)),te(2,u.IUniverInstanceService),te(3,u.Inject(u.Injector)),te(4,A.IDrawingManagerService),te(5,u.Inject(qe.DocDrawingController)),te(6,u.Inject(N.IEditorBridgeService))],Se);var Wt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,xt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Lt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Wt(n,t,r),r},Ke=(i,n)=>(t,e)=>n(t,e,i);let _e=class extends u.Disposable{constructor(i,n){super(),this._autoFillService=i,this._injector=n,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,n,t,e)=>{new u.ObjectMatrix(e).forValue((r,o,s)=>{Ue(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:r,col:o},s)})}}))}};_e=xt([Ke(0,u.Inject(N.IAutoFillService)),Ke(1,u.Inject(u.Injector))],_e);var Bt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Gt=(i,n,t,e)=>{for(var r=e>1?void 0:e?$t(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Bt(n,t,r),r},he=(i,n)=>(t,e)=>n(t,e,i);let ve=class extends u.Disposable{constructor(n,t,e,r){super();H(this,"_isSetCursor",!1);this._hoverManagerService=n,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=r}_initHover(){}_initImageClick(){}};ve=Gt([he(0,u.Inject(N.HoverManagerService)),he(1,u.Inject(P.IRenderManagerService)),he(2,u.Inject(_.SheetsSelectionsService)),he(3,u.Inject(Q.DrawingRenderService))],ve);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ht=(i,n,t,e)=>{for(var r=e>1?void 0:e?Ft(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&kt(n,t,r),r},Ee=(i,n)=>(t,e)=>n(t,e,i);let Ie=class extends u.Disposable{constructor(n,t,e){super();H(this,"_copyInfo");this._sheetClipboardService=n,this._renderManagerService=t,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(n,t,e)=>this._collect(n,t,e),onPasteCells:(n,t,e,r)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:s}=r,{range:c}=n||{},{range:d,unitId:m,subUnitId:l}=t;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:c,unitId:m,subUnitId:l})},onPastePlainText:(n,t)=>({undos:[],redos:[]})})}_collect(n,t,e){var g;const r=(g=this._renderManagerService.getRenderById(n))==null?void 0:g.with(N.SheetSkeletonManagerService);if(!r)return;const o=r.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:c,startY:d,endY:m}=o,l=this._sheetDrawingService.getDrawingData(n,t),a=[];Object.keys(l).forEach(h=>{const f=l[h],{transform:w}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:D=0,width:y=0,height:C=0}=w,{drawingStartX:T,drawingEndX:I,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:D,drawingEndY:D+C};s<=T&&I<=c&&d<=M&&v<=m&&a.push(f)}),a.length&&(this._copyInfo={drawings:a,unitId:n,subUnitId:t})}_generateMutations(n,t){var b;if(!this._copyInfo)return{redos:[],undos:[]};if([N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};const{copyRange:e}=t;if(!e)return{redos:[],undos:[]};const{drawings:r,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[c,d],mapFunc:m}=N.virtualizeDiscreteRanges([e,n]),{row:l,col:a}=m(c.startRow,c.startColumn),{row:g,col:h}=m(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(N.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const w=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:a,endColumn:a}),S=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:h,endColumn:h});if(!w||!S)return{redos:[],undos:[]};const D=[],y=[],C=S.startX-w.startX,T=S.startY-w.startY,I=g-l,M=h-a,v=t.copyType===N.COPY_TYPE.CUT,{_sheetDrawingService:O}=this;return r.forEach(j=>{const{transform:U,sheetTransform:E}=j;if(!U)return;const R={...j,unitId:o,subUnitId:s,drawingId:v?j.drawingId:u.Tools.generateRandomId(),transform:{...U,left:U.left+C,top:U.top+T},sheetTransform:{to:{...E.to,row:E.to.row+I,column:E.to.column+M},from:{...E.from,row:E.from.row+I,column:E.from.column+M}}};if(v){const{undo:W,redo:B,objects:q}=O.getBatchUpdateOp([R]);D.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:B,objects:q}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:W,objects:q}})}else{const{undo:W,redo:B,objects:q}=O.getBatchAddOp([R]);D.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:s,objects:q,type:p.DrawingApplyType.REMOVE}})}}),{redos:D,undos:y}}};Ie=Ht([Ee(0,N.ISheetClipboardService),Ee(1,P.IRenderManagerService),Ee(2,p.ISheetDrawingService)],Ie);var Vt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Xt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Yt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Vt(n,t,r),r},oe=(i,n)=>(t,e)=>n(t,e,i);let De=class extends u.Disposable{constructor(i,n,t,e,r){super(),this._drawingManagerService=i,this._renderManagerService=n,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=r,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const r=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=n.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(c,d),l=Object.values(m),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===P.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const r=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=n.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(c,d),l=Object.values(m),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===P.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const r=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(r),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookViewPermission(r).id,new _.WorksheetViewPermission(r,o).id]).pipe(L.map(g=>g.every(h=>h.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(r,o),w=Object.values(f);g?this._drawingManagerService.addNotification(w):(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.removeObject(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(r,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(r,o),h=Object.values(g);this._drawingManagerService.addNotification(h)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,t])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const r=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(r),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookEditablePermission(r).id,new _.WorksheetEditPermission(r,o).id]).pipe(L.map(g=>g.every(h=>h.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(r,o),w=Object.values(f);g?(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(h.forEach(S=>{S.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.detachTransformerFrom(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(r,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=n.getUnitId(),h=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,h),w=Object.values(f),S=this._renderManagerService.getRenderById(g),D=S==null?void 0:S.scene;if(D==null)return;this._drawingManagerService.setDrawingEditable(!0),D.getAllObjectsByOrder().forEach(C=>{C.classType===P.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>C.oKey.includes(T.drawingId))&&D.detachTransformerFrom(C)})}})})}))}};De=Xt([oe(0,A.IDrawingManagerService),oe(1,P.IRenderManagerService),oe(2,u.IPermissionService),oe(3,u.IUniverInstanceService),oe(4,u.Inject(u.UserManagerService))],De);var zt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,qt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Kt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&zt(n,t,r),r},me=(i,n)=>(t,e)=>n(t,e,i);let Ce=class extends u.Disposable{constructor(i,n,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=n,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,n,t)=>{const{unitId:e,scene:r,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],r)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,n,t)=>{const{unitId:e,subUnitId:r}=n,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r);if(!s)return t(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[n.subUnitId];if(!d)return t(i);const{scaleX:m,scaleY:l}=o.scene,a=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==u.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(h=>{if(!h.groupId&&h.transform&&u.Tools.isDefine(h.transform.left)&&u.Tools.isDefine(h.transform.top)&&u.Tools.isDefine(h.transform.width)&&u.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,m,l,{x:0,y:0}),w=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,m,l,{x:0,y:0});f.column<a.startColumn&&(a.startColumn=f.column),f.row<a.startRow&&(a.startRow=f.row),a.endRow<w.row&&(a.endRow=w.row),a.endColumn<w.column&&(a.endColumn=w.column)}}),t(a)):t(i)}}))}};Ce=qt([me(0,u.Inject(N.SheetPrintInterceptorService)),me(1,u.Inject(Q.DrawingRenderService)),me(2,A.IDrawingManagerService),me(3,P.IRenderManagerService)],Ce);var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Qt=(i,n,t,e)=>{for(var r=e>1?void 0:e?Zt(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Jt(n,t,r),r},J=(i,n)=>(t,e)=>n(t,e,i);const en=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],tn=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Ne=class extends u.Disposable{constructor(i,n,t,e,r,o,s,c,d){super(),this._context=i,this._renderManagerService=n,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=r,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!en.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(n))return this._moveRangeInterceptor(i.params);if(n===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===_.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(n===_.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(n===_.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(n===_.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(n===_.SetRowHiddenCommand.id||n===_.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,r,o)}else if(n===_.SetSpecificColsVisibleCommand.id||n===_.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t;return this._getDrawingUndoForColVisible(e,r,o)}else if(n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id||n===_.DeltaColumnWidthCommand.id||n===_.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:r,ranges:o}=t,s=n===_.DeltaRowHeightCommand.id||n===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,r,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,r=t.subUnitId,o=[],s=[],c=this._sheetDrawingService.getDrawingData(e,r),d=[],m=[];if(Object.keys(c).forEach(l=>{const a=c[l],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,n,a);d.push(...g),m.push(...h)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:g,objects:h}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:a,objects:h,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(m),a=l.undo,g=l.redo,h=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:a,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:x.id,params:[e]}),s.push({id:x.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,n,t){const e=[],r=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:m,drawingId:l}=t,{from:a,to:g}=o,{row:h,column:f}=a,{row:w,column:S}=g;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:r};const{startRow:D,endRow:y,startColumn:C,endColumn:T}=i;let I=null,M=null;if(n===0&&h>=D&&w<=y)if(f>=C&&S<=T)r.push({unitId:d,subUnitId:m,drawingId:l});else{const v=this._shrinkCol(o,c,C,T,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===1&&f>=C&&S<=T)if(h>=D&&w<=y)r.push({unitId:d,subUnitId:m,drawingId:l});else{const v=this._shrinkRow(o,c,D,y,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===2){const v=this._expandRow(o,c,D,y,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===3){const v=this._expandCol(o,c,C,T,s);I=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(I!=null&&M!=null){const v=F(I,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:I,transform:v})}return{updateDrawings:e,deleteDrawings:r}}_remainDrawingSize(i,n,t){const e=$({...i},this._selectionRenderService);e!=null&&n.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,a);else{const{from:w,to:S}=g,{row:D,column:y}=w,{row:C,column:T}=S;for(let I=0;I<t.length;I++){const M=t[I],{startRow:v,endRow:O,startColumn:b,endColumn:j}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=b&&y<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(B==null)return;W={...h,left:B.startX}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){r.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,r,a);continue}if(y>=b&&T<=j)continue;let U=null,E=null;if(y>=b&&y<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;E={...h,left:(R==null?void 0:R.startX)||0,width:((h==null?void 0:h.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(R==null)return;E={...h,left:R.startX-((h==null?void 0:h.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;if(E={...h,width:((h==null?void 0:h.width)||0)-R.endX+R.startX},U=$(E,this._selectionRenderService),U!=null&&E!=null){o.push({...a,sheetTransform:U,transform:E});break}}if(E!=null&&(U=$(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...a,sheetTransform:U,transform:E});break}else this._remainDrawingSize(h,r,a)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,r),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,n,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:r,redo:o,objects:s}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:r,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,r,a);else{const{from:w,to:S}=g,{row:D,column:y}=w,{row:C,column:T}=S;for(let I=0;I<t.length;I++){const M=t[I],{startRow:v,endRow:O,startColumn:b,endColumn:j}=M;if(C<v)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(D>=v&&D<=O){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:O});if(B==null)return;W={...h,top:B.startY}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){r.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,r,a);continue}if(D>=v&&C<=O)continue;let U=null,E=null;if(D>=v&&D<=O){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:O});if(R==null)return;E={...h,top:(R==null?void 0:R.startY)||0,height:((h==null?void 0:h.height)||0)-R.endY+R.startY}}else if(C>=v&&C<=O){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(R==null)return;E={...h,top:R.startY-((h==null?void 0:h.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:O});if(R==null)return;if(E={...h,height:((h==null?void 0:h.height)||0)-R.endY+R.startY},U=$(E,this._selectionRenderService),U!=null&&E!=null){o.push({...a,sheetTransform:U,transform:E});break}}if(E!=null&&(U=$(E,this._selectionRenderService)),E!=null&&U!=null){r.push({...a,sheetTransform:U,transform:E});break}else this._remainDrawingSize(h,r,a)}}}),r.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,r),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,n,t,e){const r=this._drawingManagerService.getDrawingData(i,n),o=[];return Object.keys(r).forEach(s=>{const c=r[s],{sheetTransform:d,transform:m,anchorType:l=p.SheetDrawingAnchorType.Position}=c;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,c);else{const{from:a,to:g}=d,{row:h,column:f}=a,{row:w,column:S}=g;for(let D=0;D<t.length;D++){const y=t[D],{startRow:C,endRow:T,startColumn:I,endColumn:M}=y;if(w<C||S<I)continue;if(l===p.SheetDrawingAnchorType.Position&&(h<=C&&w>=T||f<=I&&S>=M)){this._remainDrawingSize(m,o,c);continue}const v=F({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...c,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,n,o)}_getUnitIdAndSubUnitId(i,n){let t,e;if(n==="insert")t=i.unitId,e=i.subUnitId;else{const r=_.getSheetCommandTarget(this._univerInstanceService);if(r==null)return;t=r.unitId,e=r.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:n,fromRange:t}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:r,subUnitId:o}=e,s=(T=(C=this._renderManagerService.getRenderById(r))==null?void 0:C.with(N.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=N.attachRangeWithCoord(s,t);if(!c)return{redos:[],undos:[]};const{startX:d,endX:m,startY:l,endY:a}=c,g=this._sheetDrawingService.getDrawingData(r,o),h=[];Object.keys(g).forEach(I=>{const M=g[I];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:O=0,top:b=0,width:j=0,height:U=0}=v,{drawingStartX:E,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:O,drawingEndX:O+j,drawingStartY:b,drawingEndY:b+U};d<=E&&R<=m&&l<=W&&B<=a&&h.push(M)});const f=[],w=[],S=n.startRow-t.startRow,D=n.startColumn-t.startColumn,y=h.map(I=>{const M=I.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+D},from:{...M.from,row:M.from.row+S,column:M.from.column+D}},O=F(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:r,subUnitId:o,drawingId:I.drawingId,transform:O,sheetTransform:v}});if(y.length){const I=this._sheetDrawingService.getBatchUpdateOp(y),{undo:M,redo:v,objects:O}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:o,op:v,objects:O,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:o,op:M,objects:O,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,n){const t=this._getUnitIdAndSubUnitId(i,n);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:r}=t,{range:o}=i,s=o.startRow,c=o.endRow,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,r),a=[],g=[];if(Object.keys(l).forEach(h=>{const f=l[h],{sheetTransform:w,transform:S,anchorType:D=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(n==="insert"){const I=this._expandRow(w,S,s,c,D);y=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:M}=w,{row:v}=I,{row:O}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&O<=c)g.push({unitId:e,subUnitId:r,drawingId:h});else{const b=this._shrinkRow(w,S,s,c,D);y=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:r,drawingId:h,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),m.push({id:x.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(i,n){const t=this._getUnitIdAndSubUnitId(i,n);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:r}=t,{range:o}=i,s=o.startColumn,c=o.endColumn,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,r),a=[],g=[];if(Object.keys(l).forEach(h=>{const f=l[h],{sheetTransform:w,transform:S,anchorType:D=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(n==="insert"){const I=this._expandCol(w,S,s,c,D);y=I==null?void 0:I.newSheetTransform,C=I==null?void 0:I.newTransform}else{const{from:I,to:M}=w,{column:v}=I,{column:O}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&O<=c)g.push({unitId:e,subUnitId:r,drawingId:h});else{const b=this._shrinkCol(w,S,s,c,D);y=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!y||!C)return;const T={unitId:e,subUnitId:r,drawingId:h,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,w=h.redo,S=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:r,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),m.push({id:x.id,params:[e]}),{redos:d,undos:m}}_expandCol(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:c.row});if(g==null)return;a={...n,left:(n.left||0)+g.endX-g.startX},l=$(a,this._selectionRenderService)}else if(m>=e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkCol(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,column:d-o},to:{...c,column:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=t&&d<=e){if(d===t)a={...n,left:(n.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:c.row});if(g==null)return;a={...n,left:(n.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:c.row});if(g==null)return;l={from:{...s},to:{...c,column:t-1,columnOffset:g.endX-g.startX}},a=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_expandRow(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...n,top:(n.top||0)+g.endY-g.startY},l=$(a,this._selectionRenderService)}else if(m>=e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkRow(i,n,t,e,r=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(r===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,row:d-o},to:{...c,row:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(r===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=t&&d<=e){if(d===t)a={...n,top:(n.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...n,top:(n.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&r===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(g==null)return;l={from:{...s},to:{...c,row:t-1,rowOffset:g.endY-g.startY}},a=F(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const n=i.params,{unitId:t,subUnitId:e}=n,r=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(r).forEach(c=>{const d=r[c];d!=null&&Object.keys(d).forEach(m=>{const l=d[m].data;l!=null&&Object.keys(l).forEach(a=>{if(c===t&&m===e){const g=l[a];g.transform=F(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[a])}else s.push(l[a])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{tn.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:t,subUnitId:e,ranges:r}=n;this._refreshDrawingTransform(t,e,r)})}))}_refreshDrawingTransform(i,n,t){const e=this._drawingManagerService.getDrawingData(i,n),r=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:c,transform:d,anchorType:m=p.SheetDrawingAnchorType.Position}=s;if(m===p.SheetDrawingAnchorType.None)return!0;const{from:l,to:a}=c,{row:g,column:h}=l,{row:f,column:w}=a;for(let S=0;S<t.length;S++){const D=t[S],{startRow:y,endRow:C,startColumn:T,endColumn:I}=D;if(u.Rectangle.intersects({startRow:y,endRow:C,startColumn:T,endColumn:I},{startRow:g,endRow:f,startColumn:h,endColumn:w})||g>C||h>I){const M=m===p.SheetDrawingAnchorType.Position,v=F(c,this._selectionRenderService,this._skeletonManagerService);r.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),r.length!==0&&(this._drawingManagerService.refreshTransform(r),this._commandService.syncExecuteCommand(x.id,[i]))}};Ne=Qt([J(1,P.IRenderManagerService),J(2,u.ICommandService),J(3,N.ISheetSelectionRenderService),J(4,u.Inject(N.SheetSkeletonManagerService)),J(5,u.Inject(_.SheetInterceptorService)),J(6,p.ISheetDrawingService),J(7,A.IDrawingManagerService),J(8,u.IUniverInstanceService)],Ne);var z=function(){return z=Object.assign||function(i){for(var n,t=1,e=arguments.length;t<e;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(i[r]=n[r])}return i},z.apply(this,arguments)},nn=function(i,n){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&n.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(i);r<e.length;r++)n.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(i,e[r])&&(t[e[r]]=i[e[r]]);return t},et=Y.forwardRef(function(i,n){var t=i.icon,e=i.id,r=i.className,o=i.extend,s=nn(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),d=Y.useRef("_".concat(sn()));return tt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},z({ref:n,className:c},s),o)});function tt(i,n,t,e,r){return Y.createElement(i.tag,z(z({key:n},rn(i,t,r)),e),(on(i,t).children||[]).map(function(o,s){return tt(o,"".concat(n,"-").concat(i.tag,"-").concat(s),t,void 0,r)}))}function rn(i,n,t){var e=z({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function on(i,n){var t,e=n.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?z(z({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?z(z({},r),{attrs:z(z({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):i}function sn(){return Math.random().toString(36).substring(2,8)}et.displayName="UniverIcon";var an={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"}}]},nt=Y.forwardRef(function(i,n){return Y.createElement(et,Object.assign({},i,{id:"add-image-single",ref:n,icon:an}))});nt.displayName="AddImageSingle";const $e={id:"sheet.command.delete-drawing",type:u.CommandType.COMMAND,handler:i=>{const n=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const r=e[0].unitId,o=e.map(s=>{const{unitId:c,subUnitId:d,drawingId:m,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:m,drawingType:l}});return n.executeCommand(ae.id,{unitId:r,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:u.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(P.IRenderManagerService).getCurrentTypeOfRenderer(u.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(se).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:u.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(P.IRenderManagerService).getCurrentTypeOfRenderer(u.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(se).insertCellImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:u.CommandType.COMMAND,handler:(i,n)=>{const t=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService),r=i.get(N.ISheetSelectionRenderService),{direction:o}=n,s=e.getFocusDrawings();if(s.length===0)return!1;const c=s[0].unitId,d=s.map(l=>{const{transform:a}=l;if(a==null)return null;const g={...a},{left:h=0,top:f=0}=a;return o===u.Direction.UP?g.top=f-1:o===u.Direction.DOWN?g.top=f+1:o===u.Direction.LEFT?g.left=h-1:o===u.Direction.RIGHT&&(g.left=h+1),{...l,transform:g,sheetTransform:$(g,r)}}).filter(l=>l!=null);return t.syncExecuteCommand(de.id,{unitId:c,drawings:d})?(t.syncExecuteCommand(x.id,[c]),!0):!1}},rt="addition-and-subtraction-single",ke="sheet.menu.image";function cn(i){return{id:ke,type:G.MenuItemType.SUBITEMS,icon:rt,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function dn(i){return{id:Me.id,title:"sheetImage.upload.float",type:G.MenuItemType.BUTTON,hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET)}}function ln(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:G.MenuItemType.BUTTON}}const un="univer-image-common-panel",gn="univer-image-common-panel-grid",hn="univer-image-common-panel-border",mn="univer-image-common-panel-title",pn="univer-image-common-panel-subtitle",fn="univer-image-common-panel-row",wn="univer-image-common-panel-row-vertical",Sn="univer-image-common-panel-column",_n="univer-image-common-panel-column-center",vn="univer-image-common-panel-inline",In="univer-image-common-panel-span2",Dn="univer-image-common-panel-span3",Cn="univer-image-common-panel-input",yn="univer-sheet-image-menu",Mn="univer-sheet-image-menu-input",Z={imageCommonPanel:un,imageCommonPanelGrid:gn,imageCommonPanelBorder:hn,imageCommonPanelTitle:mn,imageCommonPanelSubtitle:pn,imageCommonPanelRow:fn,imageCommonPanelRowVertical:wn,imageCommonPanelColumn:Sn,imageCommonPanelColumnCenter:_n,imageCommonPanelInline:vn,imageCommonPanelSpan2:In,imageCommonPanelSpan3:Dn,imageCommonPanelInput:Cn,sheetImageMenu:yn,sheetImageMenuInput:Mn};function it(i){var n,t,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var r=i.length;for(n=0;n<r;n++)i[n]&&(t=it(i[n]))&&(e&&(e+=" "),e+=t)}else for(t in i)i[t]&&(e&&(e+=" "),e+=t);return e}function pe(){for(var i,n,t=0,e="",r=arguments.length;t<r;t++)(i=arguments[t])&&(n=it(i))&&(e&&(e+=" "),e+=n);return e}const Rn=i=>{var C;const n=u.useDependency(u.ICommandService),t=u.useDependency(u.LocaleService),e=u.useDependency(A.IDrawingManagerService),r=u.useDependency(P.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:c}=s,d=r.getRenderById(c),m=d==null?void 0:d.scene;if(m==null)return;const l=m.getTransformerByCreate(),[a,g]=Y.useState(!0),h=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=Y.useState(h);function S(T,I){const M=[];return T.forEach(v=>{const{oKey:O}=v,b=I.getDrawingOKey(O);if(b==null)return M.push(null),!0;const{unitId:j,subUnitId:U,drawingId:E,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:j,subUnitId:U,drawingId:E,anchorType:W,sheetTransform:B,drawingType:R})}),M}Y.useEffect(()=>{const T=l.clearControl$.subscribe(M=>{M===!0&&g(!1)}),I=l.changeStart$.subscribe(M=>{var b;const{objects:v}=M,O=S(v,e);if(O.length===0)g(!1);else if(O.length>=1){g(!0);const j=((b=O[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(j)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function D(T){w(T);const I=e.getFocusDrawings();if(I.length===0)return;const M=I.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));n.executeCommand(de.id,{unitId:I[0].unitId,drawings:M})}const y=T=>T?"block":"none";return k.jsxs("div",{className:pe(Z.imageCommonPanelGrid,Z.imageCommonPanelBorder),style:{display:y(a)},children:[k.jsx("div",{className:Z.imageCommonPanelRow,children:k.jsx("div",{className:pe(Z.imageCommonPanelColumn,Z.imageCommonPanelTitle),children:k.jsx("div",{children:t.t("drawing-anchor.title")})})}),k.jsx("div",{className:pe(Z.imageCommonPanelRow),children:k.jsx("div",{className:pe(Z.imageCommonPanelColumn),children:k.jsxs(K.RadioGroup,{value:f,onChange:D,direction:"vertical",children:[k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),k.jsx(K.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},Tn=()=>{const i=u.useDependency(A.IDrawingManagerService),n=i.getFocusDrawings(),[t,e]=Y.useState(n);return Y.useEffect(()=>{const r=i.focus$.subscribe(o=>{e(o)});return()=>{r.unsubscribe()}},[]),!!(t!=null&&t.length)&&k.jsxs("div",{className:Z.imageCommonPanel,children:[k.jsx(Q.DrawingCommonPanel,{drawings:t}),k.jsx(Rn,{drawings:t})]})},bn={[G.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:cn,[Me.id]:{order:0,menuItemFactory:dn},[Ge.id]:{order:1,menuItemFactory:ln}}}};function le(i){return!i.getContextValue(u.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(u.EDITOR_ACTIVATED)&&!i.getContextValue(u.FOCUSING_PANEL_EDITOR)&&i.getContextValue(u.FOCUSING_COMMON_DRAWINGS)}const En={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:le,staticParameters:{direction:u.Direction.DOWN}},On={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:le,staticParameters:{direction:u.Direction.UP}},An={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:le,staticParameters:{direction:u.Direction.LEFT}},Pn={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:le,staticParameters:{direction:u.Direction.RIGHT}},Un={id:$e.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:le,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var Nn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Wn=(i,n,t,e)=>{for(var r=e>1?void 0:e?jn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Nn(n,t,r),r},fe=(i,n)=>(t,e)=>n(t,e,i);let ye=class extends u.Disposable{constructor(i,n,t,e){super(),this._componentManager=i,this._menuManagerService=n,this._commandService=t,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(rt,nt)),this.disposeWithMe(i.register(Ze,Tn))}_initMenus(){this._menuManagerService.mergeMenu(bn)}_initCommands(){[Me,Ge,ce,ae,de,je,x,We,Le,Be,re,$e,xe].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[En,On,An,Pn,Un].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ye=Wn([fe(0,u.Inject(G.ComponentManager)),fe(1,G.IMenuManagerService),fe(2,u.ICommandService),fe(3,G.IShortcutService)],ye);var Ln=Object.defineProperty,xn=Object.getOwnPropertyDescriptor,Bn=(i,n,t,e)=>{for(var r=e>1?void 0:e?xn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&Ln(n,t,r),r},ne=(i,n)=>(t,e)=>n(t,e,i);function $n(i,n,t,e){const{scaleX:r,scaleY:o}=n.getAncestorScale(),s=n.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...i,absolute:c};const{left:d,right:m,top:l,bottom:a}=i,g=e.getFreeze(),{startColumn:h,startRow:f,xSplit:w,ySplit:S}=g,D=t.getNoMergeCellPositionByIndexWithNoHeader(f-S,h-w),y=t.getNoMergeCellPositionByIndexWithNoHeader(f,h),{rowHeaderWidth:C,columnHeaderHeight:T}=t,I=y.startX-D.startX,M=y.startY-D.startY,{top:v,left:O,viewportScrollX:b,viewportScrollY:j}=s;let U,E;d<O?(c.left=!0,U=(I+C+(d-O))*r,E=Math.max(Math.min((I+C+(m-O))*r,(I+C)*r),(m-b)*r)):(c.left=!1,U=Math.max((d-b)*r,(I+C)*r),E=Math.max((m-b)*r,(I+C)*r));let R,W;return l<v?(c.top=!0,R=(M+T+(l-v))*o,W=Math.max(Math.min((M+T+(m-v))*o,(M+T)*o),(a-j)*o)):(c.top=!1,R=Math.max((l-j)*o,(M+T)*o),W=Math.max((a-j)*o,(M+T)*o)),{left:U,right:E,top:R,bottom:W,absolute:c}}const Oe=(i,n,t,e)=>{const{scene:r}=n,{left:o,top:s,width:c,height:d,angle:m}=i,l={left:o,right:o+c,top:s,bottom:s+d},a=$n(l,r,t,e),{scaleX:g,scaleY:h}=r.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:m,width:c*g,height:d*h,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends u.Disposable{constructor(t,e,r,o,s,c,d){super();H(this,"_domLayerMap",new Map);H(this,"_domLayerInfoMap",new Map);H(this,"_transformChange$",new L.Subject);H(this,"transformChange$",this._transformChange$.asObservable());H(this,"_add$",new L.Subject);H(this,"add$",this._add$.asObservable());H(this,"_remove$",new L.Subject);H(this,"remove$",this._remove$.asObservable());H(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=r,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(L.filter(t=>t===u.LifecycleStages.Rendered),L.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let r=this._domLayerMap.get(t);r||(r=new Map,this._domLayerMap.set(t,r));let o=r.get(e);return o||(o=new Map,r.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),r=e==null?void 0:e.scene;if(e==null||r==null)return null;const o=r.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:r,transformer:o,renderObject:e,canvas:s}}_getFloatDomProps(t){let e;return this._hooks.forEach(r=>{e=r.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var He,Ve,Ye;const{unitId:r,subUnitId:o,drawingId:s}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:r,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(r,u.UniverInstanceType.UNIVER_SHEET);if(!m)return;const l=m.getActiveSheet().getSheetId();if(!d||!c)return;const a=(He=this._renderManagerService.getRenderById(r))==null?void 0:He.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:g,drawingType:h,data:f}=d;if(h!==u.DrawingTypeEnum.DRAWING_DOM&&h!==u.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(r);if(w==null)return;const{scene:S,canvas:D}=w;if(g==null)return!0;if(l!==o)return;const{left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:O,skewX:b,skewY:j}=g,U=A.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),E=S.getObject(U);if(E!=null){E.transformByState({left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:O,skewX:b,skewY:j});return}const R={left:y,top:C,width:T,height:I,zIndex:this._drawingManagerService.getDrawingOrder(r,o).length-1},W=h===u.DrawingTypeEnum.DRAWING_CHART;W&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const B=new P.Rect(U,R);W&&B.setObjectType(P.ObjectType.CHART),S.addObject(B,P.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const q=this._ensureMap(r,o),Re=new u.DisposableCollection,at=Oe(B,w.renderObject,a.skeleton,c.worksheet),Te=new L.BehaviorSubject(at),ct={dispose:Re,rect:B,position$:Te,unitId:r,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Te,id:s,componentKey:d.componentKey,onPointerDown:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{D.dispatchEvent(new PointerEvent(V.type,V))},onWheel:V=>{D.dispatchEvent(new WheelEvent(V.type,V))},props:(Ye=(Ve=q.get(s))==null?void 0:Ve.props)!=null?Ye:this._getFloatDomProps(s),data:f,unitId:r});const Fe=B.onTransformChange$.subscribeEvent(()=>{const V=Oe(B,w.renderObject,a.skeleton,c.worksheet);Te.next(V)});Re.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Fe&&Re.add(Fe),this._domLayerInfoMap.set(s,ct),q.set(s,{...q.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:r,subUnitId:o,drawingId:s}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(r);if(d==null)return;const{transformer:m,scene:l}=d,a=l.getObject(c);a!=null&&a.oKey&&m.clearControlByIds([a==null?void 0:a.oKey])})}))}_scrollUpdateListener(){const t=(e,r)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,r),c=Array.from(s.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:r}),m=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r);!o||!d||!m||c.forEach(a=>{const g=this._domLayerInfoMap.get(a);if(g){const h=Oe(g.rect,o.renderObject,m.skeleton,d.worksheet);g.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.filter(e=>!!e),L.switchMap(e=>e.activeSheet$),L.filter(e=>!!e),L.map(e=>{const r=this._renderManagerService.getRenderById(e.getUnitId());return r?{render:r,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),L.filter(e=>!!e),L.switchMap(e=>u.fromEventSubject(e.render.scene.getViewport(P.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(L.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:r})=>{t(e,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var r,o;if(e.id===N.SetZoomRatioOperation.id){const s=e.params,{unitId:c}=s;Array.from((o=(r=this._domLayerMap.get(c))==null?void 0:r.keys())!=null?o:[]).forEach(m=>{t(c,m)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:s,subUnitId:c}=e.params;t(s,c)}}))}_getPosition(t,e){var h;const{startX:r,endX:o,startY:s,endY:c}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(N.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(r,s);if(m==null)return;const l={column:m.actualColumn,columnOffset:r-m.startX,row:m.actualRow,rowOffset:s-m.startY},a=d.getCellWithCoordByOffset(o,c);if(a==null)return;const g={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const r=this._drawingManagerService.getDrawingByParam(e);if(!r||r.drawingType!==u.DrawingTypeEnum.DRAWING_DOM&&r.drawingType!==u.DrawingTypeEnum.DRAWING_CHART)return;const o={...r.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,r,o){const s=this._domLayerInfoMap.get(r),c=this._getSceneAndTransformerByDrawingSearch(t);if(s&&c){const{scene:d}=c,m=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:r}),l=d.getObject(m);l&&l instanceof P.Rect&&l.setProps(o)}}addFloatDomToPosition(t,e){const r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!r)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=r,{initPosition:c,componentKey:d,data:m,allowTransform:l=!0}=t,a=e!=null?e:u.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,s).set(a,t);const f={unitId:o,subUnitId:s,drawingId:a,drawingType:t.type||u.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:m,allowTransform:l};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:s,id:a}),{id:a,dispose:()=>{this._removeDom(a,!0)}}}_removeDom(t,e=!1){const r=this._domLayerInfoMap.get(t);if(!r)return;const{unitId:o,subUnitId:s}=r;this._domLayerInfoMap.delete(t),r.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(r.rect),e){this._ensureMap(o,s).delete(t);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:t});if(!m)return;const l=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:a,objects:g}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(r=>r===t);this._hooks.splice(e,1)}}}};exports.SheetCanvasFloatDomManagerService=Bn([ne(0,u.Inject(P.IRenderManagerService)),ne(1,u.IUniverInstanceService),ne(2,u.Inject(u.ICommandService)),ne(3,A.IDrawingManagerService),ne(4,u.Inject(G.CanvasFloatDomService)),ne(5,p.ISheetDrawingService),ne(6,u.Inject(u.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var ot=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,kn=(i,n,t)=>n in i?ot(i,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[n]=t,Fn=(i,n,t,e)=>{for(var r=e>1?void 0:e?Gn(n,t):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(e?s(n,t,r):s(r))||r);return e&&r&&ot(n,t,r),r},Ae=(i,n)=>(t,e)=>n(t,e,i),st=(i,n,t)=>kn(i,typeof n!="symbol"?n+"":n,t);const Hn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends u.Plugin{constructor(n=gt,t,e,r){super(),this._config=n,this._injector=t,this._renderManagerService=e,this._configService=r;const{menu:o,...s}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ut,s)}onStarting(){u.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[ye],[we],[Ce],[De],[Ie],[Se],[ve],[_e]]),u.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){u.touchDependencies(this._injector,[[Ie]])}onRendered(){this._registerRenderModules(),u.touchDependencies(this._injector,[[De],[Ce],[ye],[Se],[ve],[_e]])}onSteady(){this._injector.get(we)}_registerRenderModules(){[[se],[Ne],[Pe]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,n))})}};st(exports.UniverSheetsDrawingUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);st(exports.UniverSheetsDrawingUIPlugin,"pluginName",Hn);exports.UniverSheetsDrawingUIPlugin=Fn([u.DependentOn(A.UniverDrawingPlugin,qe.UniverDocsDrawingPlugin,Q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Ae(1,u.Inject(u.Injector)),Ae(2,P.IRenderManagerService),Ae(3,u.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=x;exports.DeleteDrawingsCommand=$e;exports.EditSheetDrawingOperation=We;exports.GroupSheetDrawingCommand=Le;exports.InsertFloatImageCommand=Me;exports.InsertSheetDrawingCommand=ce;exports.MoveDrawingsCommand=re;exports.RemoveSheetDrawingCommand=ae;exports.SHEETS_IMAGE_MENU_ID=ke;exports.SetDrawingArrangeCommand=xe;exports.SetSheetDrawingCommand=de;exports.SidebarSheetDrawingOperation=je;exports.UngroupSheetDrawingCommand=Be;
|