@univerjs/sheets-drawing-ui 0.5.3-nightly.202501070959 → 0.5.3-nightly.202501081606

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 CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var lt=Object.defineProperty;var ut=(i,r,t)=>r in i?lt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var V=(i,r,t)=>ut(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),Je=require("@univerjs/docs-drawing"),O=require("@univerjs/drawing"),ee=require("@univerjs/drawing-ui"),U=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),P=require("@univerjs/sheets-ui"),G=require("@univerjs/ui"),j=require("rxjs"),_=require("@univerjs/sheets"),Y=require("react"),Ze=require("@univerjs/docs-ui"),K=require("@univerjs/design"),gt="sheets-drawing-ui.config",Xe={},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:h,objects:g}=d,f=n.onCommandExecute({id:ae.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:h,objects:g,type:p.DrawingApplyType.REMOVE}},S={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:a,objects:g,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}},Qe="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(u.ICommandService);if(!_.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Qe},onClose:()=>{o.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[])},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(u.ICommandService);return r==null?!1:(t.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[r]),t.executeCommand(je.id,{value:"open"}),!0)}};var be={exports:{}},ie={};/**
1
+ "use strict";var lt=Object.defineProperty;var ut=(i,r,t)=>r in i?lt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var V=(i,r,t)=>ut(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),Je=require("@univerjs/docs-drawing"),E=require("@univerjs/drawing"),ee=require("@univerjs/drawing-ui"),U=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),P=require("@univerjs/sheets-ui"),G=require("@univerjs/ui"),N=require("rxjs"),_=require("@univerjs/sheets"),Y=require("react"),Ze=require("@univerjs/docs-ui"),K=require("@univerjs/design"),gt="sheets-drawing-ui.config",Xe={},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}},ce={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(D=>{const{unitId:R}=D;c.push(R)});const d=o.getBatchRemoveOp(s),{unitId:m,subUnitId:l,undo:a,redo:h,objects:g}=d,f=n.onCommandExecute({id:ce.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:h,objects:g,type:p.DrawingApplyType.REMOVE}},S={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:l,op:a,objects:g,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}},Qe="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(u.ICommandService);if(!_.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Qe},onClose:()=>{o.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[])},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(u.ICommandService);return r==null?!1:(t.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[r]),t.executeCommand(je.id,{value:"open"}),!0)}};var be={exports:{}},oe={};/**
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 ze;function ht(){if(ze)return ie;ze=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={},h=null,g=null;m!==void 0&&(h=""+m),d.key!==void 0&&(h=""+d.key),d.ref!==void 0&&(g=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:h,ref:g,props:a,_owner:n.current}}return ie.Fragment=t,ie.jsx=s,ie.jsxs=s,ie}var Ke;function mt(){return Ke||(Ke=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(O.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},J=(i,r)=>(t,e)=>r(t,e,i);let we=class extends u.RxDisposable{constructor(r,t,e,n,o,s,c,d){super();V(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._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(j.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 ee.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:h,drawingType:g}=m,f=m.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(l,a,h,g);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:ee.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(l,a,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[])})),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:ee.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ee.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===u.DrawingTypeEnum.DRAWING_DOM}]}};we=Ct([J(0,u.Inject(u.Injector)),J(1,O.IDrawingManagerService),J(2,u.Inject(P.SheetCanvasPopManagerService)),J(3,U.IRenderManagerService),J(4,u.IUniverInstanceService),J(5,u.IContextService),J(6,u.Inject(G.IUIPartsService)),J(7,u.ICommandService)],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,l=t.getCurrent();if(l==null)return;const a=P.convertPositionSheetOverGridToAbsolute(l.unitId,l.sheetId,{from:e,to:n},t);let{left:h,top:g,width:f,height:w}=a;const S=t.getCurrentSkeleton(),D=S.rowHeaderWidth+S.columnTotalWidth,y=S.columnHeaderHeight+S.rowTotalHeight;return h+f>D&&(h=D-f),g+w>y&&(g=y-w),{flipY:o,flipX:s,angle:c,skewX:d,skewY:m,left:h,top:g,width:f,height:w}}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 h={column:a.actualColumn,columnOffset:U.precisionTo(t-a.startX,1),row:a.actualRow,rowOffset:U.precisionTo(e-a.startY,1)},g=r.getCellWithCoordByOffset(t+n,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:U.precisionTo(t+n-g.startX,1),row:g.actualRow,rowOffset:U.precisionTo(e+o-g.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:m,skewY:l,from:h,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 Pe=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)}};Pe=Rt([ge(1,p.ISheetDrawingService),ge(2,O.IDrawingManagerService),ge(3,u.Inject(P.ISheetSelectionRenderService)),ge(4,u.Inject(P.SheetSkeletonManagerService))],Pe);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 h=a.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:w}=a;return{unitId:g,subUnitId:f,drawingId:w,transform:{...h,left:h.left-d.left,top:h.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:h}=a,{unitId:g,subUnitId:f,drawingId:w}=a,S=U.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,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:g,children:f})=>{o.push(g.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:h,objects:g}=d,f=o.onCommandExecute({id:ce.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:l,objects:g,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:m,subUnitId:l,objects:g,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:h,undo:g}=l;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,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:g,children:f})=>{o.push(g.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 Pt(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 et(i,r,t,e,n){var y;const{rotatedHeight:o,rotatedWidth:s}=Pt(t,e,n),d=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const l=(y=d.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:y.skeleton;if(l==null)return!1;const a=l.getCellByIndex(r.row,r.col),h=a.mergeInfo.endX-a.mergeInfo.startX-2,g=a.mergeInfo.endY-a.mergeInfo.startY-2,f=s/o,S=Math.ceil(Math.min(h,g*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,h,g){super();V(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=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:O.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=r.length;return t>O.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(O.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:O.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===O.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(O.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===O.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===O.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:h}=await O.getImageSize(m||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,h);let w=1;if(l>O.DRAWING_IMAGE_WIDTH_LIMIT||a>O.DRAWING_IMAGE_HEIGHT_LIMIT){const y=O.DRAWING_IMAGE_WIDTH_LIMIT/l,C=O.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,C)}const S=this._getImagePosition(l*w,a*w,g,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===O.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(O.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===O.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===O.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 O.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,n,m);const l=this._workbookSelections.getCurrentLastSelection();if(!l)return!1;const a=u.createDocumentModelWithStyle("",{}),h=et(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:l.primary.actualRow,col:l.primary.actualColumn},c,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.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:Ze.docDrawingPositionToTransform(g),docTransform:g,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=P.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:m,startX:l,startY:a}=c,h=!1;if(l+r>e&&(l=e-r,l<0&&(l=0,r=e),h=!0),a+t>n&&(a=n-t,a<0&&(a=0,t=n),h=!0),h){const S=this._selectionRenderService.getCellWithCoordByOffset(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,m=S.actualRow}const g={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:g,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._commandService.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[{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(P.SheetSkeletonManagerService)),X(2,u.ICommandService),X(3,P.ISheetSelectionRenderService),X(4,O.IImageIoService),X(5,G.ILocalFileService),X(6,p.ISheetDrawingService),X(7,O.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,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&&Ut(r,t,n),n},te=(i,r)=>(t,e)=>r(t,e,i);function Ue(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=et(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++)Ue(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===Ze.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)=>(Ue(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,O.IDrawingManagerService),te(5,u.Inject(Je.DocDrawingController)),te(6,u.Inject(P.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},qe=(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)=>{Ue(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};_e=xt([qe(0,u.Inject(P.IAutoFillService)),qe(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();V(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};ve=Gt([he(0,u.Inject(P.HoverManagerService)),he(1,u.Inject(U.IRenderManagerService)),he(2,u.Inject(_.SheetsSelectionsService)),he(3,u.Inject(ee.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();V(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=P.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 h;const n=(h=this._renderManagerService.getRenderById(r))==null?void 0:h.with(P.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(g=>{const f=l[g],{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([P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,P.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}=P.virtualizeDiscreteRanges([e,r]),{row:l,col:a}=m(c.startRow,c.startColumn),{row:h,col:g}=m(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(P.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const w=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:a,endColumn:a}),S=f.attachRangeWithCoord({startRow:h,endRow:h,startColumn:g,endColumn:g});if(!w||!S)return{redos:[],undos:[]};const D=[],y=[],C=S.startX-w.startX,T=S.startY-w.startY,I=h-l,M=g-a,v=t.copyType===P.COPY_TYPE.CUT,{_sheetDrawingService:A}=this;return n.forEach(L=>{const{transform:N,sheetTransform:E}=L;if(!N)return;const R={...L,unitId:o,subUnitId:s,drawingId:v?L.drawingId:u.Tools.generateRandomId(),transform:{...N,left:N.left+C,top:N.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}=A.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}=A.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,P.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(j.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),h=a==null?void 0:a.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&h.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.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),h=a==null?void 0:a.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&h.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.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(j.map(h=>h.every(g=>g.value)));l==null||l.pipe(j.filter(h=>h!==s),j.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),w=Object.values(f);h?this._drawingManagerService.addNotification(w):(g.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(j.filter(h=>h.value!==s),j.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(n,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.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(j.map(h=>h.every(g=>g.value)));l==null||l.pipe(j.filter(h=>h!==s),j.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),w=Object.values(f);h?(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(D=>S.oKey.includes(D.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(g.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(j.filter(h=>h.value!==s),j.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const h=r.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(h,g),w=Object.values(f),S=this._renderManagerService.getRenderById(h),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,O.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(P.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},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==u.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&u.Tools.isDefine(g.transform.left)&&u.Tools.isDefine(g.transform.top)&&u.Tools.isDefine(g.transform.width)&&u.Tools.isDefine(g.transform.height)){const f=s.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,l,{x:0,y:0}),w=s.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.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(P.SheetPrintInterceptorService)),me(1,u.Inject(ee.DrawingRenderService)),me(2,O.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},Z=(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:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,a);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:h,objects:g}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:h,objects:g,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:a,objects:g,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(m),a=l.undo,h=l.redo,g=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:h,objects:g,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:a,objects:g,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:h}=o,{row:g,column:f}=a,{row:w,column:S}=h;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&&g>=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(g>=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:h,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,a);else{const{from:w,to:S}=h,{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:A,startColumn:b,endColumn:L}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=b&&y<=L){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:w.row,endRow:S.row});if(B==null)return;W={...g,left:B.startX}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){n.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(g,n,a);continue}if(y>=b&&T<=L)continue;let N=null,E=null;if(y>=b&&y<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:w.row,endRow:S.row});if(R==null)return;E={...g,left:(R==null?void 0:R.startX)||0,width:((g==null?void 0:g.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=L){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(R==null)return;E={...g,left:R.startX-((g==null?void 0:g.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:L,startRow:w.row,endRow:S.row});if(R==null)return;if(E={...g,width:((g==null?void 0:g.width)||0)-R.endX+R.startX},N=$(E,this._selectionRenderService),N!=null&&E!=null){o.push({...a,sheetTransform:N,transform:E});break}}if(E!=null&&(N=$(E,this._selectionRenderService)),E!=null&&N!=null){n.push({...a,sheetTransform:N,transform:E});break}else this._remainDrawingSize(g,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:h,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,a);else{const{from:w,to:S}=h,{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:A,startColumn:b,endColumn:L}=M;if(C<v)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(D>=v&&D<=A){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:A});if(B==null)return;W={...g,top:B.startY}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){n.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(g,n,a);continue}if(D>=v&&C<=A)continue;let N=null,E=null;if(D>=v&&D<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:D,endRow:A});if(R==null)return;E={...g,top:(R==null?void 0:R.startY)||0,height:((g==null?void 0:g.height)||0)-R.endY+R.startY}}else if(C>=v&&C<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(R==null)return;E={...g,top:R.startY-((g==null?void 0:g.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:A});if(R==null)return;if(E={...g,height:((g==null?void 0:g.height)||0)-R.endY+R.startY},N=$(E,this._selectionRenderService),N!=null&&E!=null){o.push({...a,sheetTransform:N,transform:E});break}}if(E!=null&&(N=$(E,this._selectionRenderService)),E!=null&&N!=null){n.push({...a,sheetTransform:N,transform:E});break}else this._remainDrawingSize(g,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:h}=d,{row:g,column:f}=a,{row:w,column:S}=h;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&&(g<=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(P.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=P.attachRangeWithCoord(s,t);if(!c)return{redos:[],undos:[]};const{startX:d,endX:m,startY:l,endY:a}=c,h=this._sheetDrawingService.getDrawingData(n,o),g=[];Object.keys(h).forEach(I=>{const M=h[I];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:A=0,top:b=0,width:L=0,height:N=0}=v,{drawingStartX:E,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:A,drawingEndX:A+L,drawingStartY:b,drawingEndY:b+N};d<=E&&R<=m&&l<=W&&B<=a&&g.push(M)});const f=[],w=[],S=r.startRow-t.startRow,D=r.startColumn-t.startColumn,y=g.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}},A=F(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:I.drawingId,transform:A,sheetTransform:v}});if(y.length){const I=this._sheetDrawingService.getBatchUpdateOp(y),{undo:M,redo:v,objects:A}=I;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:v,objects:A,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:A,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=[],h=[];if(Object.keys(l).forEach(g=>{const f=l[g],{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:A}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&A<=c)h.push({unitId:e,subUnitId:n,drawingId:g});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:g,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&h.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;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(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,w=g.redo,S=g.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=[],h=[];if(Object.keys(l).forEach(g=>{const f=l[g],{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:A}=M;if(D===p.SheetDrawingAnchorType.Both&&v>=s&&A<=c)h.push({unitId:e,subUnitId:n,drawingId:g});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:g,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&h.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;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(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,w=g.redo,S=g.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 h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:c.row});if(h==null)return;a={...r,left:(r.left||0)+h.endX-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:c.row});if(h==null)return;a={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:c.row});if(h==null)return;l={from:{...s},to:{...c,column:t-1,columnOffset:h.endX-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:c.column});if(h==null)return;a={...r,top:(r.top||0)+h.endY-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:c.column});if(h==null)return;a={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(h==null)return;l={from:{...s},to:{...c,row:t-1,rowOffset:h.endY-h.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 h=l[a];h.transform=F(h.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:h,column:g}=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:h,endRow:f,startColumn:g,endColumn:w})||h>C||g>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([Z(1,U.IRenderManagerService),Z(2,u.ICommandService),Z(3,P.ISheetSelectionRenderService),Z(4,u.Inject(P.SheetSkeletonManagerService)),Z(5,u.Inject(_.SheetInterceptorService)),Z(6,p.ISheetDrawingService),Z(7,O.IDrawingManagerService),Z(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},tt=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 nt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},z({ref:r,className:c},s),o)});function nt(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 nt(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)}tt.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"}}]},rt=Y.forwardRef(function(i,r){return Y.createElement(tt,Object.assign({},i,{id:"add-image-single",ref:r,icon:an}))});rt.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(P.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 h={...a},{left:g=0,top:f=0}=a;return o===u.Direction.UP?h.top=f-1:o===u.Direction.DOWN?h.top=f+1:o===u.Direction.LEFT?h.left=g-1:o===u.Direction.RIGHT&&(h.left=g+1),{...l,transform:h,sheetTransform:$(h,n)}}).filter(l=>l!=null);return t.syncExecuteCommand(de.id,{unitId:c,drawings:d})?(t.syncExecuteCommand(x.id,[c]),!0):!1}},it="addition-and-subtraction-single",ke="sheet.menu.image";function cn(i){return{id:ke,type:G.MenuItemType.SUBITEMS,icon:it,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET),disabled$:P.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",Q={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 ot(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=ot(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=ot(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(O.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,h]=Y.useState(!0),g=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=Y.useState(g);function S(T,I){const M=[];return T.forEach(v=>{const{oKey:A}=v,b=I.getDrawingOKey(A);if(b==null)return M.push(null),!0;const{unitId:L,subUnitId:N,drawingId:E,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:L,subUnitId:N,drawingId:E,anchorType:W,sheetTransform:B,drawingType:R})}),M}Y.useEffect(()=>{const T=l.clearControl$.subscribe(M=>{M===!0&&h(!1)}),I=l.changeStart$.subscribe(M=>{var b;const{objects:v}=M,A=S(v,e);if(A.length===0)h(!1);else if(A.length>=1){h(!0);const L=((b=A[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(L)}});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(Q.imageCommonPanelGrid,Q.imageCommonPanelBorder),style:{display:y(a)},children:[k.jsx("div",{className:Q.imageCommonPanelRow,children:k.jsx("div",{className:pe(Q.imageCommonPanelColumn,Q.imageCommonPanelTitle),children:k.jsx("div",{children:t.t("drawing-anchor.title")})})}),k.jsx("div",{className:pe(Q.imageCommonPanelRow),children:k.jsx("div",{className:pe(Q.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(O.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:Q.imageCommonPanel,children:[k.jsx(ee.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,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(it,rt)),this.disposeWithMe(i.register(Qe,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,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,h=e.getFreeze(),{startColumn:g,startRow:f,xSplit:w,ySplit:S}=h,D=t.getNoMergeCellPositionByIndexWithNoHeader(f-S,g-w),y=t.getNoMergeCellPositionByIndexWithNoHeader(f,g),{rowHeaderWidth:C,columnHeaderHeight:T}=t,I=y.startX-D.startX,M=y.startY-D.startY,{top:v,left:A,viewportScrollX:b,viewportScrollY:L}=s;let N,E;d<A?(c.left=!0,N=(I+C+(d-A))*n,E=Math.max(Math.min((I+C+(m-A))*n,(I+C)*n),(m-b)*n)):(c.left=!1,N=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-L)*o)):(c.top=!1,R=Math.max((l-L)*o,(M+T)*o),W=Math.max((a-L)*o,(M+T)*o)),{left:N,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:h,scaleY:g}=n.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:m,width:c*h,height:d*g,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends u.Disposable{constructor(t,e,n,o,s,c,d){super();V(this,"_domLayerMap",new Map);V(this,"_domLayerInfoMap",new Map);V(this,"_transformChange$",new j.Subject);V(this,"transformChange$",this._transformChange$.asObservable());V(this,"_add$",new j.Subject);V(this,"add$",this._add$.asObservable());V(this,"_remove$",new j.Subject);V(this,"remove$",this._remove$.asObservable());V(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(j.filter(t=>t===u.LifecycleStages.Rendered),j.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(P.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:h,drawingType:g,data:f}=d;if(g!==u.DrawingTypeEnum.DRAWING_DOM&&g!==u.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:D}=w;if(h==null)return!0;if(l!==o)return;const{left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:A,skewX:b,skewY:L}=h,N=O.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),E=S.getObject(N);if(E!=null){E.transformByState({left:y,top:C,width:T,height:I,angle:M,flipX:v,flipY:A,skewX:b,skewY:L});return}const R={left:y,top:C,width:T,height:I,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},W=g===u.DrawingTypeEnum.DRAWING_CHART;if(W){const H=f?f.backgroundColor:"white";R.fill=H,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(N,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,ct=Oe(B,w.renderObject,a.skeleton,c.worksheet),Te=new j.BehaviorSubject(ct),dt={dispose:Re,rect:B,position$:Te,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Te,id:s,componentKey:d.componentKey,onPointerDown:H=>{D.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{D.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{D.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{D.dispatchEvent(new WheelEvent(H.type,H))},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 H=Oe(B,w.renderObject,a.skeleton,c.worksheet);Te.next(H)});Re.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Fe&&Re.add(Fe),this._domLayerInfoMap.set(s,dt),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=O.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(P.SheetSkeletonManagerService).getWorksheetSkeleton(n);!o||!d||!m||c.forEach(a=>{const h=this._domLayerInfoMap.get(a);if(h){const g=Oe(h.rect,o.renderObject,m.skeleton,d.worksheet);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(j.filter(e=>!!e),j.switchMap(e=>e.activeSheet$),j.filter(e=>!!e),j.map(e=>{const n=this._renderManagerService.getRenderById(e.getUnitId());return n?{render:n,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),j.filter(e=>!!e),j.switchMap(e=>u.fromEventSubject(e.render.scene.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(j.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===P.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 g;const{startX:n,endX:o,startY:s,endY:c}=t,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(P.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 h={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:h}}_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=O.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(),h=this._getPosition(c,o);if(h==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:h,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:h}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:h,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,O.IDrawingManagerService),ne(4,u.Inject(G.CanvasFloatDomService)),ne(5,p.ISheetDrawingService),ne(6,u.Inject(u.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var st=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,kn=(i,r,t)=>r in i?st(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&&st(r,t,n),n},Ae=(i,r)=>(t,e)=>r(t,e,i),at=(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=Xe,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=u.merge({},Xe,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(gt,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(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,r))})}};at(exports.UniverSheetsDrawingUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);at(exports.UniverSheetsDrawingUIPlugin,"pluginName",Hn);exports.UniverSheetsDrawingUIPlugin=Fn([u.DependentOn(O.UniverDrawingPlugin,Je.UniverDocsDrawingPlugin,ee.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;
9
+ */var ze;function ht(){if(ze)return oe;ze=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={},h=null,g=null;m!==void 0&&(h=""+m),d.key!==void 0&&(h=""+d.key),d.ref!==void 0&&(g=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:h,ref:g,props:a,_owner:n.current}}return oe.Fragment=t,oe.jsx=s,oe.jsxs=s,oe}var Ke;function mt(){return Ke||(Ke=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",ge={uploadLoading:pt,uploadLoadingBody:ft,uploadLoadingBodyAnimation:wt,univerCircleAnimation:St,uploadLoadingBodyText:_t},vt=()=>{const i=u.useDependency(E.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:ge.uploadLoading,children:k.jsxs("div",{className:ge.uploadLoadingBody,children:[k.jsx("div",{className:ge.uploadLoadingBodyAnimation}),k.jsx("div",{className:ge.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},J=(i,r)=>(t,e)=>r(t,e,i);let Se=class extends u.RxDisposable{constructor(r,t,e,n,o,s,c,d){super();V(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._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(u.UniverInstanceType.UNIVER_SHEET).pipe(N.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 ee.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:h,drawingType:g}=m,f=m.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(l,a,h,g);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:ee.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(l,a,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(u.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[])})),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:ce.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ee.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===u.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ee.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===u.DrawingTypeEnum.DRAWING_DOM}]}};Se=Ct([J(0,u.Inject(u.Injector)),J(1,E.IDrawingManagerService),J(2,u.Inject(P.SheetCanvasPopManagerService)),J(3,U.IRenderManagerService),J(4,u.IUniverInstanceService),J(5,u.IContextService),J(6,u.Inject(G.IUIPartsService)),J(7,u.ICommandService)],Se);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,l=t.getCurrent();if(l==null)return;const a=P.convertPositionSheetOverGridToAbsolute(l.unitId,l.sheetId,{from:e,to:n},t);let{left:h,top:g,width:f,height:w}=a;const S=t.getCurrentSkeleton(),I=S.rowHeaderWidth+S.columnTotalWidth,y=S.columnHeaderHeight+S.rowTotalHeight;return h+f>I&&(h=I-f),g+w>y&&(g=y-w),{flipY:o,flipX:s,angle:c,skewX:d,skewY:m,left:h,top:g,width:f,height:w}}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 h={column:a.actualColumn,columnOffset:U.precisionTo(t-a.startX,1),row:a.actualRow,rowOffset:U.precisionTo(e-a.startY,1)},g=r.getCellWithCoordByOffset(t+n,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:U.precisionTo(t+n-g.startX,1),row:g.actualRow,rowOffset:U.precisionTo(e+o-g.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:m,skewY:l,from:h,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},he=(i,r)=>(t,e)=>r(t,e,i);let Pe=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)}};Pe=Rt([he(1,p.ISheetDrawingService),he(2,E.IDrawingManagerService),he(3,u.Inject(P.ISheetSelectionRenderService)),he(4,u.Inject(P.SheetSkeletonManagerService))],Pe);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 h=a.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:w}=a;return{unitId:g,subUnitId:f,drawingId:w,transform:{...h,left:h.left-d.left,top:h.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:h}=a,{unitId:g,subUnitId:f,drawingId:w}=a,S=U.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,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:g,children:f})=>{o.push(g.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}},de={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(D=>D.unitId),d=n.getBatchAddOp(s),{unitId:m,subUnitId:l,undo:a,redo:h,objects:g}=d,f=o.onCommandExecute({id:de.id,params:r}),w={id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:l,objects:g,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:m,subUnitId:l,objects:g,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:h,undo:g}=l;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},le={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:g,children:f})=>{o.push(g.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 Pt(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 et(i,r,t,e,n){var y;const{rotatedHeight:o,rotatedWidth:s}=Pt(t,e,n),d=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const l=(y=d.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:y.skeleton;if(l==null)return!1;const a=l.getCellByIndex(r.row,r.col),h=a.mergeInfo.endX-a.mergeInfo.startX-2,g=a.mergeInfo.endY-a.mergeInfo.startY-2,f=s/o,S=Math.ceil(Math.min(h,g*f))/s,I=!S||Number.isNaN(S)?.001:S;return{width:t*I,height:e*I}}let ae=class extends u.Disposable{constructor(r,t,e,n,o,s,c,d,m,l,a,h,g){super();V(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=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=r.length;return t>E.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.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:E.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===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):C===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):C===E.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:h}=await E.getImageSize(m||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,h);let w=1;if(l>E.DRAWING_IMAGE_WIDTH_LIMIT||a>E.DRAWING_IMAGE_HEIGHT_LIMIT){const y=E.DRAWING_IMAGE_WIDTH_LIMIT/l,C=E.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,C)}const S=this._getImagePosition(l*w,a*w,g,f);if(S==null)return;const I={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(de.id,{unitId:n,drawings:[I]})}async _insertCellImage(r){let t;try{t=await this._imageIoService.saveImage(r)}catch(S){const I=S.message;I===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:K.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===E.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 E.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,n,m);const l=this._workbookSelections.getCurrentLastSelection();if(!l)return!1;const a=u.createDocumentModelWithStyle("",{}),h=et(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:l.primary.actualRow,col:l.primary.actualColumn},c,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.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:Ze.docDrawingPositionToTransform(g),docTransform:g,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=P.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:m,startX:l,startY:a}=c,h=!1;if(l+r>e&&(l=e-r,l<0&&(l=0,r=e),h=!0),a+t>n&&(a=n-t,a<0&&(a=0,t=n),h=!0),h){const S=this._selectionRenderService.getCellWithCoordByOffset(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,m=S.actualRow}const g={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:g,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(le.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._commandService.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[{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))}))}};ae=At([X(1,u.Inject(P.SheetSkeletonManagerService)),X(2,u.ICommandService),X(3,P.ISheetSelectionRenderService),X(4,E.IImageIoService),X(5,G.ILocalFileService),X(6,p.ISheetDrawingService),X(7,E.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))],ae);var Ut=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&&Ut(r,t,n),n},ne=(i,r)=>(t,e)=>r(t,e,i);function Ue(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=et(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 _e=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++)Ue(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===Ze.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)=>(Ue(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)}}))}};_e=jt([ne(0,u.ICommandService),ne(1,u.Inject(_.SheetInterceptorService)),ne(2,u.IUniverInstanceService),ne(3,u.Inject(u.Injector)),ne(4,E.IDrawingManagerService),ne(5,u.Inject(Je.DocDrawingController)),ne(6,u.Inject(P.IEditorBridgeService))],_e);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},qe=(i,r)=>(t,e)=>r(t,e,i);let ve=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)=>{Ue(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};ve=xt([qe(0,u.Inject(P.IAutoFillService)),qe(1,u.Inject(u.Injector))],ve);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},me=(i,r)=>(t,e)=>r(t,e,i);let Ie=class extends u.Disposable{constructor(r,t,e,n){super();V(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};Ie=Gt([me(0,u.Inject(P.HoverManagerService)),me(1,u.Inject(U.IRenderManagerService)),me(2,u.Inject(_.SheetsSelectionsService)),me(3,u.Inject(ee.DrawingRenderService))],Ie);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 De=class extends u.Disposable{constructor(r,t,e){super();V(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=P.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 h;const n=(h=this._renderManagerService.getRenderById(r))==null?void 0:h.with(P.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(g=>{const f=l[g],{transform:w}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:I=0,width:y=0,height:C=0}=w,{drawingStartX:T,drawingEndX:D,drawingStartY:R,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:I,drawingEndY:I+C};s<=T&&D<=c&&d<=R&&v<=m&&a.push(f)}),a.length&&(this._copyInfo={drawings:a,unitId:r,subUnitId:t})}_generateMutations(r,t){var L;if(!this._copyInfo)return{redos:[],undos:[]};if([P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};const{copyRange:n}=t;if(!n)return{redos:[],undos:[]};const{drawings:o,unitId:s,subUnitId:c}=this._copyInfo,{ranges:[d,m],mapFunc:l}=P.virtualizeDiscreteRanges([n,r]),{row:a,col:h}=l(d.startRow,d.startColumn),{row:g,col:f}=l(m.startRow,m.startColumn),w=(L=this._renderManagerService.getRenderById(s))==null?void 0:L.with(P.SheetSkeletonManagerService);if(!w)return{redos:[],undos:[]};const S=w.attachRangeWithCoord({startRow:a,endRow:a,startColumn:h,endColumn:h}),I=w.attachRangeWithCoord({startRow:g,endRow:g,startColumn:f,endColumn:f});if(!S||!I)return{redos:[],undos:[]};const y=[],C=[],T=I.startX-S.startX,D=I.startY-S.startY,R=g-a,v=f-h,A=t.copyType===P.COPY_TYPE.CUT,{_sheetDrawingService:b}=this;return o.forEach(j=>{const{transform:O,sheetTransform:M}=j;if(!O)return;const W={...j,unitId:s,subUnitId:c,drawingId:A?j.drawingId:u.Tools.generateRandomId(),transform:{...O,left:O.left+T,top:O.top+D},sheetTransform:{to:{...M.to,row:M.to.row+R,column:M.to.column+v},from:{...M.from,row:M.from.row+R,column:M.from.column+v}}};if(A){const{undo:B,redo:te,objects:q}=b.getBatchUpdateOp([W]);y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,type:p.DrawingApplyType.UPDATE,op:te,objects:q}}),C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:c,type:p.DrawingApplyType.UPDATE,op:B,objects:q}})}else{const{undo:B,redo:te,objects:q}=b.getBatchAddOp([W]);y.push({id:p.SetDrawingApplyMutation.id,params:{op:te,unitId:s,subUnitId:c,objects:q,type:p.DrawingApplyType.INSERT}}),C.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:s,subUnitId:c,objects:q,type:p.DrawingApplyType.REMOVE}})}}),{redos:y,undos:C}}};De=Ht([Ee(0,P.ISheetClipboardService),Ee(1,U.IRenderManagerService),Ee(2,p.ISheetDrawingService)],De);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},se=(i,r)=>(t,e)=>r(t,e,i);let Ce=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(N.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),h=a==null?void 0:a.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&h.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.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),h=a==null?void 0:a.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&h.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.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(N.map(h=>h.every(g=>g.value)));l==null||l.pipe(N.filter(h=>h!==s),N.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),w=Object.values(f);h?this._drawingManagerService.addNotification(w):(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(I=>S.oKey.includes(I.drawingId))&&d.removeObject(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(n,o).id))==null||a.pipe(N.filter(h=>h.value!==s),N.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(n,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.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(N.map(h=>h.every(g=>g.value)));l==null||l.pipe(N.filter(h=>h!==s),N.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),w=Object.values(f);h?(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(I=>S.oKey.includes(I.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(I=>S.oKey.includes(I.drawingId))&&d.detachTransformerFrom(S)}),m.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(n,o).id))==null||a.pipe(N.filter(h=>h.value!==s),N.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const h=r.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(h,g),w=Object.values(f),S=this._renderManagerService.getRenderById(h),I=S==null?void 0:S.scene;if(I==null)return;this._drawingManagerService.setDrawingEditable(!0),I.getAllObjectsByOrder().forEach(C=>{C.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>C.oKey.includes(T.drawingId))&&I.detachTransformerFrom(C)})}})})}))}};Ce=Xt([se(0,E.IDrawingManagerService),se(1,U.IRenderManagerService),se(2,u.IPermissionService),se(3,u.IUniverInstanceService),se(4,u.Inject(u.UserManagerService))],Ce);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},pe=(i,r)=>(t,e)=>r(t,e,i);let ye=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(P.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},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==u.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&u.Tools.isDefine(g.transform.left)&&u.Tools.isDefine(g.transform.top)&&u.Tools.isDefine(g.transform.width)&&u.Tools.isDefine(g.transform.height)){const f=s.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,l,{x:0,y:0}),w=s.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.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)}}))}};ye=qt([pe(0,u.Inject(P.SheetPrintInterceptorService)),pe(1,u.Inject(ee.DrawingRenderService)),pe(2,E.IDrawingManagerService),pe(3,U.IRenderManagerService)],ye);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},Z=(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:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,a);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:h,objects:g}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:h,objects:g,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:a,objects:g,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(m),a=l.undo,h=l.redo,g=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:h,objects:g,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:a,objects:g,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:h}=o,{row:g,column:f}=a,{row:w,column:S}=h;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:I,endRow:y,startColumn:C,endColumn:T}=i;let D=null,R=null;if(r===0&&g>=I&&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);D=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===1&&f>=C&&S<=T)if(g>=I&&w<=y)n.push({unitId:d,subUnitId:m,drawingId:l});else{const v=this._shrinkRow(o,c,I,y,s);D=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(o,c,I,y,s);D=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(o,c,C,T,s);D=v==null?void 0:v.newSheetTransform,R=v==null?void 0:v.newTransform}if(D!=null&&R!=null){const v=F(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,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:h,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,a);else{const{from:w,to:S}=h,{row:I,column:y}=w,{row:C,column:T}=S;for(let D=0;D<t.length;D++){const R=t[D],{startRow:v,endRow:A,startColumn:b,endColumn:L}=R;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,W=null;if(y>=b&&y<=L){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:w.row,endRow:S.row});if(B==null)return;W={...g,left:B.startX}}if(W!=null&&(M=$(W,this._selectionRenderService),M!=null&&W!=null)){n.push({...a,sheetTransform:M,transform:W});break}this._remainDrawingSize(g,n,a);continue}if(y>=b&&T<=L)continue;let j=null,O=null;if(y>=b&&y<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:L,startRow:w.row,endRow:S.row});if(M==null)return;O={...g,left:(M==null?void 0:M.startX)||0,width:((g==null?void 0:g.width)||0)-M.endX+M.startX}}else if(T>=b&&T<=L){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(M==null)return;O={...g,left:M.startX-((g==null?void 0:g.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:L,startRow:w.row,endRow:S.row});if(M==null)return;if(O={...g,width:((g==null?void 0:g.width)||0)-M.endX+M.startX},j=$(O,this._selectionRenderService),j!=null&&O!=null){o.push({...a,sheetTransform:j,transform:O});break}}if(O!=null&&(j=$(O,this._selectionRenderService)),O!=null&&j!=null){n.push({...a,sheetTransform:j,transform:O});break}else this._remainDrawingSize(g,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:h,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,n,a);else{const{from:w,to:S}=h,{row:I,column:y}=w,{row:C,column:T}=S;for(let D=0;D<t.length;D++){const R=t[D],{startRow:v,endRow:A,startColumn:b,endColumn:L}=R;if(C<v)continue;if(f===p.SheetDrawingAnchorType.Position){let M=null,W=null;if(I>=v&&I<=A){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:I,endRow:A});if(B==null)return;W={...g,top:B.startY}}if(W!=null&&(M=$(W,this._selectionRenderService),M!=null&&W!=null)){n.push({...a,sheetTransform:M,transform:W});break}this._remainDrawingSize(g,n,a);continue}if(I>=v&&C<=A)continue;let j=null,O=null;if(I>=v&&I<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:I,endRow:A});if(M==null)return;O={...g,top:(M==null?void 0:M.startY)||0,height:((g==null?void 0:g.height)||0)-M.endY+M.startY}}else if(C>=v&&C<=A){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(M==null)return;O={...g,top:M.startY-((g==null?void 0:g.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:A});if(M==null)return;if(O={...g,height:((g==null?void 0:g.height)||0)-M.endY+M.startY},j=$(O,this._selectionRenderService),j!=null&&O!=null){o.push({...a,sheetTransform:j,transform:O});break}}if(O!=null&&(j=$(O,this._selectionRenderService)),O!=null&&j!=null){n.push({...a,sheetTransform:j,transform:O});break}else this._remainDrawingSize(g,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:h}=d,{row:g,column:f}=a,{row:w,column:S}=h;for(let I=0;I<t.length;I++){const y=t[I],{startRow:C,endRow:T,startColumn:D,endColumn:R}=y;if(w<C||S<D)continue;if(l===p.SheetDrawingAnchorType.Position&&(g<=C&&w>=T||f<=D&&S>=R)){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(P.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=P.attachRangeWithCoord(s,t);if(!c)return{redos:[],undos:[]};const{startX:d,endX:m,startY:l,endY:a}=c,h=this._sheetDrawingService.getDrawingData(n,o),g=[];Object.keys(h).forEach(D=>{const R=h[D];if(R.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=R;if(!v)return;const{left:A=0,top:b=0,width:L=0,height:j=0}=v,{drawingStartX:O,drawingEndX:M,drawingStartY:W,drawingEndY:B}={drawingStartX:A,drawingEndX:A+L,drawingStartY:b,drawingEndY:b+j};d<=O&&M<=m&&l<=W&&B<=a&&g.push(R)});const f=[],w=[],S=r.startRow-t.startRow,I=r.startColumn-t.startColumn,y=g.map(D=>{const R=D.sheetTransform,v={to:{...R.to,row:R.to.row+S,column:R.to.column+I},from:{...R.from,row:R.from.row+S,column:R.from.column+I}},A=F(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:D.drawingId,transform:A,sheetTransform:v}});if(y.length){const D=this._sheetDrawingService.getBatchUpdateOp(y),{undo:R,redo:v,objects:A}=D;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:v,objects:A,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:R,objects:A,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=[],h=[];if(Object.keys(l).forEach(g=>{const f=l[g],{sheetTransform:w,transform:S,anchorType:I=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(r==="insert"){const D=this._expandRow(w,S,s,c,I);y=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:R}=w,{row:v}=D,{row:A}=R;if(I===p.SheetDrawingAnchorType.Both&&v>=s&&A<=c)h.push({unitId:e,subUnitId:n,drawingId:g});else{const b=this._shrinkRow(w,S,s,c,I);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:g,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&h.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;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(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,w=g.redo,S=g.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=[],h=[];if(Object.keys(l).forEach(g=>{const f=l[g],{sheetTransform:w,transform:S,anchorType:I=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,C;if(r==="insert"){const D=this._expandCol(w,S,s,c,I);y=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:R}=w,{column:v}=D,{column:A}=R;if(I===p.SheetDrawingAnchorType.Both&&v>=s&&A<=c)h.push({unitId:e,subUnitId:n,drawingId:g});else{const b=this._shrinkCol(w,S,s,c,I);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:g,transform:C,sheetTransform:y};a.push(T)}),a.length===0&&h.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;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(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),f=g.undo,w=g.redo,S=g.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 h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:c.row});if(h==null)return;a={...r,left:(r.left||0)+h.endX-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:c.row});if(h==null)return;a={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:c.row});if(h==null)return;l={from:{...s},to:{...c,column:t-1,columnOffset:h.endX-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:c.column});if(h==null)return;a={...r,top:(r.top||0)+h.endY-h.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 h=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:c.column});if(h==null)return;a={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(h==null)return;l={from:{...s},to:{...c,row:t-1,rowOffset:h.endY-h.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 h=l[a];h.transform=F(h.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:h,column:g}=l,{row:f,column:w}=a;for(let S=0;S<t.length;S++){const I=t[S],{startRow:y,endRow:C,startColumn:T,endColumn:D}=I;if(u.Rectangle.intersects({startRow:y,endRow:C,startColumn:T,endColumn:D},{startRow:h,endRow:f,startColumn:g,endColumn:w})||h>C||g>D){const R=m===p.SheetDrawingAnchorType.Position,v=F(c,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:R?d==null?void 0:d.width:v==null?void 0:v.width,height:R?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(x.id,[i]))}};Ne=Qt([Z(1,U.IRenderManagerService),Z(2,u.ICommandService),Z(3,P.ISheetSelectionRenderService),Z(4,u.Inject(P.SheetSkeletonManagerService)),Z(5,u.Inject(_.SheetInterceptorService)),Z(6,p.ISheetDrawingService),Z(7,E.IDrawingManagerService),Z(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},tt=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 nt(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},z({ref:r,className:c},s),o)});function nt(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 nt(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)}tt.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"}}]},rt=Y.forwardRef(function(i,r){return Y.createElement(tt,Object.assign({},i,{id:"add-image-single",ref:r,icon:an}))});rt.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(ce.id,{unitId:n,drawings:o})}},Re={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(ae).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(ae).insertCellImage())!=null?e:!1}},ie={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(P.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 h={...a},{left:g=0,top:f=0}=a;return o===u.Direction.UP?h.top=f-1:o===u.Direction.DOWN?h.top=f+1:o===u.Direction.LEFT?h.left=g-1:o===u.Direction.RIGHT&&(h.left=g+1),{...l,transform:h,sheetTransform:$(h,n)}}).filter(l=>l!=null);return t.syncExecuteCommand(le.id,{unitId:c,drawings:d})?(t.syncExecuteCommand(x.id,[c]),!0):!1}},it="addition-and-subtraction-single",ke="sheet.menu.image";function cn(i){return{id:ke,type:G.MenuItemType.SUBITEMS,icon:it,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,u.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function dn(i){return{id:Re.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",Q={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 ot(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=ot(i[r]))&&(e&&(e+=" "),e+=t)}else for(t in i)i[t]&&(e&&(e+=" "),e+=t);return e}function fe(){for(var i,r,t=0,e="",n=arguments.length;t<n;t++)(i=arguments[t])&&(r=ot(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(E.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,h]=Y.useState(!0),g=(C=s.anchorType)!=null?C:p.SheetDrawingAnchorType.Position,[f,w]=Y.useState(g);function S(T,D){const R=[];return T.forEach(v=>{const{oKey:A}=v,b=D.getDrawingOKey(A);if(b==null)return R.push(null),!0;const{unitId:L,subUnitId:j,drawingId:O,drawingType:M,anchorType:W,sheetTransform:B}=b;R.push({unitId:L,subUnitId:j,drawingId:O,anchorType:W,sheetTransform:B,drawingType:M})}),R}Y.useEffect(()=>{const T=l.clearControl$.subscribe(R=>{R===!0&&h(!1)}),D=l.changeStart$.subscribe(R=>{var b;const{objects:v}=R,A=S(v,e);if(A.length===0)h(!1);else if(A.length>=1){h(!0);const L=((b=A[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(L)}});return()=>{D.unsubscribe(),T.unsubscribe()}},[]);function I(T){w(T);const D=e.getFocusDrawings();if(D.length===0)return;const R=D.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));r.executeCommand(le.id,{unitId:D[0].unitId,drawings:R})}const y=T=>T?"block":"none";return k.jsxs("div",{className:fe(Q.imageCommonPanelGrid,Q.imageCommonPanelBorder),style:{display:y(a)},children:[k.jsx("div",{className:Q.imageCommonPanelRow,children:k.jsx("div",{className:fe(Q.imageCommonPanelColumn,Q.imageCommonPanelTitle),children:k.jsx("div",{children:t.t("drawing-anchor.title")})})}),k.jsx("div",{className:fe(Q.imageCommonPanelRow),children:k.jsx("div",{className:fe(Q.imageCommonPanelColumn),children:k.jsxs(K.RadioGroup,{value:f,onChange:I,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(E.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:Q.imageCommonPanel,children:[k.jsx(ee.DrawingCommonPanel,{drawings:t}),k.jsx(Rn,{drawings:t})]})},bn={[G.RibbonStartGroup.FORMULAS_INSERT]:{[ke]:{order:3,menuItemFactory:cn,[Re.id]:{order:0,menuItemFactory:dn},[Ge.id]:{order:1,menuItemFactory:ln}}}};function ue(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:ie.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:ue,staticParameters:{direction:u.Direction.DOWN}},On={id:ie.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:ue,staticParameters:{direction:u.Direction.UP}},An={id:ie.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:ue,staticParameters:{direction:u.Direction.LEFT}},Pn={id:ie.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:ue,staticParameters:{direction:u.Direction.RIGHT}},Un={id:$e.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ue,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},we=(i,r)=>(t,e)=>r(t,e,i);let Me=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(it,rt)),this.disposeWithMe(i.register(Qe,Tn))}_initMenus(){this._menuManagerService.mergeMenu(bn)}_initCommands(){[Re,Ge,de,ce,le,je,x,We,Le,Be,ie,$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()}};Me=Wn([we(0,u.Inject(G.ComponentManager)),we(1,G.IMenuManagerService),we(2,u.ICommandService),we(3,G.IShortcutService)],Me);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},re=(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,h=e.getFreeze(),{startColumn:g,startRow:f,xSplit:w,ySplit:S}=h,I=t.getNoMergeCellPositionByIndexWithNoHeader(f-S,g-w),y=t.getNoMergeCellPositionByIndexWithNoHeader(f,g),{rowHeaderWidth:C,columnHeaderHeight:T}=t,D=y.startX-I.startX,R=y.startY-I.startY,{top:v,left:A,viewportScrollX:b,viewportScrollY:L}=s;let j,O;d<A?(c.left=!0,j=(D+C+(d-A))*n,O=Math.max(Math.min((D+C+(m-A))*n,(D+C)*n),(m-b)*n)):(c.left=!1,j=Math.max((d-b)*n,(D+C)*n),O=Math.max((m-b)*n,(D+C)*n));let M,W;return l<v?(c.top=!0,M=(R+T+(l-v))*o,W=Math.max(Math.min((R+T+(m-v))*o,(R+T)*o),(a-L)*o)):(c.top=!1,M=Math.max((l-L)*o,(R+T)*o),W=Math.max((a-L)*o,(R+T)*o)),{left:j,right:O,top:M,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:h,scaleY:g}=n.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:m,width:c*h,height:d*g,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends u.Disposable{constructor(t,e,n,o,s,c,d){super();V(this,"_domLayerMap",new Map);V(this,"_domLayerInfoMap",new Map);V(this,"_transformChange$",new N.Subject);V(this,"transformChange$",this._transformChange$.asObservable());V(this,"_add$",new N.Subject);V(this,"add$",this._add$.asObservable());V(this,"_remove$",new N.Subject);V(this,"remove$",this._remove$.asObservable());V(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(N.filter(t=>t===u.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(t,e){let n=this._domLayerMap.get(t);n||(n=new Map,this._domLayerMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const o=n.getTransformerByCreate(),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(P.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:h,drawingType:g,data:f}=d;if(g!==u.DrawingTypeEnum.DRAWING_DOM&&g!==u.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:I}=w;if(h==null)return!0;if(l!==o)return;const{left:y,top:C,width:T,height:D,angle:R,flipX:v,flipY:A,skewX:b,skewY:L}=h,j=E.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),O=S.getObject(j);if(O!=null){O.transformByState({left:y,top:C,width:T,height:D,angle:R,flipX:v,flipY:A,skewX:b,skewY:L});return}const M={left:y,top:C,width:T,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},W=g===u.DrawingTypeEnum.DRAWING_CHART;if(W){const H=f?f.backgroundColor:"white";M.fill=H,M.rotateEnabled=!1,f&&f.border&&(M.stroke=f.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const B=new U.Rect(j,M);W&&B.setObjectType(U.ObjectType.CHART),S.addObject(B,U.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const te=this._ensureMap(n,o),q=new u.DisposableCollection,ct=Oe(B,w.renderObject,a.skeleton,c.worksheet),Te=new N.BehaviorSubject(ct),dt={dispose:q,rect:B,position$:Te,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Te,id:s,componentKey:d.componentKey,onPointerDown:H=>{I.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{I.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{I.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{I.dispatchEvent(new WheelEvent(H.type,H))},props:(Ye=(Ve=te.get(s))==null?void 0:Ve.props)!=null?Ye:this._getFloatDomProps(s),data:f,unitId:n});const Fe=B.onTransformChange$.subscribeEvent(()=>{const H=Oe(B,w.renderObject,a.skeleton,c.worksheet);Te.next(H)});q.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),Fe&&q.add(Fe),this._domLayerInfoMap.set(s,dt),te.set(s,{...te.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:s}=e,c=E.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(P.SheetSkeletonManagerService).getWorksheetSkeleton(n);!o||!d||!m||c.forEach(a=>{const h=this._domLayerInfoMap.get(a);if(h){const g=Oe(h.rect,o.renderObject,m.skeleton,d.worksheet);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(N.filter(e=>!!e),N.switchMap(e=>e.activeSheet$),N.filter(e=>!!e),N.map(e=>{const n=this._renderManagerService.getRenderById(e.getUnitId());return n?{render:n,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),N.filter(e=>!!e),N.switchMap(e=>u.fromEventSubject(e.render.scene.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.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===P.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 g;const{startX:n,endX:o,startY:s,endY:c}=t,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(P.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 h={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:h}}_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=E.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(),h=this._getPosition(c,o);if(h==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:h,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(de.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:h}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:h,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([re(0,u.Inject(U.IRenderManagerService)),re(1,u.IUniverInstanceService),re(2,u.Inject(u.ICommandService)),re(3,E.IDrawingManagerService),re(4,u.Inject(G.CanvasFloatDomService)),re(5,p.ISheetDrawingService),re(6,u.Inject(u.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var st=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,kn=(i,r,t)=>r in i?st(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&&st(r,t,n),n},Ae=(i,r)=>(t,e)=>r(t,e,i),at=(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=Xe,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=u.merge({},Xe,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(gt,s)}onStarting(){u.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[Me],[Se],[ye],[Ce],[De],[_e],[Ie],[ve]]),u.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){u.touchDependencies(this._injector,[[De]])}onRendered(){this._registerRenderModules(),u.touchDependencies(this._injector,[[Ce],[ye],[Me],[_e],[Ie],[ve]])}onSteady(){this._injector.get(Se)}_registerRenderModules(){[[ae],[Ne],[Pe]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,r))})}};at(exports.UniverSheetsDrawingUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);at(exports.UniverSheetsDrawingUIPlugin,"pluginName",Hn);exports.UniverSheetsDrawingUIPlugin=Fn([u.DependentOn(E.UniverDrawingPlugin,Je.UniverDocsDrawingPlugin,ee.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=Re;exports.InsertSheetDrawingCommand=de;exports.MoveDrawingsCommand=ie;exports.RemoveSheetDrawingCommand=ce;exports.SHEETS_IMAGE_MENU_ID=ke;exports.SetDrawingArrangeCommand=xe;exports.SetSheetDrawingCommand=le;exports.SidebarSheetDrawingOperation=je;exports.UngroupSheetDrawingCommand=Be;