@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 +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +22 -22
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FormulaShapeAnimationController as e,MobileShapeEditorService as t,SHAPE_CHANGE_PICKER_COMPONENT as n,SHAPE_EDITOR_TRANSFORMER_CONFIG as r,SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET as i,ShapeEditPanel as a,ShapeFloatingToolbar as o,ShapeFloatingToolbarService as s,ShapeFloatingToolbarToggleFactory as c,ShapeFormulaRibbonControl as l,ShapeGroupEnum as u,ShapePickerDropdown as d,ShapePickerPanel as f,ShapeQuickStyleGallery as p,ShapeStyleRibbonControl as m,ShapeTextEditorContainer as h,ShapeTextFloatMenuRenderControllerBase as g,ShapeTextFloatToolbar as _,ShapeTextHyperLinkHoverController as v,ShapeTextHyperLinkInfo as y,ShapeTextHyperLinkPopupService as b,ShapeTextRibbonControl as x,ToggleShapeFloatingToolbarOperation as S,UniverShapeEditorMobileUIPlugin as ee,UniverShapeEditorUIPlugin as te,activateDrawingObject as ne,bindRenderTransformerLifecycle as re,buildShapeTextDataUpdate as ie,clearActiveDrawingObjects as ae,createShapeTextHyperLinkRegions as oe,drawFormulaShapeAnimationLayers as se,getDrawingTypeNameKey as ce,getTextModel as le,getTextStyle as ue,normalizeShapeTextModel as de,plainShapeTextToDocumentData as fe,prepareShapeTextDocumentData as pe,registerShapeFormatPainter as me,resolveFormulaShapeAutoFitSize as he,resolveShapeContextualRibbonHostMode as ge,resolveShapeTextDocumentPageHeight as _e,resolveShapeTextDocumentRenderLayout as ve,resolveShapeTextEditorBehaviorShapeData as ye,resolveShapeTextEditorWrapStrategy as be,resolveShapeTextHyperLinkAt as xe,resolveShapeTextHyperLinkObject as Se,shouldAllowShapeTextEditorHostSizeShrink as Ce,shouldClipShapeTextDocument as we,useFormulaShapeToolbar as Te}from"@univerjs-pro/shape-editor-ui";import{ComponentManager as Ee,ContextMenuGroup as De,ContextMenuPosition as Oe,FloatingObjectToolbarPosition as ke,FormatPainterSessionService as Ae,ILayoutService as je,IMenuManagerService as Me,IRibbonService as Ne,ISidebarService as Pe,IconManager as Fe,MenuItemType as C,MenuManagerPosition as Ie,RibbonInsertGroup as Le,UndoRedoGroupService as Re,UniverMobileUIPlugin as ze,getMenuHiddenObservable as Be,useDependency as w,useObservable as Ve}from"@univerjs/ui";import{ConnectorCoordinateTransform as He,ImageSourceTypeEnum as Ue,ShapeArrowSizeEnum as We,ShapeArrowTypeEnum as Ge,ShapeDefaultConfig as T,ShapeFillEnum as Ke,ShapeLineTypeEnum as qe,ShapeModel as Je,ShapeRenderModeEnum as Ye,ShapeTypeEnum as Xe,computeConnectorRouteLayout as Ze,getBasicShapeRotateBound as Qe,isConnectorShape as E,isCurvedConnectorShape as $e,routeConnectorLineShape as et}from"@univerjs-pro/engine-shape";import{ShapeFormulaService as tt,UniverShapeEditorPlugin as nt,applyQuickStyleToShapeData as rt,cloneShapeDataForType as it,createShapeFormulaDocument as at,createShapeTextBoxShapeData as ot,getShapeQuickStylePreset as st,getShapeQuickStyleType as ct,resolveActiveShapeQuickStylePresetId as lt}from"@univerjs-pro/shape-editor";import{DEFAULT_SHAPE_HEIGHT as ut,DEFAULT_SHAPE_WIDTH as dt,InsertShapeCommand as ft,InsertSheetsShapeMutation as pt,RemoveSheetsShapeMutation as mt,SetShapeDrawingDataCommand as ht,SetSheetsShapeRotateCommand as gt,SetSheetsShapeTextVerticalToggleCommand as _t,SheetsShapeService as D,ToggleSheetsShapeFlipCommand as vt,UniverSheetsShapePlugin as yt,UpdateConnectorRelationCommand as bt,UpdateLineShapeResizeCommand as xt,UpdateSheetsShapeDataMutation as O}from"@univerjs-pro/sheets-shape";import{ArrangeTypeEnum as St,BooleanNumber as Ct,CommandType as k,CustomCommandExecutionError as wt,DependentOn as Tt,Disposable as A,DisposableCollection as Et,DocumentDataModel as Dt,DrawingTypeEnum as j,FOCUSING_COMMON_DRAWINGS as Ot,FOCUSING_SHAPE_TEXT_EDITOR as kt,HorizontalAlign as At,ICommandService as M,IConfigService as jt,IContextService as Mt,IImageIoService as Nt,IPermissionService as Pt,IURLImageService as Ft,IUndoRedoService as It,IUniverInstanceService as N,Inject as P,Injector as Lt,LocaleService as Rt,Plugin as zt,SheetTypes as F,ThemeService as Bt,Tools as Vt,UniverInstanceType as I,VerticalAlign as Ht,createInternalEditorID as Ut,generateRandomId as Wt,merge as Gt,registerDependencies as Kt,toDisposable as qt,touchDependencies as Jt}from"@univerjs/core";import{CURSOR_TYPE as Yt,Circle as Xt,DRAWING_OBJECT_LAYER_INDEX as L,DocumentSkeleton as Zt,DocumentViewModel as Qt,Documents as $t,IRenderManagerService as R,Image as en,RENDER_CLASS_TYPE as tn,SHEET_VIEWPORT_KEY as nn,Shape as rn,Transform as an,UniverRenderEnginePlugin as on,Vector2 as sn}from"@univerjs/engine-render";import{CopySheetCommand as cn,RemoveSheetCommand as ln,SheetInterceptorService as un,SheetPermissionCheckController as dn,SheetSkeletonService as fn,SheetsSelectionsService as pn,UniverSheetsPlugin as mn,WorkbookCopyPermission as hn,WorkbookEditablePermission as gn,WorksheetCopyPermission as _n,WorksheetEditPermission as vn,attachRangeWithCoord as yn,discreteRangeToRange as bn,getSheetCommandTarget as xn}from"@univerjs/sheets";import{DrawingApplyType as z,ISheetDrawingService as Sn,RemoveSheetDrawingCommand as Cn,SetDrawingApplyMutation as B,SetDrawingArrangeCommand as wn,SetSheetDrawingCommand as Tn,SheetDrawingAnchorType as En,UniverSheetsDrawingPlugin as Dn,applySheetDrawingPlacement as On,transformDrawingsToChartSheet as kn,transformToAxisAlignPosition as An,transformToDrawingPosition as jn}from"@univerjs/sheets-drawing";import{COPY_TYPE as Mn,ISheetClipboardService as Nn,PREDEFINED_HOOK_NAME as Pn,SHEET_VIEW_KEY as Fn,SheetCanvasPopManagerService as In,SheetPasteCommand as Ln,SheetPrintInterceptorService as Rn,SheetScrollManagerService as zn,SheetSkeletonManagerService as V,UniverSheetsMobileUIPlugin as Bn,UniverSheetsUIPlugin as Vn,deriveStateFromActiveSheet$ as Hn,getCurrentRangeDisable$ as Un,getViewportByCell as Wn}from"@univerjs/sheets-ui";import{IDrawingManagerService as H,SetDrawingSelectedOperation as Gn,UniverDrawingPlugin as Kn,getDrawingShapeKeyByDrawingSearch as U,getOrCreateDrawingCopyPlan as qn}from"@univerjs/drawing";import{BehaviorSubject as Jn,EMPTY as W,Observable as Yn,defer as Xn,distinctUntilChanged as Zn,map as Qn,merge as $n,of as er,startWith as tr,switchMap as nr}from"rxjs";import{DrawingCommonPanel as rr,DrawingImageClipService as ir,DrawingRenderService as ar,IMAGE_CLIP_SHAPE_PICKER_COMPONENT as or,MobileObjectListPanel as sr,OBJECT_LIST_FLOATING_SECTION_ID as cr,ObjectListPanelBase as lr,UniverDrawingUIPlugin as ur,getCurrentUnitInfo as dr,getObjectListPanelSectionIdForDrawingType as fr,insertGroupObject as pr}from"@univerjs/drawing-ui";import{MobileDropdown as mr}from"@univerjs/design";import{Fragment as hr,jsx as G,jsxs as gr}from"react/jsx-runtime";import{UniverLicensePlugin as _r}from"@univerjs-pro/license";import{DocInterceptorService as vr,DocSelectionManagerService as yr,UniverDocsPlugin as br}from"@univerjs/docs";import{DocCanvasPopManagerService as xr,DocEventManagerService as Sr,DocRenderController as Cr,DocSelectionRenderService as wr,UniverDocsUIPlugin as Tr}from"@univerjs/docs-ui";import{SheetDrawingAnchor as Er,SheetsDrawingGroupCopyPasteController as Dr,UniverSheetsDrawingMobileUIPlugin as Or,UniverSheetsDrawingUIPlugin as kr}from"@univerjs/sheets-drawing-ui";import{BottomIcon as Ar,FlipHorizontalIcon as jr,FlipVerticalIcon as Mr,MoveDownIcon as Nr,MoveUpIcon as Pr,ObjectLayersIcon as Fr,ShapeFormatSettingIcon as Ir,TopmostIcon as Lr}from"@univerjs/icons";import{memo as Rr,useEffect as zr,useMemo as Br,useReducer as Vr,useState as Hr}from"react";function Ur(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)?Ur(a,i):a}return n}const K={type:k.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(D),{unitId:r,subUnitId:i,shapeType:a,shapeId:o,shapeData:s,replaceShapeData:c,oldShapeJSON:l}=t;if(!n.getShapeModel(r,i,o))return!1;let u=e.get(M),d=e.get(It),{oldShapeType:f,oldShapeData:p={}}=l,m=c?p:Ur(p,s||{}),h={id:O.id,params:{unitId:r,subUnitId:i,shapeId:o,shapeType:a,shapeData:s,replace:c}},g={id:O.id,params:{unitId:r,subUnitId:i,shapeId:o,shapeType:f,shapeData:m,replace:c}};return u.syncExecuteCommand(h.id,h.params)?(d.pushUndoRedo({unitID:r,undoMutations:[g],redoMutations:[h]}),!0):!1}};function Wr(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(K.id,o)}function Gr(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(K.id,o)}function Kr(e){"@babel/helpers - typeof";return Kr=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},Kr(e)}function qr(e,t){if(Kr(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(Kr(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Jr(e){var t=qr(e,`string`);return Kr(t)==`symbol`?t:t+``}function q(e,t,n){return(t=Jr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Yr(e,t,n){let r={...t,dataModel:{...t.dataModel??{},...n?{doc:n}:null}},i=ye(e,r),a=be(i);return{clip:we(i,a),wrapStrategy:a}}var J=class extends rn{constructor(t,n){super(t,n),q(this,`_hyperLinkRegions`,[]),q(this,`_props`,void 0),q(this,`_formulaAnimation`,new e(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),q(this,`_transformCalculateSrcRect`,!0),q(this,`_drawingType`,j.DRAWING_SHAPE),q(this,`isDrawingObject`,!0),this._props={...n},this._formulaAnimation.setPresentation(n.formulaPresentation,n.animateFormulaPresentation!==!1),this._init(),this._applyFormulaAutoFitSize()}_init(){this.onTransformChange$.subscribeEvent(e=>{this._updateSrcRectByTransform(e)})}setPrstGeom(e){this._props.prstGeom=e}resolveHyperLinkAt(e){if(this._props.isEditing)return null;let t=this.getInverseCoord(e),{width:n,height:r}=this.getRealBound();return xe(this._hyperLinkRegions,{x:(this.flipX?-t.x:t.x)+n/2,y:t.y+r/2})}setEditing(e){this._props.isEditing=e,this.makeDirty(!0)}setFormulaPresentation(e,t=!0){this._formulaAnimation.setPresentation(e,t),this._props.formulaPresentation=e,this._applyFormulaAutoFitSize(),this.makeDirty(!0)}_applyFormulaAutoFitSize(){let e=this._props.shapeModel,t=e.getShapeTextData(),n=de(t==null?void 0:t.dataModel),r=n==null?void 0:n.doc,i=this._formulaAnimation.getAutoFitPresentations();if(!r||i.length===0)return;e.updateContext({width:this.width,height:this.height});let a=he({documentData:i.map(e=>at(r,e)),height:this.height,shapeData:e.getShapeData(),textRect:e.getShapeTextRect({left:0,top:0,width:this.width,height:this.height}),width:this.width});if(a){var o;this.resize(a.width,a.height),(o=this.getScene())==null||(o=o.getTransformer())==null||o.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 tn.SHAPE}_draw(e,t,n,r){let i=this._props.shapeModel;if(!i||!t)return;let a=n??this.width,o=r??this.height,s={shapeType:i.getShapeType(),width:a,height:o},c={renderMode:Ye.Path,oKey:this.oKey,image:this._props.image,angle:this.angle};i.updateContext(s),e.save();let l={top:0,left:0,width:a,height:o},u=i.getDrawingEffectBounds(l);u?this._renderWithCache(e,u,e=>{i.render(e,l,c)}):(this._releaseRenderCache(),i.render(e,l,c)),e.restore();let d=i.getShapeTextData(),f=i.getShapeTextRect(l),p=i.isLineShape();if(d&&f&&!p){e.save(),this.getState().flipX&&e.scale(-1,1);let t=a/2,n=o/2;e.translate(-t,-n),e.beginPath(),this._drawShapeText(e,d,f),e.restore()}}getDrawingPoints(e){}_drawShapeText(e,t,n){var r;this._hyperLinkRegions=[],this._props.isEditing||(!((r=t.dataModel)!=null&&r.doc)&&`isRichText`in t&&t.isRichText===!1?this._drawSimpleText(e,t,n):this._drawRichText(e,t,n))}_drawSimpleText(e,t,n){this._drawRichText(e,{...t,text:t.text??``,dataModel:{doc:fe(t,`sheets-shape-text-${this.oKey}`)}},n)}_drawRichText(e,t,n){se(e,this._formulaAnimation,(e,r,i)=>{this._drawRichTextLayer(e,t,n,r,i===`current`)})}_drawRichTextLayer(e,t,n,r,i){let a=this._props.localeService;if(!t.dataModel||!a)return;let o=de(t.dataModel);if(!o)return;let s=o.doc;if(!s)return;let c=at(s,r),l=o.va??Ht.TOP,u=o.ha??At.LEFT,d=Yr(this._props.shapeModel.getShapeData(),t,c),f=t.isHorizontal,p=pe(c,{isHorizontal:f!==!1,textRect:n,verticalAlign:l,horizontalAlign:u,wrapStrategy:d.wrapStrategy}),m=new Dt(p),h=new Qt(m),g=Zt.create(h,a);g.calculate();let _=g.getActualSize().actualHeight,v=ve({contentHeight:_,verticalAlign:l,viewportHeight:n.height});m.updateDocumentStyle({pageSize:{width:f===!1?n.height:n.width,height:_e(c,v.contentHeight)}}),m.updateDocumentDataMargin({t:v.marginTop}),g.calculate();let y=new $t(`shape-text-${this.oKey}`,g,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});y.resize(n.width,v.contentHeight),e.save(),e.translateWithPrecision(n.left,n.top),d.clip&&(e.beginPath(),e.rect(0,v.clipTop,n.width,v.clipHeight),e.clip()),v.contentVerticalOffset&&e.translateWithPrecision(0,v.contentVerticalOffset),y.draw(e),i&&(this._hyperLinkRegions=oe(y,{left:n.left,top:n.top+v.contentVerticalOffset},d.clip?{left:n.left,right:n.left+n.width,top:n.top+v.clipTop,bottom:n.top+v.clipTop+v.clipHeight}:void 0)),e.restore(),y.dispose(),g.dispose(),h.dispose(),m.dispose()}render(e,t,n=!1){if(!this.visible)return this.makeDirty(!1),this;let{width:r,height:i,left:a,top:o}=this,s=this.getRealBound();if(r=s.width,i=s.height,a=s.left,o=s.top,this.isRender(t)){let{top:e,left:n,bottom:s,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+o<e||s<o)return this}let c=a+r/2,l=o+i/2,u=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new an;t.composeMatrix({...e}),u=t.getMatrix()}return e.save(),this._props.shapeModel.isRenderLinePointsMode===!0||e.transform(u[0],u[1],u[2],u[3],c,l),this._draw(e,t,r,i),e.restore(),this.makeDirty(!1),this}getInverseCoord(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=this.transform.getMatrix(),o=t+r/2,s=n+i/2,c=new an([a[0],a[1],a[2],a[3],o,s]),l=this.getParent();return(this.isInGroup&&(l==null?void 0:l.classType)===tn.GROUP?l.ancestorTransform.multiply(c):c).invert().applyPoint(e)}isHit(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=t+r/2,o=n+i/2,s=this.transform.getMatrix(),c=new an([s[0],s[1],s[2],s[3],a,o]),l=this.getParent(),u=(this.isInGroup&&(l==null?void 0:l.classType)===tn.GROUP?l.ancestorTransform.multiply(c):c).invert().applyPoint(e),d=r/2,f=i/2,p=this._props.shapeModel;return p&&p.isLineShape()?p.isHitLine(u.x,u.y,r,i):u.x>=-d-this.strokeWidth/2&&u.x<=d+this.strokeWidth/2&&u.y>=-f-this.strokeWidth/2&&u.y<=f+this.strokeWidth/2}dispose(){this._formulaAnimation.dispose(),this._props.shapeModel=null,super.dispose()}},Xr=class extends rn{constructor(e,t){super(e,t),q(this,`_shapeId`,null),q(this,`_adjName`,null),q(this,`_unitId`,null),q(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){Xt.drawWith(e,{radius:T.adjHandleSize,fill:T.adjHandleFill,stroke:T.adjHandleStroke,strokeWidth:1,evented:!0})}};function Y(e,t){return function(n,r){t(n,r,e)}}function X(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 Z=class extends A{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,q(this,`_formulaShapes`,/* @__PURE__ */ new Map),this.disposeWithMe(this._shapeFormulaService.presentationChanged$.subscribe(e=>{var t;(t=this._formulaShapes.get(this._formulaKey(e.unitId,e.subUnitId,e.shapeId)))==null||t.forEach(t=>t.setFormulaPresentation(e.presentation,e.animationEnabled))})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._formulaShapes.delete(this._formulaKey(e.unitId,e.subUnitId,e.drawingId))})}))}renderDrawingShape(e,t,n){let{transform:r,drawingType:i,isMultiTransform:a,transforms:o}=e;if(i===j.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(a&&o?o:[r]).flatMap((r,i)=>{var o;let s=U(e,a?i:void 0),c=t.getObjectIncludeInGroup(s);if(c)return c instanceof J&&this.refreshFormulaPresentation(c,{unitId:e.unitId,subUnitId:e.subUnitId,shapeId:e.drawingId}),c.transformByState(r),[];let l=this._createShape(e,r,s,t);if(!l)return[];let u=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return u&&(n==null||(o=n.resourceCollector)==null||o.add(u)),[l]})}_createShape(e,t,n,i){let{unitId:a,subUnitId:o,drawingId:s,groupId:c,hidden:l,selectable:u,prstGeom:d,srcRect:f}=e,p=this._sheetsShapeService.getShapeModel(a,o,s);if(!p)return;let m=this._drawingManagerService.getDrawingOrder(a,o),h=m.indexOf(s),g=E(p.getShapeType()),_=p.getShapeData().formulaBinding,v={unitId:a,subUnitId:o,shapeId:s};_&&this._shapeFormulaService.register(v,_);let y=new J(n,{...t,zIndex:h===-1?m.length-1:h,shapeModel:p,drawingType:j.DRAWING_SHAPE,localeService:this._localeService,shapeId:s,unitId:a,subUnitId:o,visible:l!==!0,evented:u!==!1,formulaPresentation:_?this._shapeFormulaService.getPresentation(v):void 0,animateFormulaPresentation:(_==null?void 0:_.animationEnabled)!==!1,transformerConfig:{...r,...g?{rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1}:{},moveBoundaryEnabled:!0}});if(_){let e=this._formulaKey(a,o,s),t=this._formulaShapes.get(e)??/* @__PURE__ */ new Set;t.add(y),this._formulaShapes.set(e,t)}return i.addObject(y,L),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(y),c&&pr({drawingId:c,unitId:a,subUnitId:o},y,i,this._drawingManagerService),d!=null&&y.setPrstGeom(d),f!=null&&y.setSrcRect(f),y}_formulaKey(e,t,n){return`${e}\u0000${t}\u0000${n}`}refreshFormulaPresentation(e,t){let n=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.shapeId),r=n==null?void 0:n.getShapeData().formulaBinding,i=this._formulaKey(t.unitId,t.subUnitId,t.shapeId);if(r){this._shapeFormulaService.register(t,r);let n=this._formulaShapes.get(i)??/* @__PURE__ */ new Set;n.add(e),this._formulaShapes.set(i,n)}else{var a;this._shapeFormulaService.unregister(t),(a=this._formulaShapes.get(i))==null||a.delete(e)}e.setFormulaPresentation(r?this._shapeFormulaService.getPresentation(t):void 0,(r==null?void 0:r.animationEnabled)!==!1)}refreshShapeFillImage(e){let t=e.shapeModel.getShapeData(),n=t.fill;!n||n.fillType!==Ke.PictureFill||!n.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let n=t.fill;if(!n||n.fillType!==Ke.PictureFill||!n.fillImageSource)return;let r=n.fillImageSource,i=n.fillImageSourceType??Ue.URL,a=this._imageIoService.getImageSourceCache(r,i);if(a)e.setFillImage(a);else return this._loadAndSetImage(e,r,i)}async _loadAndSetImage(e,t,n){let r;try{if(n===Ue.UUID)r=await this._imageIoService.getImage(t);else if(n===Ue.URL)try{r=await this._urlImageService.getImage(t)}catch{r=t}else r=t}catch(e){console.error(`[ShapeRender] Failed to resolve picture fill source`,e);return}await new Promise(i=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,n,a),e.setFillImage(a),i()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),i()},a.src=r})}};Z=X([Y(0,H),Y(1,P(D)),Y(2,P(Rt)),Y(3,Nt),Y(4,Ft),Y(5,P(tt))],Z);let Zr=class extends A{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,q(this,`_activeShapeId`,null),q(this,`_unitId`,null),q(this,`_subUnitId`,null),q(this,`_activeShapeAdjustPointList`,void 0),q(this,`_shapes`,[]),q(this,`_baseShapeLeft`,0),q(this,`_baseShapeTop`,0),q(this,`_baseShapeWidth`,0),q(this,`_baseShapeHeight`,0),q(this,`_isStartAdjusting`,!1),q(this,`_activeAdjustInfo`,void 0),q(this,`_activeShapeModel`,void 0),q(this,`_adjHandlerPointerMove`,void 0),q(this,`_adjHandlerPointerUp`,void 0),q(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(V).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:a}=i;if(!a||i.drawingType!==j.DRAWING_SHAPE)return;let{left:o,top:s,width:c,height:l,flipX:u,flipY:d,angle:f=0}=a;if(o===void 0||s===void 0)return;if(e){let e=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);e==null||e.updateContext({width:c??0,height:l??0}),this._activeShapeAdjustPointList=e==null?void 0:e.getDrawingPoints()}let p=this._activeShapeAdjustPointList;for(let e=0;e<p.length;e++){let t=p[e],r=t.x,i=t.y;if(u&&(r=(c||0)-r),d&&(i=(l||0)-i),f!==0){let e=(c||0)/2,t=(l||0)/2,n=f*Math.PI/180,a=Math.cos(n),o=Math.sin(n),s=r-e,u=i-t;r=e+(s*a-u*o),i=t+(s*o+u*a)}let a={x:r,y:i,adjName:t.adjName};this._addShapeAdjustControl(n,a,a.adjName,o,s,this._unitId,this._subUnitId)}}_updateShapeAdjustControls(e=!1){e&&(this._clearShapeAdjustControls(),this._createShapeAdjustControls(e))}_addShapeAdjustControl(e,t,n,r,i,a,o){if(!this._activeShapeId)return;let s=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${n}`);if(s){s.transformByState({left:t.x+r-T.adjHandleSize,top:t.y+i-T.adjHandleSize});return}let c={left:t.x+r-T.adjHandleSize,top:t.y+i-T.adjHandleSize,adjName:n,shapeId:this._activeShapeId,unitId:a,subUnitId:o,width:T.adjHandleSize+8,height:T.adjHandleSize+8,zIndex:L+1,evented:!0},l=new Xr(`shape-adjust-point-${this._activeShapeId}-${n}`,c);this._shapes.push(l),this._attachAdjustEvent(l,e,n),e.addObject(l,L+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(V).getSkeleton(t))return r;let a=i.with(zn),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=Wn(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(qt(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,s,c;let l=e.getDrawingSearch();this._activeAdjustInfo=this._getShapeAdjustInfosById(l.unitId,l.subUnitId,l.drawingId,n),this._activeShapeModel=this._sheetsShapeService.getShapeModel(l.unitId,l.subUnitId,l.drawingId);let u=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),{transform:d}=u;if(d){let{left:e,top:t,width:n,height:r}=d;this._baseShapeLeft=e||0,this._baseShapeTop=t||0,this._baseShapeWidth=n||0,this._baseShapeHeight=r||0}let f=!!((a=u.transform)!=null&&a.flipX),p=!!((o=u.transform)!=null&&o.flipY),m=((s=u.transform)==null?void 0:s.angle)||0;this._isStartAdjusting=!0,t.disableObjectsEvent();let h={...((c=this._activeAdjustInfo)==null?void 0:c.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(Yt.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s=r/o+n.x-this._baseShapeLeft,c=i/o+n.y-this._baseShapeTop;if(m!==0){let e=this._baseShapeWidth/2,t=this._baseShapeHeight/2,n=m*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=s-e,o=c-t;s=e+(a*r+o*i),c=t+(-a*i+o*r)}f&&(s=this._baseShapeWidth-s),p&&(c=this._baseShapeHeight-c);let u={x:s,y:c},d=this._activeShapeModel.calcAdjValues(e,u,a,f,p);if(Object.keys(d).length===0)return;for(let[e,t]of Object.entries(d))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseShapeWidth,height:this._baseShapeHeight});let h=this._drawingManagerService.getDrawingByParam({unitId:l.unitId,subUnitId:l.subUnitId,drawingId:l.drawingId});h&&(this._sheetDrawingShapeRenderController.renderDrawingShape(h,t),this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(l.unitId,l.subUnitId,l.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=l.unitId,t=l.subUnitId,n=l.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&&Wr(this._commandService,e,t,n,{oldShapeData:{adjustValues:h}},{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$(I.UNIVER_SHEET);this.disposeWithMe(e.pipe(nr(e=>e?e.activeSheet$.pipe(nr(t=>{if(!t)return W;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?er(i):W})):W)).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 J&&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!==O.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===j.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===I.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)===j.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())}))}};Zr=X([Y(0,H),Y(1,P(D)),Y(2,P(R)),Y(3,P(Z)),Y(4,N),Y(5,M)],Zr);const Qr={id:`drawing.operation.set-drawing-active`,type:k.OPERATION,handler:(e,t)=>{let n=e.get(H),r=e.get(R),i=e.get(Zr);if(t==null)return!0;if(t.length>0){var a;let e=(a=r.getRenderUnitById(t[0].unitId))==null?void 0:a.scene;if(e){let{unitId:n,subUnitId:i,drawingId:a}=t[0],s=U({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(s);if(c){var o;(o=r.getRenderUnitById(t[0].unitId))==null||(o=o.scene.getTransformer())==null||o.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},$r={type:k.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var n,r;let i=xn(e.get(N));if(!i)return!1;let{unitId:a,subUnitId:o,worksheet:s}=i,c=s.getConfig(),l=c.type??F.GRID;if(l!==F.GRID&&l!==F.CHART)return!1;let u=e.get(Pt);if(((n=u.getPermissionPoint(new gn(a).id))==null?void 0:n.value)!==!0||((r=u.getPermissionPoint(new vn(a,o).id))==null?void 0:r.value)!==!0)return!1;let d=e.get(M),{value:f,enhanceParams:p}=t,m={unitId:a,subUnitId:o,shapeType:f,shapeId:Wt()};if(l===F.CHART){let t=e.get(R).getRenderUnitById(a),n=t==null?void 0:t.components.get(Fn.CHART_PAGE);if(!t||!n||![n.left,n.top,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return!1;let r={row:0,column:0,rowOffset:0,columnOffset:0},i=kn([{unitId:a,subUnitId:o,drawingId:m.shapeId,drawingType:j.DRAWING_SHAPE,transform:{left:0,top:0,width:dt,height:ut},sheetTransform:{from:r,to:r},axisAlignSheetTransform:{from:r,to:r}}],{left:n.left,top:n.top,width:n.width,height:n.height},c.rightToLeft===Ct.TRUE);if(!(i!=null&&i.length))return!1;let s=i[0].transform;m.position={x:s.left,y:s.top},m.width=s.width,m.height=s.height}else{let t=e.get(pn).getCurrentLastSelection();if(!t)return!1;m.range=t.range}if(p){let{startArrow:t,endArrow:n,horizontal:r,vertical:i}=p,a=E(f),o=f===Xe.Rect;if(a&&(t||n)&&(m.shapeData={ln:{startArrow:t?{type:Ge.Arrow,size:We.Medium}:void 0,endArrow:n?{type:Ge.Arrow,size:We.Large}:void 0}}),o&&(r||i)){let t=e.get(Bt);m.shapeData=ot({fill:{fillType:Ke.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!r,stroke:{lineStrokeType:qe.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let h=d.syncExecuteCommand(ft.id,m);return h&&await d.executeCommand(Qr.id,[{unitId:a,subUnitId:o,drawingId:m.shapeId}]),h}},ei=`sheet.shape.edit.panel`,ti=`sheet.shape.object-list.panel`,ni=`sheet.shape.floating-toolbar`,ri=`sheets-shape-ui.ribbon.shape-format`,ii=Ut(`SHAPE_TEXT`),ai=`sheet.shape.text.float-menu`,oi={id:`sheet.operation.open-shape-object-list-panel`,type:k.COMMAND,handler:(e,t)=>{let n=e.get(Pe),r=e.get(Rt),i=e.get(N),a=e.get(M);return xn(i)?(t==null?void 0:t.value)===`close`?(n.close(ti),!0):(n.open({id:ti,header:{title:r.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:ti},onClose:()=>{a.syncExecuteCommand(Gn.id,[])},width:360}),!0):!1}},si={type:k.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function ci(e){let t=e.get(H).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==j.DRAWING_SHAPE)return null;let r=e.get(D),i=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),a=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return i===void 0||!a?null:{drawing:n,shapeData:a,shapeType:i}}const li={id:`sheet.operation.apply-shape-quick-style`,type:k.OPERATION,handler:(e,t)=>{let n=ci(e),r=st((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!r||r.type!==ct(n.shapeData))return!1;let i=rt(n.shapeData,r);if(!i)return!1;let{drawing:a}=n;return e.get(M).executeCommand(K.id,{unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.drawingId,shapeData:i,oldShapeJSON:{oldShapeData:n.shapeData}})}},ui={id:`sheet.operation.update-shape-type`,type:k.OPERATION,handler:(e,t)=>{let n=ci(e),r=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!n||!r||E(n.shapeType)||E(r))return!1;let i=it(n.shapeData,r);if(!i)return!1;let{drawing:a}=n;return e.get(M).executeCommand(K.id,{unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.drawingId,shapeType:r,shapeData:i,replaceShapeData:!0,oldShapeJSON:{oldShapeType:n.shapeType,oldShapeData:n.shapeData}})}};let Q=class extends A{constructor(e,t){super(),this._clipService=e,this._drawingManagerService=t,this._registerImageShapeClipDelegate(),this._clipService.setCanUseShapeClip(!0),this.disposeWithMe({dispose:()=>this._clipService.setCanUseShapeClip(!1)})}_registerImageShapeClipDelegate(){let e=this._clipService,t=/* @__PURE__ */ new Map,n=e.registerClipDelegate((e,n,r,i,a)=>{let o=n;if(o===Xe.None||n===`custom`)return!1;try{let s=t.get(n);return s||(s=new Je(o,`clip-${n}`),t.set(n,s)),s.clearAdjustValue(),a&&Object.keys(a).length>0&&s.setShapeData({adjustValues:a},!0),s.updateContext({width:r,height:i}),s.buildClipPath(e,{left:0,top:0,width:r,height:i})}catch{return!1}});this.disposeWithMe(n),this.disposeWithMe({dispose:()=>t.clear()})}clipByShape(e,t,n,r,i){let a=this._drawingManagerService.getDrawingData(e,t);if(!a[n])return;let o={...a[n],prstGeom:r,adjustValues:i};this._drawingManagerService.featurePluginUpdateNotification([o])}};Q=X([Y(0,P(ir)),Y(1,P(H))],Q);const di=`sheet.shape.picker.component`,fi=`sheet.image-clip.shape-picker.component`;function pi({onShapeClick:e,excludeGroups:t}){return/* @__PURE__ */ G(f,{excludeGroups:t,onShapeClick:e,scrollContainer:`parent`})}function mi(){let e=w(H),t=w(Q);return/* @__PURE__ */ G(d,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[u.Line],onShapeClick:n=>{let r=e.getFocusDrawings().find(e=>e.drawingType===j.DRAWING_IMAGE);if(!r)return;let{unitId:i,subUnitId:a,drawingId:o}=r;t.clipByShape(i,a,o,n.type)}})}function hi(){let e=w(H),t=w(Q);return/* @__PURE__ */ G(d,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[u.Line],DropdownComponent:mr,onShapeClick:n=>{let r=e.getFocusDrawings().find(e=>e.drawingType===j.DRAWING_IMAGE);if(!r)return;let{unitId:i,subUnitId:a,drawingId:o}=r;t.clipByShape(i,a,o,n.type)}})}function gi(){let e=w(Ee),t=w(H),n=w(N),r=t.getFocusDrawings()[0],i=r?n.getUnitType(r.unitId):void 0,a=i===I.UNIVER_DOC?`doc.image-clip.shape-picker.component`:i===I.UNIVER_SHEET?fi:void 0,o=a?e.get(a):void 0;return o?/* @__PURE__ */ G(o,{}):null}function _i(){let e=w(M);return/* @__PURE__ */ G(pi,{onShapeClick:t=>{e.executeCommand($r.id,{value:t.type,enhanceParams:{endArrow:t.endArrow,startArrow:t.startArrow,horizontal:t.horizontal,vertical:t.vertical}})}})}function vi(){return/* @__PURE__ */ G(_i,{})}function yi(e){return Hn(e.get(N),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??F.GRID;if(r===F.GRID)return Un(e);if(r!==F.CHART)return er(!0);let i=e.get(Pt),a=[new gn(t.getUnitId()).id,new vn(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe(tr(null),Qn(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),Zn())})}function bi(e){let t=e.get(N);return{id:$r.id,type:C.SELECTOR,selections:[{label:{name:di,hoverable:!1,selectable:!1,props:{id:$r.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:Hn(t,!1,()=>new Yn(e=>{e.next(!1)})),hidden$:Be(e,I.UNIVER_SHEET),disabled$:yi(e)}}function xi(e){return Hn(e.get(N),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??F.GRID;if(r===F.GRID)return Un(e);if(r!==F.CHART)return er(!0);let i=e.get(Pt),a=[new gn(t.getUnitId()).id,new vn(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe(tr(null),Qn(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),Zn())})}function Si(e){let t=e.get(Pe);return{id:oi.id,type:C.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:Xn(()=>t.sidebarOptions$.pipe(tr(t.options),Qn(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),Zn())),hidden$:Be(e,I.UNIVER_SHEET),disabled$:xi(e)}}const Ci=`sheet.menu.shape.flip-horizontal`,wi=`sheet.menu.shape.flip-vertical`;function Ti(e){let t=e.get(H).getFocusDrawings();return t.length===1&&t[0].drawingType===j.DRAWING_SHAPE?t[0]:null}function Ei(e){let t=e.get(H);return t.focus$.pipe(tr(t.getFocusDrawings()),Qn(e=>e.length!==1||e[0].drawingType!==j.DRAWING_SHAPE))}function Di(e){return{id:Ci,commandId:vt.id,type:C.BUTTON,title:`sheets-shape-ui.flipHorizontal`,tooltip:`sheets-shape-ui.flipHorizontal`,icon:`FlipHorizontalIcon`,hidden$:Ei(e),params:()=>{let t=Ti(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipH:!0}:void 0}}}function Oi(e){return{id:wi,commandId:vt.id,type:C.BUTTON,title:`sheets-shape-ui.flipVertical`,tooltip:`sheets-shape-ui.flipVertical`,icon:`FlipVerticalIcon`,hidden$:Ei(e),params:()=>{let t=Ti(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipV:!0}:void 0}}}const ki=`sheets-shape-ui.shape-format.quick-style-gallery`,Ai=`sheets-shape-ui.shape-format.style-ribbon-control`,ji=`sheets-shape-ui.shape-format.text-ribbon-control`,Mi=`sheets-shape-ui.shape-format.formula-ribbon-control`;function Ni(){let e=w(M),t=w(H),n=w(D),r=()=>{var e;let r=t.getFocusDrawings();if(r.length!==1||((e=r[0])==null?void 0:e.drawingType)!==j.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=n.getShapeTypeById(i,a,o),c=n.getShapeDataById(i,a,o);return s===void 0||!c?null:{unitId:i,subUnitId:a,drawingId:o,shapeType:s,shapeData:c}},i=Ve(()=>new Yn(n=>{let i=()=>n.next(r()),a=t.focus$.subscribe(i),o=e.onCommandExecuted(e=>{e.id===O.id&&i()});return i(),()=>{a.unsubscribe(),o.dispose()}}),r(),!1,[e,t,n]);return{selection:i,updateShapeData:t=>{i&&Wr(e,i.unitId,i.subUnitId,i.drawingId,{oldShapeData:i.shapeData},t)}}}function Pi(){let{selection:e,updateShapeData:t}=Ni();return e?/* @__PURE__ */ G(m,{shapeData:e.shapeData,shapeType:e.shapeType,onUpdateShapeData:t}):null}function Fi(){let e=w(M),t=w(Rt),{selection:n}=Ni();return n?/* @__PURE__ */ G(p,{type:ct(n.shapeData),ariaLabel:t.t(`sheets-shape-ui.quickStyles`),activePresetId:lt(n.shapeData),onSelect:t=>e.executeCommand(li.id,{presetId:t})}):null}function Ii(){let{selection:e,updateShapeData:t}=Ni();return e?/* @__PURE__ */ G(x,{fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:e.shapeData,onUpdateShapeData:t}):null}function Li(){var e;let{selection:t,updateShapeData:n}=Ni(),r=Te({hostType:I.UNIVER_SHEET,unitId:(t==null?void 0:t.unitId)??``,subUnitId:(t==null?void 0:t.subUnitId)??``,shapeId:(t==null?void 0:t.drawingId)??``,shapeData:t==null?void 0:t.shapeData,registerBinding:!1,showLabels:!0,dropdownSide:`bottom`,onUpdateBinding:e=>n({formulaBinding:e})}),i=((e=r.extensionGroups)==null?void 0:e.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return t!=null&&t.shapeData.formulaBinding?/* @__PURE__ */ G(l,{actions:i,panel:r.panel}):null}const Ri=`sheets-shape-ui.ribbon.shape-format.style-control`,zi=`sheets-shape-ui.ribbon.shape-format.text-control`,Bi=`sheets-shape-ui.ribbon.shape-format.formula-control`,Vi=`sheets-shape-ui.ribbon.shape-format.arrange-forward`,Hi=`sheets-shape-ui.ribbon.shape-format.arrange-backward`,Ui=`sheets-shape-ui.ribbon.shape-format.arrange-front`,Wi=`sheets-shape-ui.ribbon.shape-format.arrange-back`;function Gi(e){let t=e.get(M),n=e.get(H),r=e.get(D);return new Yn(i=>{let a=()=>{let t=Ki(e),n=t?r.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;i.next(n?lt(n)??``:``)},o=n.focus$.subscribe(a),s=t.onCommandExecuted(e=>{e.id===O.id&&a()});return a(),()=>{o.unsubscribe(),s.dispose()}})}function Ki(e){var t;let n=e.get(H).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===j.DRAWING_SHAPE?n[0]:null}function qi(e,t=!1){let n=e.get(M),r=e.get(H),i=e.get(D);return new Yn(a=>{let o=()=>{let n=Ki(e);if(!n){a.next(!0);return}let r=i.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);a.next(!r||t&&r.formulaBinding==null)},s=r.focus$.subscribe(o),c=n.onCommandExecuted(e=>{e.id===O.id&&o()});return o(),()=>{s.unsubscribe(),c.dispose()}})}function Ji(e){let t=e.get(H),n=e.get(D);return t.focus$.pipe(tr(t.getFocusDrawings()),Qn(()=>{let t=Ki(e),r=t?n.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return r===void 0||E(r)}))}function Yi(e){return{id:li.id,type:C.SELECTOR,icon:`PaintIcon`,title:`shape-editor-ui.toolbar.quickStyles`,tooltip:`shape-editor-ui.toolbar.quickStyles`,selections:[{label:{name:ki,hoverable:!1,selectable:!1}}],value$:Gi(e),hidden$:qi(e)}}function Xi(e){return{id:ui.id,type:C.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:n,hoverable:!1,selectable:!1}}],hidden$:Ji(e)}}function Zi(e,t,n=!1){return r=>({id:e,type:C.BUTTON,label:{name:t,hoverable:!1,selectable:!1},hidden$:qi(r,n)})}const Qi=Zi(Ri,Ai),$i=Zi(zi,ji),ea=Zi(Bi,Mi,!0);function ta(e,t,n,r){return i=>({id:e,commandId:wn.id,type:C.BUTTON,icon:n,title:r,tooltip:r,hidden$:qi(i),params:()=>{let e=Ki(i);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:t}:void 0}})}const na=ta(Vi,St.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),ra=ta(Hi,St.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),ia=ta(Ui,St.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),aa=ta(Wi,St.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function oa(e){let t=e.get(Pe);return{activated$:Xn(()=>t.sidebarOptions$.pipe(tr(t.options),Qn(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),Zn())),id:si.id,type:C.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:qi(e),params:()=>{let t=Ki(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}const sa={[Ie.RIBBON]:{[ri]:{order:100,title:`sheets-shape-ui.formatShape`,contextual:!0,"sheets-shape-ui.ribbon.shape-format.quick-styles":{order:0,[li.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:Yi},[ui.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Xi}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[Ri]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:104},menuItemFactory:Qi}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[zi]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:344},menuItemFactory:$i}},"sheets-shape-ui.ribbon.shape-format.arrange":{order:3,[Ci]:{order:0,gridLayout:{row:1,column:1},menuItemFactory:Di},[wi]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:Oi},[Vi]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:na},[Hi]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:ra},[Ui]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:ia},[Wi]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:aa}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[Bi]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,width:120},menuItemFactory:ea}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[si.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:oa},[S.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:c}}}}},ca={[Le.MEDIA]:{[$r.id]:{order:3,menuItemFactory:bi}}},la={...ca,[Le.OTHERS]:{[oi.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Si}},[Oe.DRAWING]:{[De.OTHERS]:{[Ci]:{order:4,menuItemFactory:Di},[wi]:{order:5,menuItemFactory:Oi}}}};var ua=`@univerjs-pro/sheets-shape-ui`,da=`1.5.2`;const fa={id:`sheet.operation.open-mobile-shape-editor`,type:k.OPERATION,handler(e,n){return n?(e.get(t).open(n.mode,{hostType:I.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},pa=`sheets-shape-ui.config`,ma={};let ha=class extends A{constructor(e,t,n,r,i){super(),this._context=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._imageShapeClipController=i,q(this,`_activeImageId`,null),q(this,`_unitId`,null),q(this,`_subUnitId`,null),q(this,`_activeAdjustPointList`,void 0),q(this,`_shapes`,[]),q(this,`_baseLeft`,0),q(this,`_baseTop`,0),q(this,`_baseWidth`,0),q(this,`_baseHeight`,0),q(this,`_isStartAdjusting`,!1),q(this,`_activeAdjustInfo`,void 0),q(this,`_activeShapeModel`,void 0),q(this,`_adjHandlerPointerMove`,void 0),q(this,`_adjHandlerPointerUp`,void 0),q(this,`_isImagePointerDown`,!1),this._registerFocusChangeHandler(),this._registerMoveHandler()}clearAdjustControls(){this._clearControls()}refreshAdjustControls(){this._clearControls(),this._createControls(!0)}_getOrCreateShapeModel(e,t,n,r){let i=e;if(i!==Xe.None&&e!==`custom`)try{let a=new Je(i,`clip-adj-${e}`);return r&&a.setShapeData({adjustValues:r},!0),a.updateContext({width:t,height:n}),a}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===j.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=U({unitId:e,subUnitId:t,drawingId:n}),o=i.getObject(a);if(o instanceof en){let e=o.prstGeom;if(e)return{prstGeom:e,adjustValues:o.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(V).getCurrentSkeleton())return;let{scene:n}=t,r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId);if(!r)return;let{transform:i}=r;if(!i)return;let{left:a,top:o,width:s,height:c,flipX:l,flipY:u,angle:d=0}=i;if(a===void 0||o===void 0)return;let f=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(!f)return;if(e){let e=this._getOrCreateShapeModel(f.prstGeom,s||0,c||0,f.adjustValues);if(!e)return;this._activeAdjustPointList=e.getDrawingPoints()}let p=this._activeAdjustPointList;if(p&&p.length!==0)for(let e=0;e<p.length;e++){let t=p[e],r=t.x,i=t.y;if(l&&(r=(s||0)-r),u&&(i=(c||0)-i),d!==0){let e=(s||0)/2,t=(c||0)/2,n=d*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 f={x:r,y:i,adjName:t.adjName};this._addControl(n,f,f.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,n,r,i,a,o){if(!this._activeImageId)return;let s=`image-clip-adjust-point-${this._activeImageId}-${n}`,c=e.getObjectIncludeInGroup(s);if(c){c.transformByState({left:t.x+r-T.adjHandleSize,top:t.y+i-T.adjHandleSize});return}let l=new Xr(s,{left:t.x+r-T.adjHandleSize,top:t.y+i-T.adjHandleSize,adjName:n,shapeId:this._activeImageId,unitId:a,subUnitId:o,width:T.adjHandleSize+8,height:T.adjHandleSize+8,zIndex:L+1,evented:!0});this._shapes.push(l),this._attachAdjustEvent(l,e,n),e.addObject(l,L+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(V).getSkeleton(t))return r;let a=i.with(zn),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=Wn(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(qt(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,s;let{unitId:c,subUnitId:l,drawingId:u}=e.getDrawingSearch(),d=this._getImageDrawingInfo(c,l,u);if(!(d!=null&&d.transform))return;let{left:f,top:p,width:m,height:h}=d.transform;this._baseLeft=f||0,this._baseTop=p||0,this._baseWidth=m||0,this._baseHeight=h||0;let g=!!((a=d.transform)!=null&&a.flipX),_=!!((o=d.transform)!=null&&o.flipY),v=((s=d.transform)==null?void 0:s.angle)||0,y=this._getImagePrstGeom(c,l,u);if(!y)return;let b=this._getOrCreateShapeModel(y.prstGeom,this._baseWidth,this._baseHeight,y.adjustValues);if(!b||(this._activeShapeModel=b,this._activeAdjustInfo=b.getAdjustInfoByName(n),!this._activeAdjustInfo))return;this._isStartAdjusting=!0,t.disableObjectsEvent();let x=y.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(Yt.CROSSHAIR);let o={left:0,top:0,width:this._baseWidth,height:this._baseHeight},s=this._getScrollInfo(c,l),d=this._getZoomRatio(c,l),f=r/d+s.x-this._baseLeft,p=i/d+s.y-this._baseTop;if(v!==0){let e=this._baseWidth/2,t=this._baseHeight/2,n=v*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=f-e,o=p-t;f=e+(a*r+o*i),p=t+(-a*i+o*r)}g&&(f=this._baseWidth-f),_&&(p=this._baseHeight-p);let m=this._activeShapeModel.calcAdjValues(o,{x:f,y:p},a,g,_);if(Object.keys(m).length!==0){for(let[e,t]of Object.entries(m))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseWidth,height:this._baseHeight}),this._updateImageAdjValues(c,l,u,m),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(c,l,u,x,t)}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_updateImageAdjValues(e,t,n,r){let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i,o=U({unitId:e,subUnitId:t,drawingId:n}),s=a.getObject(o);if(s instanceof en){let e=s.prstGeomAdjValues??{};s.setPrstGeomAdjValues({...e,...r}),s.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(I.UNIVER_SHEET);this.disposeWithMe(e.pipe(nr(e=>e?e.activeSheet$.pipe(nr(t=>{if(!t)return W;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?er(i):W})):W)).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 en&&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===j.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)===j.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()}};ha=X([Y(1,H),Y(2,P(R)),Y(3,N),Y(4,P(Q))],ha);function ga({PanelComponent:e=lr}){var t;function n(e){return e.trim()||void 0}function r(e,t,n){var r;return((r=e.name)==null?void 0:r.trim())||`${n.t(`drawing-ui.objectListPanel.typeNames.${ce(e.drawingType)}`)} ${t+1}`}let i=w(Rt),a={title:i.t(`drawing-ui.objectListPanel.title`),empty:i.t(`drawing-ui.objectListPanel.empty`),showAll:i.t(`drawing-ui.objectListPanel.showAll`),hideAll:i.t(`drawing-ui.objectListPanel.hideAll`),lockAll:i.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:i.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:i.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:i.t(`drawing-ui.objectListPanel.moveBackward`),close:i.t(`drawing-ui.objectListPanel.close`),show:i.t(`drawing-ui.objectListPanel.show`),hide:i.t(`drawing-ui.objectListPanel.hide`),lock:i.t(`drawing-ui.objectListPanel.lock`),unlock:i.t(`drawing-ui.objectListPanel.unlock`),lockHint:i.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:i.t(`drawing-ui.objectListPanel.unlockHint`),name:i.t(`drawing-ui.objectListPanel.name`),nameInput:i.t(`drawing-ui.objectListPanel.nameInput`),description:i.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:i.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:i.t(`drawing-ui.objectListPanel.details`),noSelection:i.t(`drawing-ui.objectListPanel.noSelection`),locate:i.t(`drawing-ui.objectListPanel.locate`),expand:i.t(`drawing-ui.objectListPanel.expand`),collapse:i.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:i.t(`drawing-ui.objectListPanel.dragToReorder`),search:i.t(`drawing-ui.objectListPanel.search`),filterAll:i.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:i.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:i.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:i.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:i.t(`drawing-ui.objectListPanel.sectionFloating`)},o=w(M),s=w(N),c=w(Sn),l=w(H),u=w(R),d=w(je),[,f]=Vr(e=>e+1,0),p=s.getCurrentUnitOfType(I.UNIVER_SHEET),m=(p==null?void 0:p.getUnitId())??``,h=(p==null||(t=p.getActiveSheet())==null?void 0:t.getSheetId())??``,g=Ve(()=>l.focus$,l.getFocusDrawings(),!1,[l]);zr(()=>{let e=o.onCommandExecuted(()=>f());return()=>e.dispose()},[o]);let _=m&&h?c.getDrawingData(m,h):{},v=(m&&h?c.getDrawingOrder(m,h):[]).map(e=>_[e]).filter(e=>!!e).reverse(),y=v.reduce((e,t)=>(e[fr(t.drawingType)]+=1,e),{canvas:0,floating:0}),b={canvas:0,floating:0},x=v.map((e,t)=>{let n=fr(e.drawingType),o=n===cr,s=b[n]++;return{id:e.drawingId,name:r(e,t,i),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:o?a.sectionFloating:a.sectionCanvas,capabilities:o?{arrange:!1,reorder:!1}:void 0,canMoveForward:!o&&s>0,canMoveBackward:!o&&s<y.canvas-1,canReorder:!o}}),S=Br(()=>(g??[]).filter(e=>e.unitId===m&&e.subUnitId===h).map(e=>e.drawingId),[g,h,m]),ee=S[S.length-1]??null,te=e=>c.getDrawingByParam({unitId:m,subUnitId:h,drawingId:e})??null,re=async e=>{m&&e.length&&await o.executeCommand(Tn.id,{unitId:m,drawings:e})},ie=async(e,t)=>{te(e)&&await re([{unitId:m,subUnitId:h,drawingId:e,...t}])},oe=(e,t)=>{if(!m||!h)return;let n=t?S.includes(e)?S.filter(t=>t!==e):[...S,e]:[e];o.syncExecuteCommand(Gn.id,n.map(e=>({unitId:m,subUnitId:h,drawingId:e})));let r=n[n.length-1];r?(ne(u,{unitId:m,subUnitId:h,drawingId:r}),d.focus(m)):ae(u,m)},se=async(e,t)=>{await re(e.map(e=>te(e)).filter(e=>!!e).filter(e=>e.hidden!==!0!==t).map(e=>({unitId:m,subUnitId:h,drawingId:e.drawingId,hidden:!t})))},le=async(e,t)=>{await re(e.map(e=>te(e)).filter(e=>!!e).filter(e=>e.selectable!==!1!==t).map(e=>({unitId:m,subUnitId:h,drawingId:e.drawingId,selectable:t})))},ue=e=>{let t=te(e);if(t)return le([e],t.selectable===!1)},de=async(e,t)=>{var r;let i=n(t);(((r=te(e))==null?void 0:r.name)??void 0)!==i&&await ie(e,{name:i})},fe=async(e,t)=>{var r;let i=n(t);(((r=te(e))==null?void 0:r.description)??void 0)!==i&&await ie(e,{description:i})},pe=async(e,t)=>{m&&h&&await o.executeCommand(wn.id,{unitId:m,subUnitId:h,drawingIds:[e],arrangeType:t})};return!m||!h?/* @__PURE__ */ G(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:a.title}):/* @__PURE__ */ G(e,{labels:a,items:x,selectedIds:S,focusedId:ee,showHeader:!1,onSelect:oe,onSetVisible:se,onSetSelectable:le,onCommitName:de,onCommitDescription:fe,onMoveForward:async e=>pe(e,St.forward),onMoveBackward:async e=>pe(e,St.backward),onToggleSelectable:ue})}function _a(){return/* @__PURE__ */ G(ga,{PanelComponent:sr})}let va=class extends A{constructor(e,t){super(),this.disposeWithMe(e.register(ti,_a)),this.disposeWithMe(t.register({BottomIcon:Ar,FlipHorizontalIcon:jr,FlipVerticalIcon:Mr,MoveDownIcon:Nr,MoveUpIcon:Pr,ObjectLayersIcon:Fr,ShapeFormatSettingIcon:Ir,TopmostIcon:Lr})),this.disposeWithMe(e.register(di,vi)),this.disposeWithMe(e.register(fi,hi)),e.hasDefault(or)||this.disposeWithMe(e.register(or,gi))}};va=X([Y(0,P(Ee)),Y(1,P(Fe))],va);let $=class extends A{constructor(e){super(),this._permissionService=e,q(this,`_editingParams$`,new Jn(null)),q(this,`editingParams$`,this._editingParams$.asObservable()),q(this,`_onSavingEditorData$`,new Jn(!1)),q(this,`onSavingEditorData$`,this._onSavingEditorData$.asObservable()),q(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 gn(e.unitId).id),n=this._permissionService.getPermissionPoint(new vn(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)}};$=X([Y(0,Pt)],$);let ya=class extends A{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,q(this,`_lastEditingShapeKey`,null),this._initEvents(),this._initSelection(),this._initEditingParams()}_initEvents(){let{scene:e}=this._context;this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:n,offsetY:r}=t,i=e.pick(sn.FromArray([n,r]));if(i instanceof J){let e=this._sheetsShapeService.getShapeModel(i.unitId,i.subUnitId,i.shapeId);if(E(this._sheetsShapeService.getShapeType(i.unitId,i.subUnitId,i.shapeId))||e!=null&&e.getShapeData().formulaBinding)return;this._shapeTextEditingService.setEditing({visible:!0,unitId:i.unitId,subUnitId:i.subUnitId,shapeId:i.shapeId,shapeKey:i.oKey})}}))}_initSelection(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let n=e[0],r=this._drawingManagerService.getDrawingByParam(n);if((r==null?void 0:r.drawingType)===j.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===n.drawingId&&e.visible)return;let r=E(this._sheetsShapeService.getShapeType(n.unitId,n.subUnitId,n.drawingId)),i=!!((t=this._sheetsShapeService.getShapeModel(n.unitId,n.subUnitId,n.drawingId))!=null&&t.getShapeData().formulaBinding);(r||i)&&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(kt,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(kt,!1)}))}};ya=X([Y(1,P(Lt)),Y(2,P($)),Y(3,H),Y(4,Mt),Y(5,P(D))],ya);var ba=class extends ya{_initEvents(){let{scene:e}=this._context,n=this._injector.get(t);this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:r,offsetY:i}=t,a=e.pick(sn.FromArray([r,i]));if(!(a instanceof J))return;let o=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);E(this._sheetsShapeService.getShapeType(a.unitId,a.subUnitId,a.shapeId))||o!=null&&o.getShapeData().formulaBinding||n.open(`text`,{hostType:I.UNIVER_SHEET,unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.shapeId})}))}};const xa={...ca};let Sa=class extends A{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,q(this,`_shapePopupMenuDisposable`,null),this._menuManagerService.mergeMenu(xa),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe(re(this._renderManagerService,I.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(j.DRAWING_SHAPE,(e,t,n,r)=>{let i=this._sheetsShapeService.getShapeTypeById(e,t,n),a=this._sheetsShapeService.getShapeDataById(e,t,n),o=i!==void 0&&!E(i)&&!(a!=null&&a.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:fa.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`style`},disable:!1},...o?[{label:`sheets-shape-ui.editText`,index:1,commandId:fa.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:Cn.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:n,drawingType:r}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:vt.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:vt.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new Et,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(Ot,!1),this._drawingManagerService.focusDrawing(null))};return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(t.size>1){r();return}let i=t.values().next().value;if(!i){r();return}let a=this._drawingManagerService.getDrawingOKey(i.oKey);if(!a||a.drawingType!==j.DRAWING_SHAPE){r();return}let{unitId:o,subUnitId:s,drawingId:c}=a;n={unitId:o,subUnitId:s,drawingId:c},this._contextService.setContextValue(Ot,!0),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===o&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:o,subUnitId:s,drawingId:c}])})),t.add(e.clearControl$.subscribe(()=>{r()})),qt(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)}};Sa=X([Y(0,Me),Y(1,P(D)),Y(2,M),Y(3,H),Y(4,P(In)),Y(5,Mt),Y(6,R),Y(7,P($))],Sa);function Ca(e,t,n,r){let i=qn(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 wa=class extends A{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===ln.id){let t=xn(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i).filter(e=>e.drawingType===j.DRAWING_SHAPE);if(a.length===0)return{redos:[],undos:[]};let o=[],s=[];for(let e=0;e<a.length;e++){let t=a[e],i=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);i&&(o.push({id:mt.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),s.push({id:pt.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:i.getShapeType(),shapeData:JSON.parse(JSON.stringify(i.getShapeData()))}}))}return{redos:o,undos:s}}if(e.id===cn.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:i}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,n),o=Object.values(a).filter(e=>e.drawingType===j.DRAWING_SHAPE);if(o.length===0)return{redos:[],undos:[]};let s=Ca(i,o,{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()))}}),c=[],l=[];for(let{targetShapeId:e,source:n}of s)c.push({id:pt.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),l.push({id:mt.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:c,undos:l}}return{redos:[],undos:[]}}}))}};wa=X([Y(0,P(N)),Y(1,P(un)),Y(2,P(Sn)),Y(3,P(D))],wa);let Ta=class extends A{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,q(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===O.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=U({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===pt.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=U({unitId:r,subUnitId:i,drawingId:a}),l=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(V).getSkeleton(i)))return!1;if(l)return;if(t!=null&&t.fromChangeset){queueMicrotask(()=>{this._disposed||this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])});return}this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])}}))}_shapeUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._drawingManagerService.getDrawingByParam(e);if(i==null)return;let{transform:a,drawingType:o,srcRect:s,prstGeom:c}=i;if(o!==j.DRAWING_SHAPE)return;let l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;let{scene:u,transformer:d}=l;if(a==null)return!0;let f=U({unitId:t,subUnitId:n,drawingId:r}),p=u.getObjectIncludeInGroup(f);if(p==null)return!0;p.setSrcRect(s),p.setPrstGeom(c)})}))}_insertShapes(e){for(let n of e){var t;let{unitId:e,subUnitId:r,drawingId:i}=n,a=this._getSceneAndTransformerByDrawingSearch(e),o=(t=dr(this._currentUniverService,e))==null?void 0:t.subUnitId;if(a==null||o!==r)continue;let s=U({unitId:e,subUnitId:r,drawingId:i});if(this._insertingShapeKeys.has(s)||a.scene.getObjectIncludeInGroup(s)!=null)continue;let c=this._drawingManagerService.getDrawingByParam(n);if(c==null||c.drawingType!==j.DRAWING_SHAPE)continue;let l=c.data||{};if(E(l.shapeType)){let e=c.transform;e&&(c.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(s);try{this._sheetDrawingShapeRenderController.renderDrawingShape(c,a.scene)}finally{this._insertingShapeKeys.delete(s)}queueMicrotask(()=>{if(this._disposed)return;let e=U(n);if(!a.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(n);t&&this._drawingManagerService.refreshTransform([t])})}}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}};Ta=X([Y(0,M),Y(1,R),Y(2,H),Y(3,N),Y(4,P(ar)),Y(5,P(Z))],Ta);const Ea={normal:{fill:T.cxnPointFill,stroke:T.cxnPointStroke,strokeWidth:T.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var Da=class extends rn{constructor(e,t){super(e,t),q(this,`_targetShapeId`,``),q(this,`_cxnIndex`,-1),q(this,`_unitId`,``),q(this,`_subUnitId`,``),q(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??T.cxnPointRadius*2,height:e.height??T.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?Ea.highlighted:Ea.normal;Xt.drawWith(e,{radius:T.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let Oa=class extends A{constructor(e,t,n,r){super(),this._context=e,this._renderManagerService=t,this._drawingManagerService=n,this._sheetsShapeService=r,q(this,`_connectionSiteObjects`,[]),q(this,`_activeTargetShapeId`,null),q(this,`_highlightedSiteIndex`,-1),q(this,`_currentScene`,null),q(this,`_unitId`,``),q(this,`_subUnitId`,``),q(this,`_draggingConnectorId`,null)}startConnectionDetection(e,t,n,r){this._currentScene=e,this._unitId=t,this._subUnitId=n,this._draggingConnectorId=r}updateConnectionDetection(e){if(!this._currentScene)return null;let t=this._findShapeAtPoint(e);return t?(this._activeTargetShapeId!==t.shapeId&&(this._clearConnectionSites(),this._showConnectionSites(t.shapeId,t.shapeModel),this._activeTargetShapeId=t.shapeId),this._findNearestConnectionSite(e)):(this._activeTargetShapeId!==null&&(this._clearConnectionSites(),this._activeTargetShapeId=null),null)}endConnectionDetection(){this._clearConnectionSites(),this._currentScene=null,this._activeTargetShapeId=null,this._highlightedSiteIndex=-1,this._draggingConnectorId=null}getConnectionRelation(){return this._activeTargetShapeId===null||this._highlightedSiteIndex<0?null:{shapeId:this._activeTargetShapeId,cxnIndex:this._highlightedSiteIndex}}_findShapeAtPoint(e){let t=this._drawingManagerService.getDrawingData(this._unitId,this._subUnitId);for(let n of Object.keys(t)){if(n===this._draggingConnectorId||t[n].drawingType!==j.DRAWING_SHAPE)continue;let r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,n);if(!r||E(r.getShapeType())||r.getConnectionSiteList().length===0||!this._currentScene)continue;let i=U({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:n}),a=this._currentScene.getObjectIncludeInGroup(i);if(!a)continue;let{left:o,top:s,width:c,height:l}=a.getRealBound(),u=o+c/2,d=s+l/2,f=a.transform.getMatrix(),p=new an([f[0],f[1],f[2],f[3],u,d]),m=a.getParent(),h=(a.isInGroup&&(m==null?void 0:m.classType)===tn.GROUP?m.ancestorTransform.multiply(p):p).invert().applyPoint(e),g=c/2,_=l/2;if(h.x>=-g-5&&h.x<=g+5&&h.y>=-_-5&&h.y<=_+5)return{shapeId:n,shapeModel:r}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let n=U({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),r=this._currentScene.getObjectIncludeInGroup(n);if(!r)return;let{left:i,top:a,width:o,height:s}=r.getRealBound(),c=i+o/2,l=a+s/2,u=r.transform.getMatrix(),d=new an([u[0],u[1],u[2],u[3],c,l]),f=r.getParent(),p=r.isInGroup&&(f==null?void 0:f.classType)===tn.GROUP?f.ancestorTransform.multiply(d):d;t.updateContext({width:o,height:s});let m=t.getConnectionSiteList();for(let t of m){let n=t.x-o/2,r=t.y-s/2,i=p.applyPoint({x:n,y:r}),a=i.x,c=i.y,l=new Da(`connection-site-${e}-${t.index}`,{left:a-T.cxnPointRadius,top:c-T.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:T.cxnPointRadius*2,height:T.cxnPointRadius*2,zIndex:L+2,evented:!1});this._connectionSiteObjects.push(l),this._currentScene.addObject(l,L+2)}}_findNearestConnectionSite(e){let t=null,n=1/0,r=null;for(let i of this._connectionSiteObjects){let a=i.left+T.cxnPointRadius,o=i.top+T.cxnPointRadius,s=e.x-a,c=e.y-o,l=Math.sqrt(s*s+c*c);l<n&&(n=l,t=i,r={x:a,y:o})}let i=n<=10&&t?t.getConnectionInfo().cxnIndex:-1;if(i!==this._highlightedSiteIndex){for(let e of this._connectionSiteObjects){let t=e.getConnectionInfo();e.setHighlighted(t.cxnIndex===i)}this._highlightedSiteIndex=i}if(n<=10&&t&&r){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:r,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()}};Oa=X([Y(1,P(R)),Y(2,P(H)),Y(3,P(D))],Oa);let ka=class extends A{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,q(this,`_copyInfo`,void 0),this._initCopyPaste(),this._registerGroupFeaturePasteHook()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_registerGroupFeaturePasteHook(){this._groupCopyPasteController.registerFeaturePasteHook(({fromUnitId:e,fromSubUnitId:t,toUnitId:n,toSubUnitId:r,idMap:i})=>{let a=[],o=[];for(let[l,u]of i.entries()){let d=this._shapeService.getShapeModel(e,t,l);if(!d)continue;let f=d.getShapeType(),p=JSON.parse(JSON.stringify(d.getShapeData()));if(p.relation){var s,c;let e=(s=p.relation.from)==null?void 0:s.shapeId,t=(c=p.relation.to)==null?void 0:c.shapeId,n=!e||i.has(e),r=!t||i.has(t);n&&e&&p.relation.from?p.relation.from={...p.relation.from,shapeId:i.get(e)}:p.relation.from=void 0,r&&t&&p.relation.to?p.relation.to={...p.relation.to,shapeId:i.get(t)}:p.relation.to=void 0}a.push({id:pt.id,params:{unitId:n,subUnitId:r,shapeId:u,shapeType:f,shapeData:p}}),o.push({id:mt.id,params:{unitId:n,subUnitId:r,shapeId:u}})}return{redos:a,undos:o}})}_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===j.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===Pn.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===Mn.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let a=yn(i,n);if(!a)return;let{startX:o,endX:s,startY:c,endY:l}=a,u=this._sheetDrawingService.getDrawingData(e,t),d=[];for(let[e,t]of Object.entries(u)){if(t.drawingType!==j.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:a=0}=e;o<=n&&s>=n+i&&c<=r&&l>=r+a&&d.push(t)}d.length>0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:r,copyRange:n,drawings:d})}_generatePasteMutations(e,t){var n,r;let{unitId:i,subUnitId:a,range:o}=e,s=this._copyInfo,c=(n=this._instances.getUnit(s.unitId,I.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(s.subUnitId),l=(r=this._instances.getUnit(i,I.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(a),u=(c==null?void 0:c.getConfig().type)??F.GRID,d=(l==null?void 0:l.getConfig().type)??F.GRID;if(u===F.CHART||d===F.CHART)return this._generateChartSheetCopy(e,t);let f=this._sheetSkeletonService.getSkeleton(i,a);if(!f)return{redos:[],undos:[]};let p=bn(o),{unitId:m,subUnitId:h,copyRange:g,drawings:_}=this._copyInfo,v=this._sheetSkeletonService.getSkeleton(m,h);if(!v)return{redos:[],undos:[]};let y;if(!g){let e=1/0,t=1/0;for(let n of _){let{left:r=0,top:i=0}=n.transform??{};r<e&&(e=r),i<t&&(t=i)}e!==1/0&&t!==1/0&&(y={left:e,top:t})}let b=/* @__PURE__ */ new Map;if(!t)for(let e of _)b.set(e.drawingId,Wt());let x=[],S=[];for(let e of _){let{drawingId:n,transform:r,sheetTransform:o}=e;if(!r||!o)continue;let s=this._updateTransform({transform:r,sheetTransform:o},{skeleton:v,range:g},{skeleton:f,range:p},y);if(t){let{redos:t,undos:n}=this._generateCutPasteMutations({fromUnitId:m,fromSubUnitId:h,toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:s});x.push(...t),S.push(...n);continue}let{redos:c,undos:l}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:s,newDrawingId:b.get(n),idMap:b});x.push(...c),S.push(...l)}return{redos:x,undos:S}}_generateChartSheetCopy(e,t){var n;if(t)throw new wt(Ln.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[gn],worksheetTypes:[vn]},r,i))throw new wt(Ln.id);let a=(n=this._instances.getUnit(r,I.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),o=a==null?void 0:a.getConfig(),s=(o==null?void 0:o.type)??F.GRID,c=this._copyInfo,l=c.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[hn],worksheetTypes:[_n]},c.unitId,c.subUnitId)||l.some(e=>e.groupId||!this._shapeService.getShapeModel(c.unitId,c.subUnitId,e.drawingId)||!Vt.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new wt(Ln.id);let u=null;if(s===F.CHART){var d;let e=(d=this._renders.getRenderUnitById(r))==null?void 0:d.components.get(Fn.CHART_PAGE);e&&(u=kn(l,{left:e.left,top:e.top,width:e.width,height:e.height},(o==null?void 0:o.rightToLeft)===Ct.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&yn(t,bn(e.range));if(n&&l.length){let e=Math.min(...l.map(e=>e.transform.left)),r=Math.min(...l.map(e=>e.transform.top));u=l.map(i=>On(i,{kind:En.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(!u)throw new wt(Ln.id);let f=new Map(l.map(e=>[e.drawingId,Wt()])),p=[],m=[];for(let[e,t]of l.entries()){let n=u[e],a=this._generateCopyPasteMutations({toUnitId:r,toSubUnitId:i,drawing:t,idMap:f,newDrawingId:f.get(t.drawingId),newTransforms:{transform:n.transform,sheetTransform:n.sheetTransform,axisAlignSheetTransform:n.axisAlignSheetTransform,anchorType:n.anchorType}});p.push(...a.redos),m.unshift(...a.undos)}return{redos:p,undos:m}}_generateCutPasteMutations(e){let{fromUnitId:t,fromSubUnitId:n,toUnitId:r,toSubUnitId:i,drawing:a,newTransforms:o}=e,s={...a,unitId:r,subUnitId:i,...o};if(r===t&&i===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([s]);return{redos:[{id:B.id,params:{unitId:r,subUnitId:i,type:z.UPDATE,op:e,objects:n}}],undos:[{id:B.id,params:{unitId:r,subUnitId:i,type:z.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([a]),o=this._sheetDrawingService.getBatchAddOp([s]),c=this._shapeService.getShapeModel(a.unitId,a.subUnitId,a.drawingId);if(!c)return{redos:[],undos:[]};let l=c.getShapeType(),u=JSON.parse(JSON.stringify(c.getShapeData()));return{redos:[{id:B.id,params:{unitId:t,subUnitId:n,type:z.REMOVE,op:e.redo,objects:e.objects}},{id:mt.id,params:{unitId:t,subUnitId:n,shapeId:a.drawingId}},{id:B.id,params:{unitId:r,subUnitId:i,type:z.INSERT,op:o.redo,objects:o.objects}},{id:pt.id,params:{unitId:r,subUnitId:i,shapeId:a.drawingId,shapeType:l,shapeData:u}}],undos:[{id:B.id,params:{unitId:t,subUnitId:n,type:z.INSERT,op:e.undo,objects:e.objects}},{id:pt.id,params:{unitId:t,subUnitId:n,shapeId:a.drawingId,shapeType:l,shapeData:u}},{id:B.id,params:{unitId:r,subUnitId:i,type:z.REMOVE,op:o.undo,objects:o.objects}},{id:mt.id,params:{unitId:r,subUnitId:i,shapeId:a.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:i,newDrawingId:a,idMap:o}=e,s={...r,unitId:t,subUnitId:n,drawingId:a,...i},{redo:c,undo:l,objects:u}=this._sheetDrawingService.getBatchAddOp([s]),d=this._shapeService.getShapeModel(r.unitId,r.subUnitId,r.drawingId);if(!d)return{redos:[],undos:[]};let f=d.getShapeType(),p=JSON.parse(JSON.stringify(d.getShapeData()));if(p.relation){var m,h;let e=(m=p.relation.from)==null?void 0:m.shapeId,t=(h=p.relation.to)==null?void 0:h.shapeId,n=!e||o.has(e),r=!t||o.has(t);n&&e&&p.relation.from?p.relation.from={...p.relation.from,shapeId:o.get(e)}:p.relation.from=void 0,r&&t&&p.relation.to?p.relation.to={...p.relation.to,shapeId:o.get(t)}:p.relation.to=void 0}return{redos:[{id:B.id,params:{unitId:t,subUnitId:n,type:z.INSERT,op:c,objects:u}},{id:pt.id,params:{unitId:t,subUnitId:n,shapeId:a,shapeType:f,shapeData:p}}],undos:[{id:B.id,params:{unitId:t,subUnitId:n,type:z.REMOVE,op:l,objects:u}},{id:mt.id,params:{unitId:t,subUnitId:n,shapeId:a}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:s}=n,{transform:c,sheetTransform:l}=e,u={...c};if(i){let e=yn(a,i),t=yn(s,o);if(e&&t){let n=t.startX-e.startX,r=t.startY-e.startY;u.left=(u.left??0)+n,u.top=(u.top??0)+r}}else{let e=yn(s,o);if(r&&e){let t=(u.left??0)-r.left,n=(u.top??0)-r.top;u.left=e.startX+t,u.top=e.startY+n}else u.left=e==null?void 0:e.startX,u.top=e==null?void 0:e.startY}return{transform:u,sheetTransform:jn(u,s)??l}}};ka=X([Y(0,P(fn)),Y(1,P(Nn)),Y(2,P(Sn)),Y(3,P(D)),Y(4,P(Dr)),Y(5,N),Y(6,R),Y(7,P(dn))],ka);var Aa=class extends rn{constructor(e,t){super(e,t),q(this,`_shapeId`,null),q(this,`_index`,null),q(this,`_unitId`,null),q(this,`_subUnitId`,null),q(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){Xt.drawWith(e,{radius:T.cxnPointRadius,fill:T.cxnPointFill,stroke:T.cxnPointStroke,strokeWidth:T.cxnPointStrokeWidth,evented:!0})}};let ja=class extends A{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,q(this,`_activeShapeId`,void 0),q(this,`_unitId`,void 0),q(this,`_subUnitId`,void 0),q(this,`_connectorObjects`,[]),q(this,`_baseDrawingRect`,{left:0,top:0,width:0,height:0,flipX:!1,flipY:!1}),q(this,`_activeShapeModel`,void 0),q(this,`_isConnecting`,!1),q(this,`_isDrawingShapePointDown`,!1),q(this,`_hasReset`,!1),q(this,`_cxtHandlerPointerMove`,void 0),q(this,`_cxtHandlerPointerUp`,void 0),q(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(V).getCurrentSkeleton())return;let{scene:t}=e,n=this._getDrawingRect();if(!n)return;let r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!r||!E(r.getShapeType()))return;let i=r.getConnectorLinePoints();if(i.length<2)return;let a=new He(n),o=i[0],s=i[i.length-1],c=a.localToWorld(o),l=a.localToWorld(s);this._addShapeConnectorHandlerObject(t,{...c},!0),this._addShapeConnectorHandlerObject(t,{...l},!1)}_addShapeConnectorHandlerObject(e,t,n){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let r=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${n?`start`:`end`}`,i=e.getObjectIncludeInGroup(r);if(i){i.transformByState({left:t.x-T.cxnPointRadius,top:t.y-T.cxnPointRadius});return}let a=new Aa(r,{left:t.x-T.cxnPointRadius,top:t.y-T.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:n,width:T.cxnPointRadius*2,height:T.cxnPointRadius*2,zIndex:L+1,evented:!0});this._connectorObjects.push(a),this._attachConnectorObjectEvent(a,e,n),e.addObject(a,L+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(V).getSkeleton(t))return r;let a=i.with(zn),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=Wn(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_handleConnectorPointerUp(e,t,n,r,i){this._cxtHandlerPointerMove.unsubscribe(),this._cxtHandlerPointerUp.unsubscribe(),this._sheetShapeAdjustController.refreshAdjustControls();let a=this._currentConnectionTarget;this._sheetBasicShapeConnectionPointController.endConnectionDetection();let o=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c={x:n.offsetX/s+o.x,y:n.offsetY/s+o.y},l=a?a.worldPoint:c,u=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo(),d=this._activeShapeModel.getShapeType();u?this._handleConnectedEndpointPointerUp(u,l,r,a,i):this._handleFreeEndpointPointerUp(t,l,r,a,i,d),this._isConnecting=!1,this._hasReset=!1,this._currentConnectionTarget=null,e.enableObjectsEvent()}_handleFreeEndpointPointerUp(e,t,n,r,i,a){let o=a===Xe.Line||a===Xe.StraightConnector1,s=n?t:e,c=n?e:t,l=this._activeShapeModel.getConnectorLinePoints(),u=this._activeShapeModel.getShapeType(),d=$e(u),f=He.getBentTypeFromPoints(l,d),p=o?He.computeStraightConnectorLayout(s,c):He.computeConnectorResizeLayout(e,t,n,f);r?this._executeConnectionCommand(p,r,n,i):this._executeResizeCommand(p,i)}_handleConnectedEndpointPointerUp(e,t,n,r,i){let a=this._getConnectPointInfo(e);if(!a)return;let o=r?r.angle:this._calculateFreeEndpointAngle(a.point,t),s;if(r){let e=this._drawingManagerService.getDrawingByParam({unitId:r.unitId,subUnitId:r.subUnitId,drawingId:r.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:r=0,height:i=0,angle:a}=e.transform;s=Qe({left:t,top:n,width:r,height:i},a||0)}else s={left:t.x,top:t.y,width:0,height:0}}else s={left:t.x,top:t.y,width:0,height:0};let c={point:t,angle:o,bounds:s},l=n?c:a,u=n?a:c,d=this._activeShapeModel.getShapeType(),f=et(l,u,d);this._activeShapeModel.removeLinePoints();let p=Ze(f,d);r?this._executeConnectedRouteConnectionCommand(p,r,e,n,i):this._executeConnectedRouteResizeCommand(p,e,n,i)}_executeConnectionCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,a={...i},o={shapeId:t.shapeId,cxnIndex:t.cxnIndex};n?a.from=o:a.to=o;let s=this._activeShapeModel.getShapeType(),c=Ze(e.worldPoints,s),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,newAdjustValues:c.adjustValues,oldAdjustValues:r,oldRelation:i,newRelation:a,newLineType:c.lineType,oldLineType:s};this._commandService.executeCommand(bt.id,l)}_executeResizeCommand(e,t){let n=this._activeShapeModel.getShapeType(),r=Ze(e.worldPoints,n),i={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:r.adjustValues,oldAdjustValues:t,newLineType:r.lineType,oldLineType:n};this._commandService.executeCommand(xt.id,i)}_executeConnectedRouteConnectionCommand(e,t,n,r,i){let a=this._activeShapeModel.getShapeData().relation,o={...a},s={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?(o.from=s,o.to=n):(o.from=n,o.to=s);let c={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:i,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:a,newRelation:o};this._commandService.executeCommand(bt.id,c)}_executeConnectedRouteResizeCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,a={};n?(a.to=t,a.from=void 0):(a.from=t,a.to=void 0);let o={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:r,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:i,newRelation:a};this._commandService.executeCommand(bt.id,o)}_attachConnectorObjectEvent(e,t,n){this.disposeWithMe(qt(e.onPointerDown$.subscribeEvent((r,i)=>{let a=e.getDrawingSearch();if(this._activeShapeModel=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.drawingId),!this._activeShapeModel)return;let o={};this._activeShapeModel.getAdjustNames().forEach(e=>{let t=this._activeShapeModel.getAdjustValueByName(e);t!==void 0&&(o[e]=t)});let s=this._getDrawingRect();if(!s)return;this._baseDrawingRect={...s};let c=new He(this._baseDrawingRect),l=U({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),u=t.getObjectIncludeInGroup(l);this._isConnecting=!0,t.disableObjectsEvent(),this._sheetBasicShapeConnectionPointController.startConnectionDetection(t,this._unitId,this._subUnitId,this._activeShapeId),this._currentConnectionTarget=null;let d=this._activeShapeModel.getConnectorLinePoints(),f=d[0],p=d[d.length-1],m=n?c.localToWorld(p):c.localToWorld(f);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((r,i)=>{if(!this._isConnecting||!this._activeShapeModel)return;this._hasReset||=(this._sheetShapeAdjustController.clearAdjustControls(),this._activeShapeModel.clearAdjustValue(),!0);let a=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s={x:r.offsetX/o+a.x,y:r.offsetY/o+a.y},c=this._sheetBasicShapeConnectionPointController.updateConnectionDetection(s);if(c){let{shapeId:e,unitId:n,subUnitId:r}=c;if(e&&n&&r){let i=U({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=n?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,n,u,e):this._handleFreeEndpointMove(s,m,n,u,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,r)=>{this._handleConnectorPointerUp(t,m,e,n,o)}),i.stopPropagation()})))}_handleBasicShapeUpdateConnectorLineShape(e,t,n){let r=this._sheetsShapeService.getBasicShapeRelation(e,t,n);if(!r||r.length===0)return;let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i;for(let i of r){let r=i.lineShapeId,o=this._sheetsShapeService.getShapeModel(e,t,r);if(!o)continue;let s=o.getStartConnectInfo(),c=o.getEndConnectInfo(),l=(s==null?void 0:s.shapeId)===n,u=U({unitId:e,subUnitId:t,drawingId:r}),d=a.getObjectIncludeInGroup(u);if(!d)continue;let f=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});f!=null&&f.transform&&(s&&c?this._rerouteConnectorLine(e,t,r,o,s,c,d):this._moveConnectorWithShape(e,t,r,o,l?s:c,l,f,d))}}_rerouteConnectorLine(e,t,n,r,i,a,o){let s=this._unitId,c=this._subUnitId;this._unitId=e,this._subUnitId=t;let l=this._getConnectPointInfo(i),u=this._getConnectPointInfo(a);if(this._unitId=s,this._subUnitId=c,!l||!u)return;let d=r.getShapeType(),f=et(l,u,d);f&&r.updateLinePoints(f);let p=Ze(f,d);p.lineType!==d&&r.changeShapeType(p.lineType),r.clearAdjustValue();for(let[e,t]of Object.entries(p.adjustValues))r.setAdjustValueByName(e,t);r.updateContext({width:p.worldRect.width,height:p.worldRect.height}),o.transformByState({flipX:p.worldRect.flipX,flipY:p.worldRect.flipY,left:p.worldRect.left,top:p.worldRect.top,width:p.worldRect.width,height:p.worldRect.height,angle:p.rotation}),r.removeLinePoints()}_moveConnectorWithShape(e,t,n,r,i,a,o,s){let c=this._unitId,l=this._subUnitId;this._unitId=e,this._subUnitId=t;let u=this._getConnectPointInfo(i);if(this._unitId=c,this._subUnitId=l,!u)return;let{left:d=0,top:f=0,width:p=0,height:m=0,flipX:h=!1,flipY:g=!1}=o.transform,_=r.getConnectorLinePoints();if(_.length<2)return;let v=new He({left:d,top:f,width:p,height:m,flipX:h,flipY:g}),y=a?_[_.length-1]:_[0],b=v.localToWorld(y),x=He.computeConnectorResizeLayout(b,u.point,!a);s.transformByState({flipX:x.worldRect.flipX,flipY:x.worldRect.flipY,left:x.worldRect.left,top:x.worldRect.top,width:x.worldRect.width,height:x.worldRect.height,angle:x.worldRect.angle}),s.makeDirty(!0)}_clearShapeConnectorHandlerObjects(){this._connectorObjects.length!==0&&(this._connectorObjects.forEach(e=>{e.dispose()}),this._connectorObjects=[])}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(I.UNIVER_SHEET);this.disposeWithMe(e.pipe(nr(e=>e?e.activeSheet$.pipe(nr(t=>{if(!t)return W;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?er(i):W})):W)).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 J&&(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===j.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&E(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===j.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===j.DRAWING_SHAPE&&this._handleBasicShapeUpdateConnectorLineShape(n.unitId,n.subUnitId,n.drawingId)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e){let{drawingId:e}=t;if(this._activeShapeId===e){this._reset();return}}}))}_handleConnectedEndpointMove(e,t,n,r,i){var a;if(!this._activeShapeModel)return;let o=this._getConnectPointInfo(e);if(!o)return;let s=this._currentConnectionTarget?this._currentConnectionTarget.worldPoint:t,c=this._currentConnectionTarget?this._currentConnectionTarget.angle:this._calculateFreeEndpointAngle(o.point,s),l;if(this._currentConnectionTarget){let e=this._drawingManagerService.getDrawingByParam({unitId:this._currentConnectionTarget.unitId,subUnitId:this._currentConnectionTarget.subUnitId,drawingId:this._currentConnectionTarget.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:r=0,height:i=0,angle:a}=e.transform;l=Qe({left:t,top:n,width:r,height:i},a||0)}else l={left:s.x,top:s.y,width:0,height:0}}else l={left:s.x,top:s.y,width:0,height:0};let u={point:s,angle:c,bounds:l},d=n?u:o,f=n?o:u,p=this._activeShapeModel.getShapeType(),m=et(d,f,p);m&&this._activeShapeModel.updateLinePoints(m);let h=Ze(m,p);h.lineType!==p&&this._activeShapeModel.changeShapeType(h.lineType);for(let[e,t]of Object.entries(h.adjustValues))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:h.worldRect.width,height:h.worldRect.height}),r.transformByState({flipX:h.worldRect.flipX,flipY:h.worldRect.flipY,left:h.worldRect.left,top:h.worldRect.top,width:h.worldRect.width,height:h.worldRect.height,angle:h.rotation}),r.makeDirty(!0);let g=((a=this._currentConnectionTarget)==null?void 0:a.worldPoint)??t;i.transformByState({left:g.x-T.cxnPointRadius,top:g.y-T.cxnPointRadius})}_handleFreeEndpointMove(e,t,n,r,i){var a,o;let s=((a=this._currentConnectionTarget)==null?void 0:a.worldPoint)??e,c=He.computeConnectorResizeLayout(t,s,n);r.transformByState({flipX:c.worldRect.flipX,flipY:c.worldRect.flipY,left:c.worldRect.left,top:c.worldRect.top,width:c.worldRect.width,height:c.worldRect.height,angle:c.worldRect.angle});let l=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e;i.transformByState({left:l.x-T.cxnPointRadius,top:l.y-T.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:n}=e,r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,t);if(!r)return null;let i=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:t});if(!(i!=null&&i.transform))return null;let{left:a=0,top:o=0,width:s=0,height:c=0,flipX:l=!1,flipY:u=!1,angle:d}=i.transform;r.updateContext({width:s,height:c});let f=r.getConnectionSiteList().find(e=>e.index===n);if(!f)return null;let p=l?s-f.x:f.x,m=u?c-f.y:f.y;if(d!==0&&d!=null){let e=d*Math.PI/180,t=Math.cos(e),n=Math.sin(e),r=s/2,i=c/2,a=p-r,o=m-i;p=r+a*t-o*n,m=i+a*n+o*t}p+=a,m+=o;let h=f.ang/6e4;l&&(h=180-h),u&&(h=-h),h+=d||0,h=(h%360+360)%360;let g=Qe({left:a,top:o,width:s,height:c},d||0);return{point:{x:p,y:m},angle:h,bounds:g}}_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()}};ja=X([Y(1,M),Y(2,R),Y(3,H),Y(4,N),Y(5,P(D)),Y(6,P(Zr)),Y(7,P(Oa))],ja);let Ma=class extends A{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._drawingManagerService=t,this._shapeRenderController=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{var r;let{unitId:i,subUnitId:a,scene:o,resourceCollector:s}=t,c=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[a];return c==null||c.order.forEach(e=>{let t=c.data[e];t.drawingType===j.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,o,{resourceCollector:s})}),n(e)}}))}};Ma=X([Y(0,P(Rn)),Y(1,H),Y(2,P(Z))],Ma);let Na=class extends A{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([K.id,vt.id,gt.id,_t.id,xt.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===ft.id||t.id===ht.id||t.id===bt.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=xn(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==F.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[gn],worksheetTypes:[vn]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};Na=X([Y(0,P(M)),Y(1,P(N)),Y(2,P(Rt)),Y(3,P(dn))],Na);let Pa=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=U(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};Pa=X([Y(0,R)],Pa);let Fa=class extends zt{constructor(e=ma,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=Gt({},ma,this._config);this._configService.setConfig(pa,a),this._initCommands()}onStarting(){this._injector.add([va]),this._injector.get(va),Kt(this._injector,[[Sa],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na]])}onReady(){Kt(this._injector,[[Oa],[Zr],[ka]]),Jt(this._injector,[[ka],[Zr]]),[[Oa],[ha],[ja],[ba]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,e))})}onRendered(){Jt(this._injector,[[Sa],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na]])}onSteady(){this._injector.get(Sa).initShapePopupMenu()}_initCommands(){[$r,K,Qr,fa].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};q(Fa,`type`,I.UNIVER_SHEET),q(Fa,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),q(Fa,`packageName`,ua),q(Fa,`version`,da),Fa=X([Tt(_r,br,Kn,on,mn,Tr,Dn,nt,Or,yt,Bn,ee,ze),Y(1,P(Lt)),Y(2,M),Y(3,jt),Y(4,R)],Fa);const Ia={type:k.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function La(){let e=w(H),t=Ve(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return t.length===0?null:/* @__PURE__ */ G(`div`,{children:/* @__PURE__ */ gr(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ G(rr,{drawings:t,hasCropper:!1}),/* @__PURE__ */ G(Er,{drawings:t})]})})}function Ra(e){let{unitId:t,subUnitId:n,shapeId:r}=e,i=w(M),o=w(Pa);return/* @__PURE__ */ G(a,{...e,positionEditor:/* @__PURE__ */ G(La,{}),onUpdateShapeData:(e,a)=>{Wr(i,t,n,r,e,a)},onUpdateLineShapeData:(e,a)=>{Gr(i,t,n,r,e,a)},onUpdateShapeFillImage:e=>{o.updateShapeFillImage({unitId:t,subUnitId:n,drawingId:r},e)}})}function za(e){let t=w(s),n=Ve(()=>t.visible$,t.getVisible(),!1,[t]),r=e.popup.extraProps;return!r||!n?null:/* @__PURE__ */ G(Ba,{...r,canvasElement:e.popup.canvasElement})}function Ba(e){let t=w(M),n=w(D),{unitId:r,subUnitId:i,drawingId:a,drawingType:s,shapeType:c}=e,[l,u]=Hr(e.shapeData),d=Br(()=>ue(l),[l]),f=Br(()=>le(l),[l]);zr(()=>{let e=t.onCommandExecuted(e=>{if(e.id!==O.id)return;let t=n.getShapeDataById(r,i,a);t&&u(t)});return()=>e.dispose()},[t,a,n,i,r]);let p=e=>{u(t=>({...t,...e}))},m=e=>{let n=ie(l,e);Wr(t,r,i,a,{oldShapeData:{shapeText:l.shapeText}},n),p(n)},h=Te({hostType:I.UNIVER_SHEET,unitId:r,subUnitId:i,shapeId:a,shapeData:l,onUpdateBinding:e=>{let n={formulaBinding:e};Wr(t,r,i,a,{oldShapeData:{formulaBinding:l.formulaBinding}},n),p(n)}});return/* @__PURE__ */ gr(hr,{children:[/* @__PURE__ */ G(o,{canvasElement:e.canvasElement,shapeData:l,shapeType:c,textStyle:{ff:T.shapeText.fontFamily,fs:T.shapeText.fontSize,cl:{rgb:T.shapeText.color},...d},textModel:f?{ha:f.ha??At.LEFT,va:f.va??Ht.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:T.fill,defaultGradientEndColor:T.gradientEndColor,defaultStrokeColor:T.stroke,extensionGroups:h.extensionGroups,floatingObjectToolbarPosition:ke.SHEET,onUpdateShapeData:(e,n)=>{Wr(t,r,i,a,e,n),n&&p(n)},onUpdateText:m,onOpenPanel:()=>{t.executeCommand(si.id,{unitId:r,subUnitId:i,drawingId:a})},onDelete:()=>{t.executeCommand(Cn.id,{unitId:r,drawings:[{unitId:r,subUnitId:i,drawingId:a,drawingType:s}]})}}),h.panel]})}function Va(e){return!!e&&`axisAlignSheetTransform`in e&&`sheetTransform`in e}const Ha=Rr(()=>{let e=w($),t=w(D),n=w(H),r=w(M),i=w(Re),a=w(R),o=Br(()=>({getShapeModel:(e,n,r)=>t.getShapeModel(e,n,r),getShapeData:(e,n,r)=>t.getShapeDataById(e,n,r),getDrawingTransform:(e,t,r)=>{let i=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});return i==null?void 0:i.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:o,shapeText:s,oldShapeText:c,hostSize:l})=>{i.run(e,()=>{var i;let u=r.syncExecuteCommand(K.id,{unitId:e,subUnitId:t,shapeId:o,shapeData:{shapeText:s},oldShapeJSON:{oldShapeData:{shapeText:c}}});if(!u||!l)return u;let d=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:o}),f=d==null?void 0:d.transform;if(!Va(d)||!f)return!1;let p={...f,width:l.width,height:l.height},m=(i=a.getRenderUnitById(e))==null||(i=i.with(V).getSkeletonParam(t))==null?void 0:i.skeleton;return r.syncExecuteCommand(Tn.id,{unitId:e,drawings:[{...d,transform:p,sheetTransform:m?jn(p,m)??d.sheetTransform:d.sheetTransform,axisAlignSheetTransform:m?An(p,m)??d.axisAlignSheetTransform:d.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:i,width:o,height:s})=>{var c;let l=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:i}),u=l==null?void 0:l.transform;if(!Va(l)||!u)return;let d={...u,width:o,height:s},f=(c=a.getRenderUnitById(e))==null||(c=c.with(V).getSkeletonParam(t))==null?void 0:c.skeleton,p=f?jn(d,f)??l.sheetTransform:l.sheetTransform,m=f?An(d,f)??l.axisAlignSheetTransform:l.axisAlignSheetTransform;r.executeCommand(Tn.id,{unitId:e,drawings:[{...l,transform:d,sheetTransform:p,axisAlignSheetTransform:m}]})},allowHostSizeShrink:({unitId:e,subUnitId:n,shapeId:r})=>Ce(t.getShapeDataById(e,n,r)),deferHostSizeUpdateDuringEditing:()=>!0}),[r,n,a,t,i]),s=Br(()=>({viewportKeys:{main:nn.VIEW_MAIN,leftTop:nn.VIEW_MAIN_LEFT_TOP,top:nn.VIEW_MAIN_TOP,left:nn.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(V).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ G(h,{adapter:o,editingService:e,editorUnitId:ii,positionOptions:s})});let Ua=class extends A{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:Fr})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:jr})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:Mr})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:Ar})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:Nr})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:Pr})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:Ir})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:Lr}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(ei,Ra)),this.disposeWithMe(this._componentManager.register(ti,ga)),this.disposeWithMe(this._componentManager.register(di,_i)),this.disposeWithMe(this._componentManager.register(fi,mi)),this._componentManager.hasDefault(or)||this.disposeWithMe(this._componentManager.register(or,gi)),this.disposeWithMe(this._componentManager.register(ni,za)),this.disposeWithMe(this._componentManager.register(Ai,Pi)),this.disposeWithMe(this._componentManager.register(ki,Fi)),this.disposeWithMe(this._componentManager.register(ji,Ii)),this.disposeWithMe(this._componentManager.register(Mi,Li)),this.disposeWithMe(this._componentManager.register(ai,_)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,Ha))}};Ua=X([Y(0,P(Ee)),Y(1,P(Fe))],Ua);let Wa=class extends A{constructor(e,t,n,r,i,a,o,s,c){super();let l=e=>{var t,n;return(((t=s.getPermissionPoint(new gn(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=s.getPermissionPoint(new vn(e.unitId,e.subUnitId).id))==null?void 0:n.value)??!0)},u=e=>e.shapeId&&l(e)?n.getShapeDataById(e.unitId,e.subUnitId,e.shapeId)??null:null,d=()=>{let t=i.getFocusDrawings(),n=t.length===1?t[0]:null;return(n==null?void 0:n.drawingType)===j.DRAWING_SHAPE&&n.unitId===e.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe(me(e,t,{changes$:$n(i.focus$,r.editingParams$,s.permissionPointUpdate$),isActive:()=>{var t;return((t=a.getFocusedUnit())==null?void 0:t.getUnitId())===e.unitId&&!o.getContextValue(kt)&&i.getFocusDrawings().some(t=>t.unitId===e.unitId)},getSelectedTarget:d,getSource:()=>{let e=d();return e?u(e):null},getTarget:t=>{let n=e.scene.pick(new sn(t.offsetX,t.offsetY));if(!(n instanceof J))return null;let r={unitId:e.unitId,subUnitId:n.subUnitId,shapeId:n.shapeId};return l(r)?r:null},getShape:u,update:(e,t,n)=>c.executeCommand(K.id,{...e,shapeData:n,replaceShapeData:!0,oldShapeJSON:{oldShapeData:t}})}))}};Wa=X([Y(1,P(Ae)),Y(2,P(D)),Y(3,P($)),Y(4,H),Y(5,N),Y(6,Mt),Y(7,Pt),Y(8,M)],Wa);const Ga=`sheets-shape-contextual-ribbon`;let Ka=class extends A{constructor(e,t,n,r,i,a){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=a,q(this,`_visible`,!1),this._menuManagerService.mergeMenu(sa),this.disposeWithMe(qt(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,Ga),this._hide(),super.dispose()}_update(){var e;let t=this._drawingManagerService.getFocusDrawings(),n=t.length===1?t[0]:void 0;if((n==null?void 0:n.drawingType)!==j.DRAWING_SHAPE||this._univerInstanceService.getUnitType(n.unitId)!==I.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,Ga),this._hide();return}let r=(e=this._renderManagerService.getRenderUnitById(n.unitId))==null?void 0:e.engine.getCanvasElement(),i=ge(r)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(i,Ga),i?this._hide():this._visible||(this._visible=!0,this._ribbonService.showContextualTab(ri,{activate:!0}))}_hide(){this._visible&&(this._visible=!1,this._ribbonService.hideContextualTab(ri),this._ribbonService.setCollapsedIds([]))}};Ka=X([Y(0,Me),Y(1,Ne),Y(2,H),Y(3,N),Y(4,R),Y(5,P(s))],Ka);let qa=class extends g{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l,{componentKey:ai,editorUnitId:ii})}};qa=X([Y(1,P(yr)),Y(2,P(xr)),Y(3,P(wr)),Y(4,M),Y(5,P(Sr)),Y(6,P(b)),Y(7,P(vr)),Y(8,P(Cr)),Y(9,P($))],qa);let Ja=class extends v{constructor(e,t,n,r,i){super(e,t,{editing$:n.editingParams$,resolve:n=>{var a,o,s;let c=new sn(n.offsetX,n.offsetY),l=((a=e.scene.getActiveViewportByCoord(c))==null?void 0:a.transformVector2SceneCoord(c))??c,u=Se(e.scene.pick(c)??null,l);if(!(u instanceof J))return null;let d=u.resolveHyperLinkAt(l);if(!d)return null;let f=u,p={componentKey:y.componentKey,direction:`top-center`,offset:[0,10],onClickOutside:()=>t.hideInfoPopup()};return{object:u,info:{...d,unitId:u.unitId,subUnitId:u.subUnitId,shapeKey:u.oKey,readonly:!0,copyable:((o=i.getPermissionPoint(new hn(u.unitId).id))==null?void 0:o.value)!==!1&&((s=i.getPermissionPoint(new _n(u.unitId,u.subUnitId).id))==null?void 0:s.value)!==!1},attachPopup:()=>r.attachPopupToObject(f,p)}}}),this.disposeWithMe(e.unit.activeSheet$.subscribe(()=>this.clear()))}};Ja=X([Y(1,P(b)),Y(2,P($)),Y(3,P(In)),Y(4,Pt)],Ja);let Ya=class extends A{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=a,this._drawingManagerService=o,this._sheetCanvasPopManagerService=s,this._contextService=c,this._renderManagerService=l,this._shapeTextEditingService=u,q(this,`_sidebarDisposable`,null),q(this,`_activeShapeInfo`,null),q(this,`_isOpenedShapeEditPanel`,!1),q(this,`_shapeEditPanelVersion`,0),q(this,`_shapePopupMenuDisposable`,null),q(this,`_disposePopups`,[]),this._initMenu(),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(I.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(la)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe(re(this._renderManagerService,I.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_getShapeInfo(e,t,n){let r=this._sheetsShapeService.getShapeTypeById(e,t,n),i=this._sheetsShapeService.getShapeDataById(e,t,n);return r!==void 0&&i!==void 0?{shapeData:i,shapeId:n,shapeType:r,unitId:e,subUnitId:t,version:this._shapeEditPanelVersion,disableShapeOption:!1}:null}_clearPopups(){this._disposePopups.forEach(e=>e.dispose()),this._disposePopups.length=0}_popupMenuListener(e){let t=new Et;return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(this._clearPopups(),this._isOpenedShapeEditPanel||t.size>1)return;let n=t.values().next().value;if(!n)return;let r=this._drawingManagerService.getDrawingOKey(n.oKey);if(!r||r.drawingType!==j.DRAWING_SHAPE)return;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c}=r,l=this._getShapeInfo(a,o,s);if(!l)return;this._contextService.setContextValue(Ot,!0);let u=this._renderManagerService.getRenderUnitById(a),d=((u==null?void 0:u.isMainScene)===!1?u.with(In):this._sheetCanvasPopManagerService).attachPopupToObject(n,{componentKey:ni,direction:`vertical-center`,offset:[0,i],extraProps:{unitId:a,subUnitId:o,drawingId:s,drawingType:c,shapeType:l.shapeType,shapeData:l.shapeData}});this._disposePopups.push(this.disposeWithMe(d)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===a&&e.subUnitId===o&&e.drawingId===s)||this._drawingManagerService.focusDrawing([{unitId:a,subUnitId:o,drawingId:s}])})),t.add(e.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)})),t.add(e.changing$.subscribe(()=>{this._clearPopups()})),t.add(e.changeStart$.subscribe(()=>{this._clearPopups()})),qt(()=>{t.dispose(),this._clearPopups()})}_registerOperations(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===si.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===Ia.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===O.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===j.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===j.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:ei,header:{title:this._localeService.t(`sheets-shape-ui.formatShape`)},width:388,children:{label:ei,...this._activeShapeInfo},onClose:()=>{this._drawingManagerService.focusDrawing(null),this._contextService.setContextValue(Ot,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(ei),this._sidebarDisposable=null,this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)}};Ya=X([Y(0,N),Y(1,P(Pe)),Y(2,Me),Y(3,P(D)),Y(4,P(Rt)),Y(5,M),Y(6,H),Y(7,P(In)),Y(8,Mt),Y(9,R),Y(10,P($))],Ya);let Xa=class extends zt{constructor(e=ma,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=Gt({},ma,this._config);this._configService.setConfig(pa,a),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(I.UNIVER_DOC,[qa]),Jt(this._injector,[[Ya],[Ta],[Z],[Ma]])}onSteady(){this._injector.get(Ya).initShapePopupMenu()}onReady(){[[Oa],[Zr],[ka]].forEach(e=>this._injector.add(e)),Jt(this._injector,[[ka],[Zr]]),this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[Oa]),this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[ha]),this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[ja]),this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[ya]),this.disposeWithMe(this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[Ja])),this.disposeWithMe(this._renderManagerService.registerRenderModule(I.UNIVER_SHEET,[Wa]))}onStarting(){this._injector.add([Ua]),this._injector.get(Ua);let e=this._injector;[[Ya],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na],[Ka]].forEach(t=>e.add(t)),Jt(this._injector,[[Ya],[Ta],[Z],[Pa],[$],[wa],[Q],[Na],[Ka]])}_initCommands(){[$r,K,Ia,si,oi,Qr,li,ui].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};q(Xa,`type`,I.UNIVER_SHEET),q(Xa,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),q(Xa,`packageName`,ua),q(Xa,`version`,da),Xa=X([Tt(_r,br,Kn,ur,on,mn,Tr,Dn,nt,kr,yt,Vn,te),Y(1,P(Lt)),Y(2,M),Y(3,jt),Y(4,R)],Xa);export{sa as SheetsShapeUIContextualRibbonSchema,la as SheetsShapeUIMenuSchema,Fa as UniverSheetsShapeMobileUIPlugin,Xa as UniverSheetsShapeUIPlugin};
|
|
1
|
+
import{FormulaShapeAnimationController as e,MobileShapeEditorService as t,SHAPE_CHANGE_PICKER_COMPONENT as n,SHAPE_EDITOR_TRANSFORMER_CONFIG as r,SHEET_DOC_SHAPE_FLOATING_TOOLBAR_TOP_OFFSET as i,ShapeEditPanel as a,ShapeFloatingToolbar as o,ShapeFloatingToolbarService as s,ShapeFloatingToolbarToggleFactory as c,ShapeFormulaRibbonControl as l,ShapeGroupEnum as u,ShapePickerDropdown as d,ShapePickerPanel as f,ShapeQuickStyleGallery as p,ShapeStyleRibbonControl as m,ShapeTextEditorContainer as h,ShapeTextFloatMenuRenderControllerBase as g,ShapeTextFloatToolbar as _,ShapeTextHyperLinkHoverController as v,ShapeTextHyperLinkInfo as y,ShapeTextHyperLinkPopupService as b,ShapeTextRibbonControl as x,ToggleShapeFloatingToolbarOperation as S,UniverShapeEditorMobileUIPlugin as ee,UniverShapeEditorUIPlugin as te,activateDrawingObject as ne,bindRenderTransformerLifecycle as re,buildShapeTextDataUpdate as ie,clearActiveDrawingObjects as ae,createShapeTextHyperLinkRegions as oe,drawFormulaShapeAnimationLayers as se,getDrawingTypeNameKey as ce,getTextModel as le,getTextStyle as ue,isShapeTextEditingTarget as de,normalizeShapeTextModel as fe,plainShapeTextToDocumentData as pe,prepareShapeTextDocumentData as me,registerShapeFormatPainter as he,resolveFormulaShapeAutoFitSize as ge,resolveShapeContextualRibbonHostMode as _e,resolveShapeTextDocumentPageHeight as ve,resolveShapeTextDocumentRenderLayout as ye,resolveShapeTextEditorBehaviorShapeData as be,resolveShapeTextEditorWrapStrategy as xe,resolveShapeTextHyperLinkAt as Se,resolveShapeTextHyperLinkObject as Ce,shouldAllowShapeTextEditorHostSizeShrink as we,shouldClipShapeTextDocument as Te,useFormulaShapeToolbar as Ee}from"@univerjs-pro/shape-editor-ui";import{ComponentManager as De,ContextMenuGroup as Oe,ContextMenuPosition as ke,FloatingObjectToolbarPosition as Ae,FormatPainterSessionService as je,ILayoutService as Me,IMenuManagerService as Ne,IRibbonService as Pe,ISidebarService as Fe,IconManager as Ie,MenuItemType as C,MenuManagerPosition as Le,RibbonInsertGroup as Re,UndoRedoGroupService as ze,UniverMobileUIPlugin as Be,getMenuHiddenObservable as Ve,useDependency as w,useObservable as He}from"@univerjs/ui";import{ConnectorCoordinateTransform as T,ImageSourceTypeEnum as Ue,ShapeArrowSizeEnum as We,ShapeArrowTypeEnum as Ge,ShapeDefaultConfig as E,ShapeFillEnum as Ke,ShapeLineTypeEnum as qe,ShapeModel as Je,ShapeRenderModeEnum as Ye,ShapeTypeEnum as Xe,computeConnectorRouteLayout as Ze,getBasicShapeRotateBound as Qe,isConnectorShape as D,isCurvedConnectorShape as $e,routeConnectorLineShape as et}from"@univerjs-pro/engine-shape";import{ShapeFormulaService as tt,UniverShapeEditorPlugin as nt,applyQuickStyleToShapeData as rt,cloneShapeDataForType as it,createShapeFormulaDocument as at,createShapeTextBoxShapeData as ot,getShapeQuickStylePreset as st,getShapeQuickStyleType as ct,resolveActiveShapeQuickStylePresetId as lt}from"@univerjs-pro/shape-editor";import{DEFAULT_SHAPE_HEIGHT as ut,DEFAULT_SHAPE_WIDTH as dt,InsertShapeCommand as ft,InsertSheetsShapeMutation as pt,RemoveSheetsShapeMutation as mt,SetShapeDrawingDataCommand as ht,SetSheetsShapeRotateCommand as gt,SetSheetsShapeTextVerticalToggleCommand as _t,SheetsShapeService as O,ToggleSheetsShapeFlipCommand as vt,UniverSheetsShapePlugin as yt,UpdateConnectorRelationCommand as bt,UpdateLineShapeResizeCommand as xt,UpdateSheetsShapeDataMutation as k}from"@univerjs-pro/sheets-shape";import{ArrangeTypeEnum as St,BooleanNumber as Ct,CommandType as A,CustomCommandExecutionError as wt,DependentOn as Tt,Disposable as j,DisposableCollection as Et,DocumentDataModel as Dt,DrawingTypeEnum as M,FOCUSING_COMMON_DRAWINGS as Ot,FOCUSING_SHAPE_TEXT_EDITOR as kt,HorizontalAlign as At,ICommandService as N,IConfigService as jt,IContextService as Mt,IImageIoService as Nt,IPermissionService as Pt,IURLImageService as Ft,IUndoRedoService as It,IUniverInstanceService as P,Inject as F,Injector as Lt,LocaleService as Rt,Plugin as zt,SheetTypes as I,ThemeService as Bt,Tools as Vt,UniverInstanceType as L,VerticalAlign as Ht,createInternalEditorID as Ut,generateRandomId as Wt,merge as Gt,registerDependencies as Kt,toDisposable as qt,touchDependencies as Jt}from"@univerjs/core";import{CURSOR_TYPE as Yt,Circle as Xt,DRAWING_OBJECT_LAYER_INDEX as R,DocumentSkeleton as Zt,DocumentViewModel as Qt,Documents as $t,IRenderManagerService as z,Image as en,RENDER_CLASS_TYPE as tn,SHEET_VIEWPORT_KEY as nn,Shape as rn,Transform as an,UniverRenderEnginePlugin as on,Vector2 as sn}from"@univerjs/engine-render";import{CopySheetCommand as cn,RemoveSheetCommand as ln,SheetInterceptorService as un,SheetPermissionCheckController as dn,SheetSkeletonService as fn,SheetsSelectionsService as pn,UniverSheetsPlugin as mn,WorkbookCopyPermission as hn,WorkbookEditablePermission as gn,WorksheetCopyPermission as _n,WorksheetEditPermission as vn,attachRangeWithCoord as yn,discreteRangeToRange as bn,getSheetCommandTarget as xn}from"@univerjs/sheets";import{DrawingApplyType as B,ISheetDrawingService as Sn,RemoveSheetDrawingCommand as Cn,SetDrawingApplyMutation as V,SetDrawingArrangeCommand as wn,SetSheetDrawingCommand as Tn,SheetDrawingAnchorType as En,UniverSheetsDrawingPlugin as Dn,applySheetDrawingPlacement as On,transformDrawingsToChartSheet as kn,transformToAxisAlignPosition as An}from"@univerjs/sheets-drawing";import{COPY_TYPE as jn,ISheetClipboardService as Mn,PREDEFINED_HOOK_NAME as Nn,SHEET_VIEW_KEY as Pn,SheetCanvasPopManagerService as Fn,SheetPasteCommand as In,SheetPrintInterceptorService as Ln,SheetScrollManagerService as Rn,SheetSkeletonManagerService as H,UniverSheetsMobileUIPlugin as zn,UniverSheetsUIPlugin as Bn,deriveStateFromActiveSheet$ as Vn,getCurrentRangeDisable$ as Hn,getViewportByCell as Un}from"@univerjs/sheets-ui";import{IDrawingManagerService as U,SetDrawingSelectedOperation as Wn,UniverDrawingPlugin as Gn,getDrawingShapeKeyByDrawingSearch as W,getOrCreateDrawingCopyPlan as Kn}from"@univerjs/drawing";import{BehaviorSubject as qn,EMPTY as G,Observable as Jn,defer as Yn,distinctUntilChanged as Xn,map as Zn,merge as Qn,of as $n,startWith as er,switchMap as tr}from"rxjs";import{DrawingCommonPanel as nr,DrawingImageClipService as rr,DrawingRenderService as ir,IMAGE_CLIP_SHAPE_PICKER_COMPONENT as ar,MobileObjectListPanel as or,OBJECT_LIST_FLOATING_SECTION_ID as sr,ObjectListPanelBase as cr,UniverDrawingUIPlugin as lr,getCurrentUnitInfo as ur,getObjectListPanelSectionIdForDrawingType as dr,insertGroupObject as fr}from"@univerjs/drawing-ui";import{MobileDropdown as pr}from"@univerjs/design";import{Fragment as mr,jsx as K,jsxs as hr}from"react/jsx-runtime";import{UniverLicensePlugin as gr}from"@univerjs-pro/license";import{DocInterceptorService as _r,DocSelectionManagerService as vr,UniverDocsPlugin as yr}from"@univerjs/docs";import{DocCanvasPopManagerService as br,DocEventManagerService as xr,DocRenderController as Sr,DocSelectionRenderService as Cr,UniverDocsUIPlugin as wr}from"@univerjs/docs-ui";import{SheetDrawingAnchor as Tr,SheetsDrawingGroupCopyPasteController as Er,UniverSheetsDrawingMobileUIPlugin as Dr,UniverSheetsDrawingUIPlugin as Or}from"@univerjs/sheets-drawing-ui";import{BottomIcon as kr,FlipHorizontalIcon as Ar,FlipVerticalIcon as jr,MoveDownIcon as Mr,MoveUpIcon as Nr,ObjectLayersIcon as Pr,ShapeFormatSettingIcon as Fr,TopmostIcon as Ir}from"@univerjs/icons";import{memo as Lr,useEffect as Rr,useMemo as zr,useReducer as Br,useState as Vr}from"react";function Hr(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)?Hr(a,i):a}return n}const q={type:A.COMMAND,id:`sheet.command.update-shape-data`,handler:(e,t)=>{let n=e.get(O),{unitId:r,subUnitId:i,shapeType:a,shapeId:o,shapeData:s,replaceShapeData:c,oldShapeJSON:l}=t;if(!n.getShapeModel(r,i,o))return!1;let u=e.get(N),d=e.get(It),{oldShapeType:f,oldShapeData:p={}}=l,m=c?p:Hr(p,s||{}),h={id:k.id,params:{unitId:r,subUnitId:i,shapeId:o,shapeType:a,shapeData:s,replace:c}},g={id:k.id,params:{unitId:r,subUnitId:i,shapeId:o,shapeType:f,shapeData:m,replace:c}};return u.syncExecuteCommand(h.id,h.params)?(d.pushUndoRedo({unitID:r,undoMutations:[g],redoMutations:[h]}),!0):!1}};function Ur(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(q.id,o)}function Wr(e,t,n,r,i,a){let o={unitId:t,subUnitId:n,shapeId:r,shapeData:a,oldShapeJSON:i};return e.executeCommand(q.id,o)}function Gr(e){"@babel/helpers - typeof";return Gr=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},Gr(e)}function Kr(e,t){if(Gr(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(Gr(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function qr(e){var t=Kr(e,`string`);return Gr(t)==`symbol`?t:t+``}function J(e,t,n){return(t=qr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Jr(e,t,n){let r={...t,dataModel:{...t.dataModel??{},...n?{doc:n}:null}},i=be(e,r),a=xe(i);return{clip:Te(i,a),wrapStrategy:a}}var Yr=class extends rn{constructor(t,n){super(t,n),J(this,`_hyperLinkRegions`,[]),J(this,`_props`,void 0),J(this,`_formulaAnimation`,new e(()=>this.makeDirty(!0),()=>this._applyFormulaAutoFitSize())),J(this,`_transformCalculateSrcRect`,!0),J(this,`_drawingType`,M.DRAWING_SHAPE),J(this,`isDrawingObject`,!0),this._props={...n},this._formulaAnimation.setPresentation(n.formulaPresentation,n.animateFormulaPresentation!==!1),this._init(),this._applyFormulaAutoFitSize()}_init(){this.onTransformChange$.subscribeEvent(e=>{this._updateSrcRectByTransform(e)})}setPrstGeom(e){this._props.prstGeom=e}resolveHyperLinkAt(e){if(this._props.isEditing)return null;let t=this.getInverseCoord(e),{width:n,height:r}=this.getRealBound();return Se(this._hyperLinkRegions,{x:(this.flipX?-t.x:t.x)+n/2,y:t.y+r/2})}setEditing(e){this._props.isEditing=e,this.makeDirty(!0)}setFormulaPresentation(e,t=!0){this._formulaAnimation.setPresentation(e,t),this._props.formulaPresentation=e,this._applyFormulaAutoFitSize(),this.makeDirty(!0)}_applyFormulaAutoFitSize(){let e=this._props.shapeModel,t=e.getShapeTextData(),n=fe(t==null?void 0:t.dataModel),r=n==null?void 0:n.doc,i=this._formulaAnimation.getAutoFitPresentations();if(!r||i.length===0)return;e.updateContext({width:this.width,height:this.height});let a=ge({documentData:i.map(e=>at(r,e)),height:this.height,shapeData:e.getShapeData(),textRect:e.getShapeTextRect({left:0,top:0,width:this.width,height:this.height}),width:this.width});if(a){var o;this.resize(a.width,a.height),(o=this.getScene())==null||(o=o.getTransformer())==null||o.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 tn.SHAPE}_draw(e,t,n,r){let i=this._props.shapeModel;if(!i||!t)return;let a=n??this.width,o=r??this.height,s={shapeType:i.getShapeType(),width:a,height:o},c={renderMode:Ye.Path,oKey:this.oKey,image:this._props.image,angle:this.angle};i.updateContext(s),e.save();let l={top:0,left:0,width:a,height:o},u=i.getDrawingEffectBounds(l);u?this._renderWithCache(e,u,e=>{i.render(e,l,c)}):(this._releaseRenderCache(),i.render(e,l,c)),e.restore();let d=i.getShapeTextData(),f=i.getShapeTextRect(l),p=i.isLineShape();if(d&&f&&!p){e.save(),this.getState().flipX&&e.scale(-1,1);let t=a/2,n=o/2;e.translate(-t,-n),e.beginPath(),this._drawShapeText(e,d,f),e.restore()}}getDrawingPoints(e){}_drawShapeText(e,t,n){var r;this._hyperLinkRegions=[],this._props.isEditing||(!((r=t.dataModel)!=null&&r.doc)&&`isRichText`in t&&t.isRichText===!1?this._drawSimpleText(e,t,n):this._drawRichText(e,t,n))}_drawSimpleText(e,t,n){this._drawRichText(e,{...t,text:t.text??``,dataModel:{doc:pe(t,`sheets-shape-text-${this.oKey}`)}},n)}_drawRichText(e,t,n){se(e,this._formulaAnimation,(e,r,i)=>{this._drawRichTextLayer(e,t,n,r,i===`current`)})}_drawRichTextLayer(e,t,n,r,i){let a=this._props.localeService;if(!t.dataModel||!a)return;let o=fe(t.dataModel);if(!o)return;let s=o.doc;if(!s)return;let c=at(s,r),l=o.va??Ht.TOP,u=o.ha??At.LEFT,d=Jr(this._props.shapeModel.getShapeData(),t,c),f=t.isHorizontal,p=me(c,{isHorizontal:f!==!1,textRect:n,verticalAlign:l,horizontalAlign:u,wrapStrategy:d.wrapStrategy}),m=new Dt(p),h=new Qt(m),g=Zt.create(h,a);g.calculate();let _=g.getActualSize().actualHeight,v=ye({contentHeight:_,verticalAlign:l,viewportHeight:n.height});m.updateDocumentStyle({pageSize:{width:f===!1?n.height:n.width,height:ve(c,v.contentHeight)}}),m.updateDocumentDataMargin({t:v.marginTop}),g.calculate();let y=new $t(`shape-text-${this.oKey}`,g,{pageMarginLeft:0,pageMarginTop:0,onTextFillImageLoaded:()=>this.makeDirty(!0)});y.resize(n.width,v.contentHeight),e.save(),e.translateWithPrecision(n.left,n.top),d.clip&&(e.beginPath(),e.rect(0,v.clipTop,n.width,v.clipHeight),e.clip()),v.contentVerticalOffset&&e.translateWithPrecision(0,v.contentVerticalOffset),y.draw(e),i&&(this._hyperLinkRegions=oe(y,{left:n.left,top:n.top+v.contentVerticalOffset},d.clip?{left:n.left,right:n.left+n.width,top:n.top+v.clipTop,bottom:n.top+v.clipTop+v.clipHeight}:void 0)),e.restore(),y.dispose(),g.dispose(),h.dispose(),m.dispose()}render(e,t,n=!1){if(!this.visible)return this.makeDirty(!1),this;let{width:r,height:i,left:a,top:o}=this,s=this.getRealBound();if(r=s.width,i=s.height,a=s.left,o=s.top,this.isRender(t)){let{top:e,left:n,bottom:s,right:c}=t.viewBound;if(r+this.strokeWidth+a<n||c<a||i+this.strokeWidth+o<e||s<o)return this}let c=a+r/2,l=o+i/2,u=this.transform.getMatrix();if(this._props.isEditing){let e=this.getState(),t=new an;t.composeMatrix({...e}),u=t.getMatrix()}return e.save(),this._props.shapeModel.isRenderLinePointsMode===!0||e.transform(u[0],u[1],u[2],u[3],c,l),this._draw(e,t,r,i),e.restore(),this.makeDirty(!1),this}getInverseCoord(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=this.transform.getMatrix(),o=t+r/2,s=n+i/2,c=new an([a[0],a[1],a[2],a[3],o,s]),l=this.getParent();return(this.isInGroup&&(l==null?void 0:l.classType)===tn.GROUP?l.ancestorTransform.multiply(c):c).invert().applyPoint(e)}isHit(e){let{left:t,top:n,width:r,height:i}=this.getRealBound(),a=t+r/2,o=n+i/2,s=this.transform.getMatrix(),c=new an([s[0],s[1],s[2],s[3],a,o]),l=this.getParent(),u=(this.isInGroup&&(l==null?void 0:l.classType)===tn.GROUP?l.ancestorTransform.multiply(c):c).invert().applyPoint(e),d=r/2,f=i/2,p=this._props.shapeModel;return p&&p.isLineShape()?p.isHitLine(u.x,u.y,r,i):u.x>=-d-this.strokeWidth/2&&u.x<=d+this.strokeWidth/2&&u.y>=-f-this.strokeWidth/2&&u.y<=f+this.strokeWidth/2}dispose(){this._formulaAnimation.dispose(),this._props.shapeModel=null,super.dispose()}},Xr=class extends rn{constructor(e,t){super(e,t),J(this,`_shapeId`,null),J(this,`_adjName`,null),J(this,`_unitId`,null),J(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){Xt.drawWith(e,{radius:E.adjHandleSize,fill:E.adjHandleFill,stroke:E.adjHandleStroke,strokeWidth:1,evented:!0})}};function Y(e,t){return function(n,r){t(n,r,e)}}function X(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 Z=class extends j{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,J(this,`_formulaShapes`,/* @__PURE__ */ new Map),this.disposeWithMe(this._shapeFormulaService.presentationChanged$.subscribe(e=>{var t;(t=this._formulaShapes.get(this._formulaKey(e.unitId,e.subUnitId,e.shapeId)))==null||t.forEach(t=>t.setFormulaPresentation(e.presentation,e.animationEnabled))})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._formulaShapes.delete(this._formulaKey(e.unitId,e.subUnitId,e.drawingId))})}))}renderDrawingShape(e,t,n){let{transform:r,drawingType:i,isMultiTransform:a,transforms:o}=e;if(i===M.DRAWING_SHAPE&&this._drawingManagerService.getDrawingVisible()&&r)return(a&&o?o:[r]).flatMap((r,i)=>{var o;let s=W(e,a?i:void 0),c=t.getObjectIncludeInGroup(s);if(c)return c instanceof Yr&&this.refreshFormulaPresentation(c,{unitId:e.unitId,subUnitId:e.subUnitId,shapeId:e.drawingId}),c.transformByState(r),[];let l=this._createShape(e,r,s,t);if(!l)return[];let u=this._loadShapePictureFill(l,l.shapeModel.getShapeData());return u&&(n==null||(o=n.resourceCollector)==null||o.add(u)),[l]})}_createShape(e,t,n,i){let{unitId:a,subUnitId:o,drawingId:s,groupId:c,hidden:l,selectable:u,prstGeom:d,srcRect:f}=e,p=this._sheetsShapeService.getShapeModel(a,o,s);if(!p)return;let m=this._drawingManagerService.getDrawingOrder(a,o),h=m.indexOf(s),g=D(p.getShapeType()),_=p.getShapeData().formulaBinding,v={unitId:a,subUnitId:o,shapeId:s};_&&this._shapeFormulaService.register(v,_);let y=new Yr(n,{...t,zIndex:h===-1?m.length-1:h,shapeModel:p,drawingType:M.DRAWING_SHAPE,localeService:this._localeService,shapeId:s,unitId:a,subUnitId:o,visible:l!==!0,evented:u!==!1,formulaPresentation:_?this._shapeFormulaService.getPresentation(v):void 0,animateFormulaPresentation:(_==null?void 0:_.animationEnabled)!==!1,transformerConfig:{...r,...g?{rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1}:{},moveBoundaryEnabled:!0}});if(_){let e=this._formulaKey(a,o,s),t=this._formulaShapes.get(e)??/* @__PURE__ */ new Set;t.add(y),this._formulaShapes.set(e,t)}return i.addObject(y,R),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(y),c&&fr({drawingId:c,unitId:a,subUnitId:o},y,i,this._drawingManagerService),d!=null&&y.setPrstGeom(d),f!=null&&y.setSrcRect(f),y}_formulaKey(e,t,n){return`${e}\u0000${t}\u0000${n}`}refreshFormulaPresentation(e,t){let n=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.shapeId),r=n==null?void 0:n.getShapeData().formulaBinding,i=this._formulaKey(t.unitId,t.subUnitId,t.shapeId);if(r){this._shapeFormulaService.register(t,r);let n=this._formulaShapes.get(i)??/* @__PURE__ */ new Set;n.add(e),this._formulaShapes.set(i,n)}else{var a;this._shapeFormulaService.unregister(t),(a=this._formulaShapes.get(i))==null||a.delete(e)}e.setFormulaPresentation(r?this._shapeFormulaService.getPresentation(t):void 0,(r==null?void 0:r.animationEnabled)!==!1)}refreshShapeFillImage(e){let t=e.shapeModel.getShapeData(),n=t.fill;!n||n.fillType!==Ke.PictureFill||!n.fillImageSource?e.setFillImage(void 0):this._loadShapePictureFill(e,t)}_loadShapePictureFill(e,t){let n=t.fill;if(!n||n.fillType!==Ke.PictureFill||!n.fillImageSource)return;let r=n.fillImageSource,i=n.fillImageSourceType??Ue.URL,a=this._imageIoService.getImageSourceCache(r,i);if(a)e.setFillImage(a);else return this._loadAndSetImage(e,r,i)}async _loadAndSetImage(e,t,n){let r;try{if(n===Ue.UUID)r=await this._imageIoService.getImage(t);else if(n===Ue.URL)try{r=await this._urlImageService.getImage(t)}catch{r=t}else r=t}catch(e){console.error(`[ShapeRender] Failed to resolve picture fill source`,e);return}await new Promise(i=>{let a=new window.Image;a.onload=()=>{this._imageIoService.addImageSourceCache(t,n,a),e.setFillImage(a),i()},a.onerror=()=>{console.error(`[ShapeRender] Failed to load picture fill image`,t),i()},a.src=r})}};Z=X([Y(0,U),Y(1,F(O)),Y(2,F(Rt)),Y(3,Nt),Y(4,Ft),Y(5,F(tt))],Z);let Zr=class extends j{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,J(this,`_activeShapeId`,null),J(this,`_unitId`,null),J(this,`_subUnitId`,null),J(this,`_activeShapeAdjustPointList`,void 0),J(this,`_shapes`,[]),J(this,`_baseShapeLeft`,0),J(this,`_baseShapeTop`,0),J(this,`_baseShapeWidth`,0),J(this,`_baseShapeHeight`,0),J(this,`_isStartAdjusting`,!1),J(this,`_activeAdjustInfo`,void 0),J(this,`_activeShapeModel`,void 0),J(this,`_adjHandlerPointerMove`,void 0),J(this,`_adjHandlerPointerUp`,void 0),J(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(H).getCurrentSkeleton())return;let{scene:n}=t,r={unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId},i=this._drawingManagerService.getDrawingByParam(r),{transform:a}=i;if(!a||i.drawingType!==M.DRAWING_SHAPE)return;let{left:o,top:s,width:c,height:l,flipX:u,flipY:d,angle:f=0}=a;if(o===void 0||s===void 0)return;if(e){let e=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);e==null||e.updateContext({width:c??0,height:l??0}),this._activeShapeAdjustPointList=e==null?void 0:e.getDrawingPoints()}let p=this._activeShapeAdjustPointList;for(let e=0;e<p.length;e++){let t=p[e],r=t.x,i=t.y;if(u&&(r=(c||0)-r),d&&(i=(l||0)-i),f!==0){let e=(c||0)/2,t=(l||0)/2,n=f*Math.PI/180,a=Math.cos(n),o=Math.sin(n),s=r-e,u=i-t;r=e+(s*a-u*o),i=t+(s*o+u*a)}let a={x:r,y:i,adjName:t.adjName};this._addShapeAdjustControl(n,a,a.adjName,o,s,this._unitId,this._subUnitId)}}_updateShapeAdjustControls(e=!1){e&&(this._clearShapeAdjustControls(),this._createShapeAdjustControls(e))}_addShapeAdjustControl(e,t,n,r,i,a,o){if(!this._activeShapeId)return;let s=e.getObjectIncludeInGroup(`shape-adjust-point-${this._activeShapeId}-${n}`);if(s){s.transformByState({left:t.x+r-E.adjHandleSize,top:t.y+i-E.adjHandleSize});return}let c={left:t.x+r-E.adjHandleSize,top:t.y+i-E.adjHandleSize,adjName:n,shapeId:this._activeShapeId,unitId:a,subUnitId:o,width:E.adjHandleSize+8,height:E.adjHandleSize+8,zIndex:R+1,evented:!0},l=new Xr(`shape-adjust-point-${this._activeShapeId}-${n}`,c);this._shapes.push(l),this._attachAdjustEvent(l,e,n),e.addObject(l,R+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(H).getSkeleton(t))return r;let a=i.with(Rn),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=Un(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(qt(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,s,c;let l=e.getDrawingSearch();this._activeAdjustInfo=this._getShapeAdjustInfosById(l.unitId,l.subUnitId,l.drawingId,n),this._activeShapeModel=this._sheetsShapeService.getShapeModel(l.unitId,l.subUnitId,l.drawingId);let u=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),{transform:d}=u;if(d){let{left:e,top:t,width:n,height:r}=d;this._baseShapeLeft=e||0,this._baseShapeTop=t||0,this._baseShapeWidth=n||0,this._baseShapeHeight=r||0}let f=!!((a=u.transform)!=null&&a.flipX),p=!!((o=u.transform)!=null&&o.flipY),m=((s=u.transform)==null?void 0:s.angle)||0;this._isStartAdjusting=!0,t.disableObjectsEvent();let h={...((c=this._activeAdjustInfo)==null?void 0:c.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(Yt.CROSSHAIR);let e={left:0,top:0,width:this._baseShapeWidth,height:this._baseShapeHeight},n=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s=r/o+n.x-this._baseShapeLeft,c=i/o+n.y-this._baseShapeTop;if(m!==0){let e=this._baseShapeWidth/2,t=this._baseShapeHeight/2,n=m*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=s-e,o=c-t;s=e+(a*r+o*i),c=t+(-a*i+o*r)}f&&(s=this._baseShapeWidth-s),p&&(c=this._baseShapeHeight-c);let u={x:s,y:c},d=this._activeShapeModel.calcAdjValues(e,u,a,f,p);if(Object.keys(d).length===0)return;for(let[e,t]of Object.entries(d))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseShapeWidth,height:this._baseShapeHeight});let h=this._drawingManagerService.getDrawingByParam({unitId:l.unitId,subUnitId:l.subUnitId,drawingId:l.drawingId});h&&(this._sheetDrawingShapeRenderController.renderDrawingShape(h,t),this._activeShapeAdjustPointList=this._getShapeAdjustPointListById(l.unitId,l.subUnitId,l.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=l.unitId,t=l.subUnitId,n=l.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&&Ur(this._commandService,e,t,n,{oldShapeData:{adjustValues:h}},{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$(L.UNIVER_SHEET);this.disposeWithMe(e.pipe(tr(e=>e?e.activeSheet$.pipe(tr(t=>{if(!t)return G;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?$n(i):G})):G)).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 Yr&&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!==k.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===M.DRAWING_SHAPE&&this._univerInstanceService.getUnitType(t.unitId)===L.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)===M.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())}))}};Zr=X([Y(0,U),Y(1,F(O)),Y(2,F(z)),Y(3,F(Z)),Y(4,P),Y(5,N)],Zr);const Qr={id:`drawing.operation.set-drawing-active`,type:A.OPERATION,handler:(e,t)=>{let n=e.get(U),r=e.get(z),i=e.get(Zr);if(t==null)return!0;if(t.length>0){var a;let e=(a=r.getRenderUnitById(t[0].unitId))==null?void 0:a.scene;if(e){let{unitId:n,subUnitId:i,drawingId:a}=t[0],s=W({unitId:n,subUnitId:i,drawingId:a},void 0),c=e.getObjectIncludeInGroup(s);if(c){var o;(o=r.getRenderUnitById(t[0].unitId))==null||(o=o.scene.getTransformer())==null||o.activeAnObject(c)}}n.focusDrawing(t),i.setShouldShowAdjust(!1)}return!0}},$r={type:A.COMMAND,id:`sheet.command.menu-insert-shape`,handler:async(e,t)=>{var n,r;let i=xn(e.get(P));if(!i)return!1;let{unitId:a,subUnitId:o,worksheet:s}=i,c=s.getConfig(),l=c.type??I.GRID;if(l!==I.GRID&&l!==I.CHART)return!1;let u=e.get(Pt);if(((n=u.getPermissionPoint(new gn(a).id))==null?void 0:n.value)!==!0||((r=u.getPermissionPoint(new vn(a,o).id))==null?void 0:r.value)!==!0)return!1;let d=e.get(N),{value:f,enhanceParams:p}=t,m={unitId:a,subUnitId:o,shapeType:f,shapeId:Wt()};if(l===I.CHART){let t=e.get(z).getRenderUnitById(a),n=t==null?void 0:t.components.get(Pn.CHART_PAGE);if(!t||!n||![n.left,n.top,n.width,n.height].every(Number.isFinite)||n.width<=0||n.height<=0)return!1;let r={row:0,column:0,rowOffset:0,columnOffset:0},i=kn([{unitId:a,subUnitId:o,drawingId:m.shapeId,drawingType:M.DRAWING_SHAPE,transform:{left:0,top:0,width:dt,height:ut},axisAlignSheetTransform:{from:r,to:r}}],{left:n.left,top:n.top,width:n.width,height:n.height},c.rightToLeft===Ct.TRUE);if(!(i!=null&&i.length))return!1;let s=i[0].transform;m.position={x:s.left,y:s.top},m.width=s.width,m.height=s.height}else{let t=e.get(pn).getCurrentLastSelection();if(!t)return!1;m.range=t.range}if(p){let{startArrow:t,endArrow:n,horizontal:r,vertical:i}=p,a=D(f),o=f===Xe.Rect;if(a&&(t||n)&&(m.shapeData={ln:{startArrow:t?{type:Ge.Arrow,size:We.Medium}:void 0,endArrow:n?{type:Ge.Arrow,size:We.Large}:void 0}}),o&&(r||i)){let t=e.get(Bt);m.shapeData=ot({fill:{fillType:Ke.SolidFill,color:t.getColorFromTheme(`gray.0`)},isHorizontal:!!r,stroke:{lineStrokeType:qe.SolidLine,width:1,color:t.getColorFromTheme(`gray.300`)}})}}let h=d.syncExecuteCommand(ft.id,m);return h&&await d.executeCommand(Qr.id,[{unitId:a,subUnitId:o,drawingId:m.shapeId}]),h}},ei=`sheet.shape.edit.panel`,ti=`sheet.shape.object-list.panel`,ni=`sheet.shape.floating-toolbar`,ri=`sheets-shape-ui.ribbon.shape-format`,ii=Ut(`SHAPE_TEXT`),ai=`sheet.shape.text.float-menu`,oi={id:`sheet.operation.open-shape-object-list-panel`,type:A.COMMAND,handler:(e,t)=>{let n=e.get(Fe),r=e.get(Rt),i=e.get(P),a=e.get(N);return xn(i)?(t==null?void 0:t.value)===`close`?(n.close(ti),!0):(n.open({id:ti,header:{title:r.t(`sheets-shape-ui.objectListPanel.title`)},children:{label:ti},onClose:()=>{a.syncExecuteCommand(Wn.id,[])},width:360}),!0):!1}},si={type:A.OPERATION,id:`sheet.operation.open-sheet-shape-format-panel`,handler(){return!0}};function ci(e){let t=e.get(U).getFocusDrawings(),n=t.length===1?t[0]:null;if(!n||n.drawingType!==M.DRAWING_SHAPE)return null;let r=e.get(O),i=r.getShapeTypeById(n.unitId,n.subUnitId,n.drawingId),a=r.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);return i===void 0||!a?null:{drawing:n,shapeData:a,shapeType:i}}const li={id:`sheet.operation.apply-shape-quick-style`,type:A.OPERATION,handler:(e,t)=>{let n=ci(e),r=st((t==null?void 0:t.presetId)??(t==null?void 0:t.value)??``);if(!n||!r||r.type!==ct(n.shapeData))return!1;let i=rt(n.shapeData,r);if(!i)return!1;let{drawing:a}=n;return e.get(N).executeCommand(q.id,{unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.drawingId,shapeData:i,oldShapeJSON:{oldShapeData:n.shapeData}})}},ui={id:`sheet.operation.update-shape-type`,type:A.OPERATION,handler:(e,t)=>{let n=ci(e),r=(t==null?void 0:t.shapeType)??(t==null?void 0:t.value);if(!n||!r||D(n.shapeType)||D(r))return!1;let i=it(n.shapeData,r);if(!i)return!1;let{drawing:a}=n;return e.get(N).executeCommand(q.id,{unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.drawingId,shapeType:r,shapeData:i,replaceShapeData:!0,oldShapeJSON:{oldShapeType:n.shapeType,oldShapeData:n.shapeData}})}};let Q=class extends j{constructor(e,t){super(),this._clipService=e,this._drawingManagerService=t,this._registerImageShapeClipDelegate(),this._clipService.setCanUseShapeClip(!0),this.disposeWithMe({dispose:()=>this._clipService.setCanUseShapeClip(!1)})}_registerImageShapeClipDelegate(){let e=this._clipService,t=/* @__PURE__ */ new Map,n=e.registerClipDelegate((e,n,r,i,a)=>{let o=n;if(o===Xe.None||n===`custom`)return!1;try{let s=t.get(n);return s||(s=new Je(o,`clip-${n}`),t.set(n,s)),s.clearAdjustValue(),a&&Object.keys(a).length>0&&s.setShapeData({adjustValues:a},!0),s.updateContext({width:r,height:i}),s.buildClipPath(e,{left:0,top:0,width:r,height:i})}catch{return!1}});this.disposeWithMe(n),this.disposeWithMe({dispose:()=>t.clear()})}clipByShape(e,t,n,r,i){let a=this._drawingManagerService.getDrawingData(e,t);if(!a[n])return;let o={...a[n],prstGeom:r,adjustValues:i};this._drawingManagerService.featurePluginUpdateNotification([o])}};Q=X([Y(0,F(rr)),Y(1,F(U))],Q);const di=`sheet.shape.picker.component`,fi=`sheet.image-clip.shape-picker.component`;function pi({onShapeClick:e,excludeGroups:t}){return/* @__PURE__ */ K(f,{excludeGroups:t,onShapeClick:e,scrollContainer:`parent`})}function mi(){let e=w(U),t=w(Q);return/* @__PURE__ */ K(d,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[u.Line],onShapeClick:n=>{let r=e.getFocusDrawings().find(e=>e.drawingType===M.DRAWING_IMAGE);if(!r)return;let{unitId:i,subUnitId:a,drawingId:o}=r;t.clipByShape(i,a,o,n.type)}})}function hi(){let e=w(U),t=w(Q);return/* @__PURE__ */ K(d,{buttonLabel:`sheets-shape-ui.imagePanel.crop.shape`,excludeGroups:[u.Line],DropdownComponent:pr,onShapeClick:n=>{let r=e.getFocusDrawings().find(e=>e.drawingType===M.DRAWING_IMAGE);if(!r)return;let{unitId:i,subUnitId:a,drawingId:o}=r;t.clipByShape(i,a,o,n.type)}})}function gi(){let e=w(De),t=w(U),n=w(P),r=t.getFocusDrawings()[0],i=r?n.getUnitType(r.unitId):void 0,a=i===L.UNIVER_DOC?`doc.image-clip.shape-picker.component`:i===L.UNIVER_SHEET?fi:void 0,o=a?e.get(a):void 0;return o?/* @__PURE__ */ K(o,{}):null}function _i(){let e=w(N);return/* @__PURE__ */ K(pi,{onShapeClick:t=>{e.executeCommand($r.id,{value:t.type,enhanceParams:{endArrow:t.endArrow,startArrow:t.startArrow,horizontal:t.horizontal,vertical:t.vertical}})}})}function vi(){return/* @__PURE__ */ K(_i,{})}function yi(e){return Vn(e.get(P),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??I.GRID;if(r===I.GRID)return Hn(e);if(r!==I.CHART)return $n(!0);let i=e.get(Pt),a=[new gn(t.getUnitId()).id,new vn(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe(er(null),Zn(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),Xn())})}function bi(e){let t=e.get(P);return{id:$r.id,type:C.SELECTOR,selections:[{label:{name:di,hoverable:!1,selectable:!1,props:{id:$r.id}}}],icon:`ShapeIcon`,tooltip:`sheets-shape-ui.insertShape`,activated$:Vn(t,!1,()=>new Jn(e=>{e.next(!1)})),hidden$:Ve(e,L.UNIVER_SHEET),disabled$:yi(e)}}function xi(e){return Vn(e.get(P),!0,({workbook:t,worksheet:n})=>{let r=n.getConfig().type??I.GRID;if(r===I.GRID)return Hn(e);if(r!==I.CHART)return $n(!0);let i=e.get(Pt),a=[new gn(t.getUnitId()).id,new vn(t.getUnitId(),n.getSheetId()).id];return i.permissionPointUpdate$.pipe(er(null),Zn(()=>a.some(e=>{var t;return((t=i.getPermissionPoint(e))==null?void 0:t.value)!==!0})),Xn())})}function Si(e){let t=e.get(Fe);return{id:oi.id,type:C.BUTTON,icon:`ObjectLayersIcon`,title:`sheets-shape-ui.objectListPanel.open`,tooltip:`sheets-shape-ui.objectListPanel.open`,activated$:Yn(()=>t.sidebarOptions$.pipe(er(t.options),Zn(e=>e.visible===!0&&e.id===`sheet.shape.object-list.panel`),Xn())),hidden$:Ve(e,L.UNIVER_SHEET),disabled$:xi(e)}}const Ci=`sheet.menu.shape.flip-horizontal`,wi=`sheet.menu.shape.flip-vertical`;function Ti(e){let t=e.get(U).getFocusDrawings();return t.length===1&&t[0].drawingType===M.DRAWING_SHAPE?t[0]:null}function Ei(e){let t=e.get(U);return t.focus$.pipe(er(t.getFocusDrawings()),Zn(e=>e.length!==1||e[0].drawingType!==M.DRAWING_SHAPE))}function Di(e){return{id:Ci,commandId:vt.id,type:C.BUTTON,title:`sheets-shape-ui.flipHorizontal`,tooltip:`sheets-shape-ui.flipHorizontal`,icon:`FlipHorizontalIcon`,hidden$:Ei(e),params:()=>{let t=Ti(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipH:!0}:void 0}}}function Oi(e){return{id:wi,commandId:vt.id,type:C.BUTTON,title:`sheets-shape-ui.flipVertical`,tooltip:`sheets-shape-ui.flipVertical`,icon:`FlipVerticalIcon`,hidden$:Ei(e),params:()=>{let t=Ti(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.drawingId,flipV:!0}:void 0}}}let $=class extends j{constructor(e){super(),this._permissionService=e,J(this,`_editingParams$`,new qn(null)),J(this,`editingParams$`,this._editingParams$.asObservable()),J(this,`_onSavingEditorData$`,new qn(!1)),J(this,`onSavingEditorData$`,this._onSavingEditorData$.asObservable()),J(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 gn(e.unitId).id),n=this._permissionService.getPermissionPoint(new vn(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)}};$=X([Y(0,Pt)],$);const ki=`sheets-shape-ui.shape-format.quick-style-gallery`,Ai=`sheets-shape-ui.shape-format.style-ribbon-control`,ji=`sheets-shape-ui.shape-format.text-ribbon-control`,Mi=`sheets-shape-ui.shape-format.formula-ribbon-control`;function Ni(){let e=w(N),t=w(U),n=w(O),r=()=>{var e;let r=t.getFocusDrawings();if(r.length!==1||((e=r[0])==null?void 0:e.drawingType)!==M.DRAWING_SHAPE)return null;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=n.getShapeTypeById(i,a,o),c=n.getShapeDataById(i,a,o);return s===void 0||!c?null:{unitId:i,subUnitId:a,drawingId:o,shapeType:s,shapeData:c}},i=He(()=>new Jn(n=>{let i=()=>n.next(r()),a=t.focus$.subscribe(i),o=e.onCommandExecuted(e=>{e.id===k.id&&i()});return i(),()=>{a.unsubscribe(),o.dispose()}}),r(),!1,[e,t,n]);return{selection:i,updateShapeData:t=>{i&&Ur(e,i.unitId,i.subUnitId,i.drawingId,{oldShapeData:i.shapeData},t)}}}function Pi(){let{selection:e,updateShapeData:t}=Ni();return e?/* @__PURE__ */ K(m,{shapeData:e.shapeData,shapeType:e.shapeType,onUpdateShapeData:t}):null}function Fi(){let e=w(N),t=w(Rt),{selection:n}=Ni();return n?/* @__PURE__ */ K(p,{type:ct(n.shapeData),ariaLabel:t.t(`sheets-shape-ui.quickStyles`),activePresetId:lt(n.shapeData),onSelect:t=>e.executeCommand(li.id,{presetId:t})}):null}function Ii(){let{selection:e,updateShapeData:t}=Ni(),n=w($),r=He(n.editingParams$,n.getEditing());if(!e)return null;let i=de(r,e);return/* @__PURE__ */ K(x,{editorUnitId:i?ii:void 0,fontFamilyPopupDataComponent:`sheets-shape-format-font-family-menu`,shapeData:e.shapeData,onUpdateShapeData:t})}function Li(){var e;let{selection:t,updateShapeData:n}=Ni(),r=Ee({hostType:L.UNIVER_SHEET,unitId:(t==null?void 0:t.unitId)??``,subUnitId:(t==null?void 0:t.subUnitId)??``,shapeId:(t==null?void 0:t.drawingId)??``,shapeData:t==null?void 0:t.shapeData,registerBinding:!1,showLabels:!0,dropdownSide:`bottom`,onUpdateBinding:e=>n({formulaBinding:e})}),i=((e=r.extensionGroups)==null?void 0:e.flatMap(e=>e.actions).filter(e=>e.visible!==!1))??[];return t!=null&&t.shapeData.formulaBinding?/* @__PURE__ */ K(l,{actions:i,panel:r.panel}):null}const Ri=`sheets-shape-ui.ribbon.shape-format.style-control`,zi=`sheets-shape-ui.ribbon.shape-format.text-control`,Bi=`sheets-shape-ui.ribbon.shape-format.formula-control`,Vi=`sheets-shape-ui.ribbon.shape-format.arrange-forward`,Hi=`sheets-shape-ui.ribbon.shape-format.arrange-backward`,Ui=`sheets-shape-ui.ribbon.shape-format.arrange-front`,Wi=`sheets-shape-ui.ribbon.shape-format.arrange-back`;function Gi(e){let t=e.get(N),n=e.get(U),r=e.get(O);return new Jn(i=>{let a=()=>{let t=Ki(e),n=t?r.getShapeDataById(t.unitId,t.subUnitId,t.drawingId):null;i.next(n?lt(n)??``:``)},o=n.focus$.subscribe(a),s=t.onCommandExecuted(e=>{e.id===k.id&&a()});return a(),()=>{o.unsubscribe(),s.dispose()}})}function Ki(e){var t;let n=e.get(U).getFocusDrawings();return n.length===1&&((t=n[0])==null?void 0:t.drawingType)===M.DRAWING_SHAPE?n[0]:null}function qi(e,t=!1){let n=e.get(N),r=e.get(U),i=e.get(O);return new Jn(a=>{let o=()=>{let n=Ki(e);if(!n){a.next(!0);return}let r=i.getShapeDataById(n.unitId,n.subUnitId,n.drawingId);a.next(!r||t&&r.formulaBinding==null)},s=r.focus$.subscribe(o),c=n.onCommandExecuted(e=>{e.id===k.id&&o()});return o(),()=>{s.unsubscribe(),c.dispose()}})}function Ji(e){let t=e.get(U),n=e.get(O);return t.focus$.pipe(er(t.getFocusDrawings()),Zn(()=>{let t=Ki(e),r=t?n.getShapeTypeById(t.unitId,t.subUnitId,t.drawingId):void 0;return r===void 0||D(r)}))}function Yi(e){return{id:li.id,type:C.SELECTOR,icon:`PaintIcon`,title:`shape-editor-ui.toolbar.quickStyles`,tooltip:`shape-editor-ui.toolbar.quickStyles`,selections:[{label:{name:ki,hoverable:!1,selectable:!1}}],value$:Gi(e),hidden$:qi(e)}}function Xi(e){return{id:ui.id,type:C.SELECTOR,icon:`ShapeIcon`,title:`shape-editor-ui.toolbar.changeShape`,tooltip:`shape-editor-ui.toolbar.changeShape`,slot:!0,selections:[{label:{name:n,hoverable:!1,selectable:!1}}],hidden$:Ji(e)}}function Zi(e,t,n=!1){return r=>({id:e,type:C.BUTTON,label:{name:t,hoverable:!1,selectable:!1},hidden$:qi(r,n)})}const Qi=Zi(Ri,Ai),$i=Zi(zi,ji),ea=Zi(Bi,Mi,!0);function ta(e,t,n,r){return i=>({id:e,commandId:wn.id,type:C.BUTTON,icon:n,title:r,tooltip:r,hidden$:qi(i),params:()=>{let e=Ki(i);return e?{unitId:e.unitId,subUnitId:e.subUnitId,drawingIds:[e.drawingId],arrangeType:t}:void 0}})}const na=ta(Vi,St.forward,`MoveUpIcon`,`shape-editor-ui.arrange.forward`),ra=ta(Hi,St.backward,`MoveDownIcon`,`shape-editor-ui.arrange.backward`),ia=ta(Ui,St.front,`TopmostIcon`,`shape-editor-ui.arrange.front`),aa=ta(Wi,St.back,`BottomIcon`,`shape-editor-ui.arrange.back`);function oa(e){let t=e.get(Fe);return{activated$:Yn(()=>t.sidebarOptions$.pipe(er(t.options),Zn(e=>e.visible===!0&&e.id===`sheet.shape.edit.panel`),Xn())),id:si.id,type:C.BUTTON,icon:`ShapeFormatSettingIcon`,title:`sheets-shape-ui.formatShape`,tooltip:`sheets-shape-ui.formatShape`,hidden$:qi(e),params:()=>{let t=Ki(e);return t?{unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId}:void 0}}}const sa={[Le.RIBBON]:{[ri]:{order:100,title:`sheets-shape-ui.formatShape`,contextual:!0,"sheets-shape-ui.ribbon.shape-format.quick-styles":{order:0,[li.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:Yi},[ui.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:Xi}},"sheets-shape-ui.ribbon.shape-format.style":{order:1,[Ri]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:Qi}},"sheets-shape-ui.ribbon.shape-format.text":{order:2,[zi]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:$i}},"sheets-shape-ui.ribbon.shape-format.arrange":{order:3,[Ci]:{order:0,gridLayout:{row:1,column:1},menuItemFactory:Di},[wi]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:Oi},[Vi]:{order:2,gridLayout:{row:1,column:2},menuItemFactory:na},[Hi]:{order:3,gridLayout:{row:2,column:2},menuItemFactory:ra},[Ui]:{order:4,gridLayout:{row:1,column:3},menuItemFactory:ia},[Wi]:{order:5,gridLayout:{row:2,column:3},menuItemFactory:aa}},"sheets-shape-ui.ribbon.shape-format.formula":{order:4,[Bi]:{order:0,gridLayout:{row:1,column:1,rowSpan:2},menuItemFactory:ea}},"sheets-shape-ui.ribbon.shape-format.advanced":{order:5,[si.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:oa},[S.id]:{order:1,gridLayout:{row:2,column:1,showLabel:!0},menuItemFactory:c}}}}},ca={[Re.MEDIA]:{[$r.id]:{order:3,menuItemFactory:bi}}},la={...ca,[Re.OTHERS]:{[oi.id]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Si}},[ke.DRAWING]:{[Oe.OTHERS]:{[Ci]:{order:4,menuItemFactory:Di},[wi]:{order:5,menuItemFactory:Oi}}}};var ua=`@univerjs-pro/sheets-shape-ui`,da=`1.6.0`;const fa={id:`sheet.operation.open-mobile-shape-editor`,type:A.OPERATION,handler(e,n){return n?(e.get(t).open(n.mode,{hostType:L.UNIVER_SHEET,shapeId:n.drawingId,subUnitId:n.subUnitId,unitId:n.unitId}),!0):!1}},pa=`sheets-shape-ui.config`,ma={};let ha=class extends j{constructor(e,t,n,r,i){super(),this._context=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._imageShapeClipController=i,J(this,`_activeImageId`,null),J(this,`_unitId`,null),J(this,`_subUnitId`,null),J(this,`_activeAdjustPointList`,void 0),J(this,`_shapes`,[]),J(this,`_baseLeft`,0),J(this,`_baseTop`,0),J(this,`_baseWidth`,0),J(this,`_baseHeight`,0),J(this,`_isStartAdjusting`,!1),J(this,`_activeAdjustInfo`,void 0),J(this,`_activeShapeModel`,void 0),J(this,`_adjHandlerPointerMove`,void 0),J(this,`_adjHandlerPointerUp`,void 0),J(this,`_isImagePointerDown`,!1),this._registerFocusChangeHandler(),this._registerMoveHandler()}clearAdjustControls(){this._clearControls()}refreshAdjustControls(){this._clearControls(),this._createControls(!0)}_getOrCreateShapeModel(e,t,n,r){let i=e;if(i!==Xe.None&&e!==`custom`)try{let a=new Je(i,`clip-adj-${e}`);return r&&a.setShapeData({adjustValues:r},!0),a.updateContext({width:t,height:n}),a}catch{return}}_getImageDrawingInfo(e,t,n){let r={unitId:e,subUnitId:t,drawingId:n},i=this._drawingManagerService.getDrawingByParam(r);if(i&&i.drawingType===M.DRAWING_IMAGE)return i}_getImagePrstGeom(e,t,n){let r=this._renderManagerService.getRenderUnitById(e);if(!r)return;let{scene:i}=r,a=W({unitId:e,subUnitId:t,drawingId:n}),o=i.getObject(a);if(o instanceof en){let e=o.prstGeom;if(e)return{prstGeom:e,adjustValues:o.prstGeomAdjValues}}}_createControls(e=!1){if(!this._unitId||!this._subUnitId||!this._activeImageId)return;let t=this._renderManagerService.getRenderUnitById(this._unitId);if(!t||!t.with(H).getCurrentSkeleton())return;let{scene:n}=t,r=this._getImageDrawingInfo(this._unitId,this._subUnitId,this._activeImageId);if(!r)return;let{transform:i}=r;if(!i)return;let{left:a,top:o,width:s,height:c,flipX:l,flipY:u,angle:d=0}=i;if(a===void 0||o===void 0)return;let f=this._getImagePrstGeom(this._unitId,this._subUnitId,this._activeImageId);if(!f)return;if(e){let e=this._getOrCreateShapeModel(f.prstGeom,s||0,c||0,f.adjustValues);if(!e)return;this._activeAdjustPointList=e.getDrawingPoints()}let p=this._activeAdjustPointList;if(p&&p.length!==0)for(let e=0;e<p.length;e++){let t=p[e],r=t.x,i=t.y;if(l&&(r=(s||0)-r),u&&(i=(c||0)-i),d!==0){let e=(s||0)/2,t=(c||0)/2,n=d*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 f={x:r,y:i,adjName:t.adjName};this._addControl(n,f,f.adjName,a,o,this._unitId,this._subUnitId)}}_addControl(e,t,n,r,i,a,o){if(!this._activeImageId)return;let s=`image-clip-adjust-point-${this._activeImageId}-${n}`,c=e.getObjectIncludeInGroup(s);if(c){c.transformByState({left:t.x+r-E.adjHandleSize,top:t.y+i-E.adjHandleSize});return}let l=new Xr(s,{left:t.x+r-E.adjHandleSize,top:t.y+i-E.adjHandleSize,adjName:n,shapeId:this._activeImageId,unitId:a,subUnitId:o,width:E.adjHandleSize+8,height:E.adjHandleSize+8,zIndex:R+1,evented:!0});this._shapes.push(l),this._attachAdjustEvent(l,e,n),e.addObject(l,R+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(H).getSkeleton(t))return r;let a=i.with(Rn),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=Un(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(qt(e.onPointerDown$.subscribeEvent((r,i)=>{var a,o,s;let{unitId:c,subUnitId:l,drawingId:u}=e.getDrawingSearch(),d=this._getImageDrawingInfo(c,l,u);if(!(d!=null&&d.transform))return;let{left:f,top:p,width:m,height:h}=d.transform;this._baseLeft=f||0,this._baseTop=p||0,this._baseWidth=m||0,this._baseHeight=h||0;let g=!!((a=d.transform)!=null&&a.flipX),_=!!((o=d.transform)!=null&&o.flipY),v=((s=d.transform)==null?void 0:s.angle)||0,y=this._getImagePrstGeom(c,l,u);if(!y)return;let b=this._getOrCreateShapeModel(y.prstGeom,this._baseWidth,this._baseHeight,y.adjustValues);if(!b||(this._activeShapeModel=b,this._activeAdjustInfo=b.getAdjustInfoByName(n),!this._activeAdjustInfo))return;this._isStartAdjusting=!0,t.disableObjectsEvent();let x=y.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(Yt.CROSSHAIR);let o={left:0,top:0,width:this._baseWidth,height:this._baseHeight},s=this._getScrollInfo(c,l),d=this._getZoomRatio(c,l),f=r/d+s.x-this._baseLeft,p=i/d+s.y-this._baseTop;if(v!==0){let e=this._baseWidth/2,t=this._baseHeight/2,n=v*Math.PI/180,r=Math.cos(n),i=Math.sin(n),a=f-e,o=p-t;f=e+(a*r+o*i),p=t+(-a*i+o*r)}g&&(f=this._baseWidth-f),_&&(p=this._baseHeight-p);let m=this._activeShapeModel.calcAdjValues(o,{x:f,y:p},a,g,_);if(Object.keys(m).length!==0){for(let[e,t]of Object.entries(m))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:this._baseWidth,height:this._baseHeight}),this._updateImageAdjValues(c,l,u,m),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(c,l,u,x,t)}this._activeAdjustInfo=void 0,this._activeShapeModel=void 0,this._isStartAdjusting=!1,n.stopPropagation(),t.enableObjectsEvent()}),i.stopPropagation()})))}_updateImageAdjValues(e,t,n,r){let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i,o=W({unitId:e,subUnitId:t,drawingId:n}),s=a.getObject(o);if(s instanceof en){let e=s.prstGeomAdjValues??{};s.setPrstGeomAdjValues({...e,...r}),s.makeDirty(!0)}}_registerMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(L.UNIVER_SHEET);this.disposeWithMe(e.pipe(tr(e=>e?e.activeSheet$.pipe(tr(t=>{if(!t)return G;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?$n(i):G})):G)).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 en&&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===M.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)===M.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()}};ha=X([Y(1,U),Y(2,F(z)),Y(3,P),Y(4,F(Q))],ha);function ga({PanelComponent:e=cr}){var t;function n(e){return e.trim()||void 0}function r(e,t,n){var r;return((r=e.name)==null?void 0:r.trim())||`${n.t(`drawing-ui.objectListPanel.typeNames.${ce(e.drawingType)}`)} ${t+1}`}let i=w(Rt),a={title:i.t(`drawing-ui.objectListPanel.title`),empty:i.t(`drawing-ui.objectListPanel.empty`),showAll:i.t(`drawing-ui.objectListPanel.showAll`),hideAll:i.t(`drawing-ui.objectListPanel.hideAll`),lockAll:i.t(`drawing-ui.objectListPanel.lockAll`),unlockAll:i.t(`drawing-ui.objectListPanel.unlockAll`),moveForward:i.t(`drawing-ui.objectListPanel.moveForward`),moveBackward:i.t(`drawing-ui.objectListPanel.moveBackward`),close:i.t(`drawing-ui.objectListPanel.close`),show:i.t(`drawing-ui.objectListPanel.show`),hide:i.t(`drawing-ui.objectListPanel.hide`),lock:i.t(`drawing-ui.objectListPanel.lock`),unlock:i.t(`drawing-ui.objectListPanel.unlock`),lockHint:i.t(`drawing-ui.objectListPanel.lockHint`),unlockHint:i.t(`drawing-ui.objectListPanel.unlockHint`),name:i.t(`drawing-ui.objectListPanel.name`),nameInput:i.t(`drawing-ui.objectListPanel.nameInput`),description:i.t(`drawing-ui.objectListPanel.description`),descriptionPlaceholder:i.t(`drawing-ui.objectListPanel.descriptionPlaceholder`),details:i.t(`drawing-ui.objectListPanel.details`),noSelection:i.t(`drawing-ui.objectListPanel.noSelection`),locate:i.t(`drawing-ui.objectListPanel.locate`),expand:i.t(`drawing-ui.objectListPanel.expand`),collapse:i.t(`drawing-ui.objectListPanel.collapse`),dragToReorder:i.t(`drawing-ui.objectListPanel.dragToReorder`),search:i.t(`drawing-ui.objectListPanel.search`),filterAll:i.t(`drawing-ui.objectListPanel.filterAll`),filterHidden:i.t(`drawing-ui.objectListPanel.filterHidden`),filterLocked:i.t(`drawing-ui.objectListPanel.filterLocked`),sectionCanvas:i.t(`drawing-ui.objectListPanel.sectionCanvas`),sectionFloating:i.t(`drawing-ui.objectListPanel.sectionFloating`)},o=w(N),s=w(P),c=w(Sn),l=w(U),u=w(z),d=w(Me),[,f]=Br(e=>e+1,0),p=s.getCurrentUnitOfType(L.UNIVER_SHEET),m=(p==null?void 0:p.getUnitId())??``,h=(p==null||(t=p.getActiveSheet())==null?void 0:t.getSheetId())??``,g=He(()=>l.focus$,l.getFocusDrawings(),!1,[l]);Rr(()=>{let e=o.onCommandExecuted(()=>f());return()=>e.dispose()},[o]);let _=m&&h?c.getDrawingData(m,h):{},v=(m&&h?c.getDrawingOrder(m,h):[]).map(e=>_[e]).filter(e=>!!e).reverse(),y=v.reduce((e,t)=>(e[dr(t.drawingType)]+=1,e),{canvas:0,floating:0}),b={canvas:0,floating:0},x=v.map((e,t)=>{let n=dr(e.drawingType),o=n===sr,s=b[n]++;return{id:e.drawingId,name:r(e,t,i),description:e.description,visible:e.hidden!==!0,selectable:e.selectable!==!1,sectionId:n,sectionTitle:o?a.sectionFloating:a.sectionCanvas,capabilities:o?{arrange:!1,reorder:!1}:void 0,canMoveForward:!o&&s>0,canMoveBackward:!o&&s<y.canvas-1,canReorder:!o}}),S=zr(()=>(g??[]).filter(e=>e.unitId===m&&e.subUnitId===h).map(e=>e.drawingId),[g,h,m]),ee=S[S.length-1]??null,te=e=>c.getDrawingByParam({unitId:m,subUnitId:h,drawingId:e})??null,re=async e=>{m&&e.length&&await o.executeCommand(Tn.id,{unitId:m,drawings:e})},ie=async(e,t)=>{te(e)&&await re([{unitId:m,subUnitId:h,drawingId:e,...t}])},oe=(e,t)=>{if(!m||!h)return;let n=t?S.includes(e)?S.filter(t=>t!==e):[...S,e]:[e];o.syncExecuteCommand(Wn.id,n.map(e=>({unitId:m,subUnitId:h,drawingId:e})));let r=n[n.length-1];r?(ne(u,{unitId:m,subUnitId:h,drawingId:r}),d.focus(m)):ae(u,m)},se=async(e,t)=>{await re(e.map(e=>te(e)).filter(e=>!!e).filter(e=>e.hidden!==!0!==t).map(e=>({unitId:m,subUnitId:h,drawingId:e.drawingId,hidden:!t})))},le=async(e,t)=>{await re(e.map(e=>te(e)).filter(e=>!!e).filter(e=>e.selectable!==!1!==t).map(e=>({unitId:m,subUnitId:h,drawingId:e.drawingId,selectable:t})))},ue=e=>{let t=te(e);if(t)return le([e],t.selectable===!1)},de=async(e,t)=>{var r;let i=n(t);(((r=te(e))==null?void 0:r.name)??void 0)!==i&&await ie(e,{name:i})},fe=async(e,t)=>{var r;let i=n(t);(((r=te(e))==null?void 0:r.description)??void 0)!==i&&await ie(e,{description:i})},pe=async(e,t)=>{m&&h&&await o.executeCommand(wn.id,{unitId:m,subUnitId:h,drawingIds:[e],arrangeType:t})};return!m||!h?/* @__PURE__ */ K(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-500`,children:a.title}):/* @__PURE__ */ K(e,{labels:a,items:x,selectedIds:S,focusedId:ee,showHeader:!1,onSelect:oe,onSetVisible:se,onSetSelectable:le,onCommitName:de,onCommitDescription:fe,onMoveForward:async e=>pe(e,St.forward),onMoveBackward:async e=>pe(e,St.backward),onToggleSelectable:ue})}function _a(){return/* @__PURE__ */ K(ga,{PanelComponent:or})}let va=class extends j{constructor(e,t){super(),this.disposeWithMe(e.register(ti,_a)),this.disposeWithMe(t.register({BottomIcon:kr,FlipHorizontalIcon:Ar,FlipVerticalIcon:jr,MoveDownIcon:Mr,MoveUpIcon:Nr,ObjectLayersIcon:Pr,ShapeFormatSettingIcon:Fr,TopmostIcon:Ir})),this.disposeWithMe(e.register(di,vi)),this.disposeWithMe(e.register(fi,hi)),e.hasDefault(ar)||this.disposeWithMe(e.register(ar,gi))}};va=X([Y(0,F(De)),Y(1,F(Ie))],va);let ya=class extends j{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,J(this,`_lastEditingShapeKey`,null),this._initEvents(),this._initSelection(),this._initEditingParams()}_initEvents(){let{scene:e}=this._context;this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:n,offsetY:r}=t,i=e.pick(sn.FromArray([n,r]));if(i instanceof Yr){let e=this._sheetsShapeService.getShapeModel(i.unitId,i.subUnitId,i.shapeId);if(D(this._sheetsShapeService.getShapeType(i.unitId,i.subUnitId,i.shapeId))||e!=null&&e.getShapeData().formulaBinding)return;this._shapeTextEditingService.setEditing({visible:!0,unitId:i.unitId,subUnitId:i.subUnitId,shapeId:i.shapeId,shapeKey:i.oKey})}}))}_initSelection(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{if(e.length===1){let n=e[0],r=this._drawingManagerService.getDrawingByParam(n);if((r==null?void 0:r.drawingType)===M.DRAWING_SHAPE){var t;let e=this._shapeTextEditingService.getEditing();if((e==null?void 0:e.shapeId)===n.drawingId&&e.visible)return;let r=D(this._sheetsShapeService.getShapeType(n.unitId,n.subUnitId,n.drawingId)),i=!!((t=this._sheetsShapeService.getShapeModel(n.unitId,n.subUnitId,n.drawingId))!=null&&t.getShapeData().formulaBinding);(r||i)&&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(kt,n)}else this._lastEditingShapeKey=null,this._contextService.setContextValue(kt,!1)}))}};ya=X([Y(1,F(Lt)),Y(2,F($)),Y(3,U),Y(4,Mt),Y(5,F(O))],ya);var ba=class extends ya{_initEvents(){let{scene:e}=this._context,n=this._injector.get(t);this.disposeWithMe(e.onDblclick$.subscribeEvent(t=>{let{offsetX:r,offsetY:i}=t,a=e.pick(sn.FromArray([r,i]));if(!(a instanceof Yr))return;let o=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.shapeId);D(this._sheetsShapeService.getShapeType(a.unitId,a.subUnitId,a.shapeId))||o!=null&&o.getShapeData().formulaBinding||n.open(`text`,{hostType:L.UNIVER_SHEET,unitId:a.unitId,subUnitId:a.subUnitId,shapeId:a.shapeId})}))}};const xa={...ca};let Sa=class extends j{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,J(this,`_shapePopupMenuDisposable`,null),this._menuManagerService.mergeMenu(xa),this._registerFeatureMenu(),this.disposeWithMe(this._shapeTextEditingService.editingParams$.subscribe(e=>{e&&this._clearFocusedShape()}))}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe(re(this._renderManagerService,L.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_registerFeatureMenu(){this._sheetCanvasPopManagerService.registerFeatureMenu(M.DRAWING_SHAPE,(e,t,n,r)=>{let i=this._sheetsShapeService.getShapeTypeById(e,t,n),a=this._sheetsShapeService.getShapeDataById(e,t,n),o=i!==void 0&&!D(i)&&!(a!=null&&a.formulaBinding);return[{label:`sheets-shape-ui.editShape`,index:0,commandId:fa.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`style`},disable:!1},...o?[{label:`sheets-shape-ui.editText`,index:1,commandId:fa.id,commandParams:{unitId:e,subUnitId:t,drawingId:n,mode:`text`},disable:!1}]:[],{label:`sheets-shape-ui.deleteShape`,index:2,commandId:Cn.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:t,drawingId:n,drawingType:r}]},disable:!1},{label:`sheets-shape-ui.flipHorizontal`,index:3,commandId:vt.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipH:!0},disable:!1},{label:`sheets-shape-ui.flipVertical`,index:4,commandId:vt.id,commandParams:{unitId:e,subUnitId:t,shapeId:n,flipV:!0},disable:!1}]},`sheets-shape-ui.title`)}_popupMenuListener(e){let t=new Et,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(Ot,!1),this._drawingManagerService.focusDrawing(null))};return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(t.size>1){r();return}let i=t.values().next().value;if(!i){r();return}let a=this._drawingManagerService.getDrawingOKey(i.oKey);if(!a||a.drawingType!==M.DRAWING_SHAPE){r();return}let{unitId:o,subUnitId:s,drawingId:c}=a;n={unitId:o,subUnitId:s,drawingId:c},this._contextService.setContextValue(Ot,!0),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===o&&e.subUnitId===s&&e.drawingId===c)||this._drawingManagerService.focusDrawing([{unitId:o,subUnitId:s,drawingId:c}])})),t.add(e.clearControl$.subscribe(()=>{r()})),qt(()=>{t.dispose(),r()})}_clearFocusedShape(){this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)}};Sa=X([Y(0,Ne),Y(1,F(O)),Y(2,N),Y(3,U),Y(4,F(Fn)),Y(5,Mt),Y(6,z),Y(7,F($))],Sa);function Ca(e,t,n,r){let i=Kn(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 wa=class extends j{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===ln.id){let t=xn(this._univerInstanceService,e.params);if(!t)return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=t,i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i).filter(e=>e.drawingType===M.DRAWING_SHAPE);if(a.length===0)return{redos:[],undos:[]};let o=[],s=[];for(let e=0;e<a.length;e++){let t=a[e],i=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);i&&(o.push({id:mt.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId}}),s.push({id:pt.id,params:{unitId:n,subUnitId:r,shapeId:t.drawingId,shapeType:i.getShapeType(),shapeData:JSON.parse(JSON.stringify(i.getShapeData()))}}))}return{redos:o,undos:s}}if(e.id===cn.id){let{unitId:t,subUnitId:n,targetSubUnitId:r,copyContext:i}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let a=this._sheetDrawingService.getDrawingData(t,n),o=Object.values(a).filter(e=>e.drawingType===M.DRAWING_SHAPE);if(o.length===0)return{redos:[],undos:[]};let s=Ca(i,o,{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()))}}),c=[],l=[];for(let{targetShapeId:e,source:n}of s)c.push({id:pt.id,params:{unitId:t,subUnitId:r,shapeId:e,shapeType:n.shapeType,shapeData:n.shapeData}}),l.push({id:mt.id,params:{unitId:t,subUnitId:r,shapeId:e}});return{redos:c,undos:l}}return{redos:[],undos:[]}}}))}};wa=X([Y(0,F(P)),Y(1,F(un)),Y(2,F(Sn)),Y(3,F(O))],wa);let Ta=class extends j{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,J(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===k.id){let{unitId:t,subUnitId:n,shapeId:r}=e.params,i=this._getSceneAndTransformerByDrawingSearch(t),a=W({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===pt.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=W({unitId:r,subUnitId:i,drawingId:a}),l=s.getObjectIncludeInGroup(c);if(!((n=this._renderManagerService.getRenderUnitById(r))!=null&&n.with(H).getSkeleton(i)))return!1;if(l)return;if(t!=null&&t.fromChangeset){queueMicrotask(()=>{this._disposed||this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])});return}this._insertShapes([{unitId:r,subUnitId:i,drawingId:a}])}}))}_shapeUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._drawingManagerService.getDrawingByParam(e);if(i==null)return;let{transform:a,drawingType:o,srcRect:s,prstGeom:c}=i;if(o!==M.DRAWING_SHAPE)return;let l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;let{scene:u,transformer:d}=l;if(a==null)return!0;let f=W({unitId:t,subUnitId:n,drawingId:r}),p=u.getObjectIncludeInGroup(f);if(p==null)return!0;p.setSrcRect(s),p.setPrstGeom(c)})}))}_insertShapes(e){for(let n of e){var t;let{unitId:e,subUnitId:r,drawingId:i}=n,a=this._getSceneAndTransformerByDrawingSearch(e),o=(t=ur(this._currentUniverService,e))==null?void 0:t.subUnitId;if(a==null||o!==r)continue;let s=W({unitId:e,subUnitId:r,drawingId:i});if(this._insertingShapeKeys.has(s)||a.scene.getObjectIncludeInGroup(s)!=null)continue;let c=this._drawingManagerService.getDrawingByParam(n);if(c==null||c.drawingType!==M.DRAWING_SHAPE)continue;let l=c.data||{};if(D(l.shapeType)){let e=c.transform;e&&(c.transform={...e,rotateEnabled:!1,resizeEnabled:!1,borderEnabled:!1})}this._insertingShapeKeys.add(s);try{this._sheetDrawingShapeRenderController.renderDrawingShape(c,a.scene)}finally{this._insertingShapeKeys.delete(s)}queueMicrotask(()=>{if(this._disposed)return;let e=W(n);if(!a.scene.getObjectIncludeInGroup(e))return;let t=this._drawingManagerService.getDrawingByParam(n);t&&this._drawingManagerService.refreshTransform([t])})}}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}};Ta=X([Y(0,N),Y(1,z),Y(2,U),Y(3,P),Y(4,F(ir)),Y(5,F(Z))],Ta);const Ea={normal:{fill:E.cxnPointFill,stroke:E.cxnPointStroke,strokeWidth:E.cxnPointStrokeWidth},highlighted:{fill:`#4285f4`,stroke:`#1a73e8`,strokeWidth:2}};var Da=class extends rn{constructor(e,t){super(e,t),J(this,`_targetShapeId`,``),J(this,`_cxnIndex`,-1),J(this,`_unitId`,``),J(this,`_subUnitId`,``),J(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??E.cxnPointRadius*2,height:e.height??E.cxnPointRadius*2})}_draw(e){let t=this._isHighlighted?Ea.highlighted:Ea.normal;Xt.drawWith(e,{radius:E.cxnPointRadius,fill:t.fill,stroke:t.stroke,strokeWidth:t.strokeWidth,evented:!0})}};let Oa=class extends j{constructor(e,t,n,r){super(),this._context=e,this._renderManagerService=t,this._drawingManagerService=n,this._sheetsShapeService=r,J(this,`_connectionSiteObjects`,[]),J(this,`_activeTargetShapeId`,null),J(this,`_highlightedSiteIndex`,-1),J(this,`_currentScene`,null),J(this,`_unitId`,``),J(this,`_subUnitId`,``),J(this,`_draggingConnectorId`,null)}startConnectionDetection(e,t,n,r){this._currentScene=e,this._unitId=t,this._subUnitId=n,this._draggingConnectorId=r}updateConnectionDetection(e){if(!this._currentScene)return null;let t=this._findShapeAtPoint(e);return t?(this._activeTargetShapeId!==t.shapeId&&(this._clearConnectionSites(),this._showConnectionSites(t.shapeId,t.shapeModel),this._activeTargetShapeId=t.shapeId),this._findNearestConnectionSite(e)):(this._activeTargetShapeId!==null&&(this._clearConnectionSites(),this._activeTargetShapeId=null),null)}endConnectionDetection(){this._clearConnectionSites(),this._currentScene=null,this._activeTargetShapeId=null,this._highlightedSiteIndex=-1,this._draggingConnectorId=null}getConnectionRelation(){return this._activeTargetShapeId===null||this._highlightedSiteIndex<0?null:{shapeId:this._activeTargetShapeId,cxnIndex:this._highlightedSiteIndex}}_findShapeAtPoint(e){let t=this._drawingManagerService.getDrawingData(this._unitId,this._subUnitId);for(let n of Object.keys(t)){if(n===this._draggingConnectorId||t[n].drawingType!==M.DRAWING_SHAPE)continue;let r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,n);if(!r||D(r.getShapeType())||r.getConnectionSiteList().length===0||!this._currentScene)continue;let i=W({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:n}),a=this._currentScene.getObjectIncludeInGroup(i);if(!a)continue;let{left:o,top:s,width:c,height:l}=a.getRealBound(),u=o+c/2,d=s+l/2,f=a.transform.getMatrix(),p=new an([f[0],f[1],f[2],f[3],u,d]),m=a.getParent(),h=(a.isInGroup&&(m==null?void 0:m.classType)===tn.GROUP?m.ancestorTransform.multiply(p):p).invert().applyPoint(e),g=c/2,_=l/2;if(h.x>=-g-5&&h.x<=g+5&&h.y>=-_-5&&h.y<=_+5)return{shapeId:n,shapeModel:r}}return null}_showConnectionSites(e,t){if(!this._currentScene)return;let n=W({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:e}),r=this._currentScene.getObjectIncludeInGroup(n);if(!r)return;let{left:i,top:a,width:o,height:s}=r.getRealBound(),c=i+o/2,l=a+s/2,u=r.transform.getMatrix(),d=new an([u[0],u[1],u[2],u[3],c,l]),f=r.getParent(),p=r.isInGroup&&(f==null?void 0:f.classType)===tn.GROUP?f.ancestorTransform.multiply(d):d;t.updateContext({width:o,height:s});let m=t.getConnectionSiteList();for(let t of m){let n=t.x-o/2,r=t.y-s/2,i=p.applyPoint({x:n,y:r}),a=i.x,c=i.y,l=new Da(`connection-site-${e}-${t.index}`,{left:a-E.cxnPointRadius,top:c-E.cxnPointRadius,targetShapeId:e,cxnIndex:t.index,unitId:this._unitId,subUnitId:this._subUnitId,width:E.cxnPointRadius*2,height:E.cxnPointRadius*2,zIndex:R+2,evented:!1});this._connectionSiteObjects.push(l),this._currentScene.addObject(l,R+2)}}_findNearestConnectionSite(e){let t=null,n=1/0,r=null;for(let i of this._connectionSiteObjects){let a=i.left+E.cxnPointRadius,o=i.top+E.cxnPointRadius,s=e.x-a,c=e.y-o,l=Math.sqrt(s*s+c*c);l<n&&(n=l,t=i,r={x:a,y:o})}let i=n<=10&&t?t.getConnectionInfo().cxnIndex:-1;if(i!==this._highlightedSiteIndex){for(let e of this._connectionSiteObjects){let t=e.getConnectionInfo();e.setHighlighted(t.cxnIndex===i)}this._highlightedSiteIndex=i}if(n<=10&&t&&r){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:r,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()}};Oa=X([Y(1,F(z)),Y(2,F(U)),Y(3,F(O))],Oa);let ka=class extends j{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,J(this,`_copyInfo`,void 0),this._initCopyPaste(),this._registerGroupFeaturePasteHook()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_registerGroupFeaturePasteHook(){this._groupCopyPasteController.registerFeaturePasteHook(({fromUnitId:e,fromSubUnitId:t,toUnitId:n,toSubUnitId:r,idMap:i})=>{let a=[],o=[];for(let[l,u]of i.entries()){let d=this._shapeService.getShapeModel(e,t,l);if(!d)continue;let f=d.getShapeType(),p=JSON.parse(JSON.stringify(d.getShapeData()));if(p.relation){var s,c;let e=(s=p.relation.from)==null?void 0:s.shapeId,t=(c=p.relation.to)==null?void 0:c.shapeId,n=!e||i.has(e),r=!t||i.has(t);n&&e&&p.relation.from?p.relation.from={...p.relation.from,shapeId:i.get(e)}:p.relation.from=void 0,r&&t&&p.relation.to?p.relation.to={...p.relation.to,shapeId:i.get(t)}:p.relation.to=void 0}a.push({id:pt.id,params:{unitId:n,subUnitId:r,shapeId:u,shapeType:f,shapeData:p}}),o.push({id:mt.id,params:{unitId:n,subUnitId:r,shapeId:u}})}return{redos:a,undos:o}})}_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===M.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===Nn.DEFAULT_PASTE?this._generatePasteMutations(t,this._copyInfo.copyType===jn.CUT):{redos:[],undos:[]}}}))}_createCopyInfoByRange(e,t,n,r){let i=this._sheetSkeletonService.getSkeleton(e,t);if(!i)return;let a=yn(i,n);if(!a)return;let{startX:o,endX:s,startY:c,endY:l}=a,u=this._sheetDrawingService.getDrawingData(e,t),d=[];for(let[e,t]of Object.entries(u)){if(t.drawingType!==M.DRAWING_SHAPE)continue;let{transform:e}=t;if(!e)continue;let{left:n=0,top:r=0,width:i=0,height:a=0}=e;o<=n&&s>=n+i&&c<=r&&l>=r+a&&d.push(t)}d.length>0&&(this._copyInfo={unitId:e,subUnitId:t,copyType:r,copyRange:n,drawings:d})}_generatePasteMutations(e,t){var n,r;let{unitId:i,subUnitId:a,range:o}=e,s=this._copyInfo,c=(n=this._instances.getUnit(s.unitId,L.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(s.subUnitId),l=(r=this._instances.getUnit(i,L.UNIVER_SHEET))==null?void 0:r.getSheetBySheetId(a),u=(c==null?void 0:c.getConfig().type)??I.GRID,d=(l==null?void 0:l.getConfig().type)??I.GRID;if(u===I.CHART||d===I.CHART)return this._generateChartSheetCopy(e,t);let f=this._sheetSkeletonService.getSkeleton(i,a);if(!f)return{redos:[],undos:[]};let p=bn(o),{unitId:m,subUnitId:h,copyRange:g,drawings:_}=this._copyInfo,v=this._sheetSkeletonService.getSkeleton(m,h);if(!v)return{redos:[],undos:[]};let y;if(!g){let e=1/0,t=1/0;for(let n of _){let{left:r=0,top:i=0}=n.transform??{};r<e&&(e=r),i<t&&(t=i)}e!==1/0&&t!==1/0&&(y={left:e,top:t})}let b=/* @__PURE__ */ new Map;if(!t)for(let e of _)b.set(e.drawingId,Wt());let x=[],S=[];for(let e of _){let{drawingId:n,transform:r}=e;if(!r)continue;let o=this._updateTransform(r,{skeleton:v,range:g},{skeleton:f,range:p},y);if(t){let{redos:t,undos:n}=this._generateCutPasteMutations({fromUnitId:m,fromSubUnitId:h,toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:o});x.push(...t),S.push(...n);continue}let{redos:s,undos:c}=this._generateCopyPasteMutations({toUnitId:i,toSubUnitId:a,drawing:e,newTransforms:o,newDrawingId:b.get(n),idMap:b});x.push(...s),S.push(...c)}return{redos:x,undos:S}}_generateChartSheetCopy(e,t){var n;if(t)throw new wt(In.id);let{unitId:r,subUnitId:i}=e;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[gn],worksheetTypes:[vn]},r,i))throw new wt(In.id);let a=(n=this._instances.getUnit(r,L.UNIVER_SHEET))==null?void 0:n.getSheetBySheetId(i),o=a==null?void 0:a.getConfig(),s=(o==null?void 0:o.type)??I.GRID,c=this._copyInfo,l=c.drawings;if(!this._permissions.permissionCheckWithoutRange({workbookTypes:[hn],worksheetTypes:[_n]},c.unitId,c.subUnitId)||l.some(e=>e.groupId||!this._shapeService.getShapeModel(c.unitId,c.subUnitId,e.drawingId)||!Vt.diffValue(e,this._sheetDrawingService.getDrawingByParam(e))))throw new wt(In.id);let u=null;if(s===I.CHART){var d;let e=(d=this._renders.getRenderUnitById(r))==null?void 0:d.components.get(Pn.CHART_PAGE);e&&(u=kn(l,{left:e.left,top:e.top,width:e.width,height:e.height},(o==null?void 0:o.rightToLeft)===Ct.TRUE))}else{let t=this._sheetSkeletonService.getSkeleton(r,i),n=t&&yn(t,bn(e.range));if(n&&l.length){let e=Math.min(...l.map(e=>e.transform.left)),r=Math.min(...l.map(e=>e.transform.top));u=l.map(i=>On(i,{kind:En.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(!u)throw new wt(In.id);let f=new Map(l.map(e=>[e.drawingId,Wt()])),p=[],m=[];for(let[e,t]of l.entries()){let n=u[e],a=this._generateCopyPasteMutations({toUnitId:r,toSubUnitId:i,drawing:t,idMap:f,newDrawingId:f.get(t.drawingId),newTransforms:{transform:n.transform,axisAlignSheetTransform:n.axisAlignSheetTransform,anchorType:n.anchorType}});p.push(...a.redos),m.unshift(...a.undos)}return{redos:p,undos:m}}_generateCutPasteMutations(e){let{fromUnitId:t,fromSubUnitId:n,toUnitId:r,toSubUnitId:i,drawing:a,newTransforms:o}=e,s={...a,unitId:r,subUnitId:i,...o};if(r===t&&i===n){let{redo:e,undo:t,objects:n}=this._sheetDrawingService.getBatchUpdateOp([s]);return{redos:[{id:V.id,params:{unitId:r,subUnitId:i,type:B.UPDATE,op:e,objects:n}}],undos:[{id:V.id,params:{unitId:r,subUnitId:i,type:B.UPDATE,op:t,objects:n}}]}}{let e=this._sheetDrawingService.getBatchRemoveOp([a]),o=this._sheetDrawingService.getBatchAddOp([s]),c=this._shapeService.getShapeModel(a.unitId,a.subUnitId,a.drawingId);if(!c)return{redos:[],undos:[]};let l=c.getShapeType(),u=JSON.parse(JSON.stringify(c.getShapeData()));return{redos:[{id:V.id,params:{unitId:t,subUnitId:n,type:B.REMOVE,op:e.redo,objects:e.objects}},{id:mt.id,params:{unitId:t,subUnitId:n,shapeId:a.drawingId}},{id:V.id,params:{unitId:r,subUnitId:i,type:B.INSERT,op:o.redo,objects:o.objects}},{id:pt.id,params:{unitId:r,subUnitId:i,shapeId:a.drawingId,shapeType:l,shapeData:u}}],undos:[{id:V.id,params:{unitId:t,subUnitId:n,type:B.INSERT,op:e.undo,objects:e.objects}},{id:pt.id,params:{unitId:t,subUnitId:n,shapeId:a.drawingId,shapeType:l,shapeData:u}},{id:V.id,params:{unitId:r,subUnitId:i,type:B.REMOVE,op:o.undo,objects:o.objects}},{id:mt.id,params:{unitId:r,subUnitId:i,shapeId:a.drawingId}}]}}}_generateCopyPasteMutations(e){let{toUnitId:t,toSubUnitId:n,drawing:r,newTransforms:i,newDrawingId:a,idMap:o}=e,s={...r,unitId:t,subUnitId:n,drawingId:a,...i},{redo:c,undo:l,objects:u}=this._sheetDrawingService.getBatchAddOp([s]),d=this._shapeService.getShapeModel(r.unitId,r.subUnitId,r.drawingId);if(!d)return{redos:[],undos:[]};let f=d.getShapeType(),p=JSON.parse(JSON.stringify(d.getShapeData()));if(p.relation){var m,h;let e=(m=p.relation.from)==null?void 0:m.shapeId,t=(h=p.relation.to)==null?void 0:h.shapeId,n=!e||o.has(e),r=!t||o.has(t);n&&e&&p.relation.from?p.relation.from={...p.relation.from,shapeId:o.get(e)}:p.relation.from=void 0,r&&t&&p.relation.to?p.relation.to={...p.relation.to,shapeId:o.get(t)}:p.relation.to=void 0}return{redos:[{id:V.id,params:{unitId:t,subUnitId:n,type:B.INSERT,op:c,objects:u}},{id:pt.id,params:{unitId:t,subUnitId:n,shapeId:a,shapeType:f,shapeData:p}}],undos:[{id:V.id,params:{unitId:t,subUnitId:n,type:B.REMOVE,op:l,objects:u}},{id:mt.id,params:{unitId:t,subUnitId:n,shapeId:a}}]}}_updateTransform(e,t,n,r){let{range:i,skeleton:a}=t,{range:o,skeleton:s}=n,c={...e};if(i){let e=yn(a,i),t=yn(s,o);if(e&&t){let n=t.startX-e.startX,r=t.startY-e.startY;c.left=(c.left??0)+n,c.top=(c.top??0)+r}}else{let e=yn(s,o);if(r&&e){let t=(c.left??0)-r.left,n=(c.top??0)-r.top;c.left=e.startX+t,c.top=e.startY+n}else c.left=e==null?void 0:e.startX,c.top=e==null?void 0:e.startY}return{transform:c,axisAlignSheetTransform:An(c,s)}}};ka=X([Y(0,F(fn)),Y(1,F(Mn)),Y(2,F(Sn)),Y(3,F(O)),Y(4,F(Er)),Y(5,P),Y(6,z),Y(7,F(dn))],ka);var Aa=class extends rn{constructor(e,t){super(e,t),J(this,`_shapeId`,null),J(this,`_index`,null),J(this,`_unitId`,null),J(this,`_subUnitId`,null),J(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){Xt.drawWith(e,{radius:E.cxnPointRadius,fill:E.cxnPointFill,stroke:E.cxnPointStroke,strokeWidth:E.cxnPointStrokeWidth,evented:!0})}};let ja=class extends j{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,J(this,`_activeShapeId`,void 0),J(this,`_unitId`,void 0),J(this,`_subUnitId`,void 0),J(this,`_connectorObjects`,[]),J(this,`_baseDrawingRect`,{left:0,top:0,width:0,height:0,flipX:!1,flipY:!1}),J(this,`_activeShapeModel`,void 0),J(this,`_isConnecting`,!1),J(this,`_isDrawingShapePointDown`,!1),J(this,`_hasReset`,!1),J(this,`_cxtHandlerPointerMove`,void 0),J(this,`_cxtHandlerPointerUp`,void 0),J(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(H).getCurrentSkeleton())return;let{scene:t}=e,n=this._getDrawingRect();if(!n)return;let r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,this._activeShapeId);if(!r||!D(r.getShapeType()))return;let i=r.getConnectorLinePoints();if(i.length<2)return;let a=new T(n),o=i[0],s=i[i.length-1],c=a.localToWorld(o),l=a.localToWorld(s);this._addShapeConnectorHandlerObject(t,{...c},!0),this._addShapeConnectorHandlerObject(t,{...l},!1)}_addShapeConnectorHandlerObject(e,t,n){if(this._activeShapeId===void 0||this._unitId===void 0||this._subUnitId===void 0)return;let r=`connector-handler-${this._unitId}-${this._subUnitId}-${this._activeShapeId}-${n?`start`:`end`}`,i=e.getObjectIncludeInGroup(r);if(i){i.transformByState({left:t.x-E.cxnPointRadius,top:t.y-E.cxnPointRadius});return}let a=new Aa(r,{left:t.x-E.cxnPointRadius,top:t.y-E.cxnPointRadius,shapeId:this._activeShapeId,unitId:this._unitId,subUnitId:this._subUnitId,isStartConnectorPoint:n,width:E.cxnPointRadius*2,height:E.cxnPointRadius*2,zIndex:R+1,evented:!0});this._connectorObjects.push(a),this._attachConnectorObjectEvent(a,e,n),e.addObject(a,R+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(H).getSkeleton(t))return r;let a=i.with(Rn),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=Un(o.sheetViewStartRow,o.sheetViewStartColumn,i.scene,s);return c?{x:c.viewportScrollX,y:c.viewportScrollY}:r}_getZoomRatio(e,t){var n;let r=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);return(r==null?void 0:r.getZoomRatio())??1}_handleConnectorPointerUp(e,t,n,r,i){this._cxtHandlerPointerMove.unsubscribe(),this._cxtHandlerPointerUp.unsubscribe(),this._sheetShapeAdjustController.refreshAdjustControls();let a=this._currentConnectionTarget;this._sheetBasicShapeConnectionPointController.endConnectionDetection();let o=this._getScrollInfo(this._unitId,this._subUnitId),s=this._getZoomRatio(this._unitId,this._subUnitId),c={x:n.offsetX/s+o.x,y:n.offsetY/s+o.y},l=a?a.worldPoint:c,u=r?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo(),d=this._activeShapeModel.getShapeType();u?this._handleConnectedEndpointPointerUp(u,l,r,a,i):this._handleFreeEndpointPointerUp(t,l,r,a,i,d),this._isConnecting=!1,this._hasReset=!1,this._currentConnectionTarget=null,e.enableObjectsEvent()}_handleFreeEndpointPointerUp(e,t,n,r,i,a){let o=a===Xe.Line||a===Xe.StraightConnector1,s=n?t:e,c=n?e:t,l=this._activeShapeModel.getConnectorLinePoints(),u=this._activeShapeModel.getShapeType(),d=$e(u),f=T.getBentTypeFromPoints(l,d),p=o?T.computeStraightConnectorLayout(s,c):T.computeConnectorResizeLayout(e,t,n,f);r?this._executeConnectionCommand(p,r,n,i):this._executeResizeCommand(p,i)}_handleConnectedEndpointPointerUp(e,t,n,r,i){let a=this._getConnectPointInfo(e);if(!a)return;let o=r?r.angle:this._calculateFreeEndpointAngle(a.point,t),s;if(r){let e=this._drawingManagerService.getDrawingByParam({unitId:r.unitId,subUnitId:r.subUnitId,drawingId:r.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:r=0,height:i=0,angle:a}=e.transform;s=Qe({left:t,top:n,width:r,height:i},a||0)}else s={left:t.x,top:t.y,width:0,height:0}}else s={left:t.x,top:t.y,width:0,height:0};let c={point:t,angle:o,bounds:s},l=n?c:a,u=n?a:c,d=this._activeShapeModel.getShapeType(),f=et(l,u,d);this._activeShapeModel.removeLinePoints();let p=Ze(f,d);r?this._executeConnectedRouteConnectionCommand(p,r,e,n,i):this._executeConnectedRouteResizeCommand(p,e,n,i)}_executeConnectionCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,a={...i},o={shapeId:t.shapeId,cxnIndex:t.cxnIndex};n?a.from=o:a.to=o;let s=this._activeShapeModel.getShapeType(),c=Ze(e.worldPoints,s),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,newAdjustValues:c.adjustValues,oldAdjustValues:r,oldRelation:i,newRelation:a,newLineType:c.lineType,oldLineType:s};this._commandService.executeCommand(bt.id,l)}_executeResizeCommand(e,t){let n=this._activeShapeModel.getShapeType(),r=Ze(e.worldPoints,n),i={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:r.adjustValues,oldAdjustValues:t,newLineType:r.lineType,oldLineType:n};this._commandService.executeCommand(xt.id,i)}_executeConnectedRouteConnectionCommand(e,t,n,r,i){let a=this._activeShapeModel.getShapeData().relation,o={...a},s={shapeId:t.shapeId,cxnIndex:t.cxnIndex};r?(o.from=s,o.to=n):(o.from=n,o.to=s);let c={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:i,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:a,newRelation:o};this._commandService.executeCommand(bt.id,c)}_executeConnectedRouteResizeCommand(e,t,n,r){let i=this._activeShapeModel.getShapeData().relation,a={};n?(a.to=t,a.from=void 0):(a.from=t,a.to=void 0);let o={unitId:this._unitId,subUnitId:this._subUnitId,connectorShapeId:this._activeShapeId,width:e.worldRect.width,height:e.worldRect.height,left:e.worldRect.left,top:e.worldRect.top,flipX:e.worldRect.flipX||!1,flipY:e.worldRect.flipY||!1,oldAdjustValues:r,newAdjustValues:e.adjustValues,newLineType:e.lineType,rotation:e.rotation,oldRelation:i,newRelation:a};this._commandService.executeCommand(bt.id,o)}_attachConnectorObjectEvent(e,t,n){this.disposeWithMe(qt(e.onPointerDown$.subscribeEvent((r,i)=>{let a=e.getDrawingSearch();if(this._activeShapeModel=this._sheetsShapeService.getShapeModel(a.unitId,a.subUnitId,a.drawingId),!this._activeShapeModel)return;let o={};this._activeShapeModel.getAdjustNames().forEach(e=>{let t=this._activeShapeModel.getAdjustValueByName(e);t!==void 0&&(o[e]=t)});let s=this._getDrawingRect();if(!s)return;this._baseDrawingRect={...s};let c=new T(this._baseDrawingRect),l=W({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:this._activeShapeId}),u=t.getObjectIncludeInGroup(l);this._isConnecting=!0,t.disableObjectsEvent(),this._sheetBasicShapeConnectionPointController.startConnectionDetection(t,this._unitId,this._subUnitId,this._activeShapeId),this._currentConnectionTarget=null;let d=this._activeShapeModel.getConnectorLinePoints(),f=d[0],p=d[d.length-1],m=n?c.localToWorld(p):c.localToWorld(f);this._cxtHandlerPointerMove=t.onPointerMove$.subscribeEvent((r,i)=>{if(!this._isConnecting||!this._activeShapeModel)return;this._hasReset||=(this._sheetShapeAdjustController.clearAdjustControls(),this._activeShapeModel.clearAdjustValue(),!0);let a=this._getScrollInfo(this._unitId,this._subUnitId),o=this._getZoomRatio(this._unitId,this._subUnitId),s={x:r.offsetX/o+a.x,y:r.offsetY/o+a.y},c=this._sheetBasicShapeConnectionPointController.updateConnectionDetection(s);if(c){let{shapeId:e,unitId:n,subUnitId:r}=c;if(e&&n&&r){let i=W({unitId:n,subUnitId:r,drawingId:e});c.angle=(t.getObjectIncludeInGroup(i).angle||0)+c.angle}}this._currentConnectionTarget=c;let l=n?this._activeShapeModel.getEndConnectInfo():this._activeShapeModel.getStartConnectInfo();l?this._handleConnectedEndpointMove(l,s,n,u,e):this._handleFreeEndpointMove(s,m,n,u,e)}),this._cxtHandlerPointerUp=t.onPointerUp$.subscribeEvent((e,r)=>{this._handleConnectorPointerUp(t,m,e,n,o)}),i.stopPropagation()})))}_handleBasicShapeUpdateConnectorLineShape(e,t,n){let r=this._sheetsShapeService.getBasicShapeRelation(e,t,n);if(!r||r.length===0)return;let i=this._renderManagerService.getRenderUnitById(e);if(!i)return;let{scene:a}=i;for(let i of r){let r=i.lineShapeId,o=this._sheetsShapeService.getShapeModel(e,t,r);if(!o)continue;let s=o.getStartConnectInfo(),c=o.getEndConnectInfo(),l=(s==null?void 0:s.shapeId)===n,u=W({unitId:e,subUnitId:t,drawingId:r}),d=a.getObjectIncludeInGroup(u);if(!d)continue;let f=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});f!=null&&f.transform&&(s&&c?this._rerouteConnectorLine(e,t,r,o,s,c,d):this._moveConnectorWithShape(e,t,r,o,l?s:c,l,f,d))}}_rerouteConnectorLine(e,t,n,r,i,a,o){let s=this._unitId,c=this._subUnitId;this._unitId=e,this._subUnitId=t;let l=this._getConnectPointInfo(i),u=this._getConnectPointInfo(a);if(this._unitId=s,this._subUnitId=c,!l||!u)return;let d=r.getShapeType(),f=et(l,u,d);f&&r.updateLinePoints(f);let p=Ze(f,d);p.lineType!==d&&r.changeShapeType(p.lineType),r.clearAdjustValue();for(let[e,t]of Object.entries(p.adjustValues))r.setAdjustValueByName(e,t);r.updateContext({width:p.worldRect.width,height:p.worldRect.height}),o.transformByState({flipX:p.worldRect.flipX,flipY:p.worldRect.flipY,left:p.worldRect.left,top:p.worldRect.top,width:p.worldRect.width,height:p.worldRect.height,angle:p.rotation}),r.removeLinePoints()}_moveConnectorWithShape(e,t,n,r,i,a,o,s){let c=this._unitId,l=this._subUnitId;this._unitId=e,this._subUnitId=t;let u=this._getConnectPointInfo(i);if(this._unitId=c,this._subUnitId=l,!u)return;let{left:d=0,top:f=0,width:p=0,height:m=0,flipX:h=!1,flipY:g=!1}=o.transform,_=r.getConnectorLinePoints();if(_.length<2)return;let v=new T({left:d,top:f,width:p,height:m,flipX:h,flipY:g}),y=a?_[_.length-1]:_[0],b=v.localToWorld(y),x=T.computeConnectorResizeLayout(b,u.point,!a);s.transformByState({flipX:x.worldRect.flipX,flipY:x.worldRect.flipY,left:x.worldRect.left,top:x.worldRect.top,width:x.worldRect.width,height:x.worldRect.height,angle:x.worldRect.angle}),s.makeDirty(!0)}_clearShapeConnectorHandlerObjects(){this._connectorObjects.length!==0&&(this._connectorObjects.forEach(e=>{e.dispose()}),this._connectorObjects=[])}_registerDrawingMoveHandler(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(L.UNIVER_SHEET);this.disposeWithMe(e.pipe(tr(e=>e?e.activeSheet$.pipe(tr(t=>{if(!t)return G;let n=e.getUnitId(),r=this._renderManagerService.getRenderUnitById(n),i=r==null?void 0:r.scene;return i?$n(i):G})):G)).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 Yr&&(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===M.DRAWING_SHAPE){let e=this._sheetsShapeService.getShapeModel(t.unitId,t.subUnitId,t.drawingId);if(e&&D(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===M.DRAWING_SHAPE&&n.drawingId===this._activeShapeId?(this._clearShapeConnectorHandlerObjects(),this._addShapeConnectorHandlerObjects()):!this._activeShapeId&&r===M.DRAWING_SHAPE&&this._handleBasicShapeUpdateConnectorLineShape(n.unitId,n.subUnitId,n.drawingId)}})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{for(let t of e){let{drawingId:e}=t;if(this._activeShapeId===e){this._reset();return}}}))}_handleConnectedEndpointMove(e,t,n,r,i){var a;if(!this._activeShapeModel)return;let o=this._getConnectPointInfo(e);if(!o)return;let s=this._currentConnectionTarget?this._currentConnectionTarget.worldPoint:t,c=this._currentConnectionTarget?this._currentConnectionTarget.angle:this._calculateFreeEndpointAngle(o.point,s),l;if(this._currentConnectionTarget){let e=this._drawingManagerService.getDrawingByParam({unitId:this._currentConnectionTarget.unitId,subUnitId:this._currentConnectionTarget.subUnitId,drawingId:this._currentConnectionTarget.shapeId});if(e!=null&&e.transform){let{left:t=0,top:n=0,width:r=0,height:i=0,angle:a}=e.transform;l=Qe({left:t,top:n,width:r,height:i},a||0)}else l={left:s.x,top:s.y,width:0,height:0}}else l={left:s.x,top:s.y,width:0,height:0};let u={point:s,angle:c,bounds:l},d=n?u:o,f=n?o:u,p=this._activeShapeModel.getShapeType(),m=et(d,f,p);m&&this._activeShapeModel.updateLinePoints(m);let h=Ze(m,p);h.lineType!==p&&this._activeShapeModel.changeShapeType(h.lineType);for(let[e,t]of Object.entries(h.adjustValues))this._activeShapeModel.setAdjustValueByName(e,t);this._activeShapeModel.updateContext({width:h.worldRect.width,height:h.worldRect.height}),r.transformByState({flipX:h.worldRect.flipX,flipY:h.worldRect.flipY,left:h.worldRect.left,top:h.worldRect.top,width:h.worldRect.width,height:h.worldRect.height,angle:h.rotation}),r.makeDirty(!0);let g=((a=this._currentConnectionTarget)==null?void 0:a.worldPoint)??t;i.transformByState({left:g.x-E.cxnPointRadius,top:g.y-E.cxnPointRadius})}_handleFreeEndpointMove(e,t,n,r,i){var a,o;let s=((a=this._currentConnectionTarget)==null?void 0:a.worldPoint)??e,c=T.computeConnectorResizeLayout(t,s,n);r.transformByState({flipX:c.worldRect.flipX,flipY:c.worldRect.flipY,left:c.worldRect.left,top:c.worldRect.top,width:c.worldRect.width,height:c.worldRect.height,angle:c.worldRect.angle});let l=((o=this._currentConnectionTarget)==null?void 0:o.worldPoint)??e;i.transformByState({left:l.x-E.cxnPointRadius,top:l.y-E.cxnPointRadius})}_getConnectPointInfo(e){if(!this._unitId||!this._subUnitId)return null;let{shapeId:t,cxnIndex:n}=e,r=this._sheetsShapeService.getShapeModel(this._unitId,this._subUnitId,t);if(!r)return null;let i=this._drawingManagerService.getDrawingByParam({unitId:this._unitId,subUnitId:this._subUnitId,drawingId:t});if(!(i!=null&&i.transform))return null;let{left:a=0,top:o=0,width:s=0,height:c=0,flipX:l=!1,flipY:u=!1,angle:d}=i.transform;r.updateContext({width:s,height:c});let f=r.getConnectionSiteList().find(e=>e.index===n);if(!f)return null;let p=l?s-f.x:f.x,m=u?c-f.y:f.y;if(d!==0&&d!=null){let e=d*Math.PI/180,t=Math.cos(e),n=Math.sin(e),r=s/2,i=c/2,a=p-r,o=m-i;p=r+a*t-o*n,m=i+a*n+o*t}p+=a,m+=o;let h=f.ang/6e4;l&&(h=180-h),u&&(h=-h),h+=d||0,h=(h%360+360)%360;let g=Qe({left:a,top:o,width:s,height:c},d||0);return{point:{x:p,y:m},angle:h,bounds:g}}_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()}};ja=X([Y(1,N),Y(2,z),Y(3,U),Y(4,P),Y(5,F(O)),Y(6,F(Zr)),Y(7,F(Oa))],ja);let Ma=class extends j{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._drawingManagerService=t,this._shapeRenderController=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,t,n)=>{var r;let{unitId:i,subUnitId:a,scene:o,resourceCollector:s}=t,c=(r=this._drawingManagerService.getDrawingDataForUnit(i))==null?void 0:r[a];return c==null||c.order.forEach(e=>{let t=c.data[e];t.drawingType===M.DRAWING_SHAPE&&!t.hidden&&this._shapeRenderController.renderDrawingShape(t,o,{resourceCollector:s})}),n(e)}}))}};Ma=X([Y(0,F(Ln)),Y(1,U),Y(2,F(Z))],Ma);let Na=class extends j{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([q.id,vt.id,gt.id,_t.id,xt.id]);this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{let n,r;if(t.id===ft.id||t.id===ht.id||t.id===bt.id){let e=t.params;n=e.unitId,r=e.subUnitId}else if(e.has(t.id)){let e=xn(this._univerInstanceService,t.params);if((e==null?void 0:e.worksheet.getConfig().type)!==I.CHART)return;n=e.unitId,r=e.subUnitId}n&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[gn],worksheetTypes:[vn]},n,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-shape-ui.permission.editErr`)))}))}};Na=X([Y(0,F(N)),Y(1,F(P)),Y(2,F(Rt)),Y(3,F(dn))],Na);let Pa=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=W(e),a=r.getObjectIncludeInGroup(i);a==null||a.setFillImage(t)}};Pa=X([Y(0,z)],Pa);let Fa=class extends zt{constructor(e=ma,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=Gt({},ma,this._config);this._configService.setConfig(pa,a),this._initCommands()}onStarting(){this._injector.add([va]),this._injector.get(va),Kt(this._injector,[[Sa],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na]])}onReady(){Kt(this._injector,[[Oa],[Zr],[ka]]),Jt(this._injector,[[ka],[Zr]]),[[Oa],[ha],[ja],[ba]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,e))})}onRendered(){Jt(this._injector,[[Sa],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na]])}onSteady(){this._injector.get(Sa).initShapePopupMenu()}_initCommands(){[$r,q,Qr,fa].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};J(Fa,`type`,L.UNIVER_SHEET),J(Fa,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),J(Fa,`packageName`,ua),J(Fa,`version`,da),Fa=X([Tt(gr,yr,Gn,on,mn,wr,Dn,nt,Dr,yt,zn,ee,Be),Y(1,F(Lt)),Y(2,N),Y(3,jt),Y(4,z)],Fa);const Ia={type:A.OPERATION,id:`sheet.operation.close-sheet-shape-format-panel`,handler(){return!0}};function La(){let e=w(U),t=He(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return t.length===0?null:/* @__PURE__ */ K(`div`,{children:/* @__PURE__ */ hr(`div`,{className:`univer-box-border univer-px-4 univer-text-sm`,children:[/* @__PURE__ */ K(nr,{drawings:t,hasCropper:!1}),/* @__PURE__ */ K(Tr,{drawings:t})]})})}function Ra(e){let{unitId:t,subUnitId:n,shapeId:r}=e,i=w(N),o=w(Pa);return/* @__PURE__ */ K(a,{...e,positionEditor:/* @__PURE__ */ K(La,{}),onUpdateShapeData:(e,a)=>{Ur(i,t,n,r,e,a)},onUpdateLineShapeData:(e,a)=>{Wr(i,t,n,r,e,a)},onUpdateShapeFillImage:e=>{o.updateShapeFillImage({unitId:t,subUnitId:n,drawingId:r},e)}})}function za(e){let t=w(s),n=He(()=>t.visible$,t.getVisible(),!1,[t]),r=e.popup.extraProps;return!r||!n?null:/* @__PURE__ */ K(Ba,{...r,canvasElement:e.popup.canvasElement})}function Ba(e){let t=w(N),n=w(O),{unitId:r,subUnitId:i,drawingId:a,drawingType:s,shapeType:c}=e,[l,u]=Vr(e.shapeData),d=zr(()=>ue(l),[l]),f=zr(()=>le(l),[l]);Rr(()=>{let e=t.onCommandExecuted(e=>{if(e.id!==k.id)return;let t=n.getShapeDataById(r,i,a);t&&u(t)});return()=>e.dispose()},[t,a,n,i,r]);let p=e=>{u(t=>({...t,...e}))},m=e=>{let n=ie(l,e);Ur(t,r,i,a,{oldShapeData:{shapeText:l.shapeText}},n),p(n)},h=Ee({hostType:L.UNIVER_SHEET,unitId:r,subUnitId:i,shapeId:a,shapeData:l,onUpdateBinding:e=>{let n={formulaBinding:e};Ur(t,r,i,a,{oldShapeData:{formulaBinding:l.formulaBinding}},n),p(n)}});return/* @__PURE__ */ hr(mr,{children:[/* @__PURE__ */ K(o,{canvasElement:e.canvasElement,shapeData:l,shapeType:c,textStyle:{ff:E.shapeText.fontFamily,fs:E.shapeText.fontSize,cl:{rgb:E.shapeText.color},...d},textModel:f?{ha:f.ha??At.LEFT,va:f.va??Ht.TOP}:null,enableShapeFillReset:!0,enableShapeStrokeReset:!0,enableTextBackgroundReset:!0,defaultFillColor:E.fill,defaultGradientEndColor:E.gradientEndColor,defaultStrokeColor:E.stroke,extensionGroups:h.extensionGroups,floatingObjectToolbarPosition:Ae.SHEET,onUpdateShapeData:(e,n)=>{Ur(t,r,i,a,e,n),n&&p(n)},onUpdateText:m,onOpenPanel:()=>{t.executeCommand(si.id,{unitId:r,subUnitId:i,drawingId:a})},onDelete:()=>{t.executeCommand(Cn.id,{unitId:r,drawings:[{unitId:r,subUnitId:i,drawingId:a,drawingType:s}]})}}),h.panel]})}function Va(e){return!!e&&`axisAlignSheetTransform`in e}const Ha=Lr(()=>{let e=w($),t=w(O),n=w(U),r=w(N),i=w(ze),a=w(z),o=zr(()=>({getShapeModel:(e,n,r)=>t.getShapeModel(e,n,r),getShapeData:(e,n,r)=>t.getShapeDataById(e,n,r),getDrawingTransform:(e,t,r)=>{let i=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:r});return i==null?void 0:i.transform},updateShapeText:({unitId:e,subUnitId:t,shapeId:o,shapeText:s,oldShapeText:c,hostSize:l})=>{i.run(e,()=>{var i;let u=r.syncExecuteCommand(q.id,{unitId:e,subUnitId:t,shapeId:o,shapeData:{shapeText:s},oldShapeJSON:{oldShapeData:{shapeText:c}}});if(!u||!l)return u;let d=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:o}),f=d==null?void 0:d.transform;if(!Va(d)||!f)return!1;let p={...f,width:l.width,height:l.height},m=(i=a.getRenderUnitById(e))==null||(i=i.with(H).getSkeletonParam(t))==null?void 0:i.skeleton;return r.syncExecuteCommand(Tn.id,{unitId:e,drawings:[{...d,transform:p,axisAlignSheetTransform:m?An(p,m)??d.axisAlignSheetTransform:d.axisAlignSheetTransform}]})})},updateHostSize:({unitId:e,subUnitId:t,shapeId:i,width:o,height:s})=>{var c;let l=n.getDrawingByParam({unitId:e,subUnitId:t,drawingId:i}),u=l==null?void 0:l.transform;if(!Va(l)||!u)return;let d={...u,width:o,height:s},f=(c=a.getRenderUnitById(e))==null||(c=c.with(H).getSkeletonParam(t))==null?void 0:c.skeleton,p=f?An(d,f)??l.axisAlignSheetTransform:l.axisAlignSheetTransform;r.executeCommand(Tn.id,{unitId:e,drawings:[{...l,transform:d,axisAlignSheetTransform:p}]})},allowHostSizeShrink:({unitId:e,subUnitId:n,shapeId:r})=>we(t.getShapeDataById(e,n,r)),deferHostSizeUpdateDuringEditing:()=>!0}),[r,n,a,t,i]),s=zr(()=>({viewportKeys:{main:nn.VIEW_MAIN,leftTop:nn.VIEW_MAIN_LEFT_TOP,top:nn.VIEW_MAIN_TOP,left:nn.VIEW_MAIN_LEFT},getSkeleton:(e,t)=>{var n;return((n=e.with(H).getSkeletonParam(t.subUnitId))==null?void 0:n.skeleton)??null}}),[]);return/* @__PURE__ */ K(h,{adapter:o,editingService:e,editorUnitId:ii,positionOptions:s})});let Ua=class extends j{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:Pr})),this._iconManager.has(`FlipHorizontalIcon`)||this.disposeWithMe(this._iconManager.register({FlipHorizontalIcon:Ar})),this._iconManager.has(`FlipVerticalIcon`)||this.disposeWithMe(this._iconManager.register({FlipVerticalIcon:jr})),this._iconManager.has(`BottomIcon`)||this.disposeWithMe(this._iconManager.register({BottomIcon:kr})),this._iconManager.has(`MoveDownIcon`)||this.disposeWithMe(this._iconManager.register({MoveDownIcon:Mr})),this._iconManager.has(`MoveUpIcon`)||this.disposeWithMe(this._iconManager.register({MoveUpIcon:Nr})),this._iconManager.has(`ShapeFormatSettingIcon`)||this.disposeWithMe(this._iconManager.register({ShapeFormatSettingIcon:Fr})),this._iconManager.has(`TopmostIcon`)||this.disposeWithMe(this._iconManager.register({TopmostIcon:Ir}))}_registerComponents(){this.disposeWithMe(this._componentManager.register(ei,Ra)),this.disposeWithMe(this._componentManager.register(ti,ga)),this.disposeWithMe(this._componentManager.register(di,_i)),this.disposeWithMe(this._componentManager.register(fi,mi)),this._componentManager.hasDefault(ar)||this.disposeWithMe(this._componentManager.register(ar,gi)),this.disposeWithMe(this._componentManager.register(ni,za)),this.disposeWithMe(this._componentManager.register(Ai,Pi)),this.disposeWithMe(this._componentManager.register(ki,Fi)),this.disposeWithMe(this._componentManager.register(ji,Ii)),this.disposeWithMe(this._componentManager.register(Mi,Li)),this.disposeWithMe(this._componentManager.register(ai,_)),this.disposeWithMe(this._componentManager.register(`SheetShapeTextEditorContainer`,Ha))}};Ua=X([Y(0,F(De)),Y(1,F(Ie))],Ua);let Wa=class extends j{constructor(e,t,n,r,i,a,o,s,c){super();let l=e=>{var t,n;return(((t=s.getPermissionPoint(new gn(e.unitId).id))==null?void 0:t.value)??!0)&&(((n=s.getPermissionPoint(new vn(e.unitId,e.subUnitId).id))==null?void 0:n.value)??!0)},u=e=>e.shapeId&&l(e)?n.getShapeDataById(e.unitId,e.subUnitId,e.shapeId)??null:null,d=()=>{let t=i.getFocusDrawings(),n=t.length===1?t[0]:null;return(n==null?void 0:n.drawingType)===M.DRAWING_SHAPE&&n.unitId===e.unitId?{unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.drawingId}:null};this.disposeWithMe(he(e,t,{changes$:Qn(i.focus$,r.editingParams$,s.permissionPointUpdate$),isActive:()=>{var t;return((t=a.getFocusedUnit())==null?void 0:t.getUnitId())===e.unitId&&!o.getContextValue(kt)&&i.getFocusDrawings().some(t=>t.unitId===e.unitId)},getSelectedTarget:d,getSource:()=>{let e=d();return e?u(e):null},getTarget:t=>{let n=e.scene.pick(new sn(t.offsetX,t.offsetY));if(!(n instanceof Yr))return null;let r={unitId:e.unitId,subUnitId:n.subUnitId,shapeId:n.shapeId};return l(r)?r:null},getShape:u,update:(e,t,n)=>c.executeCommand(q.id,{...e,shapeData:n,replaceShapeData:!0,oldShapeJSON:{oldShapeData:t}})}))}};Wa=X([Y(1,F(je)),Y(2,F(O)),Y(3,F($)),Y(4,U),Y(5,P),Y(6,Mt),Y(7,Pt),Y(8,N)],Wa);const Ga=`sheets-shape-contextual-ribbon`;let Ka=class extends j{constructor(e,t,n,r,i,a){super(),this._menuManagerService=e,this._ribbonService=t,this._drawingManagerService=n,this._univerInstanceService=r,this._renderManagerService=i,this._shapeFloatingToolbarService=a,J(this,`_visible`,!1),this._menuManagerService.mergeMenu(sa),this.disposeWithMe(qt(this._drawingManagerService.focus$.subscribe(()=>this._update()))),this._update()}dispose(){this._shapeFloatingToolbarService.setFallbackVisible(!1,Ga),this._hide(),super.dispose()}_update(){var e;let t=this._drawingManagerService.getFocusDrawings(),n=t.length===1?t[0]:void 0;if((n==null?void 0:n.drawingType)!==M.DRAWING_SHAPE||this._univerInstanceService.getUnitType(n.unitId)!==L.UNIVER_SHEET){this._shapeFloatingToolbarService.setFallbackVisible(!1,Ga),this._hide();return}let r=(e=this._renderManagerService.getRenderUnitById(n.unitId))==null?void 0:e.engine.getCanvasElement(),i=_e(r)===`isolated`;this._shapeFloatingToolbarService.setFallbackVisible(i,Ga),i?this._hide():this._visible||(this._visible=!0,this._ribbonService.showContextualTab(ri,{activate:!0}))}_hide(){this._visible&&(this._visible=!1,this._ribbonService.hideContextualTab(ri),this._ribbonService.setCollapsedIds([]))}};Ka=X([Y(0,Ne),Y(1,Pe),Y(2,U),Y(3,P),Y(4,z),Y(5,F(s))],Ka);let qa=class extends g{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l,{componentKey:ai,editorUnitId:ii})}};qa=X([Y(1,F(vr)),Y(2,F(br)),Y(3,F(Cr)),Y(4,N),Y(5,F(xr)),Y(6,F(b)),Y(7,F(_r)),Y(8,F(Sr)),Y(9,F($))],qa);let Ja=class extends v{constructor(e,t,n,r,i){super(e,t,{editing$:n.editingParams$,resolve:n=>{var a,o,s;let c=new sn(n.offsetX,n.offsetY),l=((a=e.scene.getActiveViewportByCoord(c))==null?void 0:a.transformVector2SceneCoord(c))??c,u=Ce(e.scene.pick(c)??null,l);if(!(u instanceof Yr))return null;let d=u.resolveHyperLinkAt(l);if(!d)return null;let f=u,p={componentKey:y.componentKey,direction:`top-center`,offset:[0,10],onClickOutside:()=>t.hideInfoPopup()};return{object:u,info:{...d,unitId:u.unitId,subUnitId:u.subUnitId,shapeKey:u.oKey,readonly:!0,copyable:((o=i.getPermissionPoint(new hn(u.unitId).id))==null?void 0:o.value)!==!1&&((s=i.getPermissionPoint(new _n(u.unitId,u.subUnitId).id))==null?void 0:s.value)!==!1},attachPopup:()=>r.attachPopupToObject(f,p)}}}),this.disposeWithMe(e.unit.activeSheet$.subscribe(()=>this.clear()))}};Ja=X([Y(1,F(b)),Y(2,F($)),Y(3,F(Fn)),Y(4,Pt)],Ja);let Ya=class extends j{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._sidebarService=t,this._menuManagerService=n,this._sheetsShapeService=r,this._localeService=i,this._commandService=a,this._drawingManagerService=o,this._sheetCanvasPopManagerService=s,this._contextService=c,this._renderManagerService=l,this._shapeTextEditingService=u,J(this,`_sidebarDisposable`,null),J(this,`_activeShapeInfo`,null),J(this,`_isOpenedShapeEditPanel`,!1),J(this,`_shapeEditPanelVersion`,0),J(this,`_shapePopupMenuDisposable`,null),J(this,`_disposePopups`,[]),this._initMenu(),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(L.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(la)}initShapePopupMenu(){this._shapePopupMenuDisposable||=this.disposeWithMe(re(this._renderManagerService,L.UNIVER_SHEET,e=>this._popupMenuListener(e)))}_getShapeInfo(e,t,n){let r=this._sheetsShapeService.getShapeTypeById(e,t,n),i=this._sheetsShapeService.getShapeDataById(e,t,n);return r!==void 0&&i!==void 0?{shapeData:i,shapeId:n,shapeType:r,unitId:e,subUnitId:t,version:this._shapeEditPanelVersion,disableShapeOption:!1}:null}_clearPopups(){this._disposePopups.forEach(e=>e.dispose()),this._disposePopups.length=0}_popupMenuListener(e){let t=new Et;return t.add(e.createControl$.subscribe(()=>{let t=e.getSelectedObjectMap();if(this._clearPopups(),this._isOpenedShapeEditPanel||t.size>1)return;let n=t.values().next().value;if(!n)return;let r=this._drawingManagerService.getDrawingOKey(n.oKey);if(!r||r.drawingType!==M.DRAWING_SHAPE)return;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c}=r,l=this._getShapeInfo(a,o,s);if(!l)return;this._contextService.setContextValue(Ot,!0);let u=this._renderManagerService.getRenderUnitById(a),d=((u==null?void 0:u.isMainScene)===!1?u.with(Fn):this._sheetCanvasPopManagerService).attachPopupToObject(n,{componentKey:ni,direction:`vertical-center`,offset:[0,i],extraProps:{unitId:a,subUnitId:o,drawingId:s,drawingType:c,shapeType:l.shapeType,shapeData:l.shapeData}});this._disposePopups.push(this.disposeWithMe(d)),this._drawingManagerService.getFocusDrawings().find(e=>e.unitId===a&&e.subUnitId===o&&e.drawingId===s)||this._drawingManagerService.focusDrawing([{unitId:a,subUnitId:o,drawingId:s}])})),t.add(e.clearControl$.subscribe(()=>{this._clearPopups(),this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)})),t.add(e.changing$.subscribe(()=>{this._clearPopups()})),t.add(e.changeStart$.subscribe(()=>{this._clearPopups()})),qt(()=>{t.dispose(),this._clearPopups()})}_registerOperations(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===si.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===Ia.id&&(this._activeShapeInfo=null,this._closeShapeEditPanel()),e.id===k.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===M.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===M.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:ei,header:{title:this._localeService.t(`sheets-shape-ui.formatShape`)},width:388,children:{label:ei,...this._activeShapeInfo},onClose:()=>{this._drawingManagerService.focusDrawing(null),this._contextService.setContextValue(Ot,!1),this._sidebarDisposable=null}}),this._isOpenedShapeEditPanel=!0)}_closeShapeEditPanel(){this._isOpenedShapeEditPanel=!1,this._sidebarService.close(ei),this._sidebarDisposable=null,this._contextService.setContextValue(Ot,!1),this._drawingManagerService.focusDrawing(null)}};Ya=X([Y(0,P),Y(1,F(Fe)),Y(2,Ne),Y(3,F(O)),Y(4,F(Rt)),Y(5,N),Y(6,U),Y(7,F(Fn)),Y(8,Mt),Y(9,z),Y(10,F($))],Ya);let Xa=class extends zt{constructor(e=ma,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r,this._renderManagerService=i;let{...a}=Gt({},ma,this._config);this._configService.setConfig(pa,a),this._initCommands()}onRendered(){this._renderManagerService.registerRenderModule(L.UNIVER_DOC,[qa]),Jt(this._injector,[[Ya],[Ta],[Z],[Ma]])}onSteady(){this._injector.get(Ya).initShapePopupMenu()}onReady(){[[Oa],[Zr],[ka]].forEach(e=>this._injector.add(e)),Jt(this._injector,[[ka],[Zr]]),this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[Oa]),this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[ha]),this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[ja]),this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[ya]),this.disposeWithMe(this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[Ja])),this.disposeWithMe(this._renderManagerService.registerRenderModule(L.UNIVER_SHEET,[Wa]))}onStarting(){this._injector.add([Ua]),this._injector.get(Ua);let e=this._injector;[[Ya],[Ta],[Z],[Ma],[Pa],[$],[wa],[Q],[Na],[Ka]].forEach(t=>e.add(t)),Jt(this._injector,[[Ya],[Ta],[Z],[Pa],[$],[wa],[Q],[Na],[Ka]])}_initCommands(){[$r,q,Ia,si,oi,Qr,li,ui].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};J(Xa,`type`,L.UNIVER_SHEET),J(Xa,`pluginName`,`SHEET_SHAPE_UI_PLUGIN`),J(Xa,`packageName`,ua),J(Xa,`version`,da),Xa=X([Tt(gr,yr,Gn,lr,on,mn,wr,Dn,nt,Or,yt,Bn,te),Y(1,F(Lt)),Y(2,N),Y(3,jt),Y(4,z)],Xa);export{sa as SheetsShapeUIContextualRibbonSchema,la as SheetsShapeUIMenuSchema,Fa as UniverSheetsShapeMobileUIPlugin,Xa as UniverSheetsShapeUIPlugin};
|