@inkeep/open-knowledge 0.86.19-beta.0 → 0.86.19-beta.1

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.
Files changed (87) hide show
  1. package/dist/THIRD_PARTY_NOTICES.md +2 -2
  2. package/dist/cli.mjs +6 -6
  3. package/dist/constants-DTpS5DPL.mjs +1 -0
  4. package/dist/{dist-CJAnJkM1.mjs → dist-DRgSOIS6.mjs} +343 -343
  5. package/dist/{dist-0qA3xZU8.mjs → dist-DyVcFCkj.mjs} +1 -1
  6. package/dist/index.mjs +193 -193
  7. package/dist/{init-CxjDh4Sj.mjs → init-Cc3pxAas.mjs} +2 -2
  8. package/dist/init-rFslisPX.mjs +1 -0
  9. package/dist/{launch-json-removal-CAo7KXRA.mjs → launch-json-removal-Ca30Nixh.mjs} +1 -1
  10. package/dist/{loader-CLULyV6s.mjs → loader-BwPvEjuE.mjs} +1 -1
  11. package/dist/loader-Cy9oZb72.mjs +1 -0
  12. package/dist/{open-browser-DhYyRIyx.mjs → open-browser-CFW5reH2.mjs} +1 -1
  13. package/dist/{preview-C1ZMdegn.mjs → preview-BKERSD2q.mjs} +1 -1
  14. package/dist/preview-CJewZ-WB.mjs +1 -0
  15. package/dist/public/assets/{AccountSection-Db-4WgdI.js → AccountSection-DlWsbV8D.js} +1 -1
  16. package/dist/public/assets/{ActivityModeContent-B4BvALD6.js → ActivityModeContent-DkGHz9Ku.js} +1 -1
  17. package/dist/public/assets/{AddPropertiesButton-C9ng1KxF.js → AddPropertiesButton-D__sehWQ.js} +1 -1
  18. package/dist/public/assets/{AgentDiffPane-C-azBWgl.js → AgentDiffPane-xuZ1KudZ.js} +1 -1
  19. package/dist/public/assets/{AttachmentsSection-CJzCD8PN.js → AttachmentsSection-CHLjnxc0.js} +1 -1
  20. package/dist/public/assets/{CodeMirrorPropInput-BFJGamim.js → CodeMirrorPropInput-BpHUFt_h.js} +1 -1
  21. package/dist/public/assets/{ContentRulesSection-C225sCLc.js → ContentRulesSection-wbtHcBqr.js} +1 -1
  22. package/dist/public/assets/{DocumentContext-BUYnTCUo.js → DocumentContext-CQ2e0uie.js} +1 -1
  23. package/dist/public/assets/{EditorModeToggle-Bgl8dWUm.js → EditorModeToggle-B_E4wnhm.js} +1 -1
  24. package/dist/public/assets/{ExcalidrawDocEditor-DZZySi2f.js → ExcalidrawDocEditor-BcoRuAVp.js} +1 -1
  25. package/dist/public/assets/FeedbackForm-DhJSsu3n.js +1 -0
  26. package/dist/public/assets/{ImportSkillDialog-BNBOZDBw.js → ImportSkillDialog-lBL0HNJp.js} +1 -1
  27. package/dist/public/assets/{LinkPreviewsSection-CWS-RZFT.js → LinkPreviewsSection-CULpqlH7.js} +1 -1
  28. package/dist/public/assets/{LintConfigEditor-czXbBIwV.js → LintConfigEditor-6YyaXnFA.js} +1 -1
  29. package/dist/public/assets/{LintingSection-CJEcNaSa.js → LintingSection-DSwALvf4.js} +1 -1
  30. package/dist/public/assets/{ManagedArtifactProperties-D2pUQ39s.js → ManagedArtifactProperties-vvyx0y7Q.js} +1 -1
  31. package/dist/public/assets/ManagedArtifactProperties-wzj7pm-b.js +1 -0
  32. package/dist/public/assets/{Mermaid-Dqzqybsn.js → Mermaid-DqNhHNi1.js} +2 -2
  33. package/dist/public/assets/{MermaidDocEditor-CipeVQ06.js → MermaidDocEditor-BqqrJSxz.js} +1 -1
  34. package/dist/public/assets/{NetworkAccessSection-BZie0pu4.js → NetworkAccessSection-CJ-k8kEB.js} +1 -1
  35. package/dist/public/assets/{PropertyDisplayRow-C50F3rfZ.js → PropertyDisplayRow-Cm34goFj.js} +1 -1
  36. package/dist/public/assets/{PublishToGitHubDialog-3kv_jZ90.js → PublishToGitHubDialog-jx0Tzybl.js} +1 -1
  37. package/dist/public/assets/{SchemaConfigEditor-DpWvMeFj.js → SchemaConfigEditor-co1_VbGJ.js} +1 -1
  38. package/dist/public/assets/{SearchSection-BA_eSTo2.js → SearchSection-CU6mVIBD.js} +1 -1
  39. package/dist/public/assets/{SessionsHost-B6L9hsyq.js → SessionsHost-Ve1-rpr4.js} +2 -2
  40. package/dist/public/assets/{SettingsDialogBody-_FWM1V0h.js → SettingsDialogBody-Du3F7eab.js} +2 -2
  41. package/dist/public/assets/{ShareReceiveMissDialog-BvixXEWy.js → ShareReceiveMissDialog-Bsh7llP0.js} +1 -1
  42. package/dist/public/assets/{SkillToolbarControls-wYLMvS06.js → SkillToolbarControls-Dg0uH9dc.js} +1 -1
  43. package/dist/public/assets/{SourceEditor-DsmPCgpV.js → SourceEditor-BxraIyxO.js} +1 -1
  44. package/dist/public/assets/{SyncSection-D0wC81Eo.js → SyncSection-CI62AsGJ.js} +1 -1
  45. package/dist/public/assets/{SyncStatusBadge-DJaDDTcF.js → SyncStatusBadge--DiNAARL.js} +1 -1
  46. package/dist/public/assets/{TerminalSection-CUxI1JdU.js → TerminalSection-BWcfGvEV.js} +1 -1
  47. package/dist/public/assets/{TerminalWindowApp-BsEn6TK6.js → TerminalWindowApp-BXHW_7B9.js} +1 -1
  48. package/dist/public/assets/{TextDocEditor-ByetU4zg.js → TextDocEditor-C8zsOMpH.js} +1 -1
  49. package/dist/public/assets/{ThreadView-BCVnNzxB.js → ThreadView-CjKcF5Bj.js} +1 -1
  50. package/dist/public/assets/{TimelineDiffPane-CH-pD5Sk.js → TimelineDiffPane-BScs4tYQ.js} +1 -1
  51. package/dist/public/assets/{client-version-B0BVPYqs.js → client-version-Dyx1KpjP.js} +1 -1
  52. package/dist/public/assets/{comment-chips-BR3RJ-P9.js → comment-chips-BTYU41zd.js} +1 -1
  53. package/dist/public/assets/{config-provider-C1TYis8u.js → config-provider-Bu33ODD8.js} +1 -1
  54. package/dist/public/assets/{dist-BrKroYq_.js → dist-DjMGDcCv.js} +2 -2
  55. package/dist/public/assets/{doc-undo-manager-BhJBIikK.js → doc-undo-manager-CPZo2IhT.js} +1 -1
  56. package/dist/public/assets/{index-C63FEo_3.js → index-DQZmjexO.js} +7 -7
  57. package/dist/public/assets/{lint-plugins-CyrpkEAz.js → lint-plugins-Cv7WvUlN.js} +1 -1
  58. package/dist/public/assets/{pending-receive-nav-store-Bn9-4oY8.js → pending-receive-nav-store-6bXbTZhv.js} +1 -1
  59. package/dist/public/assets/{preferred-session-events-BiQR61Di.js → preferred-session-events-BytmLBUB.js} +1 -1
  60. package/dist/public/assets/{progress-BI8Awi9X.js → progress-Ba4KJbjQ.js} +1 -1
  61. package/dist/public/assets/{selection-context-BUX-2esB.js → selection-context-BdkqiHSg.js} +1 -1
  62. package/dist/public/assets/{src-Bq7nacsU.js → src-BKxD4aGX.js} +1 -1
  63. package/dist/public/assets/{telemetry-impl-C6cyjlPT.js → telemetry-impl-lt4HgP_f.js} +1 -1
  64. package/dist/public/assets/{telemetry-startup-Bnj7oEna.js → telemetry-startup-COAksO_l.js} +1 -1
  65. package/dist/public/assets/{typing-burst-detector-CGqFLcwn.js → typing-burst-detector-Ceucd7lf.js} +1 -1
  66. package/dist/public/assets/{use-activity-panel-DoIsdYpD.js → use-activity-panel-ClZw0uAV.js} +1 -1
  67. package/dist/public/assets/{use-open-skill-BaCDrg6G.js → use-open-skill-BufHQt2J.js} +1 -1
  68. package/dist/public/assets/{use-terminal-enabled-B9lsLlqu.js → use-terminal-enabled-kUXuNyA3.js} +1 -1
  69. package/dist/public/assets/{use-timeline-entry-diff-BynykbHw.js → use-timeline-entry-diff-DIXfdlmY.js} +1 -1
  70. package/dist/public/index.html +20 -20
  71. package/dist/{registry-probes-X4XCh3Vc.mjs → registry-probes-BzVs0MZl.mjs} +1 -1
  72. package/dist/{removal-file-path-Cjlpt0R6.mjs → removal-file-path-DjVZJivF.mjs} +1 -1
  73. package/dist/{repair-launch-json-Ch5Q9KdX.mjs → repair-launch-json-DaJc8F0u.mjs} +1 -1
  74. package/dist/{repair-mcp-configs-Bbuj1v7c.mjs → repair-mcp-configs-GI1XgsXr.mjs} +1 -1
  75. package/dist/{src-D_uBQkDY.mjs → src-CiJt-PQj.mjs} +1 -1
  76. package/dist/src-Dt5ff2eL.mjs +1 -0
  77. package/dist/{start-C6mYvDlP.mjs → start-CNmN3UB5.mjs} +3 -3
  78. package/dist/start-CTAc0UYC.mjs +1 -0
  79. package/package.json +4 -4
  80. package/dist/constants-BdwbBEFe.mjs +0 -1
  81. package/dist/init-BKES99UU.mjs +0 -1
  82. package/dist/loader-BA0np0VD.mjs +0 -1
  83. package/dist/preview-CRJMWckI.mjs +0 -1
  84. package/dist/public/assets/FeedbackForm-BS2cpPVN.js +0 -1
  85. package/dist/public/assets/ManagedArtifactProperties-BQzCwg8H.js +0 -1
  86. package/dist/src-BpUokUm6.mjs +0 -1
  87. package/dist/start-B4WcTecl.mjs +0 -1
@@ -156,6 +156,6 @@ import{MESSAGE_OPS as e,PARTICIPANT_TYPES as t}from"./dist-BUMFJcXg.js";function
156
156
  .mw-zoom-btn { width: 38px; height: 38px; border-radius: 9px; }
157
157
  .mw-zoom-btn svg { width: 17px; height: 17px; }
158
158
  }
159
- `,E=!1,D=0;function O(e){return(e.innerHTML??``).replace(/<br\s*\/?>/gi,`<br/>`).replace(/&nbsp;/gi,` `).trim()}function k(e){return(e.innerHTML??``).replace(/<br\s*\/?>/gi,`<br/>`)}function A(e){let t=window.getSelection();if(!t?.anchorNode||!e.contains(t.anchorNode))return-1;let n=document.createRange();return n.selectNodeContents(e),n.setEnd(t.anchorNode,t.anchorOffset),n.toString().length}function j(e,t){let n=window.getSelection();if(!n)return;let r=document.createRange(),i=Math.max(0,t),a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=a.nextNode();for(;o;){let e=o.textContent?.length??0;if(i<=e){r.setStart(o,i),r.collapse(!0),n.removeAllRanges(),n.addRange(r);return}i-=e,o=a.nextNode()}r.selectNodeContents(e),r.collapse(!1),n.removeAllRanges(),n.addRange(r)}var M=class{editor;container;mermaid;mermaidConfig;svgHost;overlayHost;errorBadge;correlation=null;seqCorrelation=null;popover;plusButtons=[];plusMenu=null;hoveredLifeline=null;svg=null;svgTransformObserver=null;visibilityRetryObserver=null;popoverFollowRaf=0;applyingOwnTransform=!1;popoverAnchorPick=null;tool=`select`;readOnly;debounceMs;defaultEdge;hooks;renderTimer=null;lastRenderedCode=``;disposers=[];listeners=new Map;connectSource=null;suppressNextClick=!1;lastPointerWasTouch=!1;tapTracker=null;suppressDblClickUntil=0;ghostPath=null;dragEvent=null;dragStartY=0;dragging=!1;dropIndicator=null;dropSlots=[];inlineInput=null;inlineHidden=null;pendingEditEntity=null;inPlaceSession=null;lastError=null;renderHeldByEdit=!1;panZoomEnabled;zoomScale=1;zoomTx=0;zoomTy=0;hasUserView=!1;svgSize=null;panSession=null;zoomControls=null;renderSeq=0;awaitingFonts=!1;destroyed=!1;constructor(e){if(this.editor=e.editor,this.container=e.container,this.mermaid=e.mermaid,this.readOnly=e.readOnly??!1,this.panZoomEnabled=e.panZoom??!1,this.debounceMs=e.debounceMs??200,this.defaultEdge=e.defaultEdge??{},this.hooks=e.hooks??{},this.mermaidConfig={startOnLoad:!1,...e.mermaidConfig},!E){let e=document.createElement(`style`);e.setAttribute(`data-mw`,``),e.textContent=T+h,document.head.appendChild(e),E=!0}this.container.classList.add(`mw-canvas`),this.container.tabIndex=0,e.accentColor&&this.container.style.setProperty(`--mw-accent`,e.accentColor),this.readOnly&&this.container.classList.add(`mw-readonly`),this.svgHost=document.createElement(`div`),this.svgHost.className=`mw-svg-host`,this.overlayHost=document.createElement(`div`),this.errorBadge=document.createElement(`div`),this.errorBadge.className=`mw-error-badge`,this.errorBadge.style.display=`none`,this.container.append(this.svgHost,this.overlayHost,this.errorBadge),this.popover=new m(this.overlayHost),this.mermaid.initialize(this.mermaidConfig),this.disposers.push(this.editor.on(`change`,()=>this.scheduleRender()),this.editor.on(`selectionChange`,()=>this.applySelectionStyles()));let t=e=>this.onKeyDown(e);this.container.addEventListener(`keydown`,t),this.disposers.push(()=>this.container.removeEventListener(`keydown`,t));let n=e=>{let t=e.target;!t||this.container.contains(t)||(this.inPlaceSession?.finish?.(!0),this.clearLifelineUi(),this.popover.hide(),this.editor.selection.length&&this.editor.clearSelection(`canvas`))};document.addEventListener(`pointerdown`,n,!0),this.disposers.push(()=>document.removeEventListener(`pointerdown`,n,!0)),this.panZoomEnabled&&this.setupPanZoom(),this.render()}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.listeners.get(e).delete(t)}emit(e,t){this.listeners.get(e)?.forEach(e=>e(t))}get currentTool(){return this.tool}get renderError(){return this.lastError}setTool(e){this.tool=e,this.container.classList.toggle(`mw-tool-connect`,e===`connect`),this.cancelConnect(),this.emit(`toolChange`,e)}setReadOnly(e){this.readOnly=e,this.container.classList.toggle(`mw-readonly`,e),this.closeInlineEditor(!1),this.cancelConnect(),this.clearLifelineUi(),this.updatePopover()}setHooks(e){this.hooks=e}setAccentColor(e){this.container.style.setProperty(`--mw-accent`,e)}setMermaidConfig(e){this.mermaidConfig={...this.mermaidConfig,...e},this.mermaid.initialize(this.mermaidConfig),this.lastRenderedCode=``,this.render()}addNode(e=`rect`,t=`New node`){if(this.readOnly)return;let n=this.editor.dispatch({type:`addNode`,shape:e,label:t})?.created?.[0];n&&(this.pendingEditEntity=n)}scheduleRender(){this.renderTimer&&clearTimeout(this.renderTimer),this.renderTimer=setTimeout(()=>void this.render(),this.debounceMs)}setupPanZoom(){this.container.classList.add(`mw-panzoom`);let e=e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=Math.max(-40,Math.min(40,e.deltaY));this.zoomAt(e.clientX,e.clientY,Math.exp(-t*.01))};this.container.addEventListener(`wheel`,e,{passive:!1}),this.disposers.push(()=>this.container.removeEventListener(`wheel`,e));let t=new Map,n=0,r=e=>{if(e.pointerType===`touch`&&(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===2)){let[e,r]=[...t.values()];n=Math.hypot(e.x-r.x,e.y-r.y),this.panSession=null,this.container.classList.remove(`mw-panning`),this.suppressNextClick=!0,this.popover.hide();return}if(e.button!==0||this.tool===`connect`||e.altKey||this.inlineInput||this.inPlaceSession)return;let r=e.target;if(!r||!this.svgHost.contains(r))return;let i=r;for(;i&&i!==this.container;){if(i.getAttribute?.(`data-mw-entity`))return;i=i.parentElement}this.panSession={pointerId:e.pointerId,x:e.clientX,y:e.clientY,tx:this.zoomTx,ty:this.zoomTy,moved:!1}},i=e=>{if(e.pointerType===`touch`&&t.has(e.pointerId)&&(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size>=2&&n>0)){let[e,r]=[...t.values()],i=Math.hypot(e.x-r.x,e.y-r.y);i>0&&(this.zoomAt((e.x+r.x)/2,(e.y+r.y)/2,i/n),n=i,this.suppressNextClick=!0);return}let r=this.panSession;if(!r||e.pointerId!==r.pointerId)return;let i=e.clientX-r.x,a=e.clientY-r.y;if(!r.moved&&Math.hypot(i,a)>4){r.moved=!0,this.container.classList.add(`mw-panning`);try{this.container.setPointerCapture(e.pointerId)}catch{}this.popover.hide()}r.moved&&(this.zoomTx=r.tx+i,this.zoomTy=r.ty+a,this.hasUserView=!0,this.applyViewTransform())},a=e=>{e.pointerType===`touch`&&(t.delete(e.pointerId),t.size<2&&(n=0));let r=this.panSession;!r||e.pointerId!==r.pointerId||(this.panSession=null,this.container.classList.remove(`mw-panning`),r.moved?(this.suppressNextClick=!0,this.updatePopover()):this.editor.selection.length&&this.editor.clearSelection(`canvas`))};this.container.addEventListener(`pointerdown`,r),this.container.addEventListener(`pointermove`,i),this.container.addEventListener(`pointerup`,a),this.container.addEventListener(`pointercancel`,a),this.disposers.push(()=>{this.container.removeEventListener(`pointerdown`,r),this.container.removeEventListener(`pointermove`,i),this.container.removeEventListener(`pointerup`,a),this.container.removeEventListener(`pointercancel`,a)});let o=document.createElement(`div`);o.className=`mw-zoom-controls`;let s=(e,t,n)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`mw-zoom-btn`,r.title=e,r.innerHTML=t,r.addEventListener(`pointerdown`,e=>e.stopPropagation()),r.addEventListener(`click`,e=>{e.stopPropagation(),n()}),o.appendChild(r)};if(s(`Zoom out`,p.minus,()=>this.zoomBy(1/1.25)),s(`Zoom in`,p.plus,()=>this.zoomBy(1.25)),s(`Fit diagram`,p.maximize,()=>this.fitView()),this.container.appendChild(o),this.zoomControls=o,typeof ResizeObserver<`u`){let e=new ResizeObserver(()=>{this.hasUserView||this.fitView()});e.observe(this.container),this.disposers.push(()=>e.disconnect())}}zoomBy(e){let t=this.container.getBoundingClientRect();this.zoomAt(t.left+t.width/2,t.top+t.height/2,e)}zoomAt(e,t,n){if(!this.panZoomEnabled)return;let r=this.container.getBoundingClientRect(),i=e-r.left,a=t-r.top,o=Math.min(Math.max(this.zoomScale*n,.1),4),s=o/this.zoomScale;s!==1&&(this.zoomTx=i-(i-this.zoomTx)*s,this.zoomTy=a-(a-this.zoomTy)*s,this.zoomScale=o,this.hasUserView=!0,this.applyViewTransform(),this.updatePopover())}fitView(){if(!this.panZoomEnabled||!this.svg||!this.svgSize)return;let e=this.container.clientWidth,t=this.container.clientHeight;if(!e||!t)return;let{width:n,height:r}=this.svgSize,i=Math.min((e-56)/n,(t-56)/r);this.zoomScale=Math.min(Math.max(i,.1),2),this.zoomTx=(e-n*this.zoomScale)/2,this.zoomTy=(t-r*this.zoomScale)/2,this.hasUserView=!1,this.applyViewTransform(),this.updatePopover()}applyViewTransform(){this.svg&&(this.applyingOwnTransform=!0,this.svg.style.transform=`translate(${this.zoomTx}px, ${this.zoomTy}px) scale(${this.zoomScale})`,queueMicrotask(()=>{this.applyingOwnTransform=!1}))}prepareSvgForPanZoom(){let e=this.svg;if(!e)return;let t=0,n=0,r=e.viewBox?.baseVal;if(r&&r.width&&r.height)t=r.width,n=r.height;else{let r=e.getBBox?.();t=r?.width||800,n=r?.height||600}this.svgSize={width:t,height:n},e.removeAttribute(`width`),e.removeAttribute(`height`),e.style.width=`${t}px`,e.style.height=`${n}px`,e.style.maxWidth=`none`,this.hasUserView?this.applyViewTransform():this.fitView()}async render(){if(this.inPlaceSession){this.renderHeldByEdit=!0;return}let e=this.editor.code;if(e===this.lastRenderedCode){this.lastError&&(this.lastError=null,this.errorBadge.style.display=`none`,this.editor.setDiagnostics([]),this.emit(`render`,{ok:!0}));return}let t=++this.renderSeq,n=`mw-render-${++D}`;try{this.mermaid.initialize(this.mermaidConfig);let{svg:r}=await this.mermaid.render(n,e);if(t!==this.renderSeq)return;let i=null,a=this.activeInPlaceSession(),o=a?.label;if(a&&o?.isConnected&&(i={value:k(o),caret:A(o)},a.liveTimer&&=(clearTimeout(a.liveTimer),null)),this.lastRenderedCode=e,this.lastError=null,this.errorBadge.style.display=`none`,this.svgHost.innerHTML=r,this.svg=this.svgHost.querySelector(`svg`),this.svg&&(this.panZoomEnabled?this.prepareSvgForPanZoom():this.svg.style.maxWidth=`100%`,w(this.svg),this.bindSvg()),this.editor.setDiagnostics([]),this.emit(`render`,{ok:!0}),this.remeasureWhenFontsSettle(),this.activeInPlaceSession())this.resumeInPlaceSession(i);else if(this.pendingEditEntity){let e=this.pendingEditEntity;this.pendingEditEntity=null,this.editor.entityExists(e)&&this.editEntityLabel(e)}}catch(e){if(t!==this.renderSeq)return;document.getElementById(`d${n}`)?.remove(),document.getElementById(n)?.remove();let r=e instanceof Error?e.message.split(`
160
- `)[0]:String(e);this.lastError=r,this.errorBadge.textContent=`render error: ${r}`,this.errorBadge.style.display=`block`;let i={message:r,span:null,severity:`error`,source:`mermaid`};this.editor.setDiagnostics([i]),this.emit(`render`,{ok:!1,error:r})}}remeasureWhenFontsSettle(){let e=typeof document>`u`?void 0:document.fonts;if(!e||this.awaitingFonts||e.status===`loaded`)return;this.awaitingFonts=!0;let t=()=>{this.awaitingFonts=!1,!this.destroyed&&(this.lastRenderedCode=``,this.render())};Promise.resolve(e.ready).then(t,t)}bindSvg(){let e=this.svg;if(!e)return;let{flowchart:t,sequence:n,state:r,classGraph:f,er:p}=this.editor.result;this.correlation=t?i(e,t):r?a(e,r):f?o(e,f):p?s(e,p):this.editor.result.pie?c(e,this.editor.result.pie):this.editor.result.gantt?l(e,this.editor.result.gantt):this.editor.result.lineItems?u(e,this.editor.result.lineItems):null,this.seqCorrelation=n?d(e,n):null,this.clearLifelineUi(),this.armVisibilityRetry(e,n),e.addEventListener(`click`,e=>this.onSvgClick(e)),e.addEventListener(`dblclick`,e=>this.onSvgDblClick(e)),e.addEventListener(`pointerdown`,e=>this.onSvgPointerDown(e)),e.addEventListener(`pointermove`,e=>this.onSvgPointerMove(e)),e.addEventListener(`pointerup`,e=>this.onSvgPointerUp(e)),this.seqCorrelation&&(e.addEventListener(`pointermove`,e=>this.onLifelineHover(e)),e.addEventListener(`pointerleave`,()=>this.scheduleLifelineClear())),this.svgTransformObserver?.disconnect(),typeof MutationObserver<`u`&&(this.svgTransformObserver=new MutationObserver(()=>{this.applyingOwnTransform||this.popoverFollowRaf||!this.popover.isOpen||(this.popoverFollowRaf=(typeof requestAnimationFrame==`function`?requestAnimationFrame:e=>setTimeout(e,16))(()=>{this.popoverFollowRaf=0,this.updatePopover()}))}),this.svgTransformObserver.observe(e,{attributes:!0,attributeFilter:[`style`,`transform`],subtree:!0})),this.applySelectionStyles()}armVisibilityRetry(e,t){this.visibilityRetryObserver?.disconnect(),this.visibilityRetryObserver=null,t&&(this.seqCorrelation&&this.seqCorrelation.lifelines.size>0||typeof IntersectionObserver>`u`||(this.visibilityRetryObserver=new IntersectionObserver(n=>{n.some(e=>e.intersectionRatio>0)&&e.getBoundingClientRect().width!==0&&(this.visibilityRetryObserver?.disconnect(),this.visibilityRetryObserver=null,this.svg===e&&(this.seqCorrelation=d(e,t)))}),this.visibilityRetryObserver.observe(e)))}entityFromEvent(e){return this.entityHitFromEvent(e)?.id??null}entityHitFromEvent(e){let t=e.target;for(;t&&t!==this.svg;){let e=t.getAttribute?.(`data-mw-entity`);if(e)return{id:e,el:t};t=t.parentElement}return null}topmostEntityElement(e){let t=null,n=1/0;return this.svg?.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`).forEach(e=>{let r=e.getBoundingClientRect().top;r<n&&(n=r,t=e)}),t}onSvgClick(e){if(this.suppressNextClick){this.suppressNextClick=!1;return}if(this.inlineInput||this.inPlaceSession)return;let t=this.entityHitFromEvent(e);if(t){if(this.lastPointerWasTouch&&!this.readOnly){let n=Date.now(),r=this.tapTracker;if(this.tapTracker={entity:t.id,time:n},r&&r.entity===t.id&&n-r.time<400){this.tapTracker=null,this.onSvgDblClick(e),this.suppressDblClickUntil=n+500;return}}let n=t.id;if(this.hooks.onEntityClick?.(n,e),this.popoverAnchorPick={entityId:n,index:this.entityElementIndex(n,t.el)},e.shiftKey||e.metaKey||e.ctrlKey){let e=this.editor.selection.includes(n)?this.editor.selection.filter(e=>e!==n):[...this.editor.selection,n];this.editor.setSelection(e,`canvas`)}else this.editor.setSelection([n],`canvas`),this.updatePopover();this.container.focus({preventScroll:!0})}else this.editor.clearSelection(`canvas`)}entityElementIndex(e,t){if(!this.svg)return 0;let n=[...this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`)].indexOf(t);return n>=0?n:0}onSvgDblClick(e){if(this.readOnly||Date.now()<this.suppressDblClickUntil)return;let t=e.target.closest?.(`[data-mw-member-line]`);if(t&&this.editor.result.classGraph){let n=t.getAttribute(`data-mw-member-class`),r=Number(t.getAttribute(`data-mw-member-line`)),i=this.editor.result.classGraph.classById.get(n)?.members.find(e=>e.lineIndex===r);if(i){e.preventDefault(),this.popover.hide(),this.editInPlace(`member:${n}:${r}`,t,`.nodeLabel`,i.text,e=>this.editor.dispatch({type:`cl.setMemberText`,id:n,memberLine:r,text:e},`canvas`),{live:!1});return}}let n=e.target.closest?.(`[data-mw-attr-line]`);if(n&&this.editor.result.er){let t=n.getAttribute(`data-mw-attr-entity`),r=Number(n.getAttribute(`data-mw-attr-line`)),i=this.editor.result.er.entityById.get(t)?.attributes.find(e=>e.lineIndex===r);if(i){e.preventDefault(),this.popover.hide(),this.openOverlayEditor(n,i.text,e=>this.editor.dispatch({type:`er.setAttributeText`,id:t,attrLine:r,text:e},`canvas`));return}}let r=this.entityHitFromEvent(e);r&&(e.preventDefault(),!this.hooks.onEntityDoubleClick?.(r.id)&&this.editEntityLabel(r.id,r.el))}onSvgPointerDown(e){if(this.readOnly)return;let t=this.entityFromEvent(e),n=t?.startsWith(`node:`)||t?.startsWith(`state:`)||t?.startsWith(`class:`)||t?.startsWith(`entity:`),r=this.tool===`connect`||e.altKey;if(n&&r&&t){e.preventDefault(),this.connectSource=t,this.svg?.setPointerCapture?.(e.pointerId),this.entityElement(t)?.classList.add(`mw-connect-source`),this.emit(`connectPreview`,{source:t});return}t?.startsWith(`event:`)&&this.editor.result.sequence&&e.detail<=1&&(this.dragEvent=t,this.dragStartY=e.clientY,this.dragging=!1)}entityElement(e){return this.svg?.querySelector(`[data-mw-entity="${CSS.escape(e)}"]`)??null}onSvgPointerMove(e){if(this.dragEvent&&this.svg){if(!this.dragging&&Math.abs(e.clientY-this.dragStartY)>8&&(this.dragging=!0,this.svg.setPointerCapture?.(e.pointerId),this.computeDropSlots(),this.popover.hide()),this.dragging){let t=this.container.getBoundingClientRect(),n=e.clientY-t.top+this.container.scrollTop,r=this.nearestSlot(n);r&&this.showDropIndicator(r.y)}return}if(!this.connectSource||!this.svg)return;let t=this.entityCenter(this.connectSource),n=this.clientToSvg(e.clientX,e.clientY);!t||!n||(this.ghostPath||(this.ghostPath=document.createElementNS(`http://www.w3.org/2000/svg`,`line`),this.ghostPath.classList.add(`mw-ghost-edge`),this.svg.appendChild(this.ghostPath)),this.ghostPath.setAttribute(`x1`,String(t.x)),this.ghostPath.setAttribute(`y1`,String(t.y)),this.ghostPath.setAttribute(`x2`,String(n.x)),this.ghostPath.setAttribute(`y2`,String(n.y)))}onSvgPointerUp(e){if(this.lastPointerWasTouch=e.pointerType===`touch`,this.dragEvent){let t=this.dragEvent,n=this.dragging;if(this.dragEvent=null,this.dragging=!1,this.dropIndicator?.remove(),this.dropIndicator=null,n){this.suppressNextClick=!0;let n=this.container.getBoundingClientRect(),r=this.nearestSlot(e.clientY-n.top+this.container.scrollTop);r&&this.editor.dispatch({type:`seq.moveEvent`,eventId:t,afterEvent:r.afterEvent})}return}if(!this.connectSource)return;let t=this.connectSource,n=t.startsWith(`node:`)?`node:`:t.startsWith(`state:`)?`state:`:t.startsWith(`class:`)?`class:`:`entity:`,r=document.elementFromPoint(e.clientX,e.clientY),i=null,a=r;for(;a&&a!==this.container;){let e=a.getAttribute?.(`data-mw-entity`);if(e?.startsWith(n)){i=e;break}a=a.parentElement}this.cancelConnect(),this.suppressNextClick=!0,i&&i!==t&&n===`node:`?this.editor.dispatch({type:`connect`,source:t.slice(5),target:i.slice(5),line:this.defaultEdge.line,arrowEnd:this.defaultEdge.arrowEnd}):i&&i!==t&&n===`state:`?this.editor.dispatch({type:`st.connect`,source:t.slice(6),target:i.slice(6)}):i&&i!==t&&n===`class:`?this.editor.dispatch({type:`cl.connect`,source:t.slice(6),target:i.slice(6)}):i&&i!==t&&n===`entity:`?this.editor.dispatch({type:`er.connect`,source:t.slice(7),target:i.slice(7)}):(this.editor.setSelection([t],`canvas`),this.container.focus({preventScroll:!0}))}cancelConnect(){this.connectSource&&this.entityElement(this.connectSource)?.classList.remove(`mw-connect-source`),this.connectSource=null,this.ghostPath?.remove(),this.ghostPath=null,this.emit(`connectPreview`,{source:null})}editEntityLabel(e,t){if(this.readOnly)return;let{flowchart:n,sequence:r}=this.editor.result;this.closeInlineEditor(!1),this.inPlaceSession&&this.inPlaceSession.entityId!==e&&this.inPlaceSession.finish?.(!0),this.popover.hide();let i=t&&t.getAttribute(`data-mw-entity`)===e?t:null,a=null,o=``,s=()=>{};if(n&&e.startsWith(`node:`)){let t=n.nodeById.get(e.slice(5));if(!t||(o=t.label,a=this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`renameNode`,id:t.id,label:e},`canvas`),a&&this.editInPlace(e,a,`.nodeLabel`,o,s)))return}else if(n&&e.startsWith(`edge:`)){let t=n.edges.find(t=>t.entityId===e);if(!t||(o=t.label??``,s=t=>this.editor.dispatch({type:`setEdgeLabel`,edgeId:e,label:t},`canvas`),a=this.edgeAnchor(e,!!t.label),t.label&&a&&this.editInPlace(e,a,`.edgeLabel`,o,s)))return}else if(n&&e.startsWith(`subgraph:`)){let t=n.subgraphs.find(t=>t.entityId===e);if(!t)return;o=t.title??t.id,a=this.correlation?.nodes.get(e)?.querySelector(`.cluster-label`)??i??this.correlation?.nodes.get(e)??this.svg?.querySelector(`#${CSS.escape(t.id)}`)??null,s=e=>this.editor.dispatch({type:`renameSubgraph`,id:t.id,title:e},`canvas`)}else if(this.editor.result.state&&e.startsWith(`state:`)){let t=this.editor.result.state.stateById.get(e.slice(6));if(!t||(o=t.label,a=this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`st.setStateLabel`,id:t.id,label:e},`canvas`),a&&this.editInPlace(e,a,`.nodeLabel`,o,s)))return}else if(this.editor.result.state&&e.startsWith(`trans:`)){let t=this.editor.result.state.transitions.find(t=>t.entityId===e);if(!t||(o=t.label??``,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`st.setTransitionLabel`,transId:e,label:t},`canvas`),t.label&&a&&this.editInPlace(e,a,`.edgeLabel`,o,s)))return}else if(this.editor.result.classGraph&&e.startsWith(`class:`)){let t=this.editor.result.classGraph.classById.get(e.slice(6));if(!t)return;o=t.id,a=i??this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`cl.renameClass`,id:t.id,name:e},`canvas`)}else if(this.editor.result.classGraph&&e.startsWith(`rel:`)){let t=this.editor.result.classGraph.relations.find(t=>t.entityId===e);if(!t)return;o=t.label??``,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`cl.setRelationLabel`,relId:e,label:t},`canvas`)}else if(this.editor.result.er&&e.startsWith(`entity:`)){let t=this.editor.result.er.entityById.get(e.slice(7));if(!t)return;o=t.id,a=i??this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`er.renameEntity`,id:t.id,name:e},`canvas`)}else if(this.editor.result.er&&e.startsWith(`erel:`)){let t=this.editor.result.er.relations.find(t=>t.entityId===e);if(!t)return;o=t.label,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`er.setRelationLabel`,relId:e,label:t},`canvas`)}else if(this.editor.result.pie&&e.startsWith(`slice:`)){let t=this.editor.result.pie.slices.find(t=>t.entityId===e);if(!t)return;o=String(t.value),a=i??this.entityElement(e),s=t=>{let n=Number(t);Number.isFinite(n)&&this.editor.dispatch({type:`pie.setValue`,sliceId:e,value:n},`canvas`)}}else if(this.editor.result.gantt&&e.startsWith(`task:`)){let t=this.editor.result.gantt.tasks.find(t=>t.entityId===e);if(!t)return;o=t.name,a=i??this.entityElement(e),s=t=>this.editor.dispatch({type:`gantt.setTaskName`,taskId:e,name:t},`canvas`)}else if(this.editor.result.lineItems&&e.startsWith(`item:`)){let t=this.editor.result.lineItems.items.find(t=>t.entityId===e);if(!t)return;o=t.text,a=i??this.entityElement(e),s=t=>this.editor.dispatch({type:`li.setLine`,itemId:e,text:t},`canvas`)}else if(r&&e.startsWith(`participant:`)){let t=r.participantById.get(e.slice(12));if(!t)return;o=t.label,a=i??this.topmostEntityElement(e),s=e=>this.editor.dispatch({type:`seq.renameParticipant`,id:t.id,name:e},`canvas`)}else if(r&&e.startsWith(`event:`)){let t=r.events.find(t=>t.entityId===e);if(!t)return;o=t.stmt.text,a=this.seqCorrelation?.eventTexts.get(e)??i??this.entityElement(e),s=t=>this.editor.dispatch({type:`seq.setEventText`,eventId:e,text:t},`canvas`)}a&&this.openOverlayEditor(a,o,s)}editInPlace(e,t,n,r,i,a={}){let o=t.matches?.(n)?t.querySelector(`p`)??t:t.querySelector(`${n} p`)??t.querySelector(n);if(!o||!(o instanceof HTMLElement))return!1;let s=this.inPlaceSession?.entityId===e;if(s&&this.inPlaceSession.label===o&&o.isConnected)return o.focus(),!0;s||(this.inPlaceSession={entityId:e,labelSelector:n,original:r,lastCommitted:r,caretOffset:-1,commitValue:i,liveTimer:null,label:null,finish:null});let c=this.inPlaceSession;c.label=o,o.setAttribute(`contenteditable`,`true`);let l=o.closest(`foreignObject`),u=o.style.whiteSpace,d=l?.style.overflow??``;if(o.style.whiteSpace=`nowrap`,l&&(l.style.overflow=`visible`),o.focus(),s&&c.caretOffset>=0)j(o,c.caretOffset);else{let e=window.getSelection(),t=document.createRange();t.selectNodeContents(o),e?.removeAllRanges(),e?.addRange(t)}let f=()=>{let e=A(o);e>=0&&(c.caretOffset=e)},p=()=>{if(this.inPlaceSession!==c)return;let e=O(o);!e||e===c.lastCommitted||(f(),c.lastCommitted=e,c.commitValue(e))},m=e=>{if(this.inPlaceSession!==c)return;this.inPlaceSession=null,c.liveTimer&&clearTimeout(c.liveTimer),o.removeAttribute(`contenteditable`),o.style.whiteSpace=u,l&&(l.style.overflow=d),o.removeEventListener(`keydown`,g),o.removeEventListener(`blur`,_),o.removeEventListener(`input`,h);let t=O(o);e?t&&t!==c.lastCommitted?c.commitValue(t):t||(o.textContent=c.lastCommitted):(o.innerHTML=c.original,c.lastCommitted!==c.original&&c.commitValue(c.original)),this.renderHeldByEdit&&(this.renderHeldByEdit=!1,this.scheduleRender()),this.updatePopover()},h=()=>{a.live!==!1&&(c.liveTimer&&clearTimeout(c.liveTimer),c.liveTimer=setTimeout(p,450))},g=e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),m(!0)):e.key===`Escape`&&m(!1)},_=()=>{setTimeout(()=>{this.inPlaceSession===c&&o.isConnected&&document.activeElement!==o&&m(!0)},60)};return c.finish=m,o.addEventListener(`keydown`,g),o.addEventListener(`blur`,_),o.addEventListener(`input`,h),!0}activeInPlaceSession(){return this.inPlaceSession}resumeInPlaceSession(e){let t=this.inPlaceSession;if(!t)return;if(!this.editor.entityExists(t.entityId)){this.inPlaceSession=null;return}let n=(t.entityId.startsWith(`edge:`)?this.correlation?.edgeLabels.get(t.entityId):null)??this.entityElement(t.entityId);if(!n){this.inPlaceSession=null;return}this.editInPlace(t.entityId,n,t.labelSelector,t.lastCommitted,t.commitValue);let r=this.inPlaceSession===t?t.label:null;!r||!e||(e.value&&e.value!==t.lastCommitted&&e.value!==k(r)&&(r.innerHTML=e.value,r.dispatchEvent(new Event(`input`))),e.caret>=0&&j(r,e.caret))}findTextTarget(e,t){let n=e=>(e.tagName===`text`||e.tagName===`SPAN`||e.tagName===`P`||e.tagName===`DIV`||e.tagName===`tspan`)&&(e.children.length===0||e.tagName===`text`)&&(e.textContent?.trim().length??0)>0;if(n(e))return e;let r=[...e.querySelectorAll(`text, tspan, span, p, div`)].filter(n);return!r.length&&e.parentElement&&(r=[...e.parentElement.querySelectorAll(`text, tspan, span, p, div`)].filter(n)),r.find(e=>e.textContent?.trim()===t.trim())??r.find(e=>t.trim().startsWith(e.textContent?.trim()??`\0`))??r[0]??e}openOverlayEditor(e,t,n){let r,i;typeof SVGPathElement<`u`&&e instanceof SVGPathElement?(r=this.pathMidpointRect(e),i=null):(e=this.findTextTarget(e,t),r=this.hostRect(e),i=e);let a=e.querySelector(`tspan`)??e,o=window.getComputedStyle(a),s=document.createElement(`div`);s.className=`mw-inplace-editor`,s.contentEditable=`true`,s.spellcheck=!1,s.textContent=t,s.style.left=`${r.left+r.width/2}px`,s.style.top=`${r.top}px`,s.style.transform=`translateX(-50%)`,s.style.textAlign=`center`,s.style.minWidth=`${Math.max(24,r.width)}px`,s.style.lineHeight=`${Math.max(r.height,12)}px`,s.style.fontStyle=o.fontStyle,s.style.fontWeight=o.fontWeight;let c=this.panZoomEnabled?this.zoomScale:1,l=Number.parseFloat(o.fontSize);s.style.fontSize=Number.isFinite(l)?`${l*c}px`:o.fontSize,s.style.fontFamily=o.fontFamily;let u=o.fill&&o.fill!==`none`&&a instanceof SVGElement?o.fill:o.color;if(s.style.color=u||`inherit`,this.overlayHost.appendChild(s),this.inlineInput=s,i){let e=i,t=e.style?.visibility??``;e.style&&(e.style.visibility=`hidden`),this.inlineHidden={el:e,prevVisibility:t}}s.focus();let d=document.createRange();d.selectNodeContents(s);let f=window.getSelection();f?.removeAllRanges(),f?.addRange(d);let p=()=>{let e=(s.textContent??``).trim(),r=this.inlineHidden?.el??null;this.closeInlineEditor(!1),e!==t&&(r&&(r.textContent=e),n(e))};s.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),p()),e.key===`Escape`&&this.closeInlineEditor(!1)}),s.addEventListener(`blur`,p)}closeInlineEditor(e){if(this.inlineHidden&&=(this.inlineHidden.el.style&&(this.inlineHidden.el.style.visibility=this.inlineHidden.prevVisibility),null),this.inlineInput){let t=this.inlineInput;this.inlineInput=null,t.remove(),e&&this.container.focus({preventScroll:!0})}}onKeyDown(e){if(!this.inlineInput){if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?this.editor.redo():this.editor.undo();return}if(!this.readOnly){if((e.key===`Delete`||e.key===`Backspace`)&&this.editor.selection.length){e.preventDefault(),this.editor.deleteEntities(this.editor.selection,`canvas`);return}if(e.key===`Escape`){this.cancelConnect(),this.editor.clearSelection(`canvas`);return}e.key===`Enter`&&this.editor.selection.length===1&&(e.preventDefault(),this.editEntityLabel(this.editor.selection[0]))}}}applySelectionStyles(){if(this.svg){this.svg.querySelectorAll(`.mw-selected`).forEach(e=>e.classList.remove(`mw-selected`));for(let e of this.editor.selection)this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`).forEach(e=>{e.classList.add(`mw-selected`)});this.updatePopover()}}edgeAnchor(e,t){let n=this.correlation?.edgeLabels,r=this.correlation?.edges;return t?n?.get(e)??r?.get(e)??null:r?.get(e)??n?.get(e)??null}hostRect(e){let t=e.getBoundingClientRect(),n=this.container.getBoundingClientRect();return{left:t.left-n.left+this.container.scrollLeft,top:t.top-n.top+this.container.scrollTop,width:t.width,height:t.height}}pathMidpointRect(e){let t=this.container.getBoundingClientRect(),n=typeof e.getScreenCTM==`function`&&typeof e.getTotalLength==`function`?e.getScreenCTM():null;if(!n)return this.hostRect(e);let r=e.getTotalLength(),i=e.getPointAtLength(r/2),a=new DOMPoint(i.x,i.y).matrixTransform(n),o=20*(this.panZoomEnabled?this.zoomScale:1);return{left:a.x-t.left+this.container.scrollLeft,top:a.y-t.top+this.container.scrollTop-o/2,width:0,height:o}}updatePopover(){if(this.popover.hide(),this.readOnly||this.inlineInput||this.inPlaceSession)return;let e=this.editor.selection;if(e.length!==1||!this.svg)return;let t=e[0],n=[...this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(t)}"]`)],r=null,i=this.popoverAnchorPick;if(i&&i.entityId===t&&n[i.index])r=n[i.index];else{let e=1/0;for(let t of n){let n=t.getBoundingClientRect().top;n<e&&(e=n,r=t)}}if(!r)return;let a=this.actionsFor(t);a.length&&this.popover.show(this.hostRect(r),a)}colorSection(e,t){return{title:e,columns:5,items:[...g.map(n=>({swatch:n,title:`${e}: ${n}`,onClick:()=>t(n)})),{swatch:`none`,title:`${e}: default`,onClick:()=>t(null)}]}}actionsFor(n){let{flowchart:r,sequence:i}=this.editor.result,a={icon:p.trash,title:`Delete`,danger:!0,onClick:()=>this.editor.deleteEntities([n])},o={icon:p.pencil,title:`Edit text`,onClick:()=>this.editEntityLabel(n)};if(r&&n.startsWith(`node:`)){let e=r.nodeById.get(n.slice(5));return e?[{icon:p.shapes,title:`Node shape`,panel:{title:`Node shape`,items:[{s:`rect`,g:`▭`,t:`Rectangle`},{s:`round`,g:`▢`,t:`Rounded`},{s:`stadium`,g:`⬭`,t:`Stadium`},{s:`diamond`,g:`◇`,t:`Diamond`},{s:`hexagon`,g:`⬡`,t:`Hexagon`},{s:`circle`,g:`◯`,t:`Circle`},{s:`cylinder`,g:`⛁`,t:`Cylinder`},{s:`subroutine`,g:`⧉`,t:`Subroutine`}].map(t=>({glyph:t.g,title:t.t,selected:e.shape===t.s,onClick:()=>this.editor.dispatch({type:`setNodeShape`,id:e.id,shape:t.s})}))}},{icon:p.palette,title:`Colors`,panel:{title:`Colors`,sections:[`fill`,`stroke`,`color`].map(t=>this.colorSection(t===`fill`?`Fill`:t===`stroke`?`Border`:`Text`,n=>this.editor.dispatch({type:`setNodeColor`,id:e.id,prop:t,value:n})))}},{icon:p.copy,title:`Duplicate`,onClick:()=>this.editor.dispatch({type:`duplicateNode`,id:e.id})},o,a]:[]}if(r&&n.startsWith(`subgraph:`))return[{icon:p.pencil,title:`Rename subgraph`,onClick:()=>this.editEntityLabel(n)}];if(r&&n.startsWith(`edge:`)){let e=r.edges.find(e=>e.entityId===n);if(!e)return[];let t=[{start:`open`,end:`open`,t:`No arrow`},{start:`open`,end:`arrow`,t:`Arrow`},{start:`arrow`,end:`arrow`,t:`Double point`},{start:`open`,end:`cross`,t:`Cross`},{start:`cross`,end:`cross`,t:`Double cross`},{start:`open`,end:`circle`,t:`Dot`},{start:`circle`,end:`circle`,t:`Double dot`}],i=[{line:`solid`,t:`Solid`},{line:`dotted`,t:`Dotted`},{line:`thick`,t:`Thick`},{line:`invisible`,t:`Invisible`}],s=[{v:`basis`,t:`Default (curved)`,label:`Default`,svg:b(`basis`)},{v:`natural`,t:`Natural spline`,label:`Natural`,svg:b(`natural`)},{v:`linear`,t:`Straight segments`,label:`Linear`,svg:b(`linear`)}],c=[{v:`none`,t:`No animation`,label:`None`,svg:x(`none`)},{v:`slow`,t:`Slow flow`,label:`Slow`,svg:x(`slow`)},{v:`fast`,t:`Fast flow`,label:`Fast`,svg:x(`fast`)}],l=S(this.editor.code),u=C(this.editor.code,e.order);return[{icon:p.arrowRight,title:`Arrow`,panel:{title:`Arrow`,sections:[{columns:4,items:t.map(t=>({svg:_(e.seg.line,t.start,t.end),title:t.t,selected:e.seg.arrowStart===t.start&&e.seg.arrowEnd===t.end,onClick:()=>this.editor.dispatch({type:`setEdgeStyle`,edgeId:n,arrowStart:t.start,arrowEnd:t.end})}))}]}},{icon:p.equal,title:`Stroke`,panel:{title:`Stroke`,sections:[{columns:4,items:i.map(t=>({svg:y(t.line),title:t.t,label:t.t,selected:e.seg.line===t.line,onClick:()=>this.editor.dispatch({type:`setEdgeStyle`,edgeId:n,line:t.line})}))}]}},{icon:p.palette,title:`Edge color`,panel:{title:`Edge color`,sections:[this.colorSection(`Stroke`,e=>this.editor.dispatch({type:`setEdgeColor`,edgeId:n,value:e}))]}},{icon:p.circlePlay,title:`Animate edge`,panel:{title:`Animate edge`,sections:[{columns:3,items:c.map(e=>({svg:e.svg,title:e.t,label:e.label,selected:u===e.v,onClick:()=>this.editor.dispatch({type:`setEdgeAnimation`,edgeId:n,value:e.v})}))}]}},{icon:p.spline,title:`Edge curve (diagram-wide)`,panel:{title:`Edge curve`,sections:[{columns:3,items:s.map(e=>({svg:e.svg,title:e.t,label:e.label,selected:l===e.v,onClick:()=>this.editor.dispatch({type:`setFlowCurve`,value:e.v})}))}]}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`reverseEdge`,edgeId:n})},o,a]}if(this.editor.result.state&&n.startsWith(`state:`)){let e=this.editor.result.state.stateById.get(n.slice(6));return e?e.isComposite?[o]:[{icon:p.square,title:`State type`,panel:{title:`State type`,items:[{t:`state`,g:`▢`},{t:`choice`,g:`◇`},{t:`fork`,g:`⑃`},{t:`join`,g:`⑂`}].map(t=>({glyph:t.g,title:t.t,selected:(e.stereotype??`state`)===t.t,onClick:()=>this.editor.dispatch({type:`st.setStateType`,id:e.id,stype:t.t})}))}},{icon:p.stickyNote,title:`Add note`,panel:{title:`Note`,items:[`left`,`right`].map(t=>({glyph:t===`left`?`◧`:`◨`,title:`Note ${t}`,onClick:()=>this.editor.dispatch({type:`st.addStateNote`,id:e.id,side:t})}))}},{icon:p.frame,title:`Move to composite`,onClick:()=>this.editor.dispatch({type:`st.moveToComposite`,id:e.id})},o,a]:[]}if(this.editor.result.state&&n.startsWith(`trans:`))return[{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`st.reverseTransition`,transId:n})},o,a];if(this.editor.result.classGraph&&n.startsWith(`class:`)){let e=this.editor.result.classGraph.classById.get(n.slice(6));return e?[{icon:p.listPlus,title:`Add member`,onClick:()=>{this.editor.dispatch({type:`cl.addMember`,id:e.id,text:`+attribute`})}},{icon:p.braces,title:`Annotation`,panel:{title:`Annotation`,items:[...[`interface`,`abstract`,`service`,`enumeration`].map(t=>({glyph:t,title:`<<${t}>>`,onClick:()=>this.editor.dispatch({type:`cl.setAnnotation`,id:e.id,annotation:t})})),{glyph:`none`,title:`Remove annotation`,onClick:()=>this.editor.dispatch({type:`cl.setAnnotation`,id:e.id,annotation:null})}]}},{icon:p.stickyNote,title:`Add note`,onClick:()=>this.editor.dispatch({type:`cl.addNoteFor`,id:e.id})},{icon:p.pencil,title:`Rename class`,onClick:()=>this.editEntityLabel(n)},a]:[]}if(this.editor.result.classGraph&&n.startsWith(`rel:`)){let e=this.editor.result.classGraph.relations.find(e=>e.entityId===n);return e?[{icon:p.arrowRight,title:`Relation type`,panel:{title:`Relation type`,items:[{op:`<|--`,g:`◁—`,t:`inheritance`},{op:`*--`,g:`◆—`,t:`composition`},{op:`o--`,g:`◇—`,t:`aggregation`},{op:`-->`,g:`—▶`,t:`association`},{op:`--`,g:`——`,t:`link (solid)`},{op:`..>`,g:`⋯▶`,t:`dependency`},{op:`..|>`,g:`⋯▷`,t:`realization`},{op:`..`,g:`⋯⋯`,t:`link (dashed)`}].map(t=>({glyph:t.g,title:t.t,selected:e.stmt.op===t.op,onClick:()=>this.editor.dispatch({type:`cl.setRelationType`,relId:n,op:t.op})}))}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`cl.reverseRelation`,relId:n})},{glyph:`1:1`,title:`Cardinality (e.g. 1, 0..1, 1..*, *)`,onClick:()=>{let t=this.entityElement(n);if(!t)return;this.popover.hide();let r=`${e.stmt.sourceCard??``}:${e.stmt.targetCard??``}`;this.openOverlayEditor(t,r,t=>{let[r=``,i=``]=t.split(`:`);this.editor.dispatch({type:`cl.setCardinality`,relId:n,side:`source`,value:r.trim()||null},`canvas`);let a=this.editor.result.classGraph?.relations.find(t=>t.lineIndex===e.lineIndex&&t.source===e.source&&t.target===e.target);a&&this.editor.dispatch({type:`cl.setCardinality`,relId:a.entityId,side:`target`,value:i.trim()||null},`canvas`)})}},o,a]:[]}if(this.editor.result.er&&n.startsWith(`entity:`)){let e=this.editor.result.er.entityById.get(n.slice(7));return e?[{icon:p.listPlus,title:`Add attribute`,onClick:()=>this.editor.dispatch({type:`er.addAttribute`,id:e.id})},{icon:p.pencil,title:`Rename entity`,onClick:()=>this.editEntityLabel(n)},a]:[]}if(this.editor.result.er&&n.startsWith(`erel:`)){let e=this.editor.result.er.relations.find(e=>e.entityId===n);if(!e)return[];let t=[{c:`zero-or-one`,g:`0..1`},{c:`exactly-one`,g:`1`},{c:`zero-or-more`,g:`0..*`},{c:`one-or-more`,g:`1..*`}],r=r=>({icon:r===`left`?p.arrowLeftToLine:p.arrowRightToLine,title:`${r===`left`?`Source`:`Target`} cardinality`,panel:{title:`${r===`left`?e.source:e.target} cardinality`,items:t.map(e=>({glyph:e.g,title:e.c,onClick:()=>this.editor.dispatch({type:`er.setCardinality`,relId:n,side:r,card:e.c})}))}});return[r(`left`),r(`right`),{icon:e.stmt.line===`--`?p.minus:p.ellipsis,title:e.stmt.line===`--`?`Make non-identifying (dashed)`:`Make identifying (solid)`,onClick:()=>this.editor.dispatch({type:`er.setIdentifying`,relId:n,identifying:e.stmt.line!==`--`})},o,a]}if(this.editor.result.pie&&n.startsWith(`slice:`)){let e=this.editor.result.pie.slices.find(e=>e.entityId===n);return e?[{icon:p.hash,title:`Edit value`,onClick:()=>this.editEntityLabel(n)},{icon:p.pencil,title:`Edit label`,onClick:()=>{let t=this.entityElement(n);t&&(this.popover.hide(),this.openOverlayEditor(t,e.label,e=>this.editor.dispatch({type:`pie.setLabel`,sliceId:n,label:e},`canvas`)))}},a]:[]}if(this.editor.result.gantt&&n.startsWith(`task:`)){let e=this.editor.result.gantt.tasks.find(e=>e.entityId===n);return e?[{icon:p.pencil,title:`Rename task`,onClick:()=>this.editEntityLabel(n)},{icon:p.calendar,title:`Edit schedule (id, start, duration)`,onClick:()=>{let t=this.entityElement(n);t&&(this.popover.hide(),this.openOverlayEditor(t,e.meta,e=>this.editor.dispatch({type:`gantt.setTaskMeta`,taskId:n,meta:e},`canvas`)))}},a]:[]}if(this.editor.result.lineItems&&n.startsWith(`item:`))return[{icon:p.pencil,title:`Edit line`,onClick:()=>this.editEntityLabel(n)},a];if(i&&n.startsWith(`participant:`)){let e=i.participantById.get(n.slice(12));if(!e)return[];let r={participant:`▭`,actor:`웃`,boundary:`⊢○`,control:`◉`,entity:`◯`,database:`⛁`,collections:`⧉`,queue:`▤`};return[{icon:p.user,title:`Participant type`,panel:{title:`Participant type`,items:t.map(t=>({glyph:r[t],title:t,selected:e.ptype===t,onClick:()=>this.editor.dispatch({type:`seq.setParticipantType`,id:e.id,ptype:t})}))}},{icon:p.pencil,title:`Rename`,onClick:()=>this.editEntityLabel(n)},a]}if(i&&n.startsWith(`event:`)){let t=i.events.find(e=>e.entityId===n);if(!t)return[];if(t.kind===`message`){let r={"->":`——`,"->>":`—▶`,"-->":`⋯⋯`,"-->>":`⋯▶`,"-x":`—✕`,"--x":`⋯✕`,"-)":`—⟩`,"--)":`⋯⟩`};return[{icon:p.arrowRight,title:`Message type`,panel:{title:`Message type`,items:e.map(e=>({glyph:r[e.op],title:e.label,selected:t.stmt.op===e.op,onClick:()=>this.editor.dispatch({type:`seq.setMessageOp`,eventId:n,op:e.op})}))}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`seq.reverseMessage`,eventId:n})},{icon:p.group,title:`Wrap in fragment`,panel:{title:`Fragment`,items:[`loop`,`alt`,`opt`,`par`,`critical`,`break`,`rect`].map(e=>({glyph:e,title:`Wrap in ${e}`,onClick:()=>this.editor.dispatch({type:`seq.wrapInFragment`,eventId:n,kind:e})}))}},o,a]}return[o,a]}return[]}computeDropSlots(){let e=this.editor.result.sequence;if(this.dropSlots=[],!e||!this.seqCorrelation)return;let t=e.events.map(e=>{let t=this.seqCorrelation.events.get(e.entityId);if(!t)return null;let n=this.hostRect(t);return{ev:e,y:n.top+n.height/2}}).filter(e=>e!==null);if(t.length){this.dropSlots.push({y:t[0].y-24,afterEvent:null});for(let e=1;e<t.length;e++)this.dropSlots.push({y:(t[e-1].y+t[e].y)/2,afterEvent:t[e-1].ev.entityId});this.dropSlots.push({y:t[t.length-1].y+24,afterEvent:t[t.length-1].ev.entityId})}}nearestSlot(e){let t=null,n=1/0;for(let r of this.dropSlots){let i=Math.abs(r.y-e);i<n&&(n=i,t=r)}return t}showDropIndicator(e){this.dropIndicator||(this.dropIndicator=document.createElement(`div`),this.dropIndicator.className=`mw-drop-indicator`,this.overlayHost.appendChild(this.dropIndicator)),this.dropIndicator.style.top=`${e}px`}plusHovered=!1;lifelineClearTimer=null;onLifelineHover(e){if(this.readOnly||!this.seqCorrelation||this.connectSource||!this.editor.result.sequence)return;let t=null;for(let[n,r]of this.seqCorrelation.lifelines){let i=r.getBoundingClientRect(),a=i.left+i.width/2;if(Math.abs(e.clientX-a)<=16&&e.clientY>=i.top-8&&e.clientY<=i.bottom+8){t=n;break}}t!==this.hoveredLifeline&&(t?this.showLifelinePlus(t):this.scheduleLifelineClear())}showLifelinePlus(e){this.clearLifelineUi();let t=this.editor.result.sequence,n=this.seqCorrelation?.lifelines.get(e);if(!t||!n)return;this.hoveredLifeline=e;let r=e.slice(12),i=this.hostRect(n),a=i.left+i.width/2,o=[],s=t.events.map(e=>{let t=this.seqCorrelation?.events.get(e.entityId);if(!t)return null;let n=this.hostRect(t);return{ev:e,y:n.top+n.height/2}}).filter(e=>e!==null);if(s.length===0)o.push({y:i.top+i.height/2,afterEvent:null});else{o.push({y:(i.top+s[0].y)/2,afterEvent:null});for(let e=1;e<s.length;e++)o.push({y:(s[e-1].y+s[e].y)/2,afterEvent:s[e-1].ev.entityId});o.push({y:(s[s.length-1].y+i.top+i.height)/2,afterEvent:s[s.length-1].ev.entityId})}for(let e of o){let t=document.createElement(`button`);t.type=`button`,t.className=`mw-lifeline-plus`,t.textContent=`+`,t.title=`Click to insert here · drag to another participant to connect`,t.style.left=`${a}px`,t.style.top=`${e.y}px`,t.addEventListener(`pointerenter`,()=>{this.plusHovered=!0}),t.addEventListener(`pointerleave`,()=>{this.plusHovered=!1,this.scheduleLifelineClear()}),t.addEventListener(`pointerdown`,t=>{t.stopPropagation(),this.beginPlusDrag(t,r,e.afterEvent)}),t.addEventListener(`click`,n=>{if(n.stopPropagation(),this.plusDragConsumedClick){this.plusDragConsumedClick=!1;return}this.openPlusMenu(t,r,e.afterEvent)}),this.overlayHost.appendChild(t),this.plusButtons.push(t)}}plusDragConsumedClick=!1;plusDragCleanup=null;beginPlusDrag(e,t,n){if(this.readOnly)return;let r=e.clientX,i=e.clientY,a=!1,o=(e,t)=>{let n=document.elementFromPoint(e,t);for(;n&&n!==this.container;){let e=n.getAttribute?.(`data-mw-entity`);if(e?.startsWith(`participant:`))return e.slice(12);n=n.parentElement}if(this.seqCorrelation)for(let[n,r]of this.seqCorrelation.lifelines){let i=r.getBoundingClientRect(),a=i.left+i.width/2;if(Math.abs(e-a)<=24&&t>=i.top-8&&t<=i.bottom+8)return n.slice(12)}return null},s=e=>{if(!a&&Math.hypot(e.clientX-r,e.clientY-i)<=4||(a||(a=!0,this.plusMenu?.remove(),this.plusMenu=null),!this.svg))return;let t=this.clientToSvg(r,i),n=this.clientToSvg(e.clientX,e.clientY);!t||!n||(this.ghostPath||(this.ghostPath=document.createElementNS(`http://www.w3.org/2000/svg`,`line`),this.ghostPath.classList.add(`mw-ghost-edge`),this.svg.appendChild(this.ghostPath)),this.ghostPath.setAttribute(`x1`,String(t.x)),this.ghostPath.setAttribute(`y1`,String(t.y)),this.ghostPath.setAttribute(`x2`,String(n.x)),this.ghostPath.setAttribute(`y2`,String(n.y)))},c=()=>{this.plusDragCleanup=null,document.removeEventListener(`pointermove`,s),document.removeEventListener(`pointerup`,l),document.removeEventListener(`pointercancel`,l),this.ghostPath?.remove(),this.ghostPath=null},l=e=>{if(c(),!a)return;this.plusDragConsumedClick=!0,setTimeout(()=>{this.plusDragConsumedClick=!1},0),this.clearLifelineUi();let r=o(e.clientX,e.clientY);if(!r||r===t)return;let i=this.editor.dispatch({type:`seq.addMessage`,source:t,target:r,text:`message`,afterEvent:n},`canvas`);i?.created?.[0]&&(this.pendingEditEntity=i.created[0])};this.plusDragCleanup=c,document.addEventListener(`pointermove`,s),document.addEventListener(`pointerup`,l),document.addEventListener(`pointercancel`,l)}openPlusMenu(e,t,n){this.plusMenu?.remove();let r=document.createElement(`div`);r.className=`mw-plus-menu`,r.style.left=e.style.left,r.style.top=`${parseFloat(e.style.top)+12}px`,r.addEventListener(`pointerdown`,e=>e.stopPropagation());let i=(e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.textContent=e,n.addEventListener(`click`,e=>{e.stopPropagation(),this.clearLifelineUi(),t()}),r.appendChild(n)};i(`↩ Self message`,()=>{let e=this.editor.dispatch({type:`seq.addMessage`,source:t,target:t,text:`message`,afterEvent:n},`canvas`);e?.created?.[0]&&(this.pendingEditEntity=e.created[0])});let a=(e,r)=>i(e,()=>{let e=this.editor.dispatch({type:`seq.addNote`,participant:t,placement:r,text:`note`,afterEvent:n},`canvas`);e?.created?.[0]&&(this.pendingEditEntity=e.created[0])});a(`▭ Note over`,`over`),a(`▭ Note left`,`left of`),a(`▭ Note right`,`right of`),this.overlayHost.appendChild(r),this.plusMenu=r}scheduleLifelineClear(){this.lifelineClearTimer&&clearTimeout(this.lifelineClearTimer),this.lifelineClearTimer=setTimeout(()=>{!this.plusHovered&&!this.plusMenu&&this.clearLifelineUi()},400)}clearLifelineUi(){this.plusButtons.forEach(e=>e.remove()),this.plusButtons=[],this.plusMenu?.remove(),this.plusMenu=null,this.hoveredLifeline=null,this.plusHovered=!1}clientToSvg(e,t){if(!this.svg)return null;let n=this.svg.getScreenCTM();if(!n)return null;let r=new DOMPoint(e,t).matrixTransform(n.inverse());return{x:r.x,y:r.y}}entityCenter(e){let t=this.entityElement(e);if(!t)return null;let n=t.getBoundingClientRect();return this.clientToSvg(n.left+n.width/2,n.top+n.height/2)}async validate(){try{return await this.mermaid.parse(this.editor.code),!0}catch(e){let t=e instanceof Error?e.message.split(`
159
+ `,E=!1,D=0;function O(e){return(e.innerHTML??``).replace(/<br\s*\/?>/gi,`<br/>`).replace(/&nbsp;/gi,` `).trim()}function k(e){return(e.innerHTML??``).replace(/<br\s*\/?>/gi,`<br/>`)}function A(e){let t=window.getSelection();if(!t?.anchorNode||!e.contains(t.anchorNode))return-1;let n=document.createRange();return n.selectNodeContents(e),n.setEnd(t.anchorNode,t.anchorOffset),n.toString().length}function j(e,t){let n=window.getSelection();if(!n)return;let r=document.createRange(),i=Math.max(0,t),a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=a.nextNode();for(;o;){let e=o.textContent?.length??0;if(i<=e){r.setStart(o,i),r.collapse(!0),n.removeAllRanges(),n.addRange(r);return}i-=e,o=a.nextNode()}r.selectNodeContents(e),r.collapse(!1),n.removeAllRanges(),n.addRange(r)}var M=class{editor;container;mermaid;mermaidConfig;svgHost;overlayHost;errorBadge;correlation=null;seqCorrelation=null;popover;plusButtons=[];plusMenu=null;hoveredLifeline=null;svg=null;svgTransformObserver=null;visibilityRetryObserver=null;popoverFollowRaf=0;applyingOwnTransform=!1;popoverAnchorPick=null;tool=`select`;readOnly;debounceMs;defaultEdge;hooks;renderTimer=null;lastRenderedCode=``;disposers=[];listeners=new Map;connectSource=null;suppressNextClick=!1;lastPointerWasTouch=!1;tapTracker=null;suppressDblClickUntil=0;ghostPath=null;dragEvent=null;dragStartY=0;dragging=!1;dropIndicator=null;dropSlots=[];inlineInput=null;inlineHidden=null;pendingEditEntity=null;inPlaceSession=null;lastError=null;renderHeldByEdit=!1;panZoomEnabled;zoomScale=1;zoomTx=0;zoomTy=0;hasUserView=!1;svgSize=null;panSession=null;zoomControls=null;renderSeq=0;awaitingFonts=!1;destroyed=!1;constructor(e){if(this.editor=e.editor,this.container=e.container,this.mermaid=e.mermaid,this.readOnly=e.readOnly??!1,this.panZoomEnabled=e.panZoom??!1,this.debounceMs=e.debounceMs??200,this.defaultEdge=e.defaultEdge??{},this.hooks=e.hooks??{},this.mermaidConfig={startOnLoad:!1,...e.mermaidConfig},!E){let e=document.createElement(`style`);e.setAttribute(`data-mw`,``),e.textContent=T+h,document.head.appendChild(e),E=!0}this.container.classList.add(`mw-canvas`),this.container.tabIndex=0,e.accentColor&&this.container.style.setProperty(`--mw-accent`,e.accentColor),this.readOnly&&this.container.classList.add(`mw-readonly`),this.svgHost=document.createElement(`div`),this.svgHost.className=`mw-svg-host`,this.overlayHost=document.createElement(`div`),this.errorBadge=document.createElement(`div`),this.errorBadge.className=`mw-error-badge`,this.errorBadge.style.display=`none`,this.container.append(this.svgHost,this.overlayHost,this.errorBadge),this.popover=new m(this.overlayHost),this.mermaid.initialize(this.mermaidConfig),this.disposers.push(this.editor.on(`change`,()=>this.scheduleRender()),this.editor.on(`selectionChange`,()=>this.applySelectionStyles()));let t=e=>this.onKeyDown(e);this.container.addEventListener(`keydown`,t),this.disposers.push(()=>this.container.removeEventListener(`keydown`,t));let n=e=>{let t=e.target;!t||this.container.contains(t)||(this.inPlaceSession?.finish?.(!0),this.clearLifelineUi(),this.popover.hide(),this.editor.selection.length&&this.editor.clearSelection(`canvas`))};document.addEventListener(`pointerdown`,n,!0),this.disposers.push(()=>document.removeEventListener(`pointerdown`,n,!0)),this.panZoomEnabled&&this.setupPanZoom(),this.render()}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.listeners.get(e).delete(t)}emit(e,t){this.listeners.get(e)?.forEach(e=>e(t))}get currentTool(){return this.tool}get renderError(){return this.lastError}setTool(e){this.tool=e,this.container.classList.toggle(`mw-tool-connect`,e===`connect`),this.cancelConnect(),this.emit(`toolChange`,e)}setReadOnly(e){this.readOnly=e,this.container.classList.toggle(`mw-readonly`,e),this.closeInlineEditor(!1),this.cancelConnect(),this.clearLifelineUi(),this.updatePopover()}setHooks(e){this.hooks=e}setAccentColor(e){this.container.style.setProperty(`--mw-accent`,e)}setMermaidConfig(e){this.mermaidConfig={...this.mermaidConfig,...e},this.mermaid.initialize(this.mermaidConfig),this.lastRenderedCode=``,this.render()}addNode(e=`rect`,t=`New node`){if(this.readOnly)return;let n=this.editor.dispatch({type:`addNode`,shape:e,label:t})?.created?.[0];n&&(this.pendingEditEntity=n)}scheduleRender(){this.renderTimer&&clearTimeout(this.renderTimer),this.renderTimer=setTimeout(()=>void this.render(),this.debounceMs)}setupPanZoom(){this.container.classList.add(`mw-panzoom`);let e=e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault();let t=Math.max(-40,Math.min(40,e.deltaY));this.zoomAt(e.clientX,e.clientY,Math.exp(-t*.01))};this.container.addEventListener(`wheel`,e,{passive:!1}),this.disposers.push(()=>this.container.removeEventListener(`wheel`,e));let t=new Map,n=0,r=e=>{if(e.pointerType===`touch`&&(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===2)){let[e,r]=[...t.values()];n=Math.hypot(e.x-r.x,e.y-r.y),this.panSession=null,this.container.classList.remove(`mw-panning`),this.suppressNextClick=!0,this.popover.hide();return}if(e.button!==0||this.tool===`connect`||e.altKey||this.inlineInput||this.inPlaceSession)return;let r=e.target;if(!r||!this.svgHost.contains(r))return;let i=r;for(;i&&i!==this.container;){if(i.getAttribute?.(`data-mw-entity`))return;i=i.parentElement}this.panSession={pointerId:e.pointerId,x:e.clientX,y:e.clientY,tx:this.zoomTx,ty:this.zoomTy,moved:!1}},i=e=>{if(e.pointerType===`touch`&&t.has(e.pointerId)&&(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size>=2&&n>0)){let[e,r]=[...t.values()],i=Math.hypot(e.x-r.x,e.y-r.y);i>0&&(this.zoomAt((e.x+r.x)/2,(e.y+r.y)/2,i/n),n=i,this.suppressNextClick=!0);return}let r=this.panSession;if(!r||e.pointerId!==r.pointerId)return;let i=e.clientX-r.x,a=e.clientY-r.y;if(!r.moved&&Math.hypot(i,a)>4){r.moved=!0,this.container.classList.add(`mw-panning`);try{this.container.setPointerCapture(e.pointerId)}catch{}this.popover.hide()}r.moved&&(this.zoomTx=r.tx+i,this.zoomTy=r.ty+a,this.hasUserView=!0,this.applyViewTransform())},a=e=>{e.pointerType===`touch`&&(t.delete(e.pointerId),t.size<2&&(n=0));let r=this.panSession;!r||e.pointerId!==r.pointerId||(this.panSession=null,this.container.classList.remove(`mw-panning`),r.moved?(this.suppressNextClick=!0,this.updatePopover()):this.editor.selection.length&&this.editor.clearSelection(`canvas`))};this.container.addEventListener(`pointerdown`,r),this.container.addEventListener(`pointermove`,i),this.container.addEventListener(`pointerup`,a),this.container.addEventListener(`pointercancel`,a),this.disposers.push(()=>{this.container.removeEventListener(`pointerdown`,r),this.container.removeEventListener(`pointermove`,i),this.container.removeEventListener(`pointerup`,a),this.container.removeEventListener(`pointercancel`,a)});let o=document.createElement(`div`);o.className=`mw-zoom-controls`;let s=(e,t,n)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`mw-zoom-btn`,r.title=e,r.innerHTML=t,r.addEventListener(`pointerdown`,e=>e.stopPropagation()),r.addEventListener(`click`,e=>{e.stopPropagation(),n()}),o.appendChild(r)};if(s(`Zoom out`,p.minus,()=>this.zoomBy(1/1.25)),s(`Zoom in`,p.plus,()=>this.zoomBy(1.25)),s(`Fit diagram`,p.maximize,()=>this.fitView()),this.container.appendChild(o),this.zoomControls=o,typeof ResizeObserver<`u`){let e=new ResizeObserver(()=>{this.hasUserView||this.fitView()});e.observe(this.container),this.disposers.push(()=>e.disconnect())}}zoomBy(e){let t=this.container.getBoundingClientRect();this.zoomAt(t.left+t.width/2,t.top+t.height/2,e)}zoomAt(e,t,n){if(!this.panZoomEnabled)return;let r=this.container.getBoundingClientRect(),i=e-r.left,a=t-r.top,o=Math.min(Math.max(this.zoomScale*n,.1),4),s=o/this.zoomScale;s!==1&&(this.zoomTx=i-(i-this.zoomTx)*s,this.zoomTy=a-(a-this.zoomTy)*s,this.zoomScale=o,this.hasUserView=!0,this.applyViewTransform(),this.updatePopover())}fitView(){if(!this.panZoomEnabled||!this.svg||!this.svgSize)return;let e=this.container.clientWidth,t=this.container.clientHeight;if(!e||!t)return;let{width:n,height:r}=this.svgSize,i=Math.min((e-56)/n,(t-56)/r);this.zoomScale=Math.min(Math.max(i,.1),2),this.zoomTx=(e-n*this.zoomScale)/2,this.zoomTy=(t-r*this.zoomScale)/2,this.hasUserView=!1,this.applyViewTransform(),this.updatePopover()}applyViewTransform(){this.svg&&(this.applyingOwnTransform=!0,this.svg.style.transform=`translate(${this.zoomTx}px, ${this.zoomTy}px) scale(${this.zoomScale})`,queueMicrotask(()=>{this.applyingOwnTransform=!1}))}prepareSvgForPanZoom(){let e=this.svg;if(!e)return;let t=0,n=0,r=e.viewBox?.baseVal;if(r&&r.width&&r.height)t=r.width,n=r.height;else{let r=e.getBBox?.();t=r?.width||800,n=r?.height||600}this.svgSize={width:t,height:n},e.removeAttribute(`width`),e.removeAttribute(`height`),e.style.width=`${t}px`,e.style.height=`${n}px`,e.style.maxWidth=`none`,this.hasUserView?this.applyViewTransform():this.fitView()}async render(){if(this.inPlaceSession){this.renderHeldByEdit=!0;return}let e=this.editor.code;if(e===this.lastRenderedCode){this.lastError&&(this.lastError=null,this.errorBadge.style.display=`none`,this.editor.setDiagnostics([]),this.emit(`render`,{ok:!0}));return}let t=++this.renderSeq,n=`mw-render-${++D}`;try{this.mermaid.initialize(this.mermaidConfig);let{svg:r}=await this.mermaid.render(n,e);if(t!==this.renderSeq)return;let i=null,a=this.activeInPlaceSession(),o=a?.label;if(a&&o?.isConnected&&(i={value:k(o),nodes:[...o.childNodes],caret:A(o)},a.liveTimer&&=(clearTimeout(a.liveTimer),null)),this.lastRenderedCode=e,this.lastError=null,this.errorBadge.style.display=`none`,this.svgHost.innerHTML=r,this.svg=this.svgHost.querySelector(`svg`),this.svg&&(this.panZoomEnabled?this.prepareSvgForPanZoom():this.svg.style.maxWidth=`100%`,w(this.svg),this.bindSvg()),this.editor.setDiagnostics([]),this.emit(`render`,{ok:!0}),this.remeasureWhenFontsSettle(),this.activeInPlaceSession())this.resumeInPlaceSession(i);else if(this.pendingEditEntity){let e=this.pendingEditEntity;this.pendingEditEntity=null,this.editor.entityExists(e)&&this.editEntityLabel(e)}}catch(e){if(t!==this.renderSeq)return;document.getElementById(`d${n}`)?.remove(),document.getElementById(n)?.remove();let r=e instanceof Error?e.message.split(`
160
+ `)[0]:String(e);this.lastError=r,this.errorBadge.textContent=`render error: ${r}`,this.errorBadge.style.display=`block`;let i={message:r,span:null,severity:`error`,source:`mermaid`};this.editor.setDiagnostics([i]),this.emit(`render`,{ok:!1,error:r})}}remeasureWhenFontsSettle(){let e=typeof document>`u`?void 0:document.fonts;if(!e||this.awaitingFonts||e.status===`loaded`)return;this.awaitingFonts=!0;let t=()=>{this.awaitingFonts=!1,!this.destroyed&&(this.lastRenderedCode=``,this.render())};Promise.resolve(e.ready).then(t,t)}bindSvg(){let e=this.svg;if(!e)return;let{flowchart:t,sequence:n,state:r,classGraph:f,er:p}=this.editor.result;this.correlation=t?i(e,t):r?a(e,r):f?o(e,f):p?s(e,p):this.editor.result.pie?c(e,this.editor.result.pie):this.editor.result.gantt?l(e,this.editor.result.gantt):this.editor.result.lineItems?u(e,this.editor.result.lineItems):null,this.seqCorrelation=n?d(e,n):null,this.clearLifelineUi(),this.armVisibilityRetry(e,n),e.addEventListener(`click`,e=>this.onSvgClick(e)),e.addEventListener(`dblclick`,e=>this.onSvgDblClick(e)),e.addEventListener(`pointerdown`,e=>this.onSvgPointerDown(e)),e.addEventListener(`pointermove`,e=>this.onSvgPointerMove(e)),e.addEventListener(`pointerup`,e=>this.onSvgPointerUp(e)),this.seqCorrelation&&(e.addEventListener(`pointermove`,e=>this.onLifelineHover(e)),e.addEventListener(`pointerleave`,()=>this.scheduleLifelineClear())),this.svgTransformObserver?.disconnect(),typeof MutationObserver<`u`&&(this.svgTransformObserver=new MutationObserver(()=>{this.applyingOwnTransform||this.popoverFollowRaf||!this.popover.isOpen||(this.popoverFollowRaf=(typeof requestAnimationFrame==`function`?requestAnimationFrame:e=>setTimeout(e,16))(()=>{this.popoverFollowRaf=0,this.updatePopover()}))}),this.svgTransformObserver.observe(e,{attributes:!0,attributeFilter:[`style`,`transform`],subtree:!0})),this.applySelectionStyles()}armVisibilityRetry(e,t){this.visibilityRetryObserver?.disconnect(),this.visibilityRetryObserver=null,t&&(this.seqCorrelation&&this.seqCorrelation.lifelines.size>0||typeof IntersectionObserver>`u`||(this.visibilityRetryObserver=new IntersectionObserver(n=>{n.some(e=>e.intersectionRatio>0)&&e.getBoundingClientRect().width!==0&&(this.visibilityRetryObserver?.disconnect(),this.visibilityRetryObserver=null,this.svg===e&&(this.seqCorrelation=d(e,t)))}),this.visibilityRetryObserver.observe(e)))}entityFromEvent(e){return this.entityHitFromEvent(e)?.id??null}entityHitFromEvent(e){let t=e.target;for(;t&&t!==this.svg;){let e=t.getAttribute?.(`data-mw-entity`);if(e)return{id:e,el:t};t=t.parentElement}return null}topmostEntityElement(e){let t=null,n=1/0;return this.svg?.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`).forEach(e=>{let r=e.getBoundingClientRect().top;r<n&&(n=r,t=e)}),t}onSvgClick(e){if(this.suppressNextClick){this.suppressNextClick=!1;return}if(this.inlineInput||this.inPlaceSession)return;let t=this.entityHitFromEvent(e);if(t){if(this.lastPointerWasTouch&&!this.readOnly){let n=Date.now(),r=this.tapTracker;if(this.tapTracker={entity:t.id,time:n},r&&r.entity===t.id&&n-r.time<400){this.tapTracker=null,this.onSvgDblClick(e),this.suppressDblClickUntil=n+500;return}}let n=t.id;if(this.hooks.onEntityClick?.(n,e),this.popoverAnchorPick={entityId:n,index:this.entityElementIndex(n,t.el)},e.shiftKey||e.metaKey||e.ctrlKey){let e=this.editor.selection.includes(n)?this.editor.selection.filter(e=>e!==n):[...this.editor.selection,n];this.editor.setSelection(e,`canvas`)}else this.editor.setSelection([n],`canvas`),this.updatePopover();this.container.focus({preventScroll:!0})}else this.editor.clearSelection(`canvas`)}entityElementIndex(e,t){if(!this.svg)return 0;let n=[...this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`)].indexOf(t);return n>=0?n:0}onSvgDblClick(e){if(this.readOnly||Date.now()<this.suppressDblClickUntil)return;let t=e.target.closest?.(`[data-mw-member-line]`);if(t&&this.editor.result.classGraph){let n=t.getAttribute(`data-mw-member-class`),r=Number(t.getAttribute(`data-mw-member-line`)),i=this.editor.result.classGraph.classById.get(n)?.members.find(e=>e.lineIndex===r);if(i){e.preventDefault(),this.popover.hide(),this.editInPlace(`member:${n}:${r}`,t,`.nodeLabel`,i.text,e=>this.editor.dispatch({type:`cl.setMemberText`,id:n,memberLine:r,text:e},`canvas`),{live:!1});return}}let n=e.target.closest?.(`[data-mw-attr-line]`);if(n&&this.editor.result.er){let t=n.getAttribute(`data-mw-attr-entity`),r=Number(n.getAttribute(`data-mw-attr-line`)),i=this.editor.result.er.entityById.get(t)?.attributes.find(e=>e.lineIndex===r);if(i){e.preventDefault(),this.popover.hide(),this.openOverlayEditor(n,i.text,e=>this.editor.dispatch({type:`er.setAttributeText`,id:t,attrLine:r,text:e},`canvas`));return}}let r=this.entityHitFromEvent(e);r&&(e.preventDefault(),!this.hooks.onEntityDoubleClick?.(r.id)&&this.editEntityLabel(r.id,r.el))}onSvgPointerDown(e){if(this.readOnly)return;let t=this.entityFromEvent(e),n=t?.startsWith(`node:`)||t?.startsWith(`state:`)||t?.startsWith(`class:`)||t?.startsWith(`entity:`),r=this.tool===`connect`||e.altKey;if(n&&r&&t){e.preventDefault(),this.connectSource=t,this.svg?.setPointerCapture?.(e.pointerId),this.entityElement(t)?.classList.add(`mw-connect-source`),this.emit(`connectPreview`,{source:t});return}t?.startsWith(`event:`)&&this.editor.result.sequence&&e.detail<=1&&(this.dragEvent=t,this.dragStartY=e.clientY,this.dragging=!1)}entityElement(e){return this.svg?.querySelector(`[data-mw-entity="${CSS.escape(e)}"]`)??null}onSvgPointerMove(e){if(this.dragEvent&&this.svg){if(!this.dragging&&Math.abs(e.clientY-this.dragStartY)>8&&(this.dragging=!0,this.svg.setPointerCapture?.(e.pointerId),this.computeDropSlots(),this.popover.hide()),this.dragging){let t=this.container.getBoundingClientRect(),n=e.clientY-t.top+this.container.scrollTop,r=this.nearestSlot(n);r&&this.showDropIndicator(r.y)}return}if(!this.connectSource||!this.svg)return;let t=this.entityCenter(this.connectSource),n=this.clientToSvg(e.clientX,e.clientY);!t||!n||(this.ghostPath||(this.ghostPath=document.createElementNS(`http://www.w3.org/2000/svg`,`line`),this.ghostPath.classList.add(`mw-ghost-edge`),this.svg.appendChild(this.ghostPath)),this.ghostPath.setAttribute(`x1`,String(t.x)),this.ghostPath.setAttribute(`y1`,String(t.y)),this.ghostPath.setAttribute(`x2`,String(n.x)),this.ghostPath.setAttribute(`y2`,String(n.y)))}onSvgPointerUp(e){if(this.lastPointerWasTouch=e.pointerType===`touch`,this.dragEvent){let t=this.dragEvent,n=this.dragging;if(this.dragEvent=null,this.dragging=!1,this.dropIndicator?.remove(),this.dropIndicator=null,n){this.suppressNextClick=!0;let n=this.container.getBoundingClientRect(),r=this.nearestSlot(e.clientY-n.top+this.container.scrollTop);r&&this.editor.dispatch({type:`seq.moveEvent`,eventId:t,afterEvent:r.afterEvent})}return}if(!this.connectSource)return;let t=this.connectSource,n=t.startsWith(`node:`)?`node:`:t.startsWith(`state:`)?`state:`:t.startsWith(`class:`)?`class:`:`entity:`,r=document.elementFromPoint(e.clientX,e.clientY),i=null,a=r;for(;a&&a!==this.container;){let e=a.getAttribute?.(`data-mw-entity`);if(e?.startsWith(n)){i=e;break}a=a.parentElement}this.cancelConnect(),this.suppressNextClick=!0,i&&i!==t&&n===`node:`?this.editor.dispatch({type:`connect`,source:t.slice(5),target:i.slice(5),line:this.defaultEdge.line,arrowEnd:this.defaultEdge.arrowEnd}):i&&i!==t&&n===`state:`?this.editor.dispatch({type:`st.connect`,source:t.slice(6),target:i.slice(6)}):i&&i!==t&&n===`class:`?this.editor.dispatch({type:`cl.connect`,source:t.slice(6),target:i.slice(6)}):i&&i!==t&&n===`entity:`?this.editor.dispatch({type:`er.connect`,source:t.slice(7),target:i.slice(7)}):(this.editor.setSelection([t],`canvas`),this.container.focus({preventScroll:!0}))}cancelConnect(){this.connectSource&&this.entityElement(this.connectSource)?.classList.remove(`mw-connect-source`),this.connectSource=null,this.ghostPath?.remove(),this.ghostPath=null,this.emit(`connectPreview`,{source:null})}editEntityLabel(e,t){if(this.readOnly)return;let{flowchart:n,sequence:r}=this.editor.result;this.closeInlineEditor(!1),this.inPlaceSession&&this.inPlaceSession.entityId!==e&&this.inPlaceSession.finish?.(!0),this.popover.hide();let i=t&&t.getAttribute(`data-mw-entity`)===e?t:null,a=null,o=``,s=()=>{};if(n&&e.startsWith(`node:`)){let t=n.nodeById.get(e.slice(5));if(!t||(o=t.label,a=this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`renameNode`,id:t.id,label:e},`canvas`),a&&this.editInPlace(e,a,`.nodeLabel`,o,s)))return}else if(n&&e.startsWith(`edge:`)){let t=n.edges.find(t=>t.entityId===e);if(!t||(o=t.label??``,s=t=>this.editor.dispatch({type:`setEdgeLabel`,edgeId:e,label:t},`canvas`),a=this.edgeAnchor(e,!!t.label),t.label&&a&&this.editInPlace(e,a,`.edgeLabel`,o,s)))return}else if(n&&e.startsWith(`subgraph:`)){let t=n.subgraphs.find(t=>t.entityId===e);if(!t)return;o=t.title??t.id,a=this.correlation?.nodes.get(e)?.querySelector(`.cluster-label`)??i??this.correlation?.nodes.get(e)??this.svg?.querySelector(`#${CSS.escape(t.id)}`)??null,s=e=>this.editor.dispatch({type:`renameSubgraph`,id:t.id,title:e},`canvas`)}else if(this.editor.result.state&&e.startsWith(`state:`)){let t=this.editor.result.state.stateById.get(e.slice(6));if(!t||(o=t.label,a=this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`st.setStateLabel`,id:t.id,label:e},`canvas`),a&&this.editInPlace(e,a,`.nodeLabel`,o,s)))return}else if(this.editor.result.state&&e.startsWith(`trans:`)){let t=this.editor.result.state.transitions.find(t=>t.entityId===e);if(!t||(o=t.label??``,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`st.setTransitionLabel`,transId:e,label:t},`canvas`),t.label&&a&&this.editInPlace(e,a,`.edgeLabel`,o,s)))return}else if(this.editor.result.classGraph&&e.startsWith(`class:`)){let t=this.editor.result.classGraph.classById.get(e.slice(6));if(!t)return;o=t.id,a=i??this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`cl.renameClass`,id:t.id,name:e},`canvas`)}else if(this.editor.result.classGraph&&e.startsWith(`rel:`)){let t=this.editor.result.classGraph.relations.find(t=>t.entityId===e);if(!t)return;o=t.label??``,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`cl.setRelationLabel`,relId:e,label:t},`canvas`)}else if(this.editor.result.er&&e.startsWith(`entity:`)){let t=this.editor.result.er.entityById.get(e.slice(7));if(!t)return;o=t.id,a=i??this.correlation?.nodes.get(e)??null,s=e=>this.editor.dispatch({type:`er.renameEntity`,id:t.id,name:e},`canvas`)}else if(this.editor.result.er&&e.startsWith(`erel:`)){let t=this.editor.result.er.relations.find(t=>t.entityId===e);if(!t)return;o=t.label,a=this.edgeAnchor(e,!!t.label),s=t=>this.editor.dispatch({type:`er.setRelationLabel`,relId:e,label:t},`canvas`)}else if(this.editor.result.pie&&e.startsWith(`slice:`)){let t=this.editor.result.pie.slices.find(t=>t.entityId===e);if(!t)return;o=String(t.value),a=i??this.entityElement(e),s=t=>{let n=Number(t);Number.isFinite(n)&&this.editor.dispatch({type:`pie.setValue`,sliceId:e,value:n},`canvas`)}}else if(this.editor.result.gantt&&e.startsWith(`task:`)){let t=this.editor.result.gantt.tasks.find(t=>t.entityId===e);if(!t)return;o=t.name,a=i??this.entityElement(e),s=t=>this.editor.dispatch({type:`gantt.setTaskName`,taskId:e,name:t},`canvas`)}else if(this.editor.result.lineItems&&e.startsWith(`item:`)){let t=this.editor.result.lineItems.items.find(t=>t.entityId===e);if(!t)return;o=t.text,a=i??this.entityElement(e),s=t=>this.editor.dispatch({type:`li.setLine`,itemId:e,text:t},`canvas`)}else if(r&&e.startsWith(`participant:`)){let t=r.participantById.get(e.slice(12));if(!t)return;o=t.label,a=i??this.topmostEntityElement(e),s=e=>this.editor.dispatch({type:`seq.renameParticipant`,id:t.id,name:e},`canvas`)}else if(r&&e.startsWith(`event:`)){let t=r.events.find(t=>t.entityId===e);if(!t)return;o=t.stmt.text,a=this.seqCorrelation?.eventTexts.get(e)??i??this.entityElement(e),s=t=>this.editor.dispatch({type:`seq.setEventText`,eventId:e,text:t},`canvas`)}a&&this.openOverlayEditor(a,o,s)}editInPlace(e,t,n,r,i,a={}){let o=t.matches?.(n)?t.querySelector(`p`)??t:t.querySelector(`${n} p`)??t.querySelector(n);if(!o||!(o instanceof HTMLElement))return!1;let s=this.inPlaceSession?.entityId===e;if(s&&this.inPlaceSession.label===o&&o.isConnected)return o.focus(),!0;s||(this.inPlaceSession={entityId:e,labelSelector:n,original:r,originalNodes:[...o.childNodes].map(e=>e.cloneNode(!0)),openedOn:o,lastCommitted:r,caretOffset:-1,commitValue:i,liveTimer:null,label:null,finish:null});let c=this.inPlaceSession;c.label=o,o.setAttribute(`contenteditable`,`true`);let l=o.closest(`foreignObject`),u=o.style.whiteSpace,d=l?.style.overflow??``;if(o.style.whiteSpace=`nowrap`,l&&(l.style.overflow=`visible`),o.focus(),s&&c.caretOffset>=0)j(o,c.caretOffset);else{let e=window.getSelection(),t=document.createRange();t.selectNodeContents(o),e?.removeAllRanges(),e?.addRange(t)}let f=()=>{let e=A(o);e>=0&&(c.caretOffset=e)},p=()=>{if(this.inPlaceSession!==c)return;let e=O(o);!e||e===c.lastCommitted||(f(),c.lastCommitted=e,c.commitValue(e))},m=e=>{if(this.inPlaceSession!==c)return;this.inPlaceSession=null,c.liveTimer&&clearTimeout(c.liveTimer),o.removeAttribute(`contenteditable`),o.style.whiteSpace=u,l&&(l.style.overflow=d),o.removeEventListener(`keydown`,g),o.removeEventListener(`blur`,_),o.removeEventListener(`input`,h);let t=O(o);e?t&&t!==c.lastCommitted?c.commitValue(t):t||(o.textContent=c.lastCommitted):(o.replaceChildren(...c.originalNodes),c.lastCommitted!==c.original&&c.commitValue(c.original),o!==c.openedOn&&(this.lastRenderedCode=``,this.scheduleRender())),this.renderHeldByEdit&&(this.renderHeldByEdit=!1,this.scheduleRender()),this.updatePopover()},h=()=>{a.live!==!1&&(c.liveTimer&&clearTimeout(c.liveTimer),c.liveTimer=setTimeout(p,450))},g=e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),m(!0)):e.key===`Escape`&&m(!1)},_=()=>{setTimeout(()=>{this.inPlaceSession===c&&o.isConnected&&document.activeElement!==o&&m(!0)},60)};return c.finish=m,o.addEventListener(`keydown`,g),o.addEventListener(`blur`,_),o.addEventListener(`input`,h),!0}activeInPlaceSession(){return this.inPlaceSession}resumeInPlaceSession(e){let t=this.inPlaceSession;if(!t)return;if(!this.editor.entityExists(t.entityId)){this.inPlaceSession=null;return}let n=(t.entityId.startsWith(`edge:`)?this.correlation?.edgeLabels.get(t.entityId):null)??this.entityElement(t.entityId);if(!n){this.inPlaceSession=null;return}this.editInPlace(t.entityId,n,t.labelSelector,t.lastCommitted,t.commitValue);let r=this.inPlaceSession===t?t.label:null;!r||!e||(e.value&&e.value!==t.lastCommitted&&e.value!==k(r)&&(r.replaceChildren(...e.nodes),r.dispatchEvent(new Event(`input`))),e.caret>=0&&j(r,e.caret))}findTextTarget(e,t){let n=e=>(e.tagName===`text`||e.tagName===`SPAN`||e.tagName===`P`||e.tagName===`DIV`||e.tagName===`tspan`)&&(e.children.length===0||e.tagName===`text`)&&(e.textContent?.trim().length??0)>0;if(n(e))return e;let r=[...e.querySelectorAll(`text, tspan, span, p, div`)].filter(n);return!r.length&&e.parentElement&&(r=[...e.parentElement.querySelectorAll(`text, tspan, span, p, div`)].filter(n)),r.find(e=>e.textContent?.trim()===t.trim())??r.find(e=>t.trim().startsWith(e.textContent?.trim()??`\0`))??r[0]??e}openOverlayEditor(e,t,n){let r,i;typeof SVGPathElement<`u`&&e instanceof SVGPathElement?(r=this.pathMidpointRect(e),i=null):(e=this.findTextTarget(e,t),r=this.hostRect(e),i=e);let a=e.querySelector(`tspan`)??e,o=window.getComputedStyle(a),s=document.createElement(`div`);s.className=`mw-inplace-editor`,s.contentEditable=`true`,s.spellcheck=!1,s.textContent=t,s.style.left=`${r.left+r.width/2}px`,s.style.top=`${r.top}px`,s.style.transform=`translateX(-50%)`,s.style.textAlign=`center`,s.style.minWidth=`${Math.max(24,r.width)}px`,s.style.lineHeight=`${Math.max(r.height,12)}px`,s.style.fontStyle=o.fontStyle,s.style.fontWeight=o.fontWeight;let c=this.panZoomEnabled?this.zoomScale:1,l=Number.parseFloat(o.fontSize);s.style.fontSize=Number.isFinite(l)?`${l*c}px`:o.fontSize,s.style.fontFamily=o.fontFamily;let u=o.fill&&o.fill!==`none`&&a instanceof SVGElement?o.fill:o.color;if(s.style.color=u||`inherit`,this.overlayHost.appendChild(s),this.inlineInput=s,i){let e=i,t=e.style?.visibility??``;e.style&&(e.style.visibility=`hidden`),this.inlineHidden={el:e,prevVisibility:t}}s.focus();let d=document.createRange();d.selectNodeContents(s);let f=window.getSelection();f?.removeAllRanges(),f?.addRange(d);let p=()=>{let e=(s.textContent??``).trim(),r=this.inlineHidden?.el??null;this.closeInlineEditor(!1),e!==t&&(r&&(r.textContent=e),n(e))};s.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`&&(e.preventDefault(),p()),e.key===`Escape`&&this.closeInlineEditor(!1)}),s.addEventListener(`blur`,p)}closeInlineEditor(e){if(this.inlineHidden&&=(this.inlineHidden.el.style&&(this.inlineHidden.el.style.visibility=this.inlineHidden.prevVisibility),null),this.inlineInput){let t=this.inlineInput;this.inlineInput=null,t.remove(),e&&this.container.focus({preventScroll:!0})}}onKeyDown(e){if(!this.inlineInput){if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?this.editor.redo():this.editor.undo();return}if(!this.readOnly){if((e.key===`Delete`||e.key===`Backspace`)&&this.editor.selection.length){e.preventDefault(),this.editor.deleteEntities(this.editor.selection,`canvas`);return}if(e.key===`Escape`){this.cancelConnect(),this.editor.clearSelection(`canvas`);return}e.key===`Enter`&&this.editor.selection.length===1&&(e.preventDefault(),this.editEntityLabel(this.editor.selection[0]))}}}applySelectionStyles(){if(this.svg){this.svg.querySelectorAll(`.mw-selected`).forEach(e=>e.classList.remove(`mw-selected`));for(let e of this.editor.selection)this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(e)}"]`).forEach(e=>{e.classList.add(`mw-selected`)});this.updatePopover()}}edgeAnchor(e,t){let n=this.correlation?.edgeLabels,r=this.correlation?.edges;return t?n?.get(e)??r?.get(e)??null:r?.get(e)??n?.get(e)??null}hostRect(e){let t=e.getBoundingClientRect(),n=this.container.getBoundingClientRect();return{left:t.left-n.left+this.container.scrollLeft,top:t.top-n.top+this.container.scrollTop,width:t.width,height:t.height}}pathMidpointRect(e){let t=this.container.getBoundingClientRect(),n=typeof e.getScreenCTM==`function`&&typeof e.getTotalLength==`function`?e.getScreenCTM():null;if(!n)return this.hostRect(e);let r=e.getTotalLength(),i=e.getPointAtLength(r/2),a=new DOMPoint(i.x,i.y).matrixTransform(n),o=20*(this.panZoomEnabled?this.zoomScale:1);return{left:a.x-t.left+this.container.scrollLeft,top:a.y-t.top+this.container.scrollTop-o/2,width:0,height:o}}updatePopover(){if(this.popover.hide(),this.readOnly||this.inlineInput||this.inPlaceSession)return;let e=this.editor.selection;if(e.length!==1||!this.svg)return;let t=e[0],n=[...this.svg.querySelectorAll(`[data-mw-entity="${CSS.escape(t)}"]`)],r=null,i=this.popoverAnchorPick;if(i&&i.entityId===t&&n[i.index])r=n[i.index];else{let e=1/0;for(let t of n){let n=t.getBoundingClientRect().top;n<e&&(e=n,r=t)}}if(!r)return;let a=this.actionsFor(t);a.length&&this.popover.show(this.hostRect(r),a)}colorSection(e,t){return{title:e,columns:5,items:[...g.map(n=>({swatch:n,title:`${e}: ${n}`,onClick:()=>t(n)})),{swatch:`none`,title:`${e}: default`,onClick:()=>t(null)}]}}actionsFor(n){let{flowchart:r,sequence:i}=this.editor.result,a={icon:p.trash,title:`Delete`,danger:!0,onClick:()=>this.editor.deleteEntities([n])},o={icon:p.pencil,title:`Edit text`,onClick:()=>this.editEntityLabel(n)};if(r&&n.startsWith(`node:`)){let e=r.nodeById.get(n.slice(5));return e?[{icon:p.shapes,title:`Node shape`,panel:{title:`Node shape`,items:[{s:`rect`,g:`▭`,t:`Rectangle`},{s:`round`,g:`▢`,t:`Rounded`},{s:`stadium`,g:`⬭`,t:`Stadium`},{s:`diamond`,g:`◇`,t:`Diamond`},{s:`hexagon`,g:`⬡`,t:`Hexagon`},{s:`circle`,g:`◯`,t:`Circle`},{s:`cylinder`,g:`⛁`,t:`Cylinder`},{s:`subroutine`,g:`⧉`,t:`Subroutine`}].map(t=>({glyph:t.g,title:t.t,selected:e.shape===t.s,onClick:()=>this.editor.dispatch({type:`setNodeShape`,id:e.id,shape:t.s})}))}},{icon:p.palette,title:`Colors`,panel:{title:`Colors`,sections:[`fill`,`stroke`,`color`].map(t=>this.colorSection(t===`fill`?`Fill`:t===`stroke`?`Border`:`Text`,n=>this.editor.dispatch({type:`setNodeColor`,id:e.id,prop:t,value:n})))}},{icon:p.copy,title:`Duplicate`,onClick:()=>this.editor.dispatch({type:`duplicateNode`,id:e.id})},o,a]:[]}if(r&&n.startsWith(`subgraph:`))return[{icon:p.pencil,title:`Rename subgraph`,onClick:()=>this.editEntityLabel(n)}];if(r&&n.startsWith(`edge:`)){let e=r.edges.find(e=>e.entityId===n);if(!e)return[];let t=[{start:`open`,end:`open`,t:`No arrow`},{start:`open`,end:`arrow`,t:`Arrow`},{start:`arrow`,end:`arrow`,t:`Double point`},{start:`open`,end:`cross`,t:`Cross`},{start:`cross`,end:`cross`,t:`Double cross`},{start:`open`,end:`circle`,t:`Dot`},{start:`circle`,end:`circle`,t:`Double dot`}],i=[{line:`solid`,t:`Solid`},{line:`dotted`,t:`Dotted`},{line:`thick`,t:`Thick`},{line:`invisible`,t:`Invisible`}],s=[{v:`basis`,t:`Default (curved)`,label:`Default`,svg:b(`basis`)},{v:`natural`,t:`Natural spline`,label:`Natural`,svg:b(`natural`)},{v:`linear`,t:`Straight segments`,label:`Linear`,svg:b(`linear`)}],c=[{v:`none`,t:`No animation`,label:`None`,svg:x(`none`)},{v:`slow`,t:`Slow flow`,label:`Slow`,svg:x(`slow`)},{v:`fast`,t:`Fast flow`,label:`Fast`,svg:x(`fast`)}],l=S(this.editor.code),u=C(this.editor.code,e.order);return[{icon:p.arrowRight,title:`Arrow`,panel:{title:`Arrow`,sections:[{columns:4,items:t.map(t=>({svg:_(e.seg.line,t.start,t.end),title:t.t,selected:e.seg.arrowStart===t.start&&e.seg.arrowEnd===t.end,onClick:()=>this.editor.dispatch({type:`setEdgeStyle`,edgeId:n,arrowStart:t.start,arrowEnd:t.end})}))}]}},{icon:p.equal,title:`Stroke`,panel:{title:`Stroke`,sections:[{columns:4,items:i.map(t=>({svg:y(t.line),title:t.t,label:t.t,selected:e.seg.line===t.line,onClick:()=>this.editor.dispatch({type:`setEdgeStyle`,edgeId:n,line:t.line})}))}]}},{icon:p.palette,title:`Edge color`,panel:{title:`Edge color`,sections:[this.colorSection(`Stroke`,e=>this.editor.dispatch({type:`setEdgeColor`,edgeId:n,value:e}))]}},{icon:p.circlePlay,title:`Animate edge`,panel:{title:`Animate edge`,sections:[{columns:3,items:c.map(e=>({svg:e.svg,title:e.t,label:e.label,selected:u===e.v,onClick:()=>this.editor.dispatch({type:`setEdgeAnimation`,edgeId:n,value:e.v})}))}]}},{icon:p.spline,title:`Edge curve (diagram-wide)`,panel:{title:`Edge curve`,sections:[{columns:3,items:s.map(e=>({svg:e.svg,title:e.t,label:e.label,selected:l===e.v,onClick:()=>this.editor.dispatch({type:`setFlowCurve`,value:e.v})}))}]}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`reverseEdge`,edgeId:n})},o,a]}if(this.editor.result.state&&n.startsWith(`state:`)){let e=this.editor.result.state.stateById.get(n.slice(6));return e?e.isComposite?[o]:[{icon:p.square,title:`State type`,panel:{title:`State type`,items:[{t:`state`,g:`▢`},{t:`choice`,g:`◇`},{t:`fork`,g:`⑃`},{t:`join`,g:`⑂`}].map(t=>({glyph:t.g,title:t.t,selected:(e.stereotype??`state`)===t.t,onClick:()=>this.editor.dispatch({type:`st.setStateType`,id:e.id,stype:t.t})}))}},{icon:p.stickyNote,title:`Add note`,panel:{title:`Note`,items:[`left`,`right`].map(t=>({glyph:t===`left`?`◧`:`◨`,title:`Note ${t}`,onClick:()=>this.editor.dispatch({type:`st.addStateNote`,id:e.id,side:t})}))}},{icon:p.frame,title:`Move to composite`,onClick:()=>this.editor.dispatch({type:`st.moveToComposite`,id:e.id})},o,a]:[]}if(this.editor.result.state&&n.startsWith(`trans:`))return[{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`st.reverseTransition`,transId:n})},o,a];if(this.editor.result.classGraph&&n.startsWith(`class:`)){let e=this.editor.result.classGraph.classById.get(n.slice(6));return e?[{icon:p.listPlus,title:`Add member`,onClick:()=>{this.editor.dispatch({type:`cl.addMember`,id:e.id,text:`+attribute`})}},{icon:p.braces,title:`Annotation`,panel:{title:`Annotation`,items:[...[`interface`,`abstract`,`service`,`enumeration`].map(t=>({glyph:t,title:`<<${t}>>`,onClick:()=>this.editor.dispatch({type:`cl.setAnnotation`,id:e.id,annotation:t})})),{glyph:`none`,title:`Remove annotation`,onClick:()=>this.editor.dispatch({type:`cl.setAnnotation`,id:e.id,annotation:null})}]}},{icon:p.stickyNote,title:`Add note`,onClick:()=>this.editor.dispatch({type:`cl.addNoteFor`,id:e.id})},{icon:p.pencil,title:`Rename class`,onClick:()=>this.editEntityLabel(n)},a]:[]}if(this.editor.result.classGraph&&n.startsWith(`rel:`)){let e=this.editor.result.classGraph.relations.find(e=>e.entityId===n);return e?[{icon:p.arrowRight,title:`Relation type`,panel:{title:`Relation type`,items:[{op:`<|--`,g:`◁—`,t:`inheritance`},{op:`*--`,g:`◆—`,t:`composition`},{op:`o--`,g:`◇—`,t:`aggregation`},{op:`-->`,g:`—▶`,t:`association`},{op:`--`,g:`——`,t:`link (solid)`},{op:`..>`,g:`⋯▶`,t:`dependency`},{op:`..|>`,g:`⋯▷`,t:`realization`},{op:`..`,g:`⋯⋯`,t:`link (dashed)`}].map(t=>({glyph:t.g,title:t.t,selected:e.stmt.op===t.op,onClick:()=>this.editor.dispatch({type:`cl.setRelationType`,relId:n,op:t.op})}))}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`cl.reverseRelation`,relId:n})},{glyph:`1:1`,title:`Cardinality (e.g. 1, 0..1, 1..*, *)`,onClick:()=>{let t=this.entityElement(n);if(!t)return;this.popover.hide();let r=`${e.stmt.sourceCard??``}:${e.stmt.targetCard??``}`;this.openOverlayEditor(t,r,t=>{let[r=``,i=``]=t.split(`:`);this.editor.dispatch({type:`cl.setCardinality`,relId:n,side:`source`,value:r.trim()||null},`canvas`);let a=this.editor.result.classGraph?.relations.find(t=>t.lineIndex===e.lineIndex&&t.source===e.source&&t.target===e.target);a&&this.editor.dispatch({type:`cl.setCardinality`,relId:a.entityId,side:`target`,value:i.trim()||null},`canvas`)})}},o,a]:[]}if(this.editor.result.er&&n.startsWith(`entity:`)){let e=this.editor.result.er.entityById.get(n.slice(7));return e?[{icon:p.listPlus,title:`Add attribute`,onClick:()=>this.editor.dispatch({type:`er.addAttribute`,id:e.id})},{icon:p.pencil,title:`Rename entity`,onClick:()=>this.editEntityLabel(n)},a]:[]}if(this.editor.result.er&&n.startsWith(`erel:`)){let e=this.editor.result.er.relations.find(e=>e.entityId===n);if(!e)return[];let t=[{c:`zero-or-one`,g:`0..1`},{c:`exactly-one`,g:`1`},{c:`zero-or-more`,g:`0..*`},{c:`one-or-more`,g:`1..*`}],r=r=>({icon:r===`left`?p.arrowLeftToLine:p.arrowRightToLine,title:`${r===`left`?`Source`:`Target`} cardinality`,panel:{title:`${r===`left`?e.source:e.target} cardinality`,items:t.map(e=>({glyph:e.g,title:e.c,onClick:()=>this.editor.dispatch({type:`er.setCardinality`,relId:n,side:r,card:e.c})}))}});return[r(`left`),r(`right`),{icon:e.stmt.line===`--`?p.minus:p.ellipsis,title:e.stmt.line===`--`?`Make non-identifying (dashed)`:`Make identifying (solid)`,onClick:()=>this.editor.dispatch({type:`er.setIdentifying`,relId:n,identifying:e.stmt.line!==`--`})},o,a]}if(this.editor.result.pie&&n.startsWith(`slice:`)){let e=this.editor.result.pie.slices.find(e=>e.entityId===n);return e?[{icon:p.hash,title:`Edit value`,onClick:()=>this.editEntityLabel(n)},{icon:p.pencil,title:`Edit label`,onClick:()=>{let t=this.entityElement(n);t&&(this.popover.hide(),this.openOverlayEditor(t,e.label,e=>this.editor.dispatch({type:`pie.setLabel`,sliceId:n,label:e},`canvas`)))}},a]:[]}if(this.editor.result.gantt&&n.startsWith(`task:`)){let e=this.editor.result.gantt.tasks.find(e=>e.entityId===n);return e?[{icon:p.pencil,title:`Rename task`,onClick:()=>this.editEntityLabel(n)},{icon:p.calendar,title:`Edit schedule (id, start, duration)`,onClick:()=>{let t=this.entityElement(n);t&&(this.popover.hide(),this.openOverlayEditor(t,e.meta,e=>this.editor.dispatch({type:`gantt.setTaskMeta`,taskId:n,meta:e},`canvas`)))}},a]:[]}if(this.editor.result.lineItems&&n.startsWith(`item:`))return[{icon:p.pencil,title:`Edit line`,onClick:()=>this.editEntityLabel(n)},a];if(i&&n.startsWith(`participant:`)){let e=i.participantById.get(n.slice(12));if(!e)return[];let r={participant:`▭`,actor:`웃`,boundary:`⊢○`,control:`◉`,entity:`◯`,database:`⛁`,collections:`⧉`,queue:`▤`};return[{icon:p.user,title:`Participant type`,panel:{title:`Participant type`,items:t.map(t=>({glyph:r[t],title:t,selected:e.ptype===t,onClick:()=>this.editor.dispatch({type:`seq.setParticipantType`,id:e.id,ptype:t})}))}},{icon:p.pencil,title:`Rename`,onClick:()=>this.editEntityLabel(n)},a]}if(i&&n.startsWith(`event:`)){let t=i.events.find(e=>e.entityId===n);if(!t)return[];if(t.kind===`message`){let r={"->":`——`,"->>":`—▶`,"-->":`⋯⋯`,"-->>":`⋯▶`,"-x":`—✕`,"--x":`⋯✕`,"-)":`—⟩`,"--)":`⋯⟩`};return[{icon:p.arrowRight,title:`Message type`,panel:{title:`Message type`,items:e.map(e=>({glyph:r[e.op],title:e.label,selected:t.stmt.op===e.op,onClick:()=>this.editor.dispatch({type:`seq.setMessageOp`,eventId:n,op:e.op})}))}},{icon:p.arrowLeftRight,title:`Reverse direction`,onClick:()=>this.editor.dispatch({type:`seq.reverseMessage`,eventId:n})},{icon:p.group,title:`Wrap in fragment`,panel:{title:`Fragment`,items:[`loop`,`alt`,`opt`,`par`,`critical`,`break`,`rect`].map(e=>({glyph:e,title:`Wrap in ${e}`,onClick:()=>this.editor.dispatch({type:`seq.wrapInFragment`,eventId:n,kind:e})}))}},o,a]}return[o,a]}return[]}computeDropSlots(){let e=this.editor.result.sequence;if(this.dropSlots=[],!e||!this.seqCorrelation)return;let t=e.events.map(e=>{let t=this.seqCorrelation.events.get(e.entityId);if(!t)return null;let n=this.hostRect(t);return{ev:e,y:n.top+n.height/2}}).filter(e=>e!==null);if(t.length){this.dropSlots.push({y:t[0].y-24,afterEvent:null});for(let e=1;e<t.length;e++)this.dropSlots.push({y:(t[e-1].y+t[e].y)/2,afterEvent:t[e-1].ev.entityId});this.dropSlots.push({y:t[t.length-1].y+24,afterEvent:t[t.length-1].ev.entityId})}}nearestSlot(e){let t=null,n=1/0;for(let r of this.dropSlots){let i=Math.abs(r.y-e);i<n&&(n=i,t=r)}return t}showDropIndicator(e){this.dropIndicator||(this.dropIndicator=document.createElement(`div`),this.dropIndicator.className=`mw-drop-indicator`,this.overlayHost.appendChild(this.dropIndicator)),this.dropIndicator.style.top=`${e}px`}plusHovered=!1;lifelineClearTimer=null;onLifelineHover(e){if(this.readOnly||!this.seqCorrelation||this.connectSource||!this.editor.result.sequence)return;let t=null;for(let[n,r]of this.seqCorrelation.lifelines){let i=r.getBoundingClientRect(),a=i.left+i.width/2;if(Math.abs(e.clientX-a)<=16&&e.clientY>=i.top-8&&e.clientY<=i.bottom+8){t=n;break}}t!==this.hoveredLifeline&&(t?this.showLifelinePlus(t):this.scheduleLifelineClear())}showLifelinePlus(e){this.clearLifelineUi();let t=this.editor.result.sequence,n=this.seqCorrelation?.lifelines.get(e);if(!t||!n)return;this.hoveredLifeline=e;let r=e.slice(12),i=this.hostRect(n),a=i.left+i.width/2,o=[],s=t.events.map(e=>{let t=this.seqCorrelation?.events.get(e.entityId);if(!t)return null;let n=this.hostRect(t);return{ev:e,y:n.top+n.height/2}}).filter(e=>e!==null);if(s.length===0)o.push({y:i.top+i.height/2,afterEvent:null});else{o.push({y:(i.top+s[0].y)/2,afterEvent:null});for(let e=1;e<s.length;e++)o.push({y:(s[e-1].y+s[e].y)/2,afterEvent:s[e-1].ev.entityId});o.push({y:(s[s.length-1].y+i.top+i.height)/2,afterEvent:s[s.length-1].ev.entityId})}for(let e of o){let t=document.createElement(`button`);t.type=`button`,t.className=`mw-lifeline-plus`,t.textContent=`+`,t.title=`Click to insert here · drag to another participant to connect`,t.style.left=`${a}px`,t.style.top=`${e.y}px`,t.addEventListener(`pointerenter`,()=>{this.plusHovered=!0}),t.addEventListener(`pointerleave`,()=>{this.plusHovered=!1,this.scheduleLifelineClear()}),t.addEventListener(`pointerdown`,t=>{t.stopPropagation(),this.beginPlusDrag(t,r,e.afterEvent)}),t.addEventListener(`click`,n=>{if(n.stopPropagation(),this.plusDragConsumedClick){this.plusDragConsumedClick=!1;return}this.openPlusMenu(t,r,e.afterEvent)}),this.overlayHost.appendChild(t),this.plusButtons.push(t)}}plusDragConsumedClick=!1;plusDragCleanup=null;beginPlusDrag(e,t,n){if(this.readOnly)return;let r=e.clientX,i=e.clientY,a=!1,o=(e,t)=>{let n=document.elementFromPoint(e,t);for(;n&&n!==this.container;){let e=n.getAttribute?.(`data-mw-entity`);if(e?.startsWith(`participant:`))return e.slice(12);n=n.parentElement}if(this.seqCorrelation)for(let[n,r]of this.seqCorrelation.lifelines){let i=r.getBoundingClientRect(),a=i.left+i.width/2;if(Math.abs(e-a)<=24&&t>=i.top-8&&t<=i.bottom+8)return n.slice(12)}return null},s=e=>{if(!a&&Math.hypot(e.clientX-r,e.clientY-i)<=4||(a||(a=!0,this.plusMenu?.remove(),this.plusMenu=null),!this.svg))return;let t=this.clientToSvg(r,i),n=this.clientToSvg(e.clientX,e.clientY);!t||!n||(this.ghostPath||(this.ghostPath=document.createElementNS(`http://www.w3.org/2000/svg`,`line`),this.ghostPath.classList.add(`mw-ghost-edge`),this.svg.appendChild(this.ghostPath)),this.ghostPath.setAttribute(`x1`,String(t.x)),this.ghostPath.setAttribute(`y1`,String(t.y)),this.ghostPath.setAttribute(`x2`,String(n.x)),this.ghostPath.setAttribute(`y2`,String(n.y)))},c=()=>{this.plusDragCleanup=null,document.removeEventListener(`pointermove`,s),document.removeEventListener(`pointerup`,l),document.removeEventListener(`pointercancel`,l),this.ghostPath?.remove(),this.ghostPath=null},l=e=>{if(c(),!a)return;this.plusDragConsumedClick=!0,setTimeout(()=>{this.plusDragConsumedClick=!1},0),this.clearLifelineUi();let r=o(e.clientX,e.clientY);if(!r||r===t)return;let i=this.editor.dispatch({type:`seq.addMessage`,source:t,target:r,text:`message`,afterEvent:n},`canvas`);i?.created?.[0]&&(this.pendingEditEntity=i.created[0])};this.plusDragCleanup=c,document.addEventListener(`pointermove`,s),document.addEventListener(`pointerup`,l),document.addEventListener(`pointercancel`,l)}openPlusMenu(e,t,n){this.plusMenu?.remove();let r=document.createElement(`div`);r.className=`mw-plus-menu`,r.style.left=e.style.left,r.style.top=`${parseFloat(e.style.top)+12}px`,r.addEventListener(`pointerdown`,e=>e.stopPropagation());let i=(e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.textContent=e,n.addEventListener(`click`,e=>{e.stopPropagation(),this.clearLifelineUi(),t()}),r.appendChild(n)};i(`↩ Self message`,()=>{let e=this.editor.dispatch({type:`seq.addMessage`,source:t,target:t,text:`message`,afterEvent:n},`canvas`);e?.created?.[0]&&(this.pendingEditEntity=e.created[0])});let a=(e,r)=>i(e,()=>{let e=this.editor.dispatch({type:`seq.addNote`,participant:t,placement:r,text:`note`,afterEvent:n},`canvas`);e?.created?.[0]&&(this.pendingEditEntity=e.created[0])});a(`▭ Note over`,`over`),a(`▭ Note left`,`left of`),a(`▭ Note right`,`right of`),this.overlayHost.appendChild(r),this.plusMenu=r}scheduleLifelineClear(){this.lifelineClearTimer&&clearTimeout(this.lifelineClearTimer),this.lifelineClearTimer=setTimeout(()=>{!this.plusHovered&&!this.plusMenu&&this.clearLifelineUi()},400)}clearLifelineUi(){this.plusButtons.forEach(e=>e.remove()),this.plusButtons=[],this.plusMenu?.remove(),this.plusMenu=null,this.hoveredLifeline=null,this.plusHovered=!1}clientToSvg(e,t){if(!this.svg)return null;let n=this.svg.getScreenCTM();if(!n)return null;let r=new DOMPoint(e,t).matrixTransform(n.inverse());return{x:r.x,y:r.y}}entityCenter(e){let t=this.entityElement(e);if(!t)return null;let n=t.getBoundingClientRect();return this.clientToSvg(n.left+n.width/2,n.top+n.height/2)}async validate(){try{return await this.mermaid.parse(this.editor.code),!0}catch(e){let t=e instanceof Error?e.message.split(`
161
161
  `)[0]:String(e);return this.editor.setDiagnostics([{message:t,span:null,severity:`error`,source:`mermaid`}]),!1}}destroy(){this.destroyed=!0,this.renderTimer&&clearTimeout(this.renderTimer),this.lifelineClearTimer&&clearTimeout(this.lifelineClearTimer),this.inPlaceSession?.liveTimer&&clearTimeout(this.inPlaceSession.liveTimer),this.inPlaceSession=null,this.svgTransformObserver?.disconnect(),this.svgTransformObserver=null,this.visibilityRetryObserver?.disconnect(),this.visibilityRetryObserver=null,this.disposers.forEach(e=>e()),this.plusDragCleanup?.(),this.closeInlineEditor(!1),this.cancelConnect(),this.clearLifelineUi(),this.popover.hide(),this.container.classList.remove(`mw-canvas`,`mw-tool-connect`,`mw-readonly`,`mw-panzoom`,`mw-panning`),this.svgHost.remove(),this.overlayHost.remove(),this.errorBadge.remove(),this.zoomControls?.remove()}};export{M as MermaidCanvasView,m as Popover,i as correlateFlowchart,d as correlateSequence};
@@ -1 +1 @@
1
- import{m as e}from"./config-provider-C1TYis8u.js";var t=new WeakMap;function n(n,r){let i=t.get(r);if(i)return i;let a=new e(r);t.set(r,a);let o=r.doc,s=!1,c=()=>{s||(s=!0,n.off(`destroy`,c),o?.off(`destroy`,c),t.get(r)===a&&t.delete(r),a.clear(),a.destroy())};return n.on(`destroy`,c),o?.on(`destroy`,c),a}export{n as t};
1
+ import{m as e}from"./config-provider-Bu33ODD8.js";var t=new WeakMap;function n(n,r){let i=t.get(r);if(i)return i;let a=new e(r);t.set(r,a);let o=r.doc,s=!1,c=()=>{s||(s=!0,n.off(`destroy`,c),o?.off(`destroy`,c),t.get(r)===a&&t.delete(r),a.clear(),a.destroy())};return n.on(`destroy`,c),o?.on(`destroy`,c),a}export{n as t};