@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/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@univerjs-pro/shape-editor-ui"),t=require("@univerjs/ui"),n=require("@univerjs-pro/engine-shape"),r=require("@univerjs-pro/shape-editor"),i=require("@univerjs-pro/sheets-shape"),a=require("@univerjs/core"),o=require("@univerjs/engine-render"),s=require("@univerjs/sheets"),c=require("@univerjs/sheets-drawing"),l=require("@univerjs/sheets-ui"),u=require("@univerjs/drawing"),d=require("rxjs"),f=require("@univerjs/drawing-ui"),p=require("@univerjs/design"),m=require("react/jsx-runtime"),h=require("@univerjs-pro/license"),g=require("@univerjs/docs"),_=require("@univerjs/docs-ui"),v=require("@univerjs/sheets-drawing-ui"),y=require("@univerjs/icons"),b=require("react");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}const S={type:a.CommandType.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(i.SheetsShapeService),{unitId:r,subUnitId:o,shapeType:s,shapeId:c,shapeData:l,replaceShapeData:u,oldShapeJSON:d}=t;if(!n.getShapeModel(r,o,c))return!1;let f=e.get(a.ICommandService),p=e.get(a.IUndoRedoService),{oldShapeType:m,oldShapeData:h={}}=d,g=u?h:x(h,l||{}),_={id:i.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:o,shapeId:c,shapeType:s,shapeData:l,replace:u}},v={id:i.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:o,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(t,n,r){let i={...n,dataModel:{...n.dataModel??{},...r?{doc:r}:null}},a=(0,e.resolveShapeTextEditorBehaviorShapeData)(t,i),o=(0,e.resolveShapeTextEditorWrapStrategy)(a);return{clip:(0,e.shouldClipShapeTextDocument)(a,o),wrapStrategy:o}}var D=class extends o.Shape{constructor(t,n){super(t,n),E(this,`_hyperLinkRegions`,[]),E(this,`_props`,void 0),E(this,`_formulaAnimation`,new e.FormulaShapeAnimationController(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),E(this,`_transformCalculateSrcRect`,!0),E(this,`_drawingType`,a.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(t){if(this._props.isEditing)return null;let n=this.getInverseCoord(t),{width:r,height:i}=this.getRealBound();return(0,e.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 t=this._props.shapeModel,n=t.getShapeTextData(),i=(0,e.normalizeShapeTextModel)(n==null?void 0:n.dataModel),a=i==null?void 0:i.doc,o=this._formulaAnimation.getAutoFitPresentations();if(!a||o.length===0)return;t.updateContext({width:this.width,height:this.height});let s=(0,e.resolveFormulaShapeAutoFitSize)({documentData:o.map(e=>(0,r.createShapeFormulaDocument)(a,e)),height:this.height,shapeData:t.getShapeData(),textRect:t.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 o.RENDER_CLASS_TYPE.SHAPE}_draw(e,t,r,i){let a=this._props.shapeModel;if(!a||!t)return;let o=r??this.width,s=i??this.height,c={shapeType:a.getShapeType(),width:o,height:s},l={renderMode:n.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(t,n,r){this._drawRichText(t,{...n,text:n.text??``,dataModel:{doc:(0,e.plainShapeTextToDocumentData)(n,`sheets-shape-text-${this.oKey}`)}},r)}_drawRichText(t,n,r){(0,e.drawFormulaShapeAnimationLayers)(t,this._formulaAnimation,(e,t,i)=>{this._drawRichTextLayer(e,n,r,t,i===`current`)})}_drawRichTextLayer(t,n,i,s,c){let l=this._props.localeService;if(!n.dataModel||!l)return;let u=(0,e.normalizeShapeTextModel)(n.dataModel);if(!u)return;let d=u.doc;if(!d)return;let f=(0,r.createShapeFormulaDocument)(d,s),p=u.va??a.VerticalAlign.TOP,m=u.ha??a.HorizontalAlign.LEFT,h=ne(this._props.shapeModel.getShapeData(),n,f),g=n.isHorizontal,_=(0,e.prepareShapeTextDocumentData)(f,{isHorizontal:g!==!1,textRect:i,verticalAlign:p,horizontalAlign:m,wrapStrategy:h.wrapStrategy}),v=new a.DocumentDataModel(_),y=new o.DocumentViewModel(v),b=o.DocumentSkeleton.create(y,l);b.calculate();let x=b.getActualSize().actualHeight,S=(0,e.resolveShapeTextDocumentRenderLayout)({contentHeight:x,verticalAlign:p,viewportHeight:i.height});v.updateDocumentStyle({pageSize:{width:g===!1?i.height:i.width,height:(0,e.resolveShapeTextDocumentPageHeight)(f,S.contentHeight)}}),v.updateDocumentDataMargin({t:S.marginTop}),b.calculate();let C=new o.Documents(`shape-text-${this.oKey}`,b,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});C.resize(i.width,S.contentHeight),t.save(),t.translateWithPrecision(i.left,i.top),h.clip&&(t.beginPath(),t.rect(0,S.clipTop,i.width,S.clipHeight),t.clip()),S.contentVerticalOffset&&t.translateWithPrecision(0,S.contentVerticalOffset),C.draw(t),c&&(this._hyperLinkRegions=(0,e.createShapeTextHyperLinkRegions)(C,{left:i.left,top:i.top+S.contentVerticalOffset},h.clip?{left:i.left,right:i.left+i.width,top:i.top+S.clipTop,bottom:i.top+S.clipTop+S.clipHeight}:void 0)),t.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:s}=this,c=this.getRealBound();if(r=c.width,i=c.height,a=c.left,s=c.top,this.isRender(t)){let{top:e,left:n,bottom:o,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+s<e||o<s)return this}let l=a+r/2,u=s+i/2,d=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new o.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(),s=t+r/2,c=n+i/2,l=new o.Transform([a[0],a[1],a[2],a[3],s,c]),u=this.getParent();return(this.isInGroup&&(u==null?void 0:u.classType)===o.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,s=n+i/2,c=this.transform.getMatrix(),l=new o.Transform([c[0],c[1],c[2],c[3],a,s]),u=this.getParent(),d=(this.isInGroup&&(u==null?void 0:u.classType)===o.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 o.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){o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.adjHandleSize,fill:n.ShapeDefaultConfig.adjHandleFill,stroke:n.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 a.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:o,transforms:s}=e;if(i===a.DrawingTypeEnum.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(o&&s?s:[r]).flatMap((r,i)=>{var a;let s=(0,u.getDrawingShapeKeyByDrawingSearch)(e,o?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 d=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return d&&(n==null||(a=n.resourceCollector)==null||a.add(d)),[l]})}_createShape(t,r,i,s){let{unitId:c,subUnitId:l,drawingId:u,groupId:d,hidden:p,selectable:m,prstGeom:h,srcRect:g}=t,_=this._sheetsShapeService.getShapeModel(c,l,u);if(!_)return;let v=this._drawingManagerService.getDrawingOrder(c,l),y=v.indexOf(u),b=(0,n.isConnectorShape)(_.getShapeType()),x=_.getShapeData().formulaBinding,S={unitId:c,subUnitId:l,shapeId:u};x&&this._shapeFormulaService.register(S,x);let C=new D(i,{...r,zIndex:y===-1?v.length-1:y,shapeModel:_,drawingType:a.DrawingTypeEnum.DRAWING_SHAPE,localeService:this._localeService,shapeId:u,unitId:c,subUnitId:l,visible:p!==!0,evented:m!==!1,formulaPresentation:x?this._shapeFormulaService.getPresentation(S):void 0,animateFormulaPresentation:(x==null?void 0:x.animationEnabled)!==!1,transformerConfig:{...e.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 s.addObject(C,o.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&s.attachTransformerTo(C),d&&(0,f.insertGroupObject)({drawingId:d,unitId:c,subUnitId:l},C,s,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(),r=t.fill;!r||r.fillType!==n.ShapeFillEnum.PictureFill||!r.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let r=t.fill;if(!r||r.fillType!==n.ShapeFillEnum.PictureFill||!r.fillImageSource)return;let i=r.fillImageSource,a=r.fillImageSourceType??n.ImageSourceTypeEnum.URL,o=this._imageIoService.getImageSourceCache(i,a);if(o)e.setFillImage(o);else return this._loadAndSetImage(e,i,a)}async _loadAndSetImage(e,t,r){let i;try{if(r===n.ImageSourceTypeEnum.UUID)i=await this._imageIoService.getImage(t);else if(r===n.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(n=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,r,a),e.setFillImage(a),n()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),n()},a.src=i})}};j=A([k(0,u.IDrawingManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,(0,a.Inject)(a.LocaleService)),k(3,a.IImageIoService),k(4,a.IURLImageService),k(5,(0,a.Inject)(r.ShapeFormulaService))],j);let M=class extends a.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(l.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:o}=i;if(!o||i.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let{left:s,top:c,width:u,height:d,flipX:f,flipY:p,angle:m=0}=o;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:u??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=(u||0)-r),p&&(i=(d||0)-i),m!==0){let e=(u||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,r,i,a,s,c){if(!this._activeShapeId)return;let l=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${r}`);if(l){l.transformByState({left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize});return}let u={left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize,adjName:r,shapeId:this._activeShapeId,unitId:s,subUnitId:c,width:n.ShapeDefaultConfig.adjHandleSize+8,height:n.ShapeDefaultConfig.adjHandleSize+8,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0},d=new O(`shape-adjust-point-${this._activeShapeId}-${r}`,u);this._shapes.push(d),this._attachAdjustEvent(d,e,r),e.addObject(d,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,a.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,s,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=!!((s=d.transform)!=null&&s.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(o.CURSOR_TYPE.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c=r/s+n.x-this._baseShapeLeft,l=i/s+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$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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!==i.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===a.DrawingTypeEnum.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===a.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)===a.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,u.IDrawingManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,(0,a.Inject)(o.IRenderManagerService)),k(3,(0,a.Inject)(j)),k(4,a.IUniverInstanceService),k(5,a.ICommandService)],M);const re={id:`drawing.operation.set-drawing-active`,type:a.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(u.IDrawingManagerService),r=e.get(o.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],o=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(o);if(c){var s;(s=r.getRenderUnitById(t[0].unitId))==null||(s=s.scene.getTransformer())==null||s.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},N={type:a.CommandType.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var u,d;let f=(0,s.getSheetCommandTarget)(e.get(a.IUniverInstanceService));if(!f)return!1;let{unitId:p,subUnitId:m,worksheet:h}=f,g=h.getConfig(),_=g.type??a.SheetTypes.GRID;if(_!==a.SheetTypes.GRID&&_!==a.SheetTypes.CHART)return!1;let v=e.get(a.IPermissionService);if(((u=v.getPermissionPoint(new s.WorkbookEditablePermission(p).id))==null?void 0:u.value)!==!0||((d=v.getPermissionPoint(new s.WorksheetEditPermission(p,m).id))==null?void 0:d.value)!==!0)return!1;let y=e.get(a.ICommandService),{value:b,enhanceParams:x}=t,S={unitId:p,subUnitId:m,shapeType:b,shapeId:(0,a.generateRandomId)()};if(_===a.SheetTypes.CHART){let t=e.get(o.IRenderManagerService).getRenderUnitById(p),n=t==null?void 0:t.components.get(l.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},s=(0,c.transformDrawingsToChartSheet)([{unitId:p,subUnitId:m,drawingId:S.shapeId,drawingType:a.DrawingTypeEnum.DRAWING_SHAPE,transform:{left:0,top:0,width:i.DEFAULT_SHAPE_WIDTH,height:i.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===a.BooleanNumber.TRUE);if(!(s!=null&&s.length))return!1;let u=s[0].transform;S.position={x:u.left,y:u.top},S.width=u.width,S.height=u.height}else{let t=e.get(s.SheetsSelectionsService).getCurrentLastSelection();if(!t)return!1;S.range=t.range}if(x){let{startArrow:t,endArrow:i,horizontal:o,vertical:s}=x,c=(0,n.isConnectorShape)(b),l=b===n.ShapeTypeEnum.Rect;if(c&&(t||i)&&(S.shapeData={ln:{startArrow:t?{type:n.ShapeArrowTypeEnum.Arrow,size:n.ShapeArrowSizeEnum.Medium}:void 0,endArrow:i?{type:n.ShapeArrowTypeEnum.Arrow,size:n.ShapeArrowSizeEnum.Large}:void 0}}),l&&(o||s)){let t=e.get(a.ThemeService);S.shapeData=(0,r.createShapeTextBoxShapeData)({fill:{fillType:n.ShapeFillEnum.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!o,stroke:{lineStrokeType:n.ShapeLineTypeEnum.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let C=y.syncExecuteCommand(i.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,a.createInternalEditorID)(`SHAPE_TEXT`),se=`sheet.shape.text.float-menu`,ce={id:`sheet.operation.open-shape-object-list-panel`,type:a.CommandType.COMMAND,handler:(e,n)=>{let r=e.get(t.ISidebarService),i=e.get(a.LocaleService),o=e.get(a.IUniverInstanceService),c=e.get(a.ICommandService);return(0,s.getSheetCommandTarget)(o)?(n==null?void 0:n.value)===`close`?(r.close(F),!0):(r.open({id:F,header:{title:i.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:F},onClose:()=>{c.syncExecuteCommand(u.SetDrawingSelectedOperation.id,[])},width:360}),!0):!1}},I={type:a.CommandType.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function le(e){let t=e.get(u.IDrawingManagerService).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)return null;let r=e.get(i.SheetsShapeService),o=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),s=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return o===void 0||!s?null:{drawing:n,shapeData:s,shapeType:o}}const ue={id:`sheet.operation.apply-shape-quick-style`,type:a.CommandType.OPERATION,handler:(e,t)=>{let n=le(e),i=(0,r.getShapeQuickStylePreset)((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!i||i.type!==(0,r.getShapeQuickStyleType)(n.shapeData))return!1;let o=(0,r.applyQuickStyleToShapeData)(n.shapeData,i);if(!o)return!1;let{drawing:s}=n;return e.get(a.ICommandService).executeCommand(S.id,{unitId:s.unitId,subUnitId:s.subUnitId,shapeId:s.drawingId,shapeData:o,oldShapeJSON:{oldShapeData:n.shapeData}})}},de={id:`sheet.operation.update-shape-type`,type:a.CommandType.OPERATION,handler:(e,t)=>{let i=le(e),o=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!i||!o||(0,n.isConnectorShape)(i.shapeType)||(0,n.isConnectorShape)(o))return!1;let s=(0,r.cloneShapeDataForType)(i.shapeData,o);if(!s)return!1;let{drawing:c}=i;return e.get(a.ICommandService).executeCommand(S.id,{unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.drawingId,shapeType:o,shapeData:s,replaceShapeData:!0,oldShapeJSON:{oldShapeType:i.shapeType,oldShapeData:i.shapeData}})}};let L=class extends a.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,r=e.registerClipDelegate((e,r,i,a,o)=>{let s=r;if(s===n.ShapeTypeEnum.None||r===`custom`)return!1;try{let c=t.get(r);return c||(c=new n.ShapeModel(s,`clip-${r}`),t.set(r,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(r),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,a.Inject)(f.DrawingImageClipService)),k(1,(0,a.Inject)(u.IDrawingManagerService))],L);const fe=`sheet.shape.picker.component`,pe=`sheet.image-clip.shape-picker.component`;function me({onShapeClick:t,excludeGroups:n}){return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerPanel,{excludeGroups:n,onShapeClick:t,scrollContainer:`parent`})}function he(){let n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(L);return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[e.ShapeGroupEnum.Line],onShapeClick:e=>{let t=n.getFocusDrawings().find(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE);if(!t)return;let{unitId:i,subUnitId:o,drawingId:s}=t;r.clipByShape(i,o,s,e.type)}})}function ge(){let n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(L);return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[e.ShapeGroupEnum.Line],DropdownComponent:p.MobileDropdown,onShapeClick:e=>{let t=n.getFocusDrawings().find(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE);if(!t)return;let{unitId:i,subUnitId:o,drawingId:s}=t;r.clipByShape(i,o,s,e.type)}})}function _e(){let e=(0,t.useDependency)(t.ComponentManager),n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(a.IUniverInstanceService),i=n.getFocusDrawings()[0],o=i?r.getUnitType(i.unitId):void 0,s=o===a.UniverInstanceType.UNIVER_DOC?`doc.image-clip.shape-picker.component`:o===a.UniverInstanceType.UNIVER_SHEET?pe:void 0,c=s?e.get(s):void 0;return c?/* @__PURE__ */ (0,m.jsx)(c,{}):null}function ve(){let e=(0,t.useDependency)(a.ICommandService);return/* @__PURE__ */ (0,m.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,m.jsx)(ve,{})}function be(e){return(0,l.deriveStateFromActiveSheet$)(e.get(a.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??a.SheetTypes.GRID;if(r===a.SheetTypes.GRID)return(0,l.getCurrentRangeDisable$)(e);if(r!==a.SheetTypes.CHART)return(0,d.of)(!0);let i=e.get(a.IPermissionService),o=[new s.WorkbookEditablePermission(t.getUnitId()).id,new s.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,d.startWith)(null),(0,d.map)(()=>o.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,d.distinctUntilChanged)())})}function xe(e){let n=e.get(a.IUniverInstanceService);return{id:N.id,type:t.MenuItemType.SELECTOR,selections:[{label:{name:fe,hoverable:!1,selectable:!1,props:{id:N.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:(0,l.deriveStateFromActiveSheet$)(n,!1,()=>new d.Observable(e=>{e.next(!1)})),hidden$:(0,t.getMenuHiddenObservable)(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:be(e)}}function Se(e){return(0,l.deriveStateFromActiveSheet$)(e.get(a.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??a.SheetTypes.GRID;if(r===a.SheetTypes.GRID)return(0,l.getCurrentRangeDisable$)(e);if(r!==a.SheetTypes.CHART)return(0,d.of)(!0);let i=e.get(a.IPermissionService),o=[new s.WorkbookEditablePermission(t.getUnitId()).id,new s.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,d.startWith)(null),(0,d.map)(()=>o.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,d.distinctUntilChanged)())})}function Ce(e){let n=e.get(t.ISidebarService);return{id:ce.id,type:t.MenuItemType.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:(0,d.defer)(()=>n.sidebarOptions$.pipe((0,d.startWith)(n.options),(0,d.map)(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),(0,d.distinctUntilChanged)())),hidden$:(0,t.getMenuHiddenObservable)(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:Se(e)}}const we=`sheet.menu.shape.flip-horizontal`,Te=`sheet.menu.shape.flip-vertical`;function Ee(e){let t=e.get(u.IDrawingManagerService).getFocusDrawings();return t.length===1&&t[0].drawingType===a.DrawingTypeEnum.DRAWING_SHAPE?t[0]:null}function De(e){let t=e.get(u.IDrawingManagerService);return t.focus$.pipe((0,d.startWith)(t.getFocusDrawings()),(0,d.map)(e=>e.length!==1||e[0].drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE))}function Oe(e){return{id:we,commandId:i.ToggleSheetsShapeFlipCommand.id,type:t.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:i.ToggleSheetsShapeFlipCommand.id,type:t.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}}}const 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 R(){let e=(0,t.useDependency)(a.ICommandService),n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(i.SheetsShapeService),o=()=>{var e;let t=n.getFocusDrawings();if(t.length!==1||((e=t[0])==null?void 0:e.drawingType)!==a.DrawingTypeEnum.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:o,drawingId:s}=t[0],c=r.getShapeTypeById(i,o,s),l=r.getShapeDataById(i,o,s);return c===void 0||!l?null:{unitId:i,subUnitId:o,drawingId:s,shapeType:c,shapeData:l}},s=(0,t.useObservable)(()=>new d.Observable(t=>{let r=()=>t.next(o()),a=n.focus$.subscribe(r),s=e.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&r()});return r(),()=>{a.unsubscribe(),s.dispose()}}),o(),!1,[e,n,r]);return{selection:s,updateShapeData:t=>{s&&C(e,s.unitId,s.subUnitId,s.drawingId,{oldShapeData:s.shapeData},t)}}}function Pe(){let{selection:t,updateShapeData:n}=R();return t?/* @__PURE__ */ (0,m.jsx)(e.ShapeStyleRibbonControl,{shapeData:t.shapeData,shapeType:t.shapeType,onUpdateShapeData:n}):null}function Fe(){let n=(0,t.useDependency)(a.ICommandService),i=(0,t.useDependency)(a.LocaleService),{selection:o}=R();return o?/* @__PURE__ */ (0,m.jsx)(e.ShapeQuickStyleGallery,{type:(0,r.getShapeQuickStyleType)(o.shapeData),ariaLabel:i.t(`sheets-shape-ui.quickStyles`),activePresetId:(0,r.resolveActiveShapeQuickStylePresetId)(o.shapeData),onSelect:e=>n.executeCommand(ue.id,{presetId:e})}):null}function Ie(){let{selection:t,updateShapeData:n}=R();return t?/* @__PURE__ */ (0,m.jsx)(e.ShapeTextRibbonControl,{fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:t.shapeData,onUpdateShapeData:n}):null}function Le(){var t;let{selection:n,updateShapeData:r}=R(),i=(0,e.useFormulaShapeToolbar)({hostType:a.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})}),o=((t=i.extensionGroups)==null?void 0:t.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return n!=null&&n.shapeData.formulaBinding?/* @__PURE__ */ (0,m.jsx)(e.ShapeFormulaRibbonControl,{actions:o,panel:i.panel}):null}const 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(a.ICommandService),n=e.get(u.IDrawingManagerService),o=e.get(i.SheetsShapeService);return new d.Observable(a=>{let s=()=>{let t=z(e),n=t?o.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;a.next(n?(0,r.resolveActiveShapeQuickStylePresetId)(n)??``:``)},c=n.focus$.subscribe(s),l=t.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function z(e){var t;let n=e.get(u.IDrawingManagerService).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE?n[0]:null}function B(e,t=!1){let n=e.get(a.ICommandService),r=e.get(u.IDrawingManagerService),o=e.get(i.SheetsShapeService);return new d.Observable(a=>{let s=()=>{let n=z(e);if(!n){a.next(!0);return}let r=o.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);a.next(!r||t&&r.formulaBinding==null)},c=r.focus$.subscribe(s),l=n.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function Ke(e){let t=e.get(u.IDrawingManagerService),r=e.get(i.SheetsShapeService);return t.focus$.pipe((0,d.startWith)(t.getFocusDrawings()),(0,d.map)(()=>{let t=z(e),i=t?r.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return i===void 0||(0,n.isConnectorShape)(i)}))}function qe(e){return{id:ue.id,type:t.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$:Ge(e),hidden$:B(e)}}function Je(n){return{id:de.id,type:t.MenuItemType.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:e.SHAPE_CHANGE_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],hidden$:Ke(n)}}function Ye(e,n,r=!1){return i=>({id:e,type:t.MenuItemType.BUTTON,label:{name:n,hoverable:!1,selectable:!1},hidden$:B(i,r)})}const Xe=Ye(Re,je),Ze=Ye(ze,Me),Qe=Ye(Be,Ne,!0);function $e(e,n,r,i){return a=>({id:e,commandId:c.SetDrawingArrangeCommand.id,type:t.MenuItemType.BUTTON,icon:r,title:i,tooltip:i,hidden$:B(a),params:()=>{let e=z(a);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:n}:void 0}})}const et=$e(Ve,a.ArrangeTypeEnum.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),tt=$e(He,a.ArrangeTypeEnum.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),nt=$e(Ue,a.ArrangeTypeEnum.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),rt=$e(We,a.ArrangeTypeEnum.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function it(e){let n=e.get(t.ISidebarService);return{activated$:(0,d.defer)(()=>n.sidebarOptions$.pipe((0,d.startWith)(n.options),(0,d.map)(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),(0,d.distinctUntilChanged)())),id:I.id,type:t.MenuItemType.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:B(e),params:()=>{let t=z(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}const at={[t.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:qe},[de.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Je}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[Re]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:104},menuItemFactory:Xe}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[ze]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:344},menuItemFactory:Ze}},"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},[Ve]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:et},[He]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:tt},[Ue]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:nt},[We]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:rt}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[Be]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:120},menuItemFactory:Qe}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[I.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:it},[e.ToggleShapeFloatingToolbarOperation.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:e.ShapeFloatingToolbarToggleFactory}}}}},ot={[t.RibbonInsertGroup.MEDIA]:{[N.id]:{order:3,menuItemFactory:xe}}},st={...ot,[t.RibbonInsertGroup.OTHERS]:{[ce.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Ce}},[t.ContextMenuPosition.DRAWING]:{[t.ContextMenuGroup.OTHERS]:{[we]:{order:4,menuItemFactory:Oe},[Te]:{order:5,menuItemFactory:ke}}}};var ct=`@univerjs-pro/sheets-shape-ui`,lt=`1.5.2`;const ut={id:`sheet.operation.open-mobile-shape-editor`,type:a.CommandType.OPERATION,handler(t,n){return n?(t.get(e.MobileShapeEditorService).open(n.mode,{hostType:a.UniverInstanceType.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},dt=`sheets-shape-ui.config`,ft={};let pt=class extends a.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,r,i){let a=e;if(a!==n.ShapeTypeEnum.None&&e!==`custom`)try{let o=new n.ShapeModel(a,`clip-adj-${e}`);return i&&o.setShapeData({adjustValues:i},!0),o.updateContext({width:t,height:r}),o}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),s=i.getObject(a);if(s instanceof o.Image){let e=s.prstGeom;if(e)return{prstGeom:e,adjustValues:s.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(l.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:u,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(u&&(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 l={x:r,y:i,adjName:t.adjName};this._addControl(n,l,l.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,r,i,a,s,c){if(!this._activeImageId)return;let l=`image-clip-adjust-point-${this._activeImageId}-${r}`,u=e.getObjectIncludeInGroup(l);if(u){u.transformByState({left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize});return}let d=new O(l,{left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize,adjName:r,shapeId:this._activeImageId,unitId:s,subUnitId:c,width:n.ShapeDefaultConfig.adjHandleSize+8,height:n.ShapeDefaultConfig.adjHandleSize+8,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._shapes.push(d),this._attachAdjustEvent(d,e,r),e.addObject(d,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,a.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,s,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=!!((s=f.transform)!=null&&s.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(o.CURSOR_TYPE.CROSSHAIR);let s={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(s,{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,s=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),c=a.getObject(s);if(c instanceof o.Image){let e=c.prstGeomAdjValues??{};c.setPrstGeomAdjValues({...e,...r}),c.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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 o.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===a.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)===a.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()}};pt=A([k(1,u.IDrawingManagerService),k(2,(0,a.Inject)(o.IRenderManagerService)),k(3,a.IUniverInstanceService),k(4,(0,a.Inject)(L))],pt);function mt({PanelComponent:n=f.ObjectListPanelBase}){var r;function i(e){return e.trim()||void 0}function s(t,n,r){var i;return((i=t.name)==null?void 0:i.trim())||`${r.t(`drawing-ui.objectListPanel.typeNames.${(0,e.getDrawingTypeNameKey)(t.drawingType)}`)} ${n+1}`}let l=(0,t.useDependency)(a.LocaleService),d={title:l.t(`drawing-ui.objectListPanel.title`),empty:l.t(`drawing-ui.objectListPanel.empty`),showAll:l.t(`drawing-ui.objectListPanel.showAll`),hideAll:l.t(`drawing-ui.objectListPanel.hideAll`),lockAll:l.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:l.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:l.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:l.t(`drawing-ui.objectListPanel.moveBackward`),close:l.t(`drawing-ui.objectListPanel.close`),show:l.t(`drawing-ui.objectListPanel.show`),hide:l.t(`drawing-ui.objectListPanel.hide`),lock:l.t(`drawing-ui.objectListPanel.lock`),unlock:l.t(`drawing-ui.objectListPanel.unlock`),lockHint:l.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:l.t(`drawing-ui.objectListPanel.unlockHint`),name:l.t(`drawing-ui.objectListPanel.name`),nameInput:l.t(`drawing-ui.objectListPanel.nameInput`),description:l.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:l.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:l.t(`drawing-ui.objectListPanel.details`),noSelection:l.t(`drawing-ui.objectListPanel.noSelection`),locate:l.t(`drawing-ui.objectListPanel.locate`),expand:l.t(`drawing-ui.objectListPanel.expand`),collapse:l.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:l.t(`drawing-ui.objectListPanel.dragToReorder`),search:l.t(`drawing-ui.objectListPanel.search`),filterAll:l.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:l.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:l.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:l.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:l.t(`drawing-ui.objectListPanel.sectionFloating`)},p=(0,t.useDependency)(a.ICommandService),h=(0,t.useDependency)(a.IUniverInstanceService),g=(0,t.useDependency)(c.ISheetDrawingService),_=(0,t.useDependency)(u.IDrawingManagerService),v=(0,t.useDependency)(o.IRenderManagerService),y=(0,t.useDependency)(t.ILayoutService),[,x]=(0,b.useReducer)(e=>e+1,0),S=h.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),C=(S==null?void 0:S.getUnitId())??``,w=(S==null||(r=S.getActiveSheet())==null?void 0:r.getSheetId())??``,T=(0,t.useObservable)(()=>_.focus$,_.getFocusDrawings(),!1,[_]);(0,b.useEffect)(()=>{let e=p.onCommandExecuted(()=>x());return()=>e.dispose()},[p]);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,f.getObjectListPanelSectionIdForDrawingType)(t.drawingType)]+=1,e),{canvas:0,floating:0}),ne={canvas:0,floating:0},D=te.map((e,t)=>{let n=(0,f.getObjectListPanelSectionIdForDrawingType)(e.drawingType),r=n===f.OBJECT_LIST_FLOATING_SECTION_ID,i=ne[n]++;return{id:e.drawingId,name:s(e,t,l),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:r?d.sectionFloating:d.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 p.executeCommand(c.SetSheetDrawingCommand.id,{unitId:C,drawings:e})},M=async(e,t)=>{A(e)&&await j([{unitId:C,subUnitId:w,drawingId:e,...t}])},re=(t,n)=>{if(!C||!w)return;let r=n?O.includes(t)?O.filter(e=>e!==t):[...O,t]:[t];p.syncExecuteCommand(u.SetDrawingSelectedOperation.id,r.map(e=>({unitId:C,subUnitId:w,drawingId:e})));let i=r[r.length-1];i?((0,e.activateDrawingObject)(v,{unitId:C,subUnitId:w,drawingId:i}),y.focus(C)):(0,e.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 p.executeCommand(c.SetDrawingArrangeCommand.id,{unitId:C,subUnitId:w,drawingIds:[e],arrangeType:t})};return!C||!w?/* @__PURE__ */ (0,m.jsx)(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:d.title}):/* @__PURE__ */ (0,m.jsx)(n,{labels:d,items:D,selectedIds:O,focusedId:k,showHeader:!1,onSelect:re,onSetVisible:N,onSetSelectable:P,onCommitName:ie,onCommitDescription:ae,onMoveForward:async e=>oe(e,a.ArrangeTypeEnum.forward),onMoveBackward:async e=>oe(e,a.ArrangeTypeEnum.backward),onToggleSelectable:F})}function ht(){return/* @__PURE__ */ (0,m.jsx)(mt,{PanelComponent:f.MobileObjectListPanel})}let gt=class extends a.Disposable{constructor(e,t){super(),this.disposeWithMe(e.register(F,ht)),this.disposeWithMe(t.register({BottomIcon:y.BottomIcon,FlipHorizontalIcon:y.FlipHorizontalIcon,FlipVerticalIcon:y.FlipVerticalIcon,MoveDownIcon:y.MoveDownIcon,MoveUpIcon:y.MoveUpIcon,ObjectLayersIcon:y.ObjectLayersIcon,ShapeFormatSettingIcon:y.ShapeFormatSettingIcon,TopmostIcon:y.TopmostIcon})),this.disposeWithMe(e.register(fe,ye)),this.disposeWithMe(e.register(pe,ge)),e.hasDefault(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(e.register(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,_e))}};gt=A([k(0,(0,a.Inject)(t.ComponentManager)),k(1,(0,a.Inject)(t.IconManager))],gt);let V=class extends a.Disposable{constructor(e){super(),this._permissionService=e,E(this,`_editingParams$`,new d.BehaviorSubject(null)),E(this,`editingParams$`,this._editingParams$.asObservable()),E(this,`_onSavingEditorData$`,new d.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 s.WorkbookEditablePermission(e.unitId).id),n=this._permissionService.getPermissionPoint(new s.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)}};V=A([k(0,a.IPermissionService)],V);let _t=class extends a.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:r,offsetY:i}=t,a=e.pick(o.Vector2.FromArray([r,i]));if(a instanceof D){let e=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);if((0,n.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 r=e[0],i=this._drawingManagerService.getDrawingByParam(r);if((i==null?void 0:i.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===r.drawingId&&e.visible)return;let i=(0,n.isConnectorShape)(this._sheetsShapeService.getShapeType(r.unitId,r.subUnitId,r.drawingId)),a=!!((t=this._sheetsShapeService.getShapeModel(r.unitId,r.subUnitId,r.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(a.FOCUSING_SHAPE_TEXT_EDITOR,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(a.FOCUSING_SHAPE_TEXT_EDITOR,!1)}))}};_t=A([k(1,(0,a.Inject)(a.Injector)),k(2,(0,a.Inject)(V)),k(3,u.IDrawingManagerService),k(4,a.IContextService),k(5,(0,a.Inject)(i.SheetsShapeService))],_t);var vt=class extends _t{_initEvents(){let{scene:t}=this._context,r=this._injector.get(e.MobileShapeEditorService);this.disposeWithMe(t.onDblclick$.subscribeEvent(e=>{let{offsetX:i,offsetY:s}=e,c=t.pick(o.Vector2.FromArray([i,s]));if(!(c instanceof D))return;let l=this._sheetsShapeService.getShapeModel(c.unitId,c.subUnitId,c.shapeId);(0,n.isConnectorShape)(this._sheetsShapeService.getShapeType(c.unitId,c.subUnitId,c.shapeId))||l!=null&&l.getShapeData().formulaBinding||r.open(`text`,{hostType:a.UniverInstanceType.UNIVER_SHEET,unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.shapeId})}))}};const yt={...ot};let H=class extends a.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(yt),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,e.bindRenderTransformerLifecycle)(this._renderManagerService,a.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(a.DrawingTypeEnum.DRAWING_SHAPE,(e,t,r,a)=>{let o=this._sheetsShapeService.getShapeTypeById(e,t,r),s=this._sheetsShapeService.getShapeDataById(e,t,r),l=o!==void 0&&!(0,n.isConnectorShape)(o)&&!(s!=null&&s.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:ut.id,commandParams:{unitId:e,subUnitId:t,drawingId:r,mode:`style`},disable:!1},...l?[{label:`sheets-shape-ui.editText`,index:1,commandId:ut.id,commandParams:{unitId:e,subUnitId:t,drawingId:r,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:c.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:r,drawingType:a}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:i.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:r,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:i.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:r,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new a.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(a.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 o=this._drawingManagerService.getDrawingOKey(i.oKey);if(!o||o.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE){r();return}let{unitId:s,subUnitId:c,drawingId:l}=o;n={unitId:s,subUnitId:c,drawingId:l},this._contextService.setContextValue(a.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,a.toDisposable)(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};H=A([k(0,t.IMenuManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,a.ICommandService),k(3,u.IDrawingManagerService),k(4,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(5,a.IContextService),k(6,o.IRenderManagerService),k(7,(0,a.Inject)(V))],H);function bt(e,t,n,r){let i=(0,u.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 a.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===s.RemoveSheetCommand.id){let t=(0,s.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,o=this._sheetDrawingService.getDrawingData(n,r),c=Object.values(o).filter(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=[],u=[];for(let e=0;e<c.length;e++){let t=c[e],a=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);a&&(l.push({id:i.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),u.push({id:i.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:a.getShapeType(),shapeData:JSON.parse(JSON.stringify(a.getShapeData()))}}))}return{redos:l,undos:u}}if(e.id===s.CopySheetCommand.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:o}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let s=this._sheetDrawingService.getDrawingData(t,n),c=Object.values(s).filter(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=bt(o,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:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),d.push({id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:u,undos:d}}return{redos:[],undos:[]}}}))}};U=A([k(0,(0,a.Inject)(a.IUniverInstanceService)),k(1,(0,a.Inject)(s.SheetInterceptorService)),k(2,(0,a.Inject)(c.ISheetDrawingService)),k(3,(0,a.Inject)(i.SheetsShapeService))],U);let W=class extends a.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===i.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=(0,u.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===i.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,u.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),d=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(l.SheetSkeletonManagerService).getSkeleton(i)))return!1;if(d)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:o,drawingType:s,srcRect:c,prstGeom:l}=i;if(s!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;let{scene:f,transformer:p}=d;if(o==null)return!0;let m=(0,u.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 r of e){var t;let{unitId:e,subUnitId:i,drawingId:o}=r,s=this._getSceneAndTransformerByDrawingSearch(e),c=(t=(0,f.getCurrentUnitInfo)(this._currentUniverService,e))==null?void 0:t.subUnitId;if(s==null||c!==i)continue;let l=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:i,drawingId:o});if(this._insertingShapeKeys.has(l)||s.scene.getObjectIncludeInGroup(l)!=null)continue;let d=this._drawingManagerService.getDrawingByParam(r);if(d==null||d.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let p=d.data||{};if((0,n.isConnectorShape)(p.shapeType)){let e=d.transform;e&&(d.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(l);try{this._sheetDrawingShapeRenderController.renderDrawingShape(d,s.scene)}finally{this._insertingShapeKeys.delete(l)}queueMicrotask(()=>{if(this._disposed)return;let e=(0,u.getDrawingShapeKeyByDrawingSearch)(r);if(!s.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(r);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,a.ICommandService),k(1,o.IRenderManagerService),k(2,u.IDrawingManagerService),k(3,a.IUniverInstanceService),k(4,(0,a.Inject)(f.DrawingRenderService)),k(5,(0,a.Inject)(j))],W);const xt={normal:{fill:n.ShapeDefaultConfig.cxnPointFill,stroke:n.ShapeDefaultConfig.cxnPointStroke,strokeWidth:n.ShapeDefaultConfig.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var St=class extends o.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??n.ShapeDefaultConfig.cxnPointRadius*2,height:e.height??n.ShapeDefaultConfig.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?xt.highlighted:xt.normal;o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let G=class extends a.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 r of Object.keys(t)){if(r===this._draggingConnectorId||t[r].drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,r);if(!i||(0,n.isConnectorShape)(i.getShapeType())||i.getConnectionSiteList().length===0||!this._currentScene)continue;let s=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:r}),c=this._currentScene.getObjectIncludeInGroup(s);if(!c)continue;let{left:l,top:d,width:f,height:p}=c.getRealBound(),m=l+f/2,h=d+p/2,g=c.transform.getMatrix(),_=new o.Transform([g[0],g[1],g[2],g[3],m,h]),v=c.getParent(),y=(c.isInGroup&&(v==null?void 0:v.classType)===o.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:r,shapeModel:i}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let r=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),i=this._currentScene.getObjectIncludeInGroup(r);if(!i)return;let{left:a,top:s,width:c,height:l}=i.getRealBound(),d=a+c/2,f=s+l/2,p=i.transform.getMatrix(),m=new o.Transform([p[0],p[1],p[2],p[3],d,f]),h=i.getParent(),g=i.isInGroup&&(h==null?void 0:h.classType)===o.RENDER_CLASS_TYPE.GROUP?h.ancestorTransform.multiply(m):m;t.updateContext({width:c,height:l});let _=t.getConnectionSiteList();for(let t of _){let r=t.x-c/2,i=t.y-l/2,a=g.applyPoint({x:r,y:i}),s=a.x,u=a.y,d=new St(`connection-site-${e}-${t.index}`,{left:s-n.ShapeDefaultConfig.cxnPointRadius,top:u-n.ShapeDefaultConfig.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:n.ShapeDefaultConfig.cxnPointRadius*2,height:n.ShapeDefaultConfig.cxnPointRadius*2,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+2,evented:!1});this._connectionSiteObjects.push(d),this._currentScene.addObject(d,o.DRAWING_OBJECT_LAYER_INDEX+2)}}_findNearestConnectionSite(e){let t=null,r=1/0,i=null;for(let a of this._connectionSiteObjects){let o=a.left+n.ShapeDefaultConfig.cxnPointRadius,s=a.top+n.ShapeDefaultConfig.cxnPointRadius,c=e.x-o,l=e.y-s,u=Math.sqrt(c*c+l*l);u<r&&(r=u,t=a,i={x:o,y:s})}let a=r<=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(r<=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,a.Inject)(o.IRenderManagerService)),k(2,(0,a.Inject)(u.IDrawingManagerService)),k(3,(0,a.Inject)(i.SheetsShapeService))],G);let K=class extends a.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:a})=>{let o=[],s=[];for(let[u,d]of a.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||a.has(e),r=!t||a.has(t);n&&e&&m.relation.from?m.relation.from={...m.relation.from,shapeId:a.get(e)}:m.relation.from=void 0,r&&t&&m.relation.to?m.relation.to={...m.relation.to,shapeId:a.get(t)}:m.relation.to=void 0}o.push({id:i.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d,shapeType:p,shapeData:m}}),s.push({id:i.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===a.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===l.PREDEFINED_HOOK_NAME.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===l.COPY_TYPE.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let o=(0,s.attachRangeWithCoord)(i,n);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._sheetDrawingService.getDrawingData(e,t),p=[];for(let[e,t]of Object.entries(f)){if(t.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:o=0}=e;c<=n&&l>=n+i&&u<=r&&d>=r+o&&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:o,range:c}=e,l=this._copyInfo,u=(n=this._instances.getUnit(l.unitId,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(l.subUnitId),d=(r=this._instances.getUnit(i,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(o),f=(u==null?void 0:u.getConfig().type)??a.SheetTypes.GRID,p=(d==null?void 0:d.getConfig().type)??a.SheetTypes.GRID;if(f===a.SheetTypes.CHART||p===a.SheetTypes.CHART)return this._generateChartSheetCopy(e,t);let m=this._sheetSkeletonService.getSkeleton(i,o);if(!m)return{redos:[],undos:[]};let h=(0,s.discreteRangeToRange)(c),{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,a.generateRandomId)());let C=[],w=[];for(let e of y){let{drawingId:n,transform:r,sheetTransform:a}=e;if(!r||!a)continue;let s=this._updateTransform({transform:r,sheetTransform:a},{skeleton:b,range:v},{skeleton:m,range:h},x);if(t){let{redos:t,undos:n}=this._generateCutPasteMutations({fromUnitId:g,fromSubUnitId:_,toUnitId:i,toSubUnitId:o,drawing:e,newTransforms:s});C.push(...t),w.push(...n);continue}let{redos:c,undos:l}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:o,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 a.CustomCommandExecutionError(l.SheetPasteCommand.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},r,i))throw new a.CustomCommandExecutionError(l.SheetPasteCommand.id);let o=(n=this._instances.getUnit(r,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),u=o==null?void 0:o.getConfig(),d=(u==null?void 0:u.type)??a.SheetTypes.GRID,f=this._copyInfo,p=f.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[s.WorkbookCopyPermission],worksheetTypes:[s.WorksheetCopyPermission]},f.unitId,f.subUnitId)||p.some(e=>e.groupId||!this._shapeService.getShapeModel(f.unitId,f.subUnitId,e.drawingId)||!a.Tools.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new a.CustomCommandExecutionError(l.SheetPasteCommand.id);let m=null;if(d===a.SheetTypes.CHART){var h;let e=(h=this._renders.getRenderUnitById(r))==null?void 0:h.components.get(l.SHEET_VIEW_KEY.CHART_PAGE);e&&(m=(0,c.transformDrawingsToChartSheet)(p,{left:e.left,top:e.top,width:e.width,height:e.height},(u==null?void 0:u.rightToLeft)===a.BooleanNumber.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&(0,s.attachRangeWithCoord)(t,(0,s.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,c.applySheetDrawingPlacement)(i,{kind:c.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 a.CustomCommandExecutionError(l.SheetPasteCommand.id);let g=new Map(p.map(e=>[e.drawingId,(0,a.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:a,drawing:o,newTransforms:s}=e,l={...o,unitId:r,subUnitId:a,...s};if(r===t&&a===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([l]);return{redos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.UPDATE,op:e,objects:n}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([o]),s=this._sheetDrawingService.getBatchAddOp([l]),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:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.REMOVE,op:e.redo,objects:e.objects}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId}},{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.INSERT,op:s.redo,objects:s.objects}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:r,subUnitId:a,shapeId:o.drawingId,shapeType:d,shapeData:f}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.INSERT,op:e.undo,objects:e.objects}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId,shapeType:d,shapeData:f}},{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.REMOVE,op:s.undo,objects:s.objects}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:r,subUnitId:a,shapeId:o.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:a,newDrawingId:o,idMap:s}=e,l={...r,unitId:t,subUnitId:n,drawingId:o,...a},{redo:u,undo:d,objects:f}=this._sheetDrawingService.getBatchAddOp([l]),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:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.INSERT,op:u,objects:f}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o,shapeType:m,shapeData:h}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.REMOVE,op:d,objects:f}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:l}=n,{transform:u,sheetTransform:d}=e,f={...u};if(i){let e=(0,s.attachRangeWithCoord)(a,i),t=(0,s.attachRangeWithCoord)(l,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,s.attachRangeWithCoord)(l,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,c.transformToDrawingPosition)(f,l)??d}}};K=A([k(0,(0,a.Inject)(s.SheetSkeletonService)),k(1,(0,a.Inject)(l.ISheetClipboardService)),k(2,(0,a.Inject)(c.ISheetDrawingService)),k(3,(0,a.Inject)(i.SheetsShapeService)),k(4,(0,a.Inject)(v.SheetsDrawingGroupCopyPasteController)),k(5,a.IUniverInstanceService),k(6,o.IRenderManagerService),k(7,(0,a.Inject)(s.SheetPermissionCheckController))],K);var Ct=class extends o.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){o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.cxnPointRadius,fill:n.ShapeDefaultConfig.cxnPointFill,stroke:n.ShapeDefaultConfig.cxnPointStroke,strokeWidth:n.ShapeDefaultConfig.cxnPointStrokeWidth,evented:!0})}};let wt=class extends a.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(l.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:t}=e,r=this._getDrawingRect();if(!r)return;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!i||!(0,n.isConnectorShape)(i.getShapeType()))return;let a=i.getConnectorLinePoints();if(a.length<2)return;let o=new n.ConnectorCoordinateTransform(r),s=a[0],c=a[a.length-1],u=o.localToWorld(s),d=o.localToWorld(c);this._addShapeConnectorHandlerObject(t,{...u},!0),this._addShapeConnectorHandlerObject(t,{...d},!1)}_addShapeConnectorHandlerObject(e,t,r){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let i=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${r?`start`:`end`}`,a=e.getObjectIncludeInGroup(i);if(a){a.transformByState({left:t.x-n.ShapeDefaultConfig.cxnPointRadius,top:t.y-n.ShapeDefaultConfig.cxnPointRadius});return}let s=new Ct(i,{left:t.x-n.ShapeDefaultConfig.cxnPointRadius,top:t.y-n.ShapeDefaultConfig.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:r,width:n.ShapeDefaultConfig.cxnPointRadius*2,height:n.ShapeDefaultConfig.cxnPointRadius*2,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._connectorObjects.push(s),this._attachConnectorObjectEvent(s,e,r),e.addObject(s,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,r,i,a,o){let s=o===n.ShapeTypeEnum.Line||o===n.ShapeTypeEnum.StraightConnector1,c=r?t:e,l=r?e:t,u=this._activeShapeModel.getConnectorLinePoints(),d=this._activeShapeModel.getShapeType(),f=(0,n.isCurvedConnectorShape)(d),p=n.ConnectorCoordinateTransform.getBentTypeFromPoints(u,f),m=s?n.ConnectorCoordinateTransform.computeStraightConnectorLayout(c,l):n.ConnectorCoordinateTransform.computeConnectorResizeLayout(e,t,r,p);i?this._executeConnectionCommand(m,i,r,a):this._executeResizeCommand(m,a)}_handleConnectedEndpointPointerUp(e,t,r,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:r=0,width:i=0,height:a=0,angle:o}=e.transform;c=(0,n.getBasicShapeRotateBound)({left:t,top:r,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=r?l:o,d=r?o:l,f=this._activeShapeModel.getShapeType(),p=(0,n.routeConnectorLineShape)(u,d,f);this._activeShapeModel.removeLinePoints();let m=(0,n.computeConnectorRouteLayout)(p,f);i?this._executeConnectedRouteConnectionCommand(m,i,e,r,a):this._executeConnectedRouteResizeCommand(m,e,r,a)}_executeConnectionCommand(e,t,r,a){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?s.from=c:s.to=c;let l=this._activeShapeModel.getShapeType(),u=(0,n.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:a,oldRelation:o,newRelation:s,newLineType:u.lineType,oldLineType:l};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,d)}_executeResizeCommand(e,t){let r=this._activeShapeModel.getShapeType(),a=(0,n.computeConnectorRouteLayout)(e.worldPoints,r),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:a.adjustValues,oldAdjustValues:t,newLineType:a.lineType,oldLineType:r};this._commandService.executeCommand(i.UpdateLineShapeResizeCommand.id,o)}_executeConnectedRouteConnectionCommand(e,t,n,r,a){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:a,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:o,newRelation:s};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,l)}_executeConnectedRouteResizeCommand(e,t,n,r){let a=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:a,newRelation:o};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,s)}_attachConnectorObjectEvent(e,t,r){this.disposeWithMe((0,a.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 n.ConnectorCoordinateTransform(this._baseDrawingRect),d=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),f=t.getObjectIncludeInGroup(d);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=r?l.localToWorld(h):l.localToWorld(m);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((n,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:n.offsetX/o+a.x,y:n.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,u.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,r,f,e):this._handleFreeEndpointMove(s,g,r,f,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{this._handleConnectorPointerUp(t,g,e,r,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,d=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:r}),f=a.getObjectIncludeInGroup(d);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,r,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,n.routeConnectorLineShape)(u,d,f);p&&i.updateLinePoints(p);let m=(0,n.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,r,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 n.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=n.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$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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===a.DrawingTypeEnum.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&(0,n.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===a.DrawingTypeEnum.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===a.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,r,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:r=0,width:i=0,height:a=0,angle:o}=e.transform;u=(0,n.getBasicShapeRotateBound)({left:t,top:r,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=r?d:s,p=r?s:d,m=this._activeShapeModel.getShapeType(),h=(0,n.routeConnectorLineShape)(f,p,m);h&&this._activeShapeModel.updateLinePoints(h);let g=(0,n.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-n.ShapeDefaultConfig.cxnPointRadius,top:_.y-n.ShapeDefaultConfig.cxnPointRadius})}_handleFreeEndpointMove(e,t,r,i,a){var o,s;let c=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e,l=n.ConnectorCoordinateTransform.computeConnectorResizeLayout(t,c,r);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-n.ShapeDefaultConfig.cxnPointRadius,top:u.y-n.ShapeDefaultConfig.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:r}=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===r);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,n.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()}};wt=A([k(1,a.ICommandService),k(2,o.IRenderManagerService),k(3,u.IDrawingManagerService),k(4,a.IUniverInstanceService),k(5,(0,a.Inject)(i.SheetsShapeService)),k(6,(0,a.Inject)(M)),k(7,(0,a.Inject)(G))],wt);let q=class extends a.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:o,scene:s,resourceCollector:c}=t,l=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[o];return l==null||l.order.forEach(e=>{let t=l.data[e];t.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,s,{resourceCollector:c})}),n(e)}}))}};q=A([k(0,(0,a.Inject)(l.SheetPrintInterceptorService)),k(1,u.IDrawingManagerService),k(2,(0,a.Inject)(j))],q);let J=class extends a.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,i.ToggleSheetsShapeFlipCommand.id,i.SetSheetsShapeRotateCommand.id,i.SetSheetsShapeTextVerticalToggleCommand.id,i.UpdateLineShapeResizeCommand.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===i.InsertShapeCommand.id||t.id===i.SetShapeDrawingDataCommand.id||t.id===i.UpdateConnectorRelationCommand.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=(0,s.getSheetCommandTarget)(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==a.SheetTypes.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};J=A([k(0,(0,a.Inject)(a.ICommandService)),k(1,(0,a.Inject)(a.IUniverInstanceService)),k(2,(0,a.Inject)(a.LocaleService)),k(3,(0,a.Inject)(s.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,u.getDrawingShapeKeyByDrawingSearch)(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};Y=A([k(0,o.IRenderManagerService)],Y);let X=class extends a.Plugin{constructor(e=ft,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...o}=(0,a.merge)({},ft,this._config);this._configService.setConfig(dt,o),this._initCommands()}onStarting(){this._injector.add([gt]),this._injector.get(gt),(0,a.registerDependencies)(this._injector,[[H],[W],[j],[q],[Y],[V],[U],[L],[J]])}onReady(){(0,a.registerDependencies)(this._injector,[[G],[M],[K]]),(0,a.touchDependencies)(this._injector,[[K],[M]]),[[G],[pt],[wt],[vt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,e))})}onRendered(){(0,a.touchDependencies)(this._injector,[[H],[W],[j],[q],[Y],[V],[U],[L],[J]])}onSteady(){this._injector.get(H).initShapePopupMenu()}_initCommands(){[N,S,re,ut].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E(X,`type`,a.UniverInstanceType.UNIVER_SHEET),E(X,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E(X,`packageName`,ct),E(X,`version`,lt),X=A([(0,a.DependentOn)(h.UniverLicensePlugin,g.UniverDocsPlugin,u.UniverDrawingPlugin,o.UniverRenderEnginePlugin,s.UniverSheetsPlugin,_.UniverDocsUIPlugin,c.UniverSheetsDrawingPlugin,r.UniverShapeEditorPlugin,v.UniverSheetsDrawingMobileUIPlugin,i.UniverSheetsShapePlugin,l.UniverSheetsMobileUIPlugin,e.UniverShapeEditorMobileUIPlugin,t.UniverMobileUIPlugin),k(1,(0,a.Inject)(a.Injector)),k(2,a.ICommandService),k(3,a.IConfigService),k(4,o.IRenderManagerService)],X);const Tt={type:a.CommandType.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function Et(){let e=(0,t.useDependency)(u.IDrawingManagerService),n=(0,t.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return n.length===0?null:/* @__PURE__ */ (0,m.jsx)(`div`,{children:/* @__PURE__ */ (0,m.jsxs)(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ (0,m.jsx)(f.DrawingCommonPanel,{drawings:n,hasCropper:!1}),/* @__PURE__ */ (0,m.jsx)(v.SheetDrawingAnchor,{drawings:n})]})})}function Dt(n){let{unitId:r,subUnitId:i,shapeId:o}=n,s=(0,t.useDependency)(a.ICommandService),c=(0,t.useDependency)(Y);return/* @__PURE__ */ (0,m.jsx)(e.ShapeEditPanel,{...n,positionEditor:/* @__PURE__ */ (0,m.jsx)(Et,{}),onUpdateShapeData:(e,t)=>{C(s,r,i,o,e,t)},onUpdateLineShapeData:(e,t)=>{w(s,r,i,o,e,t)},onUpdateShapeFillImage:e=>{c.updateShapeFillImage({unitId:r,subUnitId:i,drawingId:o},e)}})}function Ot(n){let r=(0,t.useDependency)(e.ShapeFloatingToolbarService),i=(0,t.useObservable)(()=>r.visible$,r.getVisible(),!1,[r]),a=n.popup.extraProps;return!a||!i?null:/* @__PURE__ */ (0,m.jsx)(kt,{...a,canvasElement:n.popup.canvasElement})}function kt(r){let o=(0,t.useDependency)(a.ICommandService),s=(0,t.useDependency)(i.SheetsShapeService),{unitId:l,subUnitId:u,drawingId:d,drawingType:f,shapeType:p}=r,[h,g]=(0,b.useState)(r.shapeData),_=(0,b.useMemo)(()=>(0,e.getTextStyle)(h),[h]),v=(0,b.useMemo)(()=>(0,e.getTextModel)(h),[h]);(0,b.useEffect)(()=>{let e=o.onCommandExecuted(e=>{if(e.id!==i.UpdateSheetsShapeDataMutation.id)return;let t=s.getShapeDataById(l,u,d);t&&g(t)});return()=>e.dispose()},[o,d,s,u,l]);let y=e=>{g(t=>({...t,...e}))},x=t=>{let n=(0,e.buildShapeTextDataUpdate)(h,t);C(o,l,u,d,{oldShapeData:{shapeText:h.shapeText}},n),y(n)},S=(0,e.useFormulaShapeToolbar)({hostType:a.UniverInstanceType.UNIVER_SHEET,unitId:l,subUnitId:u,shapeId:d,shapeData:h,onUpdateBinding:e=>{let t={formulaBinding:e};C(o,l,u,d,{oldShapeData:{formulaBinding:h.formulaBinding}},t),y(t)}});return/* @__PURE__ */ (0,m.jsxs)(m.Fragment,{children:[/* @__PURE__ */ (0,m.jsx)(e.ShapeFloatingToolbar,{canvasElement:r.canvasElement,shapeData:h,shapeType:p,textStyle:{ff:n.ShapeDefaultConfig.shapeText.fontFamily,fs:n.ShapeDefaultConfig.shapeText.fontSize,cl:{rgb:n.ShapeDefaultConfig.shapeText.color},..._},textModel:v?{ha:v.ha??a.HorizontalAlign.LEFT,va:v.va??a.VerticalAlign.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:n.ShapeDefaultConfig.fill,defaultGradientEndColor:n.ShapeDefaultConfig.gradientEndColor,defaultStrokeColor:n.ShapeDefaultConfig.stroke,extensionGroups:S.extensionGroups,floatingObjectToolbarPosition:t.FloatingObjectToolbarPosition.SHEET,onUpdateShapeData:(e,t)=>{C(o,l,u,d,e,t),t&&y(t)},onUpdateText:x,onOpenPanel:()=>{o.executeCommand(I.id,{unitId:l,subUnitId:u,drawingId:d})},onDelete:()=>{o.executeCommand(c.RemoveSheetDrawingCommand.id,{unitId:l,drawings:[{unitId:l,subUnitId:u,drawingId:d,drawingType:f}]})}}),S.panel]})}function At(e){return!!e&&`axisAlignSheetTransform`in e&&`sheetTransform`in e}const jt=(0,b.memo)(()=>{let n=(0,t.useDependency)(V),r=(0,t.useDependency)(i.SheetsShapeService),s=(0,t.useDependency)(u.IDrawingManagerService),d=(0,t.useDependency)(a.ICommandService),f=(0,t.useDependency)(t.UndoRedoGroupService),p=(0,t.useDependency)(o.IRenderManagerService),h=(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=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n});return r==null?void 0:r.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:n,shapeText:r,oldShapeText:i,hostSize:a})=>{f.run(e,()=>{var o;let u=d.syncExecuteCommand(S.id,{unitId:e,subUnitId:t,shapeId:n,shapeData:{shapeText:r},oldShapeJSON:{oldShapeData:{shapeText:i}}});if(!u||!a)return u;let f=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),m=f==null?void 0:f.transform;if(!At(f)||!m)return!1;let h={...m,width:a.width,height:a.height},g=(o=p.getRenderUnitById(e))==null||(o=o.with(l.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:o.skeleton;return d.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...f,transform:h,sheetTransform:g?(0,c.transformToDrawingPosition)(h,g)??f.sheetTransform:f.sheetTransform,axisAlignSheetTransform:g?(0,c.transformToAxisAlignPosition)(h,g)??f.axisAlignSheetTransform:f.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:n,width:r,height:i})=>{var a;let o=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=o==null?void 0:o.transform;if(!At(o)||!u)return;let f={...u,width:r,height:i},m=(a=p.getRenderUnitById(e))==null||(a=a.with(l.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:a.skeleton,h=m?(0,c.transformToDrawingPosition)(f,m)??o.sheetTransform:o.sheetTransform,g=m?(0,c.transformToAxisAlignPosition)(f,m)??o.axisAlignSheetTransform:o.axisAlignSheetTransform;d.executeCommand(c.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...o,transform:f,sheetTransform:h,axisAlignSheetTransform:g}]})},allowHostSizeShrink:({unitId:t,subUnitId:n,shapeId:i})=>(0,e.shouldAllowShapeTextEditorHostSizeShrink)(r.getShapeDataById(t,n,i)),deferHostSizeUpdateDuringEditing:()=>!0}),[d,s,p,r,f]),g=(0,b.useMemo)(()=>({viewportKeys:{main:o.SHEET_VIEWPORT_KEY.VIEW_MAIN,leftTop:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,top:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,left:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(l.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ (0,m.jsx)(e.ShapeTextEditorContainer,{adapter:h,editingService:n,editorUnitId:oe,positionOptions:g})});let Mt=class extends a.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:y.ObjectLayersIcon})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:y.FlipHorizontalIcon})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:y.FlipVerticalIcon})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:y.BottomIcon})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:y.MoveDownIcon})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:y.MoveUpIcon})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:y.ShapeFormatSettingIcon})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:y.TopmostIcon}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(P,Dt)),this.disposeWithMe(this._componentManager.register(F,mt)),this.disposeWithMe(this._componentManager.register(fe,ve)),this.disposeWithMe(this._componentManager.register(pe,he)),this._componentManager.hasDefault(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(this._componentManager.register(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,_e)),this.disposeWithMe(this._componentManager.register(ie,Ot)),this.disposeWithMe(this._componentManager.register(je,Pe)),this.disposeWithMe(this._componentManager.register(Ae,Fe)),this.disposeWithMe(this._componentManager.register(Me,Ie)),this.disposeWithMe(this._componentManager.register(Ne,Le)),this.disposeWithMe(this._componentManager.register(se,e.ShapeTextFloatToolbar)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,jt))}};Mt=A([k(0,(0,a.Inject)(t.ComponentManager)),k(1,(0,a.Inject)(t.IconManager))],Mt);let Nt=class extends a.Disposable{constructor(t,n,r,i,c,l,u,f,p){super();let m=e=>{var t,n;return(((t=f.getPermissionPoint(new s.WorkbookEditablePermission(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=f.getPermissionPoint(new s.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 e=c.getFocusDrawings(),n=e.length===1?e[0]:null;return(n==null?void 0:n.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE&&n.unitId===t.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe((0,e.registerShapeFormatPainter)(t,n,{changes$:(0,d.merge)(c.focus$,i.editingParams$,f.permissionPointUpdate$),isActive:()=>{var e;return((e=l.getFocusedUnit())==null?void 0:e.getUnitId())===t.unitId&&!u.getContextValue(a.FOCUSING_SHAPE_TEXT_EDITOR)&&c.getFocusDrawings().some(e=>e.unitId===t.unitId)},getSelectedTarget:g,getSource:()=>{let e=g();return e?h(e):null},getTarget:e=>{let n=t.scene.pick(new o.Vector2(e.offsetX,e.offsetY));if(!(n instanceof D))return null;let r={unitId:t.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}})}))}};Nt=A([k(1,(0,a.Inject)(t.FormatPainterSessionService)),k(2,(0,a.Inject)(i.SheetsShapeService)),k(3,(0,a.Inject)(V)),k(4,u.IDrawingManagerService),k(5,a.IUniverInstanceService),k(6,a.IContextService),k(7,a.IPermissionService),k(8,a.ICommandService)],Nt);const Pt=`sheets-shape-contextual-ribbon`;let Z=class extends a.Disposable{constructor(e,t,n,r,i,o){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=o,E(this,`_visible`,!1),this._menuManagerService.mergeMenu(at),this.disposeWithMe((0,a.toDisposable)(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,Pt),this._hide(),super.dispose()}_update(){var t;let n=this._drawingManagerService.getFocusDrawings(),r=n.length===1?n[0]:void 0;if((r==null?void 0:r.drawingType)!==a.DrawingTypeEnum.DRAWING_SHAPE||this._univerInstanceService.getUnitType(r.unitId)!==a.UniverInstanceType.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,Pt),this._hide();return}let i=(t=this._renderManagerService.getRenderUnitById(r.unitId))==null?void 0:t.engine.getCanvasElement(),o=(0,e.resolveShapeContextualRibbonHostMode)(i)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(o,Pt),o?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,t.IMenuManagerService),k(1,t.IRibbonService),k(2,u.IDrawingManagerService),k(3,a.IUniverInstanceService),k(4,o.IRenderManagerService),k(5,(0,a.Inject)(e.ShapeFloatingToolbarService))],Z);let Ft=class extends e.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})}};Ft=A([k(1,(0,a.Inject)(g.DocSelectionManagerService)),k(2,(0,a.Inject)(_.DocCanvasPopManagerService)),k(3,(0,a.Inject)(_.DocSelectionRenderService)),k(4,a.ICommandService),k(5,(0,a.Inject)(_.DocEventManagerService)),k(6,(0,a.Inject)(e.ShapeTextHyperLinkPopupService)),k(7,(0,a.Inject)(g.DocInterceptorService)),k(8,(0,a.Inject)(_.DocRenderController)),k(9,(0,a.Inject)(V))],Ft);let It=class extends e.ShapeTextHyperLinkHoverController{constructor(t,n,r,i,a){super(t,n,{editing$:r.editingParams$,resolve:r=>{var c,l,u;let d=new o.Vector2(r.offsetX,r.offsetY),f=((c=t.scene.getActiveViewportByCoord(d))==null?void 0:c.transformVector2SceneCoord(d))??d,p=(0,e.resolveShapeTextHyperLinkObject)(t.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:e.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 s.WorkbookCopyPermission(p.unitId).id))==null?void 0:l.value)!==!1&&((u=a.getPermissionPoint(new s.WorksheetCopyPermission(p.unitId,p.subUnitId).id))==null?void 0:u.value)!==!1},attachPopup:()=>i.attachPopupToObject(h,g)}}}),this.disposeWithMe(t.unit.activeSheet$.subscribe(()=>this.clear()))}};It=A([k(1,(0,a.Inject)(e.ShapeTextHyperLinkPopupService)),k(2,(0,a.Inject)(V)),k(3,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(4,a.IPermissionService)],It);let Q=class extends a.Disposable{constructor(e,t,n,r,i,o,s,c,l,u,d){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=o,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$(a.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(st)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,e.bindRenderTransformerLifecycle)(this._renderManagerService,a.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(t){let n=new a.DisposableCollection;return n.add(t.createControl$.subscribe(()=>{let n=t.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!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:o,subUnitId:s,drawingId:c,drawingType:u}=i,d=this._getShapeInfo(o,s,c);if(!d)return;this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0);let f=this._renderManagerService.getRenderUnitById(o),p=((f==null?void 0:f.isMainScene)===!1?f.with(l.SheetCanvasPopManagerService):this._sheetCanvasPopManagerService).attachPopupToObject(r,{componentKey:ie,direction:`vertical-center`,offset:[0,e.SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET],extraProps:{unitId:o,subUnitId:s,drawingId:c,drawingType:u,shapeType:d.shapeType,shapeData:d.shapeData}});this._disposePopups.push(this.disposeWithMe(p)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===o&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:o,subUnitId:s,drawingId:c}])})),n.add(t.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),n.add(t.changing$.subscribe(()=>{this._clearPopups()})),n.add(t.changeStart$.subscribe(()=>{this._clearPopups()})),(0,a.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===Tt.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===i.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===a.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===a.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(a.FOCUSING_COMMON_DRAWINGS,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(P),this._sidebarDisposable=null,this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};Q=A([k(0,a.IUniverInstanceService),k(1,(0,a.Inject)(t.ISidebarService)),k(2,t.IMenuManagerService),k(3,(0,a.Inject)(i.SheetsShapeService)),k(4,(0,a.Inject)(a.LocaleService)),k(5,a.ICommandService),k(6,u.IDrawingManagerService),k(7,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(8,a.IContextService),k(9,o.IRenderManagerService),k(10,(0,a.Inject)(V))],Q);let $=class extends a.Plugin{constructor(e=ft,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...o}=(0,a.merge)({},ft,this._config);this._configService.setConfig(dt,o),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,[Ft]),(0,a.touchDependencies)(this._injector,[[Q],[W],[j],[q]])}onSteady(){this._injector.get(Q).initShapePopupMenu()}onReady(){[[G],[M],[K]].forEach(e=>this._injector.add(e)),(0,a.touchDependencies)(this._injector,[[K],[M]]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[G]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[pt]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[wt]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[_t]),this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[It])),this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[Nt]))}onStarting(){this._injector.add([Mt]),this._injector.get(Mt);let e=this._injector;[[Q],[W],[j],[q],[Y],[V],[U],[L],[J],[Z]].forEach(t=>e.add(t)),(0,a.touchDependencies)(this._injector,[[Q],[W],[j],[Y],[V],[U],[L],[J],[Z]])}_initCommands(){[N,S,Tt,I,ce,re,ue,de].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E($,`type`,a.UniverInstanceType.UNIVER_SHEET),E($,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E($,`packageName`,ct),E($,`version`,lt),$=A([(0,a.DependentOn)(h.UniverLicensePlugin,g.UniverDocsPlugin,u.UniverDrawingPlugin,f.UniverDrawingUIPlugin,o.UniverRenderEnginePlugin,s.UniverSheetsPlugin,_.UniverDocsUIPlugin,c.UniverSheetsDrawingPlugin,r.UniverShapeEditorPlugin,v.UniverSheetsDrawingUIPlugin,i.UniverSheetsShapePlugin,l.UniverSheetsUIPlugin,e.UniverShapeEditorUIPlugin),k(1,(0,a.Inject)(a.Injector)),k(2,a.ICommandService),k(3,a.IConfigService),k(4,o.IRenderManagerService)],$),exports.SheetsShapeUIContextualRibbonSchema=at,exports.SheetsShapeUIMenuSchema=st,Object.defineProperty(exports,"UniverSheetsShapeMobileUIPlugin",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"UniverSheetsShapeUIPlugin",{enumerable:!0,get:function(){return $}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@univerjs-pro/shape-editor-ui"),t=require("@univerjs/ui"),n=require("@univerjs-pro/engine-shape"),r=require("@univerjs-pro/shape-editor"),i=require("@univerjs-pro/sheets-shape"),a=require("@univerjs/core"),o=require("@univerjs/engine-render"),s=require("@univerjs/sheets"),c=require("@univerjs/sheets-drawing"),l=require("@univerjs/sheets-ui"),u=require("@univerjs/drawing"),d=require("rxjs"),f=require("@univerjs/drawing-ui"),p=require("@univerjs/design"),m=require("react/jsx-runtime"),h=require("@univerjs-pro/license"),g=require("@univerjs/docs"),_=require("@univerjs/docs-ui"),v=require("@univerjs/sheets-drawing-ui"),y=require("@univerjs/icons"),b=require("react");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}const S={type:a.CommandType.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(i.SheetsShapeService),{unitId:r,subUnitId:o,shapeType:s,shapeId:c,shapeData:l,replaceShapeData:u,oldShapeJSON:d}=t;if(!n.getShapeModel(r,o,c))return!1;let f=e.get(a.ICommandService),p=e.get(a.IUndoRedoService),{oldShapeType:m,oldShapeData:h={}}=d,g=u?h:x(h,l||{}),_={id:i.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:o,shapeId:c,shapeType:s,shapeData:l,replace:u}},v={id:i.UpdateSheetsShapeDataMutation.id,params:{unitId:r,subUnitId:o,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(t,n,r){let i={...n,dataModel:{...n.dataModel??{},...r?{doc:r}:null}},a=(0,e.resolveShapeTextEditorBehaviorShapeData)(t,i),o=(0,e.resolveShapeTextEditorWrapStrategy)(a);return{clip:(0,e.shouldClipShapeTextDocument)(a,o),wrapStrategy:o}}var D=class extends o.Shape{constructor(t,n){super(t,n),E(this,`_hyperLinkRegions`,[]),E(this,`_props`,void 0),E(this,`_formulaAnimation`,new e.FormulaShapeAnimationController(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),E(this,`_transformCalculateSrcRect`,!0),E(this,`_drawingType`,a.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(t){if(this._props.isEditing)return null;let n=this.getInverseCoord(t),{width:r,height:i}=this.getRealBound();return(0,e.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 t=this._props.shapeModel,n=t.getShapeTextData(),i=(0,e.normalizeShapeTextModel)(n==null?void 0:n.dataModel),a=i==null?void 0:i.doc,o=this._formulaAnimation.getAutoFitPresentations();if(!a||o.length===0)return;t.updateContext({width:this.width,height:this.height});let s=(0,e.resolveFormulaShapeAutoFitSize)({documentData:o.map(e=>(0,r.createShapeFormulaDocument)(a,e)),height:this.height,shapeData:t.getShapeData(),textRect:t.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 o.RENDER_CLASS_TYPE.SHAPE}_draw(e,t,r,i){let a=this._props.shapeModel;if(!a||!t)return;let o=r??this.width,s=i??this.height,c={shapeType:a.getShapeType(),width:o,height:s},l={renderMode:n.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(t,n,r){this._drawRichText(t,{...n,text:n.text??``,dataModel:{doc:(0,e.plainShapeTextToDocumentData)(n,`sheets-shape-text-${this.oKey}`)}},r)}_drawRichText(t,n,r){(0,e.drawFormulaShapeAnimationLayers)(t,this._formulaAnimation,(e,t,i)=>{this._drawRichTextLayer(e,n,r,t,i===`current`)})}_drawRichTextLayer(t,n,i,s,c){let l=this._props.localeService;if(!n.dataModel||!l)return;let u=(0,e.normalizeShapeTextModel)(n.dataModel);if(!u)return;let d=u.doc;if(!d)return;let f=(0,r.createShapeFormulaDocument)(d,s),p=u.va??a.VerticalAlign.TOP,m=u.ha??a.HorizontalAlign.LEFT,h=ne(this._props.shapeModel.getShapeData(),n,f),g=n.isHorizontal,_=(0,e.prepareShapeTextDocumentData)(f,{isHorizontal:g!==!1,textRect:i,verticalAlign:p,horizontalAlign:m,wrapStrategy:h.wrapStrategy}),v=new a.DocumentDataModel(_),y=new o.DocumentViewModel(v),b=o.DocumentSkeleton.create(y,l);b.calculate();let x=b.getActualSize().actualHeight,S=(0,e.resolveShapeTextDocumentRenderLayout)({contentHeight:x,verticalAlign:p,viewportHeight:i.height});v.updateDocumentStyle({pageSize:{width:g===!1?i.height:i.width,height:(0,e.resolveShapeTextDocumentPageHeight)(f,S.contentHeight)}}),v.updateDocumentDataMargin({t:S.marginTop}),b.calculate();let C=new o.Documents(`shape-text-${this.oKey}`,b,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});C.resize(i.width,S.contentHeight),t.save(),t.translateWithPrecision(i.left,i.top),h.clip&&(t.beginPath(),t.rect(0,S.clipTop,i.width,S.clipHeight),t.clip()),S.contentVerticalOffset&&t.translateWithPrecision(0,S.contentVerticalOffset),C.draw(t),c&&(this._hyperLinkRegions=(0,e.createShapeTextHyperLinkRegions)(C,{left:i.left,top:i.top+S.contentVerticalOffset},h.clip?{left:i.left,right:i.left+i.width,top:i.top+S.clipTop,bottom:i.top+S.clipTop+S.clipHeight}:void 0)),t.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:s}=this,c=this.getRealBound();if(r=c.width,i=c.height,a=c.left,s=c.top,this.isRender(t)){let{top:e,left:n,bottom:o,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+s<e||o<s)return this}let l=a+r/2,u=s+i/2,d=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new o.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(),s=t+r/2,c=n+i/2,l=new o.Transform([a[0],a[1],a[2],a[3],s,c]),u=this.getParent();return(this.isInGroup&&(u==null?void 0:u.classType)===o.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,s=n+i/2,c=this.transform.getMatrix(),l=new o.Transform([c[0],c[1],c[2],c[3],a,s]),u=this.getParent(),d=(this.isInGroup&&(u==null?void 0:u.classType)===o.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 o.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){o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.adjHandleSize,fill:n.ShapeDefaultConfig.adjHandleFill,stroke:n.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 a.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:o,transforms:s}=e;if(i===a.DrawingTypeEnum.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(o&&s?s:[r]).flatMap((r,i)=>{var a;let s=(0,u.getDrawingShapeKeyByDrawingSearch)(e,o?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 d=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return d&&(n==null||(a=n.resourceCollector)==null||a.add(d)),[l]})}_createShape(t,r,i,s){let{unitId:c,subUnitId:l,drawingId:u,groupId:d,hidden:p,selectable:m,prstGeom:h,srcRect:g}=t,_=this._sheetsShapeService.getShapeModel(c,l,u);if(!_)return;let v=this._drawingManagerService.getDrawingOrder(c,l),y=v.indexOf(u),b=(0,n.isConnectorShape)(_.getShapeType()),x=_.getShapeData().formulaBinding,S={unitId:c,subUnitId:l,shapeId:u};x&&this._shapeFormulaService.register(S,x);let C=new D(i,{...r,zIndex:y===-1?v.length-1:y,shapeModel:_,drawingType:a.DrawingTypeEnum.DRAWING_SHAPE,localeService:this._localeService,shapeId:u,unitId:c,subUnitId:l,visible:p!==!0,evented:m!==!1,formulaPresentation:x?this._shapeFormulaService.getPresentation(S):void 0,animateFormulaPresentation:(x==null?void 0:x.animationEnabled)!==!1,transformerConfig:{...e.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 s.addObject(C,o.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&s.attachTransformerTo(C),d&&(0,f.insertGroupObject)({drawingId:d,unitId:c,subUnitId:l},C,s,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(),r=t.fill;!r||r.fillType!==n.ShapeFillEnum.PictureFill||!r.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let r=t.fill;if(!r||r.fillType!==n.ShapeFillEnum.PictureFill||!r.fillImageSource)return;let i=r.fillImageSource,a=r.fillImageSourceType??n.ImageSourceTypeEnum.URL,o=this._imageIoService.getImageSourceCache(i,a);if(o)e.setFillImage(o);else return this._loadAndSetImage(e,i,a)}async _loadAndSetImage(e,t,r){let i;try{if(r===n.ImageSourceTypeEnum.UUID)i=await this._imageIoService.getImage(t);else if(r===n.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(n=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,r,a),e.setFillImage(a),n()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),n()},a.src=i})}};j=A([k(0,u.IDrawingManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,(0,a.Inject)(a.LocaleService)),k(3,a.IImageIoService),k(4,a.IURLImageService),k(5,(0,a.Inject)(r.ShapeFormulaService))],j);let M=class extends a.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(l.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:o}=i;if(!o||i.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let{left:s,top:c,width:u,height:d,flipX:f,flipY:p,angle:m=0}=o;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:u??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=(u||0)-r),p&&(i=(d||0)-i),m!==0){let e=(u||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,r,i,a,s,c){if(!this._activeShapeId)return;let l=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${r}`);if(l){l.transformByState({left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize});return}let u={left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize,adjName:r,shapeId:this._activeShapeId,unitId:s,subUnitId:c,width:n.ShapeDefaultConfig.adjHandleSize+8,height:n.ShapeDefaultConfig.adjHandleSize+8,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0},d=new O(`shape-adjust-point-${this._activeShapeId}-${r}`,u);this._shapes.push(d),this._attachAdjustEvent(d,e,r),e.addObject(d,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,a.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,s,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=!!((s=d.transform)!=null&&s.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(o.CURSOR_TYPE.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c=r/s+n.x-this._baseShapeLeft,l=i/s+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$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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!==i.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===a.DrawingTypeEnum.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===a.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)===a.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,u.IDrawingManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,(0,a.Inject)(o.IRenderManagerService)),k(3,(0,a.Inject)(j)),k(4,a.IUniverInstanceService),k(5,a.ICommandService)],M);const re={id:`drawing.operation.set-drawing-active`,type:a.CommandType.OPERATION,handler:(e,t)=>{let n=e.get(u.IDrawingManagerService),r=e.get(o.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],o=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(o);if(c){var s;(s=r.getRenderUnitById(t[0].unitId))==null||(s=s.scene.getTransformer())==null||s.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},N={type:a.CommandType.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var u,d;let f=(0,s.getSheetCommandTarget)(e.get(a.IUniverInstanceService));if(!f)return!1;let{unitId:p,subUnitId:m,worksheet:h}=f,g=h.getConfig(),_=g.type??a.SheetTypes.GRID;if(_!==a.SheetTypes.GRID&&_!==a.SheetTypes.CHART)return!1;let v=e.get(a.IPermissionService);if(((u=v.getPermissionPoint(new s.WorkbookEditablePermission(p).id))==null?void 0:u.value)!==!0||((d=v.getPermissionPoint(new s.WorksheetEditPermission(p,m).id))==null?void 0:d.value)!==!0)return!1;let y=e.get(a.ICommandService),{value:b,enhanceParams:x}=t,S={unitId:p,subUnitId:m,shapeType:b,shapeId:(0,a.generateRandomId)()};if(_===a.SheetTypes.CHART){let t=e.get(o.IRenderManagerService).getRenderUnitById(p),n=t==null?void 0:t.components.get(l.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},s=(0,c.transformDrawingsToChartSheet)([{unitId:p,subUnitId:m,drawingId:S.shapeId,drawingType:a.DrawingTypeEnum.DRAWING_SHAPE,transform:{left:0,top:0,width:i.DEFAULT_SHAPE_WIDTH,height:i.DEFAULT_SHAPE_HEIGHT},axisAlignSheetTransform:{from:r,to:r}}],{left:n.left,top:n.top,width:n.width,height:n.height},g.rightToLeft===a.BooleanNumber.TRUE);if(!(s!=null&&s.length))return!1;let u=s[0].transform;S.position={x:u.left,y:u.top},S.width=u.width,S.height=u.height}else{let t=e.get(s.SheetsSelectionsService).getCurrentLastSelection();if(!t)return!1;S.range=t.range}if(x){let{startArrow:t,endArrow:i,horizontal:o,vertical:s}=x,c=(0,n.isConnectorShape)(b),l=b===n.ShapeTypeEnum.Rect;if(c&&(t||i)&&(S.shapeData={ln:{startArrow:t?{type:n.ShapeArrowTypeEnum.Arrow,size:n.ShapeArrowSizeEnum.Medium}:void 0,endArrow:i?{type:n.ShapeArrowTypeEnum.Arrow,size:n.ShapeArrowSizeEnum.Large}:void 0}}),l&&(o||s)){let t=e.get(a.ThemeService);S.shapeData=(0,r.createShapeTextBoxShapeData)({fill:{fillType:n.ShapeFillEnum.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!o,stroke:{lineStrokeType:n.ShapeLineTypeEnum.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let C=y.syncExecuteCommand(i.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,a.createInternalEditorID)(`SHAPE_TEXT`),oe=`sheet.shape.text.float-menu`,se={id:`sheet.operation.open-shape-object-list-panel`,type:a.CommandType.COMMAND,handler:(e,n)=>{let r=e.get(t.ISidebarService),i=e.get(a.LocaleService),o=e.get(a.IUniverInstanceService),c=e.get(a.ICommandService);return(0,s.getSheetCommandTarget)(o)?(n==null?void 0:n.value)===`close`?(r.close(F),!0):(r.open({id:F,header:{title:i.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:F},onClose:()=>{c.syncExecuteCommand(u.SetDrawingSelectedOperation.id,[])},width:360}),!0):!1}},L={type:a.CommandType.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function ce(e){let t=e.get(u.IDrawingManagerService).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)return null;let r=e.get(i.SheetsShapeService),o=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),s=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return o===void 0||!s?null:{drawing:n,shapeData:s,shapeType:o}}const le={id:`sheet.operation.apply-shape-quick-style`,type:a.CommandType.OPERATION,handler:(e,t)=>{let n=ce(e),i=(0,r.getShapeQuickStylePreset)((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!i||i.type!==(0,r.getShapeQuickStyleType)(n.shapeData))return!1;let o=(0,r.applyQuickStyleToShapeData)(n.shapeData,i);if(!o)return!1;let{drawing:s}=n;return e.get(a.ICommandService).executeCommand(S.id,{unitId:s.unitId,subUnitId:s.subUnitId,shapeId:s.drawingId,shapeData:o,oldShapeJSON:{oldShapeData:n.shapeData}})}},ue={id:`sheet.operation.update-shape-type`,type:a.CommandType.OPERATION,handler:(e,t)=>{let i=ce(e),o=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!i||!o||(0,n.isConnectorShape)(i.shapeType)||(0,n.isConnectorShape)(o))return!1;let s=(0,r.cloneShapeDataForType)(i.shapeData,o);if(!s)return!1;let{drawing:c}=i;return e.get(a.ICommandService).executeCommand(S.id,{unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.drawingId,shapeType:o,shapeData:s,replaceShapeData:!0,oldShapeJSON:{oldShapeType:i.shapeType,oldShapeData:i.shapeData}})}};let R=class extends a.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,r=e.registerClipDelegate((e,r,i,a,o)=>{let s=r;if(s===n.ShapeTypeEnum.None||r===`custom`)return!1;try{let c=t.get(r);return c||(c=new n.ShapeModel(s,`clip-${r}`),t.set(r,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(r),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,a.Inject)(f.DrawingImageClipService)),k(1,(0,a.Inject)(u.IDrawingManagerService))],R);const de=`sheet.shape.picker.component`,fe=`sheet.image-clip.shape-picker.component`;function pe({onShapeClick:t,excludeGroups:n}){return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerPanel,{excludeGroups:n,onShapeClick:t,scrollContainer:`parent`})}function me(){let n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(R);return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[e.ShapeGroupEnum.Line],onShapeClick:e=>{let t=n.getFocusDrawings().find(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE);if(!t)return;let{unitId:i,subUnitId:o,drawingId:s}=t;r.clipByShape(i,o,s,e.type)}})}function he(){let n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(R);return/* @__PURE__ */ (0,m.jsx)(e.ShapePickerDropdown,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[e.ShapeGroupEnum.Line],DropdownComponent:p.MobileDropdown,onShapeClick:e=>{let t=n.getFocusDrawings().find(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE);if(!t)return;let{unitId:i,subUnitId:o,drawingId:s}=t;r.clipByShape(i,o,s,e.type)}})}function ge(){let e=(0,t.useDependency)(t.ComponentManager),n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(a.IUniverInstanceService),i=n.getFocusDrawings()[0],o=i?r.getUnitType(i.unitId):void 0,s=o===a.UniverInstanceType.UNIVER_DOC?`doc.image-clip.shape-picker.component`:o===a.UniverInstanceType.UNIVER_SHEET?fe:void 0,c=s?e.get(s):void 0;return c?/* @__PURE__ */ (0,m.jsx)(c,{}):null}function _e(){let e=(0,t.useDependency)(a.ICommandService);return/* @__PURE__ */ (0,m.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,m.jsx)(_e,{})}function ye(e){return(0,l.deriveStateFromActiveSheet$)(e.get(a.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??a.SheetTypes.GRID;if(r===a.SheetTypes.GRID)return(0,l.getCurrentRangeDisable$)(e);if(r!==a.SheetTypes.CHART)return(0,d.of)(!0);let i=e.get(a.IPermissionService),o=[new s.WorkbookEditablePermission(t.getUnitId()).id,new s.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,d.startWith)(null),(0,d.map)(()=>o.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,d.distinctUntilChanged)())})}function be(e){let n=e.get(a.IUniverInstanceService);return{id:N.id,type:t.MenuItemType.SELECTOR,selections:[{label:{name:de,hoverable:!1,selectable:!1,props:{id:N.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:(0,l.deriveStateFromActiveSheet$)(n,!1,()=>new d.Observable(e=>{e.next(!1)})),hidden$:(0,t.getMenuHiddenObservable)(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:ye(e)}}function xe(e){return(0,l.deriveStateFromActiveSheet$)(e.get(a.IUniverInstanceService),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??a.SheetTypes.GRID;if(r===a.SheetTypes.GRID)return(0,l.getCurrentRangeDisable$)(e);if(r!==a.SheetTypes.CHART)return(0,d.of)(!0);let i=e.get(a.IPermissionService),o=[new s.WorkbookEditablePermission(t.getUnitId()).id,new s.WorksheetEditPermission(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe((0,d.startWith)(null),(0,d.map)(()=>o.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),(0,d.distinctUntilChanged)())})}function Se(e){let n=e.get(t.ISidebarService);return{id:se.id,type:t.MenuItemType.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:(0,d.defer)(()=>n.sidebarOptions$.pipe((0,d.startWith)(n.options),(0,d.map)(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),(0,d.distinctUntilChanged)())),hidden$:(0,t.getMenuHiddenObservable)(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:xe(e)}}const Ce=`sheet.menu.shape.flip-horizontal`,we=`sheet.menu.shape.flip-vertical`;function Te(e){let t=e.get(u.IDrawingManagerService).getFocusDrawings();return t.length===1&&t[0].drawingType===a.DrawingTypeEnum.DRAWING_SHAPE?t[0]:null}function Ee(e){let t=e.get(u.IDrawingManagerService);return t.focus$.pipe((0,d.startWith)(t.getFocusDrawings()),(0,d.map)(e=>e.length!==1||e[0].drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE))}function De(e){return{id:Ce,commandId:i.ToggleSheetsShapeFlipCommand.id,type:t.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:i.ToggleSheetsShapeFlipCommand.id,type:t.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 a.Disposable{constructor(e){super(),this._permissionService=e,E(this,`_editingParams$`,new d.BehaviorSubject(null)),E(this,`editingParams$`,this._editingParams$.asObservable()),E(this,`_onSavingEditorData$`,new d.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 s.WorkbookEditablePermission(e.unitId).id),n=this._permissionService.getPermissionPoint(new s.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,a.IPermissionService)],z);const 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 B(){let e=(0,t.useDependency)(a.ICommandService),n=(0,t.useDependency)(u.IDrawingManagerService),r=(0,t.useDependency)(i.SheetsShapeService),o=()=>{var e;let t=n.getFocusDrawings();if(t.length!==1||((e=t[0])==null?void 0:e.drawingType)!==a.DrawingTypeEnum.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:o,drawingId:s}=t[0],c=r.getShapeTypeById(i,o,s),l=r.getShapeDataById(i,o,s);return c===void 0||!l?null:{unitId:i,subUnitId:o,drawingId:s,shapeType:c,shapeData:l}},s=(0,t.useObservable)(()=>new d.Observable(t=>{let r=()=>t.next(o()),a=n.focus$.subscribe(r),s=e.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&r()});return r(),()=>{a.unsubscribe(),s.dispose()}}),o(),!1,[e,n,r]);return{selection:s,updateShapeData:t=>{s&&C(e,s.unitId,s.subUnitId,s.drawingId,{oldShapeData:s.shapeData},t)}}}function Ne(){let{selection:t,updateShapeData:n}=B();return t?/* @__PURE__ */ (0,m.jsx)(e.ShapeStyleRibbonControl,{shapeData:t.shapeData,shapeType:t.shapeType,onUpdateShapeData:n}):null}function Pe(){let n=(0,t.useDependency)(a.ICommandService),i=(0,t.useDependency)(a.LocaleService),{selection:o}=B();return o?/* @__PURE__ */ (0,m.jsx)(e.ShapeQuickStyleGallery,{type:(0,r.getShapeQuickStyleType)(o.shapeData),ariaLabel:i.t(`sheets-shape-ui.quickStyles`),activePresetId:(0,r.resolveActiveShapeQuickStylePresetId)(o.shapeData),onSelect:e=>n.executeCommand(le.id,{presetId:e})}):null}function Fe(){let{selection:n,updateShapeData:r}=B(),i=(0,t.useDependency)(z),a=(0,t.useObservable)(i.editingParams$,i.getEditing());if(!n)return null;let o=(0,e.isShapeTextEditingTarget)(a,n);return/* @__PURE__ */ (0,m.jsx)(e.ShapeTextRibbonControl,{editorUnitId:o?I:void 0,fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:n.shapeData,onUpdateShapeData:r})}function Ie(){var t;let{selection:n,updateShapeData:r}=B(),i=(0,e.useFormulaShapeToolbar)({hostType:a.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})}),o=((t=i.extensionGroups)==null?void 0:t.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return n!=null&&n.shapeData.formulaBinding?/* @__PURE__ */ (0,m.jsx)(e.ShapeFormulaRibbonControl,{actions:o,panel:i.panel}):null}const Le=`sheets-shape-ui.ribbon.shape-format.style-control`,Re=`sheets-shape-ui.ribbon.shape-format.text-control`,ze=`sheets-shape-ui.ribbon.shape-format.formula-control`,Be=`sheets-shape-ui.ribbon.shape-format.arrange-forward`,Ve=`sheets-shape-ui.ribbon.shape-format.arrange-backward`,He=`sheets-shape-ui.ribbon.shape-format.arrange-front`,Ue=`sheets-shape-ui.ribbon.shape-format.arrange-back`;function We(e){let t=e.get(a.ICommandService),n=e.get(u.IDrawingManagerService),o=e.get(i.SheetsShapeService);return new d.Observable(a=>{let s=()=>{let t=V(e),n=t?o.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;a.next(n?(0,r.resolveActiveShapeQuickStylePresetId)(n)??``:``)},c=n.focus$.subscribe(s),l=t.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function V(e){var t;let n=e.get(u.IDrawingManagerService).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE?n[0]:null}function Ge(e,t=!1){let n=e.get(a.ICommandService),r=e.get(u.IDrawingManagerService),o=e.get(i.SheetsShapeService);return new d.Observable(a=>{let s=()=>{let n=V(e);if(!n){a.next(!0);return}let r=o.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);a.next(!r||t&&r.formulaBinding==null)},c=r.focus$.subscribe(s),l=n.onCommandExecuted(e=>{e.id===i.UpdateSheetsShapeDataMutation.id&&s()});return s(),()=>{c.unsubscribe(),l.dispose()}})}function Ke(e){let t=e.get(u.IDrawingManagerService),r=e.get(i.SheetsShapeService);return t.focus$.pipe((0,d.startWith)(t.getFocusDrawings()),(0,d.map)(()=>{let t=V(e),i=t?r.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return i===void 0||(0,n.isConnectorShape)(i)}))}function qe(e){return{id:le.id,type:t.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$:We(e),hidden$:Ge(e)}}function Je(n){return{id:ue.id,type:t.MenuItemType.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:e.SHAPE_CHANGE_PICKER_COMPONENT,hoverable:!1,selectable:!1}}],hidden$:Ke(n)}}function Ye(e,n,r=!1){return i=>({id:e,type:t.MenuItemType.BUTTON,label:{name:n,hoverable:!1,selectable:!1},hidden$:Ge(i,r)})}const Xe=Ye(Le,Ae),Ze=Ye(Re,je),Qe=Ye(ze,Me,!0);function $e(e,n,r,i){return a=>({id:e,commandId:c.SetDrawingArrangeCommand.id,type:t.MenuItemType.BUTTON,icon:r,title:i,tooltip:i,hidden$:Ge(a),params:()=>{let e=V(a);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:n}:void 0}})}const et=$e(Be,a.ArrangeTypeEnum.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),tt=$e(Ve,a.ArrangeTypeEnum.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),nt=$e(He,a.ArrangeTypeEnum.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),rt=$e(Ue,a.ArrangeTypeEnum.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function it(e){let n=e.get(t.ISidebarService);return{activated$:(0,d.defer)(()=>n.sidebarOptions$.pipe((0,d.startWith)(n.options),(0,d.map)(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),(0,d.distinctUntilChanged)())),id:L.id,type:t.MenuItemType.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:Ge(e),params:()=>{let t=V(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}const at={[t.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:qe},[ue.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Je}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[Le]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Xe}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[Re]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Ze}},"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},[Be]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:et},[Ve]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:tt},[He]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:nt},[Ue]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:rt}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[ze]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Qe}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[L.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:it},[e.ToggleShapeFloatingToolbarOperation.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:e.ShapeFloatingToolbarToggleFactory}}}}},ot={[t.RibbonInsertGroup.MEDIA]:{[N.id]:{order:3,menuItemFactory:be}}},st={...ot,[t.RibbonInsertGroup.OTHERS]:{[se.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Se}},[t.ContextMenuPosition.DRAWING]:{[t.ContextMenuGroup.OTHERS]:{[Ce]:{order:4,menuItemFactory:De},[we]:{order:5,menuItemFactory:Oe}}}};var ct=`@univerjs-pro/sheets-shape-ui`,lt=`1.6.0`;const ut={id:`sheet.operation.open-mobile-shape-editor`,type:a.CommandType.OPERATION,handler(t,n){return n?(t.get(e.MobileShapeEditorService).open(n.mode,{hostType:a.UniverInstanceType.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},dt=`sheets-shape-ui.config`,ft={};let pt=class extends a.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,r,i){let a=e;if(a!==n.ShapeTypeEnum.None&&e!==`custom`)try{let o=new n.ShapeModel(a,`clip-adj-${e}`);return i&&o.setShapeData({adjustValues:i},!0),o.updateContext({width:t,height:r}),o}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===a.DrawingTypeEnum.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),s=i.getObject(a);if(s instanceof o.Image){let e=s.prstGeom;if(e)return{prstGeom:e,adjustValues:s.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(l.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:u,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(u&&(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 l={x:r,y:i,adjName:t.adjName};this._addControl(n,l,l.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,r,i,a,s,c){if(!this._activeImageId)return;let l=`image-clip-adjust-point-${this._activeImageId}-${r}`,u=e.getObjectIncludeInGroup(l);if(u){u.transformByState({left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize});return}let d=new O(l,{left:t.x+i-n.ShapeDefaultConfig.adjHandleSize,top:t.y+a-n.ShapeDefaultConfig.adjHandleSize,adjName:r,shapeId:this._activeImageId,unitId:s,subUnitId:c,width:n.ShapeDefaultConfig.adjHandleSize+8,height:n.ShapeDefaultConfig.adjHandleSize+8,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._shapes.push(d),this._attachAdjustEvent(d,e,r),e.addObject(d,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,a.toDisposable)(e.onPointerDown$.subscribeEvent((r,i)=>{var a,s,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=!!((s=f.transform)!=null&&s.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(o.CURSOR_TYPE.CROSSHAIR);let s={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(s,{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,s=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),c=a.getObject(s);if(c instanceof o.Image){let e=c.prstGeomAdjValues??{};c.setPrstGeomAdjValues({...e,...r}),c.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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 o.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===a.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)===a.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()}};pt=A([k(1,u.IDrawingManagerService),k(2,(0,a.Inject)(o.IRenderManagerService)),k(3,a.IUniverInstanceService),k(4,(0,a.Inject)(R))],pt);function mt({PanelComponent:n=f.ObjectListPanelBase}){var r;function i(e){return e.trim()||void 0}function s(t,n,r){var i;return((i=t.name)==null?void 0:i.trim())||`${r.t(`drawing-ui.objectListPanel.typeNames.${(0,e.getDrawingTypeNameKey)(t.drawingType)}`)} ${n+1}`}let l=(0,t.useDependency)(a.LocaleService),d={title:l.t(`drawing-ui.objectListPanel.title`),empty:l.t(`drawing-ui.objectListPanel.empty`),showAll:l.t(`drawing-ui.objectListPanel.showAll`),hideAll:l.t(`drawing-ui.objectListPanel.hideAll`),lockAll:l.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:l.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:l.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:l.t(`drawing-ui.objectListPanel.moveBackward`),close:l.t(`drawing-ui.objectListPanel.close`),show:l.t(`drawing-ui.objectListPanel.show`),hide:l.t(`drawing-ui.objectListPanel.hide`),lock:l.t(`drawing-ui.objectListPanel.lock`),unlock:l.t(`drawing-ui.objectListPanel.unlock`),lockHint:l.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:l.t(`drawing-ui.objectListPanel.unlockHint`),name:l.t(`drawing-ui.objectListPanel.name`),nameInput:l.t(`drawing-ui.objectListPanel.nameInput`),description:l.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:l.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:l.t(`drawing-ui.objectListPanel.details`),noSelection:l.t(`drawing-ui.objectListPanel.noSelection`),locate:l.t(`drawing-ui.objectListPanel.locate`),expand:l.t(`drawing-ui.objectListPanel.expand`),collapse:l.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:l.t(`drawing-ui.objectListPanel.dragToReorder`),search:l.t(`drawing-ui.objectListPanel.search`),filterAll:l.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:l.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:l.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:l.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:l.t(`drawing-ui.objectListPanel.sectionFloating`)},p=(0,t.useDependency)(a.ICommandService),h=(0,t.useDependency)(a.IUniverInstanceService),g=(0,t.useDependency)(c.ISheetDrawingService),_=(0,t.useDependency)(u.IDrawingManagerService),v=(0,t.useDependency)(o.IRenderManagerService),y=(0,t.useDependency)(t.ILayoutService),[,x]=(0,b.useReducer)(e=>e+1,0),S=h.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET),C=(S==null?void 0:S.getUnitId())??``,w=(S==null||(r=S.getActiveSheet())==null?void 0:r.getSheetId())??``,T=(0,t.useObservable)(()=>_.focus$,_.getFocusDrawings(),!1,[_]);(0,b.useEffect)(()=>{let e=p.onCommandExecuted(()=>x());return()=>e.dispose()},[p]);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,f.getObjectListPanelSectionIdForDrawingType)(t.drawingType)]+=1,e),{canvas:0,floating:0}),ne={canvas:0,floating:0},D=te.map((e,t)=>{let n=(0,f.getObjectListPanelSectionIdForDrawingType)(e.drawingType),r=n===f.OBJECT_LIST_FLOATING_SECTION_ID,i=ne[n]++;return{id:e.drawingId,name:s(e,t,l),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:r?d.sectionFloating:d.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 p.executeCommand(c.SetSheetDrawingCommand.id,{unitId:C,drawings:e})},M=async(e,t)=>{A(e)&&await j([{unitId:C,subUnitId:w,drawingId:e,...t}])},re=(t,n)=>{if(!C||!w)return;let r=n?O.includes(t)?O.filter(e=>e!==t):[...O,t]:[t];p.syncExecuteCommand(u.SetDrawingSelectedOperation.id,r.map(e=>({unitId:C,subUnitId:w,drawingId:e})));let i=r[r.length-1];i?((0,e.activateDrawingObject)(v,{unitId:C,subUnitId:w,drawingId:i}),y.focus(C)):(0,e.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 p.executeCommand(c.SetDrawingArrangeCommand.id,{unitId:C,subUnitId:w,drawingIds:[e],arrangeType:t})};return!C||!w?/* @__PURE__ */ (0,m.jsx)(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:d.title}):/* @__PURE__ */ (0,m.jsx)(n,{labels:d,items:D,selectedIds:O,focusedId:k,showHeader:!1,onSelect:re,onSetVisible:N,onSetSelectable:P,onCommitName:ie,onCommitDescription:ae,onMoveForward:async e=>I(e,a.ArrangeTypeEnum.forward),onMoveBackward:async e=>I(e,a.ArrangeTypeEnum.backward),onToggleSelectable:F})}function ht(){return/* @__PURE__ */ (0,m.jsx)(mt,{PanelComponent:f.MobileObjectListPanel})}let gt=class extends a.Disposable{constructor(e,t){super(),this.disposeWithMe(e.register(F,ht)),this.disposeWithMe(t.register({BottomIcon:y.BottomIcon,FlipHorizontalIcon:y.FlipHorizontalIcon,FlipVerticalIcon:y.FlipVerticalIcon,MoveDownIcon:y.MoveDownIcon,MoveUpIcon:y.MoveUpIcon,ObjectLayersIcon:y.ObjectLayersIcon,ShapeFormatSettingIcon:y.ShapeFormatSettingIcon,TopmostIcon:y.TopmostIcon})),this.disposeWithMe(e.register(de,ve)),this.disposeWithMe(e.register(fe,he)),e.hasDefault(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(e.register(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,ge))}};gt=A([k(0,(0,a.Inject)(t.ComponentManager)),k(1,(0,a.Inject)(t.IconManager))],gt);let _t=class extends a.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:r,offsetY:i}=t,a=e.pick(o.Vector2.FromArray([r,i]));if(a instanceof D){let e=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);if((0,n.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 r=e[0],i=this._drawingManagerService.getDrawingByParam(r);if((i==null?void 0:i.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===r.drawingId&&e.visible)return;let i=(0,n.isConnectorShape)(this._sheetsShapeService.getShapeType(r.unitId,r.subUnitId,r.drawingId)),a=!!((t=this._sheetsShapeService.getShapeModel(r.unitId,r.subUnitId,r.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(a.FOCUSING_SHAPE_TEXT_EDITOR,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(a.FOCUSING_SHAPE_TEXT_EDITOR,!1)}))}};_t=A([k(1,(0,a.Inject)(a.Injector)),k(2,(0,a.Inject)(z)),k(3,u.IDrawingManagerService),k(4,a.IContextService),k(5,(0,a.Inject)(i.SheetsShapeService))],_t);var vt=class extends _t{_initEvents(){let{scene:t}=this._context,r=this._injector.get(e.MobileShapeEditorService);this.disposeWithMe(t.onDblclick$.subscribeEvent(e=>{let{offsetX:i,offsetY:s}=e,c=t.pick(o.Vector2.FromArray([i,s]));if(!(c instanceof D))return;let l=this._sheetsShapeService.getShapeModel(c.unitId,c.subUnitId,c.shapeId);(0,n.isConnectorShape)(this._sheetsShapeService.getShapeType(c.unitId,c.subUnitId,c.shapeId))||l!=null&&l.getShapeData().formulaBinding||r.open(`text`,{hostType:a.UniverInstanceType.UNIVER_SHEET,unitId:c.unitId,subUnitId:c.subUnitId,shapeId:c.shapeId})}))}};const yt={...ot};let H=class extends a.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(yt),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,e.bindRenderTransformerLifecycle)(this._renderManagerService,a.UniverInstanceType.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(a.DrawingTypeEnum.DRAWING_SHAPE,(e,t,r,a)=>{let o=this._sheetsShapeService.getShapeTypeById(e,t,r),s=this._sheetsShapeService.getShapeDataById(e,t,r),l=o!==void 0&&!(0,n.isConnectorShape)(o)&&!(s!=null&&s.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:ut.id,commandParams:{unitId:e,subUnitId:t,drawingId:r,mode:`style`},disable:!1},...l?[{label:`sheets-shape-ui.editText`,index:1,commandId:ut.id,commandParams:{unitId:e,subUnitId:t,drawingId:r,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:c.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:r,drawingType:a}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:i.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:r,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:i.ToggleSheetsShapeFlipCommand.id,commandParams:{unitId:e,subUnitId:t,shapeId:r,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new a.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(a.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 o=this._drawingManagerService.getDrawingOKey(i.oKey);if(!o||o.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE){r();return}let{unitId:s,subUnitId:c,drawingId:l}=o;n={unitId:s,subUnitId:c,drawingId:l},this._contextService.setContextValue(a.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,a.toDisposable)(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};H=A([k(0,t.IMenuManagerService),k(1,(0,a.Inject)(i.SheetsShapeService)),k(2,a.ICommandService),k(3,u.IDrawingManagerService),k(4,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(5,a.IContextService),k(6,o.IRenderManagerService),k(7,(0,a.Inject)(z))],H);function bt(e,t,n,r){let i=(0,u.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 a.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===s.RemoveSheetCommand.id){let t=(0,s.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,o=this._sheetDrawingService.getDrawingData(n,r),c=Object.values(o).filter(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=[],u=[];for(let e=0;e<c.length;e++){let t=c[e],a=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);a&&(l.push({id:i.RemoveSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),u.push({id:i.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:a.getShapeType(),shapeData:JSON.parse(JSON.stringify(a.getShapeData()))}}))}return{redos:l,undos:u}}if(e.id===s.CopySheetCommand.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:o}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let s=this._sheetDrawingService.getDrawingData(t,n),c=Object.values(s).filter(e=>e.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE);if(c.length===0)return{redos:[],undos:[]};let l=bt(o,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:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),d.push({id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:u,undos:d}}return{redos:[],undos:[]}}}))}};U=A([k(0,(0,a.Inject)(a.IUniverInstanceService)),k(1,(0,a.Inject)(s.SheetInterceptorService)),k(2,(0,a.Inject)(c.ISheetDrawingService)),k(3,(0,a.Inject)(i.SheetsShapeService))],U);let W=class extends a.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===i.UpdateSheetsShapeDataMutation.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=(0,u.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===i.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,u.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),d=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(l.SheetSkeletonManagerService).getSkeleton(i)))return!1;if(d)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:o,drawingType:s,srcRect:c,prstGeom:l}=i;if(s!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;let{scene:f,transformer:p}=d;if(o==null)return!0;let m=(0,u.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 r of e){var t;let{unitId:e,subUnitId:i,drawingId:o}=r,s=this._getSceneAndTransformerByDrawingSearch(e),c=(t=(0,f.getCurrentUnitInfo)(this._currentUniverService,e))==null?void 0:t.subUnitId;if(s==null||c!==i)continue;let l=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:i,drawingId:o});if(this._insertingShapeKeys.has(l)||s.scene.getObjectIncludeInGroup(l)!=null)continue;let d=this._drawingManagerService.getDrawingByParam(r);if(d==null||d.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let p=d.data||{};if((0,n.isConnectorShape)(p.shapeType)){let e=d.transform;e&&(d.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(l);try{this._sheetDrawingShapeRenderController.renderDrawingShape(d,s.scene)}finally{this._insertingShapeKeys.delete(l)}queueMicrotask(()=>{if(this._disposed)return;let e=(0,u.getDrawingShapeKeyByDrawingSearch)(r);if(!s.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(r);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,a.ICommandService),k(1,o.IRenderManagerService),k(2,u.IDrawingManagerService),k(3,a.IUniverInstanceService),k(4,(0,a.Inject)(f.DrawingRenderService)),k(5,(0,a.Inject)(j))],W);const xt={normal:{fill:n.ShapeDefaultConfig.cxnPointFill,stroke:n.ShapeDefaultConfig.cxnPointStroke,strokeWidth:n.ShapeDefaultConfig.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var St=class extends o.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??n.ShapeDefaultConfig.cxnPointRadius*2,height:e.height??n.ShapeDefaultConfig.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?xt.highlighted:xt.normal;o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let G=class extends a.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 r of Object.keys(t)){if(r===this._draggingConnectorId||t[r].drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,r);if(!i||(0,n.isConnectorShape)(i.getShapeType())||i.getConnectionSiteList().length===0||!this._currentScene)continue;let s=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:r}),c=this._currentScene.getObjectIncludeInGroup(s);if(!c)continue;let{left:l,top:d,width:f,height:p}=c.getRealBound(),m=l+f/2,h=d+p/2,g=c.transform.getMatrix(),_=new o.Transform([g[0],g[1],g[2],g[3],m,h]),v=c.getParent(),y=(c.isInGroup&&(v==null?void 0:v.classType)===o.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:r,shapeModel:i}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let r=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),i=this._currentScene.getObjectIncludeInGroup(r);if(!i)return;let{left:a,top:s,width:c,height:l}=i.getRealBound(),d=a+c/2,f=s+l/2,p=i.transform.getMatrix(),m=new o.Transform([p[0],p[1],p[2],p[3],d,f]),h=i.getParent(),g=i.isInGroup&&(h==null?void 0:h.classType)===o.RENDER_CLASS_TYPE.GROUP?h.ancestorTransform.multiply(m):m;t.updateContext({width:c,height:l});let _=t.getConnectionSiteList();for(let t of _){let r=t.x-c/2,i=t.y-l/2,a=g.applyPoint({x:r,y:i}),s=a.x,u=a.y,d=new St(`connection-site-${e}-${t.index}`,{left:s-n.ShapeDefaultConfig.cxnPointRadius,top:u-n.ShapeDefaultConfig.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:n.ShapeDefaultConfig.cxnPointRadius*2,height:n.ShapeDefaultConfig.cxnPointRadius*2,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+2,evented:!1});this._connectionSiteObjects.push(d),this._currentScene.addObject(d,o.DRAWING_OBJECT_LAYER_INDEX+2)}}_findNearestConnectionSite(e){let t=null,r=1/0,i=null;for(let a of this._connectionSiteObjects){let o=a.left+n.ShapeDefaultConfig.cxnPointRadius,s=a.top+n.ShapeDefaultConfig.cxnPointRadius,c=e.x-o,l=e.y-s,u=Math.sqrt(c*c+l*l);u<r&&(r=u,t=a,i={x:o,y:s})}let a=r<=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(r<=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,a.Inject)(o.IRenderManagerService)),k(2,(0,a.Inject)(u.IDrawingManagerService)),k(3,(0,a.Inject)(i.SheetsShapeService))],G);let K=class extends a.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:a})=>{let o=[],s=[];for(let[u,d]of a.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||a.has(e),r=!t||a.has(t);n&&e&&m.relation.from?m.relation.from={...m.relation.from,shapeId:a.get(e)}:m.relation.from=void 0,r&&t&&m.relation.to?m.relation.to={...m.relation.to,shapeId:a.get(t)}:m.relation.to=void 0}o.push({id:i.InsertSheetsShapeMutation.id,params:{unitId:n,subUnitId:r,shapeId:d,shapeType:p,shapeData:m}}),s.push({id:i.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===a.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===l.PREDEFINED_HOOK_NAME.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===l.COPY_TYPE.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let o=(0,s.attachRangeWithCoord)(i,n);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._sheetDrawingService.getDrawingData(e,t),p=[];for(let[e,t]of Object.entries(f)){if(t.drawingType!==a.DrawingTypeEnum.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:o=0}=e;c<=n&&l>=n+i&&u<=r&&d>=r+o&&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:o,range:c}=e,l=this._copyInfo,u=(n=this._instances.getUnit(l.unitId,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(l.subUnitId),d=(r=this._instances.getUnit(i,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(o),f=(u==null?void 0:u.getConfig().type)??a.SheetTypes.GRID,p=(d==null?void 0:d.getConfig().type)??a.SheetTypes.GRID;if(f===a.SheetTypes.CHART||p===a.SheetTypes.CHART)return this._generateChartSheetCopy(e,t);let m=this._sheetSkeletonService.getSkeleton(i,o);if(!m)return{redos:[],undos:[]};let h=(0,s.discreteRangeToRange)(c),{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,a.generateRandomId)());let C=[],w=[];for(let e of y){let{drawingId:n,transform:r}=e;if(!r)continue;let a=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:o,drawing:e,newTransforms:a});C.push(...t),w.push(...n);continue}let{redos:s,undos:c}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:o,drawing:e,newTransforms:a,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 a.CustomCommandExecutionError(l.SheetPasteCommand.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},r,i))throw new a.CustomCommandExecutionError(l.SheetPasteCommand.id);let o=(n=this._instances.getUnit(r,a.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),u=o==null?void 0:o.getConfig(),d=(u==null?void 0:u.type)??a.SheetTypes.GRID,f=this._copyInfo,p=f.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[s.WorkbookCopyPermission],worksheetTypes:[s.WorksheetCopyPermission]},f.unitId,f.subUnitId)||p.some(e=>e.groupId||!this._shapeService.getShapeModel(f.unitId,f.subUnitId,e.drawingId)||!a.Tools.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new a.CustomCommandExecutionError(l.SheetPasteCommand.id);let m=null;if(d===a.SheetTypes.CHART){var h;let e=(h=this._renders.getRenderUnitById(r))==null?void 0:h.components.get(l.SHEET_VIEW_KEY.CHART_PAGE);e&&(m=(0,c.transformDrawingsToChartSheet)(p,{left:e.left,top:e.top,width:e.width,height:e.height},(u==null?void 0:u.rightToLeft)===a.BooleanNumber.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&(0,s.attachRangeWithCoord)(t,(0,s.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,c.applySheetDrawingPlacement)(i,{kind:c.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 a.CustomCommandExecutionError(l.SheetPasteCommand.id);let g=new Map(p.map(e=>[e.drawingId,(0,a.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:a,drawing:o,newTransforms:s}=e,l={...o,unitId:r,subUnitId:a,...s};if(r===t&&a===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([l]);return{redos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.UPDATE,op:e,objects:n}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([o]),s=this._sheetDrawingService.getBatchAddOp([l]),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:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.REMOVE,op:e.redo,objects:e.objects}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId}},{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.INSERT,op:s.redo,objects:s.objects}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:r,subUnitId:a,shapeId:o.drawingId,shapeType:d,shapeData:f}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.INSERT,op:e.undo,objects:e.objects}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o.drawingId,shapeType:d,shapeData:f}},{id:c.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:a,type:c.DrawingApplyType.REMOVE,op:s.undo,objects:s.objects}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:r,subUnitId:a,shapeId:o.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:a,newDrawingId:o,idMap:s}=e,l={...r,unitId:t,subUnitId:n,drawingId:o,...a},{redo:u,undo:d,objects:f}=this._sheetDrawingService.getBatchAddOp([l]),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:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.INSERT,op:u,objects:f}},{id:i.InsertSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o,shapeType:m,shapeData:h}}],undos:[{id:c.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:c.DrawingApplyType.REMOVE,op:d,objects:f}},{id:i.RemoveSheetsShapeMutation.id,params:{unitId:t,subUnitId:n,shapeId:o}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:l}=n,u={...e};if(i){let e=(0,s.attachRangeWithCoord)(a,i),t=(0,s.attachRangeWithCoord)(l,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,s.attachRangeWithCoord)(l,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,c.transformToAxisAlignPosition)(u,l)}}};K=A([k(0,(0,a.Inject)(s.SheetSkeletonService)),k(1,(0,a.Inject)(l.ISheetClipboardService)),k(2,(0,a.Inject)(c.ISheetDrawingService)),k(3,(0,a.Inject)(i.SheetsShapeService)),k(4,(0,a.Inject)(v.SheetsDrawingGroupCopyPasteController)),k(5,a.IUniverInstanceService),k(6,o.IRenderManagerService),k(7,(0,a.Inject)(s.SheetPermissionCheckController))],K);var Ct=class extends o.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){o.Circle.drawWith(e,{radius:n.ShapeDefaultConfig.cxnPointRadius,fill:n.ShapeDefaultConfig.cxnPointFill,stroke:n.ShapeDefaultConfig.cxnPointStroke,strokeWidth:n.ShapeDefaultConfig.cxnPointStrokeWidth,evented:!0})}};let wt=class extends a.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(l.SheetSkeletonManagerService).getCurrentSkeleton())return;let{scene:t}=e,r=this._getDrawingRect();if(!r)return;let i=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!i||!(0,n.isConnectorShape)(i.getShapeType()))return;let a=i.getConnectorLinePoints();if(a.length<2)return;let o=new n.ConnectorCoordinateTransform(r),s=a[0],c=a[a.length-1],u=o.localToWorld(s),d=o.localToWorld(c);this._addShapeConnectorHandlerObject(t,{...u},!0),this._addShapeConnectorHandlerObject(t,{...d},!1)}_addShapeConnectorHandlerObject(e,t,r){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let i=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${r?`start`:`end`}`,a=e.getObjectIncludeInGroup(i);if(a){a.transformByState({left:t.x-n.ShapeDefaultConfig.cxnPointRadius,top:t.y-n.ShapeDefaultConfig.cxnPointRadius});return}let s=new Ct(i,{left:t.x-n.ShapeDefaultConfig.cxnPointRadius,top:t.y-n.ShapeDefaultConfig.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:r,width:n.ShapeDefaultConfig.cxnPointRadius*2,height:n.ShapeDefaultConfig.cxnPointRadius*2,zIndex:o.DRAWING_OBJECT_LAYER_INDEX+1,evented:!0});this._connectorObjects.push(s),this._attachConnectorObjectEvent(s,e,r),e.addObject(s,o.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(l.SheetSkeletonManagerService).getSkeleton(t))return r;let a=i.with(l.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,l.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,r,i,a,o){let s=o===n.ShapeTypeEnum.Line||o===n.ShapeTypeEnum.StraightConnector1,c=r?t:e,l=r?e:t,u=this._activeShapeModel.getConnectorLinePoints(),d=this._activeShapeModel.getShapeType(),f=(0,n.isCurvedConnectorShape)(d),p=n.ConnectorCoordinateTransform.getBentTypeFromPoints(u,f),m=s?n.ConnectorCoordinateTransform.computeStraightConnectorLayout(c,l):n.ConnectorCoordinateTransform.computeConnectorResizeLayout(e,t,r,p);i?this._executeConnectionCommand(m,i,r,a):this._executeResizeCommand(m,a)}_handleConnectedEndpointPointerUp(e,t,r,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:r=0,width:i=0,height:a=0,angle:o}=e.transform;c=(0,n.getBasicShapeRotateBound)({left:t,top:r,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=r?l:o,d=r?o:l,f=this._activeShapeModel.getShapeType(),p=(0,n.routeConnectorLineShape)(u,d,f);this._activeShapeModel.removeLinePoints();let m=(0,n.computeConnectorRouteLayout)(p,f);i?this._executeConnectedRouteConnectionCommand(m,i,e,r,a):this._executeConnectedRouteResizeCommand(m,e,r,a)}_executeConnectionCommand(e,t,r,a){let o=this._activeShapeModel.getShapeData().relation,s={...o},c={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?s.from=c:s.to=c;let l=this._activeShapeModel.getShapeType(),u=(0,n.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:a,oldRelation:o,newRelation:s,newLineType:u.lineType,oldLineType:l};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,d)}_executeResizeCommand(e,t){let r=this._activeShapeModel.getShapeType(),a=(0,n.computeConnectorRouteLayout)(e.worldPoints,r),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:a.adjustValues,oldAdjustValues:t,newLineType:a.lineType,oldLineType:r};this._commandService.executeCommand(i.UpdateLineShapeResizeCommand.id,o)}_executeConnectedRouteConnectionCommand(e,t,n,r,a){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:a,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:o,newRelation:s};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,l)}_executeConnectedRouteResizeCommand(e,t,n,r){let a=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:a,newRelation:o};this._commandService.executeCommand(i.UpdateConnectorRelationCommand.id,s)}_attachConnectorObjectEvent(e,t,r){this.disposeWithMe((0,a.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 n.ConnectorCoordinateTransform(this._baseDrawingRect),d=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),f=t.getObjectIncludeInGroup(d);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=r?l.localToWorld(h):l.localToWorld(m);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((n,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:n.offsetX/o+a.x,y:n.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,u.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,r,f,e):this._handleFreeEndpointMove(s,g,r,f,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,n)=>{this._handleConnectorPointerUp(t,g,e,r,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,d=(0,u.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:r}),f=a.getObjectIncludeInGroup(d);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,r,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,n.routeConnectorLineShape)(u,d,f);p&&i.updateLinePoints(p);let m=(0,n.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,r,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 n.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=n.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$(a.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(e.pipe((0,d.switchMap)(e=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?(0,d.of)(i):d.EMPTY})):d.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===a.DrawingTypeEnum.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&(0,n.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===a.DrawingTypeEnum.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===a.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,r,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:r=0,width:i=0,height:a=0,angle:o}=e.transform;u=(0,n.getBasicShapeRotateBound)({left:t,top:r,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=r?d:s,p=r?s:d,m=this._activeShapeModel.getShapeType(),h=(0,n.routeConnectorLineShape)(f,p,m);h&&this._activeShapeModel.updateLinePoints(h);let g=(0,n.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-n.ShapeDefaultConfig.cxnPointRadius,top:_.y-n.ShapeDefaultConfig.cxnPointRadius})}_handleFreeEndpointMove(e,t,r,i,a){var o,s;let c=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e,l=n.ConnectorCoordinateTransform.computeConnectorResizeLayout(t,c,r);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-n.ShapeDefaultConfig.cxnPointRadius,top:u.y-n.ShapeDefaultConfig.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:r}=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===r);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,n.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()}};wt=A([k(1,a.ICommandService),k(2,o.IRenderManagerService),k(3,u.IDrawingManagerService),k(4,a.IUniverInstanceService),k(5,(0,a.Inject)(i.SheetsShapeService)),k(6,(0,a.Inject)(M)),k(7,(0,a.Inject)(G))],wt);let q=class extends a.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:o,scene:s,resourceCollector:c}=t,l=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[o];return l==null||l.order.forEach(e=>{let t=l.data[e];t.drawingType===a.DrawingTypeEnum.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,s,{resourceCollector:c})}),n(e)}}))}};q=A([k(0,(0,a.Inject)(l.SheetPrintInterceptorService)),k(1,u.IDrawingManagerService),k(2,(0,a.Inject)(j))],q);let J=class extends a.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,i.ToggleSheetsShapeFlipCommand.id,i.SetSheetsShapeRotateCommand.id,i.SetSheetsShapeTextVerticalToggleCommand.id,i.UpdateLineShapeResizeCommand.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===i.InsertShapeCommand.id||t.id===i.SetShapeDrawingDataCommand.id||t.id===i.UpdateConnectorRelationCommand.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=(0,s.getSheetCommandTarget)(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==a.SheetTypes.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};J=A([k(0,(0,a.Inject)(a.ICommandService)),k(1,(0,a.Inject)(a.IUniverInstanceService)),k(2,(0,a.Inject)(a.LocaleService)),k(3,(0,a.Inject)(s.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,u.getDrawingShapeKeyByDrawingSearch)(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};Y=A([k(0,o.IRenderManagerService)],Y);let X=class extends a.Plugin{constructor(e=ft,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...o}=(0,a.merge)({},ft,this._config);this._configService.setConfig(dt,o),this._initCommands()}onStarting(){this._injector.add([gt]),this._injector.get(gt),(0,a.registerDependencies)(this._injector,[[H],[W],[j],[q],[Y],[z],[U],[R],[J]])}onReady(){(0,a.registerDependencies)(this._injector,[[G],[M],[K]]),(0,a.touchDependencies)(this._injector,[[K],[M]]),[[G],[pt],[wt],[vt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,e))})}onRendered(){(0,a.touchDependencies)(this._injector,[[H],[W],[j],[q],[Y],[z],[U],[R],[J]])}onSteady(){this._injector.get(H).initShapePopupMenu()}_initCommands(){[N,S,re,ut].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E(X,`type`,a.UniverInstanceType.UNIVER_SHEET),E(X,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E(X,`packageName`,ct),E(X,`version`,lt),X=A([(0,a.DependentOn)(h.UniverLicensePlugin,g.UniverDocsPlugin,u.UniverDrawingPlugin,o.UniverRenderEnginePlugin,s.UniverSheetsPlugin,_.UniverDocsUIPlugin,c.UniverSheetsDrawingPlugin,r.UniverShapeEditorPlugin,v.UniverSheetsDrawingMobileUIPlugin,i.UniverSheetsShapePlugin,l.UniverSheetsMobileUIPlugin,e.UniverShapeEditorMobileUIPlugin,t.UniverMobileUIPlugin),k(1,(0,a.Inject)(a.Injector)),k(2,a.ICommandService),k(3,a.IConfigService),k(4,o.IRenderManagerService)],X);const Tt={type:a.CommandType.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function Et(){let e=(0,t.useDependency)(u.IDrawingManagerService),n=(0,t.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return n.length===0?null:/* @__PURE__ */ (0,m.jsx)(`div`,{children:/* @__PURE__ */ (0,m.jsxs)(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ (0,m.jsx)(f.DrawingCommonPanel,{drawings:n,hasCropper:!1}),/* @__PURE__ */ (0,m.jsx)(v.SheetDrawingAnchor,{drawings:n})]})})}function Dt(n){let{unitId:r,subUnitId:i,shapeId:o}=n,s=(0,t.useDependency)(a.ICommandService),c=(0,t.useDependency)(Y);return/* @__PURE__ */ (0,m.jsx)(e.ShapeEditPanel,{...n,positionEditor:/* @__PURE__ */ (0,m.jsx)(Et,{}),onUpdateShapeData:(e,t)=>{C(s,r,i,o,e,t)},onUpdateLineShapeData:(e,t)=>{w(s,r,i,o,e,t)},onUpdateShapeFillImage:e=>{c.updateShapeFillImage({unitId:r,subUnitId:i,drawingId:o},e)}})}function Ot(n){let r=(0,t.useDependency)(e.ShapeFloatingToolbarService),i=(0,t.useObservable)(()=>r.visible$,r.getVisible(),!1,[r]),a=n.popup.extraProps;return!a||!i?null:/* @__PURE__ */ (0,m.jsx)(kt,{...a,canvasElement:n.popup.canvasElement})}function kt(r){let o=(0,t.useDependency)(a.ICommandService),s=(0,t.useDependency)(i.SheetsShapeService),{unitId:l,subUnitId:u,drawingId:d,drawingType:f,shapeType:p}=r,[h,g]=(0,b.useState)(r.shapeData),_=(0,b.useMemo)(()=>(0,e.getTextStyle)(h),[h]),v=(0,b.useMemo)(()=>(0,e.getTextModel)(h),[h]);(0,b.useEffect)(()=>{let e=o.onCommandExecuted(e=>{if(e.id!==i.UpdateSheetsShapeDataMutation.id)return;let t=s.getShapeDataById(l,u,d);t&&g(t)});return()=>e.dispose()},[o,d,s,u,l]);let y=e=>{g(t=>({...t,...e}))},x=t=>{let n=(0,e.buildShapeTextDataUpdate)(h,t);C(o,l,u,d,{oldShapeData:{shapeText:h.shapeText}},n),y(n)},S=(0,e.useFormulaShapeToolbar)({hostType:a.UniverInstanceType.UNIVER_SHEET,unitId:l,subUnitId:u,shapeId:d,shapeData:h,onUpdateBinding:e=>{let t={formulaBinding:e};C(o,l,u,d,{oldShapeData:{formulaBinding:h.formulaBinding}},t),y(t)}});return/* @__PURE__ */ (0,m.jsxs)(m.Fragment,{children:[/* @__PURE__ */ (0,m.jsx)(e.ShapeFloatingToolbar,{canvasElement:r.canvasElement,shapeData:h,shapeType:p,textStyle:{ff:n.ShapeDefaultConfig.shapeText.fontFamily,fs:n.ShapeDefaultConfig.shapeText.fontSize,cl:{rgb:n.ShapeDefaultConfig.shapeText.color},..._},textModel:v?{ha:v.ha??a.HorizontalAlign.LEFT,va:v.va??a.VerticalAlign.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:n.ShapeDefaultConfig.fill,defaultGradientEndColor:n.ShapeDefaultConfig.gradientEndColor,defaultStrokeColor:n.ShapeDefaultConfig.stroke,extensionGroups:S.extensionGroups,floatingObjectToolbarPosition:t.FloatingObjectToolbarPosition.SHEET,onUpdateShapeData:(e,t)=>{C(o,l,u,d,e,t),t&&y(t)},onUpdateText:x,onOpenPanel:()=>{o.executeCommand(L.id,{unitId:l,subUnitId:u,drawingId:d})},onDelete:()=>{o.executeCommand(c.RemoveSheetDrawingCommand.id,{unitId:l,drawings:[{unitId:l,subUnitId:u,drawingId:d,drawingType:f}]})}}),S.panel]})}function At(e){return!!e&&`axisAlignSheetTransform`in e}const jt=(0,b.memo)(()=>{let n=(0,t.useDependency)(z),r=(0,t.useDependency)(i.SheetsShapeService),s=(0,t.useDependency)(u.IDrawingManagerService),d=(0,t.useDependency)(a.ICommandService),f=(0,t.useDependency)(t.UndoRedoGroupService),p=(0,t.useDependency)(o.IRenderManagerService),h=(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=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n});return r==null?void 0:r.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:n,shapeText:r,oldShapeText:i,hostSize:a})=>{f.run(e,()=>{var o;let u=d.syncExecuteCommand(S.id,{unitId:e,subUnitId:t,shapeId:n,shapeData:{shapeText:r},oldShapeJSON:{oldShapeData:{shapeText:i}}});if(!u||!a)return u;let f=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),m=f==null?void 0:f.transform;if(!At(f)||!m)return!1;let h={...m,width:a.width,height:a.height},g=(o=p.getRenderUnitById(e))==null||(o=o.with(l.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:o.skeleton;return d.syncExecuteCommand(c.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...f,transform:h,axisAlignSheetTransform:g?(0,c.transformToAxisAlignPosition)(h,g)??f.axisAlignSheetTransform:f.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:n,width:r,height:i})=>{var a;let o=s.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=o==null?void 0:o.transform;if(!At(o)||!u)return;let f={...u,width:r,height:i},m=(a=p.getRenderUnitById(e))==null||(a=a.with(l.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:a.skeleton,h=m?(0,c.transformToAxisAlignPosition)(f,m)??o.axisAlignSheetTransform:o.axisAlignSheetTransform;d.executeCommand(c.SetSheetDrawingCommand.id,{unitId:e,drawings:[{...o,transform:f,axisAlignSheetTransform:h}]})},allowHostSizeShrink:({unitId:t,subUnitId:n,shapeId:i})=>(0,e.shouldAllowShapeTextEditorHostSizeShrink)(r.getShapeDataById(t,n,i)),deferHostSizeUpdateDuringEditing:()=>!0}),[d,s,p,r,f]),g=(0,b.useMemo)(()=>({viewportKeys:{main:o.SHEET_VIEWPORT_KEY.VIEW_MAIN,leftTop:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,top:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,left:o.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(l.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ (0,m.jsx)(e.ShapeTextEditorContainer,{adapter:h,editingService:n,editorUnitId:I,positionOptions:g})});let Mt=class extends a.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:y.ObjectLayersIcon})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:y.FlipHorizontalIcon})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:y.FlipVerticalIcon})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:y.BottomIcon})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:y.MoveDownIcon})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:y.MoveUpIcon})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:y.ShapeFormatSettingIcon})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:y.TopmostIcon}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(P,Dt)),this.disposeWithMe(this._componentManager.register(F,mt)),this.disposeWithMe(this._componentManager.register(de,_e)),this.disposeWithMe(this._componentManager.register(fe,me)),this._componentManager.hasDefault(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT)||this.disposeWithMe(this._componentManager.register(f.IMAGE_CLIP_SHAPE_PICKER_COMPONENT,ge)),this.disposeWithMe(this._componentManager.register(ie,Ot)),this.disposeWithMe(this._componentManager.register(Ae,Ne)),this.disposeWithMe(this._componentManager.register(ke,Pe)),this.disposeWithMe(this._componentManager.register(je,Fe)),this.disposeWithMe(this._componentManager.register(Me,Ie)),this.disposeWithMe(this._componentManager.register(oe,e.ShapeTextFloatToolbar)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,jt))}};Mt=A([k(0,(0,a.Inject)(t.ComponentManager)),k(1,(0,a.Inject)(t.IconManager))],Mt);let Nt=class extends a.Disposable{constructor(t,n,r,i,c,l,u,f,p){super();let m=e=>{var t,n;return(((t=f.getPermissionPoint(new s.WorkbookEditablePermission(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=f.getPermissionPoint(new s.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 e=c.getFocusDrawings(),n=e.length===1?e[0]:null;return(n==null?void 0:n.drawingType)===a.DrawingTypeEnum.DRAWING_SHAPE&&n.unitId===t.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe((0,e.registerShapeFormatPainter)(t,n,{changes$:(0,d.merge)(c.focus$,i.editingParams$,f.permissionPointUpdate$),isActive:()=>{var e;return((e=l.getFocusedUnit())==null?void 0:e.getUnitId())===t.unitId&&!u.getContextValue(a.FOCUSING_SHAPE_TEXT_EDITOR)&&c.getFocusDrawings().some(e=>e.unitId===t.unitId)},getSelectedTarget:g,getSource:()=>{let e=g();return e?h(e):null},getTarget:e=>{let n=t.scene.pick(new o.Vector2(e.offsetX,e.offsetY));if(!(n instanceof D))return null;let r={unitId:t.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}})}))}};Nt=A([k(1,(0,a.Inject)(t.FormatPainterSessionService)),k(2,(0,a.Inject)(i.SheetsShapeService)),k(3,(0,a.Inject)(z)),k(4,u.IDrawingManagerService),k(5,a.IUniverInstanceService),k(6,a.IContextService),k(7,a.IPermissionService),k(8,a.ICommandService)],Nt);const Pt=`sheets-shape-contextual-ribbon`;let Z=class extends a.Disposable{constructor(e,t,n,r,i,o){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=o,E(this,`_visible`,!1),this._menuManagerService.mergeMenu(at),this.disposeWithMe((0,a.toDisposable)(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,Pt),this._hide(),super.dispose()}_update(){var t;let n=this._drawingManagerService.getFocusDrawings(),r=n.length===1?n[0]:void 0;if((r==null?void 0:r.drawingType)!==a.DrawingTypeEnum.DRAWING_SHAPE||this._univerInstanceService.getUnitType(r.unitId)!==a.UniverInstanceType.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,Pt),this._hide();return}let i=(t=this._renderManagerService.getRenderUnitById(r.unitId))==null?void 0:t.engine.getCanvasElement(),o=(0,e.resolveShapeContextualRibbonHostMode)(i)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(o,Pt),o?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,t.IMenuManagerService),k(1,t.IRibbonService),k(2,u.IDrawingManagerService),k(3,a.IUniverInstanceService),k(4,o.IRenderManagerService),k(5,(0,a.Inject)(e.ShapeFloatingToolbarService))],Z);let Ft=class extends e.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})}};Ft=A([k(1,(0,a.Inject)(g.DocSelectionManagerService)),k(2,(0,a.Inject)(_.DocCanvasPopManagerService)),k(3,(0,a.Inject)(_.DocSelectionRenderService)),k(4,a.ICommandService),k(5,(0,a.Inject)(_.DocEventManagerService)),k(6,(0,a.Inject)(e.ShapeTextHyperLinkPopupService)),k(7,(0,a.Inject)(g.DocInterceptorService)),k(8,(0,a.Inject)(_.DocRenderController)),k(9,(0,a.Inject)(z))],Ft);let It=class extends e.ShapeTextHyperLinkHoverController{constructor(t,n,r,i,a){super(t,n,{editing$:r.editingParams$,resolve:r=>{var c,l,u;let d=new o.Vector2(r.offsetX,r.offsetY),f=((c=t.scene.getActiveViewportByCoord(d))==null?void 0:c.transformVector2SceneCoord(d))??d,p=(0,e.resolveShapeTextHyperLinkObject)(t.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:e.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 s.WorkbookCopyPermission(p.unitId).id))==null?void 0:l.value)!==!1&&((u=a.getPermissionPoint(new s.WorksheetCopyPermission(p.unitId,p.subUnitId).id))==null?void 0:u.value)!==!1},attachPopup:()=>i.attachPopupToObject(h,g)}}}),this.disposeWithMe(t.unit.activeSheet$.subscribe(()=>this.clear()))}};It=A([k(1,(0,a.Inject)(e.ShapeTextHyperLinkPopupService)),k(2,(0,a.Inject)(z)),k(3,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(4,a.IPermissionService)],It);let Q=class extends a.Disposable{constructor(e,t,n,r,i,o,s,c,l,u,d){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=o,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$(a.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(st)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe((0,e.bindRenderTransformerLifecycle)(this._renderManagerService,a.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(t){let n=new a.DisposableCollection;return n.add(t.createControl$.subscribe(()=>{let n=t.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!==a.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:o,subUnitId:s,drawingId:c,drawingType:u}=i,d=this._getShapeInfo(o,s,c);if(!d)return;this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!0);let f=this._renderManagerService.getRenderUnitById(o),p=((f==null?void 0:f.isMainScene)===!1?f.with(l.SheetCanvasPopManagerService):this._sheetCanvasPopManagerService).attachPopupToObject(r,{componentKey:ie,direction:`vertical-center`,offset:[0,e.SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET],extraProps:{unitId:o,subUnitId:s,drawingId:c,drawingType:u,shapeType:d.shapeType,shapeData:d.shapeData}});this._disposePopups.push(this.disposeWithMe(p)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===o&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:o,subUnitId:s,drawingId:c}])})),n.add(t.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),n.add(t.changing$.subscribe(()=>{this._clearPopups()})),n.add(t.changeStart$.subscribe(()=>{this._clearPopups()})),(0,a.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===Tt.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===i.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===a.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===a.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(a.FOCUSING_COMMON_DRAWINGS,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(P),this._sidebarDisposable=null,this._contextService.setContextValue(a.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)}};Q=A([k(0,a.IUniverInstanceService),k(1,(0,a.Inject)(t.ISidebarService)),k(2,t.IMenuManagerService),k(3,(0,a.Inject)(i.SheetsShapeService)),k(4,(0,a.Inject)(a.LocaleService)),k(5,a.ICommandService),k(6,u.IDrawingManagerService),k(7,(0,a.Inject)(l.SheetCanvasPopManagerService)),k(8,a.IContextService),k(9,o.IRenderManagerService),k(10,(0,a.Inject)(z))],Q);let $=class extends a.Plugin{constructor(e=ft,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...o}=(0,a.merge)({},ft,this._config);this._configService.setConfig(dt,o),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_DOC,[Ft]),(0,a.touchDependencies)(this._injector,[[Q],[W],[j],[q]])}onSteady(){this._injector.get(Q).initShapePopupMenu()}onReady(){[[G],[M],[K]].forEach(e=>this._injector.add(e)),(0,a.touchDependencies)(this._injector,[[K],[M]]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[G]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[pt]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[wt]),this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[_t]),this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[It])),this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[Nt]))}onStarting(){this._injector.add([Mt]),this._injector.get(Mt);let e=this._injector;[[Q],[W],[j],[q],[Y],[z],[U],[R],[J],[Z]].forEach(t=>e.add(t)),(0,a.touchDependencies)(this._injector,[[Q],[W],[j],[Y],[z],[U],[R],[J],[Z]])}_initCommands(){[N,S,Tt,L,se,re,le,ue].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};E($,`type`,a.UniverInstanceType.UNIVER_SHEET),E($,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),E($,`packageName`,ct),E($,`version`,lt),$=A([(0,a.DependentOn)(h.UniverLicensePlugin,g.UniverDocsPlugin,u.UniverDrawingPlugin,f.UniverDrawingUIPlugin,o.UniverRenderEnginePlugin,s.UniverSheetsPlugin,_.UniverDocsUIPlugin,c.UniverSheetsDrawingPlugin,r.UniverShapeEditorPlugin,v.UniverSheetsDrawingUIPlugin,i.UniverSheetsShapePlugin,l.UniverSheetsUIPlugin,e.UniverShapeEditorUIPlugin),k(1,(0,a.Inject)(a.Injector)),k(2,a.ICommandService),k(3,a.IConfigService),k(4,o.IRenderManagerService)],$),exports.SheetsShapeUIContextualRibbonSchema=at,exports.SheetsShapeUIMenuSchema=st,Object.defineProperty(exports,"UniverSheetsShapeMobileUIPlugin",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"UniverSheetsShapeUIPlugin",{enumerable:!0,get:function(){return $}});