@univerjs/sheets-drawing-ui 0.5.1-nightly.202412031606 → 0.5.1-nightly.202412041606
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 +38 -34
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var dt=Object.defineProperty;var lt=(i,
|
|
1
|
+
"use strict";var dt=Object.defineProperty;var lt=(i,r,t)=>r in i?dt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var H=(i,r,t)=>lt(i,typeof r!="symbol"?r+"":r,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"),U=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,r)=>{const t=i.get(U.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ae={id:"sheet.command.remove-sheet-image",type:u.CommandType.COMMAND,handler:(i,r)=>{var y,C,T;const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),n=i.get(_.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,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=n.onCommandExecute({id:ae.id,params:r}),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,r)=>{const t=i.get(G.ISidebarService),e=i.get(u.LocaleService),n=i.get(u.IUniverInstanceService),o=i.get(A.IDrawingManagerService);if(!_.getSheetCommandTarget(n))return!1;switch(r.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,r)=>{const t=i.get(A.IDrawingManagerService),e=i.get(u.ICommandService);return r==null?!1:(t.focusDrawing([r]),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 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;
|
|
9
|
+
*/var Xe;function ht(){if(Xe)return ie;Xe=1;var i=Y,r=Symbol.for("react.element"),t=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,n=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:r,type:c,key:g,ref:h,props:a,_owner:n.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),r=u.useDependency(u.LocaleService),[t,e]=Y.useState(0);return Y.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.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:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var It=Object.defineProperty,Dt=Object.getOwnPropertyDescriptor,Ct=(i,r,t,e)=>{for(var n=e>1?void 0:e?Dt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&It(r,t,n),n},ee=(i,r)=>(t,e)=>r(t,e,i);let we=class extends u.RxDisposable{constructor(r,t,e,n,o,s,c){super();H(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,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(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(u.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>u.connectInjector(vt,this._injector))}_dispose(r){const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof Q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const t=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(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){n==null||n.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;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(l,a,g,h);n=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(()=>{n==null||n.dispose(),this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[u.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:We.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:Q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:Q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===u.DrawingTypeEnum.DRAWING_DOM}]}};we=Ct([ee(0,u.Inject(u.Injector)),ee(1,A.IDrawingManagerService),ee(2,u.Inject(N.SheetCanvasPopManagerService)),ee(3,U.IRenderManagerService),ee(4,u.IUniverInstanceService),ee(5,u.IContextService),ee(6,u.Inject(G.IUIPartsService))],we);function F(i,r,t){const{from:e,to:n,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}=n,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=U.precisionTo(I+a,1),j=U.precisionTo(M+h,1),P=U.precisionTo(v+w-b,1),E=U.precisionTo(O+D-j,1);C.startX===T.endX&&(P=0),C.startY===T.endY&&(E=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return b+P>R&&(b=R-P),j+E>W&&(j=W-E),{flipY:o,flipX:s,angle:c,skewX:d,skewY:m,left:b,top:j,width:P,height:E}}function $(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:s=!1,flipX:c=!1,angle:d=0,skewX:m=0,skewY:l=0}=i,a=r.getCellWithCoordByOffset(t,e);if(a==null)return;const g={column:a.actualColumn,columnOffset:U.precisionTo(t-a.startX,1),row:a.actualRow,rowOffset:U.precisionTo(e-a.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:U.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:U.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,r,t,e)=>{for(var n=e>1?void 0:e?Mt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&yt(r,t,n),n},ge=(i,r)=>(t,e)=>r(t,e,i);let Ue=class extends u.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=F(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Ue=Rt([ge(1,p.ISheetDrawingService),ge(2,A.IDrawingManagerService),ge(3,u.Inject(N.ISheetSelectionRenderService)),ge(4,u.Inject(N.SheetSkeletonManagerService))],Ue);function Tt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:c}=e,d=U.getGroupState(0,0,n.map(a=>a.transform||{})),m=n.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};r.push({parent:l,children:m})}),r}function bt(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const m=n.map(a=>{const{transform:g}=a,{unitId:h,subUnitId:f,drawingId:w}=a,S=U.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}};r.push({parent:l,children:m})}),r}const Le={id:"sheet.command.group-sheet-image",type:u.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=n.getGroupDrawingOp(r),{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,r)=>{var y,C,T;const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),n=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const s=r.drawings,c=s.map(I=>I.unitId),d=n.getBatchAddOp(s),{unitId:m,subUnitId:l,undo:a,redo:g,objects:h}=d,f=o.onCommandExecute({id:ce.id,params:r}),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,r)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService);if(!r)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=r,m={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===u.ArrangeTypeEnum.forward?l=n.getForwardDrawingsOp(m):d===u.ArrangeTypeEnum.backward?l=n.getBackwardDrawingOp(m):d===u.ArrangeTypeEnum.front?l=n.getFrontDrawingsOp(m):d===u.ArrangeTypeEnum.back&&(l=n.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,r)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,s=n.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,r)=>{const t=i.get(u.ICommandService),e=i.get(u.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=n.getUngroupDrawingOp(r),{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,r,t,e)=>{for(var n=e>1?void 0:e?Ot(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Et(r,t,n),n},X=(i,r)=>(t,e)=>r(t,e,i);function Ut(i,r,t){const e=t*Math.PI/180,n=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:o}}function Qe(i,r,t,e,n){var y;const{rotatedHeight:o,rotatedWidth:s}=Ut(t,e,n),d=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const l=(y=d.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:y.skeleton;if(l==null)return!1;const a=l.getCellByIndex(r.row,r.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(r,t,e,n,o,s,c,d,m,l,a,g,h){super();H(this,"_workbookSelections");this._context=r,this._skeletonManagerService=t,this._commandService=e,this._selectionRenderService=n,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 r=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=r.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:(r.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(r){let t;try{t=await this._imageIoService.saveImage(r)}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:n,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:n,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:n,drawings:[D]})}async _insertCellImage(r){let t;try{t=await this._imageIoService.saveImage(r)}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:n,source:o,base64Cache:s}=t,{width:c,height:d,image:m}=await A.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,n,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:n,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 r=this._context.unit,t=r.getActiveSheet(),e=r.getUnitId(),n=t.getSheetId();return{unitId:e,subUnitId:n}}_getImagePosition(r,t,e,n){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+r>e&&(l=e-r,l<0&&(l=0,r=e),g=!0),a+t>n&&(a=n-t,a<0&&(a=0,t=n),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+r,a+t);if(f==null)return;const w={column:f.actualColumn,columnOffset:l+r-f.startX,row:f.actualRow,rowOffset:a+t-f.startY};return{from:h,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:o}=r;this._commandService.executeCommand(xe.id,{unitId:t,subUnitId:e,drawingIds:n,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const t=[];r.length!==0&&(r.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:s,drawingType:c,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:n,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:r[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Le.id,r);const{unitId:t,subUnitId:e,drawingId:n}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:t,subUnitId:e,drawingId:n}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Be.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};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 Pt=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,jt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Nt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Pt(r,t,n),n},te=(i,r)=>(t,e)=>r(t,e,i);function Pe(i,r,t){var e,n,o,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.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:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.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,r,t,e,n,o,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=t,this._injector=e,this._drawingManagerService=n,this._docDrawingController=o,this._editorBridgeService=s,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,t=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),t=e.rowsAutoHeightInfo.map(n=>({startRow:n.row,endRow:n.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;t=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&t.length&&t.forEach(e=>{const n=u.Range.transformRange(e,r.worksheet);for(let o=n.startRow;o<=n.endRow;o++)for(let s=n.startColumn;s<=n.endColumn;s++)Pe(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:s},r.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,r,t)=>(Pe(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),t(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,t)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),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,r,t,e)=>{for(var n=e>1?void 0:e?Lt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Wt(r,t,n),n},Ke=(i,r)=>(t,e)=>r(t,e,i);let _e=class extends u.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new u.ObjectMatrix(e).forValue((n,o,s)=>{Pe(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,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,r,t,e)=>{for(var n=e>1?void 0:e?$t(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Bt(r,t,n),n},he=(i,r)=>(t,e)=>r(t,e,i);let ve=class extends u.Disposable{constructor(r,t,e,n){super();H(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};ve=Gt([he(0,u.Inject(N.HoverManagerService)),he(1,u.Inject(U.IRenderManagerService)),he(2,u.Inject(_.SheetsSelectionsService)),he(3,u.Inject(Q.DrawingRenderService))],ve);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ht=(i,r,t,e)=>{for(var n=e>1?void 0:e?Ft(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&kt(r,t,n),n},Ee=(i,r)=>(t,e)=>r(t,e,i);let Ie=class extends u.Disposable{constructor(r,t,e){super();H(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e)=>this._collect(r,t,e),onPasteCells:(r,t,e,n)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:s}=n,{range:c}=r||{},{range:d,unitId:m,subUnitId:l}=t;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:c,unitId:m,subUnitId:l})},onPastePlainText:(r,t)=>({undos:[],redos:[]})})}_collect(r,t,e){var g;const n=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(N.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:c,startY:d,endY:m}=o,l=this._sheetDrawingService.getDrawingData(r,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:r,subUnitId:t})}_generateMutations(r,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:n,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[c,d],mapFunc:m}=N.virtualizeDiscreteRanges([e,r]),{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 n.forEach(j=>{const{transform:P,sheetTransform:E}=j;if(!P)return;const R={...j,unitId:o,subUnitId:s,drawingId:v?j.drawingId:u.Tools.generateRandomId(),transform:{...P,left:P.left+C,top:P.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,U.IRenderManagerService),Ee(2,p.ISheetDrawingService)],Ie);var Vt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Xt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Yt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Vt(r,t,n),n},oe=(i,r)=>(t,e)=>r(t,e,i);let De=class extends u.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const n=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(n).id,new _.WorksheetViewPermission(n,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.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===U.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(([r,t])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const n=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(n).id,new _.WorksheetEditPermission(n,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.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===U.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(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var a;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(n),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookViewPermission(n).id,new _.WorksheetViewPermission(n,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(n,o),w=Object.values(f);g?this._drawingManagerService.addNotification(w):(h.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.removeObject(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(n,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(n,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(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var a;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(n),d=c==null?void 0:c.scene;if(d==null)return;const m=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new _.WorkbookEditablePermission(n).id,new _.WorksheetEditPermission(n,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(n,o),w=Object.values(f);g?(h.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(h.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.detachTransformerFrom(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(n,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=r.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===U.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>C.oKey.includes(T.drawingId))&&D.detachTransformerFrom(C)})}})})}))}};De=Xt([oe(0,A.IDrawingManagerService),oe(1,U.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,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&zt(r,t,n),n},me=(i,r)=>(t,e)=>r(t,e,i);let Ce=class extends u.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(n);if(!s)return t(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[r.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,U.IRenderManagerService)],Ce);var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Qt=(i,r,t,e)=>{for(var n=e>1?void 0:e?Zt(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Jt(r,t,n),n},J=(i,r)=>(t,e)=>r(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,r,t,e,n,o,s,c,d){super(),this._context=i,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,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 r=i.id;if(r===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===_.DeleteRangeMoveLeftCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:t}=i.params;return this._getRangeMoveUndo(t,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForRowVisible(e,n,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t;return this._getDrawingUndoForColVisible(e,n,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const t=i.params,{unitId:e,subUnitId:n,ranges:o}=t,s=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,o=[],s=[],c=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(c).forEach(l=>{const a=c[l],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,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:n,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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:n,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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,r,t){const e=[],n=[],{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:n};const{startRow:D,endRow:y,startColumn:C,endColumn:T}=i;let I=null,M=null;if(r===0&&h>=D&&w<=y)if(f>=C&&S<=T)n.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(r===1&&f>=C&&S<=T)if(h>=D&&w<=y)n.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(r===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(r===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:n}}_remainDrawingSize(i,r,t){const e=$({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,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)){n.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,n,a);continue}if(y>=b&&T<=j)continue;let P=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},P=$(E,this._selectionRenderService),P!=null&&E!=null){o.push({...a,sheetTransform:P,transform:E});break}}if(E!=null&&(P=$(E,this._selectionRenderService)),E!=null&&P!=null){n.push({...a,sheetTransform:P,transform:E});break}else this._remainDrawingSize(h,n,a)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,r,n),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:s}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],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,n,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)){n.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(h,n,a);continue}if(D>=v&&C<=O)continue;let P=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},P=$(E,this._selectionRenderService),P!=null&&E!=null){o.push({...a,sheetTransform:P,transform:E});break}}if(E!=null&&(P=$(E,this._selectionRenderService)),E!=null&&P!=null){n.push({...a,sheetTransform:P,transform:E});break}else this._remainDrawingSize(h,n,a)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,r,n),d=[],m=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,r,o);d.push(...l),m.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const c=n[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,r,o)}_getUnitIdAndSubUnitId(i,r){let t,e;if(r==="insert")t=i.unitId,e=i.subUnitId;else{const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(i){var C,T;const{toRange:r,fromRange:t}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,s=(T=(C=this._renderManagerService.getRenderById(n))==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(n,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:P=0}=v,{drawingStartX:E,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:O,drawingEndX:O+j,drawingStartY:b,drawingEndY:b+P};d<=E&&R<=m&&l<=W&&B<=a&&h.push(M)});const f=[],w=[],S=r.startRow-t.startRow,D=r.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:n,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:n,subUnitId:o,op:v,objects:O,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:O,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,s=o.startRow,c=o.endRow,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,n),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(r==="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:n,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:n,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:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,s=o.startColumn,c=o.endColumn,d=[],m=[],l=this._sheetDrawingService.getDrawingData(e,n),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(r==="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:n,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:n,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:n,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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:n,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,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,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};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={...r,left:(r.left||0)+g.endX-g.startX},l=$(a,this._selectionRenderService)}else if(m>=e)if(n===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{column:d}=s,{column:m}=c;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};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(n===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)a={...r,left:(r.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={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===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,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};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={...r,top:(r.top||0)+g.endY-g.startY},l=$(a,this._selectionRenderService)}else if(m>=e)if(n===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m+o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:c}=i,{row:d}=s,{row:m}=c;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};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(n===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:m-o}},a=F(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)a={...r,top:(r.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={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===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 r=i.params,{unitId:t,subUnitId:e}=r,n=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(n).forEach(c=>{const d=n[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 r=i.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(e).forEach(o=>{const 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);n.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}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(x.id,[i]))}};Ne=Qt([J(1,U.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 r,t=1,e=arguments.length;t<e;t++){r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(i[n]=r[n])}return i},z.apply(this,arguments)},nn=function(i,r){var t={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(t[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,e=Object.getOwnPropertySymbols(i);n<e.length;n++)r.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(i,e[n])&&(t[e[n]]=i[e[n]]);return t},et=Y.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=nn(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=Y.useRef("_".concat(sn()));return tt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},z({ref:r,className:c},s),o)});function tt(i,r,t,e,n){return Y.createElement(i.tag,z(z({key:r},rn(i,t,n)),e),(on(i,t).children||[]).map(function(o,s){return tt(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function rn(i,r,t){var e=z({},i.attrs);t!=null&&t.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=t.colorChannel1);var n=r.defIds;return!n||n.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function on(i,r){var t,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((t=i.children)===null||t===void 0)&&t.length)?z(z({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?z(z({},n),{attrs:z(z({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):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,r){return Y.createElement(et,Object.assign({},i,{id:"add-image-single",ref:r,icon:an}))});nt.displayName="AddImageSingle";const $e={id:"sheet.command.delete-drawing",type:u.CommandType.COMMAND,handler:i=>{const r=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=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 r.executeCommand(ae.id,{unitId:n,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:u.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(U.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(U.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,r)=>{const t=i.get(u.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(N.ISheetSelectionRenderService),{direction:o}=r,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,n)}}).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 r,t,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var n=i.length;for(r=0;r<n;r++)i[r]&&(t=it(i[r]))&&(e&&(e+=" "),e+=t)}else for(t in i)i[t]&&(e&&(e+=" "),e+=t);return e}function pe(){for(var i,r,t=0,e="",n=arguments.length;t<n;t++)(i=arguments[t])&&(r=it(i))&&(e&&(e+=" "),e+=r);return e}const Rn=i=>{var C;const r=u.useDependency(u.ICommandService),t=u.useDependency(u.LocaleService),e=u.useDependency(A.IDrawingManagerService),n=u.useDependency(U.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:c}=s,d=n.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:P,drawingId:E,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:j,subUnitId:P,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}));r.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),r=i.getFocusDrawings(),[t,e]=Y.useState(r);return Y.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.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}},Un={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}},Pn={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,r,t,e)=>{for(var n=e>1?void 0:e?jn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Nn(r,t,n),n},fe=(i,r)=>(t,e)=>r(t,e,i);let ye=class extends u.Disposable{constructor(i,r,t,e){super(),this._componentManager=i,this._menuManagerService=r,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,Un,Pn].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,r,t,e)=>{for(var n=e>1?void 0:e?xn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&Ln(r,t,n),n},ne=(i,r)=>(t,e)=>r(t,e,i);function $n(i,r,t,e){const{scaleX:n,scaleY:o}=r.getAncestorScale(),s=r.getViewport(U.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 P,E;d<O?(c.left=!0,P=(I+C+(d-O))*n,E=Math.max(Math.min((I+C+(m-O))*n,(I+C)*n),(m-b)*n)):(c.left=!1,P=Math.max((d-b)*n,(I+C)*n),E=Math.max((m-b)*n,(I+C)*n));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:P,right:E,top:R,bottom:W,absolute:c}}const Oe=(i,r,t,e)=>{const{scene:n}=r,{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,n,t,e),{scaleX:g,scaleY:h}=n.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,n,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=n,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 n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:o,renderObject:e,canvas:s}}_getFloatDomProps(t){let e;return this._hooks.forEach(n=>{e=n.onGetFloatDomProps(t)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var He,Ve,Ye;const{unitId:n,subUnitId:o,drawingId:s}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(n,u.UniverInstanceType.UNIVER_SHEET);if(!m)return;const l=m.getActiveSheet().getSheetId();if(!d||!c)return;const a=(He=this._renderManagerService.getRenderById(n))==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(n);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,P=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),E=S.getObject(P);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(n,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 U.Rect(P,R);W&&B.setObjectType(U.ObjectType.CHART),S.addObject(B,U.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const q=this._ensureMap(n,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:n,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:n});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:n,subUnitId:o,drawingId:s}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);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,n)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,n),c=Array.from(s.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),m=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(n);!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 n=this._renderManagerService.getRenderById(e.getUnitId());return n?{render:n,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),L.filter(e=>!!e),L.switchMap(e=>u.fromEventSubject(e.render.scene.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(L.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:n})=>{t(e,n)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,o;if(e.id===N.SetZoomRatioOperation.id){const s=e.params,{unitId:c}=s;Array.from((o=(n=this._domLayerMap.get(c))==null?void 0:n.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:n,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(n,s);if(m==null)return;const l={column:m.actualColumn,columnOffset:n-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 n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==u.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==u.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(t,e,n,o){const s=this._domLayerInfoMap.get(n),c=this._getSceneAndTransformerByDrawingSearch(t);if(s&&c){const{scene:d}=c,m=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),l=d.getObject(m);l&&l instanceof U.Rect&&l.setProps(o)}}addFloatDomToPosition(t,e){const n=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=n,{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 n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(n.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(n=>n===t);this._hooks.splice(e,1)}}}};exports.SheetCanvasFloatDomManagerService=Bn([ne(0,u.Inject(U.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,r,t)=>r in i?ot(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,Fn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Gn(r,t):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&ot(r,t,n),n},Ae=(i,r)=>(t,e)=>r(t,e,i),st=(i,r,t)=>kn(i,typeof r!="symbol"?r+"":r,t);const Hn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends u.Plugin{constructor(r=gt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;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],[Ue]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,r))})}};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,U.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;
|
package/lib/es/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var Nn = Object.defineProperty;
|
|
2
2
|
var jn = (i, e, n) => e in i ? Nn(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
|
|
3
3
|
var F = (i, e, n) => jn(i, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { CommandType as Y, ICommandService as G, IUndoRedoService as
|
|
4
|
+
import { CommandType as Y, ICommandService as G, IUndoRedoService as fe, sequenceExecute as Lt, LocaleService as Je, IUniverInstanceService as pe, useDependency as le, Inject as N, Injector as Ie, IContextService as Gt, RxDisposable as Wn, UniverInstanceType as L, connectInjector as xn, toDisposable as $n, FOCUSING_COMMON_DRAWINGS as ge, DrawingTypeEnum as V, Disposable as Z, ArrangeTypeEnum as De, createDocumentModelWithStyle as Bn, ObjectRelativeFromH as Ln, ObjectRelativeFromV as Gn, BooleanNumber as Fn, PositionedObjectLayoutType as Vn, WrapTextType as kn, BuildTextUtils as Hn, Range as Yn, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as be, DOCS_ZEN_EDITOR_UNIT_ID_KEY as ye, InterceptorEffectEnum as Xn, ObjectMatrix as zn, Tools as ve, UserManagerService as Kn, IPermissionService as Jn, Rectangle as qn, Direction as re, FOCUSING_FX_BAR_EDITOR as Zn, EDITOR_ACTIVATED as Qn, FOCUSING_PANEL_EDITOR as er, LifecycleService as tr, LifecycleStages as nr, DisposableCollection as rr, fromEventSubject as ir, generateRandomId as sr, DependentOn as or, Plugin as ar, registerDependencies as cr, touchDependencies as nt, IConfigService as dr } from "@univerjs/core";
|
|
5
5
|
import { DocDrawingController as lr, UniverDocsDrawingPlugin as ur } from "@univerjs/docs-drawing";
|
|
6
6
|
import { IDrawingManagerService as q, IImageIoService as Ft, DRAWING_IMAGE_ALLOW_IMAGE_LIST as bt, DRAWING_IMAGE_COUNT_LIMIT as yt, ImageUploadStatusType as ue, DRAWING_IMAGE_ALLOW_SIZE as Ot, getImageSize as Tt, DRAWING_IMAGE_WIDTH_LIMIT as Et, DRAWING_IMAGE_HEIGHT_LIMIT as Pt, getDrawingShapeKeyByDrawingSearch as rt, UniverDrawingPlugin as hr } from "@univerjs/drawing";
|
|
7
7
|
import { ImageCropperObject as gr, COMPONENT_IMAGE_POPUP_MENU as mr, OpenImageCropOperation as fr, ImageResetSizeOperation as pr, DrawingRenderService as Vt, DrawingCommonPanel as wr, UniverDrawingUIPlugin as _r } from "@univerjs/drawing-ui";
|
|
8
8
|
import { IRenderManagerService as X, precisionTo as ie, getGroupState as vr, transformObjectOutOfGroup as Sr, RENDER_CLASS_TYPE as he, Rect as Ut, ObjectType as Ir, DRAWING_OBJECT_LAYER_INDEX as Cr, SHEET_VIEWPORT_KEY as kt } from "@univerjs/engine-render";
|
|
9
9
|
import { ISheetDrawingService as z, SetDrawingApplyMutation as T, DrawingApplyType as E, SheetDrawingAnchorType as y, UniverSheetsDrawingPlugin as Rr } from "@univerjs/sheets-drawing";
|
|
10
10
|
import { SheetCanvasPopManagerService as Mr, attachRangeWithCoord as $e, ISheetSelectionRenderService as Ce, SheetSkeletonManagerService as Q, IEditorBridgeService as Dr, IAutoFillService as br, HoverManagerService as yr, COPY_TYPE as At, PREDEFINED_HOOK_NAME as Oe, virtualizeDiscreteRanges as Or, ISheetClipboardService as Tr, SheetPrintInterceptorService as Er, getCurrentRangeDisable$ as Pr, SetZoomRatioOperation as Ur } from "@univerjs/sheets-ui";
|
|
11
|
-
import { ISidebarService as Ar, IUIPartsService as Nr, BuiltInUIPart as jr, ILocalFileService as Wr, IMessageService as xr, MenuItemType as _t, getMenuHiddenObservable as Ht, RibbonStartGroup as $r, KeyCode as
|
|
11
|
+
import { ISidebarService as Ar, IUIPartsService as Nr, BuiltInUIPart as jr, ILocalFileService as Wr, IMessageService as xr, MenuItemType as _t, getMenuHiddenObservable as Ht, RibbonStartGroup as $r, KeyCode as me, ComponentManager as Br, IMenuManagerService as Lr, IShortcutService as Gr, CanvasFloatDomService as Fr } from "@univerjs/ui";
|
|
12
12
|
import { takeUntil as Nt, combineLatest as Te, map as Be, filter as se, distinctUntilChanged as Ee, Subject as it, take as Vr, BehaviorSubject as kr, switchMap as jt } from "rxjs";
|
|
13
13
|
import { SheetInterceptorService as qe, getSheetCommandTarget as H, SheetsSelectionsService as Yt, SetRangeValuesCommand as Hr, SetWorksheetRowHeightMutation as Xt, SetWorksheetColWidthMutation as zt, SetWorksheetRowIsAutoHeightMutation as Yr, SetWorksheetRowAutoHeightMutation as Xr, AddWorksheetMergeMutation as zr, RemoveWorksheetMergeMutation as Kr, AFTER_CELL_EDIT as Jr, INTERCEPTOR_POINT as qr, InterceptCellContentPriority as Zr, WorkbookViewPermission as Wt, WorksheetViewPermission as st, WorkbookEditablePermission as ut, WorksheetEditPermission as xe, InsertRowCommand as Kt, InsertColCommand as Jt, RemoveRowCommand as qt, RemoveColCommand as Zt, DeleteRangeMoveLeftCommand as Qt, DeleteRangeMoveUpCommand as en, InsertRangeMoveDownCommand as tn, InsertRangeMoveRightCommand as nn, DeltaRowHeightCommand as ht, SetRowHeightCommand as gt, DeltaColumnWidthCommand as rn, SetColWidthCommand as sn, SetRowHiddenCommand as on, SetSpecificRowsVisibleCommand as an, SetSpecificColsVisibleCommand as cn, SetColHiddenCommand as dn, MoveColsCommand as ln, MoveRowsCommand as un, MoveRangeCommand as hn, SetRowVisibleMutation as Qr, SetRowHiddenMutation as ei, SetColVisibleMutation as ti, SetColHiddenMutation as ni, SetWorksheetActiveOperation as ri, RangeProtectionPermissionEditPoint as ii, SetFrozenMutation as si } from "@univerjs/sheets";
|
|
14
14
|
import gn, { useEffect as vt, forwardRef as mn, useRef as oi, createElement as fn, useState as mt } from "react";
|
|
@@ -29,7 +29,7 @@ const li = "sheets-drawing-ui.config", ui = {}, W = {
|
|
|
29
29
|
type: Y.COMMAND,
|
|
30
30
|
handler: (i, e) => {
|
|
31
31
|
var I, S, R;
|
|
32
|
-
const n = i.get(G), t = i.get(
|
|
32
|
+
const n = i.get(G), t = i.get(fe), r = i.get(qe), s = i.get(z);
|
|
33
33
|
if (!e) return !1;
|
|
34
34
|
const { drawings: o } = e, d = [];
|
|
35
35
|
o.forEach((_) => {
|
|
@@ -57,7 +57,7 @@ const li = "sheets-drawing-ui.config", ui = {}, W = {
|
|
|
57
57
|
id: "sidebar.operation.sheet-image",
|
|
58
58
|
type: Y.COMMAND,
|
|
59
59
|
handler: async (i, e) => {
|
|
60
|
-
const n = i.get(Ar), t = i.get(Je), r = i.get(
|
|
60
|
+
const n = i.get(Ar), t = i.get(Je), r = i.get(pe), s = i.get(q);
|
|
61
61
|
if (!H(r)) return !1;
|
|
62
62
|
switch (e.value) {
|
|
63
63
|
case "open":
|
|
@@ -85,7 +85,7 @@ const li = "sheets-drawing-ui.config", ui = {}, W = {
|
|
|
85
85
|
return e == null ? !1 : (n.focusDrawing([e]), t.executeCommand(wn.id, { value: "open" }), !0);
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
var at = { exports: {} },
|
|
88
|
+
var at = { exports: {} }, we = {};
|
|
89
89
|
/**
|
|
90
90
|
* @license React
|
|
91
91
|
* react-jsx-runtime.production.min.js
|
|
@@ -97,7 +97,7 @@ var at = { exports: {} }, pe = {};
|
|
|
97
97
|
*/
|
|
98
98
|
var xt;
|
|
99
99
|
function hi() {
|
|
100
|
-
if (xt) return
|
|
100
|
+
if (xt) return we;
|
|
101
101
|
xt = 1;
|
|
102
102
|
var i = gn, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), t = Object.prototype.hasOwnProperty, r = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
103
103
|
function o(d, l, g) {
|
|
@@ -107,7 +107,7 @@ function hi() {
|
|
|
107
107
|
if (d && d.defaultProps) for (c in l = d.defaultProps, l) a[c] === void 0 && (a[c] = l[c]);
|
|
108
108
|
return { $$typeof: e, type: d, key: h, ref: u, props: a, _owner: r.current };
|
|
109
109
|
}
|
|
110
|
-
return
|
|
110
|
+
return we.Fragment = n, we.jsx = o, we.jsxs = o, we;
|
|
111
111
|
}
|
|
112
112
|
var $t;
|
|
113
113
|
function gi() {
|
|
@@ -177,7 +177,7 @@ let Le = class extends Wn {
|
|
|
177
177
|
this.disposeWithMe(
|
|
178
178
|
$n(
|
|
179
179
|
t.createControl$.subscribe(() => {
|
|
180
|
-
if (this._contextService.setContextValue(
|
|
180
|
+
if (this._contextService.setContextValue(ge, !0), this._hasCropObject(n))
|
|
181
181
|
return;
|
|
182
182
|
const o = t.getSelectedObjectMap();
|
|
183
183
|
if (o.size > 1) {
|
|
@@ -211,7 +211,11 @@ let Le = class extends Wn {
|
|
|
211
211
|
)
|
|
212
212
|
), this.disposeWithMe(
|
|
213
213
|
t.clearControl$.subscribe(() => {
|
|
214
|
-
r == null || r.dispose(), this._contextService.setContextValue(
|
|
214
|
+
r == null || r.dispose(), this._contextService.setContextValue(ge, !1), this._drawingManagerService.focusDrawing(null);
|
|
215
|
+
})
|
|
216
|
+
), this.disposeWithMe(
|
|
217
|
+
this._contextService.contextChanged$.subscribe((o) => {
|
|
218
|
+
o[ge] === !1 && (r == null || r.dispose());
|
|
215
219
|
})
|
|
216
220
|
), this.disposeWithMe(
|
|
217
221
|
t.changing$.subscribe(() => {
|
|
@@ -257,7 +261,7 @@ Le = Ci([
|
|
|
257
261
|
ae(1, q),
|
|
258
262
|
ae(2, N(Mr)),
|
|
259
263
|
ae(3, X),
|
|
260
|
-
ae(4,
|
|
264
|
+
ae(4, pe),
|
|
261
265
|
ae(5, Gt),
|
|
262
266
|
ae(6, N(Nr))
|
|
263
267
|
], Le);
|
|
@@ -417,7 +421,7 @@ const vn = {
|
|
|
417
421
|
id: "sheet.command.group-sheet-image",
|
|
418
422
|
type: Y.COMMAND,
|
|
419
423
|
handler: (i, e) => {
|
|
420
|
-
const n = i.get(G), t = i.get(
|
|
424
|
+
const n = i.get(G), t = i.get(fe), r = i.get(z);
|
|
421
425
|
if (!e) return !1;
|
|
422
426
|
const s = [];
|
|
423
427
|
e.forEach(({ parent: u, children: m }) => {
|
|
@@ -443,7 +447,7 @@ const vn = {
|
|
|
443
447
|
type: Y.COMMAND,
|
|
444
448
|
handler: (i, e) => {
|
|
445
449
|
var I, S, R;
|
|
446
|
-
const n = i.get(G), t = i.get(
|
|
450
|
+
const n = i.get(G), t = i.get(fe), r = i.get(z), s = i.get(qe);
|
|
447
451
|
if (!e) return !1;
|
|
448
452
|
const o = e.drawings, d = o.map((_) => _.unitId), l = r.getBatchAddOp(o), { unitId: g, subUnitId: c, undo: a, redo: h, objects: u } = l, m = s.onCommandExecute({ id: Qe.id, params: e }), f = { id: T.id, params: { op: h, unitId: g, subUnitId: c, objects: u, type: E.INSERT } }, p = { id: T.id, params: { op: a, unitId: g, subUnitId: c, objects: u, type: E.REMOVE } };
|
|
449
453
|
return Lt([...(I = m.preRedos) != null ? I : [], f, ...m.redos], n) ? (t.pushUndoRedo({
|
|
@@ -466,7 +470,7 @@ const vn = {
|
|
|
466
470
|
id: "sheet.command.set-drawing-arrange",
|
|
467
471
|
type: Y.COMMAND,
|
|
468
472
|
handler: (i, e) => {
|
|
469
|
-
const n = i.get(G), t = i.get(
|
|
473
|
+
const n = i.get(G), t = i.get(fe);
|
|
470
474
|
if (!e) return !1;
|
|
471
475
|
const r = i.get(z), { unitId: s, subUnitId: o, drawingIds: d, arrangeType: l } = e, g = { unitId: s, subUnitId: o, drawingIds: d };
|
|
472
476
|
let c;
|
|
@@ -487,7 +491,7 @@ const vn = {
|
|
|
487
491
|
id: "sheet.command.set-sheet-image",
|
|
488
492
|
type: Y.COMMAND,
|
|
489
493
|
handler: (i, e) => {
|
|
490
|
-
const n = i.get(G), t = i.get(
|
|
494
|
+
const n = i.get(G), t = i.get(fe), r = i.get(z);
|
|
491
495
|
if (!e) return !1;
|
|
492
496
|
const { drawings: s } = e, o = r.getBatchUpdateOp(s), { unitId: d, subUnitId: l, undo: g, redo: c, objects: a } = o;
|
|
493
497
|
return n.syncExecuteCommand(T.id, { unitId: d, subUnitId: l, op: c, objects: a, type: E.UPDATE }) ? (t.pushUndoRedo({
|
|
@@ -506,7 +510,7 @@ const vn = {
|
|
|
506
510
|
id: "sheet.command.ungroup-sheet-image",
|
|
507
511
|
type: Y.COMMAND,
|
|
508
512
|
handler: (i, e) => {
|
|
509
|
-
const n = i.get(G), t = i.get(
|
|
513
|
+
const n = i.get(G), t = i.get(fe), r = i.get(z);
|
|
510
514
|
if (!e) return !1;
|
|
511
515
|
const s = [];
|
|
512
516
|
e.forEach(({ parent: u, children: m }) => {
|
|
@@ -803,7 +807,7 @@ let Se = class extends Z {
|
|
|
803
807
|
_focusDrawingListener() {
|
|
804
808
|
this.disposeWithMe(
|
|
805
809
|
this._drawingManagerService.focus$.subscribe((e) => {
|
|
806
|
-
e == null || e.length === 0 ? (this._contextService.setContextValue(
|
|
810
|
+
e == null || e.length === 0 ? (this._contextService.setContextValue(ge, !1), this._sheetDrawingService.focusDrawing([])) : (this._contextService.setContextValue(ge, !0), this._sheetDrawingService.focusDrawing(e));
|
|
807
811
|
})
|
|
808
812
|
);
|
|
809
813
|
}
|
|
@@ -918,7 +922,7 @@ let Ge = class extends Z {
|
|
|
918
922
|
Ge = Ni([
|
|
919
923
|
ce(0, G),
|
|
920
924
|
ce(1, N(qe)),
|
|
921
|
-
ce(2,
|
|
925
|
+
ce(2, pe),
|
|
922
926
|
ce(3, N(Ie)),
|
|
923
927
|
ce(4, q),
|
|
924
928
|
ce(5, N(lr)),
|
|
@@ -1061,7 +1065,7 @@ let ke = class extends Z {
|
|
|
1061
1065
|
...A,
|
|
1062
1066
|
unitId: s,
|
|
1063
1067
|
subUnitId: o,
|
|
1064
|
-
drawingId: w ? A.drawingId :
|
|
1068
|
+
drawingId: w ? A.drawingId : ve.generateRandomId(),
|
|
1065
1069
|
transform: {
|
|
1066
1070
|
...P,
|
|
1067
1071
|
left: P.left + S,
|
|
@@ -1112,7 +1116,7 @@ var ki = Object.defineProperty, Hi = Object.getOwnPropertyDescriptor, Yi = (i, e
|
|
|
1112
1116
|
for (var r = t > 1 ? void 0 : t ? Hi(e, n) : e, s = i.length - 1, o; s >= 0; s--)
|
|
1113
1117
|
(o = i[s]) && (r = (t ? o(e, n, r) : o(r)) || r);
|
|
1114
1118
|
return t && r && ki(e, n, r), r;
|
|
1115
|
-
},
|
|
1119
|
+
}, _e = (i, e) => (n, t) => e(n, t, i);
|
|
1116
1120
|
let He = class extends Z {
|
|
1117
1121
|
constructor(i, e, n, t, r) {
|
|
1118
1122
|
super(), this._drawingManagerService = i, this._renderManagerService = e, this._permissionService = n, this._univerInstanceService = t, this._userManagerService = r, this._initDrawingVisible(), this._initDrawingEditable(), this._initViewPermissionChange(), this._initEditPermissionChange();
|
|
@@ -1261,11 +1265,11 @@ let He = class extends Z {
|
|
|
1261
1265
|
}
|
|
1262
1266
|
};
|
|
1263
1267
|
He = Yi([
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1268
|
+
_e(0, q),
|
|
1269
|
+
_e(1, X),
|
|
1270
|
+
_e(2, Jn),
|
|
1271
|
+
_e(3, pe),
|
|
1272
|
+
_e(4, N(Kn))
|
|
1269
1273
|
], He);
|
|
1270
1274
|
var Xi = Object.defineProperty, zi = Object.getOwnPropertyDescriptor, Ki = (i, e, n, t) => {
|
|
1271
1275
|
for (var r = t > 1 ? void 0 : t ? zi(e, n) : e, s = i.length - 1, o; s >= 0; s--)
|
|
@@ -1305,7 +1309,7 @@ let Ye = class extends Z {
|
|
|
1305
1309
|
return n(i);
|
|
1306
1310
|
const { scaleX: g, scaleY: c } = s.scene, a = i ? { ...i } : { startColumn: 0, endColumn: 0, endRow: 0, startRow: 0 }, h = l.order.map((u) => l.data[u]).filter((u) => u.drawingType !== V.DRAWING_DOM);
|
|
1307
1311
|
return h.length ? (h.forEach((u) => {
|
|
1308
|
-
if (!u.groupId && u.transform &&
|
|
1312
|
+
if (!u.groupId && u.transform && ve.isDefine(u.transform.left) && ve.isDefine(u.transform.top) && ve.isDefine(u.transform.width) && ve.isDefine(u.transform.height)) {
|
|
1309
1313
|
const m = o.skeleton.getCellIndexByOffset(u.transform.left, u.transform.top, g, c, { x: 0, y: 0 }), f = o.skeleton.getCellIndexByOffset(u.transform.left + u.transform.width, u.transform.top + u.transform.height, g, c, { x: 0, y: 0 });
|
|
1310
1314
|
m.column < a.startColumn && (a.startColumn = m.column), m.row < a.startRow && (a.startRow = m.row), a.endRow < f.row && (a.endRow = f.row), a.endColumn < f.column && (a.endColumn = f.column);
|
|
1311
1315
|
}
|
|
@@ -2079,7 +2083,7 @@ wt = Zi([
|
|
|
2079
2083
|
te(5, N(qe)),
|
|
2080
2084
|
te(6, z),
|
|
2081
2085
|
te(7, q),
|
|
2082
|
-
te(8,
|
|
2086
|
+
te(8, pe)
|
|
2083
2087
|
], wt);
|
|
2084
2088
|
var J = function() {
|
|
2085
2089
|
return J = Object.assign || function(i) {
|
|
@@ -2345,13 +2349,13 @@ const Ms = (i) => {
|
|
|
2345
2349
|
}
|
|
2346
2350
|
};
|
|
2347
2351
|
function Me(i) {
|
|
2348
|
-
return !i.getContextValue(Zn) && !i.getContextValue(Qn) && !i.getContextValue(er) && i.getContextValue(
|
|
2352
|
+
return !i.getContextValue(Zn) && !i.getContextValue(Qn) && !i.getContextValue(er) && i.getContextValue(ge);
|
|
2349
2353
|
}
|
|
2350
2354
|
const ys = {
|
|
2351
2355
|
id: Re.id,
|
|
2352
2356
|
description: "shortcut.sheet.drawing-move-down",
|
|
2353
2357
|
group: "4_sheet-drawing-view",
|
|
2354
|
-
binding:
|
|
2358
|
+
binding: me.ARROW_DOWN,
|
|
2355
2359
|
priority: 100,
|
|
2356
2360
|
preconditions: Me,
|
|
2357
2361
|
staticParameters: {
|
|
@@ -2361,7 +2365,7 @@ const ys = {
|
|
|
2361
2365
|
id: Re.id,
|
|
2362
2366
|
description: "shortcut.sheet.drawing-move-up",
|
|
2363
2367
|
group: "4_sheet-drawing-view",
|
|
2364
|
-
binding:
|
|
2368
|
+
binding: me.ARROW_UP,
|
|
2365
2369
|
priority: 100,
|
|
2366
2370
|
preconditions: Me,
|
|
2367
2371
|
staticParameters: {
|
|
@@ -2371,7 +2375,7 @@ const ys = {
|
|
|
2371
2375
|
id: Re.id,
|
|
2372
2376
|
description: "shortcut.sheet.drawing-move-left",
|
|
2373
2377
|
group: "4_sheet-drawing-view",
|
|
2374
|
-
binding:
|
|
2378
|
+
binding: me.ARROW_LEFT,
|
|
2375
2379
|
priority: 100,
|
|
2376
2380
|
preconditions: Me,
|
|
2377
2381
|
staticParameters: {
|
|
@@ -2381,7 +2385,7 @@ const ys = {
|
|
|
2381
2385
|
id: Re.id,
|
|
2382
2386
|
description: "shortcut.sheet.drawing-move-right",
|
|
2383
2387
|
group: "4_sheet-drawing-view",
|
|
2384
|
-
binding:
|
|
2388
|
+
binding: me.ARROW_RIGHT,
|
|
2385
2389
|
priority: 100,
|
|
2386
2390
|
preconditions: Me,
|
|
2387
2391
|
staticParameters: {
|
|
@@ -2393,8 +2397,8 @@ const ys = {
|
|
|
2393
2397
|
group: "4_sheet-drawing-view",
|
|
2394
2398
|
// when focusing on any other input tag do not trigger this shortcut
|
|
2395
2399
|
preconditions: Me,
|
|
2396
|
-
binding:
|
|
2397
|
-
mac:
|
|
2400
|
+
binding: me.DELETE,
|
|
2401
|
+
mac: me.BACKSPACE
|
|
2398
2402
|
};
|
|
2399
2403
|
var Us = Object.defineProperty, As = Object.getOwnPropertyDescriptor, Ns = (i, e, n, t) => {
|
|
2400
2404
|
for (var r = t > 1 ? void 0 : t ? As(e, n) : e, s = i.length - 1, o; s >= 0; s--)
|
|
@@ -2808,7 +2812,7 @@ let ze = class extends Z {
|
|
|
2808
2812
|
};
|
|
2809
2813
|
ze = xs([
|
|
2810
2814
|
de(0, N(X)),
|
|
2811
|
-
de(1,
|
|
2815
|
+
de(1, pe),
|
|
2812
2816
|
de(2, N(G)),
|
|
2813
2817
|
de(3, q),
|
|
2814
2818
|
de(4, N(Fr)),
|
package/lib/umd/index.js
CHANGED
|
@@ -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 lt(){if(Xe)return se;Xe=1;var i=x,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,l,h){var u,s={},g=null,m=null;h!==void 0&&(g=""+h),l.key!==void 0&&(g=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)e.call(l,u)&&!o.hasOwnProperty(u)&&(s[u]=l[u]);if(c&&c.defaultProps)for(u in l=c.defaultProps,l)s[u]===void 0&&(s[u]=l[u]);return{$$typeof:r,type:c,key:g,ref:m,props:s,_owner:t.current}}return se.Fragment=n,se.jsx=a,se.jsxs=a,se}var ze;function ut(){return ze||(ze=1,Oe.exports=lt()),Oe.exports}var $=ut();const me={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},gt=()=>{const i=d.useDependency(A.IImageIoService),r=d.useDependency(d.LocaleService),[n,e]=x.useState(0);return x.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),$.jsx("div",{style:{display:n>0?"block":"none"},className:me.uploadLoading,children:$.jsxs("div",{className:me.uploadLoadingBody,children:[$.jsx("div",{className:me.uploadLoadingBodyAnimation}),$.jsx("div",{className:me.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var mt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(i,r,n,e)=>{for(var t=e>1?void 0:e?ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&mt(r,n,t),t},ne=(i,r)=>(n,e)=>r(n,e,i);let he=class extends d.RxDisposable{constructor(r,n,e,t,o,a,c){super();Y(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(d.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>d.connectInjector(gt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(d.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const l=c.oKey,h=this._drawingManagerService.getDrawingOKey(l);if(!h)return;const{unitId:u,subUnitId:s,drawingId:g,drawingType:m}=h,f=h.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,s,g,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,s,g,m)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:s,drawingId:g}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:Ee.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===d.DrawingTypeEnum.DRAWING_DOM}]}};he=pt([ne(0,d.Inject(d.Injector)),ne(1,A.IDrawingManagerService),ne(2,d.Inject(N.SheetCanvasPopManagerService)),ne(3,U.IRenderManagerService),ne(4,d.IUniverInstanceService),ne(5,d.IContextService),ne(6,d.Inject(k.IUIPartsService))],he);function V(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:l=0,skewY:h=0}=i,{column:u,columnOffset:s,row:g,rowOffset:m}=e,{column:f,columnOffset:S,row:v,rowOffset:C}=t,M=n.getCurrentSkeleton(),y=N.attachRangeWithCoord(M,{startColumn:u,endColumn:u,startRow:g,endRow:g});if(y==null)return;const T=N.attachRangeWithCoord(M,{startColumn:f,endColumn:f,startRow:v,endRow:v});if(T==null)return;const{startX:I,startY:D}=y,{startX:w,startY:P}=T;let E=U.precisionTo(I+s,1),L=U.precisionTo(D+m,1),j=U.precisionTo(w+S-E,1),O=U.precisionTo(P+C-L,1);y.startX===T.endX&&(j=0),y.startY===T.endY&&(O=0);const R=M.rowHeaderWidth+M.columnTotalWidth,B=M.columnHeaderHeight+M.rowTotalHeight;return E+j>R&&(E=R-j),L+O>B&&(L=B-O),{flipY:o,flipX:a,angle:c,skewX:l,skewY:h,left:E,top:L,width:j,height:O}}function F(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:l=0,skewX:h=0,skewY:u=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const g={column:s.actualColumn,columnOffset:U.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:U.precisionTo(e-s.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:U.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:U.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:c,angle:l,skewX:h,skewY:u,from:g,to:f}}var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(i,r,n,e)=>{for(var t=e>1?void 0:e?St(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ft(r,n,t),t},pe=(i,r)=>(n,e)=>r(n,e,i);let Pe=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=V(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=vt([pe(1,p.ISheetDrawingService),pe(2,A.IDrawingManagerService),pe(3,d.Inject(N.ISheetSelectionRenderService)),pe(4,d.Inject(N.SheetSkeletonManagerService))],Pe);function _t(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,l=U.getGroupState(0,0,t.map(s=>s.transform||{})),h=t.map(s=>{const g=s.transform||{left:0,top:0},{unitId:m,subUnitId:f,drawingId:S}=s;return{unitId:m,subUnitId:f,drawingId:S,transform:{...g,left:g.left-l.left,top:g.top-l.top},groupId:c}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:h})}),r}function wt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:l={width:0,height:0}}=e;if(l==null)return;const h=t.map(s=>{const{transform:g}=s,{unitId:m,subUnitId:f,drawingId:S}=s,v=U.transformObjectOutOfGroup(g||{},l,l.width||0,l.height||0);return{unitId:m,subUnitId:f,drawingId:S,transform:v,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:h})}),r}const Ae={id:"sheet.command.group-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:wt(s),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,T;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(I=>I.unitId),l=t.getBatchAddOp(a),{unitId:h,subUnitId:u,undo:s,redo:g,objects:m}=l,f=o.onCommandExecute({id:ce.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.INSERT}},v={id:p.SetDrawingApplyMutation.id,params:{op:s,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.REMOVE}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Ue={id:"sheet.command.set-drawing-arrange",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService);if(!r)return!1;const t=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:l}=r,h={unitId:o,subUnitId:a,drawingIds:c};let u;if(l===d.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(h):l===d.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(h):l===d.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(h):l===d.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(h)),u==null)return!1;const{objects:s,redo:g,undo:m}=u;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:h,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Ne={id:"sheet.command.ungroup-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:_t(s),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ct(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&It(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);function Mt(i,r,n){const e=n*Math.PI/180,t=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ke(i,r,n,e,t){var M;const{rotatedHeight:o,rotatedWidth:a}=Mt(n,e,t),l=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(M=l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:M.skeleton;if(u==null)return!1;const s=u.getCellByIndex(r.row,r.col),g=s.mergeInfo.endX-s.mergeInfo.startX-2,m=s.mergeInfo.endY-s.mergeInfo.startY-2,f=a/o,v=Math.ceil(Math.min(g,m*f))/a,C=!v||Number.isNaN(v)?.001:v;return{width:n*C,height:e*C}}let le=class extends d.Disposable{constructor(r,n,e,t,o,a,c,l,h,u,s,g,m){super();Y(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=l,this._contextService=h,this._messageService=u,this._localeService=s,this._injector=m,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const y=M.message;y===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:l,base64Cache:h}=n,{width:u,height:s,image:g}=await A.getImageSize(h||""),{width:m,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(l,c,g);let S=1;if(u>A.DRAWING_IMAGE_WIDTH_LIMIT||s>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/u,y=A.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,y)}const v=this._getImagePosition(u*S,s*S,m,f);if(v==null)return;const C={unitId:t,subUnitId:o,drawingId:a,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:l,transform:V(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(ce.id,{unitId:t,drawings:[C]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(v){const C=v.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.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:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:c,height:l,image:h}=await A.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,h);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const s=d.createDocumentModelWithStyle("",{}),g=Ke(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},c,l,0);if(!g)return!1;const m={size:{width:g.width,height:g.height},positionH:{relativeFrom:d.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:d.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:s.getUnitId(),subUnitId:s.getUnitId(),drawingId:e,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Ye.docDrawingPositionToTransform(m),docTransform:m,behindDoc:d.BooleanNumber.FALSE,title:"",description:"",layoutType:d.PositionedObjectLayoutType.INLINE,wrapText:d.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=d.BuildTextUtils.drawing.add({documentDataModel:s,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(s.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:s.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=N.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:l,startRow:h,startX:u,startY:s}=c,g=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),g=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),g=!0),g){const v=this._selectionRenderService.getCellWithCoordByOffset(u,s);if(v==null)return;u=v.startX,s=v.startY,l=v.actualColumn,h=v.actualRow}const m={column:l,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:m,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(Ue.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:l}=e;if(l==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(h==null||h.unitId!==this._context.unitId)return;const u=F({...h.transform,...l},this._selectionRenderService);if(u==null)return;const s={...e,transform:{...h.transform,...l,...V(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(s)}),n.length>0&&this._commandService.executeCommand(de.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ae.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ne.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};le=yt([z(1,d.Inject(N.SheetSkeletonManagerService)),z(2,d.ICommandService),z(3,N.ISheetSelectionRenderService),z(4,A.IImageIoService),z(5,k.ILocalFileService),z(6,p.ISheetDrawingService),z(7,A.IDrawingManagerService),z(8,d.IContextService),z(9,k.IMessageService),z(10,d.Inject(d.LocaleService)),z(11,d.Inject(_.SheetsSelectionsService)),z(12,d.Inject(d.Injector))],le);var Dt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Tt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Rt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Dt(r,n,t),t},re=(i,r)=>(n,e)=>r(n,e,i);function je(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const c=n.p.drawings[n.p.drawingsOrder[0]],l=Ke(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(l)return c.transform.width=l.width,c.transform.height=l.height,c.docTransform.size.width=l.width,c.docTransform.size.height=l.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let fe=class extends d.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=d.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Ye.ReplaceSnapshotCommand.id&&i.params.unitId===d.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:d.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};fe=Tt([re(0,d.ICommandService),re(1,d.Inject(_.SheetInterceptorService)),re(2,d.IUniverInstanceService),re(3,d.Inject(d.Injector)),re(4,A.IDrawingManagerService),re(5,d.Inject(te.DocDrawingController)),re(6,d.Inject(N.IEditorBridgeService))],fe);var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(i,r,n,e)=>{for(var t=e>1?void 0:e?Et(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&bt(r,n,t),t},Je=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends d.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,n,e)=>{new d.ObjectMatrix(e).forValue((t,o,a)=>{je(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};Se=Ot([Je(0,d.Inject(N.IAutoFillService)),Je(1,d.Inject(d.Injector))],Se);var Pt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Ut=(i,r,n,e)=>{for(var t=e>1?void 0:e?At(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Pt(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);let _e=class extends d.Disposable{constructor(r,n,e,t){super();Y(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};_e=Ut([ve(0,d.Inject(N.HoverManagerService)),ve(1,d.Inject(U.IRenderManagerService)),ve(2,d.Inject(_.SheetsSelectionsService)),ve(3,d.Inject(q.DrawingRenderService))],_e);var Nt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,r,n,e)=>{for(var t=e>1?void 0:e?jt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Nt(r,n,t),t},We=(i,r)=>(n,e)=>r(n,e,i);let we=class extends d.Disposable{constructor(r,n,e){super();Y(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:l,unitId:h,subUnitId:u}=n;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:c,unitId:h,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var g;const t=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(N.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:l,endY:h}=o,u=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(u).forEach(m=>{const f=u[m],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:v=0,top:C=0,width:M=0,height:y=0}=S,{drawingStartX:T,drawingEndX:I,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:C,drawingEndY:C+y};a<=T&&I<=c&&l<=D&&w<=h&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var E;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(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,l],mapFunc:h}=N.virtualizeDiscreteRanges([e,r]),{row:u,col:s}=h(c.startRow,c.startColumn),{row:g,col:m}=h(l.startRow,l.startColumn),f=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(N.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:s,endColumn:s}),v=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:m,endColumn:m});if(!S||!v)return{redos:[],undos:[]};const C=[],M=[],y=v.startX-S.startX,T=v.startY-S.startY,I=g-u,D=m-s,w=n.copyType===N.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return t.forEach(L=>{const{transform:j,sheetTransform:O}=L;if(!j)return;const R={...L,unitId:o,subUnitId:a,drawingId:w?L.drawingId:d.Tools.generateRandomId(),transform:{...j,left:j.left+y,top:j.top+T},sheetTransform:{to:{...O.to,row:O.to.row+I,column:O.to.column+D},from:{...O.from,row:O.from.row+I,column:O.from.column+D}}};if(w){const{undo:B,redo:H,objects:Z}=P.getBatchUpdateOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:H,objects:Z}}),M.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:B,objects:Z}})}else{const{undo:B,redo:H,objects:Z}=P.getBatchAddOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:H,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.INSERT}}),M.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:M}}};we=Wt([We(0,N.ISheetClipboardService),We(1,U.IRenderManagerService),We(2,p.ISheetDrawingService)],we);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Bt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},ue=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(W.map(g=>g.every(m=>m.value)));u==null||u.pipe(W.filter(g=>g!==a),W.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingVisible(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?this._drawingManagerService.addNotification(S):(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.removeObject(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||s.pipe(W.filter(g=>g.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(t,o),m=Object.values(g);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(W.map(g=>g.every(m=>m.value)));u==null||u.pipe(W.filter(g=>g!==a),W.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingEditable(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.detachTransformerFrom(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||s.pipe(W.filter(g=>g.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const g=r.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,m),S=Object.values(f),v=this._renderManagerService.getRenderById(g),C=v==null?void 0:v.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(y=>{y.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>y.oKey.includes(T.drawingId))&&C.detachTransformerFrom(y)})}})})}))}};Ie=Gt([ue(0,A.IDrawingManagerService),ue(1,U.IRenderManagerService),ue(2,d.IPermissionService),ue(3,d.IUniverInstanceService),ue(4,d.Inject(d.UserManagerService))],Ie);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ht=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ft(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&kt(r,n,t),t},Ce=(i,r)=>(n,e)=>r(n,e,i);let ye=class extends d.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(l=>{this._drawingRenderService.renderDrawing(c.data[l],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),l=c==null?void 0:c[r.subUnitId];if(!l)return n(i);const{scaleX:h,scaleY:u}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=l.order.map(m=>l.data[m]).filter(m=>m.drawingType!==d.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(m=>{if(!m.groupId&&m.transform&&d.Tools.isDefine(m.transform.left)&&d.Tools.isDefine(m.transform.top)&&d.Tools.isDefine(m.transform.width)&&d.Tools.isDefine(m.transform.height)){const f=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,h,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,h,u,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};ye=Ht([Ce(0,d.Inject(N.SheetPrintInterceptorService)),Ce(1,d.Inject(q.DrawingRenderService)),Ce(2,A.IDrawingManagerService),Ce(3,U.IRenderManagerService)],ye);var $t=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Vt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&$t(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);const xt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],Xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Le=class extends d.Disposable{constructor(i,r,n,e,t,o,a,c,l){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!xt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===_.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),l=[],h=[];if(Object.keys(c).forEach(u=>{const s=c[u],{updateDrawings:g,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,s);l.push(...g),h.push(...m)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:s,redo:g,objects:m}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(h),s=u.undo,g=u.redo,m=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:h,drawingId:u}=n,{from:s,to:g}=o,{row:m,column:f}=s,{row:S,column:v}=g;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:C,endRow:M,startColumn:y,endColumn:T}=i;let I=null,D=null;if(r===0&&m>=C&&S<=M)if(f>=y&&v<=T)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkCol(o,c,y,T,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===1&&f>=y&&v<=T)if(m>=C&&S<=M)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,c,y,T,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}if(I!=null&&D!=null){const w=V(I,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:T}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:P,startColumn:E,endColumn:L}=D;if(T<E)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,B=null;if(M>=E&&M<=L){const H=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if(H==null)return;B={...m,left:H.startX}}if(B!=null&&(R=F(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(M>=E&&T<=L)continue;let j=null,O=null;if(M>=E&&M<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;O={...m,left:(R==null?void 0:R.startX)||0,width:((m==null?void 0:m.width)||0)-R.endX+R.startX}}else if(T>=E&&T<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:S.row,endRow:v.row});if(R==null)return;O={...m,left:R.startX-((m==null?void 0:m.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;if(O={...m,width:((m==null?void 0:m.width)||0)-R.endX+R.startX},j=F(O,this._selectionRenderService),j!=null&&O!=null){o.push({...s,sheetTransform:j,transform:O});break}}if(O!=null&&(j=F(O,this._selectionRenderService)),O!=null&&j!=null){t.push({...s,sheetTransform:j,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:l}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:T}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:P,startColumn:E,endColumn:L}=D;if(y<w)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,B=null;if(C>=w&&C<=P){const H=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:P});if(H==null)return;B={...m,top:H.startY}}if(B!=null&&(R=F(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(C>=w&&y<=P)continue;let j=null,O=null;if(C>=w&&C<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:P});if(R==null)return;O={...m,top:(R==null?void 0:R.startY)||0,height:((m==null?void 0:m.height)||0)-R.endY+R.startY}}else if(y>=w&&y<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:y});if(R==null)return;O={...m,top:R.startY-((m==null?void 0:m.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:P});if(R==null)return;if(O={...m,height:((m==null?void 0:m.height)||0)-R.endY+R.startY},j=F(O,this._selectionRenderService),j!=null&&O!=null){o.push({...s,sheetTransform:j,transform:O});break}}if(O!=null&&(j=F(O,this._selectionRenderService)),O!=null&&j!=null){t.push({...s,sheetTransform:j,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:l,transform:h,anchorType:u=p.SheetDrawingAnchorType.Position}=c;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:s,to:g}=l,{row:m,column:f}=s,{row:S,column:v}=g;for(let C=0;C<n.length;C++){const M=n[C],{startRow:y,endRow:T,startColumn:I,endColumn:D}=M;if(S<y||v<I)continue;if(u===p.SheetDrawingAnchorType.Position&&(m<=y&&S>=T||f<=I&&v>=D)){this._remainDrawingSize(h,o,c);continue}const w=V({...l},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...c,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var y,T;const{toRange:r,fromRange:n}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(T=(y=this._renderManagerService.getRenderById(t))==null?void 0:y.with(N.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=N.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:l,endX:h,startY:u,endY:s}=c,g=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(g).forEach(I=>{const D=g[I];if(D.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:w}=D;if(!w)return;const{left:P=0,top:E=0,width:L=0,height:j=0}=w,{drawingStartX:O,drawingEndX:R,drawingStartY:B,drawingEndY:H}={drawingStartX:P,drawingEndX:P+L,drawingStartY:E,drawingEndY:E+j};l<=O&&R<=h&&u<=B&&H<=s&&m.push(D)});const f=[],S=[],v=r.startRow-n.startRow,C=r.startColumn-n.startColumn,M=m.map(I=>{const D=I.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+C},from:{...D.from,row:D.from.row+v,column:D.from.column+C}},P=V(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:I.drawingId,transform:P,sheetTransform:w}});if(M.length){const I=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:w,objects:P}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:P,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:P,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandRow(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{row:w}=I,{row:P}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&P<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(T)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandCol(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{column:w}=I,{column:P}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&P<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(T)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_expandCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)+g.endX-g.startX},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,column:l-o},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:l-1,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(g==null)return;u={from:{...a},to:{...c,column:n-1,columnOffset:g.endX-g.startX}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_expandRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)+g.endY-g.startY},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,row:l-o},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:l-1,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(g==null)return;u={from:{...a},to:{...c,row:n-1,rowOffset:g.endY-g.startY}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const l=t[c];l!=null&&Object.keys(l).forEach(h=>{const u=l[h].data;u!=null&&Object.keys(u).forEach(s=>{if(c===n&&h===e){const g=u[s];g.transform=V(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[s])}else a.push(u[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Xt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:l,anchorType:h=p.SheetDrawingAnchorType.Position}=a;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:s}=c,{row:g,column:m}=u,{row:f,column:S}=s;for(let v=0;v<n.length;v++){const C=n[v],{startRow:M,endRow:y,startColumn:T,endColumn:I}=C;if(d.Rectangle.intersects({startRow:M,endRow:y,startColumn:T,endColumn:I},{startRow:g,endRow:f,startColumn:m,endColumn:S})||g>y||m>I){const D=h===p.SheetDrawingAnchorType.Position,w=V(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:D?l==null?void 0:l.width:w==null?void 0:w.width,height:D?l==null?void 0:l.height:w==null?void 0:w.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Le=Yt([Q(1,U.IRenderManagerService),Q(2,d.ICommandService),Q(3,N.ISheetSelectionRenderService),Q(4,d.Inject(N.SheetSkeletonManagerService)),Q(5,d.Inject(_.SheetInterceptorService)),Q(6,p.ISheetDrawingService),Q(7,A.IDrawingManagerService),Q(8,d.IUniverInstanceService)],Le);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},zt=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},Ze=x.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=zt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),l=x.useRef("_".concat(Zt()));return qe(n,"".concat(e),{defIds:n.defIds,idSuffix:l.current},K({ref:r,className:c},a),o)});function qe(i,r,n,e,t){return x.createElement(i.tag,K(K({key:r},Kt(i,n,t)),e),(Jt(i,n).children||[]).map(function(o,a){return qe(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function Kt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Jt(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Zt(){return Math.random().toString(36).substring(2,8)}Ze.displayName="UniverIcon";var qt={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"}}]},Qe=x.forwardRef(function(i,r){return x.createElement(Ze,Object.assign({},i,{id:"add-image-single",ref:r,icon:qt}))});Qe.displayName="AddImageSingle";const Be={id:"sheet.command.delete-drawing",type:d.CommandType.COMMAND,handler:i=>{const r=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:l,drawingId:h,drawingType:u}=a;return{unitId:c,subUnitId:l,drawingId:h,drawingType:u}});return r.executeCommand(ae.id,{unitId:t,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertCellImage())!=null?e:!1}},oe={id:"sheet.command.move-drawing",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService),t=i.get(N.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,l=a.map(u=>{const{transform:s}=u;if(s==null)return null;const g={...s},{left:m=0,top:f=0}=s;return o===d.Direction.UP?g.top=f-1:o===d.Direction.DOWN?g.top=f+1:o===d.Direction.LEFT?g.left=m-1:o===d.Direction.RIGHT&&(g.left=m+1),{...u,transform:g,sheetTransform:F(g,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(de.id,{unitId:c,drawings:l})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},et="addition-and-subtraction-single",ke="sheet.menu.image";function Qt(i){return{id:ke,type:k.MenuItemType.SUBITEMS,icon:et,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function en(i){return{id:Me.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET)}}function tn(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:k.MenuItemType.BUTTON}}const ee={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function tt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=tt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function De(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=tt(i))&&(e&&(e+=" "),e+=r);return e}const nn=i=>{var y;const r=d.useDependency(d.ICommandService),n=d.useDependency(d.LocaleService),e=d.useDependency(A.IDrawingManagerService),t=d.useDependency(U.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,l=t.getRenderById(c),h=l==null?void 0:l.scene;if(h==null)return;const u=h.getTransformerByCreate(),[s,g]=x.useState(!0),m=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[f,S]=x.useState(m);function v(T,I){const D=[];return T.forEach(w=>{const{oKey:P}=w,E=I.getDrawingOKey(P);if(E==null)return D.push(null),!0;const{unitId:L,subUnitId:j,drawingId:O,drawingType:R,anchorType:B,sheetTransform:H}=E;D.push({unitId:L,subUnitId:j,drawingId:O,anchorType:B,sheetTransform:H,drawingType:R})}),D}x.useEffect(()=>{const T=u.clearControl$.subscribe(D=>{D===!0&&g(!1)}),I=u.changeStart$.subscribe(D=>{var E;const{objects:w}=D,P=v(w,e);if(P.length===0)g(!1);else if(P.length>=1){g(!0);const L=((E=P[0])==null?void 0:E.anchorType)||p.SheetDrawingAnchorType.Position;S(L)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function C(T){S(T);const I=e.getFocusDrawings();if(I.length===0)return;const D=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:T}));r.executeCommand(de.id,{unitId:I[0].unitId,drawings:D})}const M=T=>T?"block":"none";return $.jsxs("div",{className:De(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:M(s)},children:[$.jsx("div",{className:ee.imageCommonPanelRow,children:$.jsx("div",{className:De(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle),children:$.jsx("div",{children:n.t("drawing-anchor.title")})})}),$.jsx("div",{className:De(ee.imageCommonPanelRow),children:$.jsx("div",{className:De(ee.imageCommonPanelColumn),children:$.jsxs(J.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[$.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),$.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),$.jsx(J.Radio,{value:p.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},rn=()=>{const i=d.useDependency(A.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=x.useState(r);return x.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&$.jsxs("div",{className:ee.imageCommonPanel,children:[$.jsx(q.DrawingCommonPanel,{drawings:n}),$.jsx(nn,{drawings:n})]})},on={[k.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:Qt,[Me.id]:{order:0,menuItemFactory:en},[Ge.id]:{order:1,menuItemFactory:tn}}}};function ge(i){return!i.getContextValue(d.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(d.EDITOR_ACTIVATED)&&!i.getContextValue(d.FOCUSING_PANEL_EDITOR)&&i.getContextValue(d.FOCUSING_COMMON_DRAWINGS)}const an={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.DOWN}},sn={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.UP}},cn={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.LEFT}},dn={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.RIGHT}},ln={id:Be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ge,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,mn=(i,r,n,e)=>{for(var t=e>1?void 0:e?gn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&un(r,n,t),t},Re=(i,r)=>(n,e)=>r(n,e,i);let Te=class extends d.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(et,Qe)),this.disposeWithMe(i.register(xe,rn))}_initMenus(){this._menuManagerService.mergeMenu(on)}_initCommands(){[Me,Ge,ce,ae,de,be,G,Ee,Ae,Ne,oe,Be,Ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[an,sn,cn,dn,ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Te=mn([Re(0,d.Inject(k.ComponentManager)),Re(1,k.IMenuManagerService),Re(2,d.ICommandService),Re(3,k.IShortcutService)],Te);var hn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(i,r,n,e)=>{for(var t=e>1?void 0:e?pn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&hn(r,n,t),t},ie=(i,r)=>(n,e)=>r(n,e,i);function Sn(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:l,right:h,top:u,bottom:s}=i,g=e.getFreeze(),{startColumn:m,startRow:f,xSplit:S,ySplit:v}=g,C=n.getNoMergeCellPositionByIndexWithNoHeader(f-v,m-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:y,columnHeaderHeight:T}=n,I=M.startX-C.startX,D=M.startY-C.startY,{top:w,left:P,viewportScrollX:E,viewportScrollY:L}=a;let j,O;l<P?(c.left=!0,j=(I+y+(l-P))*t,O=Math.max(Math.min((I+y+(h-P))*t,(I+y)*t),(h-E)*t)):(c.left=!1,j=Math.max((l-E)*t,(I+y)*t),O=Math.max((h-E)*t,(I+y)*t));let R,B;return u<w?(c.top=!0,R=(D+T+(u-w))*o,B=Math.max(Math.min((D+T+(h-w))*o,(D+T)*o),(s-L)*o)):(c.top=!1,R=Math.max((u-L)*o,(D+T)*o),B=Math.max((s-L)*o,(D+T)*o)),{left:j,right:O,top:R,bottom:B,absolute:c}}const Fe=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:l,angle:h}=i,u={left:o,right:o+c,top:a,bottom:a+l},s=Sn(u,t,n,e),{scaleX:g,scaleY:m}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:h,width:c*g,height:l*m,absolute:s.absolute}};b.SheetCanvasFloatDomManagerService=class extends d.Disposable{constructor(n,e,t,o,a,c,l){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new W.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_add$",new W.Subject);Y(this,"add$",this._add$.asObservable());Y(this,"_remove$",new W.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===d.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ot,at,st;const{unitId:t,subUnitId:o,drawingId:a}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t,d.UniverInstanceType.UNIVER_SHEET);if(!h)return;const u=h.getActiveSheet().getSheetId();if(!l||!c)return;const s=(ot=this._renderManagerService.getRenderById(t))==null?void 0:ot.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:g,drawingType:m,data:f}=l;if(m!==d.DrawingTypeEnum.DRAWING_DOM&&m!==d.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:v,canvas:C}=S;if(g==null)return!0;if(u!==o)return;const{left:M,top:y,width:T,height:I,angle:D,flipX:w,flipY:P,skewX:E,skewY:L}=g,j=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=v.getObject(j);if(O!=null){O.transformByState({left:M,top:y,width:T,height:I,angle:D,flipX:w,flipY:P,skewX:E,skewY:L});return}const R={left:M,top:y,width:T,height:I,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=m===d.DrawingTypeEnum.DRAWING_CHART;B&&(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 H=new U.Rect(j,R);B&&H.setObjectType(U.ObjectType.CHART),v.addObject(H,U.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&v.attachTransformerTo(H);const Z=this._ensureMap(t,o),$e=new d.DisposableCollection,Cn=Fe(H,S.renderObject,s.skeleton,c.worksheet),Ve=new W.BehaviorSubject(Cn),yn={dispose:$e,rect:H,position$:Ve,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ve,id:a,componentKey:l.componentKey,onPointerDown:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{C.dispatchEvent(new WheelEvent(X.type,X))},props:(st=(at=Z.get(a))==null?void 0:at.props)!=null?st:this._getFloatDomProps(a),data:f,unitId:t});const it=H.onTransformChange$.subscribeEvent(()=>{const X=Fe(H,S.renderObject,s.skeleton,c.worksheet);Ve.next(X)});$e.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),it&&$e.add(it),this._domLayerInfoMap.set(a,yn),Z.set(a,{...Z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;const{transformer:h,scene:u}=l,s=u.getObject(c);s!=null&&s.oKey&&h.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),l=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!l||!h||c.forEach(s=>{const g=this._domLayerInfoMap.get(s);if(g){const m=Fe(g.rect,o.renderObject,h.skeleton,l.worksheet);g.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>d.fromEventSubject(e.render.scene.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===N.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{n(c,h)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:c}=n,l=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(N.ISheetSelectionRenderService);if(l==null)return;const h=l.getCellWithCoordByOffset(t,a);if(h==null)return;const u={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:a-h.startY},s=l.getCellWithCoordByOffset(o,c);if(s==null)return;const g={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:u,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==d.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==d.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:l}=c,h=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=l.getObject(h);u&&u instanceof U.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:l,data:h,allowTransform:u=!0}=n,s=e!=null?e:d.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:u};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!h)return;const u=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:s,objects:g}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},b.SheetCanvasFloatDomManagerService=fn([ie(0,d.Inject(U.IRenderManagerService)),ie(1,d.IUniverInstanceService),ie(2,d.Inject(d.ICommandService)),ie(3,A.IDrawingManagerService),ie(4,d.Inject(k.CanvasFloatDomService)),ie(5,p.ISheetDrawingService),ie(6,d.Inject(d.LifecycleService))],b.SheetCanvasFloatDomManagerService);var nt=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,r,n)=>r in i?nt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,wn=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&nt(r,n,t),t},He=(i,r)=>(n,e)=>r(n,e,i),rt=(i,r,n)=>_n(i,typeof r!="symbol"?r+"":r,n);const In="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends d.Plugin{constructor(r=dt,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ct,a)}onStarting(){d.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[Te],[he],[ye],[Ie],[we],[fe],[_e],[Se]]),d.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){d.touchDependencies(this._injector,[[we]])}onRendered(){this._registerRenderModules(),d.touchDependencies(this._injector,[[Ie],[ye],[Te],[fe],[_e],[Se]])}onSteady(){this._injector.get(he)}_registerRenderModules(){[[le],[Le],[Pe]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(d.UniverInstanceType.UNIVER_SHEET,r))})}},rt(b.UniverSheetsDrawingUIPlugin,"type",d.UniverInstanceType.UNIVER_SHEET),rt(b.UniverSheetsDrawingUIPlugin,"pluginName",In),b.UniverSheetsDrawingUIPlugin=wn([d.DependentOn(A.UniverDrawingPlugin,te.UniverDocsDrawingPlugin,q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),He(1,d.Inject(d.Injector)),He(2,U.IRenderManagerService),He(3,d.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=G,b.DeleteDrawingsCommand=Be,b.EditSheetDrawingOperation=Ee,b.GroupSheetDrawingCommand=Ae,b.InsertFloatImageCommand=Me,b.InsertSheetDrawingCommand=ce,b.MoveDrawingsCommand=oe,b.RemoveSheetDrawingCommand=ae,b.SHEETS_IMAGE_MENU_ID=ke,b.SetDrawingArrangeCommand=Ue,b.SetSheetDrawingCommand=de,b.SidebarSheetDrawingOperation=be,b.UngroupSheetDrawingCommand=Ne,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var Xe;function lt(){if(Xe)return se;Xe=1;var i=x,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,l,h){var u,s={},g=null,m=null;h!==void 0&&(g=""+h),l.key!==void 0&&(g=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)e.call(l,u)&&!o.hasOwnProperty(u)&&(s[u]=l[u]);if(c&&c.defaultProps)for(u in l=c.defaultProps,l)s[u]===void 0&&(s[u]=l[u]);return{$$typeof:r,type:c,key:g,ref:m,props:s,_owner:t.current}}return se.Fragment=n,se.jsx=a,se.jsxs=a,se}var ze;function ut(){return ze||(ze=1,Oe.exports=lt()),Oe.exports}var H=ut();const me={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},gt=()=>{const i=d.useDependency(A.IImageIoService),r=d.useDependency(d.LocaleService),[n,e]=x.useState(0);return x.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),H.jsx("div",{style:{display:n>0?"block":"none"},className:me.uploadLoading,children:H.jsxs("div",{className:me.uploadLoadingBody,children:[H.jsx("div",{className:me.uploadLoadingBodyAnimation}),H.jsx("div",{className:me.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var mt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(i,r,n,e)=>{for(var t=e>1?void 0:e?ht(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&mt(r,n,t),t},ne=(i,r)=>(n,e)=>r(n,e,i);let he=class extends d.RxDisposable{constructor(r,n,e,t,o,a,c){super();Y(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(d.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>d.connectInjector(gt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof q.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(d.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const c=a.values().next().value;if(!c)return;const l=c.oKey,h=this._drawingManagerService.getDrawingOKey(l);if(!h)return;const{unitId:u,subUnitId:s,drawingId:g,drawingType:m}=h,f=h.data;if(f&&f.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,s,g,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:q.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,s,g,m)}})),this._drawingManagerService.focusDrawing([{unitId:u,subUnitId:s,drawingId:g}])}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[d.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:Ee.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ae.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:q.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:q.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===d.DrawingTypeEnum.DRAWING_DOM}]}};he=pt([ne(0,d.Inject(d.Injector)),ne(1,A.IDrawingManagerService),ne(2,d.Inject(N.SheetCanvasPopManagerService)),ne(3,U.IRenderManagerService),ne(4,d.IUniverInstanceService),ne(5,d.IContextService),ne(6,d.Inject(k.IUIPartsService))],he);function V(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:l=0,skewY:h=0}=i,{column:u,columnOffset:s,row:g,rowOffset:m}=e,{column:f,columnOffset:S,row:v,rowOffset:C}=t,M=n.getCurrentSkeleton(),y=N.attachRangeWithCoord(M,{startColumn:u,endColumn:u,startRow:g,endRow:g});if(y==null)return;const T=N.attachRangeWithCoord(M,{startColumn:f,endColumn:f,startRow:v,endRow:v});if(T==null)return;const{startX:I,startY:D}=y,{startX:w,startY:P}=T;let E=U.precisionTo(I+s,1),L=U.precisionTo(D+m,1),j=U.precisionTo(w+S-E,1),O=U.precisionTo(P+C-L,1);y.startX===T.endX&&(j=0),y.startY===T.endY&&(O=0);const R=M.rowHeaderWidth+M.columnTotalWidth,B=M.columnHeaderHeight+M.rowTotalHeight;return E+j>R&&(E=R-j),L+O>B&&(L=B-O),{flipY:o,flipX:a,angle:c,skewX:l,skewY:h,left:E,top:L,width:j,height:O}}function F(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:c=!1,angle:l=0,skewX:h=0,skewY:u=0}=i,s=r.getCellWithCoordByOffset(n,e);if(s==null)return;const g={column:s.actualColumn,columnOffset:U.precisionTo(n-s.startX,1),row:s.actualRow,rowOffset:U.precisionTo(e-s.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const f={column:m.actualColumn,columnOffset:U.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:U.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:c,angle:l,skewX:h,skewY:u,from:g,to:f}}var ft=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(i,r,n,e)=>{for(var t=e>1?void 0:e?St(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ft(r,n,t),t},pe=(i,r)=>(n,e)=>r(n,e,i);let Pe=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=V(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Pe=vt([pe(1,p.ISheetDrawingService),pe(2,A.IDrawingManagerService),pe(3,d.Inject(N.ISheetSelectionRenderService)),pe(4,d.Inject(N.SheetSkeletonManagerService))],Pe);function _t(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c}=e,l=U.getGroupState(0,0,t.map(s=>s.transform||{})),h=t.map(s=>{const g=s.transform||{left:0,top:0},{unitId:m,subUnitId:f,drawingId:S}=s;return{unitId:m,subUnitId:f,drawingId:S,transform:{...g,left:g.left-l.left,top:g.top-l.top},groupId:c}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:h})}),r}function wt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:c,transform:l={width:0,height:0}}=e;if(l==null)return;const h=t.map(s=>{const{transform:g}=s,{unitId:m,subUnitId:f,drawingId:S}=s,v=U.transformObjectOutOfGroup(g||{},l,l.width||0,l.height||0);return{unitId:m,subUnitId:f,drawingId:S,transform:v,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:c,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:h})}),r}const Ae={id:"sheet.command.group-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:wt(s),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ce={id:"sheet.command.insert-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var M,y,T;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const a=r.drawings,c=a.map(I=>I.unitId),l=t.getBatchAddOp(a),{unitId:h,subUnitId:u,undo:s,redo:g,objects:m}=l,f=o.onCommandExecute({id:ce.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.INSERT}},v={id:p.SetDrawingApplyMutation.id,params:{op:s,unitId:h,subUnitId:u,objects:m,type:p.DrawingApplyType.REMOVE}};return d.sequenceExecute([...(M=f.preRedos)!=null?M:[],S,...f.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(y=f.preUndos)!=null?y:[],v,...f.undos,{id:G.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:c}]}),!0):!1}},Ue={id:"sheet.command.set-drawing-arrange",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService);if(!r)return!1;const t=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:c,arrangeType:l}=r,h={unitId:o,subUnitId:a,drawingIds:c};let u;if(l===d.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(h):l===d.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(h):l===d.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(h):l===d.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(h)),u==null)return!1;const{objects:s,redo:g,undo:m}=u;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:s,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},de={id:"sheet.command.set-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:h,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:l,op:u,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[c]}]}),!0):!1}},Ne={id:"sheet.command.ungroup-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:f})=>{o.push(m.unitId),f.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:c,subUnitId:l,undo:h,redo:u,objects:s}=a;return n.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:l,objects:_t(s),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:s,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ct(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&It(r,n,t),t},z=(i,r)=>(n,e)=>r(n,e,i);function Mt(i,r,n){const e=n*Math.PI/180,t=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Ke(i,r,n,e,t){var M;const{rotatedHeight:o,rotatedWidth:a}=Mt(n,e,t),l=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(M=l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:M.skeleton;if(u==null)return!1;const s=u.getCellByIndex(r.row,r.col),g=s.mergeInfo.endX-s.mergeInfo.startX-2,m=s.mergeInfo.endY-s.mergeInfo.startY-2,f=a/o,v=Math.ceil(Math.min(g,m*f))/a,C=!v||Number.isNaN(v)?.001:v;return{width:n*C,height:e*C}}let le=class extends d.Disposable{constructor(r,n,e,t,o,a,c,l,h,u,s,g,m){super();Y(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=l,this._contextService=h,this._messageService=u,this._localeService=s,this._injector=m,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>A.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(A.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:A.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(M){const y=M.message;y===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(A.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===A.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:c,source:l,base64Cache:h}=n,{width:u,height:s,image:g}=await A.getImageSize(h||""),{width:m,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(l,c,g);let S=1;if(u>A.DRAWING_IMAGE_WIDTH_LIMIT||s>A.DRAWING_IMAGE_HEIGHT_LIMIT){const M=A.DRAWING_IMAGE_WIDTH_LIMIT/u,y=A.DRAWING_IMAGE_HEIGHT_LIMIT/s;S=Math.max(M,y)}const v=this._getImagePosition(u*S,s*S,m,f);if(v==null)return;const C={unitId:t,subUnitId:o,drawingId:a,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:l,transform:V(v,this._selectionRenderService,this._skeletonManagerService),sheetTransform:v};this._commandService.executeCommand(ce.id,{unitId:t,drawings:[C]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(v){const C=v.message;C===A.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:J.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:J.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===A.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:J.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:c,height:l,image:h}=await A.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,h);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const s=d.createDocumentModelWithStyle("",{}),g=Ke(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},c,l,0);if(!g)return!1;const m={size:{width:g.width,height:g.height},positionH:{relativeFrom:d.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:d.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:s.getUnitId(),subUnitId:s.getUnitId(),drawingId:e,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Ye.docDrawingPositionToTransform(m),docTransform:m,behindDoc:d.BooleanNumber.FALSE,title:"",description:"",layoutType:d.PositionedObjectLayoutType.INLINE,wrapText:d.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=d.BuildTextUtils.drawing.add({documentDataModel:s,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(s.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:s.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const c=N.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:l,startRow:h,startX:u,startY:s}=c,g=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),g=!0),s+n>t&&(s=t-n,s<0&&(s=0,n=t),g=!0),g){const v=this._selectionRenderService.getCellWithCoordByOffset(u,s);if(v==null)return;u=v.startX,s=v.startY,l=v.actualColumn,h=v.actualRow}const m={column:l,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+r,s+n);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+r-f.startX,row:f.actualRow,rowOffset:s+n-f.startY};return{from:m,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(Ue.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:c,transform:l}=e;if(l==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(h==null||h.unitId!==this._context.unitId)return;const u=F({...h.transform,...l},this._selectionRenderService);if(u==null)return;const s={...e,transform:{...h.transform,...l,...V(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(s)}),n.length>0&&this._commandService.executeCommand(de.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ae.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._drawingManagerService.focusDrawing([{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(Ne.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};le=yt([z(1,d.Inject(N.SheetSkeletonManagerService)),z(2,d.ICommandService),z(3,N.ISheetSelectionRenderService),z(4,A.IImageIoService),z(5,k.ILocalFileService),z(6,p.ISheetDrawingService),z(7,A.IDrawingManagerService),z(8,d.IContextService),z(9,k.IMessageService),z(10,d.Inject(d.LocaleService)),z(11,d.Inject(_.SheetsSelectionsService)),z(12,d.Inject(d.Injector))],le);var Dt=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Tt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Rt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Dt(r,n,t),t},re=(i,r)=>(n,e)=>r(n,e,i);function je(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const c=n.p.drawings[n.p.drawingsOrder[0]],l=Ke(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(l)return c.transform.width=l.width,c.transform.height=l.height,c.docTransform.size.width=l.width,c.docTransform.size.height=l.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let fe=class extends d.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===_.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===_.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===_.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=d.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Ye.ReplaceSnapshotCommand.id&&i.params.unitId===d.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(je(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:d.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};fe=Tt([re(0,d.ICommandService),re(1,d.Inject(_.SheetInterceptorService)),re(2,d.IUniverInstanceService),re(3,d.Inject(d.Injector)),re(4,A.IDrawingManagerService),re(5,d.Inject(te.DocDrawingController)),re(6,d.Inject(N.IEditorBridgeService))],fe);var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Ot=(i,r,n,e)=>{for(var t=e>1?void 0:e?Et(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&bt(r,n,t),t},Je=(i,r)=>(n,e)=>r(n,e,i);let Se=class extends d.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,n,e)=>{new d.ObjectMatrix(e).forValue((t,o,a)=>{je(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};Se=Ot([Je(0,d.Inject(N.IAutoFillService)),Je(1,d.Inject(d.Injector))],Se);var Pt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,Ut=(i,r,n,e)=>{for(var t=e>1?void 0:e?At(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Pt(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);let _e=class extends d.Disposable{constructor(r,n,e,t){super();Y(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};_e=Ut([ve(0,d.Inject(N.HoverManagerService)),ve(1,d.Inject(U.IRenderManagerService)),ve(2,d.Inject(_.SheetsSelectionsService)),ve(3,d.Inject(q.DrawingRenderService))],_e);var Nt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Wt=(i,r,n,e)=>{for(var t=e>1?void 0:e?jt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Nt(r,n,t),t},We=(i,r)=>(n,e)=>r(n,e,i);let we=class extends d.Disposable{constructor(r,n,e){super();Y(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:a}=t,{range:c}=r||{},{range:l,unitId:h,subUnitId:u}=n;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:c,unitId:h,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var g;const t=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(N.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:c,startY:l,endY:h}=o,u=this._sheetDrawingService.getDrawingData(r,n),s=[];Object.keys(u).forEach(m=>{const f=u[m],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:v=0,top:C=0,width:M=0,height:y=0}=S,{drawingStartX:T,drawingEndX:I,drawingStartY:D,drawingEndY:w}={drawingStartX:v,drawingEndX:v+M,drawingStartY:C,drawingEndY:C+y};a<=T&&I<=c&&l<=D&&w<=h&&s.push(f)}),s.length&&(this._copyInfo={drawings:s,unitId:r,subUnitId:n})}_generateMutations(r,n){var E;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(n.pasteType))return{redos:[],undos:[]};const{copyRange:e}=n;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:a}=this._copyInfo,{ranges:[c,l],mapFunc:h}=N.virtualizeDiscreteRanges([e,r]),{row:u,col:s}=h(c.startRow,c.startColumn),{row:g,col:m}=h(l.startRow,l.startColumn),f=(E=this._renderManagerService.getRenderById(o))==null?void 0:E.with(N.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const S=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:s,endColumn:s}),v=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:m,endColumn:m});if(!S||!v)return{redos:[],undos:[]};const C=[],M=[],y=v.startX-S.startX,T=v.startY-S.startY,I=g-u,D=m-s,w=n.copyType===N.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return t.forEach(L=>{const{transform:j,sheetTransform:O}=L;if(!j)return;const R={...L,unitId:o,subUnitId:a,drawingId:w?L.drawingId:d.Tools.generateRandomId(),transform:{...j,left:j.left+y,top:j.top+T},sheetTransform:{to:{...O.to,row:O.to.row+I,column:O.to.column+D},from:{...O.from,row:O.from.row+I,column:O.from.column+D}}};if(w){const{undo:B,redo:$,objects:Z}=P.getBatchUpdateOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:$,objects:Z}}),M.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:B,objects:Z}})}else{const{undo:B,redo:$,objects:Z}=P.getBatchAddOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:$,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.INSERT}}),M.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:a,objects:Z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:M}}};we=Wt([We(0,N.ISheetClipboardService),We(1,U.IRenderManagerService),We(2,p.ISheetDrawingService)],we);var Lt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Gt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Bt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},ue=(i,r)=>(n,e)=>r(n,e,i);let Ie=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,l),u=Object.values(h),s=this._renderManagerService.getRenderById(c),g=s==null?void 0:s.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(W.map(g=>g.every(m=>m.value)));u==null||u.pipe(W.filter(g=>g!==a),W.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingVisible(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?this._drawingManagerService.addNotification(S):(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.removeObject(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||s.pipe(W.filter(g=>g.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(t,o),m=Object.values(g);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var s;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const c=this._renderManagerService.getRenderById(t),l=c==null?void 0:c.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(W.map(g=>g.every(m=>m.value)));u==null||u.pipe(W.filter(g=>g!==a),W.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingEditable(g);const m=l.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),S=Object.values(f);g?(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.attachTransformerTo(v)}),this._drawingManagerService.addNotification(S)):(m.forEach(v=>{v.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(C=>v.oKey.includes(C.drawingId))&&l.detachTransformerFrom(v)}),h.clearSelectedObjects())}}),(s=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||s.pipe(W.filter(g=>g.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const g=r.getUnitId(),m=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,m),S=Object.values(f),v=this._renderManagerService.getRenderById(g),C=v==null?void 0:v.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(y=>{y.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>y.oKey.includes(T.drawingId))&&C.detachTransformerFrom(y)})}})})}))}};Ie=Gt([ue(0,A.IDrawingManagerService),ue(1,U.IRenderManagerService),ue(2,d.IPermissionService),ue(3,d.IUniverInstanceService),ue(4,d.Inject(d.UserManagerService))],Ie);var kt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,$t=(i,r,n,e)=>{for(var t=e>1?void 0:e?Ft(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&kt(r,n,t),t},Ce=(i,r)=>(n,e)=>r(n,e,i);let ye=class extends d.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),c=a==null?void 0:a[o];return c&&c.order.forEach(l=>{this._drawingRenderService.renderDrawing(c.data[l],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),l=c==null?void 0:c[r.subUnitId];if(!l)return n(i);const{scaleX:h,scaleY:u}=o.scene,s=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=l.order.map(m=>l.data[m]).filter(m=>m.drawingType!==d.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(m=>{if(!m.groupId&&m.transform&&d.Tools.isDefine(m.transform.left)&&d.Tools.isDefine(m.transform.top)&&d.Tools.isDefine(m.transform.width)&&d.Tools.isDefine(m.transform.height)){const f=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,h,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,h,u,{x:0,y:0});f.column<s.startColumn&&(s.startColumn=f.column),f.row<s.startRow&&(s.startRow=f.row),s.endRow<S.row&&(s.endRow=S.row),s.endColumn<S.column&&(s.endColumn=S.column)}}),n(s)):n(i)}}))}};ye=$t([Ce(0,d.Inject(N.SheetPrintInterceptorService)),Ce(1,d.Inject(q.DrawingRenderService)),Ce(2,A.IDrawingManagerService),Ce(3,U.IRenderManagerService)],ye);var Ht=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Yt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Vt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Ht(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);const xt=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],Xt=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let Le=class extends d.Disposable{constructor(i,r,n,e,t,o,a,c,l){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=c,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!xt.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===_.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===_.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===_.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===_.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===_.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===_.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===_.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===_.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===_.SetRowHiddenCommand.id||r===_.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===_.SetSpecificColsVisibleCommand.id||r===_.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id||r===_.DeltaColumnWidthCommand.id||r===_.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===_.DeltaRowHeightCommand.id||r===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],c=this._sheetDrawingService.getDrawingData(e,t),l=[],h=[];if(Object.keys(c).forEach(u=>{const s=c[u],{updateDrawings:g,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,s);l.push(...g),h.push(...m)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:s,redo:g,objects:m}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.UPDATE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(h),s=u.undo,g=u.redo,m=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:p.DrawingApplyType.REMOVE}}),a.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:s,objects:m,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),a.push({id:G.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=p.SheetDrawingAnchorType.Position,transform:c,unitId:l,subUnitId:h,drawingId:u}=n,{from:s,to:g}=o,{row:m,column:f}=s,{row:S,column:v}=g;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:C,endRow:M,startColumn:y,endColumn:T}=i;let I=null,D=null;if(r===0&&m>=C&&S<=M)if(f>=y&&v<=T)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkCol(o,c,y,T,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===1&&f>=y&&v<=T)if(m>=C&&S<=M)t.push({unitId:l,subUnitId:h,drawingId:u});else{const w=this._shrinkRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===2){const w=this._expandRow(o,c,C,M,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}else if(r===3){const w=this._expandCol(o,c,y,T,a);I=w==null?void 0:w.newSheetTransform,D=w==null?void 0:w.newTransform}if(I!=null&&D!=null){const w=V(I,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:I,transform:w})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:T}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:P,startColumn:E,endColumn:L}=D;if(T<E)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,B=null;if(M>=E&&M<=L){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if($==null)return;B={...m,left:$.startX}}if(B!=null&&(R=F(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(M>=E&&T<=L)continue;let j=null,O=null;if(M>=E&&M<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:M,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;O={...m,left:(R==null?void 0:R.startX)||0,width:((m==null?void 0:m.width)||0)-R.endX+R.startX}}else if(T>=E&&T<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:T,startRow:S.row,endRow:v.row});if(R==null)return;O={...m,left:R.startX-((m==null?void 0:m.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:L,startRow:S.row,endRow:v.row});if(R==null)return;if(O={...m,width:((m==null?void 0:m.width)||0)-R.endX+R.startX},j=F(O,this._selectionRenderService),j!=null&&O!=null){o.push({...s,sheetTransform:j,transform:O});break}}if(O!=null&&(j=F(O,this._selectionRenderService)),O!=null&&j!=null){t.push({...s,sheetTransform:j,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],l=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:c,undos:l}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const s=e[u],{sheetTransform:g,transform:m,anchorType:f=p.SheetDrawingAnchorType.Position}=s;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,s);else{const{from:S,to:v}=g,{row:C,column:M}=S,{row:y,column:T}=v;for(let I=0;I<n.length;I++){const D=n[I],{startRow:w,endRow:P,startColumn:E,endColumn:L}=D;if(y<w)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,B=null;if(C>=w&&C<=P){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:P});if($==null)return;B={...m,top:$.startY}}if(B!=null&&(R=F(B,this._selectionRenderService),R!=null&&B!=null)){t.push({...s,sheetTransform:R,transform:B});break}this._remainDrawingSize(m,t,s);continue}if(C>=w&&y<=P)continue;let j=null,O=null;if(C>=w&&C<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:C,endRow:P});if(R==null)return;O={...m,top:(R==null?void 0:R.startY)||0,height:((m==null?void 0:m.height)||0)-R.endY+R.startY}}else if(y>=w&&y<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:y});if(R==null)return;O={...m,top:R.startY-((m==null?void 0:m.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:v.column,startRow:w,endRow:P});if(R==null)return;if(O={...m,height:((m==null?void 0:m.height)||0)-R.endY+R.startY},j=F(O,this._selectionRenderService),j!=null&&O!=null){o.push({...s,sheetTransform:j,transform:O});break}}if(O!=null&&(j=F(O,this._selectionRenderService)),O!=null&&j!=null){t.push({...s,sheetTransform:j,transform:O});break}else this._remainDrawingSize(m,t,s)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:c}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:s}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...s)}return{redos:a,undos:c,preRedos:l,preUndos:h}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const c=t[a],{sheetTransform:l,transform:h,anchorType:u=p.SheetDrawingAnchorType.Position}=c;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:s,to:g}=l,{row:m,column:f}=s,{row:S,column:v}=g;for(let C=0;C<n.length;C++){const M=n[C],{startRow:y,endRow:T,startColumn:I,endColumn:D}=M;if(S<y||v<I)continue;if(u===p.SheetDrawingAnchorType.Position&&(m<=y&&S>=T||f<=I&&v>=D)){this._remainDrawingSize(h,o,c);continue}const w=V({...l},this._selectionRenderService,this._skeletonManagerService);if(w!=null){o.push({...c,transform:w});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var y,T;const{toRange:r,fromRange:n}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(T=(y=this._renderManagerService.getRenderById(t))==null?void 0:y.with(N.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const c=N.attachRangeWithCoord(a,n);if(!c)return{redos:[],undos:[]};const{startX:l,endX:h,startY:u,endY:s}=c,g=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(g).forEach(I=>{const D=g[I];if(D.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:w}=D;if(!w)return;const{left:P=0,top:E=0,width:L=0,height:j=0}=w,{drawingStartX:O,drawingEndX:R,drawingStartY:B,drawingEndY:$}={drawingStartX:P,drawingEndX:P+L,drawingStartY:E,drawingEndY:E+j};l<=O&&R<=h&&u<=B&&$<=s&&m.push(D)});const f=[],S=[],v=r.startRow-n.startRow,C=r.startColumn-n.startColumn,M=m.map(I=>{const D=I.sheetTransform,w={to:{...D.to,row:D.to.row+v,column:D.to.column+C},from:{...D.from,row:D.from.row+v,column:D.from.column+C}},P=V(w,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:I.drawingId,transform:P,sheetTransform:w}});if(M.length){const I=this._sheetDrawingService.getBatchUpdateOp(M),{undo:D,redo:w,objects:P}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:w,objects:P,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:D,objects:P,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,c=o.endRow,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandRow(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{row:w}=I,{row:P}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&P<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(T)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,c=o.endColumn,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),s=[],g=[];if(Object.keys(u).forEach(m=>{const f=u[m],{sheetTransform:S,transform:v,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(S==null||v==null)return;let M,y;if(r==="insert"){const I=this._expandCol(S,v,a,c,C);M=I==null?void 0:I.newSheetTransform,y=I==null?void 0:I.newTransform}else{const{from:I,to:D}=S,{column:w}=I,{column:P}=D;if(C===p.SheetDrawingAnchorType.Both&&w>=a&&P<=c)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(S,v,a,c,C);M=E==null?void 0:E.newSheetTransform,y=E==null?void 0:E.newTransform}}if(!M||!y)return;const T={unitId:e,subUnitId:t,drawingId:m,transform:y,sheetTransform:M};s.push(T)}),s.length===0&&g.length===0)return{redos:[],undos:[]};if(s.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(s),{undo:f,redo:S,objects:v}=m;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),f=m.undo,S=m.redo,v=m.objects;l.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:v,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:v,type:p.DrawingApplyType.INSERT}})}return l.push({id:G.id,params:[e]}),h.push({id:G.id,params:[e]}),{redos:l,undos:h}}_expandCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)+g.endX-g.startX},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkCol(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{column:l}=a,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,column:l-o},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,column:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,left:(r.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:l-1,startRow:a.row,endRow:c.row});if(g==null)return;s={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:c.row});if(g==null)return;u={from:{...a},to:{...c,column:n-1,columnOffset:g.endX-g.startX}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_expandRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)+g.endY-g.startY},u=F(s,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h+o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_shrinkRow(i,r,n,e,t=p.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:c}=i,{row:l}=a,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,s=null;if(l>e)u={from:{...a,row:l-o},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===p.SheetDrawingAnchorType.Both)u={from:{...a},to:{...c,row:h-o}},s=V(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)s={...r,top:(r.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:l-1,startColumn:a.column,endColumn:c.column});if(g==null)return;s={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}u=F(s,this._selectionRenderService)}else if(h>=n&&h<=e&&t===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(g==null)return;u={from:{...a},to:{...c,row:n-1,rowOffset:g.endY-g.startY}},s=V(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&s!=null?{newSheetTransform:u,newTransform:s}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(c=>{const l=t[c];l!=null&&Object.keys(l).forEach(h=>{const u=l[h].data;u!=null&&Object.keys(u).forEach(s=>{if(c===n&&h===e){const g=u[s];g.transform=V(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[s])}else a.push(u[s])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Xt.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:c,transform:l,anchorType:h=p.SheetDrawingAnchorType.Position}=a;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:s}=c,{row:g,column:m}=u,{row:f,column:S}=s;for(let v=0;v<n.length;v++){const C=n[v],{startRow:M,endRow:y,startColumn:T,endColumn:I}=C;if(d.Rectangle.intersects({startRow:M,endRow:y,startColumn:T,endColumn:I},{startRow:g,endRow:f,startColumn:m,endColumn:S})||g>y||m>I){const D=h===p.SheetDrawingAnchorType.Position,w=V(c,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...w,width:D?l==null?void 0:l.width:w==null?void 0:w.width,height:D?l==null?void 0:l.height:w==null?void 0:w.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};Le=Yt([Q(1,U.IRenderManagerService),Q(2,d.ICommandService),Q(3,N.ISheetSelectionRenderService),Q(4,d.Inject(N.SheetSkeletonManagerService)),Q(5,d.Inject(_.SheetInterceptorService)),Q(6,p.ISheetDrawingService),Q(7,A.IDrawingManagerService),Q(8,d.IUniverInstanceService)],Le);var K=function(){return K=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},K.apply(this,arguments)},zt=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},Ze=x.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=zt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),l=x.useRef("_".concat(Zt()));return qe(n,"".concat(e),{defIds:n.defIds,idSuffix:l.current},K({ref:r,className:c},a),o)});function qe(i,r,n,e,t){return x.createElement(i.tag,K(K({key:r},Kt(i,n,t)),e),(Jt(i,n).children||[]).map(function(o,a){return qe(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function Kt(i,r,n){var e=K({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Jt(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?K(K({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?K(K({},t),{attrs:K(K({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Zt(){return Math.random().toString(36).substring(2,8)}Ze.displayName="UniverIcon";var qt={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"}}]},Qe=x.forwardRef(function(i,r){return x.createElement(Ze,Object.assign({},i,{id:"add-image-single",ref:r,icon:qt}))});Qe.displayName="AddImageSingle";const Be={id:"sheet.command.delete-drawing",type:d.CommandType.COMMAND,handler:i=>{const r=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:c,subUnitId:l,drawingId:h,drawingType:u}=a;return{unitId:c,subUnitId:l,drawingId:h,drawingType:u}});return r.executeCommand(ae.id,{unitId:t,drawings:o})}},Me={id:"sheet.command.insert-float-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertFloatImage())!=null?e:!1}},Ge={id:"sheet.command.insert-cell-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(le).insertCellImage())!=null?e:!1}},oe={id:"sheet.command.move-drawing",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(p.ISheetDrawingService),t=i.get(N.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const c=a[0].unitId,l=a.map(u=>{const{transform:s}=u;if(s==null)return null;const g={...s},{left:m=0,top:f=0}=s;return o===d.Direction.UP?g.top=f-1:o===d.Direction.DOWN?g.top=f+1:o===d.Direction.LEFT?g.left=m-1:o===d.Direction.RIGHT&&(g.left=m+1),{...u,transform:g,sheetTransform:F(g,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(de.id,{unitId:c,drawings:l})?(n.syncExecuteCommand(G.id,[c]),!0):!1}},et="addition-and-subtraction-single",ke="sheet.menu.image";function Qt(i){return{id:ke,type:k.MenuItemType.SUBITEMS,icon:et,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function en(i){return{id:Me.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET)}}function tn(i){return{id:Ge.id,title:"sheetImage.upload.cell",type:k.MenuItemType.BUTTON}}const ee={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function tt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=tt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function De(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=tt(i))&&(e&&(e+=" "),e+=r);return e}const nn=i=>{var y;const r=d.useDependency(d.ICommandService),n=d.useDependency(d.LocaleService),e=d.useDependency(A.IDrawingManagerService),t=d.useDependency(U.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:c}=a,l=t.getRenderById(c),h=l==null?void 0:l.scene;if(h==null)return;const u=h.getTransformerByCreate(),[s,g]=x.useState(!0),m=(y=a.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[f,S]=x.useState(m);function v(T,I){const D=[];return T.forEach(w=>{const{oKey:P}=w,E=I.getDrawingOKey(P);if(E==null)return D.push(null),!0;const{unitId:L,subUnitId:j,drawingId:O,drawingType:R,anchorType:B,sheetTransform:$}=E;D.push({unitId:L,subUnitId:j,drawingId:O,anchorType:B,sheetTransform:$,drawingType:R})}),D}x.useEffect(()=>{const T=u.clearControl$.subscribe(D=>{D===!0&&g(!1)}),I=u.changeStart$.subscribe(D=>{var E;const{objects:w}=D,P=v(w,e);if(P.length===0)g(!1);else if(P.length>=1){g(!0);const L=((E=P[0])==null?void 0:E.anchorType)||p.SheetDrawingAnchorType.Position;S(L)}});return()=>{I.unsubscribe(),T.unsubscribe()}},[]);function C(T){S(T);const I=e.getFocusDrawings();if(I.length===0)return;const D=I.map(w=>({unitId:w.unitId,subUnitId:w.subUnitId,drawingId:w.drawingId,anchorType:T}));r.executeCommand(de.id,{unitId:I[0].unitId,drawings:D})}const M=T=>T?"block":"none";return H.jsxs("div",{className:De(ee.imageCommonPanelGrid,ee.imageCommonPanelBorder),style:{display:M(s)},children:[H.jsx("div",{className:ee.imageCommonPanelRow,children:H.jsx("div",{className:De(ee.imageCommonPanelColumn,ee.imageCommonPanelTitle),children:H.jsx("div",{children:n.t("drawing-anchor.title")})})}),H.jsx("div",{className:De(ee.imageCommonPanelRow),children:H.jsx("div",{className:De(ee.imageCommonPanelColumn),children:H.jsxs(J.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),H.jsx(J.Radio,{value:p.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},rn=()=>{const i=d.useDependency(A.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=x.useState(r);return x.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&H.jsxs("div",{className:ee.imageCommonPanel,children:[H.jsx(q.DrawingCommonPanel,{drawings:n}),H.jsx(nn,{drawings:n})]})},on={[k.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:Qt,[Me.id]:{order:0,menuItemFactory:en},[Ge.id]:{order:1,menuItemFactory:tn}}}};function ge(i){return!i.getContextValue(d.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(d.EDITOR_ACTIVATED)&&!i.getContextValue(d.FOCUSING_PANEL_EDITOR)&&i.getContextValue(d.FOCUSING_COMMON_DRAWINGS)}const an={id:oe.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.DOWN}},sn={id:oe.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.UP}},cn={id:oe.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.LEFT}},dn={id:oe.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:ge,staticParameters:{direction:d.Direction.RIGHT}},ln={id:Be.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ge,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,mn=(i,r,n,e)=>{for(var t=e>1?void 0:e?gn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&un(r,n,t),t},Re=(i,r)=>(n,e)=>r(n,e,i);let Te=class extends d.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(et,Qe)),this.disposeWithMe(i.register(xe,rn))}_initMenus(){this._menuManagerService.mergeMenu(on)}_initCommands(){[Me,Ge,ce,ae,de,be,G,Ee,Ae,Ne,oe,Be,Ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[an,sn,cn,dn,ln].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Te=mn([Re(0,d.Inject(k.ComponentManager)),Re(1,k.IMenuManagerService),Re(2,d.ICommandService),Re(3,k.IShortcutService)],Te);var hn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(i,r,n,e)=>{for(var t=e>1?void 0:e?pn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&hn(r,n,t),t},ie=(i,r)=>(n,e)=>r(n,e,i);function Sn(i,r,n,e){const{scaleX:t,scaleY:o}=r.getAncestorScale(),a=r.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!a)return{...i,absolute:c};const{left:l,right:h,top:u,bottom:s}=i,g=e.getFreeze(),{startColumn:m,startRow:f,xSplit:S,ySplit:v}=g,C=n.getNoMergeCellPositionByIndexWithNoHeader(f-v,m-S),M=n.getNoMergeCellPositionByIndexWithNoHeader(f,m),{rowHeaderWidth:y,columnHeaderHeight:T}=n,I=M.startX-C.startX,D=M.startY-C.startY,{top:w,left:P,viewportScrollX:E,viewportScrollY:L}=a;let j,O;l<P?(c.left=!0,j=(I+y+(l-P))*t,O=Math.max(Math.min((I+y+(h-P))*t,(I+y)*t),(h-E)*t)):(c.left=!1,j=Math.max((l-E)*t,(I+y)*t),O=Math.max((h-E)*t,(I+y)*t));let R,B;return u<w?(c.top=!0,R=(D+T+(u-w))*o,B=Math.max(Math.min((D+T+(h-w))*o,(D+T)*o),(s-L)*o)):(c.top=!1,R=Math.max((u-L)*o,(D+T)*o),B=Math.max((s-L)*o,(D+T)*o)),{left:j,right:O,top:R,bottom:B,absolute:c}}const Fe=(i,r,n,e)=>{const{scene:t}=r,{left:o,top:a,width:c,height:l,angle:h}=i,u={left:o,right:o+c,top:a,bottom:a+l},s=Sn(u,t,n,e),{scaleX:g,scaleY:m}=t.getAncestorScale();return{startX:s.left,endX:s.right,startY:s.top,endY:s.bottom,rotate:h,width:c*g,height:l*m,absolute:s.absolute}};b.SheetCanvasFloatDomManagerService=class extends d.Disposable{constructor(n,e,t,o,a,c,l){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new W.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_add$",new W.Subject);Y(this,"add$",this._add$.asObservable());Y(this,"_remove$",new W.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=c,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===d.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ot,at,st;const{unitId:t,subUnitId:o,drawingId:a}=e,c=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t,d.UniverInstanceType.UNIVER_SHEET);if(!h)return;const u=h.getActiveSheet().getSheetId();if(!l||!c)return;const s=(ot=this._renderManagerService.getRenderById(t))==null?void 0:ot.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!s)return;const{transform:g,drawingType:m,data:f}=l;if(m!==d.DrawingTypeEnum.DRAWING_DOM&&m!==d.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:v,canvas:C}=S;if(g==null)return!0;if(u!==o)return;const{left:M,top:y,width:T,height:I,angle:D,flipX:w,flipY:P,skewX:E,skewY:L}=g,j=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),O=v.getObject(j);if(O!=null){O.transformByState({left:M,top:y,width:T,height:I,angle:D,flipX:w,flipY:P,skewX:E,skewY:L});return}const R={left:M,top:y,width:T,height:I,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=m===d.DrawingTypeEnum.DRAWING_CHART;B&&(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 $=new U.Rect(j,R);B&&$.setObjectType(U.ObjectType.CHART),v.addObject($,U.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&v.attachTransformerTo($);const Z=this._ensureMap(t,o),He=new d.DisposableCollection,Cn=Fe($,S.renderObject,s.skeleton,c.worksheet),Ve=new W.BehaviorSubject(Cn),yn={dispose:He,rect:$,position$:Ve,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ve,id:a,componentKey:l.componentKey,onPointerDown:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{C.dispatchEvent(new PointerEvent(X.type,X))},onWheel:X=>{C.dispatchEvent(new WheelEvent(X.type,X))},props:(st=(at=Z.get(a))==null?void 0:at.props)!=null?st:this._getFloatDomProps(a),data:f,unitId:t});const it=$.onTransformChange$.subscribeEvent(()=>{const X=Fe($,S.renderObject,s.skeleton,c.worksheet);Ve.next(X)});He.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),it&&He.add(it),this._domLayerInfoMap.set(a,yn),Z.set(a,{...Z.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,c=A.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;const{transformer:h,scene:u}=l,s=u.getObject(c);s!=null&&s.oKey&&h.clearControlByIds([s==null?void 0:s.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),c=Array.from(a.keys()),l=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!l||!h||c.forEach(s=>{const g=this._domLayerInfoMap.get(s);if(g){const m=Fe(g.rect,o.renderObject,h.skeleton,l.worksheet);g.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>d.fromEventSubject(e.render.scene.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===N.SetZoomRatioOperation.id){const a=e.params,{unitId:c}=a;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{n(c,h)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:c}=e.params;n(a,c)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:c}=n,l=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(N.ISheetSelectionRenderService);if(l==null)return;const h=l.getCellWithCoordByOffset(t,a);if(h==null)return;const u={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:a-h.startY},s=l.getCellWithCoordByOffset(o,c);if(s==null)return;const g={column:s.actualColumn,columnOffset:o-s.startX,row:s.actualRow,rowOffset:c-s.startY};return{from:u,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==d.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==d.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(n);if(a&&c){const{scene:l}=c,h=A.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=l.getObject(h);u&&u instanceof U.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:c,componentKey:l,data:h,allowTransform:u=!0}=n,s=e!=null?e:d.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,a).set(s,n);const f={unitId:o,subUnitId:a,drawingId:s,drawingType:n.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:u};return this._commandService.executeCommand(ce.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:a,id:s}),{id:s,dispose:()=>{this._removeDom(s,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!h)return;const u=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:s,objects:g}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:s,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}},b.SheetCanvasFloatDomManagerService=fn([ie(0,d.Inject(U.IRenderManagerService)),ie(1,d.IUniverInstanceService),ie(2,d.Inject(d.ICommandService)),ie(3,A.IDrawingManagerService),ie(4,d.Inject(k.CanvasFloatDomService)),ie(5,p.ISheetDrawingService),ie(6,d.Inject(d.LifecycleService))],b.SheetCanvasFloatDomManagerService);var nt=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,r,n)=>r in i?nt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,wn=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&nt(r,n,t),t},$e=(i,r)=>(n,e)=>r(n,e,i),rt=(i,r,n)=>_n(i,typeof r!="symbol"?r+"":r,n);const In="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends d.Plugin{constructor(r=dt,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ct,a)}onStarting(){d.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[Te],[he],[ye],[Ie],[we],[fe],[_e],[Se]]),d.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){d.touchDependencies(this._injector,[[we]])}onRendered(){this._registerRenderModules(),d.touchDependencies(this._injector,[[Ie],[ye],[Te],[fe],[_e],[Se]])}onSteady(){this._injector.get(he)}_registerRenderModules(){[[le],[Le],[Pe]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(d.UniverInstanceType.UNIVER_SHEET,r))})}},rt(b.UniverSheetsDrawingUIPlugin,"type",d.UniverInstanceType.UNIVER_SHEET),rt(b.UniverSheetsDrawingUIPlugin,"pluginName",In),b.UniverSheetsDrawingUIPlugin=wn([d.DependentOn(A.UniverDrawingPlugin,te.UniverDocsDrawingPlugin,q.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),$e(1,d.Inject(d.Injector)),$e(2,U.IRenderManagerService),$e(3,d.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=G,b.DeleteDrawingsCommand=Be,b.EditSheetDrawingOperation=Ee,b.GroupSheetDrawingCommand=Ae,b.InsertFloatImageCommand=Me,b.InsertSheetDrawingCommand=ce,b.MoveDrawingsCommand=oe,b.RemoveSheetDrawingCommand=ae,b.SHEETS_IMAGE_MENU_ID=ke,b.SetDrawingArrangeCommand=Ue,b.SetSheetDrawingCommand=de,b.SidebarSheetDrawingOperation=be,b.UngroupSheetDrawingCommand=Ne,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.5.1-nightly.
|
|
3
|
+
"version": "0.5.1-nightly.202412041606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@univerjs/icons": "^0.2.8",
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
|
-
"@univerjs/core": "0.5.1-nightly.
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/drawing": "0.5.1-nightly.
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/engine-render": "0.5.1-nightly.
|
|
69
|
-
"@univerjs/sheets": "0.5.1-nightly.
|
|
70
|
-
"@univerjs/sheets-drawing": "0.5.1-nightly.
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/ui": "0.5.1-nightly.
|
|
62
|
+
"@univerjs/core": "0.5.1-nightly.202412041606",
|
|
63
|
+
"@univerjs/design": "0.5.1-nightly.202412041606",
|
|
64
|
+
"@univerjs/docs-drawing": "0.5.1-nightly.202412041606",
|
|
65
|
+
"@univerjs/drawing": "0.5.1-nightly.202412041606",
|
|
66
|
+
"@univerjs/drawing-ui": "0.5.1-nightly.202412041606",
|
|
67
|
+
"@univerjs/docs-ui": "0.5.1-nightly.202412041606",
|
|
68
|
+
"@univerjs/engine-render": "0.5.1-nightly.202412041606",
|
|
69
|
+
"@univerjs/sheets": "0.5.1-nightly.202412041606",
|
|
70
|
+
"@univerjs/sheets-drawing": "0.5.1-nightly.202412041606",
|
|
71
|
+
"@univerjs/ui": "0.5.1-nightly.202412041606",
|
|
72
|
+
"@univerjs/sheets-ui": "0.5.1-nightly.202412041606"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"less": "^4.2.1",
|