@univerjs-pro/sheets-shape-ui 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/shape-editor-ui"),require("@univerjs/ui"),require("@univerjs-pro/engine-shape"),require("@univerjs-pro/shape-editor"),require("@univerjs-pro/sheets-shape"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/drawing"),require("rxjs"),require("@univerjs/drawing-ui"),require("@univerjs/design"),require("react/jsx-runtime"),require("@univerjs-pro/license"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/sheets-drawing-ui"),require("react")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/shape-editor-ui`,`@univerjs/ui`,`@univerjs-pro/engine-shape`,`@univerjs-pro/shape-editor`,`@univerjs-pro/sheets-shape`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-drawing`,`@univerjs/sheets-ui`,`@univerjs/drawing`,`rxjs`,`@univerjs/drawing-ui`,`@univerjs/design`,`react/jsx-runtime`,`@univerjs-pro/license`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/sheets-drawing-ui`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProSheetsShapeUi={},e.UniverProShapeEditorUi,e.UniverUi,e.UniverProEngineShape,e.UniverProShapeEditor,e.UniverProSheetsShape,e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsDrawing,e.UniverSheetsUi,e.UniverDrawing,e.rxjs,e.UniverDrawingUi,e.UniverDesign,e.React,e.UniverProLicense,e.UniverDocs,e.UniverDocsUi,e.UniverSheetsDrawingUi,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function x(e,t){let n={};for(let r of Object.keys(t)){let i=t[r],a=e[r];n[r]=a===void 0?void 0:typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a&&!Array.isArray(a)?x(a,i):a}return n}let S={type:o.CommandType.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(a.SheetsShapeService),{unitId:r,subUnitId:i,shapeType:s,shapeId:c,shapeData:l,replaceShapeData:u,oldShapeJSON:d}=t;if(!n.getShapeModel(r,i,c))return!1;let f=e.get(o.ICommandService),p=e.get(o.IUndoRedoService),{oldShapeType:m,oldShapeData:h={}}=d,g=u?h:x(h,l||{}),_={id:a.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:i,shapeId:c,shapeType:s,shapeData:l,replace:u}},v={id:a.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:i,shapeId:c,shapeType:m,shapeData:g,replace:u}};return f.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:r,undoMutations:[v],redoMutations:[_]}),!0):!1}};function C(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(S.id,o)}function w(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(S.id,o)}function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function ee(e,t){if(T(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function te(e){var t=ee(e,`string`);return T(t)==`symbol`?t:t+``}function E(e,t,n){return(t=te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ne(e,n,r){let i={...n,dataModel:{...n.dataModel??{},...r?{doc:r}:null}},a=(0,t.resolveShapeTextEditorBehaviorShapeData)(e,i),o=(0,t.resolveShapeTextEditorWrapStrategy)(a);return{clip:(0,t.shouldClipShapeTextDocument)(a,o),wrapStrategy:o}}var D=class extends s.Shape{constructor(e,n){super(e,n),E(this,`_hyperLinkRegions`,[]),E(this,`_props`,void 0),E(this,`_formulaAnimation`,new t.FormulaShapeAnimationController(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),E(this,`_transformCalculateSrcRect`,!0),E(this,`_drawingType`,o.DrawingTypeEnum.DRAWING_SHAPE),E(this,`isDrawingObject`,!0),this._props={...n},this._formulaAnimation.setPresentation(n.formulaPresentation,n.animateFormulaPresentation!==!1),this._init(),this._applyFormulaAutoFitSize()}_init(){this.onTransformChange$.subscribeEvent(e=>{this._updateSrcRectByTransform(e)})}setPrstGeom(e){this._props.prstGeom=e}resolveHyperLinkAt(e){if(this._props.isEditing)return null;let n=this.getInverseCoord(e),{width:r,height:i}=this.getRealBound();return(0,t.resolveShapeTextHyperLinkAt)(this._hyperLinkRegions,{x:(this.flipX?-n.x:n.x)+r/2,y:n.y+i/2})}setEditing(e){this._props.isEditing=e,this.makeDirty(!0)}setFormulaPresentation(e,t=!0){this._formulaAnimation.setPresentation(e,t),this._props.formulaPresentation=e,this._applyFormulaAutoFitSize(),this.makeDirty(!0)}_applyFormulaAutoFitSize(){let e=this._props.shapeModel,n=e.getShapeTextData(),r=(0,t.normalizeShapeTextModel)(n==null?void 0:n.dataModel),a=r==null?void 0:r.doc,o=this._formulaAnimation.getAutoFitPresentations();if(!a||o.length===0)return;e.updateContext({width:this.width,height:this.height});let s=(0,t.resolveFormulaShapeAutoFitSize)({documentData:o.map(e=>(0,i.createShapeFormulaDocument)(a,e)),height:this.height,shapeData:e.getShapeData(),textRect:e.getShapeTextRect({left:0,top:0,width:this.width,height:this.height}),width:this.width});if(s){var c;this.resize(s.width,s.height),(c=this.getScene())==null||(c=c.getTransformer())==null||c.debounceRefreshControls()}}get unitId(){return this._props.unitId}get subUnitId(){return this._props.subUnitId}_updateSrcRectByTransform(e){if(this._props.srcRect==null||!this._transformCalculateSrcRect)return;let{width:t,height:n}=this,{width:r=0,height:i=0}=e.preValue,{left:a=0,top:o=0,right:s=0,bottom:c=0}=this._props.srcRect,l=a,u=o,d=s,f=c,p=!1;if(r!==0&&r!==t){let e=a/r,n=s/r;l=t*e,d=t*n,p=!0}if(i!==0&&i!==n){let e=o/i,t=c/i;u=n*e,f=n*t,p=!0}p&&this.setSrcRect({left:l,top:u,right:d,bottom:f})}setSrcRect(e){this._props.srcRect=e,this.makeDirty(!0)}setFillImage(e){this._props.image=e,this.makeDirty(!0)}set transform(e){this._transform=e}get transform(){this._transform||this._setTransForm();let e=this._transform.clone();return this.transformForAngle(e)}get shapeModel(){return this._props.shapeModel}get shapeId(){return this._props.shapeId}get classType(){return s.RENDER_CLASS_TYPE.SHAPE}_draw(e,t,n,i){let a=this._props.shapeModel;if(!a||!t)return;let o=n??this.width,s=i??this.height,c={shapeType:a.getShapeType(),width:o,height:s},l={renderMode:r.ShapeRenderModeEnum.Path,oKey:this.oKey,image:this._props.image,angle:this.angle};a.updateContext(c),e.save();let u={top:0,left:0,width:o,height:s},d=a.getDrawingEffectBounds(u);d?this._renderWithCache(e,d,e=>{a.render(e,u,l)}):(this._releaseRenderCache(),a.render(e,u,l)),e.restore();let f=a.getShapeTextData(),p=a.getShapeTextRect(u),m=a.isLineShape();if(f&&p&&!m){e.save(),this.getState().flipX&&e.scale(-1,1);let t=o/2,n=s/2;e.translate(-t,-n),e.beginPath(),this._drawShapeText(e,f,p),e.restore()}}getDrawingPoints(e){}_drawShapeText(e,t,n){var r;this._hyperLinkRegions=[],this._props.isEditing||(!((r=t.dataModel)!=null&&r.doc)&&`isRichText`in t&&t.isRichText===!1?this._drawSimpleText(e,t,n):this._drawRichText(e,t,n))}_drawSimpleText(e,n,r){this._drawRichText(e,{...n,text:n.text??``,dataModel:{doc:(0,t.plainShapeTextToDocumentData)(n,`sheets-shape-text-${this.oKey}`)}},r)}_drawRichText(e,n,r){(0,t.drawFormulaShapeAnimationLayers)(e,this._formulaAnimation,(e,t,i)=>{this._drawRichTextLayer(e,n,r,t,i===`current`)})}_drawRichTextLayer(e,n,r,a,c){let l=this._props.localeService;if(!n.dataModel||!l)return;let u=(0,t.normalizeShapeTextModel)(n.dataModel);if(!u)return;let d=u.doc;if(!d)return;let f=(0,i.createShapeFormulaDocument)(d,a),p=u.va??o.VerticalAlign.TOP,m=u.ha??o.HorizontalAlign.LEFT,h=ne(this._props.shapeModel.getShapeData(),n,f),g=n.isHorizontal,_=(0,t.prepareShapeTextDocumentData)(f,{isHorizontal:g!==!1,textRect:r,verticalAlign:p,horizontalAlign:m,wrapStrategy:h.wrapStrategy}),v=new o.DocumentDataModel(_),y=new s.DocumentViewModel(v),b=s.DocumentSkeleton.create(y,l);b.calculate();let x=b.getActualSize().actualHeight,S=(0,t.resolveShapeTextDocumentRenderLayout)({contentHeight:x,verticalAlign:p,viewportHeight:r.height});v.updateDocumentStyle({pageSize:{width:g===!1?r.height:r.width,height:(0,t.resolveShapeTextDocumentPageHeight)(f,S.contentHeight)}}),v.updateDocumentDataMargin({t:S.marginTop}),b.calculate();let C=new s.Documents(`shape-text-${this.oKey}`,b,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});C.resize(r.width,S.contentHeight),e.save(),e.translateWithPrecision(r.left,r.top),h.clip&&(e.beginPath(),e.rect(0,S.clipTop,r.width,S.clipHeight),e.clip()),S.contentVerticalOffset&&e.translateWithPrecision(0,S.contentVerticalOffset),C.draw(e),c&&(this._hyperLinkRegions=(0,t.createShapeTextHyperLinkRegions)(C,{left:r.left,top:r.top+S.contentVerticalOffset},h.clip?{left:r.left,right:r.left+r.width,top:r.top+S.clipTop,bottom:r.top+S.clipTop+S.clipHeight}:void 0)),e.restore(),C.dispose(),b.dispose(),y.dispose(),v.dispose()}render(e,t,n=!1){if(!this.visible)return this.makeDirty(!1),this;let{width:r,height:i,left:a,top:o}=this,c=this.getRealBound();if(r=c.width,i=c.height,a=c.left,o=c.top,this.isRender(t)){let{top:e,left:n,bottom:s,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+o<e||s<o)return this}let l=a+r/2,u=o+i/2,d=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new s.Transform;t.composeMatrix({...e}),d=t.getMatrix()}return e.save(),this._props.shapeModel.isRenderLinePointsMode===!0||e.transform(d[0],d[1],d[2],d[3],l,u),this._draw(e,t,r,i),e.restore(),this.makeDirty(!1),this}getInverseCoord(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=this.transform.getMatrix(),o=t+r/2,c=n+i/2,l=new s.Transform([a[0],a[1],a[2],a[3],o,c]),u=this.getParent();return(this.isInGroup&&(u==null?void 0:u.classType)===s.RENDER_CLASS_TYPE.GROUP?u.ancestorTransform.multiply(l):l).invert().applyPoint(e)}isHit(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=t+r/2,o=n+i/2,c=this.transform.getMatrix(),l=new s.Transform([c[0],c[1],c[2],c[3],a,o]),u=this.getParent(),d=(this.isInGroup&&(u==null?void 0:u.classType)===s.RENDER_CLASS_TYPE.GROUP?u.ancestorTransform.multiply(l):l).invert().applyPoint(e),f=r/2,p=i/2,m=this._props.shapeModel;return m&&m.isLineShape()?m.isHitLine(d.x,d.y,r,i):d.x>=-f-this.strokeWidth/2&&d.x<=f+this.strokeWidth/2&&d.y>=-p-this.strokeWidth/2&&d.y<=p+this.strokeWidth/2}dispose(){this._formulaAnimation.dispose(),this._props.shapeModel=null,super.dispose()}},O=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_shapeId`,null),E(this,`_adjName`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),t&&this.setShapeProps(t)}getDrawingSearch(){return{unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._shapeId}}setShapeProps(e){e.shapeId!==void 0&&(this._shapeId=e.shapeId),e.adjName!==void 0&&(this._adjName=e.adjName),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),this.transformByState({width:e.width,height:e.height})}_draw(e){s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.adjHandleSize,fill:r.ShapeDefaultConfig.adjHandleFill,stroke:r.ShapeDefaultConfig.adjHandleStroke,strokeWidth:1,evented:!0})}};function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._drawingManagerService=e,this._sheetsShapeService=t,this._localeService=n,this._imageIoService=r,this._urlImageService=i,this._shapeFormulaService=a,E(this,`_formulaShapes`,/* @__PURE__ */ new Map),this.disposeWithMe(this._shapeFormulaService.presentationChanged$.subscribe(e=>{var t;(t=this._formulaShapes.get(this._formulaKey(e.unitId,e.subUnitId,e.shapeId)))==null||t.forEach(t=>t.setFormulaPresentation(e.presentation,e.animationEnabled))})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._formulaShapes.delete(this._formulaKey(e.unitId,e.subUnitId,e.drawingId))})}))}renderDrawingShape(e,t,n){let{transform:r,drawingType:i,isMultiTransform:a,transforms:s}=e;if(i===o.DrawingTypeEnum.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(a&&s?s:[r]).flatMap((r,i)=>{var o;let s=(0,d.getDrawingShapeKeyByDrawingSearch)(e,a?i:void 0),c=t.getObjectIncludeInGroup(s);if(c)return c instanceof D&&this.refreshFormulaPresentation(c,{unitId:e.unitId,subUnitId:e.subUnitId,shapeId:e.drawingId}),c.transformByState(r),[];let l=this._createShape(e,r,s,t);if(!l)return[];let u=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return u&&(n==null||(o=n.resourceCollector)==null||o.add(u)),[l]})}_createShape(e,n,i,a){let{unitId:c,subUnitId:l,drawingId:u,groupId:d,hidden:f,selectable:m,prstGeom:h,srcRect:g}=e,_=this._sheetsShapeService.getShapeModel(c,l,u);if(!_)return;let v=this._drawingManagerService.getDrawingOrder(c,l),y=v.indexOf(u),b=(0,r.isConnectorShape)(_.getShapeType()),x=_.getShapeData().formulaBinding,S={unitId:c,subUnitId:l,shapeId:u};x&&this._shapeFormulaService.register(S,x);let C=new D(i,{...n,zIndex:y===-1?v.length-1:y,shapeModel:_,drawingType:o.DrawingTypeEnum.DRAWING_SHAPE,localeService:this._localeService,shapeId:u,unitId:c,subUnitId:l,visible:f!==!0,evented:m!==!1,formulaPresentation:x?this._shapeFormulaService.getPresentation(S):void 0,animateFormulaPresentation:(x==null?void 0:x.animationEnabled)!==!1,transformerConfig:{...t.SHAPE_EDITOR_TRANSFORMER_CONFIG,...b?{rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1}:{},moveBoundaryEnabled:!0}});if(x){let e=this._formulaKey(c,l,u),t=this._formulaShapes.get(e)??/* @__PURE__ */ new Set;t.add(C),this._formulaShapes.set(e,t)}return a.addObject(C,s.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&a.attachTransformerTo(C),d&&(0,p.insertGroupObject)({drawingId:d,unitId:c,subUnitId:l},C,a,this._drawingManagerService),h!=null&&C.setPrstGeom(h),g!=null&&C.setSrcRect(g),C}_formulaKey(e,t,n){return`${e}\u0000${t}\u0000${n}`}refreshFormulaPresentation(e,t){let n=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.shapeId),r=n==null?void 0:n.getShapeData().formulaBinding,i=this._formulaKey(t.unitId,t.subUnitId,t.shapeId);if(r){this._shapeFormulaService.register(t,r);let n=this._formulaShapes.get(i)??/* @__PURE__ */ new Set;n.add(e),this._formulaShapes.set(i,n)}else{var a;this._shapeFormulaService.unregister(t),(a=this._formulaShapes.get(i))==null||a.delete(e)}e.setFormulaPresentation(r?this._shapeFormulaService.getPresentation(t):void 0,(r==null?void 0:r.animationEnabled)!==!1)}refreshShapeFillImage(e){let t=e.shapeModel.getShapeData(),n=t.fill;!n||n.fillType!==r.ShapeFillEnum.PictureFill||!n.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let n=t.fill;if(!n||n.fillType!==r.ShapeFillEnum.PictureFill||!n.fillImageSource)return;let i=n.fillImageSource,a=n.fillImageSourceType??r.ImageSourceTypeEnum.URL,o=this._imageIoService.getImageSourceCache(i,a);if(o)e.setFillImage(o);else return this._loadAndSetImage(e,i,a)}async _loadAndSetImage(e,t,n){let i;try{if(n===r.ImageSourceTypeEnum.UUID)i=await this._imageIoService.getImage(t);else if(n===r.ImageSourceTypeEnum.URL)try{i=await this._urlImageService.getImage(t)}catch{i=t}else i=t}catch(e){console.error(`[ShapeRender] Failed to resolve picture fill source`,e);return}await new Promise(r=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,n,a),e.setFillImage(a),r()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),r()},a.src=i})}};j=A([k(0,d.IDrawingManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,(0,o.Inject)(o.LocaleService)),k(3,o.IImageIoService),k(4,o.IURLImageService),k(5,(0,o.Inject)(i.ShapeFormulaService))],j);let M=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._drawingManagerService=e,this._sheetsShapeService=t,this._renderManagerService=n,this._sheetDrawingShapeRenderController=r,this._univerInstanceService=i,this._commandService=a,E(this,`_activeShapeId`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_activeShapeAdjustPointList`,void 0),E(this,`_shapes`,[]),E(this,`_baseShapeLeft`,0),E(this,`_baseShapeTop`,0),E(this,`_baseShapeWidth`,0),E(this,`_baseShapeHeight`,0),E(this,`_isStartAdjusting`,!1),E(this,`_activeAdjustInfo`,void 0),E(this,`_activeShapeModel`,void 0),E(this,`_adjHandlerPointerMove`,void 0),E(this,`_adjHandlerPointerUp`,void 0),E(this,`_isShouldShowDrawingShapeAdjust`,!1),this._registerDrawingFocusChangeHandler(),this._registerDrawingMoveHandler()}_getShapeAdjustPointListById(e,t,n){let r=this._sheetsShapeService.getShapeModel(e,t,n);if(r)return r.getDrawingPoints()}clearAdjustControls(){this._clearShapeAdjustControls()}refreshAdjustControls(){this._updateShapeAdjustControls(!0)}setShouldShowAdjust(e){this._isShouldShowDrawingShapeAdjust=e}_getShapeAdjustInfosById(e,t,n,r){let i=this._sheetsShapeService.getShapeModel(e,t,n);if(i)return i.getAdjustInfoByName(r)}_createShapeAdjustControls(e=!1){if(this._unitId===null||this._subUnitId===null||this._activeShapeId===null)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:a}=i;if(!a||i.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let{left:s,top:c,width:l,height:d,flipX:f,flipY:p,angle:m=0}=a;if(s===void 0||c===void 0)return;if(e){let e=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);e==null||e.updateContext({width:l??0,height:d??0}),this._activeShapeAdjustPointList=e==null?void 0:e.getDrawingPoints()}let h=this._activeShapeAdjustPointList;for(let e=0;e<h.length;e++){let t=h[e],r=t.x,i=t.y;if(f&&(r=(l||0)-r),p&&(i=(d||0)-i),m!==0){let e=(l||0)/2,t=(d||0)/2,n=m*Math.PI/180,a=Math.cos(n),o=Math.sin(n),s=r-e,c=i-t;r=e+(s*a-c*o),i=t+(s*o+c*a)}let a={x:r,y:i,adjName:t.adjName};this._addShapeAdjustControl(n,a,a.adjName,s,c,this._unitId,this._subUnitId)}}_updateShapeAdjustControls(e=!1){e&&(this._clearShapeAdjustControls(),this._createShapeAdjustControls(e))}_addShapeAdjustControl(e,t,n,i,a,o,c){if(!this._activeShapeId)return;let l=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${n}`);if(l){l.transformByState({left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize});return}let u={left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize,adjName:n,shapeId:this._activeShapeId,unitId:o,subUnitId:c,width:r.ShapeDefaultConfig.adjHandleSize+8,height:r.ShapeDefaultConfig.adjHandleSize+8,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0},d=new O(`shape-adjust-point-${this._activeShapeId}-${n}`,u);this._shapes.push(d),this._attachAdjustEvent(d,e,n),e.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+1)}_clearShapeAdjustControls(){this._shapes.length!==0&&(this._shapes.forEach(e=>{e.dispose()}),this._shapes=[])}_updateAdjustControlPositions(){this._createShapeAdjustControls()}_getScrollInfo(e,t){var n;let r={x:0,y:0};if(!e||!t)return r;let i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_attachAdjustEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,c,l;let u=e.getDrawingSearch();this._activeAdjustInfo=this._getShapeAdjustInfosById(u.unitId,u.subUnitId,u.drawingId,n),this._activeShapeModel=this._sheetsShapeService.getShapeModel(u.unitId,u.subUnitId,u.drawingId);let d=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),{transform:f}=d;if(f){let{left:e,top:t,width:n,height:r}=f;this._baseShapeLeft=e||0,this._baseShapeTop=t||0,this._baseShapeWidth=n||0,this._baseShapeHeight=r||0}let p=!!((a=d.transform)!=null&&a.flipX),m=!!((o=d.transform)!=null&&o.flipY),h=((c=d.transform)==null?void 0:c.angle)||0;this._isStartAdjusting=!0,t.disableObjectsEvent();let g={...((l=this._activeAdjustInfo)==null?void 0:l.currentAdjustValues)??{}};this._adjHandlerPointerMove=t.onPointerMove$.subscribeEvent((e,n)=>{if(!this._isStartAdjusting)return;let{offsetX:r,offsetY:i}=e,a=this._activeAdjustInfo;if(this._activeShapeModel&&a){t.disableObjectsEvent(),t.setCursor(s.CURSOR_TYPE.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),c=r/o+n.x-this._baseShapeLeft,l=i/o+n.y-this._baseShapeTop;if(h!==0){let e=this._baseShapeWidth/2,t=this._baseShapeHeight/2,n=h*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=c-e,o=l-t;c=e+(a*r+o*i),l=t+(-a*i+o*r)}p&&(c=this._baseShapeWidth-c),m&&(l=this._baseShapeHeight-l);let d={x:c,y:l},f=this._activeShapeModel.calcAdjValues(e,d,a,p,m);if(Object.keys(f).length===0)return;for(let[e,t]of Object.entries(f))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseShapeWidth,height:this._baseShapeHeight});let g=this._drawingManagerService.getDrawingByParam({unitId:u.unitId,subUnitId:u.subUnitId,drawingId:u.drawingId});g&&(this._sheetDrawingShapeRenderController.renderDrawingShape(g,t),this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(u.unitId,u.subUnitId,u.drawingId),this._updateAdjustControlPositions())}n.stopPropagation()}),this._adjHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{this._adjHandlerPointerMove.unsubscribe(),this._adjHandlerPointerUp.unsubscribe(),t.resetCursor();let r=this._activeAdjustInfo;if(r){let e=u.unitId,t=u.subUnitId,n=u.drawingId,a={};for(let e of Object.keys(r.currentAdjustValues)){var i;let t=(i=this._activeShapeModel)==null?void 0:i.getAdjustValueByName(e);t!==void 0&&(a[e]=t)}Object.keys(a).length>0&&C(this._commandService,e,t,n,{oldShapeData:{adjustValues:g}},{adjustValues:a})}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(()=>{this._isShouldShowDrawingShapeAdjust})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;this._createShapeAdjustControls(),t!==null&&t.size===1&&t.values().next().value instanceof D&&this.setShouldShowAdjust(!0)})),this.disposeWithMe(t.changing$.subscribe(()=>{this._isShouldShowDrawingShapeAdjust&&this._clearShapeAdjustControls()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isShouldShowDrawingShapeAdjust&&(this.setShouldShowAdjust(!1),this._createShapeAdjustControls())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{this._unitId&&this._subUnitId&&this._activeShapeId&&this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId})&&(this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(this._unitId,this._subUnitId,this._activeShapeId),this._updateAdjustControlPositions())}))}))}_registerDrawingFocusChangeHandler(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==a.UpdateSheetsShapeDataMutation.id)return;let{unitId:t,subUnitId:n,shapeId:r}=e.params;t===this._unitId&&n===this._subUnitId&&r===this._activeShapeId&&this.refreshAdjustControls()})),this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let t=e[0];if(t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===o.UniverInstanceType.UNIVER_SHEET){this._activeShapeId=t.drawingId;let{unitId:e,subUnitId:n}=t;this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(e,n,this._activeShapeId),this._unitId=e,this._subUnitId=n,this._clearShapeAdjustControls(),this._createShapeAdjustControls();return}}this._activeShapeId=null,this._activeShapeAdjustPointList=void 0,this._unitId=null,this._subUnitId=null,this._clearShapeAdjustControls()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){var t;let n=e[0];((t=this._drawingManagerService.getDrawingByParam(n))==null?void 0:t.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE&&this._updateShapeAdjustControls(!0)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e)this._activeShapeId===t.drawingId&&(this._activeShapeId=null,this._activeShapeAdjustPointList=void 0,this._unitId=null,this._subUnitId=null,this._clearShapeAdjustControls())}))}};M=A([k(0,d.IDrawingManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,(0,o.Inject)(s.IRenderManagerService)),k(3,(0,o.Inject)(j)),k(4,o.IUniverInstanceService),k(5,o.ICommandService)],M);let re={id:`drawing.operation.set-drawing-active`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(d.IDrawingManagerService),r=e.get(s.IRenderManagerService),i=e.get(M);if(t==null)return!0;if(t.length>0){var a;let e=(a=r.getRenderUnitById(t[0].unitId))==null?void 0:a.scene;if(e){let{unitId:n,subUnitId:i,drawingId:a}=t[0],s=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(s);if(c){var o;(o=r.getRenderUnitById(t[0].unitId))==null||(o=o.scene.getTransformer())==null||o.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},N={type:o.CommandType.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var n,d;let f=(0,c.getSheetCommandTarget)(e.get(o.IUniverInstanceService));if(!f)return!1;let{unitId:p,subUnitId:m,worksheet:h}=f,g=h.getConfig(),_=g.type??o.SheetTypes.GRID;if(_!==o.SheetTypes.GRID&&_!==o.SheetTypes.CHART)return!1;let v=e.get(o.IPermissionService);if(((n=v.getPermissionPoint(new c.WorkbookEditablePermission(p).id))==null?void 0:n.value)!==!0||((d=v.getPermissionPoint(new c.WorksheetEditPermission(p,m).id))==null?void 0:d.value)!==!0)return!1;let y=e.get(o.ICommandService),{value:b,enhanceParams:x}=t,S={unitId:p,subUnitId:m,shapeType:b,shapeId:(0,o.generateRandomId)()};if(_===o.SheetTypes.CHART){let t=e.get(s.IRenderManagerService).getRenderUnitById(p),n=t==null?void 0:t.components.get(u.SHEET_VIEW_KEY.CHART_PAGE);if(!t||!n||![n.left,n.top,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return!1;let r={row:0,column:0,rowOffset:0,columnOffset:0},i=(0,l.transformDrawingsToChartSheet)([{unitId:p,subUnitId:m,drawingId:S.shapeId,drawingType:o.DrawingTypeEnum.DRAWING_SHAPE,transform:{left:0,top:0,width:a.DEFAULT_SHAPE_WIDTH,height:a.DEFAULT_SHAPE_HEIGHT},sheetTransform:{from:r,to:r},axisAlignSheetTransform:{from:r,to:r}}],{left:n.left,top:n.top,width:n.width,height:n.height},g.rightToLeft===o.BooleanNumber.TRUE);if(!(i!=null&&i.length))return!1;let c=i[0].transform;S.position={x:c.left,y:c.top},S.width=c.width,S.height=c.height}else{let t=e.get(c.SheetsSelectionsService).getCurrentLastSelection();if(!t)return!1;S.range=t.range}if(x){let{startArrow:t,endArrow:n,horizontal:a,vertical:s}=x,c=(0,r.isConnectorShape)(b),l=b===r.ShapeTypeEnum.Rect;if(c&&(t||n)&&(S.shapeData={ln:{startArrow:t?{type:r.ShapeArrowTypeEnum.Arrow,size:r.ShapeArrowSizeEnum.Medium}:void 0,endArrow:n?{type:r.ShapeArrowTypeEnum.Arrow,size:r.ShapeArrowSizeEnum.Large}:void 0}}),l&&(a||s)){let t=e.get(o.ThemeService);S.shapeData=(0,i.createShapeTextBoxShapeData)({fill:{fillType:r.ShapeFillEnum.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!a,stroke:{lineStrokeType:r.ShapeLineTypeEnum.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let C=y.syncExecuteCommand(a.InsertShapeCommand.id,S);return C&&await y.executeCommand(re.id,[{unitId:p,subUnitId:m,drawingId:S.shapeId}]),C}},P=`sheet.shape.edit.panel`,F=`sheet.shape.object-list.panel`,ie=`sheet.shape.floating-toolbar`,ae=`sheets-shape-ui.ribbon.shape-format`,oe=(0,o.createInternalEditorID)(`SHAPE_TEXT`),se=`sheet.shape.text.float-menu`,ce={id:`sheet.operation.open-shape-object-list-panel`,type:o.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ISidebarService),i=e.get(o.LocaleService),a=e.get(o.IUniverInstanceService),s=e.get(o.ICommandService);return(0,c.getSheetCommandTarget)(a)?(t==null?void 0:t.value)===`close`?(r.close(F),!0):(r.open({id:F,header:{title:i.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:F},onClose:()=>{s.syncExecuteCommand(d.SetDrawingSelectedOperation.id,[])},width:360}),!0):!1}},I={type:o.CommandType.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function le(e){let t=e.get(d.IDrawingManagerService).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return null;let r=e.get(a.SheetsShapeService),i=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),s=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return i===void 0||!s?null:{drawing:n,shapeData:s,shapeType:i}}let ue={id:`sheet.operation.apply-shape-quick-style`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=le(e),r=(0,i.getShapeQuickStylePreset)((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!r||r.type!==(0,i.getShapeQuickStyleType)(n.shapeData))return!1;let a=(0,i.applyQuickStyleToShapeData)(n.shapeData,r);if(!a)return!1;let{drawing:s}=n;return e.get(o.ICommandService).executeCommand(S.id,{unitId:s.unitId,subUnitId:s.subUnitId,shapeId:s.drawingId,shapeData:a,oldShapeJSON:{oldShapeData:n.shapeData}})}},de={id:`sheet.operation.update-shape-type`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=le(e),a=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!n||!a||(0,r.isConnectorShape)(n.shapeType)||(0,r.isConnectorShape)(a))return!1;let s=(0,i.cloneShapeDataForType)(n.shapeData,a);if(!s)return!1;let{drawing:c}=n;return e.get(o.ICommandService).executeCommand(S.id,{unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.drawingId,shapeType:a,shapeData:s,replaceShapeData:!0,oldShapeJSON:{oldShapeType:n.shapeType,oldShapeData:n.shapeData}})}},L=class extends o.Disposable{constructor(e,t){super(),this._clipService=e,this._drawingManagerService=t,this._registerImageShapeClipDelegate(),this._clipService.setCanUseShapeClip(!0),this.disposeWithMe({dispose:()=>this._clipService.setCanUseShapeClip(!1)})}_registerImageShapeClipDelegate(){let e=this._clipService,t=/* @__PURE__ */ new Map,n=e.registerClipDelegate((e,n,i,a,o)=>{let s=n;if(s===r.ShapeTypeEnum.None||n===`custom`)return!1;try{let c=t.get(n);return c||(c=new r.ShapeModel(s,`clip-${n}`),t.set(n,c)),c.clearAdjustValue(),o&&Object.keys(o).length>0&&c.setShapeData({adjustValues:o},!0),c.updateContext({width:i,height:a}),c.buildClipPath(e,{left:0,top:0,width:i,height:a})}catch{return!1}});this.disposeWithMe(n),this.disposeWithMe({dispose:()=>t.clear()})}clipByShape(e,t,n,r,i){let a=this._drawingManagerService.getDrawingData(e,t);if(!a[n])return;let o={...a[n],prstGeom:r,adjustValues:i};this._drawingManagerService.featurePluginUpdateNotification([o])}};L=A([k(0,(0,o.Inject)(p.DrawingImageClipService)),k(1,(0,o.Inject)(d.IDrawingManagerService))],L);let fe=`sheet.shape.picker.component`,pe=`sheet.image-clip.shape-picker.component`;function me({onShapeClick:e,excludeGroups:n}){return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerPanel,{excludeGroups:n,onShapeClick:e,scrollContainer:`parent`})}function he(){let e=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(L);return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[t.ShapeGroupEnum.Line],onShapeClick:t=>{let n=e.getFocusDrawings().find(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE);if(!n)return;let{unitId:i,subUnitId:a,drawingId:s}=n;r.clipByShape(i,a,s,t.type)}})}function ge(){let e=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(L);return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[t.ShapeGroupEnum.Line],DropdownComponent:m.MobileDropdown,onShapeClick:t=>{let n=e.getFocusDrawings().find(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE);if(!n)return;let{unitId:i,subUnitId:a,drawingId:s}=n;r.clipByShape(i,a,s,t.type)}})}function _e(){let e=(0,n.useDependency)(n.ComponentManager),t=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(o.IUniverInstanceService),i=t.getFocusDrawings()[0],a=i?r.getUnitType(i.unitId):void 0,s=a===o.UniverInstanceType.UNIVER_DOC?`doc.image-clip.shape-picker.component`:a===o.UniverInstanceType.UNIVER_SHEET?pe:void 0,c=s?e.get(s):void 0;return c?/* @__PURE__ */ (0,h.jsx)(c,{}):null}function ve(){let e=(0,n.useDependency)(o.ICommandService);return/* @__PURE__ */ (0,h.jsx)(me,{onShapeClick:t=>{e.executeCommand(N.id,{value:t.type,enhanceParams:{endArrow:t.endArrow,startArrow:t.startArrow,horizontal:t.horizontal,vertical:t.vertical}})}})}function ye(){return/* @__PURE__ */ (0,h.jsx)(ve,{})}function be(e){return(0,u.deriveStateFromActiveSheet$)(e.get(o.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??o.SheetTypes.GRID;if(r===o.SheetTypes.GRID)return(0,u.getCurrentRangeDisable$)(e);if(r!==o.SheetTypes.CHART)return(0,f.of)(!0);let i=e.get(o.IPermissionService),a=[new c.WorkbookEditablePermission(t.getUnitId()).id,new c.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,f.startWith)(null),(0,f.map)(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,f.distinctUntilChanged)())})}function xe(e){let t=e.get(o.IUniverInstanceService);return{id:N.id,type:n.MenuItemType.SELECTOR,selections:[{label:{name:fe,hoverable:!1,selectable:!1,props:{id:N.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:(0,u.deriveStateFromActiveSheet$)(t,!1,()=>new f.Observable(e=>{e.next(!1)})),hidden$:(0,n.getMenuHiddenObservable)(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:be(e)}}function Se(e){return(0,u.deriveStateFromActiveSheet$)(e.get(o.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??o.SheetTypes.GRID;if(r===o.SheetTypes.GRID)return(0,u.getCurrentRangeDisable$)(e);if(r!==o.SheetTypes.CHART)return(0,f.of)(!0);let i=e.get(o.IPermissionService),a=[new c.WorkbookEditablePermission(t.getUnitId()).id,new c.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,f.startWith)(null),(0,f.map)(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,f.distinctUntilChanged)())})}function Ce(e){let t=e.get(n.ISidebarService);return{id:ce.id,type:n.MenuItemType.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:(0,f.defer)(()=>t.sidebarOptions$.pipe((0,f.startWith)(t.options),(0,f.map)(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),(0,f.distinctUntilChanged)())),hidden$:(0,n.getMenuHiddenObservable)(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:Se(e)}}let we=`sheet.menu.shape.flip-horizontal`,Te=`sheet.menu.shape.flip-vertical`;function Ee(e){let t=e.get(d.IDrawingManagerService).getFocusDrawings();return t.length===1&&t[0].drawingType===o.DrawingTypeEnum.DRAWING_SHAPE?t[0]:null}function De(e){let t=e.get(d.IDrawingManagerService);return t.focus$.pipe((0,f.startWith)(t.getFocusDrawings()),(0,f.map)(e=>e.length!==1||e[0].drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE))}function Oe(e){return{id:we,commandId:a.ToggleSheetsShapeFlipCommand.id,type:n.MenuItemType.BUTTON,title:`sheets-shape-ui.flipHorizontal`,tooltip:`sheets-shape-ui.flipHorizontal`,icon:`FlipHorizontalIcon`,hidden$:De(e),params:()=>{let t=Ee(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipH:!0}:void 0}}}function ke(e){return{id:Te,commandId:a.ToggleSheetsShapeFlipCommand.id,type:n.MenuItemType.BUTTON,title:`sheets-shape-ui.flipVertical`,tooltip:`sheets-shape-ui.flipVertical`,icon:`FlipVerticalIcon`,hidden$:De(e),params:()=>{let t=Ee(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipV:!0}:void 0}}}let Ae=`sheets-shape-ui.shape-format.quick-style-gallery`,je=`sheets-shape-ui.shape-format.style-ribbon-control`,Me=`sheets-shape-ui.shape-format.text-ribbon-control`,Ne=`sheets-shape-ui.shape-format.formula-ribbon-control`;function Pe(){let e=(0,n.useDependency)(o.ICommandService),t=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(a.SheetsShapeService),i=()=>{var e;let n=t.getFocusDrawings();if(n.length!==1||((e=n[0])==null?void 0:e.drawingType)!==o.DrawingTypeEnum.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:a,drawingId:s}=n[0],c=r.getShapeTypeById(i,a,s),l=r.getShapeDataById(i,a,s);return c===void 0||!l?null:{unitId:i,subUnitId:a,drawingId:s,shapeType:c,shapeData:l}},s=(0,n.useObservable)(()=>new f.Observable(n=>{let r=()=>n.next(i()),o=t.focus$.subscribe(r),s=e.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&r()});return r(),()=>{o.unsubscribe(),s.dispose()}}),i(),!1,[e,t,r]);return{selection:s,updateShapeData:t=>{s&&C(e,s.unitId,s.subUnitId,s.drawingId,{oldShapeData:s.shapeData},t)}}}function Fe(){let{selection:e,updateShapeData:n}=Pe();return e?/* @__PURE__ */ (0,h.jsx)(t.ShapeStyleRibbonControl,{shapeData:e.shapeData,shapeType:e.shapeType,onUpdateShapeData:n}):null}function Ie(){let e=(0,n.useDependency)(o.ICommandService),r=(0,n.useDependency)(o.LocaleService),{selection:a}=Pe();return a?/* @__PURE__ */ (0,h.jsx)(t.ShapeQuickStyleGallery,{type:(0,i.getShapeQuickStyleType)(a.shapeData),ariaLabel:r.t(`sheets-shape-ui.quickStyles`),activePresetId:(0,i.resolveActiveShapeQuickStylePresetId)(a.shapeData),onSelect:t=>e.executeCommand(ue.id,{presetId:t})}):null}function Le(){let{selection:e,updateShapeData:n}=Pe();return e?/* @__PURE__ */ (0,h.jsx)(t.ShapeTextRibbonControl,{fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:e.shapeData,onUpdateShapeData:n}):null}function Re(){var e;let{selection:n,updateShapeData:r}=Pe(),i=(0,t.useFormulaShapeToolbar)({hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:(n==null?void 0:n.unitId)??``,subUnitId:(n==null?void 0:n.subUnitId)??``,shapeId:(n==null?void 0:n.drawingId)??``,shapeData:n==null?void 0:n.shapeData,registerBinding:!1,showLabels:!0,dropdownSide:`bottom`,onUpdateBinding:e=>r({formulaBinding:e})}),a=((e=i.extensionGroups)==null?void 0:e.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return n!=null&&n.shapeData.formulaBinding?/* @__PURE__ */ (0,h.jsx)(t.ShapeFormulaRibbonControl,{actions:a,panel:i.panel}):null}let ze=`sheets-shape-ui.ribbon.shape-format.style-control`,Be=`sheets-shape-ui.ribbon.shape-format.text-control`,Ve=`sheets-shape-ui.ribbon.shape-format.formula-control`,He=`sheets-shape-ui.ribbon.shape-format.arrange-forward`,Ue=`sheets-shape-ui.ribbon.shape-format.arrange-backward`,We=`sheets-shape-ui.ribbon.shape-format.arrange-front`,Ge=`sheets-shape-ui.ribbon.shape-format.arrange-back`;function Ke(e){let t=e.get(o.ICommandService),n=e.get(d.IDrawingManagerService),r=e.get(a.SheetsShapeService);return new f.Observable(o=>{let s=()=>{let t=R(e),n=t?r.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;o.next(n?(0,i.resolveActiveShapeQuickStylePresetId)(n)??``:``)},c=n.focus$.subscribe(s),l=t.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function R(e){var t;let n=e.get(d.IDrawingManagerService).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE?n[0]:null}function qe(e,t=!1){let n=e.get(o.ICommandService),r=e.get(d.IDrawingManagerService),i=e.get(a.SheetsShapeService);return new f.Observable(o=>{let s=()=>{let n=R(e);if(!n){o.next(!0);return}let r=i.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);o.next(!r||t&&r.formulaBinding==null)},c=r.focus$.subscribe(s),l=n.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function Je(e){let t=e.get(d.IDrawingManagerService),n=e.get(a.SheetsShapeService);return t.focus$.pipe((0,f.startWith)(t.getFocusDrawings()),(0,f.map)(()=>{let t=R(e),i=t?n.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return i===void 0||(0,r.isConnectorShape)(i)}))}function Ye(e){return{id:ue.id,type:n.MenuItemType.SELECTOR,icon:`PaintIcon`,title:`shape-editor-ui.toolbar.quickStyles`,tooltip:`shape-editor-ui.toolbar.quickStyles`,selections:[{label:{name:Ae,hoverable:!1,selectable:!1}}],value$:Ke(e),hidden$:qe(e)}}function Xe(e){return{id:de.id,type:n.MenuItemType.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:t.SHAPE_CHANGE_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],hidden$:Je(e)}}function Ze(e,t,r=!1){return i=>({id:e,type:n.MenuItemType.BUTTON,label:{name:t,hoverable:!1,selectable:!1},hidden$:qe(i,r)})}let Qe=Ze(ze,je),$e=Ze(Be,Me),et=Ze(Ve,Ne,!0);function tt(e,t,r,i){return a=>({id:e,commandId:l.SetDrawingArrangeCommand.id,type:n.MenuItemType.BUTTON,icon:r,title:i,tooltip:i,hidden$:qe(a),params:()=>{let e=R(a);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:t}:void 0}})}let nt=tt(He,o.ArrangeTypeEnum.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),rt=tt(Ue,o.ArrangeTypeEnum.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),it=tt(We,o.ArrangeTypeEnum.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),at=tt(Ge,o.ArrangeTypeEnum.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function ot(e){let t=e.get(n.ISidebarService);return{activated$:(0,f.defer)(()=>t.sidebarOptions$.pipe((0,f.startWith)(t.options),(0,f.map)(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),(0,f.distinctUntilChanged)())),id:I.id,type:n.MenuItemType.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:qe(e),params:()=>{let t=R(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}let st={[n.MenuManagerPosition.RIBBON]:{[ae]:{order:100,title:`sheets-shape-ui.formatShape`,contextual:!0,"sheets-shape-ui.ribbon.shape-format.quick-styles":{order:0,[ue.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:Ye},[de.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Xe}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[ze]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:104},menuItemFactory:Qe}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[Be]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:344},menuItemFactory:$e}},"sheets-shape-ui.ribbon.shape-format.arrange":{order:3,[we]:{order:0,gridLayout:{row:1,column:1},menuItemFactory:Oe},[Te]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:ke},[He]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:nt},[Ue]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:rt},[We]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:it},[Ge]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:at}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[Ve]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:120},menuItemFactory:et}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[I.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:ot},[t.ToggleShapeFloatingToolbarOperation.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:t.ShapeFloatingToolbarToggleFactory}}}}},ct={[n.RibbonInsertGroup.MEDIA]:{[N.id]:{order:3,menuItemFactory:xe}}},lt={...ct,[n.RibbonInsertGroup.OTHERS]:{[ce.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Ce}},[n.ContextMenuPosition.DRAWING]:{[n.ContextMenuGroup.OTHERS]:{[we]:{order:4,menuItemFactory:Oe},[Te]:{order:5,menuItemFactory:ke}}}};var ut=`@univerjs-pro/sheets-shape-ui`,dt=`1.5.2`;let ft={id:`sheet.operation.open-mobile-shape-editor`,type:o.CommandType.OPERATION,handler(e,n){return n?(e.get(t.MobileShapeEditorService).open(n.mode,{hostType:o.UniverInstanceType.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},pt=`sheets-shape-ui.config`,mt={},ht=class extends o.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._imageShapeClipController=i,E(this,`_activeImageId`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_activeAdjustPointList`,void 0),E(this,`_shapes`,[]),E(this,`_baseLeft`,0),E(this,`_baseTop`,0),E(this,`_baseWidth`,0),E(this,`_baseHeight`,0),E(this,`_isStartAdjusting`,!1),E(this,`_activeAdjustInfo`,void 0),E(this,`_activeShapeModel`,void 0),E(this,`_adjHandlerPointerMove`,void 0),E(this,`_adjHandlerPointerUp`,void 0),E(this,`_isImagePointerDown`,!1),this._registerFocusChangeHandler(),this._registerMoveHandler()}clearAdjustControls(){this._clearControls()}refreshAdjustControls(){this._clearControls(),this._createControls(!0)}_getOrCreateShapeModel(e,t,n,i){let a=e;if(a!==r.ShapeTypeEnum.None&&e!==`custom`)try{let o=new r.ShapeModel(a,`clip-adj-${e}`);return i&&o.setShapeData({adjustValues:i},!0),o.updateContext({width:t,height:n}),o}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),o=i.getObject(a);if(o instanceof s.Image){let e=o.prstGeom;if(e)return{prstGeom:e,adjustValues:o.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId);if(!r)return;let{transform:i}=r;if(!i)return;let{left:a,top:o,width:s,height:c,flipX:l,flipY:d,angle:f=0}=i;if(a===void 0||o===void 0)return;let p=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(!p)return;if(e){let e=this._getOrCreateShapeModel(p.prstGeom,s||0,c||0,p.adjustValues);if(!e)return;this._activeAdjustPointList=e.getDrawingPoints()}let m=this._activeAdjustPointList;if(m&&m.length!==0)for(let e=0;e<m.length;e++){let t=m[e],r=t.x,i=t.y;if(l&&(r=(s||0)-r),d&&(i=(c||0)-i),f!==0){let e=(s||0)/2,t=(c||0)/2,n=f*Math.PI/180,a=Math.cos(n),o=Math.sin(n),l=r-e,u=i-t;r=e+(l*a-u*o),i=t+(l*o+u*a)}let u={x:r,y:i,adjName:t.adjName};this._addControl(n,u,u.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,n,i,a,o,c){if(!this._activeImageId)return;let l=`image-clip-adjust-point-${this._activeImageId}-${n}`,u=e.getObjectIncludeInGroup(l);if(u){u.transformByState({left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize});return}let d=new O(l,{left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize,adjName:n,shapeId:this._activeImageId,unitId:o,subUnitId:c,width:r.ShapeDefaultConfig.adjHandleSize+8,height:r.ShapeDefaultConfig.adjHandleSize+8,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._shapes.push(d),this._attachAdjustEvent(d,e,n),e.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+1)}_clearControls(){this._shapes.length!==0&&(this._shapes.forEach(e=>e.dispose()),this._shapes=[])}_getScrollInfo(e,t){var n;let r={x:0,y:0},i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_attachAdjustEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,c;let{unitId:l,subUnitId:u,drawingId:d}=e.getDrawingSearch(),f=this._getImageDrawingInfo(l,u,d);if(!(f!=null&&f.transform))return;let{left:p,top:m,width:h,height:g}=f.transform;this._baseLeft=p||0,this._baseTop=m||0,this._baseWidth=h||0,this._baseHeight=g||0;let _=!!((a=f.transform)!=null&&a.flipX),v=!!((o=f.transform)!=null&&o.flipY),y=((c=f.transform)==null?void 0:c.angle)||0,b=this._getImagePrstGeom(l,u,d);if(!b)return;let x=this._getOrCreateShapeModel(b.prstGeom,this._baseWidth,this._baseHeight,b.adjustValues);if(!x||(this._activeShapeModel=x,this._activeAdjustInfo=x.getAdjustInfoByName(n),!this._activeAdjustInfo))return;this._isStartAdjusting=!0,t.disableObjectsEvent();let S=b.prstGeom;this._adjHandlerPointerMove=t.onPointerMove$.subscribeEvent((e,n)=>{if(!this._isStartAdjusting)return;let{offsetX:r,offsetY:i}=e,a=this._activeAdjustInfo;if(!this._activeShapeModel||!a)return;t.disableObjectsEvent(),t.setCursor(s.CURSOR_TYPE.CROSSHAIR);let o={left:0,top:0,width:this._baseWidth,height:this._baseHeight},c=this._getScrollInfo(l,u),f=this._getZoomRatio(l,u),p=r/f+c.x-this._baseLeft,m=i/f+c.y-this._baseTop;if(y!==0){let e=this._baseWidth/2,t=this._baseHeight/2,n=y*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=p-e,o=m-t;p=e+(a*r+o*i),m=t+(-a*i+o*r)}_&&(p=this._baseWidth-p),v&&(m=this._baseHeight-m);let h=this._activeShapeModel.calcAdjValues(o,{x:p,y:m},a,_,v);if(Object.keys(h).length!==0){for(let[e,t]of Object.entries(h))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseWidth,height:this._baseHeight}),this._updateImageAdjValues(l,u,d,h),this._activeAdjustPointList=this._activeShapeModel.getDrawingPoints(),this._createControls(),n.stopPropagation()}}),this._adjHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{if(this._adjHandlerPointerMove.unsubscribe(),this._adjHandlerPointerUp.unsubscribe(),t.resetCursor(),this._activeShapeModel){let e=this._activeShapeModel.getAdjustNames(),t={};for(let n of e){let e=this._activeShapeModel.getAdjustValueByName(n);e!==void 0&&(t[n]=e)}this._imageShapeClipController.clipByShape(l,u,d,S,t)}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_updateImageAdjValues(e,t,n,r){let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i,o=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),c=a.getObject(o);if(c instanceof s.Image){let e=c.prstGeomAdjValues??{};c.setPrstGeomAdjValues({...e,...r}),c.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(()=>{this._isImagePointerDown&&this._clearControls()})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;if(this._createControls(),t!==null&&t.size===1){let e=t.values().next().value;e instanceof s.Image&&e.prstGeom&&(this._isImagePointerDown=!0)}})),this.disposeWithMe(t.changing$.subscribe(()=>{this._isImagePointerDown&&this._clearControls()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isImagePointerDown&&(this._isImagePointerDown=!1,this._createControls())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{if(this._unitId&&this._subUnitId&&this._activeImageId){let n=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(n){var e,t;let r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId),i=(r==null||(e=r.transform)==null?void 0:e.width)||0,a=(r==null||(t=r.transform)==null?void 0:t.height)||0,o=this._getOrCreateShapeModel(n.prstGeom,i,a,n.adjustValues);o&&(this._activeAdjustPointList=o.getDrawingPoints(),this._clearControls(),this._createControls(!0))}}}))}))}_registerFocusChangeHandler(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let r=e[0];if(r.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE){let{unitId:e,subUnitId:i,drawingId:a}=r,o=this._getImagePrstGeom(e,i,a);if(o){var t,n;this._activeImageId=a,this._unitId=e,this._subUnitId=i;let r=this._getImageDrawingInfo(e,i,a),s=(r==null||(t=r.transform)==null?void 0:t.width)||0,c=(r==null||(n=r.transform)==null?void 0:n.height)||0,l=this._getOrCreateShapeModel(o.prstGeom,s,c,o.adjustValues);l&&(this._activeAdjustPointList=l.getDrawingPoints()),this._clearControls(),this._createControls(!0)}else this._resetState()}else this._resetState()}else this._resetState()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){let t=e[0],n=this._drawingManagerService.getDrawingByParam(t);(n==null?void 0:n.drawingType)===o.DrawingTypeEnum.DRAWING_IMAGE&&this._activeImageId===t.drawingId&&(this._clearControls(),this._createControls(!0))}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e)this._activeImageId===t.drawingId&&this._resetState()}))}_resetState(){this._activeImageId=null,this._unitId=null,this._subUnitId=null,this._activeAdjustPointList=void 0,this._clearControls()}};ht=A([k(1,d.IDrawingManagerService),k(2,(0,o.Inject)(s.IRenderManagerService)),k(3,o.IUniverInstanceService),k(4,(0,o.Inject)(L))],ht);function z({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,b.useId)()}`,u=(0,b.useRef)(null);return(0,b.useImperativeHandle)(e,()=>u.current),(0,b.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return yt(u.current)},[n,r]),gt(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function gt(e,t,n,r,i){return(0,b.createElement)(e.tag,{key:t,..._t(e,n,i),...r},(vt(e,n).children||[]).map((r,a)=>gt(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function _t(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function vt(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function yt(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:bt(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(xt(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function bt(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function xt(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}z.displayName=`UniverIcon`;let St={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334C15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334C2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045ZM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334C3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999C15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999C2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544ZM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999C3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421C6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641C9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421C11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946C8.64077 14.6502 8.70566 14.6923 8.77482 14.7209C8.84557 14.7502 8.92314 14.7664 9.00449 14.7664C9.08585 14.7664 9.16342 14.7502 9.23416 14.7209C9.30332 14.6923 9.36821 14.6502 9.42482 14.5946`}}]},Ct=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`bottom-icon`,ref:t,icon:St}))});Ct.displayName=`BottomIcon`;let wt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.6 3.3L6.2 8L2.6 12.7V3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.4 3.3L9.8 8L13.4 12.7V3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 2.2V3.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 6.2V7.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 10.2V11.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 14V14.2`,strokeLinecap:`round`,strokeWidth:1.2}}]},Tt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`flip-horizontal-icon`,ref:t,icon:wt}))});Tt.displayName=`FlipHorizontalIcon`;let Et={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.3 2.6L8 6.2L12.7 2.6H3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.3 13.4L8 9.8L12.7 13.4H3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.2 8H3.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M6.2 8H7.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M10.2 8H11.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M14 8H14.2`,strokeLinecap:`round`,strokeWidth:1.2}}]},Dt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`flip-vertical-icon`,ref:t,icon:Et}))});Dt.displayName=`FlipVerticalIcon`;let Ot={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 2.96401C1.25 3.84767 1.96634 4.56401 2.85 4.56401H13.15C14.0337 4.56401 14.75 3.84767 14.75 2.96401C14.75 2.08036 14.0337 1.36401 13.15 1.36401H2.85C1.96635 1.36401 1.25 2.08036 1.25 2.96401ZM2.85 3.36401C2.62909 3.36401 2.45 3.18493 2.45 2.96401C2.45 2.7431 2.62909 2.56401 2.85 2.56401H13.15C13.3709 2.56401 13.55 2.7431 13.55 2.96401C13.55 3.18493 13.3709 3.36401 13.15 3.36401H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 11.6118C5.80995 11.3774 6.18985 11.3774 6.42417 11.6118L7.3999 12.5875V6.36951C7.3999 6.03814 7.66853 5.76951 7.9999 5.76951C8.33127 5.76951 8.5999 6.03814 8.5999 6.36951V12.5875L9.57564 11.6118C9.80995 11.3774 10.1899 11.3774 10.4242 11.6118C10.6585 11.8461 10.6585 12.226 10.4242 12.4603L8.4324 14.452C8.32324 14.5655 8.16982 14.6362 7.9999 14.6362C7.82998 14.6362 7.67655 14.5655 7.56739 14.452L5.57564 12.4603C5.34132 12.226 5.34132 11.8461 5.57564 11.6118Z`}}]},kt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`move-down-icon`,ref:t,icon:Ot}))});kt.displayName=`MoveDownIcon`;let At={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z`}}]},jt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`move-up-icon`,ref:t,icon:At}))});jt.displayName=`MoveUpIcon`;let Mt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 4.75 8 1.8l6 2.95L8 7.7 2 4.75Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`m2 7.75 6 2.95 6-2.95M2 10.75l6 2.95 6-2.95`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}}]},Nt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`object-layers-icon`,ref:t,icon:Mt}))});Nt.displayName=`ObjectLayersIcon`;let Pt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.5 7V4.29412C13.5 3.5794 12.8679 3 12 3H2.57143C1.70356 3 1.5 3.5794 1.5 4.29412V7V10C1.5 10.7147 1.70356 11 2.57143 11H7.71429`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M4.2 5.5H10.5`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M4.2 8.3H6.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M11.5565 8H12.4435L12.913 8.78261L13.8 8.57391L14.4261 9.2L14.2174 10.087L15 10.5565V11.4435L14.2174 11.913L14.4261 12.8L13.8 13.4261L12.913 13.2174L12.4435 14H11.5565L11.087 13.2174L10.2 13.4261L9.57391 12.8L9.78261 11.913L9 11.4435V10.5565L9.78261 10.087L9.57391 9.2L10.2 8.57391L11.087 8.78261L11.5565 8Z`,strokeLinejoin:`round`}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M12.05 12.1C12.6299 12.1 13.1 11.6299 13.1 11.05C13.1 10.4701 12.6299 10 12.05 10C11.4701 10 11 10.4701 11 11.05C11 11.6299 11.4701 12.1 12.05 12.1Z`}}]},Ft=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`shape-format-setting-icon`,ref:t,icon:Pt}))});Ft.displayName=`ShapeFormatSettingIcon`;let It={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9C15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9ZM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9C2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9C13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665C15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665ZM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665C2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665C13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Lt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(z,Object.assign({},e,{id:`topmost-icon`,ref:t,icon:It}))});Lt.displayName=`TopmostIcon`;function Rt({PanelComponent:e=p.ObjectListPanelBase}){var r;function i(e){return e.trim()||void 0}function a(e,n,r){var i;return((i=e.name)==null?void 0:i.trim())||`${r.t(`drawing-ui.objectListPanel.typeNames.${(0,t.getDrawingTypeNameKey)(e.drawingType)}`)} ${n+1}`}let c=(0,n.useDependency)(o.LocaleService),u={title:c.t(`drawing-ui.objectListPanel.title`),empty:c.t(`drawing-ui.objectListPanel.empty`),showAll:c.t(`drawing-ui.objectListPanel.showAll`),hideAll:c.t(`drawing-ui.objectListPanel.hideAll`),lockAll:c.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:c.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:c.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:c.t(`drawing-ui.objectListPanel.moveBackward`),close:c.t(`drawing-ui.objectListPanel.close`),show:c.t(`drawing-ui.objectListPanel.show`),hide:c.t(`drawing-ui.objectListPanel.hide`),lock:c.t(`drawing-ui.objectListPanel.lock`),unlock:c.t(`drawing-ui.objectListPanel.unlock`),lockHint:c.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:c.t(`drawing-ui.objectListPanel.unlockHint`),name:c.t(`drawing-ui.objectListPanel.name`),nameInput:c.t(`drawing-ui.objectListPanel.nameInput`),description:c.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:c.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:c.t(`drawing-ui.objectListPanel.details`),noSelection:c.t(`drawing-ui.objectListPanel.noSelection`),locate:c.t(`drawing-ui.objectListPanel.locate`),expand:c.t(`drawing-ui.objectListPanel.expand`),collapse:c.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:c.t(`drawing-ui.objectListPanel.dragToReorder`),search:c.t(`drawing-ui.objectListPanel.search`),filterAll:c.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:c.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:c.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:c.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:c.t(`drawing-ui.objectListPanel.sectionFloating`)},f=(0,n.useDependency)(o.ICommandService),m=(0,n.useDependency)(o.IUniverInstanceService),g=(0,n.useDependency)(l.ISheetDrawingService),_=(0,n.useDependency)(d.IDrawingManagerService),v=(0,n.useDependency)(s.IRenderManagerService),y=(0,n.useDependency)(n.ILayoutService),[,x]=(0,b.useReducer)(e=>e+1,0),S=m.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_SHEET),C=(S==null?void 0:S.getUnitId())??``,w=(S==null||(r=S.getActiveSheet())==null?void 0:r.getSheetId())??``,T=(0,n.useObservable)(()=>_.focus$,_.getFocusDrawings(),!1,[_]);(0,b.useEffect)(()=>{let e=f.onCommandExecuted(()=>x());return()=>e.dispose()},[f]);let ee=C&&w?g.getDrawingData(C,w):{},te=(C&&w?g.getDrawingOrder(C,w):[]).map(e=>ee[e]).filter(e=>!!e).reverse(),E=te.reduce((e,t)=>(e[(0,p.getObjectListPanelSectionIdForDrawingType)(t.drawingType)]+=1,e),{canvas:0,floating:0}),ne={canvas:0,floating:0},D=te.map((e,t)=>{let n=(0,p.getObjectListPanelSectionIdForDrawingType)(e.drawingType),r=n===p.OBJECT_LIST_FLOATING_SECTION_ID,i=ne[n]++;return{id:e.drawingId,name:a(e,t,c),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:r?u.sectionFloating:u.sectionCanvas,capabilities:r?{arrange:!1,reorder:!1}:void 0,canMoveForward:!r&&i>0,canMoveBackward:!r&&i<E.canvas-1,canReorder:!r}}),O=(0,b.useMemo)(()=>(T??[]).filter(e=>e.unitId===C&&e.subUnitId===w).map(e=>e.drawingId),[T,w,C]),k=O[O.length-1]??null,A=e=>g.getDrawingByParam({unitId:C,subUnitId:w,drawingId:e})??null,j=async e=>{C&&e.length&&await f.executeCommand(l.SetSheetDrawingCommand.id,{unitId:C,drawings:e})},M=async(e,t)=>{A(e)&&await j([{unitId:C,subUnitId:w,drawingId:e,...t}])},re=(e,n)=>{if(!C||!w)return;let r=n?O.includes(e)?O.filter(t=>t!==e):[...O,e]:[e];f.syncExecuteCommand(d.SetDrawingSelectedOperation.id,r.map(e=>({unitId:C,subUnitId:w,drawingId:e})));let i=r[r.length-1];i?((0,t.activateDrawingObject)(v,{unitId:C,subUnitId:w,drawingId:i}),y.focus(C)):(0,t.clearActiveDrawingObjects)(v,C)},N=async(e,t)=>{await j(e.map(e=>A(e)).filter(e=>!!e).filter(e=>e.hidden!==!0!==t).map(e=>({unitId:C,subUnitId:w,drawingId:e.drawingId,hidden:!t})))},P=async(e,t)=>{await j(e.map(e=>A(e)).filter(e=>!!e).filter(e=>e.selectable!==!1!==t).map(e=>({unitId:C,subUnitId:w,drawingId:e.drawingId,selectable:t})))},F=e=>{let t=A(e);if(t)return P([e],t.selectable===!1)},ie=async(e,t)=>{var n;let r=i(t);(((n=A(e))==null?void 0:n.name)??void 0)!==r&&await M(e,{name:r})},ae=async(e,t)=>{var n;let r=i(t);(((n=A(e))==null?void 0:n.description)??void 0)!==r&&await M(e,{description:r})},oe=async(e,t)=>{C&&w&&await f.executeCommand(l.SetDrawingArrangeCommand.id,{unitId:C,subUnitId:w,drawingIds:[e],arrangeType:t})};return!C||!w?/* @__PURE__ */ (0,h.jsx)(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:u.title}):/* @__PURE__ */ (0,h.jsx)(e,{labels:u,items:D,selectedIds:O,focusedId:k,showHeader:!1,onSelect:re,onSetVisible:N,onSetSelectable:P,onCommitName:ie,onCommitDescription:ae,onMoveForward:async e=>oe(e,o.ArrangeTypeEnum.forward),onMoveBackward:async e=>oe(e,o.ArrangeTypeEnum.backward),onToggleSelectable:F})}function zt(){return/* @__PURE__ */ (0,h.jsx)(Rt,{PanelComponent:p.MobileObjectListPanel})}let Bt=class extends o.Disposable{constructor(e,t){super(),this.disposeWithMe(e.register(F,zt)),this.disposeWithMe(t.register({BottomIcon:Ct,FlipHorizontalIcon:Tt,FlipVerticalIcon:Dt,MoveDownIcon:kt,MoveUpIcon:jt,ObjectLayersIcon:Nt,ShapeFormatSettingIcon:Ft,TopmostIcon:Lt})),this.disposeWithMe(e.register(fe,ye)),this.disposeWithMe(e.register(pe,ge)),e.hasDefault(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(e.register(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,_e))}};Bt=A([k(0,(0,o.Inject)(n.ComponentManager)),k(1,(0,o.Inject)(n.IconManager))],Bt);let B=class extends o.Disposable{constructor(e){super(),this._permissionService=e,E(this,`_editingParams$`,new f.BehaviorSubject(null)),E(this,`editingParams$`,this._editingParams$.asObservable()),E(this,`_onSavingEditorData$`,new f.BehaviorSubject(!1)),E(this,`onSavingEditorData$`,this._onSavingEditorData$.asObservable()),E(this,`_completionFrame`,void 0),this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(()=>{let e=this.getEditing();e!=null&&e.visible&&!this._canEdit(e)&&this.setEditing(null)}))}dispose(){this._clearCompletionFrame(),this._editingParams$.next(null),this._editingParams$.complete(),this._onSavingEditorData$.next(!1),this._onSavingEditorData$.complete(),super.dispose()}setEditing(e){(e==null||!e.visible||this._canEdit(e))&&(this._clearCompletionFrame(),this._editingParams$.next(e),(e==null||e.visible&&this._onSavingEditorData$.getValue())&&this._onSavingEditorData$.next(!1))}setOnSavingEditorData(e){this._onSavingEditorData$.next(e)}getEditing(){return this._editingParams$.getValue()}_canEdit(e){let t=this._permissionService.getPermissionPoint(new c.WorkbookEditablePermission(e.unitId).id),n=this._permissionService.getPermissionPoint(new c.WorksheetEditPermission(e.unitId,e.subUnitId).id);return((t==null?void 0:t.value)??!0)&&((n==null?void 0:n.value)??!0)}completeEditing(e){let t=this.getEditing();t&&this._completionFrame===void 0&&(this.setOnSavingEditorData(!0),this._completionFrame=requestAnimationFrame(()=>{this._completionFrame=void 0,this.getEditing()===t&&this.setEditing(null)}))}_clearCompletionFrame(){this._completionFrame!==void 0&&(cancelAnimationFrame(this._completionFrame),this._completionFrame=void 0)}cancelEditing(){this.getEditing()&&this.setEditing(null)}};B=A([k(0,o.IPermissionService)],B);let Vt=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._injector=t,this._shapeTextEditingService=n,this._drawingManagerService=r,this._contextService=i,this._sheetsShapeService=a,E(this,`_lastEditingShapeKey`,null),this._initEvents(),this._initSelection(),this._initEditingParams()}_initEvents(){let{scene:e}=this._context;this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:n,offsetY:i}=t,a=e.pick(s.Vector2.FromArray([n,i]));if(a instanceof D){let e=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);if((0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(a.unitId,a.subUnitId,a.shapeId))||e!=null&&e.getShapeData().formulaBinding)return;this._shapeTextEditingService.setEditing({visible:!0,unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.shapeId,shapeKey:a.oKey})}}))}_initSelection(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let n=e[0],i=this._drawingManagerService.getDrawingByParam(n);if((i==null?void 0:i.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===n.drawingId&&e.visible)return;let i=(0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(n.unitId,n.subUnitId,n.drawingId)),a=!!((t=this._sheetsShapeService.getShapeModel(n.unitId,n.subUnitId,n.drawingId))!=null&&t.getShapeData().formulaBinding);(i||a)&&this._shapeTextEditingService.setEditing(null)}else this._shapeTextEditingService.completeEditing()}else this._shapeTextEditingService.completeEditing()})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{let t=this._shapeTextEditingService.getEditing();t&&e.some(e=>e.drawingId===t.shapeId)&&this._shapeTextEditingService.setEditing(null)}))}_initEditingParams(){this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{let{scene:t}=this._context;if(this._lastEditingShapeKey){let e=t.getObjectIncludeInGroup(this._lastEditingShapeKey);e&&e.setEditing(!1)}if(e){let n=!!e.visible,r=t.getObjectIncludeInGroup(e.shapeKey);r&&(r.setEditing(n),this._lastEditingShapeKey=e.shapeKey),this._contextService.setContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR,!1)}))}};Vt=A([k(1,(0,o.Inject)(o.Injector)),k(2,(0,o.Inject)(B)),k(3,d.IDrawingManagerService),k(4,o.IContextService),k(5,(0,o.Inject)(a.SheetsShapeService))],Vt);var Ht=class extends Vt{_initEvents(){let{scene:e}=this._context,n=this._injector.get(t.MobileShapeEditorService);this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:i,offsetY:a}=t,c=e.pick(s.Vector2.FromArray([i,a]));if(!(c instanceof D))return;let l=this._sheetsShapeService.getShapeModel(c.unitId,c.subUnitId,c.shapeId);(0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(c.unitId,c.subUnitId,c.shapeId))||l!=null&&l.getShapeData().formulaBinding||n.open(`text`,{hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.shapeId})}))}};let Ut={...ct},V=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._menuManagerService=e,this._sheetsShapeService=t,this._commandService=n,this._drawingManagerService=r,this._sheetCanvasPopManagerService=i,this._contextService=a,this._renderManagerService=o,this._shapeTextEditingService=s,E(this,`_shapePopupMenuDisposable`,null),this._menuManagerService.mergeMenu(Ut),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,t.bindRenderTransformerLifecycle)(this._renderManagerService,o.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(o.DrawingTypeEnum.DRAWING_SHAPE,(e,t,n,i)=>{let o=this._sheetsShapeService.getShapeTypeById(e,t,n),s=this._sheetsShapeService.getShapeDataById(e,t,n),c=o!==void 0&&!(0,r.isConnectorShape)(o)&&!(s!=null&&s.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:ft.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`style`},disable:!1},...c?[{label:`sheets-shape-ui.editText`,index:1,commandId:ft.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:l.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:n,drawingType:i}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:a.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:a.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new o.DisposableCollection,n=null,r=()=>{if(!n)return;let e=this._drawingManagerService.getFocusDrawings(),t=e.length===0||e.length===1&&e.some(e=>e.unitId===(n==null?void 0:n.unitId)&&e.subUnitId===(n==null?void 0:n.subUnitId)&&e.drawingId===(n==null?void 0:n.drawingId));n=null,t&&(this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null))};return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(t.size>1){r();return}let i=t.values().next().value;if(!i){r();return}let a=this._drawingManagerService.getDrawingOKey(i.oKey);if(!a||a.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE){r();return}let{unitId:s,subUnitId:c,drawingId:l}=a;n={unitId:s,subUnitId:c,drawingId:l},this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!0),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===s&&e.subUnitId===c&&e.drawingId===l)||this._drawingManagerService.focusDrawing([{unitId:s,subUnitId:c,drawingId:l}])})),t.add(e.clearControl$.subscribe(()=>{r()})),(0,o.toDisposable)(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};V=A([k(0,n.IMenuManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,o.ICommandService),k(3,d.IDrawingManagerService),k(4,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(5,o.IContextService),k(6,s.IRenderManagerService),k(7,(0,o.Inject)(B))],V);function Wt(e,t,n,r){let i=(0,d.getOrCreateDrawingCopyPlan)(e,t,n),a=[];for(let e of t){let t=i.idMap.get(e.drawingId),n=r(e);t&&n&&a.push({targetShapeId:t,source:n})}return a}let H=class extends o.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._sheetDrawingService=n,this._sheetsShapeService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===c.RemoveSheetCommand.id){let t=(0,c.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,i=this._sheetDrawingService.getDrawingData(n,r),s=Object.values(i).filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(s.length===0)return{redos:[],undos:[]};let l=[],u=[];for(let e=0;e<s.length;e++){let t=s[e],i=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);i&&(l.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),u.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:i.getShapeType(),shapeData:JSON.parse(JSON.stringify(i.getShapeData()))}}))}return{redos:l,undos:u}}if(e.id===c.CopySheetCommand.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:i}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let s=this._sheetDrawingService.getDrawingData(t,n),c=Object.values(s).filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=Wt(i,c,{unitId:t,sourceSubUnitId:n,targetSubUnitId:r},e=>{let t=this._sheetsShapeService.getShapeModel(e.unitId,e.subUnitId,e.drawingId);if(t)return{shapeType:t.getShapeType(),shapeData:JSON.parse(JSON.stringify(t.getShapeData()))}}),u=[],d=[];for(let{targetShapeId:e,source:n}of l)u.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),d.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:u,undos:d}}return{redos:[],undos:[]}}}))}};H=A([k(0,(0,o.Inject)(o.IUniverInstanceService)),k(1,(0,o.Inject)(c.SheetInterceptorService)),k(2,(0,o.Inject)(l.ISheetDrawingService)),k(3,(0,o.Inject)(a.SheetsShapeService))],H);let U=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._currentUniverService=r,this._drawingRenderService=i,this._sheetDrawingShapeRenderController=a,E(this,`_insertingShapeKeys`,/* @__PURE__ */ new Set),this._initialize()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._shapeUpdateListener()}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertShapes(e)}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(e.id===a.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),o=i==null?void 0:i.scene.getObjectIncludeInGroup(a);o&&(this._sheetDrawingShapeRenderController.refreshShapeFillImage(o),this._sheetDrawingShapeRenderController.refreshFormulaPresentation(o,{unitId:t,subUnitId:n,shapeId:r}),o.makeDirty(!0))}else if(e.id===a.InsertSheetsShapeMutation.id){var n;let{unitId:r,subUnitId:i,shapeId:a}=e.params,o=this._getSceneAndTransformerByDrawingSearch(r);if(o==null)return;let{scene:s}=o,c=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),l=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(u.SheetSkeletonManagerService).getSkeleton(i)))return!1;if(l)return;if(t!=null&&t.fromChangeset){queueMicrotask(()=>{this._disposed||this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])});return}this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])}}))}_shapeUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._drawingManagerService.getDrawingByParam(e);if(i==null)return;let{transform:a,drawingType:s,srcRect:c,prstGeom:l}=i;if(s!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let u=this._getSceneAndTransformerByDrawingSearch(t);if(u==null)return;let{scene:f,transformer:p}=u;if(a==null)return!0;let m=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),h=f.getObjectIncludeInGroup(m);if(h==null)return!0;h.setSrcRect(c),h.setPrstGeom(l)})}))}_insertShapes(e){for(let n of e){var t;let{unitId:e,subUnitId:i,drawingId:a}=n,s=this._getSceneAndTransformerByDrawingSearch(e),c=(t=(0,p.getCurrentUnitInfo)(this._currentUniverService,e))==null?void 0:t.subUnitId;if(s==null||c!==i)continue;let l=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:i,drawingId:a});if(this._insertingShapeKeys.has(l)||s.scene.getObjectIncludeInGroup(l)!=null)continue;let u=this._drawingManagerService.getDrawingByParam(n);if(u==null||u.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let f=u.data||{};if((0,r.isConnectorShape)(f.shapeType)){let e=u.transform;e&&(u.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(l);try{this._sheetDrawingShapeRenderController.renderDrawingShape(u,s.scene)}finally{this._insertingShapeKeys.delete(l)}queueMicrotask(()=>{if(this._disposed)return;let e=(0,d.getDrawingShapeKeyByDrawingSearch)(n);if(!s.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(n);t&&this._drawingManagerService.refreshTransform([t])})}}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}};U=A([k(0,o.ICommandService),k(1,s.IRenderManagerService),k(2,d.IDrawingManagerService),k(3,o.IUniverInstanceService),k(4,(0,o.Inject)(p.DrawingRenderService)),k(5,(0,o.Inject)(j))],U);let Gt={normal:{fill:r.ShapeDefaultConfig.cxnPointFill,stroke:r.ShapeDefaultConfig.cxnPointStroke,strokeWidth:r.ShapeDefaultConfig.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var Kt=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_targetShapeId`,``),E(this,`_cxnIndex`,-1),E(this,`_unitId`,``),E(this,`_subUnitId`,``),E(this,`_isHighlighted`,!1),t&&this.setShapeProps(t)}getConnectionInfo(){return{unitId:this._unitId,subUnitId:this._subUnitId,shapeId:this._targetShapeId,cxnIndex:this._cxnIndex}}setHighlighted(e){this._isHighlighted!==e&&(this._isHighlighted=e,this.makeDirty(!0))}isHighlighted(){return this._isHighlighted}setShapeProps(e){e.targetShapeId!==void 0&&(this._targetShapeId=e.targetShapeId),e.cxnIndex!==void 0&&(this._cxnIndex=e.cxnIndex),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),e.isHighlighted!==void 0&&(this._isHighlighted=e.isHighlighted),this.transformByState({width:e.width??r.ShapeDefaultConfig.cxnPointRadius*2,height:e.height??r.ShapeDefaultConfig.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?Gt.highlighted:Gt.normal;s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let W=class extends o.Disposable{constructor(e,t,n,r){super(),this._context=e,this._renderManagerService=t,this._drawingManagerService=n,this._sheetsShapeService=r,E(this,`_connectionSiteObjects`,[]),E(this,`_activeTargetShapeId`,null),E(this,`_highlightedSiteIndex`,-1),E(this,`_currentScene`,null),E(this,`_unitId`,``),E(this,`_subUnitId`,``),E(this,`_draggingConnectorId`,null)}startConnectionDetection(e,t,n,r){this._currentScene=e,this._unitId=t,this._subUnitId=n,this._draggingConnectorId=r}updateConnectionDetection(e){if(!this._currentScene)return null;let t=this._findShapeAtPoint(e);return t?(this._activeTargetShapeId!==t.shapeId&&(this._clearConnectionSites(),this._showConnectionSites(t.shapeId,t.shapeModel),this._activeTargetShapeId=t.shapeId),this._findNearestConnectionSite(e)):(this._activeTargetShapeId!==null&&(this._clearConnectionSites(),this._activeTargetShapeId=null),null)}endConnectionDetection(){this._clearConnectionSites(),this._currentScene=null,this._activeTargetShapeId=null,this._highlightedSiteIndex=-1,this._draggingConnectorId=null}getConnectionRelation(){return this._activeTargetShapeId===null||this._highlightedSiteIndex<0?null:{shapeId:this._activeTargetShapeId,cxnIndex:this._highlightedSiteIndex}}_findShapeAtPoint(e){let t=this._drawingManagerService.getDrawingData(this._unitId,this._subUnitId);for(let n of Object.keys(t)){if(n===this._draggingConnectorId||t[n].drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,n);if(!i||(0,r.isConnectorShape)(i.getShapeType())||i.getConnectionSiteList().length===0||!this._currentScene)continue;let a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:n}),c=this._currentScene.getObjectIncludeInGroup(a);if(!c)continue;let{left:l,top:u,width:f,height:p}=c.getRealBound(),m=l+f/2,h=u+p/2,g=c.transform.getMatrix(),_=new s.Transform([g[0],g[1],g[2],g[3],m,h]),v=c.getParent(),y=(c.isInGroup&&(v==null?void 0:v.classType)===s.RENDER_CLASS_TYPE.GROUP?v.ancestorTransform.multiply(_):_).invert().applyPoint(e),b=f/2,x=p/2;if(y.x>=-b-5&&y.x<=b+5&&y.y>=-x-5&&y.y<=x+5)return{shapeId:n,shapeModel:i}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let n=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),i=this._currentScene.getObjectIncludeInGroup(n);if(!i)return;let{left:a,top:o,width:c,height:l}=i.getRealBound(),u=a+c/2,f=o+l/2,p=i.transform.getMatrix(),m=new s.Transform([p[0],p[1],p[2],p[3],u,f]),h=i.getParent(),g=i.isInGroup&&(h==null?void 0:h.classType)===s.RENDER_CLASS_TYPE.GROUP?h.ancestorTransform.multiply(m):m;t.updateContext({width:c,height:l});let _=t.getConnectionSiteList();for(let t of _){let n=t.x-c/2,i=t.y-l/2,a=g.applyPoint({x:n,y:i}),o=a.x,u=a.y,d=new Kt(`connection-site-${e}-${t.index}`,{left:o-r.ShapeDefaultConfig.cxnPointRadius,top:u-r.ShapeDefaultConfig.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:r.ShapeDefaultConfig.cxnPointRadius*2,height:r.ShapeDefaultConfig.cxnPointRadius*2,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+2,evented:!1});this._connectionSiteObjects.push(d),this._currentScene.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+2)}}_findNearestConnectionSite(e){let t=null,n=1/0,i=null;for(let a of this._connectionSiteObjects){let o=a.left+r.ShapeDefaultConfig.cxnPointRadius,s=a.top+r.ShapeDefaultConfig.cxnPointRadius,c=e.x-o,l=e.y-s,u=Math.sqrt(c*c+l*l);u<n&&(n=u,t=a,i={x:o,y:s})}let a=n<=10&&t?t.getConnectionInfo().cxnIndex:-1;if(a!==this._highlightedSiteIndex){for(let e of this._connectionSiteObjects){let t=e.getConnectionInfo();e.setHighlighted(t.cxnIndex===a)}this._highlightedSiteIndex=a}if(n<=10&&t&&i){let e=t.getConnectionInfo(),n=this._getConnectionSiteAngle(e.shapeId,e.cxnIndex);return{shapeId:e.shapeId,cxnIndex:e.cxnIndex,unitId:e.unitId,subUnitId:e.subUnitId,worldPoint:i,angle:n}}return null}_getConnectionSiteAngle(e,t){let n=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,e);if(!n)return 0;let r=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e});if(!(r!=null&&r.transform))return 0;let{width:i=0,height:a=0,flipX:o=!1,flipY:s=!1}=r.transform;n.updateContext({width:i,height:a});let c=n.getConnectionSiteList().find(e=>e.index===t);if(!c)return 0;let l=c.ang/6e4;return o&&(l=180-l),s&&(l=-l),l=(l%360+360)%360,l}_clearConnectionSites(){for(let e of this._connectionSiteObjects)e.dispose();this._connectionSiteObjects=[],this._highlightedSiteIndex=-1}dispose(){this._clearConnectionSites(),super.dispose()}};W=A([k(1,(0,o.Inject)(s.IRenderManagerService)),k(2,(0,o.Inject)(d.IDrawingManagerService)),k(3,(0,o.Inject)(a.SheetsShapeService))],W);let G=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._sheetSkeletonService=e,this._sheetClipboardService=t,this._sheetDrawingService=n,this._shapeService=r,this._groupCopyPasteController=i,this._instances=a,this._renders=o,this._permissions=s,E(this,`_copyInfo`,void 0),this._initCopyPaste(),this._registerGroupFeaturePasteHook()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_registerGroupFeaturePasteHook(){this._groupCopyPasteController.registerFeaturePasteHook(({fromUnitId:e,fromSubUnitId:t,toUnitId:n,toSubUnitId:r,idMap:i})=>{let o=[],s=[];for(let[u,d]of i.entries()){let f=this._shapeService.getShapeModel(e,t,u);if(!f)continue;let p=f.getShapeType(),m=JSON.parse(JSON.stringify(f.getShapeData()));if(m.relation){var c,l;let e=(c=m.relation.from)==null?void 0:c.shapeId,t=(l=m.relation.to)==null?void 0:l.shapeId,n=!e||i.has(e),r=!t||i.has(t);n&&e&&m.relation.from?m.relation.from={...m.relation.from,shapeId:i.get(e)}:m.relation.from=void 0,r&&t&&m.relation.to?m.relation.to={...m.relation.to,shapeId:i.get(t)}:m.relation.to=void 0}o.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d,shapeType:p,shapeData:m}}),s.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d}})}return{redos:o,undos:s}})}_initCopyPaste(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:`sheets-shape-ui`,onBeforeCopyFocusedObject:(e,t,n)=>{this._copyInfo=null;let r=this._focusedDrawings.filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);return r.length!==0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:n,drawings:r},!0)},onBeforeCopy:(e,t,n,r)=>{this._copyInfo=null,this._createCopyInfoByRange(e,t,n,r)},onPasteCells:(e,t,n,r)=>{if(!r.copyId||!e||!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return i===u.PREDEFINED_HOOK_NAME.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===u.COPY_TYPE.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let a=(0,c.attachRangeWithCoord)(i,n);if(!a)return;let{startX:s,endX:l,startY:u,endY:d}=a,f=this._sheetDrawingService.getDrawingData(e,t),p=[];for(let[e,t]of Object.entries(f)){if(t.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:a=0}=e;s<=n&&l>=n+i&&u<=r&&d>=r+a&&p.push(t)}p.length>0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:r,copyRange:n,drawings:p})}_generatePasteMutations(e,t){var n,r;let{unitId:i,subUnitId:a,range:s}=e,l=this._copyInfo,u=(n=this._instances.getUnit(l.unitId,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(l.subUnitId),d=(r=this._instances.getUnit(i,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(a),f=(u==null?void 0:u.getConfig().type)??o.SheetTypes.GRID,p=(d==null?void 0:d.getConfig().type)??o.SheetTypes.GRID;if(f===o.SheetTypes.CHART||p===o.SheetTypes.CHART)return this._generateChartSheetCopy(e,t);let m=this._sheetSkeletonService.getSkeleton(i,a);if(!m)return{redos:[],undos:[]};let h=(0,c.discreteRangeToRange)(s),{unitId:g,subUnitId:_,copyRange:v,drawings:y}=this._copyInfo,b=this._sheetSkeletonService.getSkeleton(g,_);if(!b)return{redos:[],undos:[]};let x;if(!v){let e=1/0,t=1/0;for(let n of y){let{left:r=0,top:i=0}=n.transform??{};r<e&&(e=r),i<t&&(t=i)}e!==1/0&&t!==1/0&&(x={left:e,top:t})}let S=/* @__PURE__ */ new Map;if(!t)for(let e of y)S.set(e.drawingId,(0,o.generateRandomId)());let C=[],w=[];for(let e of y){let{drawingId:n,transform:r,sheetTransform:o}=e;if(!r||!o)continue;let s=this._updateTransform({transform:r,sheetTransform:o},{skeleton:b,range:v},{skeleton:m,range:h},x);if(t){let{redos:t,undos:n}=this._generateCutPasteMutations({fromUnitId:g,fromSubUnitId:_,toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:s});C.push(...t),w.push(...n);continue}let{redos:c,undos:l}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:s,newDrawingId:S.get(n),idMap:S});C.push(...c),w.push(...l)}return{redos:C,undos:w}}_generateChartSheetCopy(e,t){var n;if(t)throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[c.WorkbookEditablePermission],worksheetTypes:[c.WorksheetEditPermission]},r,i))throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let a=(n=this._instances.getUnit(r,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),s=a==null?void 0:a.getConfig(),d=(s==null?void 0:s.type)??o.SheetTypes.GRID,f=this._copyInfo,p=f.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[c.WorkbookCopyPermission],worksheetTypes:[c.WorksheetCopyPermission]},f.unitId,f.subUnitId)||p.some(e=>e.groupId||!this._shapeService.getShapeModel(f.unitId,f.subUnitId,e.drawingId)||!o.Tools.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let m=null;if(d===o.SheetTypes.CHART){var h;let e=(h=this._renders.getRenderUnitById(r))==null?void 0:h.components.get(u.SHEET_VIEW_KEY.CHART_PAGE);e&&(m=(0,l.transformDrawingsToChartSheet)(p,{left:e.left,top:e.top,width:e.width,height:e.height},(s==null?void 0:s.rightToLeft)===o.BooleanNumber.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&(0,c.attachRangeWithCoord)(t,(0,c.discreteRangeToRange)(e.range));if(n&&p.length){let e=Math.min(...p.map(e=>e.transform.left)),r=Math.min(...p.map(e=>e.transform.top));m=p.map(i=>(0,l.applySheetDrawingPlacement)(i,{kind:l.SheetDrawingAnchorType.Position,bounds:{left:n.startX+i.transform.left-e,top:n.startY+i.transform.top-r,width:i.transform.width,height:i.transform.height}},t))}}if(!m)throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let g=new Map(p.map(e=>[e.drawingId,(0,o.generateRandomId)()])),_=[],v=[];for(let[e,t]of p.entries()){let n=m[e],a=this._generateCopyPasteMutations({toUnitId:r,toSubUnitId:i,drawing:t,idMap:g,newDrawingId:g.get(t.drawingId),newTransforms:{transform:n.transform,sheetTransform:n.sheetTransform,axisAlignSheetTransform:n.axisAlignSheetTransform,anchorType:n.anchorType}});_.push(...a.redos),v.unshift(...a.undos)}return{redos:_,undos:v}}_generateCutPasteMutations(e){let{fromUnitId:t,fromSubUnitId:n,toUnitId:r,toSubUnitId:i,drawing:o,newTransforms:s}=e,c={...o,unitId:r,subUnitId:i,...s};if(r===t&&i===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([c]);return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.UPDATE,op:e,objects:n}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([o]),s=this._sheetDrawingService.getBatchAddOp([c]),u=this._shapeService.getShapeModel(o.unitId,o.subUnitId,o.drawingId);if(!u)return{redos:[],undos:[]};let d=u.getShapeType(),f=JSON.parse(JSON.stringify(u.getShapeData()));return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.REMOVE,op:e.redo,objects:e.objects}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId}},{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.INSERT,op:s.redo,objects:s.objects}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:r,subUnitId:i,shapeId:o.drawingId,shapeType:d,shapeData:f}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.INSERT,op:e.undo,objects:e.objects}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId,shapeType:d,shapeData:f}},{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.REMOVE,op:s.undo,objects:s.objects}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:r,subUnitId:i,shapeId:o.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:i,newDrawingId:o,idMap:s}=e,c={...r,unitId:t,subUnitId:n,drawingId:o,...i},{redo:u,undo:d,objects:f}=this._sheetDrawingService.getBatchAddOp([c]),p=this._shapeService.getShapeModel(r.unitId,r.subUnitId,r.drawingId);if(!p)return{redos:[],undos:[]};let m=p.getShapeType(),h=JSON.parse(JSON.stringify(p.getShapeData()));if(h.relation){var g,_;let e=(g=h.relation.from)==null?void 0:g.shapeId,t=(_=h.relation.to)==null?void 0:_.shapeId,n=!e||s.has(e),r=!t||s.has(t);n&&e&&h.relation.from?h.relation.from={...h.relation.from,shapeId:s.get(e)}:h.relation.from=void 0,r&&t&&h.relation.to?h.relation.to={...h.relation.to,shapeId:s.get(t)}:h.relation.to=void 0}return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.INSERT,op:u,objects:f}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o,shapeType:m,shapeData:h}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.REMOVE,op:d,objects:f}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:s}=n,{transform:u,sheetTransform:d}=e,f={...u};if(i){let e=(0,c.attachRangeWithCoord)(a,i),t=(0,c.attachRangeWithCoord)(s,o);if(e&&t){let n=t.startX-e.startX,r=t.startY-e.startY;f.left=(f.left??0)+n,f.top=(f.top??0)+r}}else{let e=(0,c.attachRangeWithCoord)(s,o);if(r&&e){let t=(f.left??0)-r.left,n=(f.top??0)-r.top;f.left=e.startX+t,f.top=e.startY+n}else f.left=e==null?void 0:e.startX,f.top=e==null?void 0:e.startY}return{transform:f,sheetTransform:(0,l.transformToDrawingPosition)(f,s)??d}}};G=A([k(0,(0,o.Inject)(c.SheetSkeletonService)),k(1,(0,o.Inject)(u.ISheetClipboardService)),k(2,(0,o.Inject)(l.ISheetDrawingService)),k(3,(0,o.Inject)(a.SheetsShapeService)),k(4,(0,o.Inject)(y.SheetsDrawingGroupCopyPasteController)),k(5,o.IUniverInstanceService),k(6,s.IRenderManagerService),k(7,(0,o.Inject)(c.SheetPermissionCheckController))],G);var qt=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_shapeId`,null),E(this,`_index`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_isStartConnectorPoint`,!1),t&&this.setShapeProps(t)}getDrawingSearch(){return{unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._shapeId}}setShapeProps(e){e.shapeId!==void 0&&(this._shapeId=e.shapeId),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),e.isStartConnectorPoint!==void 0&&(this._isStartConnectorPoint=e.isStartConnectorPoint),this.transformByState({width:e.width,height:e.height})}_draw(e){s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.cxnPointRadius,fill:r.ShapeDefaultConfig.cxnPointFill,stroke:r.ShapeDefaultConfig.cxnPointStroke,strokeWidth:r.ShapeDefaultConfig.cxnPointStrokeWidth,evented:!0})}};let Jt=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._context=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,this._univerInstanceService=i,this._sheetsShapeService=a,this._sheetShapeAdjustController=o,this._sheetBasicShapeConnectionPointController=s,E(this,`_activeShapeId`,void 0),E(this,`_unitId`,void 0),E(this,`_subUnitId`,void 0),E(this,`_connectorObjects`,[]),E(this,`_baseDrawingRect`,{left:0,top:0,width:0,height:0,flipX:!1,flipY:!1}),E(this,`_activeShapeModel`,void 0),E(this,`_isConnecting`,!1),E(this,`_isDrawingShapePointDown`,!1),E(this,`_hasReset`,!1),E(this,`_cxtHandlerPointerMove`,void 0),E(this,`_cxtHandlerPointerUp`,void 0),E(this,`_currentConnectionTarget`,null),this._initialize()}_initialize(){this._registerDrawingFocusChangeHandler(),this._registerDrawingMoveHandler()}_getDrawingRect(){if(!this._unitId||!this._subUnitId||!this._activeShapeId)return;let e={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},{transform:t}=this._drawingManagerService.getDrawingByParam(e);if(t)return{left:t.left||0,top:t.top||0,width:t.width||0,height:t.height||0,flipX:t.flipX||!1,flipY:t.flipY||!1,angle:t.angle}}_addShapeConnectorHandlerObjects(){if(this._unitId===void 0||this._subUnitId===void 0||this._activeShapeId===void 0)return;let e=this._renderManagerService.getRenderUnitById(this._unitId);if(!e||!e.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:t}=e,n=this._getDrawingRect();if(!n)return;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!i||!(0,r.isConnectorShape)(i.getShapeType()))return;let a=i.getConnectorLinePoints();if(a.length<2)return;let o=new r.ConnectorCoordinateTransform(n),s=a[0],c=a[a.length-1],l=o.localToWorld(s),d=o.localToWorld(c);this._addShapeConnectorHandlerObject(t,{...l},!0),this._addShapeConnectorHandlerObject(t,{...d},!1)}_addShapeConnectorHandlerObject(e,t,n){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let i=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${n?`start`:`end`}`,a=e.getObjectIncludeInGroup(i);if(a){a.transformByState({left:t.x-r.ShapeDefaultConfig.cxnPointRadius,top:t.y-r.ShapeDefaultConfig.cxnPointRadius});return}let o=new qt(i,{left:t.x-r.ShapeDefaultConfig.cxnPointRadius,top:t.y-r.ShapeDefaultConfig.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:n,width:r.ShapeDefaultConfig.cxnPointRadius*2,height:r.ShapeDefaultConfig.cxnPointRadius*2,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._connectorObjects.push(o),this._attachConnectorObjectEvent(o,e,n),e.addObject(o,s.DRAWING_OBJECT_LAYER_INDEX+1)}_getScrollInfo(e,t){var n;let r={x:0,y:0};if(!e||!t)return r;let i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_handleConnectorPointerUp(e,t,n,r,i){this._cxtHandlerPointerMove.unsubscribe(),this._cxtHandlerPointerUp.unsubscribe(),this._sheetShapeAdjustController.refreshAdjustControls();let a=this._currentConnectionTarget;this._sheetBasicShapeConnectionPointController.endConnectionDetection();let o=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c={x:n.offsetX/s+o.x,y:n.offsetY/s+o.y},l=a?a.worldPoint:c,u=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo(),d=this._activeShapeModel.getShapeType();u?this._handleConnectedEndpointPointerUp(u,l,r,a,i):this._handleFreeEndpointPointerUp(t,l,r,a,i,d),this._isConnecting=!1,this._hasReset=!1,this._currentConnectionTarget=null,e.enableObjectsEvent()}_handleFreeEndpointPointerUp(e,t,n,i,a,o){let s=o===r.ShapeTypeEnum.Line||o===r.ShapeTypeEnum.StraightConnector1,c=n?t:e,l=n?e:t,u=this._activeShapeModel.getConnectorLinePoints(),d=this._activeShapeModel.getShapeType(),f=(0,r.isCurvedConnectorShape)(d),p=r.ConnectorCoordinateTransform.getBentTypeFromPoints(u,f),m=s?r.ConnectorCoordinateTransform.computeStraightConnectorLayout(c,l):r.ConnectorCoordinateTransform.computeConnectorResizeLayout(e,t,n,p);i?this._executeConnectionCommand(m,i,n,a):this._executeResizeCommand(m,a)}_handleConnectedEndpointPointerUp(e,t,n,i,a){let o=this._getConnectPointInfo(e);if(!o)return;let s=i?i.angle:this._calculateFreeEndpointAngle(o.point,t),c;if(i){let e=this._drawingManagerService.getDrawingByParam({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:i=0,height:a=0,angle:o}=e.transform;c=(0,r.getBasicShapeRotateBound)({left:t,top:n,width:i,height:a},o||0)}else c={left:t.x,top:t.y,width:0,height:0}}else c={left:t.x,top:t.y,width:0,height:0};let l={point:t,angle:s,bounds:c},u=n?l:o,d=n?o:l,f=this._activeShapeModel.getShapeType(),p=(0,r.routeConnectorLineShape)(u,d,f);this._activeShapeModel.removeLinePoints();let m=(0,r.computeConnectorRouteLayout)(p,f);i?this._executeConnectedRouteConnectionCommand(m,i,e,n,a):this._executeConnectedRouteResizeCommand(m,e,n,a)}_executeConnectionCommand(e,t,n,i){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};n?s.from=c:s.to=c;let l=this._activeShapeModel.getShapeType(),u=(0,r.computeConnectorRouteLayout)(e.worldPoints,l),d={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,newAdjustValues:u.adjustValues,oldAdjustValues:i,oldRelation:o,newRelation:s,newLineType:u.lineType,oldLineType:l};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,d)}_executeResizeCommand(e,t){let n=this._activeShapeModel.getShapeType(),i=(0,r.computeConnectorRouteLayout)(e.worldPoints,n),o={unitId:this._unitId,subUnitId:this._subUnitId,shapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,angle:e.worldRect.angle||0,newAdjustValues:i.adjustValues,oldAdjustValues:t,newLineType:i.lineType,oldLineType:n};this._commandService.executeCommand(a.UpdateLineShapeResizeCommand.id,o)}_executeConnectedRouteConnectionCommand(e,t,n,r,i){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?(s.from=c,s.to=n):(s.from=n,s.to=c);let l={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:i,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:o,newRelation:s};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,l)}_executeConnectedRouteResizeCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,o={};n?(o.to=t,o.from=void 0):(o.from=t,o.to=void 0);let s={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:r,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:i,newRelation:o};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,s)}_attachConnectorObjectEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((i,a)=>{let o=e.getDrawingSearch();if(this._activeShapeModel=this._sheetsShapeService.getShapeModel(o.unitId,o.subUnitId,o.drawingId),!this._activeShapeModel)return;let s={};this._activeShapeModel.getAdjustNames().forEach(e=>{let t=this._activeShapeModel.getAdjustValueByName(e);t!==void 0&&(s[e]=t)});let c=this._getDrawingRect();if(!c)return;this._baseDrawingRect={...c};let l=new r.ConnectorCoordinateTransform(this._baseDrawingRect),u=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),f=t.getObjectIncludeInGroup(u);this._isConnecting=!0,t.disableObjectsEvent(),this._sheetBasicShapeConnectionPointController.startConnectionDetection(t,this._unitId,this._subUnitId,this._activeShapeId),this._currentConnectionTarget=null;let p=this._activeShapeModel.getConnectorLinePoints(),m=p[0],h=p[p.length-1],g=n?l.localToWorld(h):l.localToWorld(m);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((r,i)=>{if(!this._isConnecting||!this._activeShapeModel)return;this._hasReset||=(this._sheetShapeAdjustController.clearAdjustControls(),this._activeShapeModel.clearAdjustValue(),!0);let a=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s={x:r.offsetX/o+a.x,y:r.offsetY/o+a.y},c=this._sheetBasicShapeConnectionPointController.updateConnectionDetection(s);if(c){let{shapeId:e,unitId:n,subUnitId:r}=c;if(e&&n&&r){let i=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=n?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,n,f,e):this._handleFreeEndpointMove(s,g,n,f,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,r)=>{this._handleConnectorPointerUp(t,g,e,n,s)}),a.stopPropagation()})))}_handleBasicShapeUpdateConnectorLineShape(e,t,n){let r=this._sheetsShapeService.getBasicShapeRelation(e,t,n);if(!r||r.length===0)return;let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i;for(let i of r){let r=i.lineShapeId,o=this._sheetsShapeService.getShapeModel(e,t,r);if(!o)continue;let s=o.getStartConnectInfo(),c=o.getEndConnectInfo(),l=(s==null?void 0:s.shapeId)===n,u=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:r}),f=a.getObjectIncludeInGroup(u);if(!f)continue;let p=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});p!=null&&p.transform&&(s&&c?this._rerouteConnectorLine(e,t,r,o,s,c,f):this._moveConnectorWithShape(e,t,r,o,l?s:c,l,p,f))}}_rerouteConnectorLine(e,t,n,i,a,o,s){let c=this._unitId,l=this._subUnitId;this._unitId=e,this._subUnitId=t;let u=this._getConnectPointInfo(a),d=this._getConnectPointInfo(o);if(this._unitId=c,this._subUnitId=l,!u||!d)return;let f=i.getShapeType(),p=(0,r.routeConnectorLineShape)(u,d,f);p&&i.updateLinePoints(p);let m=(0,r.computeConnectorRouteLayout)(p,f);m.lineType!==f&&i.changeShapeType(m.lineType),i.clearAdjustValue();for(let[e,t]of Object.entries(m.adjustValues))i.setAdjustValueByName(e,t);i.updateContext({width:m.worldRect.width,height:m.worldRect.height}),s.transformByState({flipX:m.worldRect.flipX,flipY:m.worldRect.flipY,left:m.worldRect.left,top:m.worldRect.top,width:m.worldRect.width,height:m.worldRect.height,angle:m.rotation}),i.removeLinePoints()}_moveConnectorWithShape(e,t,n,i,a,o,s,c){let l=this._unitId,u=this._subUnitId;this._unitId=e,this._subUnitId=t;let d=this._getConnectPointInfo(a);if(this._unitId=l,this._subUnitId=u,!d)return;let{left:f=0,top:p=0,width:m=0,height:h=0,flipX:g=!1,flipY:_=!1}=s.transform,v=i.getConnectorLinePoints();if(v.length<2)return;let y=new r.ConnectorCoordinateTransform({left:f,top:p,width:m,height:h,flipX:g,flipY:_}),b=o?v[v.length-1]:v[0],x=y.localToWorld(b),S=r.ConnectorCoordinateTransform.computeConnectorResizeLayout(x,d.point,!o);c.transformByState({flipX:S.worldRect.flipX,flipY:S.worldRect.flipY,left:S.worldRect.left,top:S.worldRect.top,width:S.worldRect.width,height:S.worldRect.height,angle:S.worldRect.angle}),c.makeDirty(!0)}_clearShapeConnectorHandlerObjects(){this._connectorObjects.length!==0&&(this._connectorObjects.forEach(e=>{e.dispose()}),this._connectorObjects=[])}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(e=>{this._isDrawingShapePointDown&&this._activeShapeId&&this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;this._clearShapeConnectorHandlerObjects(),t!==null&&t.size===1&&t.values().next().value instanceof D&&(this._isDrawingShapePointDown=!0)})),this.disposeWithMe(t.changing$.subscribe(e=>{this._isDrawingShapePointDown&&this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isDrawingShapePointDown&&(this._isDrawingShapePointDown=!1,this._addShapeConnectorHandlerObjects())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{this._unitId&&this._subUnitId&&this._activeShapeId&&this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId})&&(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects())}))}))}_registerDrawingFocusChangeHandler(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let t=e[0];if(t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&(0,r.isConnectorShape)(e.getShapeType())){this._activeShapeId=t.drawingId,this._unitId=t.unitId,this._subUnitId=t.subUnitId,this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects();return}}}this._activeShapeId=void 0,this._unitId=void 0,this._subUnitId=void 0,this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){var t;let n=e[0],r=(t=this._drawingManagerService.getDrawingByParam(n))==null?void 0:t.drawingType;r===o.DrawingTypeEnum.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===o.DrawingTypeEnum.DRAWING_SHAPE&&this._handleBasicShapeUpdateConnectorLineShape(n.unitId,n.subUnitId,n.drawingId)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e){let{drawingId:e}=t;if(this._activeShapeId===e){this._reset();return}}}))}_handleConnectedEndpointMove(e,t,n,i,a){var o;if(!this._activeShapeModel)return;let s=this._getConnectPointInfo(e);if(!s)return;let c=this._currentConnectionTarget?this._currentConnectionTarget.worldPoint:t,l=this._currentConnectionTarget?this._currentConnectionTarget.angle:this._calculateFreeEndpointAngle(s.point,c),u;if(this._currentConnectionTarget){let e=this._drawingManagerService.getDrawingByParam({unitId:this._currentConnectionTarget.unitId,subUnitId:this._currentConnectionTarget.subUnitId,drawingId:this._currentConnectionTarget.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:i=0,height:a=0,angle:o}=e.transform;u=(0,r.getBasicShapeRotateBound)({left:t,top:n,width:i,height:a},o||0)}else u={left:c.x,top:c.y,width:0,height:0}}else u={left:c.x,top:c.y,width:0,height:0};let d={point:c,angle:l,bounds:u},f=n?d:s,p=n?s:d,m=this._activeShapeModel.getShapeType(),h=(0,r.routeConnectorLineShape)(f,p,m);h&&this._activeShapeModel.updateLinePoints(h);let g=(0,r.computeConnectorRouteLayout)(h,m);g.lineType!==m&&this._activeShapeModel.changeShapeType(g.lineType);for(let[e,t]of Object.entries(g.adjustValues))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:g.worldRect.width,height:g.worldRect.height}),i.transformByState({flipX:g.worldRect.flipX,flipY:g.worldRect.flipY,left:g.worldRect.left,top:g.worldRect.top,width:g.worldRect.width,height:g.worldRect.height,angle:g.rotation}),i.makeDirty(!0);let _=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??t;a.transformByState({left:_.x-r.ShapeDefaultConfig.cxnPointRadius,top:_.y-r.ShapeDefaultConfig.cxnPointRadius})}_handleFreeEndpointMove(e,t,n,i,a){var o,s;let c=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e,l=r.ConnectorCoordinateTransform.computeConnectorResizeLayout(t,c,n);i.transformByState({flipX:l.worldRect.flipX,flipY:l.worldRect.flipY,left:l.worldRect.left,top:l.worldRect.top,width:l.worldRect.width,height:l.worldRect.height,angle:l.worldRect.angle});let u=((s=this._currentConnectionTarget)==null?void 0:s.worldPoint)??e;a.transformByState({left:u.x-r.ShapeDefaultConfig.cxnPointRadius,top:u.y-r.ShapeDefaultConfig.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:n}=e,i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,t);if(!i)return null;let a=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:t});if(!(a!=null&&a.transform))return null;let{left:o=0,top:s=0,width:c=0,height:l=0,flipX:u=!1,flipY:d=!1,angle:f}=a.transform;i.updateContext({width:c,height:l});let p=i.getConnectionSiteList().find(e=>e.index===n);if(!p)return null;let m=u?c-p.x:p.x,h=d?l-p.y:p.y;if(f!==0&&f!=null){let e=f*Math.PI/180,t=Math.cos(e),n=Math.sin(e),r=c/2,i=l/2,a=m-r,o=h-i;m=r+a*t-o*n,h=i+a*n+o*t}m+=o,h+=s;let g=p.ang/6e4;u&&(g=180-g),d&&(g=-g),g+=f||0,g=(g%360+360)%360;let _=(0,r.getBasicShapeRotateBound)({left:o,top:s,width:c,height:l},f||0);return{point:{x:m,y:h},angle:g,bounds:_}}_calculateFreeEndpointAngle(e,t){let n=t.x-e.x,r=t.y-e.y;return Math.abs(n)>=Math.abs(r)?n>=0?180:0:r>=0?270:90}_reset(){this._activeShapeId=void 0,this._unitId=void 0,this._subUnitId=void 0,this._clearShapeConnectorHandlerObjects()}dispose(){this._clearShapeConnectorHandlerObjects(),super.dispose()}};Jt=A([k(1,o.ICommandService),k(2,s.IRenderManagerService),k(3,d.IDrawingManagerService),k(4,o.IUniverInstanceService),k(5,(0,o.Inject)(a.SheetsShapeService)),k(6,(0,o.Inject)(M)),k(7,(0,o.Inject)(W))],Jt);let K=class extends o.Disposable{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._drawingManagerService=t,this._shapeRenderController=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{var r;let{unitId:i,subUnitId:a,scene:s,resourceCollector:c}=t,l=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[a];return l==null||l.order.forEach(e=>{let t=l.data[e];t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,s,{resourceCollector:c})}),n(e)}}))}};K=A([k(0,(0,o.Inject)(u.SheetPrintInterceptorService)),k(1,d.IDrawingManagerService),k(2,(0,o.Inject)(j))],K);let q=class extends o.Disposable{constructor(e,t,n,r){super(),this._commandService=e,this._univerInstanceService=t,this._localeService=n,this._sheetPermissionCheckController=r,this._initPermission()}_initPermission(){let e=/* @__PURE__ */ new Set([S.id,a.ToggleSheetsShapeFlipCommand.id,a.SetSheetsShapeRotateCommand.id,a.SetSheetsShapeTextVerticalToggleCommand.id,a.UpdateLineShapeResizeCommand.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===a.InsertShapeCommand.id||t.id===a.SetShapeDrawingDataCommand.id||t.id===a.UpdateConnectorRelationCommand.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=(0,c.getSheetCommandTarget)(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==o.SheetTypes.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[c.WorkbookEditablePermission],worksheetTypes:[c.WorksheetEditPermission]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};q=A([k(0,(0,o.Inject)(o.ICommandService)),k(1,(0,o.Inject)(o.IUniverInstanceService)),k(2,(0,o.Inject)(o.LocaleService)),k(3,(0,o.Inject)(c.SheetPermissionCheckController))],q);let J=class{constructor(e){this._renderManagerService=e}updateShapeFillImage(e,t){let n=this._renderManagerService.getRenderUnitById(e.unitId),r=n==null?void 0:n.scene;if(!r)return;let i=(0,d.getDrawingShapeKeyByDrawingSearch)(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};J=A([k(0,s.IRenderManagerService)],J);let Y=class extends o.Plugin{constructor(e=mt,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=(0,o.merge)({},mt,this._config);this._configService.setConfig(pt,a),this._initCommands()}onStarting(){this._injector.add([Bt]),this._injector.get(Bt),(0,o.registerDependencies)(this._injector,[[V],[U],[j],[K],[J],[B],[H],[L],[q]])}onReady(){(0,o.registerDependencies)(this._injector,[[W],[M],[G]]),(0,o.touchDependencies)(this._injector,[[G],[M]]),[[W],[ht],[Jt],[Ht]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,e))})}onRendered(){(0,o.touchDependencies)(this._injector,[[V],[U],[j],[K],[J],[B],[H],[L],[q]])}onSteady(){this._injector.get(V).initShapePopupMenu()}_initCommands(){[N,S,re,ft].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E(Y,`type`,o.UniverInstanceType.UNIVER_SHEET),E(Y,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E(Y,`packageName`,ut),E(Y,`version`,dt),Y=A([(0,o.DependentOn)(g.UniverLicensePlugin,_.UniverDocsPlugin,d.UniverDrawingPlugin,s.UniverRenderEnginePlugin,c.UniverSheetsPlugin,v.UniverDocsUIPlugin,l.UniverSheetsDrawingPlugin,i.UniverShapeEditorPlugin,y.UniverSheetsDrawingMobileUIPlugin,a.UniverSheetsShapePlugin,u.UniverSheetsMobileUIPlugin,t.UniverShapeEditorMobileUIPlugin,n.UniverMobileUIPlugin),k(1,(0,o.Inject)(o.Injector)),k(2,o.ICommandService),k(3,o.IConfigService),k(4,s.IRenderManagerService)],Y);let Yt={type:o.CommandType.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function Xt(){let e=(0,n.useDependency)(d.IDrawingManagerService),t=(0,n.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return t.length===0?null:/* @__PURE__ */ (0,h.jsx)(`div`,{children:/* @__PURE__ */ (0,h.jsxs)(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ (0,h.jsx)(p.DrawingCommonPanel,{drawings:t,hasCropper:!1}),/* @__PURE__ */ (0,h.jsx)(y.SheetDrawingAnchor,{drawings:t})]})})}function Zt(e){let{unitId:r,subUnitId:i,shapeId:a}=e,s=(0,n.useDependency)(o.ICommandService),c=(0,n.useDependency)(J);return/* @__PURE__ */ (0,h.jsx)(t.ShapeEditPanel,{...e,positionEditor:/* @__PURE__ */ (0,h.jsx)(Xt,{}),onUpdateShapeData:(e,t)=>{C(s,r,i,a,e,t)},onUpdateLineShapeData:(e,t)=>{w(s,r,i,a,e,t)},onUpdateShapeFillImage:e=>{c.updateShapeFillImage({unitId:r,subUnitId:i,drawingId:a},e)}})}function Qt(e){let r=(0,n.useDependency)(t.ShapeFloatingToolbarService),i=(0,n.useObservable)(()=>r.visible$,r.getVisible(),!1,[r]),a=e.popup.extraProps;return!a||!i?null:/* @__PURE__ */ (0,h.jsx)($t,{...a,canvasElement:e.popup.canvasElement})}function $t(e){let i=(0,n.useDependency)(o.ICommandService),s=(0,n.useDependency)(a.SheetsShapeService),{unitId:c,subUnitId:u,drawingId:d,drawingType:f,shapeType:p}=e,[m,g]=(0,b.useState)(e.shapeData),_=(0,b.useMemo)(()=>(0,t.getTextStyle)(m),[m]),v=(0,b.useMemo)(()=>(0,t.getTextModel)(m),[m]);(0,b.useEffect)(()=>{let e=i.onCommandExecuted(e=>{if(e.id!==a.UpdateSheetsShapeDataMutation.id)return;let t=s.getShapeDataById(c,u,d);t&&g(t)});return()=>e.dispose()},[i,d,s,u,c]);let y=e=>{g(t=>({...t,...e}))},x=e=>{let n=(0,t.buildShapeTextDataUpdate)(m,e);C(i,c,u,d,{oldShapeData:{shapeText:m.shapeText}},n),y(n)},S=(0,t.useFormulaShapeToolbar)({hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:c,subUnitId:u,shapeId:d,shapeData:m,onUpdateBinding:e=>{let t={formulaBinding:e};C(i,c,u,d,{oldShapeData:{formulaBinding:m.formulaBinding}},t),y(t)}});return/* @__PURE__ */ (0,h.jsxs)(h.Fragment,{children:[/* @__PURE__ */ (0,h.jsx)(t.ShapeFloatingToolbar,{canvasElement:e.canvasElement,shapeData:m,shapeType:p,textStyle:{ff:r.ShapeDefaultConfig.shapeText.fontFamily,fs:r.ShapeDefaultConfig.shapeText.fontSize,cl:{rgb:r.ShapeDefaultConfig.shapeText.color},..._},textModel:v?{ha:v.ha??o.HorizontalAlign.LEFT,va:v.va??o.VerticalAlign.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:r.ShapeDefaultConfig.fill,defaultGradientEndColor:r.ShapeDefaultConfig.gradientEndColor,defaultStrokeColor:r.ShapeDefaultConfig.stroke,extensionGroups:S.extensionGroups,floatingObjectToolbarPosition:n.FloatingObjectToolbarPosition.SHEET,onUpdateShapeData:(e,t)=>{C(i,c,u,d,e,t),t&&y(t)},onUpdateText:x,onOpenPanel:()=>{i.executeCommand(I.id,{unitId:c,subUnitId:u,drawingId:d})},onDelete:()=>{i.executeCommand(l.RemoveSheetDrawingCommand.id,{unitId:c,drawings:[{unitId:c,subUnitId:u,drawingId:d,drawingType:f}]})}}),S.panel]})}function en(e){return!!e&&`axisAlignSheetTransform`in e&&`sheetTransform`in e}let tn=(0,b.memo)(()=>{let e=(0,n.useDependency)(B),r=(0,n.useDependency)(a.SheetsShapeService),i=(0,n.useDependency)(d.IDrawingManagerService),c=(0,n.useDependency)(o.ICommandService),f=(0,n.useDependency)(n.UndoRedoGroupService),p=(0,n.useDependency)(s.IRenderManagerService),m=(0,b.useMemo)(()=>({getShapeModel:(e,t,n)=>r.getShapeModel(e,t,n),getShapeData:(e,t,n)=>r.getShapeDataById(e,t,n),getDrawingTransform:(e,t,n)=>{let r=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n});return r==null?void 0:r.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:n,shapeText:r,oldShapeText:a,hostSize:o})=>{f.run(e,()=>{var s;let d=c.syncExecuteCommand(S.id,{unitId:e,subUnitId:t,shapeId:n,shapeData:{shapeText:r},oldShapeJSON:{oldShapeData:{shapeText:a}}});if(!d||!o)return d;let f=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),m=f==null?void 0:f.transform;if(!en(f)||!m)return!1;let h={...m,width:o.width,height:o.height},g=(s=p.getRenderUnitById(e))==null||(s=s.with(u.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:s.skeleton;return c.syncExecuteCommand(l.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...f,transform:h,sheetTransform:g?(0,l.transformToDrawingPosition)(h,g)??f.sheetTransform:f.sheetTransform,axisAlignSheetTransform:g?(0,l.transformToAxisAlignPosition)(h,g)??f.axisAlignSheetTransform:f.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:n,width:r,height:a})=>{var o;let s=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),d=s==null?void 0:s.transform;if(!en(s)||!d)return;let f={...d,width:r,height:a},m=(o=p.getRenderUnitById(e))==null||(o=o.with(u.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:o.skeleton,h=m?(0,l.transformToDrawingPosition)(f,m)??s.sheetTransform:s.sheetTransform,g=m?(0,l.transformToAxisAlignPosition)(f,m)??s.axisAlignSheetTransform:s.axisAlignSheetTransform;c.executeCommand(l.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...s,transform:f,sheetTransform:h,axisAlignSheetTransform:g}]})},allowHostSizeShrink:({unitId:e,subUnitId:n,shapeId:i})=>(0,t.shouldAllowShapeTextEditorHostSizeShrink)(r.getShapeDataById(e,n,i)),deferHostSizeUpdateDuringEditing:()=>!0}),[c,i,p,r,f]),g=(0,b.useMemo)(()=>({viewportKeys:{main:s.SHEET_VIEWPORT_KEY.VIEW_MAIN,leftTop:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,top:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,left:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(u.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ (0,h.jsx)(t.ShapeTextEditorContainer,{adapter:m,editingService:e,editorUnitId:oe,positionOptions:g})}),X=class extends o.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerIcons(),this._registerComponents()}_registerIcons(){this._iconManager.has(`ObjectLayersIcon`)||this.disposeWithMe(this._iconManager.register({ObjectLayersIcon:Nt})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:Tt})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:Dt})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:Ct})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:kt})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:jt})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:Ft})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:Lt}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(P,Zt)),this.disposeWithMe(this._componentManager.register(F,Rt)),this.disposeWithMe(this._componentManager.register(fe,ve)),this.disposeWithMe(this._componentManager.register(pe,he)),this._componentManager.hasDefault(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(this._componentManager.register(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,_e)),this.disposeWithMe(this._componentManager.register(ie,Qt)),this.disposeWithMe(this._componentManager.register(je,Fe)),this.disposeWithMe(this._componentManager.register(Ae,Ie)),this.disposeWithMe(this._componentManager.register(Me,Le)),this.disposeWithMe(this._componentManager.register(Ne,Re)),this.disposeWithMe(this._componentManager.register(se,t.ShapeTextFloatToolbar)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,tn))}};X=A([k(0,(0,o.Inject)(n.ComponentManager)),k(1,(0,o.Inject)(n.IconManager))],X);let nn=class extends o.Disposable{constructor(e,n,r,i,a,l,u,d,p){super();let m=e=>{var t,n;return(((t=d.getPermissionPoint(new c.WorkbookEditablePermission(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=d.getPermissionPoint(new c.WorksheetEditPermission(e.unitId,e.subUnitId).id))==null?void 0:n.value)??!0)},h=e=>e.shapeId&&m(e)?r.getShapeDataById(e.unitId,e.subUnitId,e.shapeId)??null:null,g=()=>{let t=a.getFocusDrawings(),n=t.length===1?t[0]:null;return(n==null?void 0:n.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE&&n.unitId===e.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe((0,t.registerShapeFormatPainter)(e,n,{changes$:(0,f.merge)(a.focus$,i.editingParams$,d.permissionPointUpdate$),isActive:()=>{var t;return((t=l.getFocusedUnit())==null?void 0:t.getUnitId())===e.unitId&&!u.getContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR)&&a.getFocusDrawings().some(t=>t.unitId===e.unitId)},getSelectedTarget:g,getSource:()=>{let e=g();return e?h(e):null},getTarget:t=>{let n=e.scene.pick(new s.Vector2(t.offsetX,t.offsetY));if(!(n instanceof D))return null;let r={unitId:e.unitId,subUnitId:n.subUnitId,shapeId:n.shapeId};return m(r)?r:null},getShape:h,update:(e,t,n)=>p.executeCommand(S.id,{...e,shapeData:n,replaceShapeData:!0,oldShapeJSON:{oldShapeData:t}})}))}};nn=A([k(1,(0,o.Inject)(n.FormatPainterSessionService)),k(2,(0,o.Inject)(a.SheetsShapeService)),k(3,(0,o.Inject)(B)),k(4,d.IDrawingManagerService),k(5,o.IUniverInstanceService),k(6,o.IContextService),k(7,o.IPermissionService),k(8,o.ICommandService)],nn);let rn=`sheets-shape-contextual-ribbon`,Z=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=a,E(this,`_visible`,!1),this._menuManagerService.mergeMenu(st),this.disposeWithMe((0,o.toDisposable)(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,rn),this._hide(),super.dispose()}_update(){var e;let n=this._drawingManagerService.getFocusDrawings(),r=n.length===1?n[0]:void 0;if((r==null?void 0:r.drawingType)!==o.DrawingTypeEnum.DRAWING_SHAPE||this._univerInstanceService.getUnitType(r.unitId)!==o.UniverInstanceType.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,rn),this._hide();return}let i=(e=this._renderManagerService.getRenderUnitById(r.unitId))==null?void 0:e.engine.getCanvasElement(),a=(0,t.resolveShapeContextualRibbonHostMode)(i)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(a,rn),a?this._hide():this._visible||(this._visible=!0,this._ribbonService.showContextualTab(ae,{activate:!0}))}_hide(){this._visible&&(this._visible=!1,this._ribbonService.hideContextualTab(ae),this._ribbonService.setCollapsedIds([]))}};Z=A([k(0,n.IMenuManagerService),k(1,n.IRibbonService),k(2,d.IDrawingManagerService),k(3,o.IUniverInstanceService),k(4,s.IRenderManagerService),k(5,(0,o.Inject)(t.ShapeFloatingToolbarService))],Z);let an=class extends t.ShapeTextFloatMenuRenderControllerBase{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l,{componentKey:se,editorUnitId:oe})}};an=A([k(1,(0,o.Inject)(_.DocSelectionManagerService)),k(2,(0,o.Inject)(v.DocCanvasPopManagerService)),k(3,(0,o.Inject)(v.DocSelectionRenderService)),k(4,o.ICommandService),k(5,(0,o.Inject)(v.DocEventManagerService)),k(6,(0,o.Inject)(t.ShapeTextHyperLinkPopupService)),k(7,(0,o.Inject)(_.DocInterceptorService)),k(8,(0,o.Inject)(v.DocRenderController)),k(9,(0,o.Inject)(B))],an);let on=class extends t.ShapeTextHyperLinkHoverController{constructor(e,n,r,i,a){super(e,n,{editing$:r.editingParams$,resolve:r=>{var o,l,u;let d=new s.Vector2(r.offsetX,r.offsetY),f=((o=e.scene.getActiveViewportByCoord(d))==null?void 0:o.transformVector2SceneCoord(d))??d,p=(0,t.resolveShapeTextHyperLinkObject)(e.scene.pick(d)??null,f);if(!(p instanceof D))return null;let m=p.resolveHyperLinkAt(f);if(!m)return null;let h=p,g={componentKey:t.ShapeTextHyperLinkInfo.componentKey,direction:`top-center`,offset:[0,10],onClickOutside:()=>n.hideInfoPopup()};return{object:p,info:{...m,unitId:p.unitId,subUnitId:p.subUnitId,shapeKey:p.oKey,readonly:!0,copyable:((l=a.getPermissionPoint(new c.WorkbookCopyPermission(p.unitId).id))==null?void 0:l.value)!==!1&&((u=a.getPermissionPoint(new c.WorksheetCopyPermission(p.unitId,p.subUnitId).id))==null?void 0:u.value)!==!1},attachPopup:()=>i.attachPopupToObject(h,g)}}}),this.disposeWithMe(e.unit.activeSheet$.subscribe(()=>this.clear()))}};on=A([k(1,(0,o.Inject)(t.ShapeTextHyperLinkPopupService)),k(2,(0,o.Inject)(B)),k(3,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(4,o.IPermissionService)],on);let Q=class extends o.Disposable{constructor(e,t,n,r,i,a,s,c,l,u,d){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=a,this._drawingManagerService=s,this._sheetCanvasPopManagerService=c,this._contextService=l,this._renderManagerService=u,this._shapeTextEditingService=d,E(this,`_sidebarDisposable`,null),E(this,`_activeShapeInfo`,null),E(this,`_isOpenedShapeEditPanel`,!1),E(this,`_shapeEditPanelVersion`,0),E(this,`_shapePopupMenuDisposable`,null),E(this,`_disposePopups`,[]),this._initMenu(),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose()}})),this._registerOperations(),this.initShapePopupMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearPopups()}))}_initMenu(){this._menuManagerService.mergeMenu(lt)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,t.bindRenderTransformerLifecycle)(this._renderManagerService,o.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_getShapeInfo(e,t,n){let r=this._sheetsShapeService.getShapeTypeById(e,t,n),i=this._sheetsShapeService.getShapeDataById(e,t,n);return r!==void 0&&i!==void 0?{shapeData:i,shapeId:n,shapeType:r,unitId:e,subUnitId:t,version:this._shapeEditPanelVersion,disableShapeOption:!1}:null}_clearPopups(){this._disposePopups.forEach(e=>e.dispose()),this._disposePopups.length=0}_popupMenuListener(e){let n=new o.DisposableCollection;return n.add(e.createControl$.subscribe(()=>{let n=e.getSelectedObjectMap();if(this._clearPopups(),this._isOpenedShapeEditPanel||n.size>1)return;let r=n.values().next().value;if(!r)return;let i=this._drawingManagerService.getDrawingOKey(r.oKey);if(!i||i.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:a,subUnitId:s,drawingId:c,drawingType:l}=i,d=this._getShapeInfo(a,s,c);if(!d)return;this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!0);let f=this._renderManagerService.getRenderUnitById(a),p=((f==null?void 0:f.isMainScene)===!1?f.with(u.SheetCanvasPopManagerService):this._sheetCanvasPopManagerService).attachPopupToObject(r,{componentKey:ie,direction:`vertical-center`,offset:[0,t.SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET],extraProps:{unitId:a,subUnitId:s,drawingId:c,drawingType:l,shapeType:d.shapeType,shapeData:d.shapeData}});this._disposePopups.push(this.disposeWithMe(p)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===a&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:a,subUnitId:s,drawingId:c}])})),n.add(e.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),n.add(e.changing$.subscribe(()=>{this._clearPopups()})),n.add(e.changeStart$.subscribe(()=>{this._clearPopups()})),(0,o.toDisposable)(()=>{n.dispose(),this._clearPopups()})}_registerOperations(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===I.id){let{unitId:t,subUnitId:n,drawingId:r}=e.params;this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(t,n,r),this._clearPopups(),this._openShapeEditPanel()}if(e.id===Yt.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===a.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params;if(this._activeShapeInfo&&this._activeShapeInfo.shapeId===r){let e=this._getShapeInfo(t,n,r);e&&(this._shapeEditPanelVersion+=1,e.version=this._shapeEditPanelVersion,this._activeShapeInfo=e,this._isOpenedShapeEditPanel&&this._openShapeEditPanel())}}})),this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(this._isOpenedShapeEditPanel===!1)return;if(e.length===0){this._activeShapeInfo=null,this._closeShapeEditPanel();return}if(e.length===1&&e[0].drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo)){this._openShapeEditPanel();return}let t=e.filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(e.length>1&&t.length===e.length){if(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo){this._openShapeEditPanel();return}}else if(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo){this._activeShapeInfo.disableShapeOption=!0,this._openShapeEditPanel();return}this._closeShapeEditPanel()}))}_openShapeEditPanel(){this._activeShapeInfo&&(this._sidebarDisposable=this._sidebarService.open({id:P,header:{title:this._localeService.t(`sheets-shape-ui.formatShape`)},width:388,children:{label:P,...this._activeShapeInfo},onClose:()=>{this._drawingManagerService.focusDrawing(null),this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(P),this._sidebarDisposable=null,this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};Q=A([k(0,o.IUniverInstanceService),k(1,(0,o.Inject)(n.ISidebarService)),k(2,n.IMenuManagerService),k(3,(0,o.Inject)(a.SheetsShapeService)),k(4,(0,o.Inject)(o.LocaleService)),k(5,o.ICommandService),k(6,d.IDrawingManagerService),k(7,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(8,o.IContextService),k(9,s.IRenderManagerService),k(10,(0,o.Inject)(B))],Q);let $=class extends o.Plugin{constructor(e=mt,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=(0,o.merge)({},mt,this._config);this._configService.setConfig(pt,a),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,[an]),(0,o.touchDependencies)(this._injector,[[Q],[U],[j],[K]])}onSteady(){this._injector.get(Q).initShapePopupMenu()}onReady(){[[W],[M],[G]].forEach(e=>this._injector.add(e)),(0,o.touchDependencies)(this._injector,[[G],[M]]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[W]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ht]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Jt]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Vt]),this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[on])),this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[nn]))}onStarting(){this._injector.add([X]),this._injector.get(X);let e=this._injector;[[Q],[U],[j],[K],[J],[B],[H],[L],[q],[Z]].forEach(t=>e.add(t)),(0,o.touchDependencies)(this._injector,[[Q],[U],[j],[J],[B],[H],[L],[q],[Z]])}_initCommands(){[N,S,Yt,I,ce,re,ue,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E($,`type`,o.UniverInstanceType.UNIVER_SHEET),E($,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E($,`packageName`,ut),E($,`version`,dt),$=A([(0,o.DependentOn)(g.UniverLicensePlugin,_.UniverDocsPlugin,d.UniverDrawingPlugin,p.UniverDrawingUIPlugin,s.UniverRenderEnginePlugin,c.UniverSheetsPlugin,v.UniverDocsUIPlugin,l.UniverSheetsDrawingPlugin,i.UniverShapeEditorPlugin,y.UniverSheetsDrawingUIPlugin,a.UniverSheetsShapePlugin,u.UniverSheetsUIPlugin,t.UniverShapeEditorUIPlugin),k(1,(0,o.Inject)(o.Injector)),k(2,o.ICommandService),k(3,o.IConfigService),k(4,s.IRenderManagerService)],$),e.SheetsShapeUIContextualRibbonSchema=st,e.SheetsShapeUIMenuSchema=lt,Object.defineProperty(e,"UniverSheetsShapeMobileUIPlugin",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(e,"UniverSheetsShapeUIPlugin",{enumerable:!0,get:function(){return $}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/shape-editor-ui"),require("@univerjs/ui"),require("@univerjs-pro/engine-shape"),require("@univerjs-pro/shape-editor"),require("@univerjs-pro/sheets-shape"),require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/drawing"),require("rxjs"),require("@univerjs/drawing-ui"),require("@univerjs/design"),require("react/jsx-runtime"),require("@univerjs-pro/license"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/sheets-drawing-ui"),require("react")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/shape-editor-ui`,`@univerjs/ui`,`@univerjs-pro/engine-shape`,`@univerjs-pro/shape-editor`,`@univerjs-pro/sheets-shape`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-drawing`,`@univerjs/sheets-ui`,`@univerjs/drawing`,`rxjs`,`@univerjs/drawing-ui`,`@univerjs/design`,`react/jsx-runtime`,`@univerjs-pro/license`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/sheets-drawing-ui`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProSheetsShapeUi={},e.UniverProShapeEditorUi,e.UniverUi,e.UniverProEngineShape,e.UniverProShapeEditor,e.UniverProSheetsShape,e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsDrawing,e.UniverSheetsUi,e.UniverDrawing,e.rxjs,e.UniverDrawingUi,e.UniverDesign,e.React,e.UniverProLicense,e.UniverDocs,e.UniverDocsUi,e.UniverSheetsDrawingUi,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function x(e,t){let n={};for(let r of Object.keys(t)){let i=t[r],a=e[r];n[r]=a===void 0?void 0:typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a&&!Array.isArray(a)?x(a,i):a}return n}let S={type:o.CommandType.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(a.SheetsShapeService),{unitId:r,subUnitId:i,shapeType:s,shapeId:c,shapeData:l,replaceShapeData:u,oldShapeJSON:d}=t;if(!n.getShapeModel(r,i,c))return!1;let f=e.get(o.ICommandService),p=e.get(o.IUndoRedoService),{oldShapeType:m,oldShapeData:h={}}=d,g=u?h:x(h,l||{}),_={id:a.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:i,shapeId:c,shapeType:s,shapeData:l,replace:u}},v={id:a.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:i,shapeId:c,shapeType:m,shapeData:g,replace:u}};return f.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:r,undoMutations:[v],redoMutations:[_]}),!0):!1}};function C(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(S.id,o)}function w(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(S.id,o)}function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function ee(e,t){if(T(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function te(e){var t=ee(e,`string`);return T(t)==`symbol`?t:t+``}function E(e,t,n){return(t=te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ne(e,n,r){let i={...n,dataModel:{...n.dataModel??{},...r?{doc:r}:null}},a=(0,t.resolveShapeTextEditorBehaviorShapeData)(e,i),o=(0,t.resolveShapeTextEditorWrapStrategy)(a);return{clip:(0,t.shouldClipShapeTextDocument)(a,o),wrapStrategy:o}}var D=class extends s.Shape{constructor(e,n){super(e,n),E(this,`_hyperLinkRegions`,[]),E(this,`_props`,void 0),E(this,`_formulaAnimation`,new t.FormulaShapeAnimationController(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),E(this,`_transformCalculateSrcRect`,!0),E(this,`_drawingType`,o.DrawingTypeEnum.DRAWING_SHAPE),E(this,`isDrawingObject`,!0),this._props={...n},this._formulaAnimation.setPresentation(n.formulaPresentation,n.animateFormulaPresentation!==!1),this._init(),this._applyFormulaAutoFitSize()}_init(){this.onTransformChange$.subscribeEvent(e=>{this._updateSrcRectByTransform(e)})}setPrstGeom(e){this._props.prstGeom=e}resolveHyperLinkAt(e){if(this._props.isEditing)return null;let n=this.getInverseCoord(e),{width:r,height:i}=this.getRealBound();return(0,t.resolveShapeTextHyperLinkAt)(this._hyperLinkRegions,{x:(this.flipX?-n.x:n.x)+r/2,y:n.y+i/2})}setEditing(e){this._props.isEditing=e,this.makeDirty(!0)}setFormulaPresentation(e,t=!0){this._formulaAnimation.setPresentation(e,t),this._props.formulaPresentation=e,this._applyFormulaAutoFitSize(),this.makeDirty(!0)}_applyFormulaAutoFitSize(){let e=this._props.shapeModel,n=e.getShapeTextData(),r=(0,t.normalizeShapeTextModel)(n==null?void 0:n.dataModel),a=r==null?void 0:r.doc,o=this._formulaAnimation.getAutoFitPresentations();if(!a||o.length===0)return;e.updateContext({width:this.width,height:this.height});let s=(0,t.resolveFormulaShapeAutoFitSize)({documentData:o.map(e=>(0,i.createShapeFormulaDocument)(a,e)),height:this.height,shapeData:e.getShapeData(),textRect:e.getShapeTextRect({left:0,top:0,width:this.width,height:this.height}),width:this.width});if(s){var c;this.resize(s.width,s.height),(c=this.getScene())==null||(c=c.getTransformer())==null||c.debounceRefreshControls()}}get unitId(){return this._props.unitId}get subUnitId(){return this._props.subUnitId}_updateSrcRectByTransform(e){if(this._props.srcRect==null||!this._transformCalculateSrcRect)return;let{width:t,height:n}=this,{width:r=0,height:i=0}=e.preValue,{left:a=0,top:o=0,right:s=0,bottom:c=0}=this._props.srcRect,l=a,u=o,d=s,f=c,p=!1;if(r!==0&&r!==t){let e=a/r,n=s/r;l=t*e,d=t*n,p=!0}if(i!==0&&i!==n){let e=o/i,t=c/i;u=n*e,f=n*t,p=!0}p&&this.setSrcRect({left:l,top:u,right:d,bottom:f})}setSrcRect(e){this._props.srcRect=e,this.makeDirty(!0)}setFillImage(e){this._props.image=e,this.makeDirty(!0)}set transform(e){this._transform=e}get transform(){this._transform||this._setTransForm();let e=this._transform.clone();return this.transformForAngle(e)}get shapeModel(){return this._props.shapeModel}get shapeId(){return this._props.shapeId}get classType(){return s.RENDER_CLASS_TYPE.SHAPE}_draw(e,t,n,i){let a=this._props.shapeModel;if(!a||!t)return;let o=n??this.width,s=i??this.height,c={shapeType:a.getShapeType(),width:o,height:s},l={renderMode:r.ShapeRenderModeEnum.Path,oKey:this.oKey,image:this._props.image,angle:this.angle};a.updateContext(c),e.save();let u={top:0,left:0,width:o,height:s},d=a.getDrawingEffectBounds(u);d?this._renderWithCache(e,d,e=>{a.render(e,u,l)}):(this._releaseRenderCache(),a.render(e,u,l)),e.restore();let f=a.getShapeTextData(),p=a.getShapeTextRect(u),m=a.isLineShape();if(f&&p&&!m){e.save(),this.getState().flipX&&e.scale(-1,1);let t=o/2,n=s/2;e.translate(-t,-n),e.beginPath(),this._drawShapeText(e,f,p),e.restore()}}getDrawingPoints(e){}_drawShapeText(e,t,n){var r;this._hyperLinkRegions=[],this._props.isEditing||(!((r=t.dataModel)!=null&&r.doc)&&`isRichText`in t&&t.isRichText===!1?this._drawSimpleText(e,t,n):this._drawRichText(e,t,n))}_drawSimpleText(e,n,r){this._drawRichText(e,{...n,text:n.text??``,dataModel:{doc:(0,t.plainShapeTextToDocumentData)(n,`sheets-shape-text-${this.oKey}`)}},r)}_drawRichText(e,n,r){(0,t.drawFormulaShapeAnimationLayers)(e,this._formulaAnimation,(e,t,i)=>{this._drawRichTextLayer(e,n,r,t,i===`current`)})}_drawRichTextLayer(e,n,r,a,c){let l=this._props.localeService;if(!n.dataModel||!l)return;let u=(0,t.normalizeShapeTextModel)(n.dataModel);if(!u)return;let d=u.doc;if(!d)return;let f=(0,i.createShapeFormulaDocument)(d,a),p=u.va??o.VerticalAlign.TOP,m=u.ha??o.HorizontalAlign.LEFT,h=ne(this._props.shapeModel.getShapeData(),n,f),g=n.isHorizontal,_=(0,t.prepareShapeTextDocumentData)(f,{isHorizontal:g!==!1,textRect:r,verticalAlign:p,horizontalAlign:m,wrapStrategy:h.wrapStrategy}),v=new o.DocumentDataModel(_),y=new s.DocumentViewModel(v),b=s.DocumentSkeleton.create(y,l);b.calculate();let x=b.getActualSize().actualHeight,S=(0,t.resolveShapeTextDocumentRenderLayout)({contentHeight:x,verticalAlign:p,viewportHeight:r.height});v.updateDocumentStyle({pageSize:{width:g===!1?r.height:r.width,height:(0,t.resolveShapeTextDocumentPageHeight)(f,S.contentHeight)}}),v.updateDocumentDataMargin({t:S.marginTop}),b.calculate();let C=new s.Documents(`shape-text-${this.oKey}`,b,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});C.resize(r.width,S.contentHeight),e.save(),e.translateWithPrecision(r.left,r.top),h.clip&&(e.beginPath(),e.rect(0,S.clipTop,r.width,S.clipHeight),e.clip()),S.contentVerticalOffset&&e.translateWithPrecision(0,S.contentVerticalOffset),C.draw(e),c&&(this._hyperLinkRegions=(0,t.createShapeTextHyperLinkRegions)(C,{left:r.left,top:r.top+S.contentVerticalOffset},h.clip?{left:r.left,right:r.left+r.width,top:r.top+S.clipTop,bottom:r.top+S.clipTop+S.clipHeight}:void 0)),e.restore(),C.dispose(),b.dispose(),y.dispose(),v.dispose()}render(e,t,n=!1){if(!this.visible)return this.makeDirty(!1),this;let{width:r,height:i,left:a,top:o}=this,c=this.getRealBound();if(r=c.width,i=c.height,a=c.left,o=c.top,this.isRender(t)){let{top:e,left:n,bottom:s,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+o<e||s<o)return this}let l=a+r/2,u=o+i/2,d=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new s.Transform;t.composeMatrix({...e}),d=t.getMatrix()}return e.save(),this._props.shapeModel.isRenderLinePointsMode===!0||e.transform(d[0],d[1],d[2],d[3],l,u),this._draw(e,t,r,i),e.restore(),this.makeDirty(!1),this}getInverseCoord(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=this.transform.getMatrix(),o=t+r/2,c=n+i/2,l=new s.Transform([a[0],a[1],a[2],a[3],o,c]),u=this.getParent();return(this.isInGroup&&(u==null?void 0:u.classType)===s.RENDER_CLASS_TYPE.GROUP?u.ancestorTransform.multiply(l):l).invert().applyPoint(e)}isHit(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=t+r/2,o=n+i/2,c=this.transform.getMatrix(),l=new s.Transform([c[0],c[1],c[2],c[3],a,o]),u=this.getParent(),d=(this.isInGroup&&(u==null?void 0:u.classType)===s.RENDER_CLASS_TYPE.GROUP?u.ancestorTransform.multiply(l):l).invert().applyPoint(e),f=r/2,p=i/2,m=this._props.shapeModel;return m&&m.isLineShape()?m.isHitLine(d.x,d.y,r,i):d.x>=-f-this.strokeWidth/2&&d.x<=f+this.strokeWidth/2&&d.y>=-p-this.strokeWidth/2&&d.y<=p+this.strokeWidth/2}dispose(){this._formulaAnimation.dispose(),this._props.shapeModel=null,super.dispose()}},O=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_shapeId`,null),E(this,`_adjName`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),t&&this.setShapeProps(t)}getDrawingSearch(){return{unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._shapeId}}setShapeProps(e){e.shapeId!==void 0&&(this._shapeId=e.shapeId),e.adjName!==void 0&&(this._adjName=e.adjName),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),this.transformByState({width:e.width,height:e.height})}_draw(e){s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.adjHandleSize,fill:r.ShapeDefaultConfig.adjHandleFill,stroke:r.ShapeDefaultConfig.adjHandleStroke,strokeWidth:1,evented:!0})}};function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._drawingManagerService=e,this._sheetsShapeService=t,this._localeService=n,this._imageIoService=r,this._urlImageService=i,this._shapeFormulaService=a,E(this,`_formulaShapes`,/* @__PURE__ */ new Map),this.disposeWithMe(this._shapeFormulaService.presentationChanged$.subscribe(e=>{var t;(t=this._formulaShapes.get(this._formulaKey(e.unitId,e.subUnitId,e.shapeId)))==null||t.forEach(t=>t.setFormulaPresentation(e.presentation,e.animationEnabled))})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._formulaShapes.delete(this._formulaKey(e.unitId,e.subUnitId,e.drawingId))})}))}renderDrawingShape(e,t,n){let{transform:r,drawingType:i,isMultiTransform:a,transforms:s}=e;if(i===o.DrawingTypeEnum.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(a&&s?s:[r]).flatMap((r,i)=>{var o;let s=(0,d.getDrawingShapeKeyByDrawingSearch)(e,a?i:void 0),c=t.getObjectIncludeInGroup(s);if(c)return c instanceof D&&this.refreshFormulaPresentation(c,{unitId:e.unitId,subUnitId:e.subUnitId,shapeId:e.drawingId}),c.transformByState(r),[];let l=this._createShape(e,r,s,t);if(!l)return[];let u=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return u&&(n==null||(o=n.resourceCollector)==null||o.add(u)),[l]})}_createShape(e,n,i,a){let{unitId:c,subUnitId:l,drawingId:u,groupId:d,hidden:f,selectable:m,prstGeom:h,srcRect:g}=e,_=this._sheetsShapeService.getShapeModel(c,l,u);if(!_)return;let v=this._drawingManagerService.getDrawingOrder(c,l),y=v.indexOf(u),b=(0,r.isConnectorShape)(_.getShapeType()),x=_.getShapeData().formulaBinding,S={unitId:c,subUnitId:l,shapeId:u};x&&this._shapeFormulaService.register(S,x);let C=new D(i,{...n,zIndex:y===-1?v.length-1:y,shapeModel:_,drawingType:o.DrawingTypeEnum.DRAWING_SHAPE,localeService:this._localeService,shapeId:u,unitId:c,subUnitId:l,visible:f!==!0,evented:m!==!1,formulaPresentation:x?this._shapeFormulaService.getPresentation(S):void 0,animateFormulaPresentation:(x==null?void 0:x.animationEnabled)!==!1,transformerConfig:{...t.SHAPE_EDITOR_TRANSFORMER_CONFIG,...b?{rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1}:{},moveBoundaryEnabled:!0}});if(x){let e=this._formulaKey(c,l,u),t=this._formulaShapes.get(e)??/* @__PURE__ */ new Set;t.add(C),this._formulaShapes.set(e,t)}return a.addObject(C,s.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&a.attachTransformerTo(C),d&&(0,p.insertGroupObject)({drawingId:d,unitId:c,subUnitId:l},C,a,this._drawingManagerService),h!=null&&C.setPrstGeom(h),g!=null&&C.setSrcRect(g),C}_formulaKey(e,t,n){return`${e}\u0000${t}\u0000${n}`}refreshFormulaPresentation(e,t){let n=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.shapeId),r=n==null?void 0:n.getShapeData().formulaBinding,i=this._formulaKey(t.unitId,t.subUnitId,t.shapeId);if(r){this._shapeFormulaService.register(t,r);let n=this._formulaShapes.get(i)??/* @__PURE__ */ new Set;n.add(e),this._formulaShapes.set(i,n)}else{var a;this._shapeFormulaService.unregister(t),(a=this._formulaShapes.get(i))==null||a.delete(e)}e.setFormulaPresentation(r?this._shapeFormulaService.getPresentation(t):void 0,(r==null?void 0:r.animationEnabled)!==!1)}refreshShapeFillImage(e){let t=e.shapeModel.getShapeData(),n=t.fill;!n||n.fillType!==r.ShapeFillEnum.PictureFill||!n.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let n=t.fill;if(!n||n.fillType!==r.ShapeFillEnum.PictureFill||!n.fillImageSource)return;let i=n.fillImageSource,a=n.fillImageSourceType??r.ImageSourceTypeEnum.URL,o=this._imageIoService.getImageSourceCache(i,a);if(o)e.setFillImage(o);else return this._loadAndSetImage(e,i,a)}async _loadAndSetImage(e,t,n){let i;try{if(n===r.ImageSourceTypeEnum.UUID)i=await this._imageIoService.getImage(t);else if(n===r.ImageSourceTypeEnum.URL)try{i=await this._urlImageService.getImage(t)}catch{i=t}else i=t}catch(e){console.error(`[ShapeRender] Failed to resolve picture fill source`,e);return}await new Promise(r=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,n,a),e.setFillImage(a),r()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),r()},a.src=i})}};j=A([k(0,d.IDrawingManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,(0,o.Inject)(o.LocaleService)),k(3,o.IImageIoService),k(4,o.IURLImageService),k(5,(0,o.Inject)(i.ShapeFormulaService))],j);let M=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._drawingManagerService=e,this._sheetsShapeService=t,this._renderManagerService=n,this._sheetDrawingShapeRenderController=r,this._univerInstanceService=i,this._commandService=a,E(this,`_activeShapeId`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_activeShapeAdjustPointList`,void 0),E(this,`_shapes`,[]),E(this,`_baseShapeLeft`,0),E(this,`_baseShapeTop`,0),E(this,`_baseShapeWidth`,0),E(this,`_baseShapeHeight`,0),E(this,`_isStartAdjusting`,!1),E(this,`_activeAdjustInfo`,void 0),E(this,`_activeShapeModel`,void 0),E(this,`_adjHandlerPointerMove`,void 0),E(this,`_adjHandlerPointerUp`,void 0),E(this,`_isShouldShowDrawingShapeAdjust`,!1),this._registerDrawingFocusChangeHandler(),this._registerDrawingMoveHandler()}_getShapeAdjustPointListById(e,t,n){let r=this._sheetsShapeService.getShapeModel(e,t,n);if(r)return r.getDrawingPoints()}clearAdjustControls(){this._clearShapeAdjustControls()}refreshAdjustControls(){this._updateShapeAdjustControls(!0)}setShouldShowAdjust(e){this._isShouldShowDrawingShapeAdjust=e}_getShapeAdjustInfosById(e,t,n,r){let i=this._sheetsShapeService.getShapeModel(e,t,n);if(i)return i.getAdjustInfoByName(r)}_createShapeAdjustControls(e=!1){if(this._unitId===null||this._subUnitId===null||this._activeShapeId===null)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:a}=i;if(!a||i.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let{left:s,top:c,width:l,height:d,flipX:f,flipY:p,angle:m=0}=a;if(s===void 0||c===void 0)return;if(e){let e=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);e==null||e.updateContext({width:l??0,height:d??0}),this._activeShapeAdjustPointList=e==null?void 0:e.getDrawingPoints()}let h=this._activeShapeAdjustPointList;for(let e=0;e<h.length;e++){let t=h[e],r=t.x,i=t.y;if(f&&(r=(l||0)-r),p&&(i=(d||0)-i),m!==0){let e=(l||0)/2,t=(d||0)/2,n=m*Math.PI/180,a=Math.cos(n),o=Math.sin(n),s=r-e,c=i-t;r=e+(s*a-c*o),i=t+(s*o+c*a)}let a={x:r,y:i,adjName:t.adjName};this._addShapeAdjustControl(n,a,a.adjName,s,c,this._unitId,this._subUnitId)}}_updateShapeAdjustControls(e=!1){e&&(this._clearShapeAdjustControls(),this._createShapeAdjustControls(e))}_addShapeAdjustControl(e,t,n,i,a,o,c){if(!this._activeShapeId)return;let l=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${n}`);if(l){l.transformByState({left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize});return}let u={left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize,adjName:n,shapeId:this._activeShapeId,unitId:o,subUnitId:c,width:r.ShapeDefaultConfig.adjHandleSize+8,height:r.ShapeDefaultConfig.adjHandleSize+8,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0},d=new O(`shape-adjust-point-${this._activeShapeId}-${n}`,u);this._shapes.push(d),this._attachAdjustEvent(d,e,n),e.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+1)}_clearShapeAdjustControls(){this._shapes.length!==0&&(this._shapes.forEach(e=>{e.dispose()}),this._shapes=[])}_updateAdjustControlPositions(){this._createShapeAdjustControls()}_getScrollInfo(e,t){var n;let r={x:0,y:0};if(!e||!t)return r;let i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_attachAdjustEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,c,l;let u=e.getDrawingSearch();this._activeAdjustInfo=this._getShapeAdjustInfosById(u.unitId,u.subUnitId,u.drawingId,n),this._activeShapeModel=this._sheetsShapeService.getShapeModel(u.unitId,u.subUnitId,u.drawingId);let d=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),{transform:f}=d;if(f){let{left:e,top:t,width:n,height:r}=f;this._baseShapeLeft=e||0,this._baseShapeTop=t||0,this._baseShapeWidth=n||0,this._baseShapeHeight=r||0}let p=!!((a=d.transform)!=null&&a.flipX),m=!!((o=d.transform)!=null&&o.flipY),h=((c=d.transform)==null?void 0:c.angle)||0;this._isStartAdjusting=!0,t.disableObjectsEvent();let g={...((l=this._activeAdjustInfo)==null?void 0:l.currentAdjustValues)??{}};this._adjHandlerPointerMove=t.onPointerMove$.subscribeEvent((e,n)=>{if(!this._isStartAdjusting)return;let{offsetX:r,offsetY:i}=e,a=this._activeAdjustInfo;if(this._activeShapeModel&&a){t.disableObjectsEvent(),t.setCursor(s.CURSOR_TYPE.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),c=r/o+n.x-this._baseShapeLeft,l=i/o+n.y-this._baseShapeTop;if(h!==0){let e=this._baseShapeWidth/2,t=this._baseShapeHeight/2,n=h*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=c-e,o=l-t;c=e+(a*r+o*i),l=t+(-a*i+o*r)}p&&(c=this._baseShapeWidth-c),m&&(l=this._baseShapeHeight-l);let d={x:c,y:l},f=this._activeShapeModel.calcAdjValues(e,d,a,p,m);if(Object.keys(f).length===0)return;for(let[e,t]of Object.entries(f))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseShapeWidth,height:this._baseShapeHeight});let g=this._drawingManagerService.getDrawingByParam({unitId:u.unitId,subUnitId:u.subUnitId,drawingId:u.drawingId});g&&(this._sheetDrawingShapeRenderController.renderDrawingShape(g,t),this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(u.unitId,u.subUnitId,u.drawingId),this._updateAdjustControlPositions())}n.stopPropagation()}),this._adjHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{this._adjHandlerPointerMove.unsubscribe(),this._adjHandlerPointerUp.unsubscribe(),t.resetCursor();let r=this._activeAdjustInfo;if(r){let e=u.unitId,t=u.subUnitId,n=u.drawingId,a={};for(let e of Object.keys(r.currentAdjustValues)){var i;let t=(i=this._activeShapeModel)==null?void 0:i.getAdjustValueByName(e);t!==void 0&&(a[e]=t)}Object.keys(a).length>0&&C(this._commandService,e,t,n,{oldShapeData:{adjustValues:g}},{adjustValues:a})}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(()=>{this._isShouldShowDrawingShapeAdjust})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;this._createShapeAdjustControls(),t!==null&&t.size===1&&t.values().next().value instanceof D&&this.setShouldShowAdjust(!0)})),this.disposeWithMe(t.changing$.subscribe(()=>{this._isShouldShowDrawingShapeAdjust&&this._clearShapeAdjustControls()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isShouldShowDrawingShapeAdjust&&(this.setShouldShowAdjust(!1),this._createShapeAdjustControls())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{this._unitId&&this._subUnitId&&this._activeShapeId&&this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId})&&(this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(this._unitId,this._subUnitId,this._activeShapeId),this._updateAdjustControlPositions())}))}))}_registerDrawingFocusChangeHandler(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==a.UpdateSheetsShapeDataMutation.id)return;let{unitId:t,subUnitId:n,shapeId:r}=e.params;t===this._unitId&&n===this._subUnitId&&r===this._activeShapeId&&this.refreshAdjustControls()})),this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let t=e[0];if(t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===o.UniverInstanceType.UNIVER_SHEET){this._activeShapeId=t.drawingId;let{unitId:e,subUnitId:n}=t;this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(e,n,this._activeShapeId),this._unitId=e,this._subUnitId=n,this._clearShapeAdjustControls(),this._createShapeAdjustControls();return}}this._activeShapeId=null,this._activeShapeAdjustPointList=void 0,this._unitId=null,this._subUnitId=null,this._clearShapeAdjustControls()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){var t;let n=e[0];((t=this._drawingManagerService.getDrawingByParam(n))==null?void 0:t.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE&&this._updateShapeAdjustControls(!0)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e)this._activeShapeId===t.drawingId&&(this._activeShapeId=null,this._activeShapeAdjustPointList=void 0,this._unitId=null,this._subUnitId=null,this._clearShapeAdjustControls())}))}};M=A([k(0,d.IDrawingManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,(0,o.Inject)(s.IRenderManagerService)),k(3,(0,o.Inject)(j)),k(4,o.IUniverInstanceService),k(5,o.ICommandService)],M);let re={id:`drawing.operation.set-drawing-active`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(d.IDrawingManagerService),r=e.get(s.IRenderManagerService),i=e.get(M);if(t==null)return!0;if(t.length>0){var a;let e=(a=r.getRenderUnitById(t[0].unitId))==null?void 0:a.scene;if(e){let{unitId:n,subUnitId:i,drawingId:a}=t[0],s=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(s);if(c){var o;(o=r.getRenderUnitById(t[0].unitId))==null||(o=o.scene.getTransformer())==null||o.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},N={type:o.CommandType.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var n,d;let f=(0,c.getSheetCommandTarget)(e.get(o.IUniverInstanceService));if(!f)return!1;let{unitId:p,subUnitId:m,worksheet:h}=f,g=h.getConfig(),_=g.type??o.SheetTypes.GRID;if(_!==o.SheetTypes.GRID&&_!==o.SheetTypes.CHART)return!1;let v=e.get(o.IPermissionService);if(((n=v.getPermissionPoint(new c.WorkbookEditablePermission(p).id))==null?void 0:n.value)!==!0||((d=v.getPermissionPoint(new c.WorksheetEditPermission(p,m).id))==null?void 0:d.value)!==!0)return!1;let y=e.get(o.ICommandService),{value:b,enhanceParams:x}=t,S={unitId:p,subUnitId:m,shapeType:b,shapeId:(0,o.generateRandomId)()};if(_===o.SheetTypes.CHART){let t=e.get(s.IRenderManagerService).getRenderUnitById(p),n=t==null?void 0:t.components.get(u.SHEET_VIEW_KEY.CHART_PAGE);if(!t||!n||![n.left,n.top,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return!1;let r={row:0,column:0,rowOffset:0,columnOffset:0},i=(0,l.transformDrawingsToChartSheet)([{unitId:p,subUnitId:m,drawingId:S.shapeId,drawingType:o.DrawingTypeEnum.DRAWING_SHAPE,transform:{left:0,top:0,width:a.DEFAULT_SHAPE_WIDTH,height:a.DEFAULT_SHAPE_HEIGHT},axisAlignSheetTransform:{from:r,to:r}}],{left:n.left,top:n.top,width:n.width,height:n.height},g.rightToLeft===o.BooleanNumber.TRUE);if(!(i!=null&&i.length))return!1;let c=i[0].transform;S.position={x:c.left,y:c.top},S.width=c.width,S.height=c.height}else{let t=e.get(c.SheetsSelectionsService).getCurrentLastSelection();if(!t)return!1;S.range=t.range}if(x){let{startArrow:t,endArrow:n,horizontal:a,vertical:s}=x,c=(0,r.isConnectorShape)(b),l=b===r.ShapeTypeEnum.Rect;if(c&&(t||n)&&(S.shapeData={ln:{startArrow:t?{type:r.ShapeArrowTypeEnum.Arrow,size:r.ShapeArrowSizeEnum.Medium}:void 0,endArrow:n?{type:r.ShapeArrowTypeEnum.Arrow,size:r.ShapeArrowSizeEnum.Large}:void 0}}),l&&(a||s)){let t=e.get(o.ThemeService);S.shapeData=(0,i.createShapeTextBoxShapeData)({fill:{fillType:r.ShapeFillEnum.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!a,stroke:{lineStrokeType:r.ShapeLineTypeEnum.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let C=y.syncExecuteCommand(a.InsertShapeCommand.id,S);return C&&await y.executeCommand(re.id,[{unitId:p,subUnitId:m,drawingId:S.shapeId}]),C}},P=`sheet.shape.edit.panel`,F=`sheet.shape.object-list.panel`,ie=`sheet.shape.floating-toolbar`,ae=`sheets-shape-ui.ribbon.shape-format`,I=(0,o.createInternalEditorID)(`SHAPE_TEXT`),oe=`sheet.shape.text.float-menu`,se={id:`sheet.operation.open-shape-object-list-panel`,type:o.CommandType.COMMAND,handler:(e,t)=>{let r=e.get(n.ISidebarService),i=e.get(o.LocaleService),a=e.get(o.IUniverInstanceService),s=e.get(o.ICommandService);return(0,c.getSheetCommandTarget)(a)?(t==null?void 0:t.value)===`close`?(r.close(F),!0):(r.open({id:F,header:{title:i.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:F},onClose:()=>{s.syncExecuteCommand(d.SetDrawingSelectedOperation.id,[])},width:360}),!0):!1}},L={type:o.CommandType.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function ce(e){let t=e.get(d.IDrawingManagerService).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return null;let r=e.get(a.SheetsShapeService),i=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),s=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return i===void 0||!s?null:{drawing:n,shapeData:s,shapeType:i}}let le={id:`sheet.operation.apply-shape-quick-style`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=ce(e),r=(0,i.getShapeQuickStylePreset)((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!r||r.type!==(0,i.getShapeQuickStyleType)(n.shapeData))return!1;let a=(0,i.applyQuickStyleToShapeData)(n.shapeData,r);if(!a)return!1;let{drawing:s}=n;return e.get(o.ICommandService).executeCommand(S.id,{unitId:s.unitId,subUnitId:s.subUnitId,shapeId:s.drawingId,shapeData:a,oldShapeJSON:{oldShapeData:n.shapeData}})}},ue={id:`sheet.operation.update-shape-type`,type:o.CommandType.OPERATION,handler:(e,t)=>{let n=ce(e),a=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!n||!a||(0,r.isConnectorShape)(n.shapeType)||(0,r.isConnectorShape)(a))return!1;let s=(0,i.cloneShapeDataForType)(n.shapeData,a);if(!s)return!1;let{drawing:c}=n;return e.get(o.ICommandService).executeCommand(S.id,{unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.drawingId,shapeType:a,shapeData:s,replaceShapeData:!0,oldShapeJSON:{oldShapeType:n.shapeType,oldShapeData:n.shapeData}})}},R=class extends o.Disposable{constructor(e,t){super(),this._clipService=e,this._drawingManagerService=t,this._registerImageShapeClipDelegate(),this._clipService.setCanUseShapeClip(!0),this.disposeWithMe({dispose:()=>this._clipService.setCanUseShapeClip(!1)})}_registerImageShapeClipDelegate(){let e=this._clipService,t=/* @__PURE__ */ new Map,n=e.registerClipDelegate((e,n,i,a,o)=>{let s=n;if(s===r.ShapeTypeEnum.None||n===`custom`)return!1;try{let c=t.get(n);return c||(c=new r.ShapeModel(s,`clip-${n}`),t.set(n,c)),c.clearAdjustValue(),o&&Object.keys(o).length>0&&c.setShapeData({adjustValues:o},!0),c.updateContext({width:i,height:a}),c.buildClipPath(e,{left:0,top:0,width:i,height:a})}catch{return!1}});this.disposeWithMe(n),this.disposeWithMe({dispose:()=>t.clear()})}clipByShape(e,t,n,r,i){let a=this._drawingManagerService.getDrawingData(e,t);if(!a[n])return;let o={...a[n],prstGeom:r,adjustValues:i};this._drawingManagerService.featurePluginUpdateNotification([o])}};R=A([k(0,(0,o.Inject)(p.DrawingImageClipService)),k(1,(0,o.Inject)(d.IDrawingManagerService))],R);let de=`sheet.shape.picker.component`,fe=`sheet.image-clip.shape-picker.component`;function pe({onShapeClick:e,excludeGroups:n}){return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerPanel,{excludeGroups:n,onShapeClick:e,scrollContainer:`parent`})}function me(){let e=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(R);return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[t.ShapeGroupEnum.Line],onShapeClick:t=>{let n=e.getFocusDrawings().find(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE);if(!n)return;let{unitId:i,subUnitId:a,drawingId:s}=n;r.clipByShape(i,a,s,t.type)}})}function he(){let e=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(R);return/* @__PURE__ */ (0,h.jsx)(t.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[t.ShapeGroupEnum.Line],DropdownComponent:m.MobileDropdown,onShapeClick:t=>{let n=e.getFocusDrawings().find(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE);if(!n)return;let{unitId:i,subUnitId:a,drawingId:s}=n;r.clipByShape(i,a,s,t.type)}})}function ge(){let e=(0,n.useDependency)(n.ComponentManager),t=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(o.IUniverInstanceService),i=t.getFocusDrawings()[0],a=i?r.getUnitType(i.unitId):void 0,s=a===o.UniverInstanceType.UNIVER_DOC?`doc.image-clip.shape-picker.component`:a===o.UniverInstanceType.UNIVER_SHEET?fe:void 0,c=s?e.get(s):void 0;return c?/* @__PURE__ */ (0,h.jsx)(c,{}):null}function _e(){let e=(0,n.useDependency)(o.ICommandService);return/* @__PURE__ */ (0,h.jsx)(pe,{onShapeClick:t=>{e.executeCommand(N.id,{value:t.type,enhanceParams:{endArrow:t.endArrow,startArrow:t.startArrow,horizontal:t.horizontal,vertical:t.vertical}})}})}function ve(){return/* @__PURE__ */ (0,h.jsx)(_e,{})}function ye(e){return(0,u.deriveStateFromActiveSheet$)(e.get(o.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??o.SheetTypes.GRID;if(r===o.SheetTypes.GRID)return(0,u.getCurrentRangeDisable$)(e);if(r!==o.SheetTypes.CHART)return(0,f.of)(!0);let i=e.get(o.IPermissionService),a=[new c.WorkbookEditablePermission(t.getUnitId()).id,new c.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,f.startWith)(null),(0,f.map)(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,f.distinctUntilChanged)())})}function be(e){let t=e.get(o.IUniverInstanceService);return{id:N.id,type:n.MenuItemType.SELECTOR,selections:[{label:{name:de,hoverable:!1,selectable:!1,props:{id:N.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:(0,u.deriveStateFromActiveSheet$)(t,!1,()=>new f.Observable(e=>{e.next(!1)})),hidden$:(0,n.getMenuHiddenObservable)(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:ye(e)}}function xe(e){return(0,u.deriveStateFromActiveSheet$)(e.get(o.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??o.SheetTypes.GRID;if(r===o.SheetTypes.GRID)return(0,u.getCurrentRangeDisable$)(e);if(r!==o.SheetTypes.CHART)return(0,f.of)(!0);let i=e.get(o.IPermissionService),a=[new c.WorkbookEditablePermission(t.getUnitId()).id,new c.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,f.startWith)(null),(0,f.map)(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,f.distinctUntilChanged)())})}function Se(e){let t=e.get(n.ISidebarService);return{id:se.id,type:n.MenuItemType.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:(0,f.defer)(()=>t.sidebarOptions$.pipe((0,f.startWith)(t.options),(0,f.map)(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),(0,f.distinctUntilChanged)())),hidden$:(0,n.getMenuHiddenObservable)(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:xe(e)}}let Ce=`sheet.menu.shape.flip-horizontal`,we=`sheet.menu.shape.flip-vertical`;function Te(e){let t=e.get(d.IDrawingManagerService).getFocusDrawings();return t.length===1&&t[0].drawingType===o.DrawingTypeEnum.DRAWING_SHAPE?t[0]:null}function Ee(e){let t=e.get(d.IDrawingManagerService);return t.focus$.pipe((0,f.startWith)(t.getFocusDrawings()),(0,f.map)(e=>e.length!==1||e[0].drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE))}function De(e){return{id:Ce,commandId:a.ToggleSheetsShapeFlipCommand.id,type:n.MenuItemType.BUTTON,title:`sheets-shape-ui.flipHorizontal`,tooltip:`sheets-shape-ui.flipHorizontal`,icon:`FlipHorizontalIcon`,hidden$:Ee(e),params:()=>{let t=Te(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipH:!0}:void 0}}}function Oe(e){return{id:we,commandId:a.ToggleSheetsShapeFlipCommand.id,type:n.MenuItemType.BUTTON,title:`sheets-shape-ui.flipVertical`,tooltip:`sheets-shape-ui.flipVertical`,icon:`FlipVerticalIcon`,hidden$:Ee(e),params:()=>{let t=Te(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipV:!0}:void 0}}}let z=class extends o.Disposable{constructor(e){super(),this._permissionService=e,E(this,`_editingParams$`,new f.BehaviorSubject(null)),E(this,`editingParams$`,this._editingParams$.asObservable()),E(this,`_onSavingEditorData$`,new f.BehaviorSubject(!1)),E(this,`onSavingEditorData$`,this._onSavingEditorData$.asObservable()),E(this,`_completionFrame`,void 0),this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(()=>{let e=this.getEditing();e!=null&&e.visible&&!this._canEdit(e)&&this.setEditing(null)}))}dispose(){this._clearCompletionFrame(),this._editingParams$.next(null),this._editingParams$.complete(),this._onSavingEditorData$.next(!1),this._onSavingEditorData$.complete(),super.dispose()}setEditing(e){(e==null||!e.visible||this._canEdit(e))&&(this._clearCompletionFrame(),this._editingParams$.next(e),(e==null||e.visible&&this._onSavingEditorData$.getValue())&&this._onSavingEditorData$.next(!1))}setOnSavingEditorData(e){this._onSavingEditorData$.next(e)}getEditing(){return this._editingParams$.getValue()}_canEdit(e){let t=this._permissionService.getPermissionPoint(new c.WorkbookEditablePermission(e.unitId).id),n=this._permissionService.getPermissionPoint(new c.WorksheetEditPermission(e.unitId,e.subUnitId).id);return((t==null?void 0:t.value)??!0)&&((n==null?void 0:n.value)??!0)}completeEditing(e){let t=this.getEditing();t&&this._completionFrame===void 0&&(this.setOnSavingEditorData(!0),this._completionFrame=requestAnimationFrame(()=>{this._completionFrame=void 0,this.getEditing()===t&&this.setEditing(null)}))}_clearCompletionFrame(){this._completionFrame!==void 0&&(cancelAnimationFrame(this._completionFrame),this._completionFrame=void 0)}cancelEditing(){this.getEditing()&&this.setEditing(null)}};z=A([k(0,o.IPermissionService)],z);let ke=`sheets-shape-ui.shape-format.quick-style-gallery`,Ae=`sheets-shape-ui.shape-format.style-ribbon-control`,je=`sheets-shape-ui.shape-format.text-ribbon-control`,Me=`sheets-shape-ui.shape-format.formula-ribbon-control`;function Ne(){let e=(0,n.useDependency)(o.ICommandService),t=(0,n.useDependency)(d.IDrawingManagerService),r=(0,n.useDependency)(a.SheetsShapeService),i=()=>{var e;let n=t.getFocusDrawings();if(n.length!==1||((e=n[0])==null?void 0:e.drawingType)!==o.DrawingTypeEnum.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:a,drawingId:s}=n[0],c=r.getShapeTypeById(i,a,s),l=r.getShapeDataById(i,a,s);return c===void 0||!l?null:{unitId:i,subUnitId:a,drawingId:s,shapeType:c,shapeData:l}},s=(0,n.useObservable)(()=>new f.Observable(n=>{let r=()=>n.next(i()),o=t.focus$.subscribe(r),s=e.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&r()});return r(),()=>{o.unsubscribe(),s.dispose()}}),i(),!1,[e,t,r]);return{selection:s,updateShapeData:t=>{s&&C(e,s.unitId,s.subUnitId,s.drawingId,{oldShapeData:s.shapeData},t)}}}function Pe(){let{selection:e,updateShapeData:n}=Ne();return e?/* @__PURE__ */ (0,h.jsx)(t.ShapeStyleRibbonControl,{shapeData:e.shapeData,shapeType:e.shapeType,onUpdateShapeData:n}):null}function Fe(){let e=(0,n.useDependency)(o.ICommandService),r=(0,n.useDependency)(o.LocaleService),{selection:a}=Ne();return a?/* @__PURE__ */ (0,h.jsx)(t.ShapeQuickStyleGallery,{type:(0,i.getShapeQuickStyleType)(a.shapeData),ariaLabel:r.t(`sheets-shape-ui.quickStyles`),activePresetId:(0,i.resolveActiveShapeQuickStylePresetId)(a.shapeData),onSelect:t=>e.executeCommand(le.id,{presetId:t})}):null}function Ie(){let{selection:e,updateShapeData:r}=Ne(),i=(0,n.useDependency)(z),a=(0,n.useObservable)(i.editingParams$,i.getEditing());if(!e)return null;let o=(0,t.isShapeTextEditingTarget)(a,e);return/* @__PURE__ */ (0,h.jsx)(t.ShapeTextRibbonControl,{editorUnitId:o?I:void 0,fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:e.shapeData,onUpdateShapeData:r})}function Le(){var e;let{selection:n,updateShapeData:r}=Ne(),i=(0,t.useFormulaShapeToolbar)({hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:(n==null?void 0:n.unitId)??``,subUnitId:(n==null?void 0:n.subUnitId)??``,shapeId:(n==null?void 0:n.drawingId)??``,shapeData:n==null?void 0:n.shapeData,registerBinding:!1,showLabels:!0,dropdownSide:`bottom`,onUpdateBinding:e=>r({formulaBinding:e})}),a=((e=i.extensionGroups)==null?void 0:e.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return n!=null&&n.shapeData.formulaBinding?/* @__PURE__ */ (0,h.jsx)(t.ShapeFormulaRibbonControl,{actions:a,panel:i.panel}):null}let Re=`sheets-shape-ui.ribbon.shape-format.style-control`,ze=`sheets-shape-ui.ribbon.shape-format.text-control`,Be=`sheets-shape-ui.ribbon.shape-format.formula-control`,Ve=`sheets-shape-ui.ribbon.shape-format.arrange-forward`,He=`sheets-shape-ui.ribbon.shape-format.arrange-backward`,Ue=`sheets-shape-ui.ribbon.shape-format.arrange-front`,We=`sheets-shape-ui.ribbon.shape-format.arrange-back`;function Ge(e){let t=e.get(o.ICommandService),n=e.get(d.IDrawingManagerService),r=e.get(a.SheetsShapeService);return new f.Observable(o=>{let s=()=>{let t=B(e),n=t?r.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;o.next(n?(0,i.resolveActiveShapeQuickStylePresetId)(n)??``:``)},c=n.focus$.subscribe(s),l=t.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function B(e){var t;let n=e.get(d.IDrawingManagerService).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE?n[0]:null}function Ke(e,t=!1){let n=e.get(o.ICommandService),r=e.get(d.IDrawingManagerService),i=e.get(a.SheetsShapeService);return new f.Observable(o=>{let s=()=>{let n=B(e);if(!n){o.next(!0);return}let r=i.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);o.next(!r||t&&r.formulaBinding==null)},c=r.focus$.subscribe(s),l=n.onCommandExecuted(e=>{e.id===a.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function qe(e){let t=e.get(d.IDrawingManagerService),n=e.get(a.SheetsShapeService);return t.focus$.pipe((0,f.startWith)(t.getFocusDrawings()),(0,f.map)(()=>{let t=B(e),i=t?n.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return i===void 0||(0,r.isConnectorShape)(i)}))}function Je(e){return{id:le.id,type:n.MenuItemType.SELECTOR,icon:`PaintIcon`,title:`shape-editor-ui.toolbar.quickStyles`,tooltip:`shape-editor-ui.toolbar.quickStyles`,selections:[{label:{name:ke,hoverable:!1,selectable:!1}}],value$:Ge(e),hidden$:Ke(e)}}function Ye(e){return{id:ue.id,type:n.MenuItemType.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:t.SHAPE_CHANGE_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],hidden$:qe(e)}}function Xe(e,t,r=!1){return i=>({id:e,type:n.MenuItemType.BUTTON,label:{name:t,hoverable:!1,selectable:!1},hidden$:Ke(i,r)})}let Ze=Xe(Re,Ae),Qe=Xe(ze,je),$e=Xe(Be,Me,!0);function et(e,t,r,i){return a=>({id:e,commandId:l.SetDrawingArrangeCommand.id,type:n.MenuItemType.BUTTON,icon:r,title:i,tooltip:i,hidden$:Ke(a),params:()=>{let e=B(a);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:t}:void 0}})}let tt=et(Ve,o.ArrangeTypeEnum.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),nt=et(He,o.ArrangeTypeEnum.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),rt=et(Ue,o.ArrangeTypeEnum.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),it=et(We,o.ArrangeTypeEnum.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function at(e){let t=e.get(n.ISidebarService);return{activated$:(0,f.defer)(()=>t.sidebarOptions$.pipe((0,f.startWith)(t.options),(0,f.map)(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),(0,f.distinctUntilChanged)())),id:L.id,type:n.MenuItemType.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:Ke(e),params:()=>{let t=B(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}let ot={[n.MenuManagerPosition.RIBBON]:{[ae]:{order:100,title:`sheets-shape-ui.formatShape`,contextual:!0,"sheets-shape-ui.ribbon.shape-format.quick-styles":{order:0,[le.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:Je},[ue.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Ye}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[Re]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Ze}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[ze]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Qe}},"sheets-shape-ui.ribbon.shape-format.arrange":{order:3,[Ce]:{order:0,gridLayout:{row:1,column:1},menuItemFactory:De},[we]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:Oe},[Ve]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:tt},[He]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:nt},[Ue]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:rt},[We]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:it}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[Be]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:$e}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[L.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:at},[t.ToggleShapeFloatingToolbarOperation.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:t.ShapeFloatingToolbarToggleFactory}}}}},st={[n.RibbonInsertGroup.MEDIA]:{[N.id]:{order:3,menuItemFactory:be}}},ct={...st,[n.RibbonInsertGroup.OTHERS]:{[se.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Se}},[n.ContextMenuPosition.DRAWING]:{[n.ContextMenuGroup.OTHERS]:{[Ce]:{order:4,menuItemFactory:De},[we]:{order:5,menuItemFactory:Oe}}}};var lt=`@univerjs-pro/sheets-shape-ui`,ut=`1.6.0`;let dt={id:`sheet.operation.open-mobile-shape-editor`,type:o.CommandType.OPERATION,handler(e,n){return n?(e.get(t.MobileShapeEditorService).open(n.mode,{hostType:o.UniverInstanceType.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},ft=`sheets-shape-ui.config`,pt={},mt=class extends o.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._imageShapeClipController=i,E(this,`_activeImageId`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_activeAdjustPointList`,void 0),E(this,`_shapes`,[]),E(this,`_baseLeft`,0),E(this,`_baseTop`,0),E(this,`_baseWidth`,0),E(this,`_baseHeight`,0),E(this,`_isStartAdjusting`,!1),E(this,`_activeAdjustInfo`,void 0),E(this,`_activeShapeModel`,void 0),E(this,`_adjHandlerPointerMove`,void 0),E(this,`_adjHandlerPointerUp`,void 0),E(this,`_isImagePointerDown`,!1),this._registerFocusChangeHandler(),this._registerMoveHandler()}clearAdjustControls(){this._clearControls()}refreshAdjustControls(){this._clearControls(),this._createControls(!0)}_getOrCreateShapeModel(e,t,n,i){let a=e;if(a!==r.ShapeTypeEnum.None&&e!==`custom`)try{let o=new r.ShapeModel(a,`clip-adj-${e}`);return i&&o.setShapeData({adjustValues:i},!0),o.updateContext({width:t,height:n}),o}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),o=i.getObject(a);if(o instanceof s.Image){let e=o.prstGeom;if(e)return{prstGeom:e,adjustValues:o.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId);if(!r)return;let{transform:i}=r;if(!i)return;let{left:a,top:o,width:s,height:c,flipX:l,flipY:d,angle:f=0}=i;if(a===void 0||o===void 0)return;let p=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(!p)return;if(e){let e=this._getOrCreateShapeModel(p.prstGeom,s||0,c||0,p.adjustValues);if(!e)return;this._activeAdjustPointList=e.getDrawingPoints()}let m=this._activeAdjustPointList;if(m&&m.length!==0)for(let e=0;e<m.length;e++){let t=m[e],r=t.x,i=t.y;if(l&&(r=(s||0)-r),d&&(i=(c||0)-i),f!==0){let e=(s||0)/2,t=(c||0)/2,n=f*Math.PI/180,a=Math.cos(n),o=Math.sin(n),l=r-e,u=i-t;r=e+(l*a-u*o),i=t+(l*o+u*a)}let u={x:r,y:i,adjName:t.adjName};this._addControl(n,u,u.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,n,i,a,o,c){if(!this._activeImageId)return;let l=`image-clip-adjust-point-${this._activeImageId}-${n}`,u=e.getObjectIncludeInGroup(l);if(u){u.transformByState({left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize});return}let d=new O(l,{left:t.x+i-r.ShapeDefaultConfig.adjHandleSize,top:t.y+a-r.ShapeDefaultConfig.adjHandleSize,adjName:n,shapeId:this._activeImageId,unitId:o,subUnitId:c,width:r.ShapeDefaultConfig.adjHandleSize+8,height:r.ShapeDefaultConfig.adjHandleSize+8,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._shapes.push(d),this._attachAdjustEvent(d,e,n),e.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+1)}_clearControls(){this._shapes.length!==0&&(this._shapes.forEach(e=>e.dispose()),this._shapes=[])}_getScrollInfo(e,t){var n;let r={x:0,y:0},i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_attachAdjustEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,c;let{unitId:l,subUnitId:u,drawingId:d}=e.getDrawingSearch(),f=this._getImageDrawingInfo(l,u,d);if(!(f!=null&&f.transform))return;let{left:p,top:m,width:h,height:g}=f.transform;this._baseLeft=p||0,this._baseTop=m||0,this._baseWidth=h||0,this._baseHeight=g||0;let _=!!((a=f.transform)!=null&&a.flipX),v=!!((o=f.transform)!=null&&o.flipY),y=((c=f.transform)==null?void 0:c.angle)||0,b=this._getImagePrstGeom(l,u,d);if(!b)return;let x=this._getOrCreateShapeModel(b.prstGeom,this._baseWidth,this._baseHeight,b.adjustValues);if(!x||(this._activeShapeModel=x,this._activeAdjustInfo=x.getAdjustInfoByName(n),!this._activeAdjustInfo))return;this._isStartAdjusting=!0,t.disableObjectsEvent();let S=b.prstGeom;this._adjHandlerPointerMove=t.onPointerMove$.subscribeEvent((e,n)=>{if(!this._isStartAdjusting)return;let{offsetX:r,offsetY:i}=e,a=this._activeAdjustInfo;if(!this._activeShapeModel||!a)return;t.disableObjectsEvent(),t.setCursor(s.CURSOR_TYPE.CROSSHAIR);let o={left:0,top:0,width:this._baseWidth,height:this._baseHeight},c=this._getScrollInfo(l,u),f=this._getZoomRatio(l,u),p=r/f+c.x-this._baseLeft,m=i/f+c.y-this._baseTop;if(y!==0){let e=this._baseWidth/2,t=this._baseHeight/2,n=y*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=p-e,o=m-t;p=e+(a*r+o*i),m=t+(-a*i+o*r)}_&&(p=this._baseWidth-p),v&&(m=this._baseHeight-m);let h=this._activeShapeModel.calcAdjValues(o,{x:p,y:m},a,_,v);if(Object.keys(h).length!==0){for(let[e,t]of Object.entries(h))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseWidth,height:this._baseHeight}),this._updateImageAdjValues(l,u,d,h),this._activeAdjustPointList=this._activeShapeModel.getDrawingPoints(),this._createControls(),n.stopPropagation()}}),this._adjHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{if(this._adjHandlerPointerMove.unsubscribe(),this._adjHandlerPointerUp.unsubscribe(),t.resetCursor(),this._activeShapeModel){let e=this._activeShapeModel.getAdjustNames(),t={};for(let n of e){let e=this._activeShapeModel.getAdjustValueByName(n);e!==void 0&&(t[n]=e)}this._imageShapeClipController.clipByShape(l,u,d,S,t)}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_updateImageAdjValues(e,t,n,r){let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i,o=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),c=a.getObject(o);if(c instanceof s.Image){let e=c.prstGeomAdjValues??{};c.setPrstGeomAdjValues({...e,...r}),c.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(()=>{this._isImagePointerDown&&this._clearControls()})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;if(this._createControls(),t!==null&&t.size===1){let e=t.values().next().value;e instanceof s.Image&&e.prstGeom&&(this._isImagePointerDown=!0)}})),this.disposeWithMe(t.changing$.subscribe(()=>{this._isImagePointerDown&&this._clearControls()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isImagePointerDown&&(this._isImagePointerDown=!1,this._createControls())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{if(this._unitId&&this._subUnitId&&this._activeImageId){let n=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(n){var e,t;let r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId),i=(r==null||(e=r.transform)==null?void 0:e.width)||0,a=(r==null||(t=r.transform)==null?void 0:t.height)||0,o=this._getOrCreateShapeModel(n.prstGeom,i,a,n.adjustValues);o&&(this._activeAdjustPointList=o.getDrawingPoints(),this._clearControls(),this._createControls(!0))}}}))}))}_registerFocusChangeHandler(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let r=e[0];if(r.drawingType===o.DrawingTypeEnum.DRAWING_IMAGE){let{unitId:e,subUnitId:i,drawingId:a}=r,o=this._getImagePrstGeom(e,i,a);if(o){var t,n;this._activeImageId=a,this._unitId=e,this._subUnitId=i;let r=this._getImageDrawingInfo(e,i,a),s=(r==null||(t=r.transform)==null?void 0:t.width)||0,c=(r==null||(n=r.transform)==null?void 0:n.height)||0,l=this._getOrCreateShapeModel(o.prstGeom,s,c,o.adjustValues);l&&(this._activeAdjustPointList=l.getDrawingPoints()),this._clearControls(),this._createControls(!0)}else this._resetState()}else this._resetState()}else this._resetState()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){let t=e[0],n=this._drawingManagerService.getDrawingByParam(t);(n==null?void 0:n.drawingType)===o.DrawingTypeEnum.DRAWING_IMAGE&&this._activeImageId===t.drawingId&&(this._clearControls(),this._createControls(!0))}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e)this._activeImageId===t.drawingId&&this._resetState()}))}_resetState(){this._activeImageId=null,this._unitId=null,this._subUnitId=null,this._activeAdjustPointList=void 0,this._clearControls()}};mt=A([k(1,d.IDrawingManagerService),k(2,(0,o.Inject)(s.IRenderManagerService)),k(3,o.IUniverInstanceService),k(4,(0,o.Inject)(R))],mt);function V({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,b.useId)()}`,u=(0,b.useRef)(null);return(0,b.useImperativeHandle)(e,()=>u.current),(0,b.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return vt(u.current)},[n,r]),ht(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function ht(e,t,n,r,i){return(0,b.createElement)(e.tag,{key:t,...gt(e,n,i),...r},(_t(e,n).children||[]).map((r,a)=>ht(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function gt(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function _t(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function vt(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:yt(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=e.element.style.getPropertyValue(`stroke-width`)})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(bt(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function yt(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function bt(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}V.displayName=`UniverIcon`;let xt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334C15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334C2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045ZM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334C3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999C15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999C2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544ZM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999C3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421C6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641C9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421C11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946C8.64077 14.6502 8.70566 14.6923 8.77482 14.7209C8.84557 14.7502 8.92314 14.7664 9.00449 14.7664C9.08585 14.7664 9.16342 14.7502 9.23416 14.7209C9.30332 14.6923 9.36821 14.6502 9.42482 14.5946`}}]},St=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`bottom-icon`,ref:t,icon:xt}))});St.displayName=`BottomIcon`;let Ct={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.6 3.3L6.2 8L2.6 12.7V3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.4 3.3L9.8 8L13.4 12.7V3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 2.2V3.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 6.2V7.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 10.2V11.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 14V14.2`,strokeLinecap:`round`,strokeWidth:1.2}}]},wt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`flip-horizontal-icon`,ref:t,icon:Ct}))});wt.displayName=`FlipHorizontalIcon`;let Tt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.3 2.6L8 6.2L12.7 2.6H3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.3 13.4L8 9.8L12.7 13.4H3.3Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.2 8H3.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M6.2 8H7.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M10.2 8H11.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M14 8H14.2`,strokeLinecap:`round`,strokeWidth:1.2}}]},Et=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`flip-vertical-icon`,ref:t,icon:Tt}))});Et.displayName=`FlipVerticalIcon`;let Dt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`rect`,attrs:{width:12.2,height:2.2,x:1.9,y:1.9,rx:.7}},{tag:`path`,attrs:{d:`M8 6.1v7.7m-2.6-2.6L8 13.8l2.6-2.6`}}]}]},Ot=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`move-down-icon`,ref:t,icon:Dt}))});Ot.displayName=`MoveDownIcon`;let kt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z`}}]},At=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`move-up-icon`,ref:t,icon:kt}))});At.displayName=`MoveUpIcon`;let jt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 4.75 8 1.8l6 2.95L8 7.7 2 4.75Z`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}},{tag:`path`,attrs:{stroke:`currentColor`,d:`m2 7.75 6 2.95 6-2.95M2 10.75l6 2.95 6-2.95`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.3}}]},Mt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`object-layers-icon`,ref:t,icon:jt}))});Mt.displayName=`ObjectLayersIcon`;let Nt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.5 7V4.29412C13.5 3.5794 12.8679 3 12 3H2.57143C1.70356 3 1.5 3.5794 1.5 4.29412V7V10C1.5 10.7147 1.70356 11 2.57143 11H7.71429`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M4.2 5.5H10.5`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M4.2 8.3H6.8`,strokeLinecap:`round`,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M11.5565 8H12.4435L12.913 8.78261L13.8 8.57391L14.4261 9.2L14.2174 10.087L15 10.5565V11.4435L14.2174 11.913L14.4261 12.8L13.8 13.4261L12.913 13.2174L12.4435 14H11.5565L11.087 13.2174L10.2 13.4261L9.57391 12.8L9.78261 11.913L9 11.4435V10.5565L9.78261 10.087L9.57391 9.2L10.2 8.57391L11.087 8.78261L11.5565 8Z`,strokeLinejoin:`round`}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M12.05 12.1C12.6299 12.1 13.1 11.6299 13.1 11.05C13.1 10.4701 12.6299 10 12.05 10C11.4701 10 11 10.4701 11 11.05C11 11.6299 11.4701 12.1 12.05 12.1Z`}}]},Pt=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`shape-format-setting-icon`,ref:t,icon:Nt}))});Pt.displayName=`ShapeFormatSettingIcon`;let Ft={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9C15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9ZM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9C2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9C13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665C15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665ZM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665C2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665C13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},It=(0,b.forwardRef)(function(e,t){return(0,b.createElement)(V,Object.assign({},e,{id:`topmost-icon`,ref:t,icon:Ft}))});It.displayName=`TopmostIcon`;function Lt({PanelComponent:e=p.ObjectListPanelBase}){var r;function i(e){return e.trim()||void 0}function a(e,n,r){var i;return((i=e.name)==null?void 0:i.trim())||`${r.t(`drawing-ui.objectListPanel.typeNames.${(0,t.getDrawingTypeNameKey)(e.drawingType)}`)} ${n+1}`}let c=(0,n.useDependency)(o.LocaleService),u={title:c.t(`drawing-ui.objectListPanel.title`),empty:c.t(`drawing-ui.objectListPanel.empty`),showAll:c.t(`drawing-ui.objectListPanel.showAll`),hideAll:c.t(`drawing-ui.objectListPanel.hideAll`),lockAll:c.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:c.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:c.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:c.t(`drawing-ui.objectListPanel.moveBackward`),close:c.t(`drawing-ui.objectListPanel.close`),show:c.t(`drawing-ui.objectListPanel.show`),hide:c.t(`drawing-ui.objectListPanel.hide`),lock:c.t(`drawing-ui.objectListPanel.lock`),unlock:c.t(`drawing-ui.objectListPanel.unlock`),lockHint:c.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:c.t(`drawing-ui.objectListPanel.unlockHint`),name:c.t(`drawing-ui.objectListPanel.name`),nameInput:c.t(`drawing-ui.objectListPanel.nameInput`),description:c.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:c.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:c.t(`drawing-ui.objectListPanel.details`),noSelection:c.t(`drawing-ui.objectListPanel.noSelection`),locate:c.t(`drawing-ui.objectListPanel.locate`),expand:c.t(`drawing-ui.objectListPanel.expand`),collapse:c.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:c.t(`drawing-ui.objectListPanel.dragToReorder`),search:c.t(`drawing-ui.objectListPanel.search`),filterAll:c.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:c.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:c.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:c.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:c.t(`drawing-ui.objectListPanel.sectionFloating`)},f=(0,n.useDependency)(o.ICommandService),m=(0,n.useDependency)(o.IUniverInstanceService),g=(0,n.useDependency)(l.ISheetDrawingService),_=(0,n.useDependency)(d.IDrawingManagerService),v=(0,n.useDependency)(s.IRenderManagerService),y=(0,n.useDependency)(n.ILayoutService),[,x]=(0,b.useReducer)(e=>e+1,0),S=m.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_SHEET),C=(S==null?void 0:S.getUnitId())??``,w=(S==null||(r=S.getActiveSheet())==null?void 0:r.getSheetId())??``,T=(0,n.useObservable)(()=>_.focus$,_.getFocusDrawings(),!1,[_]);(0,b.useEffect)(()=>{let e=f.onCommandExecuted(()=>x());return()=>e.dispose()},[f]);let ee=C&&w?g.getDrawingData(C,w):{},te=(C&&w?g.getDrawingOrder(C,w):[]).map(e=>ee[e]).filter(e=>!!e).reverse(),E=te.reduce((e,t)=>(e[(0,p.getObjectListPanelSectionIdForDrawingType)(t.drawingType)]+=1,e),{canvas:0,floating:0}),ne={canvas:0,floating:0},D=te.map((e,t)=>{let n=(0,p.getObjectListPanelSectionIdForDrawingType)(e.drawingType),r=n===p.OBJECT_LIST_FLOATING_SECTION_ID,i=ne[n]++;return{id:e.drawingId,name:a(e,t,c),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:r?u.sectionFloating:u.sectionCanvas,capabilities:r?{arrange:!1,reorder:!1}:void 0,canMoveForward:!r&&i>0,canMoveBackward:!r&&i<E.canvas-1,canReorder:!r}}),O=(0,b.useMemo)(()=>(T??[]).filter(e=>e.unitId===C&&e.subUnitId===w).map(e=>e.drawingId),[T,w,C]),k=O[O.length-1]??null,A=e=>g.getDrawingByParam({unitId:C,subUnitId:w,drawingId:e})??null,j=async e=>{C&&e.length&&await f.executeCommand(l.SetSheetDrawingCommand.id,{unitId:C,drawings:e})},M=async(e,t)=>{A(e)&&await j([{unitId:C,subUnitId:w,drawingId:e,...t}])},re=(e,n)=>{if(!C||!w)return;let r=n?O.includes(e)?O.filter(t=>t!==e):[...O,e]:[e];f.syncExecuteCommand(d.SetDrawingSelectedOperation.id,r.map(e=>({unitId:C,subUnitId:w,drawingId:e})));let i=r[r.length-1];i?((0,t.activateDrawingObject)(v,{unitId:C,subUnitId:w,drawingId:i}),y.focus(C)):(0,t.clearActiveDrawingObjects)(v,C)},N=async(e,t)=>{await j(e.map(e=>A(e)).filter(e=>!!e).filter(e=>e.hidden!==!0!==t).map(e=>({unitId:C,subUnitId:w,drawingId:e.drawingId,hidden:!t})))},P=async(e,t)=>{await j(e.map(e=>A(e)).filter(e=>!!e).filter(e=>e.selectable!==!1!==t).map(e=>({unitId:C,subUnitId:w,drawingId:e.drawingId,selectable:t})))},F=e=>{let t=A(e);if(t)return P([e],t.selectable===!1)},ie=async(e,t)=>{var n;let r=i(t);(((n=A(e))==null?void 0:n.name)??void 0)!==r&&await M(e,{name:r})},ae=async(e,t)=>{var n;let r=i(t);(((n=A(e))==null?void 0:n.description)??void 0)!==r&&await M(e,{description:r})},I=async(e,t)=>{C&&w&&await f.executeCommand(l.SetDrawingArrangeCommand.id,{unitId:C,subUnitId:w,drawingIds:[e],arrangeType:t})};return!C||!w?/* @__PURE__ */ (0,h.jsx)(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:u.title}):/* @__PURE__ */ (0,h.jsx)(e,{labels:u,items:D,selectedIds:O,focusedId:k,showHeader:!1,onSelect:re,onSetVisible:N,onSetSelectable:P,onCommitName:ie,onCommitDescription:ae,onMoveForward:async e=>I(e,o.ArrangeTypeEnum.forward),onMoveBackward:async e=>I(e,o.ArrangeTypeEnum.backward),onToggleSelectable:F})}function Rt(){return/* @__PURE__ */ (0,h.jsx)(Lt,{PanelComponent:p.MobileObjectListPanel})}let zt=class extends o.Disposable{constructor(e,t){super(),this.disposeWithMe(e.register(F,Rt)),this.disposeWithMe(t.register({BottomIcon:St,FlipHorizontalIcon:wt,FlipVerticalIcon:Et,MoveDownIcon:Ot,MoveUpIcon:At,ObjectLayersIcon:Mt,ShapeFormatSettingIcon:Pt,TopmostIcon:It})),this.disposeWithMe(e.register(de,ve)),this.disposeWithMe(e.register(fe,he)),e.hasDefault(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(e.register(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,ge))}};zt=A([k(0,(0,o.Inject)(n.ComponentManager)),k(1,(0,o.Inject)(n.IconManager))],zt);let Bt=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._injector=t,this._shapeTextEditingService=n,this._drawingManagerService=r,this._contextService=i,this._sheetsShapeService=a,E(this,`_lastEditingShapeKey`,null),this._initEvents(),this._initSelection(),this._initEditingParams()}_initEvents(){let{scene:e}=this._context;this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:n,offsetY:i}=t,a=e.pick(s.Vector2.FromArray([n,i]));if(a instanceof D){let e=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);if((0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(a.unitId,a.subUnitId,a.shapeId))||e!=null&&e.getShapeData().formulaBinding)return;this._shapeTextEditingService.setEditing({visible:!0,unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.shapeId,shapeKey:a.oKey})}}))}_initSelection(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let n=e[0],i=this._drawingManagerService.getDrawingByParam(n);if((i==null?void 0:i.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===n.drawingId&&e.visible)return;let i=(0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(n.unitId,n.subUnitId,n.drawingId)),a=!!((t=this._sheetsShapeService.getShapeModel(n.unitId,n.subUnitId,n.drawingId))!=null&&t.getShapeData().formulaBinding);(i||a)&&this._shapeTextEditingService.setEditing(null)}else this._shapeTextEditingService.completeEditing()}else this._shapeTextEditingService.completeEditing()})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{let t=this._shapeTextEditingService.getEditing();t&&e.some(e=>e.drawingId===t.shapeId)&&this._shapeTextEditingService.setEditing(null)}))}_initEditingParams(){this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{let{scene:t}=this._context;if(this._lastEditingShapeKey){let e=t.getObjectIncludeInGroup(this._lastEditingShapeKey);e&&e.setEditing(!1)}if(e){let n=!!e.visible,r=t.getObjectIncludeInGroup(e.shapeKey);r&&(r.setEditing(n),this._lastEditingShapeKey=e.shapeKey),this._contextService.setContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR,!1)}))}};Bt=A([k(1,(0,o.Inject)(o.Injector)),k(2,(0,o.Inject)(z)),k(3,d.IDrawingManagerService),k(4,o.IContextService),k(5,(0,o.Inject)(a.SheetsShapeService))],Bt);var Vt=class extends Bt{_initEvents(){let{scene:e}=this._context,n=this._injector.get(t.MobileShapeEditorService);this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:i,offsetY:a}=t,c=e.pick(s.Vector2.FromArray([i,a]));if(!(c instanceof D))return;let l=this._sheetsShapeService.getShapeModel(c.unitId,c.subUnitId,c.shapeId);(0,r.isConnectorShape)(this._sheetsShapeService.getShapeType(c.unitId,c.subUnitId,c.shapeId))||l!=null&&l.getShapeData().formulaBinding||n.open(`text`,{hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.shapeId})}))}};let Ht={...st},H=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._menuManagerService=e,this._sheetsShapeService=t,this._commandService=n,this._drawingManagerService=r,this._sheetCanvasPopManagerService=i,this._contextService=a,this._renderManagerService=o,this._shapeTextEditingService=s,E(this,`_shapePopupMenuDisposable`,null),this._menuManagerService.mergeMenu(Ht),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,t.bindRenderTransformerLifecycle)(this._renderManagerService,o.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(o.DrawingTypeEnum.DRAWING_SHAPE,(e,t,n,i)=>{let o=this._sheetsShapeService.getShapeTypeById(e,t,n),s=this._sheetsShapeService.getShapeDataById(e,t,n),c=o!==void 0&&!(0,r.isConnectorShape)(o)&&!(s!=null&&s.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:dt.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`style`},disable:!1},...c?[{label:`sheets-shape-ui.editText`,index:1,commandId:dt.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:l.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:n,drawingType:i}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:a.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:a.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new o.DisposableCollection,n=null,r=()=>{if(!n)return;let e=this._drawingManagerService.getFocusDrawings(),t=e.length===0||e.length===1&&e.some(e=>e.unitId===(n==null?void 0:n.unitId)&&e.subUnitId===(n==null?void 0:n.subUnitId)&&e.drawingId===(n==null?void 0:n.drawingId));n=null,t&&(this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null))};return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(t.size>1){r();return}let i=t.values().next().value;if(!i){r();return}let a=this._drawingManagerService.getDrawingOKey(i.oKey);if(!a||a.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE){r();return}let{unitId:s,subUnitId:c,drawingId:l}=a;n={unitId:s,subUnitId:c,drawingId:l},this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!0),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===s&&e.subUnitId===c&&e.drawingId===l)||this._drawingManagerService.focusDrawing([{unitId:s,subUnitId:c,drawingId:l}])})),t.add(e.clearControl$.subscribe(()=>{r()})),(0,o.toDisposable)(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};H=A([k(0,n.IMenuManagerService),k(1,(0,o.Inject)(a.SheetsShapeService)),k(2,o.ICommandService),k(3,d.IDrawingManagerService),k(4,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(5,o.IContextService),k(6,s.IRenderManagerService),k(7,(0,o.Inject)(z))],H);function Ut(e,t,n,r){let i=(0,d.getOrCreateDrawingCopyPlan)(e,t,n),a=[];for(let e of t){let t=i.idMap.get(e.drawingId),n=r(e);t&&n&&a.push({targetShapeId:t,source:n})}return a}let U=class extends o.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._sheetDrawingService=n,this._sheetsShapeService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===c.RemoveSheetCommand.id){let t=(0,c.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,i=this._sheetDrawingService.getDrawingData(n,r),s=Object.values(i).filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(s.length===0)return{redos:[],undos:[]};let l=[],u=[];for(let e=0;e<s.length;e++){let t=s[e],i=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);i&&(l.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),u.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:i.getShapeType(),shapeData:JSON.parse(JSON.stringify(i.getShapeData()))}}))}return{redos:l,undos:u}}if(e.id===c.CopySheetCommand.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:i}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let s=this._sheetDrawingService.getDrawingData(t,n),c=Object.values(s).filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=Ut(i,c,{unitId:t,sourceSubUnitId:n,targetSubUnitId:r},e=>{let t=this._sheetsShapeService.getShapeModel(e.unitId,e.subUnitId,e.drawingId);if(t)return{shapeType:t.getShapeType(),shapeData:JSON.parse(JSON.stringify(t.getShapeData()))}}),u=[],d=[];for(let{targetShapeId:e,source:n}of l)u.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),d.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:u,undos:d}}return{redos:[],undos:[]}}}))}};U=A([k(0,(0,o.Inject)(o.IUniverInstanceService)),k(1,(0,o.Inject)(c.SheetInterceptorService)),k(2,(0,o.Inject)(l.ISheetDrawingService)),k(3,(0,o.Inject)(a.SheetsShapeService))],U);let W=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._currentUniverService=r,this._drawingRenderService=i,this._sheetDrawingShapeRenderController=a,E(this,`_insertingShapeKeys`,/* @__PURE__ */ new Set),this._initialize()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._shapeUpdateListener()}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertShapes(e)}))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(e.id===a.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),o=i==null?void 0:i.scene.getObjectIncludeInGroup(a);o&&(this._sheetDrawingShapeRenderController.refreshShapeFillImage(o),this._sheetDrawingShapeRenderController.refreshFormulaPresentation(o,{unitId:t,subUnitId:n,shapeId:r}),o.makeDirty(!0))}else if(e.id===a.InsertSheetsShapeMutation.id){var n;let{unitId:r,subUnitId:i,shapeId:a}=e.params,o=this._getSceneAndTransformerByDrawingSearch(r);if(o==null)return;let{scene:s}=o,c=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),l=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(u.SheetSkeletonManagerService).getSkeleton(i)))return!1;if(l)return;if(t!=null&&t.fromChangeset){queueMicrotask(()=>{this._disposed||this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])});return}this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])}}))}_shapeUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._drawingManagerService.getDrawingByParam(e);if(i==null)return;let{transform:a,drawingType:s,srcRect:c,prstGeom:l}=i;if(s!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let u=this._getSceneAndTransformerByDrawingSearch(t);if(u==null)return;let{scene:f,transformer:p}=u;if(a==null)return!0;let m=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),h=f.getObjectIncludeInGroup(m);if(h==null)return!0;h.setSrcRect(c),h.setPrstGeom(l)})}))}_insertShapes(e){for(let n of e){var t;let{unitId:e,subUnitId:i,drawingId:a}=n,s=this._getSceneAndTransformerByDrawingSearch(e),c=(t=(0,p.getCurrentUnitInfo)(this._currentUniverService,e))==null?void 0:t.subUnitId;if(s==null||c!==i)continue;let l=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:i,drawingId:a});if(this._insertingShapeKeys.has(l)||s.scene.getObjectIncludeInGroup(l)!=null)continue;let u=this._drawingManagerService.getDrawingByParam(n);if(u==null||u.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let f=u.data||{};if((0,r.isConnectorShape)(f.shapeType)){let e=u.transform;e&&(u.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(l);try{this._sheetDrawingShapeRenderController.renderDrawingShape(u,s.scene)}finally{this._insertingShapeKeys.delete(l)}queueMicrotask(()=>{if(this._disposed)return;let e=(0,d.getDrawingShapeKeyByDrawingSearch)(n);if(!s.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(n);t&&this._drawingManagerService.refreshTransform([t])})}}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}};W=A([k(0,o.ICommandService),k(1,s.IRenderManagerService),k(2,d.IDrawingManagerService),k(3,o.IUniverInstanceService),k(4,(0,o.Inject)(p.DrawingRenderService)),k(5,(0,o.Inject)(j))],W);let Wt={normal:{fill:r.ShapeDefaultConfig.cxnPointFill,stroke:r.ShapeDefaultConfig.cxnPointStroke,strokeWidth:r.ShapeDefaultConfig.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var Gt=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_targetShapeId`,``),E(this,`_cxnIndex`,-1),E(this,`_unitId`,``),E(this,`_subUnitId`,``),E(this,`_isHighlighted`,!1),t&&this.setShapeProps(t)}getConnectionInfo(){return{unitId:this._unitId,subUnitId:this._subUnitId,shapeId:this._targetShapeId,cxnIndex:this._cxnIndex}}setHighlighted(e){this._isHighlighted!==e&&(this._isHighlighted=e,this.makeDirty(!0))}isHighlighted(){return this._isHighlighted}setShapeProps(e){e.targetShapeId!==void 0&&(this._targetShapeId=e.targetShapeId),e.cxnIndex!==void 0&&(this._cxnIndex=e.cxnIndex),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),e.isHighlighted!==void 0&&(this._isHighlighted=e.isHighlighted),this.transformByState({width:e.width??r.ShapeDefaultConfig.cxnPointRadius*2,height:e.height??r.ShapeDefaultConfig.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?Wt.highlighted:Wt.normal;s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let G=class extends o.Disposable{constructor(e,t,n,r){super(),this._context=e,this._renderManagerService=t,this._drawingManagerService=n,this._sheetsShapeService=r,E(this,`_connectionSiteObjects`,[]),E(this,`_activeTargetShapeId`,null),E(this,`_highlightedSiteIndex`,-1),E(this,`_currentScene`,null),E(this,`_unitId`,``),E(this,`_subUnitId`,``),E(this,`_draggingConnectorId`,null)}startConnectionDetection(e,t,n,r){this._currentScene=e,this._unitId=t,this._subUnitId=n,this._draggingConnectorId=r}updateConnectionDetection(e){if(!this._currentScene)return null;let t=this._findShapeAtPoint(e);return t?(this._activeTargetShapeId!==t.shapeId&&(this._clearConnectionSites(),this._showConnectionSites(t.shapeId,t.shapeModel),this._activeTargetShapeId=t.shapeId),this._findNearestConnectionSite(e)):(this._activeTargetShapeId!==null&&(this._clearConnectionSites(),this._activeTargetShapeId=null),null)}endConnectionDetection(){this._clearConnectionSites(),this._currentScene=null,this._activeTargetShapeId=null,this._highlightedSiteIndex=-1,this._draggingConnectorId=null}getConnectionRelation(){return this._activeTargetShapeId===null||this._highlightedSiteIndex<0?null:{shapeId:this._activeTargetShapeId,cxnIndex:this._highlightedSiteIndex}}_findShapeAtPoint(e){let t=this._drawingManagerService.getDrawingData(this._unitId,this._subUnitId);for(let n of Object.keys(t)){if(n===this._draggingConnectorId||t[n].drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,n);if(!i||(0,r.isConnectorShape)(i.getShapeType())||i.getConnectionSiteList().length===0||!this._currentScene)continue;let a=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:n}),c=this._currentScene.getObjectIncludeInGroup(a);if(!c)continue;let{left:l,top:u,width:f,height:p}=c.getRealBound(),m=l+f/2,h=u+p/2,g=c.transform.getMatrix(),_=new s.Transform([g[0],g[1],g[2],g[3],m,h]),v=c.getParent(),y=(c.isInGroup&&(v==null?void 0:v.classType)===s.RENDER_CLASS_TYPE.GROUP?v.ancestorTransform.multiply(_):_).invert().applyPoint(e),b=f/2,x=p/2;if(y.x>=-b-5&&y.x<=b+5&&y.y>=-x-5&&y.y<=x+5)return{shapeId:n,shapeModel:i}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let n=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),i=this._currentScene.getObjectIncludeInGroup(n);if(!i)return;let{left:a,top:o,width:c,height:l}=i.getRealBound(),u=a+c/2,f=o+l/2,p=i.transform.getMatrix(),m=new s.Transform([p[0],p[1],p[2],p[3],u,f]),h=i.getParent(),g=i.isInGroup&&(h==null?void 0:h.classType)===s.RENDER_CLASS_TYPE.GROUP?h.ancestorTransform.multiply(m):m;t.updateContext({width:c,height:l});let _=t.getConnectionSiteList();for(let t of _){let n=t.x-c/2,i=t.y-l/2,a=g.applyPoint({x:n,y:i}),o=a.x,u=a.y,d=new Gt(`connection-site-${e}-${t.index}`,{left:o-r.ShapeDefaultConfig.cxnPointRadius,top:u-r.ShapeDefaultConfig.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:r.ShapeDefaultConfig.cxnPointRadius*2,height:r.ShapeDefaultConfig.cxnPointRadius*2,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+2,evented:!1});this._connectionSiteObjects.push(d),this._currentScene.addObject(d,s.DRAWING_OBJECT_LAYER_INDEX+2)}}_findNearestConnectionSite(e){let t=null,n=1/0,i=null;for(let a of this._connectionSiteObjects){let o=a.left+r.ShapeDefaultConfig.cxnPointRadius,s=a.top+r.ShapeDefaultConfig.cxnPointRadius,c=e.x-o,l=e.y-s,u=Math.sqrt(c*c+l*l);u<n&&(n=u,t=a,i={x:o,y:s})}let a=n<=10&&t?t.getConnectionInfo().cxnIndex:-1;if(a!==this._highlightedSiteIndex){for(let e of this._connectionSiteObjects){let t=e.getConnectionInfo();e.setHighlighted(t.cxnIndex===a)}this._highlightedSiteIndex=a}if(n<=10&&t&&i){let e=t.getConnectionInfo(),n=this._getConnectionSiteAngle(e.shapeId,e.cxnIndex);return{shapeId:e.shapeId,cxnIndex:e.cxnIndex,unitId:e.unitId,subUnitId:e.subUnitId,worldPoint:i,angle:n}}return null}_getConnectionSiteAngle(e,t){let n=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,e);if(!n)return 0;let r=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e});if(!(r!=null&&r.transform))return 0;let{width:i=0,height:a=0,flipX:o=!1,flipY:s=!1}=r.transform;n.updateContext({width:i,height:a});let c=n.getConnectionSiteList().find(e=>e.index===t);if(!c)return 0;let l=c.ang/6e4;return o&&(l=180-l),s&&(l=-l),l=(l%360+360)%360,l}_clearConnectionSites(){for(let e of this._connectionSiteObjects)e.dispose();this._connectionSiteObjects=[],this._highlightedSiteIndex=-1}dispose(){this._clearConnectionSites(),super.dispose()}};G=A([k(1,(0,o.Inject)(s.IRenderManagerService)),k(2,(0,o.Inject)(d.IDrawingManagerService)),k(3,(0,o.Inject)(a.SheetsShapeService))],G);let K=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._sheetSkeletonService=e,this._sheetClipboardService=t,this._sheetDrawingService=n,this._shapeService=r,this._groupCopyPasteController=i,this._instances=a,this._renders=o,this._permissions=s,E(this,`_copyInfo`,void 0),this._initCopyPaste(),this._registerGroupFeaturePasteHook()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_registerGroupFeaturePasteHook(){this._groupCopyPasteController.registerFeaturePasteHook(({fromUnitId:e,fromSubUnitId:t,toUnitId:n,toSubUnitId:r,idMap:i})=>{let o=[],s=[];for(let[u,d]of i.entries()){let f=this._shapeService.getShapeModel(e,t,u);if(!f)continue;let p=f.getShapeType(),m=JSON.parse(JSON.stringify(f.getShapeData()));if(m.relation){var c,l;let e=(c=m.relation.from)==null?void 0:c.shapeId,t=(l=m.relation.to)==null?void 0:l.shapeId,n=!e||i.has(e),r=!t||i.has(t);n&&e&&m.relation.from?m.relation.from={...m.relation.from,shapeId:i.get(e)}:m.relation.from=void 0,r&&t&&m.relation.to?m.relation.to={...m.relation.to,shapeId:i.get(t)}:m.relation.to=void 0}o.push({id:a.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d,shapeType:p,shapeData:m}}),s.push({id:a.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d}})}return{redos:o,undos:s}})}_initCopyPaste(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:`sheets-shape-ui`,onBeforeCopyFocusedObject:(e,t,n)=>{this._copyInfo=null;let r=this._focusedDrawings.filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);return r.length!==0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:n,drawings:r},!0)},onBeforeCopy:(e,t,n,r)=>{this._copyInfo=null,this._createCopyInfoByRange(e,t,n,r)},onPasteCells:(e,t,n,r)=>{if(!r.copyId||!e||!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return i===u.PREDEFINED_HOOK_NAME.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===u.COPY_TYPE.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let a=(0,c.attachRangeWithCoord)(i,n);if(!a)return;let{startX:s,endX:l,startY:u,endY:d}=a,f=this._sheetDrawingService.getDrawingData(e,t),p=[];for(let[e,t]of Object.entries(f)){if(t.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:a=0}=e;s<=n&&l>=n+i&&u<=r&&d>=r+a&&p.push(t)}p.length>0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:r,copyRange:n,drawings:p})}_generatePasteMutations(e,t){var n,r;let{unitId:i,subUnitId:a,range:s}=e,l=this._copyInfo,u=(n=this._instances.getUnit(l.unitId,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(l.subUnitId),d=(r=this._instances.getUnit(i,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(a),f=(u==null?void 0:u.getConfig().type)??o.SheetTypes.GRID,p=(d==null?void 0:d.getConfig().type)??o.SheetTypes.GRID;if(f===o.SheetTypes.CHART||p===o.SheetTypes.CHART)return this._generateChartSheetCopy(e,t);let m=this._sheetSkeletonService.getSkeleton(i,a);if(!m)return{redos:[],undos:[]};let h=(0,c.discreteRangeToRange)(s),{unitId:g,subUnitId:_,copyRange:v,drawings:y}=this._copyInfo,b=this._sheetSkeletonService.getSkeleton(g,_);if(!b)return{redos:[],undos:[]};let x;if(!v){let e=1/0,t=1/0;for(let n of y){let{left:r=0,top:i=0}=n.transform??{};r<e&&(e=r),i<t&&(t=i)}e!==1/0&&t!==1/0&&(x={left:e,top:t})}let S=/* @__PURE__ */ new Map;if(!t)for(let e of y)S.set(e.drawingId,(0,o.generateRandomId)());let C=[],w=[];for(let e of y){let{drawingId:n,transform:r}=e;if(!r)continue;let o=this._updateTransform(r,{skeleton:b,range:v},{skeleton:m,range:h},x);if(t){let{redos:t,undos:n}=this._generateCutPasteMutations({fromUnitId:g,fromSubUnitId:_,toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:o});C.push(...t),w.push(...n);continue}let{redos:s,undos:c}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:o,newDrawingId:S.get(n),idMap:S});C.push(...s),w.push(...c)}return{redos:C,undos:w}}_generateChartSheetCopy(e,t){var n;if(t)throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[c.WorkbookEditablePermission],worksheetTypes:[c.WorksheetEditPermission]},r,i))throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let a=(n=this._instances.getUnit(r,o.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),s=a==null?void 0:a.getConfig(),d=(s==null?void 0:s.type)??o.SheetTypes.GRID,f=this._copyInfo,p=f.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[c.WorkbookCopyPermission],worksheetTypes:[c.WorksheetCopyPermission]},f.unitId,f.subUnitId)||p.some(e=>e.groupId||!this._shapeService.getShapeModel(f.unitId,f.subUnitId,e.drawingId)||!o.Tools.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let m=null;if(d===o.SheetTypes.CHART){var h;let e=(h=this._renders.getRenderUnitById(r))==null?void 0:h.components.get(u.SHEET_VIEW_KEY.CHART_PAGE);e&&(m=(0,l.transformDrawingsToChartSheet)(p,{left:e.left,top:e.top,width:e.width,height:e.height},(s==null?void 0:s.rightToLeft)===o.BooleanNumber.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&(0,c.attachRangeWithCoord)(t,(0,c.discreteRangeToRange)(e.range));if(n&&p.length){let e=Math.min(...p.map(e=>e.transform.left)),r=Math.min(...p.map(e=>e.transform.top));m=p.map(i=>(0,l.applySheetDrawingPlacement)(i,{kind:l.SheetDrawingAnchorType.Position,bounds:{left:n.startX+i.transform.left-e,top:n.startY+i.transform.top-r,width:i.transform.width,height:i.transform.height}},t))}}if(!m)throw new o.CustomCommandExecutionError(u.SheetPasteCommand.id);let g=new Map(p.map(e=>[e.drawingId,(0,o.generateRandomId)()])),_=[],v=[];for(let[e,t]of p.entries()){let n=m[e],a=this._generateCopyPasteMutations({toUnitId:r,toSubUnitId:i,drawing:t,idMap:g,newDrawingId:g.get(t.drawingId),newTransforms:{transform:n.transform,axisAlignSheetTransform:n.axisAlignSheetTransform,anchorType:n.anchorType}});_.push(...a.redos),v.unshift(...a.undos)}return{redos:_,undos:v}}_generateCutPasteMutations(e){let{fromUnitId:t,fromSubUnitId:n,toUnitId:r,toSubUnitId:i,drawing:o,newTransforms:s}=e,c={...o,unitId:r,subUnitId:i,...s};if(r===t&&i===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([c]);return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.UPDATE,op:e,objects:n}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([o]),s=this._sheetDrawingService.getBatchAddOp([c]),u=this._shapeService.getShapeModel(o.unitId,o.subUnitId,o.drawingId);if(!u)return{redos:[],undos:[]};let d=u.getShapeType(),f=JSON.parse(JSON.stringify(u.getShapeData()));return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.REMOVE,op:e.redo,objects:e.objects}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId}},{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.INSERT,op:s.redo,objects:s.objects}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:r,subUnitId:i,shapeId:o.drawingId,shapeType:d,shapeData:f}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.INSERT,op:e.undo,objects:e.objects}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId,shapeType:d,shapeData:f}},{id:l.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,type:l.DrawingApplyType.REMOVE,op:s.undo,objects:s.objects}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:r,subUnitId:i,shapeId:o.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:i,newDrawingId:o,idMap:s}=e,c={...r,unitId:t,subUnitId:n,drawingId:o,...i},{redo:u,undo:d,objects:f}=this._sheetDrawingService.getBatchAddOp([c]),p=this._shapeService.getShapeModel(r.unitId,r.subUnitId,r.drawingId);if(!p)return{redos:[],undos:[]};let m=p.getShapeType(),h=JSON.parse(JSON.stringify(p.getShapeData()));if(h.relation){var g,_;let e=(g=h.relation.from)==null?void 0:g.shapeId,t=(_=h.relation.to)==null?void 0:_.shapeId,n=!e||s.has(e),r=!t||s.has(t);n&&e&&h.relation.from?h.relation.from={...h.relation.from,shapeId:s.get(e)}:h.relation.from=void 0,r&&t&&h.relation.to?h.relation.to={...h.relation.to,shapeId:s.get(t)}:h.relation.to=void 0}return{redos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.INSERT,op:u,objects:f}},{id:a.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o,shapeType:m,shapeData:h}}],undos:[{id:l.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:l.DrawingApplyType.REMOVE,op:d,objects:f}},{id:a.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:s}=n,u={...e};if(i){let e=(0,c.attachRangeWithCoord)(a,i),t=(0,c.attachRangeWithCoord)(s,o);if(e&&t){let n=t.startX-e.startX,r=t.startY-e.startY;u.left=(u.left??0)+n,u.top=(u.top??0)+r}}else{let e=(0,c.attachRangeWithCoord)(s,o);if(r&&e){let t=(u.left??0)-r.left,n=(u.top??0)-r.top;u.left=e.startX+t,u.top=e.startY+n}else u.left=e==null?void 0:e.startX,u.top=e==null?void 0:e.startY}return{transform:u,axisAlignSheetTransform:(0,l.transformToAxisAlignPosition)(u,s)}}};K=A([k(0,(0,o.Inject)(c.SheetSkeletonService)),k(1,(0,o.Inject)(u.ISheetClipboardService)),k(2,(0,o.Inject)(l.ISheetDrawingService)),k(3,(0,o.Inject)(a.SheetsShapeService)),k(4,(0,o.Inject)(y.SheetsDrawingGroupCopyPasteController)),k(5,o.IUniverInstanceService),k(6,s.IRenderManagerService),k(7,(0,o.Inject)(c.SheetPermissionCheckController))],K);var Kt=class extends s.Shape{constructor(e,t){super(e,t),E(this,`_shapeId`,null),E(this,`_index`,null),E(this,`_unitId`,null),E(this,`_subUnitId`,null),E(this,`_isStartConnectorPoint`,!1),t&&this.setShapeProps(t)}getDrawingSearch(){return{unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._shapeId}}setShapeProps(e){e.shapeId!==void 0&&(this._shapeId=e.shapeId),e.unitId!==void 0&&(this._unitId=e.unitId),e.subUnitId!==void 0&&(this._subUnitId=e.subUnitId),e.isStartConnectorPoint!==void 0&&(this._isStartConnectorPoint=e.isStartConnectorPoint),this.transformByState({width:e.width,height:e.height})}_draw(e){s.Circle.drawWith(e,{radius:r.ShapeDefaultConfig.cxnPointRadius,fill:r.ShapeDefaultConfig.cxnPointFill,stroke:r.ShapeDefaultConfig.cxnPointStroke,strokeWidth:r.ShapeDefaultConfig.cxnPointStrokeWidth,evented:!0})}};let qt=class extends o.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._context=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,this._univerInstanceService=i,this._sheetsShapeService=a,this._sheetShapeAdjustController=o,this._sheetBasicShapeConnectionPointController=s,E(this,`_activeShapeId`,void 0),E(this,`_unitId`,void 0),E(this,`_subUnitId`,void 0),E(this,`_connectorObjects`,[]),E(this,`_baseDrawingRect`,{left:0,top:0,width:0,height:0,flipX:!1,flipY:!1}),E(this,`_activeShapeModel`,void 0),E(this,`_isConnecting`,!1),E(this,`_isDrawingShapePointDown`,!1),E(this,`_hasReset`,!1),E(this,`_cxtHandlerPointerMove`,void 0),E(this,`_cxtHandlerPointerUp`,void 0),E(this,`_currentConnectionTarget`,null),this._initialize()}_initialize(){this._registerDrawingFocusChangeHandler(),this._registerDrawingMoveHandler()}_getDrawingRect(){if(!this._unitId||!this._subUnitId||!this._activeShapeId)return;let e={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},{transform:t}=this._drawingManagerService.getDrawingByParam(e);if(t)return{left:t.left||0,top:t.top||0,width:t.width||0,height:t.height||0,flipX:t.flipX||!1,flipY:t.flipY||!1,angle:t.angle}}_addShapeConnectorHandlerObjects(){if(this._unitId===void 0||this._subUnitId===void 0||this._activeShapeId===void 0)return;let e=this._renderManagerService.getRenderUnitById(this._unitId);if(!e||!e.with(u.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:t}=e,n=this._getDrawingRect();if(!n)return;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!i||!(0,r.isConnectorShape)(i.getShapeType()))return;let a=i.getConnectorLinePoints();if(a.length<2)return;let o=new r.ConnectorCoordinateTransform(n),s=a[0],c=a[a.length-1],l=o.localToWorld(s),d=o.localToWorld(c);this._addShapeConnectorHandlerObject(t,{...l},!0),this._addShapeConnectorHandlerObject(t,{...d},!1)}_addShapeConnectorHandlerObject(e,t,n){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let i=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${n?`start`:`end`}`,a=e.getObjectIncludeInGroup(i);if(a){a.transformByState({left:t.x-r.ShapeDefaultConfig.cxnPointRadius,top:t.y-r.ShapeDefaultConfig.cxnPointRadius});return}let o=new Kt(i,{left:t.x-r.ShapeDefaultConfig.cxnPointRadius,top:t.y-r.ShapeDefaultConfig.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:n,width:r.ShapeDefaultConfig.cxnPointRadius*2,height:r.ShapeDefaultConfig.cxnPointRadius*2,zIndex:s.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._connectorObjects.push(o),this._attachConnectorObjectEvent(o,e,n),e.addObject(o,s.DRAWING_OBJECT_LAYER_INDEX+1)}_getScrollInfo(e,t){var n;let r={x:0,y:0};if(!e||!t)return r;let i=this._renderManagerService.getRenderUnitById(e);if(!i||!i.with(u.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(u.SheetScrollManagerService),o=a==null?void 0:a.getCurrentScrollState();if(!o)return r;let s=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!s)return r;let c=(0,u.getViewportByCell)(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_handleConnectorPointerUp(e,t,n,r,i){this._cxtHandlerPointerMove.unsubscribe(),this._cxtHandlerPointerUp.unsubscribe(),this._sheetShapeAdjustController.refreshAdjustControls();let a=this._currentConnectionTarget;this._sheetBasicShapeConnectionPointController.endConnectionDetection();let o=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c={x:n.offsetX/s+o.x,y:n.offsetY/s+o.y},l=a?a.worldPoint:c,u=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo(),d=this._activeShapeModel.getShapeType();u?this._handleConnectedEndpointPointerUp(u,l,r,a,i):this._handleFreeEndpointPointerUp(t,l,r,a,i,d),this._isConnecting=!1,this._hasReset=!1,this._currentConnectionTarget=null,e.enableObjectsEvent()}_handleFreeEndpointPointerUp(e,t,n,i,a,o){let s=o===r.ShapeTypeEnum.Line||o===r.ShapeTypeEnum.StraightConnector1,c=n?t:e,l=n?e:t,u=this._activeShapeModel.getConnectorLinePoints(),d=this._activeShapeModel.getShapeType(),f=(0,r.isCurvedConnectorShape)(d),p=r.ConnectorCoordinateTransform.getBentTypeFromPoints(u,f),m=s?r.ConnectorCoordinateTransform.computeStraightConnectorLayout(c,l):r.ConnectorCoordinateTransform.computeConnectorResizeLayout(e,t,n,p);i?this._executeConnectionCommand(m,i,n,a):this._executeResizeCommand(m,a)}_handleConnectedEndpointPointerUp(e,t,n,i,a){let o=this._getConnectPointInfo(e);if(!o)return;let s=i?i.angle:this._calculateFreeEndpointAngle(o.point,t),c;if(i){let e=this._drawingManagerService.getDrawingByParam({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:i=0,height:a=0,angle:o}=e.transform;c=(0,r.getBasicShapeRotateBound)({left:t,top:n,width:i,height:a},o||0)}else c={left:t.x,top:t.y,width:0,height:0}}else c={left:t.x,top:t.y,width:0,height:0};let l={point:t,angle:s,bounds:c},u=n?l:o,d=n?o:l,f=this._activeShapeModel.getShapeType(),p=(0,r.routeConnectorLineShape)(u,d,f);this._activeShapeModel.removeLinePoints();let m=(0,r.computeConnectorRouteLayout)(p,f);i?this._executeConnectedRouteConnectionCommand(m,i,e,n,a):this._executeConnectedRouteResizeCommand(m,e,n,a)}_executeConnectionCommand(e,t,n,i){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};n?s.from=c:s.to=c;let l=this._activeShapeModel.getShapeType(),u=(0,r.computeConnectorRouteLayout)(e.worldPoints,l),d={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,newAdjustValues:u.adjustValues,oldAdjustValues:i,oldRelation:o,newRelation:s,newLineType:u.lineType,oldLineType:l};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,d)}_executeResizeCommand(e,t){let n=this._activeShapeModel.getShapeType(),i=(0,r.computeConnectorRouteLayout)(e.worldPoints,n),o={unitId:this._unitId,subUnitId:this._subUnitId,shapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,angle:e.worldRect.angle||0,newAdjustValues:i.adjustValues,oldAdjustValues:t,newLineType:i.lineType,oldLineType:n};this._commandService.executeCommand(a.UpdateLineShapeResizeCommand.id,o)}_executeConnectedRouteConnectionCommand(e,t,n,r,i){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?(s.from=c,s.to=n):(s.from=n,s.to=c);let l={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:i,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:o,newRelation:s};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,l)}_executeConnectedRouteResizeCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,o={};n?(o.to=t,o.from=void 0):(o.from=t,o.to=void 0);let s={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:r,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:i,newRelation:o};this._commandService.executeCommand(a.UpdateConnectorRelationCommand.id,s)}_attachConnectorObjectEvent(e,t,n){this.disposeWithMe((0,o.toDisposable)(e.onPointerDown$.subscribeEvent((i,a)=>{let o=e.getDrawingSearch();if(this._activeShapeModel=this._sheetsShapeService.getShapeModel(o.unitId,o.subUnitId,o.drawingId),!this._activeShapeModel)return;let s={};this._activeShapeModel.getAdjustNames().forEach(e=>{let t=this._activeShapeModel.getAdjustValueByName(e);t!==void 0&&(s[e]=t)});let c=this._getDrawingRect();if(!c)return;this._baseDrawingRect={...c};let l=new r.ConnectorCoordinateTransform(this._baseDrawingRect),u=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),f=t.getObjectIncludeInGroup(u);this._isConnecting=!0,t.disableObjectsEvent(),this._sheetBasicShapeConnectionPointController.startConnectionDetection(t,this._unitId,this._subUnitId,this._activeShapeId),this._currentConnectionTarget=null;let p=this._activeShapeModel.getConnectorLinePoints(),m=p[0],h=p[p.length-1],g=n?l.localToWorld(h):l.localToWorld(m);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((r,i)=>{if(!this._isConnecting||!this._activeShapeModel)return;this._hasReset||=(this._sheetShapeAdjustController.clearAdjustControls(),this._activeShapeModel.clearAdjustValue(),!0);let a=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s={x:r.offsetX/o+a.x,y:r.offsetY/o+a.y},c=this._sheetBasicShapeConnectionPointController.updateConnectionDetection(s);if(c){let{shapeId:e,unitId:n,subUnitId:r}=c;if(e&&n&&r){let i=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=n?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,n,f,e):this._handleFreeEndpointMove(s,g,n,f,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,r)=>{this._handleConnectorPointerUp(t,g,e,n,s)}),a.stopPropagation()})))}_handleBasicShapeUpdateConnectorLineShape(e,t,n){let r=this._sheetsShapeService.getBasicShapeRelation(e,t,n);if(!r||r.length===0)return;let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i;for(let i of r){let r=i.lineShapeId,o=this._sheetsShapeService.getShapeModel(e,t,r);if(!o)continue;let s=o.getStartConnectInfo(),c=o.getEndConnectInfo(),l=(s==null?void 0:s.shapeId)===n,u=(0,d.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:r}),f=a.getObjectIncludeInGroup(u);if(!f)continue;let p=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});p!=null&&p.transform&&(s&&c?this._rerouteConnectorLine(e,t,r,o,s,c,f):this._moveConnectorWithShape(e,t,r,o,l?s:c,l,p,f))}}_rerouteConnectorLine(e,t,n,i,a,o,s){let c=this._unitId,l=this._subUnitId;this._unitId=e,this._subUnitId=t;let u=this._getConnectPointInfo(a),d=this._getConnectPointInfo(o);if(this._unitId=c,this._subUnitId=l,!u||!d)return;let f=i.getShapeType(),p=(0,r.routeConnectorLineShape)(u,d,f);p&&i.updateLinePoints(p);let m=(0,r.computeConnectorRouteLayout)(p,f);m.lineType!==f&&i.changeShapeType(m.lineType),i.clearAdjustValue();for(let[e,t]of Object.entries(m.adjustValues))i.setAdjustValueByName(e,t);i.updateContext({width:m.worldRect.width,height:m.worldRect.height}),s.transformByState({flipX:m.worldRect.flipX,flipY:m.worldRect.flipY,left:m.worldRect.left,top:m.worldRect.top,width:m.worldRect.width,height:m.worldRect.height,angle:m.rotation}),i.removeLinePoints()}_moveConnectorWithShape(e,t,n,i,a,o,s,c){let l=this._unitId,u=this._subUnitId;this._unitId=e,this._subUnitId=t;let d=this._getConnectPointInfo(a);if(this._unitId=l,this._subUnitId=u,!d)return;let{left:f=0,top:p=0,width:m=0,height:h=0,flipX:g=!1,flipY:_=!1}=s.transform,v=i.getConnectorLinePoints();if(v.length<2)return;let y=new r.ConnectorCoordinateTransform({left:f,top:p,width:m,height:h,flipX:g,flipY:_}),b=o?v[v.length-1]:v[0],x=y.localToWorld(b),S=r.ConnectorCoordinateTransform.computeConnectorResizeLayout(x,d.point,!o);c.transformByState({flipX:S.worldRect.flipX,flipY:S.worldRect.flipY,left:S.worldRect.left,top:S.worldRect.top,width:S.worldRect.width,height:S.worldRect.height,angle:S.worldRect.angle}),c.makeDirty(!0)}_clearShapeConnectorHandlerObjects(){this._connectorObjects.length!==0&&(this._connectorObjects.forEach(e=>{e.dispose()}),this._connectorObjects=[])}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,f.switchMap)(e=>e?e.activeSheet$.pipe((0,f.switchMap)(t=>{if(!t)return f.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,f.of)(i):f.EMPTY})):f.EMPTY)).subscribe(e=>{let t=e.getTransformerByCreate();this.disposeWithMe(e.onPointerMove$.subscribeEvent(e=>{this._isDrawingShapePointDown&&this._activeShapeId&&this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:t}=e;this._clearShapeConnectorHandlerObjects(),t!==null&&t.size===1&&t.values().next().value instanceof D&&(this._isDrawingShapePointDown=!0)})),this.disposeWithMe(t.changing$.subscribe(e=>{this._isDrawingShapePointDown&&this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(e.onPointerUp$.subscribeEvent(()=>{this._isDrawingShapePointDown&&(this._isDrawingShapePointDown=!1,this._addShapeConnectorHandlerObjects())})),this.disposeWithMe(t.changeEnd$.subscribe(()=>{this._unitId&&this._subUnitId&&this._activeShapeId&&this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId})&&(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects())}))}))}_registerDrawingFocusChangeHandler(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let t=e[0];if(t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&(0,r.isConnectorShape)(e.getShapeType())){this._activeShapeId=t.drawingId,this._unitId=t.unitId,this._subUnitId=t.subUnitId,this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects();return}}}this._activeShapeId=void 0,this._unitId=void 0,this._subUnitId=void 0,this._clearShapeConnectorHandlerObjects()})),this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{if(e.length===1){var t;let n=e[0],r=(t=this._drawingManagerService.getDrawingByParam(n))==null?void 0:t.drawingType;r===o.DrawingTypeEnum.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===o.DrawingTypeEnum.DRAWING_SHAPE&&this._handleBasicShapeUpdateConnectorLineShape(n.unitId,n.subUnitId,n.drawingId)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e){let{drawingId:e}=t;if(this._activeShapeId===e){this._reset();return}}}))}_handleConnectedEndpointMove(e,t,n,i,a){var o;if(!this._activeShapeModel)return;let s=this._getConnectPointInfo(e);if(!s)return;let c=this._currentConnectionTarget?this._currentConnectionTarget.worldPoint:t,l=this._currentConnectionTarget?this._currentConnectionTarget.angle:this._calculateFreeEndpointAngle(s.point,c),u;if(this._currentConnectionTarget){let e=this._drawingManagerService.getDrawingByParam({unitId:this._currentConnectionTarget.unitId,subUnitId:this._currentConnectionTarget.subUnitId,drawingId:this._currentConnectionTarget.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:i=0,height:a=0,angle:o}=e.transform;u=(0,r.getBasicShapeRotateBound)({left:t,top:n,width:i,height:a},o||0)}else u={left:c.x,top:c.y,width:0,height:0}}else u={left:c.x,top:c.y,width:0,height:0};let d={point:c,angle:l,bounds:u},f=n?d:s,p=n?s:d,m=this._activeShapeModel.getShapeType(),h=(0,r.routeConnectorLineShape)(f,p,m);h&&this._activeShapeModel.updateLinePoints(h);let g=(0,r.computeConnectorRouteLayout)(h,m);g.lineType!==m&&this._activeShapeModel.changeShapeType(g.lineType);for(let[e,t]of Object.entries(g.adjustValues))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:g.worldRect.width,height:g.worldRect.height}),i.transformByState({flipX:g.worldRect.flipX,flipY:g.worldRect.flipY,left:g.worldRect.left,top:g.worldRect.top,width:g.worldRect.width,height:g.worldRect.height,angle:g.rotation}),i.makeDirty(!0);let _=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??t;a.transformByState({left:_.x-r.ShapeDefaultConfig.cxnPointRadius,top:_.y-r.ShapeDefaultConfig.cxnPointRadius})}_handleFreeEndpointMove(e,t,n,i,a){var o,s;let c=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e,l=r.ConnectorCoordinateTransform.computeConnectorResizeLayout(t,c,n);i.transformByState({flipX:l.worldRect.flipX,flipY:l.worldRect.flipY,left:l.worldRect.left,top:l.worldRect.top,width:l.worldRect.width,height:l.worldRect.height,angle:l.worldRect.angle});let u=((s=this._currentConnectionTarget)==null?void 0:s.worldPoint)??e;a.transformByState({left:u.x-r.ShapeDefaultConfig.cxnPointRadius,top:u.y-r.ShapeDefaultConfig.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:n}=e,i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,t);if(!i)return null;let a=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:t});if(!(a!=null&&a.transform))return null;let{left:o=0,top:s=0,width:c=0,height:l=0,flipX:u=!1,flipY:d=!1,angle:f}=a.transform;i.updateContext({width:c,height:l});let p=i.getConnectionSiteList().find(e=>e.index===n);if(!p)return null;let m=u?c-p.x:p.x,h=d?l-p.y:p.y;if(f!==0&&f!=null){let e=f*Math.PI/180,t=Math.cos(e),n=Math.sin(e),r=c/2,i=l/2,a=m-r,o=h-i;m=r+a*t-o*n,h=i+a*n+o*t}m+=o,h+=s;let g=p.ang/6e4;u&&(g=180-g),d&&(g=-g),g+=f||0,g=(g%360+360)%360;let _=(0,r.getBasicShapeRotateBound)({left:o,top:s,width:c,height:l},f||0);return{point:{x:m,y:h},angle:g,bounds:_}}_calculateFreeEndpointAngle(e,t){let n=t.x-e.x,r=t.y-e.y;return Math.abs(n)>=Math.abs(r)?n>=0?180:0:r>=0?270:90}_reset(){this._activeShapeId=void 0,this._unitId=void 0,this._subUnitId=void 0,this._clearShapeConnectorHandlerObjects()}dispose(){this._clearShapeConnectorHandlerObjects(),super.dispose()}};qt=A([k(1,o.ICommandService),k(2,s.IRenderManagerService),k(3,d.IDrawingManagerService),k(4,o.IUniverInstanceService),k(5,(0,o.Inject)(a.SheetsShapeService)),k(6,(0,o.Inject)(M)),k(7,(0,o.Inject)(G))],qt);let q=class extends o.Disposable{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._drawingManagerService=t,this._shapeRenderController=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{var r;let{unitId:i,subUnitId:a,scene:s,resourceCollector:c}=t,l=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[a];return l==null||l.order.forEach(e=>{let t=l.data[e];t.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,s,{resourceCollector:c})}),n(e)}}))}};q=A([k(0,(0,o.Inject)(u.SheetPrintInterceptorService)),k(1,d.IDrawingManagerService),k(2,(0,o.Inject)(j))],q);let J=class extends o.Disposable{constructor(e,t,n,r){super(),this._commandService=e,this._univerInstanceService=t,this._localeService=n,this._sheetPermissionCheckController=r,this._initPermission()}_initPermission(){let e=/* @__PURE__ */ new Set([S.id,a.ToggleSheetsShapeFlipCommand.id,a.SetSheetsShapeRotateCommand.id,a.SetSheetsShapeTextVerticalToggleCommand.id,a.UpdateLineShapeResizeCommand.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===a.InsertShapeCommand.id||t.id===a.SetShapeDrawingDataCommand.id||t.id===a.UpdateConnectorRelationCommand.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=(0,c.getSheetCommandTarget)(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==o.SheetTypes.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[c.WorkbookEditablePermission],worksheetTypes:[c.WorksheetEditPermission]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};J=A([k(0,(0,o.Inject)(o.ICommandService)),k(1,(0,o.Inject)(o.IUniverInstanceService)),k(2,(0,o.Inject)(o.LocaleService)),k(3,(0,o.Inject)(c.SheetPermissionCheckController))],J);let Y=class{constructor(e){this._renderManagerService=e}updateShapeFillImage(e,t){let n=this._renderManagerService.getRenderUnitById(e.unitId),r=n==null?void 0:n.scene;if(!r)return;let i=(0,d.getDrawingShapeKeyByDrawingSearch)(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};Y=A([k(0,s.IRenderManagerService)],Y);let X=class extends o.Plugin{constructor(e=pt,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=(0,o.merge)({},pt,this._config);this._configService.setConfig(ft,a),this._initCommands()}onStarting(){this._injector.add([zt]),this._injector.get(zt),(0,o.registerDependencies)(this._injector,[[H],[W],[j],[q],[Y],[z],[U],[R],[J]])}onReady(){(0,o.registerDependencies)(this._injector,[[G],[M],[K]]),(0,o.touchDependencies)(this._injector,[[K],[M]]),[[G],[mt],[qt],[Vt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,e))})}onRendered(){(0,o.touchDependencies)(this._injector,[[H],[W],[j],[q],[Y],[z],[U],[R],[J]])}onSteady(){this._injector.get(H).initShapePopupMenu()}_initCommands(){[N,S,re,dt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E(X,`type`,o.UniverInstanceType.UNIVER_SHEET),E(X,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E(X,`packageName`,lt),E(X,`version`,ut),X=A([(0,o.DependentOn)(g.UniverLicensePlugin,_.UniverDocsPlugin,d.UniverDrawingPlugin,s.UniverRenderEnginePlugin,c.UniverSheetsPlugin,v.UniverDocsUIPlugin,l.UniverSheetsDrawingPlugin,i.UniverShapeEditorPlugin,y.UniverSheetsDrawingMobileUIPlugin,a.UniverSheetsShapePlugin,u.UniverSheetsMobileUIPlugin,t.UniverShapeEditorMobileUIPlugin,n.UniverMobileUIPlugin),k(1,(0,o.Inject)(o.Injector)),k(2,o.ICommandService),k(3,o.IConfigService),k(4,s.IRenderManagerService)],X);let Jt={type:o.CommandType.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function Yt(){let e=(0,n.useDependency)(d.IDrawingManagerService),t=(0,n.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return t.length===0?null:/* @__PURE__ */ (0,h.jsx)(`div`,{children:/* @__PURE__ */ (0,h.jsxs)(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ (0,h.jsx)(p.DrawingCommonPanel,{drawings:t,hasCropper:!1}),/* @__PURE__ */ (0,h.jsx)(y.SheetDrawingAnchor,{drawings:t})]})})}function Xt(e){let{unitId:r,subUnitId:i,shapeId:a}=e,s=(0,n.useDependency)(o.ICommandService),c=(0,n.useDependency)(Y);return/* @__PURE__ */ (0,h.jsx)(t.ShapeEditPanel,{...e,positionEditor:/* @__PURE__ */ (0,h.jsx)(Yt,{}),onUpdateShapeData:(e,t)=>{C(s,r,i,a,e,t)},onUpdateLineShapeData:(e,t)=>{w(s,r,i,a,e,t)},onUpdateShapeFillImage:e=>{c.updateShapeFillImage({unitId:r,subUnitId:i,drawingId:a},e)}})}function Zt(e){let r=(0,n.useDependency)(t.ShapeFloatingToolbarService),i=(0,n.useObservable)(()=>r.visible$,r.getVisible(),!1,[r]),a=e.popup.extraProps;return!a||!i?null:/* @__PURE__ */ (0,h.jsx)(Qt,{...a,canvasElement:e.popup.canvasElement})}function Qt(e){let i=(0,n.useDependency)(o.ICommandService),s=(0,n.useDependency)(a.SheetsShapeService),{unitId:c,subUnitId:u,drawingId:d,drawingType:f,shapeType:p}=e,[m,g]=(0,b.useState)(e.shapeData),_=(0,b.useMemo)(()=>(0,t.getTextStyle)(m),[m]),v=(0,b.useMemo)(()=>(0,t.getTextModel)(m),[m]);(0,b.useEffect)(()=>{let e=i.onCommandExecuted(e=>{if(e.id!==a.UpdateSheetsShapeDataMutation.id)return;let t=s.getShapeDataById(c,u,d);t&&g(t)});return()=>e.dispose()},[i,d,s,u,c]);let y=e=>{g(t=>({...t,...e}))},x=e=>{let n=(0,t.buildShapeTextDataUpdate)(m,e);C(i,c,u,d,{oldShapeData:{shapeText:m.shapeText}},n),y(n)},S=(0,t.useFormulaShapeToolbar)({hostType:o.UniverInstanceType.UNIVER_SHEET,unitId:c,subUnitId:u,shapeId:d,shapeData:m,onUpdateBinding:e=>{let t={formulaBinding:e};C(i,c,u,d,{oldShapeData:{formulaBinding:m.formulaBinding}},t),y(t)}});return/* @__PURE__ */ (0,h.jsxs)(h.Fragment,{children:[/* @__PURE__ */ (0,h.jsx)(t.ShapeFloatingToolbar,{canvasElement:e.canvasElement,shapeData:m,shapeType:p,textStyle:{ff:r.ShapeDefaultConfig.shapeText.fontFamily,fs:r.ShapeDefaultConfig.shapeText.fontSize,cl:{rgb:r.ShapeDefaultConfig.shapeText.color},..._},textModel:v?{ha:v.ha??o.HorizontalAlign.LEFT,va:v.va??o.VerticalAlign.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:r.ShapeDefaultConfig.fill,defaultGradientEndColor:r.ShapeDefaultConfig.gradientEndColor,defaultStrokeColor:r.ShapeDefaultConfig.stroke,extensionGroups:S.extensionGroups,floatingObjectToolbarPosition:n.FloatingObjectToolbarPosition.SHEET,onUpdateShapeData:(e,t)=>{C(i,c,u,d,e,t),t&&y(t)},onUpdateText:x,onOpenPanel:()=>{i.executeCommand(L.id,{unitId:c,subUnitId:u,drawingId:d})},onDelete:()=>{i.executeCommand(l.RemoveSheetDrawingCommand.id,{unitId:c,drawings:[{unitId:c,subUnitId:u,drawingId:d,drawingType:f}]})}}),S.panel]})}function $t(e){return!!e&&`axisAlignSheetTransform`in e}let en=(0,b.memo)(()=>{let e=(0,n.useDependency)(z),r=(0,n.useDependency)(a.SheetsShapeService),i=(0,n.useDependency)(d.IDrawingManagerService),c=(0,n.useDependency)(o.ICommandService),f=(0,n.useDependency)(n.UndoRedoGroupService),p=(0,n.useDependency)(s.IRenderManagerService),m=(0,b.useMemo)(()=>({getShapeModel:(e,t,n)=>r.getShapeModel(e,t,n),getShapeData:(e,t,n)=>r.getShapeDataById(e,t,n),getDrawingTransform:(e,t,n)=>{let r=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n});return r==null?void 0:r.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:n,shapeText:r,oldShapeText:a,hostSize:o})=>{f.run(e,()=>{var s;let d=c.syncExecuteCommand(S.id,{unitId:e,subUnitId:t,shapeId:n,shapeData:{shapeText:r},oldShapeJSON:{oldShapeData:{shapeText:a}}});if(!d||!o)return d;let f=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),m=f==null?void 0:f.transform;if(!$t(f)||!m)return!1;let h={...m,width:o.width,height:o.height},g=(s=p.getRenderUnitById(e))==null||(s=s.with(u.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:s.skeleton;return c.syncExecuteCommand(l.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...f,transform:h,axisAlignSheetTransform:g?(0,l.transformToAxisAlignPosition)(h,g)??f.axisAlignSheetTransform:f.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:n,width:r,height:a})=>{var o;let s=i.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),d=s==null?void 0:s.transform;if(!$t(s)||!d)return;let f={...d,width:r,height:a},m=(o=p.getRenderUnitById(e))==null||(o=o.with(u.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:o.skeleton,h=m?(0,l.transformToAxisAlignPosition)(f,m)??s.axisAlignSheetTransform:s.axisAlignSheetTransform;c.executeCommand(l.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...s,transform:f,axisAlignSheetTransform:h}]})},allowHostSizeShrink:({unitId:e,subUnitId:n,shapeId:i})=>(0,t.shouldAllowShapeTextEditorHostSizeShrink)(r.getShapeDataById(e,n,i)),deferHostSizeUpdateDuringEditing:()=>!0}),[c,i,p,r,f]),g=(0,b.useMemo)(()=>({viewportKeys:{main:s.SHEET_VIEWPORT_KEY.VIEW_MAIN,leftTop:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,top:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,left:s.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(u.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ (0,h.jsx)(t.ShapeTextEditorContainer,{adapter:m,editingService:e,editorUnitId:I,positionOptions:g})}),Z=class extends o.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerIcons(),this._registerComponents()}_registerIcons(){this._iconManager.has(`ObjectLayersIcon`)||this.disposeWithMe(this._iconManager.register({ObjectLayersIcon:Mt})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:wt})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:Et})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:St})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:Ot})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:At})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:Pt})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:It}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(P,Xt)),this.disposeWithMe(this._componentManager.register(F,Lt)),this.disposeWithMe(this._componentManager.register(de,_e)),this.disposeWithMe(this._componentManager.register(fe,me)),this._componentManager.hasDefault(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(this._componentManager.register(p.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,ge)),this.disposeWithMe(this._componentManager.register(ie,Zt)),this.disposeWithMe(this._componentManager.register(Ae,Pe)),this.disposeWithMe(this._componentManager.register(ke,Fe)),this.disposeWithMe(this._componentManager.register(je,Ie)),this.disposeWithMe(this._componentManager.register(Me,Le)),this.disposeWithMe(this._componentManager.register(oe,t.ShapeTextFloatToolbar)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,en))}};Z=A([k(0,(0,o.Inject)(n.ComponentManager)),k(1,(0,o.Inject)(n.IconManager))],Z);let tn=class extends o.Disposable{constructor(e,n,r,i,a,l,u,d,p){super();let m=e=>{var t,n;return(((t=d.getPermissionPoint(new c.WorkbookEditablePermission(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=d.getPermissionPoint(new c.WorksheetEditPermission(e.unitId,e.subUnitId).id))==null?void 0:n.value)??!0)},h=e=>e.shapeId&&m(e)?r.getShapeDataById(e.unitId,e.subUnitId,e.shapeId)??null:null,g=()=>{let t=a.getFocusDrawings(),n=t.length===1?t[0]:null;return(n==null?void 0:n.drawingType)===o.DrawingTypeEnum.DRAWING_SHAPE&&n.unitId===e.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe((0,t.registerShapeFormatPainter)(e,n,{changes$:(0,f.merge)(a.focus$,i.editingParams$,d.permissionPointUpdate$),isActive:()=>{var t;return((t=l.getFocusedUnit())==null?void 0:t.getUnitId())===e.unitId&&!u.getContextValue(o.FOCUSING_SHAPE_TEXT_EDITOR)&&a.getFocusDrawings().some(t=>t.unitId===e.unitId)},getSelectedTarget:g,getSource:()=>{let e=g();return e?h(e):null},getTarget:t=>{let n=e.scene.pick(new s.Vector2(t.offsetX,t.offsetY));if(!(n instanceof D))return null;let r={unitId:e.unitId,subUnitId:n.subUnitId,shapeId:n.shapeId};return m(r)?r:null},getShape:h,update:(e,t,n)=>p.executeCommand(S.id,{...e,shapeData:n,replaceShapeData:!0,oldShapeJSON:{oldShapeData:t}})}))}};tn=A([k(1,(0,o.Inject)(n.FormatPainterSessionService)),k(2,(0,o.Inject)(a.SheetsShapeService)),k(3,(0,o.Inject)(z)),k(4,d.IDrawingManagerService),k(5,o.IUniverInstanceService),k(6,o.IContextService),k(7,o.IPermissionService),k(8,o.ICommandService)],tn);let nn=`sheets-shape-contextual-ribbon`,rn=class extends o.Disposable{constructor(e,t,n,r,i,a){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=a,E(this,`_visible`,!1),this._menuManagerService.mergeMenu(ot),this.disposeWithMe((0,o.toDisposable)(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,nn),this._hide(),super.dispose()}_update(){var e;let n=this._drawingManagerService.getFocusDrawings(),r=n.length===1?n[0]:void 0;if((r==null?void 0:r.drawingType)!==o.DrawingTypeEnum.DRAWING_SHAPE||this._univerInstanceService.getUnitType(r.unitId)!==o.UniverInstanceType.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,nn),this._hide();return}let i=(e=this._renderManagerService.getRenderUnitById(r.unitId))==null?void 0:e.engine.getCanvasElement(),a=(0,t.resolveShapeContextualRibbonHostMode)(i)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(a,nn),a?this._hide():this._visible||(this._visible=!0,this._ribbonService.showContextualTab(ae,{activate:!0}))}_hide(){this._visible&&(this._visible=!1,this._ribbonService.hideContextualTab(ae),this._ribbonService.setCollapsedIds([]))}};rn=A([k(0,n.IMenuManagerService),k(1,n.IRibbonService),k(2,d.IDrawingManagerService),k(3,o.IUniverInstanceService),k(4,s.IRenderManagerService),k(5,(0,o.Inject)(t.ShapeFloatingToolbarService))],rn);let an=class extends t.ShapeTextFloatMenuRenderControllerBase{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l,{componentKey:oe,editorUnitId:I})}};an=A([k(1,(0,o.Inject)(_.DocSelectionManagerService)),k(2,(0,o.Inject)(v.DocCanvasPopManagerService)),k(3,(0,o.Inject)(v.DocSelectionRenderService)),k(4,o.ICommandService),k(5,(0,o.Inject)(v.DocEventManagerService)),k(6,(0,o.Inject)(t.ShapeTextHyperLinkPopupService)),k(7,(0,o.Inject)(_.DocInterceptorService)),k(8,(0,o.Inject)(v.DocRenderController)),k(9,(0,o.Inject)(z))],an);let on=class extends t.ShapeTextHyperLinkHoverController{constructor(e,n,r,i,a){super(e,n,{editing$:r.editingParams$,resolve:r=>{var o,l,u;let d=new s.Vector2(r.offsetX,r.offsetY),f=((o=e.scene.getActiveViewportByCoord(d))==null?void 0:o.transformVector2SceneCoord(d))??d,p=(0,t.resolveShapeTextHyperLinkObject)(e.scene.pick(d)??null,f);if(!(p instanceof D))return null;let m=p.resolveHyperLinkAt(f);if(!m)return null;let h=p,g={componentKey:t.ShapeTextHyperLinkInfo.componentKey,direction:`top-center`,offset:[0,10],onClickOutside:()=>n.hideInfoPopup()};return{object:p,info:{...m,unitId:p.unitId,subUnitId:p.subUnitId,shapeKey:p.oKey,readonly:!0,copyable:((l=a.getPermissionPoint(new c.WorkbookCopyPermission(p.unitId).id))==null?void 0:l.value)!==!1&&((u=a.getPermissionPoint(new c.WorksheetCopyPermission(p.unitId,p.subUnitId).id))==null?void 0:u.value)!==!1},attachPopup:()=>i.attachPopupToObject(h,g)}}}),this.disposeWithMe(e.unit.activeSheet$.subscribe(()=>this.clear()))}};on=A([k(1,(0,o.Inject)(t.ShapeTextHyperLinkPopupService)),k(2,(0,o.Inject)(z)),k(3,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(4,o.IPermissionService)],on);let Q=class extends o.Disposable{constructor(e,t,n,r,i,a,s,c,l,u,d){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=a,this._drawingManagerService=s,this._sheetCanvasPopManagerService=c,this._contextService=l,this._renderManagerService=u,this._shapeTextEditingService=d,E(this,`_sidebarDisposable`,null),E(this,`_activeShapeInfo`,null),E(this,`_isOpenedShapeEditPanel`,!1),E(this,`_shapeEditPanelVersion`,0),E(this,`_shapePopupMenuDisposable`,null),E(this,`_disposePopups`,[]),this._initMenu(),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose()}})),this._registerOperations(),this.initShapePopupMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearPopups()}))}_initMenu(){this._menuManagerService.mergeMenu(ct)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,t.bindRenderTransformerLifecycle)(this._renderManagerService,o.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_getShapeInfo(e,t,n){let r=this._sheetsShapeService.getShapeTypeById(e,t,n),i=this._sheetsShapeService.getShapeDataById(e,t,n);return r!==void 0&&i!==void 0?{shapeData:i,shapeId:n,shapeType:r,unitId:e,subUnitId:t,version:this._shapeEditPanelVersion,disableShapeOption:!1}:null}_clearPopups(){this._disposePopups.forEach(e=>e.dispose()),this._disposePopups.length=0}_popupMenuListener(e){let n=new o.DisposableCollection;return n.add(e.createControl$.subscribe(()=>{let n=e.getSelectedObjectMap();if(this._clearPopups(),this._isOpenedShapeEditPanel||n.size>1)return;let r=n.values().next().value;if(!r)return;let i=this._drawingManagerService.getDrawingOKey(r.oKey);if(!i||i.drawingType!==o.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:a,subUnitId:s,drawingId:c,drawingType:l}=i,d=this._getShapeInfo(a,s,c);if(!d)return;this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!0);let f=this._renderManagerService.getRenderUnitById(a),p=((f==null?void 0:f.isMainScene)===!1?f.with(u.SheetCanvasPopManagerService):this._sheetCanvasPopManagerService).attachPopupToObject(r,{componentKey:ie,direction:`vertical-center`,offset:[0,t.SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET],extraProps:{unitId:a,subUnitId:s,drawingId:c,drawingType:l,shapeType:d.shapeType,shapeData:d.shapeData}});this._disposePopups.push(this.disposeWithMe(p)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===a&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:a,subUnitId:s,drawingId:c}])})),n.add(e.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),n.add(e.changing$.subscribe(()=>{this._clearPopups()})),n.add(e.changeStart$.subscribe(()=>{this._clearPopups()})),(0,o.toDisposable)(()=>{n.dispose(),this._clearPopups()})}_registerOperations(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===L.id){let{unitId:t,subUnitId:n,drawingId:r}=e.params;this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(t,n,r),this._clearPopups(),this._openShapeEditPanel()}if(e.id===Jt.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===a.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params;if(this._activeShapeInfo&&this._activeShapeInfo.shapeId===r){let e=this._getShapeInfo(t,n,r);e&&(this._shapeEditPanelVersion+=1,e.version=this._shapeEditPanelVersion,this._activeShapeInfo=e,this._isOpenedShapeEditPanel&&this._openShapeEditPanel())}}})),this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(this._isOpenedShapeEditPanel===!1)return;if(e.length===0){this._activeShapeInfo=null,this._closeShapeEditPanel();return}if(e.length===1&&e[0].drawingType===o.DrawingTypeEnum.DRAWING_SHAPE&&(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo)){this._openShapeEditPanel();return}let t=e.filter(e=>e.drawingType===o.DrawingTypeEnum.DRAWING_SHAPE);if(e.length>1&&t.length===e.length){if(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo){this._openShapeEditPanel();return}}else if(this._shapeEditPanelVersion+=1,this._activeShapeInfo=this._getShapeInfo(e[0].unitId,e[0].subUnitId,e[0].drawingId),this._activeShapeInfo){this._activeShapeInfo.disableShapeOption=!0,this._openShapeEditPanel();return}this._closeShapeEditPanel()}))}_openShapeEditPanel(){this._activeShapeInfo&&(this._sidebarDisposable=this._sidebarService.open({id:P,header:{title:this._localeService.t(`sheets-shape-ui.formatShape`)},width:388,children:{label:P,...this._activeShapeInfo},onClose:()=>{this._drawingManagerService.focusDrawing(null),this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(P),this._sidebarDisposable=null,this._contextService.setContextValue(o.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};Q=A([k(0,o.IUniverInstanceService),k(1,(0,o.Inject)(n.ISidebarService)),k(2,n.IMenuManagerService),k(3,(0,o.Inject)(a.SheetsShapeService)),k(4,(0,o.Inject)(o.LocaleService)),k(5,o.ICommandService),k(6,d.IDrawingManagerService),k(7,(0,o.Inject)(u.SheetCanvasPopManagerService)),k(8,o.IContextService),k(9,s.IRenderManagerService),k(10,(0,o.Inject)(z))],Q);let $=class extends o.Plugin{constructor(e=pt,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=(0,o.merge)({},pt,this._config);this._configService.setConfig(ft,a),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,[an]),(0,o.touchDependencies)(this._injector,[[Q],[W],[j],[q]])}onSteady(){this._injector.get(Q).initShapePopupMenu()}onReady(){[[G],[M],[K]].forEach(e=>this._injector.add(e)),(0,o.touchDependencies)(this._injector,[[K],[M]]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[G]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[mt]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[qt]),this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Bt]),this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[on])),this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[tn]))}onStarting(){this._injector.add([Z]),this._injector.get(Z);let e=this._injector;[[Q],[W],[j],[q],[Y],[z],[U],[R],[J],[rn]].forEach(t=>e.add(t)),(0,o.touchDependencies)(this._injector,[[Q],[W],[j],[Y],[z],[U],[R],[J],[rn]])}_initCommands(){[N,S,Jt,L,se,re,le,ue].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E($,`type`,o.UniverInstanceType.UNIVER_SHEET),E($,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E($,`packageName`,lt),E($,`version`,ut),$=A([(0,o.DependentOn)(g.UniverLicensePlugin,_.UniverDocsPlugin,d.UniverDrawingPlugin,p.UniverDrawingUIPlugin,s.UniverRenderEnginePlugin,c.UniverSheetsPlugin,v.UniverDocsUIPlugin,l.UniverSheetsDrawingPlugin,i.UniverShapeEditorPlugin,y.UniverSheetsDrawingUIPlugin,a.UniverSheetsShapePlugin,u.UniverSheetsUIPlugin,t.UniverShapeEditorUIPlugin),k(1,(0,o.Inject)(o.Injector)),k(2,o.ICommandService),k(3,o.IConfigService),k(4,s.IRenderManagerService)],$),e.SheetsShapeUIContextualRibbonSchema=ot,e.SheetsShapeUIMenuSchema=ct,Object.defineProperty(e,"UniverSheetsShapeMobileUIPlugin",{enumerable:!0,get:function(){return X}}),Object.defineProperty(e,"UniverSheetsShapeUIPlugin",{enumerable:!0,get:function(){return $}})});