@univerjs-pro/boards-mind-ui 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/boards"),require("@univerjs-pro/boards-mind"),require("@univerjs-pro/boards-ui"),require("@univerjs-pro/license"),require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@univerjs-pro/shape-editor-ui"),require("@univerjs-pro/engine-shape"),require("@univerjs/design"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/boards`,`@univerjs-pro/boards-mind`,`@univerjs-pro/boards-ui`,`@univerjs-pro/license`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`,`@univerjs/ui`,`@univerjs-pro/shape-editor-ui`,`@univerjs-pro/engine-shape`,`@univerjs/design`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProBoardsMindUi={},e.UniverProBoards,e.UniverProBoardsMind,e.UniverProBoardsUi,e.UniverProLicense,e.UniverCore,e.UniverEngineRender,e.rxjs,e.UniverUi,e.UniverProShapeEditorUi,e.UniverProEngineShape,e.UniverDesign,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var m=`@univerjs-pro/boards-mind-ui`,h=`1.5.2`;let g=`boards-mind-ui.config`,_={};function v(e){"@babel/helpers - typeof";return v=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},v(e)}function y(e,t){if(v(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(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function b(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function x(e,t,n){return(t=b(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e,t){return function(n,r){t(n,r,e)}}function C(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 w=class extends a.RxDisposable{constructor(e,t,n){super(),this._renderContext=e,this._boardElementService=t,this._commandService=n,x(this,`_nodeSizeByKey`,/* @__PURE__ */ new Map),x(this,`_queuedLayouts`,/* @__PURE__ */ new Map),x(this,`_layoutFlushScheduled`,!1),this._init()}_init(){this._seedExistingNodeSizes(),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementAdd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e.forEach(e=>{let t=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.elementId);this._rememberNodeSize(e,t)})}))),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementUpdate$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e.forEach(e=>this._handleElementUpdate(e))})))}_seedExistingNodeSizes(){let e=this._renderContext.unitId,t=this._boardElementService.getElementDataForUnit(e);Object.entries(t).forEach(([t,n])=>{Object.values(n.data).forEach(n=>{this._rememberNodeSize({unitId:e,subUnitId:t,elementId:n.elementId},n)})})}_handleElementUpdate(e){if(e.unitId!==this._renderContext.unitId)return;let t=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.elementId),r=(0,n.getMindMapNodeMeta)(t==null?void 0:t.element),i=this._resolveNodeSize(t);if(!r||!i){this._nodeSizeByKey.delete(this._getElementKey(e));return}let a=this._getElementKey(e),o=this._nodeSizeByKey.get(a);this._nodeSizeByKey.set(a,i),o&&o.width===i.width&&o.height===i.height||this._queueLayout({unitId:e.unitId,subUnitId:e.subUnitId,scopeId:r.structureScopeId})}_rememberNodeSize(e,t){if(e.unitId!==this._renderContext.unitId)return;let r=(0,n.getMindMapNodeMeta)(t==null?void 0:t.element),i=this._resolveNodeSize(t);r&&i&&this._nodeSizeByKey.set(this._getElementKey(e),i)}_resolveNodeSize(e){let t=(e==null?void 0:e.transform)??(e==null?void 0:e.element.transform),n=t==null?void 0:t.width,r=t==null?void 0:t.height;return!Number.isFinite(n)||!Number.isFinite(r)?null:{width:n,height:r}}_queueLayout(e){this._queuedLayouts.set(`${e.unitId}:${e.subUnitId}:${e.scopeId}`,e),this._layoutFlushScheduled||(this._layoutFlushScheduled=!0,Promise.resolve().then(()=>{this._layoutFlushScheduled=!1;let e=Array.from(this._queuedLayouts.values());this._queuedLayouts.clear(),e.forEach(e=>{this._executeRootAnchoredLayout(e)})}))}_executeRootAnchoredLayout(e){var t;let r=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.scopeId),i=(t=(0,n.getMindMapContainerMeta)(r==null?void 0:r.element))==null?void 0:t.rootNodeId;this._commandService.executeCommand(n.LayoutMindMapOperation.id,{...e,skipUndo:!0,...i?{anchorNodeId:i}:null})}_getElementKey(e){return`${e.unitId}:${e.subUnitId}:${e.elementId}`}};w=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,a.ICommandService)],w);let T={primaryColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_STROKE_COLOR,surfaceColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_BACKGROUND_COLOR,textColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_COLOR,fontFamily:a.DEFAULT_STYLES.ff};function E(e,t){let n=Math.min(1,Math.max(0,Number.isFinite(t)?t:1)),r=e.trim(),i=/^#([0-9a-fA-F]{6})$/.exec(r);if(!i)return e;let a=i[1];return`rgba(${Number.parseInt(a.slice(0,2),16)}, ${Number.parseInt(a.slice(2,4),16)}, ${Number.parseInt(a.slice(4,6),16)}, ${n})`}let D={primaryColor:T.primaryColor,ghostFillColor:E(T.surfaceColor,.72),ghostTextColor:E(T.textColor,.62),rootTextColor:E(T.surfaceColor,.86),sourceHighlightFillColor:E(T.primaryColor,.12),sourceHighlightStrokeColor:E(T.primaryColor,.9),objectAlpha:.72,dragObjectAlpha:.78,connectorAlpha:.64,lineWidthScreen:2,fallbackNodeWidth:n.MIND_MAP_DEFAULT_NODE_SIZE.nodeWidth,fallbackNodeHeight:n.MIND_MAP_DEFAULT_NODE_SIZE.nodeHeight,branchGap:n.MIND_MAP_DEFAULT_LAYOUT.branchGap,sourceHaloScreen:4,ghostRadius:8,rootRadius:10,fontFamily:T.fontFamily,ghostFontWeight:500,rootFontWeight:600,rootFontSize:18,textPaddingScreen:12,dirtyPaddingScreen:24,sourceDashScreen:[6,4]};function O(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.quadraticCurveTo(t+r,n,t+r,n+o),e.lineTo(t+r,n+i-o),e.quadraticCurveTo(t+r,n+i,t+r-o,n+i),e.lineTo(t+o,n+i),e.quadraticCurveTo(t,n+i,t,n+i-o),e.lineTo(t,n+o),e.quadraticCurveTo(t,n,t+o,n),e.closePath()}function k(e,t,n){return`${e} ${t/n}px ${D.fontFamily}`}let A=`board-mind-map-drag-preview-object`,j=r.BOARD_RENDER_LAYER_INDEX.preview;function M(e,t){return Number.isFinite(e)?e:t}function N(){return D.fallbackNodeWidth}function P(){return D.fallbackNodeHeight}function F(e){return e===1?`left`:e===3?`right`:`center`}function ee(e,t,n,r){return n===1?e+r:n===3?e+t-r:e+t/2}var te=class extends o.BaseObject{constructor(e=A,t){super(e),x(this,`_state`,{ghostBounds:null,parentBounds:null,side:`right`,zoomRatio:1}),this.evented=!1,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientPreviewForeground,this.updateState(t)}updateState(e){if(this._state={...this._state,...e},this._state.ghostBounds){let e=this._resolveDirtyBounds();this.transformByState(e),this.show()}else this.hide();let t=this;typeof t.makeDirtyNoDebounce==`function`?t.makeDirtyNoDebounce(!0):this.makeDirty(!0)}isHit(e){return!1}render(e,t){let r=this._state.ghostBounds;if(!r||!this.visible)return this.makeDirty(!1),this;let i=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,a=M(r.left,0),o=M(r.top,0),s=Math.max(1,M(r.width,N())),c=Math.max(1,M(r.height,P()));if(e.save(),e.globalAlpha=D.dragObjectAlpha,e.lineWidth=D.lineWidthScreen/i,e.strokeStyle=D.primaryColor,e.fillStyle=D.ghostFillColor,this._drawConnectorPreview(e,{left:a,top:o,width:s,height:c},i),this._drawSourceHighlight(e,i),this._state.renderGhostNode===!1)return e.restore(),this.makeDirty(!1),this;O(e,a,o,s,c,D.ghostRadius),e.fill(),e.stroke();let l=this._state.textStyle,u=Number.isFinite(l==null?void 0:l.fontSize)&&((l==null?void 0:l.fontSize)??0)>0?l.fontSize:16,d=D.textPaddingScreen/i;return e.fillStyle=(l==null?void 0:l.color)??D.ghostTextColor,e.font=k(D.ghostFontWeight,u,i),e.textAlign=F(l==null?void 0:l.horizontalAlign),e.textBaseline=`middle`,e.fillText((l==null?void 0:l.text)||n.MIND_MAP_DEFAULT_NODE_TEXT,ee(a,s,l==null?void 0:l.horizontalAlign,d),o+c/2,Math.max(1,s-d*2)),e.restore(),this.makeDirty(!1),this}_resolveDirtyBounds(){let e=this._state.ghostBounds,t=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,n=D.dirtyPaddingScreen/t;if(!e)return{left:0,top:0,width:1,height:1};let r=M(e.left,0),i=M(e.top,0),a=Math.max(1,M(e.width,N())),o=Math.max(1,M(e.height,P())),s=this._state.sourceBounds,c=this._state.parentBounds,l=M(s==null?void 0:s.left,r),u=M(s==null?void 0:s.top,i),d=Math.max(1,M(s==null?void 0:s.width,a)),f=Math.max(1,M(s==null?void 0:s.height,o));if(!c){let e=Math.min(r,l)-n,t=Math.min(i,u)-n,s=Math.max(r+a,l+d)+n,c=Math.max(i+o,u+f)+n;return{left:e,top:t,width:s-e,height:c-t}}let p=M(c.left,r),m=M(c.top,i),h=Math.max(1,M(c.width,N())),g=Math.max(1,M(c.height,P())),_=Math.min(r,p,l)-n,v=Math.min(i,m,u)-n,y=Math.max(r+a,p+h,l+d)+n,b=Math.max(i+o,m+g,u+f)+n;return{left:_,top:v,width:y-_,height:b-v}}_drawSourceHighlight(e,t){var n;let r=this._state.sourceBounds;if(!r)return;let i=D.sourceHaloScreen/t,a=M(r.left,0)-i,o=M(r.top,0)-i,s=Math.max(1,M(r.width,N()))+i*2,c=Math.max(1,M(r.height,P()))+i*2;e.save(),e.globalAlpha=1,e.lineWidth=D.lineWidthScreen/t,e.strokeStyle=D.sourceHighlightStrokeColor,e.fillStyle=D.sourceHighlightFillColor,(n=e.setLineDash)==null||n.call(e,D.sourceDashScreen.map(e=>e/t)),O(e,a,o,s,c,D.rootRadius),e.fill(),e.stroke(),e.restore()}_drawConnectorPreview(e,t,n){let r=this._state.parentBounds;if(!r)return;let i=M(r.left,0),a=M(r.top,0),o=Math.max(1,M(r.width,N())),s=Math.max(1,M(r.height,P())),c=D.branchGap,l=this._state.side??`right`;if(e.save(),e.globalAlpha=D.connectorAlpha,e.strokeStyle=D.primaryColor,e.lineWidth=D.lineWidthScreen/n,e.lineCap=`round`,e.lineJoin=`round`,e.beginPath(),l===`top`||l===`bottom`){let n=i+o/2,r=t.left+t.width/2,u=l===`bottom`?a+s:a,d=l===`bottom`?t.top:t.top+t.height,f=l===`bottom`?Math.min(u+c,(u+d)/2):Math.max(u-c,(u+d)/2);e.moveTo(n,u),e.lineTo(n,f),e.lineTo(r,f),e.lineTo(r,d)}else{let n=a+s/2,r=t.top+t.height/2,u=l===`right`?i+o:i,d=l===`right`?t.left:t.left+t.width,f=l===`right`?Math.min(u+c,(u+d)/2):Math.max(u-c,(u+d)/2);e.moveTo(u,n),e.lineTo(f,n),e.lineTo(f,r),e.lineTo(d,r)}e.stroke(),e.restore()}};function I(e,t){return(t==null?void 0:t[e.elementId])??e.element.transform}function ne(e,t){let n=I(e,t);return{x:(n.left??0)+(n.width??0)/2,y:(n.top??0)+(n.height??0)/2}}function re(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function ie(e,t){let n=e.left??0,r=e.top??0,i=n+(e.width??0),a=r+(e.height??0),o=t.left??0,s=t.top??0,c=o+(t.width??0),l=s+(t.height??0),u=Math.max(o-i,n-c,0),d=Math.max(s-a,r-l,0);return Math.hypot(u,d)}function ae(e,t,r){var i;let a=(0,n.getMindMapNodeMeta)((i=e[t])==null?void 0:i.element);for(;a!=null&&a.parentNodeId;){var o;if(a.parentNodeId===r)return!0;a=(0,n.getMindMapNodeMeta)((o=e[a.parentNodeId])==null?void 0:o.element)}return!1}function oe(e,t,n){let r=I(e,n),i=r.top??0,a=r.height??0;return a<=0?null:t.y<=i+a/3?`before`:t.y>=i+a*2/3?`after`:null}function se(e,t){let n=t==null?void 0:t[e];return Number.isFinite(n==null?void 0:n.left)&&Number.isFinite(n==null?void 0:n.top)?{kind:`detach`,left:n.left,top:n.top}:{kind:`detach`}}function L(e,t,r){let i=e[t],a=(0,n.getMindMapNodeMeta)(i==null?void 0:i.element);if(!i||!a||!a.parentNodeId&&!(r!=null&&r.allowRootReparent))return{kind:`none`};let o=r==null?void 0:r.boundsByElementId,s=I(i,o),c=ne(i,o),l=Object.values(e).map(i=>{let c=(0,n.getMindMapNodeMeta)(i.element);return!c||i.elementId===t||i.elementId===a.parentNodeId||r!=null&&r.allowRootReparent&&!a.parentNodeId&&c.structureScopeId===a.structureScopeId||ae(e,i.elementId,t)?null:{item:i,snapDistance:ie(s,I(i,o)),center:ne(i,o)}}).filter(e=>!!e).sort((e,t)=>e.snapDistance-t.snapDistance||re(c,e.center)-re(c,t.center))[0];if(l&&l.snapDistance<=100){let e=(0,n.getMindMapNodeMeta)(l.item.element),t=e!=null&&e.parentNodeId?oe(l.item,c,o):null;return e!=null&&e.parentNodeId&&t?{kind:`reparent`,newParentNodeId:e.parentNodeId,side:e.side??`right`,referenceNodeId:l.item.elementId,placement:t}:{kind:`reparent`,newParentNodeId:l.item.elementId,side:c.x<l.center.x?`left`:`right`}}if(r!=null&&r.detachWhenNoSnap)return se(t,o);if(!a.parentNodeId)return{kind:`none`};let u=e[a.parentNodeId];return u&&re(c,ne(u,o))>560?se(t,o):{kind:`none`}}function ce(e,t){var r,i;return e.elementId===t||((r=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:r.structureScopeId)===t||((i=(0,n.getMindMapConnectorMeta)(e.element))==null?void 0:i.structureScopeId)===t}function le(e,t,n,r){let i=e[t];if(!i)return e;let a=i.transform??i.element.transform??{};return{...e,[t]:{...i,transform:{...a,left:(a.left??0)+n,top:(a.top??0)+r},element:{...i.element,transform:{...i.element.transform,left:(i.element.transform.left??0)+n,top:(i.element.transform.top??0)+r}}}}}function ue(e){if(!Number.isFinite(e.liveRootBounds.left)||!Number.isFinite(e.liveRootBounds.top)||!Number.isFinite(e.rootStartBounds.left)||!Number.isFinite(e.rootStartBounds.top))return null;let n=e.liveRootBounds.left-e.rootStartBounds.left,r=e.liveRootBounds.top-e.rootStartBounds.top,i=le(e.elementData,e.scopeId,n,r),a=[];return Object.values(i).forEach(o=>{if(o.elementId===e.rootNodeId||o.elementId===e.scopeId||!ce(o,e.scopeId))return;if(`connectorData`in o.element){var s;let i=(s=e.elementData[o.elementId])==null?void 0:s.element;i&&`connectorData`in i&&a.push({kind:`connector`,elementId:o.elementId,element:(0,t.offsetBoardConnectorGeometry)(i,{x:n,y:r})});return}let c=(0,t.resolveBoardElementWorldBounds)(i,o.elementId);c&&a.push({kind:`bounds`,elementId:o.elementId,bounds:c})}),{deltaX:n,deltaY:r,elementData:i,items:a}}let de=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._commandService=r,this._uiStateService=i,this._instanceService=a,this._undoRedoGroupService=o,x(this,`_dragStart`,null),x(this,`_pointerDragStart`,null),x(this,`_dragPreviewObject`,null),x(this,`_childDragActivated`,!1),x(this,`_lastChildDragAction`,null),x(this,`_objectPointerDisposables`,null),x(this,`_attachObjectPointerScheduled`,!1),x(this,`_activePointerDragDisposables`,null),x(this,`_childDragSelectionHidden`,!1),this._init()}_init(){var e,t,n,r,i;let o=this._renderContext.scene.getTransformerByCreate();this.disposeWithMe((0,a.toDisposable)(o.changeStart$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._captureDragStart()}))),this.disposeWithMe((0,a.toDisposable)(((e=o.changing$)==null?void 0:e.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{this._syncDragPreview(e==null?void 0:e.objects)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(o.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{setTimeout(()=>this._applyDragTopologyAction(e==null?void 0:e.objects),0)}))),this.disposeWithMe((0,a.toDisposable)(((t=this._renderContext.scene.onPointerDown$)==null?void 0:t.subscribeEvent({priority:3,next:([e])=>this._capturePointerChildDragStart(e)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((n=this._renderContext.scene.onPointerMove$)==null?void 0:n.subscribeEvent({priority:3,next:([e,t])=>this._syncPointerChildDragPreview(e,t)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((r=this._renderContext.scene.onPointerUp$)==null?void 0:r.subscribeEvent({priority:3,next:([e,t])=>this._applyPointerChildDrag(e,t)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((i=this._renderContext.scene.onPointerCancel$)==null?void 0:i.subscribeEvent({priority:3,next:([,e])=>this._cancelPointerChildDrag(e)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(()=>{var e;return(e=this._objectPointerDisposables)==null?void 0:e.dispose()})),this.disposeWithMe((0,a.toDisposable)(()=>this._disposeActivePointerDragListeners())),this._subscribeElementDataChanges(),this._scheduleAttachObjectPointerListeners(),this.disposeWithMe((0,a.toDisposable)(()=>this._removeDragPreviewObject()))}_subscribeElementDataChanges(){[this._boardElementService.elementAdd$,this._boardElementService.elementUpdate$,this._boardElementService.elementRemove$].forEach(e=>{this.disposeWithMe((0,a.toDisposable)(e.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._scheduleAttachObjectPointerListeners()})))}),this._elementStateService.state$&&this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._scheduleAttachObjectPointerListeners()})))}_scheduleAttachObjectPointerListeners(){this._attachObjectPointerScheduled||(this._attachObjectPointerScheduled=!0,Promise.resolve().then(()=>this._attachObjectPointerListeners()))}_attachObjectPointerListeners(){var e;this._attachObjectPointerScheduled=!1;let t=this._resolveCurrentBoardContext(),i=this._renderContext.scene;if(!t||typeof i.getObject!=`function`)return;let o=this._boardElementService.getElementData(t.unitId,t.subUnitId),s=new a.DisposableCollection;(e=this._objectPointerDisposables)==null||e.dispose(),this._objectPointerDisposables=s,Object.values(o).forEach(e=>{var a,o;let c=(0,n.getMindMapNodeMeta)(e.element);if(!(c!=null&&c.parentNodeId))return;let l=(0,r.getBoardElementRenderObjectKey)(t.unitId,e.elementId),u=((a=i.getObjectIncludeInGroup)==null?void 0:a.call(i,l))??((o=i.getObject)==null?void 0:o.call(i,l));u!=null&&u.onPointerDown$&&s.add(u.onPointerDown$.subscribeEvent({priority:-10,next:([n,r])=>this._capturePointerChildDragStart(n,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:e.elementId},r)}))})}_resolveCurrentBoardContext(){let e=this._elementStateService.getSnapshot().context;if(e)return e;let t=this._renderContext.unitId,n=t?this._instanceService.getUnit(t,a.UniverInstanceType.UNIVER_BOARD):null,r=n==null?void 0:n.getActivePageId();return!n||!r?null:{unitId:n.getUnitId(),subUnitId:r}}_captureDragStart(){let e=this._elementStateService.getSnapshot();this._childDragActivated=!1,this._childDragSelectionHidden=!1,this._lastChildDragAction=null;let r=e.context,i=e.focusedId??e.selectedIds[0];if(!r||!i){this._dragStart=null,this._removeDragPreviewObject();return}let a=this._boardElementService.getElementData(r.unitId,r.subUnitId);if(e.selectedIds.length>1){let n=this._resolveCompleteSelectedScope(a,e.selectedIds);if(!n){this._dragStart=null,this._removeDragPreviewObject();return}let i=a[n.rootNodeId],o=(0,t.resolveBoardElementWorldBounds)(a,n.rootNodeId),s=i.element.transform;this._dragStart={kind:`scope`,unitId:r.unitId,subUnitId:r.subUnitId,nodeId:n.rootNodeId,scopeId:n.scopeId,left:(o==null?void 0:o.left)??s.left??0,top:(o==null?void 0:o.top)??s.top??0,width:(o==null?void 0:o.width)??s.width??0,height:(o==null?void 0:o.height)??s.height??0,elementData:a};return}let o=a[i],s=(0,n.getMindMapNodeMeta)(o==null?void 0:o.element);if(!o||!s){this._dragStart=null,this._removeDragPreviewObject();return}let c=(0,t.resolveBoardElementWorldBounds)(a,i),l=o.element.transform;this._dragStart={kind:s.parentNodeId===null?`root`:`child`,unitId:r.unitId,subUnitId:r.subUnitId,nodeId:i,scopeId:s.structureScopeId,left:(c==null?void 0:c.left)??l.left??0,top:(c==null?void 0:c.top)??l.top??0,width:(c==null?void 0:c.width)??l.width??0,height:(c==null?void 0:c.height)??l.height??0,elementData:a}}_resolveCompleteSelectedScope(e,t){let r=new Set(t),i=t.map(t=>{var r,i,a,o;let s=(r=e[t])==null?void 0:r.element;return((i=(0,n.getMindMapNodeMeta)(s))==null?void 0:i.structureScopeId)??((a=(0,n.getMindMapConnectorMeta)(s))==null?void 0:a.structureScopeId)??((o=(0,n.getMindMapContainerMeta)(s))==null?void 0:o.structureScopeId)??null});if(i.some(e=>e===null)||new Set(i).size!==1)return null;let a=i[0];if(!a)return null;let o=Object.values(e).filter(e=>{var t;return e.element.visible!==!1&&((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.structureScopeId)===a});if(o.length===0||o.some(e=>!r.has(e.elementId)))return null;let s=o.filter(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.parentNodeId)===null});return s.length===1?{rootNodeId:s[0].elementId,scopeId:a}:null}_capturePointerChildDragStart(e,r,i){var a,o,s,c,l;if(this._uiStateService.getState().interactionMode===`viewing`||(e.button??0)!==0)return;let u=this._elementStateService.getSnapshot();if(u.activeEditingId){this._pointerDragStart=null;return}let d=r?{unitId:r.unitId,subUnitId:r.subUnitId}:u.context??this._resolveCurrentBoardContext(),f=(r==null?void 0:r.nodeId)??(u.selectedIds.length===1?u.focusedId??u.selectedIds[0]:void 0);if(!d){this._pointerDragStart=null;return}let p=this._boardElementService.getElementData(d.unitId,d.subUnitId),m=this._getBoardPointFromEvent(e);if(!r){let e=f?p[f]:null,r=(0,n.getMindMapNodeMeta)(e==null?void 0:e.element),i=f?(0,t.resolveBoardElementWorldBounds)(p,f)??(e==null?void 0:e.element.transform):null;r!=null&&r.parentNodeId&&i&&this._isPointInBounds(m,{left:i.left??0,top:i.top??0,width:i.width??0,height:i.height??0})||(f=this._findChildNodeAtPoint(p,m))}if(!f){this._pointerDragStart=null;return}let h=p[f],g=(0,n.getMindMapNodeMeta)(h==null?void 0:h.element);if(!h||!(g!=null&&g.parentNodeId)){this._pointerDragStart=null;return}this._instanceService.focusUnit(d.unitId),(a=this._renderContext.engine)==null||(o=a.getCanvasElement)==null||(o=o.call(a))==null||(s=o.focus)==null||s.call(o,{preventScroll:!0}),(c=(l=this._elementStateService).selectElements)==null||c.call(l,d,[f],f),i==null||i.stopPropagation();let _=(0,t.resolveBoardElementWorldBounds)(p,f),v=h.element.transform,y={left:(_==null?void 0:_.left)??v.left??0,top:(_==null?void 0:_.top)??v.top??0,width:(_==null?void 0:_.width)??v.width??0,height:(_==null?void 0:_.height)??v.height??0};if(!r&&!this._isPointInBounds(m,y)){this._pointerDragStart=null;return}let b=this._getPointerScreenPoint(e);this._childDragActivated=!1,this._childDragSelectionHidden=!1,this._lastChildDragAction=null,this._pointerDragStart={kind:`child`,unitId:d.unitId,subUnitId:d.subUnitId,nodeId:f,scopeId:g.structureScopeId,...y,pointerStartX:b.x,pointerStartY:b.y,elementData:p},this._attachActivePointerDragListeners(),this._consumePointerEvent(e,i)}_syncPointerChildDragPreview(e,t){var n,r;let i=this._pointerDragStart;if(!i||e.buttons!==void 0&&e.buttons!==1)return;let a=this._getPointerLiveBounds(e,i);if(!this._isChildDragPastActivationThreshold(i,a))return;this._childDragActivated||this._hideSelectionForChildDrag(),this._childDragActivated=!0;let o=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,a),s=L(i.elementData,i.nodeId,{boundsByElementId:o,detachWhenNoSnap:!0});this._lastChildDragAction=s,this._syncChildDragPreviewObject(a,s,o),this._consumePointerEvent(e,t),this._renderContext.scene.makeDirty(!0),(n=(r=this._renderContext.scene).requestRender)==null||n.call(r)}_applyPointerChildDrag(e,t){let n=this._pointerDragStart;if(!n)return;if(this._pointerDragStart=null,this._disposeActivePointerDragListeners(),this._removeDragPreviewObject(),!this._childDragActivated){this._lastChildDragAction=null;return}let r=this._boardElementService.getElementData(n.unitId,n.subUnitId),i=this._getPointerLiveBounds(e,n),a=this._createTopologyBoundsByElementId(r,n.nodeId,i),o=L(r,n.nodeId,{boundsByElementId:a,detachWhenNoSnap:!0});this._lastChildDragAction=null,this._executeChildDragAction(n.unitId,n.subUnitId,n.nodeId,r,o),this._childDragSelectionHidden=!1,this._consumePointerEvent(e,t)}_cancelPointerChildDrag(e){let t=this._pointerDragStart;if(t){if(this._pointerDragStart=null,this._disposeActivePointerDragListeners(),this._childDragActivated=!1,this._lastChildDragAction=null,this._removeDragPreviewObject(),this._childDragSelectionHidden){var n,r;(n=(r=this._elementStateService).selectElements)==null||n.call(r,{unitId:t.unitId,subUnitId:t.subUnitId},[t.nodeId],t.nodeId),this._childDragSelectionHidden=!1}e==null||e.stopPropagation()}}_attachActivePointerDragListeners(){this._disposeActivePointerDragListeners();let e=typeof window>`u`?null:window;if(!(e!=null&&e.addEventListener))return;let t=new a.DisposableCollection,n=e=>this._syncPointerChildDragPreview(e),r=e=>this._applyPointerChildDrag(e),i=()=>this._cancelPointerChildDrag();e.addEventListener(`pointermove`,n,{capture:!0}),e.addEventListener(`pointerup`,r,{capture:!0}),e.addEventListener(`pointercancel`,i,{capture:!0}),t.add((0,a.toDisposable)(()=>{e.removeEventListener(`pointermove`,n,{capture:!0}),e.removeEventListener(`pointerup`,r,{capture:!0}),e.removeEventListener(`pointercancel`,i,{capture:!0})})),this._activePointerDragDisposables=t}_findChildNodeAtPoint(e,r){let i=Object.values(e);for(let a=i.length-1;a>=0;--a){let o=i[a],s=(0,n.getMindMapNodeMeta)(o.element);if(!(s!=null&&s.parentNodeId))continue;let c=(0,t.resolveBoardElementWorldBounds)(e,o.elementId)??o.element.transform;if(this._isPointInBounds(r,{left:c.left??0,top:c.top??0,width:c.width??0,height:c.height??0}))return o.elementId}}_disposeActivePointerDragListeners(){var e;(e=this._activePointerDragDisposables)==null||e.dispose(),this._activePointerDragDisposables=null}_syncDragPreview(e){let t=this._dragStart;t&&((t.kind===`root`||t.kind===`scope`)&&this._syncRootScopePreview(e),t.kind===`root`?this._syncRootReparentPreview(e):this._syncChildDragPreview(e))}_syncRootScopePreview(e){let t=this._dragStart;if(!t||t.kind!==`root`&&t.kind!==`scope`)return;let n=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(t.unitId,t.nodeId));if(!n||!Number.isFinite(n.left)||!Number.isFinite(n.top))return;let i=ue({elementData:t.elementData,rootNodeId:t.nodeId,scopeId:t.scopeId,rootStartBounds:{left:t.left,top:t.top},liveRootBounds:{left:n.left,top:n.top}});if(!i)return;let a=this._renderContext.scene,o=a,s=!1;i.items.forEach(e=>{var n;let c=(0,r.getBoardElementRenderObjectKey)(t.unitId,e.elementId),l=((n=o.getObjectIncludeInGroup)==null?void 0:n.call(o,c))??a.getObject(c);l&&(e.kind===`connector`&&typeof l.updateElement==`function`?(l.updateElement(e.element,i.elementData),s=!0):e.kind===`bounds`&&(l.transformByState(e.bounds),typeof l.makeDirtyNoDebounce==`function`?l.makeDirtyNoDebounce(!0):l.makeDirty(!0),s=!0))}),s&&a.makeDirty(!0)}_syncRootReparentPreview(e){var t,n;let i=this._dragStart;if(!i||i.kind!==`root`)return;let a=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(i.unitId,i.nodeId));if(!a||!Number.isFinite(a.left)||!Number.isFinite(a.top)){this._removeDragPreviewObject();return}let o=this._getLiveObjectBounds(a,i),s=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,o),c=L(i.elementData,i.nodeId,{boundsByElementId:s,allowRootReparent:!0});if(c.kind!==`reparent`){this._removeDragPreviewObject();return}let l=this._ensureDragPreviewObject();l&&(l.updateState({ghostBounds:o,sourceBounds:null,parentBounds:s[c.newParentNodeId],side:c.side,textStyle:void 0,renderGhostNode:!1}),this._renderContext.scene.makeDirty(!0),(t=(n=this._renderContext.scene).requestRender)==null||t.call(n))}_syncChildDragPreview(e){var t,n;let i=this._dragStart;if(!i||i.kind!==`child`)return;let a=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(i.unitId,i.nodeId));if(!a){this._removeDragPreviewObject();return}let o=this._getLiveObjectBounds(a,i);if(!this._isChildDragPastActivationThreshold(i,o)){this._lastChildDragAction=null,this._removeDragPreviewObject(),this._restoreObjectToDragStart(a,i),this._renderContext.scene.makeDirty(!0);return}this._childDragActivated||this._hideSelectionForChildDrag(),this._childDragActivated=!0;let s=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,o),c=L(i.elementData,i.nodeId,{boundsByElementId:s,detachWhenNoSnap:!0});this._lastChildDragAction=c,this._syncChildDragPreviewObject(o,c,s),this._restoreObjectToDragStart(a,i),this._renderContext.scene.makeDirty(!0),(t=(n=this._renderContext.scene).requestRender)==null||t.call(n)}_applyDragTopologyAction(e){var t;let n=this._elementStateService.getSnapshot(),r=n.context,i=n.focusedId??n.selectedIds[0];if(r&&((t=this._dragStart)==null?void 0:t.kind)===`scope`){this._removeDragPreviewObject(),this._applyScopeTranslation(r.unitId,r.subUnitId,e);return}if(!r||!i||n.selectedIds.length!==1){this._removeDragPreviewObject(),this._dragStart=null;return}this._removeDragPreviewObject();let a=this._boardElementService.getElementData(r.unitId,r.subUnitId);if(this._applyRootTranslation(r.unitId,r.subUnitId,i,a,e))return;let o=this._resolveChildDragTopologyAction(r.unitId,r.subUnitId,i,a,e);this._executeChildDragAction(r.unitId,r.subUnitId,i,a,o)}_applyScopeTranslation(e,t,i){let a=this._dragStart;if(this._dragStart=null,!a||a.kind!==`scope`||a.unitId!==e||a.subUnitId!==t)return;let o=i==null?void 0:i.get((0,r.getBoardElementRenderObjectKey)(e,a.nodeId)),s=o&&Number.isFinite(o.left)?o.left??a.left:a.left,c=o&&Number.isFinite(o.top)?o.top??a.top:a.top,l=s-a.left,u=c-a.top;(l!==0||u!==0)&&this._commandService.executeCommand(n.TranslateMindMapOperation.id,{unitId:e,subUnitId:t,scopeId:a.scopeId,deltaX:l,deltaY:u})}_executeChildDragAction(e,t,r,i,a){if(a.kind===`reparent`){var o,s;let c=(0,n.getMindMapNodeMeta)((o=i[r])==null?void 0:o.element),l=(0,n.getMindMapNodeMeta)((s=i[a.newParentNodeId])==null?void 0:s.element);this._executeAndLayout(n.ReparentMindMapNodeOperation.id,{unitId:e,subUnitId:t,nodeId:r,newParentNodeId:a.newParentNodeId,side:a.side,...a.referenceNodeId?{referenceNodeId:a.referenceNodeId}:null,...a.placement?{placement:a.placement}:null},[c==null?void 0:c.structureScopeId,l==null?void 0:l.structureScopeId],r)}else if(a.kind===`detach`){var c;let o=(0,n.getMindMapNodeMeta)((c=i[r])==null?void 0:c.element);this._executeAndLayout(n.DetachMindMapNodeOperation.id,{unitId:e,subUnitId:t,nodeId:r,...Number.isFinite(a.left)?{left:a.left}:null,...Number.isFinite(a.top)?{top:a.top}:null},[o==null?void 0:o.structureScopeId],r)}}_applyRootTranslation(e,i,a,o,s){let c=this._dragStart;if((c==null?void 0:c.kind)===`root`&&(this._dragStart=null),!c||c.unitId!==e||c.subUnitId!==i||c.nodeId!==a)return!1;let l=o[a],u=(0,n.getMindMapNodeMeta)(l==null?void 0:l.element);if(!l||!u||u.parentNodeId!==null)return!1;let d=s==null?void 0:s.get((0,r.getBoardElementRenderObjectKey)(e,a)),f=(0,t.resolveBoardElementWorldBounds)(o,a),p=Number.isFinite(d==null?void 0:d.left)?d.left:(f==null?void 0:f.left)??l.element.transform.left??0,m=Number.isFinite(d==null?void 0:d.top)?d.top:(f==null?void 0:f.top)??l.element.transform.top??0,h=p-c.left,g=m-c.top;if(h===0&&g===0)return!0;let _={left:p,top:m,width:Number.isFinite(d==null?void 0:d.width)?d.width:c.width,height:Number.isFinite(d==null?void 0:d.height)?d.height:c.height},v=L(o,a,{boundsByElementId:this._createTopologyBoundsByElementId(o,a,_),allowRootReparent:!0});if(v.kind===`reparent`)return this._executeChildDragAction(e,i,a,o,v),!0;let y=!!f&&Math.abs(f.left-p)<.001&&Math.abs(f.top-m)<.001;return this._commandService.executeCommand(n.TranslateMindMapOperation.id,{unitId:e,subUnitId:i,scopeId:c.scopeId,deltaX:h,deltaY:g,...y?{excludeElementIds:[a],preserveExcludedWorldTransforms:!0}:null}),!0}_resolveChildDragTopologyAction(e,t,n,i,a){let o=this._dragStart;if(!o||o.kind!==`child`||o.unitId!==e||o.subUnitId!==t||o.nodeId!==n)return{kind:`none`};this._dragStart=null;let s=a==null?void 0:a.get((0,r.getBoardElementRenderObjectKey)(e,n));if(!this._childDragActivated)return s&&this._restoreObjectToDragStart(s,o),this._lastChildDragAction=null,{kind:`none`};if(!s){let e=this._lastChildDragAction??{kind:`none`};return this._lastChildDragAction=null,e}let c=this._getLiveObjectBounds(s,o);if(this._restoreObjectToDragStart(s,o),!this._isChildDragPastActivationThreshold(o,c))return this._lastChildDragAction=null,{kind:`none`};let l=L(i,n,{boundsByElementId:this._createTopologyBoundsByElementId(i,n,c),detachWhenNoSnap:!0});return this._lastChildDragAction=null,l}_isChildDragPastActivationThreshold(e,t){let n=(t.left??e.left)-e.left,r=(t.top??e.top)-e.top;return Math.hypot(n,r)>=18}_getPointerLiveBounds(e,t){let n=this._getPointerScreenPoint(e),r=this._getZoomRatio();return{left:t.left+(n.x-t.pointerStartX)/r,top:t.top+(n.y-t.pointerStartY)/r,width:t.width,height:t.height}}_getBoardPointFromEvent(e){let t=this._uiStateService.getState(),n=(t==null?void 0:t.viewportPanOffset)??{x:0,y:0},r=this._getZoomRatio();return{x:Math.round(((e.offsetX??0)-n.x)/r),y:Math.round(((e.offsetY??0)-n.y)/r)}}_getPointerScreenPoint(e){return{x:Number.isFinite(e.clientX)?e.clientX:e.offsetX??0,y:Number.isFinite(e.clientY)?e.clientY:e.offsetY??0}}_getZoomRatio(){let e=this._uiStateService.getState().zoomRatio;return Number.isFinite(e)&&(e??0)>0?e:1}_isPointInBounds(e,t){return e.x>=t.left&&e.x<=t.left+t.width&&e.y>=t.top&&e.y<=t.top+t.height}_consumePointerEvent(e,t){var n,r;t==null||t.stopPropagation(),t&&(t.skipNextObservers=!0),(n=e.preventDefault)==null||n.call(e),(r=e.stopPropagation)==null||r.call(e)}_hideSelectionForChildDrag(){var e,t;this._childDragSelectionHidden||=((e=(t=this._elementStateService).clearSelection)==null||e.call(t),!0)}_getLiveObjectBounds(e,t){return{left:Number.isFinite(e.left)?e.left:t.left,top:Number.isFinite(e.top)?e.top:t.top,width:Number.isFinite(e.width)?e.width:t.width,height:Number.isFinite(e.height)?e.height:t.height}}_restoreObjectToDragStart(e,t){typeof e.transformByState==`function`&&e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height}),typeof e.makeDirtyNoDebounce==`function`?e.makeDirtyNoDebounce(!0):typeof e.makeDirty==`function`&&e.makeDirty(!0)}_createTopologyBoundsByElementId(e,n,r){return Object.fromEntries(Object.keys(e).map(i=>i===n?[i,r]:[i,(0,t.resolveBoardElementWorldBounds)(e,i)??e[i].element.transform]))}_ensureDragPreviewObject(){if(this._dragPreviewObject)return this._dragPreviewObject;let e=this._renderContext.scene;return typeof e.addObject==`function`?(this._dragPreviewObject=new te(A),e.addObject(this._dragPreviewObject,j),this._dragPreviewObject):null}_syncChildDragPreviewObject(e,t,n){let r=this._ensureDragPreviewObject();r&&r.updateState({ghostBounds:e,sourceBounds:this._resolvePreviewSourceBounds(),parentBounds:t.kind===`reparent`?n[t.newParentNodeId]:null,side:t.kind===`reparent`?t.side:`right`,textStyle:this._resolvePreviewTextStyle(),renderGhostNode:!0})}_resolvePreviewSourceBounds(){let e=this._pointerDragStart??this._dragStart;return e?{left:e.left,top:e.top,width:e.width,height:e.height}:null}_resolvePreviewTextStyle(){var e,t;let n=this._pointerDragStart??this._dragStart,r=n==null||(e=n.elementData[n.nodeId])==null?void 0:e.element,i=r==null||(t=r.shapeData)==null?void 0:t.shapeText;if(i)return{text:typeof i.text==`string`?i.text:void 0,fontSize:Number.isFinite(i.fontSize)?i.fontSize:void 0,color:typeof i.color==`string`?i.color:void 0,horizontalAlign:Number.isFinite(i.horizontalAlign)?i.horizontalAlign:void 0}}_removeDragPreviewObject(){var e,t,n;if(!this._dragPreviewObject)return;let r=this._renderContext.scene;(e=r.removeObjects)==null||e.call(r,[this._dragPreviewObject]),this._dragPreviewObject=null,(t=(n=this._renderContext.scene).makeDirty)==null||t.call(n,!0)}_executeAndLayout(e,t,r,i){let a=[...new Set(r.filter(e=>!!e))],o=typeof t.unitId==`string`?t.unitId:this._renderContext.unitId,s=this._undoRedoGroupService.createRunner(o),c=s(()=>this._commandService.executeCommand(e,t));Promise.resolve(c).then(e=>{var r,o,c,l;if(e){if(a.forEach(e=>{s(()=>this._commandService.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:e}))}),i&&typeof t.unitId==`string`&&typeof t.subUnitId==`string`){var u,d;(u=(d=this._elementStateService).selectElements)==null||u.call(d,{unitId:t.unitId,subUnitId:t.subUnitId},[i],i)}(r=(o=this._renderContext.scene).makeDirty)==null||r.call(o,!0),(c=(l=this._renderContext.scene).requestRender)==null||c.call(l)}})}};de=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,a.ICommandService),S(4,r.IBoardUIStateService),S(5,a.IUniverInstanceService),S(6,(0,a.Inject)(c.UndoRedoGroupService))],de);function R({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,f.useId)()}`,u=(0,f.useRef)(null);return(0,f.useImperativeHandle)(e,()=>u.current),(0,f.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return he(u.current)},[n,r]),fe(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function fe(e,t,n,r,i){return(0,f.createElement)(e.tag,{key:t,...pe(e,n,i),...r},(me(e,n).children||[]).map((r,a)=>fe(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function pe(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function me(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function he(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:ge(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(_e(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function ge(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function _e(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}R.displayName=`UniverIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 13.6999C1.3999 13.3685 1.66853 13.0999 1.9999 13.0999H13.9999C14.3313 13.0999 14.5999 13.3685 14.5999 13.6999C14.5999 14.0312 14.3313 14.2999 13.9999 14.2999H1.9999C1.66853 14.2999 1.3999 14.0312 1.3999 13.6999Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7.57564 10.3914C7.80995 10.6257 8.18985 10.6257 8.42417 10.3914L10.4242 8.3914C10.6585 8.15709 10.6585 7.77719 10.4242 7.54287C10.1899 7.30856 9.80995 7.30856 9.57564 7.54287L7.9999 9.11861L6.42417 7.54287C6.18985 7.30856 5.80995 7.30856 5.57564 7.54287C5.34132 7.77719 5.34132 8.15709 5.57564 8.3914L7.57564 10.3914Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7.9999 10.5671C8.33127 10.5671 8.5999 10.2985 8.5999 9.96714V2.30047C8.5999 1.9691 8.33127 1.70047 7.9999 1.70047C7.66853 1.70047 7.3999 1.9691 7.3999 2.30047V9.96714C7.3999 10.2985 7.66853 10.5671 7.9999 10.5671Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`align-bottom-icon`,ref:t,icon:ve}))});ye.displayName=`AlignBottomIcon`;let be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 1.89941C1.66853 1.89941 1.3999 2.16804 1.3999 2.49941C1.3999 2.83078 1.66853 3.09941 1.9999 3.09941H13.9999C14.3313 3.09941 14.5999 2.83078 14.5999 2.49941C14.5999 2.16804 14.3313 1.89941 13.9999 1.89941H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 5.56641C1.66853 5.56641 1.3999 5.83504 1.3999 6.16641C1.3999 6.49778 1.66853 6.76641 1.9999 6.76641H13.9999C14.3313 6.76641 14.5999 6.49778 14.5999 6.16641C14.5999 5.83504 14.3313 5.56641 13.9999 5.56641H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 9.8334C1.3999 9.50203 1.66853 9.2334 1.9999 9.2334H13.9999C14.3313 9.2334 14.5999 9.50203 14.5999 9.8334C14.5999 10.1648 14.3313 10.4334 13.9999 10.4334H1.9999C1.66853 10.4334 1.3999 10.1648 1.3999 9.8334Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 12.9004C1.66853 12.9004 1.3999 13.169 1.3999 13.5004C1.3999 13.8318 1.66853 14.1004 1.9999 14.1004H13.9999C14.3313 14.1004 14.5999 13.8318 14.5999 13.5004C14.5999 13.169 14.3313 12.9004 13.9999 12.9004H1.9999Z`}}]},xe=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`align-text-both-icon`,ref:t,icon:be}))});xe.displayName=`AlignTextBothIcon`;let Se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 2.3002C1.3999 2.63157 1.66853 2.9002 1.9999 2.9002H13.9999C14.3313 2.9002 14.5999 2.63157 14.5999 2.3002C14.5999 1.96882 14.3313 1.7002 13.9999 1.7002H1.9999C1.66853 1.7002 1.3999 1.96882 1.3999 2.3002Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.22957 5.47839C8.30034 5.50767 8.36664 5.55107 8.42417 5.6086L10.4242 7.6086C10.6585 7.84291 10.6585 8.22281 10.4242 8.45713C10.1899 8.69144 9.80995 8.69144 9.57564 8.45713L8.5999 7.48139V13.6995C8.5999 14.0309 8.33127 14.2995 7.9999 14.2995C7.66853 14.2995 7.3999 14.0309 7.3999 13.6995V7.48139L6.42417 8.45713C6.18985 8.69144 5.80995 8.69144 5.57564 8.45713C5.34132 8.22281 5.34132 7.84291 5.57564 7.6086L7.57541 5.60882C7.7522 5.43203 8.01209 5.38841 8.22957 5.47839Z`}}]},Ce=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`align-top-icon`,ref:t,icon:Se}))});Ce.displayName=`AlignTopIcon`;let we={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.65791 1.30005C3.77355 1.30005 3.05664 2.01696 3.05664 2.90132V12.8588C3.05664 13.8755 3.88086 14.6998 4.89759 14.6998H9.1016C11.2233 14.6998 12.9433 12.9798 12.9433 10.8581C12.9433 9.13925 11.8145 7.68407 10.2578 7.1934C10.8806 6.56856 11.2655 5.70659 11.2655 4.75472C11.2655 2.84676 9.71883 1.30005 7.81087 1.30005H4.65791ZM4.25664 2.90132C4.25664 2.6797 4.4363 2.50005 4.65791 2.50005H7.81087C9.05609 2.50005 10.0655 3.5095 10.0655 4.75472C10.0655 5.99993 9.05609 7.00938 7.81087 7.00938H4.25664V2.90132ZM4.25664 12.8588V8.21636H9.1016C10.5606 8.21636 11.7433 9.39909 11.7433 10.8581C11.7433 12.317 10.5606 13.4998 9.1016 13.4998H4.89759C4.5436 13.4998 4.25664 13.2128 4.25664 12.8588Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Te=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`bold-icon`,ref:t,icon:we}))});Te.displayName=`BoldIcon`;let Ee={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 1.89941C1.66853 1.89941 1.3999 2.16804 1.3999 2.49941C1.3999 2.83078 1.66853 3.09941 1.9999 3.09941H13.9999C14.3313 3.09941 14.5999 2.83078 14.5999 2.49941C14.5999 2.16804 14.3313 1.89941 13.9999 1.89941H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.33315 5.56641C3.00178 5.56641 2.73315 5.83504 2.73315 6.16641C2.73315 6.49778 3.00178 6.76641 3.33315 6.76641H12.6665C12.9979 6.76641 13.2665 6.49778 13.2665 6.16641C13.2665 5.83504 12.9979 5.56641 12.6665 5.56641H3.33315Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 9.8334C1.3999 9.50203 1.66853 9.2334 1.9999 9.2334H13.9999C14.3313 9.2334 14.5999 9.50203 14.5999 9.8334C14.5999 10.1648 14.3313 10.4334 13.9999 10.4334H1.9999C1.66853 10.4334 1.3999 10.1648 1.3999 9.8334Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.33315 12.9004C3.00178 12.9004 2.73315 13.169 2.73315 13.5004C2.73315 13.8318 3.00178 14.1004 3.33315 14.1004H12.6665C12.9979 14.1004 13.2665 13.8318 13.2665 13.5004C13.2665 13.169 12.9979 12.9004 12.6665 12.9004H3.33315Z`}}]},De=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`horizontally-icon`,ref:t,icon:Ee}))});De.displayName=`HorizontallyIcon`;let Oe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M9.80385 1.40005H11.9997C12.3311 1.40005 12.5997 1.66868 12.5997 2.00005C12.5997 2.33143 12.3311 2.60005 11.9997 2.60005H10.1185L7.12251 13.4001H9.33324C9.66461 13.4001 9.93324 13.6687 9.93324 14.0001C9.93324 14.3314 9.66461 14.6001 9.33324 14.6001H6.34785C6.33847 14.6003 6.32905 14.6003 6.31962 14.6001H3.9999C3.66853 14.6001 3.3999 14.3314 3.3999 14.0001C3.3999 13.6687 3.66853 13.4001 3.9999 13.4001H5.87719L8.87322 2.60005H6.66641C6.33504 2.60005 6.06641 2.33143 6.06641 2.00005C6.06641 1.66868 6.33504 1.40005 6.66641 1.40005H9.52916C9.61698 1.37929 9.71064 1.3781 9.80385 1.40005Z`}}]},ke=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`italic-icon`,ref:t,icon:Oe}))});ke.displayName=`ItalicIcon`;let Ae={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 1.89941C1.66853 1.89941 1.3999 2.16804 1.3999 2.49941C1.3999 2.83078 1.66853 3.09941 1.9999 3.09941H13.9999C14.3313 3.09941 14.5999 2.83078 14.5999 2.49941C14.5999 2.16804 14.3313 1.89941 13.9999 1.89941H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 5.56641C1.66853 5.56641 1.3999 5.83504 1.3999 6.16641C1.3999 6.49778 1.66853 6.76641 1.9999 6.76641H11.3332C11.6646 6.76641 11.9332 6.49778 11.9332 6.16641C11.9332 5.83504 11.6646 5.56641 11.3332 5.56641H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 9.8334C1.3999 9.50203 1.66853 9.2334 1.9999 9.2334H13.9999C14.3313 9.2334 14.5999 9.50203 14.5999 9.8334C14.5999 10.1648 14.3313 10.4334 13.9999 10.4334H1.9999C1.66853 10.4334 1.3999 10.1648 1.3999 9.8334Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 12.9004C1.66853 12.9004 1.3999 13.169 1.3999 13.5004C1.3999 13.8318 1.66853 14.1004 1.9999 14.1004H11.3332C11.6646 14.1004 11.9332 13.8318 11.9332 13.5004C11.9332 13.169 11.6646 12.9004 11.3332 12.9004H1.9999Z`}}]},je=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`left-justifying-icon`,ref:t,icon:Ae}))});je.displayName=`LeftJustifyingIcon`;let Me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z`}}]},Ne=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`more-horizontal-icon`,ref:t,icon:Me}))});Ne.displayName=`MoreHorizontalIcon`;let Pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 1.89941C1.66853 1.89941 1.3999 2.16804 1.3999 2.49941C1.3999 2.83078 1.66853 3.09941 1.9999 3.09941H13.9999C14.3313 3.09941 14.5999 2.83078 14.5999 2.49941C14.5999 2.16804 14.3313 1.89941 13.9999 1.89941H1.9999Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.66665 5.56641C4.33528 5.56641 4.06665 5.83504 4.06665 6.16641C4.06665 6.49778 4.33528 6.76641 4.66665 6.76641H14C14.3314 6.76641 14.6 6.49778 14.6 6.16641C14.6 5.83504 14.3314 5.56641 14 5.56641H4.66665Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.3999 9.8334C1.3999 9.50203 1.66853 9.2334 1.9999 9.2334H13.9999C14.3313 9.2334 14.5999 9.50203 14.5999 9.8334C14.5999 10.1648 14.3313 10.4334 13.9999 10.4334H1.9999C1.66853 10.4334 1.3999 10.1648 1.3999 9.8334Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.66665 12.9004C4.33528 12.9004 4.06665 13.169 4.06665 13.5004C4.06665 13.8318 4.33528 14.1004 4.66665 14.1004H14C14.3314 14.1004 14.6 13.8318 14.6 13.5004C14.6 13.169 14.3314 12.9004 14 12.9004H4.66665Z`}}]},Fe=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`right-justifying-icon`,ref:t,icon:Pe}))});Fe.displayName=`RightJustifyingIcon`;let Ie={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`circle`,attrs:{cx:7,cy:7,r:5.2}},{tag:`path`,attrs:{d:`M10.8 10.8L14.2 14.2`}}]}]},Le=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`search-icon`,ref:t,icon:Ie}))});Le.displayName=`SearchIcon`;let Re={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.5 3.5L16.5 16.5`,strokeLinecap:`round`,strokeWidth:1.6}}]},ze=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`shape-line-icon`,ref:t,icon:Re}))});ze.displayName=`ShapeLineIcon`;let Be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.00033 1.20996C6.43345 1.20996 5.23596 1.88077 4.64804 2.94304C4.06338 3.99943 4.15123 5.32084 4.90099 6.47062C5.08199 6.7482 5.45374 6.82648 5.73131 6.64548C6.00888 6.46448 6.08716 6.09273 5.90616 5.81516C5.36418 4.98402 5.35768 4.13897 5.69797 3.52412C6.035 2.91515 6.78176 2.40996 8.00033 2.40996C9.19423 2.40996 10.0017 2.93409 10.5236 3.46755C10.7871 3.73682 10.9756 4.00712 11.0974 4.20903C11.158 4.30951 11.2013 4.39164 11.2284 4.44625C11.2419 4.47351 11.2514 4.49377 11.2568 4.50588L11.2621 4.51771C11.3901 4.82216 11.7407 4.96686 12.046 4.83992C12.3519 4.71267 12.4968 4.36149 12.3695 4.05552L11.8231 4.28278C12.3695 4.05552 12.3697 4.0558 12.3695 4.05552L12.3691 4.05437L12.3685 4.05298L12.367 4.04953L12.3629 4.03993L12.3498 4.01036C12.3388 3.98619 12.3234 3.95326 12.3033 3.91282C12.2632 3.83203 12.2043 3.72072 12.1249 3.58908C11.9666 3.32674 11.7235 2.97805 11.3814 2.62834C10.6921 1.92381 9.59192 1.20996 8.00033 1.20996Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.11953 8.5999H7.88935C10.1109 9.46549 10.5895 10.7649 10.4268 11.6869C10.2475 12.703 9.26939 13.5898 8.00009 13.5898C6.63323 13.5898 5.77631 13.0502 5.25534 12.528C4.99021 12.2623 4.80823 11.9965 4.69365 11.7993C4.63659 11.7011 4.59698 11.6211 4.5727 11.5686C4.56059 11.5424 4.55236 11.5231 4.54774 11.512L4.54352 11.5016C4.4267 11.193 4.0823 11.0363 3.77279 11.1516C3.46228 11.2673 3.30438 11.6129 3.4201 11.9234L3.9649 11.7203C3.4201 11.9234 3.41998 11.9231 3.4201 11.9234L3.4206 11.9247L3.42118 11.9263L3.42262 11.9301L3.42661 11.9403C3.42977 11.9484 3.43394 11.9588 3.43914 11.9713C3.44956 11.9965 3.46418 12.0304 3.48334 12.0719C3.52161 12.1547 3.57828 12.2682 3.65608 12.4021C3.81124 12.6692 4.0534 13.0223 4.40584 13.3756C5.12 14.0914 6.27196 14.7898 8.00009 14.7898C9.82574 14.7898 11.3236 13.5101 11.6085 11.8955C11.812 10.7422 11.3901 9.55402 10.2665 8.5999H13.8804C14.2117 8.5999 14.4803 8.33127 14.4803 7.9999C14.4803 7.66853 14.2117 7.3999 13.8804 7.3999H8.01411C8.0048 7.39968 7.99551 7.39969 7.98625 7.3999H2.11953C1.78816 7.3999 1.51953 7.66853 1.51953 7.9999C1.51953 8.33127 1.78816 8.5999 2.11953 8.5999Z`}}]},Ve=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`strikethrough-icon`,ref:t,icon:Be}))});Ve.displayName=`StrikethroughIcon`;let He={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.46416 2.03237C4.46416 1.701 4.19553 1.43237 3.86416 1.43237C3.53279 1.43237 3.26416 1.701 3.26416 2.03237V7.33338C3.26416 10.0313 5.35834 12.2667 7.9999 12.2667C10.6415 12.2667 12.7356 10.0313 12.7356 7.33338V2.03237C12.7356 1.701 12.467 1.43237 12.1356 1.43237C11.8043 1.43237 11.5356 1.701 11.5356 2.03237V7.33338C11.5356 9.42194 9.92656 11.0667 7.9999 11.0667C6.07325 11.0667 4.46416 9.42194 4.46416 7.33338V2.03237Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.66641 13.4663C2.33504 13.4663 2.06641 13.7349 2.06641 14.0663C2.06641 14.3977 2.33504 14.6663 2.66641 14.6663H13.3331C13.6644 14.6663 13.9331 14.3977 13.9331 14.0663C13.9331 13.7349 13.6644 13.4663 13.3331 13.4663H2.66641Z`}}]},Ue=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`underline-icon`,ref:t,icon:He}))});Ue.displayName=`UnderlineIcon`;let We={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.9999 0.733398C8.33127 0.733398 8.5999 1.00203 8.5999 1.3334V4.55137L9.57564 3.57564C9.80995 3.34132 10.1899 3.34132 10.4242 3.57564C10.6585 3.80995 10.6585 4.18985 10.4242 4.42417L8.42417 6.42417C8.18985 6.65848 7.80995 6.65848 7.57564 6.42417L5.57564 4.42417C5.34132 4.18985 5.34132 3.80995 5.57564 3.57564C5.80995 3.34132 6.18985 3.34132 6.42417 3.57564L7.3999 4.55137V1.3334C7.3999 1.00203 7.66853 0.733398 7.9999 0.733398Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 11.5756L7.57564 9.57564C7.80995 9.34132 8.18985 9.34132 8.42417 9.57564L10.4242 11.5756C10.6585 11.81 10.6585 12.1899 10.4242 12.4242C10.1899 12.6585 9.80995 12.6585 9.57564 12.4242L8.5999 11.4484V14.6665C8.5999 14.9979 8.33127 15.2665 7.9999 15.2665C7.66853 15.2665 7.3999 14.9979 7.3999 14.6665V11.4484L6.42417 12.4242C6.18985 12.6585 5.80995 12.6585 5.57564 12.4242C5.34132 12.1899 5.34132 11.81 5.57564 11.5756Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9999 7.40015C1.66853 7.40015 1.3999 7.66878 1.3999 8.00015C1.3999 8.33152 1.66853 8.60015 1.9999 8.60015H13.9999C14.3313 8.60015 14.5999 8.33152 14.5999 8.00015C14.5999 7.66878 14.3313 7.40015 13.9999 7.40015H1.9999Z`}}]},Ge=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(R,Object.assign({},e,{id:`vertical-center-icon`,ref:t,icon:We}))});Ge.displayName=`VerticalCenterIcon`;let z=class extends a.Disposable{constructor(e,t,n,r,i,a,o,s,c){super(),this.renderContext=e,this.commandService=t,this.elementService=n,this.elementStateService=r,this.uiStateService=i,this.clipboardService=a,this.dialogService=o,this.localeService=s,this.textEditingService=c}};z=C([S(1,a.ICommandService),S(2,t.IBoardElementService),S(3,r.IBoardElementStateService),S(4,r.IBoardUIStateService),S(5,n.IMindMapClipboardService),S(6,c.IDialogService),S(7,(0,a.Inject)(a.LocaleService)),S(8,(0,a.Inject)(r.BoardTextEditingService))],z);let Ke=`board.mind-map.description-dialog`,qe=`board-mind-map-description-dialog`;function Je(e){let{unitId:t,subUnitId:r,nodeId:i,initialDescription:o=``}=e,s=(0,c.useDependency)(a.ICommandService),l=(0,c.useDependency)(c.IDialogService),u=(0,c.useDependency)(a.LocaleService),[m,h]=(0,f.useState)(o),g=()=>l.close(qe);return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-w-full univer-flex-col univer-gap-4`,"data-board-mind-map-description-dialog":`true`,children:[/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:u.t(`boards-mind-ui.description`)}),/* @__PURE__ */ (0,p.jsx)(d.Textarea,{autoFocus:!0,className:`univer-h-32 univer-resize-none univer-text-sm`,placeholder:u.t(`boards-mind-ui.descriptionPlaceholder`),value:m,onValueChange:h})]}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`default`,onClick:g,children:u.t(`boards-mind-ui.cancel`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`primary`,onClick:()=>{s.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:t,subUnitId:r,nodeId:i,foreignAttributes:{_note:m.trim()?m:null}}),g()},children:u.t(`boards-mind-ui.saveDescription`)})]})]})}let B=`board.operation.mind-map.keyboard-shortcut`,Ye=`FOCUSING_MIND_MAP_NODE`,Xe=`FOCUSING_MIND_MAP_BLANK_BOARD`,Ze={copy:r.BOARD_SHORTCUT_BINDINGS.copy,paste:r.BOARD_SHORTCUT_BINDINGS.paste,"paste-as-new":r.BOARD_SHORTCUT_BINDINGS.paste,"add-child":r.BOARD_SHORTCUT_BINDINGS.addChildNode,"add-sibling-or-child":r.BOARD_SHORTCUT_BINDINGS.addSiblingNode,promote:r.BOARD_SHORTCUT_BINDINGS.addParentNode,"toggle-collapse":r.BOARD_SHORTCUT_BINDINGS.foldChildNodes,"collapse-all":r.BOARD_SHORTCUT_BINDINGS.collapseAllNodes,"edit-text":r.BOARD_SHORTCUT_BINDINGS.editCurrentNode,"open-description":r.BOARD_SHORTCUT_BINDINGS.addDescription,delete:c.KeyCode.DELETE,"arrow-left":c.KeyCode.ARROW_LEFT,"arrow-right":c.KeyCode.ARROW_RIGHT,"arrow-up":c.KeyCode.ARROW_UP,"arrow-down":c.KeyCode.ARROW_DOWN},Qe={delete:[c.KeyCode.BACKSPACE]};function $e(e){return[Ze[e],...Qe[e]??[]]}let V=class extends a.RxDisposable{constructor(e,t,n,r){super(),this._mindMapClipboardService=e,this._commandService=t,this._shortcutService=n,this._undoRedoGroupService=r,this._init()}_init(){this.disposeWithMe(this._commandService.registerCommand(this._createKeyboardShortcutOperation())),this._createShortcutItems().forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_createKeyboardShortcutOperation(){return{id:B,type:a.CommandType.OPERATION,handler:(e,t,n)=>{let r=et(e,n);return r?this.handleShortcut(r,t==null?void 0:t.action):!1}}}_createShortcutItems(){let e=(e,t)=>({id:B,binding:e,priority:160,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!e.getContextValue(`FOCUSING_MIND_MAP_NODE`),staticParameters:{action:t}}),t=t=>$e(t).map(n=>e(n,t));return[...t(`copy`),{id:B,binding:Ze.paste,priority:160,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!this._mindMapClipboardService.getPayload()&&!!e.getContextValue(`FOCUSING_MIND_MAP_NODE`),staticParameters:{action:`paste`}},{id:B,binding:Ze[`paste-as-new`],priority:150,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!this._mindMapClipboardService.getPayload()&&!!e.getContextValue(`FOCUSING_MIND_MAP_BLANK_BOARD`),staticParameters:{action:`paste-as-new`}},...t(`add-child`),...t(`add-sibling-or-child`),...t(`promote`),...t(`toggle-collapse`),...t(`collapse-all`),...t(`edit-text`),...t(`open-description`),...t(`delete`),...t(`arrow-left`),...t(`arrow-right`),...t(`arrow-up`),...t(`arrow-down`)]}handleShortcut(e,t){return e.uiStateService.getState().interactionMode===`viewing`&&t!==`copy`?!1:t===`copy`?this._copySelectedNode(e):t===`paste`?this._pasteUnderSelectedNode(e):t===`paste-as-new`?this._pasteAsNewMindMap(e):t===`add-child`?this._addChild(e):t===`add-sibling-or-child`?this._addSiblingOrChild(e):t===`promote`?this._executeNodeOperation(e,n.PromoteMindMapNodeOperation.id):t===`toggle-collapse`?this._executeNodeOperation(e,n.ToggleMindMapNodeCollapseOperation.id):t===`collapse-all`?this._collapseAll(e):t===`edit-text`?this._openSelectedTextEditing(e):t===`open-description`?this._openDescriptionDialog(e):t===`delete`?this._deleteSelectedNode(e):t&&tt(t)?this._navigateByTopology(e,t):!1}_copySelectedNode(e){let t=this._getSelectedMindMapContext(e);return t?(e.commandService.executeCommand(n.CopyMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId}),!0):!1}_pasteUnderSelectedNode(e){let t=this._getSelectedMindMapContext(e);return!t||!e.clipboardService.getPayload()?!1:(this._executeAndLayout(e,n.PasteMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,targetNodeId:t.nodeId},t.scopeId),!0)}_pasteAsNewMindMap(e){let t=this._getBlankBoardContext(e);if(!t||!e.clipboardService.getPayload())return!1;let r=e.uiStateService.getState(),i=Number.isFinite(r.zoomRatio)&&r.zoomRatio>0?r.zoomRatio:1,a=Math.round((64-r.viewportPanOffset.x)/i),o=Math.round((64-r.viewportPanOffset.y)/i);return e.commandService.executeCommand(n.PasteMindMapAsNewMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,left:a,top:o}),!0}_addChild(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(e,n.AddMindMapChildOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,parentNodeId:t.nodeId,nodeId:r,connectorId:(0,a.generateRandomId)(6),text:e.localeService.t(`boards-mind-ui.panel.addText`)},t.scopeId,r),!0}_addSiblingOrChild(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(e,t.isRoot?n.AddMindMapChildOperation.id:n.AddMindMapSiblingOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,...t.isRoot?{parentNodeId:t.nodeId,nodeId:r}:{nodeId:t.nodeId,siblingNodeId:r},connectorId:(0,a.generateRandomId)(6),text:e.localeService.t(`boards-mind-ui.panel.addText`)},t.scopeId,r),!0}_executeNodeOperation(e,t){let n=this._getSelectedMindMapContext(e);return n?(this._executeAndLayout(e,t,{unitId:n.unitId,subUnitId:n.subUnitId,nodeId:n.nodeId},n.scopeId),!0):!1}_deleteSelectedNode(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=e.commandService.syncExecuteCommand(n.DeleteMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId});return r&&e.elementStateService.clearSelection(),r}_collapseAll(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=e.elementService.getElementData(t.unitId,t.subUnitId),i=Object.values(r).map(e=>{let i=(0,n.getMindMapNodeMeta)(e.element);return(i==null?void 0:i.structureScopeId)===t.scopeId&&this._getMindMapChildren(r,t.scopeId,e.elementId).length>0?{nodeId:e.elementId,collapsed:i.collapsed}:null}).filter(e=>!!e);if(i.length===0)return!1;let a=i.some(e=>!e.collapsed),o=e.commandService,s=this._undoRedoGroupService.createRunner(t.unitId),c=i.map(e=>s(()=>o.executeCommand(n.ToggleMindMapNodeCollapseOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:e.nodeId,collapsed:a})));return Promise.all(c.map(e=>Promise.resolve(e))).then(e=>{e.some(Boolean)&&s(()=>o.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId}))}),!0}_openSelectedTextEditing(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;e.elementStateService.selectElements({unitId:t.unitId,subUnitId:t.subUnitId},[t.nodeId],t.nodeId);let n=e.textEditingService;return n.ignoreExternalFocusChanges(),n.setEditing({unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.nodeId,shapeKey:(0,r.getBoardElementRenderObjectKey)(t.unitId,t.nodeId),visible:!0}),!0}_openDescriptionDialog(e){let t=this._getSelectedMindMapContext(e);return t?(e.dialogService.open({id:qe,title:{title:`boards-mind-ui.description`},width:420,draggable:!0,mask:!1,maskClosable:!0,children:{label:Ke,unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,initialDescription:t.description}}),!0):!1}_navigateByTopology(e,t){let r=this._getSelectedMindMapContext(e);if(!r)return!1;let i=e.elementService.getElementData(r.unitId,r.subUnitId),a=i[r.nodeId],o=(0,n.getMindMapNodeMeta)(a==null?void 0:a.element);if(!a||!o)return!1;let s={"arrow-left":`ArrowLeft`,"arrow-right":`ArrowRight`,"arrow-up":`ArrowUp`,"arrow-down":`ArrowDown`}[t];if(!s)return!1;let c=this._resolveArrowNavigationTarget(i,r.nodeId,o,s);return c?(e.elementStateService.selectElements({unitId:r.unitId,subUnitId:r.subUnitId},[c],c),!0):!1}_resolveArrowNavigationTarget(e,t,r,i){let a=this._getMindMapChildren(e,r.structureScopeId,t);if(r.parentNodeId===null){if(i===`ArrowLeft`){var o;return((o=a.find(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.side)===`left`}))==null?void 0:o.elementId)??null}if(i===`ArrowRight`){var s;return((s=a.find(e=>{var t;return(((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.side)??`right`)===`right`}))==null?void 0:s.elementId)??null}return null}let c=r.side??`right`,l=c===`right`?`ArrowLeft`:`ArrowRight`,u=c===`right`?`ArrowRight`:`ArrowLeft`;if(i===l)return r.parentNodeId;if(i===u){var d;return((d=a[0])==null?void 0:d.elementId)??null}if(i===`ArrowUp`||i===`ArrowDown`){let n=this._getMindMapChildren(e,r.structureScopeId,r.parentNodeId),a=n.findIndex(e=>e.elementId===t),o=i===`ArrowUp`?n[a-1]:n[a+1];return(o==null?void 0:o.elementId)??null}return null}_getMindMapChildren(e,t,r){return Object.values(e).filter(e=>{let i=(0,n.getMindMapNodeMeta)(e.element);return(i==null?void 0:i.structureScopeId)===t&&i.parentNodeId===r&&e.element.visible!==!1}).sort((e,t)=>{let r=(0,n.getMindMapNodeMeta)(e.element),i=(0,n.getMindMapNodeMeta)(t.element);return(0,n.compareMindMapOrderKey)(r==null?void 0:r.orderKey,i==null?void 0:i.orderKey)||e.elementId.localeCompare(t.elementId)})}_getSelectedMindMapContext(e){var t;let r=e.elementStateService.getSnapshot(),i=r.focusedId??r.selectedIds[0];if(!i||r.selectedIds.length!==1||r.activeEditingId||r.isTransforming)return null;let a=r.context??{unitId:e.renderContext.unitId,subUnitId:e.renderContext.unit.getActivePageId()},o=e.elementService.getElementData(a.unitId,a.subUnitId)[i],s=(0,n.getMindMapNodeMeta)(o==null?void 0:o.element);return!o||!s?null:{unitId:a.unitId,subUnitId:a.subUnitId,nodeId:i,scopeId:s.structureScopeId,isRoot:s.parentNodeId===null,description:((t=s.foreignAttributes)==null?void 0:t._note)??``}}_getBlankBoardContext(e){var t,n;let r=e.elementStateService.getSnapshot();return r.activeEditingId||r.isTransforming||r.selectedIds.length>0||r.focusedId?null:{unitId:((t=r.context)==null?void 0:t.unitId)??e.renderContext.unitId,subUnitId:((n=r.context)==null?void 0:n.subUnitId)??e.renderContext.unit.getActivePageId()}}_executeAndLayout(e,t,r,i){let a=e.commandService,o=this._undoRedoGroupService.createRunner(r.unitId),s=o(()=>a.executeCommand(t,r));Promise.resolve(s).then(e=>{e&&o(()=>a.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:i}))})}_executeCreateAndEdit(e,t,i,a,o){let s={unitId:i.unitId,subUnitId:i.subUnitId},c=e.commandService,l=this._undoRedoGroupService.createRunner(i.unitId),u=l(()=>c.executeCommand(t,i));Promise.resolve(u).then(t=>{if(!t)return;l(()=>c.executeCommand(n.LayoutMindMapOperation.id,{...s,scopeId:a})),e.elementStateService.selectElements(s,[o],o);let i=e.textEditingService;i.ignoreExternalFocusChanges(),i.setEditing({...s,shapeId:o,shapeKey:(0,r.getBoardElementRenderObjectKey)(s.unitId,o),visible:!0})})}};V=C([S(0,n.IMindMapClipboardService),S(1,a.ICommandService),S(2,c.IShortcutService),S(3,(0,a.Inject)(c.UndoRedoGroupService))],V);function et(e,t){var n,r;let i=typeof(t==null?void 0:t.unitId)==`string`?t.unitId:(n=e.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_BOARD))==null?void 0:n.getUnitId();return i?((r=e.get(o.IRenderManagerService).getRenderUnitById(i))==null?void 0:r.with(z))??null:null}function tt(e){return e===`arrow-left`||e===`arrow-right`||e===`arrow-up`||e===`arrow-down`}let nt={min:1,max:5,defaultValue:3},rt={min:0,max:100,defaultValue:100},it=[{kind:`dropdown`,titleKey:`boards-mind-ui.toolbar.primary.line`,panel:`line`},{kind:`fontColor`,titleKey:`boards-mind-ui.toolbar.primary.fontColor`},{kind:`typography`,titleKey:`boards-mind-ui.toolbar.primary.typography`},{kind:`dropdown`,titleKey:`boards-mind-ui.toolbar.primary.more`,panel:`more`,dividerBefore:!0}],H={addSibling:`add-sibling-or-child`,addChild:`add-child`,copy:`copy`,paste:`paste`,delete:`delete`},at=[{key:`mind-map`,title:`Mind map`,items:[{value:`mindmap-horizontal`,icon:`mindmap-horizontal`,labelKey:`boards-mind-ui.panel.structureKind.mindmapHorizontal`},{value:`mindmap-vertical`,icon:`mindmap-vertical`,labelKey:`boards-mind-ui.panel.structureKind.mindmapVertical`}]},{key:`tree-diagram`,title:`Tree diagram`,items:[{value:`tree-right`,icon:`tree-right`,labelKey:`boards-mind-ui.panel.structureKind.treeRight`},{value:`tree-left`,icon:`tree-left`,labelKey:`boards-mind-ui.panel.structureKind.treeLeft`},{value:`tree-alternate`,icon:`tree-alternate`,labelKey:`boards-mind-ui.panel.structureKind.treeAlternate`}]},{key:`timeline`,title:`Timeline`,items:[{value:`timeline-horizontal`,icon:`timeline-horizontal`,labelKey:`boards-mind-ui.panel.structureKind.timelineHorizontal`},{value:`timeline-vertical`,icon:`timeline-vertical`,labelKey:`boards-mind-ui.panel.structureKind.timelineVertical`}]}],ot={key:`branch`,title:`Branch`,items:[{value:`curve`,icon:`branch-curve`,labelKey:`boards-mind-ui.panel.branchLineType.curve`},{value:`rounded-orthogonal`,icon:`branch-rounded-orthogonal`,labelKey:`boards-mind-ui.panel.branchLineType.roundedOrthogonal`},{value:`orthogonal`,icon:`branch-orthogonal`,labelKey:`boards-mind-ui.panel.branchLineType.orthogonal`}]},st=`board.mind-map.floating-toolbar`;function ct(e,t){e.executeCommand(B,{action:t})}let lt={line:ze,more:Ne};function U(e){e.stopPropagation(),e.preventDefault()}function ut(e,t=`univer-size-5`,n){return/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarIcon,{children:/* @__PURE__ */ (0,p.jsx)(e,{className:t,extend:n})})}function dt(e){var t,n;let r=(e==null?void 0:e.shapeText)??{},i=r.dataModel&&typeof r.dataModel==`object`?r.dataModel:{},o=(t=i.doc)==null||(t=t.documentStyle)==null?void 0:t.textStyle;return{color:typeof r.color==`string`?r.color:(o==null||(n=o.cl)==null?void 0:n.rgb)??l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_COLOR,fontFamily:typeof r.fontFamily==`string`?r.fontFamily:(o==null?void 0:o.ff)??a.DEFAULT_STYLES.ff,fontSize:typeof r.fontSize==`number`?r.fontSize:typeof(o==null?void 0:o.fs)==`number`?o.fs:a.DEFAULT_STYLES.fs,horizontalAlign:r.horizontalAlign??i.ha??a.HorizontalAlign.LEFT,textFill:r.textFill&&typeof r.textFill==`object`?r.textFill:o==null?void 0:o.textFill,verticalAlign:r.verticalAlign??i.va??a.VerticalAlign.MIDDLE}}function ft(e,t){if(!t)return;let n=$e(t);if(!n.length)return;let r=n.map(n=>e.getShortcutDisplay({id:`board.operation.mind-map.keyboard-shortcut`,binding:n,staticParameters:{action:t}})??void 0).filter(e=>!!e);return r.length?[...new Set(r)].join(`/`):void 0}async function pt(e,t,r){return await Promise.resolve(t(()=>e.executeCommand(n.ChangeMindMapLayoutOperation.id,r)))?(await Promise.resolve(t(()=>e.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:r.scopeId}))),!0):!1}async function mt(e,t,r){return await Promise.resolve(t(()=>e.executeCommand(n.ChangeMindMapBranchLineTypeOperation.id,r)))?(await Promise.resolve(t(()=>e.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:r.scopeId}))),!0):!1}function ht({className:e=`univer-size-5`}){return/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarIcon,{children:/* @__PURE__ */ (0,p.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M4.5 7.5h4.2c1.9 0 3.3 1.5 3.3 3.3v2.4c0 1.8 1.4 3.3 3.3 3.3h4.2`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M19.5 7.5h-4.2c-1.9 0-3.3 1.5-3.3 3.3`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M4.5 16.5h4.2c1.9 0 3.3-1.5 3.3-3.3`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`})]})})}function gt({icon:e}){let t=`#d8dce3`,n={stroke:`currentColor`,strokeWidth:2.6,strokeLinecap:`round`,strokeLinejoin:`round`},r={stroke:t,strokeWidth:3.2,strokeLinecap:`round`};return/* @__PURE__ */ (0,p.jsxs)(`svg`,{className:`univer-h-9 univer-w-12`,viewBox:`0 0 80 56`,fill:`none`,"aria-hidden":`true`,children:[e===`mindmap-horizontal`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M31 13c9 8 9 22 18 30M49 13c-9 8-9 22-18 30M31 13c-7 4-9 9-9 15s2 11 9 15M49 13c7 4 9 9 9 15s-2 11-9 15`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M12 15h9M12 28h9M12 41h9M59 15h9M59 28h9M59 41h9`,...r})]}),e===`mindmap-vertical`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M21 28h38M40 11v34M28 16c7 4 10 8 12 12 2-4 5-8 12-12M28 40c7-4 10-8 12-12 2 4 5 8 12 12`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M22 8h36M22 48h36M14 18v20M66 18v20`,stroke:t,strokeWidth:2.6,strokeLinecap:`round`,strokeDasharray:`6 7`})]}),e===`tree-right`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M24 12v32M24 19c0 4 3 6 7 6h7M24 29c0 4 3 6 7 6h7M24 39c0 4 3 6 7 6h7`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M47 25h13M47 35h13M47 45h13`,...r}),/* @__PURE__ */ (0,p.jsx)(`circle`,{cx:`24`,cy:`12`,r:`3`,fill:`currentColor`})]}),e===`tree-left`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M56 12v32M56 19c0 4-3 6-7 6h-7M56 29c0 4-3 6-7 6h-7M56 39c0 4-3 6-7 6h-7`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M20 25h13M20 35h13M20 45h13`,...r}),/* @__PURE__ */ (0,p.jsx)(`circle`,{cx:`56`,cy:`12`,r:`3`,fill:`currentColor`})]}),e===`tree-alternate`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M42 12v32M42 20c0 4-3 6-7 6h-7M42 30c0 4 3 6 7 6h7M42 39c0 4-3 6-7 6h-7`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M12 26h11M58 36h11M12 45h11`,...r}),/* @__PURE__ */ (0,p.jsx)(`circle`,{cx:`42`,cy:`12`,r:`3`,fill:`currentColor`})]}),e===`timeline-horizontal`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M15 31h50M35 31V18c0-4 3-7 8-7h9M35 31v13c0 4 3 7 8 7h9`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M56 11h11M56 51h11`,...r}),/* @__PURE__ */ (0,p.jsx)(`circle`,{cx:`17`,cy:`31`,r:`3`,fill:`currentColor`})]}),e===`timeline-vertical`&&/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M40 9v40M40 20c8 0 11 4 11 11v8M40 35c-8 0-11 4-11 11v4`,...n}),/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M56 39h11M13 50h11`,...r}),/* @__PURE__ */ (0,p.jsx)(`circle`,{cx:`40`,cy:`9`,r:`3`,fill:`currentColor`})]}),e===`branch-curve`&&/* @__PURE__ */ (0,p.jsx)(p.Fragment,{children:/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M16 28c16 0 25-13 43-13M16 28c16 0 25 13 43 13`,...n})}),e===`branch-rounded-orthogonal`&&/* @__PURE__ */ (0,p.jsx)(p.Fragment,{children:/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M16 29h18c7 0 10-5 10-12v-3M34 29h10c7 0 10 5 10 12v3`,...n})}),e===`branch-orthogonal`&&/* @__PURE__ */ (0,p.jsx)(p.Fragment,{children:/* @__PURE__ */ (0,p.jsx)(`path`,{d:`M17 33h21M38 17v30M38 17h24`,...n})})]})}function _t(e,n){let r=e.textStyle,i=(0,t.documentTextStyleToBoardShapeTextStyle)(r),a={...i.color===void 0?null:{color:i.color},...i.fontFamily===void 0?null:{fontFamily:i.fontFamily},...i.fontSize===void 0?null:{fontSize:i.fontSize},...i.bold===void 0?null:{bold:i.bold},...i.italic===void 0?null:{italic:i.italic},...i.underline===void 0?null:{underline:i.underline},...i.strikethrough===void 0?null:{strikethrough:i.strikethrough},...i.textFill===void 0?null:{textFill:i.textFill}};e.horizontalAlign!==void 0&&(a.horizontalAlign=e.horizontalAlign),e.verticalAlign!==void 0&&(a.verticalAlign=e.verticalAlign),Object.keys(a).length>0&&n({textStyle:a})}function vt(e,t,n){let r=e??{},i=(0,l.buildShapeTextDataUpdate)(r,t),a=i.shapeText??r.shapeText??{};return{...r,...i,shapeText:{...a,...n.color===void 0?null:{color:n.color},...n.fontSize===void 0?null:{fontSize:n.fontSize},...n.bold===void 0?null:{bold:n.bold},...n.italic===void 0?null:{italic:n.italic},...n.underline===void 0?null:{underline:n.underline},...n.strikethrough===void 0?null:{strikethrough:n.strikethrough},...n.horizontalAlign===void 0?null:{horizontalAlign:n.horizontalAlign},...n.verticalAlign===void 0?null:{verticalAlign:n.verticalAlign},...n.textFill===void 0?null:{textFill:n.textFill}}}}function yt(e,t){let n=e==null?void 0:e.stroke;n&&t({lineType:n.dashType===u.ShapeLineDashEnum.RoundDot||n.dashType===u.ShapeLineDashEnum.SquareDot?`dot`:n.dashType===u.ShapeLineDashEnum.Dash?`dash`:`solid`,...typeof n.width==`number`?{strokeWidth:n.width}:null,...typeof n.color==`string`?{stroke:n.color}:null,...typeof n.opacity==`number`?{opacity:n.opacity}:null})}function bt(e){return e!=null&&e.length?e[0]<=2?u.ShapeLineDashEnum.RoundDot:u.ShapeLineDashEnum.Dash:u.ShapeLineDashEnum.Solid}function xt(e){return{stroke:{lineStrokeType:u.ShapeLineTypeEnum.SolidLine,dashType:bt(e==null?void 0:e.dash),color:(e==null?void 0:e.stroke)??l.SHAPE_FLOATING_TOOLBAR_DEFAULT_STROKE_COLOR,width:(e==null?void 0:e.strokeWidth)??nt.defaultValue,opacity:(e==null?void 0:e.opacity)??rt.defaultValue/100}}}function St(e){var t,r,i;let o=(0,c.useDependency)(a.ICommandService),s=(0,c.useDependency)(c.IShortcutService),u=(0,c.useDependency)(a.LocaleService),m=(0,c.useDependency)(c.UndoRedoGroupService),[h,g]=(0,f.useState)(null),[_,v]=(0,f.useState)((t=e.popup.extraProps)==null?void 0:t.shapeData),y=e.popup.extraProps;if(!y)return null;let b={unitId:y.unitId,subUnitId:y.subUnitId},x=e=>{o.executeCommand(n.UpdateMindMapNodeOperation.id,{...b,nodeId:y.elementId,...e})},S=(e,t)=>{let n=t??{};v(e=>({...e??{},...n})),x({...n.fill===void 0?null:{fill:n.fill},...n.stroke===void 0?null:{stroke:n.stroke}})},C=e=>{o.executeCommand(n.UpdateMindMapIncomingConnectorOperation.id,{...b,nodeId:y.elementId,style:e})},w=xt(y.incomingConnectorStyle),T=e=>ft(s,e),E=e=>{ct(o,e)},D=(_==null?void 0:_.shapeText)??{},O=dt(_),k=e=>{_t(e,t=>{v(n=>vt(n,e,t.textStyle)),x(t)})},A=[{label:u.t(`boards-mind-ui.alignLeft`),value:a.HorizontalAlign.LEFT,icon:/* @__PURE__ */ (0,p.jsx)(je,{})},{label:u.t(`boards-mind-ui.alignCenter`),value:a.HorizontalAlign.CENTER,icon:/* @__PURE__ */ (0,p.jsx)(De,{})},{label:u.t(`boards-mind-ui.alignRight`),value:a.HorizontalAlign.RIGHT,icon:/* @__PURE__ */ (0,p.jsx)(Fe,{})},{label:u.t(`boards-mind-ui.alignJustify`),value:a.HorizontalAlign.JUSTIFIED,icon:/* @__PURE__ */ (0,p.jsx)(xe,{})}],j=[{label:u.t(`boards-mind-ui.alignTop`),value:a.VerticalAlign.TOP,icon:/* @__PURE__ */ (0,p.jsx)(Ce,{})},{label:u.t(`boards-mind-ui.alignMiddle`),value:a.VerticalAlign.MIDDLE,icon:/* @__PURE__ */ (0,p.jsx)(Ge,{})},{label:u.t(`boards-mind-ui.alignBottom`),value:a.VerticalAlign.BOTTOM,icon:/* @__PURE__ */ (0,p.jsx)(ye,{})}],M=()=>{E(`add-sibling-or-child`)},N=()=>{E(`add-child`)},P=()=>{E(`copy`)},F=()=>{E(`paste`)},ee=()=>{E(`delete`)},te=((r=y.layout)==null?void 0:r.structureKind)??n.MIND_MAP_DEFAULT_LAYOUT.structureKind,I=(0,n.resolveMindMapBranchLineTypeForStructure)(te,((i=y.layout)==null?void 0:i.branchLineType)??n.MIND_MAP_DEFAULT_LAYOUT.branchLineType),ne=e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(e,I);pt(o,m.createRunner(y.unitId),{...b,scopeId:y.scopeId,structureKind:e,...t===I?null:{branchLineType:t}}),g(null)},re=e=>{mt(o,m.createRunner(y.unitId),{...b,scopeId:y.scopeId,branchLineType:e}),g(null)},ie=(e,t,n,r=!1)=>/* @__PURE__ */ (0,p.jsx)(`button`,{type:`button`,"aria-label":u.t(e.labelKey),disabled:r,className:(0,d.clsx)(`univer-flex univer-h-12 univer-min-w-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent univer-p-0 univer-text-gray-900 univer-outline-none univer-transition-colors hover:univer-bg-gray-0`,t&&`univer-bg-[#e8eefc] univer-text-[#2f6fed] hover:univer-bg-[#e8eefc]`,r&&`univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent`),onMouseDown:U,onPointerDown:U,onClick:e=>{e.stopPropagation(),r||n()},children:/* @__PURE__ */ (0,p.jsx)(gt,{icon:e.icon})},e.value),ae=()=>/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-w-[202px] univer-rounded-xl univer-border univer-border-gray-200 univer-bg-gray-0 univer-px-4 univer-py-4 univer-shadow-lg`,onMouseDown:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[at.map(e=>/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-mb-2 univer-text-lg univer-text-gray-900`,children:e.title}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-h-14 univer-overflow-hidden univer-rounded-xl univer-bg-gray-100 univer-p-1`,style:{gridTemplateColumns:`repeat(${e.items.length}, minmax(0, 1fr))`},children:e.items.map(e=>ie(e,e.value===te,()=>ne(e.value)))})]},e.key)),/* @__PURE__ */ (0,p.jsx)(d.Separator,{}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-mb-0`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-mb-2 univer-text-lg univer-text-gray-900`,children:ot.title}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-h-14 univer-overflow-hidden univer-rounded-xl univer-bg-gray-100 univer-p-1`,style:{gridTemplateColumns:`repeat(${ot.items.length}, minmax(0, 1fr))`},children:ot.items.map(e=>ie(e,e.value===I,()=>re(e.value),e.value===`curve`&&!(0,n.isMindMapPlainStructureKind)(te)))})]})]}),oe=e=>{switch(e){case`line`:return/* @__PURE__ */ (0,p.jsx)(l.ShapeStrokePanelContent,{title:u.t(`boards-mind-ui.toolbar.panel.line`),shapeData:w,modeOptions:[`solid`,`dash`,`dot`],showDashDropdown:!1,widthRange:{min:nt.min,max:nt.max,step:1},onUpdateShapeData:(e,t)=>{yt(t,C)}});case`more`:return/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuPanel,{title:u.t(`boards-mind-ui.toolbar.panel.more`),minWidthClassName:`univer-min-w-[240px]`,children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.addSibling`),shortcut:T(H.addSibling),onClick:M}),/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.addChild`),shortcut:T(H.addChild),onClick:N}),/* @__PURE__ */ (0,p.jsx)(d.Separator,{}),/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.copy`),shortcut:T(H.copy),onClick:P}),/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.paste`),shortcut:T(H.paste),onClick:F}),/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.delete`),shortcut:T(H.delete),onClick:ee})]})});default:return null}},se=it.flatMap(e=>{let t=[];if(e.dividerBefore&&t.push(/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`divider-${e.kind}`)),e.kind===`typography`)return t.push(/* @__PURE__ */ (0,p.jsx)(l.TypographyPanelButton,{title:u.t(`boards-mind-ui.toolbar.panel.typography`),fontFamily:O.fontFamily,textStyle:{isBold:D.bold===!0,isItalic:D.italic===!0,isUnderline:D.underline===!0,isStrike:D.strikethrough===!0},horizontalAlign:O.horizontalAlign,verticalAlign:O.verticalAlign,horizontalAlignOptions:A,verticalAlignOptions:j,onUpdateText:k},e.kind)),t;if(e.kind===`fontColor`){let n={fs:O.fontSize,cl:{rgb:O.color},...O.textFill===void 0?null:{textFill:O.textFill}};return t.push(/* @__PURE__ */ (0,p.jsx)(l.TextFillButton,{title:u.t(`boards-mind-ui.toolbar.action.fontColor`),textStyle:n,fallbackColor:O.color,onChange:e=>k({textStyle:e})},e.kind)),t.push(/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarFontSizeSelect,{value:String(O.fontSize),onChange:e=>{k({textStyle:{fs:e}})}},`mind-map-font-size`)),t}return t.push(/* @__PURE__ */ (0,p.jsx)(d.Dropdown,{open:h===e.panel,overlay:oe(e.panel),onOpenChange:t=>g(t?e.panel:null),children:/* @__PURE__ */ (0,p.jsx)(`span`,{children:/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarDropdownTrigger,{title:u.t(e.titleKey),active:h===e.panel,icon:ut(lt[e.panel]),sizeClassName:`univer-h-7 univer-min-w-9 univer-w-auto univer-gap-1 univer-px-1.5`,onMouseDown:U,onPointerDown:U})})},e.panel)),t}),L=[...y.isRootNode?[/* @__PURE__ */ (0,p.jsx)(d.Dropdown,{open:h===`layout`,overlay:ae(),onOpenChange:e=>g(e?`layout`:null),children:/* @__PURE__ */ (0,p.jsx)(`span`,{children:/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarDropdownTrigger,{title:u.t(`boards-mind-ui.toolbar.action.layout`),active:h===`layout`,icon:/* @__PURE__ */ (0,p.jsx)(ht,{}),sizeClassName:`univer-h-7 univer-min-w-9 univer-w-auto univer-gap-1 univer-px-1.5`,onMouseDown:U,onPointerDown:U})})},`mind-map-layout-dropdown`),/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`layout-panel-divider`)]:[],/* @__PURE__ */ (0,p.jsx)(l.ShapeFillButton,{title:u.t(`boards-mind-ui.toolbar.action.fill`),shapeData:_??{},onUpdateShapeData:S},`mind-map-fill`),/* @__PURE__ */ (0,p.jsx)(l.ShapeStrokePanelButton,{title:u.t(`boards-mind-ui.toolbar.action.stroke`),shapeData:_??{},onUpdateShapeData:S},`mind-map-stroke`),/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`style-divider`)];return/* @__PURE__ */ (0,p.jsxs)(l.ShapeFloatingToolbarContent,{maxWidthClassName:`univer-max-w-[min(760px,calc(100vw-32px))]`,onMouseDown:e=>e.stopPropagation(),children:[L,se]})}function Ct(e){let{left:t,top:n,width:r,height:i}=e;return{left:t,right:t+r,top:n-56,bottom:n+i}}let wt=class extends a.RxDisposable{constructor(e,t,n,r,i,a){super(),this._renderContext=e,this._boardCanvasPopManagerService=t,this._boardElementService=n,this._elementStateService=r,this._boardTextEditingService=i,this._interactionSurfaceService=a,x(this,`_popupDisposable`,null),x(this,`_popupSelectionKey`,null),this._init()}dispose(){this._clearPopup(),super.dispose()}_init(){let e=this._renderContext.scene.getTransformerByCreate();this.disposeWithMe((0,a.toDisposable)(e.createControl$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._showPopupForSelection()))),this.disposeWithMe((0,a.toDisposable)(e.clearControl$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._clearPopupIfSelectionChanged()))),this.disposeWithMe((0,a.toDisposable)(e.changeStart$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._clearPopup()))),this.disposeWithMe((0,a.toDisposable)(e.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>setTimeout(()=>this._showPopupForSelection(),0)))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>setTimeout(()=>this._showPopupForSelection(),0)))),this.disposeWithMe((0,a.toDisposable)(this._interactionSurfaceService.interactionSurfaceActive$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e?this._clearPopup():setTimeout(()=>this._showPopupForSelection(),0)}))),this.disposeWithMe((0,a.toDisposable)(this._boardTextEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{(e==null?void 0:e.unitId)===this._renderContext.unitId&&(e.visible?this._clearPopup():setTimeout(()=>this._showPopupForSelection(),0))})))}_clearPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null,this._popupSelectionKey=null}_clearPopupIfSelectionChanged(){setTimeout(()=>{this._isPopupSelectionStillActive()||this._clearPopup()},0)}_isPopupSelectionStillActive(){let e=this._elementStateService.getSnapshot();return!!e.context&&e.selectedIds.length>0&&this._popupSelectionKey===this._buildPopupSelectionKey(e.context.unitId,e.context.subUnitId,e.selectedIds)}_buildPopupSelectionKey(e,t,n){return`${e}:${t}:${n.join(`,`)}`}_resolveIncomingConnectorStyle(e,t,r,i){let a=this._boardElementService.getElementData(e,t),o=Object.values(a).find(e=>{let t=(0,n.getMindMapConnectorMeta)(e.element);return(t==null?void 0:t.structureScopeId)===r&&t.childNodeId===i});if(o&&`connectorData`in o.element)return o.element.connectorData.style}_showPopupForSelection(){var e,i,a;if(this._interactionSurfaceService.isInteractionSurfaceActive){this._clearPopup();return}let o=this._boardTextEditingService.getEditing();if((o==null?void 0:o.visible)===!0&&o.unitId===this._renderContext.unitId){this._clearPopup();return}let s=this._elementStateService.getSnapshot();if(s.isTransforming||(0,r.resolveBoardFloatingToolbarSelection)({context:s.context,selectedIds:s.selectedIds,getElementById:(e,t,n)=>this._boardElementService.getElementById(e,t,n)}).owner!==`mind-map`){this._clearPopup();return}let c=this._renderContext.scene.getTransformerByCreate().getSelectedObjectMap(),l=Array.from(c.values()).map(e=>this._resolveSelectedEntry(e)).filter(e=>!!e).filter(e=>!!(0,n.getMindMapNodeMeta)(e.elementData.element)),u=l.find(e=>e.elementData.elementId===s.focusedId)??l[0]??this._resolveSelectedMindMapEntryFromState();if(!u){this._clearPopup();return}let d=(0,n.getMindMapNodeMeta)(u.elementData.element);if(!d){this._clearPopup();return}let f=(e=this._boardElementService.getElementData(u.elementData.unitId,u.elementData.subUnitId)[d.structureScopeId])==null?void 0:e.element,p=(0,n.getMindMapContainerMeta)(f),m=f==null||(i=f.custom)==null||(i=i.mindmap)==null||(i=i.layout)==null?void 0:i.structureKind,h=((p==null?void 0:p.layout.structureKind)??m)===`mindmap-vertical`&&(d.parentNodeId===null||d.side===`top`),g=d.parentNodeId!==null&&d.side!==`top`&&d.side!==`bottom`,_=h||g,v=((a=s.context)==null?void 0:a.unitId)===u.elementData.unitId&&s.context.subUnitId===u.elementData.subUnitId&&s.selectedIds.length?s.selectedIds:[u.elementData.elementId],y=this._buildPopupSelectionKey(u.elementData.unitId,u.elementData.subUnitId,v);this._popupDisposable&&this._popupSelectionKey===y||(this._clearPopup(),this._popupDisposable=this.disposeWithMe(this._boardCanvasPopManagerService.attachPopupToObject(u.elementData.unitId,u.elementData.subUnitId,u.object,{componentKey:st,direction:`top-center`,offset:[0,8],..._?{anchorBoundResolver:Ct}:null,extraProps:{unitId:u.elementData.unitId,subUnitId:u.elementData.subUnitId,elementId:u.elementData.elementId,scopeId:d.structureScopeId,isRootNode:d.parentNodeId===null,left:u.elementData.element.transform.left??0,top:u.elementData.element.transform.top??0,shapeData:u.elementData.element.type===t.BoardElementType.Shape?u.elementData.element.shapeData:void 0,layout:p==null?void 0:p.layout,incomingConnectorStyle:this._resolveIncomingConnectorStyle(u.elementData.unitId,u.elementData.subUnitId,d.structureScopeId,u.elementData.elementId)}})),this._popupSelectionKey=y)}_resolveSelectedMindMapEntryFromState(){var e;let t=this._elementStateService.getSnapshot(),i=t.context,a=t.focusedId??t.selectedIds[0];if(!i||!a)return null;let o=this._boardElementService.getElementById(i.unitId,i.subUnitId,a);if(!o||!(0,n.getMindMapNodeMeta)(o.element))return null;let s=(0,r.getBoardElementRenderObjectKey)(i.unitId,a),c=this._renderContext.scene,l=((e=c.getObjectIncludeInGroup)==null?void 0:e.call(c,s))??this._renderContext.scene.getObject(s);return l?{object:l,elementData:o}:null}_resolveSelectedEntry(e){var t;if(!e)return null;let n=(0,r.parseBoardElementRenderObjectKey)(e.oKey);if(!n)return null;let i=this._elementStateService.getSnapshot(),a=((t=i.context)==null?void 0:t.unitId)===n.unitId?i.context.subUnitId:void 0;if(!a)return null;let o=this._boardElementService.getElementById(n.unitId,a,n.elementId);return o?{object:e,elementData:o}:null}};wt=C([S(1,(0,a.Inject)(r.BoardCanvasPopManagerService)),S(2,(0,a.Inject)(t.IBoardElementService)),S(3,(0,a.Inject)(r.IBoardElementStateService)),S(4,(0,a.Inject)(r.BoardTextEditingService)),S(5,(0,a.Inject)(r.BoardInteractionSurfaceService))],wt);let Tt=`board-mind-map-pending-insert-object`,Et=r.BOARD_RENDER_LAYER_INDEX.preview;var Dt=class extends o.BaseObject{constructor(e=Tt,t){super(e),x(this,`_state`,{point:null,children:[]}),x(this,`_preview`,null),this.evented=!1,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientPreview,this.updateState(t)}updateState(e){let t=this._state;if(this._state={...t,...e},!this._preview||t.structureKind!==this._state.structureKind||t.rootText!==this._state.rootText||t.branchLineType!==this._state.branchLineType||!a.Tools.diffValue(t.children,this._state.children)||!a.Tools.diffValue(t.blueprint,this._state.blueprint)){let e={left:0,top:0,structureKind:this._state.structureKind,branchLineType:this._state.branchLineType},t=this._state.blueprint;t&&this._state.rootText&&(t={...t,root:{...t.root,text:this._state.rootText}}),this._preview=t?(0,n.createMindMapElementsFromBlueprint)({...e,blueprint:t}):(0,n.createMindMapElements)({...e,rootText:this._state.rootText,children:this._state.children})}this._state.point?this.show():this.hide(),this.makeDirty(!0)}isHit(e){return!1}getRootTopLeft(e){var t,r;return{left:Math.round(e.x-(((t=this._preview)==null?void 0:t.rootNode.transform.width)??n.MIND_MAP_DEFAULT_NODE_SIZE.rootWidth)/2),top:Math.round(e.y-(((r=this._preview)==null?void 0:r.rootNode.transform.height)??n.MIND_MAP_DEFAULT_NODE_SIZE.rootHeight)/2)}}render(e,t){var r;let i=this._state.point,a=this._preview;if(!i||!a||!this.visible)return this.makeDirty(!1),this;let o=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,s=a.rootNode.transform.width??n.MIND_MAP_DEFAULT_NODE_SIZE.rootWidth,c=a.rootNode.transform.height??n.MIND_MAP_DEFAULT_NODE_SIZE.rootHeight,l=this.getRootTopLeft(i),u=l.left-(a.rootNode.transform.left??0),d=l.top-(a.rootNode.transform.top??0),f=u-(a.container.transform.left??0),p=d-(a.container.transform.top??0);e.save(),e.globalAlpha=D.objectAlpha,e.lineWidth=D.lineWidthScreen/o,e.strokeStyle=D.primaryColor,e.beginPath();for(let t of((r=a.container.containerData.shapeData.customGeometry)==null?void 0:r.pathLst)??[])for(let n of t.dataArray??[]){let t=Number(n.points[0])+u,r=Number(n.points[1])+d;n.command===`M`?e.moveTo(t,r):n.command===`L`&&e.lineTo(t,r)}for(let t of a.connectors){var m;if(t.visible===!1)continue;let n=t.connectorData,r=n.start.kind===`free`?n.start:n.start.fallbackPoint,i=n.end.kind===`free`?n.end:n.end.fallbackPoint;if(!r||!i)continue;e.moveTo(r.x+f,r.y+p);let a=(m=n.curveData)==null?void 0:m.controls;if(n.routing===`curve`&&a&&a.length>=2)e.bezierCurveTo(a[0].x+f,a[0].y+p,a[1].x+f,a[1].y+p,i.x+f,i.y+p);else{var h;for(let t of((h=n.orthogonalData)==null?void 0:h.routePoints)??[])e.lineTo(t.x+f,t.y+p);e.lineTo(i.x+f,i.y+p)}}e.stroke();for(let t of a.nodes)t.id!==a.rootNode.id&&t.visible!==!1&&(O(e,u+(t.transform.left??0),d+(t.transform.top??0),t.transform.width??n.MIND_MAP_DEFAULT_NODE_SIZE.nodeWidth,t.transform.height??n.MIND_MAP_DEFAULT_NODE_SIZE.nodeHeight,D.ghostRadius),e.fillStyle=D.ghostFillColor,e.fill(),e.stroke());O(e,l.left,l.top,s,c,D.rootRadius),e.fillStyle=D.primaryColor,e.fill(),e.stroke(),e.fillStyle=D.rootTextColor,e.font=k(D.rootFontWeight,D.rootFontSize,o),e.textAlign=`center`,e.textBaseline=`middle`;let g=D.textPaddingScreen/o;return e.fillText(n.MIND_MAP_DEFAULT_NODE_TEXT,l.left+s/2,l.top+c/2,Math.max(1,s-g*2)),e.restore(),this.makeDirty(!1),this}};let Ot={children:[{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(0),side:`right`},{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(1),side:`right`},{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(2),side:`right`}]};var W=class extends a.Disposable{constructor(...e){super(...e),x(this,`_template`,Ot)}setTemplate(e){var t;let n=(e==null?void 0:e.children)??(e==null||(t=e.blueprint)==null?void 0:t.root.children);this._template={rootText:e==null?void 0:e.rootText,structureKind:e==null?void 0:e.structureKind,branchLineType:e==null?void 0:e.branchLineType,children:this._normalizeChildren(n,e==null?void 0:e.structureKind),blueprint:e!=null&&e.blueprint?this._cloneBlueprint(e.blueprint):void 0}}getTemplate(){var e;return{rootText:this._template.rootText,structureKind:this._template.structureKind,branchLineType:this._template.branchLineType,children:(e=this._template.children)==null?void 0:e.map(e=>({...e})),blueprint:this._template.blueprint?this._cloneBlueprint(this._template.blueprint):void 0}}_cloneBlueprint(e){return{title:e.title,root:this._cloneBlueprintNode(e.root)}}_cloneBlueprintNode(e){return{...e,foreignAttributes:e.foreignAttributes?{...e.foreignAttributes}:void 0,children:e.children.map(e=>this._cloneBlueprintNode(e))}}_normalizeChildren(e,t){let r=!e,i=e??Ot.children;return i==null?void 0:i.map((e,i)=>({...e,text:e.text??n.MIND_MAP_DEFAULT_NODE_TEXT,side:this._resolveChildSide(e.side,i,t,r)}))}_resolveChildSide(e,t,n,r){return n===`mindmap-vertical`?r?`bottom`:e??`bottom`:n===`tree-left`?r?`left`:e??`left`:n===`tree-right`?r?`right`:e??`right`:n===`tree-alternate`?r?t%2==0?`left`:`right`:e??(t%2==0?`left`:`right`):n===`timeline-horizontal`?r?t%2==0?`top`:`bottom`:e??(t%2==0?`top`:`bottom`):n===`timeline-vertical`?r?t%2==0?`left`:`right`:e??(t%2==0?`left`:`right`):e}};function kt(e,t){let n=Number.isFinite(t.zoomRatio)&&t.zoomRatio>0?t.zoomRatio:1;return{x:Math.round((e.offsetX-t.panOffset.x)/n),y:Math.round((e.offsetY-t.panOffset.y)/n)}}function At(e){var t;e!=null&&e.dispose?e.dispose():e==null||(t=e.unsubscribe)==null||t.call(e)}function jt(e){var n;return e.activeTool===t.BoardToolType.MindMap&&((n=e.pendingInsert)==null?void 0:n.type)===t.BoardToolType.MindMap}let G=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._renderContext=e,this._instanceSrv=t,this._stateService=n,this._commandService=r,this._insertStateService=i,this._elementStateService=a,this._boardTextEditingService=o,x(this,`_previewObject`,null),x(this,`_lastPoint`,null),this._init()}_init(){var e;let{scene:t,unitId:n}=this._renderContext,r=this._instanceSrv.getUnit(n,a.UniverInstanceType.UNIVER_BOARD);if(!r)return;let i=(e=t.onPointerMove$)==null?void 0:e.subscribeEvent({priority:4,next:([e,t])=>this._handlePointerMove(e,t)}),o=t.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>this._handlePointerDown(r,e,t)});this.disposeWithMe((0,a.toDisposable)(()=>At(i))),this.disposeWithMe((0,a.toDisposable)(()=>At(o)));let s=this._stateService.state$.subscribe(()=>this._syncPreviewObject());this.disposeWithMe((0,a.toDisposable)(()=>At(s))),this.disposeWithMe((0,a.toDisposable)(()=>{this._removePreviewObject()})),this._syncPreviewObject()}_syncPreviewObject(){var e,t;let n=this._stateService.getState();if(!jt(n)){this._removePreviewObject();return}let r=this._ensurePreviewObject(),i=this._insertStateService.getTemplate();r.updateState({point:this._lastPoint,structureKind:i.structureKind,rootText:i.rootText,branchLineType:i.branchLineType,children:i.children,blueprint:i.blueprint,zoomRatio:n.zoomRatio}),(e=(t=this._renderContext.scene).makeDirty)==null||e.call(t,!0)}_ensurePreviewObject(){var e,t;if(this._previewObject)return this._previewObject;let n=this._insertStateService.getTemplate(),r=new Dt(Tt,{point:this._lastPoint,structureKind:n.structureKind,rootText:n.rootText,branchLineType:n.branchLineType,children:n.children,blueprint:n.blueprint,zoomRatio:this._stateService.getState().zoomRatio});return this._previewObject=r,(e=(t=this._renderContext.scene).addObject)==null||e.call(t,r,Et),r}_removePreviewObject(){var e,t,n,r;this._previewObject?((e=(t=this._renderContext.scene).removeObjects)==null||e.call(t,[this._previewObject]),this._previewObject=null,this._lastPoint=null,(n=(r=this._renderContext.scene).makeDirty)==null||n.call(r,!0)):this._lastPoint=null}_getPointFromEvent(e){let t=this._stateService.getState();return kt(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio})}_handlePointerMove(e,t){jt(this._stateService.getState())&&(this._lastPoint=this._getPointFromEvent(e),this._syncPreviewObject(),t.stopPropagation())}async _handlePointerDown(e,t,n){let i=await this._insertMindMap(e,t,n);if(!i)return;let a={unitId:this._renderContext.unitId,subUnitId:i.subUnitId};this._boardTextEditingService.ignoreExternalFocusChanges(),this._boardTextEditingService.setEditing({...a,shapeId:i.rootNodeId,shapeKey:(0,r.getBoardElementRenderObjectKey)(a.unitId,i.rootNodeId),visible:!0})}async _insertMindMap(e,r,i){var o;let s=this._stateService.getState(),c=r.button??0;if(!jt(s)||c!==0)return null;let l=this._getPointFromEvent(r);this._lastPoint=l,this._syncPreviewObject();let u=this._ensurePreviewObject().getRootTopLeft(l),d=this._insertStateService.getTemplate(),f=(0,a.generateRandomId)(6),p=e.getActivePageId(),m=this._commandService.executeCommand(n.InsertBoardMindMapOperation.id,{unitId:this._renderContext.unitId,subUnitId:p,left:u.left,top:u.top,rootNodeId:f,rootText:d.rootText,structureKind:d.structureKind,branchLineType:d.branchLineType,children:d.children,blueprint:d.blueprint});if(this._stateService.setActiveTool(t.BoardToolType.Select),i.stopPropagation(),(o=r.preventDefault)==null||o.call(r),!await m||this._disposed)return null;let h={unitId:this._renderContext.unitId,subUnitId:p};return this._elementStateService.selectElements(h,[f],f),{rootNodeId:f,subUnitId:p}}};G=C([S(1,a.IUniverInstanceService),S(2,r.IBoardUIStateService),S(3,a.ICommandService),S(4,(0,a.Inject)(W)),S(5,r.IBoardElementStateService),S(6,(0,a.Inject)(r.BoardTextEditingService))],G);var K=class extends a.Disposable{constructor(...e){super(...e),x(this,`_refresh$`,new s.Subject),x(this,`refresh$`,this._refresh$.asObservable())}notify(e){this._refresh$.next(e)}dispose(){this._refresh$.complete(),super.dispose()}};function Mt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function Nt(e,t,r){let i=e[t],a=(0,n.getMindMapNodeMeta)(i==null?void 0:i.element);if(!i||!a)return null;let o=(0,n.resolveMindMapNodeHostSize)(i,r);if(!o)return null;let s=i.transform??i.element.transform,c={...e,[t]:{...i,transform:{...s,width:o.width,height:o.height},element:{...i.element,transform:{...i.element.transform,width:o.width,height:o.height}}}};return(0,n.resolveMindMapLayoutPreview)(c,a.structureScopeId)}let Pt=class extends a.RxDisposable{constructor(e,t,r,i,o,s){super(),this._renderContext=e,this._intrinsicSizeService=t,this._boardElementService=r,this._textEditingService=i,this._previewRefreshService=o,this._commandService=s,x(this,`_activePreview`,null),x(this,`_provider`,{match:e=>e.unitId===this._renderContext.unitId&&!!(0,n.getMindMapNodeMeta)(e.element),resolveHostSize:e=>this._resolveHostSize(e),previewHostSize:e=>this._previewHostSize(e),updateHostSize:e=>this._updateHostSize(e),updateShapeText:e=>this._updateShapeText(e)}),this.disposeWithMe(this._intrinsicSizeService.registerProvider(this._provider)),this._initEditingRestore(),this.disposeWithMe((0,a.toDisposable)(()=>this._restoreActivePreview()))}_updateHostSize(e){return this._previewHostSize(e)}_updateShapeText(e){let t=e.params.hostSize?this._resolveHostSize({elementData:e.elementData,params:e.params.hostSize}):null,i=e.elementData.transform??e.elementData.element.transform;return(!t||t.width===i.width&&t.height===i.height)&&(0,r.areBoardShapeTextValuesEquivalent)(e.params.shapeText,e.params.oldShapeText)?!0:this._commandService.syncExecuteCommand(n.UpdateMindMapNodeOperation.id,{unitId:e.params.unitId,subUnitId:e.params.subUnitId,nodeId:e.params.shapeId,shapeText:e.params.shapeText,...t?{hostSize:{width:t.width,height:t.height}}:null})}_previewHostSize(e){let t=this._resolveHostSize(e);if(!t)return!1;let n=e.elementData.transform??e.elementData.element.transform;return!this._activePreview&&n.width===t.width&&n.height===t.height||this._syncLayoutPreview(e,t),!0}_resolveHostSize(e){return!Mt(e.params.width)||!Mt(e.params.height)?null:(0,n.resolveMindMapNodeHostSize)(e.elementData,{width:e.params.width,height:e.params.height})}_initEditingRestore(){this.disposeWithMe((0,a.toDisposable)(this._textEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e||this._restoreActivePreview()})))}_syncLayoutPreview(e,t){var r;let i=this._boardElementService.getElementData(e.params.unitId,e.params.subUnitId),a=Nt(i,e.params.shapeId,t),o=(0,n.getMindMapNodeMeta)((r=i[e.params.shapeId])==null?void 0:r.element);a&&o&&(this._activePreview={unitId:e.params.unitId,subUnitId:e.params.subUnitId,scopeId:o.structureScopeId},this._syncElementDataToScene(a,o.structureScopeId)&&this._previewRefreshService.notify({unitId:e.params.unitId,subUnitId:e.params.subUnitId,nodeId:e.params.shapeId,scopeId:o.structureScopeId}))}_restoreActivePreview(){let e=this._activePreview;if(!e)return;this._activePreview=null;let t=this._boardElementService.getElementData(e.unitId,e.subUnitId);this._syncElementDataToScene(t,e.scopeId)&&this._previewRefreshService.notify({unitId:e.unitId,subUnitId:e.subUnitId,nodeId:e.scopeId,scopeId:e.scopeId})}_syncElementDataToScene(e,t){let i=!1;if(Object.values(e).forEach(a=>{var o;let s=(0,n.getMindMapNodeMeta)(a.element),c=(o=a.element.custom)==null?void 0:o.structured;if(a.elementId!==t&&(s==null?void 0:s.structureScopeId)!==t&&(c==null?void 0:c.structureScopeId)!==t)return;let l=this._getSceneObject(a.elementId);l&&(i=(0,r.syncBoardElementRenderObject)(l,a,{elementData:e,unitId:this._renderContext.unitId})||i)}),i){var a,o;this._renderContext.scene.makeDirty(!0),(a=(o=this._renderContext.scene).requestRender)==null||a.call(o)}return i}_getSceneObject(e){var t;let n=(0,r.getBoardElementRenderObjectKey)(this._renderContext.unitId,e),i=this._renderContext.scene;return((t=i.getObjectIncludeInGroup)==null?void 0:t.call(i,n))??this._renderContext.scene.getObject(n)??null}};Pt=C([S(1,(0,a.Inject)(r.BoardShapeIntrinsicSizeService)),S(2,(0,a.Inject)(t.IBoardElementService)),S(3,(0,a.Inject)(r.BoardTextEditingService)),S(4,(0,a.Inject)(K)),S(5,a.ICommandService)],Pt);let q={touchHitRadius:22,radius:18,addChildRadius:14,siblingHoverRadius:10,siblingDotRadius:5,siblingDotGap:3,gap:10,collapsePlusMinDistance:44,primaryColor:T.primaryColor,surfaceColor:T.surfaceColor,borderWidth:2,glyphSize:8,addChildGlyphSize:6,siblingGlyphSize:5.5,glyphWidth:2.4,glyphHoverWidth:3,badgeFontWeight:600,badgeFontSize:18,fontFamily:T.fontFamily};function Ft(e){let t=q.radius,n=q.addChildRadius,r=q.siblingHoverRadius,i=q.gap,a=q.siblingDotRadius,o=a+q.siblingDotGap,s=q.collapsePlusMinDistance,c=e.bounds.top+e.bounds.height/2,l=e.bounds.left+e.bounds.width/2,u=e.bounds.left-t-i,d=e.bounds.left+e.bounds.width+t+i,f=e.bounds.top-t-i,p=e.bounds.top+e.bounds.height+t+i,m=e.bounds.left-n-i,h=e.bounds.left+e.bounds.width+n+i,g=e.bounds.top-n-i,_=e.bounds.top+e.bounds.height+n+i,v=[],y=e.side===`top`||e.side===`bottom`,b=y?l:e.side===`left`?u:d,x=y?e.side===`top`?f:p:c;if(e.hasChildren&&e.collapsedDescendantCount>0)return v.push({kind:`toggle-collapse`,x:b,y:x,radius:t,badgeCount:e.collapsedDescendantCount}),v;if(e.isRoot?(e.rootChildSides??(y?[`top`,`bottom`]:[`left`,`right`])).forEach(e=>{e===`top`?v.push({kind:`add-child-top`,x:l,y:g,radius:n}):e===`bottom`?v.push({kind:`add-child-bottom`,x:l,y:_,radius:n}):e===`left`?v.push({kind:`add-child-left`,x:m,y:c,radius:n}):v.push({kind:`add-child-right`,x:h,y:c,radius:n})}):(v.push({kind:e.side===`left`?`add-child-left`:e.side===`top`?`add-child-top`:e.side===`bottom`?`add-child-bottom`:`add-child-right`,x:y?l:e.side===`left`?m:h,y:y?e.side===`top`?g:_:c,radius:n}),y?(v.push({kind:`add-sibling-before`,placement:`before`,x:e.bounds.left-o,y:c,radius:r,visualRadius:a}),v.push({kind:`add-sibling-after`,placement:`after`,x:e.bounds.left+e.bounds.width+o,y:c,radius:r,visualRadius:a})):(v.push({kind:`add-sibling-before`,placement:`before`,x:l,y:e.bounds.top-o,radius:r,visualRadius:a}),v.push({kind:`add-sibling-after`,placement:`after`,x:l,y:e.bounds.top+e.bounds.height+o,radius:r,visualRadius:a}))),e.hasChildren){let n={kind:`toggle-collapse`,x:b,y:x,radius:t};v.push(n);let r=v.find(t=>t.kind===(e.side===`left`?`add-child-left`:e.side===`top`?`add-child-top`:e.side===`bottom`?`add-child-bottom`:`add-child-right`));r&&Math.hypot(r.x-n.x,r.y-n.y)<s&&(e.side===`top`||e.side===`bottom`?r.y=n.y+(e.side===`top`?-s:s):r.x=n.x+(e.side===`left`?-s:s))}return v}let It=`board-mind-map-node-controls-object`,Lt=r.BOARD_RENDER_LAYER_INDEX.connectorAffordance;function Rt(e,t){return!!e&&e.kind===t.kind&&e.x===t.x&&e.y===t.y}var zt=class extends o.Control{constructor(e=It,t){super(e),x(this,`_state`,{controls:[]}),this.evented=!0,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientControl,this.updateState(t)}updateState(e){this._state={...this._state,...e},this._state.controls.length>0?this.show():this.hide(),this.makeDirty(!0)}setHoveredControl(e){!e&&!this._state.hoveredControl||e&&Rt(this._state.hoveredControl,e)||(this._state={...this._state,hoveredControl:e},this.makeDirty(!0))}getHitControl(e,t){var n;let r=(n=this.getScene())==null?void 0:n.getAncestorScale(),i=null,a=1/0;for(let n=this._state.controls.length-1;n>=0;--n){let s=this._state.controls[n],c=Math.hypot(e.x-s.x,e.y-s.y);if(t!==o.DeviceType.Touch){if(c<=s.radius)return s;continue}let l=Math.hypot((e.x-s.x)*((r==null?void 0:r.scaleX)??1),(e.y-s.y)*((r==null?void 0:r.scaleY)??1));(c<=s.radius||l<=q.touchHitRadius)&&l<a&&(i=s,a=l)}return i}getTouchHitDistance(e){var t;let n=this.getHitControl(e,o.DeviceType.Touch),r=(t=this.getScene())==null?void 0:t.getAncestorScale();return n?Math.hypot((e.x-n.x)*((r==null?void 0:r.scaleX)??1),(e.y-n.y)*((r==null?void 0:r.scaleY)??1)):1/0}isHit(e){return!!this.getHitControl({x:e.x,y:e.y})}render(e,t){return!this.visible||this._state.controls.length===0?(this.makeDirty(!1),this):(e.save(),this._state.controls.forEach(t=>{let n=Rt(this._state.hoveredControl,t),r=t.badgeCount!==void 0,i=t.kind===`add-child-left`||t.kind===`add-child-right`||t.kind===`add-child-top`||t.kind===`add-child-bottom`,a=t.kind===`add-sibling-before`||t.kind===`add-sibling-after`,o=a&&!n?t.visualRadius??t.radius:t.radius;if(e.beginPath(),e.fillStyle=t.kind===`toggle-collapse`?q.surfaceColor:q.primaryColor,e.strokeStyle=q.primaryColor,e.lineWidth=q.borderWidth,e.arc(t.x,t.y,o,0,Math.PI*2),e.fill(),(!a||n)&&e.stroke(),!r&&(!a||n)){if(e.beginPath(),e.strokeStyle=t.kind===`toggle-collapse`?q.primaryColor:q.surfaceColor,e.lineWidth=a?q.glyphWidth:n?q.glyphHoverWidth:q.glyphWidth,e.lineCap=`round`,t.kind===`toggle-collapse`){let n=q.glyphSize;e.moveTo(t.x+n/2,t.y-n),e.lineTo(t.x-n/2,t.y),e.lineTo(t.x+n/2,t.y+n)}else{let n=a?q.siblingGlyphSize:i?q.addChildGlyphSize:q.glyphSize;e.moveTo(t.x-n,t.y),e.lineTo(t.x+n,t.y),e.moveTo(t.x,t.y-n),e.lineTo(t.x,t.y+n)}e.stroke()}r&&(e.fillStyle=q.primaryColor,e.font=`${q.badgeFontWeight} ${q.badgeFontSize}px ${q.fontFamily}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(String(t.badgeCount),t.x,t.y))}),e.restore(),this.makeDirty(!1),this)}};function Bt(e){return e===`tree-left`||e===`tree-right`||e===`tree-alternate`}function Vt(e){return e===`timeline-horizontal`||e===`timeline-vertical`}function Ht(e,t){let n=Number.isFinite(t.zoomRatio)&&t.zoomRatio>0?t.zoomRatio:1;return{x:Math.round((e.offsetX-t.panOffset.x)/n),y:Math.round((e.offsetY-t.panOffset.y)/n)}}let Ut=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o,s,c){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._stateService=r,this._commandService=i,this._boardTextEditingService=a,this._localeService=o,this._previewRefreshService=s,this._undoRedoGroupService=c,x(this,`_object`,null),x(this,`_objectEventDisposables`,null),x(this,`_activeNodeId`,null),x(this,`_activeScopeId`,null),this._init()}_init(){var e,t,n;let{scene:r}=this._renderContext,i=(e=r.getTransformerByCreate)==null?void 0:e.call(r);i&&(this.disposeWithMe((0,a.toDisposable)(i.changing$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(({objects:e})=>{this._syncControls(e,{hideRootControls:!0})}))),this.disposeWithMe((0,a.toDisposable)(i.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=e==null?void 0:e.objects;this._syncControls(t),setTimeout(()=>this._syncControls(t),0)})))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._syncControls()))),this.disposeWithMe((0,a.toDisposable)(this._stateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._syncControls()))),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementUpdate$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=this._elementStateService.getSnapshot().context;t&&e.some(e=>e.unitId===t.unitId&&e.subUnitId===t.subUnitId&&(e.elementId===this._activeNodeId||e.elementId===this._activeScopeId))&&this._syncControls()}))),this.disposeWithMe((0,a.toDisposable)(this._previewRefreshService.refresh$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=this._elementStateService.getSnapshot().context;t&&t.unitId===e.unitId&&t.subUnitId===e.subUnitId&&(this._activeScopeId&&this._activeScopeId!==e.scopeId||this._syncControls())}))),this.disposeWithMe((0,a.toDisposable)(r.onPointerMove$.subscribeEvent(e=>this._handlePointerMove(e)))),this.disposeWithMe((0,a.toDisposable)(r.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>{this._handlePointerDown(e)&&this._consumeControlEvent(e,t)}}))),this.disposeWithMe((0,a.toDisposable)(((t=r.onPointerUp$)==null?void 0:t.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((n=r.onDblclick$)==null?void 0:n.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(()=>this._removeObject())),this._syncControls()}_ensureObject(){return this._object||(this._object=new zt(It),this._attachObjectEvents(this._object),this._renderContext.scene.addObject(this._object,Lt)),this._object}_attachObjectEvents(e){var t;(t=this._objectEventDisposables)==null||t.dispose();let n=new a.DisposableCollection;n.add(e.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>{this._handlePointerDown(e)&&this._consumeControlEvent(e,t)}})),n.add(e.onPointerUp$.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}})),n.add(e.onDblclick$.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}})),this._objectEventDisposables=n}_removeObject(){var e;this._object&&(this._renderContext.scene.removeObjects([this._object]),(e=this._objectEventDisposables)==null||e.dispose(),this._objectEventDisposables=null,this._object=null,this._activeNodeId=null,this._activeScopeId=null,this._renderContext.scene.makeDirty(!0))}_syncControls(e,t){var i,a;if(this._stateService.getState().interactionMode===`viewing`){this._removeObject();return}let o=this._elementStateService.getSnapshot(),s=o.context,c=o.focusedId??o.selectedIds[0];if(!s||!c||o.selectedIds.length!==1){this._removeObject();return}let l=this._boardElementService.getElementData(s.unitId,s.subUnitId),u=l[c],d=(0,n.getMindMapNodeMeta)(u==null?void 0:u.element);if(!u||!d){this._removeObject();return}let f=(0,r.getBoardElementRenderObjectKey)(s.unitId,c);if(t!=null&&t.hideRootControls&&d.parentNodeId==null&&e!=null&&e.has(f)){this._removeObject();return}let p=this._resolveControlBounds(l,s.unitId,c,e);if(!p){this._removeObject();return}let m=Object.values(l).filter(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.parentNodeId)===c}),h=d.collapsed?this._countDescendants(l,c):0;this._activeNodeId=c,this._activeScopeId=d.structureScopeId;let g=(i=l[d.structureScopeId])==null?void 0:i.element,_=(0,n.getMindMapContainerMeta)(g),v=g==null||(a=g.custom)==null||(a=a.mindmap)==null||(a=a.layout)==null?void 0:a.structureKind,y=(_==null?void 0:_.layout.structureKind)??v,b=d.parentNodeId==null,x=this._resolveControlSide(d.side,b,y);this._ensureObject().updateState({controls:Ft({bounds:p,isRoot:b,side:x,rootChildSides:this._resolveRootChildControlSides(b,y),hasChildren:m.length>0,collapsedDescendantCount:h})}),this._renderContext.scene.makeDirty(!0)}_resolveControlSide(e,t,n){return n===`timeline-vertical`?!t&&(e===`left`||e===`right`)?e:`bottom`:n===`mindmap-vertical`?!t&&(e===`top`||e===`bottom`)?e:`bottom`:e===`left`?`left`:`right`}_resolveRootChildControlSides(e,t){if(e){if(Bt(t))return[`bottom`];if(t===`timeline-horizontal`)return[`right`];if(t===`timeline-vertical`)return[`bottom`]}}_resolveCreateChildSide(e){var t,r;let i=this._elementStateService.getSnapshot().context;if(!i||!this._activeNodeId)return;let a=this._boardElementService.getElementData(i.unitId,i.subUnitId),o=(0,n.getMindMapNodeMeta)((t=a[this._activeNodeId])==null?void 0:t.element),s=o?(0,n.getMindMapContainerMeta)((r=a[o.structureScopeId])==null?void 0:r.element):null;if((o==null?void 0:o.parentNodeId)!=null||!Bt(s==null?void 0:s.layout.structureKind)&&!Vt(s==null?void 0:s.layout.structureKind))return e===`add-child-left`?`left`:e===`add-child-top`?`top`:e===`add-child-bottom`?`bottom`:`right`}_resolveControlBounds(e,n,i,a){var o,s;let c=(0,r.getBoardElementRenderObjectKey)(n,i),l=a==null?void 0:a.get(c),u=this._toFiniteBounds(l);if(u)return u;let d=this._renderContext.scene,f=((o=d.getObjectIncludeInGroup)==null?void 0:o.call(d,c))??((s=d.getObject)==null?void 0:s.call(d,c));return this._toFiniteBounds(f)||(0,t.resolveBoardElementWorldBounds)(e,i)}_toFiniteBounds(e){return e&&Number.isFinite(e.left)&&Number.isFinite(e.top)&&Number.isFinite(e.width)&&Number.isFinite(e.height)?{left:e.left,top:e.top,width:e.width,height:e.height}:null}_countDescendants(e,t){return Object.values(e).filter(e=>{var r;return((r=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:r.parentNodeId)===t}).reduce((t,n)=>t+1+this._countDescendants(e,n.elementId),0)}_handlePointerMove(e){if(!this._object)return;let t=this._stateService.getState(),n=Ht(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio});this._object.setHoveredControl(this._object.getHitControl(n,e.deviceType))}_handlePointerDown(e){if(!this._object||!this._activeNodeId||(e.button??0)!==0)return!1;let t=this._elementStateService.getSnapshot().context;if(!t)return!1;let r=this._stateService.getState(),i=Ht(e,{panOffset:r.viewportPanOffset,zoomRatio:r.zoomRatio}),o=this._object.getHitControl(i,e.deviceType);if(!o)return!1;if(o.kind===`toggle-collapse`)return this._executeAndLayout(n.ToggleMindMapNodeCollapseOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:this._activeNodeId}),!0;if(o.kind===`add-child-left`||o.kind===`add-child-right`||o.kind===`add-child-top`||o.kind===`add-child-bottom`){let e=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(n.AddMindMapChildOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,parentNodeId:this._activeNodeId,side:this._resolveCreateChildSide(o.kind),nodeId:e,connectorId:(0,a.generateRandomId)(6),text:this._localeService.t(`boards-mind-ui.panel.addText`)},e),!0}if(o.kind===`add-sibling-before`||o.kind===`add-sibling-after`){let e=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(n.AddMindMapSiblingOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:this._activeNodeId,placement:o.placement??(o.kind===`add-sibling-before`?`before`:`after`),siblingNodeId:e,connectorId:(0,a.generateRandomId)(6),text:this._localeService.t(`boards-mind-ui.panel.addText`)},e),!0}return!0}_isControlEvent(e){if(!this._object||(e.button??0)!==0)return!1;let t=this._stateService.getState(),n=Ht(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio});return!!this._object.getHitControl(n,e.deviceType)}_consumeControlEvent(e,t){var n,r;t.stopPropagation(),(n=e.preventDefault)==null||n.call(e),(r=e.stopPropagation)==null||r.call(e)}_executeAndLayout(e,t){let r=this._activeScopeId;this._undoRedoGroupService.run(t.unitId,()=>{this._commandService.syncExecuteCommand(e,t)&&r&&(this._commandService.syncExecuteCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:r}),this._syncControls())})}_executeCreateAndEdit(e,t,n){let i={unitId:t.unitId,subUnitId:t.subUnitId},a=this._commandService.executeCommand(e,t);Promise.resolve(a).then(e=>{e&&(this._syncControls(),this._elementStateService.selectElements(i,[n],n),this._boardTextEditingService.ignoreExternalFocusChanges(),this._boardTextEditingService.setEditing({...i,shapeId:n,shapeKey:(0,r.getBoardElementRenderObjectKey)(i.unitId,n),visible:!0}))})}};Ut=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,(0,a.Inject)(r.IBoardUIStateService)),S(4,a.ICommandService),S(5,(0,a.Inject)(r.BoardTextEditingService)),S(6,(0,a.Inject)(a.LocaleService)),S(7,(0,a.Inject)(K)),S(8,(0,a.Inject)(c.UndoRedoGroupService))],Ut);let Wt=`FOCUSING_MIND_MAP_TEXT_EDITOR`,J=class extends a.RxDisposable{constructor(e,t){super(),this._commandService=e,this._shortcutService=t,this._init()}_init(){this.disposeWithMe(this._shortcutService.registerShortcut(this._createQuoteShortcut()))}_createQuoteShortcut(){return{id:l.SHAPE_TEXT_EDITOR_QUOTE_COMMAND_ID,binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,priority:1e3,preconditions:e=>e.getContextValue(`FOCUSING_MIND_MAP_TEXT_EDITOR`)&&this._commandService.hasCommand(l.SHAPE_TEXT_EDITOR_QUOTE_COMMAND_ID)}}};J=C([S(0,a.ICommandService),S(1,c.IShortcutService)],J);let Gt=[Ye,Xe,Wt],Kt=class extends a.RxDisposable{constructor(e,t,n,r,i){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._textEditingService=r,this._contextService=i,x(this,`_isActive`,!1),this.disposeWithMe((0,a.toDisposable)(this._renderContext.activated$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{this._isActive=e,this._syncContext()}))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._syncContext()}))),this.disposeWithMe((0,a.toDisposable)(this._textEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._syncContext()}))),this._syncContext()}_syncContext(){var e,t;let r=this._elementStateService.getSnapshot(),i=this._textEditingService.getEditing(),a=i!=null&&i.visible?i.shapeId:r.activeEditingId,o=r.focusedId??r.selectedIds[0],s=r.context??{unitId:this._renderContext.unitId,subUnitId:this._renderContext.unit.getActivePageId()},c=this._isActive&&!!o&&r.selectedIds.length===1&&!a&&!r.isTransforming,l=this._isActive?this._boardElementService.getElementData(s.unitId,s.subUnitId):{};this._contextService.setContextValue(Ye,c&&!!(0,n.getMindMapNodeMeta)((e=l[o])==null?void 0:e.element)),this._contextService.setContextValue(Xe,this._isActive&&r.selectedIds.length===0&&!r.focusedId&&!a&&!r.isTransforming),this._contextService.setContextValue(Wt,!!a&&!!(0,n.getMindMapNodeMeta)((t=l[a])==null?void 0:t.element))}dispose(){this._resetContext(),super.dispose()}_resetContext(){Gt.forEach(e=>this._contextService.setContextValue(e,!1))}};Kt=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,(0,a.Inject)(r.BoardTextEditingService)),S(4,a.IContextService)],Kt);var qt=class extends G{async _handlePointerDown(e,t,n){await this._insertMindMap(e,t,n)}};let Jt={id:`board.operation.mind-map.open-panel`,type:a.CommandType.OPERATION,handler:(e,t)=>!!(t!=null&&t.unitId)&&!!t.subUnitId&&!!t.scopeId},Y=`board.mind-map.panel`,Yt=[`structure`,`layout`,`importExport`];n.MIND_MAP_DEFAULT_LAYOUT.horizontalGap,n.MIND_MAP_DEFAULT_LAYOUT.siblingGap,n.MIND_MAP_DEFAULT_LAYOUT.branchGap;let Xt=[{labelKey:`boards-mind-ui.panel.spacing.parentGap`,key:`horizontalGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.horizontalGap},{labelKey:`boards-mind-ui.panel.spacing.siblingGap`,key:`siblingGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.siblingGap},{labelKey:`boards-mind-ui.panel.spacing.branchGap`,key:`branchGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.branchGap}],Zt=[{labelKey:`boards-mind-ui.panel.layout.right`,value:`right`},{labelKey:`boards-mind-ui.panel.layout.left`,value:`left`},{labelKey:`boards-mind-ui.panel.layout.both`,value:`both`}],Qt=[{labelKey:`boards-mind-ui.panel.structureKind.mindmapHorizontal`,value:`mindmap-horizontal`},{labelKey:`boards-mind-ui.panel.structureKind.mindmapVertical`,value:`mindmap-vertical`},{labelKey:`boards-mind-ui.panel.structureKind.treeRight`,value:`tree-right`},{labelKey:`boards-mind-ui.panel.structureKind.treeLeft`,value:`tree-left`},{labelKey:`boards-mind-ui.panel.structureKind.treeAlternate`,value:`tree-alternate`},{labelKey:`boards-mind-ui.panel.structureKind.timelineHorizontal`,value:`timeline-horizontal`},{labelKey:`boards-mind-ui.panel.structureKind.timelineVertical`,value:`timeline-vertical`}],$t=[{labelKey:`boards-mind-ui.panel.branchLineType.curve`,value:`curve`},{labelKey:`boards-mind-ui.panel.branchLineType.roundedOrthogonal`,value:`rounded-orthogonal`},{labelKey:`boards-mind-ui.panel.branchLineType.orthogonal`,value:`orthogonal`}];function en(e){let t=(e==null?void 0:e.structureKind)??n.MIND_MAP_DEFAULT_LAYOUT.structureKind;return{spacing:{horizontalGap:(e==null?void 0:e.horizontalGap)??n.MIND_MAP_DEFAULT_LAYOUT.horizontalGap,siblingGap:(e==null?void 0:e.siblingGap)??n.MIND_MAP_DEFAULT_LAYOUT.siblingGap,branchGap:(e==null?void 0:e.branchGap)??n.MIND_MAP_DEFAULT_LAYOUT.branchGap},direction:(e==null?void 0:e.direction)??n.MIND_MAP_DEFAULT_LAYOUT.direction,structureKind:t,branchLineType:(0,n.resolveMindMapBranchLineTypeForStructure)(t,e==null?void 0:e.branchLineType)}}async function tn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapLayoutOperation.id,t))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function nn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapBranchLineTypeOperation.id,t))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function rn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapLayoutOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,...t.horizontalGap===void 0?{}:{horizontalGap:t.horizontalGap},...t.siblingGap===void 0?{}:{siblingGap:t.siblingGap},...t.branchGap===void 0?{}:{branchGap:t.branchGap}}))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function an(e,t){return t.nodeId===t.targetNodeId||!await Promise.resolve(e.executeCommand(n.ReparentMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,targetNodeId:t.targetNodeId,referenceNodeId:t.targetNodeId,placement:t.placement}))?!1:(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0)}async function on(e,t){let r=t.text.trim();return!r||!await Promise.resolve(e.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,text:r}))?!1:(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0)}async function sn(e){var t;let n=(t=globalThis.navigator)==null?void 0:t.clipboard;return n!=null&&n.writeText?(await n.writeText(e),!0):!1}async function cn(e,t,r=sn){let i=await Promise.resolve(e.executeCommand(n.ExportMindMapOpmlOperation.id,t));if(typeof i!=`string`||!i)return!1;try{return await r(i)!==!1}catch{return!1}}async function ln(e,t){return t.opml.trim()?(await e.executeCommand(n.ImportMindMapOpmlOperation.id,t)).success:!1}function un(e,t){let n=`shapeData`in e.element?e.element.shapeData.shapeText:void 0;return(n==null?void 0:n.text)||t}function dn(e,t,r=n.MIND_MAP_DEFAULT_NODE_TEXT){let i=Object.values(e).map(e=>{let r=(0,n.getMindMapNodeMeta)(e.element);return(r==null?void 0:r.structureScopeId)===t?{data:e,meta:r}:null}).filter(e=>!!e),a=/* @__PURE__ */ new Map;i.forEach(e=>{let t=e.meta.parentNodeId;a.set(t,[...a.get(t)??[],e])}),a.forEach(e=>{e.sort((e,t)=>(0,n.compareMindMapOrderKey)(e.meta.orderKey,t.meta.orderKey)||e.data.elementId.localeCompare(t.data.elementId))});let o=[],s=(e,t)=>{(a.get(e)??[]).forEach(e=>{o.push({nodeId:e.data.elementId,depth:t,text:un(e.data,r)}),s(e.data.elementId,t+1)})};return s(null,0),o}function fn(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.text.toLowerCase().includes(n)):e}function pn(e){return{paddingInlineStart:8+(Number.isFinite(e)&&e>0?e:0)*16}}function mn(e){return/* @__PURE__ */ (0,p.jsx)(d.Segmented,{className:`univer-w-full univer-text-xs`,...e})}function X(e){return/* @__PURE__ */ (0,p.jsxs)(`section`,{className:`univer-py-4`,"data-board-mind-map-panel-section":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`h3`,{className:`univer-mb-3 univer-text-sm univer-font-semibold univer-text-gray-900 dark:!univer-text-gray-100`,children:e.title}),e.children]})}function hn(e,i=`structure`){var o,l,u;let d=(0,c.useDependency)(a.ICommandService),p=(0,c.useDependency)(r.IBoardElementStateService),m=(0,c.useDependency)(t.IBoardElementService),h=(0,c.useDependency)(a.LocaleService),[,g]=(0,f.useReducer)(e=>e+1,0);(0,f.useEffect)(()=>{let t=(0,s.merge)(m.elementAdd$,m.elementUpdate$,m.elementRemove$).subscribe(t=>{t.some(t=>t.unitId===e.unitId&&t.subUnitId===e.subUnitId)&&g()});return()=>t.unsubscribe()},[m,e.unitId,e.subUnitId]);let _=m.getElementData(e.unitId,e.subUnitId),v=dn(_,e.scopeId,h.t(`boards-mind-ui.panel.addText`)),y=(o=(0,n.getMindMapContainerMeta)((l=_[e.scopeId])==null?void 0:l.element))==null?void 0:o.layout,[b,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(``),{spacing:E,direction:D,structureKind:O,branchLineType:k}=en(y),[A,j]=(0,f.useState)(null),[M,N]=(0,f.useState)(i),P=fn(v,b),F={unitId:e.unitId,subUnitId:e.subUnitId,scopeId:e.scopeId};return{commandService:d,elementStateService:p,localeService:h,query:b,setQuery:x,editingOutlineNode:S,setEditingOutlineNode:C,opmlText:w,setOpmlText:T,spacing:E,layoutDirection:D,structureKind:O,branchLineType:k,setDraggedOutlineNodeId:j,activeTab:M,setActiveTab:N,visibleOutlineItems:P,baseParams:F,tabItems:Yt.map(e=>({label:h.t(`boards-mind-ui.panel.tab.${e}`),value:e})),selectedNode:e.nodeId?(u=_[e.nodeId])==null?void 0:u.element:void 0,branchLineItems:$t.filter(e=>e.value!==`curve`||(0,n.isMindMapPlainStructureKind)(O)),changeLayout:e=>tn(d,{...F,direction:e}),changeStructureKind:e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(e,k);return tn(d,{...F,structureKind:e,...t===k?null:{branchLineType:t}})},changeBranchLineType:e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(O,e);return nn(d,{...F,branchLineType:t})},changeSpacing:(e,t)=>{let n={...E,[e]:t};return rn(d,{...F,...n})},importOpml:()=>{ln(d,{unitId:e.unitId,subUnitId:e.subUnitId,left:120,top:120,opml:w}).then(e=>{e&&T(``)})},exportOpml:()=>cn(d,F),startRenameNode:(e,t)=>{C({nodeId:e,text:t})},commitRenameNode:()=>{S&&on(d,{...F,nodeId:S.nodeId,text:S.text}).then(e=>{e&&C(null)})},reorderNode:(e,t)=>{if(e.preventDefault(),!A||A===t)return;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY<n.top+n.height/2?`before`:`after`;j(null),an(d,{...F,nodeId:A,targetNodeId:t,placement:r})}}}function gn(e){let{elementStateService:t,localeService:n,query:r,setQuery:i,editingOutlineNode:a,setEditingOutlineNode:o,opmlText:s,setOpmlText:c,spacing:l,layoutDirection:u,structureKind:f,branchLineType:m,setDraggedOutlineNodeId:h,activeTab:g,setActiveTab:_,visibleOutlineItems:v,tabItems:y,branchLineItems:b,changeLayout:x,changeStructureKind:S,changeBranchLineType:C,changeSpacing:w,importOpml:T,exportOpml:E,startRenameNode:D,commitRenameNode:O,reorderNode:k}=hn(e);return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-size-full univer-bg-gray-0 univer-text-sm univer-text-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-gray-200`,"data-board-mind-map-panel":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-py-3`,"data-board-mind-map-panel-tabs":`true`,children:/* @__PURE__ */ (0,p.jsx)(mn,{items:y,value:g,onChange:e=>_(e)})}),g===`structure`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.structure`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{slot:/* @__PURE__ */ (0,p.jsx)(Le,{}),value:r,placeholder:n.t(`boards-mind-ui.panel.searchNodes`),className:(0,d.clsx)(`univer-mb-3 univer-w-full`,!1),onChange:i}),v.length?/* @__PURE__ */ (0,p.jsx)(`ol`,{className:`univer-space-y-1`,children:v.map(r=>/* @__PURE__ */ (0,p.jsx)(`li`,{draggable:!0,className:`univer-flex univer-items-center univer-gap-1 univer-truncate univer-rounded univer-py-1 univer-text-left univer-text-gray-800`,style:pn(r.depth),onDragStart:e=>{var t;h(r.nodeId),(t=e.dataTransfer)==null||t.setData(`text/plain`,r.nodeId),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`)},onDragOver:e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`)},onDrop:e=>k(e,r.nodeId),onDragEnd:()=>h(null),children:(a==null?void 0:a.nodeId)===r.nodeId?/* @__PURE__ */ (0,p.jsxs)(`div`,{className:(0,d.clsx)(`univer-flex univer-min-w-0 univer-flex-1 univer-gap-2`,`univer-items-center`),children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{autoFocus:!0,size:`small`,className:void 0,value:a.text,onChange:e=>o({nodeId:r.nodeId,text:e}),onKeyDown:e=>{e.key===`Enter`&&O(),e.key===`Escape`&&o(null)}}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`primary`,disabled:!a.text.trim(),onClick:O,children:n.t(`boards-mind-ui.panel.rename`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`default`,onClick:()=>o(null),children:n.t(`boards-mind-ui.panel.cancel`)})]}):/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`ghost`,className:(0,d.clsx)(`univer-min-w-0 univer-flex-1 univer-justify-start univer-truncate univer-text-left`,!1),onClick:()=>t.selectElements({unitId:e.unitId,subUnitId:e.subUnitId},[r.nodeId],r.nodeId),children:r.text}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:(0,d.clsx)(`univer-text-gray-500`,`univer-text-xs`),size:`small`,variant:`default`,onClick:()=>D(r.nodeId,r.text),children:n.t(`boards-mind-ui.panel.rename`)})]})},r.nodeId))}):/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-text-xs univer-text-gray-400 dark:!univer-text-gray-500`,"data-board-mind-map-panel-empty-state":`true`,children:n.t(`boards-mind-ui.panel.emptyNodes`)})]})}),g===`layout`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.layout`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-space-y-3`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(d.Select,{className:`univer-w-full univer-min-w-0`,"aria-label":n.t(`boards-mind-ui.panel.tab.layout`),options:Qt.map(e=>({label:n.t(e.labelKey),value:e.value})),value:f,onChange:e=>S(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(mn,{items:Zt.map(e=>({label:n.t(e.labelKey),value:e.value})),value:u,onChange:e=>x(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(mn,{items:b.map(e=>({label:n.t(e.labelKey),value:e.value})),value:m,onChange:e=>C(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-space-y-2`,children:Xt.map(({labelKey:e,key:t,min:r,max:i})=>/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-xs univer-text-gray-600`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-w-20 univer-shrink-0`,children:n.t(e)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{controls:!0,inputClassName:void 0,min:r,max:i,step:4,value:l[t],precision:0,className:`univer-w-24`,onChange:e=>w(t,Number(e??r))})]},t))})]})}),g===`importExport`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.importExport`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Textarea,{className:(0,d.clsx)(`univer-h-28 univer-resize-none`,`univer-text-xs`),placeholder:n.t(`boards-mind-ui.panel.pasteOPML`),value:s,onValueChange:c}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`primary`,disabled:!s.trim(),onClick:T,children:n.t(`boards-mind-ui.panel.importOPML`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`default`,onClick:E,children:n.t(`boards-mind-ui.panel.exportOPML`)})]})]})})]})}let _n=class extends a.Disposable{constructor(e,t,n){super(),this._commandService=e,this._localeService=t,this._sidebarService=n,x(this,`_sidebarDisposable`,null),this.disposeWithMe(this._commandService.registerCommand(Jt)),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Jt.id)return;let t=e.params;t&&`unitId`in t&&typeof t.unitId==`string`&&`subUnitId`in t&&typeof t.subUnitId==`string`&&`scopeId`in t&&typeof t.scopeId==`string`&&this.open({unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,nodeId:`nodeId`in t&&typeof t.nodeId==`string`?t.nodeId:void 0})}))}dispose(){var e;(e=this._sidebarDisposable)==null||e.dispose(),this._sidebarDisposable=null,super.dispose()}open(e){var t;let n={label:Y,...e},r={id:Y,layout:`canvas`,header:{title:this._localeService.t(`boards-mind-ui.panel.title`)},width:388,children:n,onClose:()=>{this._sidebarDisposable=null}};(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=this._sidebarService.open(r)}};_n=C([S(0,a.ICommandService),S(1,(0,a.Inject)(a.LocaleService)),S(2,(0,a.Inject)(c.ISidebarService))],_n);function vn(e){let t=(0,c.useDependency)(a.ICommandService),n=e.popup.extraProps;return n?/* @__PURE__ */ (0,p.jsx)(l.MobileShapeMenu,{shapeRef:{hostType:a.UniverInstanceType.UNIVER_BOARD,unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.elementId},onText:()=>ct(t,`edit-text`),onStyle:()=>t.executeCommand(Jt.id,{unitId:n.unitId,subUnitId:n.subUnitId,scopeId:n.scopeId,nodeId:n.elementId}),onDelete:()=>ct(t,`delete`)}):null}function yn(e){var t,r,i,o,s;let m=(0,c.useDependency)(a.ICommandService),h=(0,c.useDependency)(a.LocaleService),g=(0,c.useDependency)(c.IFontService),_=(0,c.useObservable)(g.fonts$,g.getFonts()),[v,y]=(0,f.useState)(null),b=(0,l.getTextStyle)(e.shapeData),x=b.ff??u.ShapeDefaultConfig.shapeText.fontFamily,S=b.fs??u.ShapeDefaultConfig.shapeText.fontSize;function C(t){return m.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:e.unitId,subUnitId:e.subUnitId,nodeId:e.nodeId,...t})}let w=[{key:`fill`,value:((t=e.shapeData.fill)==null?void 0:t.color)??u.ShapeDefaultConfig.fill},{key:`stroke`,value:((r=e.shapeData.stroke)==null?void 0:r.color)??u.ShapeDefaultConfig.stroke},{key:`fontColor`,value:((i=b.cl)==null?void 0:i.rgb)??u.ShapeDefaultConfig.shapeText.color}];if(v){var T;return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-w-full`,onClick:()=>y(null),size:`middle`,children:h.t(`boards-mind-ui.panel.cancel`)}),v===`fontFamily`?_==null?void 0:_.map(e=>/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-w-full`,"aria-pressed":x===e.value,variant:x===e.value?`primary`:`default`,onClick:async()=>{await C({textStyle:{fontFamily:e.value}}),y(null)},size:`middle`,children:e.label},e.value)):/* @__PURE__ */ (0,p.jsx)(d.MobileColorPresets,{value:(T=w.find(({key:e})=>e===v))==null?void 0:T.value,onSelect:async e=>{v===`fill`?await C({fillColor:e}):v===`stroke`?await C({strokeColor:e}):await C({textStyle:{color:e}}),y(null)}})]})}let E=[{key:`bold`,active:b.bl===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(Te,{})},{key:`italic`,active:b.it===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(ke,{})},{key:`underline`,active:((o=b.ul)==null?void 0:o.s)===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(Ue,{})},{key:`strikethrough`,active:((s=b.st)==null?void 0:s.s)===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(Ve,{})}];return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-grid-cols-4 univer-gap-2`,children:E.map(({key:e,active:t,icon:n})=>/* @__PURE__ */ (0,p.jsx)(d.Button,{"aria-label":h.t(`boards-mind-ui.panel.nodeStyle.${e}`),"aria-pressed":t,variant:t?`primary`:`default`,onClick:()=>C({textStyle:{[e]:!t}}),size:`middle`,children:n},e))}),/* @__PURE__ */ (0,p.jsxs)(d.Button,{className:`univer-w-full univer-justify-between`,onClick:()=>y(`fontFamily`),size:`middle`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.panel.nodeStyle.fontFamily`)}),/* @__PURE__ */ (0,p.jsx)(`span`,{children:x})]}),/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-4`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.panel.nodeStyle.fontSize`)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{className:`univer-w-32`,controls:!1,min:1,value:S,onChange:e=>{if(e!=null)return C({textStyle:{fontSize:e}})},size:`small`})]}),w.map(({key:e,value:t})=>/* @__PURE__ */ (0,p.jsxs)(d.Button,{className:`univer-w-full univer-justify-between`,onClick:()=>y(e),size:`middle`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.toolbar.action.${e}`)}),/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-size-6 univer-rounded univer-border univer-border-solid univer-border-gray-200`,style:{backgroundColor:t}})]},e))]})}function bn(e){return/* @__PURE__ */ (0,p.jsx)(`div`,{className:(0,d.clsx)(`univer-grid univer-w-full univer-gap-2`,e.items.length===4?`univer-grid-cols-[repeat(4,minmax(min-content,1fr))] max-[359px]:univer-grid-cols-2`:`univer-grid-cols-3`),children:e.items.map(t=>/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-min-w-0 univer-whitespace-normal univer-px-2`,variant:e.value===t.value?`primary`:`default`,"aria-pressed":e.value===t.value,onClick:()=>e.onChange(t.value),size:`middle`,children:/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-min-w-0 univer-break-words`,children:t.label})},t.value))})}function xn(e){let{commandService:r,elementStateService:i,localeService:a,query:o,setQuery:s,editingOutlineNode:c,setEditingOutlineNode:l,opmlText:u,setOpmlText:f,spacing:m,layoutDirection:h,structureKind:g,branchLineType:_,activeTab:v,setActiveTab:y,visibleOutlineItems:b,baseParams:x,tabItems:S,selectedNode:C,branchLineItems:w,changeLayout:T,changeStructureKind:E,changeBranchLineType:D,changeSpacing:O,importOpml:k,startRenameNode:A,commitRenameNode:j}=hn(e,e.nodeId?`style`:`structure`);return(C==null?void 0:C.type)===t.BoardElementType.Shape&&S.unshift({label:a.t(`boards-mind-ui.panel.nodeStyle.style`),value:`style`}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-size-full univer-bg-gray-0 univer-text-sm univer-text-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-gray-200`,"data-board-mind-map-panel":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-py-3`,"data-board-mind-map-panel-tabs":`true`,children:/* @__PURE__ */ (0,p.jsx)(d.Segmented,{className:`univer-w-full [&_button]:univer-whitespace-normal [&_button]:univer-break-words [&_button]:univer-px-1`,items:S,value:v,onChange:e=>y(e)})}),v===`style`&&(C==null?void 0:C.type)===t.BoardElementType.Shape&&/* @__PURE__ */ (0,p.jsx)(yn,{unitId:e.unitId,subUnitId:e.subUnitId,nodeId:C.id,shapeData:C.shapeData}),v===`structure`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.structure`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{slot:/* @__PURE__ */ (0,p.jsx)(Le,{}),value:o,placeholder:a.t(`boards-mind-ui.panel.searchNodes`),className:(0,d.clsx)(`univer-mb-3 univer-w-full`,``),onChange:s,size:`small`}),b.length?/* @__PURE__ */ (0,p.jsx)(`ol`,{className:`univer-space-y-1`,children:b.map(t=>/* @__PURE__ */ (0,p.jsx)(`li`,{className:`univer-flex univer-items-center univer-gap-1 univer-truncate univer-rounded univer-py-1 univer-text-left univer-text-gray-800`,style:pn(t.depth),children:(c==null?void 0:c.nodeId)===t.nodeId?/* @__PURE__ */ (0,p.jsxs)(`div`,{className:(0,d.clsx)(`univer-flex univer-min-w-0 univer-flex-1 univer-gap-2`,`univer-flex-wrap`),children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{autoFocus:!1,size:`small`,className:`univer-w-full`,value:c.text,onChange:e=>l({nodeId:t.nodeId,text:e}),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&l(null)}}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`primary`,disabled:!c.text.trim(),onClick:j,children:a.t(`boards-mind-ui.panel.rename`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`default`,onClick:()=>l(null),children:a.t(`boards-mind-ui.panel.cancel`)})]}):/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`middle`,variant:`ghost`,className:(0,d.clsx)(`univer-min-w-0 univer-flex-1 univer-justify-start univer-truncate univer-text-left`,``),onClick:()=>i.selectElements({unitId:e.unitId,subUnitId:e.subUnitId},[t.nodeId],t.nodeId),children:t.text}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:(0,d.clsx)(`univer-text-gray-500`,`univer-px-3`),size:`middle`,variant:`default`,onClick:()=>A(t.nodeId,t.text),children:a.t(`boards-mind-ui.panel.rename`)})]})},t.nodeId))}):/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-text-xs univer-text-gray-400 dark:!univer-text-gray-500`,"data-board-mind-map-panel-empty-state":`true`,children:a.t(`boards-mind-ui.panel.emptyNodes`)})]})}),v===`layout`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.layout`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-space-y-3`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(bn,{items:Qt.map(e=>({label:a.t(e.labelKey),value:e.value})),value:g,onChange:e=>E(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(bn,{items:Zt.map(e=>({label:a.t(e.labelKey),value:e.value})),value:h,onChange:e=>T(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(bn,{items:w.map(e=>({label:a.t(e.labelKey),value:e.value})),value:_,onChange:e=>D(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-space-y-2`,children:Xt.map(({labelKey:e,key:t,min:n,max:r})=>/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-xs univer-text-gray-600`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-flex-1 univer-text-sm`,children:a.t(e)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{controls:!1,min:n,max:r,step:4,value:m[t],precision:0,className:`univer-w-32`,onChange:e=>O(t,Number(e??n)),size:`small`})]},t))})]})}),v===`importExport`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.importExport`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Textarea,{className:(0,d.clsx)(`univer-h-28 univer-resize-none`,``),placeholder:a.t(`boards-mind-ui.panel.pasteOPML`),value:u,onValueChange:f,size:`small`}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`primary`,disabled:!u.trim(),onClick:k,children:a.t(`boards-mind-ui.panel.importOPML`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`default`,onClick:async()=>{let e=await r.executeCommand(n.ExportMindMapOpmlOperation.id,x);e!==!1&&f(e)},children:a.t(`boards-mind-ui.panel.exportOPML`)})]})]})})]})}let Sn=class extends a.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(Ke,Je)),this.disposeWithMe(this._componentManager.register(st,vn)),this.disposeWithMe(this._componentManager.register(Y,xn))}};Sn=C([S(0,(0,a.Inject)(c.ComponentManager))],Sn);let Cn=class extends a.Disposable{constructor(e,t,n){super(),this._commandService=e,this._localeService=t,this._sidebarService=n,x(this,`_sidebarDisposable`,null),this.disposeWithMe(this._commandService.registerCommand(Jt)),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Jt.id)return;let t=e.params;t&&`unitId`in t&&typeof t.unitId==`string`&&`subUnitId`in t&&typeof t.subUnitId==`string`&&`scopeId`in t&&typeof t.scopeId==`string`&&this.open({unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,nodeId:`nodeId`in t&&typeof t.nodeId==`string`?t.nodeId:void 0})}))}dispose(){var e;(e=this._sidebarDisposable)==null||e.dispose(),this._sidebarDisposable=null,super.dispose()}open(e){var t;let n={label:Y,...e};(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=this._sidebarService.open({id:Y,header:{title:this._localeService.t(`boards-mind-ui.panel.title`)},width:388,children:n,onClose:()=>{this._sidebarDisposable=null}})}};Cn=C([S(0,a.ICommandService),S(1,(0,a.Inject)(a.LocaleService)),S(2,(0,a.Inject)(c.ISidebarService))],Cn);let wn=class extends a.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(Ke,Je)),this.disposeWithMe(this._componentManager.register(st,St)),this.disposeWithMe(this._componentManager.register(Y,gn))}};wn=C([S(0,(0,a.Inject)(c.ComponentManager))],wn);let Z=class{constructor(e,t,n){this._stateService=e,this._insertStateService=t,this._renderManagerService=n}beginMindMapMode(e){var n,i;let a=(n=this._renderManagerService.getRenderUnitById(e.unitId))==null||(i=n.getInjector)==null?void 0:i.call(n),o=(a==null?void 0:a.get(r.IBoardUIStateService))??this._stateService;return((a==null?void 0:a.get(W))??this._insertStateService).setTemplate({rootText:e.rootText,structureKind:e.structureKind,branchLineType:e.branchLineType,children:e.children,blueprint:e.blueprint}),o.setShapeSidebarOpen(!1),o.clearPendingInsert(),o.setActiveTool(t.BoardToolType.MindMap),o.setPendingInsert({type:t.BoardToolType.MindMap}),!0}};Z=C([S(0,r.IBoardUIStateService),S(1,(0,a.Inject)(W)),S(2,o.IRenderManagerService)],Z);let Tn=`UNIVER_BOARDS_MIND_UI_PLUGIN`,En=[z],Dn=[Kt],Q=class extends a.Plugin{constructor(e=_,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{...i}=(0,a.merge)({},_,this._config);this._configService.setConfig(g,i)}onStarting(){r.UniverBoardsUIPlugin.registerRuntimeScopedDependencies(this._injector,[[W],[K]]),this._getDependencies().forEach(e=>this._injector.add(e));let e=this._injector.get(Z),n=this._injector.get(t.IBoardMindMapAdapterService);this.disposeWithMe(n.registerAdapter(e)),this.disposeWithMe(this._injector.get(V)),this.disposeWithMe(this._injector.get(J)),this.disposeWithMe(this._injector.get(Cn)),this.disposeWithMe(this._injector.get(wn)),this._enableMindMapToolbarTool()}_getDependencies(){return[[W],[K],[Z],[V],[J],[Cn],[wn]]}_getRenderModules(){return[En,Dn,[G],[Ut],[wt],[de],[w],[Pt]]}onReady(){this._getRenderModules().forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_BOARD,e))})}_enableMindMapToolbarTool(){var e,n;let i=this._getBoardsUIConfig();this._configService.setConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY,{...i,toolbar:{...i.toolbar,tools:{...(e=i.toolbar)==null?void 0:e.tools,[t.BoardToolType.MindMap]:On((n=i.toolbar)==null||(n=n.tools)==null?void 0:n[t.BoardToolType.MindMap])}}})}_getBoardsUIConfig(){return this._configService.getConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY)??{}}};x(Q,`pluginName`,Tn),x(Q,`packageName`,m),x(Q,`version`,h),x(Q,`type`,a.UniverInstanceType.UNIVER_BOARD),Q=C([(0,a.DependentOn)(i.UniverLicensePlugin,o.UniverRenderEnginePlugin,t.UniverBoardsPlugin,n.UniverBoardsMindPlugin,r.UniverBoardsUIPlugin),S(1,(0,a.Inject)(a.Injector)),S(2,a.IConfigService),S(3,o.IRenderManagerService)],Q);function On(e){return e===!1?!1:typeof e!=`object`||{...e,enabled:e.enabled??!0}}let $=class extends a.Plugin{constructor(e=_,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{...i}=(0,a.merge)({},_,this._config);this._configService.setConfig(g,i)}onStarting(){let e=[[W],[K]];r.UniverBoardsMobileUIPlugin.registerRuntimeScopedDependencies(this._injector,e),[...e,[Z],[V],[J],[_n],[Sn]].forEach(e=>this._injector.add(e)),this.disposeWithMe(this._injector.get(t.IBoardMindMapAdapterService).registerAdapter(this._injector.get(Z))),this.disposeWithMe(this._injector.get(V)),this.disposeWithMe(this._injector.get(J)),this.disposeWithMe(this._injector.get(_n)),this.disposeWithMe(this._injector.get(Sn)),this._enableMindMapToolbarTool()}onReady(){[[z],[Kt],[G,{useClass:qt}],[Ut],[wt],[de],[w],[Pt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_BOARD,e))})}_enableMindMapToolbarTool(){var e,n;let i=this._getBoardsUIConfig();this._configService.setConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY,{...i,toolbar:{...i.toolbar,tools:{...(e=i.toolbar)==null?void 0:e.tools,[t.BoardToolType.MindMap]:kn((n=i.toolbar)==null||(n=n.tools)==null?void 0:n[t.BoardToolType.MindMap])}}})}_getBoardsUIConfig(){return this._configService.getConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY)??{}}};x($,`pluginName`,Tn),x($,`packageName`,m),x($,`version`,h),x($,`type`,a.UniverInstanceType.UNIVER_BOARD),$=C([(0,a.DependentOn)(i.UniverLicensePlugin,o.UniverRenderEnginePlugin,t.UniverBoardsPlugin,n.UniverBoardsMindPlugin,r.UniverBoardsMobileUIPlugin),S(1,(0,a.Inject)(a.Injector)),S(2,a.IConfigService),S(3,o.IRenderManagerService)],$);function kn(e){return e===!1?!1:typeof e!=`object`||{...e,enabled:e.enabled??!0}}Object.defineProperty(e,"UniverBoardsMindMobileUIPlugin",{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,"UniverBoardsMindUIPlugin",{enumerable:!0,get:function(){return Q}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/boards"),require("@univerjs-pro/boards-mind"),require("@univerjs-pro/boards-ui"),require("@univerjs-pro/license"),require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@univerjs-pro/shape-editor-ui"),require("@univerjs-pro/engine-shape"),require("@univerjs/design"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/boards`,`@univerjs-pro/boards-mind`,`@univerjs-pro/boards-ui`,`@univerjs-pro/license`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`,`@univerjs/ui`,`@univerjs-pro/shape-editor-ui`,`@univerjs-pro/engine-shape`,`@univerjs/design`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProBoardsMindUi={},e.UniverProBoards,e.UniverProBoardsMind,e.UniverProBoardsUi,e.UniverProLicense,e.UniverCore,e.UniverEngineRender,e.rxjs,e.UniverUi,e.UniverProShapeEditorUi,e.UniverProEngineShape,e.UniverDesign,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var m=`@univerjs-pro/boards-mind-ui`,h=`1.6.0`;let g=`boards-mind-ui.config`,_={};function v(e){"@babel/helpers - typeof";return v=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},v(e)}function y(e,t){if(v(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(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function b(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function x(e,t,n){return(t=b(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e,t){return function(n,r){t(n,r,e)}}function C(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 w=class extends a.RxDisposable{constructor(e,t,n){super(),this._renderContext=e,this._boardElementService=t,this._commandService=n,x(this,`_nodeSizeByKey`,/* @__PURE__ */ new Map),x(this,`_queuedLayouts`,/* @__PURE__ */ new Map),x(this,`_layoutFlushScheduled`,!1),this._init()}_init(){this._seedExistingNodeSizes(),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementAdd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e.forEach(e=>{let t=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.elementId);this._rememberNodeSize(e,t)})}))),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementUpdate$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e.forEach(e=>this._handleElementUpdate(e))})))}_seedExistingNodeSizes(){let e=this._renderContext.unitId,t=this._boardElementService.getElementDataForUnit(e);Object.entries(t).forEach(([t,n])=>{Object.values(n.data).forEach(n=>{this._rememberNodeSize({unitId:e,subUnitId:t,elementId:n.elementId},n)})})}_handleElementUpdate(e){if(e.unitId!==this._renderContext.unitId)return;let t=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.elementId),r=(0,n.getMindMapNodeMeta)(t==null?void 0:t.element),i=this._resolveNodeSize(t);if(!r||!i){this._nodeSizeByKey.delete(this._getElementKey(e));return}let a=this._getElementKey(e),o=this._nodeSizeByKey.get(a);this._nodeSizeByKey.set(a,i),o&&o.width===i.width&&o.height===i.height||this._queueLayout({unitId:e.unitId,subUnitId:e.subUnitId,scopeId:r.structureScopeId})}_rememberNodeSize(e,t){if(e.unitId!==this._renderContext.unitId)return;let r=(0,n.getMindMapNodeMeta)(t==null?void 0:t.element),i=this._resolveNodeSize(t);r&&i&&this._nodeSizeByKey.set(this._getElementKey(e),i)}_resolveNodeSize(e){let t=(e==null?void 0:e.transform)??(e==null?void 0:e.element.transform),n=t==null?void 0:t.width,r=t==null?void 0:t.height;return!Number.isFinite(n)||!Number.isFinite(r)?null:{width:n,height:r}}_queueLayout(e){this._queuedLayouts.set(`${e.unitId}:${e.subUnitId}:${e.scopeId}`,e),this._layoutFlushScheduled||(this._layoutFlushScheduled=!0,Promise.resolve().then(()=>{this._layoutFlushScheduled=!1;let e=Array.from(this._queuedLayouts.values());this._queuedLayouts.clear(),e.forEach(e=>{this._executeRootAnchoredLayout(e)})}))}_executeRootAnchoredLayout(e){var t;let r=this._boardElementService.getElementById(e.unitId,e.subUnitId,e.scopeId),i=(t=(0,n.getMindMapContainerMeta)(r==null?void 0:r.element))==null?void 0:t.rootNodeId;this._commandService.executeCommand(n.LayoutMindMapOperation.id,{...e,skipUndo:!0,...i?{anchorNodeId:i}:null})}_getElementKey(e){return`${e.unitId}:${e.subUnitId}:${e.elementId}`}};w=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,a.ICommandService)],w);let T={primaryColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_STROKE_COLOR,surfaceColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_BACKGROUND_COLOR,textColor:l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_COLOR,fontFamily:a.DEFAULT_STYLES.ff};function E(e,t){let n=Math.min(1,Math.max(0,Number.isFinite(t)?t:1)),r=e.trim(),i=/^#([0-9a-fA-F]{6})$/.exec(r);if(!i)return e;let a=i[1];return`rgba(${Number.parseInt(a.slice(0,2),16)}, ${Number.parseInt(a.slice(2,4),16)}, ${Number.parseInt(a.slice(4,6),16)}, ${n})`}let D={primaryColor:T.primaryColor,ghostFillColor:E(T.surfaceColor,.72),ghostTextColor:E(T.textColor,.62),rootTextColor:E(T.surfaceColor,.86),sourceHighlightFillColor:E(T.primaryColor,.12),sourceHighlightStrokeColor:E(T.primaryColor,.9),objectAlpha:.72,dragObjectAlpha:.78,connectorAlpha:.64,lineWidthScreen:2,fallbackNodeWidth:n.MIND_MAP_DEFAULT_NODE_SIZE.nodeWidth,fallbackNodeHeight:n.MIND_MAP_DEFAULT_NODE_SIZE.nodeHeight,branchGap:n.MIND_MAP_DEFAULT_LAYOUT.branchGap,sourceHaloScreen:4,ghostRadius:8,rootRadius:10,fontFamily:T.fontFamily,ghostFontWeight:500,rootFontWeight:600,rootFontSize:18,textPaddingScreen:12,dirtyPaddingScreen:24,sourceDashScreen:[6,4]};function O(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.quadraticCurveTo(t+r,n,t+r,n+o),e.lineTo(t+r,n+i-o),e.quadraticCurveTo(t+r,n+i,t+r-o,n+i),e.lineTo(t+o,n+i),e.quadraticCurveTo(t,n+i,t,n+i-o),e.lineTo(t,n+o),e.quadraticCurveTo(t,n,t+o,n),e.closePath()}function k(e,t,n){return`${e} ${t/n}px ${D.fontFamily}`}let A=`board-mind-map-drag-preview-object`,j=r.BOARD_RENDER_LAYER_INDEX.preview;function M(e,t){return Number.isFinite(e)?e:t}function N(){return D.fallbackNodeWidth}function P(){return D.fallbackNodeHeight}function F(e){return e===1?`left`:e===3?`right`:`center`}function ee(e,t,n,r){return n===1?e+r:n===3?e+t-r:e+t/2}var te=class extends o.BaseObject{constructor(e=A,t){super(e),x(this,`_state`,{ghostBounds:null,parentBounds:null,side:`right`,zoomRatio:1}),this.evented=!1,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientPreviewForeground,this.updateState(t)}updateState(e){if(this._state={...this._state,...e},this._state.ghostBounds){let e=this._resolveDirtyBounds();this.transformByState(e),this.show()}else this.hide();let t=this;typeof t.makeDirtyNoDebounce==`function`?t.makeDirtyNoDebounce(!0):this.makeDirty(!0)}isHit(e){return!1}render(e,t){let r=this._state.ghostBounds;if(!r||!this.visible)return this.makeDirty(!1),this;let i=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,a=M(r.left,0),o=M(r.top,0),s=Math.max(1,M(r.width,N())),c=Math.max(1,M(r.height,P()));if(e.save(),e.globalAlpha=D.dragObjectAlpha,e.lineWidth=D.lineWidthScreen/i,e.strokeStyle=D.primaryColor,e.fillStyle=D.ghostFillColor,this._drawConnectorPreview(e,{left:a,top:o,width:s,height:c},i),this._drawSourceHighlight(e,i),this._state.renderGhostNode===!1)return e.restore(),this.makeDirty(!1),this;O(e,a,o,s,c,D.ghostRadius),e.fill(),e.stroke();let l=this._state.textStyle,u=Number.isFinite(l==null?void 0:l.fontSize)&&((l==null?void 0:l.fontSize)??0)>0?l.fontSize:16,d=D.textPaddingScreen/i;return e.fillStyle=(l==null?void 0:l.color)??D.ghostTextColor,e.font=k(D.ghostFontWeight,u,i),e.textAlign=F(l==null?void 0:l.horizontalAlign),e.textBaseline=`middle`,e.fillText((l==null?void 0:l.text)||n.MIND_MAP_DEFAULT_NODE_TEXT,ee(a,s,l==null?void 0:l.horizontalAlign,d),o+c/2,Math.max(1,s-d*2)),e.restore(),this.makeDirty(!1),this}_resolveDirtyBounds(){let e=this._state.ghostBounds,t=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,n=D.dirtyPaddingScreen/t;if(!e)return{left:0,top:0,width:1,height:1};let r=M(e.left,0),i=M(e.top,0),a=Math.max(1,M(e.width,N())),o=Math.max(1,M(e.height,P())),s=this._state.sourceBounds,c=this._state.parentBounds,l=M(s==null?void 0:s.left,r),u=M(s==null?void 0:s.top,i),d=Math.max(1,M(s==null?void 0:s.width,a)),f=Math.max(1,M(s==null?void 0:s.height,o));if(!c){let e=Math.min(r,l)-n,t=Math.min(i,u)-n,s=Math.max(r+a,l+d)+n,c=Math.max(i+o,u+f)+n;return{left:e,top:t,width:s-e,height:c-t}}let p=M(c.left,r),m=M(c.top,i),h=Math.max(1,M(c.width,N())),g=Math.max(1,M(c.height,P())),_=Math.min(r,p,l)-n,v=Math.min(i,m,u)-n,y=Math.max(r+a,p+h,l+d)+n,b=Math.max(i+o,m+g,u+f)+n;return{left:_,top:v,width:y-_,height:b-v}}_drawSourceHighlight(e,t){var n;let r=this._state.sourceBounds;if(!r)return;let i=D.sourceHaloScreen/t,a=M(r.left,0)-i,o=M(r.top,0)-i,s=Math.max(1,M(r.width,N()))+i*2,c=Math.max(1,M(r.height,P()))+i*2;e.save(),e.globalAlpha=1,e.lineWidth=D.lineWidthScreen/t,e.strokeStyle=D.sourceHighlightStrokeColor,e.fillStyle=D.sourceHighlightFillColor,(n=e.setLineDash)==null||n.call(e,D.sourceDashScreen.map(e=>e/t)),O(e,a,o,s,c,D.rootRadius),e.fill(),e.stroke(),e.restore()}_drawConnectorPreview(e,t,n){let r=this._state.parentBounds;if(!r)return;let i=M(r.left,0),a=M(r.top,0),o=Math.max(1,M(r.width,N())),s=Math.max(1,M(r.height,P())),c=D.branchGap,l=this._state.side??`right`;if(e.save(),e.globalAlpha=D.connectorAlpha,e.strokeStyle=D.primaryColor,e.lineWidth=D.lineWidthScreen/n,e.lineCap=`round`,e.lineJoin=`round`,e.beginPath(),l===`top`||l===`bottom`){let n=i+o/2,r=t.left+t.width/2,u=l===`bottom`?a+s:a,d=l===`bottom`?t.top:t.top+t.height,f=l===`bottom`?Math.min(u+c,(u+d)/2):Math.max(u-c,(u+d)/2);e.moveTo(n,u),e.lineTo(n,f),e.lineTo(r,f),e.lineTo(r,d)}else{let n=a+s/2,r=t.top+t.height/2,u=l===`right`?i+o:i,d=l===`right`?t.left:t.left+t.width,f=l===`right`?Math.min(u+c,(u+d)/2):Math.max(u-c,(u+d)/2);e.moveTo(u,n),e.lineTo(f,n),e.lineTo(f,r),e.lineTo(d,r)}e.stroke(),e.restore()}};function I(e,t){return(t==null?void 0:t[e.elementId])??e.element.transform}function ne(e,t){let n=I(e,t);return{x:(n.left??0)+(n.width??0)/2,y:(n.top??0)+(n.height??0)/2}}function re(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function ie(e,t){let n=e.left??0,r=e.top??0,i=n+(e.width??0),a=r+(e.height??0),o=t.left??0,s=t.top??0,c=o+(t.width??0),l=s+(t.height??0),u=Math.max(o-i,n-c,0),d=Math.max(s-a,r-l,0);return Math.hypot(u,d)}function L(e,t,r){var i;let a=(0,n.getMindMapNodeMeta)((i=e[t])==null?void 0:i.element);for(;a!=null&&a.parentNodeId;){var o;if(a.parentNodeId===r)return!0;a=(0,n.getMindMapNodeMeta)((o=e[a.parentNodeId])==null?void 0:o.element)}return!1}function ae(e,t,n){let r=I(e,n),i=r.top??0,a=r.height??0;return a<=0?null:t.y<=i+a/3?`before`:t.y>=i+a*2/3?`after`:null}function oe(e,t){let n=t==null?void 0:t[e];return Number.isFinite(n==null?void 0:n.left)&&Number.isFinite(n==null?void 0:n.top)?{kind:`detach`,left:n.left,top:n.top}:{kind:`detach`}}function R(e,t,r){let i=e[t],a=(0,n.getMindMapNodeMeta)(i==null?void 0:i.element);if(!i||!a||!a.parentNodeId&&!(r!=null&&r.allowRootReparent))return{kind:`none`};let o=r==null?void 0:r.boundsByElementId,s=I(i,o),c=ne(i,o),l=Object.values(e).map(i=>{let c=(0,n.getMindMapNodeMeta)(i.element);return!c||i.elementId===t||i.elementId===a.parentNodeId||r!=null&&r.allowRootReparent&&!a.parentNodeId&&c.structureScopeId===a.structureScopeId||L(e,i.elementId,t)?null:{item:i,snapDistance:ie(s,I(i,o)),center:ne(i,o)}}).filter(e=>!!e).sort((e,t)=>e.snapDistance-t.snapDistance||re(c,e.center)-re(c,t.center))[0];if(l&&l.snapDistance<=100){let e=(0,n.getMindMapNodeMeta)(l.item.element),t=e!=null&&e.parentNodeId?ae(l.item,c,o):null;return e!=null&&e.parentNodeId&&t?{kind:`reparent`,newParentNodeId:e.parentNodeId,side:e.side??`right`,referenceNodeId:l.item.elementId,placement:t}:{kind:`reparent`,newParentNodeId:l.item.elementId,side:c.x<l.center.x?`left`:`right`}}if(r!=null&&r.detachWhenNoSnap)return oe(t,o);if(!a.parentNodeId)return{kind:`none`};let u=e[a.parentNodeId];return u&&re(c,ne(u,o))>560?oe(t,o):{kind:`none`}}function se(e,t){var r,i;return e.elementId===t||((r=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:r.structureScopeId)===t||((i=(0,n.getMindMapConnectorMeta)(e.element))==null?void 0:i.structureScopeId)===t}function ce(e,t,n,r){let i=e[t];if(!i)return e;let a=i.transform??i.element.transform??{};return{...e,[t]:{...i,transform:{...a,left:(a.left??0)+n,top:(a.top??0)+r},element:{...i.element,transform:{...i.element.transform,left:(i.element.transform.left??0)+n,top:(i.element.transform.top??0)+r}}}}}function le(e){if(!Number.isFinite(e.liveRootBounds.left)||!Number.isFinite(e.liveRootBounds.top)||!Number.isFinite(e.rootStartBounds.left)||!Number.isFinite(e.rootStartBounds.top))return null;let n=e.liveRootBounds.left-e.rootStartBounds.left,r=e.liveRootBounds.top-e.rootStartBounds.top,i=ce(e.elementData,e.scopeId,n,r),a=[];return Object.values(i).forEach(o=>{if(o.elementId===e.rootNodeId||o.elementId===e.scopeId||!se(o,e.scopeId))return;if(`connectorData`in o.element){var s;let i=(s=e.elementData[o.elementId])==null?void 0:s.element;i&&`connectorData`in i&&a.push({kind:`connector`,elementId:o.elementId,element:(0,t.offsetBoardConnectorGeometry)(i,{x:n,y:r})});return}let c=(0,t.resolveBoardElementWorldBounds)(i,o.elementId);c&&a.push({kind:`bounds`,elementId:o.elementId,bounds:c})}),{deltaX:n,deltaY:r,elementData:i,items:a}}let z=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._commandService=r,this._uiStateService=i,this._instanceService=a,this._undoRedoGroupService=o,x(this,`_dragStart`,null),x(this,`_pointerDragStart`,null),x(this,`_dragPreviewObject`,null),x(this,`_childDragActivated`,!1),x(this,`_lastChildDragAction`,null),x(this,`_objectPointerDisposables`,null),x(this,`_attachObjectPointerScheduled`,!1),x(this,`_activePointerDragDisposables`,null),x(this,`_childDragSelectionHidden`,!1),this._init()}_init(){var e,t,n,r,i;let o=this._renderContext.scene.getTransformerByCreate();this.disposeWithMe((0,a.toDisposable)(o.changeStart$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._captureDragStart()}))),this.disposeWithMe((0,a.toDisposable)(((e=o.changing$)==null?void 0:e.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{this._syncDragPreview(e==null?void 0:e.objects)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(o.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{setTimeout(()=>this._applyDragTopologyAction(e==null?void 0:e.objects),0)}))),this.disposeWithMe((0,a.toDisposable)(((t=this._renderContext.scene.onPointerDown$)==null?void 0:t.subscribeEvent({priority:3,next:([e])=>this._capturePointerChildDragStart(e)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((n=this._renderContext.scene.onPointerMove$)==null?void 0:n.subscribeEvent({priority:3,next:([e,t])=>this._syncPointerChildDragPreview(e,t)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((r=this._renderContext.scene.onPointerUp$)==null?void 0:r.subscribeEvent({priority:3,next:([e,t])=>this._applyPointerChildDrag(e,t)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((i=this._renderContext.scene.onPointerCancel$)==null?void 0:i.subscribeEvent({priority:3,next:([,e])=>this._cancelPointerChildDrag(e)}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(()=>{var e;return(e=this._objectPointerDisposables)==null?void 0:e.dispose()})),this.disposeWithMe((0,a.toDisposable)(()=>this._disposeActivePointerDragListeners())),this._subscribeElementDataChanges(),this._scheduleAttachObjectPointerListeners(),this.disposeWithMe((0,a.toDisposable)(()=>this._removeDragPreviewObject()))}_subscribeElementDataChanges(){[this._boardElementService.elementAdd$,this._boardElementService.elementUpdate$,this._boardElementService.elementRemove$].forEach(e=>{this.disposeWithMe((0,a.toDisposable)(e.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._scheduleAttachObjectPointerListeners()})))}),this._elementStateService.state$&&this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._scheduleAttachObjectPointerListeners()})))}_scheduleAttachObjectPointerListeners(){this._attachObjectPointerScheduled||(this._attachObjectPointerScheduled=!0,Promise.resolve().then(()=>this._attachObjectPointerListeners()))}_attachObjectPointerListeners(){var e;this._attachObjectPointerScheduled=!1;let t=this._resolveCurrentBoardContext(),i=this._renderContext.scene;if(!t||typeof i.getObject!=`function`)return;let o=this._boardElementService.getElementData(t.unitId,t.subUnitId),s=new a.DisposableCollection;(e=this._objectPointerDisposables)==null||e.dispose(),this._objectPointerDisposables=s,Object.values(o).forEach(e=>{var a,o;let c=(0,n.getMindMapNodeMeta)(e.element);if(!(c!=null&&c.parentNodeId))return;let l=(0,r.getBoardElementRenderObjectKey)(t.unitId,e.elementId),u=((a=i.getObjectIncludeInGroup)==null?void 0:a.call(i,l))??((o=i.getObject)==null?void 0:o.call(i,l));u!=null&&u.onPointerDown$&&s.add(u.onPointerDown$.subscribeEvent({priority:-10,next:([n,r])=>this._capturePointerChildDragStart(n,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:e.elementId},r)}))})}_resolveCurrentBoardContext(){let e=this._elementStateService.getSnapshot().context;if(e)return e;let t=this._renderContext.unitId,n=t?this._instanceService.getUnit(t,a.UniverInstanceType.UNIVER_BOARD):null,r=n==null?void 0:n.getActivePageId();return!n||!r?null:{unitId:n.getUnitId(),subUnitId:r}}_captureDragStart(){let e=this._elementStateService.getSnapshot();this._childDragActivated=!1,this._childDragSelectionHidden=!1,this._lastChildDragAction=null;let r=e.context,i=e.focusedId??e.selectedIds[0];if(!r||!i){this._dragStart=null,this._removeDragPreviewObject();return}let a=this._boardElementService.getElementData(r.unitId,r.subUnitId);if(e.selectedIds.length>1){let n=this._resolveCompleteSelectedScope(a,e.selectedIds);if(!n){this._dragStart=null,this._removeDragPreviewObject();return}let i=a[n.rootNodeId],o=(0,t.resolveBoardElementWorldBounds)(a,n.rootNodeId),s=i.element.transform;this._dragStart={kind:`scope`,unitId:r.unitId,subUnitId:r.subUnitId,nodeId:n.rootNodeId,scopeId:n.scopeId,left:(o==null?void 0:o.left)??s.left??0,top:(o==null?void 0:o.top)??s.top??0,width:(o==null?void 0:o.width)??s.width??0,height:(o==null?void 0:o.height)??s.height??0,elementData:a};return}let o=a[i],s=(0,n.getMindMapNodeMeta)(o==null?void 0:o.element);if(!o||!s){this._dragStart=null,this._removeDragPreviewObject();return}let c=(0,t.resolveBoardElementWorldBounds)(a,i),l=o.element.transform;this._dragStart={kind:s.parentNodeId===null?`root`:`child`,unitId:r.unitId,subUnitId:r.subUnitId,nodeId:i,scopeId:s.structureScopeId,left:(c==null?void 0:c.left)??l.left??0,top:(c==null?void 0:c.top)??l.top??0,width:(c==null?void 0:c.width)??l.width??0,height:(c==null?void 0:c.height)??l.height??0,elementData:a}}_resolveCompleteSelectedScope(e,t){let r=new Set(t),i=t.map(t=>{var r,i,a,o;let s=(r=e[t])==null?void 0:r.element;return((i=(0,n.getMindMapNodeMeta)(s))==null?void 0:i.structureScopeId)??((a=(0,n.getMindMapConnectorMeta)(s))==null?void 0:a.structureScopeId)??((o=(0,n.getMindMapContainerMeta)(s))==null?void 0:o.structureScopeId)??null});if(i.some(e=>e===null)||new Set(i).size!==1)return null;let a=i[0];if(!a)return null;let o=Object.values(e).filter(e=>{var t;return e.element.visible!==!1&&((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.structureScopeId)===a});if(o.length===0||o.some(e=>!r.has(e.elementId)))return null;let s=o.filter(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.parentNodeId)===null});return s.length===1?{rootNodeId:s[0].elementId,scopeId:a}:null}_capturePointerChildDragStart(e,r,i){var a,o,s,c,l;if(this._uiStateService.getState().interactionMode===`viewing`||(e.button??0)!==0)return;let u=this._elementStateService.getSnapshot();if(u.activeEditingId){this._pointerDragStart=null;return}let d=r?{unitId:r.unitId,subUnitId:r.subUnitId}:u.context??this._resolveCurrentBoardContext(),f=(r==null?void 0:r.nodeId)??(u.selectedIds.length===1?u.focusedId??u.selectedIds[0]:void 0);if(!d){this._pointerDragStart=null;return}let p=this._boardElementService.getElementData(d.unitId,d.subUnitId),m=this._getBoardPointFromEvent(e);if(!r){let e=f?p[f]:null,r=(0,n.getMindMapNodeMeta)(e==null?void 0:e.element),i=f?(0,t.resolveBoardElementWorldBounds)(p,f)??(e==null?void 0:e.element.transform):null;r!=null&&r.parentNodeId&&i&&this._isPointInBounds(m,{left:i.left??0,top:i.top??0,width:i.width??0,height:i.height??0})||(f=this._findChildNodeAtPoint(p,m))}if(!f){this._pointerDragStart=null;return}let h=p[f],g=(0,n.getMindMapNodeMeta)(h==null?void 0:h.element);if(!h||!(g!=null&&g.parentNodeId)){this._pointerDragStart=null;return}this._instanceService.focusUnit(d.unitId),(a=this._renderContext.engine)==null||(o=a.getCanvasElement)==null||(o=o.call(a))==null||(s=o.focus)==null||s.call(o,{preventScroll:!0}),(c=(l=this._elementStateService).selectElements)==null||c.call(l,d,[f],f),i==null||i.stopPropagation();let _=(0,t.resolveBoardElementWorldBounds)(p,f),v=h.element.transform,y={left:(_==null?void 0:_.left)??v.left??0,top:(_==null?void 0:_.top)??v.top??0,width:(_==null?void 0:_.width)??v.width??0,height:(_==null?void 0:_.height)??v.height??0};if(!r&&!this._isPointInBounds(m,y)){this._pointerDragStart=null;return}let b=this._getPointerScreenPoint(e);this._childDragActivated=!1,this._childDragSelectionHidden=!1,this._lastChildDragAction=null,this._pointerDragStart={kind:`child`,unitId:d.unitId,subUnitId:d.subUnitId,nodeId:f,scopeId:g.structureScopeId,...y,pointerStartX:b.x,pointerStartY:b.y,elementData:p},this._attachActivePointerDragListeners(),this._consumePointerEvent(e,i)}_syncPointerChildDragPreview(e,t){var n,r;let i=this._pointerDragStart;if(!i||e.buttons!==void 0&&e.buttons!==1)return;let a=this._getPointerLiveBounds(e,i);if(!this._isChildDragPastActivationThreshold(i,a))return;this._childDragActivated||this._hideSelectionForChildDrag(),this._childDragActivated=!0;let o=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,a),s=R(i.elementData,i.nodeId,{boundsByElementId:o,detachWhenNoSnap:!0});this._lastChildDragAction=s,this._syncChildDragPreviewObject(a,s,o),this._consumePointerEvent(e,t),this._renderContext.scene.makeDirty(!0),(n=(r=this._renderContext.scene).requestRender)==null||n.call(r)}_applyPointerChildDrag(e,t){let n=this._pointerDragStart;if(!n)return;if(this._pointerDragStart=null,this._disposeActivePointerDragListeners(),this._removeDragPreviewObject(),!this._childDragActivated){this._lastChildDragAction=null;return}let r=this._boardElementService.getElementData(n.unitId,n.subUnitId),i=this._getPointerLiveBounds(e,n),a=this._createTopologyBoundsByElementId(r,n.nodeId,i),o=R(r,n.nodeId,{boundsByElementId:a,detachWhenNoSnap:!0});this._lastChildDragAction=null,this._executeChildDragAction(n.unitId,n.subUnitId,n.nodeId,r,o),this._childDragSelectionHidden=!1,this._consumePointerEvent(e,t)}_cancelPointerChildDrag(e){let t=this._pointerDragStart;if(t){if(this._pointerDragStart=null,this._disposeActivePointerDragListeners(),this._childDragActivated=!1,this._lastChildDragAction=null,this._removeDragPreviewObject(),this._childDragSelectionHidden){var n,r;(n=(r=this._elementStateService).selectElements)==null||n.call(r,{unitId:t.unitId,subUnitId:t.subUnitId},[t.nodeId],t.nodeId),this._childDragSelectionHidden=!1}e==null||e.stopPropagation()}}_attachActivePointerDragListeners(){this._disposeActivePointerDragListeners();let e=typeof window>`u`?null:window;if(!(e!=null&&e.addEventListener))return;let t=new a.DisposableCollection,n=e=>this._syncPointerChildDragPreview(e),r=e=>this._applyPointerChildDrag(e),i=()=>this._cancelPointerChildDrag();e.addEventListener(`pointermove`,n,{capture:!0}),e.addEventListener(`pointerup`,r,{capture:!0}),e.addEventListener(`pointercancel`,i,{capture:!0}),t.add((0,a.toDisposable)(()=>{e.removeEventListener(`pointermove`,n,{capture:!0}),e.removeEventListener(`pointerup`,r,{capture:!0}),e.removeEventListener(`pointercancel`,i,{capture:!0})})),this._activePointerDragDisposables=t}_findChildNodeAtPoint(e,r){let i=Object.values(e);for(let a=i.length-1;a>=0;--a){let o=i[a],s=(0,n.getMindMapNodeMeta)(o.element);if(!(s!=null&&s.parentNodeId))continue;let c=(0,t.resolveBoardElementWorldBounds)(e,o.elementId)??o.element.transform;if(this._isPointInBounds(r,{left:c.left??0,top:c.top??0,width:c.width??0,height:c.height??0}))return o.elementId}}_disposeActivePointerDragListeners(){var e;(e=this._activePointerDragDisposables)==null||e.dispose(),this._activePointerDragDisposables=null}_syncDragPreview(e){let t=this._dragStart;t&&((t.kind===`root`||t.kind===`scope`)&&this._syncRootScopePreview(e),t.kind===`root`?this._syncRootReparentPreview(e):this._syncChildDragPreview(e))}_syncRootScopePreview(e){let t=this._dragStart;if(!t||t.kind!==`root`&&t.kind!==`scope`)return;let n=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(t.unitId,t.nodeId));if(!n||!Number.isFinite(n.left)||!Number.isFinite(n.top))return;let i=le({elementData:t.elementData,rootNodeId:t.nodeId,scopeId:t.scopeId,rootStartBounds:{left:t.left,top:t.top},liveRootBounds:{left:n.left,top:n.top}});if(!i)return;let a=this._renderContext.scene,o=a,s=!1;i.items.forEach(e=>{var n;let c=(0,r.getBoardElementRenderObjectKey)(t.unitId,e.elementId),l=((n=o.getObjectIncludeInGroup)==null?void 0:n.call(o,c))??a.getObject(c);l&&(e.kind===`connector`&&typeof l.updateElement==`function`?(l.updateElement(e.element,i.elementData),s=!0):e.kind===`bounds`&&(l.transformByState(e.bounds),typeof l.makeDirtyNoDebounce==`function`?l.makeDirtyNoDebounce(!0):l.makeDirty(!0),s=!0))}),s&&a.makeDirty(!0)}_syncRootReparentPreview(e){var t,n;let i=this._dragStart;if(!i||i.kind!==`root`)return;let a=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(i.unitId,i.nodeId));if(!a||!Number.isFinite(a.left)||!Number.isFinite(a.top)){this._removeDragPreviewObject();return}let o=this._getLiveObjectBounds(a,i),s=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,o),c=R(i.elementData,i.nodeId,{boundsByElementId:s,allowRootReparent:!0});if(c.kind!==`reparent`){this._removeDragPreviewObject();return}let l=this._ensureDragPreviewObject();l&&(l.updateState({ghostBounds:o,sourceBounds:null,parentBounds:s[c.newParentNodeId],side:c.side,textStyle:void 0,renderGhostNode:!1}),this._renderContext.scene.makeDirty(!0),(t=(n=this._renderContext.scene).requestRender)==null||t.call(n))}_syncChildDragPreview(e){var t,n;let i=this._dragStart;if(!i||i.kind!==`child`)return;let a=e==null?void 0:e.get((0,r.getBoardElementRenderObjectKey)(i.unitId,i.nodeId));if(!a){this._removeDragPreviewObject();return}let o=this._getLiveObjectBounds(a,i);if(!this._isChildDragPastActivationThreshold(i,o)){this._lastChildDragAction=null,this._removeDragPreviewObject(),this._restoreObjectToDragStart(a,i),this._renderContext.scene.makeDirty(!0);return}this._childDragActivated||this._hideSelectionForChildDrag(),this._childDragActivated=!0;let s=this._createTopologyBoundsByElementId(i.elementData,i.nodeId,o),c=R(i.elementData,i.nodeId,{boundsByElementId:s,detachWhenNoSnap:!0});this._lastChildDragAction=c,this._syncChildDragPreviewObject(o,c,s),this._restoreObjectToDragStart(a,i),this._renderContext.scene.makeDirty(!0),(t=(n=this._renderContext.scene).requestRender)==null||t.call(n)}_applyDragTopologyAction(e){var t;let n=this._elementStateService.getSnapshot(),r=n.context,i=n.focusedId??n.selectedIds[0];if(r&&((t=this._dragStart)==null?void 0:t.kind)===`scope`){this._removeDragPreviewObject(),this._applyScopeTranslation(r.unitId,r.subUnitId,e);return}if(!r||!i||n.selectedIds.length!==1){this._removeDragPreviewObject(),this._dragStart=null;return}this._removeDragPreviewObject();let a=this._boardElementService.getElementData(r.unitId,r.subUnitId);if(this._applyRootTranslation(r.unitId,r.subUnitId,i,a,e))return;let o=this._resolveChildDragTopologyAction(r.unitId,r.subUnitId,i,a,e);this._executeChildDragAction(r.unitId,r.subUnitId,i,a,o)}_applyScopeTranslation(e,t,i){let a=this._dragStart;if(this._dragStart=null,!a||a.kind!==`scope`||a.unitId!==e||a.subUnitId!==t)return;let o=i==null?void 0:i.get((0,r.getBoardElementRenderObjectKey)(e,a.nodeId)),s=o&&Number.isFinite(o.left)?o.left??a.left:a.left,c=o&&Number.isFinite(o.top)?o.top??a.top:a.top,l=s-a.left,u=c-a.top;(l!==0||u!==0)&&this._commandService.executeCommand(n.TranslateMindMapOperation.id,{unitId:e,subUnitId:t,scopeId:a.scopeId,deltaX:l,deltaY:u})}_executeChildDragAction(e,t,r,i,a){if(a.kind===`reparent`){var o,s;let c=(0,n.getMindMapNodeMeta)((o=i[r])==null?void 0:o.element),l=(0,n.getMindMapNodeMeta)((s=i[a.newParentNodeId])==null?void 0:s.element);this._executeAndLayout(n.ReparentMindMapNodeOperation.id,{unitId:e,subUnitId:t,nodeId:r,newParentNodeId:a.newParentNodeId,side:a.side,...a.referenceNodeId?{referenceNodeId:a.referenceNodeId}:null,...a.placement?{placement:a.placement}:null},[c==null?void 0:c.structureScopeId,l==null?void 0:l.structureScopeId],r)}else if(a.kind===`detach`){var c;let o=(0,n.getMindMapNodeMeta)((c=i[r])==null?void 0:c.element);this._executeAndLayout(n.DetachMindMapNodeOperation.id,{unitId:e,subUnitId:t,nodeId:r,...Number.isFinite(a.left)?{left:a.left}:null,...Number.isFinite(a.top)?{top:a.top}:null},[o==null?void 0:o.structureScopeId],r)}}_applyRootTranslation(e,i,a,o,s){let c=this._dragStart;if((c==null?void 0:c.kind)===`root`&&(this._dragStart=null),!c||c.unitId!==e||c.subUnitId!==i||c.nodeId!==a)return!1;let l=o[a],u=(0,n.getMindMapNodeMeta)(l==null?void 0:l.element);if(!l||!u||u.parentNodeId!==null)return!1;let d=s==null?void 0:s.get((0,r.getBoardElementRenderObjectKey)(e,a)),f=(0,t.resolveBoardElementWorldBounds)(o,a),p=Number.isFinite(d==null?void 0:d.left)?d.left:(f==null?void 0:f.left)??l.element.transform.left??0,m=Number.isFinite(d==null?void 0:d.top)?d.top:(f==null?void 0:f.top)??l.element.transform.top??0,h=p-c.left,g=m-c.top;if(h===0&&g===0)return!0;let _={left:p,top:m,width:Number.isFinite(d==null?void 0:d.width)?d.width:c.width,height:Number.isFinite(d==null?void 0:d.height)?d.height:c.height},v=R(o,a,{boundsByElementId:this._createTopologyBoundsByElementId(o,a,_),allowRootReparent:!0});if(v.kind===`reparent`)return this._executeChildDragAction(e,i,a,o,v),!0;let y=!!f&&Math.abs(f.left-p)<.001&&Math.abs(f.top-m)<.001;return this._commandService.executeCommand(n.TranslateMindMapOperation.id,{unitId:e,subUnitId:i,scopeId:c.scopeId,deltaX:h,deltaY:g,...y?{excludeElementIds:[a],preserveExcludedWorldTransforms:!0}:null}),!0}_resolveChildDragTopologyAction(e,t,n,i,a){let o=this._dragStart;if(!o||o.kind!==`child`||o.unitId!==e||o.subUnitId!==t||o.nodeId!==n)return{kind:`none`};this._dragStart=null;let s=a==null?void 0:a.get((0,r.getBoardElementRenderObjectKey)(e,n));if(!this._childDragActivated)return s&&this._restoreObjectToDragStart(s,o),this._lastChildDragAction=null,{kind:`none`};if(!s){let e=this._lastChildDragAction??{kind:`none`};return this._lastChildDragAction=null,e}let c=this._getLiveObjectBounds(s,o);if(this._restoreObjectToDragStart(s,o),!this._isChildDragPastActivationThreshold(o,c))return this._lastChildDragAction=null,{kind:`none`};let l=R(i,n,{boundsByElementId:this._createTopologyBoundsByElementId(i,n,c),detachWhenNoSnap:!0});return this._lastChildDragAction=null,l}_isChildDragPastActivationThreshold(e,t){let n=(t.left??e.left)-e.left,r=(t.top??e.top)-e.top;return Math.hypot(n,r)>=18}_getPointerLiveBounds(e,t){let n=this._getPointerScreenPoint(e),r=this._getZoomRatio();return{left:t.left+(n.x-t.pointerStartX)/r,top:t.top+(n.y-t.pointerStartY)/r,width:t.width,height:t.height}}_getBoardPointFromEvent(e){let t=this._uiStateService.getState(),n=(t==null?void 0:t.viewportPanOffset)??{x:0,y:0},r=this._getZoomRatio();return{x:Math.round(((e.offsetX??0)-n.x)/r),y:Math.round(((e.offsetY??0)-n.y)/r)}}_getPointerScreenPoint(e){return{x:Number.isFinite(e.clientX)?e.clientX:e.offsetX??0,y:Number.isFinite(e.clientY)?e.clientY:e.offsetY??0}}_getZoomRatio(){let e=this._uiStateService.getState().zoomRatio;return Number.isFinite(e)&&(e??0)>0?e:1}_isPointInBounds(e,t){return e.x>=t.left&&e.x<=t.left+t.width&&e.y>=t.top&&e.y<=t.top+t.height}_consumePointerEvent(e,t){var n,r;t==null||t.stopPropagation(),t&&(t.skipNextObservers=!0),(n=e.preventDefault)==null||n.call(e),(r=e.stopPropagation)==null||r.call(e)}_hideSelectionForChildDrag(){var e,t;this._childDragSelectionHidden||=((e=(t=this._elementStateService).clearSelection)==null||e.call(t),!0)}_getLiveObjectBounds(e,t){return{left:Number.isFinite(e.left)?e.left:t.left,top:Number.isFinite(e.top)?e.top:t.top,width:Number.isFinite(e.width)?e.width:t.width,height:Number.isFinite(e.height)?e.height:t.height}}_restoreObjectToDragStart(e,t){typeof e.transformByState==`function`&&e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height}),typeof e.makeDirtyNoDebounce==`function`?e.makeDirtyNoDebounce(!0):typeof e.makeDirty==`function`&&e.makeDirty(!0)}_createTopologyBoundsByElementId(e,n,r){return Object.fromEntries(Object.keys(e).map(i=>i===n?[i,r]:[i,(0,t.resolveBoardElementWorldBounds)(e,i)??e[i].element.transform]))}_ensureDragPreviewObject(){if(this._dragPreviewObject)return this._dragPreviewObject;let e=this._renderContext.scene;return typeof e.addObject==`function`?(this._dragPreviewObject=new te(A),e.addObject(this._dragPreviewObject,j),this._dragPreviewObject):null}_syncChildDragPreviewObject(e,t,n){let r=this._ensureDragPreviewObject();r&&r.updateState({ghostBounds:e,sourceBounds:this._resolvePreviewSourceBounds(),parentBounds:t.kind===`reparent`?n[t.newParentNodeId]:null,side:t.kind===`reparent`?t.side:`right`,textStyle:this._resolvePreviewTextStyle(),renderGhostNode:!0})}_resolvePreviewSourceBounds(){let e=this._pointerDragStart??this._dragStart;return e?{left:e.left,top:e.top,width:e.width,height:e.height}:null}_resolvePreviewTextStyle(){var e,t;let n=this._pointerDragStart??this._dragStart,r=n==null||(e=n.elementData[n.nodeId])==null?void 0:e.element,i=r==null||(t=r.shapeData)==null?void 0:t.shapeText;if(i)return{text:typeof i.text==`string`?i.text:void 0,fontSize:Number.isFinite(i.fontSize)?i.fontSize:void 0,color:typeof i.color==`string`?i.color:void 0,horizontalAlign:Number.isFinite(i.horizontalAlign)?i.horizontalAlign:void 0}}_removeDragPreviewObject(){var e,t,n;if(!this._dragPreviewObject)return;let r=this._renderContext.scene;(e=r.removeObjects)==null||e.call(r,[this._dragPreviewObject]),this._dragPreviewObject=null,(t=(n=this._renderContext.scene).makeDirty)==null||t.call(n,!0)}_executeAndLayout(e,t,r,i){let a=[...new Set(r.filter(e=>!!e))],o=typeof t.unitId==`string`?t.unitId:this._renderContext.unitId,s=this._undoRedoGroupService.createRunner(o),c=s(()=>this._commandService.executeCommand(e,t));Promise.resolve(c).then(e=>{var r,o,c,l;if(e){if(a.forEach(e=>{s(()=>this._commandService.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:e}))}),i&&typeof t.unitId==`string`&&typeof t.subUnitId==`string`){var u,d;(u=(d=this._elementStateService).selectElements)==null||u.call(d,{unitId:t.unitId,subUnitId:t.subUnitId},[i],i)}(r=(o=this._renderContext.scene).makeDirty)==null||r.call(o,!0),(c=(l=this._renderContext.scene).requestRender)==null||c.call(l)}})}};z=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,a.ICommandService),S(4,r.IBoardUIStateService),S(5,a.IUniverInstanceService),S(6,(0,a.Inject)(c.UndoRedoGroupService))],z);function B({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,f.useId)()}`,u=(0,f.useRef)(null);return(0,f.useImperativeHandle)(e,()=>u.current),(0,f.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return pe(u.current)},[n,r]),ue(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function ue(e,t,n,r,i){return(0,f.createElement)(e.tag,{key:t,...de(e,n,i),...r},(fe(e,n).children||[]).map((r,a)=>ue(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function de(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function fe(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function pe(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:me(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=e.element.style.getPropertyValue(`stroke-width`)})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(he(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function me(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function he(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}B.displayName=`UniverIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 13.6h12M8 2.2v8.3m-2.4-2.4L8 10.5l2.4-2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},_e=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`align-bottom-icon`,ref:t,icon:ge}))});_e.displayName=`AlignBottomIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 3.2h12M2 6.4h12M2 9.6h12M2 12.8h12`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},ye=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`align-text-both-icon`,ref:t,icon:ve}))});ye.displayName=`AlignTextBothIcon`;let be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 2.4h12M8 13.8V5.5m-2.4 2.4L8 5.5l2.4 2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},xe=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`align-top-icon`,ref:t,icon:be}))});xe.displayName=`AlignTopIcon`;let Se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M4.6 2.3h3.7c2 0 3.2.9 3.2 2.7S10.2 7.7 8.3 7.7H4.6m0-5.4v11.4h4c2.4 0 3.8-1.1 3.8-3s-1.4-3-3.8-3`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.9}}]},Ce=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`bold-icon`,ref:t,icon:Se}))});Ce.displayName=`BoldIcon`;let we={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 3.2h12M4 6.4h8M2 9.6h12M4 12.8h8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Te=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`horizontally-icon`,ref:t,icon:we}))});Te.displayName=`HorizontallyIcon`;let Ee={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M7.4 2.3h5.1M3.5 13.7h5.1m1.3-11.4-3.8 11.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},De=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`italic-icon`,ref:t,icon:Ee}))});De.displayName=`ItalicIcon`;let Oe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 3.2h12M2 6.4h8M2 9.6h12M2 12.8h8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},ke=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`left-justifying-icon`,ref:t,icon:Oe}))});ke.displayName=`LeftJustifyingIcon`;let Ae={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M1.8 8h1.6c4.7 0 4.5-4.4 9-4.4h1.8M3.4 8c4.7 0 4.5 4.4 9 4.4h1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},je=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-branch-curve-icon`,ref:t,icon:Ae}))});je.displayName=`MindBranchCurveIcon`;let Me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M1.8 8h5M14.2 3.6H6.8v8.8h7.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Ne=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-branch-orthogonal-icon`,ref:t,icon:Me}))});Ne.displayName=`MindBranchOrthogonalIcon`;let Pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M1.8 8h3.4c1.1 0 1.6-.6 1.6-1.6v-.8c0-1.1.9-2 2-2h5.4M5.2 8c1.1 0 1.6.6 1.6 1.6v.8c0 1.1.9 2 2 2h5.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Fe=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-branch-rounded-orthogonal-icon`,ref:t,icon:Pe}))});Fe.displayName=`MindBranchRoundedOrthogonalIcon`;let Ie={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 3.7h1.2c.8 0 1.4.6 1.4 1.4v5.8c0 .8-.6 1.4-1.4 1.4H2M14 3.7h-1.2c-.8 0-1.4.6-1.4 1.4v5.8c0 .8.6 1.4 1.4 1.4H14M4.6 8h6.8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`rect`,attrs:{width:3.2,height:2.8,x:6.4,y:6.6,fill:`currentColor`,rx:.6}}]},Le=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-layout-horizontal-icon`,ref:t,icon:Ie}))});Le.displayName=`MindLayoutHorizontalIcon`;let Re={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.7 2v1.2c0 .8.6 1.4 1.4 1.4h5.8c.8 0 1.4-.6 1.4-1.4V2M3.7 14v-1.2c0-.8.6-1.4 1.4-1.4h5.8c.8 0 1.4.6 1.4 1.4V14M8 4.6v6.8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`rect`,attrs:{width:3.2,height:2.8,x:6.4,y:6.6,fill:`currentColor`,rx:.6}}]},ze=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-layout-vertical-icon`,ref:t,icon:Re}))});ze.displayName=`MindLayoutVerticalIcon`;let Be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.1 8h11.8M5.8 8V4.3c0-.7.5-1.2 1.2-1.2h2.7M9.7 8v3.7c0 .7.5 1.2 1.2 1.2h2.7`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`circle`,attrs:{cx:2.1,cy:8,r:1.05,fill:`currentColor`}}]},Ve=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-timeline-horizontal-icon`,ref:t,icon:Be}))});Ve.displayName=`MindTimelineHorizontalIcon`;let He={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 2.1v11.8M8 5.8h3.7c.7 0 1.2.5 1.2 1.2v2.7M8 9.7H4.3c-.7 0-1.2.5-1.2 1.2v2.7`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`circle`,attrs:{cx:8,cy:2.1,r:1.05,fill:`currentColor`}}]},Ue=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-timeline-vertical-icon`,ref:t,icon:He}))});Ue.displayName=`MindTimelineVerticalIcon`;let We={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M8 2.7v8.6a1.5 1.5 0 0 1-1.5 1.5H2.2M8 5H2.2M8 8.9h5.8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`circle`,attrs:{cx:8,cy:2.7,r:1.15,fill:`currentColor`}}]},Ge=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-tree-alternate-icon`,ref:t,icon:We}))});Ge.displayName=`MindTreeAlternateIcon`;let Ke={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M12.3 2.7v8.6a1.5 1.5 0 0 1-1.5 1.5H3.7M12.3 5H3.7M12.3 8.9H5.7`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`circle`,attrs:{cx:12.3,cy:2.7,r:1.15,fill:`currentColor`}}]},qe=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-tree-left-icon`,ref:t,icon:Ke}))});qe.displayName=`MindTreeLeftIcon`;let Je={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.7 2.7v8.6a1.5 1.5 0 0 0 1.5 1.5h7.1M3.7 5h8.6M3.7 8.9h6.6`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}},{tag:`circle`,attrs:{cx:3.7,cy:2.7,r:1.15,fill:`currentColor`}}]},Ye=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`mind-tree-right-icon`,ref:t,icon:Je}))});Ye.displayName=`MindTreeRightIcon`;let Xe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z`}}]},Ze=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`more-horizontal-icon`,ref:t,icon:Xe}))});Ze.displayName=`MoreHorizontalIcon`;let Qe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 3.2h12M6 6.4h8M2 9.6h12M6 12.8h8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},$e=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`right-justifying-icon`,ref:t,icon:Qe}))});$e.displayName=`RightJustifyingIcon`;let et={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`circle`,attrs:{cx:7,cy:7,r:5.2}},{tag:`path`,attrs:{d:`M10.8 10.8L14.2 14.2`}}]}]},tt=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`search-icon`,ref:t,icon:et}))});tt.displayName=`SearchIcon`;let nt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M3.5 3.5L16.5 16.5`,strokeLinecap:`round`,strokeWidth:1.6}}]},rt=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`shape-line-icon`,ref:t,icon:nt}))});rt.displayName=`ShapeLineIcon`;let it={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M11.4 4.2c-.7-1.5-2.1-2.1-3.7-2.1-2 0-3.3 1.2-3.3 2.7 0 1.3.9 2.1 2.7 2.7M8.8 8.4c2.1.7 3 1.4 3 2.8 0 1.6-1.4 2.8-3.6 2.8-1.9 0-3.4-.9-4-2.4M1.8 8h12.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},at=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`strikethrough-icon`,ref:t,icon:it}))});at.displayName=`StrikethroughIcon`;let ot={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M4 2.1v5.1a4 4 0 0 0 8 0V2.1M2.8 14h10.4`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},st=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`underline-icon`,ref:t,icon:ot}))});st.displayName=`UnderlineIcon`;let ct={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2 8h12M8 1.6v3.8L6.2 3.6M8 5.4l1.8-1.8M8 14.4v-3.8l-1.8 1.8M8 10.6l1.8 1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},lt=(0,f.forwardRef)(function(e,t){return(0,f.createElement)(B,Object.assign({},e,{id:`vertical-center-icon`,ref:t,icon:ct}))});lt.displayName=`VerticalCenterIcon`;let V=class extends a.Disposable{constructor(e,t,n,r,i,a,o,s,c){super(),this.renderContext=e,this.commandService=t,this.elementService=n,this.elementStateService=r,this.uiStateService=i,this.clipboardService=a,this.dialogService=o,this.localeService=s,this.textEditingService=c}};V=C([S(1,a.ICommandService),S(2,t.IBoardElementService),S(3,r.IBoardElementStateService),S(4,r.IBoardUIStateService),S(5,n.IMindMapClipboardService),S(6,c.IDialogService),S(7,(0,a.Inject)(a.LocaleService)),S(8,(0,a.Inject)(r.BoardTextEditingService))],V);let ut=`board.mind-map.description-dialog`,dt=`board-mind-map-description-dialog`;function ft(e){let{unitId:t,subUnitId:r,nodeId:i,initialDescription:o=``}=e,s=(0,c.useDependency)(a.ICommandService),l=(0,c.useDependency)(c.IDialogService),u=(0,c.useDependency)(a.LocaleService),[m,h]=(0,f.useState)(o),g=()=>l.close(dt);return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-w-full univer-flex-col univer-gap-4`,"data-board-mind-map-description-dialog":`true`,children:[/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:u.t(`boards-mind-ui.description`)}),/* @__PURE__ */ (0,p.jsx)(d.Textarea,{autoFocus:!0,className:`univer-h-32 univer-resize-none univer-text-sm`,placeholder:u.t(`boards-mind-ui.descriptionPlaceholder`),value:m,onValueChange:h})]}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`default`,onClick:g,children:u.t(`boards-mind-ui.cancel`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`primary`,onClick:()=>{s.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:t,subUnitId:r,nodeId:i,foreignAttributes:{_note:m.trim()?m:null}}),g()},children:u.t(`boards-mind-ui.saveDescription`)})]})]})}let H=`board.operation.mind-map.keyboard-shortcut`,pt=`FOCUSING_MIND_MAP_NODE`,mt=`FOCUSING_MIND_MAP_BLANK_BOARD`,ht={copy:r.BOARD_SHORTCUT_BINDINGS.copy,paste:r.BOARD_SHORTCUT_BINDINGS.paste,"paste-as-new":r.BOARD_SHORTCUT_BINDINGS.paste,"add-child":r.BOARD_SHORTCUT_BINDINGS.addChildNode,"add-sibling-or-child":r.BOARD_SHORTCUT_BINDINGS.addSiblingNode,promote:r.BOARD_SHORTCUT_BINDINGS.addParentNode,"toggle-collapse":r.BOARD_SHORTCUT_BINDINGS.foldChildNodes,"collapse-all":r.BOARD_SHORTCUT_BINDINGS.collapseAllNodes,"edit-text":r.BOARD_SHORTCUT_BINDINGS.editCurrentNode,"open-description":r.BOARD_SHORTCUT_BINDINGS.addDescription,delete:c.KeyCode.DELETE,"arrow-left":c.KeyCode.ARROW_LEFT,"arrow-right":c.KeyCode.ARROW_RIGHT,"arrow-up":c.KeyCode.ARROW_UP,"arrow-down":c.KeyCode.ARROW_DOWN},gt={delete:[c.KeyCode.BACKSPACE]};function _t(e){return[ht[e],...gt[e]??[]]}let U=class extends a.RxDisposable{constructor(e,t,n,r){super(),this._mindMapClipboardService=e,this._commandService=t,this._shortcutService=n,this._undoRedoGroupService=r,this._init()}_init(){this.disposeWithMe(this._commandService.registerCommand(this._createKeyboardShortcutOperation())),this._createShortcutItems().forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_createKeyboardShortcutOperation(){return{id:H,type:a.CommandType.OPERATION,handler:(e,t,n)=>{let r=vt(e,n);return r?this.handleShortcut(r,t==null?void 0:t.action):!1}}}_createShortcutItems(){let e=(e,t)=>({id:H,binding:e,priority:160,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!e.getContextValue(`FOCUSING_MIND_MAP_NODE`),staticParameters:{action:t}}),t=t=>_t(t).map(n=>e(n,t));return[...t(`copy`),{id:H,binding:ht.paste,priority:160,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!this._mindMapClipboardService.getPayload()&&!!e.getContextValue(`FOCUSING_MIND_MAP_NODE`),staticParameters:{action:`paste`}},{id:H,binding:ht[`paste-as-new`],priority:150,preconditions:e=>(0,r.isBoardShortcutAvailable)(e)&&!!this._mindMapClipboardService.getPayload()&&!!e.getContextValue(`FOCUSING_MIND_MAP_BLANK_BOARD`),staticParameters:{action:`paste-as-new`}},...t(`add-child`),...t(`add-sibling-or-child`),...t(`promote`),...t(`toggle-collapse`),...t(`collapse-all`),...t(`edit-text`),...t(`open-description`),...t(`delete`),...t(`arrow-left`),...t(`arrow-right`),...t(`arrow-up`),...t(`arrow-down`)]}handleShortcut(e,t){return e.uiStateService.getState().interactionMode===`viewing`&&t!==`copy`?!1:t===`copy`?this._copySelectedNode(e):t===`paste`?this._pasteUnderSelectedNode(e):t===`paste-as-new`?this._pasteAsNewMindMap(e):t===`add-child`?this._addChild(e):t===`add-sibling-or-child`?this._addSiblingOrChild(e):t===`promote`?this._executeNodeOperation(e,n.PromoteMindMapNodeOperation.id):t===`toggle-collapse`?this._executeNodeOperation(e,n.ToggleMindMapNodeCollapseOperation.id):t===`collapse-all`?this._collapseAll(e):t===`edit-text`?this._openSelectedTextEditing(e):t===`open-description`?this._openDescriptionDialog(e):t===`delete`?this._deleteSelectedNode(e):t&&yt(t)?this._navigateByTopology(e,t):!1}_copySelectedNode(e){let t=this._getSelectedMindMapContext(e);return t?(e.commandService.executeCommand(n.CopyMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId}),!0):!1}_pasteUnderSelectedNode(e){let t=this._getSelectedMindMapContext(e);return!t||!e.clipboardService.getPayload()?!1:(this._executeAndLayout(e,n.PasteMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,targetNodeId:t.nodeId},t.scopeId),!0)}_pasteAsNewMindMap(e){let t=this._getBlankBoardContext(e);if(!t||!e.clipboardService.getPayload())return!1;let r=e.uiStateService.getState(),i=Number.isFinite(r.zoomRatio)&&r.zoomRatio>0?r.zoomRatio:1,a=Math.round((64-r.viewportPanOffset.x)/i),o=Math.round((64-r.viewportPanOffset.y)/i);return e.commandService.executeCommand(n.PasteMindMapAsNewMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,left:a,top:o}),!0}_addChild(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(e,n.AddMindMapChildOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,parentNodeId:t.nodeId,nodeId:r,connectorId:(0,a.generateRandomId)(6),text:e.localeService.t(`boards-mind-ui.panel.addText`)},t.scopeId,r),!0}_addSiblingOrChild(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(e,t.isRoot?n.AddMindMapChildOperation.id:n.AddMindMapSiblingOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,...t.isRoot?{parentNodeId:t.nodeId,nodeId:r}:{nodeId:t.nodeId,siblingNodeId:r},connectorId:(0,a.generateRandomId)(6),text:e.localeService.t(`boards-mind-ui.panel.addText`)},t.scopeId,r),!0}_executeNodeOperation(e,t){let n=this._getSelectedMindMapContext(e);return n?(this._executeAndLayout(e,t,{unitId:n.unitId,subUnitId:n.subUnitId,nodeId:n.nodeId},n.scopeId),!0):!1}_deleteSelectedNode(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=e.commandService.syncExecuteCommand(n.DeleteMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId});return r&&e.elementStateService.clearSelection(),r}_collapseAll(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;let r=e.elementService.getElementData(t.unitId,t.subUnitId),i=Object.values(r).map(e=>{let i=(0,n.getMindMapNodeMeta)(e.element);return(i==null?void 0:i.structureScopeId)===t.scopeId&&this._getMindMapChildren(r,t.scopeId,e.elementId).length>0?{nodeId:e.elementId,collapsed:i.collapsed}:null}).filter(e=>!!e);if(i.length===0)return!1;let a=i.some(e=>!e.collapsed),o=e.commandService,s=this._undoRedoGroupService.createRunner(t.unitId),c=i.map(e=>s(()=>o.executeCommand(n.ToggleMindMapNodeCollapseOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:e.nodeId,collapsed:a})));return Promise.all(c.map(e=>Promise.resolve(e))).then(e=>{e.some(Boolean)&&s(()=>o.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId}))}),!0}_openSelectedTextEditing(e){let t=this._getSelectedMindMapContext(e);if(!t)return!1;e.elementStateService.selectElements({unitId:t.unitId,subUnitId:t.subUnitId},[t.nodeId],t.nodeId);let n=e.textEditingService;return n.ignoreExternalFocusChanges(),n.setEditing({unitId:t.unitId,subUnitId:t.subUnitId,shapeId:t.nodeId,shapeKey:(0,r.getBoardElementRenderObjectKey)(t.unitId,t.nodeId),visible:!0}),!0}_openDescriptionDialog(e){let t=this._getSelectedMindMapContext(e);return t?(e.dialogService.open({id:dt,title:{title:`boards-mind-ui.description`},width:420,draggable:!0,mask:!1,maskClosable:!0,children:{label:ut,unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,initialDescription:t.description}}),!0):!1}_navigateByTopology(e,t){let r=this._getSelectedMindMapContext(e);if(!r)return!1;let i=e.elementService.getElementData(r.unitId,r.subUnitId),a=i[r.nodeId],o=(0,n.getMindMapNodeMeta)(a==null?void 0:a.element);if(!a||!o)return!1;let s={"arrow-left":`ArrowLeft`,"arrow-right":`ArrowRight`,"arrow-up":`ArrowUp`,"arrow-down":`ArrowDown`}[t];if(!s)return!1;let c=this._resolveArrowNavigationTarget(i,r.nodeId,o,s);return c?(e.elementStateService.selectElements({unitId:r.unitId,subUnitId:r.subUnitId},[c],c),!0):!1}_resolveArrowNavigationTarget(e,t,r,i){let a=this._getMindMapChildren(e,r.structureScopeId,t);if(r.parentNodeId===null){if(i===`ArrowLeft`){var o;return((o=a.find(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.side)===`left`}))==null?void 0:o.elementId)??null}if(i===`ArrowRight`){var s;return((s=a.find(e=>{var t;return(((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.side)??`right`)===`right`}))==null?void 0:s.elementId)??null}return null}let c=r.side??`right`,l=c===`right`?`ArrowLeft`:`ArrowRight`,u=c===`right`?`ArrowRight`:`ArrowLeft`;if(i===l)return r.parentNodeId;if(i===u){var d;return((d=a[0])==null?void 0:d.elementId)??null}if(i===`ArrowUp`||i===`ArrowDown`){let n=this._getMindMapChildren(e,r.structureScopeId,r.parentNodeId),a=n.findIndex(e=>e.elementId===t),o=i===`ArrowUp`?n[a-1]:n[a+1];return(o==null?void 0:o.elementId)??null}return null}_getMindMapChildren(e,t,r){return Object.values(e).filter(e=>{let i=(0,n.getMindMapNodeMeta)(e.element);return(i==null?void 0:i.structureScopeId)===t&&i.parentNodeId===r&&e.element.visible!==!1}).sort((e,t)=>{let r=(0,n.getMindMapNodeMeta)(e.element),i=(0,n.getMindMapNodeMeta)(t.element);return(0,n.compareMindMapOrderKey)(r==null?void 0:r.orderKey,i==null?void 0:i.orderKey)||e.elementId.localeCompare(t.elementId)})}_getSelectedMindMapContext(e){var t;let r=e.elementStateService.getSnapshot(),i=r.focusedId??r.selectedIds[0];if(!i||r.selectedIds.length!==1||r.activeEditingId||r.isTransforming)return null;let a=r.context??{unitId:e.renderContext.unitId,subUnitId:e.renderContext.unit.getActivePageId()},o=e.elementService.getElementData(a.unitId,a.subUnitId)[i],s=(0,n.getMindMapNodeMeta)(o==null?void 0:o.element);return!o||!s?null:{unitId:a.unitId,subUnitId:a.subUnitId,nodeId:i,scopeId:s.structureScopeId,isRoot:s.parentNodeId===null,description:((t=s.foreignAttributes)==null?void 0:t._note)??``}}_getBlankBoardContext(e){var t,n;let r=e.elementStateService.getSnapshot();return r.activeEditingId||r.isTransforming||r.selectedIds.length>0||r.focusedId?null:{unitId:((t=r.context)==null?void 0:t.unitId)??e.renderContext.unitId,subUnitId:((n=r.context)==null?void 0:n.subUnitId)??e.renderContext.unit.getActivePageId()}}_executeAndLayout(e,t,r,i){let a=e.commandService,o=this._undoRedoGroupService.createRunner(r.unitId),s=o(()=>a.executeCommand(t,r));Promise.resolve(s).then(e=>{e&&o(()=>a.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:i}))})}_executeCreateAndEdit(e,t,i,a,o){let s={unitId:i.unitId,subUnitId:i.subUnitId},c=e.commandService,l=this._undoRedoGroupService.createRunner(i.unitId),u=l(()=>c.executeCommand(t,i));Promise.resolve(u).then(t=>{if(!t)return;l(()=>c.executeCommand(n.LayoutMindMapOperation.id,{...s,scopeId:a})),e.elementStateService.selectElements(s,[o],o);let i=e.textEditingService;i.ignoreExternalFocusChanges(),i.setEditing({...s,shapeId:o,shapeKey:(0,r.getBoardElementRenderObjectKey)(s.unitId,o),visible:!0})})}};U=C([S(0,n.IMindMapClipboardService),S(1,a.ICommandService),S(2,c.IShortcutService),S(3,(0,a.Inject)(c.UndoRedoGroupService))],U);function vt(e,t){var n,r;let i=typeof(t==null?void 0:t.unitId)==`string`?t.unitId:(n=e.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_BOARD))==null?void 0:n.getUnitId();return i?((r=e.get(o.IRenderManagerService).getRenderUnitById(i))==null?void 0:r.with(V))??null:null}function yt(e){return e===`arrow-left`||e===`arrow-right`||e===`arrow-up`||e===`arrow-down`}let bt={min:1,max:5,defaultValue:3},xt={min:0,max:100,defaultValue:100},St=[{kind:`dropdown`,titleKey:`boards-mind-ui.toolbar.primary.line`,panel:`line`},{kind:`fontColor`,titleKey:`boards-mind-ui.toolbar.primary.fontColor`},{kind:`typography`,titleKey:`boards-mind-ui.toolbar.primary.typography`},{kind:`dropdown`,titleKey:`boards-mind-ui.toolbar.primary.more`,panel:`more`,dividerBefore:!0}],W={addSibling:`add-sibling-or-child`,addChild:`add-child`,copy:`copy`,paste:`paste`,delete:`delete`},Ct=[{key:`mind-map`,title:`Mind map`,items:[{value:`mindmap-horizontal`,icon:`mindmap-horizontal`,labelKey:`boards-mind-ui.panel.structureKind.mindmapHorizontal`},{value:`mindmap-vertical`,icon:`mindmap-vertical`,labelKey:`boards-mind-ui.panel.structureKind.mindmapVertical`}]},{key:`tree-diagram`,title:`Tree diagram`,items:[{value:`tree-right`,icon:`tree-right`,labelKey:`boards-mind-ui.panel.structureKind.treeRight`},{value:`tree-left`,icon:`tree-left`,labelKey:`boards-mind-ui.panel.structureKind.treeLeft`},{value:`tree-alternate`,icon:`tree-alternate`,labelKey:`boards-mind-ui.panel.structureKind.treeAlternate`}]},{key:`timeline`,title:`Timeline`,items:[{value:`timeline-horizontal`,icon:`timeline-horizontal`,labelKey:`boards-mind-ui.panel.structureKind.timelineHorizontal`},{value:`timeline-vertical`,icon:`timeline-vertical`,labelKey:`boards-mind-ui.panel.structureKind.timelineVertical`}]}],wt={key:`branch`,title:`Branch`,items:[{value:`curve`,icon:`branch-curve`,labelKey:`boards-mind-ui.panel.branchLineType.curve`},{value:`rounded-orthogonal`,icon:`branch-rounded-orthogonal`,labelKey:`boards-mind-ui.panel.branchLineType.roundedOrthogonal`},{value:`orthogonal`,icon:`branch-orthogonal`,labelKey:`boards-mind-ui.panel.branchLineType.orthogonal`}]},Tt=`board.mind-map.floating-toolbar`;function Et(e,t){e.executeCommand(H,{action:t})}let Dt={line:rt,more:Ze};function G(e){e.stopPropagation(),e.preventDefault()}function Ot(e,t=`univer-size-5`,n){return/* @__PURE__ */ (0,p.jsx)(c.EditorToolbarIcon,{children:/* @__PURE__ */ (0,p.jsx)(e,{className:t,extend:n})})}function kt(e){var t,n;let r=(e==null?void 0:e.shapeText)??{},i=r.dataModel&&typeof r.dataModel==`object`?r.dataModel:{},o=(t=i.doc)==null||(t=t.documentStyle)==null?void 0:t.textStyle;return{color:typeof r.color==`string`?r.color:(o==null||(n=o.cl)==null?void 0:n.rgb)??l.SHAPE_FLOATING_TOOLBAR_DEFAULT_TEXT_COLOR,fontFamily:typeof r.fontFamily==`string`?r.fontFamily:(o==null?void 0:o.ff)??a.DEFAULT_STYLES.ff,fontSize:typeof r.fontSize==`number`?r.fontSize:typeof(o==null?void 0:o.fs)==`number`?o.fs:a.DEFAULT_STYLES.fs,horizontalAlign:r.horizontalAlign??i.ha??a.HorizontalAlign.LEFT,textFill:r.textFill&&typeof r.textFill==`object`?r.textFill:o==null?void 0:o.textFill,verticalAlign:r.verticalAlign??i.va??a.VerticalAlign.MIDDLE}}function At(e,t){if(!t)return;let n=_t(t);if(!n.length)return;let r=n.map(n=>e.getShortcutDisplay({id:`board.operation.mind-map.keyboard-shortcut`,binding:n,staticParameters:{action:t}})??void 0).filter(e=>!!e);return r.length?[...new Set(r)].join(`/`):void 0}async function jt(e,t,r){return await Promise.resolve(t(()=>e.executeCommand(n.ChangeMindMapLayoutOperation.id,r)))?(await Promise.resolve(t(()=>e.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:r.scopeId}))),!0):!1}async function Mt(e,t,r){return await Promise.resolve(t(()=>e.executeCommand(n.ChangeMindMapBranchLineTypeOperation.id,r)))?(await Promise.resolve(t(()=>e.executeCommand(n.LayoutMindMapOperation.id,{unitId:r.unitId,subUnitId:r.subUnitId,scopeId:r.scopeId}))),!0):!1}let Nt={"mindmap-horizontal":Le,"mindmap-vertical":ze,"tree-right":Ye,"tree-left":qe,"tree-alternate":Ge,"timeline-horizontal":Ve,"timeline-vertical":Ue,"branch-curve":je,"branch-rounded-orthogonal":Fe,"branch-orthogonal":Ne};function Pt(e,n){let r=e.textStyle,i=(0,t.documentTextStyleToBoardShapeTextStyle)(r),a={...i.color===void 0?null:{color:i.color},...i.fontFamily===void 0?null:{fontFamily:i.fontFamily},...i.fontSize===void 0?null:{fontSize:i.fontSize},...i.bold===void 0?null:{bold:i.bold},...i.italic===void 0?null:{italic:i.italic},...i.underline===void 0?null:{underline:i.underline},...i.strikethrough===void 0?null:{strikethrough:i.strikethrough},...i.textFill===void 0?null:{textFill:i.textFill}};e.horizontalAlign!==void 0&&(a.horizontalAlign=e.horizontalAlign),e.verticalAlign!==void 0&&(a.verticalAlign=e.verticalAlign),Object.keys(a).length>0&&n({textStyle:a})}function Ft(e,t,n){let r=e??{},i=(0,l.buildShapeTextDataUpdate)(r,t),a=i.shapeText??r.shapeText??{};return{...r,...i,shapeText:{...a,...n.color===void 0?null:{color:n.color},...n.fontSize===void 0?null:{fontSize:n.fontSize},...n.bold===void 0?null:{bold:n.bold},...n.italic===void 0?null:{italic:n.italic},...n.underline===void 0?null:{underline:n.underline},...n.strikethrough===void 0?null:{strikethrough:n.strikethrough},...n.horizontalAlign===void 0?null:{horizontalAlign:n.horizontalAlign},...n.verticalAlign===void 0?null:{verticalAlign:n.verticalAlign},...n.textFill===void 0?null:{textFill:n.textFill}}}}function It(e,t){let n=e==null?void 0:e.stroke;n&&t({lineType:n.dashType===u.ShapeLineDashEnum.RoundDot||n.dashType===u.ShapeLineDashEnum.SquareDot?`dot`:n.dashType===u.ShapeLineDashEnum.Dash?`dash`:`solid`,...typeof n.width==`number`?{strokeWidth:n.width}:null,...typeof n.color==`string`?{stroke:n.color}:null,...typeof n.opacity==`number`?{opacity:n.opacity}:null})}function Lt(e){return e!=null&&e.length?e[0]<=2?u.ShapeLineDashEnum.RoundDot:u.ShapeLineDashEnum.Dash:u.ShapeLineDashEnum.Solid}function Rt(e){return{stroke:{lineStrokeType:u.ShapeLineTypeEnum.SolidLine,dashType:Lt(e==null?void 0:e.dash),color:(e==null?void 0:e.stroke)??l.SHAPE_FLOATING_TOOLBAR_DEFAULT_STROKE_COLOR,width:(e==null?void 0:e.strokeWidth)??bt.defaultValue,opacity:(e==null?void 0:e.opacity)??xt.defaultValue/100}}}function zt(e){var r;let i=(0,c.useDependency)(a.ICommandService),o=(0,c.useDependency)(c.IShortcutService),u=(0,c.useDependency)(a.LocaleService),m=(0,c.useDependency)(c.UndoRedoGroupService),[h,g]=(0,f.useState)(null),[_,v]=(0,f.useState)((r=e.popup.extraProps)==null?void 0:r.shapeData),y=e.popup.extraProps,b=(0,c.useDependency)(t.IBoardElementService),{unitId:x,subUnitId:S,scopeId:C}=y??{},w=(0,c.useObservable)(()=>!x||!S||!C?(0,s.of)(void 0):b.elementUpdate$.pipe((0,s.filter)(e=>e.some(e=>e.unitId===x&&e.subUnitId===S&&e.elementId===C)),(0,s.startWith)(null),(0,s.map)(()=>{var e,t;return(e=(0,n.getMindMapContainerMeta)((t=b.getElementById(x,S,C))==null?void 0:t.element))==null?void 0:e.layout})),void 0,!0,[b,x,S,C]);if(!y)return null;let T={unitId:y.unitId,subUnitId:y.subUnitId},E=e=>{i.executeCommand(n.UpdateMindMapNodeOperation.id,{...T,nodeId:y.elementId,...e})},D=(e,t)=>{let n=t??{};v(e=>({...e??{},...n})),E({...n.fill===void 0?null:{fill:n.fill},...n.stroke===void 0?null:{stroke:n.stroke}})},O=e=>{i.executeCommand(n.UpdateMindMapIncomingConnectorOperation.id,{...T,nodeId:y.elementId,style:e})},k=Rt(y.incomingConnectorStyle),A=e=>At(o,e),j=e=>{Et(i,e)},M=(_==null?void 0:_.shapeText)??{},N=kt(_),P=e=>{Pt(e,t=>{v(n=>Ft(n,e,t.textStyle)),E(t)})},F=[{label:u.t(`boards-mind-ui.alignLeft`),value:a.HorizontalAlign.LEFT,icon:/* @__PURE__ */ (0,p.jsx)(ke,{})},{label:u.t(`boards-mind-ui.alignCenter`),value:a.HorizontalAlign.CENTER,icon:/* @__PURE__ */ (0,p.jsx)(Te,{})},{label:u.t(`boards-mind-ui.alignRight`),value:a.HorizontalAlign.RIGHT,icon:/* @__PURE__ */ (0,p.jsx)($e,{})},{label:u.t(`boards-mind-ui.alignJustify`),value:a.HorizontalAlign.JUSTIFIED,icon:/* @__PURE__ */ (0,p.jsx)(ye,{})}],ee=[{label:u.t(`boards-mind-ui.alignTop`),value:a.VerticalAlign.TOP,icon:/* @__PURE__ */ (0,p.jsx)(xe,{})},{label:u.t(`boards-mind-ui.alignMiddle`),value:a.VerticalAlign.MIDDLE,icon:/* @__PURE__ */ (0,p.jsx)(lt,{})},{label:u.t(`boards-mind-ui.alignBottom`),value:a.VerticalAlign.BOTTOM,icon:/* @__PURE__ */ (0,p.jsx)(_e,{})}],te=()=>{j(`add-sibling-or-child`)},I=()=>{j(`add-child`)},ne=()=>{j(`copy`)},re=()=>{j(`paste`)},ie=()=>{j(`delete`)},L=(w==null?void 0:w.structureKind)??n.MIND_MAP_DEFAULT_LAYOUT.structureKind,ae=(0,n.resolveMindMapBranchLineTypeForStructure)(L,w==null?void 0:w.branchLineType),oe=e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(e,ae);jt(i,m.createRunner(y.unitId),{...T,scopeId:y.scopeId,structureKind:e,...t===ae?null:{branchLineType:t}}),g(null)},R=e=>{Mt(i,m.createRunner(y.unitId),{...T,scopeId:y.scopeId,branchLineType:e}),g(null)},se=(e,t,n,r=!1)=>{let i=Nt[e.icon];return/* @__PURE__ */ (0,p.jsx)(`button`,{type:`button`,"aria-label":u.t(e.labelKey),disabled:r,className:(0,d.clsx)(`univer-flex univer-h-12 univer-min-w-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent univer-p-0 univer-text-gray-900 univer-outline-none univer-transition-colors hover:univer-bg-gray-0 dark:hover:!univer-bg-gray-700`,!t&&!r&&`dark:!univer-text-gray-200`,t&&`univer-bg-primary-50 univer-text-primary-600 hover:univer-bg-primary-50 dark:!univer-bg-primary-900 dark:!univer-text-primary-200 dark:hover:!univer-bg-primary-900`,r&&`univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-500 dark:hover:!univer-bg-transparent`),onMouseDown:G,onPointerDown:G,onClick:e=>{e.stopPropagation(),r||n()},children:/* @__PURE__ */ (0,p.jsx)(i,{className:`univer-size-7`,"aria-hidden":`true`})},e.value)},ce=()=>/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-w-[202px] univer-rounded-xl univer-border univer-border-gray-200 univer-bg-gray-0 univer-px-4 univer-py-4 univer-shadow-lg dark:!univer-border-gray-700 dark:!univer-bg-gray-900`,onMouseDown:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[Ct.map(e=>/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-mb-2 univer-text-lg univer-text-gray-900 dark:!univer-text-gray-200`,children:e.title}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-h-14 univer-overflow-hidden univer-rounded-xl univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800`,style:{gridTemplateColumns:`repeat(${e.items.length}, minmax(0, 1fr))`},children:e.items.map(e=>se(e,e.value===L,()=>oe(e.value)))})]},e.key)),/* @__PURE__ */ (0,p.jsx)(d.Separator,{}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-mb-0`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-mb-2 univer-text-lg univer-text-gray-900 dark:!univer-text-gray-200`,children:wt.title}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-h-14 univer-overflow-hidden univer-rounded-xl univer-bg-gray-100 univer-p-1 dark:!univer-bg-gray-800`,style:{gridTemplateColumns:`repeat(${wt.items.length}, minmax(0, 1fr))`},children:wt.items.map(e=>se(e,e.value===ae,()=>R(e.value),e.value===`curve`&&!(0,n.isMindMapPlainStructureKind)(L)))})]})]}),le=e=>{switch(e){case`line`:return/* @__PURE__ */ (0,p.jsx)(l.ShapeStrokePanelContent,{title:u.t(`boards-mind-ui.toolbar.panel.line`),shapeData:k,modeOptions:[`solid`,`dash`,`dot`],showDashDropdown:!1,widthRange:{min:bt.min,max:bt.max,step:1},onUpdateShapeData:(e,t)=>{It(t,O)}});case`more`:return/* @__PURE__ */ (0,p.jsx)(c.EditorMenuPanel,{title:u.t(`boards-mind-ui.toolbar.panel.more`),minWidthClassName:`univer-min-w-[240px]`,children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,p.jsx)(c.EditorMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.addSibling`),shortcut:A(W.addSibling),onClick:te}),/* @__PURE__ */ (0,p.jsx)(c.EditorMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.addChild`),shortcut:A(W.addChild),onClick:I}),/* @__PURE__ */ (0,p.jsx)(d.Separator,{}),/* @__PURE__ */ (0,p.jsx)(c.EditorMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.copy`),shortcut:A(W.copy),onClick:ne}),/* @__PURE__ */ (0,p.jsx)(c.EditorMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.paste`),shortcut:A(W.paste),onClick:re}),/* @__PURE__ */ (0,p.jsx)(c.EditorMenuItem,{label:u.t(`boards-mind-ui.toolbar.action.delete`),shortcut:A(W.delete),onClick:ie})]})});default:return null}},z=St.flatMap(e=>{let t=[];if(e.dividerBefore&&t.push(/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`divider-${e.kind}`)),e.kind===`typography`)return t.push(/* @__PURE__ */ (0,p.jsx)(l.TypographyPanelButton,{title:u.t(`boards-mind-ui.toolbar.panel.typography`),fontFamily:N.fontFamily,textStyle:{isBold:M.bold===!0,isItalic:M.italic===!0,isUnderline:M.underline===!0,isStrike:M.strikethrough===!0},horizontalAlign:N.horizontalAlign,verticalAlign:N.verticalAlign,horizontalAlignOptions:F,verticalAlignOptions:ee,onUpdateText:P},e.kind)),t;if(e.kind===`fontColor`){let n={fs:N.fontSize,cl:{rgb:N.color},...N.textFill===void 0?null:{textFill:N.textFill}};return t.push(/* @__PURE__ */ (0,p.jsx)(l.TextFillButton,{title:u.t(`boards-mind-ui.toolbar.action.fontColor`),textStyle:n,fallbackColor:N.color,onChange:e=>P({textStyle:e})},e.kind)),t.push(/* @__PURE__ */ (0,p.jsx)(l.ShapeFloatingToolbarFontSizeSelect,{value:String(N.fontSize),onChange:e=>{P({textStyle:{fs:e}})}},`mind-map-font-size`)),t}return t.push(/* @__PURE__ */ (0,p.jsx)(d.Dropdown,{open:h===e.panel,overlay:le(e.panel),onOpenChange:t=>g(t?e.panel:null),children:/* @__PURE__ */ (0,p.jsx)(`span`,{children:/* @__PURE__ */ (0,p.jsx)(c.EditorDropdownTrigger,{title:u.t(e.titleKey),active:h===e.panel,icon:Ot(Dt[e.panel]),className:`[&>svg:last-child_*]:[vector-effect:non-scaling-stroke]`,sizeClassName:`univer-h-7 univer-min-w-9 univer-w-auto univer-gap-1 univer-px-1.5`,onMouseDown:G,onPointerDown:G})})},e.panel)),t}),B=[...y.isRootNode?[/* @__PURE__ */ (0,p.jsx)(d.Dropdown,{open:h===`layout`,overlay:ce(),onOpenChange:e=>g(e?`layout`:null),children:/* @__PURE__ */ (0,p.jsx)(`span`,{children:/* @__PURE__ */ (0,p.jsx)(c.EditorDropdownTrigger,{title:u.t(`boards-mind-ui.toolbar.action.layout`),active:h===`layout`,icon:Ot(Nt[L]),className:`[&>svg:last-child_*]:[vector-effect:non-scaling-stroke]`,sizeClassName:`univer-h-7 univer-min-w-9 univer-w-auto univer-gap-1 univer-px-1.5`,onMouseDown:G,onPointerDown:G})})},`mind-map-layout-dropdown`),/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`layout-panel-divider`)]:[],/* @__PURE__ */ (0,p.jsx)(l.ShapeFillButton,{title:u.t(`boards-mind-ui.toolbar.action.fill`),shapeData:_??{},onUpdateShapeData:D},`mind-map-fill`),/* @__PURE__ */ (0,p.jsx)(l.ShapeStrokePanelButton,{title:u.t(`boards-mind-ui.toolbar.action.stroke`),shapeData:_??{},onUpdateShapeData:D},`mind-map-stroke`),/* @__PURE__ */ (0,p.jsx)(d.Separator,{orientation:`vertical`},`style-divider`)];return/* @__PURE__ */ (0,p.jsxs)(c.EditorFloatingToolbar,{maxWidthClassName:`univer-max-w-[min(760px,calc(100vw-32px))]`,onMouseDown:e=>e.stopPropagation(),children:[B,z]})}function Bt(e){let{left:t,top:n,width:r,height:i}=e;return{left:t,right:t+r,top:n-56,bottom:n+i}}let Vt=class extends a.RxDisposable{constructor(e,t,n,r,i,a){super(),this._renderContext=e,this._boardCanvasPopManagerService=t,this._boardElementService=n,this._elementStateService=r,this._boardTextEditingService=i,this._interactionSurfaceService=a,x(this,`_popupDisposable`,null),x(this,`_popupSelectionKey`,null),this._init()}dispose(){this._clearPopup(),super.dispose()}_init(){let e=this._renderContext.scene.getTransformerByCreate();this.disposeWithMe((0,a.toDisposable)(e.createControl$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._showPopupForSelection()))),this.disposeWithMe((0,a.toDisposable)(e.clearControl$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._clearPopupIfSelectionChanged()))),this.disposeWithMe((0,a.toDisposable)(e.changeStart$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._clearPopup()))),this.disposeWithMe((0,a.toDisposable)(e.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>setTimeout(()=>this._showPopupForSelection(),0)))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>setTimeout(()=>this._showPopupForSelection(),0)))),this.disposeWithMe((0,a.toDisposable)(this._interactionSurfaceService.interactionSurfaceActive$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e?this._clearPopup():setTimeout(()=>this._showPopupForSelection(),0)}))),this.disposeWithMe((0,a.toDisposable)(this._boardTextEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{(e==null?void 0:e.unitId)===this._renderContext.unitId&&(e.visible?this._clearPopup():setTimeout(()=>this._showPopupForSelection(),0))})))}_clearPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null,this._popupSelectionKey=null}_clearPopupIfSelectionChanged(){setTimeout(()=>{this._isPopupSelectionStillActive()||this._clearPopup()},0)}_isPopupSelectionStillActive(){let e=this._elementStateService.getSnapshot();return!!e.context&&e.selectedIds.length>0&&this._popupSelectionKey===this._buildPopupSelectionKey(e.context.unitId,e.context.subUnitId,e.selectedIds)}_buildPopupSelectionKey(e,t,n){return`${e}:${t}:${n.join(`,`)}`}_resolveIncomingConnectorStyle(e,t,r,i){let a=this._boardElementService.getElementData(e,t),o=Object.values(a).find(e=>{let t=(0,n.getMindMapConnectorMeta)(e.element);return(t==null?void 0:t.structureScopeId)===r&&t.childNodeId===i});if(o&&`connectorData`in o.element)return o.element.connectorData.style}_showPopupForSelection(){var e,i,a;if(this._interactionSurfaceService.isInteractionSurfaceActive){this._clearPopup();return}let o=this._boardTextEditingService.getEditing();if((o==null?void 0:o.visible)===!0&&o.unitId===this._renderContext.unitId){this._clearPopup();return}let s=this._elementStateService.getSnapshot();if(s.isTransforming||(0,r.resolveBoardFloatingToolbarSelection)({context:s.context,selectedIds:s.selectedIds,getElementById:(e,t,n)=>this._boardElementService.getElementById(e,t,n)}).owner!==`mind-map`){this._clearPopup();return}let c=this._renderContext.scene.getTransformerByCreate().getSelectedObjectMap(),l=Array.from(c.values()).map(e=>this._resolveSelectedEntry(e)).filter(e=>!!e).filter(e=>!!(0,n.getMindMapNodeMeta)(e.elementData.element)),u=l.find(e=>e.elementData.elementId===s.focusedId)??l[0]??this._resolveSelectedMindMapEntryFromState();if(!u){this._clearPopup();return}let d=(0,n.getMindMapNodeMeta)(u.elementData.element);if(!d){this._clearPopup();return}let f=(e=this._boardElementService.getElementData(u.elementData.unitId,u.elementData.subUnitId)[d.structureScopeId])==null?void 0:e.element,p=(0,n.getMindMapContainerMeta)(f),m=f==null||(i=f.custom)==null||(i=i.mindmap)==null||(i=i.layout)==null?void 0:i.structureKind,h=((p==null?void 0:p.layout.structureKind)??m)===`mindmap-vertical`&&(d.parentNodeId===null||d.side===`top`),g=d.parentNodeId!==null&&d.side!==`top`&&d.side!==`bottom`,_=h||g,v=((a=s.context)==null?void 0:a.unitId)===u.elementData.unitId&&s.context.subUnitId===u.elementData.subUnitId&&s.selectedIds.length?s.selectedIds:[u.elementData.elementId],y=this._buildPopupSelectionKey(u.elementData.unitId,u.elementData.subUnitId,v);this._popupDisposable&&this._popupSelectionKey===y||(this._clearPopup(),this._popupDisposable=this.disposeWithMe(this._boardCanvasPopManagerService.attachPopupToObject(u.elementData.unitId,u.elementData.subUnitId,u.object,{componentKey:Tt,direction:`top-center`,offset:[0,8],..._?{anchorBoundResolver:Bt}:null,extraProps:{unitId:u.elementData.unitId,subUnitId:u.elementData.subUnitId,elementId:u.elementData.elementId,scopeId:d.structureScopeId,isRootNode:d.parentNodeId===null,left:u.elementData.element.transform.left??0,top:u.elementData.element.transform.top??0,shapeData:u.elementData.element.type===t.BoardElementType.Shape?u.elementData.element.shapeData:void 0,incomingConnectorStyle:this._resolveIncomingConnectorStyle(u.elementData.unitId,u.elementData.subUnitId,d.structureScopeId,u.elementData.elementId)}})),this._popupSelectionKey=y)}_resolveSelectedMindMapEntryFromState(){var e;let t=this._elementStateService.getSnapshot(),i=t.context,a=t.focusedId??t.selectedIds[0];if(!i||!a)return null;let o=this._boardElementService.getElementById(i.unitId,i.subUnitId,a);if(!o||!(0,n.getMindMapNodeMeta)(o.element))return null;let s=(0,r.getBoardElementRenderObjectKey)(i.unitId,a),c=this._renderContext.scene,l=((e=c.getObjectIncludeInGroup)==null?void 0:e.call(c,s))??this._renderContext.scene.getObject(s);return l?{object:l,elementData:o}:null}_resolveSelectedEntry(e){var t;if(!e)return null;let n=(0,r.parseBoardElementRenderObjectKey)(e.oKey);if(!n)return null;let i=this._elementStateService.getSnapshot(),a=((t=i.context)==null?void 0:t.unitId)===n.unitId?i.context.subUnitId:void 0;if(!a)return null;let o=this._boardElementService.getElementById(n.unitId,a,n.elementId);return o?{object:e,elementData:o}:null}};Vt=C([S(1,(0,a.Inject)(r.BoardCanvasPopManagerService)),S(2,(0,a.Inject)(t.IBoardElementService)),S(3,(0,a.Inject)(r.IBoardElementStateService)),S(4,(0,a.Inject)(r.BoardTextEditingService)),S(5,(0,a.Inject)(r.BoardInteractionSurfaceService))],Vt);let Ht=`board-mind-map-pending-insert-object`,Ut=r.BOARD_RENDER_LAYER_INDEX.preview;var Wt=class extends o.BaseObject{constructor(e=Ht,t){super(e),x(this,`_state`,{point:null,children:[]}),x(this,`_preview`,null),this.evented=!1,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientPreview,this.updateState(t)}updateState(e){let t=this._state;if(this._state={...t,...e},!this._preview||t.structureKind!==this._state.structureKind||t.rootText!==this._state.rootText||t.branchLineType!==this._state.branchLineType||!a.Tools.diffValue(t.children,this._state.children)||!a.Tools.diffValue(t.blueprint,this._state.blueprint)){let e={left:0,top:0,structureKind:this._state.structureKind,branchLineType:this._state.branchLineType},t=this._state.blueprint;t&&this._state.rootText&&(t={...t,root:{...t.root,text:this._state.rootText}}),this._preview=t?(0,n.createMindMapElementsFromBlueprint)({...e,blueprint:t}):(0,n.createMindMapElements)({...e,rootText:this._state.rootText,children:this._state.children})}this._state.point?this.show():this.hide(),this.makeDirty(!0)}isHit(e){return!1}getRootTopLeft(e){var t,r;return{left:Math.round(e.x-(((t=this._preview)==null?void 0:t.rootNode.transform.width)??n.MIND_MAP_DEFAULT_NODE_SIZE.rootWidth)/2),top:Math.round(e.y-(((r=this._preview)==null?void 0:r.rootNode.transform.height)??n.MIND_MAP_DEFAULT_NODE_SIZE.rootHeight)/2)}}render(e,t){var r;let i=this._state.point,a=this._preview;if(!i||!a||!this.visible)return this.makeDirty(!1),this;let o=Number.isFinite(this._state.zoomRatio)&&(this._state.zoomRatio??0)>0?this._state.zoomRatio:1,s=a.rootNode.transform.width??n.MIND_MAP_DEFAULT_NODE_SIZE.rootWidth,c=a.rootNode.transform.height??n.MIND_MAP_DEFAULT_NODE_SIZE.rootHeight,l=this.getRootTopLeft(i),u=l.left-(a.rootNode.transform.left??0),d=l.top-(a.rootNode.transform.top??0),f=u-(a.container.transform.left??0),p=d-(a.container.transform.top??0);e.save(),e.globalAlpha=D.objectAlpha,e.lineWidth=D.lineWidthScreen/o,e.strokeStyle=D.primaryColor,e.beginPath();for(let t of((r=a.container.containerData.shapeData.customGeometry)==null?void 0:r.pathLst)??[])for(let n of t.dataArray??[]){let t=Number(n.points[0])+u,r=Number(n.points[1])+d;n.command===`M`?e.moveTo(t,r):n.command===`L`&&e.lineTo(t,r)}for(let t of a.connectors){var m;if(t.visible===!1)continue;let n=t.connectorData,r=n.start.kind===`free`?n.start:n.start.fallbackPoint,i=n.end.kind===`free`?n.end:n.end.fallbackPoint;if(!r||!i)continue;e.moveTo(r.x+f,r.y+p);let a=(m=n.curveData)==null?void 0:m.controls;if(n.routing===`curve`&&a&&a.length>=2)e.bezierCurveTo(a[0].x+f,a[0].y+p,a[1].x+f,a[1].y+p,i.x+f,i.y+p);else{var h;for(let t of((h=n.orthogonalData)==null?void 0:h.routePoints)??[])e.lineTo(t.x+f,t.y+p);e.lineTo(i.x+f,i.y+p)}}e.stroke();for(let t of a.nodes)t.id!==a.rootNode.id&&t.visible!==!1&&(O(e,u+(t.transform.left??0),d+(t.transform.top??0),t.transform.width??n.MIND_MAP_DEFAULT_NODE_SIZE.nodeWidth,t.transform.height??n.MIND_MAP_DEFAULT_NODE_SIZE.nodeHeight,D.ghostRadius),e.fillStyle=D.ghostFillColor,e.fill(),e.stroke());O(e,l.left,l.top,s,c,D.rootRadius),e.fillStyle=D.primaryColor,e.fill(),e.stroke(),e.fillStyle=D.rootTextColor,e.font=k(D.rootFontWeight,D.rootFontSize,o),e.textAlign=`center`,e.textBaseline=`middle`;let g=D.textPaddingScreen/o;return e.fillText(n.MIND_MAP_DEFAULT_NODE_TEXT,l.left+s/2,l.top+c/2,Math.max(1,s-g*2)),e.restore(),this.makeDirty(!1),this}};let Gt={children:[{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(0),side:`right`},{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(1),side:`right`},{text:n.MIND_MAP_DEFAULT_NODE_TEXT,orderKey:(0,n.getMindMapDefaultChildOrderKey)(2),side:`right`}]};var K=class extends a.Disposable{constructor(...e){super(...e),x(this,`_template`,Gt)}setTemplate(e){var t;let n=(e==null?void 0:e.children)??(e==null||(t=e.blueprint)==null?void 0:t.root.children);this._template={rootText:e==null?void 0:e.rootText,structureKind:e==null?void 0:e.structureKind,branchLineType:e==null?void 0:e.branchLineType,children:this._normalizeChildren(n,e==null?void 0:e.structureKind),blueprint:e!=null&&e.blueprint?this._cloneBlueprint(e.blueprint):void 0}}getTemplate(){var e;return{rootText:this._template.rootText,structureKind:this._template.structureKind,branchLineType:this._template.branchLineType,children:(e=this._template.children)==null?void 0:e.map(e=>({...e})),blueprint:this._template.blueprint?this._cloneBlueprint(this._template.blueprint):void 0}}_cloneBlueprint(e){return{title:e.title,root:this._cloneBlueprintNode(e.root)}}_cloneBlueprintNode(e){return{...e,foreignAttributes:e.foreignAttributes?{...e.foreignAttributes}:void 0,children:e.children.map(e=>this._cloneBlueprintNode(e))}}_normalizeChildren(e,t){let r=!e,i=e??Gt.children;return i==null?void 0:i.map((e,i)=>({...e,text:e.text??n.MIND_MAP_DEFAULT_NODE_TEXT,side:this._resolveChildSide(e.side,i,t,r)}))}_resolveChildSide(e,t,n,r){return n===`mindmap-vertical`?r?`bottom`:e??`bottom`:n===`tree-left`?r?`left`:e??`left`:n===`tree-right`?r?`right`:e??`right`:n===`tree-alternate`?r?t%2==0?`left`:`right`:e??(t%2==0?`left`:`right`):n===`timeline-horizontal`?r?t%2==0?`top`:`bottom`:e??(t%2==0?`top`:`bottom`):n===`timeline-vertical`?r?t%2==0?`left`:`right`:e??(t%2==0?`left`:`right`):e}};function Kt(e,t){let n=Number.isFinite(t.zoomRatio)&&t.zoomRatio>0?t.zoomRatio:1;return{x:Math.round((e.offsetX-t.panOffset.x)/n),y:Math.round((e.offsetY-t.panOffset.y)/n)}}function qt(e){var t;e!=null&&e.dispose?e.dispose():e==null||(t=e.unsubscribe)==null||t.call(e)}function Jt(e){var n;return e.activeTool===t.BoardToolType.MindMap&&((n=e.pendingInsert)==null?void 0:n.type)===t.BoardToolType.MindMap}let Yt=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._renderContext=e,this._instanceSrv=t,this._stateService=n,this._commandService=r,this._insertStateService=i,this._elementStateService=a,this._boardTextEditingService=o,x(this,`_previewObject`,null),x(this,`_lastPoint`,null),this._init()}_init(){var e;let{scene:t,unitId:n}=this._renderContext,r=this._instanceSrv.getUnit(n,a.UniverInstanceType.UNIVER_BOARD);if(!r)return;let i=(e=t.onPointerMove$)==null?void 0:e.subscribeEvent({priority:4,next:([e,t])=>this._handlePointerMove(e,t)}),o=t.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>this._handlePointerDown(r,e,t)});this.disposeWithMe((0,a.toDisposable)(()=>qt(i))),this.disposeWithMe((0,a.toDisposable)(()=>qt(o)));let s=this._stateService.state$.subscribe(()=>this._syncPreviewObject());this.disposeWithMe((0,a.toDisposable)(()=>qt(s))),this.disposeWithMe((0,a.toDisposable)(()=>{this._removePreviewObject()})),this._syncPreviewObject()}_syncPreviewObject(){var e,t;let n=this._stateService.getState();if(!Jt(n)){this._removePreviewObject();return}let r=this._ensurePreviewObject(),i=this._insertStateService.getTemplate();r.updateState({point:this._lastPoint,structureKind:i.structureKind,rootText:i.rootText,branchLineType:i.branchLineType,children:i.children,blueprint:i.blueprint,zoomRatio:n.zoomRatio}),(e=(t=this._renderContext.scene).makeDirty)==null||e.call(t,!0)}_ensurePreviewObject(){var e,t;if(this._previewObject)return this._previewObject;let n=this._insertStateService.getTemplate(),r=new Wt(Ht,{point:this._lastPoint,structureKind:n.structureKind,rootText:n.rootText,branchLineType:n.branchLineType,children:n.children,blueprint:n.blueprint,zoomRatio:this._stateService.getState().zoomRatio});return this._previewObject=r,(e=(t=this._renderContext.scene).addObject)==null||e.call(t,r,Ut),r}_removePreviewObject(){var e,t,n,r;this._previewObject?((e=(t=this._renderContext.scene).removeObjects)==null||e.call(t,[this._previewObject]),this._previewObject=null,this._lastPoint=null,(n=(r=this._renderContext.scene).makeDirty)==null||n.call(r,!0)):this._lastPoint=null}_getPointFromEvent(e){let t=this._stateService.getState();return Kt(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio})}_handlePointerMove(e,t){Jt(this._stateService.getState())&&(this._lastPoint=this._getPointFromEvent(e),this._syncPreviewObject(),t.stopPropagation())}async _handlePointerDown(e,t,n){let i=await this._insertMindMap(e,t,n);if(!i)return;let a={unitId:this._renderContext.unitId,subUnitId:i.subUnitId};this._boardTextEditingService.ignoreExternalFocusChanges(),this._boardTextEditingService.setEditing({...a,shapeId:i.rootNodeId,shapeKey:(0,r.getBoardElementRenderObjectKey)(a.unitId,i.rootNodeId),visible:!0})}async _insertMindMap(e,r,i){var o;let s=this._stateService.getState(),c=r.button??0;if(!Jt(s)||c!==0)return null;let l=this._getPointFromEvent(r);this._lastPoint=l,this._syncPreviewObject();let u=this._ensurePreviewObject().getRootTopLeft(l),d=this._insertStateService.getTemplate(),f=(0,a.generateRandomId)(6),p=e.getActivePageId(),m=this._commandService.executeCommand(n.InsertBoardMindMapOperation.id,{unitId:this._renderContext.unitId,subUnitId:p,left:u.left,top:u.top,rootNodeId:f,rootText:d.rootText,structureKind:d.structureKind,branchLineType:d.branchLineType,children:d.children,blueprint:d.blueprint});if(this._stateService.setActiveTool(t.BoardToolType.Select),i.stopPropagation(),(o=r.preventDefault)==null||o.call(r),!await m||this._disposed)return null;let h={unitId:this._renderContext.unitId,subUnitId:p};return this._elementStateService.selectElements(h,[f],f),{rootNodeId:f,subUnitId:p}}};Yt=C([S(1,a.IUniverInstanceService),S(2,r.IBoardUIStateService),S(3,a.ICommandService),S(4,(0,a.Inject)(K)),S(5,r.IBoardElementStateService),S(6,(0,a.Inject)(r.BoardTextEditingService))],Yt);var Xt=class extends a.Disposable{constructor(...e){super(...e),x(this,`_refresh$`,new s.Subject),x(this,`refresh$`,this._refresh$.asObservable())}notify(e){this._refresh$.next(e)}dispose(){this._refresh$.complete(),super.dispose()}};function Zt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0}function Qt(e,t,r){let i=e[t],a=(0,n.getMindMapNodeMeta)(i==null?void 0:i.element);if(!i||!a)return null;let o=(0,n.resolveMindMapNodeHostSize)(i,r);if(!o)return null;let s=i.transform??i.element.transform,c={...e,[t]:{...i,transform:{...s,width:o.width,height:o.height},element:{...i.element,transform:{...i.element.transform,width:o.width,height:o.height}}}};return(0,n.resolveMindMapLayoutPreview)(c,a.structureScopeId)}let $t=class extends a.RxDisposable{constructor(e,t,r,i,o,s){super(),this._renderContext=e,this._intrinsicSizeService=t,this._boardElementService=r,this._textEditingService=i,this._previewRefreshService=o,this._commandService=s,x(this,`_activePreview`,null),x(this,`_provider`,{match:e=>e.unitId===this._renderContext.unitId&&!!(0,n.getMindMapNodeMeta)(e.element),resolveHostSize:e=>this._resolveHostSize(e),previewHostSize:e=>this._previewHostSize(e),updateHostSize:e=>this._updateHostSize(e),updateShapeText:e=>this._updateShapeText(e)}),this.disposeWithMe(this._intrinsicSizeService.registerProvider(this._provider)),this._initEditingRestore(),this.disposeWithMe((0,a.toDisposable)(()=>this._restoreActivePreview()))}_updateHostSize(e){return this._previewHostSize(e)}_updateShapeText(e){let t=e.params.hostSize?this._resolveHostSize({elementData:e.elementData,params:e.params.hostSize}):null,i=e.elementData.transform??e.elementData.element.transform;return(!t||t.width===i.width&&t.height===i.height)&&(0,r.areBoardShapeTextValuesEquivalent)(e.params.shapeText,e.params.oldShapeText)?!0:this._commandService.syncExecuteCommand(n.UpdateMindMapNodeOperation.id,{unitId:e.params.unitId,subUnitId:e.params.subUnitId,nodeId:e.params.shapeId,shapeText:e.params.shapeText,...t?{hostSize:{width:t.width,height:t.height}}:null})}_previewHostSize(e){let t=this._resolveHostSize(e);if(!t)return!1;let n=e.elementData.transform??e.elementData.element.transform;return!this._activePreview&&n.width===t.width&&n.height===t.height||this._syncLayoutPreview(e,t),!0}_resolveHostSize(e){return!Zt(e.params.width)||!Zt(e.params.height)?null:(0,n.resolveMindMapNodeHostSize)(e.elementData,{width:e.params.width,height:e.params.height})}_initEditingRestore(){this.disposeWithMe((0,a.toDisposable)(this._textEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{e||this._restoreActivePreview()})))}_syncLayoutPreview(e,t){var r;let i=this._boardElementService.getElementData(e.params.unitId,e.params.subUnitId),a=Qt(i,e.params.shapeId,t),o=(0,n.getMindMapNodeMeta)((r=i[e.params.shapeId])==null?void 0:r.element);a&&o&&(this._activePreview={unitId:e.params.unitId,subUnitId:e.params.subUnitId,scopeId:o.structureScopeId},this._syncElementDataToScene(a,o.structureScopeId)&&this._previewRefreshService.notify({unitId:e.params.unitId,subUnitId:e.params.subUnitId,nodeId:e.params.shapeId,scopeId:o.structureScopeId}))}_restoreActivePreview(){let e=this._activePreview;if(!e)return;this._activePreview=null;let t=this._boardElementService.getElementData(e.unitId,e.subUnitId);this._syncElementDataToScene(t,e.scopeId)&&this._previewRefreshService.notify({unitId:e.unitId,subUnitId:e.subUnitId,nodeId:e.scopeId,scopeId:e.scopeId})}_syncElementDataToScene(e,t){let i=!1;if(Object.values(e).forEach(a=>{var o;let s=(0,n.getMindMapNodeMeta)(a.element),c=(o=a.element.custom)==null?void 0:o.structured;if(a.elementId!==t&&(s==null?void 0:s.structureScopeId)!==t&&(c==null?void 0:c.structureScopeId)!==t)return;let l=this._getSceneObject(a.elementId);l&&(i=(0,r.syncBoardElementRenderObject)(l,a,{elementData:e,unitId:this._renderContext.unitId})||i)}),i){var a,o;this._renderContext.scene.makeDirty(!0),(a=(o=this._renderContext.scene).requestRender)==null||a.call(o)}return i}_getSceneObject(e){var t;let n=(0,r.getBoardElementRenderObjectKey)(this._renderContext.unitId,e),i=this._renderContext.scene;return((t=i.getObjectIncludeInGroup)==null?void 0:t.call(i,n))??this._renderContext.scene.getObject(n)??null}};$t=C([S(1,(0,a.Inject)(r.BoardShapeIntrinsicSizeService)),S(2,(0,a.Inject)(t.IBoardElementService)),S(3,(0,a.Inject)(r.BoardTextEditingService)),S(4,(0,a.Inject)(Xt)),S(5,a.ICommandService)],$t);let q={touchHitRadius:22,radius:18,addChildRadius:14,siblingHoverRadius:10,siblingDotRadius:5,siblingDotGap:3,gap:10,collapsePlusMinDistance:44,primaryColor:T.primaryColor,surfaceColor:T.surfaceColor,borderWidth:2,glyphSize:8,addChildGlyphSize:6,siblingGlyphSize:5.5,glyphWidth:2.4,glyphHoverWidth:3,badgeFontWeight:600,badgeFontSize:18,fontFamily:T.fontFamily};function en(e){let t=q.radius,n=q.addChildRadius,r=q.siblingHoverRadius,i=q.gap,a=q.siblingDotRadius,o=a+q.siblingDotGap,s=q.collapsePlusMinDistance,c=e.bounds.top+e.bounds.height/2,l=e.bounds.left+e.bounds.width/2,u=e.bounds.left-t-i,d=e.bounds.left+e.bounds.width+t+i,f=e.bounds.top-t-i,p=e.bounds.top+e.bounds.height+t+i,m=e.bounds.left-n-i,h=e.bounds.left+e.bounds.width+n+i,g=e.bounds.top-n-i,_=e.bounds.top+e.bounds.height+n+i,v=[],y=e.side===`top`||e.side===`bottom`,b=y?l:e.side===`left`?u:d,x=y?e.side===`top`?f:p:c;if(e.hasChildren&&e.collapsedDescendantCount>0)return v.push({kind:`toggle-collapse`,x:b,y:x,radius:t,badgeCount:e.collapsedDescendantCount}),v;if(e.isRoot?(e.rootChildSides??(y?[`top`,`bottom`]:[`left`,`right`])).forEach(e=>{e===`top`?v.push({kind:`add-child-top`,x:l,y:g,radius:n}):e===`bottom`?v.push({kind:`add-child-bottom`,x:l,y:_,radius:n}):e===`left`?v.push({kind:`add-child-left`,x:m,y:c,radius:n}):v.push({kind:`add-child-right`,x:h,y:c,radius:n})}):(v.push({kind:e.side===`left`?`add-child-left`:e.side===`top`?`add-child-top`:e.side===`bottom`?`add-child-bottom`:`add-child-right`,x:y?l:e.side===`left`?m:h,y:y?e.side===`top`?g:_:c,radius:n}),y?(v.push({kind:`add-sibling-before`,placement:`before`,x:e.bounds.left-o,y:c,radius:r,visualRadius:a}),v.push({kind:`add-sibling-after`,placement:`after`,x:e.bounds.left+e.bounds.width+o,y:c,radius:r,visualRadius:a})):(v.push({kind:`add-sibling-before`,placement:`before`,x:l,y:e.bounds.top-o,radius:r,visualRadius:a}),v.push({kind:`add-sibling-after`,placement:`after`,x:l,y:e.bounds.top+e.bounds.height+o,radius:r,visualRadius:a}))),e.hasChildren){let n={kind:`toggle-collapse`,x:b,y:x,radius:t};v.push(n);let r=v.find(t=>t.kind===(e.side===`left`?`add-child-left`:e.side===`top`?`add-child-top`:e.side===`bottom`?`add-child-bottom`:`add-child-right`));r&&Math.hypot(r.x-n.x,r.y-n.y)<s&&(e.side===`top`||e.side===`bottom`?r.y=n.y+(e.side===`top`?-s:s):r.x=n.x+(e.side===`left`?-s:s))}return v}let tn=`board-mind-map-node-controls-object`,nn=r.BOARD_RENDER_LAYER_INDEX.connectorAffordance;function rn(e,t){return!!e&&e.kind===t.kind&&e.x===t.x&&e.y===t.y}var an=class extends o.Control{constructor(e=tn,t){super(e),x(this,`_state`,{controls:[]}),this.evented=!0,this.zIndex=r.BOARD_RENDER_OBJECT_Z_INDEX.transientControl,this.updateState(t)}updateState(e){this._state={...this._state,...e},this._state.controls.length>0?this.show():this.hide(),this.makeDirty(!0)}setHoveredControl(e){!e&&!this._state.hoveredControl||e&&rn(this._state.hoveredControl,e)||(this._state={...this._state,hoveredControl:e},this.makeDirty(!0))}getHitControl(e,t){var n;let r=(n=this.getScene())==null?void 0:n.getAncestorScale(),i=null,a=1/0;for(let n=this._state.controls.length-1;n>=0;--n){let s=this._state.controls[n],c=Math.hypot(e.x-s.x,e.y-s.y);if(t!==o.DeviceType.Touch){if(c<=s.radius)return s;continue}let l=Math.hypot((e.x-s.x)*((r==null?void 0:r.scaleX)??1),(e.y-s.y)*((r==null?void 0:r.scaleY)??1));(c<=s.radius||l<=q.touchHitRadius)&&l<a&&(i=s,a=l)}return i}getTouchHitDistance(e){var t;let n=this.getHitControl(e,o.DeviceType.Touch),r=(t=this.getScene())==null?void 0:t.getAncestorScale();return n?Math.hypot((e.x-n.x)*((r==null?void 0:r.scaleX)??1),(e.y-n.y)*((r==null?void 0:r.scaleY)??1)):1/0}isHit(e){return!!this.getHitControl({x:e.x,y:e.y})}render(e,t){return!this.visible||this._state.controls.length===0?(this.makeDirty(!1),this):(e.save(),this._state.controls.forEach(t=>{let n=rn(this._state.hoveredControl,t),r=t.badgeCount!==void 0,i=t.kind===`add-child-left`||t.kind===`add-child-right`||t.kind===`add-child-top`||t.kind===`add-child-bottom`,a=t.kind===`add-sibling-before`||t.kind===`add-sibling-after`,o=a&&!n?t.visualRadius??t.radius:t.radius;if(e.beginPath(),e.fillStyle=t.kind===`toggle-collapse`?q.surfaceColor:q.primaryColor,e.strokeStyle=q.primaryColor,e.lineWidth=q.borderWidth,e.arc(t.x,t.y,o,0,Math.PI*2),e.fill(),(!a||n)&&e.stroke(),!r&&(!a||n)){if(e.beginPath(),e.strokeStyle=t.kind===`toggle-collapse`?q.primaryColor:q.surfaceColor,e.lineWidth=a?q.glyphWidth:n?q.glyphHoverWidth:q.glyphWidth,e.lineCap=`round`,t.kind===`toggle-collapse`){let n=q.glyphSize;e.moveTo(t.x+n/2,t.y-n),e.lineTo(t.x-n/2,t.y),e.lineTo(t.x+n/2,t.y+n)}else{let n=a?q.siblingGlyphSize:i?q.addChildGlyphSize:q.glyphSize;e.moveTo(t.x-n,t.y),e.lineTo(t.x+n,t.y),e.moveTo(t.x,t.y-n),e.lineTo(t.x,t.y+n)}e.stroke()}r&&(e.fillStyle=q.primaryColor,e.font=`${q.badgeFontWeight} ${q.badgeFontSize}px ${q.fontFamily}`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(String(t.badgeCount),t.x,t.y))}),e.restore(),this.makeDirty(!1),this)}};function on(e){return e===`tree-left`||e===`tree-right`||e===`tree-alternate`}function sn(e){return e===`timeline-horizontal`||e===`timeline-vertical`}function cn(e,t){let n=Number.isFinite(t.zoomRatio)&&t.zoomRatio>0?t.zoomRatio:1;return{x:Math.round((e.offsetX-t.panOffset.x)/n),y:Math.round((e.offsetY-t.panOffset.y)/n)}}let ln=class extends a.RxDisposable{constructor(e,t,n,r,i,a,o,s,c){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._stateService=r,this._commandService=i,this._boardTextEditingService=a,this._localeService=o,this._previewRefreshService=s,this._undoRedoGroupService=c,x(this,`_object`,null),x(this,`_objectEventDisposables`,null),x(this,`_activeNodeId`,null),x(this,`_activeScopeId`,null),this._init()}_init(){var e,t,n;let{scene:r}=this._renderContext,i=(e=r.getTransformerByCreate)==null?void 0:e.call(r);i&&(this.disposeWithMe((0,a.toDisposable)(i.changing$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(({objects:e})=>{this._syncControls(e,{hideRootControls:!0})}))),this.disposeWithMe((0,a.toDisposable)(i.changeEnd$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=e==null?void 0:e.objects;this._syncControls(t),setTimeout(()=>this._syncControls(t),0)})))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._syncControls()))),this.disposeWithMe((0,a.toDisposable)(this._stateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>this._syncControls()))),this.disposeWithMe((0,a.toDisposable)(this._boardElementService.elementUpdate$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=this._elementStateService.getSnapshot().context;t&&e.some(e=>e.unitId===t.unitId&&e.subUnitId===t.subUnitId&&(e.elementId===this._activeNodeId||e.elementId===this._activeScopeId))&&this._syncControls()}))),this.disposeWithMe((0,a.toDisposable)(this._previewRefreshService.refresh$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{let t=this._elementStateService.getSnapshot().context;t&&t.unitId===e.unitId&&t.subUnitId===e.subUnitId&&(this._activeScopeId&&this._activeScopeId!==e.scopeId||this._syncControls())}))),this.disposeWithMe((0,a.toDisposable)(r.onPointerMove$.subscribeEvent(e=>this._handlePointerMove(e)))),this.disposeWithMe((0,a.toDisposable)(r.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>{this._handlePointerDown(e)&&this._consumeControlEvent(e,t)}}))),this.disposeWithMe((0,a.toDisposable)(((t=r.onPointerUp$)==null?void 0:t.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(((n=r.onDblclick$)==null?void 0:n.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}}))??{dispose:()=>{}})),this.disposeWithMe((0,a.toDisposable)(()=>this._removeObject())),this._syncControls()}_ensureObject(){return this._object||(this._object=new an(tn),this._attachObjectEvents(this._object),this._renderContext.scene.addObject(this._object,nn)),this._object}_attachObjectEvents(e){var t;(t=this._objectEventDisposables)==null||t.dispose();let n=new a.DisposableCollection;n.add(e.onPointerDown$.subscribeEvent({priority:4,next:([e,t])=>{this._handlePointerDown(e)&&this._consumeControlEvent(e,t)}})),n.add(e.onPointerUp$.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}})),n.add(e.onDblclick$.subscribeEvent({priority:4,next:([e,t])=>{this._isControlEvent(e)&&this._consumeControlEvent(e,t)}})),this._objectEventDisposables=n}_removeObject(){var e;this._object&&(this._renderContext.scene.removeObjects([this._object]),(e=this._objectEventDisposables)==null||e.dispose(),this._objectEventDisposables=null,this._object=null,this._activeNodeId=null,this._activeScopeId=null,this._renderContext.scene.makeDirty(!0))}_syncControls(e,t){var i,a;if(this._stateService.getState().interactionMode===`viewing`){this._removeObject();return}let o=this._elementStateService.getSnapshot(),s=o.context,c=o.focusedId??o.selectedIds[0];if(!s||!c||o.selectedIds.length!==1){this._removeObject();return}let l=this._boardElementService.getElementData(s.unitId,s.subUnitId),u=l[c],d=(0,n.getMindMapNodeMeta)(u==null?void 0:u.element);if(!u||!d){this._removeObject();return}let f=(0,r.getBoardElementRenderObjectKey)(s.unitId,c);if(t!=null&&t.hideRootControls&&d.parentNodeId==null&&e!=null&&e.has(f)){this._removeObject();return}let p=this._resolveControlBounds(l,s.unitId,c,e);if(!p){this._removeObject();return}let m=Object.values(l).filter(e=>{var t;return((t=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:t.parentNodeId)===c}),h=d.collapsed?this._countDescendants(l,c):0;this._activeNodeId=c,this._activeScopeId=d.structureScopeId;let g=(i=l[d.structureScopeId])==null?void 0:i.element,_=(0,n.getMindMapContainerMeta)(g),v=g==null||(a=g.custom)==null||(a=a.mindmap)==null||(a=a.layout)==null?void 0:a.structureKind,y=(_==null?void 0:_.layout.structureKind)??v,b=d.parentNodeId==null,x=this._resolveControlSide(d.side,b,y);this._ensureObject().updateState({controls:en({bounds:p,isRoot:b,side:x,rootChildSides:this._resolveRootChildControlSides(b,y),hasChildren:m.length>0,collapsedDescendantCount:h})}),this._renderContext.scene.makeDirty(!0)}_resolveControlSide(e,t,n){return n===`timeline-vertical`?!t&&(e===`left`||e===`right`)?e:`bottom`:n===`mindmap-vertical`?!t&&(e===`top`||e===`bottom`)?e:`bottom`:e===`left`?`left`:`right`}_resolveRootChildControlSides(e,t){if(e){if(on(t))return[`bottom`];if(t===`timeline-horizontal`)return[`right`];if(t===`timeline-vertical`)return[`bottom`]}}_resolveCreateChildSide(e){var t,r;let i=this._elementStateService.getSnapshot().context;if(!i||!this._activeNodeId)return;let a=this._boardElementService.getElementData(i.unitId,i.subUnitId),o=(0,n.getMindMapNodeMeta)((t=a[this._activeNodeId])==null?void 0:t.element),s=o?(0,n.getMindMapContainerMeta)((r=a[o.structureScopeId])==null?void 0:r.element):null;if((o==null?void 0:o.parentNodeId)!=null||!on(s==null?void 0:s.layout.structureKind)&&!sn(s==null?void 0:s.layout.structureKind))return e===`add-child-left`?`left`:e===`add-child-top`?`top`:e===`add-child-bottom`?`bottom`:`right`}_resolveControlBounds(e,n,i,a){var o,s;let c=(0,r.getBoardElementRenderObjectKey)(n,i),l=a==null?void 0:a.get(c),u=this._toFiniteBounds(l);if(u)return u;let d=this._renderContext.scene,f=((o=d.getObjectIncludeInGroup)==null?void 0:o.call(d,c))??((s=d.getObject)==null?void 0:s.call(d,c));return this._toFiniteBounds(f)||(0,t.resolveBoardElementWorldBounds)(e,i)}_toFiniteBounds(e){return e&&Number.isFinite(e.left)&&Number.isFinite(e.top)&&Number.isFinite(e.width)&&Number.isFinite(e.height)?{left:e.left,top:e.top,width:e.width,height:e.height}:null}_countDescendants(e,t){return Object.values(e).filter(e=>{var r;return((r=(0,n.getMindMapNodeMeta)(e.element))==null?void 0:r.parentNodeId)===t}).reduce((t,n)=>t+1+this._countDescendants(e,n.elementId),0)}_handlePointerMove(e){if(!this._object)return;let t=this._stateService.getState(),n=cn(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio});this._object.setHoveredControl(this._object.getHitControl(n,e.deviceType))}_handlePointerDown(e){if(!this._object||!this._activeNodeId||(e.button??0)!==0)return!1;let t=this._elementStateService.getSnapshot().context;if(!t)return!1;let r=this._stateService.getState(),i=cn(e,{panOffset:r.viewportPanOffset,zoomRatio:r.zoomRatio}),o=this._object.getHitControl(i,e.deviceType);if(!o)return!1;if(o.kind===`toggle-collapse`)return this._executeAndLayout(n.ToggleMindMapNodeCollapseOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:this._activeNodeId}),!0;if(o.kind===`add-child-left`||o.kind===`add-child-right`||o.kind===`add-child-top`||o.kind===`add-child-bottom`){let e=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(n.AddMindMapChildOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,parentNodeId:this._activeNodeId,side:this._resolveCreateChildSide(o.kind),nodeId:e,connectorId:(0,a.generateRandomId)(6),text:this._localeService.t(`boards-mind-ui.panel.addText`)},e),!0}if(o.kind===`add-sibling-before`||o.kind===`add-sibling-after`){let e=(0,a.generateRandomId)(6);return this._executeCreateAndEdit(n.AddMindMapSiblingOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:this._activeNodeId,placement:o.placement??(o.kind===`add-sibling-before`?`before`:`after`),siblingNodeId:e,connectorId:(0,a.generateRandomId)(6),text:this._localeService.t(`boards-mind-ui.panel.addText`)},e),!0}return!0}_isControlEvent(e){if(!this._object||(e.button??0)!==0)return!1;let t=this._stateService.getState(),n=cn(e,{panOffset:t.viewportPanOffset,zoomRatio:t.zoomRatio});return!!this._object.getHitControl(n,e.deviceType)}_consumeControlEvent(e,t){var n,r;t.stopPropagation(),(n=e.preventDefault)==null||n.call(e),(r=e.stopPropagation)==null||r.call(e)}_executeAndLayout(e,t){let r=this._activeScopeId;this._undoRedoGroupService.run(t.unitId,()=>{this._commandService.syncExecuteCommand(e,t)&&r&&(this._commandService.syncExecuteCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:r}),this._syncControls())})}_executeCreateAndEdit(e,t,n){let i={unitId:t.unitId,subUnitId:t.subUnitId},a=this._commandService.executeCommand(e,t);Promise.resolve(a).then(e=>{e&&(this._syncControls(),this._elementStateService.selectElements(i,[n],n),this._boardTextEditingService.ignoreExternalFocusChanges(),this._boardTextEditingService.setEditing({...i,shapeId:n,shapeKey:(0,r.getBoardElementRenderObjectKey)(i.unitId,n),visible:!0}))})}};ln=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,(0,a.Inject)(r.IBoardUIStateService)),S(4,a.ICommandService),S(5,(0,a.Inject)(r.BoardTextEditingService)),S(6,(0,a.Inject)(a.LocaleService)),S(7,(0,a.Inject)(Xt)),S(8,(0,a.Inject)(c.UndoRedoGroupService))],ln);let un=`FOCUSING_MIND_MAP_TEXT_EDITOR`,J=class extends a.RxDisposable{constructor(e,t){super(),this._commandService=e,this._shortcutService=t,this._init()}_init(){this.disposeWithMe(this._shortcutService.registerShortcut(this._createQuoteShortcut()))}_createQuoteShortcut(){return{id:l.SHAPE_TEXT_EDITOR_QUOTE_COMMAND_ID,binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,priority:1e3,preconditions:e=>e.getContextValue(`FOCUSING_MIND_MAP_TEXT_EDITOR`)&&this._commandService.hasCommand(l.SHAPE_TEXT_EDITOR_QUOTE_COMMAND_ID)}}};J=C([S(0,a.ICommandService),S(1,c.IShortcutService)],J);let dn=[pt,mt,un],fn=class extends a.RxDisposable{constructor(e,t,n,r,i){super(),this._renderContext=e,this._boardElementService=t,this._elementStateService=n,this._textEditingService=r,this._contextService=i,x(this,`_isActive`,!1),this.disposeWithMe((0,a.toDisposable)(this._renderContext.activated$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(e=>{this._isActive=e,this._syncContext()}))),this.disposeWithMe((0,a.toDisposable)(this._elementStateService.state$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._syncContext()}))),this.disposeWithMe((0,a.toDisposable)(this._textEditingService.editingParams$.pipe((0,s.takeUntil)(this.dispose$)).subscribe(()=>{this._syncContext()}))),this._syncContext()}_syncContext(){var e,t;let r=this._elementStateService.getSnapshot(),i=this._textEditingService.getEditing(),a=i!=null&&i.visible?i.shapeId:r.activeEditingId,o=r.focusedId??r.selectedIds[0],s=r.context??{unitId:this._renderContext.unitId,subUnitId:this._renderContext.unit.getActivePageId()},c=this._isActive&&!!o&&r.selectedIds.length===1&&!a&&!r.isTransforming,l=this._isActive?this._boardElementService.getElementData(s.unitId,s.subUnitId):{};this._contextService.setContextValue(pt,c&&!!(0,n.getMindMapNodeMeta)((e=l[o])==null?void 0:e.element)),this._contextService.setContextValue(mt,this._isActive&&r.selectedIds.length===0&&!r.focusedId&&!a&&!r.isTransforming),this._contextService.setContextValue(un,!!a&&!!(0,n.getMindMapNodeMeta)((t=l[a])==null?void 0:t.element))}dispose(){this._resetContext(),super.dispose()}_resetContext(){dn.forEach(e=>this._contextService.setContextValue(e,!1))}};fn=C([S(1,(0,a.Inject)(t.IBoardElementService)),S(2,(0,a.Inject)(r.IBoardElementStateService)),S(3,(0,a.Inject)(r.BoardTextEditingService)),S(4,a.IContextService)],fn);var pn=class extends Yt{async _handlePointerDown(e,t,n){await this._insertMindMap(e,t,n)}};let mn={id:`board.operation.mind-map.open-panel`,type:a.CommandType.OPERATION,handler:(e,t)=>!!(t!=null&&t.unitId)&&!!t.subUnitId&&!!t.scopeId},Y=`board.mind-map.panel`,hn=[`structure`,`layout`,`importExport`];n.MIND_MAP_DEFAULT_LAYOUT.horizontalGap,n.MIND_MAP_DEFAULT_LAYOUT.siblingGap,n.MIND_MAP_DEFAULT_LAYOUT.branchGap;let gn=[{labelKey:`boards-mind-ui.panel.spacing.parentGap`,key:`horizontalGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.horizontalGap},{labelKey:`boards-mind-ui.panel.spacing.siblingGap`,key:`siblingGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.siblingGap},{labelKey:`boards-mind-ui.panel.spacing.branchGap`,key:`branchGap`,...n.MIND_MAP_LAYOUT_SPACING_LIMITS.branchGap}],_n=[{labelKey:`boards-mind-ui.panel.layout.right`,value:`right`},{labelKey:`boards-mind-ui.panel.layout.left`,value:`left`},{labelKey:`boards-mind-ui.panel.layout.both`,value:`both`}],vn=[{labelKey:`boards-mind-ui.panel.structureKind.mindmapHorizontal`,value:`mindmap-horizontal`},{labelKey:`boards-mind-ui.panel.structureKind.mindmapVertical`,value:`mindmap-vertical`},{labelKey:`boards-mind-ui.panel.structureKind.treeRight`,value:`tree-right`},{labelKey:`boards-mind-ui.panel.structureKind.treeLeft`,value:`tree-left`},{labelKey:`boards-mind-ui.panel.structureKind.treeAlternate`,value:`tree-alternate`},{labelKey:`boards-mind-ui.panel.structureKind.timelineHorizontal`,value:`timeline-horizontal`},{labelKey:`boards-mind-ui.panel.structureKind.timelineVertical`,value:`timeline-vertical`}],yn=[{labelKey:`boards-mind-ui.panel.branchLineType.curve`,value:`curve`},{labelKey:`boards-mind-ui.panel.branchLineType.roundedOrthogonal`,value:`rounded-orthogonal`},{labelKey:`boards-mind-ui.panel.branchLineType.orthogonal`,value:`orthogonal`}];function bn(e){let t=(e==null?void 0:e.structureKind)??n.MIND_MAP_DEFAULT_LAYOUT.structureKind;return{spacing:{horizontalGap:(e==null?void 0:e.horizontalGap)??n.MIND_MAP_DEFAULT_LAYOUT.horizontalGap,siblingGap:(e==null?void 0:e.siblingGap)??n.MIND_MAP_DEFAULT_LAYOUT.siblingGap,branchGap:(e==null?void 0:e.branchGap)??n.MIND_MAP_DEFAULT_LAYOUT.branchGap},direction:(e==null?void 0:e.direction)??n.MIND_MAP_DEFAULT_LAYOUT.direction,structureKind:t,branchLineType:(0,n.resolveMindMapBranchLineTypeForStructure)(t,e==null?void 0:e.branchLineType)}}async function xn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapLayoutOperation.id,t))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function Sn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapBranchLineTypeOperation.id,t))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function Cn(e,t){return await Promise.resolve(e.executeCommand(n.ChangeMindMapLayoutOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,...t.horizontalGap===void 0?{}:{horizontalGap:t.horizontalGap},...t.siblingGap===void 0?{}:{siblingGap:t.siblingGap},...t.branchGap===void 0?{}:{branchGap:t.branchGap}}))?(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0):!1}async function wn(e,t){return t.nodeId===t.targetNodeId||!await Promise.resolve(e.executeCommand(n.ReparentMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,targetNodeId:t.targetNodeId,referenceNodeId:t.targetNodeId,placement:t.placement}))?!1:(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0)}async function Tn(e,t){let r=t.text.trim();return!r||!await Promise.resolve(e.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,nodeId:t.nodeId,text:r}))?!1:(await Promise.resolve(e.executeCommand(n.LayoutMindMapOperation.id,{unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId})),!0)}async function En(e){var t;let n=(t=globalThis.navigator)==null?void 0:t.clipboard;return n!=null&&n.writeText?(await n.writeText(e),!0):!1}async function Dn(e,t,r=En){let i=await Promise.resolve(e.executeCommand(n.ExportMindMapOpmlOperation.id,t));if(typeof i!=`string`||!i)return!1;try{return await r(i)!==!1}catch{return!1}}async function On(e,t){return t.opml.trim()?(await e.executeCommand(n.ImportMindMapOpmlOperation.id,t)).success:!1}function kn(e,t){let n=`shapeData`in e.element?e.element.shapeData.shapeText:void 0;return(n==null?void 0:n.text)||t}function An(e,t,r=n.MIND_MAP_DEFAULT_NODE_TEXT){let i=Object.values(e).map(e=>{let r=(0,n.getMindMapNodeMeta)(e.element);return(r==null?void 0:r.structureScopeId)===t?{data:e,meta:r}:null}).filter(e=>!!e),a=/* @__PURE__ */ new Map;i.forEach(e=>{let t=e.meta.parentNodeId;a.set(t,[...a.get(t)??[],e])}),a.forEach(e=>{e.sort((e,t)=>(0,n.compareMindMapOrderKey)(e.meta.orderKey,t.meta.orderKey)||e.data.elementId.localeCompare(t.data.elementId))});let o=[],s=(e,t)=>{(a.get(e)??[]).forEach(e=>{o.push({nodeId:e.data.elementId,depth:t,text:kn(e.data,r)}),s(e.data.elementId,t+1)})};return s(null,0),o}function jn(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.text.toLowerCase().includes(n)):e}function Mn(e){return{paddingInlineStart:8+(Number.isFinite(e)&&e>0?e:0)*16}}function Nn(e){return/* @__PURE__ */ (0,p.jsx)(d.Segmented,{className:`univer-w-full univer-text-xs`,...e})}function X(e){return/* @__PURE__ */ (0,p.jsxs)(`section`,{className:`univer-py-4`,"data-board-mind-map-panel-section":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`h3`,{className:`univer-mb-3 univer-text-sm univer-font-semibold univer-text-gray-900 dark:!univer-text-gray-100`,children:e.title}),e.children]})}function Pn(e,i=`structure`){var o,l,u;let d=(0,c.useDependency)(a.ICommandService),p=(0,c.useDependency)(r.IBoardElementStateService),m=(0,c.useDependency)(t.IBoardElementService),h=(0,c.useDependency)(a.LocaleService),[,g]=(0,f.useReducer)(e=>e+1,0);(0,f.useEffect)(()=>{let t=(0,s.merge)(m.elementAdd$,m.elementUpdate$,m.elementRemove$).subscribe(t=>{t.some(t=>t.unitId===e.unitId&&t.subUnitId===e.subUnitId)&&g()});return()=>t.unsubscribe()},[m,e.unitId,e.subUnitId]);let _=m.getElementData(e.unitId,e.subUnitId),v=An(_,e.scopeId,h.t(`boards-mind-ui.panel.addText`)),y=(o=(0,n.getMindMapContainerMeta)((l=_[e.scopeId])==null?void 0:l.element))==null?void 0:o.layout,[b,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(``),{spacing:E,direction:D,structureKind:O,branchLineType:k}=bn(y),[A,j]=(0,f.useState)(null),[M,N]=(0,f.useState)(i),P=jn(v,b),F={unitId:e.unitId,subUnitId:e.subUnitId,scopeId:e.scopeId};return{commandService:d,elementStateService:p,localeService:h,query:b,setQuery:x,editingOutlineNode:S,setEditingOutlineNode:C,opmlText:w,setOpmlText:T,spacing:E,layoutDirection:D,structureKind:O,branchLineType:k,setDraggedOutlineNodeId:j,activeTab:M,setActiveTab:N,visibleOutlineItems:P,baseParams:F,tabItems:hn.map(e=>({label:h.t(`boards-mind-ui.panel.tab.${e}`),value:e})),selectedNode:e.nodeId?(u=_[e.nodeId])==null?void 0:u.element:void 0,branchLineItems:yn.filter(e=>e.value!==`curve`||(0,n.isMindMapPlainStructureKind)(O)),changeLayout:e=>xn(d,{...F,direction:e}),changeStructureKind:e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(e,k);return xn(d,{...F,structureKind:e,...t===k?null:{branchLineType:t}})},changeBranchLineType:e=>{let t=(0,n.resolveMindMapBranchLineTypeForStructure)(O,e);return Sn(d,{...F,branchLineType:t})},changeSpacing:(e,t)=>{let n={...E,[e]:t};return Cn(d,{...F,...n})},importOpml:()=>{On(d,{unitId:e.unitId,subUnitId:e.subUnitId,left:120,top:120,opml:w}).then(e=>{e&&T(``)})},exportOpml:()=>Dn(d,F),startRenameNode:(e,t)=>{C({nodeId:e,text:t})},commitRenameNode:()=>{S&&Tn(d,{...F,nodeId:S.nodeId,text:S.text}).then(e=>{e&&C(null)})},reorderNode:(e,t)=>{if(e.preventDefault(),!A||A===t)return;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY<n.top+n.height/2?`before`:`after`;j(null),wn(d,{...F,nodeId:A,targetNodeId:t,placement:r})}}}function Fn(e){let{elementStateService:t,localeService:n,query:r,setQuery:i,editingOutlineNode:a,setEditingOutlineNode:o,opmlText:s,setOpmlText:c,spacing:l,layoutDirection:u,structureKind:f,branchLineType:m,setDraggedOutlineNodeId:h,activeTab:g,setActiveTab:_,visibleOutlineItems:v,tabItems:y,branchLineItems:b,changeLayout:x,changeStructureKind:S,changeBranchLineType:C,changeSpacing:w,importOpml:T,exportOpml:E,startRenameNode:D,commitRenameNode:O,reorderNode:k}=Pn(e);return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-size-full univer-bg-gray-0 univer-text-sm univer-text-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-gray-200`,"data-board-mind-map-panel":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-py-3`,"data-board-mind-map-panel-tabs":`true`,children:/* @__PURE__ */ (0,p.jsx)(Nn,{items:y,value:g,onChange:e=>_(e)})}),g===`structure`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.structure`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{slot:/* @__PURE__ */ (0,p.jsx)(tt,{}),value:r,placeholder:n.t(`boards-mind-ui.panel.searchNodes`),className:(0,d.clsx)(`univer-mb-3 univer-w-full`,!1),onChange:i}),v.length?/* @__PURE__ */ (0,p.jsx)(`ol`,{className:`univer-space-y-1`,children:v.map(r=>/* @__PURE__ */ (0,p.jsx)(`li`,{draggable:!0,className:`univer-flex univer-items-center univer-gap-1 univer-truncate univer-rounded univer-py-1 univer-text-left univer-text-gray-800`,style:Mn(r.depth),onDragStart:e=>{var t;h(r.nodeId),(t=e.dataTransfer)==null||t.setData(`text/plain`,r.nodeId),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`)},onDragOver:e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`)},onDrop:e=>k(e,r.nodeId),onDragEnd:()=>h(null),children:(a==null?void 0:a.nodeId)===r.nodeId?/* @__PURE__ */ (0,p.jsxs)(`div`,{className:(0,d.clsx)(`univer-flex univer-min-w-0 univer-flex-1 univer-gap-2`,`univer-items-center`),children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{autoFocus:!0,size:`small`,className:void 0,value:a.text,onChange:e=>o({nodeId:r.nodeId,text:e}),onKeyDown:e=>{e.key===`Enter`&&O(),e.key===`Escape`&&o(null)}}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`primary`,disabled:!a.text.trim(),onClick:O,children:n.t(`boards-mind-ui.panel.rename`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`default`,onClick:()=>o(null),children:n.t(`boards-mind-ui.panel.cancel`)})]}):/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`small`,variant:`ghost`,className:(0,d.clsx)(`univer-min-w-0 univer-flex-1 univer-justify-start univer-truncate univer-text-left`,!1),onClick:()=>t.selectElements({unitId:e.unitId,subUnitId:e.subUnitId},[r.nodeId],r.nodeId),children:r.text}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:(0,d.clsx)(`univer-text-gray-500`,`univer-text-xs`),size:`small`,variant:`default`,onClick:()=>D(r.nodeId,r.text),children:n.t(`boards-mind-ui.panel.rename`)})]})},r.nodeId))}):/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-text-xs univer-text-gray-400 dark:!univer-text-gray-500`,"data-board-mind-map-panel-empty-state":`true`,children:n.t(`boards-mind-ui.panel.emptyNodes`)})]})}),g===`layout`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.layout`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-space-y-3`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(d.Select,{className:`univer-w-full univer-min-w-0`,"aria-label":n.t(`boards-mind-ui.panel.tab.layout`),options:vn.map(e=>({label:n.t(e.labelKey),value:e.value})),value:f,onChange:e=>S(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(Nn,{items:_n.map(e=>({label:n.t(e.labelKey),value:e.value})),value:u,onChange:e=>x(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(Nn,{items:b.map(e=>({label:n.t(e.labelKey),value:e.value})),value:m,onChange:e=>C(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-space-y-2`,children:gn.map(({labelKey:e,key:t,min:r,max:i})=>/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-xs univer-text-gray-600`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-w-20 univer-shrink-0`,children:n.t(e)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{controls:!0,inputClassName:void 0,min:r,max:i,step:4,value:l[t],precision:0,className:`univer-w-24`,onChange:e=>w(t,Number(e??r))})]},t))})]})}),g===`importExport`&&/* @__PURE__ */ (0,p.jsx)(X,{title:n.t(`boards-mind-ui.panel.tab.importExport`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Textarea,{className:(0,d.clsx)(`univer-h-28 univer-resize-none`,`univer-text-xs`),placeholder:n.t(`boards-mind-ui.panel.pasteOPML`),value:s,onValueChange:c}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`primary`,disabled:!s.trim(),onClick:T,children:n.t(`boards-mind-ui.panel.importOPML`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:void 0,size:`small`,variant:`default`,onClick:E,children:n.t(`boards-mind-ui.panel.exportOPML`)})]})]})})]})}let In=class extends a.Disposable{constructor(e,t,n){super(),this._commandService=e,this._localeService=t,this._sidebarService=n,x(this,`_sidebarDisposable`,null),this.disposeWithMe(this._commandService.registerCommand(mn)),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==mn.id)return;let t=e.params;t&&`unitId`in t&&typeof t.unitId==`string`&&`subUnitId`in t&&typeof t.subUnitId==`string`&&`scopeId`in t&&typeof t.scopeId==`string`&&this.open({unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,nodeId:`nodeId`in t&&typeof t.nodeId==`string`?t.nodeId:void 0})}))}dispose(){var e;(e=this._sidebarDisposable)==null||e.dispose(),this._sidebarDisposable=null,super.dispose()}open(e){var t;let n={label:Y,...e},r={id:Y,layout:`canvas`,header:{title:this._localeService.t(`boards-mind-ui.panel.title`)},width:388,children:n,onClose:()=>{this._sidebarDisposable=null}};(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=this._sidebarService.open(r)}};In=C([S(0,a.ICommandService),S(1,(0,a.Inject)(a.LocaleService)),S(2,(0,a.Inject)(c.ISidebarService))],In);function Ln(e){let t=(0,c.useDependency)(a.ICommandService),n=e.popup.extraProps;return n?/* @__PURE__ */ (0,p.jsx)(l.MobileShapeMenu,{shapeRef:{hostType:a.UniverInstanceType.UNIVER_BOARD,unitId:n.unitId,subUnitId:n.subUnitId,shapeId:n.elementId},onText:()=>Et(t,`edit-text`),onStyle:()=>t.executeCommand(mn.id,{unitId:n.unitId,subUnitId:n.subUnitId,scopeId:n.scopeId,nodeId:n.elementId}),onDelete:()=>Et(t,`delete`)}):null}function Rn(e){var t,r,i,o,s;let m=(0,c.useDependency)(a.ICommandService),h=(0,c.useDependency)(a.LocaleService),g=(0,c.useDependency)(c.IFontService),_=(0,c.useObservable)(g.fonts$,g.getFonts()),[v,y]=(0,f.useState)(null),b=(0,l.getTextStyle)(e.shapeData),x=b.ff??u.ShapeDefaultConfig.shapeText.fontFamily,S=b.fs??u.ShapeDefaultConfig.shapeText.fontSize;function C(t){return m.executeCommand(n.UpdateMindMapNodeOperation.id,{unitId:e.unitId,subUnitId:e.subUnitId,nodeId:e.nodeId,...t})}let w=[{key:`fill`,value:((t=e.shapeData.fill)==null?void 0:t.color)??u.ShapeDefaultConfig.fill},{key:`stroke`,value:((r=e.shapeData.stroke)==null?void 0:r.color)??u.ShapeDefaultConfig.stroke},{key:`fontColor`,value:((i=b.cl)==null?void 0:i.rgb)??u.ShapeDefaultConfig.shapeText.color}];if(v){var T;return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-w-full`,onClick:()=>y(null),size:`middle`,children:h.t(`boards-mind-ui.panel.cancel`)}),v===`fontFamily`?_==null?void 0:_.map(e=>/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-w-full`,"aria-pressed":x===e.value,variant:x===e.value?`primary`:`default`,onClick:async()=>{await C({textStyle:{fontFamily:e.value}}),y(null)},size:`middle`,children:e.label},e.value)):/* @__PURE__ */ (0,p.jsx)(d.MobileColorPresets,{value:(T=w.find(({key:e})=>e===v))==null?void 0:T.value,onSelect:async e=>{v===`fill`?await C({fillColor:e}):v===`stroke`?await C({strokeColor:e}):await C({textStyle:{color:e}}),y(null)}})]})}let E=[{key:`bold`,active:b.bl===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(Ce,{})},{key:`italic`,active:b.it===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(De,{})},{key:`underline`,active:((o=b.ul)==null?void 0:o.s)===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(st,{})},{key:`strikethrough`,active:((s=b.st)==null?void 0:s.s)===a.BooleanNumber.TRUE,icon:/* @__PURE__ */ (0,p.jsx)(at,{})}];return/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-grid univer-grid-cols-4 univer-gap-2`,children:E.map(({key:e,active:t,icon:n})=>/* @__PURE__ */ (0,p.jsx)(d.Button,{"aria-label":h.t(`boards-mind-ui.panel.nodeStyle.${e}`),"aria-pressed":t,variant:t?`primary`:`default`,onClick:()=>C({textStyle:{[e]:!t}}),size:`middle`,children:n},e))}),/* @__PURE__ */ (0,p.jsxs)(d.Button,{className:`univer-w-full univer-justify-between`,onClick:()=>y(`fontFamily`),size:`middle`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.panel.nodeStyle.fontFamily`)}),/* @__PURE__ */ (0,p.jsx)(`span`,{children:x})]}),/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-4`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.panel.nodeStyle.fontSize`)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{className:`univer-w-32`,controls:!1,min:1,value:S,onChange:e=>{if(e!=null)return C({textStyle:{fontSize:e}})},size:`small`})]}),w.map(({key:e,value:t})=>/* @__PURE__ */ (0,p.jsxs)(d.Button,{className:`univer-w-full univer-justify-between`,onClick:()=>y(e),size:`middle`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{children:h.t(`boards-mind-ui.toolbar.action.${e}`)}),/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-size-6 univer-rounded univer-border univer-border-solid univer-border-gray-200`,style:{backgroundColor:t}})]},e))]})}function zn(e){return/* @__PURE__ */ (0,p.jsx)(`div`,{className:(0,d.clsx)(`univer-grid univer-w-full univer-gap-2`,e.items.length===4?`univer-grid-cols-[repeat(4,minmax(min-content,1fr))] max-[359px]:univer-grid-cols-2`:`univer-grid-cols-3`),children:e.items.map(t=>/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-min-w-0 univer-whitespace-normal univer-px-2`,variant:e.value===t.value?`primary`:`default`,"aria-pressed":e.value===t.value,onClick:()=>e.onChange(t.value),size:`middle`,children:/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-min-w-0 univer-break-words`,children:t.label})},t.value))})}function Bn(e){let{commandService:r,elementStateService:i,localeService:a,query:o,setQuery:s,editingOutlineNode:c,setEditingOutlineNode:l,opmlText:u,setOpmlText:f,spacing:m,layoutDirection:h,structureKind:g,branchLineType:_,activeTab:v,setActiveTab:y,visibleOutlineItems:b,baseParams:x,tabItems:S,selectedNode:C,branchLineItems:w,changeLayout:T,changeStructureKind:E,changeBranchLineType:D,changeSpacing:O,importOpml:k,startRenameNode:A,commitRenameNode:j}=Pn(e,e.nodeId?`style`:`structure`);return(C==null?void 0:C.type)===t.BoardElementType.Shape&&S.unshift({label:a.t(`boards-mind-ui.panel.nodeStyle.style`),value:`style`}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-size-full univer-bg-gray-0 univer-text-sm univer-text-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-gray-200`,"data-board-mind-map-panel":`true`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-py-3`,"data-board-mind-map-panel-tabs":`true`,children:/* @__PURE__ */ (0,p.jsx)(d.Segmented,{className:`univer-w-full [&_button]:univer-whitespace-normal [&_button]:univer-break-words [&_button]:univer-px-1`,items:S,value:v,onChange:e=>y(e)})}),v===`style`&&(C==null?void 0:C.type)===t.BoardElementType.Shape&&/* @__PURE__ */ (0,p.jsx)(Rn,{unitId:e.unitId,subUnitId:e.subUnitId,nodeId:C.id,shapeData:C.shapeData}),v===`structure`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.structure`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{slot:/* @__PURE__ */ (0,p.jsx)(tt,{}),value:o,placeholder:a.t(`boards-mind-ui.panel.searchNodes`),className:(0,d.clsx)(`univer-mb-3 univer-w-full`,``),onChange:s,size:`small`}),b.length?/* @__PURE__ */ (0,p.jsx)(`ol`,{className:`univer-space-y-1`,children:b.map(t=>/* @__PURE__ */ (0,p.jsx)(`li`,{className:`univer-flex univer-items-center univer-gap-1 univer-truncate univer-rounded univer-py-1 univer-text-left univer-text-gray-800`,style:Mn(t.depth),children:(c==null?void 0:c.nodeId)===t.nodeId?/* @__PURE__ */ (0,p.jsxs)(`div`,{className:(0,d.clsx)(`univer-flex univer-min-w-0 univer-flex-1 univer-gap-2`,`univer-flex-wrap`),children:[/* @__PURE__ */ (0,p.jsx)(d.Input,{autoFocus:!1,size:`small`,className:`univer-w-full`,value:c.text,onChange:e=>l({nodeId:t.nodeId,text:e}),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&l(null)}}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`primary`,disabled:!c.text.trim(),onClick:j,children:a.t(`boards-mind-ui.panel.rename`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`default`,onClick:()=>l(null),children:a.t(`boards-mind-ui.panel.cancel`)})]}):/* @__PURE__ */ (0,p.jsxs)(p.Fragment,{children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{size:`middle`,variant:`ghost`,className:(0,d.clsx)(`univer-min-w-0 univer-flex-1 univer-justify-start univer-truncate univer-text-left`,``),onClick:()=>i.selectElements({unitId:e.unitId,subUnitId:e.subUnitId},[t.nodeId],t.nodeId),children:t.text}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:(0,d.clsx)(`univer-text-gray-500`,`univer-px-3`),size:`middle`,variant:`default`,onClick:()=>A(t.nodeId,t.text),children:a.t(`boards-mind-ui.panel.rename`)})]})},t.nodeId))}):/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-text-xs univer-text-gray-400 dark:!univer-text-gray-500`,"data-board-mind-map-panel-empty-state":`true`,children:a.t(`boards-mind-ui.panel.emptyNodes`)})]})}),v===`layout`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.layout`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-space-y-3`,children:[/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(zn,{items:vn.map(e=>({label:a.t(e.labelKey),value:e.value})),value:g,onChange:e=>E(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(zn,{items:_n.map(e=>({label:a.t(e.labelKey),value:e.value})),value:h,onChange:e=>T(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:/* @__PURE__ */ (0,p.jsx)(zn,{items:w.map(e=>({label:a.t(e.labelKey),value:e.value})),value:_,onChange:e=>D(e)})}),/* @__PURE__ */ (0,p.jsx)(`div`,{className:`univer-space-y-2`,children:gn.map(({labelKey:e,key:t,min:n,max:r})=>/* @__PURE__ */ (0,p.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-xs univer-text-gray-600`,children:[/* @__PURE__ */ (0,p.jsx)(`span`,{className:`univer-flex-1 univer-text-sm`,children:a.t(e)}),/* @__PURE__ */ (0,p.jsx)(d.InputNumber,{controls:!1,min:n,max:r,step:4,value:m[t],precision:0,className:`univer-w-32`,onChange:e=>O(t,Number(e??n)),size:`small`})]},t))})]})}),v===`importExport`&&/* @__PURE__ */ (0,p.jsx)(X,{title:a.t(`boards-mind-ui.panel.tab.importExport`),children:/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Textarea,{className:(0,d.clsx)(`univer-h-28 univer-resize-none`,``),placeholder:a.t(`boards-mind-ui.panel.pasteOPML`),value:u,onValueChange:f,size:`small`}),/* @__PURE__ */ (0,p.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`primary`,disabled:!u.trim(),onClick:k,children:a.t(`boards-mind-ui.panel.importOPML`)}),/* @__PURE__ */ (0,p.jsx)(d.Button,{className:`univer-flex-1`,size:`middle`,variant:`default`,onClick:async()=>{let e=await r.executeCommand(n.ExportMindMapOpmlOperation.id,x);e!==!1&&f(e)},children:a.t(`boards-mind-ui.panel.exportOPML`)})]})]})})]})}let Vn=class extends a.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(ut,ft)),this.disposeWithMe(this._componentManager.register(Tt,Ln)),this.disposeWithMe(this._componentManager.register(Y,Bn))}};Vn=C([S(0,(0,a.Inject)(c.ComponentManager))],Vn);let Hn=class extends a.Disposable{constructor(e,t,n){super(),this._commandService=e,this._localeService=t,this._sidebarService=n,x(this,`_sidebarDisposable`,null),this.disposeWithMe(this._commandService.registerCommand(mn)),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==mn.id)return;let t=e.params;t&&`unitId`in t&&typeof t.unitId==`string`&&`subUnitId`in t&&typeof t.subUnitId==`string`&&`scopeId`in t&&typeof t.scopeId==`string`&&this.open({unitId:t.unitId,subUnitId:t.subUnitId,scopeId:t.scopeId,nodeId:`nodeId`in t&&typeof t.nodeId==`string`?t.nodeId:void 0})}))}dispose(){var e;(e=this._sidebarDisposable)==null||e.dispose(),this._sidebarDisposable=null,super.dispose()}open(e){var t;let n={label:Y,...e};(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=this._sidebarService.open({id:Y,header:{title:this._localeService.t(`boards-mind-ui.panel.title`)},width:388,children:n,onClose:()=>{this._sidebarDisposable=null}})}};Hn=C([S(0,a.ICommandService),S(1,(0,a.Inject)(a.LocaleService)),S(2,(0,a.Inject)(c.ISidebarService))],Hn);let Un=class extends a.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(ut,ft)),this.disposeWithMe(this._componentManager.register(Tt,zt)),this.disposeWithMe(this._componentManager.register(Y,Fn))}};Un=C([S(0,(0,a.Inject)(c.ComponentManager))],Un);let Z=class{constructor(e,t,n){this._stateService=e,this._insertStateService=t,this._renderManagerService=n}beginMindMapMode(e){var n,i;let a=(n=this._renderManagerService.getRenderUnitById(e.unitId))==null||(i=n.getInjector)==null?void 0:i.call(n),o=(a==null?void 0:a.get(r.IBoardUIStateService))??this._stateService;return((a==null?void 0:a.get(K))??this._insertStateService).setTemplate({rootText:e.rootText,structureKind:e.structureKind,branchLineType:e.branchLineType,children:e.children,blueprint:e.blueprint}),o.setShapeSidebarOpen(!1),o.clearPendingInsert(),o.setActiveTool(t.BoardToolType.MindMap),o.setPendingInsert({type:t.BoardToolType.MindMap}),!0}};Z=C([S(0,r.IBoardUIStateService),S(1,(0,a.Inject)(K)),S(2,o.IRenderManagerService)],Z);let Wn=`UNIVER_BOARDS_MIND_UI_PLUGIN`,Gn=[V],Kn=[fn],Q=class extends a.Plugin{constructor(e=_,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{...i}=(0,a.merge)({},_,this._config);this._configService.setConfig(g,i)}onStarting(){r.UniverBoardsUIPlugin.registerRuntimeScopedDependencies(this._injector,[[K],[Xt]]),this._getDependencies().forEach(e=>this._injector.add(e));let e=this._injector.get(Z),n=this._injector.get(t.IBoardMindMapAdapterService);this.disposeWithMe(n.registerAdapter(e)),this.disposeWithMe(this._injector.get(U)),this.disposeWithMe(this._injector.get(J)),this.disposeWithMe(this._injector.get(Hn)),this.disposeWithMe(this._injector.get(Un)),this._enableMindMapToolbarTool()}_getDependencies(){return[[K],[Xt],[Z],[U],[J],[Hn],[Un]]}_getRenderModules(){return[Gn,Kn,[Yt],[ln],[Vt],[z],[w],[$t]]}onReady(){this._getRenderModules().forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_BOARD,e))})}_enableMindMapToolbarTool(){var e,n;let i=this._getBoardsUIConfig();this._configService.setConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY,{...i,toolbar:{...i.toolbar,tools:{...(e=i.toolbar)==null?void 0:e.tools,[t.BoardToolType.MindMap]:qn((n=i.toolbar)==null||(n=n.tools)==null?void 0:n[t.BoardToolType.MindMap])}}})}_getBoardsUIConfig(){return this._configService.getConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY)??{}}};x(Q,`pluginName`,Wn),x(Q,`packageName`,m),x(Q,`version`,h),x(Q,`type`,a.UniverInstanceType.UNIVER_BOARD),Q=C([(0,a.DependentOn)(i.UniverLicensePlugin,o.UniverRenderEnginePlugin,t.UniverBoardsPlugin,n.UniverBoardsMindPlugin,r.UniverBoardsUIPlugin),S(1,(0,a.Inject)(a.Injector)),S(2,a.IConfigService),S(3,o.IRenderManagerService)],Q);function qn(e){return e===!1?!1:typeof e!=`object`||{...e,enabled:e.enabled??!0}}let $=class extends a.Plugin{constructor(e=_,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{...i}=(0,a.merge)({},_,this._config);this._configService.setConfig(g,i)}onStarting(){let e=[[K],[Xt]];r.UniverBoardsMobileUIPlugin.registerRuntimeScopedDependencies(this._injector,e),[...e,[Z],[U],[J],[In],[Vn]].forEach(e=>this._injector.add(e)),this.disposeWithMe(this._injector.get(t.IBoardMindMapAdapterService).registerAdapter(this._injector.get(Z))),this.disposeWithMe(this._injector.get(U)),this.disposeWithMe(this._injector.get(J)),this.disposeWithMe(this._injector.get(In)),this.disposeWithMe(this._injector.get(Vn)),this._enableMindMapToolbarTool()}onReady(){[[V],[fn],[Yt,{useClass:pn}],[ln],[Vt],[z],[w],[$t]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_BOARD,e))})}_enableMindMapToolbarTool(){var e,n;let i=this._getBoardsUIConfig();this._configService.setConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY,{...i,toolbar:{...i.toolbar,tools:{...(e=i.toolbar)==null?void 0:e.tools,[t.BoardToolType.MindMap]:Jn((n=i.toolbar)==null||(n=n.tools)==null?void 0:n[t.BoardToolType.MindMap])}}})}_getBoardsUIConfig(){return this._configService.getConfig(r.BOARDS_UI_PLUGIN_CONFIG_KEY)??{}}};x($,`pluginName`,Wn),x($,`packageName`,m),x($,`version`,h),x($,`type`,a.UniverInstanceType.UNIVER_BOARD),$=C([(0,a.DependentOn)(i.UniverLicensePlugin,o.UniverRenderEnginePlugin,t.UniverBoardsPlugin,n.UniverBoardsMindPlugin,r.UniverBoardsMobileUIPlugin),S(1,(0,a.Inject)(a.Injector)),S(2,a.IConfigService),S(3,o.IRenderManagerService)],$);function Jn(e){return e===!1?!1:typeof e!=`object`||{...e,enabled:e.enabled??!0}}Object.defineProperty(e,"UniverBoardsMindMobileUIPlugin",{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,"UniverBoardsMindUIPlugin",{enumerable:!0,get:function(){return Q}})});