@univerjs/sheets-drawing-ui 0.5.4-nightly.202501170612 → 0.5.4-nightly.202501171606

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 Bt=Object.defineProperty;var xt=(i,r,t)=>r in i?Bt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t;var z=(i,r,t)=>xt(i,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),Mt=require("@univerjs/docs-drawing"),P=require("@univerjs/drawing"),me=require("@univerjs/drawing-ui"),j=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),U=require("@univerjs/sheets-ui"),H=require("@univerjs/ui"),W=require("rxjs"),_=require("@univerjs/sheets"),q=require("react"),Tt=require("@univerjs/docs-ui"),ne=require("@univerjs/design"),Lt="sheets-drawing-ui.config",Dt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const t=i.get(j.IRenderManagerService);return r.forEach(e=>{var n,o;(o=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ue={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var D,y,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(_.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(C=>{const{unitId:M}=C;a.push(M)});const d=o.getBatchRemoveOp(s),{unitId:m,subUnitId:u,undo:c,redo:g,objects:h}=d,f=n.onCommandExecute({id:Ue.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:g,objects:h,type:p.DrawingApplyType.REMOVE}},w={id:p.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:h,type:p.DrawingApplyType.INSERT}};return l.sequenceExecute([...(D=f.preRedos)!=null?D:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:m,undoMutations:[...(y=f.preUndos)!=null?y:[],w,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:a}]}),!0):!1}},bt="COMPONENT_SHEET_DRAWING_PANEL",mt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const t=i.get(H.ISidebarService),e=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!_.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:bt},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},pt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const t=i.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[r]),t.executeCommand(mt.id,{value:"open"}),!0)}};var ct={exports:{}},Ee={};/**
1
+ "use strict";var xt=Object.defineProperty;var $t=(i,r,n)=>r in i?xt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n;var J=(i,r,n)=>$t(i,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),Et=require("@univerjs/docs-drawing"),E=require("@univerjs/drawing"),pe=require("@univerjs/drawing-ui"),U=require("@univerjs/engine-render"),f=require("@univerjs/sheets-drawing"),P=require("@univerjs/sheets-ui"),H=require("@univerjs/ui"),N=require("rxjs"),v=require("@univerjs/sheets"),Z=require("react"),Ot=require("@univerjs/docs-ui"),ne=require("@univerjs/design"),Gt="sheets-drawing-ui.config",Rt={},G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(U.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Be={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var D,y,T;const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(v.SheetInterceptorService),o=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(C=>{const{unitId:M}=C;a.push(M)});const d=o.getBatchRemoveOp(s),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=t.onCommandExecute({id:Be.id,params:r}),S={id:f.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:f.DrawingApplyType.REMOVE}},w={id:f.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:g,type:f.DrawingApplyType.INSERT}};return l.sequenceExecute([...(D=p.preRedos)!=null?D:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(y=p.preUndos)!=null?y:[],w,...p.undos,{id:G.id,params:a}],redoMutations:[...(T=p.preRedos)!=null?T:[],S,...p.redos,{id:G.id,params:a}]}),!0):!1}},Pt="COMPONENT_SHEET_DRAWING_PANEL",wt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(H.ISidebarService),e=i.get(l.LocaleService),t=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);if(!v.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Pt},onClose:()=>{o.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},St={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(l.ICommandService);return r==null?!1:(n.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[r]),n.executeCommand(wt.id,{value:"open"}),!0)}};var ut={exports:{}},Ue={};/**
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 Ct;function kt(){if(Ct)return Ee;Ct=1;var i=q,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(a,d,m){var u,c={},g=null,h=null;m!==void 0&&(g=""+m),d.key!==void 0&&(g=""+d.key),d.ref!==void 0&&(h=d.ref);for(u in d)e.call(d,u)&&!o.hasOwnProperty(u)&&(c[u]=d[u]);if(a&&a.defaultProps)for(u in d=a.defaultProps,d)c[u]===void 0&&(c[u]=d[u]);return{$$typeof:r,type:a,key:g,ref:h,props:c,_owner:n.current}}return Ee.Fragment=t,Ee.jsx=s,Ee.jsxs=s,Ee}var yt;function $t(){return yt||(yt=1,ct.exports=kt()),ct.exports}var Y=$t();const Gt="univer-upload-loading",Ft="univer-upload-loading-body",Ht="univer-upload-loading-body-animation",Vt="univer-UniverCircleAnimation",Yt="univer-upload-loading-body-text",ke={uploadLoading:Gt,uploadLoadingBody:Ft,uploadLoadingBodyAnimation:Ht,univerCircleAnimation:Vt,uploadLoadingBodyText:Yt},Xt=()=>{const i=l.useDependency(P.IImageIoService),r=l.useDependency(l.LocaleService),[t,e]=q.useState(0);return q.useEffect(()=>{const n=i.change$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[i]),Y.jsx("div",{style:{display:t>0?"block":"none"},className:ke.uploadLoading,children:Y.jsxs("div",{className:ke.uploadLoadingBody,children:[Y.jsx("div",{className:ke.uploadLoadingBodyAnimation}),Y.jsx("div",{className:ke.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${t}`})]})})};var Kt=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&&Kt(r,t,n),n},ue=(i,r)=>(t,e)=>r(t,e,i);let Xe=class extends l.RxDisposable{constructor(r,t,e,n,o,s,a,d){super();z(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=t,this._canvasPopManagerService=e,this._renderManagerService=n,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(H.BuiltInUIPart.CONTENT,()=>l.connectInjector(Xt,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 me.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(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:g,drawingType:h}=m,f=m.data;if(f&&f.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,g,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:me.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,g,h)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:pt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ue.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:me.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:me.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};Xe=qt([ue(0,l.Inject(l.Injector)),ue(1,P.IDrawingManagerService),ue(2,l.Inject(U.SheetCanvasPopManagerService)),ue(3,j.IRenderManagerService),ue(4,l.IUniverInstanceService),ue(5,l.IContextService),ue(6,l.Inject(H.IUIPartsService)),ue(7,l.ICommandService)],Xe);function X(i,r,t){const{from:e,to:n,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:m=0}=i,u=t.getCurrent();if(u==null)return;const c=U.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:g,top:h,width:f,height:S}=c;const w=t.getCurrentSkeleton(),v=w.rowHeaderWidth+w.columnTotalWidth,D=w.columnHeaderHeight+w.rowTotalHeight;return g+f>v&&(g=v-f),h+S>D&&(h=D-S),{flipY:o,flipX:s,angle:a,skewX:d,skewY:m,left:g,top:h,width:f,height:S}}function F(i,r){const{left:t=0,top:e=0,width:n=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:m=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const g={column:c.actualColumn,columnOffset:j.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:j.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+o);if(h==null)return;const f={column:h.actualColumn,columnOffset:j.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(e+o-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:m,skewY:u,from:g,to:f}}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},$e=(i,r)=>(t,e)=>r(t,e,i);let ut=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const t=i[r];for(const e in t.data){const n=t.data[e];n.transform=X(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};ut=Qt([$e(1,p.ISheetDrawingService),$e(2,P.IDrawingManagerService),$e(3,l.Inject(U.ISheetSelectionRenderService)),$e(4,l.Inject(U.SheetSkeletonManagerService))],ut);function en(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a}=e,d=j.getGroupState(0,0,n.map(c=>c.transform||{})),m=n.map(c=>{const g=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:S}=c;return{unitId:h,subUnitId:f,drawingId:S,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:m})}),r}function tn(i){const r=[];return i.forEach(t=>{const{parent:e,children:n}=t,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const m=n.map(c=>{const{transform:g}=c,{unitId:h,subUnitId:f,drawingId:S}=c,w=j.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:m})}),r}const ft={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:a,subUnitId:d,objects:tn(c),type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},Ne={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var D,y,T;const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(p.ISheetDrawingService),o=i.get(_.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(C=>C.unitId),d=n.getBatchAddOp(s),{unitId:m,subUnitId:u,undo:c,redo:g,objects:h}=d,f=o.onCommandExecute({id:Ne.id,params:r}),S={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:m,subUnitId:u,objects:h,type:p.DrawingApplyType.INSERT}},w={id:p.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:h,type:p.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(D=f.preRedos)!=null?D:[],S,...f.redos],t)?(e.pushUndoRedo({unitID:m,undoMutations:[...(y=f.preUndos)!=null?y:[],w,...f.undos,{id:G.id,params:a}],redoMutations:[...(T=f.preRedos)!=null?T:[],S,...f.redos,{id:G.id,params:a}]}),!0):!1}},wt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:d}=r,m={unitId:o,subUnitId:s,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:g,undo:h}=u;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:c,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},je={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,s=n.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:m,objects:c,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},St={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),n=i.get(p.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:f})=>{o.push(h.unitId),f.forEach(S=>{o.push(S.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return t.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:m,unitId:a,subUnitId:d,objects:en(c),type:p.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:p.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(i,r,t,e)=>{for(var n=e>1?void 0:e?rn(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},Z=(i,r)=>(t,e)=>r(t,e,i);function sn(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 D;const{rotatedHeight:o,rotatedWidth:s}=sn(t,e,n),d=i.get(j.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(D=d.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:D.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),g=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=s/o,w=Math.ceil(Math.min(g,h*f))/s,v=!w||Number.isNaN(w)?.001:w;return{width:t*v,height:e*v}}let Pe=class extends l.Disposable{constructor(r,t,e,n,o,s,a,d,m,u,c,g,h){super();z(this,"_workbookSelections");this._context=r,this._skeletonManagerService=t,this._commandService=e,this._selectionRenderService=n,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=a,this._drawingManagerService=d,this._contextService=m,this._messageService=u,this._localeService=c,this._injector=h,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),t=r.length;return t>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.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:P.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(D){const y=D.message;y===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.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:a,source:d,base64Cache:m}=t,{width:u,height:c,image:g}=await P.getImageSize(m||""),{width:h,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,a,g);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||c>P.DRAWING_IMAGE_HEIGHT_LIMIT){const D=P.DRAWING_IMAGE_WIDTH_LIMIT/u,y=P.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(D,y)}const w=this._getImagePosition(u*S,c*S,h,f);if(w==null)return;const v={unitId:n,subUnitId:o,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:d,transform:X(w,this._selectionRenderService,this._skeletonManagerService),sheetTransform:w};this._commandService.executeCommand(Ne.id,{unitId:n,drawings:[v]})}async _insertCellImage(r){let t;try{t=await this._imageIoService.saveImage(r)}catch(w){const v=w.message;v===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const{imageId:e,imageSourceType:n,source:o,base64Cache:s}=t,{width:a,height:d,image:m}=await P.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,n,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),g=Et(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},a,d,0);if(!g)return!1;const h={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},f={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:n,source:o,transform:Tt.docDrawingPositionToTransform(h),docTransform:h,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[f],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.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 a=U.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(a==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=a,g=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),g=!0),c+t>n&&(c=n-t,c<0&&(c=0,t=n),g=!0),g){const w=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(w==null)return;u=w.startX,c=w.startY,d=w.actualColumn,m=w.actualRow}const h={column:d,columnOffset:0,row:m,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(u+r,c+t);if(f==null)return;const S={column:f.actualColumn,columnOffset:u+r-f.startX,row:f.actualRow,rowOffset:c+t-f.startY};return{from:h,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:t,subUnitId:e,drawingIds:n,arrangeType:o}=r;this._commandService.executeCommand(wt.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:a,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 u=F({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...X(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};t.push(c)}),t.length>0&&this._commandService.executeCommand(je.id,{unitId:r[0].unitId,drawings:t}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(ft.id,r);const{unitId:t,subUnitId:e,drawingId:n}=r[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:t,subUnitId:e,drawingId:n}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(St.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};Pe=on([Z(1,l.Inject(U.SheetSkeletonManagerService)),Z(2,l.ICommandService),Z(3,U.ISheetSelectionRenderService),Z(4,P.IImageIoService),Z(5,H.ILocalFileService),Z(6,p.ISheetDrawingService),Z(7,P.IDrawingManagerService),Z(8,l.IContextService),Z(9,H.IMessageService),Z(10,l.Inject(l.LocaleService)),Z(11,l.Inject(_.SheetsSelectionsService)),Z(12,l.Inject(l.Injector))],Pe);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(i,r,t,e)=>{for(var n=e>1?void 0:e?cn(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&&an(r,t,n),n},Se=(i,r)=>(t,e)=>r(t,e,i);function gt(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 a=t.p.drawings[t.p.drawingsOrder[0]],d=Et(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Ke=class extends l.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=l.Range.transformRange(e,r.worksheet);for(let o=n.startRow;o<=n.endRow;o++)for(let s=n.startColumn;s<=n.endColumn;s++)gt(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(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Tt.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,t)=>(gt(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:l.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)}}))}};Ke=dn([Se(0,l.ICommandService),Se(1,l.Inject(_.SheetInterceptorService)),Se(2,l.IUniverInstanceService),Se(3,l.Inject(l.Injector)),Se(4,P.IDrawingManagerService),Se(5,l.Inject(Mt.DocDrawingController)),Se(6,l.Inject(U.IEditorBridgeService))],Ke);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,gn=(i,r,t,e)=>{for(var n=e>1?void 0:e?un(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},Rt=(i,r)=>(t,e)=>r(t,e,i);let ze=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,o,s)=>{gt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};ze=gn([Rt(0,l.Inject(U.IAutoFillService)),Rt(1,l.Inject(l.Injector))],ze);var hn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(i,r,t,e)=>{for(var n=e>1?void 0:e?mn(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&&hn(r,t,n),n},Ge=(i,r)=>(t,e)=>r(t,e,i);let qe=class extends l.Disposable{constructor(r,t,e,n){super();z(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=t,this._selectionsService=e,this._drawingRenderService=n}_initHover(){}_initImageClick(){}};qe=pn([Ge(0,l.Inject(U.HoverManagerService)),Ge(1,l.Inject(j.IRenderManagerService)),Ge(2,l.Inject(_.SheetsSelectionsService)),Ge(3,l.Inject(me.DrawingRenderService))],qe);var fn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,Sn=(i,r,t,e)=>{for(var n=e>1?void 0:e?wn(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&&fn(r,t,n),n},dt=(i,r)=>(t,e)=>r(t,e,i);let Je=class extends l.Disposable{constructor(r,t,e){super();z(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=U.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:m,subUnitId:u}=t;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:a,unitId:m,subUnitId:u})},onPastePlainText:(r,t)=>({undos:[],redos:[]})})}_collect(r,t,e){var g;const n=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(U.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:a,startY:d,endY:m}=o,u=this._sheetDrawingService.getDrawingData(r,t),c=[];Object.keys(u).forEach(h=>{const f=u[h],{transform:S}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:v=0,width:D=0,height:y=0}=S,{drawingStartX:T,drawingEndX:C,drawingStartY:M,drawingEndY:I}={drawingStartX:w,drawingEndX:w+D,drawingStartY:v,drawingEndY:v+y};s<=T&&C<=a&&d<=M&&I<=m&&c.push(f)}),c.length&&(this._copyInfo={drawings:c,unitId:r,subUnitId:t})}_generateMutations(r,t){var x;if(!this._copyInfo)return{redos:[],undos:[]};if([U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,U.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:a}=this._copyInfo,{ranges:[d,m],mapFunc:u}=U.virtualizeDiscreteRanges([n,r]),{row:c,col:g}=u(d.startRow,d.startColumn),{row:h,col:f}=u(m.startRow,m.startColumn),S=(x=this._renderManagerService.getRenderById(s))==null?void 0:x.with(U.SheetSkeletonManagerService);if(!S)return{redos:[],undos:[]};const w=S.attachRangeWithCoord({startRow:c,endRow:c,startColumn:g,endColumn:g}),v=S.attachRangeWithCoord({startRow:h,endRow:h,startColumn:f,endColumn:f});if(!w||!v)return{redos:[],undos:[]};const D=[],y=[],T=v.startX-w.startX,C=v.startY-w.startY,M=h-c,I=f-g,A=t.copyType===U.COPY_TYPE.CUT,{_sheetDrawingService:b}=this;return o.forEach(B=>{const{transform:E,sheetTransform:R}=B;if(!E)return;const N={...B,unitId:s,subUnitId:a,drawingId:A?B.drawingId:l.Tools.generateRandomId(),transform:{...E,left:E.left+T,top:E.top+C},sheetTransform:{to:{...R.to,row:R.to.row+M,column:R.to.column+I},from:{...R.from,row:R.from.row+M,column:R.from.column+I}}};if(A){const{undo:O,redo:k,objects:V}=b.getBatchUpdateOp([N]);D.push({id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:k,objects:V}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:a,type:p.DrawingApplyType.UPDATE,op:O,objects:V}})}else{const{undo:O,redo:k,objects:V}=b.getBatchAddOp([N]);D.push({id:p.SetDrawingApplyMutation.id,params:{op:k,unitId:s,subUnitId:a,objects:V,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:O,unitId:s,subUnitId:a,objects:V,type:p.DrawingApplyType.REMOVE}})}}),{redos:D,undos:y}}};Je=Sn([dt(0,U.ISheetClipboardService),dt(1,j.IRenderManagerService),dt(2,p.ISheetDrawingService)],Je);var _n=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,In=(i,r,t,e)=>{for(var n=e>1?void 0:e?vn(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&&_n(r,t,n),n},Oe=(i,r)=>(t,e)=>r(t,e,i);let Ze=class extends l.Disposable{constructor(i,r,t,e,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.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(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(a,d),u=Object.values(m),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===j.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.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(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(a,d),u=Object.values(m),c=this._renderManagerService.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===j.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>f.oKey.includes(S.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(n),d=a==null?void 0:a.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(n).id,new _.WorksheetViewPermission(n,o).id]).pipe(W.map(g=>g.every(h=>h.value)));u==null||u.pipe(W.filter(g=>g!==s),W.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),S=Object.values(f);g?this._drawingManagerService.addNotification(S):(h.forEach(w=>{w.classType===j.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>w.oKey.includes(v.drawingId))&&d.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(n,o).id))==null||c.pipe(W.filter(g=>g.value!==s),W.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(n,o),h=Object.values(g);this._drawingManagerService.addNotification(h)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,t])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const n=r.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(n),d=a==null?void 0:a.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(n).id,new _.WorksheetEditPermission(n,o).id]).pipe(W.map(g=>g.every(h=>h.value)));u==null||u.pipe(W.filter(g=>g!==s),W.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const h=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(n,o),S=Object.values(f);g?(h.forEach(w=>{w.classType===j.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>w.oKey.includes(v.drawingId))&&d.attachTransformerTo(w)}),this._drawingManagerService.addNotification(S)):(h.forEach(w=>{w.classType===j.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>w.oKey.includes(v.drawingId))&&d.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(n,o).id))==null||c.pipe(W.filter(g=>g.value!==s),W.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=r.getUnitId(),h=e.getSheetId(),f=this._drawingManagerService.getDrawingData(g,h),S=Object.values(f),w=this._renderManagerService.getRenderById(g),v=w==null?void 0:w.scene;if(v==null)return;this._drawingManagerService.setDrawingEditable(!0),v.getAllObjectsByOrder().forEach(y=>{y.classType===j.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>y.oKey.includes(T.drawingId))&&v.detachTransformerFrom(y)})}})})}))}};Ze=In([Oe(0,P.IDrawingManagerService),Oe(1,j.IRenderManagerService),Oe(2,l.IPermissionService),Oe(3,l.IUniverInstanceService),Oe(4,l.Inject(l.UserManagerService))],Ze);var Dn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,yn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Cn(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&&Dn(r,t,n),n},Fe=(i,r)=>(t,e)=>r(t,e,i);let Qe=class extends l.Disposable{constructor(i,r,t,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,t)=>{const{unitId:e,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(d=>{this._drawingRenderService.renderDrawing(a.data[d],n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,t)=>{const{unitId:e,subUnitId:n}=r,o=this._renderManagerService.getRenderById(e);if(!o)return t(i);const s=o.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(n);if(!s)return t(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(h=>d.data[h]).filter(h=>h.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,m,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,m,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),t(c)):t(i)}}))}};Qe=yn([Fe(0,l.Inject(U.SheetPrintInterceptorService)),Fe(1,l.Inject(me.DrawingRenderService)),Fe(2,P.IDrawingManagerService),Fe(3,j.IRenderManagerService)],Qe);var Rn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Tn=(i,r,t,e)=>{for(var n=e>1?void 0:e?Mn(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&&Rn(r,t,n),n},ge=(i,r)=>(t,e)=>r(t,e,i);const bn=[_.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],En=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let ht=class extends l.Disposable{constructor(i,r,t,e,n,o,s,a,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=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!bn.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=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],m=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:g,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...g),m.push(...h)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:g,objects:h}=u;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:g,objects:h,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,g=u.redo,h=u.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:g,objects:h,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:p.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,t){const e=[],n=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:m,drawingId:u}=t,{from:c,to:g}=o,{row:h,column:f}=c,{row:S,column:w}=g;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:v,endRow:D,startColumn:y,endColumn:T}=i;let C=null,M=null;if(r===0&&h>=v&&S<=D)if(f>=y&&w<=T)n.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkCol(o,a,y,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===1&&f>=y&&w<=T)if(h>=v&&S<=D)n.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkRow(o,a,v,D,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,v,D,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,y,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}if(C!=null&&M!=null){const I=X(C,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:C,transform:I})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(i,r,t){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=g,{row:v,column:D}=S,{row:y,column:T}=w;for(let C=0;C<t.length;C++){const M=t[C],{startRow:I,endRow:A,startColumn:b,endColumn:x}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,N=null;if(D>=b&&D<=x){const O=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:x,startRow:S.row,endRow:w.row});if(O==null)return;N={...h,left:O.startX}}if(N!=null&&(R=F(N,this._selectionRenderService),R!=null&&N!=null)){n.push({...c,sheetTransform:R,transform:N});break}this._remainDrawingSize(h,n,c);continue}if(D>=b&&T<=x)continue;let B=null,E=null;if(D>=b&&D<=x){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:x,startRow:S.row,endRow:w.row});if(R==null)return;E={...h,left:(R==null?void 0:R.startX)||0,width:((h==null?void 0:h.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=x){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:S.row,endRow:w.row});if(R==null)return;E={...h,left:R.startX-((h==null?void 0:h.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:x,startRow:S.row,endRow:w.row});if(R==null)return;if(E={...h,width:((h==null?void 0:h.width)||0)-R.endX+R.startX},B=F(E,this._selectionRenderService),B!=null&&E!=null){o.push({...c,sheetTransform:B,transform:E});break}}if(E!=null&&(B=F(E,this._selectionRenderService)),E!=null&&B!=null){n.push({...c,sheetTransform:B,transform:E});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:o,objects:s}=e,a=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:p.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,t){const e=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:g,transform:h,anchorType:f=p.SheetDrawingAnchorType.Position}=c;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:S,to:w}=g,{row:v,column:D}=S,{row:y,column:T}=w;for(let C=0;C<t.length;C++){const M=t[C],{startRow:I,endRow:A,startColumn:b,endColumn:x}=M;if(y<I)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,N=null;if(v>=I&&v<=A){const O=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(O==null)return;N={...h,top:O.startY}}if(N!=null&&(R=F(N,this._selectionRenderService),R!=null&&N!=null)){n.push({...c,sheetTransform:R,transform:N});break}this._remainDrawingSize(h,n,c);continue}if(v>=I&&y<=A)continue;let B=null,E=null;if(v>=I&&v<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:v,endRow:A});if(R==null)return;E={...h,top:(R==null?void 0:R.startY)||0,height:((h==null?void 0:h.height)||0)-R.endY+R.startY}}else if(y>=I&&y<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:y});if(R==null)return;E={...h,top:R.startY-((h==null?void 0:h.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:A});if(R==null)return;if(E={...h,height:((h==null?void 0:h.height)||0)-R.endY+R.startY},B=F(E,this._selectionRenderService),B!=null&&E!=null){o.push({...c,sheetTransform:B,transform:E});break}}if(E!=null&&(B=F(E,this._selectionRenderService)),E!=null&&B!=null){n.push({...c,sheetTransform:B,transform:E});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,r,t,e){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:m,anchorType:u=p.SheetDrawingAnchorType.Position}=a;if(u===p.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,a);else{const{from:c,to:g}=d,{row:h,column:f}=c,{row:S,column:w}=g;for(let v=0;v<t.length;v++){const D=t[v],{startRow:y,endRow:T,startColumn:C,endColumn:M}=D;if(S<y||w<C)continue;if(u===p.SheetDrawingAnchorType.Position&&(h<=y&&S>=T||f<=C&&w>=M)){this._remainDrawingSize(m,o,a);continue}const I=X({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...a,transform:I});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 y,T;const{toRange:r,fromRange:t}=i,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=e,s=(T=(y=this._renderManagerService.getRenderById(n))==null?void 0:y.with(U.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=U.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=a,g=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(g).forEach(C=>{const M=g[C];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:I}=M;if(!I)return;const{left:A=0,top:b=0,width:x=0,height:B=0}=I,{drawingStartX:E,drawingEndX:R,drawingStartY:N,drawingEndY:O}={drawingStartX:A,drawingEndX:A+x,drawingStartY:b,drawingEndY:b+B};d<=E&&R<=m&&u<=N&&O<=c&&h.push(M)});const f=[],S=[],w=r.startRow-t.startRow,v=r.startColumn-t.startColumn,D=h.map(C=>{const M=C.sheetTransform,I={to:{...M.to,row:M.to.row+w,column:M.to.column+v},from:{...M.from,row:M.from.row+w,column:M.from.column+v}},A=X(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:C.drawingId,transform:A,sheetTransform:I}});if(D.length){const C=this._sheetDrawingService.getBatchUpdateOp(D),{undo:M,redo:I,objects:A}=C;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:I,objects:A,type:p.DrawingApplyType.UPDATE}}),S.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:M,objects:A,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:S}}_moveRowInterceptor(i,r){const t=this._getUnitIdAndSubUnitId(i,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:o}=i,s=o.startRow,a=o.endRow,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],g=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let D,y;if(r==="insert"){const C=this._expandRow(S,w,s,a,v);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{row:I}=C,{row:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=s&&A<=a)g.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(S,w,s,a,v);D=b==null?void 0:b.newSheetTransform,y=b==null?void 0:b.newTransform}}if(!D||!y)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:y,sheetTransform:D};c.push(T)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,S=h.redo,w=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),m.push({id:G.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,a=o.endColumn,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],g=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:S,transform:w,anchorType:v=p.SheetDrawingAnchorType.Position}=f;if(S==null||w==null)return;let D,y;if(r==="insert"){const C=this._expandCol(S,w,s,a,v);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{column:I}=C,{column:A}=M;if(v===p.SheetDrawingAnchorType.Both&&I>=s&&A<=a)g.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(S,w,s,a,v);D=b==null?void 0:b.newSheetTransform,y=b==null?void 0:b.newTransform}}if(!D||!y)return;const T={unitId:e,subUnitId:n,drawingId:h,transform:y,sheetTransform:D};c.push(T)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:S,objects:w}=h;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.UPDATE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(g),f=h.undo,S=h.redo,w=h.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:p.DrawingApplyType.REMOVE}}),m.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:p.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),m.push({id:G.id,params:[e]}),{redos:d,undos:m}}_expandCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:m}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(g==null)return;c={...r,left:(r.left||0)+g.endX-g.startX},u=F(c,this._selectionRenderService)}else if(m>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:m+o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{column:d}=s,{column:m}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-o},to:{...a,column:m-o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:m-o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:a.row});if(g==null)return;c={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}u=F(c,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(g==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:g.endX-g.startX}},c=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:m}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...r,top:(r.top||0)+g.endY-g.startY},u=F(c,this._selectionRenderService)}else if(m>=e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:m+o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,t,e,n=p.SheetDrawingAnchorType.Position){const o=e-t+1,{from:s,to:a}=i,{row:d}=s,{row:m}=a;if(n===p.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-o},to:{...a,row:m-o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&m<=e)return null;if(d<t&&m>e)if(n===p.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:m-o}},c=X(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:a.column});if(g==null)return;c={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}u=F(c,this._selectionRenderService)}else if(m>=t&&m<=e&&n===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(g==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:g.endY-g.startY}},c=X(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}: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(a=>{const d=n[a];d!=null&&Object.keys(d).forEach(m=>{const u=d[m].data;u!=null&&Object.keys(u).forEach(c=>{if(a===t&&m===e){const g=u[c];g.transform=X(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[c])}else s.push(u[c])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{En.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:a,transform:d,anchorType:m=p.SheetDrawingAnchorType.Position}=s;if(m===p.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:g,column:h}=u,{row:f,column:S}=c;for(let w=0;w<t.length;w++){const v=t[w],{startRow:D,endRow:y,startColumn:T,endColumn:C}=v;if(l.Rectangle.intersects({startRow:D,endRow:y,startColumn:T,endColumn:C},{startRow:g,endRow:f,startColumn:h,endColumn:S})||g>y||h>C){const M=m===p.SheetDrawingAnchorType.Position,I=X(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...I,width:M?d==null?void 0:d.width:I==null?void 0:I.width,height:M?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[i]))}};ht=Tn([ge(1,j.IRenderManagerService),ge(2,l.ICommandService),ge(3,U.ISheetSelectionRenderService),ge(4,l.Inject(U.SheetSkeletonManagerService)),ge(5,l.Inject(_.SheetInterceptorService)),ge(6,p.ISheetDrawingService),ge(7,P.IDrawingManagerService),ge(8,l.IUniverInstanceService)],ht);var Q=function(){return Q=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},Q.apply(this,arguments)},On=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},Ot=q.forwardRef(function(i,r){var t=i.icon,e=i.id,n=i.className,o=i.extend,s=On(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(n||"").trim(),d=q.useRef("_".concat(Un()));return At(t,"".concat(e),{defIds:t.defIds,idSuffix:d.current},Q({ref:r,className:a},s),o)});function At(i,r,t,e,n){return q.createElement(i.tag,Q(Q({key:r},An(i,t,n)),e),(Pn(i,t).children||[]).map(function(o,s){return At(o,"".concat(r,"-").concat(i.tag,"-").concat(s),t,void 0,n)}))}function An(i,r,t){var e=Q({},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],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function Pn(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)?Q(Q({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&e&&e.indexOf(n.attrs.id)>-1?Q(Q({},n),{attrs:Q(Q({},n.attrs),{id:n.attrs.id+r.idSuffix})}):n})}):i}function Un(){return Math.random().toString(36).substring(2,8)}Ot.displayName="UniverIcon";var Nn={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"}}]},Pt=q.forwardRef(function(i,r){return q.createElement(Ot,Object.assign({},i,{id:"add-image-single",ref:r,icon:Nn}))});Pt.displayName="AddImageSingle";const _t={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:d,drawingId:m,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:m,drawingType:u}});return r.executeCommand(Ue.id,{unitId:n,drawings:o})}},tt={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(j.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(Pe).insertFloatImage())!=null?e:!1}},vt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,e;return(e=(t=i.get(j.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:t.with(Pe).insertCellImage())!=null?e:!1}},De={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const t=i.get(l.ICommandService),e=i.get(p.ISheetDrawingService),n=i.get(U.ISheetSelectionRenderService),{direction:o}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const g={...c},{left:h=0,top:f=0}=c;return o===l.Direction.UP?g.top=f-1:o===l.Direction.DOWN?g.top=f+1:o===l.Direction.LEFT?g.left=h-1:o===l.Direction.RIGHT&&(g.left=h+1),{...u,transform:g,sheetTransform:F(g,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(je.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},Ut="addition-and-subtraction-single",It="sheet.menu.image";function jn(i){return{id:It,type:H.MenuItemType.SUBITEMS,icon:Ut,tooltip:"sheetImage.title",hidden$:H.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:U.getCurrentRangeDisable$(i,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function Wn(i){return{id:tt.id,title:"sheetImage.upload.float",type:H.MenuItemType.BUTTON,hidden$:H.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Bn(i){return{id:vt.id,title:"sheetImage.upload.cell",type:H.MenuItemType.BUTTON}}const xn="univer-image-common-panel",Ln="univer-image-common-panel-grid",kn="univer-image-common-panel-border",$n="univer-image-common-panel-title",Gn="univer-image-common-panel-subtitle",Fn="univer-image-common-panel-row",Hn="univer-image-common-panel-row-vertical",Vn="univer-image-common-panel-column",Yn="univer-image-common-panel-column-center",Xn="univer-image-common-panel-inline",Kn="univer-image-common-panel-span2",zn="univer-image-common-panel-span3",qn="univer-image-common-panel-input",Jn="univer-sheet-image-menu",Zn="univer-sheet-image-menu-input",he={imageCommonPanel:xn,imageCommonPanelGrid:Ln,imageCommonPanelBorder:kn,imageCommonPanelTitle:$n,imageCommonPanelSubtitle:Gn,imageCommonPanelRow:Fn,imageCommonPanelRowVertical:Hn,imageCommonPanelColumn:Vn,imageCommonPanelColumnCenter:Yn,imageCommonPanelInline:Xn,imageCommonPanelSpan2:Kn,imageCommonPanelSpan3:zn,imageCommonPanelInput:qn,sheetImageMenu:Jn,sheetImageMenuInput:Zn};function Nt(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=Nt(i[r]))&&(e&&(e+=" "),e+=t)}else for(t in i)i[t]&&(e&&(e+=" "),e+=t);return e}function He(){for(var i,r,t=0,e="",n=arguments.length;t<n;t++)(i=arguments[t])&&(r=Nt(i))&&(e&&(e+=" "),e+=r);return e}const Qn=i=>{var y;const r=l.useDependency(l.ICommandService),t=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),n=l.useDependency(j.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=n.getRenderById(a),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,g]=q.useState(!0),h=(y=s.anchorType)!=null?y:p.SheetDrawingAnchorType.Position,[f,S]=q.useState(h);function w(T,C){const M=[];return T.forEach(I=>{const{oKey:A}=I,b=C.getDrawingOKey(A);if(b==null)return M.push(null),!0;const{unitId:x,subUnitId:B,drawingId:E,drawingType:R,anchorType:N,sheetTransform:O}=b;M.push({unitId:x,subUnitId:B,drawingId:E,anchorType:N,sheetTransform:O,drawingType:R})}),M}q.useEffect(()=>{const T=u.clearControl$.subscribe(M=>{M===!0&&g(!1)}),C=u.changeStart$.subscribe(M=>{var b;const{objects:I}=M,A=w(I,e);if(A.length===0)g(!1);else if(A.length>=1){g(!0);const x=((b=A[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;S(x)}});return()=>{C.unsubscribe(),T.unsubscribe()}},[]);function v(T){S(T);const C=e.getFocusDrawings();if(C.length===0)return;const M=C.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:T}));r.executeCommand(je.id,{unitId:C[0].unitId,drawings:M})}const D=T=>T?"block":"none";return Y.jsxs("div",{className:He(he.imageCommonPanelGrid,he.imageCommonPanelBorder),style:{display:D(c)},children:[Y.jsx("div",{className:he.imageCommonPanelRow,children:Y.jsx("div",{className:He(he.imageCommonPanelColumn,he.imageCommonPanelTitle),children:Y.jsx("div",{children:t.t("drawing-anchor.title")})})}),Y.jsx("div",{className:He(he.imageCommonPanelRow),children:Y.jsx("div",{className:He(he.imageCommonPanelColumn),children:Y.jsxs(ne.RadioGroup,{value:f,onChange:v,direction:"vertical",children:[Y.jsx(ne.Radio,{value:p.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),Y.jsx(ne.Radio,{value:p.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),Y.jsx(ne.Radio,{value:p.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})})]})},er=()=>{const i=l.useDependency(P.IDrawingManagerService),r=i.getFocusDrawings(),[t,e]=q.useState(r);return q.useEffect(()=>{const n=i.focus$.subscribe(o=>{e(o)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&Y.jsxs("div",{className:he.imageCommonPanel,children:[Y.jsx(me.DrawingCommonPanel,{drawings:t}),Y.jsx(Qn,{drawings:t})]})},tr={[H.RibbonStartGroup.FORMULAS_INSERT]:{[It]:{order:3,menuItemFactory:jn,[tt.id]:{order:0,menuItemFactory:Wn},[vt.id]:{order:1,menuItemFactory:Bn}}}};function We(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const nr={id:De.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:l.Direction.DOWN}},rr={id:De.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:l.Direction.UP}},ir={id:De.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.LEFT}},or={id:De.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.RIGHT}},sr={id:_t.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:We,binding:H.KeyCode.DELETE,mac:H.KeyCode.BACKSPACE};var ar=Object.defineProperty,cr=Object.getOwnPropertyDescriptor,dr=(i,r,t,e)=>{for(var n=e>1?void 0:e?cr(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&&ar(r,t,n),n},Ve=(i,r)=>(t,e)=>r(t,e,i);let et=class extends l.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(Ut,Pt)),this.disposeWithMe(i.register(bt,er))}_initMenus(){this._menuManagerService.mergeMenu(tr)}_initCommands(){[tt,vt,Ne,Ue,je,mt,G,pt,ft,St,De,_t,wt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[nr,rr,ir,or,sr].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};et=dr([Ve(0,l.Inject(H.ComponentManager)),Ve(1,H.IMenuManagerService),Ve(2,l.ICommandService),Ve(3,H.IShortcutService)],et);var lr=Object.defineProperty,ur=Object.getOwnPropertyDescriptor,gr=(i,r,t,e)=>{for(var n=e>1?void 0:e?ur(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&&lr(r,t,n),n},_e=(i,r)=>(t,e)=>r(t,e,i);function hr(i,r,t,e,n){const{scaleX:o,scaleY:s}=r.getAncestorScale(),a=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),d={left:!0,top:!0};if(!a)return{...i,absolute:d};const{left:m,right:u,top:c,bottom:g}=i,h=e.getFreeze(),{startColumn:f,startRow:S,xSplit:w,ySplit:v}=h,D=t.getNoMergeCellPositionByIndex(S-v,f-w),y=t.getNoMergeCellPositionByIndex(S,f),T=y.startX-D.startX,C=y.startY-D.startY;let{top:M,left:I,viewportScrollX:A,viewportScrollY:b}=a;const{boundsOfViewArea:x,scrollDirectionResponse:B}=n||{};x&&(l.Tools.isDefine(x.top)&&(M=x.top),l.Tools.isDefine(x.left)&&(I=x.left)),B==="HORIZONTAL"&&(b=0),B==="VERTICAL"&&(A=0);let E,R;m<I?(d.left=!0,E=(T+I+(m-I))*o,R=Math.max(Math.min((T+I+(u-I))*o,(T+I)*o),(u-A)*o)):(d.left=!1,E=Math.max((m-A)*o,I*o),R=Math.max((u-A)*o,I*o));let N,O;return c<M?(d.top=!0,N=(C+M+(c-M))*s,O=Math.max(Math.min((C+M+(u-M))*s,(C+M)*s),(g-b)*s)):(d.top=!1,N=Math.max((c-b)*s,M*s),O=Math.max((g-b)*s,M*s)),{left:E,right:R,top:N,bottom:O,absolute:d}}const ve=(i,r,t,e,n)=>{const{scene:o}=r,{left:s,top:a,width:d,height:m,angle:u}=i,c={left:s,right:s+d,top:a,bottom:a+m},g=hr(c,o,t,e,n),{scaleX:h,scaleY:f}=o.getAncestorScale();return{startX:g.left,endX:g.right,startY:g.top,endY:g.bottom,rotate:u,width:d*h,height:m*f,absolute:g.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,o,s,a,d){super();z(this,"_domLayerMap",new Map);z(this,"_domLayerInfoMap",new Map);z(this,"_transformChange$",new W.Subject);z(this,"transformChange$",this._transformChange$.asObservable());z(this,"_add$",new W.Subject);z(this,"add$",this._add$.asObservable());z(this,"_remove$",new W.Subject);z(this,"remove$",this._remove$.asObservable());z(this,"_hooks",[]);this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(t=>t===l.LifecycleStages.Rendered),W.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,renderUnit: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 ie,oe,J;const{unitId:n,subUnitId:o,drawingId:s}=e,a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!a)return;const c=(ie=this._renderManagerService.getRenderById(n))==null?void 0:ie.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!c)return;const{transform:g,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:w,canvas:v}=S;if(g==null)return!0;if(u!==o)return;const{left:D,top:y,width:T,height:C,angle:M,flipX:I,flipY:A,skewX:b,skewY:x}=g,B=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),E=w.getObject(B);if(E!=null){E.transformByState({left:D,top:y,width:T,height:C,angle:M,flipX:I,flipY:A,skewX:b,skewY:x});return}const R={left:D,top:y,width:T,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},N=h===l.DrawingTypeEnum.DRAWING_CHART;if(N){const $=f?f.backgroundColor:"white";R.fill=$,R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8}const O=new j.Rect(B,R);N&&O.setObjectType(j.ObjectType.CHART),w.addObject(O,j.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(O);const k=this._ensureMap(n,o),V=new l.DisposableCollection,re=ve(O,S.renderUnit,c.skeleton,a.worksheet),ee=new W.BehaviorSubject(re),Ie={dispose:V,rect:O,position$:ee,unitId:n,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ee,id:s,componentKey:d.componentKey,onPointerDown:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{v.dispatchEvent(new PointerEvent($.type,$))},onWheel:$=>{v.dispatchEvent(new WheelEvent($.type,$))},props:(J=(oe=k.get(s))==null?void 0:oe.props)!=null?J:this._getFloatDomProps(s),data:f,unitId:n});const de=O.onTransformChange$.subscribeEvent(()=>{const $=ve(O,S.renderUnit,c.skeleton,a.worksheet);ee.next($)});V.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),de&&V.add(de),this._domLayerInfoMap.set(s,Ie),k.set(s,{...k.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{const{unitId:n,subUnitId:o,drawingId:s}=e,a=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const t=(e,n)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,n),a=Array.from(s.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(n);!o||!d||!m||a.forEach(c=>{const g=this._domLayerInfoMap.get(c);if(g){const h=ve(g.rect,o.renderUnit,m.skeleton,d.worksheet,g);g.position$.next(h)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const n=this._renderManagerService.getRenderById(e.getUnitId());return n?{render:n,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.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===U.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(n=this._domLayerMap.get(a))==null?void 0:n.keys())!=null?o:[]).forEach(m=>{t(a,m)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;t(s,a)}}))}_getPosition(t,e){var h;const{startX:n,endX:o,startY:s,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(U.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(n,s);if(m==null)return;const u={column:m.actualColumn,columnOffset:n-m.startX,row:m.actualRow,rowOffset:s-m.startY},c=d.getCellWithCoordByOffset(o,a);if(c==null)return;const g={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const 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),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:d}=a,m=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(m);u&&u instanceof j.Rect&&u.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:a,componentKey:d,data:m,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),g=this._getPosition(a,o);if(g==null)return;this._ensureMap(o,s).set(c,t);const f={unitId:o,subUnitId:s,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:g,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Ne.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!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 a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.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 u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:g}=u;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:c,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(t){return this._hooks.push(t),{dispose:()=>{const e=this._hooks.findIndex(n=>n===t);this._hooks.splice(e,1)}}}addFloatDomToRange(t,e,n,o){var x,B,E,R;const s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(x=this._renderManagerService.getRenderById(a))==null?void 0:x.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:g,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w}=this._createRangePositionObserver(t,u,c.skeleton),v=this._getPosition(w,a);if(v==null)return;this._ensureMap(a,d).set(S,e);const y=w.endX-w.startX,T=w.endY-w.startY,C=(B=n.width)!=null?B:y,M=(E=n.height)!=null?E:T,I=w.startX+Ye(n.x,y),A=w.startY+Ye(n.y,T),b={unitId:a,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:v,transform:{left:I,top:A,width:C,height:M},data:h,allowTransform:f};{const{unitId:N,subUnitId:O,drawingId:k}=b,V=_.getSheetCommandTarget(this._univerInstanceService,{unitId:N,subUnitId:O}),re=b,ee=this._univerInstanceService.getUnit(N,l.UniverInstanceType.UNIVER_SHEET);if(!ee)return;const Ie=ee.getActiveSheet().getSheetId();if(!re||!V)return;const de=(R=this._renderManagerService.getRenderById(N))==null?void 0:R.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(O);if(!de)return;const{transform:ie,drawingType:oe,data:J}=re;if(oe!==l.DrawingTypeEnum.DRAWING_DOM&&oe!==l.DrawingTypeEnum.DRAWING_CHART)return;const $=this._getSceneAndTransformerByDrawingSearch(N);if($==null)return;const{scene:se,canvas:ae}=$;if(ie==null||Ie!==O)return;const{left:pe,top:Ce,width:ye,height:Re,angle:Be,flipX:nt,flipY:rt,skewX:it,skewY:ot}=ie,xe=P.getDrawingShapeKeyByDrawingSearch({unitId:N,subUnitId:O,drawingId:k}),Me=se.getObject(xe);if(Me!=null){Me.transformByState({left:pe,top:Ce,width:ye,height:Re,angle:Be,flipX:nt,flipY:rt,skewX:it,skewY:ot});return}const te={left:pe,top:Ce,width:ye,height:Re,zIndex:this._drawingManagerService.getDrawingOrder(N,O).length-1},Le=oe===l.DrawingTypeEnum.DRAWING_CHART;if(Le){const L=J?J.backgroundColor:"white";te.fill=L,te.rotateEnabled=!1,J&&J.border&&(te.stroke=J.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const K=new j.Rect(xe,te);Le&&K.setObjectType(j.ObjectType.CHART),se.addObject(K,j.DRAWING_OBJECT_LAYER_INDEX),re.allowTransform!==!1&&se.attachTransformerTo(K);const Te=this._ensureMap(N,O),fe=new l.DisposableCollection,le=se.getMainViewport(),st={top:le.top,left:le.left,bottom:le.bottom,right:le.right},ce={dispose:fe,rect:K,boundsOfViewArea:st,unitId:N,subUnitId:O},at=ve(K,$.renderUnit,de.skeleton,V.worksheet,ce),we=new W.BehaviorSubject(at);ce.position$=we,this._canvasFloatDomService.addFloatDom({position$:we,id:k,componentKey:re.componentKey,onPointerDown:L=>{ae.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{ae.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{ae.dispatchEvent(new PointerEvent(L.type,L))},onWheel:L=>{ae.dispatchEvent(new WheelEvent(L.type,L))},data:J,unitId:N});const be=K.onTransformChange$.subscribeEvent(()=>{const L=ve(K,$.renderUnit,de.skeleton,V.worksheet,ce);we.next(L)});fe.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),be&&fe.add(be),this._domLayerInfoMap.set(k,ce),Te.set(k,{...Te.get(k)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(t,e,n,o){var B,E,R,N;const s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(B=this._renderManagerService.getRenderById(a))==null?void 0:B.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:g,data:h,allowTransform:f=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),v=w;v.startY=0;const D=this._getPosition(w,a);if(D==null)return;this._ensureMap(a,d).set(S,e);const T=w.endX-w.startX,C=w.endY-w.startY,M=(E=n.width)!=null?E:T,I=(R=n.height)!=null?R:C,A=v.startX+Ye(n.x,T),b=v.startY+Ye(n.y,C),x={unitId:a,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:D,transform:{left:A,top:b,width:M,height:I},data:h,allowTransform:f};{const{unitId:O,subUnitId:k,drawingId:V}=x,re=_.getSheetCommandTarget(this._univerInstanceService,{unitId:O,subUnitId:k}),ee=x,Ie=this._univerInstanceService.getUnit(O,l.UniverInstanceType.UNIVER_SHEET);if(!Ie)return;const de=Ie.getActiveSheet().getSheetId();if(!ee||!re)return;const ie=(N=this._renderManagerService.getRenderById(O))==null?void 0:N.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(k);if(!ie)return;const{transform:oe,drawingType:J,data:$}=ee;if(J!==l.DrawingTypeEnum.DRAWING_DOM&&J!==l.DrawingTypeEnum.DRAWING_CHART)return;const se=this._getSceneAndTransformerByDrawingSearch(O);if(se==null)return;const{scene:ae,canvas:pe}=se;if(oe==null||de!==k)return;const{left:Ce,top:ye,width:Re,height:Be,angle:nt,flipX:rt,flipY:it,skewX:ot,skewY:xe}=oe,Me=P.getDrawingShapeKeyByDrawingSearch({unitId:O,subUnitId:k,drawingId:V}),te=ae.getObject(Me);if(te!=null){te.transformByState({left:Ce,top:ye,width:Re,height:Be,angle:nt,flipX:rt,flipY:it,skewX:ot,skewY:xe});return}const Le={left:Ce,top:ye,width:Re,height:Be,zIndex:this._drawingManagerService.getDrawingOrder(O,k).length-1},K=new j.Rect(Me,Le);ae.addObject(K,j.DRAWING_OBJECT_LAYER_INDEX),ee.allowTransform!==!1&&ae.attachTransformerTo(K);const Te=this._ensureMap(O,k),fe=new l.DisposableCollection,le=ae.getMainViewport(),st={top:0,left:le.left,bottom:le.bottom,right:le.right},ce={dispose:fe,rect:K,unitId:O,subUnitId:k,boundsOfViewArea:st,scrollDirectionResponse:"HORIZONTAL"},at=ve(K,se.renderUnit,ie.skeleton,re.worksheet,ce),we=new W.BehaviorSubject(at);ce.position$=we,this._canvasFloatDomService.addFloatDom({position$:we,id:V,componentKey:ee.componentKey,onPointerDown:L=>{pe.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{pe.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{pe.dispatchEvent(new PointerEvent(L.type,L))},onWheel:L=>{pe.dispatchEvent(new WheelEvent(L.type,L))},data:$,unitId:O});const be=K.onTransformChange$.subscribeEvent(()=>{const L=ve(K,se.renderUnit,ie.skeleton,re.worksheet,ce);we.next(L)});fe.add(()=>{this._canvasFloatDomService.removeFloatDom(V)}),be&&fe.add(be),this._domLayerInfoMap.set(V,ce),Te.set(V,{...Te.get(V)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:o,startColumn:s}=t;const a=Ae(o,s,n),d=new W.BehaviorSubject(a),m=Ae(t.endRow,t.endColumn,n),u=new W.BehaviorSubject(m),c=()=>{const v=Ae(o,s,n),D=Ae(t.endRow,t.endColumn,n);d.next(v),u.next(D)},g=new l.DisposableCollection;g.add(e.engine.clientRect$.subscribe(()=>c())),g.add(this._commandService.onCommandExecuted(v=>{if(v.id===_.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(y=>y.row===o)>-1){c();return}(_.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===U.SetScrollOperation.id||v.id===U.SetZoomRatioOperation.id)&&c()}));const h=(v,D)=>{o=v,s=D,c()},f=()=>({rotate:0,width:m.right-a.left,height:m.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:m.right,endY:m.bottom}),S=d.pipe(W.map(v=>{const D=Ae(t.endRow,t.endColumn,n);return console.log("service",v.left,v.top),{rotate:0,width:D.right-v.left,height:D.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:D.right,endY:D.bottom}})),w=f();return console.log("init position",w),{position$:S,position:w,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:g}}};exports.SheetCanvasFloatDomManagerService=gr([_e(0,l.Inject(j.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,P.IDrawingManagerService),_e(4,l.Inject(H.CanvasFloatDomService)),_e(5,p.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Ae(i,r,t){const e=t.getCellWithCoordByIndex(i,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ye(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const t=Number.parseFloat(i);return r*t/100}var jt=Object.defineProperty,mr=Object.getOwnPropertyDescriptor,pr=(i,r,t)=>r in i?jt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[r]=t,fr=(i,r,t,e)=>{for(var n=e>1?void 0:e?mr(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},lt=(i,r)=>(t,e)=>r(t,e,i),Wt=(i,r,t)=>pr(i,typeof r!="symbol"?r+"":r,t);const wr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Dt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:o,...s}=l.merge({},Dt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Lt,s)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[et],[Xe],[Qe],[Ze],[Je],[Ke],[qe],[ze]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Je]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[Ze],[Qe],[et],[Ke],[qe],[ze]])}onSteady(){this._injector.get(Xe)}_registerRenderModules(){[[Pe],[ht],[ut]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Wt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Wt(exports.UniverSheetsDrawingUIPlugin,"pluginName",wr);exports.UniverSheetsDrawingUIPlugin=fr([l.DependentOn(P.UniverDrawingPlugin,Mt.UniverDocsDrawingPlugin,me.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),lt(1,l.Inject(l.Injector)),lt(2,j.IRenderManagerService),lt(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=_t;exports.EditSheetDrawingOperation=pt;exports.GroupSheetDrawingCommand=ft;exports.InsertFloatImageCommand=tt;exports.InsertSheetDrawingCommand=Ne;exports.MoveDrawingsCommand=De;exports.RemoveSheetDrawingCommand=Ue;exports.SHEETS_IMAGE_MENU_ID=It;exports.SetDrawingArrangeCommand=wt;exports.SetSheetDrawingCommand=je;exports.SidebarSheetDrawingOperation=mt;exports.UngroupSheetDrawingCommand=St;
9
+ */var Mt;function Ft(){if(Mt)return Ue;Mt=1;var i=Z,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(a,d,m){var u,c={},h=null,g=null;m!==void 0&&(h=""+m),d.key!==void 0&&(h=""+d.key),d.ref!==void 0&&(g=d.ref);for(u in d)e.call(d,u)&&!o.hasOwnProperty(u)&&(c[u]=d[u]);if(a&&a.defaultProps)for(u in d=a.defaultProps,d)c[u]===void 0&&(c[u]=d[u]);return{$$typeof:r,type:a,key:h,ref:g,props:c,_owner:t.current}}return Ue.Fragment=n,Ue.jsx=s,Ue.jsxs=s,Ue}var Tt;function Ht(){return Tt||(Tt=1,ut.exports=Ft()),ut.exports}var X=Ht();const Yt="univer-upload-loading",Vt="univer-upload-loading-body",Xt="univer-upload-loading-body-animation",Kt="univer-UniverCircleAnimation",zt="univer-upload-loading-body-text",He={uploadLoading:Yt,uploadLoadingBody:Vt,uploadLoadingBodyAnimation:Xt,univerCircleAnimation:Kt,uploadLoadingBodyText:zt},qt=()=>{const i=l.useDependency(E.IImageIoService),r=l.useDependency(l.LocaleService),[n,e]=Z.useState(0);return Z.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),X.jsx("div",{style:{display:n>0?"block":"none"},className:He.uploadLoading,children:X.jsxs("div",{className:He.uploadLoadingBody,children:[X.jsx("div",{className:He.uploadLoadingBodyAnimation}),X.jsx("div",{className:He.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var Jt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Qt=(i,r,n,e)=>{for(var t=e>1?void 0:e?Zt(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Jt(r,n,t),t},ge=(i,r)=>(n,e)=>r(n,e,i);let qe=class extends l.RxDisposable{constructor(r,n,e,t,o,s,a,d){super();J(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=a,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(H.BuiltInUIPart.CONTENT,()=>l.connectInjector(qt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof pe.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const s=e.getSelectedObjectMap();if(s.size>1){t==null||t.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:pe.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:St.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Be.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:pe.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:pe.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};qe=Qt([ge(0,l.Inject(l.Injector)),ge(1,E.IDrawingManagerService),ge(2,l.Inject(P.SheetCanvasPopManagerService)),ge(3,U.IRenderManagerService),ge(4,l.IUniverInstanceService),ge(5,l.IContextService),ge(6,l.Inject(H.IUIPartsService)),ge(7,l.ICommandService)],qe);function z(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:m=0}=i,u=n.getCurrent();if(u==null)return;const c=P.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=c;const w=n.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,D=w.columnHeaderHeight+w.rowTotalHeight;return h+p>_&&(h=_-p),g+S>D&&(g=D-S),{flipY:o,flipX:s,angle:a,skewX:d,skewY:m,left:h,top:g,width:p,height:S}}function F(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:m=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(n,e);if(c==null)return;const h={column:c.actualColumn,columnOffset:U.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:U.precisionTo(e-c.startY,1)},g=r.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:U.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:U.precisionTo(e+o-g.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:m,skewY:u,from:h,to:p}}var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,r,n,e)=>{for(var t=e>1?void 0:e?tn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&en(r,n,t),t},Ye=(i,r)=>(n,e)=>r(n,e,i);let mt=class extends l.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=z(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};mt=nn([Ye(1,f.ISheetDrawingService),Ye(2,E.IDrawingManagerService),Ye(3,l.Inject(P.ISheetSelectionRenderService)),Ye(4,l.Inject(P.SheetSkeletonManagerService))],mt);function rn(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:s,drawingId:a}=e,d=U.getGroupState(0,0,t.map(c=>c.transform||{})),m=t.map(c=>{const h=c.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=c;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-d.left,top:h.top-d.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:m})}),r}function on(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const m=t.map(c=>{const{transform:h}=c,{unitId:g,subUnitId:p,drawingId:S}=c,w=U.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:w,groupId:void 0}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:m})}),r}const _t={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=t.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:f.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:m,unitId:a,subUnitId:d,objects:on(c),type:f.DrawingApplyType.UNGROUP}},{id:G.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:f.DrawingApplyType.GROUP}},{id:G.id,params:o}]}),!0):!1}},ke={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var D,y,T;const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService),o=i.get(v.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(C=>C.unitId),d=t.getBatchAddOp(s),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=o.onCommandExecute({id:ke.id,params:r}),S={id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:f.DrawingApplyType.INSERT}},w={id:f.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:g,type:f.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(D=p.preRedos)!=null?D:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(y=p.preUndos)!=null?y:[],w,...p.undos,{id:G.id,params:a}],redoMutations:[...(T=p.preRedos)!=null?T:[],S,...p.redos,{id:G.id,params:a}]}),!0):!1}},vt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService);if(!r)return!1;const t=i.get(f.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:d}=r,m={unitId:o,subUnitId:s,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:h,undo:g}=u;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:s,objects:c,type:f.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:c,type:f.DrawingApplyType.ARRANGE}}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:c,type:f.DrawingApplyType.ARRANGE}}]}),!0):!1}},Le={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,s=t.getBatchUpdateOp(o),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:f.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:m,objects:c,type:f.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:f.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},It={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(l.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=t.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:m,redo:u,objects:c}=s;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:f.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:m,unitId:a,subUnitId:d,objects:rn(c),type:f.DrawingApplyType.GROUP}},{id:G.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:f.DrawingApplyType.UNGROUP}},{id:G.id,params:o}]}),!0):!1}};var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,cn=(i,r,n,e)=>{for(var t=e>1?void 0:e?an(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&sn(r,n,t),t},Q=(i,r)=>(n,e)=>r(n,e,i);function dn(i,r,n){const e=n*Math.PI/180,t=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function At(i,r,n,e,t){var D;const{rotatedHeight:o,rotatedWidth:s}=dn(n,e,t),d=i.get(U.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(D=d.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:D.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),h=c.mergeInfo.endX-c.mergeInfo.startX-2,g=c.mergeInfo.endY-c.mergeInfo.startY-2,p=s/o,w=Math.ceil(Math.min(h,g*p))/s,_=!w||Number.isNaN(w)?.001:w;return{width:n*_,height:e*_}}let We=class extends l.Disposable{constructor(r,n,e,t,o,s,a,d,m,u,c,h,g){super();J(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=a,this._drawingManagerService=d,this._contextService=m,this._messageService=u,this._localeService=c,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(",")}),n=r.length;return n>E.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(D){const y=D.message;y===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:s,imageSourceType:a,source:d,base64Cache:m}=n,{width:u,height:c,image:h}=await E.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(d,a,h);let S=1;if(u>E.DRAWING_IMAGE_WIDTH_LIMIT||c>E.DRAWING_IMAGE_HEIGHT_LIMIT){const D=E.DRAWING_IMAGE_WIDTH_LIMIT/u,y=E.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(D,y)}const w=this._getImagePosition(u*S,c*S,g,p);if(w==null)return;const _={unitId:t,subUnitId:o,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:a,source:d,transform:z(w,this._selectionRenderService,this._skeletonManagerService),sheetTransform:w};this._commandService.executeCommand(ke.id,{unitId:t,drawings:[_]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(w){const _=w.message;_===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):_===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):_===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:s}=n,{width:a,height:d,image:m}=await E.getImageSize(s||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),h=At(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},a,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Ot.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(v.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(s=o[o.length-1].range);const a=P.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(a==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=a,h=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),h=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),h=!0),h){const w=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(w==null)return;u=w.startX,c=w.startY,d=w.actualColumn,m=w.actualRow}const g={column:d,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+r,c+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:c+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(vt.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:s,drawingType:a,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:s});if(m==null||m.unitId!==this._context.unitId)return;const u=F({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...z(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Le.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(_t.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._commandService.syncExecuteCommand(E.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(It.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};We=cn([Q(1,l.Inject(P.SheetSkeletonManagerService)),Q(2,l.ICommandService),Q(3,P.ISheetSelectionRenderService),Q(4,E.IImageIoService),Q(5,H.ILocalFileService),Q(6,f.ISheetDrawingService),Q(7,E.IDrawingManagerService),Q(8,l.IContextService),Q(9,H.IMessageService),Q(10,l.Inject(l.LocaleService)),Q(11,l.Inject(v.SheetsSelectionsService)),Q(12,l.Inject(l.Injector))],We);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,gn=(i,r,n,e)=>{for(var t=e>1?void 0:e?un(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&ln(r,n,t),t},De=(i,r)=>(n,e)=>r(n,e,i);function pt(i,r,n){var e,t,o,s;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((s=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=n.p.drawings[n.p.drawingsOrder[0]],d=At(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let Je=class extends l.Disposable{constructor(i,r,n,e,t,o,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=s,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===v.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===v.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===v.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let s=t.startColumn;s<=t.endColumn;s++)pt(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(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Ot.ReplaceSnapshotCommand.id&&i.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(v.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(pt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:v.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};Je=gn([De(0,l.ICommandService),De(1,l.Inject(v.SheetInterceptorService)),De(2,l.IUniverInstanceService),De(3,l.Inject(l.Injector)),De(4,E.IDrawingManagerService),De(5,l.Inject(Et.DocDrawingController)),De(6,l.Inject(P.IEditorBridgeService))],Je);var hn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(i,r,n,e)=>{for(var t=e>1?void 0:e?mn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&hn(r,n,t),t},bt=(i,r)=>(n,e)=>r(n,e,i);let Ze=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,s)=>{pt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},s)})}}))}};Ze=pn([bt(0,l.Inject(P.IAutoFillService)),bt(1,l.Inject(l.Injector))],Ze);var fn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,Sn=(i,r,n,e)=>{for(var t=e>1?void 0:e?wn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&fn(r,n,t),t},Ve=(i,r)=>(n,e)=>r(n,e,i);let Qe=class extends l.Disposable{constructor(r,n,e,t){super();J(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};Qe=Sn([Ve(0,l.Inject(P.HoverManagerService)),Ve(1,l.Inject(U.IRenderManagerService)),Ve(2,l.Inject(v.SheetsSelectionsService)),Ve(3,l.Inject(pe.DrawingRenderService))],Qe);var _n=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,In=(i,r,n,e)=>{for(var t=e>1?void 0:e?vn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&_n(r,n,t),t},gt=(i,r)=>(n,e)=>r(n,e,i);let et=class extends l.Disposable{constructor(r,n,e){super();J(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=P.COPY_TYPE.COPY,pasteType:s}=t,{range:a}=r||{},{range:d,unitId:m,subUnitId:u}=n;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:a,unitId:m,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var h;const t=(h=this._renderManagerService.getRenderById(r))==null?void 0:h.with(P.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:a,startY:d,endY:m}=o,u=this._sheetDrawingService.getDrawingData(r,n),c=[];Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==f.SheetDrawingAnchorType.Both||!S)return;const{left:w=0,top:_=0,width:D=0,height:y=0}=S,{drawingStartX:T,drawingEndX:C,drawingStartY:M,drawingEndY:I}={drawingStartX:w,drawingEndX:w+D,drawingStartY:_,drawingEndY:_+y};s<=T&&C<=a&&d<=M&&I<=m&&c.push(p)}),c.length&&(this._copyInfo={drawings:c,unitId:r,subUnitId:n})}_generateMutations(r,n){var x;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(n.pasteType))return{redos:[],undos:[]};const{copyRange:t}=n;if(!t)return{redos:[],undos:[]};const{drawings:o,unitId:s,subUnitId:a}=this._copyInfo,{ranges:[d,m],mapFunc:u}=P.virtualizeDiscreteRanges([t,r]),{row:c,col:h}=u(d.startRow,d.startColumn),{row:g,col:p}=u(m.startRow,m.startColumn),S=(x=this._renderManagerService.getRenderById(s))==null?void 0:x.with(P.SheetSkeletonManagerService);if(!S)return{redos:[],undos:[]};const w=S.attachRangeWithCoord({startRow:c,endRow:c,startColumn:h,endColumn:h}),_=S.attachRangeWithCoord({startRow:g,endRow:g,startColumn:p,endColumn:p});if(!w||!_)return{redos:[],undos:[]};const D=[],y=[],T=_.startX-w.startX,C=_.startY-w.startY,M=g-c,I=p-h,A=n.copyType===P.COPY_TYPE.CUT,{_sheetDrawingService:b}=this;return o.forEach(W=>{const{transform:O,sheetTransform:R}=W;if(!O)return;const k={...W,unitId:s,subUnitId:a,drawingId:A?W.drawingId:l.Tools.generateRandomId(),transform:{...O,left:O.left+T,top:O.top+C},sheetTransform:{to:{...R.to,row:R.to.row+M,column:R.to.column+I},from:{...R.from,row:R.from.row+M,column:R.from.column+I}}};if(A){const{undo:L,redo:Y,objects:j}=b.getBatchUpdateOp([k]);D.push({id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:a,type:f.DrawingApplyType.UPDATE,op:Y,objects:j}}),y.push({id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:a,type:f.DrawingApplyType.UPDATE,op:L,objects:j}})}else{const{undo:L,redo:Y,objects:j}=b.getBatchAddOp([k]);D.push({id:f.SetDrawingApplyMutation.id,params:{op:Y,unitId:s,subUnitId:a,objects:j,type:f.DrawingApplyType.INSERT}}),y.push({id:f.SetDrawingApplyMutation.id,params:{op:L,unitId:s,subUnitId:a,objects:j,type:f.DrawingApplyType.REMOVE}})}}),{redos:D,undos:y}}};et=In([gt(0,P.ISheetClipboardService),gt(1,U.IRenderManagerService),gt(2,f.ISheetDrawingService)],et);var Dn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,yn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Cn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Dn(r,n,t),t},Ne=(i,r)=>(n,e)=>r(n,e,i);let tt=class extends l.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const a=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(a,d),u=Object.values(m),c=this._renderManagerService.getRenderById(a),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).every(a=>a.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const a=r.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(a,d),u=Object.values(m),c=this._renderManagerService.getRenderById(a),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===U.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),d=a==null?void 0:a.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookViewPermission(t).id,new v.WorksheetViewPermission(t,o).id]).pipe(N.map(h=>h.every(g=>g.value)));u==null||u.pipe(N.filter(h=>h!==s),N.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(w=>{w.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.removeObject(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetViewPermission(t,o).id))==null||c.pipe(N.filter(h=>h.value!==s),N.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(N.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let s=!0;const a=this._renderManagerService.getRenderById(t),d=a==null?void 0:a.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new v.WorkbookEditablePermission(t).id,new v.WorksheetEditPermission(t,o).id]).pipe(N.map(h=>h.every(g=>g.value)));u==null||u.pipe(N.filter(h=>h!==s),N.distinctUntilChanged()).subscribe({next:h=>{s=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(w=>{w.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.attachTransformerTo(w)}),this._drawingManagerService.addNotification(S)):(g.forEach(w=>{w.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(_=>w.oKey.includes(_.drawingId))&&d.detachTransformerFrom(w)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new v.WorksheetEditPermission(t,o).id))==null||c.pipe(N.filter(h=>h.value!==s),N.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const h=r.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),w=this._renderManagerService.getRenderById(h),_=w==null?void 0:w.scene;if(_==null)return;this._drawingManagerService.setDrawingEditable(!0),_.getAllObjectsByOrder().forEach(y=>{y.classType===U.RENDER_CLASS_TYPE.IMAGE&&S.some(T=>y.oKey.includes(T.drawingId))&&_.detachTransformerFrom(y)})}})})}))}};tt=yn([Ne(0,E.IDrawingManagerService),Ne(1,U.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],tt);var Rn=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Tn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Mn(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&Rn(r,n,t),t},Xe=(i,r)=>(n,e)=>r(n,e,i);let nt=class extends l.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[o];return a&&a.order.forEach(d=>{this._drawingRenderService.renderDrawing(a.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const s=o.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!s)return n(i);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return n(i);const{scaleX:m,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=s.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<c.startColumn&&(c.startColumn=p.column),p.row<c.startRow&&(c.startRow=p.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),n(c)):n(i)}}))}};nt=Tn([Xe(0,l.Inject(P.SheetPrintInterceptorService)),Xe(1,l.Inject(pe.DrawingRenderService)),Xe(2,E.IDrawingManagerService),Xe(3,U.IRenderManagerService)],nt);var bn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,On=(i,r,n,e)=>{for(var t=e>1?void 0:e?En(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&bn(r,n,t),t},he=(i,r)=>(n,e)=>r(n,e,i);const Pn=[v.InsertRowCommand.id,v.InsertColCommand.id,v.RemoveRowCommand.id,v.RemoveColCommand.id,v.DeleteRangeMoveLeftCommand.id,v.DeleteRangeMoveUpCommand.id,v.InsertRangeMoveDownCommand.id,v.InsertRangeMoveRightCommand.id,v.DeltaRowHeightCommand.id,v.SetRowHeightCommand.id,v.DeltaColumnWidthCommand.id,v.SetColWidthCommand.id,v.SetRowHiddenCommand.id,v.SetSpecificRowsVisibleCommand.id,v.SetSpecificColsVisibleCommand.id,v.SetColHiddenCommand.id,v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id],An=[v.SetRowVisibleMutation.id,v.SetRowHiddenMutation.id,v.SetColVisibleMutation.id,v.SetColHiddenMutation.id,v.SetWorksheetRowHeightMutation.id,v.SetWorksheetColWidthMutation.id];let ft=class extends l.Disposable{constructor(i,r,n,e,t,o,s,a,d){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Pn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===v.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([v.MoveColsCommand.id,v.MoveRowsCommand.id,v.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===v.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===v.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===v.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===v.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===v.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===v.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===v.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===v.SetRowHiddenCommand.id||r===v.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===v.SetSpecificColsVisibleCommand.id||r===v.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===v.DeltaRowHeightCommand.id||r===v.SetRowHeightCommand.id||r===v.DeltaColumnWidthCommand.id||r===v.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,s=r===v.DeltaRowHeightCommand.id||r===v.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=v.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(e,t),d=[],m=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,r,c);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:h,objects:g}=u;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:f.DrawingApplyType.UPDATE}}),s.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:f.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,h=u.redo,g=u.objects;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:f.DrawingApplyType.REMOVE}}),s.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:f.DrawingApplyType.INSERT}})}return o.push({id:G.id,params:[e]}),s.push({id:G.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:s=f.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:m,drawingId:u}=n,{from:c,to:h}=o,{row:g,column:p}=c,{row:S,column:w}=h;if(o==null||a==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:_,endRow:D,startColumn:y,endColumn:T}=i;let C=null,M=null;if(r===0&&g>=_&&S<=D)if(p>=y&&w<=T)t.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkCol(o,a,y,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===1&&p>=y&&w<=T)if(g>=_&&S<=D)t.push({unitId:d,subUnitId:m,drawingId:u});else{const I=this._shrinkRow(o,a,_,D,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,a,_,D,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,a,y,T,s);C=I==null?void 0:I.newSheetTransform,M=I==null?void 0:I.newTransform}if(C!=null&&M!=null){const I=z(C,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:C,transform:I})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=F({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:w}=h,{row:_,column:D}=S,{row:y,column:T}=w;for(let C=0;C<n.length;C++){const M=n[C],{startRow:I,endRow:A,startColumn:b,endColumn:x}=M;if(T<b)continue;if(p===f.SheetDrawingAnchorType.Position){let R=null,k=null;if(D>=b&&D<=x){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:x,startRow:S.row,endRow:w.row});if(L==null)return;k={...g,left:L.startX}}if(k!=null&&(R=F(k,this._selectionRenderService),R!=null&&k!=null)){t.push({...c,sheetTransform:R,transform:k});break}this._remainDrawingSize(g,t,c);continue}if(D>=b&&T<=x)continue;let W=null,O=null;if(D>=b&&D<=x){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:D,endColumn:x,startRow:S.row,endRow:w.row});if(R==null)return;O={...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<=x){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:S.row,endRow:w.row});if(R==null)return;O={...g,left:R.startX-((g==null?void 0:g.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:x,startRow:S.row,endRow:w.row});if(R==null)return;if(O={...g,width:((g==null?void 0:g.width)||0)-R.endX+R.startX},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...c,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...c,sheetTransform:W,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:s}=e,a=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:f.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}],d=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:s,type:f.DrawingApplyType.UPDATE}},{id:G.id,params:[i]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:w}=h,{row:_,column:D}=S,{row:y,column:T}=w;for(let C=0;C<n.length;C++){const M=n[C],{startRow:I,endRow:A,startColumn:b,endColumn:x}=M;if(y<I)continue;if(p===f.SheetDrawingAnchorType.Position){let R=null,k=null;if(_>=I&&_<=A){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:A});if(L==null)return;k={...g,top:L.startY}}if(k!=null&&(R=F(k,this._selectionRenderService),R!=null&&k!=null)){t.push({...c,sheetTransform:R,transform:k});break}this._remainDrawingSize(g,t,c);continue}if(_>=I&&y<=A)continue;let W=null,O=null;if(_>=I&&_<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:_,endRow:A});if(R==null)return;O={...g,top:(R==null?void 0:R.startY)||0,height:((g==null?void 0:g.height)||0)-R.endY+R.startY}}else if(y>=I&&y<=A){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:y});if(R==null)return;O={...g,top:R.startY-((g==null?void 0:g.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:w.column,startRow:I,endRow:A});if(R==null)return;if(O={...g,height:((g==null?void 0:g.height)||0)-R.endY+R.startY},W=F(O,this._selectionRenderService),W!=null&&O!=null){o.push({...c,sheetTransform:W,transform:O});break}}if(O!=null&&(W=F(O,this._selectionRenderService)),O!=null&&W!=null){t.push({...c,sheetTransform:W,transform:O});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);d.push(...u),m.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(s=>{const a=t[s],{sheetTransform:d,transform:m,anchorType:u=f.SheetDrawingAnchorType.Position}=a;if(u===f.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,a);else{const{from:c,to:h}=d,{row:g,column:p}=c,{row:S,column:w}=h;for(let _=0;_<n.length;_++){const D=n[_],{startRow:y,endRow:T,startColumn:C,endColumn:M}=D;if(S<y||w<C)continue;if(u===f.SheetDrawingAnchorType.Position&&(g<=y&&S>=T||p<=C&&w>=M)){this._remainDrawingSize(m,o,a);continue}const I=z({...d},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...a,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=v.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var y,T;const{toRange:r,fromRange:n}=i,e=v.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,s=(T=(y=this._renderManagerService.getRenderById(t))==null?void 0:y.with(P.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=P.attachRangeWithCoord(s,n);if(!a)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=a,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(C=>{const M=h[C];if(M.anchorType!==f.SheetDrawingAnchorType.Both)return;const{transform:I}=M;if(!I)return;const{left:A=0,top:b=0,width:x=0,height:W=0}=I,{drawingStartX:O,drawingEndX:R,drawingStartY:k,drawingEndY:L}={drawingStartX:A,drawingEndX:A+x,drawingStartY:b,drawingEndY:b+W};d<=O&&R<=m&&u<=k&&L<=c&&g.push(M)});const p=[],S=[],w=r.startRow-n.startRow,_=r.startColumn-n.startColumn,D=g.map(C=>{const M=C.sheetTransform,I={to:{...M.to,row:M.to.row+w,column:M.to.column+_},from:{...M.from,row:M.from.row+w,column:M.from.column+_}},A=z(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:C.drawingId,transform:A,sheetTransform:I}});if(D.length){const C=this._sheetDrawingService.getBatchUpdateOp(D),{undo:M,redo:I,objects:A}=C;p.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:I,objects:A,type:f.DrawingApplyType.UPDATE}}),S.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:M,objects:A,type:f.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,s=o.startRow,a=o.endRow,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:w,anchorType:_=f.SheetDrawingAnchorType.Position}=p;if(S==null||w==null)return;let D,y;if(r==="insert"){const C=this._expandRow(S,w,s,a,_);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{row:I}=C,{row:A}=M;if(_===f.SheetDrawingAnchorType.Both&&I>=s&&A<=a)h.push({unitId:e,subUnitId:t,drawingId:g});else{const b=this._shrinkRow(S,w,s,a,_);D=b==null?void 0:b.newSheetTransform,y=b==null?void 0:b.newTransform}}if(!D||!y)return;const T={unitId:e,subUnitId:t,drawingId:g,transform:y,sheetTransform:D};c.push(T)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:w}=g;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.UPDATE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,w=g.objects;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.REMOVE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),m.push({id:G.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,s=o.startColumn,a=o.endColumn,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:w,anchorType:_=f.SheetDrawingAnchorType.Position}=p;if(S==null||w==null)return;let D,y;if(r==="insert"){const C=this._expandCol(S,w,s,a,_);D=C==null?void 0:C.newSheetTransform,y=C==null?void 0:C.newTransform}else{const{from:C,to:M}=S,{column:I}=C,{column:A}=M;if(_===f.SheetDrawingAnchorType.Both&&I>=s&&A<=a)h.push({unitId:e,subUnitId:t,drawingId:g});else{const b=this._shrinkCol(S,w,s,a,_);D=b==null?void 0:b.newSheetTransform,y=b==null?void 0:b.newTransform}}if(!D||!y)return;const T={unitId:e,subUnitId:t,drawingId:g,transform:y,sheetTransform:D};c.push(T)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:w}=g;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.UPDATE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,w=g.objects;d.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:w,type:f.DrawingApplyType.REMOVE}}),m.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:w,type:f.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),m.push({id:G.id,params:[e]}),{redos:d,undos:m}}_expandCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:s,to:a}=i,{column:d}=s,{column:m}=a;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:s.row,endRow:a.row});if(h==null)return;c={...r,left:(r.left||0)+h.endX-h.startX},u=F(c,this._selectionRenderService)}else if(m>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:m+o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:s,to:a}=i,{column:d}=s,{column:m}=a;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-o},to:{...a,column:m-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:m-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)c={...r,left:(r.left||0)-i.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:s.row,endRow:a.row});if(h==null)return;c={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}u=F(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===f.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:s.row,endRow:a.row});if(h==null)return;u={from:{...s},to:{...a,column:n-1,columnOffset:h.endX-h.startX}},c=z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:s,to:a}=i,{row:d}=s,{row:m}=a;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:s.column,endColumn:a.column});if(h==null)return;c={...r,top:(r.top||0)+h.endY-h.startY},u=F(c,this._selectionRenderService)}else if(m>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:m+o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:s,to:a}=i,{row:d}=s,{row:m}=a;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-o},to:{...a,row:m-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:m-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:F({...r},this._selectionRenderService),newTransform:r};else if(d>=n&&d<=e){if(d===n)c={...r,top:(r.top||0)-i.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:s.column,endColumn:a.column});if(h==null)return;c={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}u=F(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===f.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...s},to:{...a,row:n-1,rowOffset:h.endY-h.startY}},c=z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===v.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(t).forEach(a=>{const d=t[a];d!=null&&Object.keys(d).forEach(m=>{const u=d[m].data;u!=null&&Object.keys(u).forEach(c=>{if(a===n&&m===e){const h=u[c];h.transform=z(h.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[c])}else s.push(u[c])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{An.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:a,transform:d,anchorType:m=f.SheetDrawingAnchorType.Position}=s;if(m===f.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:h,column:g}=u,{row:p,column:S}=c;for(let w=0;w<n.length;w++){const _=n[w],{startRow:D,endRow:y,startColumn:T,endColumn:C}=_;if(l.Rectangle.intersects({startRow:D,endRow:y,startColumn:T,endColumn:C},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>y||g>C){const M=m===f.SheetDrawingAnchorType.Position,I=z(a,this._selectionRenderService,this._skeletonManagerService);t.push({...s,transform:{...I,width:M?d==null?void 0:d.width:I==null?void 0:I.width,height:M?d==null?void 0:d.height:I==null?void 0:I.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(G.id,[i]))}};ft=On([he(1,U.IRenderManagerService),he(2,l.ICommandService),he(3,P.ISheetSelectionRenderService),he(4,l.Inject(P.SheetSkeletonManagerService)),he(5,l.Inject(v.SheetInterceptorService)),he(6,f.ISheetDrawingService),he(7,E.IDrawingManagerService),he(8,l.IUniverInstanceService)],ft);var ee=function(){return ee=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},ee.apply(this,arguments)},Un=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},Ut=Z.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,s=Un(i,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=Z.useRef("_".concat(Wn()));return Nt(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},ee({ref:r,className:a},s),o)});function Nt(i,r,n,e,t){return Z.createElement(i.tag,ee(ee({key:r},Nn(i,n,t)),e),(jn(i,n).children||[]).map(function(o,s){return Nt(o,"".concat(r,"-").concat(i.tag,"-").concat(s),n,void 0,t)}))}function Nn(i,r,n){var e=ee({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],a=o[1];typeof a=="string"&&(e[s]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function jn(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?ee(ee({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?ee(ee({},t),{attrs:ee(ee({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function Wn(){return Math.random().toString(36).substring(2,8)}Ut.displayName="UniverIcon";var Bn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},jt=Z.forwardRef(function(i,r){return Z.createElement(Ut,Object.assign({},i,{id:"add-image-single",ref:r,icon:Bn}))});jt.displayName="AddImageSingle";const Dt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),e=i.get(f.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(s=>{const{unitId:a,subUnitId:d,drawingId:m,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:m,drawingType:u}});return r.executeCommand(Be.id,{unitId:t,drawings:o})}},it={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(We).insertFloatImage())!=null?e:!1}},Ct={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(We).insertCellImage())!=null?e:!1}},Te={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(l.ICommandService),e=i.get(f.ISheetDrawingService),t=i.get(P.ISheetSelectionRenderService),{direction:o}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const h={...c},{left:g=0,top:p=0}=c;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:F(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Le.id,{unitId:a,drawings:d})?(n.syncExecuteCommand(G.id,[a]),!0):!1}},Wt="addition-and-subtraction-single",yt="sheet.menu.image";function kn(i){return{id:yt,type:H.MenuItemType.SUBITEMS,icon:Wt,tooltip:"sheetImage.title",hidden$:H.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookEditablePermission],worksheetTypes:[v.WorksheetEditPermission],rangeTypes:[v.RangeProtectionPermissionEditPoint]})}}function Ln(i){return{id:it.id,title:"sheetImage.upload.float",type:H.MenuItemType.BUTTON,hidden$:H.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function xn(i){return{id:Ct.id,title:"sheetImage.upload.cell",type:H.MenuItemType.BUTTON}}const $n="univer-image-common-panel",Gn="univer-image-common-panel-grid",Fn="univer-image-common-panel-border",Hn="univer-image-common-panel-title",Yn="univer-image-common-panel-subtitle",Vn="univer-image-common-panel-row",Xn="univer-image-common-panel-row-vertical",Kn="univer-image-common-panel-column",zn="univer-image-common-panel-column-center",qn="univer-image-common-panel-inline",Jn="univer-image-common-panel-span2",Zn="univer-image-common-panel-span3",Qn="univer-image-common-panel-input",er="univer-sheet-image-menu",tr="univer-sheet-image-menu-input",me={imageCommonPanel:$n,imageCommonPanelGrid:Gn,imageCommonPanelBorder:Fn,imageCommonPanelTitle:Hn,imageCommonPanelSubtitle:Yn,imageCommonPanelRow:Vn,imageCommonPanelRowVertical:Xn,imageCommonPanelColumn:Kn,imageCommonPanelColumnCenter:zn,imageCommonPanelInline:qn,imageCommonPanelSpan2:Jn,imageCommonPanelSpan3:Zn,imageCommonPanelInput:Qn,sheetImageMenu:er,sheetImageMenuInput:tr};function Bt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=Bt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function Ke(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=Bt(i))&&(e&&(e+=" "),e+=r);return e}const nr=i=>{var y;const r=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(E.IDrawingManagerService),t=l.useDependency(U.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,d=t.getRenderById(a),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,h]=Z.useState(!0),g=(y=s.anchorType)!=null?y:f.SheetDrawingAnchorType.Position,[p,S]=Z.useState(g);function w(T,C){const M=[];return T.forEach(I=>{const{oKey:A}=I,b=C.getDrawingOKey(A);if(b==null)return M.push(null),!0;const{unitId:x,subUnitId:W,drawingId:O,drawingType:R,anchorType:k,sheetTransform:L}=b;M.push({unitId:x,subUnitId:W,drawingId:O,anchorType:k,sheetTransform:L,drawingType:R})}),M}Z.useEffect(()=>{const T=u.clearControl$.subscribe(M=>{M===!0&&h(!1)}),C=u.changeStart$.subscribe(M=>{var b;const{objects:I}=M,A=w(I,e);if(A.length===0)h(!1);else if(A.length>=1){h(!0);const x=((b=A[0])==null?void 0:b.anchorType)||f.SheetDrawingAnchorType.Position;S(x)}});return()=>{C.unsubscribe(),T.unsubscribe()}},[]);function _(T){S(T);const C=e.getFocusDrawings();if(C.length===0)return;const M=C.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:T}));r.executeCommand(Le.id,{unitId:C[0].unitId,drawings:M})}const D=T=>T?"block":"none";return X.jsxs("div",{className:Ke(me.imageCommonPanelGrid,me.imageCommonPanelBorder),style:{display:D(c)},children:[X.jsx("div",{className:me.imageCommonPanelRow,children:X.jsx("div",{className:Ke(me.imageCommonPanelColumn,me.imageCommonPanelTitle),children:X.jsx("div",{children:n.t("drawing-anchor.title")})})}),X.jsx("div",{className:Ke(me.imageCommonPanelRow),children:X.jsx("div",{className:Ke(me.imageCommonPanelColumn),children:X.jsxs(ne.RadioGroup,{value:p,onChange:_,direction:"vertical",children:[X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),X.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},rr=()=>{const i=l.useDependency(E.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=Z.useState(r);return Z.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&X.jsxs("div",{className:me.imageCommonPanel,children:[X.jsx(pe.DrawingCommonPanel,{drawings:n}),X.jsx(nr,{drawings:n})]})},ir={[H.RibbonStartGroup.FORMULAS_INSERT]:{[yt]:{order:3,menuItemFactory:kn,[it.id]:{order:0,menuItemFactory:Ln},[Ct.id]:{order:1,menuItemFactory:xn}}}};function xe(i){return!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.EDITOR_ACTIVATED)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const or={id:Te.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_DOWN,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.DOWN}},sr={id:Te.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_UP,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.UP}},ar={id:Te.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_LEFT,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.LEFT}},cr={id:Te.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:H.KeyCode.ARROW_RIGHT,priority:100,preconditions:xe,staticParameters:{direction:l.Direction.RIGHT}},dr={id:Dt.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:xe,binding:H.KeyCode.DELETE,mac:H.KeyCode.BACKSPACE};var lr=Object.defineProperty,ur=Object.getOwnPropertyDescriptor,gr=(i,r,n,e)=>{for(var t=e>1?void 0:e?ur(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&lr(r,n,t),t},ze=(i,r)=>(n,e)=>r(n,e,i);let rt=class extends l.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Wt,jt)),this.disposeWithMe(i.register(Pt,rr))}_initMenus(){this._menuManagerService.mergeMenu(ir)}_initCommands(){[it,Ct,ke,Be,Le,wt,G,St,_t,It,Te,Dt,vt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[or,sr,ar,cr,dr].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};rt=gr([ze(0,l.Inject(H.ComponentManager)),ze(1,H.IMenuManagerService),ze(2,l.ICommandService),ze(3,H.IShortcutService)],rt);var hr=Object.defineProperty,mr=Object.getOwnPropertyDescriptor,pr=(i,r,n,e)=>{for(var t=e>1?void 0:e?mr(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&hr(r,n,t),t},Ce=(i,r)=>(n,e)=>r(n,e,i);function fr(i,r,n,e,t){const{scaleX:o,scaleY:s}=r.getAncestorScale(),a=r.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),d={left:!0,top:!0};if(!a)return{...i,absolute:d};const{left:m,right:u,top:c,bottom:h}=i;let{top:g,left:p,viewportScrollX:S,viewportScrollY:w}=a;const{boundsOfViewArea:_,scrollDirectionResponse:D}=t||{};_&&(l.Tools.isDefine(_.top)&&(g=_.top),l.Tools.isDefine(_.left)&&(p=_.left)),D==="HORIZONTAL"&&(w=0),D==="VERTICAL"&&(S=0);let y,T;m<p?(d.left=!0,y=(p+(m-p))*o,T=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(d.left=!1,y=Math.max((m-S)*o,p*o),T=Math.max((u-S)*o,p*o));let C,M;return c<g?(d.top=!0,C=(g+(c-g))*s,M=Math.max(Math.min((g+(u-g))*s,g*s),(h-w)*s)):(d.top=!1,C=Math.max((c-w)*s,g*s),M=Math.max((h-w)*s,g*s)),{left:y,right:T,top:C,bottom:M,absolute:d}}const ye=(i,r,n,e,t)=>{const{scene:o}=r,{left:s,top:a,width:d,height:m,angle:u}=i,c={left:s,right:s+d,top:a,bottom:a+m},h=fr(c,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:d*g,height:m*p,absolute:h.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,s,a,d){super();J(this,"_domLayerMap",new Map);J(this,"_domLayerInfoMap",new Map);J(this,"_transformChange$",new N.Subject);J(this,"transformChange$",this._transformChange$.asObservable());J(this,"_add$",new N.Subject);J(this,"add$",this._add$.asObservable());J(this,"_remove$",new N.Subject);J(this,"remove$",this._remove$.asObservable());J(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(n=>n===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:s}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var fe,le,oe;const{unitId:t,subUnitId:o,drawingId:s}=e,a=v.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!a)return;const c=(fe=this._renderManagerService.getRenderById(t))==null?void 0:fe.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!c)return;const{transform:h,drawingType:g,data:p}=d;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:w,canvas:_}=S;if(h==null)return!0;if(u!==o)return;const{left:D,top:y,width:T,height:C,angle:M,flipX:I,flipY:A,skewX:b,skewY:x}=h,W=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),O=w.getObject(W);if(O!=null){O.transformByState({left:D,top:y,width:T,height:C,angle:M,flipX:I,flipY:A,skewX:b,skewY:x});return}const R={left:D,top:y,width:T,height:C,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},k=g===l.DrawingTypeEnum.DRAWING_CHART;if(k){const $=p?p.backgroundColor:"white";R.fill=$,R.rotateEnabled=!1,p&&p.border&&(R.stroke=p.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8}const L=new U.Rect(W,R);k&&L.setObjectType(U.ObjectType.CHART),w.addObject(L,U.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(L);const Y=this._ensureMap(t,o),j=new l.DisposableCollection,V=ye(L,S.renderUnit,c.skeleton,a.worksheet),K=new N.BehaviorSubject(V),re={dispose:j,rect:L,position$:K,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:K,id:s,componentKey:d.componentKey,onPointerDown:$=>{_.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{_.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{_.dispatchEvent(new PointerEvent($.type,$))},onWheel:$=>{_.dispatchEvent(new WheelEvent($.type,$))},props:(oe=(le=Y.get(s))==null?void 0:le.props)!=null?oe:this._getFloatDomProps(s),data:p,unitId:t});const ie=L.onTransformChange$.subscribeEvent(()=>{const $=ye(L,S.renderUnit,c.skeleton,a.worksheet);K.next($)});j.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),ie&&j.add(ie),this._domLayerInfoMap.set(s,re),Y.set(s,{...Y.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:s}=e,a=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,t),a=Array.from(s.keys()),d=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!m||a.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const g=ye(h.rect,o.renderUnit,m.skeleton,d.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.filter(e=>!!e),N.switchMap(e=>e.activeSheet$),N.filter(e=>!!e),N.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),N.filter(e=>!!e),N.switchMap(e=>l.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:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===P.SetZoomRatioOperation.id){const s=e.params,{unitId:a}=s;Array.from((o=(t=this._domLayerMap.get(a))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(a,m)})}else if(e.id===v.SetFrozenMutation.id){const{unitId:s,subUnitId:a}=e.params;n(s,a)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:s,endY:a}=n,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(P.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(t,s);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:s-m.startY},c=d.getCellWithCoordByOffset(o,a);if(c==null)return;const h={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const s=this._domLayerInfoMap.get(t),a=this._getSceneAndTransformerByDrawingSearch(n);if(s&&a){const{scene:d}=a,m=E.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=d.getObject(m);u&&u instanceof U.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=v.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=t,{initPosition:a,componentKey:d,data:m,allowTransform:u=!0}=n,c=e!=null?e:l.generateRandomId(),h=this._getPosition(a,o);if(h==null)return;this._ensureMap(o,s).set(c,n);const p={unitId:o,subUnitId:s,drawingId:c,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:h,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:m,allowTransform:u};return this._commandService.executeCommand(ke.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:s}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(t.rect),e){this._ensureMap(o,s).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:h}=u;this._commandService.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:c,objects:h,type:f.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var x,W,O,R,k,L;const s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(x=this._renderManagerService.getRenderById(a))==null?void 0:x.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w}=this._createRangePositionObserver(n,u,c.skeleton),_=this._getPosition(w,a);if(_==null)return;this._ensureMap(a,d).set(S,e);const y=w.endX-w.startX,T=w.endY-w.startY,C=(W=t.width)!=null?W:y,M=(O=t.height)!=null?O:T,I=w.startX+Me(t.marginX,y),A=w.startY+Me(t.marginY,T),b={unitId:a,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:_,transform:{left:I,top:A,width:C,height:M},data:g,allowTransform:p};{const{unitId:Y,subUnitId:j,drawingId:V}=b,K=v.getSheetCommandTarget(this._univerInstanceService,{unitId:Y,subUnitId:j}),re=b,ie=this._univerInstanceService.getUnit(Y,l.UniverInstanceType.UNIVER_SHEET);if(!ie)return;const fe=ie.getActiveSheet().getSheetId();if(!re||!K)return;const le=(R=this._renderManagerService.getRenderById(Y))==null?void 0:R.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(j);if(!le)return;const{transform:oe,drawingType:$,data:se}=re;if($!==l.DrawingTypeEnum.DRAWING_DOM&&$!==l.DrawingTypeEnum.DRAWING_CHART)return;const Re=this._getSceneAndTransformerByDrawingSearch(Y);if(Re==null)return;const{scene:ae,canvas:ce}=Re;if(oe==null||fe!==j)return;const{left:we,top:be,width:Ee,height:Oe,angle:$e,flipX:ot,flipY:st,skewX:at,skewY:ct}=oe,Ge=E.getDrawingShapeKeyByDrawingSearch({unitId:Y,subUnitId:j,drawingId:V}),Pe=ae.getObject(Ge);if(Pe!=null){Pe.transformByState({left:we,top:be,width:Ee,height:Oe,angle:$e,flipX:ot,flipY:st,skewX:at,skewY:ct});return}const te={left:we,top:be,width:Ee,height:Oe,zIndex:this._drawingManagerService.getDrawingOrder(Y,j).length-1},Fe=$===l.DrawingTypeEnum.DRAWING_CHART;if(Fe){const B=se?se.backgroundColor:"white";te.fill=B,te.rotateEnabled=!1,se&&se.border&&(te.stroke=se.border),te.paintFirst="stroke",te.strokeWidth=1,te.borderEnabled=!1,te.radius=8}const q=new U.Rect(Ge,te);Fe&&q.setObjectType(U.ObjectType.CHART),ae.addObject(q,U.DRAWING_OBJECT_LAYER_INDEX),re.allowTransform!==!1&&ae.attachTransformerTo(q);const Se=this._ensureMap(Y,j),_e=new l.DisposableCollection,ue=ae.getMainViewport(),dt={top:ue.top,left:ue.left,bottom:ue.bottom,right:ue.right},de={dispose:_e,rect:q,boundsOfViewArea:dt,unitId:Y,subUnitId:j},lt=ye(q,Re.renderUnit,le.skeleton,K.worksheet,de),ve=new N.BehaviorSubject(lt);de.position$=ve;let Ie={position$:ve,id:V,componentKey:re.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:B=>{ce.dispatchEvent(new WheelEvent(B.type,B))},props:(L=(k=Se.get(V))==null?void 0:k.props)!=null?L:this._getFloatDomProps(V),data:se,unitId:Y};e.eventPassThrough&&(Ie={...Ie,onPointerDown:B=>{ce.dispatchEvent(new PointerEvent(B.type,B))},onPointerMove:B=>{ce.dispatchEvent(new PointerEvent(B.type,B))},onPointerUp:B=>{ce.dispatchEvent(new PointerEvent(B.type,B))}}),this._canvasFloatDomService.addFloatDom(Ie);const Ae=q.onTransformChange$.subscribeEvent(()=>{const B=ye(q,Re.renderUnit,le.skeleton,K.worksheet,de);ve.next(B)});_e.add(()=>{this._canvasFloatDomService.removeFloatDom(V)}),Ae&&_e.add(Ae),this._domLayerInfoMap.set(V,de),Se.set(V,{...Se.get(V)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var W,O,R,k,L,Y;const s=v.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(W=this._renderManagerService.getRenderById(a))==null?void 0:W.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:w}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),_=w;_.startY=0;const D=this._getPosition(w,a);if(D==null)return;this._ensureMap(a,d).set(S,e);const T=w.endX-w.startX,C=w.endY-w.startY,M=(O=t.width)!=null?O:T,I=(R=t.height)!=null?R:C;let A=0,b=0;if(t.horizonOffsetAlign==="right"){const j=Me(t.marginX,T);A=_.endX-j-M}else A=_.startX+Me(t.marginX,T);if(t.verticalOffsetAlign==="bottom"){const j=Me(t.marginY,C);b=_.endY-j-I}else b=_.startY+Me(t.marginY,C);const x={unitId:a,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:D,transform:{left:A,top:b,width:M,height:I},data:g,allowTransform:p};{const{unitId:j,subUnitId:V,drawingId:K}=x,re=v.getSheetCommandTarget(this._univerInstanceService,{unitId:j,subUnitId:V}),ie=x,fe=this._univerInstanceService.getUnit(j,l.UniverInstanceType.UNIVER_SHEET);if(!fe)return;const le=fe.getActiveSheet().getSheetId();if(!ie||!re)return;const oe=(k=this._renderManagerService.getRenderById(j))==null?void 0:k.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(V);if(!oe)return;const{transform:$,drawingType:se,data:Re}=ie;if(se!==l.DrawingTypeEnum.DRAWING_DOM&&se!==l.DrawingTypeEnum.DRAWING_CHART)return;const ae=this._getSceneAndTransformerByDrawingSearch(j);if(ae==null)return;const{scene:ce,canvas:we}=ae;if($==null||le!==V)return;const{left:be,top:Ee,width:Oe,height:$e,angle:ot,flipX:st,flipY:at,skewX:ct,skewY:Ge}=$,Pe=E.getDrawingShapeKeyByDrawingSearch({unitId:j,subUnitId:V,drawingId:K}),te=ce.getObject(Pe);if(te!=null){te.transformByState({left:be,top:Ee,width:Oe,height:$e,angle:ot,flipX:st,flipY:at,skewX:ct,skewY:Ge});return}const Fe={left:be,top:Ee,width:Oe,height:$e,zIndex:this._drawingManagerService.getDrawingOrder(j,V).length-1},q=new U.Rect(Pe,Fe);ce.addObject(q,U.DRAWING_OBJECT_LAYER_INDEX),ie.allowTransform!==!1&&ce.attachTransformerTo(q);const Se=this._ensureMap(j,V),_e=new l.DisposableCollection,ue=ce.getMainViewport(),dt={top:0,left:ue.left,bottom:ue.bottom,right:ue.right},de={dispose:_e,rect:q,unitId:j,subUnitId:V,boundsOfViewArea:dt,scrollDirectionResponse:"HORIZONTAL"},lt=ye(q,ae.renderUnit,oe.skeleton,re.worksheet,de),ve=new N.BehaviorSubject(lt);de.position$=ve;let Ie={position$:ve,id:K,componentKey:ie.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:B=>{we.dispatchEvent(new WheelEvent(B.type,B))},props:(Y=(L=Se.get(K))==null?void 0:L.props)!=null?Y:this._getFloatDomProps(K),data:Re,unitId:j};e.eventPassThrough&&(Ie={...Ie,onPointerDown:B=>{we.dispatchEvent(new PointerEvent(B.type,B))},onPointerMove:B=>{we.dispatchEvent(new PointerEvent(B.type,B))},onPointerUp:B=>{we.dispatchEvent(new PointerEvent(B.type,B))}}),this._canvasFloatDomService.addFloatDom(Ie);const Ae=q.onTransformChange$.subscribeEvent(()=>{const B=ye(q,ae.renderUnit,oe.skeleton,re.worksheet,de);ve.next(B)});_e.add(()=>{this._canvasFloatDomService.removeFloatDom(K)}),Ae&&_e.add(Ae),this._domLayerInfoMap.set(K,de),Se.set(K,{...Se.get(K)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:s}=n;const a=je(o,s,t),d=new N.BehaviorSubject(a),m=je(n.endRow,n.endColumn,t),u=new N.BehaviorSubject(m),c=()=>{const _=je(o,s,t),D=je(n.endRow,n.endColumn,t);d.next(_),u.next(D)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>c())),h.add(this._commandService.onCommandExecuted(_=>{if(_.id===v.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(y=>y.row===o)>-1){c();return}(v.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===P.SetScrollOperation.id||_.id===P.SetZoomRatioOperation.id)&&c()}));const g=(_,D)=>{o=_,s=D,c()},p=()=>({rotate:0,width:m.right-a.left,height:m.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:m.right,endY:m.bottom}),S=d.pipe(N.map(_=>{const D=je(n.endRow,n.endColumn,t);return console.log("service",_.left,_.top),{rotate:0,width:D.right-_.left,height:D.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:D.right,endY:D.bottom}})),w=p();return console.log("init position",w),{position$:S,position:w,updateRowCol:g,topLeftPos$:d,rightBottomPos$:u,disposable:h}}};exports.SheetCanvasFloatDomManagerService=pr([Ce(0,l.Inject(U.IRenderManagerService)),Ce(1,l.IUniverInstanceService),Ce(2,l.Inject(l.ICommandService)),Ce(3,E.IDrawingManagerService),Ce(4,l.Inject(H.CanvasFloatDomService)),Ce(5,f.ISheetDrawingService),Ce(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function je(i,r,n){const e=n.getCellWithCoordByIndex(i,r),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function Me(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const n=Number.parseFloat(i);return r*n/100}var kt=Object.defineProperty,wr=Object.getOwnPropertyDescriptor,Sr=(i,r,n)=>r in i?kt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,_r=(i,r,n,e)=>{for(var t=e>1?void 0:e?wr(r,n):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(r,n,t):s(t))||t);return e&&t&&kt(r,n,t),t},ht=(i,r)=>(n,e)=>r(n,e,i),Lt=(i,r,n)=>Sr(i,typeof r!="symbol"?r+"":r,n);const vr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Rt,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...s}=l.merge({},Rt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Gt,s)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[rt],[qe],[nt],[tt],[et],[Je],[Qe],[Ze]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[et]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[tt],[nt],[rt],[Je],[Qe],[Ze]])}onSteady(){this._injector.get(qe)}_registerRenderModules(){[[We],[ft],[mt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Lt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Lt(exports.UniverSheetsDrawingUIPlugin,"pluginName",vr);exports.UniverSheetsDrawingUIPlugin=_r([l.DependentOn(E.UniverDrawingPlugin,Et.UniverDocsDrawingPlugin,pe.UniverDrawingUIPlugin,f.UniverSheetsDrawingPlugin),ht(1,l.Inject(l.Injector)),ht(2,U.IRenderManagerService),ht(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=Dt;exports.EditSheetDrawingOperation=St;exports.GroupSheetDrawingCommand=_t;exports.InsertFloatImageCommand=it;exports.InsertSheetDrawingCommand=ke;exports.MoveDrawingsCommand=Te;exports.RemoveSheetDrawingCommand=Be;exports.SHEETS_IMAGE_MENU_ID=yt;exports.SetDrawingArrangeCommand=vt;exports.SetSheetDrawingCommand=Le;exports.SidebarSheetDrawingOperation=wt;exports.UngroupSheetDrawingCommand=It;