koboyo 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/assets/editor/assets/IconNote-CSELvWzx.js +1 -0
  2. package/assets/editor/assets/code-panel-BfsykjSz.js +43 -0
  3. package/assets/editor/assets/flow-layer-BC35drcK.js +1 -0
  4. package/assets/editor/assets/flow-panel-D_K9wgZi.js +1 -0
  5. package/assets/editor/assets/{index-DGJESAlV.css → index-CC2h28V_.css} +1 -1
  6. package/assets/editor/assets/{index-By5YsjJ8.js → index-DfNbwHl_.js} +7 -7
  7. package/assets/editor/assets/tool-catalog-ChSwaLIq.js +1 -0
  8. package/assets/editor/assets/{tool-drawer-GdbF-XpT.js → tool-drawer-CG7-cnML.js} +1 -1
  9. package/assets/editor/assets/tree-rq4RTGgw.js +1 -0
  10. package/assets/editor/index.html +4 -4
  11. package/dist/koboyo.js +285 -229
  12. package/package.json +5 -5
  13. package/skills/koboyo/SKILL.md +33 -1
  14. package/skills/koboyo/references/architecture.md +4 -4
  15. package/skills/koboyo/references/bpmn.md +1 -1
  16. package/skills/koboyo/references/chart.md +1 -1
  17. package/skills/koboyo/references/cycle.md +1 -1
  18. package/skills/koboyo/references/erd.md +1 -1
  19. package/skills/koboyo/references/flowchart.md +1 -1
  20. package/skills/koboyo/references/funnel.md +1 -1
  21. package/skills/koboyo/references/gantt.md +1 -1
  22. package/skills/koboyo/references/gitgraph.md +1 -1
  23. package/skills/koboyo/references/journey.md +1 -1
  24. package/skills/koboyo/references/matrix.md +1 -1
  25. package/skills/koboyo/references/mindmap.md +2 -2
  26. package/skills/koboyo/references/orgchart.md +1 -1
  27. package/skills/koboyo/references/pyramid.md +1 -1
  28. package/skills/koboyo/references/sankey.md +1 -1
  29. package/skills/koboyo/references/sequence.md +1 -1
  30. package/skills/koboyo/references/statemachine.md +1 -1
  31. package/skills/koboyo/references/timeline.md +1 -1
  32. package/skills/koboyo/references/venn.md +1 -1
  33. package/skills/koboyo/references/wireframe.md +1 -1
  34. package/assets/editor/assets/IconNote-C0uYQWp-.js +0 -1
  35. package/assets/editor/assets/code-panel-CVIEtmj2.js +0 -43
  36. package/assets/editor/assets/flow-layer-CGYUYmni.js +0 -1
  37. package/assets/editor/assets/flow-panel-BNLlwdYm.js +0 -1
  38. package/assets/editor/assets/tool-catalog-DOYGpvRD.js +0 -1
  39. package/assets/editor/assets/tree-BSe8fgqT.js +0 -1
@@ -0,0 +1 @@
1
+ import{t as e}from"./createReactComponent-9UsI5fmM.js";var t=e(`outline`,`link`,`Link`,[[`path`,{d:`M9 15l6 -6`,key:`svg-0`}],[`path`,{d:`M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464`,key:`svg-1`}],[`path`,{d:`M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463`,key:`svg-2`}]]),n=e(`outline`,`note`,`Note`,[[`path`,{d:`M13 20l7 -7`,key:`svg-0`}],[`path`,{d:`M13 20v-6a1 1 0 0 1 1 -1h6v-7a2 2 0 0 0 -2 -2h-12a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7`,key:`svg-1`}]]);export{t as n,n as t};
@@ -0,0 +1,43 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-2Zwg-L3c.js";import{Fn as r}from"./useScrollLock-B7mQdXyv.js";import{t as i}from"./tooltip-DgEojto1.js";import{a,o}from"./editor-B0tARd79.js";import{M as s,t as c}from"./reflow-Cv75wPSh.js";import{s as l}from"./style-BENGW2ZV.js";import{A as u,C as d,Zt as f,_ as p,ar as m,x as h,zt as g}from"./slides-D9bnXqtf.js";import{A as _,D as v,E as y,M as b,N as x,O as S,R as C,S as w,T,b as E,g as D,h as O,j as k,k as ee}from"./registry-DCgwH8wI.js";import{n as te}from"./renderer-environment-DmWXvuT4.js";import{a as ne,t as re}from"./icon-sources-CZI1h18s.js";import{t as A}from"./icons-DzW1j-r3.js";import{o as ie,r as ae,t as oe}from"./diagram-fingerprint-CsqZK4xZ.js";import{t as se}from"./createReactComponent-9UsI5fmM.js";import{t as ce}from"./IconAlertTriangle-CxPhYpe-.js";import{t as le}from"./IconCode-hd05zxU4.js";import{t as ue}from"./IconX-AlbPkO_g.js";import{n as de,t as fe}from"./storage-CvDRYh5V.js";import{a as pe}from"./chrome-C2RCq3SI.js";import{i as me,n as he,r as ge,t as _e}from"./DialogRoot-mHGRFW9m.js";import{n as ve,t as ye}from"./DialogTitle-CFhr-gP9.js";import{n as be}from"./dialog-B32krrce.js";import{r as xe}from"./chrome-layout-B8YmHznO.js";import{t as Se}from"./panel-shell-CG2aq4Ia.js";import{d as Ce,f as j,i as we,p as Te,r as Ee,t as De,u as Oe}from"./layout-offthread-BwetpTFH.js";import{n as ke,t as Ae}from"./export-DEFKKRRi.js";import{r as je}from"./flows-GGbkNqs8.js";import{n as M}from"./icon-catalog-CbUlEKtK.js";var Me=se(`outline`,`book`,`Book`,[[`path`,{d:`M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0`,key:`svg-0`}],[`path`,{d:`M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0`,key:`svg-1`}],[`path`,{d:`M3 6l0 13`,key:`svg-2`}],[`path`,{d:`M12 6l0 13`,key:`svg-3`}],[`path`,{d:`M21 6l0 13`,key:`svg-4`}]]),N=e(t(),1);function P(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`node`}function F(e,t){let n=e,r=2;for(;t.has(n);)n=`${e}-${r}`,r+=1;return t.add(n),n}function Ne(e,t,n=0){let r=!1,i=0;for(let a=0;a<e.length;a+=1){let o=e[a];if(o===`"`){r=!r;continue}if(!r){if(o===`[`){i+=1;continue}if(o===`]`){i=Math.max(0,i-1);continue}if(i===0&&a>=n){for(let n=0;n<t.length;n+=1)if(e.startsWith(t[n],a))return{index:a,needle:n}}}}return null}function I(e,t,n=0){return Ne(e,[t],n)?.index??-1}function L(e){let t=I(e,`//`);return t===-1?e:e.slice(0,t)}function R(e,t){let n=[],r=0,i=0,a=!1;for(let o=0;o<e.length;o+=1){let s=e[o];s===`"`?a=!a:!a&&s===`[`?r+=1:!a&&s===`]`?r=Math.max(0,r-1):!a&&r===0&&s===t&&(n.push(e.slice(i,o)),i=o+1)}return n.push(e.slice(i)),n}function z(e){let t=e.trim();return t.length>=2&&t.startsWith(`"`)&&t.endsWith(`"`)?t.slice(1,-1).replace(/\\n/g,`
2
+ `):t}function B(e){return/\s|[:=,[\]{}]/.test(e)?`"${e.replace(/"/g,``)}"`:e}function V(e){let t=e.trimEnd();if(!t.endsWith(`]`))return{rest:e,attrs:null};let n=0,r=!1;for(let e=t.length-1;e>=0;--e){let i=t[e];if(i===`"`)r=!r;else if(!r&&i===`]`)n+=1;else if(!r&&i===`[`&&(--n,n===0))return{rest:t.slice(0,e),attrs:t.slice(e+1,t.length-1)}}return{rest:e,attrs:null}}var Pe={done:`done`,complete:`done`,active:`active`,doing:`active`,crit:`critical`,critical:`critical`,milestone:`milestone`};function Fe(e){let t=/^(\d+(?:\.\d+)?)\s*(d|day|days|w|week|weeks|h|hour|hours|m|min|mins|minute|minutes|s|sec|secs|second|seconds)?$/i.exec(e.trim());if(!t)return;let n=Number(t[1]),r=(t[2]??`d`).toLowerCase();return r.startsWith(`w`)?n*7:r.startsWith(`h`)?n/24:r===`m`||r.startsWith(`min`)?n/1440:r===`s`||r.startsWith(`sec`)?n/86400:n}function Ie(e){let t=[],n=``,r=[],i=new Set,a=``,o=!1;return e.split(`
3
+ `).forEach((e,s)=>{let c=L(e).trim();if(c.length===0||c.toLowerCase()===`gantt`)return;let l=c.match(/^title\s*:\s*(.*)$/i);if(l){n=z(l[1].trim());return}let u=c.match(/^section\s+(.+)$/i);if(u){a=z(u[1].trim());return}let d=c.match(/^excludes\s*:\s*(.*)$/i);if(d){/weekends?/i.test(d[1])?o=!0:t.push({line:s+1,message:`only "excludes: weekends" is supported, not "${d[1].trim()}"`});return}let{attrs:f,rest:p}=V(c),m;for(let e of R(f??``,`,`)){let n=e.trim().toLowerCase();n&&(Pe[n]?m=Pe[n]:t.push({line:s+1,message:`unknown task attribute "${e.trim()}"`}))}let h=p.trim().match(/^[-*]\s+(.*)$/),g=(h?h[1]:p).trim();if(g.length===0)return;let _=g.indexOf(`:`),v=z((_===-1?g:g.slice(0,_)).trim());if(v.length===0)return;let y=_===-1?``:g.slice(_+1),b,x,S,C=[];for(let e of R(y,`,`)){let n=e.trim();if(!n)continue;let r=n.match(/^after\s+(.+)$/i);if(r){C.push(...r[1].trim().split(/\s+/).map(P));continue}let i=n.match(/^until\s+(.+)$/i);if(i){S=P(i[1].trim());continue}if(/^\d{4}-\d{2}-\d{2}$/.test(n)){b=n;continue}let a=Fe(n);if(a!==void 0){x=a;continue}t.push({line:s+1,message:`unknown schedule part "${n}" (expected a date, "after <task>", or a length like 5d)`})}r.push({id:F(P(v)||`t${r.length+1}`,i),label:v,section:a===``?void 0:a,start:b,after:C.length>0?C:void 0,days:x,until:S,status:m})}),{diagram:j({kind:`gantt`,title:n,tasks:r,skipWeekends:o}),diagnostics:t,iconUses:[]}}function Le(e,t,n){let r={};if(!e||e.trim()===``)return r;for(let i of R(e,`,`)){let e=i.trim();if(!e)continue;let a=I(e,`:`);if(a===-1){let i=e.toLowerCase();i===`highlight`?r.kind=`highlight`:i===`reverse`||i===`revert`?r.kind=`reverse`:n.push({line:t,message:`unknown commit attribute "${e}"`});continue}let o=e.slice(0,a).trim().toLowerCase(),s=z(e.slice(a+1));o===`tag`?r.tag=s:o===`label`?r.label=s:n.push({line:t,message:`unknown commit attribute "${o}"`})}return r}function Re(e){let t=[],n=``,r=[],i=[],a=`main`,o=new Map,s=new Set,c=e=>{r.includes(e)||r.push(e)};c(a);let l=(e,t,n={})=>{let{id:r,...c}=n,l=e.trim(),u=s.has(a)?void 0:o.get(a);s.add(a),i.push({id:r??(P(l)||`c${i.length+1}`),branch:a,label:l.length>0?l:void 0,tag:t.tag,kind:t.kind,branchFrom:u,...c})};return e.split(`
4
+ `).forEach((e,r)=>{let i=L(e).trim();if(i.length===0||i.toLowerCase()===`gitgraph`)return;let s=i.match(/^title\s*:\s*(.*)$/i);if(s){n=z(s[1].trim());return}let{attrs:u,rest:d}=V(i),f=Le(u,r+1,t),p=d.trim(),m=p.match(/^branch\s+(.+)$/i);if(m){let e=z(m[1].trim());e!==a&&o.set(e,a),a=e,c(a);return}let h=p.match(/^(?:checkout|switch)\s+(.+)$/i);if(h){a=z(h[1].trim()),c(a);return}let g=p.match(/^merge\s+(.+)$/i);if(g){let e=z(g[1].trim());if(e===a){t.push({line:r+1,message:`cannot merge "${e}" into itself — checkout another branch first`});return}c(e),l(f.label??`merge ${e}`,f,{mergeFrom:e});return}let _=p.match(/^cherry-?pick\s+(.+)$/i);if(_){let e=P(z(_[1].trim()));l(f.label??`pick ${e}`,f,{cherryPick:e,id:`pick-${e}`});return}let v=p.match(/^commit\b\s*(.*)$/i);if(v){l(f.label??v[1],f);return}t.push({line:r+1,message:`unknown git line "${p}" (expected commit, branch, checkout, merge or cherry-pick)`})}),{diagram:j({kind:`gitgraph`,title:n,lanes:r,commits:i}),diagnostics:t,iconUses:[]}}function ze(e){let t=[],n=``,r=[];return e.split(`
5
+ `).forEach((e,i)=>{let a=L(e).trim();if(a.length===0||a.toLowerCase()===`sankey`)return;let o=a.match(/^title\s*:\s*(.*)$/i);if(o){n=z(o[1].trim());return}let s=a.match(/^(.+?)\s*(?:->|=>)\s*(.+)$/),c=s?[s[1],...s[2].split(`:`)]:R(a,`,`).map(e=>e.trim());if(c.length<3){t.push({line:i+1,message:`expected "From -> To : value" but read "${a}"`});return}let l=Number(z(c[2].trim()));if(!Number.isFinite(l)||l<=0){t.push({line:i+1,message:`flow needs a positive value, got "${c[2].trim()}"`});return}r.push({from:z(c[0].trim()),to:z(c[1].trim()),value:l})}),{diagram:j({kind:`sankey`,title:n,flows:r}),diagnostics:t,iconUses:[]}}var H=ee,Be=x,Ve=C;function He(e){return Object.fromEntries(e.map(e=>[e,e]))}var U=He(k),Ue={...He(_),square:`sharp`,round:`rounded`},We=He(T),Ge={...He(E),x:`cross`,o:`circle`,dot:`circle`},Ke={full:`full`,half:`half`,"1/2":`half`,third:`third`,"1/3":`third`,"two-thirds":`twoThirds`,twothirds:`twoThirds`,"2/3":`twoThirds`},qe=Te,Je=new Set([`on`,`checked`,`true`]),Ye=new Set([`off`,`unchecked`,`false`]),Xe=new Map(O.map((e,t)=>[e,t])),Ze={white:`#ffffff`,black:`#1e1e1e`,silver:`#c0c0c0`,maroon:`#800000`,crimson:`#dc143c`,tomato:`#ff6347`,salmon:`#fa8072`,lightsalmon:`#ffa07a`,coral:`#ff7f50`,gold:`#ffd700`,khaki:`#f0e68c`,lavender:`#e6e6fa`,plum:`#dda0dd`,orchid:`#da70d6`,magenta:`#ff00ff`,fuchsia:`#ff00ff`,indigo:`#4b0082`,navy:`#000080`,royalblue:`#4169e1`,skyblue:`#87ceeb`,lightblue:`#add8e6`,lightskyblue:`#87cefa`,steelblue:`#4682b4`,lightcyan:`#e0ffff`,cyan:`#00ffff`,aqua:`#00ffff`,aquamarine:`#7fffd4`,turquoise:`#40e0d0`,mint:`#98ff98`,mintcream:`#f5fffa`,lightgreen:`#90ee90`,palegreen:`#98fb98`,seagreen:`#2e8b57`,forestgreen:`#228b22`,olive:`#808000`,lime:`#00ff00`,limegreen:`#32cd32`,lightyellow:`#ffffe0`,lemonchiffon:`#fffacd`,beige:`#f5f5dc`,ivory:`#fffff0`,tan:`#d2b48c`,wheat:`#f5deb3`,peachpuff:`#ffdab9`,brown:`#a52a2a`,chocolate:`#d2691e`,sienna:`#a0522d`,peru:`#cd853f`,lightpink:`#ffb6c1`,hotpink:`#ff69b4`,deeppink:`#ff1493`,rosybrown:`#bc8f8f`,lightgray:`#d3d3d3`,lightgrey:`#d3d3d3`,darkgray:`#a9a9a9`,darkgrey:`#a9a9a9`,dimgray:`#696969`,dimgrey:`#696969`,gainsboro:`#dcdcdc`,whitesmoke:`#f5f5f5`,slategray:`#708090`,slategrey:`#708090`,darkblue:`#00008b`,darkgreen:`#006400`,darkred:`#8b0000`,darkorange:`#ff8c00`,darkviolet:`#9400d3`,darkcyan:`#008b8b`,darkkhaki:`#bdb76b`,lightcoral:`#f08080`,lightseagreen:`#20b2aa`,lightsteelblue:`#b0c4de`,lightgoldenrodyellow:`#fafad2`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumblue:`#0000cd`,cornflowerblue:`#6495ed`,dodgerblue:`#1e90ff`,goldenrod:`#daa520`,thistle:`#d8bfd8`,violetred:`#d02090`,paleturquoise:`#afeeee`,powderblue:`#b0e0e6`},Qe={blue:`#a5d8ff`,green:`#b2f2bb`,red:`#ffc9c9`,orange:`#ffd8a8`,violet:`#eebefa`,teal:`#96f2d7`,pink:`#fcc2d7`,yellow:`#ffec99`,gray:`#e9ecef`};function $e(e){let t=(e>>16&255)/255,n=(e>>8&255)/255,r=(e&255)/255,i=Math.max(t,n,r),a=Math.min(t,n,r),o=i-a,s=0;o>0&&(s=i===t?(n-r)/o%6:i===n?(r-t)/o+2:(t-n)/o+4,s=(s*60+360)%360);let c=(i+a)/2,l=o===0?0:o/(1-Math.abs(2*c-1));return{hue:s,saturation:l}}var et=/^(?:light|dark|medium|pale|deep|hot|dim|royal|sky|forest|sea|slate|steel)?(blue|green|red|orange|violet|purple|teal|pink|yellow|gray|grey)$/,tt={purple:`violet`,grey:`gray`};function nt(e){let t=e.trim().toLowerCase(),n=et.exec(t);if(n)return tt[n[1]]??n[1];let r=Ze[t],i=/^#?([0-9a-f]{6})$/i.exec(r??t);if(!i)return null;let{hue:a,saturation:o}=$e(parseInt(i[1],16));if(o<.12)return`gray`;let s=null,c=1/0;for(let[e,t]of Object.entries(Qe)){if(e===`gray`)continue;let n=$e(parseInt(t.slice(1),16)).hue,r=Math.abs(a-n),i=Math.min(r,360-r);i<c&&(c=i,s=e)}return s}var rt=new Set(M),it=new Set([`rectangle`,`box`,`ellipse`,`circle`,`diamond`,`cylinder`,`hexagon`,`triangle`,`pentagon`,`octagon`,`plus`,`cross`,`star`,`heart`,`cloud`,`arrow-up`,`arrow-down`,`arrow-left`,`arrow-right`]),at=/^(tech|aws|gcp|azure)\/[a-z0-9-]+$/,ot=new Set([`lucide`,`tech`,`aws`,`gcp`,`azure`,`emoji`,`mood`]),st={frames:!1,shapes:!1};function ct(e,t,n){let r=e.toLowerCase();if(r===`flow`||r===`animated`){t.flow=!0;return}if(r===`invisible`||r===`hidden`){t.invisible=!0;return}if(r===`shadow`){t.shadow=!0;return}if(H[r]){t.color=H[r];return}if(Be[r]){t.shape=Be[r],n.check.shapes&&!it.has(r)&&n.use({kind:`keyword`,written:e,ref:Ve(r),reading:`shape`});return}if(U[r]){t.fill=U[r];return}if(Ue[r]){t.corner=Ue[r];return}if(We[r]){t.frame=We[r],n.check.frames&&n.use({kind:`keyword`,written:e,ref:Ve(r),reading:`frame`});return}if(Ke[r]){t.width=Ke[r];return}if(Je.has(r)){t.value=1;return}if(Ye.has(r)){t.value=0;return}let i=Xe.get(r);if(i!==void 0){t.value=i;return}let a=/^(\d+(?:\.\d+)?)%$/.exec(r);if(a){t.value=Number(a[1])/100;return}if(/^\d*\.\d+$/.test(r)||/^[01]$/.test(r)){t.value=Number(r);return}let o=nt(z(e));if(o){t.color=o;return}if(at.test(r)){t.icon=Ve(r),n.use({kind:`icon`,written:e,ref:t.icon});return}if(rt.has(r)){t.icon=r,n.use({kind:`icon`,written:e,ref:r});return}let s=n.push(`unknown attribute "${e}"`);n.use({kind:`unknown`,written:e,ref:Ve(r),diagnostic:s})}function W(e,t,n,r=st){let i={};if(!e||e.trim()===``)return i;let a=e=>{let r={line:t,message:e};return n.diagnostics.push(r),r},o={push:a,use:e=>{n.iconUses.push({...e,line:t})},check:r};for(let t of R(e,`,`)){let e=t.trim();if(!e)continue;let n=I(e,`:`);if(n===-1){ct(e,i,o);continue}let r=e.slice(0,n).trim().toLowerCase(),s=z(e.slice(n+1)),c=s.toLowerCase();if(r===`icon`)i.icon=Ve(c),o.use({kind:`icon`,written:s,ref:i.icon});else if(ot.has(r)){let e=c.trim();a(`"${r}:${e}" reads as a key: value pair. For the icon, write `+(at.test(`${r}/${e}`)?`[${r}/${e}]`:`[icon: ${r}/${e}]`))}else if(r===`color`)i.color=H[c]??nt(s)??void 0,i.color||a(`unknown color "${s}"`);else if(r===`shape`)i.shape=Be[c],i.shape||a(`unknown shape "${s}"`);else if(r===`fill`||r===`colormode`)i.fill=U[c],i.fill||a(`unknown fill "${s}" (pastel, bold, outline)`);else if(r===`corner`||r===`corners`)i.corner=Ue[c],i.corner||a(`unknown corner "${s}" (sharp, rounded)`);else if(r===`frame`)i.frame=We[c],i.frame||a(`unknown frame "${s}" (browser, phone, window)`);else if(r===`width`)i.width=Ke[c],i.width||a(`unknown width "${s}"`);else if(r===`label`)i.label=s;else if(r===`labelcolor`||r===`textcolor`)i.labelColor=H[c]??nt(s)??void 0,i.labelColor||a(`unknown label color "${s}"`);else if(r===`group`)i.group=s;else if(r===`head`)i.head=Ge[c],i.head||a(`unknown head "${s}" (arrow, circle or cross)`);else if(r===`link`||r===`href`||r===`url`)i.link=m(s)??void 0,s&&!i.link&&a(`unsafe or invalid link "${s}"`);else if(r===`active`||r===`value`){let e=Number(c.replace(`%`,``));Number.isFinite(e)?i.value=c.endsWith(`%`)?e/100:e:a(`"${r}" expects a number`)}else if(r===`score`){let e=Number(c);Number.isFinite(e)?i.score=e:a(`"score" expects a number ${v.min}-${v.max}`)}else a(`unknown attribute key "${r}"`)}return i}function lt(e,t){let n=[],r={diagnostics:n,iconUses:[]},i=``,a=[],o=[],s={},c=t===`journey`,l=t===`timeline`,u=``,d,f=new Set,p=e=>{let t=e.match(/^"([^"]*)"\s*(?::\s*(.*))?$/);if(t)return{label:t[1].trim(),detail:t[2]?.trim()||void 0};let n=e.indexOf(`:`);return n<0?{label:z(e.trim())}:{label:z(e.slice(0,n).trim()),detail:e.slice(n+1).trim()||void 0}};return e.split(`
6
+ `).forEach((e,m)=>{let h=L(e),g=h.trim();if(g.length===0||g.toLowerCase()===t)return;let _=h.length-h.trimStart().length;if(l&&_>=2&&d){let e=g.match(/^[-*]\s+(.*)$/);if(e){let{rest:t}=V(e[1].trim()),n=z(t.trim());n.length>0&&(d.events||(d.events=d.detail?[d.detail]:[],d.detail=void 0),d.events.length<8&&d.events.push(n));return}}let v=g.match(/^(title|x|y)\s*:\s*(.*)$/i);if(v){let e=v[1].toLowerCase(),t=v[2].trim();if(e===`title`)i=z(t);else{let r=t.split(`|`).map(e=>z(e.trim()));r.length>=2?s[e]=r:n.push({line:m+1,message:`axis "${e}" needs two labels separated by | (e.g. x: Low | High)`})}return}let y=c||l?g.match(/^section\s+(.+)$/i):null;if(y){u=z(y[1].trim());return}let b=g.match(/^overlap\s+(.+?)\s*:\s*(.*)$/i);if(b){let e=b[1].split(/\s*[+&,]\s*/).map(e=>P(z(e.trim()))).filter(e=>e.length>0),t=z(b[2].trim());e.length>=2&&t.length>0?o.push({ids:e,label:t}):n.push({line:m+1,message:`overlap needs two set names and a label (overlap a + b: label)`});return}let x=g.match(/^[-*]\s+(.*)$/),{attrs:S,rest:C}=V(x?x[1].trim():g),{label:w,detail:T}=p(C.trim());if(w.length===0)return;let E=W(S,m+1,r),D=c&&T!==void 0&&/^\d+(\.\d+)?$/.test(T),O={id:F(P(w)||`i${a.length}`,f),label:w,detail:D?void 0:T,color:E.color,icon:E.icon,score:c?E.score??(D?Number(T):void 0):void 0,group:(c||l)&&u!==``?u:void 0};a.push(O),d=l?O:void 0}),{diagram:j({kind:`infographic`,variant:t,title:i,items:a,overlaps:o.length>0?o:void 0,axes:s.x||s.y?s:void 0}),diagnostics:n,iconUses:r.iconUses}}function ut(e){let t=[],n={diagnostics:t,iconUses:[]},r=``,i=``,a=[];e.split(`
7
+ `).forEach((e,t)=>{let o=L(e.replace(/\t/g,` `)),s=o.trim();if(s.length===0||s.toLowerCase()===`mindmap`)return;let c=s.match(/^(title|central|root|center)\s*:\s*(.*)$/i);if(c){let e=z(c[2].trim());c[1].toLowerCase()===`title`?r=e:i=e;return}let l=o.match(/^(\s*)[-*]\s+(.*)$/);if(l){let{attrs:e,rest:r}=V(l[2].trim()),i=z(r.trim());i.length>0&&a.push({indent:l[1].length,label:i,attrs:W(e,t+1,n)});return}i?a.push({indent:0,label:z(s),attrs:{}}):i=z(s)});let o=[],s=new Set,c=a.reduce((e,t)=>Math.min(e,t.indent),1/0),l=[];for(let e of a){if(e.indent<=c){let t=[];o.push({id:F(P(e.label)||`b${o.length}`,s),label:e.label,color:e.attrs.color,icon:e.attrs.icon,children:t}),l.length=0,l.push({indent:e.indent,children:t});continue}for(;l.length>1&&e.indent<=l[l.length-1].indent;)l.pop();let t=l[l.length-1];if(!t){let t=[];o.push({id:F(P(e.label)||`b${o.length}`,s),label:e.label,children:t}),l.push({indent:e.indent,children:t});continue}let n=[];t.children.push({label:e.label,icon:e.attrs.icon,children:n}),l.push({indent:e.indent,children:n})}return{diagram:j({kind:`mindmap`,title:r,central:i||r,branches:o}),diagnostics:t,iconUses:n.iconUses}}var dt=[...Object.keys(w),`mindmap`,`gitgraph`,`gantt`,`sankey`,...y],ft=[`<-.->`,`<-->`,`<..>`,`-.->`,`<-.-`,`<->`,`-->`,`<--`,`<..`,`..>`,`<-`,`->`,`<>`,`>`,`<`],pt={"1:1":{value:`1:1`,swap:!1},"1:n":{value:`1:N`,swap:!1},"n:1":{value:`1:N`,swap:!0},"n:m":{value:`N:M`,swap:!1},"m:n":{value:`N:M`,swap:!1}},mt=[`1:1`,`1:N`,`N:1`,`N:M`],ht={"|o":`zeroOrOne`,"||":`one`,"}o":`zeroOrMany`,"}|":`oneOrMany`},gt={"o|":`zeroOrOne`,"||":`one`,"o{":`zeroOrMany`,"|{":`oneOrMany`};Object.fromEntries(Object.entries(ht).map(([e,t])=>[t,e])),Object.fromEntries(Object.entries(gt).map(([e,t])=>[t,e]));var _t={};for(let[e,t]of Object.entries(ht))for(let[n,r]of Object.entries(gt))for(let[i,a]of[[`--`,!0],[`..`,!1]])_t[`${e}${i}${n}`]={from:t,to:r,identifying:a};var vt=Object.keys(_t),yt=[`||--||`,`||--o{`,`|o--o{`,`||--|{`,`}|--o{`],bt={"<|--":{kind:`inheritance`,swap:!0},"--|>":{kind:`inheritance`,swap:!1},"<|..":{kind:`realization`,swap:!0},"..|>":{kind:`realization`,swap:!1},"--*":{kind:`composition`,swap:!0},"*--":{kind:`composition`,swap:!1},"--o":{kind:`aggregation`,swap:!0},"o--":{kind:`aggregation`,swap:!1},"..>":{kind:`dependency`,swap:!1},"<..":{kind:`dependency`,swap:!0}},xt=Object.keys(bt),St=e=>e.includes(`.`)||e.includes(`--`),Ct=e=>e===`<-`||e===`<..`||e===`<--`||e===`<-.-`||e===`<`,wt=e=>e===`<->`||e===`<..>`||e===`<-->`||e===`<-.->`||e===`<>`;function Tt(e){return/^[<\-.*o]/.test(e)}function Et(e){return Tt(e)?e:` ${e} `}function Dt(e){return Tt(e)?e.length:e.length+2}function Ot(e,t,n=0){let r=Ne(e,t.map(Et),n);return r?{index:r.index,token:t[r.needle]}:null}function kt(e,t){let n=[],r=null,i=0;for(;i<e.length;){let a=Ot(e,t,i);if(!a)break;let o=e.slice(i,a.index);r===null?r=o:n[n.length-1].segment=o,n.push({token:a.token,segment:``}),i=a.index+Dt(a.token)}return r===null?null:(n[n.length-1].segment=e.slice(i),{first:r,hops:n})}function At(){return{diagnostics:[],iconUses:[],raw:{},family:null,title:``,direction:void 0,icons:void 0,kanban:!1,defaultFill:void 0,nodes:[],groups:[],edges:[],nodeByKey:new Map,groupByKey:new Map,usedIds:new Set,groupStack:[],actors:[],messages:[],frames:[],blockStack:[],activations:[],activationOpen:new Map,notes:[],legendEntries:[],inLegend:!1,entities:[],relations:[],currentEntity:null,erdGroupStack:[],classHeader:!1,screens:[],currentScreen:null}}function jt(e){return e.groupStack[e.groupStack.length-1]??null}function G(e){return e.family??`architecture`}function Mt(e){return{frames:!0,shapes:G(e)===`architecture`}}function Nt(e,t,n,r){let i=(r??t).toLowerCase(),a=r?e.nodeByKey.get(i):e.nodeByKey.get(i)??e.nodeByKey.get(t.toLowerCase());if(a){let t=e.nodes.find(e=>e.id===a);return t&&(t.icon??=n.icon,t.shape??=n.shape,t.color??=n.color,t.fill??=n.fill,t.corner??=n.corner,t.labelColor??=n.labelColor,t.shadow||=n.shadow,t.link??=n.link,t.group??=n.group?Pt(e,n.group):jt(e)??void 0,n.label&&(t.label=n.label)),a}let o=F(r||P(t),e.usedIds);return e.nodes.push({id:o,label:n.label??t,icon:n.icon,shape:n.shape,color:n.color,fill:n.fill,corner:n.corner,labelColor:n.labelColor,shadow:n.shadow,link:n.link,group:n.group?Pt(e,n.group):jt(e)??void 0}),e.nodeByKey.set(i,o),(!r||!e.nodeByKey.has(t.toLowerCase()))&&e.nodeByKey.set(t.toLowerCase(),o),n.label&&!e.nodeByKey.has(n.label.toLowerCase())&&e.nodeByKey.set(n.label.toLowerCase(),o),o}function Pt(e,t){let n=t.toLowerCase(),r=e.groupByKey.get(n);if(r)return r;let i=F(P(t),e.usedIds);return e.groups.push({id:i,label:t}),e.groupByKey.set(n,i),i}function Ft(e,t,n,r){let i=Pt(e,t),a=e.groups.find(e=>e.id===i);return a&&(a.icon??=n.icon,a.color??=n.color,a.frame??=n.frame,r&&!a.parent&&r!==i&&(a.parent=r),n.label&&(a.label=n.label)),i}function It(e,t,n,r,i,a){let o=(n??t).toLowerCase(),s=e.nodeByKey.get(o)??e.nodeByKey.get(t.toLowerCase());if(s){let t=e.actors.find(e=>e.id===s);return t&&(r&&(t.label=r),t.icon??=i,t.link??=a),s}let c=F(n??P(t),e.usedIds);return e.actors.push({id:c,label:r??t,icon:i,link:a}),e.nodeByKey.set(o,c),e.nodeByKey.set(t.toLowerCase(),c),r&&!e.nodeByKey.has(r.toLowerCase())&&e.nodeByKey.set(r.toLowerCase(),c),c}function Lt(e,t,n){let{attrs:r,rest:i}=V(t.trim()),a=W(r,n,e,Mt(e)),{id:o,name:s}=Bt(i);if(!s)return null;if(!(e.nodeByKey.get((o??s).toLowerCase())??e.nodeByKey.get(s.toLowerCase()))){let t=e.groupByKey.get(s.toLowerCase());if(t)return t}return Nt(e,s,a,o)}function Rt(e,t,n){let{attrs:r,rest:i}=V(t.trim()),a=W(r,n,e),{id:o,name:s}=Bt(i);return s?It(e,s,o,a.label,a.icon,a.link):null}function zt(e,t){let n=e.nodeByKey.get(t.toLowerCase());if(n)return n;let r=t.lastIndexOf(`.`);return r>0?e.nodeByKey.get(t.slice(0,r).trim().toLowerCase())??null:null}function Bt(e){let t=I(e,`=`);if(t===-1)return{name:z(e)};let n=e.slice(0,t).trim(),r=z(e.slice(t+1));return/^[A-Za-z0-9_-]+$/.test(n)?{id:n.toLowerCase(),name:r}:{name:z(e)}}var Vt=[...vt,...xt,...ft,...Object.keys(pt).flatMap(e=>[e,e.toUpperCase()])],Ht=[...ft];function Ut(e,t){let n=I(e,`:`,t);for(;n!==-1&&(e[n+1]===`:`||e[n-1]===`:`);)n=I(e,`:`,e[n+1]===`:`?n+2:n+1);return n}function Wt(e,t,n){let r=G(e)===`erd`?Vt:Ht,i=Ot(t,r);if(!i)return!1;let a=Ut(t,i.index+Dt(i.token)),o=a===-1?void 0:t.slice(a+1).trim()||void 0,s={};if(o!==void 0&&G(e)!==`erd`){let t=V(o);t.attrs!==null&&(s=W(t.attrs,n,e),o=t.rest.trim()||void 0)}let c=kt(a===-1?t:t.slice(0,a),r);if(!c)return!1;if(G(e)===`sequence`){let t=Rt(e,c.first,n),r=Rt(e,c.hops[0].segment,n);if(!t||!r)return e.diagnostics.push({line:n,message:`message needs both ends`,severity:`error`}),!0;c.hops.length>1&&e.diagnostics.push({line:n,message:`one message per line in sequence diagrams`});let i=c.hops[0].token,a=Ct(i);return e.messages.push({from:a?r:t,to:a?t:r,label:o??``,reply:St(i)||void 0,bidirectional:wt(i)||void 0}),!0}if(G(e)===`erd`){let t=z(c.first),r=c.hops[0],i=z(r.segment),a=zt(e,t),s=zt(e,i);if(!a||!s)return e.diagnostics.push({line:n,message:`relation references an undeclared table (${a?i:t})`,severity:`error`}),!0;let l=bt[r.token],u=_t[r.token],d=u||l?void 0:pt[r.token.toLowerCase()],f=l?l.swap:d?.swap;return c.hops.length>1&&e.diagnostics.push({line:n,message:`one relation per line in ERDs`}),e.relations.push({from:f?s:a,to:f?a:s,cardinality:d?.value,fromCard:u?.from,toCard:u?.to,identifying:u&&!u.identifying?!1:void 0,kind:l?.kind,label:o}),!0}let l=R(c.first,`,`).map(t=>Lt(e,t,n)).filter(e=>e!==null);for(let t of c.hops){let r=t.token,i=R(t.segment,`,`).map(t=>Lt(e,t,n)).filter(e=>e!==null);if(l.length===0||i.length===0)return e.diagnostics.push({line:n,message:`edge needs both ends`,severity:`error`}),!0;for(let t of l)for(let n of i)e.edges.push({from:Ct(r)?n:t,to:Ct(r)?t:n,label:o,dashed:St(r)||void 0,bidirectional:wt(r)||void 0,color:s.color,flow:s.flow||void 0,head:s.head,invisible:s.invisible||void 0,back:Ct(r)||void 0});l=i}return!0}var Gt={"+":`public`,"-":`private`,"#":`protected`,"~":`package`},Kt=new Set([`(`,`<`,`[`,`{`]),qt=new Set([`)`,`>`,`]`,`}`]);function Jt(e){let t=[],n=0,r=!1,i=``;for(let a of e){if(a===`"`)r=!r;else if(!r&&Kt.has(a))n+=1;else if(!r&&qt.has(a))n=Math.max(0,n-1);else if(!r&&n===0&&/\s/.test(a)){i&&t.push(i),i=``;continue}i+=a}return i&&t.push(i),t}function Yt(e,t,n){if(e.currentEntity){let r=e.currentEntity,i=Jt(t.replace(/,$/,``));if(i.length===0)return!0;let a=z(i[0]);if(/^-{2,}$/.test(a)&&i.length===1)return r.methods??=[],!0;let o=/^([+\-#~])(.+)$/.exec(a),s=o?Gt[o[1]]:void 0,c=(o?o[2]:a).replace(/:$/,``),l,u;for(let t of i.slice(1)){let r=t.toLowerCase();r===`pk`||r===`fk`?u=r:l?e.classHeader?l=`${l} ${t}`:e.diagnostics.push({line:n,message:`extra field token "${t}"`}):l=z(t)}let d={name:c,type:l,key:u,visibility:s};return r.methods===void 0?(r.fields??=[]).push(d):r.methods.push(d),!0}let r=/^group\b([^{]*)\{$/i.exec(t),i=r?V(r[1].trim()):null;if(i&&z(i.rest)){let t=W(i.attrs,n,e);return e.erdGroupStack.push(Ft(e,z(i.rest),t,null)),!0}if(t.endsWith(`{`)||/\{\s*\}$/.test(t)){let r=/\{\s*\}$/.test(t),{attrs:i,rest:a}=V(t.replace(/\{\s*\}?$/,``).trim()),o=W(i,n,e),{id:s,name:c}=Bt(a);if(!c)return e.diagnostics.push({line:n,message:`table needs a name`,severity:`error`}),!0;let l=F(s??P(c),e.usedIds),u={id:l,label:o.label??c,color:o.color,fields:[],group:e.erdGroupStack[e.erdGroupStack.length-1]};return e.entities.push(u),e.nodeByKey.set((s??c).toLowerCase(),l),e.nodeByKey.set(c.toLowerCase(),l),r||(e.currentEntity=u),!0}return Wt(e,t,n)||e.diagnostics.push({line:n,message:`expected a table or relation`,severity:`error`}),!0}function Xt(e){let t=e.raw;t.kind=`erd`,t.entities=e.entities,t.relations=e.relations,t.groups=e.groups,t.variant=e.classHeader?`class`:void 0}function Zt(e,t,n){let r=/^(loop|alt|opt|par|break)\b(.*)\{$/.exec(t);if(r)return e.blockStack.push({kind:r[1],label:r[2].trim()||r[1],start:e.messages.length}),!0;let i=/^note\s+(over|left of|right of)\s+(.+?)\s*:\s*(.*)$/i.exec(t);if(i){let t=i[1].toLowerCase().startsWith(`over`)?`over`:i[1].toLowerCase().startsWith(`left`)?`left`:`right`,r=R(i[2],`,`).map(e=>e.trim()).filter(e=>e.length>0).map(t=>It(e,z(t)));return r.length===0?e.diagnostics.push({line:n,message:`note needs a lifeline`}):e.notes.push({text:i[3].trim(),actors:r,placement:t,after:e.messages.length-1}),!0}let a=/^(activate|deactivate)\s+(.+)$/i.exec(t);if(a){let t=It(e,z(a[2]));if(a[1].toLowerCase()===`activate`)if(e.activationOpen.has(t))e.diagnostics.push({line:n,message:`"${a[2]}" is already active`});else{let n=e.messages[e.messages.length-1],r=n&&(n.from===t||n.to===t);e.activationOpen.set(t,r?e.messages.length-1:e.messages.length)}else{let r=e.activationOpen.get(t);r===void 0?e.diagnostics.push({line:n,message:`deactivate without activate for "${a[2]}"`}):(e.activationOpen.delete(t),e.messages.length>r&&e.activations.push({actor:t,from:r,to:e.messages.length-1}))}return!0}if(Wt(e,t,n))return!0;let{attrs:o,rest:s}=V(t),c=W(o,n,e),{id:l,name:u}=Bt(s);return u&&It(e,u,l,c.label,c.icon,c.link),!0}function Qt(e){let t=e.raw;t.kind=`sequence`,t.actors=e.actors,t.messages=e.messages,t.frames=e.frames,t.activations=e.activations,t.notes=e.notes}function $t(e,t,n){let r=/^screen\b(.*)\{$/i.exec(t);if(r){let{attrs:t,rest:i}=V(r[1].trim()),a=W(t,n,e);return e.currentScreen={name:z(i)||`Screen ${e.screens.length+1}`,frame:a.frame??`phone`,controls:[]},e.screens.push(e.currentScreen),!0}if(!e.currentScreen)return e.diagnostics.push({line:n,message:"expected `screen Name { … }`",severity:`error`}),!0;let i=e.currentScreen,{attrs:a,rest:o}=V(t),s=W(a,n,e),c=I(o,`:`),l=(c===-1?o:o.slice(0,c)).trim().toLowerCase(),u=c===-1?void 0:o.slice(c+1).trim()||void 0;return qe.has(l)?(i.controls??=[],i.controls.push({kind:l,label:s.label??u,width:s.width,value:s.value}),!0):(e.diagnostics.push({line:n,message:`unknown widget "${l}"`,severity:`error`}),!0)}function en(e){let t=e.raw;t.kind=`wireframe`,t.screens=e.screens}var tn={bar:`bar`,column:`bar`,xychart:`bar`,xy:`bar`,line:`line`,area:`area`,scatter:`scatter`,pie:`pie`,donut:`donut`,doughnut:`donut`,radar:`radar`,quadrant:`quadrant`},nn=[...new Set(Object.values(tn))],rn=new Set([`chart`,`pie`,`xychart`,`radar`,...Object.keys(tn)]);function an(e){let t=e.trim().toLowerCase().split(/\s+/),n=t[0];return n===`chart`?tn[t[1]??``]??`bar`:tn[n]??`bar`}function on(e){return R(e,`,`).map(e=>z(e.trim())).filter(e=>e.length>0)}function sn(e){let t=/^\[?\s*([-\d.]+)\s*,\s*([-\d.]+)\s*\]?$/.exec(e.trim());return t?[t[1],t[2]]:null}function cn(e){let t=[],n=e.split(`
8
+ `),r=n.findIndex(e=>L(e).trim().length>0);if(r===-1)return{spec:null,diagnostics:t};let i=an(L(n[r]).trim()),a,o,s,c,l,u,d=null,f=[],p=[],m=i===`quadrant`,h=[``,``,``,``],g=[];for(let e=r+1;e<n.length;e+=1){let r=L(n[e]).trim();if(!r)continue;let i=r.toLowerCase();if(i===`showvalues`||i===`values`||i===`showdata`){c=!0;continue}if(i===`stacked`){l=!0;continue}if(i===`horizontal`){u=!0;continue}let _=r.indexOf(`:`);if(_===-1){t.push({line:e+1,message:`chart rows are "label: values"; skipped "${r}"`});continue}let v=r.slice(0,_).trim(),y=v.toLowerCase(),b=r.slice(_+1).trim();if(y===`title`){a=z(b);continue}if(y===`x-axis`||y===`xaxis`||y===`x`){o=z(b);continue}if(y===`y-axis`||y===`yaxis`||y===`y`){s=z(b);continue}if(m){let n=/^quadrant-([1-4])$/.exec(y);if(n){h[Number(n[1])-1]=z(b);continue}let i=sn(b);if(i){g.push([z(v),i[0],i[1]]);continue}t.push({line:e+1,message:`quadrant rows are "label: [x, y]"; skipped "${r}"`});continue}if(y===`categories`||y===`axis`||y===`labels`){d=on(b);continue}let x=/^series\s+(.+)$/i.exec(v),S=z((x?x[1]:v).trim()),C=on(b);if(C.length===0){t.push({line:e+1,message:`"${v}" has no numeric values`});continue}d||x?f.push({name:S,values:C}):p.push({label:S,values:C})}let _=m?[[``,`x`,`y`],...g]:un(d,f,p);return _.length<2?(t.push({line:0,message:`chart has no data rows`,severity:`error`}),{spec:null,diagnostics:t}):{spec:{chartType:i,title:a,xTitle:o,yTitle:s,cells:_,showValues:c,stacked:l,horizontal:u,showLegend:m?void 0:ln(i,_,f.filter(e=>e.name).length)||void 0,quadrantLabels:m&&h.some(Boolean)?h:void 0},diagnostics:t}}function ln(e,t,n){return e===`pie`||e===`donut`?t.slice(1).some(e=>(e[0]??``).trim().length>0):e===`radar`?n>=1:n>=2}function un(e,t,n){if(e&&t.length>0)return[[``,...t.map(e=>e.name||`Value`)],...e.map((e,n)=>[e,...t.map(e=>e.values[n]??``)])];if(t.length>0){let e=Math.max(...t.map(e=>e.values.length)),n=[``,...t.map(e=>e.name||`Value`)],r=[];for(let n=0;n<e;n+=1)r.push([`${n+1}`,...t.map(e=>e.values[n]??``)]);return[n,...r]}if(n.length>0){let e=Math.max(...n.map(e=>e.values.length));return[e<=1?[``,`Value`]:[``,...Array.from({length:e},(e,t)=>`Series ${t+1}`)],...n.map(t=>[t.label,...Array.from({length:e},(e,n)=>t.values[n]??``)])]}return[]}function dn(e){let t=Math.max(0,e.cells.length-1);if(e.chartType===`quadrant`)return`a quadrant chart · ${t} ${t===1?`point`:`points`}`;let n=Math.max(0,e.cells[0].length-1),r=n===1?`1 series`:`${n} series`;return`a ${e.chartType} chart · ${t} ${t===1?`row`:`rows`} · ${r}`}var fn=new Set([...dt,...rn]),pn=new Set(y),mn=new Set([`[*]`,`start`,`begin`,`initial`]),hn=new Set([`end`,`final`,`stop`,`done`]);function gn(e,t){if(e===`flowchart`||e===`bpmn`||e===`orgchart`){t.shape??=`rectangle`;return}if(e!==`statemachine`)return;let n=t.id??``,r=(t.label??``).toLowerCase();mn.has(n)||mn.has(r)?(t.shape??=`circle`,t.fill??=`bold`,t.color??=`gray`):hn.has(n)||hn.has(r)?t.shape??=`double-circle`:t.shape??=`ellipse`}function _n(e,t,n){let r=w[t.toLowerCase()];if(r&&e.family===null&&e.nodes.length===0&&e.actors.length===0&&e.entities.length===0&&e.screens.length===0&&!e.title){e.family=r;let n=t.toLowerCase();return e.classHeader=n===`class`||n===`uml`,!0}if(e.inLegend&&!t.startsWith(`}`)){let r=I(t,`:`);return r===-1?(e.diagnostics.push({line:n,message:"legend rows are `swatch: meaning`",severity:`error`}),!0):(e.legendEntries.push({swatch:z(t.slice(0,r)),label:t.slice(r+1).trim()}),!0)}if(t.startsWith(`}`)){let r=t.slice(1).trim();if(e.inLegend)return e.inLegend=!1,!0;if(G(e)===`sequence`&&e.blockStack.length>0){let t=e.blockStack.pop();e.messages.length>t.start?e.frames.push({kind:t.kind,label:t.label,from:t.start,to:e.messages.length-1}):e.diagnostics.push({line:n,message:`empty ${t.kind} block`});let i=/^(else|and)\b(.*)\{$/.exec(r);return i?e.blockStack.push({kind:i[1]===`and`?`par`:`alt`,label:i[2].trim()||i[1],start:e.messages.length}):r&&e.diagnostics.push({line:n,message:`unexpected "${r}" after }`,severity:`error`}),!0}return e.currentEntity?(e.currentEntity=null,!0):e.erdGroupStack.length>0?(e.erdGroupStack.pop(),!0):e.currentScreen?(e.currentScreen=null,!0):e.groupStack.length>0?(e.groupStack.pop(),!0):(e.diagnostics.push({line:n,message:`unmatched }`,severity:`error`}),!0)}if(/^legend\b.*\{$/i.test(t))return e.inLegend=!0,!0;let i=/^direction\s+(right|down|left|up)$/i.exec(t);if(i&&!e.currentEntity&&!e.currentScreen)return e.direction=i[1].toLowerCase(),!0;if(/^kanban$/i.test(t)&&!e.currentEntity&&!e.currentScreen)return e.kanban=!0,!0;let a=/^title\s+(\S.*)$/i.exec(t);if(a&&!e.title&&!e.currentEntity&&!e.currentScreen)return e.title=z(a[1].trim()),!0;let o=/^(colorMode|styleMode|typeface|autoNumber)\b\s*:?\s*(.*)$/i.exec(t);if(o&&!e.currentEntity&&!e.currentScreen){let t=o[1].toLowerCase(),r=o[2].trim().toLowerCase();return t===`colormode`&&U[r]?e.defaultFill=U[r]:e.diagnostics.push({line:n,message:`${o[1]} isn't supported; skipped`}),!0}let s=/^(title|direction|icons)\s*:\s*(.+)$/i.exec(t);if(s&&!e.currentEntity&&!e.currentScreen){let t=s[1].toLowerCase(),r=s[2].trim();if(t===`title`)e.title=z(r);else if(t===`icons`){let t=r.toLowerCase();t===`inside`||t===`badge`||t===`hanging`?e.icons=t===`inside`?`inside`:`badge`:e.diagnostics.push({line:n,message:`icons "${r}" is not supported (badge, inside)`})}else{let t=r.toLowerCase();t===`down`||t===`right`||t===`up`||t===`left`?e.direction=t:e.diagnostics.push({line:n,message:`direction "${r}" is not supported (right, down, left, up)`})}return!0}return!1}function vn(e,t,n){let r=t.replace(/^group\b/i,``),i=r!==t,a=(i?/^(.*)\{$/:/^([^{]+)\{$/).exec(r);if(a){let{attrs:t,rest:r}=V(a[1].trim()),i=W(t,n,e),o=z(r)||`Group ${e.groups.length+1}`;return e.groupStack.push(Ft(e,o,i,jt(e))),!0}let o=(i?/^([^{]*)\{(.*)\}$/:/^([^{]+)\{(.+)\}$/).exec(r);if(o){let{attrs:t,rest:r}=V(o[1].trim()),i=W(t,n,e),a=Ft(e,z(r)||`Group ${e.groups.length+1}`,i,jt(e));for(let t of R(o[2],`,`)){let r=z(t);r&&yn(e,Nt(e,r,{}),a,n)}return!0}if(Wt(e,t,n))return!0;let s=jt(e),c=s?R(t,`,`):[t];for(let t of c){let r=t.trim();if(!r)continue;let{attrs:i,rest:a}=V(r),o=W(i,n,e,Mt(e)),{id:c,name:l}=Bt(a);if(!l){e.diagnostics.push({line:n,message:`expected a node name`,severity:`error`});continue}let u=Nt(e,l,o,c);s&&yn(e,u,s,n)}return!0}function yn(e,t,n,r){let i=e.nodes.find(e=>e.id===t);if(!i)return;let a=i.group;if(i.group=n,a===void 0||a===n)return;let o=t=>e.groups.find(e=>e.id===t)?.label??t;e.diagnostics.push({line:r,message:`"${i.label}" is already in group "${o(a)}" — one name is one node, so it moved to "${o(n)}". For a separate node with the same label, give it its own id: \`${P(o(n))}-${i.id} = ${i.label}\` (and use that id in its edges)`})}function bn(e){let t=G(e),n=e.raw;if(n.title=e.title,n.legend=e.legendEntries.length>0?e.legendEntries:void 0,t===`sequence`)Qt(e);else if(t===`erd`)Xt(e);else if(t===`wireframe`)en(e);else{n.kind=`graph`;let r=t===`flowchart`||t===`bpmn`||t===`orgchart`;n.direction=e.direction??(r?`down`:`right`),n.icons=e.icons,n.swimlanes=t===`bpmn`||void 0,n.kanban=e.kanban?!0:void 0,n.variant=t===`orgchart`?`orgchart`:t===`statemachine`?`statemachine`:void 0;for(let n of e.nodes)gn(t,n);if(e.defaultFill)for(let t of e.nodes)t.fill??=e.defaultFill;n.nodes=e.nodes,n.groups=e.groups,n.edges=e.edges;for(let t of e.groups){let n=e.nodes.some(e=>e.group===t.id),r=e.groups.some(e=>e.parent===t.id&&e.id!==t.id);!n&&!r&&e.diagnostics.push({line:0,message:`group "${t.label}" has no members`})}}return{diagram:j(n),diagnostics:e.diagnostics,iconUses:e.iconUses}}function xn(e){let t=e.split(`
9
+ `).map(e=>L(e).trim().toLowerCase()).find(e=>e.length>0);if(t===`mindmap`)return ut(e);if(t===`gitgraph`)return Re(e);if(t===`gantt`)return Ie(e);if(t===`sankey`)return ze(e);let n=(t??``).split(/\s+/)[0];if(pn.has(n))return lt(e,n);if(rn.has(n)){let{spec:t,diagnostics:n}=cn(e);return{diagram:j({kind:`graph`}),chart:t??void 0,diagnostics:n,iconUses:[]}}let r=At(),i=e.split(`
10
+ `);for(let e=0;e<i.length;e+=1){let t=e+1,n=L(i[e]).trim();if(n&&!_n(r,n,t)){if(G(r)===`sequence`){Zt(r,n,t);continue}if(G(r)===`erd`){Yt(r,n,t);continue}if(G(r)===`wireframe`){$t(r,n,t);continue}vn(r,n,t)}}for(let e of r.blockStack)r.messages.length>e.start&&r.frames.push({kind:e.kind,label:e.label,from:e.start,to:r.messages.length-1}),r.diagnostics.push({line:i.length,message:`unclosed ${e.kind} block`,severity:`error`});for(let[e,t]of r.activationOpen)r.messages.length>t&&r.activations.push({actor:e,from:t,to:r.messages.length-1});return bn(r)}var Sn={architecture:`architecture`,graph:`architecture`,flowchart:`flowchart`,flow:`flowchart`,bpmn:`flowchart`,sequence:`sequence`,erd:`erd`,wireframe:`flowchart`},Cn={"<-->":`<-->`,"-->":`-->`,"<--":`<--`,"<>":`<->`,"--":`-->`,">":`->`,"<":`<-`,"-":`->`},wn={"<>":`N:M`,">":`N:1`,"<":`1:N`,"-":`1:1`},Tn=/^[\w"][\w" -]*\s+[\w(),]+\s+(pk|fk)\s*$/i,En=/^(loop|alt|opt|par|break)\b.*\{\s*$/i,Dn=/^(activate|deactivate)\s+\S/i,On=/\[[^\]]*\b(diamond|oval|circle|cylinder|hexagon|parallelogram|trapezoid|triangle|cloud|star|queue|callout|note|sticky)\b[^\]]*\]/i,kn=[`<-->`,`<..>`,`<->`,`-->`,`<--`,`<..`,`..>`,`<-`,`->`,`<>`,`>`,`<`,`--`,`-`];function An(e){let t=0,n=-1;for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`[`)t+=1;else if(i===`]`)t=Math.max(0,t-1);else if(i===`:`&&t===0){n=r;break}}let r=(n>=0?e.slice(0,n):e).trim(),i=e=>e.replace(/\s*\[[^\]]*\]\s*$/,``).trim();for(let e of kn){let t=r.indexOf(` ${e} `);if(t>=0)return{src:i(r.slice(0,t)),dst:i(r.slice(t+e.length+2))}}return null}function jn(e){let t=0,n=0,r=0,i=0,a=0,o=new Set;for(let s of e){if(!s)continue;Tn.test(s)&&(t+=1),(En.test(s)||Dn.test(s))&&(n+=1),On.test(s)&&(i+=1),/\{\s*$/.test(s)&&!En.test(s)&&!s.startsWith(`}`)&&(a+=1);let e=An(s);e&&e.src&&e.dst&&(r+=1,o.add(e.src.toLowerCase()),o.add(e.dst.toLowerCase()),e.src.toLowerCase()===e.dst.toLowerCase()&&(n+=2))}return t>0?`erd`:n>0||r>=3&&i===0&&a===0&&o.size>0&&r/o.size>=1.3?`sequence`:e.some(e=>/icon:\s*(aws|gcp|azure|tech)[-/]/i.test(e))?`architecture`:`flowchart`}function Mn(e,t){let n=[...new Set([...Object.keys(t),...ft])].sort((e,t)=>t.length-e.length),r=new Set,i=``,a=!1,o=0,s=0;for(;s<e.length;){let c=e[s];if(c===`"`){a=!a,i+=c,s+=1;continue}if(a){i+=c,s+=1;continue}if(c===`[`){o+=1,i+=c,s+=1;continue}if(c===`]`){o=Math.max(0,o-1),i+=c,s+=1;continue}if(o>0){i+=c,s+=1;continue}let l=!1;for(let a of n){if(!e.startsWith(a,s))continue;let n=t[a];if(n===void 0){i+=a,s+=a.length,l=!0;break}let o=s===0?` `:e[s-1],c=s+a.length>=e.length?` `:e[s+a.length];if(!(!/\s/.test(o)||!/\s/.test(c))){i+=n,r.add(a),s+=a.length,l=!0;break}}l||(i+=c,s+=1)}return{text:i,rewrote:r}}function Nn(e,t,n){let{rest:r,attrs:i}=V(e.slice(0,e.lastIndexOf(`{`)).trimEnd());if(i===null)return e;let a=[];for(let e of R(i,`,`)){let r=e.trim();if(!r)continue;let i=r.indexOf(`:`),o=i===-1?null:r.slice(0,i).trim().toLowerCase();if(o===`color`||o===`label`){a.push(r);continue}let s=i===-1?r.toLowerCase():null;if(s&&(H[s]||nt(z(r)))){a.push(r);continue}n.push({line:t,message:o===`icon`?`table icons aren't supported; dropped "${r.slice(i+1).trim()}"`:`"${r}" isn't supported on tables; dropped`})}let o=r.trim();return a.length>0?`${o} [${a.join(`, `)}] {`:`${o} {`}function Pn(e){for(let t of R(e,`,`)){let e=t.trim(),n=e.indexOf(`:`);if(n!==-1&&e.slice(0,n).trim().toLowerCase()===`label`)return z(e.slice(n+1))}return z(e)}function Fn(e){let t=e.split(`
11
+ `),n=t.map(e=>L(e).trim()),r=Sn[(n.find(Boolean)??``).toLowerCase()];if(r)return{code:e,family:r,diagnostics:[]};let i=jn(n),a=[],o=[i,``],s=!1;for(let e=0;e<t.length;e+=1){let n=o.length+1,r=t[e],c=L(r),l=r.slice(c.length),u=c.trim(),d=c.slice(0,c.length-c.trimStart().length);if(!u){o.push(r);continue}let f=/^(styleMode|typeface|autoNumber)\b/i.exec(u);if(f&&!s){a.push({line:n,message:`${f[1]} isn't supported; removed`}),o.push(`${d}// ${u} (not supported)${l}`);continue}if(/^colorMode\b/i.test(u)&&!s){o.push(`${d}${u.replace(/^colorMode\s*:?\s*/i,`colorMode `)}${l}`);continue}if(i===`erd`){if(s){u.startsWith(`}`)&&(s=!1),o.push(r);continue}if(u.endsWith(`{`)){o.push(`${d}${Nn(u,n,a)}${l}`),s=!0;continue}let{text:e}=Mn(c,wn);o.push(`${e}${l}`);continue}if(i===`sequence`){let e=/^(loop|alt|opt|par|break)\s*\[(.*)\]\s*\{$/i.exec(u);if(e){let t=Pn(e[2]);o.push(`${d}${e[1].toLowerCase()}${t?` ${t}`:``} {${l}`);continue}let t=/^\}\s*(else|and)\s*\[(.*)\]\s*\{$/i.exec(u);if(t){let e=Pn(t[2]);o.push(`${d}} ${t[1].toLowerCase()}${e?` ${e}`:``} {${l}`);continue}}let{text:p,rewrote:m}=Mn(c,Cn);(m.has(`-`)||m.has(`--`))&&a.push({line:n,message:`plain lines render as arrows`}),o.push(`${p}${l}`)}return{code:o.join(`
12
+ `),family:i,diagnostics:a}}function In(e){let t=e.split(`
13
+ `).map(e=>L(e).trim()).filter(Boolean);if(t.length===0||fn.has(t[0].toLowerCase().split(/\s+/)[0]))return!1;let n=!1;for(let e of t){if(/(^|\s)(-->|<--|<-->)(\s|$)/.test(e)){n=!0;continue}if(/->|\.\.>|<\.\./.test(e)||/(^|\s)<-(\s|$)/.test(e)||/(^|\s)(1:1|1:N|N:1|N:M|M:N)(\s|$)/i.test(e))return!1;/(^|\s)(>|<|<>|-)\s/.test(e)&&(n=!0),/^(colorMode|styleMode|typeface|autoNumber)\b/i.test(e)&&(n=!0),/\[[^\]]*icon\s*:[^\]]*\]\s*\{$/.test(e)&&(n=!0),/^(loop|alt|opt|par|break)\s*\[label\s*:/i.test(e)&&(n=!0)}return n}function Ln(e){let t=e.trim(),n=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(t);return n&&(t=`#${n[1]}${n[1]}${n[2]}${n[2]}${n[3]}${n[3]}`),nt(t)}function Rn(e){let t=/fill:\s*([^,;]+)/i.exec(e),n=/stroke:\s*([^,;]+)/i.exec(e),r=t?.[1]??n?.[1];return!r||/none|transparent/i.test(r)?n&&n!==t?Ln(n[1]):null:Ln(r)}function K(e){if(/%%\{/.test(e))return e;let t=e.indexOf(`%%`);return t>=0?e.slice(0,t):e}function zn(e){return!Number.isInteger(e)||e<1||e>1114111?``:String.fromCodePoint(e)}function q(e){let t=e.trim();t.length>=2&&/^["'].*["']$/.test(t)&&(t=t.slice(1,-1).trim());let n=t.startsWith("`")&&t.endsWith("`");return t=t.replace(/<br\s*\/?>/gi,` `).replace(/^`+|`+$/g,``),n&&(t=t.replace(/\*\*([^*]+)\*\*/g,`$1`).replace(/\*([^*]+)\*/g,`$1`).replace(/__([^_]+)__/g,`$1`).replace(/_([^_]+)_/g,`$1`)),t.replace(/\*\*/g,``).replace(/\\"/g,`"`).replace(/&?#x([0-9a-f]+);/gi,(e,t)=>zn(parseInt(t,16))).replace(/&?#(\d+);/g,(e,t)=>zn(Number(t))).replace(/\b(fa|fab|fas|far|fal|fad|fak):[a-z0-9-]+/gi,``).replace(/\s+/g,` `).trim()}function Bn(e){let t=[],n=``,r=!1;for(let i of e){let e=r?`${n} ${i.trim()}`:i;(e.match(/"/g)??[]).length%2==1?(n=e,r=!0):(t.push(e),n=``,r=!1)}return r&&t.push(n),t}function J(e){return/[:=[\]{}<>]|->|--|\/\//.test(e)?`"${e.replace(/"/g,``)}"`:e}function Y(e){return/[[\]{}]/.test(e)||/\/\//.test(e)?`"${e.replace(/"/g,``)}"`:e}function Vn(e,t){if(!t||/^title:/m.test(e))return e;let n=e.split(`
14
+ `);return n.splice(1,0,`title: ${t}`),n.join(`
15
+ `)}function X(e){return e.join(`
16
+ `).replace(/\n{3,}/g,`
17
+
18
+ `).trimEnd()+`
19
+ `}function Hn(e){let t=e.replace(/%%\{[\s\S]*?\}%%/g,``),n,r=0,i=/^\s*---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(t);if(i){let e=/^\s*title:\s*(.+)$/m.exec(i[1]);e&&(n=q(e[1].trim())),t=t.slice(i[0].length),r=i[0].split(`
20
+ `).length-1}return{lines:t.split(`
21
+ `),title:n,dropped:r}}var Un={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Wn=[{open:`(((`,close:`)))`,shape:`double-circle`},{open:`([`,close:`])`,shape:`ellipse`},{open:`[[`,close:`]]`,shape:`predefined-process`},{open:`[(`,close:`)]`,shape:`cylinder`},{open:`((`,close:`))`,shape:`circle`},{open:`{{`,close:`}}`,shape:`hexagon`},{open:`[/`,close:`/]`,shape:`parallelogram`},{open:`[\\`,close:`\\]`,shape:`parallelogram`},{open:`[/`,close:`\\]`,shape:`trapezoid`},{open:`[\\`,close:`/]`,shape:`trapezoid`},{open:`[`,close:`]`,shape:null},{open:`(`,close:`)`,shape:null},{open:`{`,close:`}`,shape:`diamond`},{open:`>`,close:`]`,shape:`chevron`}],Gn={rect:`rectangle`,proc:`rectangle`,process:`rectangle`,rectangle:`rectangle`,rounded:`rectangle`,event:`rectangle`,"lin-rect":`rectangle`,"lin-proc":`rectangle`,"lined-process":`rectangle`,"lined-rectangle":`rectangle`,"shaded-process":`rectangle`,"div-rect":`rectangle`,"div-proc":`rectangle`,"divided-process":`rectangle`,"divided-rectangle":`rectangle`,"win-pane":`rectangle`,"internal-storage":`rectangle`,"window-pane":`rectangle`,text:`rectangle`,odd:`rectangle`,"tag-rect":`rectangle`,"tag-proc":`rectangle`,"tagged-process":`rectangle`,"tagged-rectangle":`rectangle`,"st-rect":`multi-process`,processes:`multi-process`,procs:`multi-process`,"stacked-rectangle":`multi-process`,fork:`fork-join`,join:`fork-join`,stadium:`ellipse`,pill:`ellipse`,terminal:`ellipse`,delay:`delay`,"half-rounded-rectangle":`delay`,hourglass:`ellipse`,collate:`ellipse`,display:`ellipse`,"curv-trap":`ellipse`,"curved-trapezoid":`ellipse`,"fr-rect":`predefined-process`,subproc:`predefined-process`,subprocess:`predefined-process`,subroutine:`predefined-process`,"framed-rectangle":`predefined-process`,diam:`diamond`,decision:`diamond`,diamond:`diamond`,question:`diamond`,cyl:`cylinder`,cylinder:`cylinder`,database:`cylinder`,db:`cylinder`,"lin-cyl":`cylinder`,"lined-cylinder":`cylinder`,disk:`cylinder`,"h-cyl":`cylinder`,"horizontal-cylinder":`cylinder`,das:`cylinder`,"bow-rect":`cylinder`,"bow-tie-rectangle":`cylinder`,"stored-data":`cylinder`,datastore:`cylinder`,"data-store":`cylinder`,"lean-r":`parallelogram`,"lean-right":`parallelogram`,"in-out":`parallelogram`,"lean-l":`parallelogram`,"lean-left":`parallelogram`,"out-in":`parallelogram`,flag:`parallelogram`,"paper-tape":`parallelogram`,"trap-b":`trapezoid`,"trapezoid-bottom":`trapezoid`,trapezoid:`trapezoid`,priority:`trapezoid`,"trap-t":`trapezoid`,"trapezoid-top":`trapezoid`,"inv-trapezoid":`trapezoid`,manual:`trapezoid`,doc:`document`,document:`document`,"lin-doc":`document`,"lined-document":`document`,"tag-doc":`document`,"tagged-document":`document`,docs:`multi-document`,documents:`multi-document`,"st-doc":`multi-document`,"stacked-document":`multi-document`,tri:`triangle`,triangle:`triangle`,extract:`triangle`,"flip-tri":`triangle`,"flipped-triangle":`triangle`,"manual-file":`triangle`,cloud:`cloud`,bang:`star`,bolt:`bolt`,"com-link":`bolt`,"lightning-bolt":`bolt`,brace:`note`,"brace-l":`note`,"brace-r":`note`,braces:`note`,comment:`note`,"notch-rect":`card`,card:`card`,"notched-rectangle":`card`,"notch-pent":`pentagon`,"loop-limit":`pentagon`,"notched-pentagon":`pentagon`,"sl-rect":`manual-input`,"manual-input":`manual-input`,"sloped-rectangle":`manual-input`,hex:`hexagon`,hexagon:`hexagon`,prepare:`hexagon`,circle:`circle`,circ:`circle`,"sm-circ":`circle`,"small-circle":`circle`,start:`circle`,"dbl-circ":`double-circle`,"double-circle":`double-circle`,"fr-circ":`double-circle`,"framed-circle":`double-circle`,stop:`octagon`,"f-circ":`circle`,junction:`circle`,"filled-circle":`circle`,"cross-circ":`circle`,summary:`circle`,"crossed-circle":`circle`,icon:`rectangle`,img:`rectangle`},Kn=/\s*((?:<|o|x)?(?:-\.+-*|-{2,}|={2,}|~{3,})(?:>|o|x)?)\s*(?:\|([^|]*)\|)?\s*/,qn=new RegExp(Kn.source,`g`);function Jn(e,t){let n=/^classDef\s+(\S+)\s+(.+)$/i.exec(e);if(n){let e=Rn(n[2]);return e&&t.classColor.set(n[1],e),t.classAnim&&/animation/i.test(n[2])&&t.classAnim.add(n[1]),!0}let r=/^style\s+(\S+)\s+(.+)$/i.exec(e);if(r){let e=Rn(r[2]);return e&&t.styleColor.set(r[1],e),!0}let i=/^class\s+(.+?)\s+(\S+)$/i.exec(e);if(i){let e=t.keyOf??(e=>e);for(let n of i[1].split(`,`).map(e=>e.trim()).filter(Boolean))t.nodeClass.set(e(n),i[2]);return!0}return!1}function Yn(e){let t=e.trim(),n=/[ox]$/.exec(t),r=/^~{3,}$/.test(t);return{dashed:t.includes(`.`),bidir:/^[<ox]/.test(t)&&/[>ox]$/.test(t),head:n?n[0]===`o`?`circle`:`cross`:null,invisible:r}}function Xn(e){return e.replace(/--\s+([^|]+?)\s+-->/g,`-->|$1|`).replace(/==\s+([^|]+?)\s+==>/g,`==>|$1|`).replace(/-\.\s+([^|]+?)\s+\.->/g,`-.->|$1|`).replace(/--\s+([^|]+?)\s+---/g,`---|$1|`).replace(/==\s+([^|]+?)\s+===/g,`===|$1|`).replace(/-\.\s+([^|]+?)\s+\.-/g,`-.-|$1|`)}function Zn(e){let t=[],n=0,r=``,i=``;for(let a of e)r?(i+=a,a===r&&(r=``)):a===`"`||a===`'`?(r=a,i+=a):a===`[`||a===`(`||a===`{`?(n+=1,i+=a):a===`]`||a===`)`||a===`}`?(n=Math.max(0,n-1),i+=a):a===`&`&&n===0?(t.push(i),i=``):i+=a;return t.push(i),t}function Qn(e,t,n,r){let i=e.trim();if(!i)return null;let a=/^([A-Za-z0-9_-]+)@\{(.+)\}$/.exec(i);if(a){let e=/shape:\s*"?([A-Za-z0-9-]+)"?/.exec(a[2]),i=/label:\s*("([^"]*)"|'([^']*)'|[^,}]+)/.exec(a[2]),o=/icon:\s*"?([^",}]+)"?/.exec(a[2]);if(!e&&!i&&!o)return null;let s=e?Gn[e[1].toLowerCase()]??null:null,c=i?q(i[1]):null,l=o?$n(o[1]):null;return Z(a[1],c,s,r,t,n,l)}i=i.replace(/:::[A-Za-z0-9_-]+\s*$/,``).trim();let o=i,s=null,c=null,l=null;for(let e of Wn){let t=i.indexOf(e.open);if(t>0&&i.endsWith(e.close)){o=i.slice(0,t).trim(),l=i.slice(t+e.open.length,i.length-e.close.length),s=q(l),c=e.shape;break}}if(o=o.replace(/^["']|["']$/g,``).trim(),!o)return null;let u=null,d=l?/\b(fa[bsrld]?|fak):([a-z0-9-]+)/i.exec(l):null;return d&&(u=$n(`${d[1]}:${d[2]}`),s=s&&s.length>0?s:null),Z(o,s,c,r,t,n,u)}function Z(e,t,n,r,i,a,o=null){let s=i.get(e);return s?(t&&!s.label&&(s.label=t),n&&!s.shape&&(s.shape=n),o&&!s.icon&&(s.icon=o)):(i.set(e,{id:e,label:t,shape:n,group:r,icon:o}),a.push(e)),e}function $n(e){let t=e.trim().replace(/^["']|["']$/g,``);return(t.includes(`:`)?t.slice(t.lastIndexOf(`:`)+1):t).replace(/^fa-/,``)}function er(e,t){let n=/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/i.exec(e);if(!n)return!1;let r=Rn(n[2]),i=/animation/i.test(n[2]);if(/^default$/i.test(n[1].trim()))return r&&(t.linkDefaultColor=r),i&&(t.linkDefaultAnim=!0),!0;for(let e of n[1].split(`,`).map(e=>Number(e.trim())))Number.isInteger(e)&&(r&&t.linkColor.set(e,r),i&&t.linkAnim.add(e));return!0}function tr(e,t){let n=/^subgraph\s+(.+)$/i.exec(e);if(!n)return!1;let r=/^(\S+)\s*\[(.+)\]$/.exec(n[1].trim()),i=q((r?r[2]:n[1]).trim()),a=t.groupStack[t.groupStack.length-1]??null;return t.groupStack.push(i),t.groups.includes(i)||(t.groups.push(i),t.groupParents.set(i,a)),!0}function nr(e,t,n,r){let i=/^click\s+(\S+)\s+(.+)$/i.exec(e);if(!i)return!1;let a=i[2].trim().replace(/^href\s+/i,``),o=/^["']([^"']+)["']/.exec(a);return o?m(o[1])?(n.nodeLink.set(i[1],o[1]),!0):(r.push({line:t,message:`click link "${o[1]}" isn't imported (a node link needs a full URL)`}),!0):(r.push({line:t,message:`click callbacks aren't imported`}),!0)}function rr(e,t,n){let{nodes:r,order:i,edges:a}=t,o=[];for(let n of e.matchAll(/([A-Za-z0-9_-]+)@(?=(?:<|o|x)?[-=.])/g))t.edgeIds.add(n[1]),o.push(n[1]);let s=a.length,c=Xn(e.replace(/\b[A-Za-z0-9_-]+@(?=(?:<|o|x)?[-=.])/g,``));qn.lastIndex=0;let l=[],u=0,d;for(;d=qn.exec(c);)l.push({node:c.slice(u,d.index),link:{...Yn(d[1]),label:(d[2]??``).trim()}}),u=qn.lastIndex;l.push({node:c.slice(u)});let f=[];for(let e=0;e<l.length;e+=1){let t=Zn(l[e].node).map(e=>Qn(e,r,i,n)).filter(e=>e!==null);if(f.length>0&&t.length>0&&l[e-1].link){let n=l[e-1].link;for(let e of f)for(let r of t)a.push({src:e,dst:r,dashed:n.dashed,bidir:n.bidir,head:n.head,invisible:n.invisible,label:n.label})}t.length>0&&(f=t)}if(o.length>0&&a.length>s){let e=Array.from({length:a.length-s},(e,t)=>s+t);for(let n of o)t.edgeIndices.set(n,e)}}function ir(e){let{edges:t,nodeClass:n,classColor:r,linkColor:i,linkAnim:a}=e;for(let t of e.nodes.values()){let i=n.get(t.id);t.color=e.styleColor.get(t.id)??(i?r.get(i)??null:null),t.link=e.nodeLink.get(t.id)??null}for(let[i,a]of e.edgeIndices){let o=n.get(i),s=e.edgeAnimIds.has(i)||(o?e.classAnim.has(o):!1),c=o?r.get(o):void 0;for(let e of a)s&&(t[e].flow=!0),c&&(t[e].color=c)}for(let[e,n]of i)t[e]&&(t[e].color=n);for(let e of a)t[e]&&(t[e].flow=!0);let{linkDefaultColor:o,linkDefaultAnim:s}=e;(o||s)&&t.forEach((e,t)=>{o&&!i.has(t)&&(e.color??=o),s&&!a.has(t)&&(e.flow||=!0)})}function ar(e,t,n,r=`flowchart`){let i={nodes:new Map,order:[],edges:[],groups:[],groupStack:[],groupParents:new Map,edgeIds:new Set,classColor:new Map,classAnim:new Set,styleColor:new Map,nodeClass:new Map,edgeAnimIds:new Set,edgeIndices:new Map,linkColor:new Map,linkAnim:new Set,linkDefaultColor:null,linkDefaultAnim:!1,nodeLink:new Map},a=!1;for(let t=0;t<e.length;t+=1){let r=K(e[t]).trim();if(!r)continue;if(a){r.includes(`}`)&&(a=!1);continue}let o=/^acc(?:Title|Descr)\b\s*(\{)?/i.exec(r);if(o){o[1]&&!r.includes(`}`)&&(a=!0);continue}if(r.includes(`:::`))for(let e of r.matchAll(/([A-Za-z0-9_-]+)\s*(?:\[[^\]]*\]|\([^)]*\)|\{[^}]*\})?:::([A-Za-z0-9_-]+)/g))i.nodeClass.set(e[1],e[2]);let s=/^([A-Za-z0-9_-]+)\s*(?:@\{|\{|\[)/.exec(r);if(s&&i.edgeIds.has(s[1])){/animate|animation|\bfast\b|\bslow\b/i.test(r)&&i.edgeAnimIds.add(s[1]);continue}if(Jn(r,i)||er(r,i)||tr(r,i))continue;if(/^end$/i.test(r)){i.groupStack.pop();continue}if(/^direction\s+/i.test(r)||nr(r,t+1,i,n))continue;let c=i.groupStack[i.groupStack.length-1]??null;if(!Kn.test(r)||/^[A-Za-z0-9_-]+@\{/.test(r)){Qn(r,i.nodes,i.order,c);continue}rr(r,i,c)}ir(i);let{nodes:o,order:s,edges:c,groups:l,groupParents:u}=i;return sr(r,t,o,s,c,l,u)}function or(e,t,n){return ar(e,t,n,`bpmn`)}function sr(e,t,n,r,i,a,o){let s=[e];t&&t!==`down`&&e===`flowchart`&&s.push(`direction: ${t}`),t&&t!==`right`&&(e===`statemachine`||e===`architecture`)&&s.push(`direction: ${t}`),s.push(``);let c=(e,t)=>{let n=[];e.shape&&n.push(e.shape),e.color&&n.push(e.color),e.icon&&n.push(`icon: ${e.icon}`),e.link&&n.push(`link: ${e.link}`);let r=n.length>0?` [${n.join(`, `)}]`:``;return e.label!==null&&e.label!==e.id&&e.label!==``?`${t}${J(e.id)} = ${Y(e.label)}${r}`:n.length>0?`${t}${J(e.id)}${r}`:null},l=new Set;for(let e of i)l.add(e.src),l.add(e.dst);for(let e of r){let t=n.get(e);if(t.group)continue;let r=c(t,``);r?s.push(r):l.has(e)||s.push(J(t.id))}if(o){let e=new Map;for(let t of a){let n=o.get(t)??null,r=a.includes(n)?n:null,i=e.get(r)??[];i.push(t),e.set(r,i)}let t=(i,a)=>{s.push(`${a}group ${Y(i)} {`);for(let e of r){let t=n.get(e);t.group===i&&s.push(c(t,`${a} `)??`${a} ${J(e)}`)}for(let n of e.get(i)??[])t(n,`${a} `);s.push(`${a}}`)};for(let n of e.get(null)??[])t(n,``)}else for(let e of a){s.push(`group ${Y(e)} {`);for(let t of r){let r=n.get(t);r.group===e&&s.push(c(r,` `)??` ${J(t)}`)}s.push(`}`)}i.length>0&&s.push(``);for(let e of i){let t=e.bidir?e.dashed?`<-->`:`<->`:e.dashed?`-->`:`->`,n=[];e.color&&n.push(e.color),e.flow&&n.push(`flow`),e.invisible&&n.push(`invisible`),e.head&&n.push(`head: ${e.head}`);let r=n.length>0?` [${n.join(`, `)}]`:``,i=e.label?` : ${e.label}`:r?` :`:``;s.push(`${J(e.src)} ${t} ${J(e.dst)}${i}${r}`)}return X(s)}var cr={cloud:{shape:`cloud`},database:{shape:`cylinder`},disk:{shape:`cylinder`},internet:{icon:`globe`},server:{icon:`server`}};function lr(e,t){let n=new Map,r=[],i=[],a=new Map,o=[],s=new Map,c=e=>{let t=cr[e?.toLowerCase()]??{};return{shape:t.shape??null,iconAttr:t.icon?`[icon: ${t.icon}]`:``}};for(let t of e){let e=K(t).trim();if(!e||/^architecture/i.test(e))continue;let l=/^group\s+(\w+)\s*(?:\(([^)]*)\))?\s*\[([^\]]*)\]/i.exec(e);if(l){let e=l[1];a.set(e,q(l[3])),o.includes(e)||o.push(e);continue}let u=/^(?:service|junction)\s+(\w+)\s*(?:\(([^)]*)\))?\s*(?:\[([^\]]*)\])?\s*(?:in\s+(\w+))?/i.exec(e);if(u){let e=u[1],t=u[2]??``,i=u[3]?q(u[3]):e,a=u[4]??null,{shape:o}=c(t);Z(e,i,o,a,n,r),a&&s.set(e,a);continue}let d=/^(\w+)(?:\{group\})?(?::[LRTB])?\s*(<?-->?|--)\s*(?:[LRTB]:)?(\w+)(?:\{group\})?$/.exec(e);if(d){let e=d[1],t=d[3];Z(e,null,null,null,n,r),Z(t,null,null,null,n,r),i.push({src:e,dst:t,dashed:!1,bidir:d[2].startsWith(`<`),label:``})}}for(let[e,t]of s){let r=n.get(e);r&&(r.group=a.get(t)??t)}return sr(`architecture`,null,n,r,i,o.map(e=>a.get(e)??e))}var ur={person:`actor`,person_ext:`actor`,systemdb:`cylinder`,systemdb_ext:`cylinder`,containerdb:`cylinder`,containerdb_ext:`cylinder`,componentdb:`cylinder`,systemqueue:`queue`,systemqueue_ext:`queue`,containerqueue:`queue`,componentqueue:`queue`};function dr(e){let t=[],n=0,r=``,i=``;for(let a of e)r?(a===r&&(r=``),i+=a):a===`"`||a===`'`?(r=a,i+=a):a===`(`?(n+=1,i+=a):a===`)`?(--n,i+=a):a===`,`&&n===0?(t.push(i.trim()),i=``):i+=a;return i.trim()&&t.push(i.trim()),t}function fr(e,t){let n=new Map,r=[],i=[],a=[],o=[],s=``,c=0;for(let t=0;t<e.length;t+=1){let l=e[t],u=K(l).trim();if(!u||/^C4\w+/i.test(u)||/^Update\w+/i.test(u))continue;if(u===`}`){o.pop();continue}let d=/^title\s+(.+)$/i.exec(u);if(d){s=q(d[1]);continue}let f=/^(\w+)\s*\(([\s\S]*?)\)\s*(\{)?$/.exec(u);if(!f)continue;let p=f[1],m=dr(f[2]),h=p.toLowerCase();if(/boundary/i.test(p)){let e=q(m[1]??m[0]??`Boundary`);o.push(e),a.includes(e)||a.push(e);continue}if(/^(rel|birel)/i.test(p)){let e=q(m[0]),t=q(m[1]),n=q(m[2]??``);i.push({src:e,dst:t,dashed:!1,bidir:/^birel/i.test(p),label:n});continue}let g=q(m[0]),_=q(m[1]??m[0]),v=ur[h]??null;!c&&q(m[2]??``)&&(c=t+1),Z(g,_,v,o[o.length-1]??null,n,r)}return c&&t.push({line:c,message:`C4 descriptions aren't imported — each box keeps its name only`}),Vn(sr(`architecture`,null,n,r,i,a),s)}function pr(e,t){let n=e=>/\*|n|\.\.\*|\.\.n|[2-9]/i.test(e),r=n(e),i=n(t);return!e&&!t?null:r&&i?`N:M`:!r&&i?`1:N`:r&&!i?`N:1`:`1:1`}function mr(e){let t=/^[+\-#~]/.exec(e.trim()),n=t?t[0]:``,r=e.trim().slice(n.length).replace(/[*$]\s*$/,``).replace(/~[^~]*~/g,``).trim();if(!r)return null;let i=/^([A-Za-z0-9_]+)\s*\([^)]*\)\s*(.*)$/.exec(r);if(i){let e=i[2].trim(),t=`${n}${i[1]}()`;return e?`${J(t)} ${B(e)}`:J(t)}let a=r.split(/\s+/).filter(Boolean);return a.length===0?null:a.length===1?J(`${n}${a[0]}`):`${J(`${n}${a[a.length-1]}`)} ${B(a.slice(0,-1).join(` `))}`}function hr(e,t,n=`erd`){let r=[n,``],i=[...e],a=[];for(let e of i)e.group&&!a.includes(e.group)&&a.push(e.group);let o=(e,t)=>{let n=e.label?`${J(e.id)} = ${Y(e.label)}`:J(e.id),i=e.methods&&e.methods.length>0?[...e.fields,`---`,...e.methods]:e.fields;if(i.length===0){r.push(`${t}${n} { }`);return}r.push(`${t}${n} {`);for(let e of i)r.push(`${t} ${e}`);r.push(`${t}}`)};for(let e of a){r.push(`group ${Y(e)} {`);for(let t of i)t.group===e&&o(t,` `);r.push(`}`)}for(let e of i)e.group||o(e,``);return t.length>0&&(r.push(``),r.push(...t)),X(r)}function gr(e){let t=/^([|o}{]+)(?:--|\.\.)([|o}{]+)$/.exec(e);if(!t)return{value:null,swap:!1};let n=/[}{]/.test(t[1]),r=/[}{]/.test(t[2]);return n&&r?{value:`N:M`,swap:!1}:!n&&r?{value:`1:N`,swap:!1}:n&&!r?{value:`1:N`,swap:!0}:{value:`1:1`,swap:!1}}function _r(e,t){let n=[],r=new Map,i=[],a=null,o=(e,t)=>{let i=r.get(e);return i?t&&!i.label&&(i.label=t):(i={id:e,label:t??null,fields:[]},n.push(i),r.set(e,i)),i};for(let n=0;n<e.length;n+=1){let r=K(e[n]).trim();if(!r||/^direction\b/i.test(r))continue;let s=/^(style|classDef|class)\b/i.exec(r);if(s){a||t.push({line:n+1,message:`'${s[1]}' is not imported — table colours don't carry over`});continue}if(r===`}`){a=null;continue}if(a){let e=r.replace(/"[^"]*"\s*$/,``).trim().split(/\s+/).filter(Boolean);if(e.length===0)continue;let t=e[0],n=e[1]??t,i=e.slice(2).map(e=>e.toLowerCase()),o=i.includes(`pk`)?` pk`:i.includes(`fk`)?` fk`:``;a.fields.push(`${J(n)} ${t}${o}`);continue}let c=/^([A-Za-z0-9_-]+)(?:\[("?)([^\]]+)\2\])?\s*\{$/.exec(r);if(c){a=o(c[1],c[3]?q(c[3]):null);continue}let l=vr(r);if(l){let e=_t[l.token]?l.token:(()=>{let{value:e,swap:t}=gr(l.token);return t&&([l.from,l.to]=[l.to,l.from]),e??`->`})();o(l.from),o(l.to),i.push(`${J(l.from)} ${e} ${J(l.to)}${l.label?` : ${l.label}`:``}`);continue}if(/^[A-Za-z0-9_-]+$/.test(r)){o(r);continue}t.push({line:n+1,message:`couldn't parse '${r}'`})}return hr(n,i)}function vr(e){let t=/^(\S+)\s+([|o}{]+(?:--|\.\.)[|o}{]+)\s+(\S+)(?:\s*:\s*(.+))?$/.exec(e);return t?{from:t[1],to:t[3],token:t[2],label:t[4]?t[4].trim():``}:null}function yr(e,t){let n=[],r=[],i=null;for(let t of e){let e=K(t).trim();if(!e)continue;if(e===`}`){i&&n.push(i),i=null;continue}let a=/^(\w*requirement|requirement|element|designConstraint)\s+([A-Za-z0-9_]+)\s*\{(.+)\}$/i.exec(e);if(a){let e={id:a[2],kind:/element/i.test(a[1])?`element`:`requirement`,text:``,fields:[]};for(let t of a[3].split(/[;,]/)){let n=/^\s*(\w+)\s*:\s*(.+?)\s*$/.exec(t);if(!n)continue;let r=n[1].toLowerCase(),i=q(n[2].trim());r===`text`||r===`name`?e.text=i:e.fields.push(`${r} ${B(i)}`)}n.push(e);continue}let o=/^(\w*requirement|requirement|element|designConstraint)\s+([A-Za-z0-9_]+)\s*\{$/i.exec(e);if(o){i={id:o[2],kind:/element/i.test(o[1])?`element`:`requirement`,text:``,fields:[]};continue}if(i){let t=/^(\w+)\s*:\s*(.+)$/.exec(e);if(t){let e=t[1].toLowerCase(),n=q(t[2].trim());e===`text`||e===`name`?i.text=n:i.fields.push(`${e} ${B(n)}`)}continue}let s=/^(\S+)\s*-\s*(\w+)\s*->\s*(\S+)$/.exec(e),c=/^(\S+)\s*<-\s*(\w+)\s*-\s*(\S+)$/.exec(e);s?r.push({from:J(s[1]),to:J(s[3]),label:s[2]}):c&&r.push({from:J(c[3]),to:J(c[1]),label:c[2]})}let a=new Set(n.map(e=>J(e.id)));for(let e of r)for(let t of[e.from,e.to])a.has(t)||(a.add(t),n.push({id:t,kind:`requirement`,text:``,fields:[]}));let o=[`erd`,``];for(let e of n){o.push(`${J(e.id)} {`),e.text&&o.push(` text ${B(e.text)}`);for(let t of e.fields)o.push(` ${t}`);o.push(`}`)}return r.length>0&&(o.push(``),o.push(...r.map(e=>`${e.from} -> ${e.to} : ${e.label}`))),X(o)}var br=[`<|..`,`..|>`,`<|--`,`--|>`,`*--`,`--*`,`o--`,`--o`,`..>`,`<..`,`-->`,`<--`,`..`,`--`];function xr(e,t){let n=new Map,r=[],i=null,a=null,o=(e,t)=>{let r=e.replace(/^["']|["']$/g,``),i=n.get(r);return i?t&&(i.label=t):(i={id:r,label:t??r,fields:[],methods:[],group:a??void 0},n.set(r,i)),i},s=(e,t)=>{(t.includes(`(`)?e.methods:e.fields).push(t)};for(let c=0;c<e.length;c+=1){let l=K(e[c]).trim();if(!l||/^(direction|click|callback|link|note)\b/i.test(l))continue;let u=/^(cssClass|style|classDef)\b/i.exec(l);if(u){i||t.push({line:c+1,message:`'${u[1]}' is not imported — class colours don't carry over`});continue}let d=/^namespace\s+("?)([^"{]+)\1\s*\{?$/i.exec(l);if(d){a=d[2].trim();continue}if(l===`}`){i?i=null:a=null;continue}let f=i?null:/^<<(.+?)>>\s+(\S+)$/.exec(l);if(f){let e=n.get(J(f[2]));e&&e.fields.unshift(J(`«${f[1].trim()}»`));continue}if(i){let e=/^<<(.+)>>$/.exec(l);if(e){i.fields.push(J(`«${e[1].trim()}»`));continue}let t=mr(l);t&&s(i,t);continue}let p=/^class\s+([A-Za-z0-9_~"'.]+)(?:\["([^"]+)"\])?\s*(\{)?$/.exec(l);if(p){let e=o(p[1].replace(/~[^~]*~/g,``),p[2]);p[3]&&(i=e);continue}let m=/^([A-Za-z0-9_~"'.]+)\s*:\s*(.+)$/.exec(l);if(m&&!/[<|*o.>-]{2}/.test(l.split(`:`)[0])){let e=o(m[1].replace(/~[^~]*~/g,``)),t=/^<<(.+)>>$/.exec(m[2].trim());if(t)e.fields.push(J(`«${t[1].trim()}»`));else{let t=mr(m[2]);t&&s(e,t)}continue}let h=Sr(l);if(h){o(h.from),o(h.to);let e=bt[h.token]?h.token:pr(h.leftCard,h.rightCard)??`->`,t=h.label;r.push(`${J(h.from)} ${e} ${J(h.to)}${t?` : ${t}`:``}`);continue}t.push({line:c+1,message:`couldn't parse '${l}'`})}return hr([...n.values()].map(e=>({id:e.id,label:e.label===e.id?null:e.label,fields:e.fields,methods:e.methods,group:e.group})),r,`class`)}function Sr(e){let t=e.indexOf(`:`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1).trim():``;for(let e of br){let t=n.indexOf(e);if(t<=0)continue;let i=n.slice(0,t).trim(),a=n.slice(t+e.length).trim(),o=``,s=``,c=/"([^"]*)"\s*$/.exec(i);c&&(o=c[1],i=i.slice(0,c.index).trim());let l=/^"([^"]*)"/.exec(a);l&&(s=l[1],a=a.slice(l[0].length).trim());let u=i.replace(/~[^~]*~/g,``).trim(),d=a.replace(/~[^~]*~/g,``).trim();if(u&&d)return{from:u,to:d,token:e,label:r,leftCard:o,rightCard:s}}return null}var Cr=[{token:`<<-->>`,out:`<->`},{token:`<<->>`,out:`<->`},{token:`-->>`,out:`-->`},{token:`--x`,out:`-->`},{token:`--)`,out:`-->`},{token:`->>`,out:`->`},{token:`-->`,out:`-->`},{token:`-x`,out:`->`},{token:`-)`,out:`->`},{token:`->`,out:`->`}];function wr(e){let t=e.indexOf(`:`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1).trim():``;for(let{token:e,out:t}of Cr){let i=n.indexOf(e);if(i>0){let a=n.slice(0,i).trim().replace(/[+-]$/,``).trim(),o=n.slice(i+e.length).trim().replace(/^[+-]/,``).trim();if(a&&o)return{src:a,arrow:t,dst:o,text:r}}}return null}function Tr(e,t){let n=new Map;for(let r=0;r<e.length;r+=1){let i=K(e[r]).trim(),a=/^link\s+([^:]+):\s*(?:[^@]*@\s*)?(\S+)\s*$/i.exec(i);if(a){let e=a[1].trim();n.has(e)||n.set(e,a[2].trim());continue}let o=/^links\s+([^:]+):\s*(\{.*\})\s*$/i.exec(i);if(o){let e=o[1].trim(),i=[...o[2].matchAll(/"[^"]*"\s*:\s*"([^"]*)"/g)].map(e=>e[1]);if(i.length===0)continue;n.has(e)||n.set(e,i[0]),i.length>1&&t.push({line:r+1,message:`'${e}' has ${i.length} links; only the first is kept`})}}return n}function Er(e,t){let n=[`sequence`,``],r=Tr(e,t),i=e=>{let t=r.get(e.trim());return t?` [link: ${t}]`:``},a=0,o=[],s=!1,c=0,l=()=>` `.repeat(a);for(let r=0;r<e.length;r+=1){let u=K(e[r]).trim();if(!u)continue;if(/^autonumber\b/i.test(u)){s=!0;continue}if(/^(box|rect)\b/i.test(u)){o.push(`skip`),t.push({line:r+1,message:`'${u.split(/\s+/)[0]}' is not imported — its contents are kept`});continue}if(/^links?\s+[^:]+:/i.test(u))continue;if(/^properties\b/i.test(u)){t.push({line:r+1,message:`'properties' is not imported`});continue}if(/^destroy\s+(?!participant\b|actor\b)\S+/i.test(u)){t.push({line:r+1,message:`'destroy' is not imported — the lifeline runs to the end`});continue}let d=/^(?:create|destroy)\s+(?:participant|actor)\s+(.+)$/i.exec(u)??/^(?:participant|actor)\s+(.+)$/i.exec(u);if(d){let e=/^(.+?)\s+as\s+(.+)$/i.exec(d[1].trim());if(e){let t=e[1].trim(),r=i(t)||i(q(e[2]));n.push(`${l()}${t} = ${q(e[2])}${r}`)}else{let e=q(d[1].trim());n.push(`${l()}${e}${i(e)}`)}continue}let f=/^(loop|alt|opt|par|break|critical)\b\s*(.*)$/i.exec(u);if(f){let e=f[1].toLowerCase()===`critical`?`opt`:f[1].toLowerCase(),t=f[2].trim();n.push(`${l()}${e}${t?` ${t}`:``} {`),o.push(`emit`),a+=1;continue}let p=/^(else|and|option)\b\s*(.*)$/i.exec(u);if(p){a=Math.max(0,a-1);let e=p[1].toLowerCase()===`and`?`and`:`else`,t=p[2].trim();n.push(`${l()}} ${e}${t?` ${t}`:``} {`),a+=1;continue}if(/^end$/i.test(u)){if(o.pop()===`skip`)continue;a=Math.max(0,a-1),n.push(`${l()}}`);continue}let m=/^note\s+(over|left of|right of)\s+([^:]+):\s*(.*)$/i.exec(u);if(m){let e=m[1].toLowerCase(),t=m[2].split(`,`).map(e=>e.trim()).join(`, `);n.push(`${l()}note ${e} ${t} : ${m[3].trim()}`);continue}if(/^(activate|deactivate)\s+\S/i.test(u)){n.push(`${l()}${u}`);continue}let h=wr(u);if(h){let e=s?`${c+=1}. ${h.text??``}`.trim():h.text,t=e?` : ${e}`:``;n.push(`${l()}${h.src} ${h.arrow} ${h.dst}${t}`);continue}t.push({line:r+1,message:`couldn't parse '${u}'`})}return X(n)}function Dr(e,t){let n=[`sequence`,``];for(let r=0;r<e.length;r+=1){let i=K(e[r]).trim();if(!i||/^zenuml$/i.test(i)||i===`{`||i===`}`)continue;let a=/^(?:@\w+\s+)?(?:participant\s+)?([A-Za-z0-9_]+)(?:\s+as\s+"?([^"]+)"?)?$/i.exec(i),o=/^([A-Za-z0-9_]+)\s*(->|=>|-->)\s*([A-Za-z0-9_]+)\s*:\s*(.+)$/.exec(i);if(o){let e=o[2]===`-->`?`-->`:`->`;n.push(`${o[1]} ${e} ${o[3]} : ${o[4].trim()}`);continue}if(/\b(if|else|while|for|forEach|opt|loop|par|try|catch|finally|return|new)\b/.test(i)){t.push({line:r+1,message:`ZenUML control '${i}' is simplified on import`});continue}a&&/^(participant|@)/i.test(i)&&n.push(a[2]?`${a[1]} = ${q(a[2])}`:a[1])}return X(n)}function Or(e,t){return e===null?t:`${P(e)}-${t}`}function kr(e,t,n){let r=new Map,i=[],a=[],o=[],s=new Map,c=0,l=[],u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=()=>l[l.length-1]?.title??null,g=e=>{let t=r.get(e);if(t)return t;let n={id:e,label:null,shape:null,group:h()};return r.set(e,n),i.push(e),n},_=(e,t,n)=>{o.includes(e)||(o.push(e),s.set(e,t)),l.push({title:e,parent:t,region:n})};for(let t=0;t<e.length;t+=1){let i=K(e[t]).trim();if(!i||/^direction\b/i.test(i)||(i.includes(`:::`)&&(i=i.replace(/([A-Za-z0-9_.-]+):::([A-Za-z0-9_-]+)/g,(e,t,n)=>(m.set(J(t),n),t))),Jn(i,{classColor:f,styleColor:p,nodeClass:m,keyOf:J})))continue;if(/^(note)\b/i.test(i)){let r=/^note\s+(?:(left|right)\s+of\s+)?([^:]+):\s*(.*)$/i.exec(i),o=r?J(r[2].trim()):null,s=r?r[3].trim():``;if(!r){let n=/^note\s+(?:(left|right)\s+of\s+)?(\S+)\s*$/i.exec(i);o=n?J(n[2].trim()):null;let r=[];for(;t+1<e.length&&!/^end note$/i.test(K(e[t+1]).trim());)t+=1,r.push(K(e[t]).trim());t+=1,s=r.filter(Boolean).join(` `)}if(o&&s){let e=J(`note-${o}-${c+=1}`);g(o);let t=g(e);t.label=s,t.shape=`note`,a.push({src:o,dst:e,dashed:!0,bidir:!1,label:``})}else n.push({line:t+1,message:`a state note with no text is dropped`});continue}if(/^end note$/i.test(i))continue;if(i===`--`){let e=l[l.length-1];if(!e)continue;let t;if(e.region)l.pop(),t=e.parent;else{t=e.title;let n=jr(t,1);o.push(n),s.set(n,t);for(let e of r.values())e.group===t&&(e.group=n);u.set(t,1)}let n=(u.get(t)??1)+1;u.set(t,n),_(jr(t,n),t,!0);continue}if(i===`}`){l.pop()?.region&&l.pop();continue}let v=/^state\s+(?:"([^"]+)"\s+as\s+)?([A-Za-z0-9_.-]+)\s*\{$/i.exec(i);if(v){let e=v[1]??v[2];d.set(J(v[2]),e),_(e,h(),!1);continue}let y=/^state\s+(.+)$/i.exec(i);if(y&&!i.includes(`-->`)){let e=y[1].trim(),t=/^"([^"]+)"\s+as\s+([A-Za-z0-9_.-]+)$/.exec(e);if(t){g(J(t[2])).label=t[1];continue}let n=/^([A-Za-z0-9_.-]+)\s+<<(choice|fork|join)>>$/.exec(e);if(n){g(J(n[1])).shape=n[2]===`choice`?`diamond`:`fork-join`;continue}g(J(e));continue}let b=/^([A-Za-z0-9_.-]+)\s*:\s*(.+)$/.exec(i);if(b&&!i.includes(`-->`)){g(J(b[1])).label=q(b[2]);continue}if(i.includes(`-->`)){let e=i.indexOf(`:`),t=e>=0?i.slice(0,e):i,n=e>=0?i.slice(e+1).trim():``,r=t.indexOf(`-->`),o=Ar(t.slice(0,r).trim(),`src`,h(),g),s=Ar(t.slice(r+3).trim(),`dst`,h(),g);o&&s&&a.push({src:o,dst:s,dashed:!1,bidir:!1,label:n});continue}n.push({line:t+1,message:`couldn't parse '${i}'`})}for(let[e,t]of d){let n=r.get(e);if(!(!n||n.label!==null||n.shape!==null)){r.delete(e),i.splice(i.indexOf(e),1);for(let n of a)n.src===e&&(n.src=J(t)),n.dst===e&&(n.dst=J(t))}}for(let e of r.values()){let t=m.get(e.id);e.color=p.get(e.id)??(t?f.get(t)??null:null)}return sr(`statemachine`,t,r,i,a,o,s)}function Ar(e,t,n,r){if(e===`[*]`){let e=t===`src`?`start`:`end`,i=J(Or(n,e)),a=r(i);return a.label=e,a.shape=e===`start`?`circle`:`double-circle`,i}let i=J(e.replace(/^["']|["']$/g,``).trim());return i&&r(i),i}function jr(e,t){return`${e} ${t}`}function Mr(e,t,n){let r=``,i=[],a=null;for(let o of e){let e=K(o).trim();if(!e)continue;let s=/^title\s+(.+)$/i.exec(e);if(s){r=q(s[1]);continue}let c=/^section\s+(.+)$/i.exec(e);if(c){a={name:q(c[1]),tasks:[]},i.push(a);continue}n(e,e=>{a||(a={name:t,tasks:[]},i.push(a)),a.tasks.push(e)})}return{title:r,sections:i}}function Nr(e,t){let{title:n,sections:r}=Mr(e,``,(e,t)=>{let n=/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/.exec(e);n&&t({label:q(n[1]),score:Number(n[2]),actors:n[3]?.trim()||void 0})}),i=[`journey`];n&&i.push(`title: ${n}`),i.push(``);for(let e of r){e.name&&i.push(`section ${e.name}`);for(let t of e.tasks){let e=t.label.replace(/:/g,` `).replace(/\s+/g,` `).trim(),n=t.actors?.replace(/:/g,` `).replace(/\s+/g,` `).trim();i.push(`- ${e}${n?`: ${n}`:``} [score: ${t.score}]`)}i.push(``)}return X(i)}function Pr(e,t){let n=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))/864e5:void 0},r=n(e),i=n(t);return r===void 0||i===void 0?void 0:Math.round(i-r)}function Fr(e,t){let n=0,r=!1,{title:i,sections:a}=Mr(e,``,(e,i)=>{let a=/^(dateFormat|axisFormat|excludes|includes|todayMarker|tickInterval|weekday|weekend)\b/i.exec(e);if(a){let n=a[1].toLowerCase();if(n===`excludes`||n===`weekend`||n===`weekday`){/weekends?/i.test(e)?r=!0:t.push({line:1,message:`gantt "${e.trim()}" isn't supported — only weekends can be excluded, so those days still count`});return}n!==`dateformat`&&n!==`axisformat`&&n!==`tickinterval`&&t.push({line:1,message:`gantt "${a[1]}" isn't supported`});return}let o=e.indexOf(`:`);if(o===-1)return;let s={label:e.slice(0,o).trim(),after:[]};n+=1;for(let t of e.slice(o+1).split(`,`).map(e=>e.trim())){let e=t.toLowerCase();e===`done`||e===`active`||e===`milestone`?s.status=e:e===`crit`?s.status=`critical`:e.startsWith(`after `)?s.after.push(...t.slice(6).trim().split(/\s+/).map(P)):/^\d{4}-\d{2}-\d{2}$/.test(t)?s.start?s.end=t:s.start=t:/^\d+(\.\d+)?\s*(d|w|h|m|s|day|days|week|weeks|hour|hours|min|mins|minute|minutes|sec|secs|second|seconds)$/i.test(t)?s.length=t.replace(/\s+/g,``):/^until\s+/i.test(t)?s.until=t.slice(5).trim():/^[A-Za-z][\w-]*$/.test(t)&&(s.mermaidId=t)}i(s)}),o=new Map,s=new Set;for(let e of a)for(let t of e.tasks){let e=F(P(t.label),s);t.mermaidId&&o.set(t.mermaidId,e)}let c=[`gantt`];i&&c.push(`title: ${i}`),r&&c.push(`excludes: weekends`);for(let e of a){c.push(``),e.name&&c.push(`section ${e.name}`);for(let t of e.tasks){let e=[];if(t.after.length>0?e.push(`after ${t.after.map(e=>o.get(e)??e).join(` `)}`):t.start&&e.push(t.start),t.until)e.push(`until ${o.get(t.until)??P(t.until)}`);else if(t.length)e.push(t.length);else if(t.start&&t.end){let n=Pr(t.start,t.end);n!==void 0&&n>0&&e.push(`${n}d`)}let n=t.label.replace(/[[\]]/g,``).replace(/:/g,` `).replace(/\s+/g,` `).trim(),r=t.status?` [${t.status}]`:``;c.push(`- ${n}${e.length>0?`: ${e.join(`, `)}`:``}${r}`)}}return X(c)}function Ir(e,t){let n=[`chart pie`],r=[];for(let t of e){let e=K(t).trim();if(!e||/^showdata$/i.test(e))continue;let i=/^title\s+(.+)$/i.exec(e);if(i){n.push(`title: ${q(i[1])}`);continue}let a=/^("([^"]*)"|'([^']*)'|[^:]+)\s*:\s*([\d.]+)$/.exec(e);a&&r.push(`${q(a[1])} : ${a[4]}`)}return n.push(``,...r),X(n)}function Lr(e,t){let n=``,r=``,i=``,a={},o=[];for(let t of e){let e=K(t).trim();if(!e)continue;let s=/^title\s+(.+)$/i.exec(e);if(s){n=q(s[1]);continue}let c=/^x-axis\s+(.+)$/i.exec(e);if(c){r=q(c[1].trim());continue}let l=/^y-axis\s+(.+)$/i.exec(e);if(l){i=q(l[1].trim());continue}let u=/^quadrant-([1-4])\s+(.+)$/i.exec(e);if(u){a[Number(u[1])]=q(u[2]);continue}let d=/^(.+?):::?[A-Za-z0-9_-]*\s*:?\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]/.exec(e)??/^(.+?)\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]/.exec(e);d&&o.push({label:q(d[1].replace(/:::.*$/,``).trim()),x:d[2],y:d[3]})}let s=[`quadrant`];n&&s.push(`title: ${n}`),r&&s.push(`x-axis: ${r}`),i&&s.push(`y-axis: ${i}`);for(let e=1;e<=4;e+=1)a[e]&&s.push(`quadrant-${e}: ${a[e]}`);s.push(``);for(let e of o)s.push(`${e.label}: [${e.x}, ${e.y}]`);return X(s)}function Rr(e,t){let n=`Timeline`,r=[],i=null,a=null;for(let t of e){let e=K(t).trim();if(!e||/^timeline\b/i.test(e))continue;let o=/^title\s+(.+)$/i.exec(e);if(o){n=q(o[1]);continue}let s=/^section\s+(.+)$/i.exec(e);if(s){i={name:q(s[1]),periods:[]},r.push(i),a=null;continue}if(e.startsWith(`:`)&&a){a.events.push(...R(e,`:`).map(e=>q(e.trim())).filter(Boolean));continue}let c=R(e,`:`).map(e=>q(e.trim())).filter(Boolean);c.length!==0&&(i||(i={name:null,periods:[]},r.push(i)),a={period:c[0],events:c.slice(1)},i.periods.push(a))}let o=e=>e.includes(`:`)?`"${e}"`:e,s=[`timeline`,`title: ${n}`,``],c=r.some(e=>e.name!==null);for(let e of r){c&&s.push(`section ${e.name??`Events`}`);for(let t of e.periods){let e=o(t.period);if(t.events.length>1){s.push(`- ${e}`);for(let e of t.events)s.push(` - ${e}`)}else s.push(`- ${e}${t.events[0]?`: ${t.events[0]}`:``}`)}}return X(s)}function zr(e){let t=[],n=``,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];r?a===`"`&&e[i+1]===`"`?(n+=`"`,i+=1):a===`"`?r=!1:n+=a:a===`"`?r=!0:a===`,`?(t.push(n.trim()),n=``):n+=a}return t.push(n.trim()),t}function Br(e,t){let n=[`venn`],r=[],i=[],a=``,o=e=>{let t=/\[\s*"?([^"\]]*)"?\s*\]/.exec(e);return t?t[1].trim():null},s=e=>e.split(`,`).map(e=>P(q(e.trim().replace(/:\d+$/,``)))).filter(Boolean);for(let t of e){let e=K(t).trim();if(!e||/^venn(-beta)?$/i.test(e))continue;let n=/^title\s+(.+)$/i.exec(e);if(n){a=q(n[1].trim());continue}let c=/^set\s+([^[]+)(.*)$/i.exec(e);if(c){let e=P(q(c[1].trim().replace(/:\d+$/,``)));e&&r.push({id:e,label:o(c[2])??q(c[1].trim())});continue}let l=/^union\s+([^[]+)(.*)$/i.exec(e);if(l){let e=s(l[1]),t=o(l[2]);e.length>=2&&t&&i.push({ids:e,label:t});continue}let u=/^text\s+([^[]+)(.*)$/i.exec(e);if(u){let e=s(u[1]),t=o(u[2]);if(!t)continue;if(e.length===1){let n=r.find(t=>t.id===e[0]);n&&!n.detail&&(n.detail=t)}else e.length>=2&&!i.some(t=>t.ids.join()===e.join())&&i.push({ids:e,label:t});continue}}a&&n.push(`title: ${a}`),n.push(``);let c=e=>e.replace(/[:+&,]/g,` `).replace(/\s+/g,` `).trim(),l=new Map(r.map(e=>[e.id,c(e.label)]));for(let e of r){let t=l.get(e.id)??e.id;n.push(`- ${t}${e.detail?`: ${c(e.detail)}`:``}`)}for(let e of i){let t=e.ids.map(e=>l.get(e)).filter(e=>!!e);t.length<2||n.push(`overlap ${t.join(` + `)}: ${c(e.label)}`)}return X(n)}function Vr(e,t){let n=[`sankey`],r=[],i=!0;for(let t of e){let e=t.trim();if(!e)continue;if(i&&/^sankey/i.test(e)){i=!1;continue}i=!1;let n=zr(e);if(n.length<3||!n[0]||!n[1])continue;let a=Number(n[2]);if(!Number.isFinite(a)||a<=0)continue;let o=e=>e.replace(/->|=>/g,`-`).replace(/[:,]/g,` `).trim();r.push(`${o(n[0])} -> ${o(n[1])} : ${a}`)}return n.push(``,...r),X(n)}function Hr(e){let t=/\[(.*)\]/.exec(e);return(t?t[1]:e).split(`,`).map(e=>q(e.trim())).filter(Boolean)}function Ur(e,t){let n=``,r=``,i=``,a=[],o=null,s=!1,c=[],l=!1,u=!1,d=/(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/;for(let t of e){let e=K(t).trim();if(!e||/^xychart/i.test(e))continue;if(/^horizontal$/i.test(e)){s=!0;continue}if(/^vertical$/i.test(e)){s=!1;continue}let f=/^title\s+(.+)$/i.exec(e);if(f){n=q(f[1]);continue}let p=/^x-axis\s+(.+)$/i.exec(e);if(p){if(p[1].includes(`[`))a=Hr(p[1]);else{let e=d.exec(p[1]);e&&(o={min:Number(e[1]),max:Number(e[2])}),r=q(p[1].replace(d,``).trim())}continue}let m=/^y-axis\s+(.+)$/i.exec(e);if(m){i=q(m[1].replace(d,``).trim());continue}let h=/^bar\s+(.+)$/i.exec(e),g=/^line\s+(.+)$/i.exec(e);(h||g)&&(h?l=!0:u=!0,c.push({name:h?`Bar`:`Line`,values:Hr((h??g)[1])}))}let f=l?`bar`:u?`line`:`bar`,p=[];for(let e of c)p.some(t=>t.values.join(`\0`)===e.values.join(`\0`))||p.push(e);if(c.length=0,c.push(...p),a.length===0&&c.length>0){let e=Math.max(...c.map(e=>e.values.length));if(o&&e>1){let{min:t,max:n}=o;a=Array.from({length:e},(r,i)=>{let a=t+(n-t)*i/(e-1);return String(Math.round(a*1e3)/1e3)})}else a=Array.from({length:e},(e,t)=>String(t+1))}let m=[`chart ${f}`];n&&m.push(`title: ${n}`),s&&m.push(`horizontal`),r&&m.push(`x-axis: ${r}`),i&&m.push(`y-axis: ${i}`),a.length>0&&m.push(`categories: ${a.join(`, `)}`),m.push(``);for(let e of c)m.push(`${e.name} : ${e.values.join(`, `)}`);return X(m)}function Wr(e,t){let n=``,r=[],i=[];for(let t of e){let e=K(t).trim();if(!e||/^radar/i.test(e))continue;let a=/^title\s+(.+)$/i.exec(e);if(a){n=q(a[1]);continue}let o=/^axis\s+(.+)$/i.exec(e);if(o){for(let e of o[1].split(`,`)){let t=/\["?([^"\]]+)"?\]/.exec(e);r.push(q(t?t[1]:e.trim()))}continue}let s=/^curve\s+([A-Za-z0-9_]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{([^}]*)\}/i.exec(e);if(s){let e=q(s[2]||s[1]),t=s[3],n=t.includes(`:`)?t.split(`,`).map(e=>e.split(`:`)[1]?.trim()??``).filter(Boolean):t.split(`,`).map(e=>e.trim()).filter(Boolean);i.push({name:e,values:n})}}let a=[`chart radar`];n&&a.push(`title: ${n}`),r.length>0&&a.push(`categories: ${r.join(`, `)}`),a.push(``);for(let e of i)a.push(`${e.name} : ${e.values.join(`, `)}`);return X(a)}function Gr(e,t){let n=[`gitgraph`],r=[],i=0,a=e=>e.replace(/[[\]]/g,``).replace(/\s+/g,` `).trim(),o=e=>{let t=/tag:\s*"([^"]*)"/.exec(e),n=/type:\s*(\w+)/.exec(e),r=[];return t&&r.push(`tag: ${a(t[1])}`),n&&/highlight/i.test(n[1])?r.push(`highlight`):n&&/reverse/i.test(n[1])&&r.push(`reverse`),r.length>0?` [${r.join(`, `)}]`:``};for(let t of e){let e=K(t).trim();if(!e||/^gitGraph/i.test(e))continue;let n=/^commit\b(.*)$/i.exec(e);if(n){let e=/id:\s*"([^"]*)"/.exec(n[1]),t=e?a(e[1]):`commit ${i+=1}`;r.push(`commit ${t}${o(n[1])}`);continue}let s=/^branch\s+(\S+)/i.exec(e);if(s){r.push(`branch ${a(s[1])}`);continue}let c=/^(?:checkout|switch)\s+(\S+)/i.exec(e);if(c){r.push(`checkout ${a(c[1])}`);continue}let l=/^merge\s+(\S+)(.*)$/i.exec(e);if(l){r.push(`merge ${a(l[1])}${o(l[2])}`);continue}let u=/^cherry-pick\b(.*)$/i.exec(e);if(u){let e=/id:\s*"([^"]*)"/.exec(u[1]);e&&r.push(`cherry-pick ${P(a(e[1]))}${o(u[1])}`);continue}}return n.push(``,...r),X(n)}function Kr(e){let t=e.trim().replace(/:::[A-Za-z0-9_ -]+$/,``).trim(),n=[[`((`,`))`],[`))`,`((`],[`)`,`(`],[`[`,`]`],[`(`,`)`],[`{{`,`}}`]];if(/^[A-Za-z0-9_]*\s*([(){}[\]])/.exec(t))for(let[e,r]of n){let n=t.indexOf(e);if(n>=0&&t.endsWith(r))return q(t.slice(n+e.length,t.length-r.length))}return q(t)}function qr(e,t){let n=[],r=``;for(let t of e){let e=K(t.replace(/\t/g,` `)),i=e.trim();if(!i||/^mindmap$/i.test(i)||/^::icon\(/i.test(i)||/^:::/.test(i))continue;let a=/^title\s+(.+)$/i.exec(i);if(a){r=q(a[1]);continue}let o=e.length-e.trimStart().length;n.push({indent:o,label:Kr(i)})}if(n.length===0)return X([`mindmap`,r?`central: ${r}`:``]);let i=n[0],a=n.slice(1),o=a.length>0?Math.min(...a.map(e=>e.indent)):i.indent+2,s=[`mindmap`,`central: ${i.label}`];r&&s.push(`title: ${r}`),s.push(``);let c=[];for(let e of a){for(;c.length>0&&e.indent<=c[c.length-1];)c.pop();let t=e.indent<=o?0:c.length;t===0&&(c.length=0),c.push(e.indent),s.push(`${` `.repeat(t)}- ${e.label}`)}return X(s)}function Jr(e,t){let n=[],r=``,i=/^([\s│┃|]*)[├└┣┗][─━-]+\s*(.*)$/;for(let t of e){let e=K(t.replace(/\t/g,` `)),a=e.trim();if(!a||/^tree(view)?(-beta)?$/i.test(a))continue;let o=/^title\s+(.+)$/i.exec(a);if(o){r=q(o[1]);continue}let s=i.exec(e),c=s?Math.round(s[1].replace(/[│┃|]/g,` `).length/4)*4+4:e.length-e.trimStart().length,l=(s?s[2]:a).trim();if(!l)continue;l=l.replace(/:::\S+/g,``).trim();let u=null,d=/^(.*?)\s*##\s*(.+)$/.exec(l);d&&(l=d[1].trim(),u=d[2].trim());let f=null,p=/icon\(\s*([^)]*)\s*\)/i.exec(l);if(p){l=l.replace(p[0],``).trim();let e=p[1].trim().toLowerCase();f=e&&e!==`none`?$n(e):null}let m=q(l).trim();m&&n.push({indent:c,label:m,icon:f,detail:u})}if(n.length===0)return X([`flowchart`,r?`title: ${r}`:``]);let a=new Map,o=[],s=[],c=[];for(let e of n){for(;c.length>0&&e.indent<=c[c.length-1].indent;)c.pop();let t=c.length>0?c[c.length-1]:null,n=P(e.label.replace(/\/+$/,``)),r=t?`${t.id}-${n}`:n;for(;a.has(r);)r=`${r}-${o.length}`;let i=e.detail?`${e.label} (${e.detail})`:e.label;a.set(r,{id:r,label:i,shape:e.label.endsWith(`/`)?null:`document`,group:null,icon:e.icon}),o.push(r),t&&s.push({src:t.id,dst:r,dashed:!1,bidir:!1,label:``}),c.push({indent:e.indent,id:r})}let l=sr(`flowchart`,`right`,a,o,s,[]);if(!r)return l;let u=l.split(`
22
+ `),d=u.findIndex(e=>e.startsWith(`direction:`));return u.splice(d>=0?d+1:1,0,`title: ${r}`),X(u)}function Yr(e,t){let n=`Packet`,r=[],i=0;for(let t of e){let e=K(t).trim();if(!e||/^packet/i.test(e))continue;let a=/^title\s+(.+)$/i.exec(e);if(a){n=q(a[1]);continue}let o=/^\+(\d+)\s*:\s*"?([^"]*)"?$/.exec(e);if(o){let e=Number(o[1]);r.push({range:`${i}-${i+e-1}`,label:q(o[2])}),i+=e;continue}let s=/^(\d+)(?:-(\d+))?\s*:\s*"?([^"]*)"?$/.exec(e);if(s){let e=Number(s[1]),t=s[2]?Number(s[2]):e;r.push({range:s[2]?`${e}-${t}`:`${e}`,label:q(s[3])}),i=t+1}}let a=[`flowchart`,`title: ${n}`,``];a.push(`group ${Y(n)} {`);let o=0;for(let e of r)a.push(` f${o+=1} = ${Y(`${e.range}: ${e.label}`)}`);return a.push(`}`),X(a)}function Xr(e,t){let n=[],r=null,i=null;for(let t of e){let e=K(t.replace(/\t/g,` `)),a=e.trim();if(!a||/^kanban$/i.test(a))continue;let o=e.length-e.trimStart().length;i===null&&(i=o);let s=a.replace(/@\{[^}]*\}\s*$/,``).trim(),c=/^[A-Za-z0-9_]*\["?([^"\]]+)"?\]$/.exec(s)??/^[A-Za-z0-9_]*\[([^\]]+)\]$/.exec(s),l=q(c?c[1]:s);o<=i?(r={title:l,items:[]},n.push(r)):r&&r.items.push(l)}let a=[`flowchart`,`kanban`,``],o=0;for(let e of n){a.push(`group ${Y(e.title)} {`);for(let t of e.items)a.push(` k${o+=1} = ${Y(t)}`);a.push(`}`)}return X(a)}function Zr(e){let t=e.trim().split(/\s+/)[0]??``,n=t.toLowerCase();if(/^c4(context|container|component|dynamic|deployment)$/i.test(t))return`c4`;switch(n){case`flowchart`:case`graph`:return`flowchart`;case`swimlane`:case`swimlane-beta`:return`swimlane`;case`sequencediagram`:return`sequence`;case`classdiagram`:case`classdiagram-v2`:return`class`;case`statediagram`:case`statediagram-v2`:return`state`;case`erdiagram`:return`er`;case`journey`:return`journey`;case`gantt`:return`gantt`;case`pie`:return`pie`;case`quadrantchart`:return`quadrant`;case`requirementdiagram`:return`requirement`;case`gitgraph`:return`git`;case`mindmap`:return`mindmap`;case`timeline`:return`timeline`;case`sankey`:case`sankey-beta`:return`sankey`;case`xychart`:case`xychart-beta`:return`xychart`;case`packet`:case`packet-beta`:return`packet`;case`kanban`:return`kanban`;case`architecture`:case`architecture-beta`:return`architecture`;case`radar`:case`radar-beta`:return`radar`;case`treeview`:case`treeview-beta`:return`treeview`;case`venn`:case`venn-beta`:return`venn`;case`zenuml`:return`zenuml`;default:return null}}function Qr(e){let{lines:t,title:n,dropped:r}=Hn(e),i=t.map(e=>K(e).trim()).find(Boolean)??``,a=t.findIndex(e=>K(e).trim()===i),o=Zr(i),s=[];if(!o){let t=i.split(/\s+/)[0]||`diagram`;return{code:e,family:null,diagnostics:[{line:r+a+1,message:`Mermaid ${t} diagrams aren't supported yet`}]}}let c=null;if(o===`flowchart`||o===`swimlane`){let e=/^(?:flowchart|graph|swimlane(?:-beta)?)\b\s*([A-Za-z]{2})?/i.exec(i);c=e&&e[1]?Un[e[1].toUpperCase()]??null:null}if(o===`state`){let e=/\bdirection\s+([A-Za-z]{2})\b/i.exec(t.slice(a).join(`
23
+ `));c=e?Un[e[1].toUpperCase()]??null:null}let l=Bn(t.slice(a+1)),u=!1;if(o===`flowchart`||o===`swimlane`){let e=i.replace(/^(?:flowchart|graph|swimlane(?:-beta)?)\b\s*([A-Za-z]{2})?/i,``).trim();e&&(l.unshift(e),u=!0)}o===`xychart`&&/\bhorizontal\b/i.test(i)&&(l.unshift(`horizontal`),u=!0);let d;switch(o){case`flowchart`:d=ar(l,c,s);break;case`swimlane`:d=or(l,c,s);break;case`sequence`:d=Er(l,s);break;case`class`:d=xr(l,s);break;case`state`:d=kr(l,c,s);break;case`er`:d=_r(l,s);break;case`journey`:d=Nr(l,s);break;case`gantt`:d=Fr(l,s);break;case`pie`:d=Ir(l,s);break;case`quadrant`:d=Lr(l,s);break;case`requirement`:d=yr(l,s);break;case`git`:d=Gr(l,s);break;case`c4`:d=fr(l,s);break;case`mindmap`:d=qr(l,s);break;case`timeline`:d=Rr(l,s);break;case`sankey`:d=Vr(l,s);break;case`xychart`:d=Ur(l,s);break;case`packet`:d=Yr(l,s);break;case`kanban`:d=Xr(l,s);break;case`architecture`:d=lr(l,s);break;case`radar`:d=Wr(l,s);break;case`treeview`:d=Jr(l,s);break;case`venn`:d=Br(l,s);break;case`zenuml`:d=Dr(l,s);break;default:d=e}let f=r+a+ +!u;for(let e of s)e.line+=f;return{code:Vn(d,n),family:o,diagnostics:s}}var $r=/^(sequenceDiagram|classDiagram|stateDiagram(-v2)?|erDiagram|gantt|journey|gitGraph|quadrantChart|requirementDiagram|C4(Context|Container|Component|Dynamic|Deployment)|timeline|sankey(-beta)?|xychart(-beta)?|packet(-beta)?|kanban|architecture-beta|radar(-beta)?|treeview(-beta)?|venn(-beta)?|swimlane(-beta)?|zenuml|mindmap|pie)\b/;function ei(e){return fn.has(e)&&$r.test(e)}function ti(e){return e.slice(1).map(e=>K(e).trim()).some(e=>/^[-*]\s+\S/.test(e)||/^(title|central)\s*:/i.test(e)||/\S\s*->\s*\S/.test(e))}function ni(e){let t=e.split(`
24
+ `).map(e=>K(e).trim()).filter(Boolean);if(t[0]===`---`){let e=t.indexOf(`---`,1);e!==-1&&(t=t.slice(e+1))}let n=t[0];if(!n)return!1;if(/^(flowchart|graph)\s+(TD|TB|BT|LR|RL)\b/i.test(n))return!0;let r=n.split(/\s+/)[0].toLowerCase();return fn.has(r)?$r.test(n)&&!$r.test(r)?!0:ei(r)?!ti(t):!1:$r.test(n)?!0:/-->\||->>|-->>|-\.->|==>|\|\|--|o\{|\{\{|<\|--/.test(e)}var ri={eraser:`eraser.io`,mermaid:`Mermaid`};function ii(e){return ni(e)?`mermaid`:In(e)?`eraser`:null}function ai(e,t){return{language:t,...t===`mermaid`?Qr(e):Fn(e)}}function oi(e){let t=ii(e);if(!t)return{source:e,converted:null};let n=ai(e,t);return{source:n.code,converted:n}}function si(e){let t=f(e);return t?{x:t.x+t.width+160,y:t.y}:null}function ci(e){return{async resolve(t){let n=await e.resolveIcon(t).catch(()=>null);return n?n.source===`lucide`?n.name:`${n.source}/${n.name}`:null},async names(){let t=await Promise.all(re.filter(e=>!ne(e)).map(async t=>(await e.loadAssetIndex(t).catch(()=>[])).map(e=>`${t}/${e[1]}`)));return[...M,...t.flat()]}}}var li=e(r(),1),ui=[...mt,...yt],di=new Set(Object.keys(w).filter(e=>!D.includes(e))),fi=[...dt.filter(e=>!di.has(e)),`chart`],pi=[`title`,`direction`,`icons`],mi=[`right`,`down`,`left`,`up`],hi=[`badge`,`inside`],gi=[`group`,`screen`,`note`,`legend`,`loop`,`alt`,`else`,`opt`,`par`,`and`,`break`,`activate`,`deactivate`,`central`],_i=[`icon`,`color`,`shape`,`fill`,`colorMode`,`corner`,`frame`,`label`,`labelColor`,`group`,`link`,`head`,`width`,`value`,`score`],vi=[`full`,`half`,`third`,`two-thirds`],yi=new Set([...Object.keys(w),`mindmap`,...y,`chart`,...pi,...gi,...nn]),bi=[`drawnicons`,`aws`,`gcp`,`azure`,`tech`,`mood`,`emoji`],xi={drawnicons:`Library`,aws:`AWS`,gcp:`GCP`,azure:`Azure`,tech:`Tech`,mood:`Mood`,emoji:`Emoji`},Si=[`server`,`database`,`user`,`cloud`,`queue`,`globe`,`lock`,`mail`];function Q(e,t,n){return e.map(e=>({label:e,detail:t,insert:n?n(e):void 0}))}var Ci=bi.map(e=>({label:`${e}/`,detail:`${xi[e]} icons`,insert:`${e}/`}));function wi(e){let t=Q(e?M:Si,`icon`);return[...Ci,...t]}function Ti(e,t,n,r,i,a){let o=a?.entries(e);if(!o)return{from:n,to:r,query:i,options:[]};let s=t.toLowerCase(),c=[],l=[];for(let t of o){let n={label:`${e}/${t.slug}`,detail:t.name,iconUrl:a?.iconUrl(e,t.slug)},r=t.slug.toLowerCase(),i=t.name.toLowerCase();!s||r.startsWith(s)||i.startsWith(s)?c.push(n):(r.includes(s)||i.includes(s))&&l.push(n)}return{from:n,to:r,query:i,options:[...c,...l].slice(0,80)}}var Ei={color:Q(S,`colour`),labelcolor:Q(S,`colour`),textcolor:Q(S,`colour`),shape:Q(b,`shape`),fill:Q(k,`fill`),colormode:Q(k,`fill`),corner:Q(_,`corner`),corners:Q(_,`corner`),frame:Q(T,`frame`),head:Q(E,`head`),width:Q(vi,`width`)};function Di(e,t){return e===`icon`?wi(t):Ei[e]??null}function Oi(e){return[...Q(_i,`key`,e=>`${e}: `),...Q(S,`colour`),...Q(b,`shape`),...Q(k,`fill`),...Q(_,`corner`),...Q([`shadow`,`flow`,`invisible`],`flag`),...Q(T,`frame`),...Ci,...Q(e?M:Si,`icon`)]}function ki(e){for(let t of e.split(`
25
+ `)){let e=t.trim();if(!e||e.startsWith(`//`))continue;let n=e.toLowerCase().split(/\s+/)[0];return w[n]||(n===`chart`||dt.includes(n)?n:`architecture`)}return`architecture`}var Ai=new RegExp(ft.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).concat(`,`,`=`).join(`|`));function ji(e){let t=new Set;for(let n of e.split(`
26
+ `)){let e=n.replace(/\/\/.*$/,``).trim();if(!e)continue;let r=e.toLowerCase().split(/\s+/)[0];if(!yi.has(r)){e=e.replace(/\[[^\]]*\]/g,``).replace(/:.*/,``);for(let n of e.split(Ai)){let e=n.trim();e&&/[A-Za-z]/.test(e)&&e.length<=40&&t.add(e)}}}return[...t]}function Mi(e,t){if(!t)return e;let n=t.toLowerCase(),r=[],i=[];for(let t of e){let e=t.label.toLowerCase();e.startsWith(n)?r.push(t):e.includes(n)&&i.push(t)}return[...r,...i]}function Ni(e,t,n,r){let i=Mi(r,n).slice(0,80);return i.length===0?null:{from:e,to:t,query:n,options:i}}function Pi(e,t,n){let r=e.lastIndexOf(`
27
+ `,t-1)+1,i=e.slice(r,t);if(/^\s*direction\s*:\s*\w*$/i.test(i)){let e=/\w*$/.exec(i)?.[0]??``;return Ni(t-e.length,t,e,Q(mi,`direction`))}if(/^\s*icons\s*:\s*\w*$/i.test(i)){let e=/\w*$/.exec(i)?.[0]??``;return Ni(t-e.length,t,e,Q(hi,`icons`))}let a=i.lastIndexOf(`[`);if(a>i.lastIndexOf(`]`)){let e=i.slice(a+1).split(`,`).pop()??``,r=e.match(/([a-zA-Z][\w-]*)\s*:\s*([\w/-]*)$/),o=r?r[1].toLowerCase():null,s=r?r[2]:/[\w/-]*$/.exec(e)?.[0]??``,c=t-s.length,l=/^([a-z]+)\/(.*)$/.exec(s);if(l&&bi.includes(l[1]))return Ti(l[1],l[2],c,t,s,n);if(o){let e=Di(o,s);if(e)return Ni(c,t,s,e)}return Ni(c,t,s,Oi(s))}let o=/[\w/-]*$/.exec(i)?.[0]??``,c=t-o.length,l=i.replace(/^\s+/,``),u=!/\s/.test(l),d=ki(e),f=ji(e);if(u){let e=[...Q(fi,`family`),...Q(pi,`directive`,e=>`${e}: `)];return d===`wireframe`?(e.push(Q([`screen`],`block`)[0]),e.push(...Q(s,`control`,e=>`${e}: `))):d===`sequence`?e.push(...Q([`note`,`loop`,`alt`,`opt`,`par`,`break`,`activate`,`deactivate`],`block`)):d===`erd`?e.push(...Q(ui,`cardinality`,e=>`${e} `)):d===`mindmap`?e.push(...Q([`central`],`directive`,()=>`central: `)):d===`gitgraph`?e.push(...Q([`commit`,`branch`,`checkout`,`merge`,`cherry-pick`],`block`,e=>e===`commit`?e:`${e} `)):d===`gantt`?(e.push(Q([`section`],`block`,e=>`${e} `)[0]),e.push(Q([`excludes`],`directive`,()=>`excludes: weekends`)[0])):d===`journey`||d===`timeline`?e.push(Q([`section`],`block`,e=>`${e} `)[0]):d===`venn`?e.push(Q([`overlap`],`block`,e=>`${e} `)[0]):d===`sankey`||d===`chart`||e.push(...Q([`group`,`legend`],`block`)),e.push(...Q(f,`node`)),Ni(c,t,o,e)}return Ni(c,t,o,[...Q(ft,`connector`,e=>`${e} `),...Q(d===`erd`?ui:[],`cardinality`,e=>`${e} `),...Q(f,`node`)])}var Fi=new Set([...dt,...rn,`quadrant-1`,`quadrant-2`,`quadrant-3`,`quadrant-4`,`group`,`screen`,`note`,`loop`,`alt`,`opt`,`par`,`break`,`and`,`else`,`activate`,`deactivate`,`legend`,`title`,`direction`,`icons`,`kanban`,`central`,`root`,`center`,`categories`,`x-axis`,`y-axis`,`stacked`,`horizontal`,`section`,`overlap`,`excludes`,`commit`,`branch`,`checkout`,`switch`,`merge`,`cherry-pick`]),Ii=new Set([...ft,...xt,...vt]);function Li(e){return Ii.has(e)||e.toLowerCase()in pt}function Ri(e,t){for(let n of t.split(/(\[[^\]]*\])/g))if(n){if(n.startsWith(`[`)&&n.endsWith(`]`)){e.push({kind:`attribute`,text:n});continue}for(let t of n.split(/(\s+)/))t&&e.push({kind:Li(t)?`connector`:`plain`,text:t})}}function zi(e,t){let n=-1;for(let e=0;e<t.length-1;e+=1)if(t[e]===`/`&&t[e+1]===`/`){let r=e===0?` `:t[e-1];if(/\s/.test(r)){n=e;break}}let r=n>=0?t.slice(0,n):t,i=n>=0?t.slice(n):``,a=r.match(/^(\s*)([A-Za-z][\w-]*)([\s\S]*)$/);a&&Fi.has(a[2].toLowerCase())?(a[1]&&e.push({kind:`plain`,text:a[1]}),e.push({kind:`keyword`,text:a[2]}),Ri(e,a[3])):Ri(e,r),i&&e.push({kind:`comment`,text:i})}function Bi(e){let t=[];for(let n of e.split(`
28
+ `))zi(t,n),t.push({kind:`plain`,text:`
29
+ `});return t}var $=n(),Vi={plain:null,keyword:`text-violet-600 dark:text-violet-400`,connector:`text-sky-600 dark:text-sky-400`,attribute:`text-amber-700 dark:text-amber-300`,comment:`text-[var(--chrome-fg-400)] italic`};function Hi(e){return(0,$.jsx)($.Fragment,{children:Bi(e.code).map((e,t)=>{let n=Vi[e.kind];return n?(0,$.jsx)(`span`,{className:n,children:e.text},t):(0,$.jsx)(N.Fragment,{children:e.text},t)})})}var Ui=[`aws`,`gcp`,`azure`,`tech`];function Wi(){let[e,t]=(0,N.useState)(0),n=(0,N.useRef)(!0);(0,N.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]);let r=(0,N.useCallback)(e=>{A().cachedAssetIndex(e)||A().loadAssetIndex(e).then(()=>{n.current&&t(e=>e+1)}).catch(()=>void 0)},[]);return(0,N.useEffect)(()=>{for(let e of Ui)r(e)},[r]),{snapshot:(0,N.useMemo)(()=>({entries(e){let t=A().cachedAssetIndex(e);return t?t.map(e=>({name:e[0],slug:e[1],keywords:e[2]})):(r(e),null)},iconUrl(e,t){return A().assetIconUrl(e,t)}}),[r]),iconsVersion:e}}function Gi(e){return e.filter(e=>e.severity===`error`)}function Ki(e){return e===1?`1 error — that line will be skipped`:`${e} errors — those lines will be skipped`}function qi(e,t){if(!Number.isInteger(t)||t<1)return null;let n=0;for(let r=1;r<t;r++){let t=e.indexOf(`
30
+ `,n);if(t===-1)return null;n=t+1}let r=e.indexOf(`
31
+ `,n);return{start:n,end:r===-1?e.length:r}}var Ji=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace`,Yi=12,Xi=20,Zi=12,Qi=60,$i={margin:0,border:0,padding:Zi,fontFamily:Ji,fontSize:Yi,lineHeight:`${Xi}px`,fontVariantLigatures:`none`,fontFeatureSettings:`"liga" 0, "calt" 0`,tabSize:2,whiteSpace:`pre`,overflowWrap:`normal`,wordBreak:`normal`},ea=0;function ta(){let e=typeof document<`u`?document.fonts:void 0;if(!e)return!0;try{return e.check(`${Yi}px 'JetBrains Mono'`)}catch{return!0}}function na(){if(ea)return ea;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return Yi*.6;e.font=`${Yi}px ${Ji}`;let t=e.measureText(`M`).width||Yi*.6;return ta()&&(ea=t),t}function ra(e,t){let n=e.value,r=n.lastIndexOf(`
32
+ `,t-1)+1,i=n.slice(0,t).split(`
33
+ `).length-1,a=t-r,o=e.getBoundingClientRect();return{left:o.left+Zi+a*na()-e.scrollLeft,top:o.top+Zi+(i+1)*Xi-e.scrollTop}}function ia(e){let t=(0,N.useRef)(null),n=(0,N.useRef)(null),r=(0,N.useRef)(``),i=(0,N.useRef)(0),a=(0,N.useRef)(null),o=(0,N.useRef)(()=>void 0),[s,c]=(0,N.useState)(null),l=(0,N.useRef)(null),{snapshot:u,iconsVersion:d}=Wi();(0,N.useEffect)(()=>{o.current(!1)},[d]),(0,N.useLayoutEffect)(()=>{if(a.current!=null&&t.current){let e=a.current;t.current.selectionStart=e,t.current.selectionEnd=e,a.current=null}f()});function f(){let e=t.current,i=n.current;if(!e||!i)return!1;let a=`translate(${-e.scrollLeft}px, ${-e.scrollTop}px)`;return a===r.current?!1:(r.current=a,i.style.transform=a,!0)}function p(){f()&&c(e=>{let n=t.current;if(!e||!n)return e;let r=ra(n,n.selectionStart);return r.left===e.left&&r.top===e.top?e:{...e,...r}})}function m(){cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{p(),document.activeElement===t.current&&m()})}(0,N.useEffect)(()=>()=>cancelAnimationFrame(i.current),[]),(0,N.useImperativeHandle)(e.handleRef,()=>({revealLine(e){let n=t.current;if(!n)return;let r=qi(n.value,e);if(!r)return;n.focus({preventScroll:!0}),n.setSelectionRange(r.start,r.end);let i=Zi+(e-1)*Xi,a=i+Xi;(i<n.scrollTop||a>n.scrollTop+n.clientHeight)&&(n.scrollTop=Math.max(0,i-n.clientHeight/2)),n.scrollLeft=0,c(null),f()}}));function h(e){let n=t.current;if(!n)return;let r=n.selectionStart;if(r!==n.selectionEnd){c(null);return}let i=Pi(n.value,r,u),a=n.value.slice(0,r),o=i!=null&&i.options.length===1&&i.options[0].label.toLowerCase()===i.query.toLowerCase(),s=e||i!=null&&!o&&(i.query.length>=1||a.endsWith(`[`));if(!i||!s){c(null);return}let l=ra(n,r);c({from:i.from,to:i.to,options:i.options.slice(0,Qi),index:0,left:l.left,top:l.top})}function g(n){let r=t.current;if(!r)return;let i=r.selectionStart,o=r.value,s=Pi(o,i,u),l=s?s.from:i,d=n.insert??n.label,f=o.slice(0,l)+d+o.slice(i);a.current=l+d.length,c(null),e.onChange(f),requestAnimationFrame(()=>h(!1))}o.current=h;function _(t){if(t.stopPropagation(),t.key===`Enter`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),c(null),e.onGenerate();return}if(t.key===` `&&t.ctrlKey||t.key===`Escape`&&s){if(t.key===`Escape`){t.preventDefault(),c(null);return}t.preventDefault(),h(!0);return}if(s){if(t.key===`ArrowDown`){t.preventDefault(),c({...s,index:(s.index+1)%s.options.length});return}if(t.key===`ArrowUp`){t.preventDefault(),c({...s,index:(s.index-1+s.options.length)%s.options.length});return}(t.key===`Enter`||t.key===`Tab`)&&(t.preventDefault(),g(s.options[s.index]))}}return(0,N.useEffect)(()=>{if(!s)return;let e=t.current;if(!e)return;let n=ra(e,e.selectionStart);(n.left!==s.left||n.top!==s.top)&&c({...s,left:n.left,top:n.top})},[e.value,s]),(0,N.useLayoutEffect)(()=>{let e=l.current;if(!s||!e)return;e.style.left=`8px`;let t=e.getBoundingClientRect(),n=Math.max(8,Math.min(s.left,window.innerWidth-t.width-8)),r=s.top+t.height<=window.innerHeight-8?s.top:Math.max(8,s.top-t.height-Xi);e.style.left=`${n}px`,e.style.top=`${r}px`},[s]),(0,$.jsxs)(`div`,{className:`relative overflow-hidden ${e.className??``}`,children:[(0,$.jsx)(`pre`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 overflow-hidden text-[var(--chrome-fg-900)]`,style:{margin:0},children:(0,$.jsx)(`code`,{ref:n,style:{...$i,display:`block`},children:(0,$.jsx)(Hi,{code:e.value})})}),(0,$.jsx)(`textarea`,{ref:t,value:e.value,spellCheck:!1,wrap:`off`,autoCapitalize:`off`,autoCorrect:`off`,"data-testid":`code-input`,placeholder:e.placeholder,onChange:t=>{e.onChange(t.target.value),requestAnimationFrame(()=>h(!1))},onKeyDown:_,onScroll:p,onFocus:m,onBlur:()=>c(null),onClick:()=>c(null),className:`absolute inset-0 resize-none bg-transparent text-transparent caret-[var(--chrome-fg-900)] outline-none`,style:$i}),s&&(0,li.createPortal)((0,$.jsx)(`ul`,{ref:l,className:`fixed z-50 max-h-56 min-w-44 max-w-80 overflow-y-auto rounded-lg bg-[var(--chrome-popup)] py-1 shadow-lg ring-1 ring-[var(--chrome-ring)]`,style:{left:s.left,top:s.top,fontFamily:Ji,fontSize:12},role:`listbox`,onPointerDown:e=>e.preventDefault(),children:s.options.map((e,t)=>(0,$.jsxs)(`li`,{role:`option`,"aria-selected":t===s.index,onPointerDown:t=>{t.preventDefault(),g(e)},onPointerEnter:()=>c(e=>e&&{...e,index:t}),className:`flex cursor-pointer items-center gap-2.5 px-2.5 py-1 ${t===s.index?`bg-[var(--chrome-hover)] text-[var(--chrome-fg-900)]`:`text-[var(--chrome-fg-700)]`}`,children:[e.iconUrl&&(0,$.jsx)(`img`,{src:e.iconUrl,alt:``,loading:`lazy`,className:`h-4 w-4 shrink-0 object-contain`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 truncate text-[10px] text-[var(--chrome-fg-400)]`,children:e.detail})]},`${e.label}-${t}`))}),document.body)]})}function aa(e,t){if(!e)return null;let n=t.get(e.shapeId);return n?{...e,shapeId:n}:e}function oa(e){let t=new Map,n=new Map,r=new Map;return e.forEach((e,i)=>{t.set(e.id,`s${i+1}`),e.groupId&&!n.has(e.groupId)&&n.set(e.groupId,`g${n.size+1}`),e.lockId&&!r.has(e.lockId)&&r.set(e.lockId,`l${r.size+1}`)}),e.map(e=>{let i={...e,id:t.get(e.id)};return i.groupId&&=n.get(i.groupId),i.lockId&&=r.get(i.lockId),i.type===`arrow`&&(i.startBinding=aa(i.startBinding,t),i.endBinding=aa(i.endBinding,t)),i.type===`figure`&&i.flows&&(i.flows=g(i.flows,e=>t.get(e)??e)),i.type===`polygon`&&i.band&&(i.band={...i.band,from:t.get(i.band.from)??i.band.from,to:t.get(i.band.to)??i.band.to}),i})}var sa=3,ca=4,la=new Set([`emoji`,`mood`]),ua=[...Object.keys(H),...Object.keys(Be),...Object.keys(U),...Object.keys(We),...Object.keys(Ue),`flow`,`shadow`,`invisible`];async function da(e,t){let n=new Map,r=e=>{let r=n.get(e);return r||(r=t.resolve(e),n.set(e,r)),r},i=null,a=()=>(i??=t.names(),i),o=new Map,s=[];for(let t of e.iconUses){if(!t.ref)continue;let e=await fa(t,await r(t.ref),a);e&&(t.kind===`unknown`?o.set(t.diagnostic,e):s.push(e))}let c=[...e.diagnostics.map(e=>o.get(e)??e),...s],l=e=>e>0?e:1/0;return c.map((e,t)=>({diagnostic:e,index:t})).sort((e,t)=>l(e.diagnostic.line)-l(t.diagnostic.line)||e.index-t.index).map(e=>e.diagnostic)}async function fa(e,t,n){if(e.kind===`icon`){if(t)return null;let r=ga(e.ref,await n(),[]);return ma(e.line,`unknown icon "${e.written}"`,r)}if(e.kind===`keyword`){if(!t)return null;let n=e.reading===`shape`?`is drawn as a shape here`:`is a frame, which only applies to a group or a screen`,r=t.includes(`/`)?pa(t):`icon: ${t}`;return ma(e.line,`"${e.written}" ${n}. For the icon, write [${r}]`,[])}if(t)return{line:e.line,message:`unknown attribute "${e.written}". For the icon, write [${pa(t)}]`,severity:`warning`,suggestions:[t]};let r=ga(e.ref,await n(),ua);return ma(e.line,e.diagnostic.message,r)}function pa(e){let t=e.includes(`/`)?e.slice(0,e.indexOf(`/`)):null;return t&&![`tech`,`aws`,`gcp`,`azure`].includes(t)?`icon: ${e}`:e}function ma(e,t,n){return n.length===0?{line:e,message:t,severity:`warning`}:{line:e,message:`${t} (did you mean: ${n.join(`, `)}?)`,severity:`warning`,suggestions:n}}function ha(e){return e.toLowerCase().replace(/[^a-z0-9]/g,``)}function ga(e,t,n){let r=e.search(/[:/]/),i=r>0?e.slice(0,r):null,a=ha(i?e.slice(r+1):e);if(a.length===0)return[];let o=i?t.filter(e=>e.startsWith(`${i}/`)):[...n,...t.filter(e=>!la.has(e.split(`/`)[0]))],s=[];for(let e of o){let t=_a(a,ha(e.slice(e.indexOf(`/`)+1)));t!==null&&s.push({name:e,score:t})}s.sort((t,n)=>t.score-n.score||Math.abs(t.name.length-e.length)-Math.abs(n.name.length-e.length)||t.name.localeCompare(n.name));let c=s[0]?.score??0,l=new Set,u=[];for(let{name:e,score:t}of s)if(t>=ca&&c<ca||(l.has(e)||(l.add(e),u.push(e)),u.length===sa))break;return u}function _a(e,t){if(t.length===0)return null;if(t===e)return 0;if(e.length>=3&&t.startsWith(e))return 1;let n=Math.min(3,Math.max(1,Math.floor(e.length/3))),r=Math.abs(t.length-e.length)>n?n+1:va(e,t);return r<=n?.5+r:e.length>=4&&t.includes(e)?2:t.length>=3&&e.startsWith(t)?ca:null}function va(e,t){let n=[],r=Array.from({length:t.length+1},(e,t)=>t);for(let i=1;i<=e.length;i+=1){let a=[i];for(let o=1;o<=t.length;o+=1){let s=e[i-1]===t[o-1]?0:1,c=Math.min(r[o]+1,a[o-1]+1,r[o-1]+s);i>1&&o>1&&e[i-1]===t[o-2]&&e[i-2]===t[o-1]&&(c=Math.min(c,n[o-2]+1)),a.push(c)}n=r,r=a}return r[t.length]}function ya(e,t,n){return{...ie(t,{fontFamily:n?.fontFamily??l,color:n?.color??`#1e1e1e`,opacity:n?.opacity??1},e.chartType),horizontal:e.horizontal,stacked:e.stacked,cells:e.cells,showValues:e.showValues,showLegend:e.showLegend,showTitles:!!(e.title||e.xTitle||e.yTitle),title:e.title,xTitle:e.xTitle,yTitle:e.yTitle,quadrantLabels:e.quadrantLabels}}function ba(e){if(e.layout!==void 0)return e.layout;let{environment:t}=e;return(e,n,r)=>we(e,n,t,r)}var xa={x:0,y:0};function Sa(e){return e||void 0}function Ca(e,t){return t===`stable`?oa(e):e}function wa(e,t){return t.environment?da(e,ci(t.environment.icons)):Promise.resolve(e.diagnostics)}async function Ta(e,t){let n=t.origin??xa,r=ba(t),i=await wa(e,t);if(e.chart){let[r]=Ca([ya(e.chart,n)],t.ids);return{status:`ok`,kind:`chart`,shapes:[r],bounds:{x:r.x,y:r.y,width:r.width,height:r.height},primary:r,title:Sa(e.chart.title),diagnostics:i}}if(Oe(e.diagram))return{status:`empty`,diagnostics:i};let a=await r(e.diagram,n,{frame:t.frame});if(!a)return{status:`empty`,diagnostics:i};let o=Ca(c(a.shapes),t.ids);return{status:`ok`,kind:`diagram`,shapes:o,bounds:a.bounds,primary:Ee(o),title:Sa(e.diagram.title),diagnostics:i}}function Ea(e){let{source:t,converted:n}=oi(e),r=xn(t);return{source:t,converted:n,parsed:r,diagnostics:[...n?.diagnostics??[],...r.diagnostics]}}async function Da(e,t){if(Gi(e.diagnostics).length>0&&!t.allowErrors)return{status:`gated`};let n=await Ta(e.parsed,{origin:t.origin,layout:t.layout}),r=t.icons?await da({diagnostics:e.diagnostics,iconUses:e.parsed.iconUses},t.icons):e.diagnostics;if(n.status===`empty`)return{status:`empty`,diagnostics:r};n.primary&&ae(n.primary,e.source,n.shapes);let i=n.kind===`chart`?e.parsed.chart:void 0;return{status:`built`,shapes:n.shapes,primary:n.primary,label:i?n.primary.title||`Chart`:n.primary?.label||`Diagram`,bounds:n.bounds,summary:i?dn(i):Ce(e.parsed.diagram),diagnostics:r}}function Oa(e,t){switch(t.type){case`load`:return{code:t.code,linked:t.linked,diagnostics:[],result:null,errorGate:!1};case`edit`:return{...e,code:t.code};case`report`:return{...e,diagnostics:t.diagnostics??e.diagnostics,result:t.result===void 0?e.result:t.result};case`gate`:return{...e,diagnostics:[],errorGate:!0};case`ungate`:return e.errorGate?{...e,errorGate:!1}:e;case`link`:return{...e,linked:t.linked}}}var ka=96,Aa=`// Describe a diagram as code.
34
+ // Full syntax guide at koboyo.com/docs
35
+ title: My pipeline
36
+
37
+ API Gateway [aws/api-gateway]
38
+ Resize fn [aws/lambda, green]
39
+ Postgres [cylinder, blue]
40
+
41
+ API Gateway -> Resize fn: upload
42
+ Resize fn --> Postgres: async write
43
+ `;function ja(){return fe.getString(de.diagramCode)??Aa}function Ma(e,t,n){let r=si(e);if(r)return r;let i=d({x:n.width/2,y:n.height/2},t);return{x:i.x-400,y:i.y-250}}function Na(e){let{containerRef:t}=e,{store:n,viewportAnimation:r,history:s}=a(),l=te(),{beginTransaction:d,endTransaction:f}=s,m=o(e=>e.rightPanel===`code`),g=o(e=>e.selectedIds),{addMany:_,removeShapes:v,setCodeOpen:y,setViewport:b}=n.getState(),[x,S]=(0,N.useReducer)(Oa,void 0,()=>({code:ja(),diagnostics:[],result:null,errorGate:!1,linked:null})),{code:C,diagnostics:w,result:T,errorGate:E,linked:D}=x,[O,k]=(0,N.useState)(!1),ee=(0,N.useRef)(null),[ne,re]=(0,N.useState)(null),[A,ie]=(0,N.useState)(`next`);(0,N.useEffect)(()=>{D||fe.setString(de.diagramCode,C)},[C,D]);let ae=(0,N.useRef)(D);ae.current=D;let se=(0,N.useRef)(C);se.current=C,(0,N.useEffect)(()=>{if(!m||g.size!==1)return;let e=[...g][0];if(ae.current?.frameId===e)return;let t=n.getState().shapes,r=u(t,e);if(!r||r.type!==`figure`&&r.type!==`chart`||typeof r.code!=`string`||!r.code.trim())return;let i=ae.current;if(i){let e=u(t,i.frameId);if(e&&(e.type===`figure`||e.type===`chart`)&&e.code!==se.current)return}S({type:`load`,code:r.code,linked:{frameId:r.id,label:(r.type===`chart`?r.title:r.label)||(r.type===`chart`?`Chart`:`Diagram`),stale:oe(t,r)}})},[m,g,n]);let Ce=(0,N.useRef)(null),j=o(e=>e.codeSeed),we=(0,N.useRef)(null);(0,N.useEffect)(()=>{if(!m)return;let e=j===null?null:n.getState().codeSeed;e!==null&&(n.getState().setCodeSeed(null),we.current=e,S({type:`load`,code:e,linked:null}));let t=Ce.current;!t||we.current===null||we.current!==C||(we.current=null,t())},[m,j,C,n]);let Te=(0,N.useDeferredValue)(C),Ee=(0,N.useMemo)(()=>xn(oi(Te).source).diagnostics,[Te]),Oe=Gi(Ee).length,je=E&&Oe>0,M=je?Ee:w;(0,N.useEffect)(()=>{Oe===0&&S({type:`ungate`})},[Oe]);let P=xe()===`docked`;if(!m)return null;function F(){S({type:`load`,code:ja(),linked:null})}let Ne=()=>{let e=t.current,n=e?.clientWidth??window.innerWidth,r=e?.clientHeight??window.innerHeight;return{width:Math.max(1,n-(P?360:0)),height:r}};function I(e){r.animate(n.getState().viewport,h(e,Ne(),ka),b)}let L=ii(C);function R(){if(!L)return;let e=ai(C,L);S({type:`edit`,code:e.code}),S({type:`report`,diagnostics:e.diagnostics,result:e.code===C?null:`Converted from ${ri[L]}.`})}function z(e,t){return t.type===`figure`?[t,...p(e,t)]:[t]}async function B(e){let t=n.getState();if(!t.viewMode){if(e.target){if(oe(t.shapes,e.target)&&!e.force){let n=l.theme.palette(),[r,i]=await Promise.all([ke(z(t.shapes,e.target),l,{padding:20,background:n.bg,palette:n}),ke(c(e.shapes),l,{padding:20,background:n.bg,palette:n})]);ie(`next`),re({current:Ae(r),next:Ae(i)});return}let n=Pa(t.shapes,e.target,e.shapes,e.primary);d(),v(new Set(z(t.shapes,e.target).map(e=>e.id))),_(n),f()}else _(e.shapes);e.primary?(S({type:`link`,linked:{frameId:e.primary.id,label:e.label,stale:!1}}),n.getState().setSelectedIds(new Set([e.primary.id]))):e.target&&S({type:`link`,linked:null}),I(e.bounds),S({type:`report`,result:`${e.target?`Updated`:`Added`} ${e.summary}.`}),P||y(!1)}}async function V(e={}){if(!(O||n.getState().viewMode)){k(!0),S({type:`report`,result:null});try{let t=Ea(C);t.converted&&t.converted.code!==C&&S({type:`edit`,code:t.converted.code});let r=n.getState(),i=D?u(r.shapes,D.frameId):void 0,a=i&&(i.type===`figure`||i.type===`chart`)?i:void 0,o=await Da(t,{origin:a?{x:a.x,y:a.y}:Ma(r.shapes,r.viewport,Ne()),layout:De,allowErrors:je||!!e.skipErrors,icons:ci(l.icons)});if(o.status===`gated`){S({type:`gate`});return}if(S({type:`ungate`}),D&&!a&&S({type:`link`,linked:null}),S({type:`report`,diagnostics:o.diagnostics}),o.status===`empty`){S({type:`report`,result:`Nothing to draw yet. Add a node or an edge.`});return}await B({target:a,shapes:o.shapes,primary:o.primary,label:o.label,bounds:o.bounds,summary:o.summary,force:e.force??!1})}catch(e){S({type:`report`,diagnostics:[],result:be(e,`Couldn't draw this. Check the code and try again.`)})}finally{k(!1)}}}return Ce.current=V,(0,$.jsxs)(Se,{width:360,testId:`code-panel`,ariaLabel:`Diagram as code`,onDismiss:()=>y(!1),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-2 pl-4 pr-2`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[14px] text-[var(--chrome-fg-900)]`,children:[(0,$.jsx)(le,{size:15,stroke:1.75}),`Diagram as code`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(i,{label:`Syntax guide`,side:`bottom`,children:(0,$.jsx)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Syntax guide`,"data-testid":`code-docs-link`,className:pe,children:(0,$.jsx)(Me,{size:16,stroke:1.75})})}),(0,$.jsx)(i,{label:`Hide code panel`,side:`bottom`,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Hide code panel`,"data-testid":`code-close`,onClick:()=>y(!1),className:pe,children:(0,$.jsx)(ue,{size:16,stroke:1.75})})})]})]}),(0,$.jsx)(`div`,{className:`mx-3 h-px bg-[var(--chrome-divider)]`}),D&&(0,$.jsxs)(`div`,{"data-testid":`code-linked-chip`,"data-stale":D.stale?`true`:`false`,className:`mx-3 mt-2 flex items-start justify-between gap-2 rounded-lg px-2.5 py-1.5 text-[12px] ${D.stale?`bg-amber-50 text-amber-800`:`bg-[var(--chrome-hover)] text-[var(--chrome-fg-700)]`}`,children:[(0,$.jsx)(`span`,{className:`text-pretty`,children:D.stale?`“${D.label}” was edited on the canvas. Updating from this code replaces those edits.`:`Editing “${D.label}”. Generating replaces it.`}),(0,$.jsx)(i,{label:`Back to the draft`,side:`bottom`,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Stop editing this diagram`,"data-testid":`code-unlink`,onClick:F,className:`shrink-0 rounded-md p-0.5 transition-[background-color,scale] active:scale-[0.96] ${D.stale?`hover:bg-amber-100`:`hover:bg-[var(--chrome-rest)]`}`,children:(0,$.jsx)(ue,{size:14,stroke:1.75})})})]}),L&&(0,$.jsxs)(`div`,{"data-testid":`code-foreign-hint`,className:`mx-3 mt-2 flex items-center justify-between gap-2 rounded-lg bg-amber-50 px-2.5 py-1.5 text-[12px] text-amber-800`,children:[(0,$.jsxs)(`span`,{className:`min-w-0`,children:[`Looks like `,ri[L],`.`]}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-foreign-convert`,onClick:R,className:`shrink-0 whitespace-nowrap rounded-md px-1.5 py-0.5 text-amber-900 underline decoration-amber-400 transition-[background-color,scale] hover:bg-amber-100 active:scale-[0.96]`,children:`Convert now`})]}),(0,$.jsx)(ia,{handleRef:ee,value:C,onChange:e=>S({type:`edit`,code:e}),onGenerate:()=>void V(),placeholder:`API -> Worker: job`,className:`m-3 flex-1 rounded-lg text-[12px] leading-relaxed ring-1 ring-[var(--chrome-ring)] focus-within:ring-black/25`}),(M.length>0||T)&&(0,$.jsxs)(`div`,{className:`mx-3 mb-2 flex max-h-32 flex-col gap-1 overflow-y-auto`,children:[T&&(0,$.jsx)(`div`,{"data-testid":`code-result`,className:`text-pretty text-[12px] text-[var(--chrome-fg-600)]`,children:T}),M.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,"data-testid":`code-diagnostic`,"data-severity":e.severity??`warning`,disabled:e.line<=0,onClick:()=>ee.current?.revealLine(e.line),className:`-mx-1 rounded px-1 text-left text-pretty text-[12px] leading-snug tabular-nums transition-colors enabled:hover:bg-[var(--chrome-hover)] ${e.severity===`error`?`text-red-600`:`text-amber-700`}`,children:[e.line>0?`Line ${e.line}: `:``,e.message]},`${e.line}-${t}`))]}),(0,$.jsxs)(`div`,{className:`border-t border-[var(--chrome-ring)] p-3`,children:[je&&(0,$.jsxs)(`div`,{role:`status`,"data-testid":`code-error-gate`,className:`mb-2 flex items-start gap-1.5 rounded-lg bg-red-50 px-2.5 py-1.5 text-[12px] text-[var(--chrome-danger)] dark:bg-red-500/10`,children:[(0,$.jsx)(ce,{size:14,stroke:1.75,className:`mt-px shrink-0`}),(0,$.jsx)(`span`,{className:`text-pretty tabular-nums`,children:Ki(Oe)})]}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-generate`,disabled:O||C.trim().length===0,onClick:()=>void V(),className:`w-full rounded-lg bg-[var(--chrome-accent)] px-3 py-2 text-[13px] text-white transition-[background-color,scale] hover:bg-[var(--chrome-accent-hover)] active:scale-[0.96] disabled:bg-[var(--chrome-rest)] disabled:active:scale-100`,children:O?`Generating…`:je?`Apply anyway`:D?`Update diagram`:L?`Convert ${ri[L]} & generate`:`Generate diagram`}),(0,$.jsx)(`p`,{className:`mt-1.5 text-center text-[11px] text-[var(--chrome-fg-400)]`,children:`⌘↵ generates · the code stays for tweaking`})]}),ne&&(0,$.jsx)(_e,{open:!0,onOpenChange:e=>!e&&re(null),children:(0,$.jsxs)(he,{children:[(0,$.jsx)(me,{className:`fixed inset-0 z-40 bg-gray-900/25`}),(0,$.jsxs)(ge,{"data-overlay":!0,"data-testid":`code-replace-dialog`,className:`fixed left-1/2 top-1/2 z-50 flex max-h-[92dvh] w-[min(860px,94vw)] -translate-x-1/2 -translate-y-1/2 flex-col rounded-2xl bg-[var(--chrome-popup)] p-5 shadow-[0_24px_70px_rgba(0,0,0,0.22)] outline-none ring-1 ring-[var(--chrome-ring)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ye,{className:`text-[15px] font-medium text-[var(--chrome-fg-900)]`,children:`Replace your edits?`}),(0,$.jsx)(`p`,{className:`mt-1 text-[13px] leading-snug text-[var(--chrome-fg-600)]`,children:`This diagram was edited on the canvas after its code was generated. Compare both, then keep your edits or replace them with the code.`})]}),(0,$.jsx)(ve,{"aria-label":`Close`,className:`-mr-1 -mt-1 shrink-0 rounded-lg p-1 text-[var(--chrome-fg-500)] outline-none transition-colors hover:bg-[var(--chrome-hover)]`,children:(0,$.jsx)(ue,{size:16,stroke:1.75})})]}),(0,$.jsx)(`div`,{role:`tablist`,className:`mt-4 inline-flex self-start rounded-lg bg-[var(--chrome-rest)] p-0.5 text-[12.5px]`,children:[{key:`next`,label:`Code version`},{key:`current`,label:`Already on Canvas`}].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":A===e.key,onClick:()=>ie(e.key),className:`rounded-md px-3 py-1 transition-colors ${A===e.key?`bg-[var(--chrome-popup)] text-[var(--chrome-fg-900)] shadow-sm`:`text-[var(--chrome-fg-500)] hover:text-[var(--chrome-fg-800)]`}`,children:e.label},e.key))}),(0,$.jsxs)(`div`,{className:`mt-3 flex min-h-0 flex-1 items-center justify-center overflow-auto rounded-xl bg-[var(--canvas-bg)] p-4 ring-1 ring-[var(--chrome-ring)] [min-height:clamp(260px,56vh,520px)]`,children:[(0,$.jsx)(`img`,{src:ne.current,alt:`Your edits`,className:`max-h-full max-w-full object-contain ${A===`current`?``:`hidden`}`}),(0,$.jsx)(`img`,{src:ne.next,alt:`Code version`,className:`max-h-full max-w-full object-contain ${A===`next`?``:`hidden`}`})]}),(0,$.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--chrome-fg-500)]`,children:A===`current`?`What you have on the canvas.`:`Rebuilt from the code. You can undo this.`}),A===`current`?(0,$.jsx)(ve,{className:`rounded-lg bg-[var(--chrome-rest)] px-3.5 py-2 text-[13px] text-[var(--chrome-fg-800)] outline-none ring-1 ring-[var(--chrome-ring)] transition-[background-color,scale] hover:bg-[var(--chrome-hover)] active:scale-[0.96]`,children:`Keep my edits`}):(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-confirm-replace`,onClick:()=>{re(null),V({force:!0,skipErrors:!0})},className:`rounded-lg bg-[var(--chrome-accent)] px-3.5 py-2 text-[13px] text-white outline-none transition-[background-color,scale] hover:bg-[var(--chrome-accent-hover)] active:scale-[0.96]`,children:`Apply my Code Changes`})]})]})]})})]})}function Pa(e,t,n,r){if(t.type!==`figure`||!t.flows?.length||r?.type!==`figure`)return n;let{flows:i}=je(e,t,n,r);return n.map(e=>e===r?{...r,flows:i}:e)}export{Na as CodePanel};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-2Zwg-L3c.js";import{a as r,o as i}from"./editor-B0tARd79.js";import{S as a,Yr as o,Zt as s,an as c,w as l,x as u}from"./slides-D9bnXqtf.js";import{r as d,t as f}from"./dom-PAoZruqo.js";import{t as p}from"./editable-target-BTLnvKNi.js";import{n as m,t as h}from"./IconArrowBackUp-Brd2WpCh.js";import{t as g}from"./createReactComponent-9UsI5fmM.js";import{a as _,b as v,c as y,d as b,h as x,m as S,n as C,o as w,p as T,r as E,v as D}from"./tree-rq4RTGgw.js";import{t as O}from"./IconChevronLeft-BR0iwdRI.js";import{t as k}from"./IconChevronRight-DBDnxPYT.js";import{t as A}from"./IconFocusCentered-C5PcDeR0.js";import{t as j}from"./IconPencil-C5Y-Y4dC.js";import{t as M}from"./IconPlus-BbmieIBT.js";import{t as N}from"./IconX-AlbPkO_g.js";import{t as P}from"./IconPlayerPlayFilled-D4OODBX7.js";import{n as F}from"./core-CBnmD9hT.js";import{r as ee}from"./flow-start-ccYJ2KB9.js";import{r as I,t as L}from"./chrome-layout-B8YmHznO.js";import{c as R,i as z,l as B,n as V,o as te,s as H,t as ne}from"./flows-GGbkNqs8.js";import{a as U,i as W,n as G,o as K,r as q,t as re}from"./flow-stage-fiF5Nggn.js";var ie=g(`outline`,`rotate`,`Rotate`,[[`path`,{d:`M19.95 11a8 8 0 1 0 -.5 4m.5 5v-5h-5`,key:`svg-0`}]]),ae=g(`filled`,`player-pause-filled`,`PlayerPauseFilled`,[[`path`,{d:`M9 4h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h2a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2z`,key:`svg-0`}],[`path`,{d:`M17 4h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h2a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2z`,key:`svg-1`}]]),J=e(t(),1),Y=n(),X=10,Z=28,oe=.5,se=4,ce=24;function le(e){let{frame:t,flow:n,targets:a,viewport:o}=e,s=r(),d=i(e=>e.hoveredId),f=i(e=>e.flowEdit)??{},p=I()===`docked`,m=n.steps.length;(0,J.useEffect)(()=>{let{store:e,viewportAnimation:n}=s,r=e.getState(),i=document.querySelector(`[data-canvas-root]`),a={width:(i?.clientWidth??window.innerWidth)-(p?L(`flow`):0),height:i?.clientHeight??window.innerHeight},o=c(t),d=l({x:o.x,y:o.y-Z},r.viewport),f=l({x:o.x+o.width,y:o.y+o.height},r.viewport),m=d.x>=0&&d.y>=0&&f.x<=a.width&&f.y<=a.height,h=f.x-d.x>=a.width*oe||f.y-d.y>=a.height*oe;m&&h||n.animate(r.viewport,u(o,a,64),r.setViewport)},[t.id,s,p]);let h=(0,J.useRef)(m);h.current=m,(0,J.useEffect)(()=>{let e=e=>{if(e.button!==0)return;let r=e.target instanceof Element?e.target:null;if(!r?.closest(`[data-canvas-root]`)||r.closest(`[data-overlay]`))return;let i=r.closest(`[data-shape-id]`)?.getAttribute(`data-shape-id`)??r.closest(`[data-icon-label]`)?.getAttribute(`data-icon-label`),a=s.store.getState(),o=a.shapes.find(e=>e.id===t.id);if(!i||o?.type!==`figure`)return;let c=F(a.shapes,o).find(e=>e.id===i);if(!c)return;e.preventDefault(),e.stopPropagation(),ue();let l=S({selected:a.flowEdit?.picking},h.current);if(l!==null){b(s,t.id,n.id,l,c);return}if(a.flowEdit?.picking!=null&&a.patchFlowEdit({picking:null}),e.shiftKey){y(s,t.id,n.id,c);return}w(s,t.id,n.id,c)};return window.addEventListener(`pointerdown`,e,!0),()=>window.removeEventListener(`pointerdown`,e,!0)},[s,t.id,n.id]);let[g,_]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let e=e=>_(e.shiftKey);return window.addEventListener(`keydown`,e),window.addEventListener(`keyup`,e),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`keyup`,e)}},[]);let v=new Map(a.map(e=>[e.id,e])),C=d?v.get(d):void 0,E=x(f,m),D=S(f,m),O=S({selected:f.picking},m),k=T(f,m),A=S({selected:f.hovered},m),j=V(t.flows??[],n.id),M=j?.flow.steps[j.index],N=n.steps[E-1]?.target;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(fe,{frame:t,viewport:o}),M&&R(M).flatMap(e=>{let t=v.get(e);return t?[(0,Y.jsx)(ye,{shape:t,viewport:o},e)]:[]}),A!==null&&R(n.steps[A]).flatMap(e=>{let t=v.get(e);return t?[(0,Y.jsx)(`div`,{"data-testid":`flow-step-ring`,className:`pointer-events-none absolute rounded-md border-2 border-[var(--flow-accent)]`,style:U(t,o)},e)]:[]}),C&&(O!==null||C.id!==N||g)&&(0,Y.jsx)(`div`,{"data-testid":`flow-add-hint`,className:`pointer-events-none absolute rounded-md border-2 border-dashed border-[var(--canvas-selection)]`,style:U(C,o),children:(0,Y.jsx)(`span`,{className:`absolute -top-6 left-0 whitespace-nowrap rounded-md bg-[var(--chrome-accent)] px-1.5 py-0.5 text-[11px] font-medium text-white shadow-sm`,children:de(O,g?k:null,E,m)})}),(0,Y.jsx)(he,{flow:n,byId:v,viewport:o,slot:E}),(0,Y.jsx)(ge,{flow:n,targets:a,fork:M,viewport:o}),(0,Y.jsx)(ve,{flow:n,byId:v,viewport:o,selected:D,onSelect:e=>s.store.getState().patchFlowEdit({selected:e}),onDrop:(e,r)=>b(s,t.id,n.id,e,r)}),(0,Y.jsx)(pe,{picking:O,slot:E,count:m})]})}function ue(){let e=document.activeElement;e instanceof HTMLElement&&p(e)&&e.blur()}function de(e,t,n,r){return e===null?t===null?n<r?`Add as step ${n+1}`:`Add as step ${r+1}`:`Add to step ${t+1}`:`Step ${e+1} lights this`}function fe(e){let{frame:t,viewport:n}=e,r=c(t),i=l({x:r.x-X,y:r.y-Z},n),a=l({x:r.x+r.width+X,y:r.y+r.height+X},n);return(0,Y.jsx)(`div`,{"data-testid":`flow-edit-focus`,className:`pointer-events-none absolute rounded-lg ring-2 ring-[color-mix(in_srgb,var(--flow-accent)_35%,transparent)]`,style:{left:i.x,top:i.y,width:Math.max(0,a.x-i.x),height:Math.max(0,a.y-i.y)}})}function pe(e){let{picking:t,slot:n,count:r}=e,i=null;return t===null?n<r&&(i=`The next box goes in as step ${n+1} · Esc adds at the end`):i=`Click the box step ${t+1} should light · Esc to cancel`,i?(0,Y.jsx)(`p`,{"data-testid":`flow-board-hint`,className:`pointer-events-none absolute bottom-6 left-1/2 z-30 -translate-x-1/2 whitespace-nowrap rounded-lg bg-[var(--chrome-fg-900)] px-3 py-2 text-[12.5px] text-[var(--chrome-page)] shadow-lg`,children:i}):null}function me(e,t,n){for(let r of n.values()){if(r.type!==`arrow`)continue;let n=r.startBinding?.shapeId,i=r.endBinding?.shapeId;if(n===e.target&&i===t.target||n===t.target&&i===e.target)return r}return null}function he(e){let{flow:t,byId:n,viewport:i,slot:a}=e,s=r(),c=t.steps.slice(1).flatMap((e,r)=>{let i=t.steps[r],a=me(i,e,n);return a?[{arrow:a,slot:r+1}]:[]}),u=new Map;for(let{arrow:e}of c)u.set(e.id,(u.get(e.id)??0)+1);let d=new Map;return(0,Y.jsx)(Y.Fragment,{children:c.map(({arrow:e,slot:t})=>{let n=d.get(e.id)??0;d.set(e.id,n+1);let r=(n-((u.get(e.id)??1)-1)/2)*ce,c=l(o(e),i),f=typeof e.label==`string`&&e.label.trim().length>0,p=t===a;return(0,Y.jsx)(`button`,{type:`button`,"data-overlay":!0,"data-testid":`flow-arrow-insert`,"aria-label":`Add a step between step ${t} and step ${t+1}`,title:`Add a step between ${t} and ${t+1}`,className:`absolute z-20 flex h-[18px] w-[18px] -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full ring-1 transition-[opacity,background-color] hover:opacity-100 ${p?`bg-[var(--flow-accent)] text-white opacity-100 ring-[var(--flow-accent)]`:`bg-[var(--chrome-popup)] text-[var(--flow-accent)] opacity-60 ring-[color-mix(in_srgb,var(--flow-accent)_45%,transparent)]`}`,style:{left:c.x+r,top:c.y+(f?16:0)},onPointerDown:e=>e.stopPropagation(),onClick:()=>s.store.getState().patchFlowEdit({slot:t,picking:null}),children:(0,Y.jsx)(M,{size:11,stroke:2.5})},`${e.id}-${t}`)})})}function ge(e){let{flow:t,targets:n,fork:i,viewport:a}=e,o=r(),s=[..._(n,t.steps,i).values()];return(0,Y.jsx)(Y.Fragment,{children:[...new Map(s.map(e=>[e.arrow.id,e])).values()].flatMap(e=>e.ends.map(t=>{let r=n.find(e=>e.id===t.shapeId),i=r?z(n,r):`its box`,s=l(t.point,a);return(0,Y.jsxs)(`button`,{type:`button`,"data-overlay":!0,"data-testid":`flow-loose-end`,"aria-label":`Attach the arrow to ${i}`,title:`This arrow isn't attached to ${i}, so the flow can't follow it`,className:`group/loose absolute z-20 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center`,style:{left:s.x,top:s.y},onPointerDown:e=>e.stopPropagation(),onClick:()=>E(o,e),children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`absolute h-3 w-3 rounded-full bg-[var(--flow-warn)] opacity-60 motion-safe:animate-ping`,style:{animationIterationCount:4}}),(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`relative h-3 w-3 rounded-full bg-[var(--flow-warn)] ring-2 ring-[var(--canvas-bg)]`}),(0,Y.jsxs)(`span`,{className:`absolute left-1/2 top-5 flex -translate-x-1/2 items-center whitespace-nowrap rounded-md bg-[var(--chrome-popup)] px-1.5 py-0.5 text-[11px] font-medium text-[var(--flow-warn-fg)] shadow-sm ring-1 ring-[color-mix(in_srgb,var(--flow-warn)_45%,transparent)] group-hover/loose:bg-[color-mix(in_srgb,var(--flow-warn)_12%,var(--chrome-popup))]`,children:[`Attach to `,i]})]},`${e.arrow.id}-${t.end}`)}))})}function _e(e,t,n){for(let r of document.elementsFromPoint(e,t)){let e=r.closest(`[data-shape-id]`)?.getAttribute(`data-shape-id`)??r.closest(`[data-icon-label]`)?.getAttribute(`data-icon-label`);if(e&&n.has(e))return e}return null}function ve(e){let{flow:t,byId:n,viewport:r,selected:i,onSelect:a,onDrop:o}=e,[s,c]=(0,J.useState)(null),l=K(t),u=W(t),d=new Set(n.keys()),f=(e,t)=>{if(e.button!==0)return;e.stopPropagation(),e.preventDefault(),ue();let n=e.currentTarget.closest(`[data-canvas-root]`)?.getBoundingClientRect(),r={left:n?.left??0,top:n?.top??0};e.currentTarget.setPointerCapture(e.pointerId),c({index:t,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,x:e.clientX-r.left,y:e.clientY-r.top,origin:r,dragging:!1,over:null})},p=e=>{if(!s||s.pointerId!==e.pointerId)return;let t=Math.hypot(e.clientX-s.startX,e.clientY-s.startY),n=s.dragging||t>se;c({...s,x:e.clientX-s.origin.left,y:e.clientY-s.origin.top,dragging:n,over:n?_e(e.clientX,e.clientY,d):null})},m=e=>{if(!s||s.pointerId!==e.pointerId)return;if(c(null),!s.dragging){a(s.index);return}let r=s.over?n.get(s.over):void 0;r&&r.id!==t.steps[s.index]?.target&&o(s.index,r)},h=s?.over?n.get(s.over):void 0;return(0,Y.jsxs)(Y.Fragment,{children:[h&&s&&h.id!==t.steps[s.index]?.target&&(0,Y.jsx)(`div`,{"data-testid":`flow-badge-drop`,className:`pointer-events-none absolute rounded-md border-2 border-[var(--flow-accent)] bg-[color-mix(in_srgb,var(--flow-accent)_6%,transparent)]`,style:U(h,r)}),[...l].map(([e,o])=>{let l=n.get(e);if(!l)return null;let d=q(l,r);return(0,Y.jsx)(`span`,{"data-overlay":!0,className:`absolute z-20 flex items-center gap-1 ${l.type===`arrow`?`-translate-x-1/2 -translate-y-[calc(100%+14px)]`:`-translate-x-full -translate-y-full`}`,style:{left:d.x-2,top:d.y-2},children:o.map(e=>{let n=e-1,r=s?.dragging&&s.index===n,o=i===n;return(0,Y.jsx)(`button`,{type:`button`,"data-testid":`flow-step-badge`,"data-selected":o||void 0,"aria-label":`Step ${e}: ${t.steps[n]?.title??``}`,"aria-pressed":o,title:`Click to select · drag onto another box to change it`,className:`flex h-[22px] min-w-[22px] cursor-grab touch-none items-center justify-center rounded-full px-1.5 text-[11.5px] font-semibold tabular-nums text-white transition-shadow active:cursor-grabbing ${u.has(e)?`bg-[var(--flow-fail)]`:`bg-[var(--flow-accent)]`} ${o?`ring-[3px] ring-[color-mix(in_srgb,var(--flow-accent)_35%,transparent)]`:`hover:ring-[3px] hover:ring-[color-mix(in_srgb,var(--flow-accent)_20%,transparent)]`} ${r?`opacity-35`:``}`,onPointerDown:e=>f(e,n),onPointerMove:p,onPointerUp:m,onPointerCancel:()=>c(null),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a(n))},children:e},e)})},e)}),s?.dragging&&(0,Y.jsx)(`span`,{"aria-hidden":!0,"data-testid":`flow-badge-ghost`,className:`pointer-events-none absolute z-30 flex h-[26px] min-w-[26px] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-[var(--flow-accent)] px-1.5 text-[12.5px] font-semibold tabular-nums text-white shadow-[0_6px_14px_rgba(0,0,0,0.25)]`,style:{left:s.x,top:s.y},children:s.index+1})]})}function ye(e){let{shape:t,viewport:n}=e,r=U(t,n,4);return(0,Y.jsxs)(`span`,{"data-testid":`flow-fork-marker`,className:`pointer-events-none absolute flex -translate-x-1/2 items-center gap-1 whitespace-nowrap rounded-full bg-[var(--flow-accent)] py-1 pl-1.5 pr-2.5 text-[11.5px] font-medium text-white`,style:{left:r.left+r.width/2,top:r.top+r.height+6},children:[(0,Y.jsx)(v,{size:13,stroke:2}),`Path starts here`]})}var be=2600,xe=.55,Se=1.1;function Ce(e,t){let n=document.querySelector(`[data-canvas-root]`),r=n?.clientWidth??window.innerWidth,i=n?.clientHeight??window.innerHeight;return{width:Math.max(1,r-(e?L(t):0)),height:Math.max(1,i-Te)}}var we={call:`Call`,async:`Fire and forget`,reply:`Reply`},Te=150;function Ee(e){let{frame:t,flow:n,targets:o,step:l,viewport:d}=e,f=r(),{store:p,viewportAnimation:h}=f,g=i(e=>e.rightPanel),_=I()===`docked`,v=n.steps.length,y=Math.min(Math.max(l,0),Math.max(v-1,0)),b=n.steps[y],x=(0,J.useMemo)(()=>new Map(o.map(e=>[e.id,e])),[o]),S=(0,J.useMemo)(()=>b?R(b).flatMap(e=>x.get(e)??[]):[],[b,x]),w=(0,J.useMemo)(()=>{let e=y>0?n.steps[y-1]:void 0;return e?R(e).flatMap(e=>x.get(e)??[]):[]},[n.steps,y,x]),T=i(e=>e.flowPlay?.trail),E=i(e=>e.viewMode),O=T?.[T.length-1],k=O?t.flows?.find(e=>e.id===O.flowId)?.name:void 0,[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(()=>u(c(t),Ce(_,g),64).zoom<xe),P=e=>{let r=Math.min(Math.max(e,0),v-1);p.getState().setFlowPlay({frameId:t.id,flowId:n.id,step:r,trail:T})},F=()=>{!O||!T||(j(!1),p.getState().setFlowPlay({frameId:t.id,flowId:O.flowId,step:O.step,trail:T.slice(0,-1)}))},L=(0,J.useRef)(F);L.current=F;let z=()=>{p.getState().setFlowPlay(null)},B=t.flows??[],V={tabs:C(B).filter(e=>e.steps.length>0).map(e=>({id:e.id,name:e.name})),active:De(B,n.id,T),onTab:e=>{j(!1),p.getState().setFlowPlay({frameId:t.id,flowId:e,step:0})},onEdit:E?null:()=>D(f,t.id,n.id),onNew:E?null:()=>{p.getState().setFlowPlay(null),ee(f,t.id)}},H=(0,J.useRef)(P);H.current=P;let U=(0,J.useRef)(z);U.current=z;let W=(0,J.useRef)(y);W.current=y;let G=()=>Ce(_,g),K=(0,J.useRef)(G);if(K.current=G,(0,J.useEffect)(()=>{let e=p.getState();e.setSelectedIds(new Set),h.animate(e.viewport,u(c(t),K.current(),64),e.setViewport)},[t.id,p,h]),(0,J.useEffect)(()=>{let e=s(M?[...S,...w]:S);if(!e)return;let t=p.getState();if(M){let n=u(e,K.current(),120),r=Math.min(n.zoom,Se),i=K.current();h.animate(t.viewport,{zoom:r,x:i.width/2-(e.x+e.width/2)*r,y:i.height/2-(e.y+e.height/2)*r},t.setViewport);return}let n=a(e,t.viewport,K.current(),96);n&&h.animate(t.viewport,n,t.setViewport)},[S,w,M,p,h]),(0,J.useEffect)(()=>{let e=e=>{if((e.target instanceof Element?e.target:null)?.closest(`input, textarea, select, [contenteditable=true], [role=menu]`)||(e.key===` `||e.key===`Enter`)&&m(e.target))return;let t=W.current;if(e.key===`ArrowRight`||e.key===` `||e.key===`Enter`)e.preventDefault(),H.current(t+1);else if(e.key===`ArrowLeft`||e.key===`Backspace`){if(e.preventDefault(),t===0&&L.current){L.current();return}H.current(t-1)}else e.key===`Home`?(e.preventDefault(),H.current(0)):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),U.current())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]),(0,J.useEffect)(()=>{if(!A)return;if(y>=v-1||(b?.branches?.length??0)>0){j(!1);return}let e=window.setTimeout(()=>H.current(W.current+1),be);return()=>window.clearTimeout(e)},[A,y,v,b]),!b)return(0,Y.jsx)(Oe,{flow:n,index:0,kind:`call`,autoplay:!1,onAutoplay:()=>{},onGo:()=>{},onStop:z,branches:[],onBranch:()=>{},returnName:k??null,onBack:F,follow:M,onFollow:N,switcher:V});let q=ne(t.flows??[],n.id);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(re,{frameId:t.id,flow:n,targets:o,index:y,viewport:d,lead:q}),(0,Y.jsx)(Oe,{flow:n,index:y,kind:te(o,[...q,...n.steps],q.length+y),autoplay:A,onAutoplay:j,onGo:P,onStop:z,branches:(b.branches??[]).flatMap(e=>{let r=t.flows?.find(t=>t.id===e&&t.id!==n.id);return r&&r.steps.length>0?[{id:r.id,name:r.name}]:[]}),onBranch:e=>{j(!1),p.getState().setFlowPlay({frameId:t.id,flowId:e,step:0,trail:[...T??[],{flowId:n.id,step:y}]})},returnName:k??null,onBack:F,follow:M,onFollow:N,switcher:V})]})}function De(e,t,n){let r=n?.[0]?.flowId;if(r)return r;let i=t,a=new Set;for(;!a.has(i);){a.add(i);let t=V(e,i);if(!t)return i;i=t.flow.id}return i}function Oe(e){let{flow:t,index:n,kind:r,autoplay:i,onAutoplay:a,onGo:o,onStop:s,branches:c,onBranch:l}=e,{returnName:u,onBack:d,follow:f,onFollow:p,switcher:m}=e,g=t.steps.length,_=t.steps[n],y=n>=g-1,b=`flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-lg text-[var(--chrome-fg-600)] transition-colors hover:bg-[var(--chrome-hover)] hover:text-[var(--chrome-fg-900)] disabled:pointer-events-none disabled:opacity-35`;return(0,Y.jsxs)(`div`,{"data-overlay":!0,"data-testid":`flow-player`,className:`absolute bottom-6 left-1/2 z-30 flex w-[min(600px,calc(100%-32px))] -translate-x-1/2 flex-col gap-2 rounded-2xl bg-[var(--chrome-popup)] p-3 shadow-[0_8px_32px_rgba(0,0,0,0.16)] ring-1 ring-[var(--chrome-ring)]`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(ke,{switcher:m}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`span`,{className:`mt-0.5 flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full px-1.5 text-[12px] font-medium tabular-nums text-white ${_?.fails?`bg-[var(--flow-fail)]`:`bg-[var(--flow-accent)]`}`,children:g===0?`–`:n+1}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`p`,{"data-testid":`flow-step-title`,className:`text-[14px] font-medium leading-snug text-[var(--chrome-fg-900)]`,children:_?.title||(g===0?`This flow has no steps yet`:`Untitled step`)}),_?.text&&(0,Y.jsx)(`p`,{"data-testid":`flow-step-text`,className:`mt-0.5 text-[13px] leading-relaxed text-[var(--chrome-fg-600)]`,children:_.text}),_&&(r!==`call`||_.payload||_.fails)&&(0,Y.jsxs)(`p`,{className:`mt-1 flex flex-wrap items-center gap-1.5 text-[11px] text-[var(--chrome-fg-500)]`,children:[_.fails&&(0,Y.jsx)(`span`,{"data-testid":`flow-step-fails`,className:`rounded-full bg-[color-mix(in_srgb,var(--flow-fail)_14%,transparent)] px-2 py-0.5 font-medium text-[var(--flow-fail)]`,children:`Fails here`}),r!==`call`&&(0,Y.jsx)(`span`,{"data-testid":`flow-step-kind`,className:`rounded-full bg-[var(--chrome-rest)] px-2 py-0.5`,children:we[r]}),_.payload&&(0,Y.jsxs)(`span`,{className:`rounded-full bg-[var(--chrome-rest)] px-2 py-0.5`,children:[`Carries `,_.payload]})]}),c.length>0&&(0,Y.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`flow-branches`,children:[(0,Y.jsx)(`span`,{className:`text-[12px] text-[var(--chrome-fg-500)]`,children:`Or follow:`}),c.map(e=>(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`flow-branch`,className:`flex cursor-pointer items-center gap-1 rounded-full px-2.5 py-1 text-[12px] font-medium text-[var(--chrome-fg-900)] bg-[var(--chrome-rest)] transition-colors hover:bg-[var(--chrome-hover)]`,onClick:()=>l(e.id),children:[(0,Y.jsx)(v,{size:12,stroke:2}),e.name]},e.id))]})]}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Stop playing`,className:b,onClick:s,children:(0,Y.jsx)(N,{size:16,stroke:1.75})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-1 truncate text-[12px] text-[var(--chrome-fg-500)]`,children:[u&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`flow-back`,title:`Back to where this path was taken (←)`,className:`flex cursor-pointer items-center gap-0.5 rounded px-1 font-medium text-[var(--chrome-fg-900)] hover:bg-[var(--chrome-hover)]`,onClick:d,children:[(0,Y.jsx)(h,{size:13,stroke:2}),u]}),(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`/`})]}),(u||!m.tabs.some(e=>e.id===t.id)||!Q(m))&&(0,Y.jsx)(`span`,{className:`truncate`,children:t.name})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,"data-testid":`flow-dots`,children:t.steps.map((e,t)=>(0,Y.jsx)(`button`,{type:`button`,"aria-label":e.branches?.length?`Step ${t+1}, where another path starts`:`Step ${t+1}`,"data-fork":e.branches?.length?!0:void 0,onClick:()=>o(t),className:`relative h-1.5 cursor-pointer rounded-full transition-all ${t===n?`w-4 bg-[var(--flow-accent)]`:`w-1.5 bg-[var(--chrome-fg-300)] hover:bg-[var(--chrome-fg-500)]`}`,children:e.branches?.length?(0,Y.jsx)(v,{size:9,stroke:2.5,"aria-hidden":!0,className:`absolute left-1/2 top-2 -translate-x-1/2 text-[var(--chrome-fg-400)]`}):null},`${e.target}-${t}`))}),(0,Y.jsx)(`span`,{"data-testid":`flow-position`,className:`w-10 text-right text-[12px] tabular-nums text-[var(--chrome-fg-500)]`,children:g===0?`0 / 0`:`${n+1} / ${g}`}),(0,Y.jsxs)(`div`,{className:`flex items-center`,children:[(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Previous step`,"data-testid":`flow-prev`,className:b,disabled:n===0&&!u,onClick:()=>n===0?d():o(n-1),children:(0,Y.jsx)(O,{size:16,stroke:2})}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":f?`Show the whole diagram`:`Follow each step`,title:f?`Show the whole diagram`:`Follow each step`,"aria-pressed":f,"data-testid":`flow-follow`,className:`${b} ${f?`bg-[var(--chrome-active)] text-[var(--chrome-fg-900)]`:``}`,onClick:()=>p(!f),children:(0,Y.jsx)(A,{size:16,stroke:1.75})}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":i?`Pause`:`Play automatically`,"data-testid":`flow-autoplay`,className:b,disabled:g<2,onClick:()=>{!i&&y&&o(0),a(!i)},children:i?(0,Y.jsx)(ae,{size:14}):(0,Y.jsx)(P,{size:14})}),y&&g>1?(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Play again`,"data-testid":`flow-replay`,className:b,onClick:()=>o(0),children:(0,Y.jsx)(ie,{size:15,stroke:1.75})}):(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Next step`,"data-testid":`flow-next`,className:b,disabled:y,onClick:()=>o(n+1),children:(0,Y.jsx)(k,{size:16,stroke:2})})]})]})]})}function Q(e){return e.tabs.length>1||e.onEdit!==null}function ke(e){let{tabs:t,active:n,onTab:r,onEdit:i,onNew:a}=e.switcher;if(!Q(e.switcher))return null;let o=`shrink-0 cursor-pointer rounded-md px-2 py-1 text-[12.5px] transition-colors hover:bg-[var(--chrome-hover)]`;return(0,Y.jsxs)(`div`,{className:`-mx-1 -mt-1 flex items-center gap-1 border-b border-[var(--chrome-divider)] pb-1.5`,children:[(0,Y.jsxs)(`div`,{role:`group`,"aria-label":`Flows`,"data-testid":`flow-tabs`,className:`flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto`,children:[t.map(e=>(0,Y.jsx)(`button`,{type:`button`,"aria-pressed":e.id===n,"data-testid":`flow-tab`,className:`${o} ${e.id===n?`bg-[var(--chrome-active)] font-medium text-[var(--chrome-fg-900)]`:`text-[var(--chrome-fg-500)]`}`,onClick:()=>r(e.id),children:e.name},e.id)),a&&(0,Y.jsx)(`button`,{type:`button`,"aria-label":`New flow`,title:`New flow`,"data-testid":`flow-tab-new`,className:`${o} flex items-center text-[var(--chrome-fg-400)]`,onClick:a,children:(0,Y.jsx)(M,{size:14,stroke:2})})]}),i&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`flow-player-edit`,className:`flex shrink-0 cursor-pointer items-center gap-1 rounded-md px-2 py-1 text-[12.5px] font-medium text-[var(--chrome-fg-700)] transition-colors hover:bg-[var(--chrome-hover)]`,onClick:i,children:[(0,Y.jsx)(j,{size:13,stroke:1.75}),`Edit`]})]})}var $=10,Ae=28,je=.28;function Me(e){let{viewport:t}=e,{store:n}=r(),a=i(e=>e.shapes),o=i(e=>e.flowEdit),s=i(e=>e.flowPlay),c=i(e=>e.flowPreview),l=s??o??c,u=(0,J.useMemo)(()=>{let e=l?a.find(e=>e.id===l.frameId):void 0;return e?.type===`figure`?e:null},[a,l]),d=(0,J.useMemo)(()=>u?F(a,u):[],[a,u]),f=u?.flows?.find(e=>e.id===l?.flowId),p=(0,J.useMemo)(()=>f?H(f,d):null,[f,d]);return(0,J.useEffect)(()=>{if(!l||u&&f)return;let e=n.getState();e.setFlowPlay(null),e.setFlowEdit(null),e.setFlowPreview(null)},[l,u,f,n]),!l||!u||!p?null:s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ne,{frame:u,viewport:t}),(0,Y.jsx)(Ee,{frame:u,flow:p,targets:d,step:s.step,viewport:t})]}):o?(0,Y.jsx)(le,{frame:u,flow:p,targets:d,viewport:t}):(0,Y.jsx)(Pe,{flow:p,targets:d,viewport:t})}function Ne(e){let{frame:t,viewport:n}=e,r=c(t),i=l({x:r.x-$,y:r.y-Ae},n),a=l({x:r.x+r.width+$,y:r.y+r.height+$},n);return(0,Y.jsx)(`div`,{"data-testid":`flow-spotlight`,className:`pointer-events-none absolute rounded-lg`,style:{left:i.x,top:i.y,width:Math.max(0,a.x-i.x),height:Math.max(0,a.y-i.y),boxShadow:`0 0 0 9999px var(--canvas-scrim)`}})}function Pe(e){let{flow:t,targets:n,viewport:r}=e,i=(0,J.useMemo)(()=>new Map(n.map(e=>[e.id,e])),[n]);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`style`,{"data-testid":`flow-preview`,children:(0,J.useMemo)(()=>{let e=new Set(t.steps.flatMap(R));t.steps.forEach((r,i)=>{let a=t.steps[i-1];if(a)for(let t of R(r))for(let r of R(a)){let i=B(n,r,t);if(i?.kind===`arrows`){i.hops.forEach(t=>e.add(t.arrow.id)),i.through.forEach(t=>e.add(t));break}}});let r=n.filter(t=>!e.has(t.id)&&t.type!==`figure`).flatMap(e=>[d(e.id),f(`data-icon-label`,e.id)]);return[`[data-canvas-root] :is([data-shape-id],[data-icon-label]){transition:opacity 180ms ease}`,r.length>0?`${r.join(`,`)}{opacity:${je}!important}`:``].join(``)},[t.steps,n])}),(0,Y.jsx)(G,{numbers:K(t),byId:i,viewport:r,current:null,failing:W(t)})]})}export{Me as FlowLayer};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-2Zwg-L3c.js";import{t as r}from"./tooltip-DgEojto1.js";import{D as i,E as a,T as o,g as s,h as c,i as l,l as u,m as d,o as f,p,r as m,t as h}from"./menu-BPrc8Ara.js";import{i as g}from"./config-a_lz-57R.js";import{a as _,o as v}from"./editor-B0tARd79.js";import{k as y}from"./slides-D9bnXqtf.js";import{t as b}from"./editable-target-BTLnvKNi.js";import{t as x}from"./createReactComponent-9UsI5fmM.js";import{t as S}from"./IconAlertTriangle-CxPhYpe-.js";import{n as C,r as w,t as T}from"./IconTrash-DbN_RxB7.js";import{_ as E,a as D,b as O,f as k,g as ee,h as A,i as j,l as M,m as N,p as te,r as ne,s as re,t as P,u as ie,v as F,y as ae}from"./tree-rq4RTGgw.js";import{n as oe}from"./useValueChanged-p8z-93L4.js";import{t as se}from"./IconChevronLeft-BR0iwdRI.js";import{t as I}from"./IconChevronRight-DBDnxPYT.js";import{i as ce,n as le,r as L,t as ue}from"./use-drag-reorder-C3h4ZMoZ.js";import{n as R,t as z}from"./IconNote-CSELvWzx.js";import{t as B}from"./IconPencil-C5Y-Y4dC.js";import{t as V}from"./IconPlus-BbmieIBT.js";import{n as H,r as U,t as W}from"./MenuSubmenuTrigger-CpN67g09.js";import{t as G}from"./IconSparkles-WDcg8BA9.js";import{t as K}from"./IconX-AlbPkO_g.js";import{t as q}from"./IconPlayerPlayFilled-D4OODBX7.js";import{n as de,r as fe,t as pe}from"./core-CBnmD9hT.js";import{n as J,r as Y}from"./flow-start-ccYJ2KB9.js";import{n as me}from"./surface-Dke4SWpE.js";import{a as he}from"./chrome-C2RCq3SI.js";import"./chrome-layout-B8YmHznO.js";import{t as ge}from"./panel-shell-CG2aq4Ia.js";import{i as _e,n as ve,s as ye}from"./flows-GGbkNqs8.js";var be=x(`outline`,`arrows-exchange`,`ArrowsExchange`,[[`path`,{d:`M7 10h14l-4 -4`,key:`svg-0`}],[`path`,{d:`M17 14h-14l4 4`,key:`svg-1`}]]),xe=x(`outline`,`package`,`Package`,[[`path`,{d:`M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5`,key:`svg-0`}],[`path`,{d:`M12 12l8 -4.5`,key:`svg-1`}],[`path`,{d:`M12 12l0 9`,key:`svg-2`}],[`path`,{d:`M12 12l-8 -4.5`,key:`svg-3`}],[`path`,{d:`M16 5.25l-8 4.5`,key:`svg-4`}]]),X=e(t(),1),Se=`w-full min-w-0 rounded-md bg-transparent px-1.5 py-1 text-[12px] text-[var(--chrome-fg-800)] outline-none ring-1 ring-transparent transition-shadow placeholder:text-[var(--chrome-fg-300)] hover:ring-[var(--chrome-ring)] focus:bg-[var(--chrome-rest)] focus:ring-[var(--chrome-fg-300)]`,Ce=`flex cursor-pointer items-center gap-1.5 rounded-md px-1.5 py-1 text-[12px] text-[var(--chrome-fg-500)] transition-colors hover:bg-[var(--chrome-hover)] hover:text-[var(--chrome-fg-900)] disabled:pointer-events-none disabled:text-[var(--chrome-fg-300)]`,we=`flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-[var(--chrome-fg-400)] transition-colors hover:bg-[var(--chrome-hover)] hover:text-[var(--chrome-fg-800)] disabled:pointer-events-none disabled:opacity-40`,Te=`flex h-9 w-full cursor-pointer items-center justify-center gap-2 rounded-lg bg-[var(--chrome-accent)] text-[13px] text-white transition-colors hover:bg-[var(--chrome-accent-hover)] disabled:pointer-events-none disabled:bg-[var(--chrome-hover)] disabled:text-[var(--chrome-fg-400)]`,Ee=`flex cursor-pointer items-center justify-center gap-1.5 rounded-lg px-3 text-[13px] text-[var(--chrome-fg-700)] ring-1 ring-[var(--chrome-ring)] transition-colors hover:bg-[var(--chrome-rest)] hover:text-[var(--chrome-fg-900)] disabled:pointer-events-none disabled:opacity-50`,Z=n(),De=[{kind:`call`,label:`Call`,hint:`Waits for an answer`,pickable:!0},{kind:`async`,label:`Fire and forget`,hint:`Doesn't wait for an answer`,pickable:!0},{kind:`reply`,label:`Reply`,hint:`Answers an earlier step`,pickable:!1}],Oe=e=>De.find(t=>t.kind===e)?.label;function ke(e){let{step:t,index:n,count:r,current:a,selected:o,picking:s,names:c,otherFlows:l,loose:u}=e,{actions:d,grip:p,rowRef:m,rowStyle:h}=e,{onPlay:g,onChange:_,onMove:v,onRemove:y,onNewPath:b}=d,[x,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),E=t.kind??`call`,D=t.also??[],k=t.branches??[],ee=new Map(l.map(e=>[e.id,e.name])),A=x||!!t.text,j=w||!!t.payload,M=D.length>0||E!==`call`||j||t.fails||k.length>0;return(0,Z.jsxs)(`li`,{ref:m,"data-testid":`flow-step-${n}`,"data-current":a||void 0,"data-selected":o||void 0,"aria-current":o?`step`:void 0,className:`group relative flex gap-2.5 rounded-lg py-2.5 pl-5 pr-2 transition-colors ${s?`bg-[color-mix(in_srgb,var(--flow-accent)_10%,transparent)] ring-1 ring-[color-mix(in_srgb,var(--flow-accent)_45%,transparent)]`:o?`bg-[color-mix(in_srgb,var(--flow-accent)_8%,transparent)] ring-1 ring-[color-mix(in_srgb,var(--flow-accent)_30%,transparent)]`:a?`bg-[var(--chrome-active)]`:`hover:bg-[var(--chrome-rest)]`}`,style:h,onPointerDown:e=>{e.target.closest(`[data-step-insert]`)||d.onSelect()},onFocusCapture:e=>{e.target.closest(`[data-step-insert]`)||d.onSelect()},onPointerEnter:()=>d.onHover(!0),onPointerLeave:()=>d.onHover(!1),children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Add a step before step ${n+1}`,title:`Add a step here`,"data-testid":`flow-step-insert-${n}`,"data-step-insert":!0,className:`absolute -top-2.5 left-1/2 z-10 flex h-5 w-5 -translate-x-1/2 cursor-pointer items-center justify-center rounded-full bg-[var(--chrome-popup)] text-[var(--flow-accent)] opacity-0 ring-1 ring-[color-mix(in_srgb,var(--flow-accent)_40%,transparent)] transition-opacity hover:bg-[color-mix(in_srgb,var(--flow-accent)_10%,var(--chrome-popup))] focus-visible:opacity-100 group-hover:opacity-100`,onPointerDown:e=>e.stopPropagation(),onClick:d.onInsertBefore,children:(0,Z.jsx)(V,{size:11,stroke:2.5})}),(0,Z.jsx)(`span`,{"aria-hidden":!0,"data-testid":`flow-step-grip-${n}`,title:`Drag to reorder`,className:`absolute bottom-0 left-0 top-0 flex w-5 cursor-grab touch-none items-center justify-center text-[var(--chrome-fg-300)] opacity-0 transition-opacity active:cursor-grabbing group-hover:opacity-100`,...p,children:(0,Z.jsx)(ce,{size:13,stroke:1.75})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Play from step ${n+1}`,title:`Play from this step`,onClick:g,className:`mt-px flex h-6 min-w-6 shrink-0 cursor-pointer items-center justify-center rounded-full px-1.5 text-[12px] font-semibold tabular-nums text-white transition-shadow hover:ring-4 hover:ring-[color-mix(in_srgb,var(--flow-accent)_20%,transparent)] ${t.fails?`bg-[var(--flow-fail)]`:`bg-[var(--flow-accent)]`}`,children:n+1}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5 pr-6`,children:[(0,Z.jsx)(`input`,{"aria-label":`Step title`,"data-testid":`flow-step-title-${n}`,className:`${Se} -mx-1.5 h-6 px-1.5 text-[13px] font-semibold text-[var(--chrome-fg-900)]`,defaultValue:t.title,onBlur:e=>{e.target.value!==t.title&&_({title:e.target.value})},onKeyDown:ze},`t-${t.title}`),A&&(0,Z.jsx)(`textarea`,{autoFocus:x&&!t.text,"aria-label":`What happens at this step`,"data-testid":`flow-step-text-${n}`,rows:1,className:`w-full min-w-0 rounded-md bg-transparent px-1.5 py-1 text-[12px] text-[var(--chrome-fg-800)] outline-none ring-1 ring-transparent transition-shadow placeholder:text-[var(--chrome-fg-300)] hover:ring-[var(--chrome-ring)] focus:bg-[var(--chrome-rest)] focus:ring-[var(--chrome-fg-300)] -mx-1.5 resize-none px-1.5 text-[12px] leading-relaxed text-[var(--chrome-fg-600)] [field-sizing:content]`,placeholder:`What happens here`,defaultValue:t.text??``,onBlur:e=>{let n=e.target.value.trim();n!==(t.text??``)&&_({text:n}),n||C(!1)},onKeyDown:ze},`d-${t.text??``}`),u&&(0,Z.jsx)(je,{index:n,names:u.names,justAdded:o,onAttach:u.onAttach}),M&&(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1`,"data-testid":`flow-step-chips-${n}`,children:[E!==`call`&&(0,Z.jsx)(Fe,{kind:E,onPick:e=>_({kind:e}),trigger:(0,Z.jsxs)(f,{"data-testid":`flow-step-kind-${n}`,className:`${Q} cursor-pointer hover:bg-[var(--chrome-hover)]`,children:[Oe(E),(0,Z.jsx)(i,{size:11,stroke:2,className:`text-[var(--chrome-fg-400)]`})]})}),j&&(0,Z.jsx)(Pe,{index:n,payload:t.payload,editing:w,onEdit:()=>T(!0),onDone:e=>{T(!1),e!==(t.payload??``)&&_({payload:e||void 0})}}),t.fails&&(0,Z.jsx)(Ne,{testId:`flow-step-fails-${n}`,tone:`fail`,icon:(0,Z.jsx)(S,{size:11,stroke:2}),label:`Fails here`,onRemove:()=>_({fails:void 0})}),D.map(e=>(0,Z.jsx)(Ne,{icon:(0,Z.jsx)(V,{size:11,stroke:2}),label:c.get(e)??`Shape`,title:`Part of this step`,onRemove:()=>_({also:D.filter(t=>t!==e)})},e)),k.map(e=>(0,Z.jsx)(Ne,{testId:`flow-step-path-${n}`,icon:(0,Z.jsx)(O,{size:11,stroke:2}),label:ee.get(e)??`Missing flow`,title:`Another path from here`,onRemove:()=>_({branches:k.filter(t=>t!==e)})},e))]})]}),(0,Z.jsx)(Re,{index:n,count:r,step:t,hasNote:A,hasPayload:j,paths:l.filter(e=>!k.includes(e.id)),onNote:()=>C(!0),onPayload:()=>T(!0),onChange:_,onMove:v,onRemove:y,onNewPath:b,onInsertBefore:d.onInsertBefore,onInsertAfter:d.onInsertAfter,onChangeBox:d.onChangeBox})]})}var Ae=[{transform:`translateX(0)`},{transform:`translateX(-4px)`},{transform:`translateX(4px)`},{transform:`translateX(-3px)`},{transform:`translateX(2px)`},{transform:`translateX(0)`}];function je(e){let{index:t,names:n,justAdded:r,onAttach:i}=e,a=(0,X.useRef)(null),o=(0,X.useRef)(r);return(0,X.useEffect)(()=>{let e=a.current;!o.current||!e||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches||e.animate(Ae,{duration:360,easing:`ease-out`})},[]),(0,Z.jsxs)(`div`,{ref:a,role:`status`,"data-testid":`flow-step-loose-${t}`,title:`The arrow isn't attached to ${n}, so the hand-off can't follow it`,className:`mt-1 flex items-start gap-1.5 rounded-md bg-[color-mix(in_srgb,var(--flow-warn)_12%,transparent)] py-1 pl-1.5 pr-1 text-[11.5px] text-[var(--flow-warn-fg)] ring-1 ring-[color-mix(in_srgb,var(--flow-warn)_30%,transparent)]`,children:[(0,Z.jsx)(S,{size:12,stroke:2,className:`mt-[3px] shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 py-px leading-snug`,children:[`Arrow isn't attached to `,n]}),(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-step-attach-${t}`,className:`flex h-5 shrink-0 cursor-pointer items-center gap-1 rounded px-1.5 font-medium hover:bg-[color-mix(in_srgb,var(--flow-warn)_18%,transparent)]`,onClick:i,children:[(0,Z.jsx)(R,{size:11,stroke:2}),`Attach`]})]})}var Q=`flex h-6 items-center gap-1 rounded-md bg-[var(--chrome-rest)] px-1.5 text-[11.5px] text-[var(--chrome-fg-700)] ring-1 ring-[var(--chrome-ring)]`,$=`flex cursor-default select-none items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-[var(--chrome-fg-700)] outline-none data-[highlighted]:bg-[var(--chrome-hover)]`,Me=`min-w-[200px] p-1 outline-none ${me.popup}`;function Ne(e){let{label:t,icon:n,onRemove:r,testId:i,title:a,tone:o}=e;return(0,Z.jsxs)(`span`,{"data-testid":i,title:a,className:`${Q} pr-0.5 ${o===`fail`?`bg-[color-mix(in_srgb,var(--flow-fail)_10%,transparent)] text-[var(--flow-fail)] ring-[color-mix(in_srgb,var(--flow-fail)_25%,transparent)]`:``}`,children:[(0,Z.jsx)(`span`,{className:`opacity-70`,children:n}),(0,Z.jsx)(`span`,{className:`max-w-[140px] truncate`,children:t}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Remove ${t}`,className:`flex h-4 w-4 cursor-pointer items-center justify-center rounded opacity-60 hover:bg-[var(--chrome-hover)] hover:opacity-100`,onClick:r,children:(0,Z.jsx)(K,{size:10,stroke:2})})]})}function Pe(e){let{index:t,payload:n,editing:r,onEdit:i,onDone:a}=e;return r?(0,Z.jsxs)(`span`,{className:`${Q} pr-1`,children:[(0,Z.jsx)(xe,{size:11,stroke:2,className:`opacity-70`}),(0,Z.jsx)(`input`,{autoFocus:!0,"data-testid":`flow-step-payload-${t}`,"aria-label":`What this step carries`,placeholder:`e.g. order #1042`,className:`w-28 bg-transparent text-[11.5px] outline-none placeholder:text-[var(--chrome-fg-400)]`,defaultValue:n??``,onBlur:e=>a(e.target.value.trim()),onKeyDown:e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&e.currentTarget.blur()}})]}):(0,Z.jsxs)(`span`,{className:`${Q} pr-0.5`,"data-testid":`flow-step-payload-chip-${t}`,children:[(0,Z.jsx)(xe,{size:11,stroke:2,className:`opacity-70`}),(0,Z.jsx)(`button`,{type:`button`,title:`What this step carries`,className:`max-w-[140px] cursor-text truncate`,onClick:i,children:n}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Remove what it carries`,className:`flex h-4 w-4 cursor-pointer items-center justify-center rounded opacity-60 hover:bg-[var(--chrome-hover)] hover:opacity-100`,onClick:()=>a(``),children:(0,Z.jsx)(K,{size:10,stroke:2})})]})}function Fe(e){let{kind:t,onPick:n,trigger:r}=e;return(0,Z.jsxs)(u,{children:[r,(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{side:`bottom`,align:`start`,sideOffset:4,className:`z-50 outline-none`,children:(0,Z.jsx)(m,{"data-overlay":!0,className:`min-w-[220px] p-1`,children:(0,Z.jsx)(Ie,{kind:t,onPick:n})})})})]})}function Ie(e){let{kind:t,onPick:n}=e;return(0,Z.jsx)(Z.Fragment,{children:De.filter(e=>e.pickable).map(e=>(0,Z.jsxs)(s,{"data-testid":`flow-kind-${e.kind}`,className:$,onClick:()=>n(e.kind===`call`?void 0:e.kind),children:[(0,Z.jsx)(`span`,{className:`flex w-4 justify-center text-[var(--chrome-fg-900)]`,children:t===e.kind&&(0,Z.jsx)(oe,{size:14,stroke:2})}),(0,Z.jsxs)(`span`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--chrome-fg-900)]`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--chrome-fg-400)]`,children:e.hint})]})]},e.kind))})}function Le(e){let{label:t,icon:n,testId:r,children:i}=e;return(0,Z.jsxs)(H,{children:[(0,Z.jsxs)(W,{className:`${$} justify-between`,"data-testid":r,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[var(--chrome-fg-400)]`,children:n}),t]}),(0,Z.jsx)(I,{size:14,stroke:1.75,className:`text-[var(--chrome-fg-400)]`})]}),(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{className:`z-50 outline-none`,children:(0,Z.jsx)(c,{"data-overlay":!0,className:Me,children:i})})})]})}function Re(e){let{index:t,count:n,step:r,hasNote:i,hasPayload:o,paths:c}=e,{onNote:g,onPayload:_,onChange:v,onMove:y,onRemove:b,onNewPath:x}=e,{onInsertBefore:E,onInsertAfter:D,onChangeBox:k}=e,ee=r.branches??[];return(0,Z.jsxs)(u,{children:[(0,Z.jsx)(f,{"aria-label":`Step options`,"data-testid":`flow-step-menu-${t}`,className:`${we} absolute right-1.5 top-2 opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100 data-[popup-open]:opacity-100`,children:(0,Z.jsx)(a,{size:14,stroke:1.75})}),(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{side:`bottom`,align:`end`,sideOffset:4,className:`z-50 outline-none`,children:(0,Z.jsxs)(m,{"data-overlay":!0,className:`min-w-[210px] p-1`,children:[(0,Z.jsx)(h,{testId:`flow-step-change-box`,icon:(0,Z.jsx)(be,{size:15,stroke:1.75}),onClick:k,children:`Change box…`}),(0,Z.jsx)(h,{testId:`flow-step-insert-above`,icon:(0,Z.jsx)(le,{size:15,stroke:1.75}),onClick:E,children:`Add a step above`}),(0,Z.jsx)(h,{testId:`flow-step-insert-below`,icon:(0,Z.jsx)(L,{size:15,stroke:1.75}),onClick:D,children:`Add a step below`}),(0,Z.jsx)(l,{}),!i&&(0,Z.jsx)(h,{testId:`flow-step-add-note`,icon:(0,Z.jsx)(z,{size:15,stroke:1.75}),onClick:g,children:`Add a note`}),(0,Z.jsx)(Le,{label:`How it travels`,icon:(0,Z.jsx)(U,{size:15,stroke:1.75}),testId:`flow-step-travels`,children:(0,Z.jsx)(Ie,{kind:r.kind??`call`,onPick:e=>v({kind:e})})}),!o&&(0,Z.jsx)(h,{testId:`flow-step-add-payload`,icon:(0,Z.jsx)(xe,{size:15,stroke:1.75}),onClick:_,children:`Add what it carries`}),(0,Z.jsx)(h,{testId:`flow-step-toggle-fails`,icon:(0,Z.jsx)(S,{size:15,stroke:1.75}),onClick:()=>v({fails:!r.fails||void 0}),children:r.fails?`Doesn't fail here`:`Fails here`}),(0,Z.jsxs)(Le,{label:`Another path from here`,icon:(0,Z.jsx)(O,{size:15,stroke:1.75}),testId:`flow-step-paths`,children:[c.map(e=>(0,Z.jsx)(s,{className:$,onClick:()=>v({branches:[...ee,e.id]}),children:e.name},e.id)),c.length>0&&(0,Z.jsx)(l,{}),(0,Z.jsxs)(s,{className:$,"data-testid":`flow-step-new-path`,onClick:x,children:[(0,Z.jsx)(V,{size:14,stroke:1.75,className:`text-[var(--chrome-fg-400)]`}),`New path`]})]}),(0,Z.jsx)(l,{}),(0,Z.jsx)(h,{testId:`flow-step-up`,icon:(0,Z.jsx)(C,{size:15,stroke:1.75}),disabled:t===0,onClick:()=>y(-1),children:`Move up`}),(0,Z.jsx)(h,{testId:`flow-step-down`,icon:(0,Z.jsx)(w,{size:15,stroke:1.75}),disabled:t===n-1,onClick:()=>y(1),children:`Move down`}),(0,Z.jsx)(h,{testId:`flow-step-remove`,icon:(0,Z.jsx)(T,{size:15,stroke:1.75}),onClick:b,children:`Remove step`})]})})})]})}function ze(e){e.stopPropagation(),(e.key===`Enter`&&!e.shiftKey||e.key===`Escape`)&&e.currentTarget.blur()}function Be(){let e=_(),{store:t}=e,n=v(e=>e.shapes),i=v(e=>e.viewMode),a=(0,X.useMemo)(()=>fe(n),[n]),o=(0,X.useMemo)(()=>y(n).filter(e=>pe(n,[e])?.id===e.id),[n]),s=()=>t.getState().setFlowsOpen(!1),c=(e,n)=>t.getState().setFlowPreview(n?{frameId:e,flowId:n}:null);return(0,X.useEffect)(()=>()=>t.getState().setFlowPreview(null),[t]),(0,Z.jsxs)(ge,{width:300,testId:`flow-list`,ariaLabel:`Flows`,onDismiss:s,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 py-2 pl-4 pr-2`,children:[(0,Z.jsx)(`span`,{className:`flex-1 text-[14px] font-medium text-[var(--chrome-fg-900)]`,children:`Flows`}),!i&&o.length>0&&(0,Z.jsx)(Ue,{frames:o,onPick:t=>Y(e,t.id)}),(0,Z.jsx)(r,{label:`Close`,side:`bottom`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close flows`,"data-testid":`flow-list-close`,onClick:s,className:he,children:(0,Z.jsx)(K,{size:16,stroke:1.75})})})]}),(0,Z.jsx)(`div`,{className:`mx-3 h-px bg-[var(--chrome-divider)]`}),(0,Z.jsx)(`div`,{className:`flex flex-1 flex-col gap-4 overflow-y-auto p-3`,children:a.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[(0,Z.jsx)(`p`,{className:`text-balance text-[13px] font-medium text-[var(--chrome-fg-900)]`,children:`No flows yet`}),(0,Z.jsx)(`p`,{className:`text-balance text-[12px] leading-relaxed text-[var(--chrome-fg-500)]`,children:o.length>0?`A flow walks people through a diagram, one step at a time.`:`Put a diagram in a frame, then add a flow to it.`})]}):a.map(n=>(0,Z.jsxs)(`section`,{className:`flex flex-col gap-0.5`,onPointerLeave:()=>c(n.id,null),children:[(0,Z.jsx)(`h3`,{className:`truncate px-2 pb-1 text-[11px] font-medium text-[var(--chrome-fg-400)]`,children:n.label||`Untitled frame`}),P(n.flows??[]).map(({flow:r,depth:a,origin:o})=>(0,Z.jsx)(Ve,{flow:r,depth:a,forkStep:o?o.index+1:null,viewMode:i,onPreview:e=>c(n.id,e?r.id:null),onPlay:()=>J(e,n.id,r.id),onOpen:()=>t.getState().setFlowEdit({frameId:n.id,flowId:r.id})},r.id))]},n.id))})]})}function Ve(e){let{flow:t,depth:n,forkStep:i,viewMode:a,onPreview:o,onPlay:s,onOpen:c}=e,l=t.steps.length,u=t.steps.some(e=>e.fails),d=`${l} ${l===1?`step`:`steps`}`;return(0,Z.jsxs)(`div`,{"data-testid":`flow-list-row`,className:`group flex items-center gap-2 rounded-lg py-1.5 pr-1.5 transition-colors hover:bg-[var(--chrome-rest)]`,style:{paddingLeft:8+n*18},onPointerEnter:()=>o(!0),children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[var(--chrome-fg-400)]`,children:n>0?(0,Z.jsx)(O,{size:14,stroke:1.75}):(0,Z.jsx)(U,{size:14,stroke:1.75})}),(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-list-open`,title:a?`Play ${t.name}`:`Edit ${t.name}`,className:`flex min-w-0 flex-1 cursor-pointer flex-col text-left`,onFocus:()=>o(!0),onBlur:()=>o(!1),onClick:a?s:c,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate text-[13px] font-medium text-[var(--chrome-fg-900)]`,children:t.name}),u&&(0,Z.jsx)(`span`,{title:`Shows something failing`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--flow-fail)]`})]}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[var(--chrome-fg-400)]`,children:i===null?d:`From step ${i} · ${d}`})]}),l>0&&(0,Z.jsx)(r,{label:`Play`,side:`left`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Play ${t.name}`,"data-testid":`flow-list-play`,className:`flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-full bg-[var(--flow-accent)] text-white opacity-90 transition-opacity hover:opacity-100`,onClick:s,children:(0,Z.jsx)(q,{size:11})})})]})}var He=`flex h-7 cursor-pointer items-center gap-1 rounded-md px-2 text-[12.5px] font-medium text-[var(--flow-accent)] transition-colors hover:bg-[var(--chrome-hover)]`;function Ue(e){let{frames:t,onPick:n}=e,r=t.length===1?t[0]:void 0;return r?(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-list-new`,title:`New flow on ${r.label||`the frame`}`,className:He,onClick:()=>n(r),children:[(0,Z.jsx)(V,{size:14,stroke:2}),`New`]}):(0,Z.jsxs)(u,{children:[(0,Z.jsxs)(f,{"data-testid":`flow-list-new`,className:He,children:[(0,Z.jsx)(V,{size:14,stroke:2}),`New`]}),(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{side:`bottom`,align:`end`,sideOffset:6,className:`z-50 outline-none`,children:(0,Z.jsxs)(m,{"data-overlay":!0,className:`min-w-[240px] p-1`,children:[(0,Z.jsx)(`span`,{className:`block px-2 pb-1 pt-1.5 text-[11px] font-medium text-[var(--chrome-fg-400)]`,children:`On which diagram?`}),t.map(e=>(0,Z.jsx)(s,{"data-testid":`flow-list-new-frame`,className:`flex cursor-default select-none items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-[var(--chrome-fg-700)] outline-none data-[highlighted]:bg-[var(--chrome-hover)]`,onClick:()=>n(e),children:e.label||`Untitled frame`},e.id))]})})})]})}function We(e){let{frameId:t,readOnly:n}=e,r=_();return(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{side:`bottom`,align:`end`,sideOffset:6,className:`z-50 outline-none`,children:(0,Z.jsx)(m,{"data-overlay":!0,"data-testid":`figure-flow-list`,className:`w-[300px] p-1`,finalFocus:()=>r.store.getState().flowEdit===null,children:(0,Z.jsx)(Ge,{frameId:t,readOnly:n})})})})}function Ge(e){let{frameId:t,readOnly:n}=e,r=_(),i=v(e=>{let n=e.shapes.find(e=>e.id===t);return n?.type===`figure`?n:null}),a=v(e=>e.lastFlow[t]),o=e=>r.store.getState().setFlowPreview(e?{frameId:t,flowId:e}:null);return(0,X.useEffect)(()=>()=>r.store.getState().setFlowPreview(null),[r]),i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`p`,{className:`px-2 pb-1 pt-1.5 text-[11px] font-medium text-[var(--chrome-fg-400)]`,children:[`Flows on `,i.label||`this diagram`]}),(0,Z.jsx)(`div`,{onPointerLeave:()=>o(null),children:P(i.flows??[]).map(({flow:e,depth:t,origin:r})=>(0,Z.jsx)(qe,{frame:i,flow:e,depth:t,forkStep:r?r.index+1:null,last:e.id===a,readOnly:n,onPreview:o},e.id))}),!n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(l,{}),(0,Z.jsx)(h,{testId:`figure-flow-new`,icon:(0,Z.jsx)(V,{size:15,stroke:1.75}),onClick:()=>Y(r,t),children:`New flow`})]})]}):null}var Ke=`flex h-7 w-7 shrink-0 cursor-default items-center justify-center rounded-lg text-[var(--chrome-fg-400)] outline-none data-[highlighted]:bg-[var(--chrome-hover)] data-[highlighted]:text-[var(--chrome-fg-800)]`;function qe(e){let{frame:t,flow:n,depth:r,forkStep:i,last:c,readOnly:l,onPreview:u}=e,f=_(),g=n.steps.length,v=n.steps.some(e=>e.fails);return(0,Z.jsxs)(`div`,{"data-testid":`figure-flow-row`,className:`flex items-center gap-0.5`,style:{paddingLeft:r*16},onPointerEnter:()=>u(n.id),children:[(0,Z.jsxs)(s,{"data-testid":`figure-flow-row-play`,disabled:g===0,className:`${me.menuItem} min-w-0 flex-1`,onFocus:()=>u(n.id),onClick:()=>J(f,t.id,n.id),children:[(0,Z.jsx)(`span`,{className:c?`text-[var(--flow-accent)]`:`text-[var(--chrome-fg-400)]`,children:r>0?(0,Z.jsx)(O,{size:15,stroke:1.75}):c?(0,Z.jsx)(q,{size:13}):(0,Z.jsx)(o,{size:15,stroke:1.75})}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`span`,{className:`truncate text-[var(--chrome-fg-900)]`,children:n.name}),i!==null&&(0,Z.jsxs)(`span`,{className:`text-[11px] text-[var(--chrome-fg-400)]`,children:[`From step `,i]})]}),v&&(0,Z.jsx)(`span`,{title:`Shows something failing`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--flow-fail)]`}),(0,Z.jsxs)(`span`,{className:`shrink-0 text-[11px] tabular-nums text-[var(--chrome-fg-400)]`,children:[g,` `,g===1?`step`:`steps`]})]}),!l&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(s,{"aria-label":`Edit ${n.name}`,"data-testid":`figure-flow-row-edit`,className:Ke,onFocus:()=>u(n.id),onClick:()=>F(f,t.id,n.id),children:(0,Z.jsx)(B,{size:14,stroke:1.75})}),(0,Z.jsxs)(H,{children:[(0,Z.jsx)(W,{"aria-label":`More for ${n.name}`,"data-testid":`figure-flow-row-more`,className:Ke,children:(0,Z.jsx)(a,{size:14,stroke:1.75})}),(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{className:`z-50 outline-none`,sideOffset:4,children:(0,Z.jsxs)(m,{"data-overlay":!0,className:`min-w-[160px] p-1`,children:[(0,Z.jsx)(h,{testId:`figure-flow-rename`,icon:(0,Z.jsx)(B,{size:15,stroke:1.75}),onClick:()=>f.store.getState().setFlowEdit({frameId:t.id,flowId:n.id,rename:!0}),children:`Rename`}),(0,Z.jsx)(h,{testId:`figure-flow-delete`,icon:(0,Z.jsx)(T,{size:15,stroke:1.75}),onClick:()=>E(f,t.id,n.id),children:`Delete`})]})})})]})]})]})}var Je=/^Flow \d+$/;function Ye(){let e=v(e=>e.flowEdit);return v(e=>e.rightPanel===`flow`)?e?(0,Z.jsx)(Xe,{frameId:e.frameId,flowId:e.flowId},e.flowId):(0,Z.jsx)(Be,{}):null}function Xe(e){let{frameId:t,flowId:n}=e,{ai:i}=g(),a=_(),{store:o}=a,s=v(e=>e.shapes),c=v(e=>e.flowPlay),l=v(e=>e.flowEdit)??{},u=c!==null,d=c?.flowId===n?c.step:null,f=(0,X.useMemo)(()=>{let e=s.find(e=>e.id===t);return e?.type===`figure`?e:null},[s,t]),p=(0,X.useMemo)(()=>f?de(s,f):[],[s,f]),m=f?.flows?.find(e=>e.id===n),h=m?ye(m,p):null,y=h?.steps.length??0,[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),T=o.getState().patchFlowEdit;(0,X.useEffect)(()=>{l.rename&&(w(!0),o.getState().patchFlowEdit({rename:!1}))},[l.rename,o]);let P=ue({count:y,gap:1,onReorder:(e,r)=>M(a,t,n,e,r),onPress:e=>T({selected:e})}),F=()=>{h&&h.steps.length===0&&E(a,t,n),o.getState().setFlowEdit(null)},oe=()=>{h&&h.steps.length===0&&E(a,t,n),o.getState().setFlowsOpen(!0)},I=()=>{if(h&&h.steps.length>0&&Je.test(h.name)){S(!0);return}F()},ce=(0,X.useRef)(I);ce.current=I;let le=(0,X.useRef)(y);if(le.current=y,(0,X.useEffect)(()=>{let e=e=>{let r=o.getState();if(r.flowPlay||b(e.target)||(e.target instanceof Element?e.target:null)?.closest(`[role=menu], [role=dialog]`))return;let i=r.flowEdit??{},s=le.current,c=N(i,s);if(e.key===`Escape`){if(e.preventDefault(),e.stopPropagation(),i.picking!==null&&i.picking!==void 0){r.patchFlowEdit({picking:null});return}if(k(i,s)){r.patchFlowEdit({slot:null});return}ce.current();return}if(c!==null){if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault(),e.stopPropagation(),ie(a,t,n,c);return}if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){e.preventDefault(),e.stopPropagation();let r=c+(e.key===`ArrowUp`?-1:1);r>=0&&r<s&&M(a,t,n,c,r)}}};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[o,a,t,n]),!f||!h)return null;let L=f.flows??[],R=new Map(p.map(e=>[e.id,_e(p,e)])),z=ve(L,n),B=z?.flow.steps[z.index],V=B?.title??``,H=D(p,h.steps,B),U=A(l,y),W=N(l,y),G=N({selected:l.picking},y),fe=te(l,y),pe=L.filter(e=>e.id!==n).map(e=>({id:e.id,name:e.name}));function me(e){let t=H.get(e);return t?{names:j(t,R),onAttach:()=>ne(a,t)}:null}function be(e){let r=e.trim();r&&r!==h?.name&&ae(a,t,n,e=>({...e,name:r}))}return(0,Z.jsxs)(ge,{width:300,testId:`flow-panel`,ariaLabel:`Flow`,onDismiss:F,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-0.5 py-2 pl-1.5 pr-2`,children:[(0,Z.jsx)(r,{label:`All flows`,side:`bottom`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`All flows`,"data-testid":`flow-panel-back`,onClick:oe,className:he,children:(0,Z.jsx)(se,{size:16,stroke:1.75})})}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:C?(0,Z.jsx)(`input`,{autoFocus:!0,"aria-label":`Flow name`,"data-testid":`flow-name`,className:`${Se} text-[14px] font-medium`,defaultValue:h.name,onFocus:e=>e.target.select(),onBlur:e=>{be(e.target.value),w(!1)},onKeyDown:ze}):(0,Z.jsx)(tt,{current:h,flows:L,onPick:e=>o.getState().setFlowEdit({frameId:t,flowId:e}),onRename:()=>w(!0),onNew:()=>Y(a,t),onDelete:()=>E(a,t,n)})}),(0,Z.jsx)(r,{label:`Close`,side:`bottom`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close the flow panel`,"data-testid":`flow-panel-done`,onClick:F,className:he,children:(0,Z.jsx)(K,{size:16,stroke:1.75})})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 px-4 pb-2.5`,children:[(0,Z.jsxs)(`span`,{className:`truncate text-[11px] text-[var(--chrome-fg-400)]`,children:[f.label||`Untitled frame`,` · `,y,` `,y===1?`step`:`steps`,y>1&&` · drag to reorder`]}),z&&(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-origin`,title:`Open ${z.flow.name}`,className:`-ml-1 flex min-w-0 cursor-pointer items-center gap-1 self-start rounded-md bg-[color-mix(in_srgb,var(--flow-accent)_10%,transparent)] px-1.5 py-1 text-[11.5px] text-[var(--flow-accent)] transition-colors hover:bg-[color-mix(in_srgb,var(--flow-accent)_16%,transparent)]`,onClick:()=>o.getState().setFlowEdit({frameId:t,flowId:z.flow.id}),children:[(0,Z.jsx)(O,{size:12,stroke:2,className:`shrink-0`}),(0,Z.jsxs)(`span`,{className:`truncate`,children:[`From `,z.flow.name,`, step `,z.index+1]})]})]}),(0,Z.jsx)(`div`,{className:`mx-3 h-px bg-[var(--chrome-divider)]`}),(0,Z.jsx)(`div`,{ref:P.listRef,className:`flex flex-1 flex-col gap-1 overflow-y-auto p-3`,children:y===0?(0,Z.jsx)($e,{fork:z?{title:V,step:z.index+1}:null,onAi:i?()=>{E(a,t,n),o.getState().askAi(`Write a flow for the frame "${f.label||`Untitled`}" (${f.id}) showing `)}:null}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`ol`,{className:`flex flex-col gap-px pt-1`,"data-testid":`flow-steps`,children:h.steps.map((e,r)=>(0,Z.jsx)(Ze,{before:U===r&&U<y,hidden:P.dragging,number:r+1,onCancel:()=>T({slot:null}),children:(0,Z.jsx)(ke,{step:e,index:r,count:y,current:d===r,selected:W===r,picking:G===r,names:R,otherFlows:pe,loose:me(r),rowRef:P.setItemRef(r),rowStyle:P.rowStyle(r),grip:P.rowHandlers(r),actions:{onPlay:()=>J(a,t,n,r),onChange:e=>re(a,t,n,r,e),onMove:e=>M(a,t,n,r,r+e),onRemove:()=>ie(a,t,n,r),onNewPath:()=>ee(a,t,n,r),onSelect:()=>{o.getState().flowEdit?.selected!==r&&T({selected:r})},onHover:e=>T({hovered:e?r:null}),onInsertBefore:()=>T({slot:r,picking:null}),onInsertAfter:()=>T({slot:r+1<y?r+1:null,picking:null}),onChangeBox:()=>T({picking:r,selected:r})}})},`${e.target}-${r}`))}),(0,Z.jsx)(Qe,{picking:G,inserting:U<y,next:y+1,joined:fe,onCancelPick:()=>T({picking:null}),onToEnd:()=>T({slot:null})})]})}),(0,Z.jsx)(`div`,{className:`border-t border-[var(--chrome-ring)] p-3`,children:x?(0,Z.jsx)(et,{suggestion:nt(h),onSave:e=>{be(e),F()},onSkip:F}):(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`${Ee} h-9 flex-1`,"data-testid":`flow-play`,disabled:y===0||u,onClick:()=>J(a,t,n),children:[(0,Z.jsx)(q,{size:12}),`Preview`]}),(0,Z.jsx)(`button`,{type:`button`,className:`${Te} flex-1`,"data-testid":`flow-done`,onClick:I,children:`Done`})]})})]})}function Ze(e){let{before:t,hidden:n,number:i,onCancel:a,children:o}=e;return(0,Z.jsxs)(Z.Fragment,{children:[t&&(0,Z.jsxs)(`li`,{"data-testid":`flow-slot`,className:`my-1 flex items-center gap-2.5 rounded-lg border border-dashed border-[color-mix(in_srgb,var(--flow-accent)_55%,transparent)] bg-[color-mix(in_srgb,var(--flow-accent)_6%,transparent)] py-2 pl-5 pr-1.5 text-[12px] text-[var(--flow-accent)] ${n?`invisible`:``}`,children:[(0,Z.jsx)(`span`,{className:`flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full border border-dashed border-[var(--flow-accent)]`,children:(0,Z.jsx)(V,{size:12,stroke:2.5})}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[`Click the box for a new step `,i]}),(0,Z.jsx)(r,{label:`Add at the end instead`,side:`left`,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Add at the end instead`,"data-testid":`flow-slot-cancel`,className:`flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-[color-mix(in_srgb,var(--flow-accent)_12%,transparent)]`,onClick:a,children:(0,Z.jsx)(K,{size:13,stroke:2})})})]}),o]})}function Qe(e){let{picking:t,inserting:n,next:r,joined:i,onCancelPick:a,onToEnd:o}=e,s=`flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full bg-[color-mix(in_srgb,var(--flow-accent)_12%,transparent)] px-1.5 text-[12px] font-semibold tabular-nums text-[var(--flow-accent)]`;return t===null?n?(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-hint`,className:`mt-1 flex cursor-pointer items-center gap-2.5 rounded-lg border border-dashed border-[var(--chrome-divider)] px-2 py-2.5 text-left text-[12px] text-[var(--chrome-fg-500)] transition-colors hover:bg-[var(--chrome-rest)]`,onClick:o,children:[(0,Z.jsx)(`span`,{className:s,children:(0,Z.jsx)(V,{size:12,stroke:2.5})}),`Add at the end instead`]}):(0,Z.jsxs)(`div`,{"data-testid":`flow-hint`,className:`mt-1 flex items-center gap-2.5 rounded-lg border border-dashed border-[var(--chrome-divider)] px-2 py-2.5 text-[12px] text-[var(--chrome-fg-500)]`,children:[(0,Z.jsx)(`span`,{className:s,children:r}),(0,Z.jsxs)(`span`,{children:[`Click the next box or arrow`,i!==null&&(0,Z.jsxs)(`span`,{className:`block text-[11px] text-[var(--chrome-fg-400)]`,children:[`Shift-click to add it to step `,i+1]})]})]}):(0,Z.jsxs)(`div`,{"data-testid":`flow-hint`,className:`mt-1 flex items-center gap-2.5 rounded-lg border border-dashed border-[var(--flow-accent)] px-2 py-2.5 text-[12px] text-[var(--chrome-fg-700)]`,children:[(0,Z.jsx)(`span`,{className:s,children:t+1}),(0,Z.jsxs)(`span`,{className:`flex-1`,children:[`Click the box step `,t+1,` should light`,(0,Z.jsx)(`span`,{className:`block text-[11px] text-[var(--chrome-fg-400)]`,children:`Its title and notes stay`})]}),(0,Z.jsx)(`button`,{type:`button`,className:Ce,onClick:a,children:`Cancel`})]})}function $e(e){let{onAi:t,fork:n}=e;return n?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-3 py-8 text-center`,"data-testid":`flow-empty`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl bg-[var(--chrome-rest)] px-5 py-4`,"aria-hidden":!0,children:[(0,Z.jsxs)(`span`,{className:`flex h-7 items-center gap-1 rounded-full bg-[var(--chrome-popup)] px-2.5 text-[12px] font-medium text-[var(--chrome-fg-700)] ring-1 ring-[var(--chrome-ring)]`,children:[(0,Z.jsx)(O,{size:13,stroke:2,className:`text-[var(--flow-accent)]`}),n.title||`Step ${n.step}`]}),(0,Z.jsx)(`span`,{className:`h-0.5 w-5 rounded-full bg-[color-mix(in_srgb,var(--flow-accent)_35%,transparent)]`}),(0,Z.jsx)(`span`,{className:`flex h-7 w-7 items-center justify-center rounded-full bg-[var(--flow-accent)] text-[12px] font-semibold text-white`,children:`1`})]}),(0,Z.jsxs)(`p`,{className:`text-balance text-[13px] font-medium text-[var(--chrome-fg-900)]`,children:[`What happens after `,n.title||`step ${n.step}`,`?`]}),(0,Z.jsxs)(`p`,{className:`text-balance text-[12px] leading-relaxed text-[var(--chrome-fg-500)]`,children:[`Click where it goes next. Viewers can pick this path at step `,n.step,`.`]})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-3 py-8 text-center`,"data-testid":`flow-empty`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2 rounded-xl bg-[var(--chrome-rest)] px-5 py-4`,"aria-hidden":!0,children:[1,2,3].map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e>1&&(0,Z.jsx)(`span`,{className:`h-0.5 w-5 rounded-full bg-[color-mix(in_srgb,var(--flow-accent)_35%,transparent)]`}),(0,Z.jsx)(`span`,{className:`flex h-7 w-7 items-center justify-center rounded-full text-[12px] font-semibold ${e===1?`bg-[var(--flow-accent)] text-white`:`bg-[var(--chrome-popup)] text-[var(--flow-accent)] ring-1 ring-[color-mix(in_srgb,var(--flow-accent)_30%,transparent)]`}`,children:e})]},e))}),(0,Z.jsx)(`p`,{className:`text-balance text-[13px] font-medium text-[var(--chrome-fg-900)]`,children:`Click the boxes in order`}),(0,Z.jsx)(`p`,{className:`text-balance text-[12px] leading-relaxed text-[var(--chrome-fg-500)]`,children:`Start with whoever kicks things off.`}),t&&(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`flow-ai`,className:`flex cursor-pointer items-center gap-1.5 rounded-md px-1.5 py-1 text-[12px] text-[var(--chrome-fg-500)] transition-colors hover:bg-[var(--chrome-hover)] hover:text-[var(--chrome-fg-900)] disabled:pointer-events-none disabled:text-[var(--chrome-fg-300)]`,onClick:t,children:[(0,Z.jsx)(G,{size:13,stroke:1.75}),`Or write the steps with AI`]})]})}function et(e){let{suggestion:t,onSave:n,onSkip:r}=e,[i,a]=(0,X.useState)(t);return(0,Z.jsxs)(`form`,{className:`flex flex-col gap-2`,"data-testid":`flow-name-prompt`,onSubmit:e=>{e.preventDefault(),n(i)},children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-[12px] font-medium text-[var(--chrome-fg-800)]`,children:`Name this flow`}),(0,Z.jsx)(`input`,{autoFocus:!0,"data-testid":`flow-name-input`,className:`${Se} h-8 ring-[var(--chrome-ring)]`,value:i,onFocus:e=>e.target.select(),onChange:e=>a(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&r()}})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`${Ee} h-9 flex-1`,"data-testid":`flow-name-skip`,onClick:r,children:`Skip`}),(0,Z.jsx)(`button`,{type:`submit`,className:`${Te} flex-1`,"data-testid":`flow-name-save`,disabled:!i.trim(),children:`Save`})]})]})}function tt(e){let{current:t,flows:n,onPick:r,onRename:a,onNew:o,onDelete:c}=e,g=(0,X.useRef)(!1);return(0,Z.jsxs)(u,{onOpenChange:e=>{e&&(g.current=!1)},children:[(0,Z.jsxs)(f,{"data-testid":`flow-switcher`,className:`flex max-w-full cursor-pointer items-center gap-1 rounded-md px-1.5 py-1 text-left transition-colors hover:bg-[var(--chrome-hover)] data-[popup-open]:bg-[var(--chrome-hover)]`,children:[(0,Z.jsx)(`span`,{className:`truncate text-[14px] font-medium text-[var(--chrome-fg-900)]`,children:t.name}),(0,Z.jsx)(i,{size:14,stroke:1.75,className:`shrink-0 text-[var(--chrome-fg-400)]`})]}),(0,Z.jsx)(d,{children:(0,Z.jsx)(p,{side:`bottom`,align:`start`,sideOffset:4,className:`z-50 outline-none`,children:(0,Z.jsxs)(m,{"data-overlay":!0,className:`min-w-[240px] p-1`,finalFocus:()=>!g.current,children:[P(n).map(({flow:e,depth:n})=>(0,Z.jsxs)(s,{"data-testid":`flow-switcher-item`,className:`flex cursor-default select-none items-center gap-2 rounded-lg py-1.5 pr-2 text-[13px] text-[var(--chrome-fg-700)] outline-none data-[highlighted]:bg-[var(--chrome-hover)]`,style:{paddingLeft:8+n*16},onClick:()=>r(e.id),children:[(0,Z.jsx)(`span`,{className:`text-[var(--chrome-fg-400)]`,children:n>0?(0,Z.jsx)(O,{size:14,stroke:1.75}):(0,Z.jsx)(U,{size:14,stroke:1.75})}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[var(--chrome-fg-900)]`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-[11px] tabular-nums text-[var(--chrome-fg-400)]`,children:e.steps.length}),(0,Z.jsx)(`span`,{className:`flex w-4 justify-center text-[var(--chrome-fg-900)]`,children:e.id===t.id&&(0,Z.jsx)(oe,{size:14,stroke:2})})]},e.id)),(0,Z.jsx)(l,{}),(0,Z.jsx)(h,{testId:`flow-name-edit`,icon:(0,Z.jsx)(B,{size:15,stroke:1.75}),onClick:()=>{g.current=!0,a()},children:`Rename`}),(0,Z.jsx)(h,{testId:`flow-new`,icon:(0,Z.jsx)(V,{size:15,stroke:1.75}),onClick:o,children:`New flow on this frame`}),(0,Z.jsx)(h,{testId:`flow-delete`,icon:(0,Z.jsx)(T,{size:15,stroke:1.75}),onClick:c,children:`Delete this flow`})]})})})]})}function nt(e){let t=e.steps[0]?.title.trim(),n=e.steps[e.steps.length-1]?.title.trim();return t?n&&n!==t?`${t} to ${n}`:t:e.name}export{We as FlowMenuPopup,Ye as FlowPanel};