yuhwa 1.0.0 → 1.0.2

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.
@@ -0,0 +1,587 @@
1
+ (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={slate:[`#f8fafc`,`#f1f5f9`,`#e2e8f0`,`#cbd5e1`,`#94a3b8`,`#64748b`,`#475569`,`#334155`,`#1e293b`,`#0f172a`,`#020617`],gray:[`#fafaf9`,`#f5f5f4`,`#e7e5e4`,`#d6d3d1`,`#a8a29e`,`#78716c`,`#57534e`,`#44403c`,`#292524`,`#1c1917`,`#0c0a09`],red:[`#fff1f2`,`#ffe4e6`,`#fecdd3`,`#fda4af`,`#fb7185`,`#f43f5e`,`#e11d48`,`#be123c`,`#9f1239`,`#881337`,`#4c0519`],orange:[`#fff7ed`,`#ffedd5`,`#fed7aa`,`#fdba74`,`#fb923c`,`#f97316`,`#ea580c`,`#c2410c`,`#9a3412`,`#7c2d12`,`#431407`],amber:[`#fffbeb`,`#fef3c7`,`#fde68a`,`#fcd34d`,`#fbbf24`,`#f59e0b`,`#d97706`,`#b45309`,`#92400e`,`#78350f`,`#451a03`],lime:[`#f7fee7`,`#ecfccb`,`#d9f99d`,`#bef264`,`#a3e635`,`#84cc16`,`#65a30d`,`#4d7c0f`,`#3f6212`,`#365314`,`#1a2e05`],green:[`#ecfdf5`,`#d1fae5`,`#a7f3d0`,`#6ee7b7`,`#34d399`,`#10b981`,`#059669`,`#047857`,`#065f46`,`#064e3b`,`#022c22`],teal:[`#f0fdfa`,`#ccfbf1`,`#99f6e4`,`#5eead4`,`#2dd4bf`,`#14b8a6`,`#0d9488`,`#0f766e`,`#115e59`,`#134e4a`,`#042f2e`],cyan:[`#ecfeff`,`#cffafe`,`#a5f3fc`,`#67e8f9`,`#22d3ee`,`#06b6d4`,`#0891b2`,`#0e7490`,`#155e75`,`#164e63`,`#083344`],blue:[`#eff6ff`,`#dbeafe`,`#bfdbfe`,`#93c5fd`,`#60a5fa`,`#3b82f6`,`#2563eb`,`#1d4ed8`,`#1e40af`,`#1e3a8a`,`#172554`],indigo:[`#eef2ff`,`#e0e7ff`,`#c7d2fe`,`#a5b4fc`,`#818cf8`,`#6366f1`,`#4f46e5`,`#4338ca`,`#3730a3`,`#312e81`,`#1e1b4b`],purple:[`#f5f3ff`,`#ede9fe`,`#ddd6fe`,`#c4b5fd`,`#a78bfa`,`#8b5cf6`,`#7c3aed`,`#6d28d9`,`#5b21b6`,`#4c1d95`,`#2e1065`],pink:[`#fdf2f8`,`#fce7f3`,`#fbcfe8`,`#f9a8d4`,`#f472b6`,`#ec4899`,`#db2777`,`#be185d`,`#9d174d`,`#831843`,`#500724`]};e.violet=e.purple,e.rose=e.red,e.emerald=e.green,e.yellow=e.amber,e.grey=e.gray,e.sky=e.cyan;var t=t=>Object.hasOwn(e,t),n=[`slate`,`gray`,`red`,`orange`,`amber`,`lime`,`green`,`teal`,`cyan`,`blue`,`indigo`,`purple`,`pink`],r={50:0,100:1,200:2,300:3,400:4,500:5,600:6,700:7,800:8,900:9,950:10};function i(t,n){return e[t]?.[r[n]]}var a=`Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`,o=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,s=t=>e[t]&&{fill:i(t,50),stroke:i(t,300),text:i(t,900)},c=t=>e[t]&&{fill:i(t,50)+`b3`,stroke:i(t,200),text:i(t,700)},l=t=>e[t]&&{fill:i(t,950),stroke:i(t,600),text:i(t,100)},u=t=>e[t]&&{fill:i(t,950)+`80`,stroke:i(t,800),text:i(t,300)},d={paper:{name:`paper`,dark:!1,background:`#fbfaf7`,font:a,mono:!1,fontSize:14,node:{fill:`#ffffff`,stroke:`#d9d4c7`,text:`#2a2925`,sub:`#7a766c`},group:{fill:`#f3f1ea`,stroke:`#e4e0d4`,text:`#7a766c`,dash:null},edge:{stroke:`#8f8a7e`,text:`#55524a`,labelBg:`#fbfaf7`,ink:`#55524a`},title:`#2a2925`,accent:`#2563eb`,strokeWidth:1.25,edgeWidth:1.5,radius:10,shadow:`rgba(60, 50, 30, 0.10)`,grid:null,tone:s,groupTone:c,edgeTone:e=>i(e,500)}},f=Object.keys(d);function p(e){let t=e;t.edge.ink??=t.edge.text,d[t.name]=t,f.includes(t.name)||f.push(t.name)}var m=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,h=new Map(`aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 greenyellow adff2f honeydew f0fff0 hotpink ff69b4 indianred cd5c5c ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightsteelblue b0c4de lightyellow ffffe0 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370db mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred db7093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f plum dda0dd powderblue b0e0e6 rebeccapurple 663399 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c thistle d8bfd8 tomato ff6347 turquoise 40e0d0 wheat f5deb3 white ffffff whitesmoke f5f5f5 yellowgreen 9acd32`.match(/\S+ \S+/g).map(e=>e.split(` `))),g=e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`),_=(e,t)=>e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e);function v(e){let t=e.trim().toLowerCase(),n=t.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/)?.[1];if(n)return`#`+(n.length<=4?n.slice(0,3).split(``).map(e=>e+e).join(``):n.slice(0,6));let r=t.match(/^(rgba?|hsla?)\(\s*([^)]*)\)$/);if(r){let e=r[2].split(/\s*[,/]\s*|\s+/).filter(Boolean);if(e.length<3||e.slice(0,3).some(e=>!Number.isFinite(parseFloat(e))))return;if(r[1].startsWith(`rgb`))return`#`+e.slice(0,3).map(e=>g(_(e,255))).join(``);let t=(parseFloat(e[0])%360+360)%360/360,n=Math.min(1,_(e[1],1)/(e[1].endsWith(`%`)?1:100)),i=Math.min(1,_(e[2],1)/(e[2].endsWith(`%`)?1:100)),a=i<.5?i*(1+n):i+n-i*n,o=2*i-a,s=e=>(e=(e+1)%1,e<1/6?o+(a-o)*6*e:e<.5?a:e<2/3?o+(a-o)*(2/3-e)*6:o);return`#`+[t+1/3,t,t-1/3].map(e=>g(s(e)*255)).join(``)}let i=h.get(t);return i?`#`+i:void 0}var y=e=>{let t=e.length===4?e.slice(1).split(``).map(e=>e+e).join(``):e.slice(1);return[0,2,4].map(e=>parseInt(t.slice(e,e+2),16))},b=(e,t,n)=>`#`+y(e).map((e,r)=>Math.round(e*n+y(t)[r]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``);function x(e,t,n){let r=v(e);return r?{fill:b(r,m.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,t.dark?n?.14:.22:n?.07:.12),stroke:r,text:t.dark?b(r,`#ffffff`,.45):b(r,`#000000`,.55)}:void 0}var S=new WeakMap,C=new WeakMap,w=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),T=[`solid`,`dashed`,`dotted`],E=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t;function D(e){let t=e===`mono`||/mono|code|courier/i.test(e);return e===`mono`||e===`sans`?{font:t?o:a,mono:t}:{font:`${e}, ${t?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`}`,mono:t}}var ee={base:{info:`the theme to start from (default: paper)`,kind:`word`},dark:{info:`true for a dark theme: palette colours pick dark shades`,kind:`word`,values:[`true`,`false`]},background:{info:`page colour, or none`,kind:`color`,values:[`none`]},font:{info:`font family; a name with "mono" in it switches to monospace`,kind:`word`,values:[`sans`,`mono`]},"font-size":{info:`base text size in px`,kind:`number`},"node-fill":{info:`box fill`,kind:`color`},"node-stroke":{info:`box border`,kind:`color`},"node-text":{info:`box label`,kind:`color`},"node-sub":{info:`second line of a box (sub:)`,kind:`color`},"group-fill":{info:`group background`,kind:`color`,values:[`none`]},"group-stroke":{info:`group border`,kind:`color`},"group-text":{info:`group label`,kind:`color`},"group-border":{info:`group border style: solid, dashed or dotted`,kind:`word`,values:T},"edge-color":{info:`lines`,kind:`color`},"edge-text":{info:`edge labels and panel ink`,kind:`color`},"label-bg":{info:`background behind edge labels`,kind:`color`},"title-color":{info:`title and panel headings`,kind:`color`},accent:{info:`code spans, chips and highlights`,kind:`color`},radius:{info:`corner radius in px`,kind:`number`},"stroke-width":{info:`box border width`,kind:`number`},"edge-width":{info:`line width`,kind:`number`},shadow:{info:`box shadow colour, or none`,kind:`color`,values:[`none`]},grid:{info:`background grid colour, or none`,kind:`color`,values:[`none`]}};function O(e,t,n){let r=n??d[t.base]??d.paper,a=w(t.dark,r.dark),o=(e,n,i)=>k(t[e],r,a?i:n),f=(e,n)=>{let r=parseFloat(t[e]);return Number.isFinite(r)&&r>=0?r:n},p=e=>!w(t[e],!0),m=p(`background`)?`none`:o(`background`,50,950)??r.background,h=o(`edge-text`,700,300)??r.edge.text,g=a!==r.dark,_=t.font?.trim(),v=_?D(_):{font:r.font,mono:r.mono};return{name:e,dark:a,background:m,font:v.font,mono:v.mono,fontSize:f(`font-size`,r.fontSize),node:{fill:o(`node-fill`,50,900)??r.node.fill,stroke:o(`node-stroke`,300,600)??r.node.stroke,text:o(`node-text`,900,100)??r.node.text,sub:o(`node-sub`,500,400)??r.node.sub},group:{fill:p(`group-fill`)?`none`:o(`group-fill`,50,950)??r.group.fill,stroke:o(`group-stroke`,200,800)??r.group.stroke,text:o(`group-text`,700,300)??r.group.text,dash:E(t[`group-border`],r.group.dash)},edge:{stroke:o(`edge-color`,500,400)??r.edge.stroke,text:h,labelBg:o(`label-bg`,50,950)??(r.edge.labelBg===r.background||t.background?m:r.edge.labelBg),labelStroke:r.edge.labelStroke,ink:t[`edge-text`]?h:o(`edge-color`,600,300)??r.edge.ink},title:o(`title-color`,900,100)??r.title,accent:o(`accent`,600,400)??r.accent,strokeWidth:f(`stroke-width`,r.strokeWidth),edgeWidth:f(`edge-width`,r.edgeWidth),radius:f(`radius`,r.radius),shadow:p(`shadow`)?null:o(`shadow`,200,950)??(g?a?`rgba(0, 0, 0, 0.45)`:`rgba(15, 23, 42, 0.10)`:r.shadow),grid:p(`grid`)?null:o(`grid`,200,800)??r.grid,tone:g?a?l:s:r.tone,groupTone:g?a?u:c:r.groupTone,edgeTone:g?e=>i(e,a?400:500):r.edgeTone}}function te(e,t,n=[]){let r=t[e],i=r.base??(d[e]?e:void 0);return O(e,r,i&&t[i]&&i!==e&&!n.includes(i)?te(i,t,[...n,e]):d[i??`paper`]??d.paper)}var ne=e=>[...new Set([...f,...Object.keys(e??{})])];function re(e,t){if(e&&t?.[e]){let n=C.get(t);n||C.set(t,n=new Map);let r=n.get(e);return r||n.set(e,r=ie(te(e,t))),r}return ie(d[e??`paper`]??d.paper)}function ie(e){let t=S.get(e);return t||(t={...e,tone:n=>e.tone(n)??x(n,t,!1),groupTone:n=>e.groupTone(n)??x(n,t,!0),edgeTone:t=>e.edgeTone(t)??(v(t)?t:void 0)},S.set(e,t)),t}var ae=e=>{let n=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!n&&t(n[1])&&(!n[2]||n[2]in r)||!!v(e)},oe=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function k(t,n,a){if(!t)return;let o=t.match(/^([a-z]+)(?:-(\d{2,3}))?$/);if(o&&e[o[1]]){let e=o[2]?Number(o[2]):a;return i(o[1],e in r?e:a)}return se(t)?t:void 0}var se=e=>/^[\w\s#(),.%/+-]*$/.test(e),ce=e=>{let t=e.replace(/[\u0000-\u0020\u007f]/g,``).match(/^([a-z][a-z0-9+.-]*):/i);return!t||[`http`,`https`,`mailto`].includes(t[1].toLowerCase())},le=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,ue=/\*\*(.+?)\*\*|~~(.+?)~~|`([^`]+)`|\[\[(.+?)\]\]|\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+?)\}|\*(.+?)\*/g,de=e=>le.test(e)&&(e.startsWith(`#`)||t(e.replace(/-\d+$/,``)));function A(e){let t=[],n=0,r=e=>{let n=t[t.length-1];e.kind===`text`&&n?.kind===`text`?n.text+=e.text:e.text&&t.push(e)};for(let t of e.matchAll(ue))if(r({kind:`text`,text:e.slice(n,t.index)}),n=t.index+t[0].length,t[1]!==void 0)r({kind:`bold`,text:t[1]});else if(t[2]!==void 0)r({kind:`strike`,text:t[2]});else if(t[3]!==void 0)r({kind:`accent`,text:t[3]});else if(t[4]!==void 0){let e=t[4].match(/^([#\w-]+):\s*(.+)$/);e&&de(e[1])?r({kind:`chip`,text:e[2],color:e[1]}):r({kind:`chip`,text:t[4]})}else t[5]===void 0?r({kind:`muted`,text:t[7]}):de(t[5])?r({kind:`color`,text:t[6],color:t[5]}):r({kind:`text`,text:t[0]});return r({kind:`text`,text:e.slice(n)}),t}var fe=e=>e.map(e=>e.text).join(``);function pe(e){let t=Math.min(...e.filter(e=>e.trim()).map(e=>e.match(/^[ \t]*/)[0].length)),n=Number.isFinite(t)?t:0;for(;e.length&&!e[0].trim();)e.shift();for(;e.length&&!e[e.length-1].trim();)e.pop();return e.map(e=>e.slice(n).replace(/\t/g,` `))}var j=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),M=e=>(Math.round(e*100)/100).toString(),me=(e,t,n,r,i,a=``)=>`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central" font-size="${M(n)}" fill="${r}"${a}>${i}</text>`,N=(e,t,n)=>e&&k(e,t,t.dark?400:600)||n,he=.55,ge=(e,t)=>e.kind===`bold`?700:t;function P(e,t,n,r,i=400){let a=0;for(let o of e){let e=r(o.text,t,ge(o,i),n);o.w=o.kind===`chip`?e+t*he*2:e,a+=o.w}return a}var _e=e=>e.reduce((e,t)=>e+(t.w??0),0);function ve(e,t,n,r){if(e.color)return N(e.color,n,t.text);switch(e.kind){case`muted`:case`strike`:return t.sub;case`accent`:return n.accent;default:return r?t.sub:t.text}}function ye(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=ve(l,i,a,o);if(l.kind===`chip`){let a=r*1.6,o=l.color&&u.startsWith(`#`)&&u.length===7?`${u}1f`:`none`;c.push(`<rect x="${M(t)}" y="${M(n-a/2)}" width="${M(e)}" height="${M(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(me(t+r*he,n,r,l.color?u:i.text,j(l.text),` xml:space="preserve"`))}else{let a=ge(l,s);if(c.push(me(t,n,r,u,j(l.text),` xml:space="preserve"${a===400?``:` font-weight="${a}"`}`)),l.kind===`strike`){let r=l.text.length-l.text.trimStart().length,a=t+e*r/Math.max(1,l.text.length);c.push(`<path d="M${M(a)},${M(n)}H${M(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function be(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${ve(e,t,n,r)}"`];return e.kind===`bold`&&i.push(`font-weight="750"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${j(e.text)}</tspan>`}).join(``)}var F=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function xe(e,t=`border-style`){let n=e[t];return n&&T.includes(n)?n:w(e.dashed,!1)?`dashed`:w(e.dotted,!1)?`dotted`:void 0}function Se(e,t){let n=k(t[`edge-color`],e,e.dark?400:500),r=F(t[`edge-width`],NaN);if(!n&&!(r>0))return e;let i=Object.create(e);return n&&(i.edge={...e.edge,stroke:n,ink:n}),r>0&&(i.edgeWidth=r),i}function Ce(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function we(e,t){switch(e){case`dashed`:return`${M(t*4)} ${M(t*3)}`;case`dotted`:return`${M(t*.1)} ${M(t*2.6)}`;default:return null}}function Te(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=F(n.border??n[`stroke-width`],F(i[`stroke-width`],r.strokeWidth)),s=k(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=k(n.stroke,r,500)??a?.stroke??r.node.stroke,l=k(n.text,r,r.dark?100:800)??a?.text??r.node.text;return{fill:s,stroke:c,text:l,sub:k(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:we(xe(n),o),radius:F(n.radius,F(i.radius,r.radius)),fontSize:F(n[`font-size`],F(i[`font-size`],r.fontSize)),fontWeight:w(n.bold,!1)?650:F(n[`font-weight`],500),italic:w(n.italic,!1),shadow:w(n.shadow,w(i.shadow,r.shadow!==null)),opacity:F(n.opacity,1)}}function Ee(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:k(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:k(n.stroke,t,300)??r?.stroke??t.group.stroke,text:k(n.text,t,700)??r?.text??t.group.text,dash:De(n,t.group.dash)}}function De(e,t){return E(xe(e),t)}function Oe(e,t,n){let r=t.theme;if(!r||!(d[r]||n?.[r])||r===e.name)return Se(e,t);let i=Object.create(re(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,Se(i,t)}function ke(e,t,n){let r=e.color?t.groupTone(e.color):void 0,i=t.name!==n.name,a=e.border?.trim(),o=a===`none`||a===`false`||e[`border-width`]===`0`,s=a&&ae(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:k(c,t,t.dark?950:50)??r?.fill??(i&&t.background!==`none`?t.background:t.group.fill);return{framed:e.frame!==`false`&&e.frame!==`none`,fill:l,stroke:o?`none`:k(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:k(e.text,t,t.dark?200:700)??r?.text??t.title,width:F(e[`border-width`],a&&!s&&!o?F(a,1):1),dash:De(e,null),radius:F(e.radius,Math.min(14,t.radius+4)),shadow:w(e.shadow,!1)}}function Ae(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??k(n.color,r,500):void 0,o=k(n.stroke,r,r.dark?400:500)??a??r.edge.stroke,s=t.line===`thick`||w(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=F(n.width,s),l=xe(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=w(n.flow??n.animate,!1);return{stroke:o,width:c,dash:we(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:k(n[`label-color`],r,700)??(a&&!r.dark?k(n.color,r,700):r.edge.text),labelBg:k(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:F(n.opacity,1)}}var je=[`top`,`right`,`bottom`,`left`],Me=[`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],Ne=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),Pe=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),Fe=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Ie=e=>Math.hypot(e.x,e.y),Le=e=>{let t=Ie(e)||1;return{x:e.x/t,y:e.y/t}},Re=(e,t)=>Ie(Fe(e,t)),I=e=>Math.round(e*100)/100;function ze(e,t,n,r){let i=Ne(e),a=t.x-i.x,o=t.y-i.y,s=Math.abs(a)-(e.w+(n?.w??0))/2,c=Math.abs(o)-(e.h+(n?.h??0))/2;return r===`right`||r===`left`?s+=24:c+=24,s>=c?a>=0?`right`:`left`:o>=0?`bottom`:`top`}function Be(e,t,n){let r=Ne(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function Ve(e,t,n,r,i,a,o){let s=Math.min(e.x,t.x)-80,c=Math.min(e.y,t.y)-80,l={x:s,y:c,w:Math.max(e.x+e.w,t.x+t.w)+80-s,h:Math.max(e.y+e.h,t.y+t.h)+80-c},u=o.filter(n=>n!==e&&n!==t&&Ke(n,l));if(!u.length)return[n,r];let d=i?[n,Be(e,Ne(t),n)]:[n],f=a?[r,Be(t,Ne(e),r)]:[r],p=[n,r],m=1/0;for(let i of d)for(let a of f){let o=Et(e.shape,e,i,0),s=Et(t.shape,t,a,0),c=ot({kind:`cubic`,segs:$e(o,wt[i],s,wt[a],[])}),l=0;for(let e of u)c.some(t=>t.x>e.x+2&&t.x<e.x+e.w-2&&t.y>e.y+2&&t.y<e.y+e.h-2)&&l++;let d=l*1e3+(i===n?0:40)+(a===r?0:40);d<m&&(m=d,p=[i,a])}return p}var He=(e,t)=>e&&(Me.includes(e)||ft.has(e))?e:t;function Ue(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=new Map;for(let t of e.edges){if(t.from===t.to||e.layout.edges[t.key]?.via?.length||n.dummyVia.get(t.key)?.length)continue;let r=i(t.from,t.to);a.has(r)||a.set(r,[]),a.get(r).push(t.key)}let o=n.theme.fontSize*2.1;for(let s of e.edges){let c=t.get(s.from),l=t.get(s.to);if(!c||!l)continue;let u=Ce(e,s),d=Ae(e,s,u,n.theme,n.defaultCurve),f=e.layout.edges[s.key],p=!!f?.via?.length,m=(p?f.via:n.dummyVia.get(s.key)??[]).map(e=>({...e})),h=c!==l&&!m.length?a.get(i(s.from,s.to)):void 0;if(h&&h.length>1){let[t,r]=s.from<s.to?[c,l]:[l,c],i=Le(Fe(Ne(r),Ne(t))),a=n.theme.fontSize*.86,u=h.map(t=>{let r=e.edges.find(e=>e.key===t)?.label,s=r?Math.max(...r.split(`
2
+ `).map(e=>n.measure(e,a,500,n.theme.mono)))+18:0;return Math.max(o,Math.abs(i.y)*s+Math.abs(i.x)*o+6)}),d=u.reduce((e,t)=>e+t,0),f=h.indexOf(s.key),p=u.slice(0,f).reduce((e,t)=>e+t,0)+u[f]/2-d/2,g=Ne(c),_=Ne(l);p&&m.push(Pe({x:(g.x+_.x)/2,y:(g.y+_.y)/2},{x:-i.y,y:i.x},p))}let g=f?.ports?.[0]??u.exit??u[`from-side`],_=f?.ports?.[1]??u.enter??u[`to-side`],v=je.includes(g)?g:null,y=je.includes(_)?_:null,b=v??ze(c,m[0]??Ne(l),m.length?null:l,n.direction),x=y??ze(l,m[m.length-1]??Ne(c),m.length?null:c,n.direction);m.length||c===l||v&&y||([b,x]=Ve(c,l,b,x,!v,!y,n.obstacles)),r.push({e:s,a:c,b:l,via:m,manualVia:p,sides:c===l?[`right`,`top`]:[b,x],t:[0,0],style:d,headKind:s.endHead||u.head?He(u.head,`arrow`):`none`,tailKind:s.startHead||u.tail?He(u.tail,`arrow`):`none`,labelOff:f?.label})}let s=new Map;for(let e of r)if(e.a!==e.b)for(let t of[0,1]){let n=t===0?e.a:e.b,r=t===0?e.via[0]??Ne(e.b):e.via[e.via.length-1]??Ne(e.a),i=`${n.id}\u0000${e.sides[t]}`;s.has(i)||s.set(i,[]),s.get(i).push({it:e,end:t,other:r})}for(let[e,t]of s){let n=e.split(`\0`)[1],i=n===`top`||n===`bottom`;t.sort((e,t)=>(i?e.other.x-t.other.x:e.other.y-t.other.y)||r.indexOf(e.it)-r.indexOf(t.it));let a=t.length;t.forEach((e,t)=>e.it.t[e.end]=a===1?0:(t+1)/(a+1)*2-1)}return r.map(e=>We(e,n))}function We(e,t){let{a:n,b:r,style:i}=e,a,o,s;if(n===r)o={x:n.x+n.w,y:n.y+n.h*.32},s={x:n.x+n.w*.68,y:n.y},a={kind:`cubic`,segs:[[o,Pe(o,{x:52,y:0}),Pe(s,{x:0,y:-52}),s]]};else{o=Et(n.shape,n,e.sides[0],e.t[0]),s=Et(r.shape,r,e.sides[1],e.t[1]);let c=wt[e.sides[0]],l=wt[e.sides[1]];a=i.curve===`orthogonal`?{kind:`poly`,pts:tt(o,c,s,l,e.via,n,r,t.obstacles),radius:10}:i.curve===`straight`?{kind:`poly`,pts:[o,...e.via,s],radius:e.via.length?6:0}:{kind:`cubic`,segs:$e(o,c,s,l,e.via)}}let c=ot(a),l,u=e.e.props.caption;if(e.e.label||u){let n=t.theme.fontSize*.86,r=e.e.label?e.e.label.split(`
3
+ `):[],i=r.length?Math.max(...r.map(e=>t.measure(e,n,500,t.theme.mono)))+(t.theme.edge.labelStroke?18:12):0,a=r.length?r.length*n*1.3+6:0,o=n*.88,s=u?u.split(`
4
+ `):[],d=s.length?Math.max(...s.map(e=>t.measure(e,o,400,t.theme.mono)))+8:0,f=s.length*o*1.3+(s.length?4:0),p=Math.max(i,d)/2,m=a?-a/2:0,h=(a?a/2:0)+f,g=e.e.props.rotate===`true`||e.e.props.rotate===``,_=e=>g?{x:e.x+m,y:e.y-p,w:h-m,h:p*2}:{x:e.x-p,y:e.y+m,w:p*2,h:h-m},v=e.labelOff?Pe(ct(c),e.labelOff):Je(c,_,e,t),y=_(v);l={text:e.e.label??``,caption:u,...y,anchor:v,pill:{w:i,h:a},rotate:g}}let d=[],f=Ye(i.width),p=Ze(a,`end`),m=Ze(a,`start`);return e.headKind!==`none`&&(d.push({at:s,angle:Math.atan2(p.y,p.x),kind:e.headKind}),Qe(a,`end`,Xe(e.headKind,f,i.width))),e.tailKind!==`none`&&(d.push({at:o,angle:Math.atan2(m.y,m.x),kind:e.tailKind}),Qe(a,`start`,Xe(e.tailKind,f,i.width))),{key:e.e.key,decl:e.e,d:ut(a),samples:c,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:l,heads:d,style:i}}var Ge=[.5,.42,.58,.34,.66,.26,.74],Ke=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,qe=(e,t)=>e.x>=t.x&&e.y>=t.y&&e.x+e.w<=t.x+t.w&&e.y+e.h<=t.y+t.h;function Je(e,t,n,r){let i=lt(e,.5),a=1/0;for(let n of Ge){let o=lt(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)Ke(s,e)&&(c+=4);for(let e of r.groups??[])Ke(s,e.header)?c+=3:Ke(s,e.box)&&!qe(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}var Ye=e=>7+e*2;function Xe(e,t,n){let r=ft.get(e);if(r)return typeof r.inset==`function`?r.inset(t,n):r.inset??0;switch(e){case`arrow`:return t*.8;case`open`:return n*.8;case`dot`:return t*.7;case`diamond`:return t*1.6;default:return 0}}function Ze(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(Re(n[e],n[n.length-1])>.5)return Le(Fe(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(Re(n[e],n[0])>.5)return Le(Fe(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return Le(Fe(r,Re(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return Le(Fe(n,Re(r,n)>.5?r:i))}function Qe(e,t,n){if(!(n<=0)){if(e.kind===`poly`){let r=e.pts,[i,a]=t===`end`?[r.length-1,r.length-2]:[0,1],o=Re(r[i],r[a]);if(o<.5)return;r[i]=Pe(r[i],Le(Fe(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=Le(Fe(Re(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=Pe(t[3],r,n),Re(t[2],t[3])<n&&(t[2]=Pe(t[3],r,n))}else{let t=e.segs[0],r=Le(Fe(Re(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=Pe(t[0],r,n)}}}function $e(e,t,n,r,i){if(!i.length){let i=Re(e,n),a=t.x*(n.x-e.x)+t.y*(n.y-e.y)>0,o=Math.max(28,Math.min(a?160:220,i*(a?.42:.6)));return[[e,Pe(e,t,o),Pe(n,r,o),n]]}let a=[e,...i,n],o=a.map((e,n)=>n===0?t:n===a.length-1?{x:-r.x,y:-r.y}:Le(Fe(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=Re(a[e],a[e+1]),n=e===0?t*.45:t/3,r=e===a.length-2?t*.45:t/3;s.push([a[e],Pe(a[e],o[e],n),Pe(a[e+1],o[e+1],-r),a[e+1]])}return s}var et=18;function tt(e,t,n,r,i,a,o,s){let c=Pe(e,t,et),l=Pe(n,r,et),u=[e,c],d=c,f=t.x===0?`v`:`h`;for(let e of i)Math.abs(e.x-d.x)<.5||Math.abs(e.y-d.y)<.5?u.push(e):f===`h`?(u.push({x:e.x,y:d.y},e),f=`v`):(u.push({x:d.x,y:e.y},e),f=`h`),d=e;let p=[(d.x+l.x)/2,Math.min(a.x,o.x)-24,Math.max(a.x+a.w,o.x+o.w)+24],m=[(d.y+l.y)/2,Math.min(a.y,o.y)-24,Math.max(a.y+a.h,o.y+o.h)+24],h=[[{x:l.x,y:d.y}],[{x:d.x,y:l.y}]];for(let e of p)h.push([{x:e,y:d.y},{x:e,y:l.y}]);for(let e of m)h.push([{x:d.x,y:e},{x:l.x,y:e}]);let g=null,_=1/0;for(let e of h){let t=rt([...u,...e,l,n]),r=at(t,s);r<_&&(_=r,g=t)}return g}function nt(e){let t=[];for(let n of e)(!t.length||Re(t[t.length-1],n)>.5)&&t.push(n);return t}function rt(e){let t=nt(e),n=[];for(let e=0;e<t.length;e++){if(n.length>=1&&e<t.length-1){let r=n[n.length-1],i=t[e+1],a=Le(Fe(t[e],r)),o=Le(Fe(i,t[e]));if(Math.abs(a.x*o.y-a.y*o.x)<1e-6&&a.x*o.x+a.y*o.y>0)continue}n.push(t[e])}return n}function it(e,t,n){let r=n.x+2,i=n.x+n.w-2,a=n.y+2,o=n.y+n.h-2;return Math.abs(e.y-t.y)<.5?e.y<=a||e.y>=o?!1:Math.max(e.x,t.x)>r&&Math.min(e.x,t.x)<i:Math.abs(e.x-t.x)<.5?e.x<=r||e.x>=i?!1:Math.max(e.y,t.y)>a&&Math.min(e.y,t.y)<o:!1}function at(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=Re(e[a-1],e[a]),a>=2){let t=Le(Fe(e[a-1],e[a-2])),n=Le(Fe(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)it(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}function ot(e){if(e.kind===`poly`)return e.pts.map(e=>({...e}));let t=[];for(let[n,r,i,a]of e.segs)for(let e=+!!t.length;e<=16;e++)t.push(st(n,r,i,a,e/16));return t}function st(e,t,n,r,i){let a=1-i;return{x:a*a*a*e.x+3*a*a*i*t.x+3*a*i*i*n.x+i*i*i*r.x,y:a*a*a*e.y+3*a*a*i*t.y+3*a*i*i*n.y+i*i*i*r.y}}function ct(e){return lt(e,.5)}function lt(e,t){let n=0;for(let t=1;t<e.length;t++)n+=Re(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=Re(e[t-1],e[t]);if(r<=n&&n>0){let i=r/n;return{x:e[t-1].x+(e[t].x-e[t-1].x)*i,y:e[t-1].y+(e[t].y-e[t-1].y)*i}}r-=n}return e[0]??{x:0,y:0}}function ut(e){if(e.kind===`cubic`){let t=`M${I(e.segs[0][0].x)},${I(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${I(n.x)},${I(n.y)} ${I(r.x)},${I(r.y)} ${I(i.x)},${I(i.y)}`;return t}let t=nt(e.pts),n=`M${I(t[0].x)},${I(t[0].y)}`;for(let r=1;r<t.length-1;r++){let i=t[r-1],a=t[r],o=t[r+1],s=Math.min(e.radius,Re(i,a)/2,Re(a,o)/2);if(s<.5){n+=`L${I(a.x)},${I(a.y)}`;continue}let c=Pe(a,Le(Fe(i,a)),s),l=Pe(a,Le(Fe(o,a)),s);n+=`L${I(c.x)},${I(c.y)}Q${I(a.x)},${I(a.y)} ${I(l.x)},${I(l.y)}`}let r=t[t.length-1];return n+`L${I(r.x)},${I(r.y)}`}var dt=new Map,ft=new Map,pt=[],mt=[];function ht(e,t,n,r,i,a=Ye(i)){let o=Math.cos(t),s=Math.sin(t),c=(t,n)=>`${M(e.x+t*o-n*s)},${M(e.y+t*s+n*o)}`;switch(n){case`arrow`:return`<path d="M${c(0,0)}L${c(-a,a*.5)}Q${c(-a*.78,0)} ${c(-a,-a*.5)}Z" fill="${r}" stroke="${r}" stroke-width="${M(i*.5)}" stroke-linejoin="round"/>`;case`open`:return`<path d="M${c(-a*.95,a*.55)}L${c(0,0)}L${c(-a*.95,-a*.55)}" fill="none" stroke="${r}" stroke-width="${M(i)}" stroke-linecap="round" stroke-linejoin="round"/>`;case`dot`:{let e=a*.36;return`<circle cx="${c(-e,0).split(`,`)[0]}" cy="${c(-e,0).split(`,`)[1]}" r="${M(e)}" fill="${r}"/>`}case`diamond`:return`<path d="M${c(0,0)}L${c(-a*.8,a*.45)}L${c(-a*1.6,0)}L${c(-a*.8,-a*.45)}Z" fill="${r}"/>`;case`bar`:return`<path d="M${c(-4,a*.6)}L${c(-4,-a*.6)}" stroke="${r}" stroke-width="${M(i*1.2)}" stroke-linecap="round"/>`;default:{let o=ft.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}}}var gt=[`rounded`,`box`,`pill`,`circle`,`ellipse`,`diamond`,`hexagon`,`cylinder`,`parallelogram`,`document`,`note`,`text`],_t={rect:`box`,rectangle:`box`,square:`box`,round:`rounded`,stadium:`pill`,capsule:`pill`,oval:`ellipse`,rhombus:`diamond`,decision:`diamond`,database:`cylinder`,db:`cylinder`,storage:`cylinder`,doc:`document`,io:`parallelogram`,sticky:`note`,label:`text`,plain:`text`,none:`text`};function vt(e){if(!e)return`rounded`;let t=e.toLowerCase();return gt.includes(t)||dt.has(t)?t:_t[t]??`rounded`}function yt(e,t,n){let r=dt.get(e);if(r?.size)return r.size(t,n);let i=t+44,a=n+28;switch(e){case`circle`:{let e=Math.max(Math.hypot(t,n)+16,64);return{w:e,h:e}}case`ellipse`:return{w:Math.max((t+16)*1.42,90),h:Math.max((n+12)*1.42,50)};case`diamond`:return{w:Math.max(t*1.6+40,100),h:Math.max(n*1.8+32,70)};case`hexagon`:return a=Math.max(a,48),{w:i+a*.4,h:a};case`cylinder`:return{w:Math.max(i,96),h:Math.max(a+18,66)};case`parallelogram`:return{w:i+24,h:Math.max(a,48)};case`document`:return{w:Math.max(i,96),h:Math.max(a+10,56)};case`note`:return{w:Math.max(i+8,96),h:Math.max(a,48)};case`pill`:return{w:Math.max(i+8,96),h:Math.max(a,44)};case`text`:return{w:t+12,h:n+8};default:return{w:Math.max(i,96),h:Math.max(a,48)}}}function bt(e){return e===`cylinder`?5:e===`document`?-4:0}var L=e=>(Math.round(e*100)/100).toString();function xt(e,t,n){let r=dt.get(e);if(r)return r.path(t,n);let{x:i,y:a,w:o,h:s}=t,c=Math.min(n,o/2,s/2);switch(e){case`box`:return Ct(i,a,o,s,Math.min(c,3));case`pill`:return Ct(i,a,o,s,s/2);case`circle`:case`ellipse`:{let e=o/2,t=s/2;return`M${L(i+e-e)},${L(a+t)}a${L(e)},${L(t)} 0 1,0 ${L(e*2)},0a${L(e)},${L(t)} 0 1,0 ${L(-e*2)},0Z`}case`diamond`:return`M${L(i+o/2)},${L(a)}L${L(i+o)},${L(a+s/2)}L${L(i+o/2)},${L(a+s)}L${L(i)},${L(a+s/2)}Z`;case`hexagon`:{let e=Math.min(s*.3,o/4);return`M${L(i+e)},${L(a)}L${L(i+o-e)},${L(a)}L${L(i+o)},${L(a+s/2)}L${L(i+o-e)},${L(a+s)}L${L(i+e)},${L(a+s)}L${L(i)},${L(a+s/2)}Z`}case`parallelogram`:{let e=Math.min(16,o/5);return`M${L(i+e)},${L(a)}L${L(i+o)},${L(a)}L${L(i+o-e)},${L(a+s)}L${L(i)},${L(a+s)}Z`}case`cylinder`:{let e=Math.min(9,s/6),t=o/2;return`M${L(i)},${L(a+e)}a${L(t)},${L(e)} 0 0,1 ${L(o)},0L${L(i+o)},${L(a+s-e)}a${L(t)},${L(e)} 0 0,1 ${L(-o)},0Z`}case`document`:{let e=Math.min(8,s/6);return`M${L(i+c)},${L(a)}L${L(i+o-c)},${L(a)}Q${L(i+o)},${L(a)} ${L(i+o)},${L(a+c)}L${L(i+o)},${L(a+s-e)}C${L(i+o*.75)},${L(a+s-e*3)} ${L(i+o*.25)},${L(a+s+e)} ${L(i)},${L(a+s-e)}L${L(i)},${L(a+c)}Q${L(i)},${L(a)} ${L(i+c)},${L(a)}Z`}case`note`:{let e=Math.min(14,o/5,s/3);return`M${L(i)},${L(a)}L${L(i+o-e)},${L(a)}L${L(i+o)},${L(a+e)}L${L(i+o)},${L(a+s)}L${L(i)},${L(a+s)}Z`}default:return Ct(i,a,o,s,c)}}function St(e,t){let n=dt.get(e);if(n)return n.detail?.(t)??null;let{x:r,y:i,w:a,h:o}=t;if(e===`cylinder`){let e=Math.min(9,o/6);return`M${L(r)},${L(i+e)}a${L(a/2)},${L(e)} 0 0,0 ${L(a)},0`}if(e===`note`){let e=Math.min(14,a/5,o/3);return`M${L(r+a-e)},${L(i)}L${L(r+a-e)},${L(i+e)}L${L(r+a)},${L(i+e)}`}return null}function Ct(e,t,n,r,i){return i<=0?`M${L(e)},${L(t)}h${L(n)}v${L(r)}h${L(-n)}Z`:`M${L(e+i)},${L(t)}H${L(e+n-i)}A${L(i)},${L(i)} 0 0 1 ${L(e+n)},${L(t+i)}V${L(t+r-i)}A${L(i)},${L(i)} 0 0 1 ${L(e+n-i)},${L(t+r)}H${L(e+i)}A${L(i)},${L(i)} 0 0 1 ${L(e)},${L(t+r-i)}V${L(t+i)}A${L(i)},${L(i)} 0 0 1 ${L(e+i)},${L(t)}Z`}var wt={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function Tt(e){return e===`circle`||e===`ellipse`||e===`diamond`?.45:e===`hexagon`||e===`pill`?.55:.75}function Et(e,t,n,r){let i=t.x+t.w/2,a=t.y+t.h/2,o=t.w/2,s=t.h/2,c=Math.max(-1,Math.min(1,r))*Tt(e),l=n===`top`||n===`bottom`,u=n===`bottom`||n===`right`?1:-1,d=c*(l?o:s),f,p=c;switch(e){case`circle`:case`ellipse`:f=(l?s:o)*Math.sqrt(Math.max(0,1-p*p));break;case`diamond`:f=(l?s:o)*(1-Math.abs(p));break;case`hexagon`:f=l?s:o-Math.min(t.h*.3,t.w/4)*Math.abs(p);break;case`pill`:if(l)f=s;else{let e=s;f=o-e+Math.sqrt(Math.max(0,e*e-d*d))}break;case`cylinder`:if(l){let e=Math.min(9,t.h/6);f=s-e+e*Math.sqrt(Math.max(0,1-p*p))}else f=o;break;default:f=l?s:o}return l?{x:i+d,y:a+u*f}:{x:i+u*f,y:a+d}}var Dt=[`smooth`,`orthogonal`,`straight`],Ot=[`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],kt=[`top`,`right`,`bottom`,`left`,`auto`],At=`shape.color.fill.stroke.text.sub.sub-color.icon.border.stroke-width.border-style.dashed.dotted.radius.bold.italic.font-size.font-weight.shadow.opacity.width.height.link.tooltip.meta.caps.mono.max-width`.split(`.`),jt=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`],Mt=[`color`,`fill`,`stroke`,`text`,`border-style`,`dashed`,`dotted`,`meta`,`caps`],Nt={shape:[...gt,...Object.keys(_t)],"border-style":T,style:T,curve:Dt,head:Ot,tail:Ot,exit:kt,"from-side":kt,enter:kt,"to-side":kt},Pt=[`color`],Ft=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`],It=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`];function Lt(e,t){let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]}function Rt(e,t){let n=``,r=1/0;for(let i of t){let t=Lt(e.toLowerCase(),i);t<r&&([n,r]=[i,t])}return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function zt(e,t,r,i,a,o){for(let[s,c]of Object.entries(e)){let e=o?.[s]??i;if(!t.includes(s)){r===`node`&&jt.includes(s)?a(e,`"${s}" is an edge prop, but here it is on a node. On an edge line, edge props go after a colon: a -> b: [${s}]`):a(e,`Unknown ${r} prop "${s}"${Rt(s,t)||` (${r} props: ${t.join(`, `)})`}`);continue}let l=Nt[s],u=s===`frame`?c.trim().split(/\s+/)[0].toLowerCase():c.toLowerCase();if(Pt.includes(s)&&!ae(c))a(e,`Unknown ${s} "${c}"${Rt(c,n)||`: use a palette name (${n.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`}`);else if(l&&!l.includes(u)){let t=s===`shape`?gt:l;a(e,`Unknown ${s} "${c}"${Rt(c,l)||` (use one of: ${t.join(`, `)})`}`)}else Ft.includes(s)&&![`true`,`false`].includes(c)?a(e,`${s} expects true or false, got "${c}"`):It.includes(s)&&!Number.isFinite(parseFloat(c))?a(e,`${s} expects a number, got "${c}"`):s===`link`&&!ce(c)&&a(e,`link "${c}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function Bt(e){let t=(t,n)=>e.diagnostics.push({line:t+1,message:n,severity:`warning`});for(let n of e.nodes.values())n.ref&&zt(n.props,At,`node`,n.ref.line,t,n.ref.propLines);let r=new Set;for(let n of e.edges){if(!n.ref)continue;let e=n.ref.line;r.has(e)||(r.add(e),zt(n.props,jt,`edge`,e,t,n.ref.propLines))}for(let n of e.groups.values())n.ref&&zt(n.props,Mt,`group`,n.ref.line,t,n.ref.propLines);let i=ne(e.themes);for(let r of e.panels){if(!r.ref)continue;let e=r.lines?.[0]??r.ref.line,a=r.props;a.theme&&!i.includes(a.theme)&&t(e,`Unknown theme "${a.theme}"${Rt(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let r of[`background`,`fill`,`stroke`,`text`,`edge-color`])a[r]&&![`none`,`transparent`].includes(a[r])&&!ae(a[r])&&t(e,`Unknown ${r} "${a[r]}"${Rt(a[r],n)||`: use a palette name, #hex, rgb(), hsl() or a CSS colour name`}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!ae(o)&&!Number.isFinite(parseFloat(o))&&t(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!T.includes(a[`border-style`])&&t(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${T.join(`, `)})`)}let a=[...new Set([...At,...jt,...Mt])];for(let[n,r]of Object.entries(e.classes)){let i=e.classLines?.[n];i!==void 0&&zt(r,a,`class .${n}`,i,t)}e.diagnostics.sort((e,t)=>e.line-t.line)}var Vt=Object.keys(ee),Ht=new Set([`title`,`subtitle`,`theme`,`accent`,`direction`,`curve`,`gap`,`rank-gap`,`font`,`font-size`,`background`,`padding`,`shadow`,`radius`,`stroke-width`,`shape`,`grid`,`panels`,`panel-gap`,`wrap`,`edge-color`,`edge-width`]),Ut={pie:`chart ID [type: pie]`,donut:`chart ID [type: donut]`,bar:`chart ID`,line:`chart ID [type: line]`,xychart:`chart ID`,sequenceDiagram:`sequence ID`,gitGraph:`git ID`,quadrantChart:`quadrant ID`,mindMap:`mindmap ID`,roadmap:`gantt ID`,board:`kanban ID`},Wt=new Map,Gt=new Map,Kt=[],qt={direction:[`right`,`down`,`left`,`up`],curve:[`smooth`,`orthogonal`,`straight`],panels:[`row`,`column`,`grid`,`wrap`]},Jt={lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`},Yt=new Set([...n,`violet`]),Xt=new Set([`smooth`,`orthogonal`,`straight`]),Zt=e=>gt.includes(e)||e in _t||dt.has(e),Qt=e=>/\.yuhwa$/i.test(e);function $t(e,t){if(/^[a-z][a-z0-9+.-]*:/i.test(t))return t;let n=t.startsWith(`/`)||!e?``:e.replace(/[^/]*$/,``),r=(n+t).startsWith(`/`),i=[];for(let e of(n+t).split(`/`))if(e&&e!==`.`){if(e===`..`&&i.length&&i[i.length-1]!==`..`)i.pop();else if(e===`..`&&r)continue;else i.push(e)}return(r?`/`:``)+i.join(`/`)}var en=new Set([`top`,`right`,`bottom`,`left`,`auto`]),tn=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,nn=/^(<)?(--|-|\.\.|==|=)(>)?/,rn=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,an=/^-?\d+(?:\.\d+)?/;function on(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
+ `:t===`t`?` `:t)}function sn(e){let t=[],n=0,r=e.length;for(;n<r;){let i=e[n];if(/\s/.test(i)){n++;continue}if(i===`/`&&e[n+1]===`/`&&(n===0||/\s/.test(e[n-1])))return{tokens:t,codeEnd:n};let a=e.slice(n);if(i===`"`||i===`'`){let a=n+1;for(;a<r&&e[a]!==i;)a+=e[a]===`\\`?2:1;t.push({kind:`string`,value:on(e.slice(n+1,a)),start:n,end:Math.min(a+1,r)}),n=a+1;continue}if(i===`[`){let i=n+1,a=null;for(;i<r;){let t=e[i];if(a)t===`\\`?i++:t===a&&(a=null);else if(t===`"`||t===`'`)a=t;else if(t===`]`)break;i++}t.push({kind:`props`,value:e.slice(n+1,i),start:n,end:Math.min(i+1,r)}),n=i+1;continue}let o;if(i===`$`&&(o=a.match(/^\$[A-Za-z_]\w*/))){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(rn)){t.push({kind:`class`,value:o[0].slice(1),start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(tn)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(an)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(nn)){t.push({kind:`arrow`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(`{},:`.includes(i)){t.push({kind:`punct`,value:i,start:n,end:n+1}),n++;continue}let s=a.match(/^\S+/);t.push({kind:`word`,value:s[0],start:n,end:n+s[0].length}),n+=s[0].length}return{tokens:t,codeEnd:r}}function cn(e){let t=[];for(let n of e)if(n.kind===`punct`){if(n.value===`:`)break;(n.value===`{`||n.value===`}`)&&t.push(n.value)}return t}function ln(e,t,n,r){let i=e.value.trim();return/\s/.test(i)&&!/[:,;]/.test(i)?(r(n,`[${i}] looks like a Mermaid label. Write: ${t} "${i}" (props are separated by commas)`),{}):R(e.value)}var un=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function R(e=``){let t={},n=[],r=``,i=null,a=0;for(let t=0;t<e.length;t++){let o=e[t];i?(r+=o,o===`\\`?r+=e[++t]??``:o===i&&(i=null)):o===`"`||o===`'`?(i=o,r+=o):o===`(`?(a++,r+=o):o===`)`?(a=Math.max(0,a-1),r+=o):(o===`,`||o===`;`)&&!a?(n.push(r),r=``):r+=o}n.push(r);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`);if(r<0){let e=n.toLowerCase();Yt.has(e)?t.color=e:Zt(e)?t.shape=e:Xt.has(e)?t.curve=e:ae(n)?t.color=n:t[e]=`true`;continue}let i=un(n.slice(0,r)),a=n.slice(r+1).trim();/^(["']).*\1$/s.test(a)&&(a=on(a.slice(1,-1))),t[i]=a}return t}var dn=/\s*(?<!\[)\[([^[\]]*)\]\s*$/;function fn(e,t){let n=e.match(dn),r=n?R(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index),r]:[e,{}]}function pn(e,t,n){let r=un(t),[i,a]=fn(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=gn(a);return s?`${o} [${s}]`:o}var mn=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&ae(e.color)};function hn(e,t,n,r,i){let a=un(n),[o,s]=fn(e,i),c=Object.keys(s).length>0&&t.test(o),l=(c?o.trimEnd():e).replace(t,(e,t,n,i)=>{let{[a]:o,...s}=R(n),l=gn(c||r===null?s:{[a]:r,...s});return`${t}${l?` [${l}]`:``}${i}`});if(!c)return l;r===null?delete s[a]:s[a]=r;let u=gn(s);return u?`${l} [${u}]`:l}function gn(e){return Object.entries(e).map(([e,t])=>t===`true`&&!Yt.has(e)&&!Zt(e)&&!Xt.has(e)&&!ae(e)?e:e===`color`&&ae(t)&&!Zt(t)&&!Xt.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${/[,;[\]]|^\s|\s$|^$/.test(t)||t.includes(`
6
+ `)?JSON.stringify(t):t}`).join(`, `)}function _n(e){let t=e.match(nn),n=!!t[1],r=!!t[3],i=t[2],a;return a=i.startsWith(`=`)?`thick`:i===`..`?`dotted`:i===`--`&&(n||r)?`dashed`:`solid`,{start:n,end:r,line:a}}var vn=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,yn=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*?)\s*$/,bn=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,xn=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,Sn=new WeakMap;function Cn(e){let t=[],n=``,r=null,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(r)o===`\\`?n+=o+(e[++a]??``):(n+=o,o===r&&(r=null));else{if(o===`"`||o===`'`)r=o;else if(`[({`.includes(o))i++;else if(`])}`.includes(o))i--;else if(o===`,`&&!i){t.push(n.trim()),n=``;continue}n+=o}}return(n.trim()||t.length)&&t.push(n.trim()),t}var wn=e=>/^(["']).*\1$/s.test(e.trim())?on(e.trim().slice(1,-1)):e.trim();function Tn(e,t={}){let r={settings:{},nodes:new Map,edges:[],groups:new Map,classes:{},layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},i=e.split(`
7
+ `),a=t.seen??=new Set;t.file&&a.add(t.file);let o=new Set,s=!1,c=[],l=new Map,u=(e,t,n=`warning`)=>r.diagnostics.push({line:e+1,message:t,severity:n}),d,f=(e,t,r,i)=>{if(!(t in ee))return u(i,`Unknown theme key "${t}"${Rt(t,Vt)||` (keys: ${Vt.join(`, `)})`}`);ee[t].kind!==`color`||[`none`,`transparent`].includes(r)||r.includes(`$`)||ae(r)||u(i,`Unknown color "${r}" for ${t}${Rt(r,n)}`),e[t]=r},p=new Map,m=(e,t,n)=>{p.has(e)&&u(n,`Theme "${e}" is defined twice`),(r.themes??={})[e]=t,p.set(e,n)},h=()=>{for(let e=c.length-1;e>=0;e--)if(c[e].kind===`group`)return c[e].id},g=e=>{let t=r.nodes.get(e);return t||(t={id:e,label:e,props:{},classes:[],implicit:!0,group:h()},r.nodes.set(e,t)),t},_=new Map,v=(e,t,n,r)=>{let i=t.value;e.labelRef={line:n,at:t.start,range:[t.start,t.end],generated:C||void 0};let a=_.get(e.id);a!==void 0&&e.label!==i&&u(n,`"${e.id}" already has the label "${e.label}" (line ${a+1}); this renames it to "${i}"`+(r?`. For an edge label write: ... -> ${e.id}: ${i}`:``)),e.label=i,_.set(e.id,n)},y=new Map,b=(e,n,i)=>{if(!t.resolve)return u(n,`Cannot import "${e}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let o=$t(t.file,e);if(!Qt(o))return u(n,`Cannot import "${e}": imports must be .yuhwa files`,`error`);let s=[...t.chain??(t.file?[t.file]:[])];if(s.includes(o))return u(n,`Import cycle: ${[...s,o].join(` -> `)}`,`error`);let c=i?`${o}{${i.map(e=>e.join(` as `)).join(`,`)}}`:o;if(a.has(c))return;let d;try{d=t.resolve(o)}catch{d=void 0}if(d===void 0)return u(n,`Cannot import "${e}": file not found (${o})`,`error`);let f=new Set(a),p=Tn(d,{resolve:t.resolve,file:o,chain:[...s,o],seen:f});for(let t of p.diagnostics)u(n,`${e}:${t.line}: ${t.message}`,t.severity);let m=Dn(p,i,t=>u(n,`${e}: ${t}`,`error`));if(m===p)for(let e of f)a.add(e);a.add(c),On(r,m,l),(r.imports??=[]).push(o,...p.imports??[])},x=r.vars={},S=r.defs={};Sn.set(S,S);let C=!1,w=0,T=null,E=e=>e.match(/^\s*/)[0].length,D=(e,t,n,r=!1)=>{let i=e.match(yn);return i?e.slice(0,e.length-i[2].length)+D(i[2],t,n,r):e.replace(vn,(e,i,a)=>{let o=i??a;if(!o)return`$`;let s=n?.[o]??x[o];return s===void 0?(r||u(t,`Unknown variable "$${o}"${Rt(o,[...Object.keys(n??{}),...Object.keys(x)])}`),e):s})},O=(e,t,n)=>{if(w>=16)return void u(n,`${e.name}(): calls nest too deep`,`error`);let r=Cn(t),i={},a=0;for(let t of r){let o=t.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(o&&e.params.some(e=>e.name===o[1]))i[o[1]]=wn(o[2]);else if(a<e.params.length)i[e.params[a++].name]=wn(t);else return void u(n,`${e.name}() takes ${e.params.length} argument(s), got ${r.length}`,`error`)}for(let t of e.params)if(!(t.name in i)){if(t.default===void 0)return void u(n,`${e.name}(): missing argument "${t.name}" (${e.params.map(e=>e.name).join(`, `)})`,`error`);i[t.name]=t.default}let o=c.length,s=C;C=!0,w++;let l=e.body.map(e=>D(e,n,i)),d=Sn.get(e)??S;for(let e of l)te(e,n,!0,d);w--,C=s,c.length>o&&(u(n,`${e.name}(): a block inside the component is not closed`,`error`),c.length=o)},te=(e,t,n=!1,r=S)=>{if(/^\s*#(\s|$)/.test(e))return void u(t,`Comments start with "//", not "#"`,`error`);let i=c[c.length-1];if(i?.kind===`def`){for(let t of cn(sn(e).tokens))i.depth+=t===`{`?1:-1;if(i.depth>0)return void i.lines.push(e);c.pop(),e.trim()!==`}`&&u(t,`Expected "}" alone on the line that closes ${i.id}()`,`error`);let n=i.params,a=Object.fromEntries(n.map(e=>[e.name,`\${${e.name}}`])),o={name:i.id,params:n,body:pe(i.lines).map(e=>D(e,t,a,!0))};Sn.set(o,r),S[o.name]&&u(i.start,`Component "${o.name}" is defined twice`),S[o.name]=o;return}let a=i?.kind===`body`||i?.kind===`panel`;if(!a&&i?.kind!==`layout`){let i=e.match(yn);if(i){x[i[1]]=wn((n?i[2]:D(i[2],t)).replace(/\s+\/\/.*$/,``));return}let a=e.match(bn);if(a){c.length&&u(t,`def must be at the top level`,`error`);let e=Cn(a[2]).map(e=>{let n=e.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return n||u(t,`Bad parameter "${e}": def name(a, b = "default") {`,`error`),{name:n?.[1]??e,default:n?.[2]===void 0?void 0:wn(n[2])}});c.push({kind:`def`,id:a[1],start:t,lines:[],depth:1,params:e});return}let o=e.replace(/\s+\/\/.*$/,``).match(xn);if(o){let i=r[o[1]]??S[o[1]];if(i)return void O(i,n?o[2]:D(o[2],t),t);if(!sn(e).tokens.some(e=>e.kind===`arrow`))return void u(t,`Unknown component "${o[1]}"${Rt(o[1],Object.keys(S))}`,`error`)}}let o=n||i?.kind===`layout`||!a&&/^\s*(import|export)\b/.test(e)?e:D(e,t,void 0,a),s=C;C||=o!==e,ge(o,t),C=s},re=(e,t,n)=>{if(t.trim()===`}`){c.pop();let t=r.nodes.get(e.id);t.body=pe(e.lines),t.bodyLines=[e.start,n]}else e.lines.push(t)},ie=(e,t,n)=>{if(t.trim()===`}`){c.pop();let t=e.panel,r=e.lines.findIndex(e=>e.trim());t.body=pe(e.lines),t.lines=[e.start,n],t.data=Wt.get(t.kind).parse(t.body,t.props,(t,n)=>u(t<0?e.start:e.start+1+Math.max(0,r)+t,n))}else e.lines.push(t.slice(0,sn(t).codeEnd).trimEnd())},oe=(e,t,n)=>{let r=t.slice(0,sn(t).codeEnd).trim();if(!r)return;if(r===`}`){c.pop(),m(e.id,e.props,e.start);return}let i=r.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);if(!i)return void u(n,`Expected "key: value" in theme ${e.id} (keys: ${Vt.join(`, `)})`,`error`);f(e.props,i[1].toLowerCase(),wn(i[2].trim()),n)},k=(e,t)=>{let n=e.slice(0,sn(e).codeEnd).trim();n&&(n.startsWith(`}`)?(c.pop(),r.layoutBlock[1]=t):(y.set(n.split(/\s+/)[0],t),jn(n,t,r,u)))},se=e=>{c.length?c.pop():u(e,`Unmatched "}"`,`error`),T=null},ce=(e,t,n)=>{if(c.length)u(t,`import must be at the top level`,`error`);else if(!e[1])u(t,`import needs a path: import "./shared.yuhwa"`,`error`);else if(!n)e.length>2&&u(t,`Unexpected "${e[2].value}" after import path`,`error`),b(e[1].value,t);else{let n=En(e,t,u);n&&b(n.path,t,n.names)}},le=(e,t,n)=>{c.length&&u(n,`export must be at the top level`,`error`);let i=e[1].kind===`ident`&&e[2]?.value===`:`&&Ht.has(e[1].value.toLowerCase());if(i||e[1].value===`theme`&&e[2]?.kind===`ident`){let a=e[1].value.toLowerCase();return i&&!r.sharedSettings?.includes(a)&&(r.sharedSettings??=[]).push(a),te(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)}s=!0;let a=e.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`);if(e[1].value===`def`&&e[2])o.add(e[2].value);else if(e[1].value.startsWith(`$`)&&(e[2]?.value===`:`||e[2]?.value===`=`))o.add(e[1].value);else for(let t of e.slice(1))(t.kind===`ident`||t.kind===`class`)&&o.add(t.kind===`class`?`.${t.value}`:t.value);if(!a||e.slice(1).some(e=>e.kind===`ident`&&Wt.has(e.value)))return te(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)},ue=(e,t)=>{c.length&&u(t,`theme must be at the top level`,`error`);let n={},r=2;if(e[r]?.kind===`props`){for(let[i,a]of Object.entries(R(e[r].value)))f(n,i,a,t);r++}if(e[r]?.value===`{`){if(r++,e[r]?.value===`}`)r++;else if(r===e.length)return void c.push({kind:`theme`,id:e[1].value,start:t,props:n})}r<e.length&&u(t,`Unexpected "${e[r].value}" in theme ${e[1].value}`,`error`),m(e[1].value,n,t)},de=(e,t)=>{u(t,`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...Wt.keys()].join(`, `)})`+(Ut[e[0].value]&&Wt.has(Ut[e[0].value].split(` `)[0])?`: write "${Ut[e[0].value].replace(`ID`,e[1].value)} {"`:``))},A=(e,t)=>{let n=e[0].value,i=1,a=e[i]?.kind===`ident`?e[i++].value:`${n}${r.panels.length+1}`,o=C?void 0:e[i]?.kind===`string`?{line:t,at:e[i].start,range:[e[i].start,e[i].end]}:{line:t,at:e[i-1].end},s=e[i]?.kind===`string`?e[i++].value:void 0,l={line:t,insertAt:e[i-1].end},d={};e[i]?.kind===`props`&&(d=R(e[i].value),l.props=[e[i].start,e[i].end],i++),d.vertical!==void 0&&d.direction===void 0&&d.vertical!==`false`&&(d.direction=`down`),delete d.vertical,i!==e.length-1&&u(t,`Unexpected "${e[i].value}" in ${n} header`,`error`),c.length&&u(t,`${n} must be at the top level`,`error`);let f={kind:n,id:a,label:s,props:d,body:[],data:void 0,ref:C?void 0:l,labelRef:o};r.panels.push(f),c.push({kind:`panel`,id:a,start:t,lines:[],panel:f})},fe=(e,t)=>{c.length&&u(t,`layout block must be at top level`,`error`),r.layoutBlock=[t,t],e[2]?.value!==`}`&&c.push({kind:`layout`})},j=(e,t,n)=>{let i=2,a=e[1].value;e[1].kind===`string`&&(a=e[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,i=1);let o=r.groups.get(a)??{id:a,label:a,props:{},parent:h()};if(e[i]?.kind===`string`){let t=e[i++];o.label=t.value,o.labelRef={line:n,at:t.start,range:[t.start,t.end],id:i===2?a:void 0}}else o.labelRef??={line:n,at:e[1].end};for(C&&(o.labelRef.generated=!0);e[i]?.kind===`class`;)(o.classes??=[]).push(e[i++].value);let s={line:n,insertAt:e[i-1].end,generated:C||void 0};if(e[i]?.kind===`props`&&(Object.assign(o.props,R(e[i].value)),s.props=[e[i].start,e[i].end],i++),o.ref=s,T={indent:E(t),targets:[o]},r.groups.set(a,o),e[i]?.value!==`{`){u(n,`Expected "{" after group ${a}`,`error`);return}i++;let l=e.findIndex((e,t)=>t>=i&&e.value===`}`);if(l>=0){for(let t=i;t<l;t++)if(e[t].kind===`ident`){let n=g(e[t].value);n.group=a}}else c.push({kind:`group`,id:a})},M=(e,t,n)=>{let i=e[e.length-1],a={};for(let t of e.slice(1))t.kind===`class`&&(r.classes[t.value]?Object.assign(a,r.classes[t.value]):u(n,`Unknown class ".${t.value}"${Rt(t.value,Object.keys(r.classes))}`));r.classes[e[0].value]={...r.classes[e[0].value],...a,...i.kind===`props`?R(i.value):{}},(r.classLines??={})[e[0].value]=n,T={indent:E(t),targets:[{props:r.classes[e[0].value]}]}},me=(e,t,n,i,a)=>{let o=un(e[0].value),s=t.slice(e[1].end,i).trim();/^(["']).*\1$/.test(s)&&(s=on(s.slice(1,-1)));let l=T&&E(t)>T.indent?T.targets:null,f=a?.kind===`group`?r.groups.get(a.id):void 0,p=l??(f?[f]:null);if(p){for(let e of p)e.props[o]=s||`true`,e.ref&&!C&&((e.ref.propLines??={})[o]=n);return}if(c.length&&u(n,`Setting "${o}" should be at the top level`),!Ht.has(o)){let t=e[0].value,r=s.startsWith(`{`)?`${t} [${s.slice(1,-1).trim()}]`:`${t} "${s}"`;u(n,`Unknown setting "${o}"${Rt(o,[...Ht])||`. For a node write ${r}`}`);return}o===`direction`&&(s=Jt[s.toLowerCase()]??s),o===`theme`&&(d=n);let m=o===`theme`?void 0:qt[o];m&&s&&!s.includes(`$`)&&!m.includes(s)&&u(n,`Unknown ${o} "${s}"${Rt(s,m)||` (use one of: ${m.join(`, `)})`}`),r.settings[o]=s},N=(e,t,n,i)=>{let a=r.edges.length;if(kn(e,n,t.slice(0,i),r,g,l,u,v),T={indent:E(t),targets:r.edges.slice(a)},C){for(let e of r.edges.slice(a))e.ref&&(e.ref.generated=!0),e.labelRef&&(e.labelRef.generated=!0);for(let t of e)if(t.kind===`ident`){let e=r.nodes.get(t.value);e?.ref?.line===n&&(e.ref.generated=!0),e?.labelRef?.line===n&&(e.labelRef.generated=!0)}}},he=(e,t,n)=>{let r=0,i=!0;for(;r<e.length;){let a=e[r];if(a.kind===`punct`&&a.value===`,`){r++,i=!0;continue}if(!i&&a.kind===`ident`){let t=[e[r-1].value];for(;e[r]?.kind===`ident`;)t.push(e[r++].value);let i=t.join(` `),a=t[0].toLowerCase();u(n,a===`subgraph`||a===`end`?`"${t[0]}" is Mermaid syntax: write group id "Label" { ... }`:`"${i}" looks like a label: write ${t.join(`_`).toLowerCase()} "${i}" (or separate nodes with commas)`,`error`);break}if(a.kind===`punct`&&a.value===`{`&&r===e.length-1&&r>0&&e[r-1].kind!==`punct`){let t=e.slice(0,r).reverse().find(e=>e.kind===`ident`);c.push({kind:`body`,id:t.value,start:n,lines:[]});break}if(a.kind!==`ident`){u(n,`Unexpected "${a.value}"`,`error`);break}i=!1;let o=g(a.value);o.implicit=!1;let s=h();for(s&&o.group&&o.group!==s&&u(n,`"${a.value}" is already in group "${o.group}": a node lives in one group, so it moves to "${s}"`),s&&(o.group=s),r++,e[r]?.kind===`string`?v(o,e[r++],n,!1):o.labelRef??={line:n,at:a.end,generated:C||void 0};e[r]?.kind===`class`;){let t=e[r++].value;o.classes.includes(t)||o.classes.push(t)}let l={line:n,insertAt:e[r-1].end,generated:C||void 0};e[r]?.kind===`props`&&(Object.assign(o.props,ln(e[r],o.id,n,u)),l.props=[e[r].start,e[r].end],r++),o.ref=l,T={indent:E(t),targets:[o]}}},ge=(e,t)=>{let n=c[c.length-1];if(n?.kind===`body`)return re(n,e,t);if(n?.kind===`panel`)return ie(n,e,t);if(n?.kind===`theme`)return oe(n,e,t);if(n?.kind===`layout`)return k(e,t);let{tokens:i,codeEnd:a}=sn(e);if(!i.length)return;let o=/^\s*%%/.test(e)?`Comments start with # or //`:/(--|==|-\.|->|=>)\|[^|]*\|/.test(e)?`Edge labels go after a colon: a -> b: label`:void 0;if(o)return void u(t,o,`error`);if(i[0].kind===`punct`&&i[0].value===`}`)return se(t);let s=i[0].kind===`ident`?i[0].value:void 0,l=i[1]?.value===`{`&&i.some(e=>e.kind===`ident`&&e.value===`from`);if(s===`import`&&(i[1]?.kind===`string`||i.length===1||l))return ce(i,t,l);if(s===`export`&&i.length>1&&i[1].kind!==`arrow`&&i[1].value!==`:`)return le(i,e,t);let d=s===void 0?void 0:Gt.get(s);if(d&&i[1]?.kind!==`arrow`&&i[1]?.value!==`:`&&i[1]?.value!==`,`)return void d.parse(e.slice(i[0].end,a).trim(),r,{line:t,warn:(e,n)=>u(t,e,n)});if(s===`theme`&&i[1]?.kind===`ident`&&(i[2]?.kind===`props`||i[2]?.value===`{`))return ue(i,t);let f=i[i.length-1].value===`{`;if(s!==void 0&&i.length>2&&!Wt.has(s)&&i[1].kind===`ident`&&f&&s!==`group`&&s!==`layout`&&de(i,t),s!==void 0&&Wt.has(s)&&f&&(i[1]?.kind===`ident`||i[1]?.kind===`string`||i[1]?.kind===`props`||i[1]?.value===`{`))return A(i,t);if(s===`layout`&&i[1]?.value===`{`)return fe(i,t);if(s===`group`&&(i[1]?.kind===`ident`||i[1]?.kind===`string`&&i.some(e=>e.value===`{`)))return j(i,e,t);let p=i[i.length-1];if(i[0].kind===`class`&&i.slice(1,-1).every(e=>e.kind===`class`)&&(p.kind===`props`||p.kind===`class`))return M(i,e,t);if(s!==void 0&&i[1]?.kind===`punct`&&i[1].value===`:`)return me(i,e,t,a,n);if(i.some(e=>e.kind===`arrow`))return N(i,e,t,a);he(i,e,t)};for(let e=0;e<i.length;e++)te(i[e],e);for(let e of c)e.kind===`group`?u(i.length-1,`Group "${e.id}" is missing "}"`,`error`):e.kind===`body`?u(e.start,`Body of "${e.id}" is missing a closing "}" line`,`error`):e.kind===`panel`?u(e.start,`${e.panel.kind} "${e.id}" is missing a closing "}" line`,`error`):e.kind===`def`?u(e.start,`def ${e.id}() is missing "}"`,`error`):e.kind===`theme`?u(e.start,`theme ${e.id} is missing "}"`,`error`):u(i.length-1,`layout block is missing "}"`,`error`);let P=ne(r.themes);for(let[e,t]of p){let n=r.themes[e].base;n&&n!==e&&!P.includes(n)&&u(t,`Unknown base theme "${n}"${Rt(n,P)}`)}let _e=r.settings.theme;d!==void 0&&_e&&!_e.includes(`$`)&&(P.includes(_e)||u(d,`Unknown theme "${_e}"${Rt(_e,P)||` (use one of: ${P.join(`, `)})`}`));for(let e of r.nodes.values())for(let t of e.classes)r.classes[t]||u(e.ref?.line??0,`Unknown class ".${t}"`);let ve=new Set;for(let e of[...r.edges,...r.groups.values()])for(let t of e.classes??[]){let n=e.ref?.line??0;r.classes[t]||ve.has(`${n}.${t}`)||(ve.add(`${n}.${t}`),u(n,`Unknown class ".${t}"`))}if(s){let e=new Set(r.panels.map(e=>e.id));r.exports=[...o].filter(t=>t.startsWith(`.`)?t.slice(1)in r.classes:t.startsWith(`$`)?t.slice(1)in x:r.nodes.has(t)||r.groups.has(t)||e.has(t)||t in S||t in(r.themes??{}));for(let e of o)!r.exports.includes(e)&&!Wt.has(e)&&e!==`group`&&e!==`def`&&u(0,`export: "${e}" is not declared in this file`)}for(let e of r.panels){let t=r.layout.nodes[e.id];t&&(t.x!==void 0&&t.y!==void 0&&(An(r,e.id).at={x:t.x,y:t.y}),delete r.layout.nodes[e.id])}for(let[e,t]of r.groups)r.nodes.has(e)&&u(r.edges.find(t=>t.ref&&(t.from===e||t.to===e))?.ref?.line??t.ref?.line??0,`"${e}" is both a node and a group. Edges connect nodes, not groups: use a node inside "${e}", or rename one of them`);Bt(r);for(let e of Kt)e(r);for(let e of Object.keys(r.layout.nodes)){let t=y.get(e);t!==void 0&&!r.nodes.has(e)&&!r.groups.has(e)&&u(t,`layout: there is no node "${e}" (renamed or deleted?); remove this line${Rt(e,[...r.nodes.keys()])}`)}return r}function En(e,t,n){let r=e.findIndex(e=>e.value===`}`),i=e=>(n(t,`${e}: import { a, b as c, .style } from "./file.yuhwa"`,`error`),null);if(r<0)return i(`import list is missing "}"`);let a=[],o=2;for(;o<r;){let t=e[o];if(t.value===`,`){o++;continue}if(t.kind!==`ident`&&t.kind!==`class`)return i(`Unexpected "${t.value}" in import list`);let n=t.kind===`class`?`.${t.value}`:t.value,r=n;if(o++,e[o]?.kind===`ident`&&e[o].value===`as`){let t=e[o+1];if(!t||t.kind!==`ident`&&t.kind!==`class`||t.kind===`class`!==n.startsWith(`.`)||t.value.startsWith(`$`)!==n.startsWith(`$`))return i(`"as" needs a new ${n.startsWith(`.`)?`class`:n.startsWith(`$`)?`variable`:`name`} after "${n}"`);r=t.kind===`class`?`.${t.value}`:t.value,o+=2}a.push([n,r])}return e[r+1]?.value!==`from`||e[r+2]?.kind!==`string`?i(`Expected from "path" after the import list`):e.length>r+3?i(`Unexpected "${e[r+3].value}" after import path`):a.length?{path:e[r+2].value,names:a}:i(`Empty import list`)}function Dn(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),a=new Map,o=new Set,s=new Set(e.panels.map(e=>e.id));if(t)for(let[c,l]of t){let t=c.replace(/^\./,``);if(e.sharedSettings?.includes(c)&&!e.nodes.has(c)&&!e.groups.has(c)){l===c?o.add(c):n(`a setting keeps its name: import { ${c} }`);continue}let u=c.startsWith(`.`)?t in e.classes:c.startsWith(`$`)?c.slice(1)in(e.vars??{}):e.nodes.has(t)||e.groups.has(t)||s.has(t)||t in(e.defs??{});!u&&c in(e.themes??{})||(u?i(c)?(o.add(c),l!==c&&a.set(c,l)):n(`"${c}" is not exported (exports: ${r.join(`, `)||`none`})`):n(`no "${c}" to import${r?.length?` (exports: ${r.join(`, `)})`:``}`))}else for(let e of r)o.add(e);let c=t=>{for(let n=t;n;n=e.groups.get(n)?.parent)if(o.has(n))return!0;return!1},l={settings:{},nodes:new Map,edges:[],groups:new Map,classes:{},layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},u=e=>a.get(e)?.replace(/^\./,``)??e,d=e=>a.get(`.${e}`)?.slice(1)??e,f=new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(l.groups.set(u(t.id),{...t,id:u(t.id),parent:t.parent&&l.groups.has(u(t.parent))?u(t.parent):void 0,classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e)));let p=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(p(t.id)){let e=t.group&&l.groups.has(u(t.group))?u(t.group):void 0;l.nodes.set(u(t.id),{...t,id:u(t.id),group:e,classes:t.classes.map(d)}),t.classes.forEach(e=>f.add(e))}for(let t of e.edges)if(p(t.from)&&p(t.to)){let e=u(t.from)+`->`+u(t.to)+(t.key.match(/#\d+$/)?.[0]??``);l.edges.push({...t,key:e,from:u(t.from),to:u(t.to),classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e))}for(let t of e.panels)o.has(t.id)&&l.panels.push({...t,id:u(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(o.has(t))for(let e of n.body)for(let t of sn(e).tokens)t.kind===`class`&&f.add(t.value);l.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||o.has(e));for(let t of l.sharedSettings)l.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(o.has(`.${t}`)||f.has(t))&&(l.classes[d(t)]=n);l.vars={};for(let[t,n]of Object.entries(e.vars??{}))o.has(`$${t}`)&&(l.vars[(a.get(`$${t}`)??`$${t}`).slice(1)]=n);l.defs={};for(let[t,n]of Object.entries(e.defs??{}))o.has(t)&&(l.defs[a.get(t)??t]=n);return l.themes=e.themes,l}function On(e,t,n){for(let n of t.sharedSettings??[])!(n in e.settings)&&n in t.settings&&(e.settings[n]=t.settings[n]);for(let[n,r]of Object.entries(t.classes))e.classes[n]={...r,...e.classes[n]};for(let n of t.groups.values())e.groups.has(n.id)||e.groups.set(n.id,{...n,props:{...n.props},ref:void 0,labelRef:void 0});for(let n of t.nodes.values()){let t=e.nodes.get(n.id);if(!t)e.nodes.set(n.id,{...n,props:{...n.props},classes:[...n.classes],ref:void 0,labelRef:void 0,bodyLines:void 0});else{t.implicit&&!n.implicit&&(t.label=n.label,t.implicit=!1),t.props={...n.props,...t.props};for(let e of n.classes)t.classes.includes(e)||t.classes.push(e);t.group??=n.group,!t.body&&n.body&&(t.body=n.body)}}for(let r of t.edges){let t=`${r.from}->${r.to}`,i=(n.get(t)??0)+1;n.set(t,i),e.edges.push({...r,key:i===1?t:`${t}#${i}`,ref:void 0,labelRef:void 0})}for(let n of t.panels)e.panels.push({...n,lines:void 0,ref:void 0,labelRef:void 0});for(let[n,r]of Object.entries(t.data??{}))n in(e.data??={})||(e.data[n]=r);t.layout.ranks?.length&&(e.layout.ranks??=[]).push(...t.layout.ranks);for(let[n,r]of Object.entries(t.vars??{}))(e.vars??={})[n]??=r;for(let[n,r]of Object.entries(t.defs??{}))(e.defs??={})[n]??=r;for(let[n,r]of Object.entries(t.themes??{}))(e.themes??={})[n]??=r}function kn(e,t,n,r,i,a,o,s){let c=0,l=!1,u=(n=!1)=>{let a=[],u=!0;for(;c<e.length;){if(e[c].kind===`punct`&&e[c].value===`,`){c++,u=!0;continue}if(e[c].kind!==`ident`)break;if(!u){let n=a.pop(),r=[n];for(;e[c]?.kind===`ident`;)r.push(e[c++].value);let i=r.join(` `);o(t,`"${i}" looks like a label: write ${r.join(`_`).toLowerCase()} "${i}" (or separate nodes with commas)`,`error`),a.push(n);continue}u=!1;let d=e[c++].value;a.push(d);let f=c,p=!r.nodes.has(d),m=i(d);if(e[c]?.kind===`string`){let r=e[c++],i=r.value;n&&p&&c===e.length&&!l&&/^[a-z][a-z ]*$/.test(i)&&o(t,`"${i}" becomes the label of node "${d}". For an edge label write: ... -> ${d}: ${i}`),s(m,r,t,!0),l=!0}for(;e[c]?.kind===`class`;){let t=e[c++].value;m.classes.includes(t)||m.classes.push(t)}let h=!m.ref||m.implicit;e[c]?.kind===`props`?(Object.assign(m.props,ln(e[c],d,t,o)),h&&(m.ref={line:t,props:[e[c].start,e[c].end],insertAt:e[c].start}),c++):c>f&&h&&(m.ref={line:t,insertAt:e[c-1].end}),c>f&&(m.implicit=!1),c>f&&h&&!m.labelRef&&(m.labelRef={line:t,at:e[f-1].end})}return a},d=u();if(!d.length){o(t,`Edge needs a source node`,`error`);return}let f=[];for(;c<e.length&&e[c].kind===`arrow`;){let n=e[c++].value,r=u(!0);if(!r.length){o(t,`Edge "${n}" needs a target node`,`error`);return}f.push({from:d,to:r,arrow:n}),d=r}let p,m=[],h={},g={line:t,insertAt:e[c-1].end,prefix:`:`},_={line:t,at:e[c-1].end,colon:!1};if(e[c]?.kind===`punct`&&e[c].value===`:`){g.insertAt=_.at=e[c].end,_.colon=void 0,g.prefix=void 0,c++;let t=c;for(;c<e.length&&e[c].kind!==`class`&&e[c].kind!==`props`;)c++;for(c>t&&(p=c-t===1&&e[t].kind===`string`?e[t].value:n.slice(e[t].start,e[c-1].end).trim(),g.insertAt=e[c-1].end,_.range=[e[t].start,e[c-1].end]);e[c]?.kind===`class`;)m.push(e[c].value),g.insertAt=e[c++].end;e[c]?.kind===`props`&&(h=R(e[c].value),g.props=[e[c].start,e[c].end],c++)}if(c<e.length){let n=e[c].kind===`string`?` (edge labels go after a colon: a -> b: "label")`:``;o(t,`Unexpected "${e[c].value}" in edge${n}`,`error`)}for(let e of f){let t=_n(e.arrow);for(let n of e.from)for(let i of e.to){let e=n,o=i,s=t.start,c=t.end;s&&!c&&([e,o]=[o,e],[s,c]=[!1,!0]);let l=`${e}->${o}`,u=(a.get(l)??0)+1;a.set(l,u);let d={key:u===1?l:`${l}#${u}`,from:e,to:o,label:p,startHead:s,endHead:c,line:t.line,props:{...h},classes:[...m],ref:g,labelRef:_};r.edges.push(d)}}}var An=(e,t)=>(e.layout.panels??={})[t]??={};function jn(e,t,n,r){let i=e.replace(/\s*->\s*/g,`->`).split(/\s+/),a=i[0],o=(e,t)=>{let n=[];for(let r=0;r<t;r++){let t=Number(i[e+r]);if(!Number.isFinite(t))return null;n.push(t)}return n},s=1;if(a===`rank`&&i[1]!==`at`&&i[1]!==`size`){let e=i.slice(1).filter(Boolean);if(e.length<2)return r(t,`rank needs two or more node ids: rank a b c`);(n.layout.ranks??=[]).push(e);return}if(a.includes(`->`)){let e=a.match(/^(.+?)->(.+?)(?:#(\d+))?$/);if(!e)return r(t,`Bad edge key "${a}"`);let c=`${e[1]}->${e[2]}${e[3]&&e[3]!==`1`?`#`+e[3]:``}`,l=n.layout.edges[c]??={};for(;s<i.length;){let e=i[s++];if(e===`via`)for(l.via=[];s+1<i.length&&Number.isFinite(Number(i[s]))&&Number.isFinite(Number(i[s+1]));)l.via.push({x:Number(i[s]),y:Number(i[s+1])}),s+=2;else if(e===`label`){let e=o(s,2);if(!e)return r(t,`label expects two numbers: dx dy`);l.label={x:e[0],y:e[1]},s+=2}else if(e===`ports`){let e=i[s],n=i[s+1];if(!en.has(e)||!en.has(n))return r(t,`ports expects two sides: top|right|bottom|left|auto`);l.ports=[e,n],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}return}let c=a.indexOf(`:`);if(c>0){let s=a.slice(0,c),l=a.slice(c+1),u=i[1]===`offset`?2:1,d=i.length-u,f=l&&(d===1||d===2)?o(u,d):null;if(!f)return r(t,`Bad panel part "${e.trim()}" (expected panel:part d, or panel:part dx dy)`);(An(n,s).parts??={})[l]={x:f[0],y:f[1]??0};return}if(n.panels.some(e=>e.id===a)){let e=i[1]===`at`&&i.length===4?o(2,2):null;if(!e)return r(t,`panel "${a}" takes only "at x y" in layout (its content sets the size)`);An(n,a).at={x:e[0],y:e[1]};return}let l=n.layout.nodes[a]??={};for(;s<i.length;){let e=i[s++];if(e===`at`){let e=o(s,2);if(!e)return r(t,`at expects two numbers: x y`);l.x=e[0],l.y=e[1],s+=2}else if(e===`size`){let e=o(s,2);if(!e)return r(t,`size expects two numbers: width height`);l.w=e[0],l.h=e[1],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}}function Mn(e){let t=new WeakMap;return(n,r)=>{let i=t.get(r);if(i?.data===n)return i.g;let a=e(n,r);return t.set(r,{data:n,g:a}),a}}function Nn(e){return(t,n,r)=>{if(n.op!==`set`||n.key!==`color`)return null;let i=e(t,n.id,n.value||null,r);return i&&{body:i,id:n.id}}}var Pn={plugins:[],rows:[],frames:new Map,decorations:[],panels:Wt},Fn=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)};function In(...e){for(let t of e)if(!Pn.plugins.some(e=>e.name===t.name)){Pn.plugins.push(t);for(let e of t.themes??[])p(e);Pn.rows.push(...t.rows??[]);for(let e of t.frames??[])Pn.frames.set(e.name,e);for(let e of t.decorations??[])Pn.decorations.push(e),Ht.add(e.setting);for(let e of t.panels??[])Wt.set(e.name,e);for(let e of t.statements??[])Gt.set(e.keyword,e);for(let e of t.shapes??[])dt.set(e.name,e);for(let e of t.markers??[])ft.set(e.name,e);Fn(Nt.shape??=[],t.shapes?.map(e=>e.name)),Fn(Nt.head??=[],t.markers?.map(e=>e.name)),Nt.tail!==Nt.head&&Fn(Nt.tail??=[],t.markers?.map(e=>e.name)),t.transform&&Kt.push(t.transform),t.afterLayout&&pt.push(t.afterLayout),t.postRender&&mt.push(t.postRender);for(let e of t.settings??[])Ht.add(e);Fn(At,t.props?.node),Fn(jt,t.props?.edge),Fn(Mt,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))Fn(Nt[e]??=[],n);Fn(Ft,t.bools),Fn(It,t.numbers)}Pn.frames.size&&Fn(Nt.frame??=[],[...Pn.frames.keys()])}var Ln={name:`themes`,themes:[O(`midnight`,{dark:`true`,background:`#0d1117`,"node-fill":`#161b26`,"node-stroke":`#2b3445`,"node-text":`#e6edf3`,"node-sub":`#8b96a8`,"group-fill":`#121722`,"group-stroke":`#222a38`,"group-text":`#8b96a8`,"edge-color":`#5d6a80`,"edge-text":`#aab4c3`,"title-color":`#e6edf3`,accent:`#60a5fa`}),{name:`blueprint`,dark:!0,background:`#0f3460`,font:o,mono:!0,fontSize:13,node:{fill:`#0f3460`,stroke:`#c9dcf5`,text:`#eaf2fd`,sub:`#9fbde3`},group:{fill:`none`,stroke:`#6f97c9`,text:`#9fbde3`,dash:`6 4`},edge:{stroke:`#c9dcf5`,text:`#eaf2fd`,labelBg:`#0f3460`,ink:`#eaf2fd`},title:`#eaf2fd`,accent:`#7dd3fc`,strokeWidth:1.25,edgeWidth:1.25,radius:2,shadow:null,grid:`rgba(201, 220, 245, 0.08)`,tone:t=>e[t]&&{fill:`#0f3460`,stroke:i(t,300),text:i(t,100)},groupTone:t=>e[t]&&{fill:`none`,stroke:i(t,400),text:i(t,200)},edgeTone:e=>i(e,300)},{name:`mono`,dark:!1,background:`#ffffff`,font:a,mono:!1,fontSize:14,node:{fill:`#ffffff`,stroke:`#18181b`,text:`#18181b`,sub:`#52525b`},group:{fill:`none`,stroke:`#a1a1aa`,text:`#52525b`,dash:`4 4`},edge:{stroke:`#18181b`,text:`#18181b`,labelBg:`#ffffff`,ink:`#18181b`},title:`#18181b`,accent:`#18181b`,strokeWidth:1.5,edgeWidth:1.5,radius:4,shadow:null,grid:null,tone:t=>e[t]&&{fill:i(t,100),stroke:`#18181b`,text:`#18181b`},groupTone:t=>e[t]&&{fill:i(t,50),stroke:`#a1a1aa`,text:`#52525b`},edgeTone:e=>i(e,700)},{name:`pastel`,dark:!1,background:`#fdfcff`,font:a,mono:!1,fontSize:14,node:{fill:`#f3f0ff`,stroke:`#f3f0ff`,text:`#3b3561`,sub:`#7c76a3`},group:{fill:`#f7f6fb`,stroke:`#f7f6fb`,text:`#8b86ad`,dash:null},edge:{stroke:`#b3add6`,text:`#5c5685`,labelBg:`#fdfcff`,ink:`#5c5685`},title:`#3b3561`,accent:`#a78bfa`,strokeWidth:1,edgeWidth:2,radius:16,shadow:`rgba(80, 60, 160, 0.08)`,grid:null,tone:t=>e[t]&&{fill:i(t,100),stroke:i(t,100),text:i(t,900)},groupTone:t=>e[t]&&{fill:i(t,50),stroke:i(t,50),text:i(t,700)},edgeTone:e=>i(e,300)},{name:`terminal`,dark:!0,background:`#0c0c10`,font:o,mono:!0,fontSize:13,node:{fill:`#121218`,stroke:`#2c2c38`,text:`#ececf1`,sub:`#7d7d8f`},group:{fill:`#0f0f14`,stroke:`#26262f`,text:`#8b8b9c`,dash:null},edge:{stroke:`#a78bfa`,text:`#ddd6fe`,labelBg:`#16141f`,ink:`#ddd6fe`,labelStroke:`#6d28d9`},title:`#f4f4f7`,accent:`#a78bfa`,strokeWidth:1,edgeWidth:1.5,radius:6,shadow:null,grid:null,tone:t=>e[t]&&{fill:i(t,950),stroke:i(t,700),text:i(t,200)},groupTone:t=>e[t]&&{fill:i(t,950)+`66`,stroke:i(t,900),text:i(t,300)},edgeTone:e=>i(e,400)},{name:`sepia`,dark:!1,background:`#f6efe1`,font:`'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif`,mono:!1,fontSize:15,node:{fill:`#fbf6ea`,stroke:`#c8b48f`,text:`#3e2f1c`,sub:`#86704f`},group:{fill:`#efe4cd`,stroke:`#dccaa6`,text:`#86704f`,dash:null},edge:{stroke:`#9c8460`,text:`#5c4a30`,labelBg:`#f6efe1`,ink:`#5c4a30`},title:`#3e2f1c`,accent:`#b45309`,strokeWidth:1.25,edgeWidth:1.5,radius:6,shadow:`rgba(90, 60, 20, 0.12)`,grid:null,tone:t=>e[t]&&{fill:i(t,100),stroke:i(t,400),text:i(t,900)},groupTone:t=>e[t]&&{fill:i(t,100)+`99`,stroke:i(t,300),text:i(t,800)},edgeTone:e=>i(e,600)},O(`frost`,{background:`#f5f8fc`,"node-fill":`#ffffff`,"node-stroke":`#c7d4e5`,"node-text":`#1b2a41`,"node-sub":`#64748b`,"group-fill":`#eaf0f8`,"group-stroke":`#eaf0f8`,"group-text":`#5b6b82`,"edge-color":`#8ea3bf`,"edge-text":`#3b4a61`,"title-color":`#1b2a41`,accent:`#0284c7`,"stroke-width":`1`,radius:`12`,shadow:`none`}),{name:`contrast`,dark:!1,background:`#ffffff`,font:a,mono:!1,fontSize:15,node:{fill:`#ffffff`,stroke:`#000000`,text:`#000000`,sub:`#262626`},group:{fill:`#f4f4f5`,stroke:`#000000`,text:`#000000`,dash:null},edge:{stroke:`#000000`,text:`#000000`,labelBg:`#ffffff`,ink:`#000000`,labelStroke:`#000000`},title:`#000000`,accent:`#1d4ed8`,strokeWidth:2,edgeWidth:2,radius:6,shadow:null,grid:null,tone:t=>e[t]&&{fill:i(t,100),stroke:i(t,800),text:i(t,950)},groupTone:t=>e[t]&&{fill:i(t,50),stroke:i(t,800),text:i(t,900)},edgeTone:e=>i(e,700)},O(`ocean`,{dark:`true`,background:`#0b1d2a`,"node-fill":`#0f2a3b`,"node-stroke":`#1f4a63`,"node-text":`#e0f2fe`,"node-sub":`#7fa6bd`,"group-fill":`#0d2433`,"group-stroke":`#173a4f`,"group-text":`#7fa6bd`,"edge-color":`#22b8cf`,"edge-text":`#a5e4ef`,"title-color":`#e0f2fe`,accent:`#2dd4bf`,shadow:`rgba(0, 10, 20, 0.5)`}),O(`ember`,{dark:`true`,background:`#1a1412`,"node-fill":`#241c19`,"node-stroke":`#45342c`,"node-text":`#fbeee6`,"node-sub":`#b09a8c`,"group-fill":`#201916`,"group-stroke":`#352823`,"group-text":`#b09a8c`,"edge-color":`#f97316`,"edge-text":`#fdba74`,"title-color":`#fbeee6`,accent:`#fb923c`,radius:`8`,shadow:`rgba(0, 0, 0, 0.5)`}),{name:`dusk`,dark:!0,background:`#1c1830`,font:a,mono:!1,fontSize:14,node:{fill:`#26203f`,stroke:`#3d3463`,text:`#f3eefe`,sub:`#a59cc8`},group:{fill:`#221c39`,stroke:`#221c39`,text:`#a59cc8`,dash:null},edge:{stroke:`#f0abfc`,text:`#f5d0fe`,labelBg:`#1c1830`,ink:`#f5d0fe`},title:`#f3eefe`,accent:`#c084fc`,strokeWidth:1,edgeWidth:1.75,radius:14,shadow:`rgba(10, 5, 30, 0.5)`,grid:null,tone:t=>e[t]&&{fill:i(t,900)+`cc`,stroke:i(t,500),text:i(t,100)},groupTone:t=>e[t]&&{fill:i(t,950)+`80`,stroke:i(t,900),text:i(t,300)},edgeTone:e=>i(e,300)}]},Rn=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e)),zn=(e,t)=>N(e,t.theme,t.theme.accent),Bn=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${oe}))?:\\s*(.*)$`)),Vn={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=Bn(`bars`,e);return t?{kind:`bars`,values:Rn(t[2]),color:t[1]}:null},measure:(e,{fs:t})=>({w:e.values.length*t*.85,h:t*3.4}),render(e,t,n){let{fs:r}=n,i=Math.max(...e.values,0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=zn(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${M(t.x+n*r*.85)}" y="${M(a-c)}" width="${M(r*.55)}" height="${M(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},Hn={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=Bn(`spark`,e);return t?{kind:`spark`,values:Rn(t[2]),color:t[1]}:null},measure:(e,{fs:t})=>({w:Math.max(t*8,e.values.length*t*.9),h:t*3.2}),render(e,t,n){let r=e.values;if(r.length<2)return``;let{fs:i}=n,a=Math.min(...r),o=Math.max(...r)-a||1,s=t.y+i*.45,c=t.y+t.h-i*.45,l=r.map((e,n)=>[t.x+n/(r.length-1)*t.w,c-(e-a)/o*(c-s)]),u=l.map(([e,t],n)=>`${n?`L`:`M`}${M(e)},${M(t)}`).join(``),d=zn(e.color,n),[f,p]=l[l.length-1];return`<path d="${u}L${M(t.x+t.w)},${M(c)}L${M(t.x)},${M(c)}Z" fill="${d}" fill-opacity="0.14"/><path d="${u}" fill="none" stroke="${d}" stroke-width="1.75" stroke-linejoin="round" stroke-linecap="round"/><circle cx="${M(f)}" cy="${M(p)}" r="2.6" fill="${d}"/>`}},Un={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=Bn(`progress`,e);if(!t)return null;let n=t[2].match(/^(\d+(?:\.\d+)?)\s*(%|\/\s*(\d+(?:\.\d+)?))?\s*(.*)$/);if(!n)return{kind:`progress`,ratio:0,value:``,label:A(t[2]),color:t[1]};let r=Number(n[1]),i=n[3]?r/(Number(n[3])||1):r/100,a=n[3]?`${n[1]}/${n[3]}`:`${n[1]}%`;return{kind:`progress`,ratio:Math.max(0,Math.min(1,i)),value:a,label:A(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:P(e.label,t,r,i)+t*2+i(e.value,t,600,r),h:n+t*.7}),render(e,t,n){let{fs:r,lh:i,col:a,theme:o}=n,s=t.y+i*.5,c=t.y+i+r*.05,l=r*.42,u=zn(e.color,n);return ye(e.label,t.x,s,r,a,o)+me(t.x+t.w,s,r,a.sub,j(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${M(t.x)}" y="${M(c)}" width="${M(t.w)}" height="${M(l)}" rx="${M(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${M(t.x)}" y="${M(c)}" width="${M(Math.max(l,t.w*e.ratio))}" height="${M(l)}" rx="${M(l/2)}" fill="${u}"/>`:``)}},Wn=1.75,Gn={name:`charts`,rows:[Vn,Hn,Un,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=Bn(`stat`,e);return t?{kind:`stat`,items:t[2].split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/);return{value:A(t),label:A(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*Wn;return e.ws=e.items.map(e=>Math.max(P(e.value,i,n,r,700),P(e.label,t*.9,n,r))),{w:e.ws.reduce((e,t)=>e+t,0)+t*2.4*Math.max(0,e.items.length-1),h:i*1.25+t*1.5}},render(e,t,n){let{fs:r,col:i,theme:a}=n,o=r*Wn,s=e.items.length,c=e.ws??e.items.map(()=>t.w/s),l=s>1?(t.w-c.reduce((e,t)=>e+t,0))/(s-1):0,u=[],d=e.color?{...i,text:zn(e.color,n)}:i,f=t.x;return e.items.forEach((e,n)=>{if(n>0){let e=f-l/2;u.push(`<path d="M${M(e)},${M(t.y+r*.3)}V${M(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(ye(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(ye(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},Kn=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function qn(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}var Jn=e=>e*1.8,Yn={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=qn(e),r=t?.kind===`table`?t:void 0;if(n.every(e=>/^:?-{2,}:?$/.test(e)))return r&&r.cells.length===1&&(r.header=!0),!0;let i=n.map(A);return r?(r.cells.push(i),!0):{kind:`table`,cells:[i],header:!1,numeric:[]}},finish(e){let t=Math.max(...e.cells.map(e=>e.length));for(let n of e.cells)for(;n.length<t;)n.push([]);let n=e.header?e.cells.slice(1):e.cells;e.numeric=Array.from({length:t},(e,t)=>n.length>0&&n.every(e=>!fe(e[t])||Kn.test(fe(e[t]).trim())))},measure(e,{fs:t,lh:n,mono:r,measure:i}){let a=e.cells[0]?.length??0;return e.cols=Array.from({length:a},(n,a)=>Math.max(0,...e.cells.map(e=>P(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+Jn(t)*Math.max(0,a-1),h:n*e.cells.length+(e.header?t*.5:0)}},render(e,t,{fs:n,lh:r,col:i,theme:a}){let o=[],s=e.cols??[];if(e.cells.forEach((c,l)=>{let u=t.y+r*(l+.5)+(e.header&&l>0?n*.5:0),d=t.x;c.forEach((t,r)=>{let c=e.numeric[r]?d+s[r]-_e(t):d;o.push(ye(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+Jn(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${M(t.x)},${M(e)}H${M(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},Xn=[`#ff5f57`,`#febc2e`,`#28c840`],Zn=e=>Math.round(e*2.3);function Qn(e,t,n,r,i){let a=Zn(t),o=Math.min(n,a/2,e.w/2),s=`M${M(e.x)},${M(e.y+a)}V${M(e.y+o)}A${M(o)},${M(o)} 0 0 1 ${M(e.x+o)},${M(e.y)}H${M(e.x+e.w-o)}A${M(o)},${M(o)} 0 0 1 ${M(e.x+e.w)},${M(e.y+o)}V${M(e.y+a)}Z`,c=t*.3,l=Xn.map((n,r)=>`<circle cx="${M(e.x+t+r*c*3.3)}" cy="${M(e.y+a/2)}" r="${M(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${M(e.x)},${M(e.y+a)}H${M(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}var $n=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,er={name:`browser`,inset:e=>({top:Zn(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=Zn(a),s=$n(e,a),c=e.x+e.w-a*.8,l=a*1.35,u=e.y+(o-l)/2,d=a*.78,f=c-s>a*3?`<rect x="${M(s)}" y="${M(u)}" width="${M(c-s)}" height="${M(l)}" rx="${M(l/2)}" fill="${t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?me(s+a*.7,e.y+o/2,d,n.sub,j(r)):``):``;return`<g class="frame">${Qn(e,a,i,n.stroke,t.dark)}${f}</g>`}},tr=(e,t)=>({name:e,inset:e=>({top:Zn(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=Zn(o),c=i?me(e.x+e.w/2,e.y+s/2,o*.78,r.sub,j(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${Qn(e,o,a,r.stroke,n.dark)}${c}</g>`}}),nr={name:`frames`,frames:[er,tr(`window`,``),tr(`terminal`,`❯ `)],props:{node:[`frame`]}},rr=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),ir={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=rr(e);if(!r.length)return null;let i=t.fontSize*.82,a=r.reduce((e,r)=>e+n(r.replace(/[*`~[\]{}]/g,``),i,400,t.mono),0)+i*3*(r.length-1);return{bottom:i*2.8,w:a}},render(e,t,n,{pad:r}){let i=rr(e),a=n.fontSize*.82,o=t.y+t.h*.55,s={text:n.node.text,sub:n.node.sub,stroke:n.node.stroke},c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${M(c)},${M(t.y)}H${M(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`];return i.forEach((e,t)=>{let r=i.length,[d,f]=r===1||t===0?[c,`start`]:t===r-1?[l,`end`]:[c+(l-c)*t/(r-1),`middle`];u.push(`<text x="${M(d)}" y="${M(o)}" dominant-baseline="central" text-anchor="${f}" font-size="${M(a)}" xml:space="preserve">${be(A(e),s,n,!0)}</text>`)}),`<g class="footer">${u.join(``)}</g>`}}]},ar=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),or=new Set(`mwMW@%`.split(``)),sr=(e,t,n,r)=>{if(r)return[...e].length*t*.6;let i=0;for(let t of e){let e=t.codePointAt(0);e>8192?i+=e>126976?1.2:1:ar.has(t)?i+=.3:or.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},cr=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,lr;function ur(e){return(t,n,r,i)=>{if(lr===void 0)try{lr=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{lr=null}if(!lr)return sr(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?cr:e;return lr.font=`${r} ${n}px ${a}`,lr.measureText(t).width}}var dr=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function fr(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return dr.test(t)?{kind:`arrow`,key:t,label:r}:t.startsWith(`.`)?{kind:`class`,key:t.slice(1),label:r||t.slice(1)}:{kind:`color`,key:t,label:r||t}})}var pr=e=>{let t=e.fontSize*.82;return{fs:t,sw:t*1.6,sh:t*1.05,gap:t*.5,space:t*1.6}};function mr(e,t,n){let{fs:r,sw:i,gap:a}=pr(t);return e.map(e=>i+a+P(A(e.label),r,t.mono,n))}function hr(e,t,n,r,i){let{sw:a,sh:o}=pr(r);if(e.kind===`arrow`){let i=r.edge.stroke,o=e.key.startsWith(`=`)?r.edgeWidth*2:r.edgeWidth,s=e.key.startsWith(`-->`)?` stroke-dasharray="${M(o*3)} ${M(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${M(o)} ${M(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${M(t)},${M(n)}H${M(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${M(o)}"${s} fill="none"/>`+(c?`<path d="M${M(u)},${M(n)}L${M(u-l)},${M(n-l*.5)}L${M(u-l)},${M(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${M(t)},${M(n)}L${M(t+l)},${M(n-l*.5)}L${M(t+l)},${M(n+l*.5)}Z" fill="${i}"/>`:``)}let s={x:t,y:n-o/2,w:a,h:o};if(e.kind===`class`){let t={id:``,label:``,props:{},classes:[e.key],implicit:!1},n=Ce(i,t),a=Te(i,t,n,r),o=vt(n.shape??i.settings.shape);return`<path d="${xt(o===`text`?`rounded`:o,s,Math.min(a.radius,4))}" fill="${a.fill}" stroke="${a.stroke}" stroke-width="1.2"${a.dash?` stroke-dasharray="${a.dash}"`:``}/>`}let c=r.tone(e.key),l=c?.fill??k(e.key,r,400)??r.node.fill,u=c?.stroke??k(e.key,r,600)??r.node.stroke;return`<rect x="${M(s.x)}" y="${M(s.y)}" width="${M(s.w)}" height="${M(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function gr(e,t,n){let r=[[]],i=0;return e.forEach((e,a)=>{let o=r[r.length-1];o.length&&i+n+e>t?(r.push([a]),i=e):(o.push(a),i+=(o.length>1?n:0)+e)}),r}var _r=760,vr={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=fr(e);if(!n.length)return null;let{fs:r,space:i}=pr(t),a=mr(n,t,sr),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=gr(a,_r,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,_r)}},render(e,t,n,{pad:r,d:i}){let a=fr(e),{fs:o,gap:s,space:c,sw:l}=pr(n),u=mr(a,n,sr),d={text:n.node.text,sub:n.node.sub,stroke:n.node.stroke},f=[];return gr(u,Math.min(_r,t.w-r*2),c).forEach((e,p)=>{let m=t.x+r,h=t.y+o*1.4+p*o*1.9;for(let t of e){let e=a[t];f.push(hr(e,m,h,n,i)),e.label&&f.push(`<text x="${M(m+l+s)}" y="${M(h)}" dominant-baseline="central" font-size="${M(o)}" xml:space="preserve">${be(A(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},yr=String.raw`[\p{L}_][\p{L}\p{N}_-]*`,br=new RegExp(String.raw`^(participant|actor)\s+(${yr})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?$`,`u`),xr=new RegExp(String.raw`^(${yr})\s*(-->|->|\.\.>|=>)\s*(${yr})\s*(?::\s*(.*))?$`,`u`),Sr=new RegExp(String.raw`^(${yr}\s*(?:-->|->|\.\.>|=>)\s*${yr})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),Cr=new RegExp(String.raw`^(participant|actor)\s+(${yr}(?:\s*,\s*${yr})+)$`,`u`),wr=new RegExp(String.raw`^note\s+(${yr}(?:\s*,\s*${yr})*)\s*:\s*(.*)$`,`u`),Tr=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,Er=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],Dr=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>Er.includes(e))&&(!e.color||ae(e.color))},Or=e=>fn(e,Dr),kr={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function Ar(e,t,n){let r=[],i=[],a=0,o=e=>{let t=r.find(t=>t.id===e);return t||r.push(t={id:e,label:e,actor:!1,first:a}),t},s=0;return e.forEach((e,t)=>{a=t;let r=e.trim();if(!r)return;let c;if(c=r.match(br)){let e=o(c[2]);e.decl=a,e.actor=c[1]===`actor`,c[3]!==void 0&&(e.label=c[3]);let t=c[4]&&R(c[4]).color;t&&(e.tone=t)}else if(c=r.match(Cr))for(let e of c[2].split(`,`)){let t=o(e.trim());t.actor=c[1]===`actor`,t.list??=a}else if(c=r.match(wr)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=Or(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(xr)){o(c[1]),o(c[3]);let[e,t]=Or(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:kr[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(Tr))?i.push({kind:`divider`,text:c[1]}):(c=r.match(Sr))?n(a,`sequence: props go at the end of a message: "${c[1]}${c[3]?`: ${c[3]}`:``} [${c[2]}]"`):n(a,`sequence: cannot read "${r}" (expected "a -> b: message", "note a: text", "participant a \\"Label\\"" or "--- section ---")`)}),{parts:r,steps:i}}function jr(e){let t={note:0,divider:0};return e.steps.map(e=>e.kind===`msg`?`m${e.n}`:e.kind===`note`?`note${++t.note}`:`d${++t.divider}`)}var Mr=Mn(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.numbered!==void 0&&i.numbered!==`false`,s=e=>P(A(e),a,n.mono,r),c=t.fs*2.5,l=e.parts.map(e=>Math.max(r(e.label,t.fs,600,n.mono)+28,t.fs*6)),u=l.slice(1).map((e,t)=>(l[t]+e)/2+24),d=t=>e.parts.findIndex(e=>e.id===t),f=e=>o?`${e.n}. `:``,p=0,m=(e,t,n)=>{let r=u.slice(e,t).reduce((e,t)=>e+t,0);r<n&&(u[t-1]+=n-r)};for(let t of e.steps)if(t.kind===`msg`){let e=d(t.from),n=d(t.to),r=s(f(t)+t.text)+28;e===n?e<u.length?m(e,e+1,r+30):p=Math.max(p,r+30-l[e]/2):m(Math.min(e,n),Math.max(e,n),r)}else if(t.kind===`note`){let e=t.over.map(d).sort((e,t)=>e-t),n=s(t.text)+24;e[0]!==e[e.length-1]&&m(e[0],e[e.length-1],n-40)}let h=e=>t.offsets[e]?.x??0;u.forEach((t,n)=>{u[n]=Math.max((l[n]+l[n+1])/2+8,t+h(e.parts[n+1].id))});let g=[l[0]/2];u.forEach((e,t)=>g.push(g[t]+e));let _=e.parts.length?g[g.length-1]+l[l.length-1]/2+Math.max(0,p):0;for(let t of e.steps)t.kind===`note`&&t.over.length===1&&(_=Math.max(_,g[d(t.over[0])]+(s(t.text)+24)/2));let v=e=>e.kind===`msg`?e.from===e.to?a*3.6:a*2.6:e.kind===`note`?a*2.6:a*2.4,y=jr(e),b=e.steps.map((e,t)=>Math.max(-v(e)*.3,h(y[t]))),x=c*2+a*1.4+e.steps.reduce((e,t,n)=>e+v(t)+b[n],0);return{fs:a,boxH:c,widths:l,xs:g,w:_,h:x,rowH:v,extra:b,parts:y,idx:d,num:f,textW:s,noteX:e=>{let t=g[Math.min(...e.over.map(d))];return Math.min(t-(s(e.text)+24)/2,t-20)}}});function Nr(e,t){let n=we(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function Pr(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=Mr(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},d=n.props,f=k(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=Nr(xe(d,`lifeline-style`)??`dashed`,1),m=[],h=t.y,g=t.y+i.h-o;e.parts.forEach((e,t)=>m.push(`<path d="M${M(c(t))},${M(h+o)}V${M(g)}" stroke="${f}" stroke-width="1"${p}/>`));let _=t=>e.parts.map((e,a)=>{let s=e.tone?r.tone(e.tone):void 0,l=i.widths[a],u=e.actor?o/2:Math.min(10,r.radius+2);return`<rect x="${M(c(a)-l/2)}" y="${M(t)}" width="${M(l)}" height="${M(o)}" rx="${M(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${M(r.strokeWidth)}"/><text x="${M(c(a))}" y="${M(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${M(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${j(e.label)}</text>`}).join(``);m.push(_(h),_(g));let v=h+o+a*.7;for(let[n,o]of e.steps.entries()){v+=i.extra[n];let e=i.rowH(o);if(o.kind===`msg`){let e=i.idx(o.from),t=i.idx(o.to),n=o.props,s=xe(n,`style`)??(o.line===`thick`?`solid`:o.line),d=F(n.width,o.line===`thick`||w(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=Nr(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=A(i.num(o)+o.text),g=o.tone?N(o.tone,r,l):l,_=o.tone?{...u,text:g}:u;if(e===t){let t=c(e),n=v+a*1.6,i=n+a*1.3;m.push(`<path d="M${M(t)},${M(n)}H${M(t+26-8)}Q${M(t+26)},${M(n)} ${M(t+26)},${M(n+8)}V${M(i-8)}Q${M(t+26)},${M(i)} ${M(t+26-8)},${M(i)}H${M(t+2)}" fill="none" stroke="${g}" stroke-width="${M(d)}"${f}/>`),m.push(ht({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${M(t+34)}" y="${M((n+i)/2)}" dominant-baseline="central" font-size="${M(a)}" xml:space="preserve">${be(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${M(c(e))},${M(s)}H${M(c(t)-n*2)}" stroke="${g}" stroke-width="${M(d)}"${f}/>`),m.push(ht({x:c(t)-n,y:s},n>0?0:Math.PI,p,g,d,5+d*1.4)),(o.text||i.num(o))&&m.push(`<text x="${M((c(e)+c(t))/2)}" y="${M(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a)}" xml:space="preserve">${be(h,_,r)}</text>`)}}else if(o.kind===`note`){let n=o.over.map(i.idx).sort((e,t)=>e-t),s=i.textW(o.text)+24,l=t.x+i.noteX(o),u=n.length>1?Math.max(c(n[n.length-1])+20,l+s):l+s,d=o.tone&&r.tone(o.tone)||r.tone(`amber`),f=a*1.9,p=v+(e-f)/2;m.push(`<rect x="${M(l)}" y="${M(p)}" width="${M(u-l)}" height="${M(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${M((l+u)/2)}" y="${M(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a)}" xml:space="preserve">${be(A(o.text),{text:d.text,sub:d.text,stroke:d.stroke},r)}</text>`)}else{let n=v+e/2,s=o.text?i.textW(o.text)+20:0,c=t.x+t.w/2;m.push(`<path d="M${M(t.x)},${M(n)}H${M(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${M(c-s/2)}" y="${M(n-a*.85)}" width="${M(s)}" height="${M(a*1.7)}" rx="${M(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${M(c)}" y="${M(n)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a*.92)}" font-weight="600" fill="${r.node.sub}">${j(o.text)}</text>`))}v+=e}return m.join(``)}function Fr(e,t,n){if(!e.parts.length)return[];let r=Mr(e,n),i=e=>t.x+r.xs[e],a=e.parts.slice(1).map((e,n)=>({part:e.id,x:i(n+1),y:t.y+r.boxH,axis:`x`,title:`move lifeline ${e.id}`})),o=t.y+r.boxH+r.fs*.7;return e.steps.forEach((e,n)=>{o+=r.extra[n];let s=r.rowH(e),c=e.kind===`msg`?{x:i(r.idx(e.from)),y:o+r.fs*(e.from===e.to?1.6:1.85)}:e.kind===`note`?{x:r.noteX(e)-9,y:o+s/2}:{x:t.x,y:o+s/2},l=e.kind===`msg`?`message ${e.n}`:e.kind===`note`?`note`:`divider`;a.push({part:r.parts[n],...c,axis:`y`,title:`move ${l} down`}),o+=s}),a}var Ir={name:`sequence`,panels:[{name:`sequence`,guide:'`participant|actor id "Label" [color]` (`participant a, b, c` fixes the order), `a -> b: msg` (`-->` reply, `..>` dotted, `=>` thick, `a -> a` self call), `note a, b: text`, `--- section ---`. A message takes edge props at its end: `a -> b: retry [red, style: dotted]`.',layoutParts:"a participant id moves its lifeline and the ones after it; `m<n>` (message), `note<n>`, `d<n>` (divider) add room above that row",syntax:`sequence id "Title" [numbered] { a -> b: message }`,parse:Ar,measure(e,t){let n=Mr(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:Pr,handles:Fr,options:{numbered:[`true`,`false`],lifeline:[],"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=jr(e);return[...e.parts.map(e=>({id:e.id,label:e.label,kind:e.actor?`actor`:`participant`,tone:e.tone})),...e.steps.flatMap((e,n)=>e.kind===`divider`?[]:[{id:t[n],label:e.kind===`msg`?`${e.from} → ${e.to}${e.text?`: ${e.text}`:``}`:`note: ${e.text}`,kind:e.kind===`msg`?`message`:`note`,tone:e.tone}])]},editPart:Nn((e,t,n,r)=>{let i=[...e],a=r.parts.find(e=>e.id===t);if(a){if(a.decl!==void 0)return i[a.decl]=pn(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${gn({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=jr(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=Or(e[s.at]),u=c;delete l.color;let d=gn(n?{color:n,...l}:l);return u=d?/:/.test(u.replace(/^.*?(-->|->|\.\.>|=>)/,``))||s.kind===`note`?`${u} [${d}]`:`${u}: [${d}]`:u.replace(/\s*:\s*$/,``),i[s.at]=u,i})}]},Lr=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,Rr=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function zr(e,t,n){let r=[];return e.forEach((e,t)=>{let i=e.trim();if(!i)return;let a=i.match(/^[-*]\s+(.*)$/);if(a){r.length?r[r.length-1].details.push(a[1]):n(t,`timeline: a "- detail" line needs an event above it`);return}let[o,s]=fn(i,mn),c=o.match(Lr);c?r.push({when:c[1].trim(),tone:s.color??R(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function Br(e){let t=new Set;return e.map((e,n)=>{let r=!/\s/.test(e.when)&&!t.has(e.when)&&!/^e\d+$/.test(e.when)?e.when:`e${n+1}`;return t.add(r),r})}function Vr(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#|[-*]\s)/.test(r)&&Lr.test(r)&&t.push(n)}),t}var Hr=Mn(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.9,o=i.direction===`down`,s=(e,t=a,i=400)=>P(A(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>Math.max(s(e.title,a,600),...e.details.map(e=>s(e,a*.92)))),u=e.map(e=>1+e.details.length),d=Br(e),f=o?e.map((e,t)=>u[t]*a*1.45+a*1.2):e.map((e,t)=>Math.max(c[t],l[t],a*7)+a*1.6),p=a*(o?1.2:1.6),m=[];f.forEach((e,n)=>{let r=n?Math.max(-p*.75,t.offsets[d[n]]?.x??0):0;m.push(n?m[n-1]+f[n-1]+r:0)});let h=e.length?m[m.length-1]+f[f.length-1]-p:0;if(o){let e=Math.max(0,...c)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+Math.max(0,...l),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+Math.max(1,...u)*a*1.45}});function Ur(e,t,n){if(!e.length)return``;let r=n.theme,i=Hr(e,n),{fs:a}=i,o={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},s=r.group.stroke,c=[],l=(e,t,n)=>{let i=N(n.tone,r,r.accent);return`<circle cx="${M(e)}" cy="${M(t)}" r="${M(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${M(e)}" cy="${M(t)}" r="${M(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${M(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${be(A(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${M(n)},${M(t.y+a*.5)}V${M(t.y+i.h-a*.5)}" stroke="${s}" stroke-width="2" stroke-linecap="round"/>`),e.forEach((e,o)=>{let s=t.y+a*.5+i.at[o];c.push(`<text x="${M(n-16)}" y="${M(s)}" dominant-baseline="central" text-anchor="end" font-size="${M(a*.9)}" font-weight="600" fill="${N(e.tone,r,r.node.sub)}">${j(e.when)}</text>`),c.push(l(n,s,e)),c.push(u(n+20,s,e.title,a,600,`start`,!1)),e.details.forEach((e,t)=>c.push(u(n+20,s+(t+1)*a*1.45,e,a*.92,400,`start`,!0)))}),c.join(``)}let d=t.y+a*1.9;return c.push(`<path d="M${M(t.x)},${M(d)}H${M(t.x+t.w)}" stroke="${s}" stroke-width="2" stroke-linecap="round"/>`),e.forEach((e,n)=>{let o=t.x+i.at[n];c.push(`<text x="${M(o)}" y="${M(t.y+a*.5)}" dominant-baseline="central" font-size="${M(a*.9)}" font-weight="600" fill="${N(e.tone,r,r.node.sub)}">${j(e.when)}</text>`),c.push(l(o+a*.42,d,e)),c.push(u(o,d+a*1.55,e.title,a,600,`start`,!1)),e.details.forEach((e,t)=>c.push(u(o,d+a*1.55+(t+1)*a*1.45,e,a*.92,400,`start`,!0)))}),c.join(``)}var Wr={name:`timeline`,panels:[{name:`timeline`,guide:"`when [color]: title`, then indented `- detail` lines. The colon needs a space after it, so `12:30: deploy` works.",layoutParts:"an event by its one-word `when`, else `e<n>`, adds room before it",syntax:`timeline id "Title" [direction: down] { 2025 Q1: Launch }`,options:{direction:[`right`,`down`]},parse:zr,measure(e,t){if(!e.length)return{w:0,h:0};let n=Hr(e,t);return{w:n.w,h:n.h}},render:Ur,parts:e=>Br(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:Nn((e,t,n,r)=>{let i=Vr(e)[Br(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=hn(e[i],Rr,`color`,n,mn),a}),handles(e,t,n){if(!e.length)return[];let r=Hr(e,n);return e.slice(1).map((e,i)=>r.vertical?{part:r.parts[i+1],x:t.x+r.left,y:t.y+n.fs*.45+r.at[i+1],axis:`y`,title:`move ${e.when}`}:{part:r.parts[i+1],x:t.x+r.at[i+1]+r.fs*.42,y:t.y+r.fs*1.9,axis:`x`,title:`move ${e.when}`})}}]},Gr=[`bar`,`column`,`line`,`pie`,`donut`],Kr=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],qr=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,Jr=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/;function Yr(e,t,n){let r=t.type??`bar`;Gr.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${Gr.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=fn(r,mn),s=a.match(qr);s?i.push({label:s[1].trim().replace(/^"(.*)"$/,`$1`),tone:o.color??R(s[2]).color,value:Number(s[3])}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:Gr.includes(r)?r:`bar`,items:i}}var Xr=(e,t=``)=>`${Math.round(e*100)/100}${t}`;function Zr(e,t,n,r){return e.tone?N(e.tone,n.theme,n.theme.accent):r?i(Kr[t%Kr.length],n.theme.dark?400:500):n.theme.accent}var Qr=Mn(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=Math.max(0,...e.items.map(e=>r(e.label,a,400,n.mono))),c=Math.max(0,...e.items.map(e=>r(Xr(e.value,o),a,600,n.mono))),l=e.items.reduce((e,t)=>e+Math.max(0,t.value),0),u=t.offsets.size??{x:0,y:0},d=Math.max(1,e.items.length),f=Math.max(t.fs*2,t.fs*5.2+(u.x+u.y)/4),p=o===`%`?-10:r(`100%`,a,400,n.mono);switch(e.type){case`pie`:case`donut`:return{fs:a,unit:o,lw:s,vw:c,total:l,r:f,colW:0,plotH:0,w:f*2+28+a*1.6+s+14+c+10+p,h:Math.max(f*2,e.items.length*a*1.75)};case`bar`:{let n=Math.max(t.fs*3,t.fs*14+u.x),r=Math.max(a*1.4,a*2+u.y/d);return{fs:a,unit:o,lw:s,vw:c,total:l,r:f,colW:0,plotH:0,barMax:n,pitch:r,w:s+12+n+10+c,h:e.items.length*r-a*.6}}default:{let n=Math.max(a*2.5,Math.max(a*3,s+12,c+12)+u.x/d),r=Math.max(t.fs*3,t.fs*9+u.y);return{fs:a,unit:o,lw:s,vw:c,total:l,r:f,colW:n,plotH:r,w:n*e.items.length,h:r+a*3.2}}}});function $r(e,t,n,r,i,a){let o=(n,r)=>`${M(e+n*Math.sin(r))},${M(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return $r(e,t,n,r,o,a)+$r(e,t,n,o,i,a)}return a?`M${o(n,r)}A${M(n)},${M(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${M(a)},${M(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${M(e)},${M(t)}L${o(n,r)}A${M(n)},${M(n)} 0 ${s} 1 ${o(n,i)}Z`}function ei(e,t,n){if(!e.items.length)return``;let r=n.theme,i=Qr(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${M(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${j(n)}</text>`,l=Math.max(0,...e.items.map(e=>e.value))||1;if(e.type===`pie`||e.type===`donut`){let l=t.x+i.r,u=t.y+i.h/2,d=e.type===`donut`?i.r*.6:0,f=r.background===`none`?r.node.fill:r.background,p=0;e.items.forEach((e,t)=>{let r=Math.max(0,e.value);if(!r||!i.total)return;let a=p+r/i.total*Math.PI*2;s.push(`<path d="${$r(l,u,i.r,p,a,d)}" fill="${Zr(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,Xr(i.total,o),`middle`,r.node.text,700,a*1.35)),s.push(c(l,u+a*.85,`total`,`middle`,r.node.sub,400,a*.85)));let m=t.x+i.r*2+28,h=e.items.length*a*1.75,g=t.y+(i.h-h)/2+a*.875;return e.items.forEach((e,l)=>{s.push(`<rect x="${M(m)}" y="${M(g-a*.45)}" width="${M(a*.9)}" height="${M(a*.9)}" rx="2.5" fill="${Zr(e,l,n,!0)}"/>`),s.push(c(m+a*1.6,g,e.label)),s.push(c(m+a*1.6+i.lw+14+i.vw,g,Xr(e.value,o),`end`,r.node.text,600)),i.total&&o!==`%`&&s.push(c(t.x+t.w,g,`${Math.round(Math.max(0,e.value)/i.total*100)}%`,`end`,r.node.sub)),g+=a*1.75}),s.join(``)}if(e.type===`bar`){let u=t.x+i.lw+12,{barMax:d,pitch:f}=i;return e.items.forEach((e,i)=>{let p=t.y+i*f+a*.7,m=Math.max(2,Math.max(0,e.value)/l*d);s.push(c(u-12,p,e.label,`end`,r.node.sub)),s.push(`<rect x="${M(u)}" y="${M(p-a*.55)}" width="${M(d)}" height="${M(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${M(u)}" y="${M(p-a*.55)}" width="${M(m)}" height="${M(a*1.1)}" rx="3" fill="${Zr(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,Xr(e.value,o),`start`,r.node.text,600))}),s.join(``)}let u=t.y+a*1.6+i.plotH,d=e=>t.x+i.colW*(e+.5),f=e=>u-Math.max(0,e)/l*i.plotH;for(let e=1;e<=3;e++){let n=u-i.plotH*e/4;s.push(`<path d="M${M(t.x)},${M(n)}H${M(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="2 4" opacity="0.8"/>`)}if(e.type===`column`){let t=Math.min(i.colW*.62,a*3.2);e.items.forEach((e,i)=>{let l=f(e.value);s.push(`<rect x="${M(d(i)-t/2)}" y="${M(l)}" width="${M(t)}" height="${M(Math.max(2,u-l))}" rx="3" fill="${Zr(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,Xr(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${M(d(t))},${M(f(e.value))}`);s.push(`<path d="M${M(d(0))},${M(u)}L${t.join(`L`)}L${M(d(e.items.length-1))},${M(u)}Z" fill="${r.accent}" opacity="0.12"/>`),s.push(`<path d="M${t.join(`L`)}" fill="none" stroke="${r.accent}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>`),e.items.forEach((e,t)=>{let i=Zr(e,t,n,!1);s.push(`<circle cx="${M(d(t))}" cy="${M(f(e.value))}" r="${M(a*.32)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2"/>`),s.push(c(d(t),f(e.value)-a*.95,Xr(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${M(t.x)},${M(u)}H${M(t.x+t.w)}" stroke="${r.node.stroke}" stroke-width="1"/>`),e.items.forEach((e,t)=>s.push(c(d(t),u+a*1.1,e.label,`middle`,r.node.sub))),s.join(``)}var ti={name:`chart`,panels:[{name:`chart`,guide:"`label [color]: number` per line; `unit` is appended to values.",layoutParts:"`size DX DY` grows the plot",syntax:`chart id "Title" [type: bar|column|line|pie|donut, unit: %] { label: 42 }`,parse:Yr,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=Qr(e,t);return{w:n.w,h:n.h}},render:ei,options:{type:[...Gr],unit:[]},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:Nn((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim();return!/^(\/\/|#)/.test(n)&&qr.test(fn(n,mn)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=hn(e[i],Jr,`color`,n,mn),a}),handles(e,t,n){if(!e.items.length)return[];let r=Qr(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},ni=[`normal`,`highlight`,`reverse`],ri=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],ii=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,ai=String.raw`(?:\s*\[([^\]]*)\])?`,oi=new RegExp(String.raw`^commit(?:\s+(.*?))?${ai}$`,`u`),si=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${ii})(?:\s+from\s+(\S+))?${ai}$`,`u`),ci=new RegExp(String.raw`^(?:checkout|switch)\s+(${ii})$`,`u`),li=new RegExp(String.raw`^merge\s+(${ii})(?:\s+(.*?))?${ai}$`,`u`),ui=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${ai}$`,`u`),di=/^tag\s+(\S+)$/;function fi(e){let t=R(e??``);for(let e of ni)t[e]===`true`&&(t.type=e,delete t[e]);return t}function pi(e,t,n){let r=[{name:t.main||`main`,lane:0,head:-1}],i=[],a=r[0],o=e=>r.find(t=>t.name===e),s=e=>{let t=o(e);if(t)return t.head>=0?t.head:void 0;let n=i.findIndex(t=>t.id===e||t.tags.includes(e));return n>=0?n:void 0},c=(e,t,r)=>{let o=t.type;o&&!ni.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${ni.join(`, `)})`),o=void 0),t.id&&i.some(e=>e.id===t.id)&&n(r,`git: commit id "${t.id}" is used twice`),i.push({...e,lane:a.lane,tags:t.tag?[t.tag]:[],id:t.id,tone:t.color,type:o,at:r}),a.head=i.length-1};return e.forEach((e,t)=>{let l=e.trim();if(!l)return;let u;if(u=l.match(si)){if(o(u[1]))return n(t,`git: branch "${u[1]}" already exists (use "checkout ${u[1]}")`);let e=a.head;if(u[2]){let r=o(u[2])?.head??s(u[2]);if(r===void 0)return n(t,`git: unknown branch, commit or tag "${u[2]}"`);e=r}let i=fi(u[3]),c=i.order===void 0?void 0:Number(i.order);c!==void 0&&!Number.isFinite(c)&&n(t,`git: order must be a number, got "${i.order}"`);let l={name:u[1],lane:r.length,head:e,tone:i.color,label:i.label,order:Number.isFinite(c)?c:void 0,at:t};r.push(l),a=l}else if(u=l.match(ci)){let e=o(u[1]);e?a=e:n(t,`git: unknown branch "${u[1]}" (create it with "branch ${u[1]}")`)}else if(u=l.match(li)){let e=o(u[1]);if(!e)return n(t,`git: unknown branch "${u[1]}"`);if(e===a)return n(t,`git: cannot merge "${u[1]}" into itself`);if(e.head<0)return n(t,`git: "${u[1]}" has no commits to merge`);let r=[a.head,e.head].filter(e=>e>=0);c({msg:wn(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},fi(u[3]),t)}else if(u=l.match(ui)){let e=s(u[1]);if(e===void 0)return n(t,`git: cherry-pick: unknown commit, tag or branch "${u[1]}" (give the commit an id: commit "msg" [id: abc])`);if(i[e].lane===a.lane)return n(t,`git: cherry-pick: "${u[1]}" is already on ${a.name}`);c({msg:wn(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},fi(u[3]),t)}else(u=l.match(di))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(oi))?c({msg:wn(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},fi(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function mi(e,t,n){let r=e.branches[t]?.tone;return r?N(r,n.theme,n.theme.accent):i(ri[t%ri.length],n.theme.dark?400:500)}function hi(e){let t=new Set(e.branches.map(e=>e.name));return e.commits.map((e,n)=>{let r=e.id??e.tags[0];return(!r||t.has(r)||/\s/.test(r))&&(r=`c${n+1}`),t.add(r),r})}var gi=new WeakMap,_i=Mn(function(e,t){let n=JSON.stringify([t.fs,t.props,t.offsets]),r=gi.get(e);if(r&&r.key===n&&r.theme===t.theme&&r.measure===t.measure)return r.G;let i=vi(e,t);return gi.set(e,{key:n,theme:t.theme,measure:t.measure,G:i}),i});function vi(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=hi(e),l=e=>s[e]?.x??0,u=e=>P(A(e),a,n.mono,r),d=e=>r(e,a*.82,600,n.mono)+a*1.1,f=a*.5,p=e=>(e.order??e.lane)-(e.order===void 0?0:.5),m=new Set(e.commits.map(e=>e.lane)),h=e.branches.filter(e=>m.has(e.lane)).sort((e,t)=>p(e)-p(t)),g=new Map(h.map((e,t)=>[e.lane,t])),_=o?a*1.7:a*4,v=[];h.forEach((e,t)=>{let n=Math.max(t?f*3-_:0,l(e.name));v.push((t?v[t-1]+_:0)+n)});let y=v[v.length-1]??0,b=o?e.commits.map(()=>a*2.1):e.commits.map(e=>Math.max(a*2.6,u(e.msg)+a*2,...e.tags.map(e=>d(e)+a*.6))),x=o?0:Math.max(0,...h.map(e=>r(e.label??e.name,a,600,n.mono)))+a*1.4,S=[];b.forEach((e,t)=>{let n=t?S[t-1]+b[t-1]/2:x,r=Math.max(f*3-(t?b[t-1]/2:0)-e/2,l(c[t]));S.push(n+e/2+r)});let C=e.commits.length?S[S.length-1]+b[b.length-1]/2:0,w={fs:a,r:f,vertical:o,parts:c,off:s,used:h,slot:g,pillW:d,textW:u,spans:b,at:S,gap:e=>(S[e-1]+b[e-1]/2+S[e]-b[e]/2)/2,lanePos:v};if(o){let t=_,n=y+t+a*.6,i=new Map;for(let e of h)i.set(e.head,[...i.get(e.head)??[],e]);let o=e.commits.map((e,t)=>{let n=[...(i.get(t)??[]).map(e=>e.label??e.name),...e.tags].reduce((e,t)=>e+d(t)+a*.4,0);return(e.id?r(e.id,a,400,!0)+a*.6:0)+n+u(e.msg)}),s=e.commits.map((e,n)=>({x:t/2+v[g.get(e.lane)??0],y:S[n]}));return{...w,laneW:t,textX:n,heads:i,labelW:x,top:0,pos:s,w:n+Math.max(0,...o),h:C}}let T=Math.max(0,...e.commits.filter(e=>g.get(e.lane)===0).map(e=>e.tags.length)),E=a*.6+T*a*1.5,D=e.commits.map((e,t)=>({x:S[t],y:E+v[g.get(e.lane)??0]}));return{...w,laneW:0,textX:0,heads:new Map,labelW:x,top:E,pos:D,w:C,h:E+y+a*2}}var yi=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function bi(e,t,n){let{fs:r,r:i,parts:a,vertical:o}=t,s=t.pos.map(e=>({x:n.x+e.x,y:n.y+e.y})),c=r*1.6,l=n=>Math.max(0,...e.commits[n].tags.map(e=>t.pillW(e))),u=[],d=[];e.commits.forEach((n,f)=>{n.parents.forEach((p,m)=>{let h=s[p],g=s[f];if(e.commits[p].lane===n.lane){u.push({i:f,k:m,d:`M${M(h.x)},${M(h.y)}L${M(g.x)},${M(g.y)}`});return}let _=`${a[f]}^${m+1}`,v=t.off[_]?.x??0;if(o){let e=Math.min(c,Math.abs(g.y-h.y))/2,t=yi((m?g.y-e:h.y+e)+v,h.y+e,g.y-e);d.push({i:f,k:m,part:_,handle:{x:(h.x+g.x)/2,y:t},d:`M${M(h.x)},${M(h.y)}V${M(t-e)}C${M(h.x)},${M(t)} ${M(g.x)},${M(t)} ${M(g.x)},${M(t+e)}V${M(g.y)}`});return}let y=g.y>h.y,b=(n,r)=>Math.max(i,(r?t.textW(e.commits[n].msg):l(n))/2),x=Math.min(c,Math.abs(g.x-h.x))/2,S=yi((m?g.x-b(f,!y)-r*.7:h.x+b(p,y)+r*.7)+v,h.x+x,g.x-x);d.push({i:f,k:m,part:_,handle:{x:S,y:(h.y+g.y)/2},d:`M${M(h.x)},${M(h.y)}H${M(S-x)}C${M(S)},${M(h.y)} ${M(S)},${M(g.y)} ${M(S+x)},${M(g.y)}H${M(g.x)}`})})});let f=[];return e.commits.forEach((e,r)=>{if(e.pick===void 0)return;let i=s[e.pick],c=s[r],l=`${a[r]}^pick`,u=t.off[l]??{x:0,y:0};if(o){let e=Math.max(i.x,c.x)+t.laneW+u.x,n=(i.y+c.y)/2+u.y;f.push({i:r,part:l,handle:{x:(i.x+2*e+c.x)/4,y:(i.y+2*n+c.y)/4},d:`M${M(i.x)},${M(i.y)}Q${M(e)},${M(n)} ${M(c.x)},${M(c.y)}`});return}let d=(i.x+c.x)/2,p=d;for(let i=e.pick+1;i<=r;i++)(Math.abs(n.x+t.gap(i)-d)<Math.abs(p-d)||p===d)&&(p=n.x+t.gap(i));p+=u.x,f.push({i:r,part:l,handle:{x:(i.x+6*p+c.x)/8,y:(i.y+c.y)/2+.75*u.y},d:`M${M(i.x)},${M(i.y)}C${M(p)},${M(i.y+u.y)} ${M(p)},${M(c.y+u.y)} ${M(c.x)},${M(c.y)}`})}),{lanes:u,bends:d,picks:f}}function xi(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=_i(e,n),{fs:a,r:s}=i,c=n.props.color&&r.groupTone(n.props.color)?.fill||[r.group.fill,r.background,r.node.fill].find(e=>e&&e!==`none`),l={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},u=[],d=i.pos.map(e=>({x:t.x+e.x,y:t.y+e.y})),f=(e,t,n,r,o,s)=>{let l=i.pillW(n),u=s===`middle`?e-l/2:e,d=a*1.3;return`<rect x="${M(u)}" y="${M(t-d/2)}" width="${M(l)}" height="${M(d)}" rx="${M(d/2)}" fill="${o?r:c}" stroke="${r}" stroke-width="1.2"/><text x="${M(u+l/2)}" y="${M(t)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a*.82)}" font-weight="600" fill="${o?c:r}">${j(n)}</text>`};if(!i.vertical)for(let r of i.used){let o=t.y+i.top+i.lanePos[i.slot.get(r.lane)];u.push(`<text x="${M(t.x)}" y="${M(o)}" dominant-baseline="central" font-size="${M(a)}" font-weight="600" fill="${mi(e,r.lane,n)}">${j(r.label??r.name)}</text>`)}let p=Math.max(2,r.edgeWidth*1.4),m=bi(e,i,t),h=(t,r)=>mi(e,r?e.commits[e.commits[t].parents[r]].lane:e.commits[t].lane,n);for(let t of m.picks)u.push(`<path d="${t.d}" fill="none" stroke="${mi(e,e.commits[t.i].lane,n)}" stroke-width="${M(p*.7)}" stroke-dasharray="${M(p*1.6)} ${M(p*1.6)}" opacity="0.8"/>`);for(let e of[...m.bends,...m.lanes])u.push(`<path d="${e.d}" fill="none" stroke="${h(e.i,e.k)}" stroke-width="${M(p)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((m,h)=>{let{x:g,y:_}=d[h],v=m.tone?N(m.tone,r,mi(e,m.lane,n)):mi(e,m.lane,n);if(m.type===`highlight`){let e=s*1.1;u.push(`<rect x="${M(g-e)}" y="${M(_-e)}" width="${M(e*2)}" height="${M(e*2)}" rx="${M(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${M(p)}"/>`)}else if(m.type===`reverse`){let e=s*.55;u.push(`<circle cx="${M(g)}" cy="${M(_)}" r="${M(s)}" fill="${c}" stroke="${v}" stroke-width="${M(p)}"/><path d="M${M(g-e)},${M(_-e)}L${M(g+e)},${M(_+e)}M${M(g+e)},${M(_-e)}L${M(g-e)},${M(_+e)}" stroke="${v}" stroke-width="${M(p*.8)}" stroke-linecap="round"/>`)}else m.merge?u.push(`<circle cx="${M(g)}" cy="${M(_)}" r="${M(s*1.05)}" fill="${v}"/><circle cx="${M(g)}" cy="${M(_)}" r="${M(s*.4)}" fill="${c}"/>`):m.pick===void 0?u.push(`<circle cx="${M(g)}" cy="${M(_)}" r="${M(s)}" fill="${c}" stroke="${v}" stroke-width="${M(p)}"/>`):u.push(`<circle cx="${M(g)}" cy="${M(_)}" r="${M(s)}" fill="${c}" stroke="${v}" stroke-width="${M(p)}" stroke-dasharray="${M(p*1.2)} ${M(p)}"/>`);if(i.vertical){let s=t.x+i.textX;m.id&&(u.push(`<text x="${M(s)}" y="${M(_)}" dominant-baseline="central" font-size="${M(a)}" font-family="${j(o)}" fill="${r.node.sub}">${j(m.id)}</text>`),s+=n.measure(m.id,a,400,!0)+a*.6);for(let t of i.heads.get(h)??[]){let r=t.label??t.name;u.push(f(s,_,r,mi(e,t.lane,n),!1,`start`)),s+=i.pillW(r)+a*.4}for(let e of m.tags)u.push(f(s,_,e,v,!0,`start`)),s+=i.pillW(e)+a*.4;m.msg&&u.push(`<text x="${M(s)}" y="${M(_)}" dominant-baseline="central" font-size="${M(a)}" xml:space="preserve">${be(A(m.msg),l,r,m.merge)}</text>`)}else m.tags.forEach((e,t)=>u.push(f(g,_-a*1.45-t*a*1.5,e,v,!0,`middle`))),m.msg&&u.push(`<text x="${M(g)}" y="${M(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a)}" stroke="${c}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${be(A(m.msg),l,r,m.merge)}</text>`)}),u.join(``)}var Si={name:`git`,panels:[{name:`git`,guide:'`commit ["msg"] [tag: v1, id: a1b2, color, highlight|reverse]`, `branch name [from <branch|commit id|tag>] [color, order: 2, label: "…"]` (creates and checks out), `checkout name` / `switch name`, `merge name ["msg"] [tag: v2]`, `cherry-pick <id|tag|branch>`, `tag v1`. Starts on `main` (`[main: trunk]` renames it); `order` moves a lane.',layoutParts:"a branch name (its lane), a commit (id, first tag or `c<n>`; a branch name wins), `<commit>^1` / `^2` (the bend from its first / second parent), `<commit>^pick`",syntax:`git id "Title" [direction: down] { commit "msg" [tag: v1, id: a1, highlight] / branch name [from v1, order: 0, label: "…"] / checkout main / merge name / cherry-pick a1 }`,parse:pi,options:{direction:[`right`,`down`]},parts:e=>[...e.branches.filter(e=>e.at!==void 0).map(e=>({id:e.name,label:e.label??e.name,kind:`branch`,tone:e.tone})),...hi(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:Nn((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[hi(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=pn(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=_i(e,t);return{w:n.w,h:n.h}},render:xi,handles(e,t,n){if(!e.commits.length)return[];let r=_i(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=bi(e,r,t),s=e=>r.lanePos[r.slot.get(e.lane)];return[...r.used.map(e=>({part:e.name,...r.vertical?{x:t.x+r.laneW/2+s(e),y:t.y+r.h}:{x:t.x+r.labelW-r.fs*.6,y:t.y+r.top+s(e)},axis:a,title:`move lane ${e.name}`})),...r.pos.map((e,n)=>({part:r.parts[n],x:t.x+e.x,y:t.y+e.y,axis:i,title:`move commit ${r.parts[n]}`})),...o.bends.map(e=>({part:e.part,...e.handle,axis:i,title:`move bend`})),...o.picks.map(e=>({part:e.part,...e.handle,title:`move cherry-pick line`}))]}}]},Ci=[`box`,`pill`,`plain`,`circle`],wi=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],Ti=/^(?:[-*+]\s+)?(.*?)(?:\s*\[([^\]]*)\])?$/,Ei=e=>R(e??``);function Di(e,t,n){let r=null,i=0,a=[];return e.forEach((e,t)=>{let o=e.trim();if(!o)return;let s=e.match(/^\s*/)[0].replace(/\t/g,` `).length,c=o.match(Ti),l=Ei(c[2]);l.shape&&!Ci.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${Ci.join(`, `)})`);let u={text:c[1].trim(),tone:l.color,shape:l.shape,line:t,children:[]};if(!u.text)return n(t,`mindmap: a node needs some text`);if(!r)r=u,i=s,a.push({indent:s,node:u});else{for(s<=i&&(n(t,`mindmap: "${u.text}" is not indented under the root "${r.text}"; a map has one root`),s=i+1);a.length>1&&a[a.length-1].indent>=s;)a.pop();a[a.length-1].node.children.push(u),a.push({indent:s,node:u})}}),r}function Oi(e,t=[]){t.push(e);for(let n of e.children)Oi(n,t);return t}function ki(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return e.map((e,n)=>/^[\w-]+$/.test(e.text)&&t.get(e.text)===1&&!/^n\d+$/.test(e.text)?e.text:`n${n+1}`)}var Ai=Mn(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.9,o=[`right`,`left`,`down`].includes(i.layout)?i.layout:`both`,s=o===`down`,c=i.colors===`mono`,l=Oi(e),u=ki(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=new Map,p=(e,t,i,o)=>{let s=Ci.includes(e.shape??``)?e.shape:t===0?`pill`:t===1?`box`:`plain`,l=t===0?a*1.2:t===1?a:a*.92,u=t===0?700:t===1?600:400,m=P(A(e.text),l,n.mono,r,u),h=s===`plain`?{x:a*.15,y:a*.3}:{x:l*(t?.8:1.1),y:l*.5},g=m+h.x*2,_=l*1.25+h.y*2;s===`circle`&&(g=_=Math.max(g,_));let v={node:e,part:d.get(e),depth:t,side:0,color:e.tone??i,shape:s,font:l,weight:u,x:0,y:0,w:g,h:_,parent:o};f.set(e,v),e.children.forEach((e,n)=>p(e,t+1,e.tone??(t===0?c?void 0:wi[n%wi.length]:v.color),v))};p(e,0,e.tone);let m=e=>s?a*.8:e<=1?a*.9:a*.35,h=(e,n,r)=>n?Math.max(-m(r)*.75,t.offsets[d.get(e)]?.x??0):0,g=e=>s?e.w:e.h,_=new Map,v=(e,t=e.children)=>{let n=f.get(e),r=0;t.forEach((e,t)=>{r+=v(e)+(t?m(n.depth):0)+h(e,t,n.depth)});let i=Math.max(g(n),r);return t===e.children&&_.set(e,i),i};v(e);let y=e.children,b=y,x=[];if(o===`left`)[b,x]=[[],y];else if(o===`both`&&y.length>1){let e=y.reduce((e,t)=>e+_.get(t),0),t=0,n=1,r=1/0;for(let i=1;i<y.length;i++){t+=_.get(y[i-1]);let a=Math.abs(e-2*t);a<r&&([r,n]=[a,i])}b=y.slice(0,n),x=y.slice(n)}let S=e=>s?a*1.9:e===0?a*2.6:a*1.7,C=(e,t,n)=>{let r=v(e.node,t),i=(s?e.x+e.w/2:e.y+e.h/2)-r/2;t.forEach((t,r)=>{i+=(r?m(e.depth):0)+h(t,r,e.depth);let a=f.get(t),o=_.get(t);a.side=s?0:n,s?(a.x=i+o/2-a.w/2,a.y=e.y+e.h+S(e.depth)):(a.y=i+o/2-a.h/2,a.x=n>0?e.x+e.w+S(e.depth):e.x-S(e.depth)-a.w),i+=o,C(a,t.children,n)})},w=f.get(e);C(w,b,1),C(w,x,-1);let T=l.map(e=>f.get(e)),E=Math.min(...T.map(e=>e.x)),D=Math.min(...T.map(e=>e.y));for(let e of T)e.x-=E,e.y-=D;return{all:T,down:s,w:Math.max(...T.map(e=>e.x+e.w)),h:Math.max(...T.map(e=>e.y+e.h))}}),ji=(e,t)=>t?N(t,e,e.accent):e.accent;function Mi(e,t,n){if(!e)return``;let r=n.theme,i=Ai(e,n),a=[],o=[],s=e=>t.x+e,c=e=>t.y+e,l=(e,t)=>i.down?[e.x+e.w/2,t?e.y+e.h:e.y]:[(t?e.side>=0:e.side<0)?e.x+e.w:e.x,e.shape===`plain`?e.y+e.h:e.y+e.h/2];for(let e of i.all){let t=ji(r,e.color);if(e.parent){let n=l(e.parent,!0);!i.down&&e.parent.depth===0&&(n[0]=e.side<0?e.parent.x:e.parent.x+e.parent.w);let[r,o]=n,[u,d]=l(e,!1),f=Math.max(1.4,3.6-e.depth*.7),p=i.down?`M${M(s(r))},${M(c(o))}C${M(s(r))},${M(c((o+d)/2))} ${M(s(u))},${M(c((o+d)/2))} ${M(s(u))},${M(c(d))}`:`M${M(s(r))},${M(c(o))}C${M(s((r+u)/2))},${M(c(o))} ${M(s((r+u)/2))},${M(c(d))} ${M(s(u))},${M(c(d))}`;a.push(`<path d="${p}" fill="none" stroke="${t}" stroke-width="${M(f)}" stroke-linecap="round" opacity="0.9"/>`)}let u=e.color?r.tone(e.color):void 0,d=e.depth===0&&!u?r.node.fill:u?.fill??r.node.fill,f=e.depth===0&&!u?r.accent:u?.stroke??r.node.stroke,p=e.shape===`plain`?r.node.text:u?.text??r.node.text,m=s(e.x),h=c(e.y);if(e.shape===`plain`)o.push(`<path d="M${M(m)},${M(h+e.h)}H${M(m+e.w)}" stroke="${t}" stroke-width="${M(Math.max(1.4,3.6-e.depth*.7))}" stroke-linecap="round"/>`);else{let t=e.shape===`pill`||e.shape===`circle`?e.h/2:Math.min(r.radius+2,e.h/2);o.push(`<rect x="${M(m)}" y="${M(h)}" width="${M(e.w)}" height="${M(e.h)}" rx="${M(t)}" fill="${d}" stroke="${f}" stroke-width="${e.depth===0?2.5:1.5}"/>`)}let g=e.shape===`plain`?h+e.h/2-n.fs*.05:h+e.h/2;o.push(`<text x="${M(m+e.w/2)}" y="${M(g)}" dominant-baseline="central" text-anchor="middle" font-size="${M(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${be(A(e.node.text),{text:p,sub:r.node.sub,stroke:f},r)}</text>`)}return a.join(``)+o.join(``)}var Ni={name:`mindmap`,panels:[{name:`mindmap`,guide:"indentation is the tree, the first line the root; `-` / `*` bullets are optional. A trailing `[color]` tints a subtree, `[shape: box|pill|plain|circle]` changes one node.",layoutParts:"a node by its one-word text, else `n<k>`, adds room before it among its siblings",syntax:`mindmap id "Title" [layout: both] { Root\\n Branch [green]\\n Leaf }`,options:{layout:[`both`,`right`,`left`,`down`],colors:[`branches`,`mono`]},parse:Di,measure(e,t){if(!e)return{w:0,h:0};let n=Ai(e,t);return{w:n.w,h:n.h}},render:Mi,parts(e){if(!e)return[];let t=Oi(e),n=new Map([[e,0]]);for(let e of t)for(let t of e.children)n.set(t,n.get(e)+1);return ki(t).map((e,r)=>({id:e,label:t[r].text,kind:n.get(t[r])===0?`root`:n.get(t[r])===1?`branch`:`node`,tone:t[r].tone}))},editPart:Nn((e,t,n,r)=>{if(!r)return null;let i=Oi(r),a=i[ki(i).indexOf(t)];if(!a)return null;let o=[...e],s=e[a.line],c=s.match(/\s*\[([^\]]*)\]\s*$/),{color:l,...u}=Ei(c?.[1]),d=gn(n?{color:n,...u}:u);return o[a.line]=(c?s.slice(0,c.index):s.trimEnd())+(d?` [${d}]`:``),o}),handles(e,t,n){if(!e)return[];let r=Ai(e,n),i=[];for(let e of r.all)if(e.parent&&e.parent.node.children[0]!==e.node){if(e.parent.depth===0&&e.parent.node.children.indexOf(e.node)>0){let t=r.all.find(t=>t.node===e.parent.node.children[e.parent.node.children.indexOf(e.node)-1]);if(t&&t.side!==e.side)continue}i.push({part:e.part,x:t.x+(r.down?e.x:e.side<0?e.x+e.w:e.x),y:t.y+e.y+e.h/2,axis:r.down?`x`:`y`,title:`move ${e.node.text}`})}return i}}]},Pi=864e5,Fi=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Ii=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,Li=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,Ri=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function zi(e){let t=e.trim().match(/^(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T](\d{1,2}):(\d{2}))?$/);if(!t)return NaN;let[n,r,i,a=`0`,o=`0`]=t.slice(1),s=Date.UTC(+n,r-1,+i,+a,+o),c=new Date(s);return c.getUTCMonth()===r-1&&c.getUTCDate()===+i?s:NaN}function Bi(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:Pi,w:7*Pi}[t[2].toLowerCase()]:NaN}function Vi(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s)return;let c=s.match(Ri);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?R(t[2]).color:void 0);return}let[l,u]=fn(s),d=l.match(Ii);if(!d)return n(t,`gantt: cannot read "${s}" (expected "id: 2025-01-06, 5d" or "--- Section ---")`);let[,f,p,m,h]=d;r.some(e=>e.id===f)&&n(t,`gantt: task "${f}" is defined twice`);let g={...R(m),...u},_=g.milestone===`true`,v={line:t,date:NaN,after:[],len:NaN,endDate:NaN},y=h.split(`,`).map(e=>e.trim()).filter(Boolean),b=0,x=y[0]??``;/^after\s/i.test(x)?(v.after=x.slice(6).trim().split(/\s+/),b=1):Number.isNaN(zi(x))?x&&Number.isNaN(Bi(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=zi(x),b=1);let S=y[b];S===void 0?!_&&x&&n(t,`gantt: task "${f}" needs a length, e.g. "${x}, 3d"`):(v.len=Bi(S),Number.isNaN(v.len)&&(v.endDate=zi(S),Number.isNaN(v.endDate)&&n(t,`gantt: "${S}" is not a length (3h, 5d, 2w) or an end date`)));let C=g.progress===void 0?NaN:parseFloat(g.progress)/(g.progress.endsWith(`%`)?100:1);g.progress!==void 0&&!(C>=0&&C<=1)&&n(t,`gantt: progress "${g.progress}" must be 0% to 100%`),r.push({id:f,label:p?.replace(/\\(.)/g,`$1`)??f,tone:g.color??void 0,progress:Math.min(1,Math.max(0,C)),owner:g.owner,done:g.done===`true`,active:g.active===`true`,crit:g.crit===`true`,milestone:_,start:NaN,end:NaN,after:v.after,section:a.length-1}),i.push(v)});let s=new Map(r.map((e,t)=>[e.id,t])),c=r.map(()=>0),l=i.map(e=>e.date).filter(e=>!Number.isNaN(e)),u=l.length?Math.min(...l):Date.UTC(2025,0,1),d=e=>{let t=r[e];if(c[e]===2)return t.end;if(c[e]===1)return n(i[e].line,`gantt: "${t.id}" depends on itself through "after"`),u;c[e]=1;let a=i[e],o=a.date;if(a.after.length){let e=a.after.flatMap(e=>{let t=s.get(e);return t===void 0?(n(a.line,`gantt: "after ${e}": no task "${e}"`),[]):[d(t)]});o=e.length?Math.max(...e):u}else Number.isNaN(o)&&(e>0?o=d(e-1):(n(a.line,`gantt: the first task needs a start date`),o=u));return t.start=o,t.end=t.milestone?o:Number.isNaN(a.len)?Number.isNaN(a.endDate)?o+Pi:Math.max(o,a.endDate):o+a.len,c[e]=2,t.end};return r.forEach((e,t)=>d(t)),{tasks:r,sections:a,sectionTones:o,min:r.length?Math.min(...r.map(e=>e.start)):0,max:r.length?Math.max(...r.map(e=>e.end)):0}}function Hi(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!Ri.test(r)&&Ii.test(fn(r)[0])&&t.push(n)}),t}function Ui(e){let t=v(e);if(!t)return`#fff`;let[n,r,i]=[1,3,5].map(e=>parseInt(t.slice(e,e+2),16));return .299*n+.587*r+.114*i>150?`#111827`:`#fff`}var Wi=e=>{let t=new Date(e);return`${Fi[t.getUTCMonth()]} ${t.getUTCDate()}`},Gi=e=>{let t=e/Pi;return t<1?`${Math.round(e/36e5*10)/10}h`:t>=14&&t%7==0?`${t/7}w`:`${Math.round(t*10)/10}d`};function Ki(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/Pi)*Pi;if(a>=7)for(;new Date(o).getUTCDay()!==1;)o+=Pi;for(;o<=t;o+=a*Pi)i.push({t:o,label:Wi(o)});return i}for(let a of[1,2,3,6,12,24,60]){if(a*30.4*n<r)continue;let o=new Date(e),s=o.getUTCFullYear(),c=o.getUTCMonth()+(o.getUTCDate()>1||o.getUTCHours()?1:0);c=Math.ceil(c/a)*a;let l=!0;for(;;){s+=Math.floor(c/12),c%=12;let e=Date.UTC(s,c,1);if(e>t)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${Fi[c]} ${s}`:Fi[c]}),l=!1,c+=a}return i}return i}var qi={compact:1.6,normal:2.1,loose:2.7},Ji=Mn(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(qi[i.density??``]??qi.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>P(A(e),a,n.mono,r,t),f=e=>r(e,a*.82,500,n.mono),p=e=>e.done?`${e.label} ✓`:e.label,m=Math.max(l?0:a*4,...l?[]:e.tasks.map(e=>d(p(e))),...e.sections.map(e=>d(e,700))),h=m?m+a*1.4:a*.5,g=Math.floor(e.min/Pi)*Pi,_=Math.max(g+Pi,Math.ceil(e.max/Pi)*Pi),v=(_-g)/Pi,y={day:a*2.4,week:a*.8,month:a*.22}[i.scale??``]??Math.min(a*3,Math.max(a*.35,a*38/v)),b=e=>h+(e-g)/Pi*y,x=v*y,S=[],C=c,w=-1;for(e.tasks.forEach((e,n)=>{for(;w<e.section;)w++,S.push({y:C,section:w}),C+=s;C+=Math.max(-o*.4,t.offsets[e.id]?.x??0),S.push({y:C,task:n}),C+=o});w<e.sections.length-1;)S.push({y:C,section:++w}),C+=s;let T=Math.max(a*1.25,o*.62),E=Math.min(T,a*1.3)*.5,D=a*.5,ee=h+x;return{fs:a,rowH:o,secH:s,axisH:c,labelW:h,min:g,max:_,dayW:y,x:b,plotW:x,rows:S,barH:T,ms:E,texts:e.tasks.map(e=>{let t=Number.isNaN(e.progress)||e.milestone?``:`${Math.round(e.progress*100)}%`,n=[i.notes===`none`?``:i.notes===`dates`&&!e.milestone?`${Wi(e.start)} – ${Wi(e.end)}`:e.milestone?Wi(e.start):Gi(e.end-e.start),t].filter(Boolean).join(` · `),r=b(e.start),o=e.milestone?r+E:b(e.end),s=e.milestone||u?0:o-r-D*2,c=i.bars===`solid`&&t?-1:s,m=[],h=[],g=l?p(e):``,_=g?d(g,500):0;g&&_<=s?(m.push({x:r+D,s:g,kind:`label`,w:_}),n&&f(n)<=c-_-D?m.push({x:o-D,s:n,kind:`note`,end:!0,w:f(n)}):n&&h.push({s:n,kind:`note`})):(g&&h.push({s:g,kind:`label`}),n&&!g&&f(n)<=c?m.push({x:r+D,s:n,kind:`note`,w:f(n)}):n&&h.push({s:n,kind:`note`})),e.owner&&h.push({s:e.owner,kind:`note`});let v=o+a*.9,y=h.map(e=>{let t=e.kind===`label`?d(e.s):f(e.s),n={...e,x:v,w:t};return v+=t+a*.7,n});return y.length&&(ee=Math.max(ee,v-a*.7)),{inner:m,after:y}}),name:p,w:ee,h:C}});function Yi(e,t){let n=e.filter((t,n)=>!n||Math.hypot(t[0]-e[n-1][0],t[1]-e[n-1][1])>.5),r=`M${M(n[0][0])},${M(n[0][1])}`;for(let e=1;e<n.length-1;e++){let[i,a,o]=[n[e-1],n[e],n[e+1]],s=Math.hypot(a[0]-i[0],a[1]-i[1]),c=Math.hypot(o[0]-a[0],o[1]-a[1]),l=Math.min(t,s/2,c/2),u=[a[0]-(a[0]-i[0])/s*l,a[1]-(a[1]-i[1])/s*l],d=[a[0]+(o[0]-a[0])/c*l,a[1]+(o[1]-a[1])/c*l];r+=`L${M(u[0])},${M(u[1])}Q${M(a[0])},${M(a[1])} ${M(d[0])},${M(d[1])}`}let i=n[n.length-1];return`${r}L${M(i[0])},${M(i[1])}`}function Xi(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=Ji(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},p=(e,t,n,i,a,s=!1)=>`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${M(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${be(A(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${M(o*.82)}" font-weight="500" fill="${r}">${j(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3)for(let e=a.min;e<a.max;e+=Pi){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${M(c(e))}" y="${M(t.y+a.axisH*.8)}" width="${M(a.dayW)}" height="${M(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/Pi)*Pi:zi(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${Wi(h)}`:``,v=_?n.measure(_,o*.72,650,r.mono)+o*.8:0,y=t.x+a.labelW+a.plotW,b=Math.max(t.x+a.labelW,Math.min(c(h)-v/2,y-v));for(let e of Ki(a.min,a.max,a.dayW,o*5.5)){let s=c(e.t),f=n.measure(e.label,o*.82,400,r.mono),p=Math.max(t.x+a.labelW+f/2,Math.min(s,y-f/2)),m=_&&p+f/2>b-o*.4&&p-f/2<b+v+o*.4;i.grid!==`none`&&d.push(`<path d="M${M(s)},${M(t.y+a.axisH*.75)}V${M(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${M(p)}" y="${M(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${M(o*.82)}" fill="${r.node.sub}">${j(e.label)}</text>`)}d.push(`<path d="M${M(t.x+a.labelW)},${M(t.y+a.axisH*.75)}H${M(t.x+a.labelW+a.plotW)}" stroke="${u}" stroke-width="1.5"/>`);let x=new Map;for(let e of a.rows)e.task!==void 0&&x.set(e.task,e.y);let S=e=>t.y+x.get(e),C=e=>S(e)+a.rowH/2,w=t=>t.tone??e.sectionTones[t.section]??(t.crit?`red`:void 0),T=a.labelW+a.plotW;if(i.rows!==`plain`){let e=0;for(let n of a.rows)n.section===void 0?e++%2&&d.push(`<rect x="${M(t.x-o*.4)}" y="${M(t.y+n.y)}" width="${M(T+o*.4)}" height="${M(a.rowH)}" rx="3" fill="${u}" opacity="0.16"/>`):e=0}for(let n of a.rows)if(n.section!==void 0){let s=t.y+n.y+a.secH/2,l=e.sectionTones[n.section],f=l?N(l,r,r.node.sub):r.node.sub;d.push(`<path d="M${M(t.x)},${M(t.y+n.y+1)}H${M(t.x+T)}" stroke="${u}" stroke-width="1" opacity="0.6"/>`,p(t.x,s,e.sections[n.section],700,f));let m=e.tasks.filter(e=>e.section===n.section);if(m.length&&i.summary!==`hide`){let e=c(Math.min(...m.map(e=>e.start))),t=Math.max(e+2,c(Math.max(...m.map(e=>e.end)))),n=o*.32;d.push(`<path d="M${M(e)},${M(s+n*1.6)}V${M(s-n/2)}H${M(t)}V${M(s+n*1.6)}" fill="none" stroke="${f}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${M(e)}" y="${M(s-n/2)}" width="${M(t-e)}" height="${M(n)}" fill="${f}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${M(c(h))},${M(t.y+a.axisH*.35)}V${M(l)}" stroke="${N(`red`,r,r.accent)}" stroke-width="1.5" stroke-dasharray="4 3"/>`),i.arrows!==`hide`){let t=new Map(e.tasks.map((e,t)=>[e.id,t])),n=o*.6,s=r.edge.stroke,l=Math.min(r.edgeWidth,1.5),u=4+l*2;e.tasks.forEach((r,f)=>{for(let p of r.after){let m=t.get(p);if(m===void 0||m===f)continue;let h=e.tasks[m],g=h.milestone?c(h.start)+a.ms:c(h.end),_=C(m),v=r.milestone?c(r.start)-a.ms:c(r.start),y=C(f),b=v-u*.78,x;if(i.arrows===`curved`){let e=Math.max(o*.9,Math.abs(b-g)/2);x=`M${M(g)},${M(_)}C${M(g+e)},${M(_)} ${M(b-e)},${M(y)} ${M(b)},${M(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=Yi([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=Yi([[g,_],[g+n,_],[g+n,e],[b-n,e],[b-n,y],[b,y]],o*.35)}d.push(`<path d="${x}" fill="none" stroke="${s}" stroke-width="${M(l)}" stroke-linejoin="round"/>`,ht({x:v,y},0,`arrow`,s,l,u))}})}let E=i.bars===`solid`||i.bars===`outline`||i.bars===`thin`?i.bars:`soft`,D=new Map,ee=e=>{let n=`${e}|${E}`,r=D.get(n);if(!r){r=`mg-hatch-${Math.round(t.x)}-${Math.round(t.y)}-${D.size}`,D.set(n,r);let i=E===`solid`?Ui(e):e;d.push(`<defs><pattern id="${r}" patternUnits="userSpaceOnUse" width="7" height="7" patternTransform="rotate(45)"><rect width="3" height="7" fill="${i}" opacity="${E===`solid`?.28:.22}"/></pattern></defs>`)}return r};if(e.tasks.forEach((e,n)=>{let s=C(n),l=w(e),u=l?r.tone(l):void 0,f=N(l,r,r.accent);i.labels!==`bar`&&d.push(p(t.x,s,a.name(e),400,e.done?r.node.sub:void 0));let h=e.done?` opacity="0.55"`:``,{inner:g,after:_}=a.texts[n];for(let n of _)d.push(n.kind===`label`?p(t.x+n.x,s,n.s,400,e.done?r.node.sub:void 0):m(t.x+n.x,s,n.s,r.node.sub));if(e.milestone){let t=c(e.start);d.push(`<path d="M${M(t)},${M(s-a.ms)}L${M(t+a.ms)},${M(s)}L${M(t)},${M(s+a.ms)}L${M(t-a.ms)},${M(s)}Z" fill="${f}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"${h}/>`);return}let v=c(e.start),y=Math.max(2,c(e.end)-v),b=E===`thin`?Math.max(4,o*.38):a.barH,x=s-b/2,S=E===`thin`?b/2:Math.min(b/3,y/2),T=e.crit?N(`red`,r,f):f,D=!Number.isNaN(e.progress),O=(e,t)=>`<rect x="${M(v)}" y="${M(x)}" width="${M(e)}" height="${M(b)}" rx="${M(S)}" ${t}${h}/>`,te=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,ne=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,re=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(O(y,`fill="${ne}"${re}${te?` stroke="${T}" stroke-width="${te}"`:``}`));let ie=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;ie&&d.push(O(ie,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-ie>2&&d.push(`<rect x="${M(v+ie)}" y="${M(x)}" width="${M(y-ie)}" height="${M(b)}" rx="${M(S)}" fill="url(#${ee(f)})"/>`);for(let e of g){let n=t.x+e.x+(e.end?0:e.w),i=E===`solid`&&(!D||n<=v+ie-o*.2)?Ui(f):u?.text??r.node.text;d.push(e.kind===`label`?p(t.x+e.x,s,e.s,500,i,e.end):m(t.x+e.x,s,e.s,i,e.end))}}),g){let e=N(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${M(b)}" y="${M(n-o*.55)}" width="${M(v)}" height="${M(o*1.1)}" rx="${M(o*.55)}" fill="${e}"/>`,`<text x="${M(b+v/2)}" y="${M(n)}" dominant-baseline="central" text-anchor="middle" font-size="${M(o*.72)}" font-weight="650" fill="${Ui(e)}">${j(_)}</text>`)}return d.join(``)}var Zi={name:`gantt`,panels:[{name:`gantt`,guide:'`id "Label" [color, done, active, crit, milestone, progress: 60%, owner: ana]: start, length`. start: a date or `after a b` (empty: after the task above); length: 3h, 5d, 2w or an end date. `--- Section [color] ---` groups rows.',layoutParts:`a task id adds room above its row`,syntax:`gantt id "Title" [today: 2025-01-20] { api "Build API": 2025-01-06, 2w }`,options:{today:[],scale:[`day`,`week`,`month`],bars:[`soft`,`solid`,`outline`,`thin`],labels:[`left`,`bar`],notes:[`length`,`dates`,`none`],density:[`compact`,`normal`,`loose`],rows:[`striped`,`plain`],grid:[`show`,`none`],summary:[`show`,`hide`],weekends:[`hide`,`show`],arrows:[`elbow`,`curved`,`hide`]},parse:Vi,measure(e,t){if(!e.tasks.length)return{w:0,h:0};let n=Ji(e,t);return{w:n.w,h:n.h}},render:Xi,parts:e=>e.tasks.map(e=>({id:e.id,label:e.label===e.id?e.id:`${e.id}: ${e.label}`,kind:e.milestone?`milestone`:`task`,tone:e.tone})),editPart:Nn((e,t,n,r)=>{let i=Hi(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=hn(e[i],Li,`color`,n),a}),handles(e,t,n){if(!e.tasks.length)return[];let r=Ji(e,n);return r.rows.flatMap(n=>n.task===void 0?[]:[{part:e.tasks[n.task].id,x:t.x+r.labelW-r.fs*.5,y:t.y+n.y+2,axis:`y`,title:`move ${e.tasks[n.task].id}`}])}}]},Qi=/^([xy])-axis\s*:?\s*(.*)$/i,$i=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,ea=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,ta=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,na=[`teal`,`blue`,`slate`,`amber`],ra=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function ia(e,t,n){let r={x:[``,``],y:[``,``],q:[{text:``},{text:``},{text:``},{text:``}],points:[],scale:1},i=[];e.forEach((e,t)=>{let a=e.trim();if(!a)return;let o=a.match(Qi);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=fn(a,mn),l=s.match($i);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??R(l[2]).color};return}let u=s.match(ea);if(!u)return n(t,`quadrant: cannot read "${a}" (expected "Name: x, y", "q1: label" or "x-axis low -> high")`);i.push({name:u[1].trim().replace(/^"(.*)"$/,`$1`),tone:c.color??R(u[2]).color,x:+u[3],y:+u[4],line:t})});let a=i.some(e=>e.x>1||e.y>1)?100:1;r.scale=a;let o=new Set;return i.forEach((e,t)=>{let i=e.x/a,s=e.y/a;(i<0||i>1||s<0||s>1)&&(n(e.line,`quadrant: "${e.name}" is outside the chart (values go from 0 to ${a})`),i=Math.min(1,Math.max(0,i)),s=Math.min(1,Math.max(0,s)));let c=ra(e.name);(!c||o.has(c)||/^(p\d+|size)$/.test(c))&&(c=`p${t+1}`),o.add(c),r.points.push({name:e.name,id:c,x:i,y:s,tone:e.tone,line:e.line})}),r}function aa(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!Qi.test(r)&&!$i.test(r)&&ea.test(fn(r,mn)[0])&&t.push(n)}),t}function oa(e,t,n,r,i){let a=[...e],o=e=>Number(e.toFixed(5)),s=t.scale===100&&o(r*100)<=1&&o(i*100)<=1&&t.points.every(e=>e===n||e.x<=.01&&e.y<=.01);for(let c of t.points){if(c!==n&&!s)continue;let l=e[c.line],[u]=fn(l,mn),d=new RegExp(ea,`d`).exec(u.trimEnd());if(!d?.indices?.[3]||!d.indices[4])return null;let[f,p]=d.indices[3],[m,h]=d.indices[4],g=s?1:t.scale,_=o((c===n?r:c.x)*g),v=o((c===n?i:c.y)*g);a[c.line]=l.slice(0,f)+_+l.slice(p,m)+v+l.slice(h)}return a}var sa=Mn(function(e,t){let{theme:n,measure:r}=t,i=t.fs*.88,a=t.offsets.size??{x:0,y:0},o=Math.max(i*12,i*24+(a.x+a.y)/2),s=e.y[0]||e.y[1]?i*2:0,c=e.x[0]||e.x[1]?i*2:0,l=i*.38,u=i*.9,d=e.points.map(e=>{let n=t.offsets[e.id]??{x:0,y:0};return{x:Math.min(o,Math.max(0,e.x*o+n.x)),y:Math.min(o,Math.max(0,(1-e.y)*o+n.y))}}),f=d.map(e=>({x:e.x-l,y:e.y-l,w:l*2,h:l*2}));e.q.forEach((e,t)=>{if(!e.text)return;let a=P(A(e.text),i,n.mono,r,700),s=t===0||t===3?o*.75:o*.25,c=t<2?i*1.1:o/2+i*1.1;f.push({x:s-a/2,y:c-i*.6,w:a,h:i*1.2})});let p=(e,t)=>Math.max(0,Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)),m=l+4,h=e.points.map(()=>({x:0,y:0,w:0,h:0})),g=e.points.map((e,t)=>t).sort((e,t)=>d[e].x-d[t].x||d[e].y-d[t].y);for(let t of g){let i=d[t],a=P(A(e.points[t].name),u,n.mono,r),s=u*1.2,c=[{x:i.x+m,y:i.y-s/2,w:a,h:s},{x:i.x-m-a,y:i.y-s/2,w:a,h:s},{x:i.x-a/2,y:i.y-m-s,w:a,h:s},{x:i.x-a/2,y:i.y+m,w:a,h:s},{x:i.x+m*.7,y:i.y-m*.7-s,w:a,h:s},{x:i.x+m*.7,y:i.y+m*.7,w:a,h:s},{x:i.x-m*.7-a,y:i.y-m*.7-s,w:a,h:s},{x:i.x-m*.7-a,y:i.y+m*.7,w:a,h:s}],l=c[0],g=1/0;for(let e of c){let t=Math.max(0,-e.x)+Math.max(0,e.x+e.w-o)+Math.max(0,-e.y)+Math.max(0,e.y+e.h-o),n=f.reduce((t,n)=>t+p(e,n),0)+t*s*4;n<g-.01&&([l,g]=[e,n])}h[t]=l,f.push(l)}return{fs:i,lfs:u,S:o,left:s,bottom:c,r:l,pts:d,labels:h,w:s+o,h:o+c}});function ca(e,t,n){let r=n.theme,a=sa(e,n),{fs:o,S:s}=a,c=t.x+a.left,l=t.y,u=[],d={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},f=s/2,p=[[f,0],[0,0],[0,f],[f,f]];e.q.forEach((e,t)=>{let n=e.tone??na[t],a=r.tone(n)?.fill??i(n,r.dark?900:50)??r.node.fill;u.push(`<rect x="${M(c+p[t][0])}" y="${M(l+p[t][1])}" width="${M(f)}" height="${M(f)}" fill="${a}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=N(e.tone??na[t],r,r.node.sub);u.push(`<text x="${M(c+p[t][0]+f/2)}" y="${M(l+p[t][1]+o*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${M(o)}" font-weight="700" xml:space="preserve">${be(A(e.text),{...d,text:n},r)}</text>`)}),u.push(`<rect x="${M(c)}" y="${M(l)}" width="${M(s)}" height="${M(s)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${M(c+f)},${M(l)}V${M(l+s)}M${M(c)},${M(l+f)}H${M(c+s)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let m=(e,t,n,i)=>n?`<text x="${M(e)}" y="${M(t)}" dominant-baseline="central" text-anchor="middle" font-size="${M(o*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${M(e)} ${M(t)})"`:``}>${j(n)}</text>`:``,h=l+s+a.bottom/2;u.push(m(c+f/2,h,e.x[0],!1),m(c+f*1.5,h,e.x[1],!1));let g=t.x+a.left/2;return u.push(m(g,l+f*1.5,e.y[0],!0),m(g,l+f/2,e.y[1],!0)),e.points.forEach((e,t)=>{let n=N(e.tone,r,r.accent),{x:i,y:o}=a.pts[t],s=a.labels[t];u.push(`<circle cx="${M(c+i)}" cy="${M(l+o)}" r="${M(a.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${M(c+s.x)}" y="${M(l+s.y+s.h/2)}" dominant-baseline="central" font-size="${M(a.lfs)}" xml:space="preserve">${be(A(e.name),d,r)}</text>`)}),u.join(``)}var la={name:`quadrant`,panels:[{name:`quadrant`,guide:"`x-axis Low -> High`, `y-axis Low -> High`, `q1..q4 [color]: label` (q1 top right, counter-clockwise), points `Name [color]: x, y` from 0 to 1.",layoutParts:"a point by its name (lower case, `-` for spaces), else `p<n>`, moves by `DX DY`; `size DX DY` grows the plot",syntax:`quadrant id "Title" { x-axis Low -> High; q1: Quick wins; Search: 0.3, 0.8 }`,parse:ia,measure(e,t){let n=sa(e,t);return{w:n.w,h:n.h}},render:ca,parts:e=>[...e.q.map((e,t)=>({id:`q${t+1}`,label:e.text||`q${t+1}`,kind:`quadrant`,tone:e.tone})),...e.points.map(e=>({id:e.id,label:e.name,kind:`point`,tone:e.tone}))],editPart:Nn((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>$i.test(e.trim())&&e.trim()[1]===a[1]),i<0){let t=n?` [${n}]`:``;return[...e,`q${a[1]}${t}:`]}}else i=aa(e)[r.points.findIndex(e=>e.id===t)];if(i===void 0)return null;let o=[...e];return o[i]=hn(e[i],ta,`color`,n,mn),o}),handles(e,t,n){let r=sa(e,n),i=t.x+r.left;return[...e.points.map((n,a)=>({part:n.id,x:i+r.pts[a].x,y:t.y+r.pts[a].y,title:`move ${n.name}`,editPosition:(t,i)=>oa(t,e,n,Math.min(1,Math.max(0,n.x+i.x/r.S)),Math.min(1,Math.max(0,n.y-i.y/r.S)))})),{part:`size`,x:i+r.S,y:t.y+r.S,title:`resize`}]}}]},ua={high:`red`,medium:`amber`,low:`gray`};function da(e){let[t,n]=fn(e);return{text:t.trim(),props:n}}var fa=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``),pa=e=>e.match(/^\s*/)[0].length,ma=e=>!e.trim(),ha=/^[-*]\s+/;function ga(e,t,n){let r=[],i=Math.min(...e.filter(e=>!ma(e)).map(pa)),a,o=0,s=0,c=-1,l=new Set,u=(e,t)=>{e&&e.end<0&&(e.end=t)};return e.forEach((e,t)=>{if(ma(e))return;let d=e.trim(),f=pa(e),p=c;if(c=t,ha.test(d)){let e=r[r.length-1];if(!e)return n(t,`kanban: a "- card" needs a column above it`);u(a,p+1);let{text:i,props:c}=da(d.replace(ha,``)),l=[];for(let[e,r]of Object.entries(c))e!==`color`&&(e===`owner`?l.push({text:`@${r}`}):e===`ticket`?l.push({text:r,mono:!0,tone:`blue`}):e===`priority`?(ua[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:ua[r]??`gray`})):l.push({text:r===`true`?e:`${e}: ${r}`}));a={id:`k${++s}`,start:t,end:-1,text:i,tone:c.color,chips:l,details:[],props:c},o=f,e.cards.push(a);return}if(f>i&&a&&f>o){a.details.push(d);return}f>i&&n(t,`kanban: "${d}" is indented like a card; start cards with "- "`),u(a,p+1),u(r[r.length-1],p+1);let{text:m,props:h}=da(d),g=h.limit===void 0?void 0:Number(h.limit);g!==void 0&&!(g>=0)&&n(t,`kanban: limit expects a number, got "${h.limit}"`);let _=fa(m);(!_||l.has(_)||/^[ck]\d+$/.test(_))&&(_=`c${r.length+1}`),l.add(_),r.push({id:_,start:t,end:-1,title:m,tone:h.color,limit:g>=0?g:void 0,cards:[]}),a=void 0}),u(a,c+1),u(r[r.length-1],c+1),r}function _a(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=fn(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=gn(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}var va=[`owner`,`ticket`,`priority`];function ya(e,t,n){let r=n.findIndex(e=>e.id===t.id),i=n[r],a=i?-1:n.findIndex(e=>e.cards.some(e=>e.id===t.id)),o=n[a],s=o?o.cards.findIndex(e=>e.id===t.id):-1,c=o?.cards[s],l=i??c,u=t=>e.slice(t.start,t.end),d=t=>` `.repeat(t.cards[0]?pa(e[t.cards[0].start]):pa(e[t.start])+2),f=(t,n,r=u(t))=>{let i=[...e];return n>=t.end?(i.splice(n,0,...r),i.splice(t.start,t.end-t.start)):(i.splice(t.start,t.end-t.start),i.splice(n,0,...r)),i},p=(e,t)=>{if(!t)return{body:e};let n=ga(e,{},()=>{})[t[0]];return{body:e,id:t[1]===void 0?n?.id:n?.cards[t[1]<0?n.cards.length-1:t[1]]?.id}},m=i?[r]:[a,s];switch(t.op){case`set`:{if(!l)return null;let{key:r,value:i}=t;if(c&&r===`column`){let t=n.findIndex(e=>e.id===i),r=n[t];if(!r||r===o)return null;let a=d(r),s=pa(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,pa(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?va:[`limit`]).includes(r)))return null;let a=[...e];return a[l.start]=_a(e[l.start],(e,t)=>r===`text`?i?.trim()||e:(i===null||i===``?delete t[r]:t[r]=i,e)),p(a,m)}case`up`:case`down`:{let e=i?n:o?.cards??[],c=i?r:s,u=t.op===`up`?c-1:c+1;return!l||!e[u]?null:p(f(l,t.op===`up`?e[u].start:e[u].end),i?[u]:[a,u])}case`remove`:{if(!l)return null;let t=[...e];return t.splice(l.start,l.end-l.start),p(t)}case`add`:{let a=[...e];if(t.id===void 0){let t=n[0]?pa(e[n[0].start]):0;return a.splice(n.length?n[n.length-1].end:e.length,0,` `.repeat(t)+`New column`),p(a,[n.length])}return i?(a.splice(i.end,0,d(i)+`- New card`),p(a,[r,-1])):null}}}var ba=Mn(function(e,t){let{theme:n,measure:r}=t,i=t.fs*.88,a=i*.7,o=i*.6,s=i*.9,c=i*.55,l=i*2.4,u=i*.76,d=e=>r(e.text,u,600,e.mono||n.mono)+u*1.1,f=e=>{let t=e.chips.reduce((e,t)=>e+d(t)+i*.35,0);return{w:Math.max(P(A(e.text),i,n.mono,r,500),t,...e.details.map(e=>P(A(e),i*.88,n.mono,r))),h:a*1.7+i*1.2+(e.chips.length?i*1.5:0)+e.details.length*i*1.25}},p=e.map(e=>e.cards.map(f)),m=e=>e.limit===void 0?`${e.cards.length}`:`${e.cards.length}/${e.limit}`,h=Math.max(i*11,...e.map(e=>r(e.title,i,700,n.mono)+r(m(e),i*.8,600,n.mono)+i*3.2),...p.flat().map(e=>e.w+a*2+o*2)),g=[],_=0;e.forEach((e,n)=>{n&&(_+=s+Math.max(-s*.7,t.offsets[e.id]?.x??0)),g.push(_),_+=h});let v=Math.max(i*7,...p.map(e=>l+e.reduce((e,t)=>e+t.h+c,0)+o));return{fs:i,pad:a,cpad:o,gap:s,cardGap:c,headH:l,chipFs:u,chipW:d,sizes:p,badge:m,colW:h,at:g,w:_,h:v}});function xa(e,t,n){if(!e.length)return``;let r=n.theme,i=ba(e,n),{fs:a}=i,o=[],s={text:r.node.text,sub:r.node.sub,stroke:r.node.stroke},c=Math.min(r.radius,a*.6),l=N(`red`,r,r.accent);return e.forEach((e,u)=>{let d=t.x+i.at[u],f=t.y,p=e.tone?r.groupTone(e.tone):void 0,m=e.limit!==void 0&&e.cards.length>e.limit;o.push(`<rect x="${M(d)}" y="${M(f)}" width="${M(i.colW)}" height="${M(i.h)}" rx="${M(c+2)}" fill="${p?.fill??r.group.fill}" stroke="${m?l:p?.stroke??r.group.stroke}" stroke-width="${m?2:1}"/>`);let h=f+i.headH/2;o.push(`<circle cx="${M(d+i.cpad+a*.35)}" cy="${M(h)}" r="${M(a*.32)}" fill="${N(e.tone,r,r.node.sub)}"/>`,`<text x="${M(d+i.cpad+a*1.05)}" y="${M(h)}" dominant-baseline="central" font-size="${M(a)}" font-weight="700" xml:space="preserve">${be(A(e.title),{...s,text:p?.text??r.node.text},r)}</text>`);let g=i.badge(e),_=n.measure(g,a*.8,600,r.mono)+a*.9,v=d+i.colW-i.cpad-_;o.push(`<rect x="${M(v)}" y="${M(h-a*.6)}" width="${M(_)}" height="${M(a*1.2)}" rx="${M(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${M(v+_/2)}" y="${M(h)}" dominant-baseline="central" text-anchor="middle" font-size="${M(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${j(g)}</text>`);let y=f+i.headH;e.cards.forEach((e,t)=>{let n=i.sizes[u][t],l=d+i.cpad,f=i.colW-i.cpad*2,p=e.tone?r.tone(e.tone):void 0;o.push(`<rect x="${M(l)}" y="${M(y)}" width="${M(f)}" height="${M(n.h)}" rx="${M(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${M(l)}" y="${M(y+c/2)}" width="3.5" height="${M(n.h-c)}" rx="1.75" fill="${N(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${M(l+i.pad)}" y="${M(m)}" dominant-baseline="central" font-size="${M(a)}" font-weight="500" xml:space="preserve">${be(A(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${M(l+i.pad)}" y="${M(m-a*.6)}" dominant-baseline="central" font-size="${M(a*.88)}" xml:space="preserve">${be(A(t),s,r,!0)}</text>`);if(e.chips.length){let t=l+i.pad,n=m+a*.85;for(let s of e.chips){let e=i.chipW(s),c=s.tone?r.tone(s.tone):void 0;o.push(`<rect x="${M(t)}" y="${M(n-i.chipFs*.75)}" width="${M(e)}" height="${M(i.chipFs*1.5)}" rx="${M(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${M(t+e/2)}" y="${M(n)}" dominant-baseline="central" text-anchor="middle" font-size="${M(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${j(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}In(Ln,Gn,Yn,nr,vr,ir,Ir,Wr,ti,Si,Ni,Zi,la,{name:`kanban`,panels:[{name:`kanban`,guide:"a line at the outer indent is a column `Todo [color, limit: 3]`, `- text [owner: ana, ticket: X-1, priority: low|medium|high, color]` a card, deeper lines its details.",layoutParts:"a column by its title (lower case, `-` for spaces), else `c<n>`, adds room before it",syntax:`kanban id "Title" { Todo [gray]
8
+ - Write docs [owner: ana] }`,parse:ga,measure(e,t){if(!e.length)return{w:0,h:0};let n=ba(e,t);return{w:n.w,h:n.h}},render:xa,parts(e){let t=e.map(e=>e.id);return e.flatMap(e=>[{id:e.id,label:e.title,kind:`column`,tone:e.tone,fields:{text:[],limit:[]},values:{text:e.title,...e.limit!==void 0&&{limit:String(e.limit)}},actions:[`up`,`down`,`remove`,`add`],adds:`card`},...e.cards.map(n=>({id:n.id,label:n.text,kind:`card`,tone:n.tone,fields:{text:[],column:t,owner:[],ticket:[],priority:[``,`low`,`medium`,`high`]},values:{text:n.text,column:e.id,...n.props},actions:[`up`,`down`,`remove`]}))])},editPart:ya,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=ba(e,n);return e.slice(1).map((e,n)=>({part:e.id,x:t.x+r.at[n+1],y:t.y+r.headH/2,axis:`x`,title:`move ${e.title}`}))}}]});function Sa(e){let t=[],n=new Map;for(let r of e){let e=r.replace(/\s+$/,``),i=e.trim();if(!i){t.push({kind:`gap`});continue}if(/^-{3,}$/.test(i)){t.push({kind:`rule`});continue}let a=t[t.length-1],o=!1;for(let e of Pn.rows){let r=e.parse(i,a);if(r!=null){r!==!0&&(t.push(r),n.set(r,e)),o=!0;break}}if(o)continue;let s=e.indexOf(` || `);s>=0?t.push({kind:`text`,left:A(e.slice(0,s)),right:A(e.slice(s+4).trim())}):t.push({kind:`text`,left:A(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}var Ca=e=>Pn.rows.find(t=>t.kind===e.kind);function wa(e,t,n,r,i){let a=t*1.75,o={fs:t,lh:a,mono:n,measure:r,theme:i},s=[],c=[],l=0,u=0;for(let i of e){let e=a;if(i.kind===`text`){let e=i;l=Math.max(l,P(e.left,t,n,r)+(e.right?t*2+P(e.right,t,n,r):0))}else if(i.kind===`rule`)e=t*1.1;else if(i.kind===`gap`)e=t*.6;else{let t=Ca(i)?.measure(i,o)??{w:0,h:0};l=Math.max(l,t.w),e=t.h}s.push(u),c.push(e),u+=e}return{rows:e,fs:t,lh:a,mono:n,ys:s,hs:c,w:l,h:u}}function Ta(e,t,n){let r=e.caps?Math.round(e.fontSize*.8*10)/10:e.fontSize,i=e.caps?r*.12:0,a=e.label?(e.caps?e.label.toUpperCase():e.label).split(`
9
+ `):[],o=e.sub?e.sub.split(`
10
+ `):[],s=Math.round(e.fontSize*.82*10)/10,c=r*1.35,l=s*1.4,u=Math.round(r*1.15),d=e.caps?650:e.weight,f=(e,r,a)=>n(e,r,a,t.mono)+i*[...e].length,p=0;a.forEach((t,n)=>{p=Math.max(p,f(t,r,d)+(n===0&&e.icon?u+8:0))});for(let e of o)p=Math.max(p,n(e,s,400,t.mono));e.meta&&(p+=s*2.4+n(e.meta,s,400,t.mono)),!a.length&&e.meta&&(p=n(e.meta,s,400,t.mono));let m=a.length||e.meta?Math.max(a.length*c,e.meta?l:0)+(o.length?o.length*l+2:0):0,h=Math.round(e.fontSize*.86*10)/10,g=e.body?.length?wa(Sa(e.body),h,e.mono,n,t):void 0,_=!e.frameless&&!!g&&m>0,v=g&&m>0?_?21:8:0,y=e.frameless?4:14,b=e.frame?.trim().match(/^(\S+)\s*(.*)$/),x=b?Pn.frames.get(b[1].toLowerCase()):void 0,S=x?.inset(e.fontSize)??{top:0},C=S.top,w=S.bottom??0,T=x?Math.max(200,n(b[2],s,400,t.mono)+110):120,E=Math.max(p,g?.w??0)+y*2,D=m+v+(g?.h??0)+(e.frameless?y*2:y*1.7)+C+w;return{pad:y,frameless:e.frameless,labelWeight:d,metaW:e.meta?n(e.meta,s,400,t.mono):0,label:a,sub:o,icon:e.icon,meta:e.meta,caps:e.caps,labelSize:r,labelLh:c,subSize:s,subLh:l,iconSize:u,letterSpacing:i,headH:m,sep:v,divider:_,body:g,frame:x?{name:x.name,arg:b[2]}:void 0,frameTop:C,frameBottom:w,w:e.frameless?E:Math.max(E,T),h:D}}function Ea(e,t,n,r,i,a,o){let s=[],c=t+e.pad,l=t+r-e.pad,u=n+e.frameTop+(i-e.h)/2+(e.frameless?e.pad:e.pad*.85);if(e.headH>0){let t=u+(e.label.length?e.labelLh:e.subLh)/2,n=c;e.icon&&(s.push(me(c+e.iconSize/2,t,e.iconSize,a.text,j(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${M(e.letterSpacing)}"`:``;e.label.forEach((i,o)=>s.push(me(o?c:n,t+o*e.labelLh,e.labelSize,e.caps?a.sub:a.text,j(i),` font-weight="${e.labelWeight}"${r}`)));let i=u+e.label.length*e.labelLh+2;for(let t of e.sub)s.push(me(c,i+e.subLh/2,e.subSize,a.sub,j(t))),i+=e.subLh;e.meta&&s.push(me(l,t,e.subSize,a.sub,j(e.meta),` text-anchor="end"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${M(t)},${M(n)}H${M(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(Da(e.body,c,l,u+e.headH+e.sep,a,o)),s.join(``)}function Da(e,t,n,r,i,a){let s=[],c=e.fs,l={fs:c,lh:e.lh,mono:e.mono,measure:()=>0,theme:a,col:i};return e.rows.forEach((o,u)=>{let d=r+e.ys[u],f=e.hs[u];if(o.kind===`text`){let e=o,r=d+f/2;s.push(ye(e.left,t,r,c,i,a)),e.right&&s.push(ye(e.right,n-_e(e.right),r,c,i,a))}else o.kind===`rule`?s.push(`<path d="M${M(t)},${M(d+f/2)}H${M(n)}" stroke="${i.stroke}" stroke-width="1"/>`):o.kind!==`gap`&&s.push(Ca(o)?.render(o,{x:t,y:d,w:n-t,h:f},l)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${j(o)}"`:``}>${s.join(``)}</g>`}function Oa(e,t,n){let r=[];for(let i of e.split(`
11
+ `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of i.split(/ +/)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function ka(e,t,n,r,i,a,o,s=!1,c=0){let l=s?r*.1:0,u=Math.round(r*.82*10)/10,d=Oa(s?e.toUpperCase():e,c,e=>o(e,r,i,a.mono)+l*[...e].length),f=t?Oa(t,c,e=>o(e,u,400,a.mono)):[],p=Math.round(r*.82*10)/10,m=r*1.3,h=p*1.35,g=Math.round(r*1.6),_=0;for(let e of d)_=Math.max(_,o(e,r,i,a.mono)+l*[...e].length);for(let e of f)_=Math.max(_,o(e,p,400,a.mono));let v=d.length*m+f.length*h+(f.length?3:0);return n&&(v+=g+4,_=Math.max(_,g)),{lines:d,sub:f,icon:n,lineHeight:m,subSize:p,subLineHeight:h,iconSize:g,letterSpacing:l,w:_,h:v}}function Aa(e,t){let{title:n,subtitle:r}=e.settings;if(!n&&!r)return null;let i=t.fontSize*1.3,a=t.fontSize*.95;return{titleSize:i,subSize:a,h:(n?i*1.3:0)+(r?a*1.5:0)+10}}function ja(e,t){let n=[],r=new Set,i=t;for(;i&&e.groups.has(i)&&!r.has(i);)r.add(i),n.unshift(i),i=e.groups.get(i).parent;return n}function Ma(e){let t=new Map;for(let n of e)n.forEach((e,r)=>{for(let i of e.path){let e=t.get(i)??[0,0];e[0]+=(r+.5)/n.length,e[1]++,t.set(i,e)}});return new Map([...t].map(([e,[t,n]])=>[e,t/n]))}function Na(e,t,n,r){let i=e.flat(),a=new Map;for(let e of i)e.path.forEach((t,n)=>{let r=a.get(t);r||a.set(t,r={members:[],gPath:e.path.slice(0,n+1),r0:e.rank,r1:e.rank}),r.members.push(e),r.r0=Math.min(r.r0,e.rank),r.r1=Math.max(r.r1,e.rank)});let o=[...a.keys()];if(!o.length)return;let s=e.map(e=>{let t=new Map;return e.forEach((e,n)=>{for(let r of e.path){let e=t.get(r);e?e[1]=n:t.set(r,[n,n])}}),t}),c=n*.5+6,l=Ma(e),u=e=>`\0L${e}`,d=e=>`\0R${e}`,f=new Map(i.map(e=>[e.id,e.pos]));for(let e of o)f.set(u(e),-1/0).set(d(e),-1/0);let p=new Map([...f.keys()].map(e=>[e,[]])),m=new Map([...f.keys()].map(e=>[e,0])),h=(e,t,n)=>{p.get(e).push([t,n]),m.set(t,m.get(t)+1)};for(let t of e)for(let e=1;e<t.length;e++)h(t[e-1].id,t[e].id,r(t[e-1],t[e]));for(let[n,{members:r,gPath:i,r0:o,r1:f}]of a){let a=1/0,p=-1/0;for(let e of r){let r=e.path.length-e.path.indexOf(n),i=e.oExt/2+r*18+(t?r*26:0),o=e.oExt/2+r*18;h(u(n),e.id,i),h(e.id,d(n),o),a=Math.min(a,e.pos-i),p=Math.max(p,e.pos+o)}let m=(a+p)/2,g=e=>{let t=i.findIndex((t,n)=>e.path[n]!==t),n=e.path[t];return n===void 0?void 0:l.get(n)<l.get(i[t])};for(let t=o;t<=f;t++){let r=e[t],i=s[t].get(n),a;if(i)a=[i[0]-1,i[1]+1];else{let e=0,t=r.length;r.forEach((n,r)=>{let i=g(n);i===!0&&(e=Math.max(e,r+1)),i===!1&&(t=Math.min(t,r))});let n=e;for(;n<t&&r[n].pos<m;)n++;a=[n-1,n]}let[o,l]=a;o>=0&&h(r[o].id,u(n),r[o].oExt/2+c),l<r.length&&h(d(n),r[l].id,r[l].oExt/2+c)}}let g=new Map;for(let[e,t]of a){let n=t.gPath.slice(0,-1).join(`\0`);g.set(n,[...g.get(n)??[],e])}for(let e of g.values())for(let t of e)for(let n of e){let[e,r]=[a.get(t),a.get(n)];l.get(t)>=l.get(n)||e.r1<r.r0||r.r1<e.r0||h(d(t),u(n),c)}let _=[...m].filter(([,e])=>e===0).map(([e])=>e),v=new Set;for(;v.size<f.size;){if(!_.length){let e=``,t=1/0;for(let[n,r]of m)!v.has(n)&&r<t&&([e,t]=[n,r]);_.push(e)}let e=_.pop();if(!v.has(e)){v.add(e);for(let[t,n]of p.get(e))v.has(t)||(f.set(t,Math.max(f.get(t),f.get(e)+n)),m.set(t,m.get(t)-1),m.get(t)===0&&_.push(t))}}for(let e of i)e.pos=f.get(e.id)}function Pa(e,t){let n=Object.create(e),r=k(t.background,e,e.dark?950:50);r&&(n.background=t.background===`none`||t.background===`transparent`?`none`:r,e.edge.labelBg===e.background&&n.background!==`none`&&(n.edge={...e.edge,labelBg:r})),t.font&&({font:n.font,mono:n.mono}=D(t.font));let i=k(t.accent,e,e.dark?400:600);return i&&(n.accent=i),t[`font-size`]&&Number.isFinite(parseFloat(t[`font-size`]))&&(n.fontSize=parseFloat(t[`font-size`])),t.grid!==void 0&&(n.grid=w(t.grid,!0)?t.grid===`true`||t.grid===`on`||t.grid===`yes`||t.grid===``?e.grid??(e.dark?`rgba(255,255,255,.05)`:`rgba(0,0,0,.05)`):k(t.grid,e,e.dark?800:200)??e.grid:null),w(t.shadow,!0)?t.shadow!==void 0&&!n.shadow&&(n.shadow=e.dark?`rgba(0,0,0,.5)`:`rgba(15,23,42,.12)`):n.shadow=null,Se(n,t)}var Fa=e=>e===`right`||e===`left`;function Ia(e,t={}){let n=Pa(re(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??sr,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=Fa(i),o=F(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=F(e.settings[`rank-gap`],s?96:72),l=[`smooth`,`orthogonal`,`straight`].includes(e.settings.curve)?e.settings.curve:`smooth`,u=e.settings.shape,d=new Map,f=new Map;for(let t of e.nodes.values()){let i=Ce(e,t),a=Te(e,t,i,n),o=vt(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=F(i[`max-width`],F(e.settings.wrap,0)),l=ka(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c),p;t.body?.length||i.meta||i.frame?(l.card=Ta({label:t.label,sub:i.sub,icon:i.icon,meta:i.meta,caps:s,body:t.body,mono:i.mono!==`false`,frameless:o===`text`,fontSize:a.fontSize,weight:a.fontWeight,frame:i.frame},n,r),p={w:l.card.w,h:l.card.h}):p=yt(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??Ra(F(i.width,p.w)),g=m?.h??Ra(F(i.height,p.h));d.set(t.id,{id:t.id,decl:t,shape:o,style:a,x:0,y:0,w:h,h:g,pinned:!1})}let p=[...d.keys()],m=[];e.edges.forEach((e,t)=>{if(e.from===e.to||!d.has(e.from)||!d.has(e.to)||e.props.constraint===`false`)return;let n=Math.max(1,Math.min(12,Math.round(F(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})}),za(p,m);let h=Ba(p,m),g=(e.layout.ranks??[]).map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);g.length&&La(h,m,g);let _=new Set(m.flatMap(e=>[e.from,e.to])),v=new Map;for(let t of e.edges)if(t.props.constraint===`false`&&d.has(t.from)&&d.has(t.to))for(let[e,n]of[[t.from,t.to],[t.to,t.from]])!_.has(e)&&_.has(n)&&!v.has(e)&&(v.set(e,n),h.set(e,h.get(n)));let y=new Map;for(let t of p){let n=d.get(t);y.set(t,{id:t,real:!0,path:ja(e,n.decl.group),oExt:a?n.h:n.w,rExt:a?n.w:n.h,rank:h.get(t),pos:0})}let b=[],x=new Map;for(let e of m){let[t,n]=e.reversed?[e.to,e.from]:[e.from,e.to],r=h.get(t),i=h.get(n);if(i-r<=1){b.push([t,n,1]);continue}let a=y.get(t).path,o=y.get(n).path,s=[];for(let e=0;e<Math.min(a.length,o.length)&&a[e]===o[e];e++)s.push(a[e]);let c=t,l=[];for(let n=r+1;n<i;n++){let r=`\u0000${e.idx}:${n}`;y.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0}),b.push([c,r,c===t?1:2]),l.push(r),c=r}b.push([c,n,1]),x.set(e.idx,e.reversed?l.reverse():l)}let S=Math.max(0,...[...y.values()].map(e=>e.rank)),C=Array.from({length:S+1},()=>[]);for(let e of y.values())C[e.rank].push(e);let w=new Map,T=new Map;for(let e of y.keys())w.set(e,[]),T.set(e,[]);for(let[e,t,n]of b)T.get(e).push([t,n]),w.get(t).push([e,n]);Va(C,w,T,v);let E=(e,t)=>{let n=0;for(;n<e.path.length&&n<t.path.length&&e.path[n]===t.path[n];)n++;let r=e.path.length-n,i=t.path.length-n,s=(r+i)*18+(r+i>0?10:0);a&&(s+=i*26);let c=!e.real&&!t.real?14:!e.real||!t.real?o*.6:o;return(e.oExt+t.oExt)/2+c+s};for(let e of C){let t=0;e.forEach((n,r)=>{r>0&&(t+=E(e[r-1],n)),n.pos=t})}let D=e=>e.length?e[e.length-1].pos-e[0].pos:0,ee=Math.max(...C.map(D));for(let e of C){let t=(ee-D(e))/2;for(let n of e)n.pos+=t}for(let e=0;e<16;e++){let t=e<12?e%2==0?`down`:`up`:`both`,n=t===`up`?[...C].reverse():C;for(let e of n){if(!e.length)continue;let n=[],r=[];for(let i of e){let e=t===`down`?w.get(i.id):t===`up`?T.get(i.id):[...w.get(i.id),...T.get(i.id)],a=0,o=0;for(let[t,n]of e)o+=y.get(t).pos*n,a+=n;n.push(a?o/a:i.pos),r.push(a||.25)}let i=Wa(n,r,e.slice(1).map((t,n)=>E(e[n],t)));e.forEach((e,t)=>e.pos=i[t])}}Na(C,a,o,E);let O=C.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),te=Array(C.length).fill(0);e.edges.forEach(e=>{if(!e.label||!h.has(e.from)||!h.has(e.to))return;let t=Math.min(h.get(e.from),h.get(e.to));if(Math.abs(h.get(e.from)-h.get(e.to))!==1)return;let i=n.fontSize*.86,o=e.label.split(`
12
+ `),s=a?Math.max(...o.map(e=>r(e,i,500,n.mono)))+16:o.length*i*1.3+10;te[t]=Math.max(te[t],s)});let ne=[],ie=0;for(let e=0;e<C.length;e++)ne.push(ie+O[e]/2),ie+=O[e]+Math.max(c,te[e]+44);let ae=(e,t)=>{switch(i){case`right`:return{x:e,y:t};case`left`:return{x:-e,y:t};case`down`:return{x:t,y:e};case`up`:return{x:t,y:-e}}};for(let e of y.values()){if(!e.real)continue;let t=d.get(e.id),n=ae(ne[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}let oe=new Map;for(let[e,t]of x)oe.set(e,t.map(e=>{let t=y.get(e);return ae(ne[t.rank],t.pos)}));let k=Math.max(0,...[...y.values()].map(e=>e.path.length)),se=1/0,ce=1/0;for(let e of d.values())se=Math.min(se,e.x),ce=Math.min(ce,e.y);if(d.size){let e=k*18-se,t=k*44-ce;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of oe.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}Ka(e,d,a,o);let le=[...d.values()].some(e=>e.pinned),ue=qa(e,d,n),de=new Map;le||e.edges.forEach((e,t)=>oe.has(t)&&de.set(e.key,oe.get(t)));let A=Ue(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:de,obstacles:[...d.values()],groups:ue.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:35}}))}),{bounds:fe,decor:pe,panels:j}=Ja(d,ue,A,e,n,r),M={nodes:d,groups:ue,edges:A,bounds:fe,direction:i,theme:n,blocks:f,decor:pe,panels:j};for(let t of pt)t(M,e);return M}function La(e,t,n){let r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));for(let i=0;i<50;i++){let i=!1;for(let t of n){let n=Math.max(...t.map(t=>e.get(t)));for(let r of t)e.get(r)!==n&&(e.set(r,n),i=!0)}for(let n of t){let[t,a]=n.reversed?[n.to,n.from]:[n.from,n.to];if(r.has(t)&&r.get(t)===r.get(a))continue;let o=e.get(t)+(n.len??1);e.get(a)<o&&(e.set(a,o),i=!0)}if(!i)return}}var Ra=e=>Math.ceil(e/2)*2;function za(e,t){let n=new Map;for(let t of e)n.set(t,[]);for(let e of t)n.get(e.from).push(e);let r=new Map,i=e=>{let t=[[e,0]];for(r.set(e,1);t.length;){let e=t[t.length-1],i=n.get(e[0]);if(e[1]>=i.length){r.set(e[0],2),t.pop();continue}let a=i[e[1]++],o=r.get(a.to);o===1?a.reversed=!0:o||(r.set(a.to,1),t.push([a.to,0]))}};for(let t of e)r.get(t)||i(t)}function Ba(e,t){let n=new Map,r=new Map,i=new Map;for(let t of e)n.set(t,[]),i.set(t,[]),r.set(t,0);for(let e of t){let[t,a]=e.reversed?[e.to,e.from]:[e.from,e.to];n.get(t).push([a,e.len??1]),i.get(a).push(t),r.set(a,r.get(a)+1)}let a=new Map,o=e.filter(e=>r.get(e)===0),s=[];for(let e of o)a.set(e,0);for(;o.length;){let e=o.shift();s.push(e);for(let[t,i]of n.get(e))a.set(t,Math.max(a.get(t)??0,a.get(e)+i)),r.set(t,r.get(t)-1),r.get(t)===0&&o.push(t)}for(let t of e)a.has(t)||a.set(t,0);for(let e=s.length-1;e>=0;e--){let t=s[e],r=n.get(t);r.length&&!i.get(t).length&&a.set(t,Math.max(0,Math.min(...r.map(([e,t])=>a.get(e)-t))))}return a}function Va(e,t,n,r=new Map){let i=new Map,a=()=>e.forEach(e=>e.forEach((e,t)=>i.set(e.id,t))),o=e=>{for(let[t,n]of r)e.has(n)&&e.has(t)&&e.set(t,e.get(n)+.001);return e};for(let t of e)Ua(t,o(new Map(t.map((e,t)=>[e.id,t]))));a();let s=()=>{let t=0;for(let r=0;r<e.length-1;r++){let a=[];for(let t of e[r])for(let[e]of n.get(t.id))a.push([i.get(t.id),i.get(e)]);for(let e=0;e<a.length;e++)for(let n=e+1;n<a.length;n++)(a[e][0]-a[n][0])*(a[e][1]-a[n][1])<0&&t++}return t},c=e.map(e=>[...e]),l=s();for(let r=0;r<24&&l>0;r++){let a=r%2==0,u=a?e.map((e,t)=>t).slice(1):e.map((e,t)=>t).reverse().slice(1);for(let r of u){let s=e[r],c=new Map;for(let e of s){let r=(a?t.get(e.id):n.get(e.id)).map(([e])=>i.get(e));c.set(e.id,r.length?r.reduce((e,t)=>e+t,0)/r.length:i.get(e.id))}Ua(s,o(c)),s.forEach((e,t)=>i.set(e.id,t))}let d=s();d<l&&(l=d,c=e.map(e=>[...e]))}c.forEach((t,n)=>e[n]=t),Ha(e)}function Ha(e){let t=Ma(e);if(!t.size)return;let n=e=>t.get(e),r=(e,t)=>{let i=[];for(let n of e){let e=n.path[t],r=i[i.length-1];e!==void 0&&r?.g===e?r.nodes.push(n):i.push({g:e,nodes:[n]})}let a=i.map((e,t)=>e.g===void 0?-1:t).filter(e=>e>=0),o=a.map(e=>i[e]).sort((e,t)=>n(e.g)-n(t.g));return a.forEach((e,t)=>i[e]=o[t]),i.flatMap(e=>e.g===void 0?e.nodes:r(e.nodes,t+1))};for(let t=0;t<e.length;t++)e[t]=r(e[t],0)}function Ua(e,t){let n=new Map,r=new Map;for(let n of e)for(let e of n.path){let i=r.get(e)??[0,0];i[0]+=t.get(n.id),i[1]++,r.set(e,i)}for(let[e,[t,i]]of r)n.set(e,t/i);let i=e=>({ent:[...e.path,e.id],val:[...e.path.map(e=>n.get(e)),t.get(e.id)]}),a=new Map(e.map(e=>[e.id,i(e)])),o=new Map(e.map((e,t)=>[e.id,t]));e.sort((e,t)=>{let n=a.get(e.id),r=a.get(t.id);for(let i=0;i<Math.max(n.ent.length,r.ent.length);i++){if(n.ent[i]===r.ent[i])continue;let a=n.val[i]??0,s=r.val[i]??0;return a===s?o.get(e.id)-o.get(t.id):a-s}return o.get(e.id)-o.get(t.id)})}function Wa(e,t,n){let r=e.length,i=Array(r).fill(0);for(let e=1;e<r;e++)i[e]=i[e-1]+n[e-1];let a=[];for(let n=0;n<r;n++)for(a.push({sum:(e[n]-i[n])*t[n],w:t[n],start:n,end:n});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.sum/t.w<=e.sum/e.w)break;a.splice(a.length-2,2,{sum:t.sum+e.sum,w:t.w+e.w,start:t.start,end:e.end})}let o=Array(r);for(let e of a)for(let t=e.start;t<=e.end;t++)o[t]=e.sum/e.w+i[t];return o}function Ga(e,t,n){return e.x<t.x+t.w+n&&t.x<e.x+e.w+n&&e.y<t.y+t.h+n&&t.y<e.y+e.h+n}function Ka(e,t,n,r){let i=0,a=0,o=0;for(let n of t.values()){let t=e.layout.nodes[n.id];t?.x!==void 0&&t.y!==void 0&&(i+=t.x-n.x,a+=t.y-n.y,o++,n.x=t.x,n.y=t.y,n.pinned=!0)}if(!o||o===t.size)return;i=Math.round(i/o),a=Math.round(a/o);let s=[...t.values()].filter(e=>e.pinned);for(let e of t.values())if(!e.pinned){e.x+=i,e.y+=a;for(let t=0;t<200;t++){let t=s.find(t=>Ga(e,t,r/2));if(!t)break;n?e.y=t.y+t.h+r:e.x=t.x+t.w+r}s.push(e)}}function qa(e,t,n){let r=t=>ja(e,t).length,i=[...e.groups.keys()].sort((e,t)=>r(t)-r(e)),a=new Map,o=[];for(let s of i){let i=[];for(let e of t.values())e.decl.group===s&&i.push(e);for(let[t,n]of a)e.groups.get(t).parent===s&&i.push(n);if(!i.length)continue;let c=Math.min(...i.map(e=>e.x))-18,l=Math.min(...i.map(e=>e.y))-18-26,u=Math.max(...i.map(e=>e.x+e.w))+18,d=Math.max(...i.map(e=>e.y+e.h))+18,f={x:c,y:l,w:u-c,h:d-l};a.set(s,f);let p=e.groups.get(s);o.push({id:s,decl:p,depth:r(s),...f,style:Ee({...p,props:Ce(e,p)},n)})}return o.sort((e,t)=>e.depth-t.depth)}function Ja(e,t,n,r,i,a){let o=1/0,s=1/0,c=-1/0,l=-1/0,u=e=>{o=Math.min(o,e.x),s=Math.min(s,e.y),c=Math.max(c,e.x+e.w),l=Math.max(l,e.y+e.h)};for(let t of e.values())u(t);for(let e of t)u(e);for(let e of n){for(let t of e.samples)u({x:t.x,y:t.y,w:0,h:0});e.label&&u({x:e.label.x,y:e.label.y,w:e.label.w,h:e.label.h})}let d=Number.isFinite(o);d||(o=s=0,c=l=r.panels.length?0:100);let f=Za(r,i,a,d?{x:o,y:s,w:c-o,h:l-s}:null);for(let e of f)u(e.box);let p=F(r.settings.padding,24);o-=p,s-=p,c+=p,l+=p;let m=Aa(r,i);m&&(s-=m.h,r.settings.title&&(c=Math.max(c,o+p+P(A(r.settings.title),m.titleSize,i.mono,a,650)+p)),r.settings.subtitle&&(c=Math.max(c,o+p+P(A(r.settings.subtitle),m.subSize,i.mono,a)+p)));let h=[];for(let e of Pn.decorations){let t=r.settings[e.setting];if(!t)continue;let n=e.measure(t,i,a,r);n&&(n.w&&(c=Math.max(c,o+p*2+n.w)),n.bottom&&(h.push({name:e.name,value:t,area:{x:o,y:l,w:0,h:n.bottom}}),l+=n.bottom),n.top&&(s-=n.top,h.push({name:e.name,value:t,area:{x:o,y:s,w:0,h:n.top}})))}let g={x:Math.floor(o),y:Math.floor(s),w:Math.ceil(c-o),h:Math.ceil(l-s)};for(let e of h)e.area.x=g.x,e.area.w=g.w;return{bounds:g,decor:h,panels:f}}var Ya=(e,t)=>e?t.fontSize*2.3:0;function Xa(e,t,n,r){return{theme:n,measure:r,fs:n.fontSize,props:e.props,offsets:t}}function Za(e,t,n,r){let i=[];for(let r of e.panels){let a=Pn.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=Xa(r,o,Oe(t,r.props,e.themes),n),c=a.measure(r.data,s),l=Ya(r.label,t),u=r.label?n(r.label,t.fontSize*1.05,650,t.mono):0,d=Ra(Math.max(c.w,u)+32),f=Ra(c.h+l+32),p={x:0,y:0,w:d-32,h:c.h},m;i.push({decl:r,box:{x:0,y:0,w:d,h:f},inner:p,offsets:o,ctx:s,get handles(){return m??=a.handles?.(r.data,p,s)??[]}})}if(!i.length)return i;let a=F(e.settings[`panel-gap`],48),o=e.settings.panels??`row`,s=[...r?[r]:[],...i.map(e=>e.box)],c=r?.x??0,l=r?.y??0;if(o===`wrap`){let e=Math.max(r?.w??0,...i.map(e=>e.box.w),1200),t=0,n=r?r.h+a:0,o=0;for(let r of i)t>0&&t+r.box.w>e&&(t=0,n+=o+a,o=0),r.box.x=Math.round(c+t),r.box.y=Math.round(l+n),t+=r.box.w+a,o=Math.max(o,r.box.h)}let u=o===`column`?1:o===`grid`?Math.ceil(Math.sqrt(s.length)):s.length,d=[],f=[];s.forEach((e,t)=>{let n=Math.floor(t/u),r=t%u;d[r]=Math.max(d[r]??0,e.w),f[n]=Math.max(f[n]??0,e.h)});let p=(e,t)=>e.slice(0,t).reduce((e,t)=>e+t,0)+t*a;s.forEach((e,t)=>{r&&t===0||o===`wrap`||(e.x=Math.round(c+p(d,t%u)),e.y=Math.round(l+p(f,Math.floor(t/u))))});for(let n of i){let r=e.layout.panels?.[n.decl.id]?.at;r&&(n.box.x=r.x,n.box.y=r.y),n.inner.x=n.box.x+16,n.inner.y=n.box.y+16+Ya(n.decl.label,t)}return i}var Qa=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`);function $a(e,t){if(!t||!ce(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${Qa(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}var z=e=>(Math.round(e*100)/100).toString(),B=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?z(t):Qa(t)}"`,eo=0;function to(e){let t=t=>fe(A(e.nodes.get(t)?.label??t)),n=e.edges.slice(0,40).map(e=>`${t(e.from)} to ${t(e.to)}${e.label?` (${fe(A(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&fe(A(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function no(e,t,n={}){let r=t.theme,i=n.idPrefix??`yuhwa${(eo++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&fe(A(s)),l=to(e),u=t.edges.some(e=>e.style.flow),d=r.shadow&&([...t.nodes.values()].some(e=>e.style.shadow)||!!t.panels?.some(e=>e.decl.props.shadow&&e.decl.props.shadow!==`false`));o.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${z(a.x)} ${z(a.y)} ${z(a.w)} ${z(a.h)}"`+B(`width`,n.width??a.w)+(n.width?``:B(`height`,a.h))+` role="img"${B(`aria-label`,c||`diagram`)}${l?B(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${Qa(r.font)}">`),c&&o.push(`<title>${Qa(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${Qa(l)}</desc>`);let f=[];d&&f.push(`<filter id="${i}-sh" x="-20%" y="-20%" width="140%" height="150%"><feDropShadow dx="0" dy="1.5" stdDeviation="2.2" flood-color="${r.shadow}"/></filter>`),r.grid&&f.push(`<pattern id="${i}-grid" width="24" height="24" patternUnits="userSpaceOnUse"><path d="M24 0H0V24" fill="none" stroke="${r.grid}" stroke-width="1"/></pattern>`);let p=n.snapGrid;p&&f.push(`<pattern id="${i}-snap" x="${-p/2}" y="${-p/2}" width="${p}" height="${p}" patternUnits="userSpaceOnUse"><circle cx="${p/2}" cy="${p/2}" r="0.9" fill="${r.node.sub}" opacity="0.35"/></pattern>`),f.length&&o.push(`<defs>${f.join(``)}</defs>`),u&&o.push(`<style>@keyframes ${i}-flow{to{stroke-dashoffset:var(--mf,-40px)}}.${i}-flow{animation:${i}-flow 1.2s linear infinite}@media (prefers-reduced-motion:reduce){.${i}-flow{animation:none}}</style>`),n.transparent||(o.push(`<rect x="${z(a.x)}" y="${z(a.y)}" width="${z(a.w)}" height="${z(a.h)}" fill="${r.background}"/>`),r.grid&&o.push(`<rect x="${z(a.x)}" y="${z(a.y)}" width="${z(a.w)}" height="${z(a.h)}" fill="url(#${i}-grid)"/>`)),p&&o.push(`<rect x="${z(a.x)}" y="${z(a.y)}" width="${z(a.w)}" height="${z(a.h)}" fill="url(#${i}-snap)" pointer-events="none"/>`);let m=Aa(e,r);if(m){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i={text:r.title,sub:r.node.sub,stroke:r.node.stroke};s&&(o.push(`<text x="${z(a.x+t)}" y="${z(n+m.titleSize*.8)}" font-size="${z(m.titleSize)}" font-weight="650" xml:space="preserve">${be(A(s),i,r)}</text>`),n+=m.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${z(a.x+t)}" y="${z(n+m.subSize*.95)}" font-size="${z(m.subSize)}" xml:space="preserve">${be(A(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=Pn.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:parseFloat(e.settings.padding)||24,bounds:a,d:e}))}o.push(`<g class="groups">`);for(let e of[...t.groups].sort((e,t)=>e.depth-t.depth))o.push(io(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(oo(e,i,!!n.interactive));o.push(`</g><g class="nodes">`);for(let n of t.nodes.values())o.push(lo(e,n,t,d?`${i}-sh`:null));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(co(e,t));o.push(`</g>`),t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>ro(e,t,n.measure,d?`${i}-sh`:null)).join(``)}</g>`),o.push(`</svg>`);let h=o.join(``);for(let n of mt)h=n(h,e,t);return h}function ro(e,t,n,r){let i=t.theme,a=Pn.panels.get(e.decl.kind);if(!a)return``;let o=e.ctx.theme,s=ke(e.decl.props,o,i),{box:c}=e,l=Ya(e.decl.label,o),u=[`<g${B(`data-panel`,e.decl.id)}${B(`class`,`panel panel-${e.decl.kind}`)}>`];return s.framed&&u.push(`<rect x="${z(c.x)}" y="${z(c.y)}" width="${z(c.w)}" height="${z(c.h)}" rx="${z(s.radius)}" fill="${s.fill}" stroke="${s.stroke}" stroke-width="${z(s.width)}"${B(`stroke-dasharray`,s.dash)}${s.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&u.push(`<text x="${z(c.x+16)}" y="${z(c.y+16+l*.32)}" dominant-baseline="central" font-size="${z(o.fontSize*1.05)}" font-weight="650" fill="${s.text}" xml:space="preserve">${be(A(e.decl.label),{text:s.text,sub:o.node.sub,stroke:o.node.stroke},o)}</text>`),u.push(a.render(e.decl.data,e.inner,!n||n===e.ctx.measure?e.ctx:{...e.ctx,measure:n})),u.push(`</g>`),u.join(``)}function io(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=o.caps!==void 0&&o.caps!==`false`,c=s?e.decl.label.toUpperCase():e.decl.label,l=c?`<text x="${z(e.x+18-4)}" y="${z(e.y+17)}" font-size="${z(s?a*.92:a)}" font-weight="600" letter-spacing="${s?`0.1em`:`0.02em`}" fill="${i.text}">${Qa(c)}</text>`:``,u=o.meta?`<text x="${z(e.x+e.w-18+4)}" y="${z(e.y+17)}" text-anchor="end" font-size="${z(a)}" fill="${r.node.sub}">${Qa(o.meta)}</text>`:``;return`<g${B(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${z(e.x)}" y="${z(e.y)}" width="${z(e.w)}" height="${z(e.h)}" rx="${z(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${B(`stroke-dasharray`,i.dash)}/>`+l+u+`</g>`}function ao(e,t,n=!1){let r=t.split(/[\s,]+/).reduce((e,t)=>e+(parseFloat(t)||0),0)||10,i=r*Math.max(1,Math.round(40/r)),a=n?`;animation-direction:reverse;animation-delay:${z(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${z(-i)}px${a}"`}function oo(e,t,n){let r=e.style,i=[];i.push(`<g${B(`data-edge`,e.key)}${r.opacity<1?B(`opacity`,r.opacity):``}>`),n&&i.push(`<path d="${e.d}" fill="none" stroke="transparent" stroke-width="14" stroke-linecap="round"/>`);let a=`<path d="${e.d}" fill="none" stroke="${r.stroke}" stroke-width="${z(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${z(e*3)} ${z(e*9)}`;i.push(a+` opacity="0.35"`+B(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+B(`stroke-dasharray`,n)+ao(t,n)+`/>`,a+B(`stroke-dasharray`,n)+ao(t,n,!0)+`/>`)}else i.push(a+B(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?ao(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(ht(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function so(e,t,n,r){return n.style.labelBg!==r.theme.background||r.theme.edge.labelStroke?[]:r.groups.filter(n=>n.style.fill!==`none`&&e>=n.x&&e<=n.x+n.w&&t>=n.y&&t<=n.y+n.h).sort((e,t)=>e.depth-t.depth).map(e=>e.style.fill)}function co(e,t){let n=e.label,r=t.theme,i=r.fontSize*.86,{x:a,y:o}=n.anchor,s=[],c=n.text?n.text.split(`
13
+ `):[];if(c.length){let{w:l,h:u}=n.pill,d=i*1.3,f=o-(c.length-1)*d/2,p=c.map((e,t)=>`<tspan x="${z(a)}" y="${z(f+t*d)}">${Qa(e)}</tspan>`).join(``),m=r.edge.labelStroke,h=`x="${z(a-l/2)}" y="${z(o-u/2)}" width="${z(l)}" height="${z(u)}" rx="${m?z(u/2):4}"`;s.push(`<rect ${h} fill="${e.style.labelBg}"`+(m?` stroke="${m}" stroke-width="1"`:``)+`/>`,...so(a,o,e,t).map(e=>`<rect ${h} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${z(i)}" font-weight="500" fill="${e.style.text}">${p}</text>`)}if(n.caption){let t=i*.88,l=n.caption.split(`
14
+ `),u=o+(c.length?n.pill.h/2:0)+2,d=Math.max(n.pill.w,n.w),f=`<rect x="${z(a-(n.rotate?n.h:d)/2)}" y="${z(u)}" width="${z(n.rotate?n.h:d)}" height="${z(l.length*t*1.3+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,p=l.map((e,n)=>`<tspan x="${z(a)}" y="${z(u+t*1.3*(n+.5)+1)}">${Qa(e)}</tspan>`).join(``);s.push(f,`<text text-anchor="middle" dominant-baseline="central" font-size="${z(t)}" fill="${r.node.sub}">${p}</text>`)}let l=n.rotate?` transform="rotate(-90 ${z(a)} ${z(o)})"`:``;return`<g${B(`data-edge-label`,e.key)}${l}>${s.join(``)}</g>`}function lo(e,t,n,r){let i=t.style,a=Ce(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${Qa(a.tooltip)}</title>`:``;if(s.push(`<g${B(`data-node`,t.id)}${i.opacity<1?B(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${xt(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${z(i.strokeWidth)}"`+B(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=St(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${z(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&Pn.frames.get(o.card.frame.name);e&&s.push(e.render(t,{theme:n.theme,col:{text:i.text,sub:i.sub,stroke:i.stroke},arg:o.card.frame.arg,radius:i.radius,fs:i.fontSize})),s.push(Ea(o.card,t.x,t.y,t.w,t.h,{text:i.text,sub:i.sub,stroke:i.stroke},n.theme)),s.push(`</g>`);let r=s.join(``);return r=$a(r,a.link),r}let l=t.x+t.w/2,u=t.y+t.h/2+bt(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${z(l)}" y="${z(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${z(o.iconSize)}">${Qa(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${z(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+(i.italic?` font-style="italic"`:``)+(o.letterSpacing?` letter-spacing="${z(o.letterSpacing)}"`:``),f=o.lines.map((e,t)=>`<tspan x="${z(l)}" y="${z(u+o.lineHeight*(t+.5))}">${Qa(e)}</tspan>`).join(``);if(s.push(`<text ${d}>${f}</text>`),u+=o.lines.length*o.lineHeight,o.sub.length){u+=3;let e=o.sub.map((e,t)=>`<tspan x="${z(l)}" y="${z(u+o.subLineHeight*(t+.5))}">${Qa(e)}</tspan>`).join(``);s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${z(o.subSize)}" fill="${i.sub}">${e}</text>`)}s.push(`</g>`);let p=s.join(``);return p=$a(p,a.link),p}var uo=new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),fo=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,po=e=>JSON.stringify(e);function mo(e,t){let n={};for(let[r,i]of Object.entries(e))t.includes(r)||i==null||(n[r]=typeof i==`object`?JSON.stringify(i):String(i));let r=gn(n);return r?` [${r}]`:``}var ho=e=>(Array.isArray(e)?e:e?[e]:[]).map(e=>` .${e}`).join(``),go=e=>Array.isArray(e)?e:[e];function _o(e){let t=[],n;try{n=typeof e==`string`?JSON.parse(e):e}catch(e){return{source:``,errors:[`Invalid JSON: ${e.message}`]}}if(!n||typeof n!=`object`||Array.isArray(n))return{source:``,errors:[`JSON diagram must be an object`]};let r=[],i={...n.settings};for(let e of[`title`,`direction`,`theme`])n[e]!==void 0&&(i[e]=n[e]);for(let[e,t]of Object.entries(i))r.push(`${e}: ${String(t)}`);r.length&&r.push(``);for(let[e,t]of Object.entries(n.classes??{}))r.push(`.${e}${mo(t,[])}`);n.classes&&Object.keys(n.classes).length&&r.push(``);let a=(e,n)=>typeof e==`string`&&fo.test(e)?!0:(t.push(`${n} id ${JSON.stringify(e)} must start with a letter and use only letters, digits, "_" and "-"`),!1),o=(e,n)=>{let r=`${e.id}${e.label===void 0?``:` `+po(String(e.label))}${ho(e.class)}${mo(e,[`id`,`label`,`group`,`class`,`body`])}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
15
+ `);return i.length?(i.some(e=>e.trim()===`}`)&&t.push(`node "${e.id}" body must not contain a line that is only "}"`),[`${n}${r} {`,...i.filter(e=>e.trim()!==`}`).map(e=>`${n} ${e}`),`${n}}`].join(`
16
+ `)):n+r},s=(n.groups??[]).filter(e=>a(e.id,`group`)),c=new Set(s.map(e=>e.id)),l=(n.nodes??[]).filter(e=>a(e.id,`node`));for(let e of l)e.group&&!c.has(e.group)&&(s.push({id:e.group}),c.add(e.group));let u=(e,t)=>{let n=` `.repeat(t);for(let t of l.filter(t=>(t.group||void 0)===e))r.push(o(t,n));for(let i of s.filter(t=>(t.parent||void 0)===e))r.push(`${n}group ${i.id}${i.label===void 0?``:` `+po(String(i.label))}${ho(i.class)}${mo(i,[`id`,`label`,`parent`,`class`])} {`),u(i.id,t+1),r.push(`${n}}`)};for(let e of s)e.parent&&!c.has(e.parent)&&t.push(`group "${e.id}" has unknown parent "${e.parent}"`);u(void 0,0),(l.length||s.length)&&r.push(``);for(let e of n.edges??[]){if(e.from===void 0||e.to===void 0){t.push(`edge ${JSON.stringify(e)} needs "from" and "to"`);continue}let n=go(e.from).filter(e=>a(e,`edge.from`)),i=go(e.to).filter(e=>a(e,`edge.to`));if(!n.length||!i.length)continue;let o=e.arrow??`->`;uo.has(o)||t.push(`edge arrow "${o}" must be one of ${[...uo].join(` `)}`);let s=`${e.label===void 0?``:` `+po(String(e.label))}${ho(e.class)}${mo(e,[`from`,`to`,`label`,`arrow`,`class`])}`;r.push(`${n.join(`, `)} ${uo.has(o)?o:`->`} ${i.join(`, `)}${s?`:`+s:``}`)}return{source:r.join(`
17
+ `).replace(/\n+$/,``)+`
18
+ `,errors:t}}var V=e=>JSON.stringify(e),vo=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:V(e);function H(e,t=!1){let n=e.trim();return(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),n=n.replace(/<br\s*\/?>/gi,`
19
+ `).replace(/<\/?(b|i|em|strong|span|code)[^>]*>/gi,``).replace(/&quot;|#quot;/g,`"`).replace(/&amp;/g,`&`).replace(/#59;/g,`;`).replace(/\bfa[bsr]?:fa-[\w-]+\s*/g,``).replace(/^`(.*)`$/s,`$1`),t||(n=n.replace(/\*\*(.+?)\*\*/g,`$1`)),n.trim()}var U=(e,t=!1)=>H(e,t).replace(/\s*\n\s*/g,` `);function yo(e,t=bo){let n=e.trim().replace(/^"(.*)"$/,`$1`).replace(/[^\p{L}\p{N}_-]+/gu,`_`).replace(/^[-_]+(?=.)|-+$/g,``);return/^[\p{L}_]/u.test(n)||(n=`n`+n),t.has(n)&&(n+=`_`),n}var bo=new Set([`group`,`layout`,`import`,`export`,`def`]);function xo(e,t){let n=(e??``).toLowerCase().replace(/[^\p{L}\p{N}\s]+/gu,` `).trim().split(/\s+/).filter(Boolean).slice(0,3).join(`-`);return/^[\p{L}_]/u.test(n)?n:t}function So(e,t,n,r,i){let a=[e,t];return n&&a.push(V(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}function Co(e){let t=e.match(/^title\b\s*:?\s*(.*)$/i);return t?H(t[1]):void 0}function wo(e,t){return/^(accTitle|accDescr)\b/.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function To(e){let t=e.trim().replace(/^\[|\]$/g,``),n=[],r=``,i=!1;for(let e of t)e===`"`?i=!i:e===`,`&&!i?(n.push(r.trim()),r=``):r+=e;return r.trim()&&n.push(r.trim()),n}var Eo=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:V(e),Do={fill:`fill`,stroke:`stroke`,color:`text`,"stroke-width":`stroke-width`,"stroke-dasharray":`border-style`,"font-weight":`font-weight`,"font-size":`font-size`,rx:`radius`,opacity:`opacity`};function Oo(e,t){let n=[];for(let r of e.replace(/;$/,``).split(`,`)){let[e,...i]=r.split(`:`),a=e?.trim(),o=i.join(`:`).trim();if(!a)continue;let s=Do[a];s?(o=s===`border-style`?`dashed`:o.replace(/px$/,``),s===`font-weight`&&o===`bold`?n.push(`bold`):n.push(`${s}: ${o}`)):t(`style "${a}" is not supported and was skipped`)}return n.join(`, `)}var ko=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Ao={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`};function jo(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(V(e.label));for(let t of e.classes)n.push(`.${t}`);let r=[];e.note&&r.push(`shape: note`),e.sub&&r.push(`sub: ${V(e.sub)}`),e.style&&r.push(e.style),r.length&&n.push(`[${r.join(`, `)}]`);let i=e.rows.length?e.rows:[...e.attrs,...e.attrs.length&&e.methods.length?[`---`]:[],...e.methods];return i.length?(n.length===1&&n.push(V(e.id)),[`${t}${n.join(` `)} {`,...i.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function Mo(e,t,n,r,i,a,o){let s=[];for(let e of i.items)s.push(...jo(r.get(e),``));for(let e of a){s.push(`group ${e.id} ${V(e.label)} {`);for(let t of e.items)s.push(...jo(r.get(t),` `));s.push(`}`)}o.length&&s.push(``);for(let e of o){let t=[e.label?Eo(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);s.push(`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`)}return[...[e?`title: ${e}`:``,`direction: ${t}`].filter(Boolean),...n.length?[``,...n]:[],``,...s]}var No={"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`},Po=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,Fo=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,Io=e=>e.replace(/~([^~]*)~/g,`<$1>`),Lo=e=>e.replace(/~[^~]*~/g,``),Ro=(e,t)=>{let n=new Map,r={id:``,label:``,items:[]},i=[],a=r,o=[],s=[],c=`down`,l=t.title,u=0,d=e=>{let t=yo(Lo(e)),r=n.get(t);return r||(r={id:t,attrs:[],methods:[],rows:[],classes:[]},(t!==e||/~/.test(e))&&(r.label=Io(e.replace(/^"(.*)"$/,`$1`))),n.set(t,r),a.items.push(t)),r},f=(e,t)=>{let n=Io(t.trim());if(!n)return;let r=n.match(/^<<(.+)>>$/);r?e.sub=`«${r[1].trim()}»`:(n.includes(`(`)?e.methods:e.attrs).push(n)};for(let p=0;p<e.length;p++){let m=e[p],h=m.text,g=e=>t.warn(m.line,e);if(/^(accTitle|accDescr)\b/.test(h)){t.warnOnce(`acc`,m.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let _=h.match(/^title\s*:?\s*(.*)$/);if(_){l=H(_[1]);continue}let v=h.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(v){c=Ao[v[1].toUpperCase()];continue}let y=h.match(/^namespace\s+(\S+)\s*\{$/);if(y){a={id:yo(y[1]),label:y[1],items:[]},i.push(a);continue}if(h===`}`){a===r?g(`"}" without a namespace`):a=r;continue}let b=h.match(/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/);if(b){let t=d(b[1]+(b[2]??``));if(b[3]!==void 0&&(t.label=U(b[3])),b[4]&&t.classes.push(b[4]),b[5]&&!b[6])for(;++p<e.length&&e[p].text!==`}`;)f(t,e[p].text);continue}let x=h.match(/^<<(.+)>>\s+(\S+)$/);if(x){d(x[2]).sub=`«${x[1].trim()}»`;continue}let S=h.match(/^note\s+for\s+(\S+)\s+"(.*)"$/);if(S){let e=`note${++u}`;n.set(e,{id:e,label:H(S[2]),attrs:[],methods:[],rows:[],classes:[],note:!0}),a.items.push(e),o.push({from:e,to:d(S[1]).id,arrow:`..`,props:[]});continue}let C=h.match(/^note\s+"(.*)"$/);if(C){let e=`note${++u}`;n.set(e,{id:e,label:H(C[1]),attrs:[],methods:[],rows:[],classes:[],note:!0}),a.items.push(e);continue}let w=h.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=Oo(w[2],g);for(let t of w[1].split(`,`))s.push(`.${t.trim()} [${e}]`);continue}let T=h.match(/^cssClass\s+"([^"]+)"\s+([\w-]+)$/);if(T){for(let e of T[1].split(`,`))d(e.trim()).classes.push(T[2]);continue}let E=h.match(/^style\s+(\S+)\s+(.*)$/);if(E){d(E[1]).style=Oo(E[2],g);continue}if(/^(click|callback|link)\b/.test(h)){t.warnOnce(`click`,m.line,`click, link and callback are skipped`);continue}let D=h.match(Po)??h.match(Fo);if(D){let[,e,n,r,i,a,s,c,l]=D,u=[];r&&u.push(`tail: ${No[r]}`),a&&u.push(`head: ${No[a]}`),(r===`o`||a===`o`)&&t.warnOnce(`aggr`,m.line,`aggregation (o--) is drawn with a filled diamond, like composition`);let f=[n,s].filter(e=>e!==void 0);f.length&&u.push(`caption: ${V(f.join(` to `))}`),o.push({from:d(e).id,to:d(c).id,arrow:i,props:u,label:l?U(l):void 0});continue}let ee=h.match(/^([^\s:]+)\s*:\s*(.*)$/);ee?f(d(ee[1]),ee[2]):g(`could not read "${h}"`)}return Mo(l,c,s,n,r,i,o)},zo={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},Bo={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Vo=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,Ho=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,Uo=(e,t)=>{let n=new Map,r={id:``,label:``,items:[]},i=[],a=`down`,o=t.title,s=e=>{let t=e.replace(/^"(.*)"$/,`$1`),i=yo(t),a=n.get(i);return a||(a={id:i,attrs:[],methods:[],rows:[],classes:[]},i!==t&&(a.label=t),n.set(i,a),r.items.push(i)),a};for(let n=0;n<e.length;n++){let r=e[n],c=r.text;if(/^(accTitle|accDescr)\b/.test(c)){t.warnOnce(`acc`,r.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let l=c.match(/^title\s*:?\s*(.*)$/);if(l){o=H(l[1]);continue}let u=c.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(u){a=Ao[u[1].toUpperCase()];continue}let d=c.match(/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/);if(d){let r=s(d[1]);if(d[2]!==void 0&&(r.label=d[2]),d[3])continue;for(;++n<e.length&&e[n].text!==`}`;){let i=e[n].text.match(Ho);if(!i){t.warn(e[n].line,`could not read attribute "${e[n].text}"`);continue}let a=i[3].replace(/\s+/g,``).replace(/,/g,`, `),o=[i[1],i[2],a,i[4]??``].map(e=>e.replace(/\|/g,`/`));r.rows.push(`| ${o.join(` | `)} |`)}continue}let f=c.match(Vo);if(f){let[,e,t,n,r,a,o]=f;i.push({from:s(e).id,to:s(a).id,arrow:n===`..`?`..`:`--`,props:[`caption: ${V(`${zo[t]} to ${Bo[r]}`)}`],label:U(o)||void 0});continue}let p=c.match(/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/);p?s(p[1]).label=p[2]:/^(classDef|class|style)\b/.test(c)?t.warnOnce(`erstyle`,r.line,`ER styles and classes are skipped`):/^("[^"]*"|[\w-]+)$/.test(c)?s(c):t.warn(r.line,`could not read "${c}"`)}return Mo(o,a,[],n,r,[],i)};function Wo(e,t){let n=Co(e.text);return n!==void 0&&(t.title=n,!0)}var Go=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,Ko=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,qo=(e,t)=>{let n={title:t.title},r=[],i=new Map,a=new Set,o=!1,s=(e,t,n=!1)=>{let o=e.trim(),s=i.get(o),c=!s;if(s||(s=yo(o),i.set(o,s)),t!==void 0||c&&s!==o){let e=n?`actor`:`participant`,i=t??o;a.has(s)||r.push(i===s?`${e} ${s}`:`${e} ${s} ${V(i)}`),a.add(s)}return s};for(let i of e){let e=i.text;if(wo(i,t)||Wo(i,n))continue;if(e===`autonumber`||e.startsWith(`autonumber `)){o=!0;continue}let a=e.match(/^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/);if(a){let e=a[2];/@\{/.test(e)&&(t.warnOnce(`ptype`,i.line,`participant types (@{ "type": … }) are skipped`),e=e.replace(/@\{.*$/,``)),s(e,a[3]===void 0?e.trim():U(a[3]),a[1]===`actor`);continue}let c=e.match(/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i);if(c){let e=c[1].split(`,`).map(e=>s(e));r.push(`note ${e.join(`, `)}: ${U(c[2])}`);continue}let l=e.match(Ko);if(l){t.warnOnce(`block`,i.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[l[1],U(l[2])].filter(Boolean).join(` `)} ---`);continue}if(e===`end`)continue;if(/^rect\b/.test(e)){t.warnOnce(`rect`,i.line,`"rect" highlight boxes are skipped`);continue}let u=e.match(/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/);if(u){t.warnOnce(u[1],i.line,`"${u[1]}" is not supported and was skipped`);continue}let d=e.match(Go);if(d){let[,e,n,a,o,c]=d;a&&t.warnOnce(`act`,i.line,`activation markers (+/-) are skipped`),n.endsWith(`x`)&&t.warnOnce(`cross`,i.line,`cross arrow ends (-x) are drawn as normal arrows`),n.startsWith(`<<`)&&t.warnOnce(`bidi`,i.line,`two-way arrows (<<->>) are drawn one way`);let l=n.replace(/^<</,``).startsWith(`--`)?`-->`:`->`;r.push(`${s(e)} ${l} ${s(o)}: ${U(c)}`)}else t.warn(i.line,`could not read "${e}"`)}return So(`sequence`,xo(n.title,`seq`),n.title,o?[`numbered`]:[],r)},Jo=(e,t)=>{let n={title:t.title},r=[],i,a=0;for(let o of e){let e=o.text;if(wo(o,t)||Wo(o,n))continue;let s=e.match(/^section\s+(.*)$/);if(s){i=ko[a++%ko.length],t.warnOnce(`section`,o.line,`timeline sections become a colour per section`),r.push(`// ${U(s[1])}`);continue}let c=e.split(/\s*:\s*/).map(e=>U(e));if(e.startsWith(`:`)){if(!r.length||r[r.length-1].startsWith(`//`)){t.warn(o.line,`event detail "${e}" has no event above it`);continue}for(let e of c.slice(1).filter(Boolean))r.push(` - ${e}`);continue}let[l,u,...d]=c;if(!u)t.warn(o.line,`event "${l}" has no text`),r.push(`${l}${i?` [${i}]`:``}: ${l}`);else{r.push(`${l}${i?` [${i}]`:``}: ${u}`);for(let e of d.filter(Boolean))r.push(` - ${e}`)}}return So(`timeline`,xo(n.title,`events`),n.title,[],r)},Yo=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function Xo(e){let t={};for(let n of e.matchAll(Yo))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}var Zo=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``),Qo=(e,t)=>{let n={title:t.title},r=[],i=t.header.match(/^\s*(LR|TB|BT)\s*:?/);(i?.[1]===`TB`||i?.[1]===`BT`)&&r.push(`direction: down`),i?.[1]===`BT`&&t.warn(e[0]?.line??1,`bottom-to-top git graphs are drawn top to bottom`);let a=[],o=(e,t)=>{let n=e.type?.toUpperCase();n===`HIGHLIGHT`?t.push(`highlight`):n===`REVERSE`&&t.push(`reverse`)};for(let r of e){let e=r.text;if(wo(r,t)||Wo(r,n))continue;let i=e.match(/^commit\b(.*)$/);if(i){let e=Xo(i[1]),t=[];e.id&&t.push(`id: ${vo(Zo(e.id))}`),e.tag&&t.push(`tag: ${vo(e.tag)}`),o(e,t),a.push([`commit`,e.msg?V(e.msg):``,t.length?`[${t.join(`, `)}]`:``].filter(Boolean).join(` `));continue}let s=e.match(/^branch\s+("[^"]*"|\S+)(.*)$/);if(s){let e=Xo(s[2]);a.push(`branch ${Zo(s[1])}${e.order?` [order: ${e.order}]`:``}`);continue}let c=e.match(/^(checkout|switch)\s+(.+)$/);if(c){a.push(`${c[1]} ${Zo(c[2])}`);continue}let l=e.match(/^merge\s+("[^"]*"|\S+)(.*)$/);if(l){let e=Xo(l[2]),t=[];e.id&&t.push(`id: ${vo(Zo(e.id))}`),e.tag&&t.push(`tag: ${vo(e.tag)}`),o(e,t),a.push(`merge ${Zo(l[1])}${t.length?` [${t.join(`, `)}]`:``}`);continue}let u=e.match(/^cherry-pick\b(.*)$/);if(u){let e=Xo(u[1]);e.parent&&t.warnOnce(`parent`,r.line,`cherry-pick "parent" is skipped`),e.tag&&t.warnOnce(`cptag`,r.line,`cherry-pick "tag" is skipped`),e.id?a.push(`cherry-pick ${Zo(e.id)}`):t.warn(r.line,`cherry-pick needs an id`)}else t.warn(r.line,`could not read "${e}"`)}return So(`git`,xo(n.title,`history`),n.title,r,a)},$o=e=>/[[\]:]|^"/.test(e)?V(e):e,es=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=Co(r)??n.title);let i=[];for(let r of e){if(wo(r,t)||Wo(r,n)||r.text===`showData`)continue;let e=r.text.match(/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/);e?i.push(`${$o(U(e[1]))}: ${e[2]}`):t.warn(r.line,`could not read "${r.text}"`)}return So(`chart`,xo(n.title,`pie`),n.title,[`type: pie`],i)},ts=(e,t)=>{let n={title:t.title},r=/\bhorizontal\b/.test(t.header),i=[],a=[];for(let r of e){let e=r.text;if(wo(r,t)||Wo(r,n))continue;let o=e.match(/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/);if(o){let e=o[1].trim();e.startsWith(`[`)?i=To(e).map(e=>U(e)):t.warnOnce(`xrange`,r.line,`a numeric x-axis range becomes 1, 2, 3, …`);continue}if(/^y-axis\b/.test(e)){t.warnOnce(`yaxis`,r.line,`the y-axis title and range are skipped; the chart scales to the data`);continue}let s=e.match(/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/);s?a.push({type:s[1],values:To(s[2]),line:r.line}):t.warn(r.line,`could not read "${e}"`)}a.length>1&&t.warn(a[1].line,`each xychart series becomes its own chart; yuhwa charts plot one series`);let o=xo(n.title,`xy`),s=[];return a.forEach((e,t)=>{let a=e.values.map((e,t)=>`${$o(i[t]??String(t+1))}: ${e}`),c=e.type===`line`?`line`:r?`bar`:`column`;t&&s.push(``),s.push(...So(`chart`,t?`${o}${t+1}`:o,n.title,[`type: ${c}`],a))}),a.length||s.push(...So(`chart`,o,n.title,[`type: column`],[])),s},ns=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(wo(i,t)||Wo(i,n))continue;let a=e.match(/^section\s+(.*)$/);if(a){r.push(`// ${U(a[1])}`);continue}let o=e.match(/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/);if(o){o[3]&&t.warnOnce(`actors`,i.line,`journey actors are skipped; scores become a column chart`);let e=Number(o[2]),n=e<=2?`red`:e<4?`amber`:`green`;r.push(`${$o(U(o[1]))} [${n}]: ${o[2]}`)}else t.warn(i.line,`could not read "${e}"`)}return So(`chart`,xo(n.title,`journey`),n.title,[`type: column`],r)},rs=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function is(e,t,n){let r=e;/:::/.test(r)&&(t.warnOnce(`mmclass`,n,`mindmap classes (:::) are skipped`),r=r.replace(/\s*:::.*$/,``));for(let[e,i,a]of rs){let o=r.indexOf(e);if(!(o<0||!r.endsWith(i)||r.length<o+e.length+i.length)&&/^[\w-]*$/.test(r.slice(0,o)))return a||t.warnOnce(`mmshape`,n,`cloud, bang and hexagon mindmap shapes use the default look`),{text:H(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:H(r,!0)}}var as=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(wo(a,t))continue;if(a.text.startsWith(`::icon(`)){t.warnOnce(`icon`,a.line,`mindmap icons (::icon) are skipped`);continue}for(;r.length&&r[r.length-1]>=a.indent;)r.pop();let e=r.length;r.push(a.indent),e===0&&i++&&t.warn(a.line,`a mindmap has one root; this node starts a second tree`);let o=is(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return So(`mindmap`,xo(t.title,`map`),t.title,[`layout: both`],n)},os=new Set([`done`,`active`,`crit`,`milestone`]),ss=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,cs=(e,t)=>{let n={title:t.title},r=new Set,i=[];for(let t of e){let e=t.text.match(/^([^:]+?)\s*:\s*(.*)$/);if(!e||/^(title|dateFormat|section)\b/.test(t.text)||ss.test(t.text))continue;let n=e[2].split(`,`).map(e=>e.trim()).filter(Boolean);i.push({l:t,label:e[1],items:n});let a=n.filter(e=>!os.has(e));a.length===3&&r.add(yo(a[0]))}let a=new Map,o=0,s=()=>{let e;do e=`t${++o}`;while(r.has(e));return e},c=(e,n)=>{let r=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/);return!r||[`h`,`d`,`w`].includes(r[2])?e:(t.warnOnce(`mins`,n,`minute and second lengths are rounded up to 1h`),`1h`)},l=e=>e.replace(/^after\s+(.*)$/,(e,t)=>`after `+t.split(/\s+/).map(e=>a.get(e)??yo(e)).join(` `)),u=[],d=0,f=!0;for(let r of e){let e=r.text;if(wo(r,t)||Wo(r,n))continue;let o=e.match(/^dateFormat\s+(.*)$/);if(o){/^YYYY-MM-DD( HH:mm)?$/.test(o[1].trim())||t.warn(r.line,`dateFormat "${o[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`);continue}if(ss.test(e)){let n=e.split(/\s+/)[0];t.warnOnce(n,r.line,`"${n}" is not supported and was skipped`);continue}let p=e.match(/^section\s+(.*)$/);if(p){u.push(`--- ${U(p[1])} ---`);continue}let m=i[d];if(!m||m.l!==r){t.warn(r.line,`could not read "${e}"`);continue}d++;let h=m.items.filter(e=>os.has(e)),g=m.items.filter(e=>!os.has(e)),_,v,y;g.length>=3?[_,v,y]=[yo(g[0]),g[1],g[2]]:g.length===2?[_,v,y]=[s(),g[0],g[1]]:[_,y]=[s(),g[0]],g.length>=3&&a.set(g[0],_),g.length>3&&t.warn(r.line,`extra task fields "${g.slice(3).join(`, `)}" are skipped`),f&&!v&&t.warn(r.line,`the first task has no start date`),f=!1,y?.startsWith(`until `)&&(t.warnOnce(`until`,r.line,`"until" ends become a 1d length`),y=`1d`),y&&=c(y,r.line);let b=(h.includes(`milestone`)?[v?l(v):``]:[v?l(v):``,y??``]).filter(Boolean).join(`, `),x=[_,V(U(m.label)),h.length?`[${h.join(`, `)}]`:``].filter(Boolean).join(` `);u.push(b?`${x}: ${b}`:x)}return So(`gantt`,xo(n.title,`plan`),n.title,[],u)},ls=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(wo(i,t)||Wo(i,n))continue;let a=e.match(/^([xy])-axis\s+(.*)$/);if(a){let[e,t]=a[2].split(/\s*-->\s*/).map(e=>U(e));r.push(`${a[1]}-axis ${e}${t?` -> ${t}`:``}`);continue}let o=e.match(/^quadrant-([1-4])\s+(.*)$/);if(o){r.push(`q${o[1]}: ${U(o[2])}`);continue}if(/^classDef\b/.test(e)){t.warnOnce(`qclass`,i.line,`quadrant point classes are skipped`);continue}let s=e.match(/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/);if(s){let n=Xo(s[4].replace(/,/g,` `));/:::/.test(e)&&t.warnOnce(`qclass`,i.line,`quadrant point classes are skipped`),(n.radius||n[`stroke-color`]||n[`stroke-width`])&&t.warnOnce(`qstyle`,i.line,`point radius and stroke are skipped`);let a=n.color&&/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(n.color)?` [${n.color}]`:``;r.push(`${U(s[1])}${a}: ${s[2]}, ${s[3]}`)}else t.warn(i.line,`could not read "${e}"`)}return So(`quadrant`,xo(n.title,`matrix`),n.title,[],r)},us={"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`};function ds(e){let t={},n=e.match(/@\{(.*)\}\s*$/),r=n?e.slice(0,n.index).trim():e;if(n)for(let e of n[1].matchAll(/([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g))t[e[1]]=e[2].trim().replace(/^(['"])(.*)\1$/,`$2`);let i=r.match(/^[\w-]*\[(.*)\]$/);return i&&(r=i[1]),{text:U(r,!0),meta:t}}var fs=(e,t)=>{let n=[],r=Math.min(...e.filter(e=>!/^(accTitle|accDescr)\b/.test(e.text)).map(e=>e.indent));for(let i of e){if(wo(i,t))continue;let{text:e,meta:a}=ds(i.text);if(i.indent<=r){n.push(e);continue}let o=[];if(a.assigned&&o.push(`owner: ${vo(a.assigned)}`),a.ticket&&o.push(`ticket: ${vo(a.ticket)}`),a.priority){let e=us[a.priority.toLowerCase()];e?(/very/i.test(a.priority)&&t.warnOnce(`very`,i.line,`"Very High" and "Very Low" priorities become high and low`),o.push(`priority: ${e}`)):t.warn(i.line,`priority "${a.priority}" is skipped`)}for(let[e,t]of Object.entries(a))![`assigned`,`ticket`,`priority`].includes(e)&&/^[\w-]+$/.test(e)&&o.push(`${e}: ${vo(t)}`);n.push(` - ${e}${o.length?` [${o.join(`, `)}]`:``}`)}return So(`kanban`,xo(t.title,`board`),t.title,[],n)},ps={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},ms={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},hs=(e,t)=>{let n=new Map,r=new Map,i={id:``,label:``,items:[]},a=[i],o=[],s=[],c=`down`,l=t.title,u=0,d=()=>a[a.length-1],f=(e,t=`state`)=>{let i=yo(e),a=n.get(i);return a?t!==`state`&&(a.kind=t):(a={id:i,kind:t,descs:[],classes:[]},i!==e.trim()&&(a.label=H(e)),n.set(i,a),r.has(i)||d().items.push(i)),a},p=e=>{let t=d(),r=e?`end`:`start`;if(!t[r]){let e=t.id?`${t.id}_${r}`:r;t[r]=e,n.set(e,{id:e,label:``,kind:r,descs:[],classes:[]}),t.items.push(e)}return t[r]},m=(e,t)=>{if(e===`[*]`)return p(t);let n=e.match(/^(.+?)(?::::([\w-]+))?$/);if(r.has(yo(n[1])))return yo(n[1]);let i=f(n[1]);return n[2]&&!i.classes.includes(n[2])&&i.classes.push(n[2]),i.id};for(let p=0;p<e.length;p++){let h=e[p],g=h.text,_=e=>t.warn(h.line,e);if(/^(accTitle|accDescr)\b/.test(g)){t.warnOnce(`acc`,h.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let v=g.match(/^title\s*:?\s*(.*)$/);if(v){l=H(v[1]);continue}let y=g.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(y){a.length>1?t.warnOnce(`subdir`,h.line,`direction inside a composite state is skipped`):c=ps[y[1].toUpperCase()];continue}if(/^(hide empty description|scale\b)/.test(g))continue;if(g===`}`){a.length>1?a.pop():_(`"}" without a composite state`);continue}if(g===`--`){t.warnOnce(`conc`,h.line,`concurrent regions (--) are drawn as one region`);continue}let b=g.match(/^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/);if(b){let e=yo(b[2]);if(n.delete(e))for(let t of[i,...r.values()])t.items=t.items.filter(t=>t!==e);let t={id:e,label:b[1]===void 0?b[2]:H(b[1]),items:[]};r.set(e,t),d().items.push(t),a.push(t);continue}let x=g.match(/^state\s+(\S+)\s+<<(fork|join|choice)>>$/);if(x){f(x[1],x[2]===`choice`?`choice`:`fork`).label=``;continue}let S=g.match(/^state\s+"([^"]*)"\s+as\s+(\S+)$/);if(S){f(S[2]).label=U(S[1]);continue}let C=g.match(/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/);if(C){let e=f(C[1]);C[2]&&e.descs.push(U(C[2]));continue}let w=g.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=Oo(w[2],_);for(let t of w[1].split(`,`))s.push(`.${t.trim()} [${e}]`);continue}let T=g.match(/^class\s+([\w,\s-]+?)\s+([\w-]+)$/);if(T){for(let e of T[1].split(`,`))f(e.trim()).classes.push(T[2]);continue}let E=g.match(/^style\s+([\w-]+)\s+(.*)$/);if(E){f(E[1]).style=Oo(E[2],_);continue}let D=g.match(/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i);if(D){let t=D[2];if(t===void 0){let n=[];for(;++p<e.length&&e[p].text!==`end note`;)n.push(e[p].text);t=n.join(`
20
+ `)}let r=m(D[1].trim(),!1),i=`note${++u}`;n.set(i,{id:i,label:H(t),kind:`note`,descs:[],classes:[]}),d().items.push(i),o.push({from:i,to:r,dotted:!0});continue}let ee=g.match(/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/);if(ee){let e=m(ee[1],!1),t=m(ee[2],!0);o.push({from:e,to:t,label:ee[3]?U(ee[3]):void 0,line:h.line});continue}let O=g.match(/^([^\s:]+)\s*:\s*(.*)$/);O?f(O[1]).descs.push(U(O[2])):/^(click|link|callback)\b/.test(g)?t.warnOnce(`click`,h.line,`click handlers are skipped`):/^[\p{L}\p{N}_-]+$/u.test(g)?f(g):_(`could not read "${g}"`)}a.length>1&&t.warn(e[e.length-1]?.line??1,`composite state is missing "}"`);for(let e of o){let n=r.get(e.from),i=r.get(e.to);(n||i)&&t.warnOnce(`composite`,e.line??1,`edges to a composite state attach to its start or end inside`),n&&(e.from=n.end??_s(n)??e.from),i&&(e.to=i.start??gs(i)??e.to)}let h=new Set([...n.values()].map(e=>e.kind)),g=c===`right`||c===`left`,_=[];h.has(`start`)&&_.push(`.state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]`),h.has(`end`)&&_.push(`.state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]`),h.has(`fork`)&&_.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${g?8:70}, height: ${g?70:8}]`),h.has(`choice`)&&_.push(`.state-choice [shape: diamond, width: 28, height: 28]`);let v=[],y=(e,t)=>{let r=` `.repeat(t);for(let i of e.items){if(typeof i!=`string`){v.push(`${r}group ${i.id} ${V(i.label)} {`),y(i,t+1),v.push(`${r}}`);continue}let e=n.get(i),a=[e.id],o=e.label??e.id;(o!==e.id||e.kind===`note`)&&a.push(V(o));let s=ms[e.kind];s&&a.push(`.${s}`);for(let t of e.classes)a.push(`.${t}`);let c=[];e.kind===`note`&&c.push(`shape: note`),e.descs.length&&c.push(`sub: ${V(e.descs.join(` / `))}`),e.style&&c.push(e.style),c.length&&a.push(`[${c.join(`, `)}]`),v.push(r+a.join(` `))}};y(i,0),o.length&&v.push(``);for(let e of o){let t=e.dotted?`..`:`->`;v.push(`${e.from} ${t} ${e.to}${e.label?`: `+Eo(e.label):``}`)}let b=[l?`title: ${l}`:``,`direction: ${c}`].filter(Boolean),x=[..._,...s];return[...b,...x.length?[``,...x]:[],``,...v]};function gs(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??gs(t);if(e)return e}}function _s(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??_s(n);if(r)return r}}var vs=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*;?\s*$/i,ys={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},bs={sequenceDiagram:qo,timeline:Jo,gitGraph:Qo,pie:es,"xychart-beta":ts,xychart:ts,journey:ns,mindmap:as,gantt:cs,quadrantChart:ls,kanban:fs,stateDiagram:hs,"stateDiagram-v2":hs,classDiagram:Ro,"classDiagram-v2":Ro,erDiagram:Uo},xs=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function Ss(e){let t=e.findIndex(e=>e.trim());if(t<0||e[t].trim()!==`---`)return 0;let n=e.findIndex((e,n)=>n>t&&e.trim()===`---`);return n<0?0:n+1}function Cs(e){for(let t=Ss(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function ws(e){let t=e.split(`
21
+ `),n=Cs(t);if(n<0)return;let r=t[n].trim().match(/^([A-Za-z][\w-]*)(.*)$/);if(!r)return;let[,i,a]=r;if((i in bs||xs.test(i))&&!/^[\w-]/.test(a)&&!(!(i===`pie`&&/^\s*(showData\b|title\b)/.test(a))&&/"/.test(a)||/[{]|->|=>|\.\.>|^\s*[,:.[]/.test(a)))return{type:i,rest:a,index:n}}function Ts(e){let t=e.split(`
22
+ `),n=Cs(t);if(n>=0&&vs.test(t[n]))return!0;let r=ws(e);return!!r&&r.type in bs}function Es(e){let t=ws(e);return t&&!(t.type in bs)?t.type:void 0}function Ds(e){let t=ws(e),n=t&&bs[t.type];if(!t||!n)return Ms(e);let r=[],i=new Set,a=e.split(`
23
+ `),o;for(let e=0;e<Ss(a);e++){let t=a[e].match(/^\s*title\s*:\s*(.+)$/);t&&(o=H(t[1]))}let s=[];for(let e=t.index+1;e<a.length;e++){let t=a[e].replace(/%%.*$/,``).replace(/\s+$/,``),n=t.trim();if(!n)continue;let r=t.match(/^\s*/)[0];s.push({text:n,line:e+1,indent:r.replace(/\t/g,` `).length})}return{source:n(s,{header:t.rest.replace(/%%.*$/,``).trim(),title:o,warn:(e,t)=>r.push({line:e,message:t}),warnOnce(e,t,n){i.has(e)||(i.add(e),r.push({line:t,message:n}))}}).join(`
24
+ `).replace(/^\n+/,``)+`
25
+ `,warnings:r}}var Os=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],ks=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,As=/^([<ox])?(--|==|-\.)\s*([^-=.>|][^>|]*?)\s*(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,js=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/;function Ms(e){let t=[],n=[],r=[],i=new Map,a=new Set,o=[],s=0,c=new Set,l=e=>{let t=i.get(e);return t||(t=e.replace(/[^\p{L}\p{N}_-]/gu,`_`).replace(/-+$/,``),/^[\p{L}_]/u.test(t)||(t=`n`+t),bo.has(t)&&(t+=`_`),i.set(e,t),t)},u=()=>` `.repeat(s),d=e.split(`
26
+ `),f=Ss(d);for(let e=0;e<d.length;e++){let i=n=>t.push({line:e+1,message:n});if(e<f){let t=d[e].match(/^\s*title\s*:\s*(.+)$/);t&&r.push(`title: ${t[1].trim().replace(/^(["'])(.*)\1$/,`$2`)}`);continue}let p=d[e].replace(/%%.*$/,``);for(let e of Ns(p)){let t=e.trim();if(!t)continue;let d=t.match(vs);if(d){d[2]&&r.push(`direction: ${ys[d[2].toUpperCase()]}`);continue}if(/^title\s*:?/i.test(t)&&s===0){r.push(`title: ${t.replace(/^title\s*:?\s*/i,``)}`);continue}if(/^direction\s+(TD|TB|BT|RL|LR)$/i.test(t)){s?i(`subgraph direction is not supported; the whole diagram uses one direction`):r.push(`direction: ${ys[t.split(/\s+/)[1].toUpperCase()]}`);continue}let f=t.match(/^subgraph\s+(.*)$/);if(f){let e=f[1].trim(),t,r,i=e.match(/^([\w-]+)\s*\[(.*)\]$/);i?[t,r]=[l(i[1]),H(i[2])]:/^".*"$/.test(e)?[r,t]=[H(e),l(H(e).toLowerCase())]:/^[\w-]+$/.test(e)?[t,r]=[l(e),e]:[r,t]=[e,l(e.toLowerCase())],c.add(t),n.push(`${u()}group ${t} ${V(r)} {`),s++;continue}if(t===`end`){s?(s--,n.push(`${u()}}`)):i(`"end" without subgraph`);continue}let p=t.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(p){let e=Oo(p[2],i);for(let t of p[1].split(`,`))o.push(`.${t.trim()} [${e}]`);continue}let m=t.match(/^class\s+([\w,\s-]+?)\s+([\w-]+)$/);if(m){for(let e of m[1].split(`,`))n.push(`${u()}${l(e.trim())} .${m[2]}`);continue}let h=t.match(/^style\s+([\w-]+)\s+(.*)$/);if(h){let e=Oo(h[2],i);e&&n.push(`${u()}${l(h[1])} [${e}]`);continue}if(/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/.test(t)){i(`"${t.split(/\s+/)[0]}" is not supported and was skipped`);continue}let g=Ps(t,l,i);if(g){for(let e of g.nodes){let t=[e.id];e.label!==void 0&&e.label!==e.id&&t.push(V(e.label));for(let n of e.classes)t.push(`.${n}`);e.shape&&t.push(`[shape: ${e.shape}]`),(!a.has(e.id)||t.length>1||s)&&(n.push(u()+t.join(` `)),a.add(e.id))}for(let e of g.edges){let t=[e.label?/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e.label)?e.label:V(e.label):``,e.props?`[${e.props}]`:``].filter(Boolean).join(` `);n.push(`${u()}${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`)}}}}for(;s>0;)s--,n.push(`${u()}}`),t.push({line:d.length,message:`subgraph is missing "end"`});for(let e of c)a.has(e)&&t.push({line:1,message:`"${e}" is both a node and a subgraph; edges to subgraphs are not supported`});let p=[...r,...o.length?[``,...o]:[]];return{source:[...p,...p.length?[``]:[],...n].join(`
27
+ `)+`
28
+ `,warnings:t}}function Ns(e){let t=[],n=0,r=``,i=0;for(let a=0;a<e.length;a++){let o=e[a];r?o===r&&(r=``):o===`"`?r=o:`[({`.includes(o)?n++:`)]}`.includes(o)?n=Math.max(0,n-1):o===`;`&&n===0&&(t.push(e.slice(i,a)),i=a+1)}return t.push(e.slice(i)),t}function Ps(e,t,n){let r=0,i=e,a=()=>{for(;r<i.length&&/\s/.test(i[r]);)r++},o=[],s=()=>{a();let e=i.slice(r).match(ks);if(!e)return null;r+=e[0].length;let n={id:t(e[0]),classes:[]};for(let[e,t,a]of Os){if(!i.startsWith(e,r))continue;let o=Fs(i,r+e.length,t);if(!(o<0)){n.label=H(i.slice(r+e.length,o)),n.shape=a||void 0,r=o+t.length;break}}for(;i.startsWith(`:::`,r);){let e=i.slice(r+3).match(/^[\w-]+/);if(!e)break;n.classes.push(e[0]),r+=3+e[0].length}return o.push(n),n},c=()=>{let e=[];for(;;){let t=s();if(!t)return e.length?e:null;if(e.push(t),a(),i[r]===`&`)r++;else return e}},l=c();if(!l)return n(`could not read "${e}"`),null;let u=[],d=l;for(;a(),!(r>=i.length);){let t=i.slice(r),a=t.match(As),o,s,l,f;if(a&&/[->=]/.test(a[4]))[o,s,f]=[a[1],a[2],H(a[3])],l=a[4].endsWith(`>`)?`>`:a[5],r+=a[0].length;else{if(a=t.match(js),!a){n(`could not read "${t}"`);break}[o,s,l]=[a[1],a[2],a[3]],f=a[4]===void 0?void 0:H(a[4]),r+=a[0].length}let p=s.startsWith(`=`),m=s.includes(`.`),h=!!l,g=!!o,_,v=[];_=g&&h?`<->`:!h&&!g?`--`:p?`=>`:m?`..>`:`->`,(_===`<->`||_===`--`)&&(p&&v.push(`width: 3`),m&&v.push(`style: dotted`)),l===`o`&&v.push(`head: dot`),l===`x`&&v.push(`head: bar`),o===`o`&&v.push(`tail: dot`),o===`x`&&v.push(`tail: bar`),g&&!h&&(_=`--`,v.push(`tail: arrow`));let y=c();if(!y){n(`link without a target in "${e}"`);break}for(let e of d)for(let t of y)u.push({from:e.id,to:t.id,arrow:_,label:f||void 0,props:v.join(`, `)||void 0});d=y}return{nodes:o,edges:u}}function Fs(e,t,n){let r=!1;for(let i=t;i<e.length;i++)if(e[i]===`"`&&(r=!r),!r&&e.startsWith(n,i))return i;return-1}var Is=e=>Math.round(e);function Ls(e){let t=[];for(let[n,r]of Object.entries(e.nodes)){let e=[n];r.x!==void 0&&r.y!==void 0&&e.push(`at ${Is(r.x)} ${Is(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${Is(r.w)} ${Is(r.h)}`),e.length>1&&t.push(` `+e.join(` `))}for(let n of e.ranks??[])t.push(` rank ${n.join(` `)}`);for(let[n,r]of Object.entries(e.edges)){let e=[n];r.via?.length&&e.push(`via `+r.via.map(e=>`${Is(e.x)} ${Is(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(Is(r.label.x)||Is(r.label.y))&&e.push(`label ${Is(r.label.x)} ${Is(r.label.y)}`),e.length>1&&t.push(` `+e.join(` `))}for(let[n,r]of Object.entries(e.panels??{})){r.at&&t.push(` ${n} at ${Is(r.at.x)} ${Is(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(Is(i.x)||Is(i.y))&&t.push(` ${n}:${e} ${Is(i.x)}${Is(i.y)?` ${Is(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
29
+ `)}\n}`:``}function Rs(e,t,n=Tn(e)){let r=Ls(t),i=e.split(`
30
+ `);if(n.layoutBlock){let[e,t]=n.layoutBlock,a=!r&&e>0&&i[e-1].trim()===``?e-1:e;return i.splice(a,t-a+1,...r?r.split(`
31
+ `):[]),i.join(`
32
+ `)}return r?`${e.replace(/\s*$/,``)}\n\n${r}\n`:e}var zs=e=>gn({v:e}).replace(/^v: /,``);function Bs(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=R(a.slice(s+1,c-1))),i===null?delete o[r]:o[r]=i;let l=gn(o),u=l?`[${l}]`:``,d=a.slice(0,s),f=a.slice(c);if(e[t.line]=t.props?d+u+f:d+(u?(t.prefix??``)+` `+u:``)+f,!l&&t.props){let r=d.replace(/\s+$/,``);n===`edge`&&r.endsWith(`:`)&&!f.trim()&&(r=r.slice(0,-1).replace(/\s+$/,``)),e[t.line]=(r+f).replace(/\s+$/,``)}}var Vs=(e,t)=>t.kind===`node`?e.nodes.get(t.id):t.kind===`group`?e.groups.get(t.id):t.kind===`panel`?e.panels.find(e=>e.id===t.id):e.edges.find(e=>e.key===t.id);function Hs(e,t,n){let r=t.layoutBlock?t.layoutBlock[0]:e.length,i=r>0&&e[r-1].trim()!==``&&t.layoutBlock?[n,``]:[n];return!t.layoutBlock&&e[e.length-1]===``?e.splice(e.length-1,0,...i):e.splice(r,0,...i),e.join(`
33
+ `)}var Us=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Ws=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e);function Gs(e,t,n,r=Tn(e)){let i=Vs(r,t);if(!i)return e;let a=e.split(`
34
+ `),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?Hs(a,r,`${t.id} ${Us(n)}`):e;if(o.generated)return e;let s=a[o.line],c=t.kind===`edge`;if(!n){if(!o.range)return e;let t=s.slice(0,o.range[0]).replace(/\s+$/,``),n=s.slice(o.range[1]);return o.id&&(t+=` `+o.id),c&&t.endsWith(`:`)&&!n.trim()&&(t=t.slice(0,-1).replace(/\s+$/,``)),a[o.line]=(t+n).replace(/\s+$/,``),a.join(`
35
+ `)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&Ws(n)?n:Us(n));return a[o.line]=o.range?s.slice(0,o.range[0])+u+s.slice(o.range[1]):s.slice(0,o.at)+(o.colon===!1?`:`:``)+` `+u+s.slice(o.at),a.join(`
36
+ `)}var Ks={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function qs(e,t,n,r,i=Tn(e)){n=un(n);let a=Vs(i,t);if(!a)return e;let o=Js(e,t,n,r,i,a);for(let e of(Ks[n]??[]).filter(e=>e in a.props))o=qs(o,t,e,null);return o}function Js(e,t,n,r,i,a){let o=e.split(`
37
+ `),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:Hs(o,i,`${t.id} [${gn({[n]:r})}]`);let c=s.propLines;if(c){let e=s.props?R(o[s.line].slice(s.props[0]+1,s.props[1]-1)):{};if(n in c)return r===null?o.splice(c[n],1):o[c[n]]=`${o[c[n]].match(/^\s*/)[0]}${n}: ${zs(r)}`,n in e&&Bs(o,s,t.kind,n,null),o.join(`
38
+ `);if(r!==null&&!(n in e)){let e=Math.max(...Object.values(c));return o.splice(e+1,0,`${o[e].match(/^\s*/)[0]}${n}: ${zs(r)}`),o.join(`
39
+ `)}}return Bs(o,s,t.kind,n,r),o.join(`
40
+ `)}function Ys(e,t,n){let r=e.split(`
41
+ `),i=RegExp(`^(export\\s+)?${t.replace(/[-]/g,`\\-`)}\\s*:`),a=r.findIndex(e=>i.test(e));if(a>=0)return n===null?r.splice(a,1):r[a]=`${r[a].match(i)[1]??``}${t}: ${n}`,r.join(`
42
+ `);if(n===null)return e;let o=0;for(;o<r.length&&/^(export\s+)?[\w-]+\s*:(?!:)/.test(r[o])&&!r[o].includes(`->`)||/^\s*(\/\/|#)/.test(r[o]??``);)o++;return r.splice(o,0,`${t}: ${n}`),r.join(`
43
+ `)}function Xs(e,t,n,r=Tn(e)){let i,a=Qs(e,t,r,(e,t)=>{let r=e.editPart?.(t.body,n,t.data);return i=r?.id,r?.body??null});return{source:a,id:a===e?void 0:i}}function Zs(e,t,n,r){let i=t.panels.find(e=>e.id===n),a=t.layout.panels?.[n]?.parts?.[r.part];if(!a||!r.editPosition||!i?.lines||i.ref?.generated)return Rs(e,t.layout,t);let[o,s]=i.lines,c=e.split(`
44
+ `),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,sn(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return Rs(e,t.layout,t);let f=u.slice(d,d+i.body.length),p=r.editPosition(f,a);if(!p||p.length!==f.length)return Rs(e,t.layout,t);if(p.forEach((e,t)=>{c[o+1+d+t]=e+l[d+t].slice(f[t].length)}),t.layoutBlock){let[e,i]=t.layoutBlock,a=n+`:`+r.part,o=c.slice(e+1,i),s=o.filter(e=>e.trimStart().split(/\s+/,1)[0]!==a);if(s.length!==o.length){if(s.some(e=>e.trim()))c.splice(e+1,o.length,...s);else{let t=e>0&&!c[e-1].trim()?e-1:e;c.splice(t,i-t+1)}}}return c.join(`
45
+ `)}function Qs(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&Wt.get(i.kind);if(!i?.lines||!a||i.ref&&i.ref.generated)return e;let[o,s]=i.lines;if(s-o-1!==i.body.length)return e;let c=r(a,i);if(!c)return e;let l=e.split(`
46
+ `),u=l.slice(o+1,s).filter(e=>e.trim()),d=u.length?u.map(e=>e.match(/^\s*/)[0]).reduce((e,t)=>t.length<e.length?t:e):l[o].match(/^\s*/)[0]+` `;return l.splice(o+1,s-o-1,...c.map(e=>e.trim()?d+e:``)),l.join(`
47
+ `)}function $s(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=_o(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=Es(e);if(t)return{source:``,format:`mermaid`,diagnostics:[{line:1,severity:`error`,message:`Mermaid "${t}" is not supported; yuhwa has no equivalent for it`}]};if(Ts(e)){let t=Ds(e);return{source:t.source,format:`mermaid`,diagnostics:t.warnings.map(e=>({...e,message:`mermaid: ${e.message}`,severity:`warning`}))}}return{source:e,format:`yuhwa`,diagnostics:[]}}var ec=class{timer;apply;redraw;constructor(e,t){this.apply=e,this.redraw=t}input(e){this.apply(e,this.timer===void 0),this.end(),this.timer=setTimeout(()=>{this.timer=void 0,this.redraw()},150)}end(){clearTimeout(this.timer),this.timer=void 0}},tc=class{revision=0;acknowledged=0;active=!1;write;status;constructor(e,t){this.write=e,this.status=t}get dirty(){return this.revision!==this.acknowledged}changed(){this.revision++}async save(){if(!this.active&&this.dirty){this.active=!0;try{for(;this.dirty;){let e=this.revision,t=await this.write();this.acknowledged=e,this.dirty||this.status(t)}}catch{this.status(`save failed`)}finally{this.active=!1}}}},nc=[{name:`Everything (showcase)`,source:`title: **Shopfront** platform
48
+ subtitle: everything yuhwa can draw, in one file
49
+ direction: right
50
+ theme: paper
51
+ panels: wrap
52
+ panel-gap: 40
53
+ legend: .svc Service | .store Datastore | .ext External | --> async | ..> optional | red Deprecated
54
+ footer: yuhwa showcase | {teal: v1.0} | 2026
55
+
56
+ // variables: replaced in labels, props, settings and panel bodies
57
+ $brand: indigo
58
+ $db: "Postgres 16"
59
+ $warn: rgb(234, 88, 12)
60
+
61
+ // classes, one built on another
62
+ .svc [color: $brand, shape: rounded]
63
+ .store [amber, cylinder]
64
+ .ext [color: hsl(330 70% 50%), dashed]
65
+ .primary .svc [bold, shadow]
66
+ .async [dashed, flow: true]
67
+
68
+ // a component: one service, its database and the edge between them
69
+ def service(id, label, lang = Go) {
70
+ $id "$label" .svc [sub: $lang]
71
+ \${id}_db "$label DB" .store
72
+ $id -> \${id}_db: SQL
73
+ }
74
+
75
+ // nodes: every shape, sub lines, icons, links and tooltips
76
+ user "Customer" [shape: circle, purple, icon: 🙂]
77
+ admin "Admin" [ellipse, #0ea5e9]
78
+ web "Storefront" [frame: browser shop.example.com] {
79
+ **Cart** || 3 items
80
+ ---
81
+ progress: 72% checkout funnel
82
+ spark: 3 5 4 6 8 7 9
83
+ }
84
+
85
+ group edge "Edge" [color: slate, dashed] {
86
+ cdn "CDN" [hexagon, teal, link: https://example.com, tooltip: cached at 40 PoPs]
87
+ waf "WAF" [parallelogram, color: tomato]
88
+ }
89
+
90
+ group core "Core services" [color: #4f46e5] {
91
+ gateway "API Gateway" .svc .primary [sub: "auth, rate limit"]
92
+ service(orders, Orders, Kotlin)
93
+ service(payments, Payments, lang: Rust)
94
+ group search "Search" [teal] {
95
+ indexer "Indexer" .svc
96
+ es "Elasticsearch" .store [color: $warn]
97
+ }
98
+ }
99
+
100
+ queue "Event bus" [diamond, lime]
101
+ stripe "Stripe" .ext [document]
102
+ legacy "Legacy ERP" [box, red, opacity: 0.7]
103
+ note "nightly sync,\\nbest effort" [note, yellow-100]
104
+
105
+ metrics "metrics" [meta: live, caps: true] {
106
+ stat: 99.98% uptime | 41ms p50
107
+ bars: 3 5 4 6 8 9 7
108
+ | service | p95 |
109
+ |----------|--------|
110
+ | orders | 120 ms |
111
+ | payments | 88 ms |
112
+ ✓ health || [[green: ok]]
113
+ }
114
+
115
+ // edges: every arrow, labels, captions and edge props
116
+ user -> web: browse
117
+ web -> cdn: assets [label-bg: lightyellow, curve: straight]
118
+ admin => cdn: purge [color: $brand, width: 3]
119
+ cdn -> waf -> gateway
120
+ gateway -> orders, payments
121
+ gateway <-> indexer: query [curve: orthogonal]
122
+ orders --> queue: OrderPlaced .async
123
+ queue ..> indexer: reindex [caption: within 2 s]
124
+ payments -> stripe: charge [head: dot, color: #db2777]
125
+ indexer -- es
126
+ queue -> legacy: export [dotted, red]
127
+ legacy .. note
128
+ stripe == metrics
129
+
130
+ // panels, in reading order: how it works, how it runs, what comes next
131
+ sequence login "Sign in" [numbered, lifeline-style: dotted] {
132
+ actor user "Customer" [purple]
133
+ participant web, db
134
+ participant api "API" [indigo]
135
+ user -> web: open /login
136
+ web -> api: POST /login
137
+ api -> db: find user
138
+ db --> api: row [width: 2]
139
+ api -> db: audit [red, dotted, head: open]
140
+ note api: checks the hash [amber]
141
+ --- session ---
142
+ api --> web: 200 + cookie [green]
143
+ web -> web: render
144
+ }
145
+
146
+ chart p95 "Latency p95" [type: column, unit: ms] {
147
+ checkout: 120
148
+ search [green]: 48
149
+ payments [hsl(330 70% 50%)]: 88
150
+ }
151
+
152
+ chart traffic "Traffic by region" [type: donut, unit: %, theme: midnight, shadow] {
153
+ EU: 46
154
+ US [indigo]: 31
155
+ APAC: 23
156
+ }
157
+
158
+ quadrant prio "Priorities" [background: lightyellow, border: orange, border-style: dashed, radius: 6] {
159
+ x-axis Low effort -> High effort
160
+ y-axis Low value -> High value
161
+ q1 [green]: Quick wins
162
+ q2: Big bets
163
+ q3: Fill-ins
164
+ q4 [red]: Money pit
165
+ Search [teal]: 0.25, 0.8
166
+ Billing: 0.7, 0.65
167
+ Exports [color: tomato]: 0.3, 0.3
168
+ }
169
+
170
+ // three looks for a gantt: a label column, names on solid bars, thin lines
171
+ gantt plan "Q1 plan" [today: 2026-01-20, weekends: show] {
172
+ --- Design [violet] ---
173
+ research "User research" [progress: 100%]: 2026-01-05, 5d
174
+ wireframes [done]: after research, 4d
175
+ review [milestone]: after wireframes
176
+ --- Build [teal] ---
177
+ api "Build API" [active, progress: 40%, owner: ana]: 2026-01-14, 2w
178
+ ui [crit, owner: kim]: after wireframes api, 10d
179
+ launch [milestone, red]: after ui
180
+ }
181
+
182
+ gantt release "Release 2.0" [theme: midnight, today: 2026-02-18, bars: solid, labels: bar, notes: dates, density: compact, arrows: curved, summary: hide] {
183
+ --- Beta [sky] ---
184
+ beta "Private beta" [progress: 80%]: 2026-02-02, 2w
185
+ feedback "Feedback round" [active]: after beta, 1w
186
+ --- GA [green] ---
187
+ docs "Docs" [progress: 30%]: 2026-02-16, 10d
188
+ ga "General availability" [milestone]: after feedback docs
189
+ }
190
+
191
+ gantt hiring "Hiring" [bars: thin, labels: bar, rows: plain, grid: none, scale: week, density: loose] {
192
+ sourcing "Sourcing" [blue, progress: 70%]: 2026-01-05, 3w
193
+ interviews "Interviews" [indigo]: after sourcing, 4w
194
+ offers "Offers" [green]: after interviews, 2w
195
+ start "First day" [milestone]: after offers
196
+ }
197
+
198
+ timeline roadmap "Roadmap" [border: 2] {
199
+ 2026 Q1: Private beta
200
+ - 40 design partners
201
+ 2026 Q2 [green]: **Launch**
202
+ 2026 Q3 [#0ea5e9]: Mobile app
203
+ 2026 Q4 [color: rgb(234, 88, 12)]: EU region
204
+ }
205
+
206
+ kanban sprint "Sprint 12" {
207
+ Todo [gray]
208
+ - Write docs [owner: ana, priority: high]
209
+ - **Fix** login [red]
210
+ Doing [blue, limit: 2]
211
+ - API v2 [ticket: MER-12]
212
+ needs the new auth flow
213
+ - Search tuning [owner: kim]
214
+ - Billing export
215
+ Done [green]
216
+ - Ship 1.0
217
+ }
218
+
219
+ git release_flow "Release flow" {
220
+ commit "init" [tag: v1.0]
221
+ branch feature/login [pink]
222
+ commit "login form"
223
+ commit "oauth"
224
+ checkout main
225
+ commit "hotfix" [id: fix, highlight, red]
226
+ merge feature/login [tag: v1.1]
227
+ branch release/1.0 from v1.0 [label: "1.0.x", #0ea5e9]
228
+ cherry-pick fix
229
+ }
230
+
231
+ mindmap ideas "Launch plan" [layout: both] {
232
+ **Launch**
233
+ Marketing [pink]
234
+ Blog posts
235
+ Newsletter
236
+ Product
237
+ Beta [#16a34a]
238
+ - Pricing page
239
+ Sales [shape: pill]
240
+ Partners
241
+ }
242
+ `},{name:`Multi-file system`,source:`title: Shop platform
243
+ subtitle: three files, one diagram
244
+ legend: .svc Service | .store Datastore | .ext External | --> async
245
+
246
+ // the shared look: only what styles.yuhwa exports
247
+ import { theme, .svc, .store, .ext, .async, $brand } from "./shared/styles.yuhwa"
248
+ accent: $brand
249
+ // the orders group (with its members) and payments, renamed
250
+ import { orders, payments as billing } from "./services.yuhwa"
251
+ // the release history panel
252
+ import "./release.yuhwa"
253
+
254
+ user "Shopper" [circle, purple]
255
+ web "Storefront" .svc
256
+ sub: Next.js
257
+ stripe "Stripe" .ext
258
+
259
+ user -> web: browses [flow]
260
+ web -> orders-api: place order
261
+ orders-api -> billing: charge
262
+ billing -> stripe: API .async
263
+ `,files:{"shared/styles.yuhwa":`// shared classes, imported by every diagram
264
+ // one theme for every file that imports it (a plain theme: line would stay here)
265
+ export theme: pastel
266
+ export $brand: blue
267
+ .svc
268
+ color: $brand
269
+ shape: rounded
270
+ .store [amber, cylinder]
271
+ .ext [slate, dashed]
272
+ .async
273
+ style: dashed
274
+ flow: true
275
+ .internal [red]
276
+
277
+ // .internal stays private to this file
278
+ export .svc, .store, .ext, .async
279
+ `,"services.yuhwa":`import { theme, .svc, .store } from "./shared/styles.yuhwa"
280
+
281
+ // one service: its API, its database and the line between them
282
+ def service(id, label, store, lang = Go) {
283
+ $id "$label" .svc
284
+ sub: $lang
285
+ $store .store
286
+ $id -> $store
287
+ }
288
+
289
+ export orders, payments, search
290
+
291
+ group orders "Orders" {
292
+ service(orders-api, "Orders API", orders-db, Kotlin)
293
+ }
294
+
295
+ payments "Payments" .svc
296
+ sub: Go
297
+ search "Search" .svc
298
+ `,"release.yuhwa":`git release "Releases" {
299
+ commit "init" [tag: v0.1.0]
300
+ branch feature/cart
301
+ commit "cart model"
302
+ commit "checkout"
303
+ checkout main
304
+ commit "hotfix" [id: hotfix, type: highlight]
305
+ merge feature/cart [tag: v0.2.0]
306
+ branch release/0.2
307
+ cherry-pick hotfix
308
+ }
309
+ `}},{name:`Web app`,source:`title: Web app
310
+ direction: right
311
+
312
+ .svc [blue]
313
+
314
+ user "You" [circle, purple]
315
+ group app "Your app" {
316
+ web "Web app" .svc
317
+ sub: Next.js
318
+ api "API" .svc
319
+ }
320
+ db "Database" [cylinder, amber]
321
+
322
+ user -> web: visits
323
+ flow: true
324
+ web -> api
325
+ api -> db: SQL
326
+ `},{name:`Team ownership`,source:`title: Who owns what
327
+ subtitle: three teams, one request path
328
+ theme: pastel
329
+
330
+ .web [blue]
331
+ .platform [purple]
332
+ .data [green]
333
+
334
+ group web "Web team" .web {
335
+ meta: 5 people
336
+ site "Marketing site" .web
337
+ shop "Shop frontend" .web
338
+ }
339
+ group platform "Platform team" .platform {
340
+ meta: 4 people
341
+ gw "API gateway" .platform
342
+ auth "Auth" .platform
343
+ }
344
+ group data "Data team" .data {
345
+ meta: 3 people
346
+ wh "Warehouse" .data [cylinder]
347
+ bi "Dashboards" .data
348
+ }
349
+
350
+ site, shop -> gw
351
+ gw -> auth
352
+ gw ..> wh: events
353
+ flow: true
354
+ wh -> bi
355
+ `},{name:`Release dashboard`,source:`title: Shop release **v2.4**
356
+ subtitle: what ships on {green: Friday}
357
+ footer: **landfall** v2.4 | \`eu-central-1\` | updated {green: 2 min ago}
358
+ theme: midnight
359
+
360
+ app "Storefront" [frame: browser shop.example.com, blue] {
361
+ stat: 99.9% uptime | 42ms p95 | 1.2k rps
362
+ ---
363
+ spark blue: 3 5 4 6 8 7 9 12 10 14
364
+ }
365
+ ci "Pipeline" [frame: terminal ~/shop, meta: 42s] {
366
+ progress green: 72% tests
367
+ progress amber: 9/12 deploys
368
+ bars purple: 3 5 4 8 6 9
369
+ }
370
+ flags "Flags" [frame: window Settings] {
371
+ new-checkout || [[green: on]]
372
+ dark-mode || [[off]]
373
+ }
374
+
375
+ app -> ci: build
376
+ flow: true
377
+ ci -> flags
378
+ `},{name:`Service table`,source:`title: Service status
379
+ theme: terminal
380
+
381
+ api "api" [meta: v3.2, green] {
382
+ | route | p95 | rps |
383
+ |----------|-------|------|
384
+ | /orders | 42ms | 310 |
385
+ | /cart | 18ms | 920 |
386
+ }
387
+ db "postgres" [cylinder, amber]
388
+
389
+ api -> db: pool 20
390
+ `},{name:`Annotated sketch`,source:`theme: mono
391
+ curve: straight
392
+
393
+ a "Input" -> b "Parse" -> c "Layout" -> d "Render" -> e "SVG" [document]
394
+ note "deterministic:\\nsame input, same SVG" [note]
395
+ d -- note
396
+ style: dotted
397
+ constraint: false
398
+ `},{name:`Sign-in story`,source:`title: Sign in
399
+ subtitle: flow, sequence and numbers in one file
400
+ panels: row
401
+
402
+ web "Web" [blue] -> api "API" [blue] -> db "Postgres" [cylinder, amber]
403
+
404
+ sequence login "Sign in" [numbered] {
405
+ actor user "Customer" [purple]
406
+ participant web, api, db
407
+ user -> web: open /login
408
+ web -> api: POST /login
409
+ api -> db: find user
410
+ db --> api: row
411
+ note api: compares the **bcrypt** hash
412
+ api --> web: 200 + cookie
413
+ }
414
+
415
+ chart latency "Latency p95" [unit: ms] {
416
+ checkout: 120
417
+ search [green]: 48
418
+ login: 80
419
+ }
420
+ `},{name:`Git flow`,source:`title: Release flow
421
+ subtitle: trunk-based, short-lived branches
422
+
423
+ git flow "main and feature branches" {
424
+ commit "init" [tag: v0.1.0]
425
+ branch feature/login
426
+ commit "login form"
427
+ commit "oauth provider"
428
+ checkout main
429
+ commit "fix typo"
430
+ branch fix/cache [amber]
431
+ commit "cache headers"
432
+ checkout main
433
+ merge fix/cache [tag: v0.1.1]
434
+ merge feature/login [tag: v0.2.0]
435
+ commit "docs"
436
+ }
437
+ `},{name:`Product overview`,source:`title: Checkout v2
438
+ subtitle: architecture, plan, branches and numbers in one file
439
+ panels: grid
440
+
441
+ .svc [blue]
442
+ web "Web" .svc -> api "API" .svc -> db "Orders" [cylinder, amber]
443
+ api -> queue "Events" [pill, teal]: publish
444
+ style: dashed
445
+
446
+ timeline plan "Roadmap" {
447
+ Jan: Design
448
+ Feb [blue]: Build
449
+ Mar [green]: **Launch**
450
+ }
451
+
452
+ git branches "Branches" {
453
+ commit "v1" [tag: v1.0]
454
+ branch checkout-v2
455
+ commit "new cart"
456
+ commit "payments"
457
+ checkout main
458
+ merge checkout-v2 [tag: v2.0]
459
+ }
460
+
461
+ chart conv "Conversion" [type: line, unit: %] {
462
+ Jan: 2.1
463
+ Feb: 2.4
464
+ Mar: 3.2
465
+ }
466
+ `}],rc=[{label:`Sequence diagram`,group:`Panels`,id:`seq`,text:`sequence {id} "Checkout" [numbered] {
467
+ actor user "Customer" [purple]
468
+ participant web, api, db
469
+ user -> web: add to cart
470
+ web -> api: POST /orders
471
+ api -> db: insert order
472
+ db --> api: id
473
+ note api: idempotency key
474
+ api --> web: 201 Created
475
+ }`},{label:`Timeline`,group:`Panels`,id:`plan`,text:`timeline {id} "Roadmap" {
476
+ 2026 Q1: Private beta
477
+ - 40 design partners
478
+ 2026 Q2 [green]: **Launch**
479
+ 2026 Q4 [amber]: EU region
480
+ }`},{label:`Bar chart`,group:`Panels`,id:`chart`,text:`chart {id} "Requests by service" [type: bar] {
481
+ api: 420
482
+ web: 310
483
+ worker [amber]: 95
484
+ }`},{label:`Donut chart`,group:`Panels`,id:`share`,text:`chart {id} "Traffic by region" [type: donut, unit: %] {
485
+ EU: 46
486
+ US: 31
487
+ APAC: 23
488
+ }`},{label:`Line chart`,group:`Panels`,id:`latency`,text:`chart {id} "p95 latency" [type: line, unit: ms] {
489
+ Mon: 120
490
+ Tue: 96
491
+ Wed: 140
492
+ Thu: 88
493
+ Fri: 72
494
+ }`},{label:`Git branches`,group:`Panels`,id:`git`,text:`git {id} "Release flow" {
495
+ commit "init" [tag: v1.0]
496
+ checkout -b feature/login
497
+ commit "login form"
498
+ commit "oauth"
499
+ checkout main
500
+ commit "hotfix" [id: fix, type: highlight, tag: v1.0.1]
501
+ merge feature/login [tag: v1.1]
502
+ branch release/1.0 from v1.0 [label: "1.0.x"]
503
+ cherry-pick fix
504
+ }`},{label:`Mind map`,group:`Panels`,id:`ideas`,text:`mindmap {id} "Launch plan" {
505
+ **Launch**
506
+ Marketing [pink]
507
+ Blog posts
508
+ Newsletter
509
+ Product
510
+ Beta [green]
511
+ Sales
512
+ }`},{label:`Gantt chart`,group:`Panels`,id:`plan`,text:`gantt {id} "Q1 plan" {
513
+ --- Design ---
514
+ research "User research": 2026-01-05, 5d
515
+ wireframes [blue]: after research, 4d
516
+ --- Build ---
517
+ api "Build API" [green, active]: after wireframes, 2w
518
+ launch [milestone]: after api
519
+ }`},{label:`Quadrant`,group:`Panels`,id:`prio`,text:`quadrant {id} "Priorities" {
520
+ x-axis Low effort -> High effort
521
+ y-axis Low value -> High value
522
+ q1: Quick wins
523
+ q2: Big bets
524
+ q3: Fill-ins
525
+ q4: Money pit
526
+ Search [teal]: 0.25, 0.8
527
+ Billing: 0.7, 0.65
528
+ }`},{label:`Kanban board`,group:`Panels`,id:`board`,text:`kanban {id} "Sprint" {
529
+ Todo [gray]
530
+ - Write docs [owner: ana]
531
+ Doing [blue, limit: 2]
532
+ - API v2 [ticket: MER-12]
533
+ Done [green]
534
+ - Ship 1.0
535
+ }`},{label:`Node`,group:`Graph`,id:`node`,text:`{id} "New node" [blue]`},{label:`Group`,group:`Graph`,id:`group`,text:`group {id} "New group" {
536
+ {id}_a "First"
537
+ {id}_b "Second"
538
+ }
539
+ {id}_a -> {id}_b`},{label:`Class (shared style)`,group:`Graph`,id:`style`,text:`.{id} [color: teal, shape: pill]`},{label:`Variable`,group:`Graph`,id:`color`,text:"${id}: teal"},{label:`Component (reusable nodes)`,group:`Graph`,id:`service`,text:`def {id}(id, label, lang = Go) {
540
+ $id "$label" [color: blue, sub: $lang]
541
+ $id-db [shape: cylinder, color: amber]
542
+ $id -> $id-db
543
+ }
544
+ {id}(first, "First")
545
+ {id}(second, "Second", Rust)`},{label:`Card with rows`,group:`Graph`,id:`card`,text:`{id} "orders" [meta: 12k/day, color: amber] {
546
+ | field | type |
547
+ |--------|-------|
548
+ | id | uuid |
549
+ | total | money |
550
+ ---
551
+ spark: 3 5 4 8 7 9
552
+ }`}],ic=class{worker;id=0;pending=new Map;handlers=new Map;versions=new Map;constructor(e){this.worker=e,e.addEventListener(`message`,e=>this.receive(e.data))}receive(e){if(e&&typeof e==`object`){if(`id`in e&&!(`method`in e)){let t=this.pending.get(e.id);if(!t)return;this.pending.delete(e.id),e.error?t.reject(Error(e.error.message)):t.resolve(e.result)}else if(`method`in e){`id`in e&&this.worker.postMessage({jsonrpc:`2.0`,id:e.id,result:null});for(let t of this.handlers.get(e.method)??[])t(e.params)}}}request(e,t){let n=++this.id;return new Promise((r,i)=>{this.pending.set(n,{resolve:r,reject:i}),this.worker.postMessage({jsonrpc:`2.0`,id:n,method:e,params:t})})}notify(e,t){this.worker.postMessage({jsonrpc:`2.0`,method:e,params:t})}on(e,t){let n=this.handlers.get(e);return n||this.handlers.set(e,n=new Set),n.add(t),()=>n.delete(t)}async initialize(){let e=await this.request(`initialize`,{processId:null,rootUri:null,capabilities:{}});return this.notify(`initialized`,{}),e}open(e,t){this.versions.set(e,1),this.notify(`textDocument/didOpen`,{textDocument:{uri:e,languageId:`yuhwa`,version:1,text:t}})}change(e,t){if(!this.versions.has(e))return this.open(e,t);let n=this.versions.get(e)+1;this.versions.set(e,n),this.notify(`textDocument/didChange`,{textDocument:{uri:e,version:n},contentChanges:[{text:t}]})}close(e){this.versions.delete(e)&&this.notify(`textDocument/didClose`,{textDocument:{uri:e}})}dispose(){this.worker.terminate();for(let e of this.pending.values())e.reject(Error(`client disposed`));this.pending.clear()}},ac=e=>`file:///`+e.split(`/`).map(encodeURIComponent).join(`/`),oc=e=>decodeURIComponent(new URL(e).pathname).slice(1);function sc(e,t){let n=0;for(let r=0;r<t.line;r++){let t=e.indexOf(`
553
+ `,n);if(t<0)return e.length;n=t+1}return Math.min(n+t.character,e.length)}function cc(e,t){let n=e.slice(0,t);return{line:n.split(`
554
+ `).length-1,character:t-(n.lastIndexOf(`
555
+ `)+1)}}function lc(e,t){let n=t.map(t=>({from:sc(e,t.range.start),to:sc(e,t.range.end),text:t.newText})).sort((e,t)=>t.from-e.from);for(let t of n)e=e.slice(0,t.from)+t.text+e.slice(t.to);return e}function uc(e,t){let n=getComputedStyle(e),r=document.createElement(`div`);for(let e of[`font`,`letterSpacing`,`lineHeight`,`padding`,`border`,`boxSizing`,`tabSize`,`textIndent`,`wordSpacing`])r.style[e]=n[e];Object.assign(r.style,{position:`absolute`,visibility:`hidden`,whiteSpace:`pre-wrap`,overflowWrap:`break-word`,width:e.clientWidth+`px`,top:`0`,left:`-9999px`}),r.textContent=e.value.slice(0,t);let i=document.createElement(`span`);i.textContent=`​`,r.append(i),document.body.append(r);let a=e.getBoundingClientRect(),o={left:a.left+i.offsetLeft-e.scrollLeft,top:a.top+i.offsetTop-e.scrollTop,height:parseFloat(n.lineHeight)||i.offsetHeight};return r.remove(),o}var dc=e=>e.replace(/[&<>]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`})[e]),fc=e=>dc(e).replace(/\*\*([^*]+)\*\*/g,`<b>$1</b>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\n\n/g,`<br>`),pc={3:`ƒ`,6:`n`,7:`c`,9:`p`,10:`k`,12:`v`,14:`⌘`,17:`f`};function mc(e){let{ta:t}=e,n=new ic(new Worker(new URL(new URL(`lsp.worker-RlPj9blG.js`,import.meta.url).href,``+import.meta.url),{type:`module`})),r=n.initialize(),i=!1,a=[];r.then(e=>{a=e.capabilities.semanticTokensProvider.legend.tokenTypes,i=!0,l()});let o=new Map,s=new Map;n.on(`textDocument/publishDiagnostics`,t=>{let n=oc(t.uri);s.set(n,t.diagnostics),e.onDiagnostics(n)});function c(){if(!i)return!1;let t=e.files(),r=!1;for(let[i,a]of Object.entries(t))o.get(i)!==a&&(o.set(i,a),n.change(ac(i),a),r||=i===e.current());for(let e of o.keys())e in t||(o.delete(e),s.delete(e),n.close(ac(e)));return r}function l(){(c()||ie!==e.current())&&(re=new Map,se(),le())}async function u(i,a={},o=t.selectionStart){await r,c();let s=ac(e.current());return n.request(i,{textDocument:{uri:s},position:cc(t.value,o),...a})}function d(e){let n=sc(t.value,e.start);t.focus(),t.setSelectionRange(n,sc(t.value,e.end));let r=uc(t,n),i=t.getBoundingClientRect();(r.top<i.top||r.top+r.height>i.bottom)&&(t.scrollTop+=r.top-i.top-t.clientHeight/3)}function f(n){let r=t.selectionStart,i=lc(t.value,n);e.commit(i),t.setSelectionRange(r,r)}let p=document.createElement(`div`);p.className=`lsp-complete`,p.hidden=!0,p.setAttribute(`role`,`listbox`),document.body.append(p);let m=[],h=0,g=0,_=e=>{let n=e.textEdit&&`range`in e.textEdit?e.textEdit.range:void 0;return n?t.value.slice(sc(t.value,n.start),t.selectionStart):``};async function v(e){let n=++g,r=await u(`textDocument/completion`);if(n!==g||document.activeElement!==t)return;let i=r?.length?_(r[0]):``,a=i.toLowerCase();if(m=(r??[]).filter(e=>e.label!==i&&e.label.toLowerCase().startsWith(a)).slice(0,60),!m.length||!i&&!e&&!y())return x();h=0,b()}let y=()=>/[.[",/:>]\s?$/.test(t.value.slice(0,t.selectionStart));function b(){p.innerHTML=``,m.forEach((e,t)=>{let n=document.createElement(`div`);n.className=`item`+(t===h?` active`:``),n.setAttribute(`role`,`option`);let r=document.createElement(`span`);r.className=`kind`,r.textContent=pc[e.kind??0]??`·`;let i=document.createElement(`span`);if(i.className=`label`,i.textContent=e.label,n.append(r,i),e.detail){let t=document.createElement(`span`);t.className=`detail`,t.textContent=e.detail,n.append(t)}n.onmousedown=e=>{e.preventDefault(),S(t)},p.append(n)});let e=uc(t,t.selectionStart);p.hidden=!1;let n=e.top+e.height+p.offsetHeight<innerHeight;p.style.left=Math.min(e.left,innerWidth-p.offsetWidth-8)+`px`,p.style.top=(n?e.top+e.height+2:e.top-p.offsetHeight-2)+`px`,p.children[h]?.scrollIntoView({block:`nearest`})}function x(){g++,m=[],p.hidden=!0}function S(e){let n=m[e];if(x(),!n)return;let r=n.textEdit&&`range`in n.textEdit?n.textEdit:void 0,i=r?.newText??n.label,a=r?sc(t.value,r.range.start):t.selectionStart;t.setRangeText(i,a,t.selectionStart,`end`),t.dispatchEvent(new Event(`input`)),/[:(]\s?$/.test(i)&&v(!0)}let C=document.createElement(`div`);C.className=`lsp-hover`,C.hidden=!0,document.body.append(C);let w=0;async function T(){let e=t.selectionStart;if(e!==t.selectionEnd)return;let n=await u(`textDocument/hover`);if(!n||t.selectionStart!==e||!p.hidden)return;let r=typeof n.contents==`object`&&`value`in n.contents?n.contents.value:String(n.contents);C.innerHTML=fc(r);let i=uc(t,n.range?sc(t.value,n.range.start):e);C.hidden=!1,C.style.left=Math.min(i.left,innerWidth-C.offsetWidth-8)+`px`,C.style.top=i.top-C.offsetHeight-4+`px`}let E=()=>{clearTimeout(w),C.hidden=!0};async function D(){try{let t=await u(`textDocument/prepareRename`),n=prompt(`Rename ${t.placeholder} to`,t.placeholder)?.trim();if(!n||n===t.placeholder)return;let r=(await u(`textDocument/rename`,{newName:n})).changes[ac(e.current())]??[];f(r),e.status(`renamed ${r.length} place${r.length===1?``:`s`}`)}catch(t){e.status(t.message)}}async function ee(){let t=await u(`textDocument/definition`);if(!t)return e.status(`no definition here`);let n=oc(t.uri);if(n!==e.current()){if(!(n in e.files()))return e.status(`${n} is not open`);e.open(n)}d(t.range)}let O=document.createElement(`pre`);O.className=`lsp-paint`,O.setAttribute(`aria-hidden`,`true`);let te=document.createElement(`div`);te.className=`lsp-wrap`,t.replaceWith(te),te.append(O,t);let ne=new Map,re=new Map,ie=``,ae=null,oe=0,k=0;function se(){O.style.width=t.clientWidth+`px`,O.style.height=t.clientHeight+`px`;let e=``;for(let[n,r]of t.value.split(`
556
+ `).entries()){n&&(e+=`
557
+ `);let t=ae&&n>=ae[0]&&n<=ae[1];t&&(e+=`<span class="src-mark">`);let i=[...ne.get(n)??[],...re.get(n)??[]];if(!i.length)e+=dc(r);else{let t=[...new Set([0,r.length,...i.flatMap(e=>[e.start,e.end])])].filter(e=>e<=r.length).sort((e,t)=>e-t);for(let n=0;n<t.length-1;n++){let[a,o]=[t[n],t[n+1]],s=i.filter(e=>e.start<=a&&e.end>=o).map(e=>e.cls),c=dc(r.slice(a,o));e+=s.length?`<span class="${s.join(` `)}">${c}</span>`:c}}t&&(e+=`</span>`)}O.innerHTML=e+` `,O.scrollTop=t.scrollTop}function ce(e){let t=new Map;for(let n of e)t.set(n.line,[...t.get(n.line)??[],n]);return t}function le(){clearTimeout(oe),oe=window.setTimeout(async()=>{await r,c();let[i,o]=[e.current(),t.value],s=await n.request(`textDocument/semanticTokens/full`,{textDocument:{uri:ac(i)}});if(e.current()!==i||t.value!==o)return;let l=[];for(let e=0,t=0,n=0;e<s.data.length;e+=5){t+=s.data[e],n=s.data[e]?s.data[e+1]:n+s.data[e+1];let r=`t-${a[s.data[e+3]]}`+(s.data[e+4]&1?` t-decl`:``);l.push({line:t,start:n,end:n+s.data[e+2],cls:r})}ne=ce(l),ie=i,se()},30)}function ue(){clearTimeout(k),k=window.setTimeout(async()=>{let e=t.selectionStart,n=t.value,r=e===t.selectionEnd?await u(`textDocument/documentHighlight`):null;if(t.value!==n||t.selectionStart!==e)return;let i=ce((r&&r.length>1?r:[]).map(e=>({line:e.range.start.line,start:e.range.start.character,end:e.range.end.character,cls:e.kind===3?`mark mark-decl`:`mark`})));(i.size||re.size)&&(re=i,se())},120)}t.addEventListener(`input`,()=>{re=new Map,se(),le(),ue()}),t.addEventListener(`scroll`,()=>O.scrollTop=t.scrollTop),t.addEventListener(`keyup`,e=>{(e.key.startsWith(`Arrow`)||e.key===`Home`||e.key===`End`||e.key===`PageUp`||e.key===`PageDown`)&&ue()}),new ResizeObserver(()=>se()).observe(t),se(),t.addEventListener(`input`,e=>{if(E(),!(e instanceof InputEvent)||e.inputType!==`insertText`)return x();v(!1)}),t.addEventListener(`keydown`,e=>{E();let t=!p.hidden;if(t&&(e.key===`ArrowDown`||e.key===`ArrowUp`))h=(h+(e.key===`ArrowDown`?1:m.length-1))%m.length,b();else if(t&&(e.key===`Enter`||e.key===`Tab`))S(h);else if(t&&e.key===`Escape`)x();else if(e.key===` `&&e.ctrlKey)v(!0);else if(e.key===`F2`)D();else if(e.key===`F12`)ee();else{t&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`Home`||e.key===`End`)&&x();return}e.preventDefault(),e.stopImmediatePropagation()},!0),t.addEventListener(`blur`,()=>{x(),E()}),t.addEventListener(`scroll`,()=>{x(),E()}),t.addEventListener(`click`,e=>{if(x(),E(),ue(),e.metaKey||e.ctrlKey)return void ee();w=window.setTimeout(()=>void T(),350)});function de(e,n=!1){if(ae=e,se(),!e||!n)return;let r=sc(t.value,{line:e[0],character:0}),i=sc(t.value,{line:e[1]+1,character:0}),a=uc(t,r).top,o=uc(t,i).top,s=t.getBoundingClientRect();(a<s.top||o>s.bottom)&&(t.scrollTop+=a-s.top-t.clientHeight/3)}return{sync:l,mark:de,diagnostics:e=>s.get(e)??[],reveal:d,async fix(t){let n=(await u(`textDocument/codeAction`,{range:t.range,context:{diagnostics:[t]}}))?.[0]?.edit?.changes?.[ac(e.current())];return n?(f(n),!0):!1}}}var hc=class{diagram;L;snap;constructor(e,t,n){this.diagram=e,this.L=t,this.snap=n}pinAll(){for(let e of this.L.nodes.values()){let t=this.diagram.layout.nodes[e.id]??={};(t.x===void 0||t.y===void 0)&&(t.x=Math.round(e.x),t.y=Math.round(e.y))}}edgeOverride(e){return this.diagram.layout.edges[e]??={}}nearestSide(e,t){let n=this.L.nodes.get(e),r=(t.x-(n.x+n.w/2))/(n.w/2),i=(t.y-(n.y+n.h/2))/(n.h/2);return Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`bottom`:`top`}pinned(e,t){t&&this.pinAll();let n=t?this.L.nodes.get(e):this.L.panels.find(t=>t.decl.id===e).box,r=t?this.diagram.layout.nodes[e]??={}:((this.diagram.layout.panels??={})[e]??={}).at??={x:n.x,y:n.y};return r.x??=n.x,r.y??=n.y,{o:r,w:n.w,h:n.h}}centre(e,t){let{o:n,w:r,h:i}=this.pinned(e,t),a=n.x+r/2,o=n.y+i/2;return(e,t,s)=>{n.x=Math.round(this.snap(a+t.x,s)-r/2),n.y=Math.round(this.snap(o+t.y,s)-i/2)}}part(e,t){let n=((this.diagram.layout.panels??={})[e]??={}).parts??={},r=n[t.part]??{x:0,y:0},i=(e,t,n)=>Math.round(this.snap(e+t,n)-e);return(e,a,o)=>{let s=t.axis??`xy`;n[t.part]=s===`xy`?{x:r.x+i(t.x,a.x,o),y:r.y+i(t.y,a.y,o)}:{x:r.x+i(t[s],a[s],o),y:0}}}resize(e){let t=this.L.nodes.get(e),n=t.w,r=t.h;return this.pinAll(),(t,i,a)=>{let o=this.diagram.layout.nodes[e];o.w=Math.max(24,this.snap(n+i.x,a)),o.h=Math.max(16,this.snap(r+i.y,a))}}via(e,t,n){let r=this.L.edges.find(t=>t.key===e);this.pinAll();let i=this.edgeOverride(e),a=i.via=r.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)}));n&&a.splice(t,0,{x:Math.round(n.x),y:Math.round(n.y)});let o={...a[t]};return(e,n,r)=>{a[t]={x:this.snap(o.x+n.x,r),y:this.snap(o.y+n.y,r)}}}port(e,t){let n=this.L.edges.find(t=>t.key===e),r=this.edgeOverride(e),i=t===0?n.decl.from:n.decl.to;return e=>{let n=r.ports?[...r.ports]:[`auto`,`auto`];n[t]=this.nearestSide(i,e),r.ports=n}}label(e){let t=this.edgeOverride(e),n=t.label?{...t.label}:{x:0,y:0};return(e,r)=>{t.label={x:Math.round(n.x+r.x),y:Math.round(n.y+r.y)}}}bend(e,t){let n=this.L.edges.find(t=>t.key===e),r=null,i=0;return(a,o,s)=>{if(!r){this.pinAll(),r=this.edgeOverride(e),r.via=n.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)}));let a=[n.start,...n.via,n.end],o=1/0;for(let e=0;e<a.length-1;e++){let n=gc(t,a[e],a[e+1]);n<o&&(o=n,i=e)}r.via.splice(i,0,{x:Math.round(t.x),y:Math.round(t.y)})}r.via[i]={x:this.snap(t.x+o.x,s),y:this.snap(t.y+o.y,s)}}}group(e){let{diagram:t}=this;this.pinAll();let n=[...t.nodes.values()].filter(n=>ja(t,n.group).includes(e)).map(e=>e.id),r=n.map(e=>({...t.layout.nodes[e]})),i=Object.entries(t.layout.edges).filter(([e])=>{let r=t.edges.find(t=>t.key===e);return r&&n.includes(r.from)&&n.includes(r.to)}).map(([e,t])=>({o:t,via:(t.via??[]).map(e=>({...e})),k:e}));return(e,a,o)=>{let s=this.snap(a.x,o),c=this.snap(a.y,o);n.forEach((e,n)=>{t.layout.nodes[e].x=r[n].x+s,t.layout.nodes[e].y=r[n].y+c});for(let e of i)e.o.via=e.via.map(e=>({x:e.x+s,y:e.y+c}))}}};function gc(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i||1,o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}var W=e=>document.querySelector(e),G=W(`#source`),K=W(`#stage`),_c=W(`#diagnostics`),vc=W(`#inspector`),yc=W(`#status`),bc=W(`#theme`),xc=W(`#direction`),Sc=W(`#curve`),Cc=W(`#template`),wc=W(`#save`),Tc=W(`#summary`),Ec=W(`#zoom-fit`),Dc=W(`#tabs`),Oc=W(`#insert`),kc=`title: Hello yuhwa
558
+ direction: right
559
+
560
+ .svc [blue]
561
+
562
+ user "You" [shape: circle, purple]
563
+
564
+ group app "Your app" {
565
+ web "Web app" .svc [sub: "Next.js"]
566
+ api "API" .svc
567
+ }
568
+ db "Database" [shape: cylinder, amber]
569
+
570
+ user -> web: visits
571
+ web -> api
572
+ api -> db: SQL
573
+
574
+ // Drag boxes, edges and labels in the preview.
575
+ // Positions are written to the layout block below.
576
+ `,q=``,J,Ac,Y=null,jc=0,Mc=null,Nc=[],Pc=[],Fc=`main.yuhwa`,X={[Fc]:``},Z=Fc,Ic=new Map,Lc=new URLSearchParams(location.search).has(`server`),Rc={},zc=(e,t)=>t?.altKey?Math.round(e):Math.round(e/12)*12,Bc=e=>{yc.textContent=e,e&&setTimeout(()=>yc.textContent===e&&(yc.textContent=``),2e3)};function Vc(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Hc(e){let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))}function Uc(){return K.querySelector(`svg`)}function Wc(e){let t=Uc(),n=new DOMPoint(e.clientX,e.clientY).matrixTransform(t.getScreenCTM().inverse());return{x:n.x,y:n.y}}function Q(e=!0){e&&(J=Tn(q,{file:Z,resolve:e=>e===Z?q:X[e]})),Ac=Ia(J,{measureFor:e=>ur(e.font)}),K.innerHTML=no(J,Ac,{interactive:!0,idPrefix:`ed`,snapGrid:12});let t=!J.nodes.size&&!J.panels.length&&!J.settings.title;if(K.classList.toggle(`is-empty`,t),t){let e=document.createElement(`p`);e.className=`empty-hint`,e.textContent=Object.keys(J.classes).length?`Nothing to draw yet: this file only defines classes. Import it from another file, or add a node.`:`Nothing to draw yet. Type a line like a -> b or pick something from Insert.`,K.append(e)}let n=Uc();rl(n),Y&&!al(Y)&&(Y=null),ll(n),e&&(gu.sync(),ul(),dl());let r=Jc(Y);if(e||r!==Gc){let e=Xc(Y);gu.mark(e,r!==Gc);let t=qc(e);r===Gc&&t&&t===Kc||zl(),Gc=r,Kc=t}}var Gc=``,Kc=``;function qc(e){return!Y||!e?``:[q.split(`
577
+ `).slice(e[0],e[1]+1).join(`
578
+ `),JSON.stringify(J.layout),Object.keys(J.classes).join()].join(`
579
+ \0`)}var Jc=e=>e?`${e.kind}:${e.id}`:``;function Yc(e){let t=q.split(`
580
+ `),n=0;for(let r=e;r<t.length;r++){for(let e of t[r].replace(/"[^"]*"/g,``))if(e===`{`)n++;else if(e===`}`&&--n===0)return r;if(!n)return e}return e}function Xc(e){if(!e)return null;if(e.kind===`node`){let t=J.nodes.get(e.id);if(!t)return null;if(!t.ref||t.implicit){let t=J.edges.find(t=>(t.from===e.id||t.to===e.id)&&t.ref)?.ref.line;return t===void 0?null:[t,t]}let n=Math.max(t.ref.line,t.bodyLines?.[1]??0,...Object.values(t.ref.propLines??{}));return[t.ref.line,n]}if(e.kind===`edge`){let t=J.edges.find(t=>t.key===e.id)?.ref?.line;return t===void 0?null:[t,t]}if(e.kind===`group`){let t=J.groups.get(e.id)?.ref?.line;return t===void 0?null:[t,Yc(t)]}return J.panels.find(t=>t.id===e.id)?.lines??null}function Zc(e){let t=null,n=1/0,r=r=>{let i=Xc(r);i&&e>=i[0]&&e<=i[1]&&i[1]-i[0]<n&&(t=r,n=i[1]-i[0])};for(let e of J.nodes.values())e.implicit||r({kind:`node`,id:e.id});for(let e of J.edges)r({kind:`edge`,id:e.key});for(let e of J.groups.keys())r({kind:`group`,id:e});for(let e of J.panels)r({kind:`panel`,id:e.id});return t&&al(t)?t:null}function Qc(e){let t={node:`data-node`,edge:`data-edge`,group:`data-group`,panel:`data-panel`}[e.kind],n=Uc()?.querySelector(`[${t}="${CSS.escape(e.id)}"]`);if(!n)return;let r=n.getBoundingClientRect(),i=K.getBoundingClientRect();r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom||K.scrollBy({left:r.left+r.width/2-(i.left+i.width/2),top:r.top+r.height/2-(i.top+i.height/2),behavior:`smooth`})}function $c(){if(G.value!==q)return;let e=Zc(q.slice(0,G.selectionStart).split(`
581
+ `).length-1);Jc(e)!==Jc(Y)&&(Y=e,Q(!1),e&&Qc(e))}var el=.1,tl=8,nl=()=>{let e=Ac.bounds;return Math.min(1.5,Math.max(.2,Math.min((K.clientWidth-48)/e.w,(K.clientHeight-48)/e.h)))};function rl(e){let t=Ac.bounds,n=jc||nl();Mc?(e.setAttribute(`viewBox`,Mc.viewBox),e.setAttribute(`width`,String(Mc.w)),e.setAttribute(`height`,String(Mc.h))):(e.setAttribute(`width`,String(Math.round(t.w*n))),e.setAttribute(`height`,String(Math.round(t.h*n)))),Ec.textContent=`${Math.round((Mc?Mc.w/t.w:n)*100)}%`,Ec.title=jc?`Fit to view (⌘0)`:`Fitted to view`}function il(e,t){let n=Uc();if(!n||Mc)return;let r=e?Math.min(tl,Math.max(el,e)):0;if(r===jc)return;let i=K.getBoundingClientRect(),a=t?.clientX??i.left+i.width/2,o=t?.clientY??i.top+i.height/2,s=n.getBoundingClientRect(),c=(a-s.left)/s.width,l=(o-s.top)/s.height;if(jc=r,rl(n),n.querySelector(`:scope > .overlay`)?.remove(),ll(n),!jc)return;let u=n.getBoundingClientRect();K.scrollLeft+=u.left+c*u.width-a,K.scrollTop+=u.top+l*u.height-o}function al(e){return e.kind===`node`?Ac.nodes.has(e.id):e.kind===`group`?Ac.groups.some(t=>t.id===e.id):e.kind===`panel`?Ac.panels.some(t=>t.decl.id===e.id):Ac.edges.some(t=>t.key===e.id)}var ol=`http://www.w3.org/2000/svg`;function sl(e,t){let n=document.createElementNS(ol,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,String(r));return n}var cl=``;matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>cl=``);function ll(e){if(!Y)return;let t=sl(`g`,{class:`overlay`}),n=Ac.bounds.w/(e.width.baseVal.value||Ac.bounds.w),r=cl||=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||`#2563eb`,i=(e,i,a,o,s=`circle`)=>{let c={"data-handle":a,"data-i":o,stroke:r,"stroke-width":1.5*n,style:`cursor:move`};s===`square`?t.append(sl(`rect`,{x:e-5*n,y:i-5*n,width:10*n,height:10*n,rx:2*n,fill:`#fff`,...c})):t.append(sl(`circle`,{cx:e,cy:i,r:(s===`ring`?4:5.5)*n,fill:s===`ring`?`#fff`:r,...c}))};if(Y.kind===`node`){let e=Ac.nodes.get(Y.id);t.append(sl(`rect`,{x:e.x-4,y:e.y-4,width:e.w+8,height:e.h+8,rx:6,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),i(e.x+e.w+4,e.y+e.h+4,`resize`,0,`square`)}else if(Y.kind===`panel`){let e=Ac.panels.find(e=>e.decl.id===Y.id);t.append(sl(`rect`,{x:e.box.x-3,y:e.box.y-3,width:e.box.w+6,height:e.box.h+6,rx:12,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),e.handles.forEach((n,r)=>{let a=!!J.layout.panels?.[e.decl.id]?.parts?.[n.part];i(n.x,n.y,`part`,r,a?`circle`:`ring`);let o=t.lastElementChild,s=sl(`title`,{});s.textContent=`${n.title??n.part}${a?` · double-click to reset`:``}`,o.append(s),o.setAttribute(`style`,`cursor:${n.axis===`x`?`ew-resize`:n.axis===`y`?`ns-resize`:`move`}`)})}else if(Y.kind===`group`){let e=Ac.groups.find(e=>e.id===Y.id);t.append(sl(`rect`,{x:e.x-3,y:e.y-3,width:e.w+6,height:e.h+6,rx:14,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`}))}else{let e=Ac.edges.find(e=>e.key===Y.id);t.append(sl(`path`,{d:e.d,fill:`none`,stroke:r,"stroke-width":e.style.width+4,opacity:.25,"pointer-events":`none`}));let n=[e.start,...e.via,e.end];for(let e=0;e<n.length-1;e++)i((n[e].x+n[e+1].x)/2,(n[e].y+n[e+1].y)/2,`mid`,e,`ring`);e.via.forEach((e,t)=>i(e.x,e.y,`via`,t)),i(e.start.x,e.start.y,`end`,0,`square`),i(e.end.x,e.end.y,`end`,1,`square`)}e.append(t)}function ul(){_c.innerHTML=``;let e=gu.diagnostics(Z),t=e.filter(e=>e.severity===1).length,n=e.length-t,r=(e,t)=>`${e} ${t}${e===1?``:`s`}`;if(Tc.textContent=`${r(J.nodes.size,`node`)} · ${r(J.edges.length,`edge`)}`,t||n){let e=document.createElement(`span`);e.className=`bad`,e.textContent=` · ${t?r(t,`error`):r(n,`warning`)}`,Tc.append(e)}for(let t of e){let e=document.createElement(`div`);e.className=t.severity===1?`error`:`warning`;let n=typeof t.message==`string`?t.message:t.message.value;e.textContent=`${t.range.start.line+1}: ${n}`,e.onclick=()=>gu.reveal(t.range);let r=n.match(/did you mean "([^"\n]+)"/);if(r){let n=document.createElement(`button`);n.className=`fix`,n.textContent=`use ${r[1]}`,n.onclick=e=>{e.stopPropagation(),gu.fix(t)},e.append(n)}_c.append(e)}}function dl(){let e=ne(J.themes);if([...bc.options].map(e=>e.value).join()!==e.join()){bc.replaceChildren();for(let t of e)bc.append(new Option(t,t))}bc.value=e.includes(J.settings.theme)?J.settings.theme:`paper`,xc.value=J.settings.direction||`right`,Sc.value=J.settings.curve||`smooth`}function fl(e,t,n=!1,r=``){let i=document.createElement(`label`);i.className=`field ${r}`.trim(),i.classList.toggle(`unset`,n);let a=document.createElement(`span`);return a.textContent=e,i.append(a,t),i}function pl(e,t,n,r){let i=document.createElement(`select`);for(let e of t)i.append(new Option(e||`default`,e));return n&&!t.includes(n)&&i.append(new Option(n,n)),i.value=n,i.onchange=()=>r(i.value),fl(e,i,!n)}var ml=e=>e.replace(/\n/g,`\\n`),hl=e=>e.replace(/\\n/g,`
582
+ `);function gl(e,t,n=`text`,r=``){let i=document.createElement(`input`);return i.type=n,i.value=n===`text`?ml(e):e,i.placeholder=r,i.spellcheck=!1,n===`number`&&(i.step=`any`),i.onchange=()=>t(n===`text`?hl(i.value.trim()):i.value),i.onkeydown=t=>{t.stopPropagation(),t.key===`Enter`?i.blur():t.key===`Escape`&&(i.value=n===`text`?ml(e):e,i.blur())},i}function _l(e,t,n,r=``){return fl(e,gl(t,n,`text`,r),!t,`text`)}function $(e,t,n,r=``){return fl(e,gl(t,n,`number`,r),!t,`text`)}function vl(e,t,n){let r=document.createElement(`input`);return r.type=`checkbox`,r.checked=t,r.onchange=()=>n(r.checked),fl(e,r,!t,`toggle`)}var yl=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function bl(e,t=400){if(!e)return;let n=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);return(n&&i(n[1],n[2]?Number(n[2]):t))??(CSS.supports(`color`,e)?e:void 0)}var xl=e=>!e||!yl.test(e)?`#888888`:e.length===4?`#${e.slice(1).split(``).map(e=>e+e).join(``)}`:e.toLowerCase();function Sl(e){let t=document.createElement(`i`);return t.className=e?`swatch`:`swatch none`,e&&t.style.setProperty(`--sw`,bl(e)??`transparent`),t}function Cl(e,t){let r=document.createElement(`div`);r.className=`palette`;let i=(n,r)=>{let i=document.createElement(`button`);return i.type=`button`,i.className=`dot${n?``:` none`}${n===e?` on`:``}`,i.title=r,i.setAttribute(`aria-label`,r),n&&i.style.setProperty(`--sw`,bl(n)??`transparent`),i.onclick=()=>t(n),i};r.append(i(``,`default`),...n.map(e=>i(e,e)));let a=document.createElement(`label`),o=!!e&&!n.includes(e);a.className=`dot custom${o?` on`:``}`,a.title=`custom colour`,o&&a.style.setProperty(`--sw`,bl(e)??`transparent`);let s=document.createElement(`input`);return s.type=`color`,s.value=xl(bl(e,500)),s.onchange=()=>t(s.value),a.append(s),r.append(a),r}function wl(e,t,n,r=``){let i=document.createElement(`div`);i.className=`color-field`;let a=document.createElement(`div`);a.className=`color-head`;let o=document.createElement(`span`);o.textContent=e;let s=document.createElement(`code`);s.textContent=t||(r?`${r} (class)`:`default`),a.append(o,s);let c=gl(t,n,`text`,r||`#hex, rgb(), hsl(), tomato`);return c.classList.add(`color-text`),i.append(a,Cl(t,e=>n(e)),c),i}function Tl(e,t,n,r=``){let i=document.createElement(`div`);i.className=`field color`,i.classList.toggle(`unset`,!t);let a=document.createElement(`span`);a.textContent=e;let o=document.createElement(`label`);o.className=`dot${t?``:` none`}`,o.style.setProperty(`--sw`,bl(t,500)??`transparent`),o.title=`pick a colour`;let s=document.createElement(`input`);s.type=`color`,s.value=xl(bl(t,500)),s.onchange=()=>n(s.value),o.append(s);let c=gl(t,n,`text`,r||`none`);return i.append(a,o,c),t&&i.append(kl(`×`,()=>n(``),`clear`)),i}function El(e){let t=e.kind===`node`?J.nodes.get(e.id):e.kind===`group`?J.groups.get(e.id):e.kind===`panel`?J.panels.find(t=>t.id===e.id):J.edges.find(t=>t.key===e.id);return t&&(t.labelRef?!t.labelRef.generated:e.kind===`node`&&!t.ref)?t.label??``:null}function Dl(e,t){t!==El(e)&&Hl(Gs(q,e,t,J))}function Ol(e,t){let n=El(e);if(n===null)return;let r=e.kind===`group`||e.kind===`panel`?t.querySelector(`:scope > text`):null,i=(r??t).getBoundingClientRect(),a=Math.max(i.width+24,140),o=document.createElement(`input`);o.className=`label-edit`,o.value=ml(n),o.spellcheck=!1;let s=r||e.kind!==`group`&&e.kind!==`panel`?i.top+i.height/2-15:i.top+6,c=r||e.kind!==`group`&&e.kind!==`panel`?i.left+i.width/2-a/2:i.left+6;Object.assign(o.style,{top:`${s}px`,left:`${Math.max(4,c)}px`,width:`${a}px`}),document.body.append(o),o.focus(),o.select();let l=!1,u=t=>{l||(l=!0,o.remove(),t&&Dl(e,hl(o.value)))};o.onkeydown=e=>{e.stopPropagation(),e.key===`Enter`?u(!0):e.key===`Escape`&&u(!1)},o.onblur=()=>u(!0)}function kl(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,n&&(r.className=n),r.onclick=t,r}function Al(e,t,n){return t?kl(e,()=>{n(),Ul()}):null}function jl(e,...t){let n=t.filter(e=>!!e);if(!n.length)return;let r=document.createElement(`section`),i=document.createElement(`h3`);i.textContent=e;let a=document.createElement(`div`);a.className=`rows`,a.append(...n),r.append(i,a),vc.append(r)}function Ml(e){let t=document.createElement(`p`);return t.className=`hint`,t.innerHTML=e,t}var Nl=null,Pl={up:`↑`,down:`↓`,remove:`✕`};function Fl(e,t){let n=n=>r=>t({op:`set`,id:e.id,key:n,value:r||null}),r=[Cl(e.tone??``,n(`color`))],i=e.values??{},a=Object.entries(e.fields??{}).map(([e,t])=>t.length?pl(e,t,i[e]??``,n(e)):_l(e,i[e]??``,n(e)));if(a.length){let e=document.createElement(`div`);e.className=`rows`,e.append(...a),r.push(e)}if(e.actions?.length){let n=document.createElement(`div`);n.className=`part-actions`;for(let r of e.actions){let i=document.createElement(`button`);i.type=`button`,i.textContent=r===`add`?`+ ${e.adds??`add`}`:Pl[r],i.title=r===`add`?`add to ${e.label}`:`${r} ${e.id}`,i.onclick=()=>t({op:r,id:e.id}),n.append(i)}r.push(n)}return r}function Il(e,t,n){let r=document.createElement(`div`);r.className=`parts`;let i=(t,n=!0)=>{let r=Xs(q,e,t,J);if(r.source===q)return Bc(`this part cannot be changed here`);Nl=n&&r.id?`${e}:${r.id}`:null,Hl(r.source)},a=``;for(let n of t){if(n.kind!==a){a=n.kind;let e=document.createElement(`div`);e.className=`parts-kind`,e.textContent=a,r.append(e)}let t=`${e}:${n.id}`,o=document.createElement(`div`);o.className=`part`;let s=document.createElement(`button`);s.type=`button`,s.title=`edit ${n.id}`;let c=document.createElement(`span`);c.textContent=n.label;let l=document.createElement(`code`);l.textContent=n.tone??``,s.append(Sl(n.tone??``),c,l);let u=e=>{o.classList.toggle(`open`,e),o.replaceChildren(s,...e?Fl(n,i):[])};s.onclick=()=>{let e=Nl!==t;r.querySelector(`.part.open`)?.dispatchEvent(new Event(`close`)),Nl=e?t:null,u(e)},o.addEventListener(`close`,()=>u(!1)),u(Nl===t),r.append(o)}if(n){let e=document.createElement(`button`);e.type=`button`,e.className=`part-add`,e.textContent=`+ ${n}`,e.onclick=()=>i({op:`add`}),r.append(e)}return r}var Ll=`Click a box, edge, group or panel to style it · double-click to edit its text · drag to move · drag an edge to bend it · drag a panel's dots to adjust it · double-click a bend or dot to reset it · <kbd>alt</kbd> no snapping · <kbd>←</kbd><kbd>→</kbd> nudge`;function Rl(){let e=J.settings,t=e=>t=>Hl(Ys(q,e,t||null)),n=document.createElement(`div`);n.className=`title`,n.innerHTML=`<small>diagram</small>settings`,vc.append(n),jl(`Text`,_l(`title`,e.title??``,t(`title`)),_l(`subtitle`,e.subtitle??``,t(`subtitle`)),_l(`font`,e.font??``,t(`font`),`theme font`),$(`font size`,e[`font-size`]??``,t(`font-size`),`14`)),jl(`Style`,pl(`theme`,[``,...ne(J.themes)],e.theme??``,t(`theme`)),Tl(`accent`,e.accent??``,t(`accent`),`theme`),Tl(`background`,e.background??``,t(`background`),`theme`),$(`radius`,e.radius??``,t(`radius`),`theme`),$(`stroke`,e[`stroke-width`]??``,t(`stroke-width`),`theme`),Tl(`edge color`,e[`edge-color`]??``,t(`edge-color`),`theme`),$(`edge width`,e[`edge-width`]??``,t(`edge-width`),`theme`),vl(`shadow`,!!e.shadow&&e.shadow!==`false`,e=>t(`shadow`)(e?`true`:``)),pl(`shape`,[``,...gt],e.shape??``,t(`shape`))),jl(`Layout`,pl(`direction`,[``,`right`,`down`,`left`,`up`],e.direction??``,t(`direction`)),pl(`curve`,[``,`smooth`,`orthogonal`,`straight`],e.curve??``,t(`curve`)),$(`gap`,e.gap??``,t(`gap`),`36`),$(`rank gap`,e[`rank-gap`]??``,t(`rank-gap`),`auto`),$(`padding`,e.padding??``,t(`padding`),`24`),$(`wrap`,e.wrap??``,t(`wrap`),`off`),pl(`panels`,[``,`row`,`column`,`grid`,`wrap`],e.panels??``,t(`panels`)),$(`panel gap`,e[`panel-gap`]??``,t(`panel-gap`),`48`),vl(`grid`,!!e.grid&&e.grid!==`false`,e=>t(`grid`)(e?`true`:``))),vc.append(Ml(Ll))}function zl(){if(vc.innerHTML=``,!Y)return Rl();let e=Y,t=document.createElement(`div`);t.className=`title`;let n=document.createElement(`small`);n.textContent=e.kind;let r=document.createElement(`span`);r.textContent=e.id,t.append(n,r,kl(`×`,()=>{Y=null,Q(!1)},`clear`)),t.lastElementChild.setAttribute(`title`,`deselect (Esc)`),vc.append(t);let i={kind:e.kind,id:e.id},a=e=>t=>Hl(qs(q,i,e,t||null)),o=(e,t)=>vl(e,!!t[e]&&t[e]!==`false`,t=>a(e)(t?`true`:``)),s=El(i),c=s!==null&&_l(e.kind===`panel`?`title`:`label`,s,e=>Dl(i,e));if(e.kind===`panel`){let t=J.panels.find(t=>t.id===e.id),r=Pn.panels.get(t.kind);n.textContent=t.kind;let i=r?.options??{},s=!!t.ref&&!t.ref.generated;jl(`Text`,c),s&&(jl(`Options`,...Object.entries(i).map(([e,n])=>n.length?pl(e,[``,...n],t.props[e]??``,a(e)):_l(e,t.props[e]??``,a(e)))),jl(`Style`,wl(`color`,t.props.color??``,a(`color`)),pl(`theme`,[``,...ne(J.themes)],t.props.theme??``,a(`theme`)),Tl(`background`,t.props.background??t.props.fill??``,a(`background`),`theme`),Tl(`border`,t.props.border??t.props.stroke??``,a(`border`),`theme`),pl(`border style`,[``,`solid`,`dashed`,`dotted`],xe(t.props)??``,a(`border-style`)),$(`border width`,t.props[`border-width`]??``,a(`border-width`),`1`),Tl(`edge color`,t.props[`edge-color`]??``,a(`edge-color`),`theme`),$(`edge width`,t.props[`edge-width`]??``,a(`edge-width`),`theme`),$(`radius`,t.props.radius??``,a(`radius`),`10`),o(`shadow`,t.props),vl(`frame`,t.props.frame!==`false`,e=>a(`frame`)(e?``:`false`))));let l=r?.parts?.(t.data)??[],u=s&&!!r?.editPart&&!!t.lines&&t.lines[1]-t.lines[0]-1===t.body.length;l.length&&jl(`Parts`,u?Il(e.id,l,r?.adds):Ml(`Write the panel body on its own lines to colour its parts here.`));let d=J.layout.panels?.[e.id];jl(`Layout`,Al(`Unpin`,d?.at,()=>delete d.at),Al(`Reset layout`,d?.parts,()=>delete d.parts))}else if(e.kind===`node`){let n=J.nodes.get(e.id),r=Object.assign({},...n.classes.map(e=>J.classes[e]??{})),i=e=>n.props[e]??``;jl(`Text`,c,_l(`sub`,i(`sub`),a(`sub`),r.sub),Tl(`text`,i(`text`),a(`text`),r.text),$(`font size`,i(`font-size`),a(`font-size`),r[`font-size`]??`auto`),o(`bold`,n.props),o(`italic`,n.props),o(`mono`,n.props),_l(`icon`,i(`icon`),a(`icon`),r.icon),_l(`link`,i(`link`),a(`link`),r.link),_l(`tooltip`,i(`tooltip`),a(`tooltip`),r.tooltip)),jl(`Colour`,wl(`color`,i(`color`),a(`color`),r.color),Tl(`fill`,i(`fill`),a(`fill`),r.fill??`from color`),Tl(`stroke`,i(`stroke`),a(`stroke`),r.stroke??`from color`)),jl(`Shape`,pl(`shape`,[``,...gt],i(`shape`)||``,a(`shape`)),pl(`border`,[``,`solid`,`dashed`,`dotted`],xe(n.props)??``,a(`border-style`)),$(`border width`,i(`stroke-width`),a(`stroke-width`),r[`stroke-width`]??`theme`),$(`radius`,i(`radius`),a(`radius`),r.radius??`theme`),$(`opacity`,i(`opacity`),a(`opacity`),`1`),o(`shadow`,n.props)),jl(`Size`,$(`width`,i(`width`),a(`width`),`auto`),$(`height`,i(`height`),a(`height`),`auto`),$(`max width`,i(`max-width`),a(`max-width`),`auto`),Al(`Unpin`,J.layout.nodes[e.id],()=>delete J.layout.nodes[e.id])),r.shape&&!n.props.shape&&(t.title=`shape ${r.shape} from class`)}else if(e.kind===`edge`){let t=J.edges.find(t=>t.key===e.id),n=e=>t.props[e]??``,r=[``,`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],i=[``,`top`,`right`,`bottom`,`left`,`auto`];jl(`Text`,c,Tl(`label colour`,n(`label-color`),a(`label-color`)),Tl(`label bg`,n(`label-bg`),a(`label-bg`))),jl(`Line`,wl(`color`,n(`color`),a(`color`)),Tl(`stroke`,n(`stroke`),a(`stroke`),`from color`),pl(`style`,[``,`solid`,`dashed`,`dotted`],xe(t.props,`style`)??``,a(`style`)),$(`width`,n(`width`),a(`width`),`theme`),$(`opacity`,n(`opacity`),a(`opacity`),`1`),o(`flow`,t.props),o(`animate`,t.props)),jl(`Ends`,pl(`head`,r,n(`head`),a(`head`)),pl(`tail`,r,n(`tail`),a(`tail`)),pl(`exit`,i,n(`exit`),a(`exit`)),pl(`enter`,i,n(`enter`),a(`enter`))),jl(`Route`,pl(`curve`,[``,`smooth`,`orthogonal`,`straight`],n(`curve`),a(`curve`)),o(`constraint`,t.props),Al(`Reset route`,J.layout.edges[e.id],()=>delete J.layout.edges[e.id])),t.ref&&J.edges.filter(e=>e.ref===t.ref).length>1&&vc.append(Ml(`Style applies to every edge on this line.`))}else{let t=J.groups.get(e.id),n=e=>t.props[e]??``;jl(`Text`,c,Tl(`text`,n(`text`),a(`text`)),o(`caps`,t.props)),jl(`Colour`,wl(`color`,n(`color`),a(`color`)),Tl(`fill`,n(`fill`),a(`fill`),`from color`),Tl(`stroke`,n(`stroke`),a(`stroke`),`from color`),pl(`border`,[``,`solid`,`dashed`,`dotted`],xe(t.props)??``,a(`border-style`)))}}function Bl(e){Nc[Nc.length-1]!==e&&Nc.push(e),Nc.length>200&&Nc.shift(),Pc.length=0}function Vl(e,t=!0){if(e===q)return;uu.end(),t&&Bl(q),q=e;let n=G.scrollTop;G.value=e,G.scrollTop=n,Gl()}function Hl(e){Vl(e),Q(!0)}function Ul(){Hl(Rs(q,J.layout,J))}var Wl=0;function Gl(){if(X[Z]=q,Lc)Kl.changed(),clearTimeout(Wl),Wl=window.setTimeout(ql,500);else try{localStorage.setItem(`yuhwa-files`,JSON.stringify({files:X,current:Z}))}catch{}}var Kl=new tc(async()=>{let e=await fetch(`/api/source`,{method:`PUT`,body:JSON.stringify({files:X})});if(!e.ok)throw Error(`save failed`);let{written:t=[]}=await e.json();return t.length?`saved ${t.join(`, `)}`:`saved`},Bc);function ql(){if(Lc)return clearTimeout(Wl),Kl.save()}var Jl=()=>new hc(J,Ac,zc),Yl=null,Xl=null,Zl=!1,Ql=new Map,$l=null;function eu(e,t){Xl={x:e.clientX,y:e.clientY,left:K.scrollLeft,top:K.scrollTop,moved:!1,clear:t},K.setPointerCapture(e.pointerId),K.classList.add(`panning`),e.preventDefault()}var tu=()=>{let[e,t]=[...Ql.values()];return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,d:Math.hypot(e.x-t.x,e.y-t.y)}};K.addEventListener(`wheel`,e=>{if(!(e.ctrlKey||e.metaKey)||Yl||!Uc())return;e.preventDefault();let t=e.deltaMode===1?e.deltaY*16:e.deltaY;il(lu()*Math.min(2,Math.max(.5,Math.exp(-t*.01))),e)},{passive:!1}),K.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||(Ql.set(e.pointerId,{x:e.clientX,y:e.clientY}),Ql.size!==2))return;if(Yl){let{moved:e,finish:t}=Yl;Yl=null,Mc=null,K.classList.remove(`dragging`),e?t():Q()}Xl=null;let t=tu();$l={d:t.d,z:lu(),mid:t},e.stopImmediatePropagation()},{capture:!0}),K.addEventListener(`pointermove`,e=>{if(!Ql.has(e.pointerId)||(Ql.set(e.pointerId,{x:e.clientX,y:e.clientY}),!$l||Ql.size!==2))return;let t=tu();il($l.z*t.d/Math.max(1,$l.d),{clientX:t.x,clientY:t.y}),K.scrollLeft-=t.x-$l.mid.x,K.scrollTop-=t.y-$l.mid.y,$l.mid=t,e.stopImmediatePropagation()},{capture:!0});var nu=e=>{Ql.delete(e.pointerId),Ql.size<2&&($l=null)};K.addEventListener(`pointerup`,nu,{capture:!0}),K.addEventListener(`pointercancel`,nu,{capture:!0}),K.addEventListener(`pointerdown`,e=>{if(!Uc()||$l)return;if(e.button===1||e.button===0&&Zl)return eu(e,!1);if(e.button!==0)return;let t=e.target.closest(`[data-handle],[data-node],[data-edge-label],[data-edge],[data-group],[data-panel]`);if(!t)return eu(e,!0);let n=Wc(e),r=Uc();Mc={viewBox:r.getAttribute(`viewBox`),w:r.width.baseVal.value,h:r.height.baseVal.value};let i=Ul,a=()=>{},o=Jl();if(t.hasAttribute(`data-handle`)){let e=t.getAttribute(`data-handle`),r=Number(t.getAttribute(`data-i`));if(Y?.kind===`panel`&&e===`part`){let e=Y.id,t=Ac.panels.find(t=>t.decl.id===e).handles[r];i=()=>Hl(Zs(q,J,e,t)),a=o.part(e,t)}else Y?.kind===`node`&&e===`resize`?a=o.resize(Y.id):Y?.kind===`edge`&&(e===`via`||e===`mid`?a=o.via(Y.id,r,e===`mid`?n:null):e===`end`&&(a=o.port(Y.id,r===0?0:1)))}else if(t.hasAttribute(`data-node`)){let e=t.getAttribute(`data-node`);Y={kind:`node`,id:e},a=o.centre(e,!0)}else if(t.hasAttribute(`data-edge-label`)){let e=t.getAttribute(`data-edge-label`);Y={kind:`edge`,id:e},a=o.label(e)}else if(t.hasAttribute(`data-edge`)){let e=t.getAttribute(`data-edge`);Y={kind:`edge`,id:e},a=o.bend(e,n)}else if(t.hasAttribute(`data-panel`)){let e=t.getAttribute(`data-panel`);Y={kind:`panel`,id:e},a=o.centre(e,!1)}else if(t.hasAttribute(`data-group`)){let e=t.getAttribute(`data-group`);Y={kind:`group`,id:e},a=o.group(e)}Yl={move:a,finish:i,moved:!1,start:n},K.setPointerCapture(e.pointerId),Q(!1),e.preventDefault()}),K.addEventListener(`pointermove`,e=>{if(Xl){let t=e.clientX-Xl.x,n=e.clientY-Xl.y;if(!Xl.moved&&Math.hypot(t,n)<3)return;Xl.moved=!0,K.scrollLeft=Xl.left-t,K.scrollTop=Xl.top-n;return}if(!Yl)return;let t=Wc(e),n={x:t.x-Yl.start.x,y:t.y-Yl.start.y};!Yl.moved&&Math.hypot(n.x,n.y)<3||(Yl.moved=!0,K.classList.add(`dragging`),Yl.move(t,n,e),ru||=requestAnimationFrame(()=>{ru=0,Q(!1)}))});var ru=0;function iu(){if(Xl){let{moved:e,clear:t}=Xl;Xl=null,K.classList.remove(`panning`),!e&&t&&Y&&(Y=null,Q(!1));return}if(!Yl)return;let{moved:e,finish:t}=Yl;Yl=null,Mc=null,K.classList.remove(`dragging`),e?t():Q()}K.addEventListener(`pointerup`,iu),K.addEventListener(`pointercancel`,iu),K.addEventListener(`dblclick`,e=>{let t=e.target,n=t.closest(`[data-handle]`),r=t.closest(`[data-edge-label]`);if(Y?.kind===`panel`&&n?.getAttribute(`data-handle`)===`part`){let e=Y.id,t=Ac.panels.find(t=>t.decl.id===e)?.handles[Number(n.getAttribute(`data-i`))]?.part,r=J.layout.panels?.[e];if(!t||!r?.parts?.[t])return;delete r.parts[t],Object.keys(r.parts).length||delete r.parts,Ul()}else if(Y?.kind===`edge`&&n){let e=J.layout.edges[Y.id],t=Number(n.getAttribute(`data-i`));if(!e)return;if(n.getAttribute(`data-handle`)===`via`&&e.via)e.via.splice(t,1),e.via.length||delete e.via;else if(n.getAttribute(`data-handle`)===`end`&&e.ports)e.ports[t]=`auto`;else return;Ul()}else if(!n){let e=r??t.closest(`[data-node],[data-edge],[data-group],[data-panel]`);if(!e)return il(0);let[n,i]=r?[`edge`,r.getAttribute(`data-edge-label`)]:[`node`,`edge`,`group`,`panel`].map(t=>[t,e.getAttribute(`data-${t}`)]).find(([,e])=>e!==null),a=n===`edge`&&!r?K.querySelector(`[data-edge-label="${CSS.escape(i)}"]`)??e:e;Ol({kind:n,id:i},a)}}),document.addEventListener(`keydown`,e=>{let t=e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLInputElement,n=e.metaKey||e.ctrlKey;if(n&&e.key.toLowerCase()===`s`){e.preventDefault(),ql();return}if(t)return;if(e.key===` `&&!e.repeat){Zl=!0,K.classList.add(`can-pan`),e.preventDefault();return}let r=n&&{"=":1.25,"+":1.25,"-":.8,_:.8,0:0,1:-1}[e.key];if(r!==void 0&&r!==!1){e.preventDefault(),il(r===-1?1:r&&lu()*r);return}if(n&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?ou():au();return}if(e.key===`Escape`){Y=null,Q(!1);return}let i={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};if(i[e.key]&&(Y?.kind===`node`||Y?.kind===`panel`)){e.preventDefault();let t=e.shiftKey?12:1,{o:n}=Jl().pinned(Y.id,Y.kind===`node`);n.x+=i[e.key].x*t,n.y+=i[e.key].y*t,Ul()}});function au(){let e=Nc.pop();e!==void 0&&(Pc.push(q),Vl(e,!1),Q(!0))}function ou(){let e=Pc.pop();e!==void 0&&(Nc.push(q),Vl(e,!1),Q(!0))}for(let e of f)bc.append(new Option(e,e));for(let e of nc)Cc.append(new Option(e.name,e.name));Cc.onchange=()=>{let e=nc.find(e=>e.name===Cc.value);if(Cc.value=``,e){if(e.files){if(Lc)return Bc(`multi-file templates need the browser editor`);if(X[Z]=q,Object.values(X).some(e=>e.trim()&&e!==kc)&&!confirm(`Replace all files with "${e.name}"?`))return;Ru({files:{[Fc]:e.source,...e.files},current:Fc}),G.value=q,Gl(),Cu(),Q(!0)}else Hl(e.source)}},bc.onchange=()=>Hl(Ys(q,`theme`,bc.value===`paper`&&!/^\s*import\b/m.test(q)?null:bc.value)),xc.onchange=()=>{J.layout.nodes={},J.layout.edges={};for(let e of Object.values(J.layout.panels??{}))delete e.at;Hl(Ys(Rs(q,J.layout,J),`direction`,xc.value))},Sc.onchange=()=>Hl(Ys(q,`curve`,Sc.value===`smooth`?null:Sc.value)),W(`#undo`).onclick=au,W(`#redo`).onclick=ou,W(`#reset`).onclick=()=>{J.layout={nodes:{},edges:{}},Ul()};function su(){return no(J,Ia(J,{measureFor:e=>ur(e.font)}),{idPrefix:`yuhwa`})}async function cu(e,t){try{await navigator.clipboard.writeText(e),Bc(`${t} copied`)}catch{Bc(`clipboard blocked`)}}W(`#copy-svg`).onclick=()=>cu(su(),`SVG`),W(`#copy-md`).onclick=()=>cu("```yuhwa\n"+q.replace(/\s*$/,``)+"\n```\n",`Markdown`),W(`#download`).onclick=()=>{let e=document.createElement(`a`);e.href=URL.createObjectURL(new Blob([su()],{type:`image/svg+xml`})),e.download=(J.settings.title||`diagram`).toLowerCase().replace(/[^\w]+/g,`-`)+`.svg`,e.click(),setTimeout(()=>URL.revokeObjectURL(e.href),1e3)},W(`#share`).onclick=()=>{let e=Object.keys(X).length>1,t=`${location.origin}${location.pathname}#${e?`files=${Vc(JSON.stringify({files:X,current:Z}))}`:`src=${Vc(q)}`}`;history.replaceState(null,``,t),cu(t,`link`)},W(`#zoom-in`).onclick=()=>il(lu()*1.25),W(`#zoom-out`).onclick=()=>il(lu()/1.25),W(`#zoom-fit`).onclick=()=>il(+!jc);function lu(){let e=Uc();return e?e.width.baseVal.value/Ac.bounds.w:1}wc.hidden=!Lc,wc.onclick=()=>void ql(),window.addEventListener(`beforeunload`,e=>{Lc&&Kl.dirty&&e.preventDefault()}),window.addEventListener(`resize`,()=>jc||Q(!1)),document.addEventListener(`keyup`,e=>{e.key===` `&&(Zl=!1,K.classList.remove(`can-pan`))}),window.addEventListener(`blur`,()=>{Zl=!1,K.classList.remove(`can-pan`)});var uu=new ec((e,t)=>{t&&Bl(q),q=e,Gl()},()=>Q(!0));G.addEventListener(`input`,()=>uu.input(G.value)),G.addEventListener(`click`,$c),G.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&$c()}),G.addEventListener(`keydown`,e=>{e.key===`Tab`&&(e.preventDefault(),G.setRangeText(` `,G.selectionStart,G.selectionEnd,`end`),G.dispatchEvent(new Event(`input`)))});function du(e,t,n){let r=document.createElement(`div`);r.className=`split ${e}`,r.setAttribute(`role`,`separator`),t(r),r.addEventListener(`pointerdown`,e=>{e.preventDefault(),r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let t=e=>n(e),i=()=>{r.classList.remove(`dragging`),r.removeEventListener(`pointermove`,t),r.removeEventListener(`pointerup`,i);try{localStorage.setItem(`yuhwa-panes`,JSON.stringify(mu))}catch{}jc||Q(!1)};r.addEventListener(`pointermove`,t),r.addEventListener(`pointerup`,i)})}var fu=W(`main`),pu=W(`#left`),mu={};try{mu=JSON.parse(localStorage.getItem(`yuhwa-panes`)??`{}`)}catch{}var hu=()=>{mu.left&&(fu.style.gridTemplateColumns=`${mu.left}px 1fr var(--side)`),mu.diag&&Object.assign(_c.style,{height:`${mu.diag}px`,maxHeight:`none`})};du(`split-x`,e=>pu.append(e),e=>{mu.left=Math.round(Math.min(Math.max(e.clientX-fu.getBoundingClientRect().left,240),innerWidth-640)),hu()}),du(`split-y`,e=>_c.before(e),e=>{let t=pu.getBoundingClientRect().bottom;mu.diag=Math.round(Math.min(Math.max(t-e.clientY,40),pu.clientHeight-160)),hu()}),hu();var gu=mc({ta:G,files:()=>({...X,[Z]:G.value}),current:()=>Z,commit:Hl,open:_u,status:Bc,onDiagnostics:e=>{e===Z&&ul()}});function _u(e){if(e===Z||!(e in X))return;X[Z]=q,uu.end(),Ic.set(Z,{undo:Nc,redo:Pc}),Z=e,q=X[e];let t=Ic.get(e);Nc=t?.undo??[],Pc=t?.redo??[],Y=null,G.value=q,G.scrollTop=0,Gl(),Cu(),Q(!0)}var vu=e=>{let t=e.trim().replace(/^\.?\//,``).replace(/\s+/g,`-`);return t?/\.\w+$/.test(t)?t:`${t}.yuhwa`:``};function yu(e,t){let n=e;for(let t=2;n in X;t++)n=e.replace(/(\.\w+)?$/,`-${t}$1`);return X[n]=t,_u(n),n}function bu(e){let t=Z.split(`/`).slice(0,-1),n=e.split(`/`),r=0;for(;r<t.length&&t[r]===n[r];)r++;let i=t.slice(r).map(()=>`..`);return(i.length?i.join(`/`)+`/`:`./`)+n.slice(r).join(`/`)}function xu(e){let t=vu(prompt(`Rename file`,e)??``);if(!t||t===e)return;if(t in X)return Bc(`${t} exists`);X[Z]=q,uu.end();let n=X[e];delete X[e],X[t]=n;let r=e=>e.split(`/`).pop();for(let n of Object.keys(X))X[n]=X[n].replace(/^(\s*(?:\/\/\s*)?import\s+(?:\{[^}]*\}\s*from\s+)?")([^"]+)(")/gm,(n,i,a,o)=>r(a)===r(e)?i+a.slice(0,-r(e).length)+r(t)+o:n);Z===e&&(Z=t),q=X[Z],G.value=q,Gl(),Cu(),Q(!0)}function Su(e){Object.keys(X).length<2||(!X[e].trim()||confirm(`Delete ${e}?`))&&(e===Z&&_u(Object.keys(X).find(t=>t!==e)),delete X[e],Ic.delete(e),Gl(),Cu(),Q(!0))}function Cu(){Dc.innerHTML=``;for(let e of Object.keys(X)){let t=document.createElement(`button`);t.className=`tab`,t.setAttribute(`role`,`tab`),t.setAttribute(`aria-selected`,String(e===Z)),t.textContent=e,t.onclick=()=>_u(e),Lc||(t.title=`${e}: double-click to rename`,t.ondblclick=()=>xu(e));let n=document.createElement(`span`);n.className=`x`,n.textContent=`×`,n.title=`Delete ${e}`,n.onclick=t=>{t.stopPropagation(),Su(e)},Lc||t.append(n),Dc.append(t)}Dc.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`,inline:`nearest`}),wu.hidden=Lc,Eu()}var wu=W(`#add-file`);wu.onclick=()=>{let e=vu(prompt(`New file name`,`shared.yuhwa`)??``);e&&Bc(`${yu(e,`// Shared classes and nodes. Use them from ${Z} with:\n// import "${bu(e).replace(/^(\.\.\/)+/,`./`)}"\n\n.svc [blue]\n`)} added`)};function Tu(e){let t=new Set([...J.nodes.keys(),...J.panels.map(e=>e.id),...J.groups.keys(),...Object.keys(J.classes),...Object.keys(J.vars??{}),...Object.keys(J.defs??{})]);for(let n=1;;n++){let r=n===1?e:`${e}${n}`;if(!t.has(r)&&!q.includes(`${r} `))return r}}function Eu(){Oc.replaceChildren(Oc.options[0]);let e=new Map,t=(t,n,r)=>{let i=e.get(t);i||(i=document.createElement(`optgroup`),i.label=t,e.set(t,i),Oc.append(i)),i.append(new Option(n,r))};rc.forEach((e,n)=>t(e.group,e.label,`s${n}`));for(let e of Pn.panels.keys())rc.some(t=>t.text.startsWith(e+` `))||t(`Panels`,e,`k${e}`);for(let e of Object.keys(X))e!==Z&&t(`Import a file`,`import "${bu(e)}"`,`f${e}`)}function Du(e,t=!1){let n=q.search(/^layout\s*\{/m),r=t?0:n>=0?n:q.length,i=q.slice(0,r).replace(/\s*$/,``),a=q.slice(r),o=i?t?``:`
583
+
584
+ `:``,s=t?`${e}\n${q}`:`${i}${o}${e}\n${a?`
585
+ `+a:``}`;Hl(s);let c=t?0:i.length+o.length;G.focus(),G.setSelectionRange(c,c+e.length);let l=s.slice(0,c).split(`
586
+ `).length;G.scrollTop=Math.max(0,(l-3)*parseFloat(getComputedStyle(G).lineHeight||`20`))}Oc.onchange=()=>{let e=Oc.value;if(Oc.value=``,e.startsWith(`s`)){let t=rc[Number(e.slice(1))],n=Tu(t.id);Du(t.text.replaceAll(`{id}`,n)),Bc(`${t.label.toLowerCase()} added`)}else if(e.startsWith(`k`)){let t=Pn.panels.get(e.slice(1));Du(`${t.name} ${Tu(t.name)} "${t.name}" {\n // ${t.syntax??``}\n}`)}else if(e.startsWith(`f`)){let t=`import "${bu(e.slice(1))}"`;if(q.includes(t))return Bc(`already imported`);Du(t,!0)}};var Ou=W(`#import-dlg`),ku=W(`#import-text`),Au=W(`#import-msg`),ju=W(`#import-new`),Mu=`imported.yuhwa`;function Nu(e=``,t=`imported.yuhwa`){ku.value=e,Mu=t,Au.textContent=``,Au.className=``,ju.checked=!Lc,ju.disabled=Lc,Ou.showModal(),ku.focus()}W(`#import`).onclick=()=>Nu();async function Pu(e){Nu(await e.text(),vu(e.name.replace(/\.(mmd|mermaid|json|txt|md)$/,``)))}W(`#import-file`).onchange=async e=>{let t=e.target.files?.[0];t&&await Pu(t),e.target.value=``};var Fu=e=>e.match(/```(?:yuhwa|mermaid|json)[^\n]*\n([\s\S]*?)```/)?.[1]??e;W(`#import-go`).onclick=e=>{e.preventDefault();let t=Fu(ku.value);if(!t.trim())return Ou.close();let n=$s(t),r=n.diagnostics.filter(e=>e.severity===`error`);if(r.length||!n.source.trim()){Au.className=`error`,Au.textContent=r.map(e=>e.message).join(`
587
+ `)||`nothing to import`;return}let i=n.format===`yuhwa`?`yuhwa`:n.format===`json`?`JSON`:`Mermaid`;ju.checked?yu(Mu,n.source):Hl(n.source),Ou.close();let a=n.diagnostics.length;Bc(`imported ${i}${a?` (${a} warning${a>1?`s`:``})`:``}`)},addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),addEventListener(`drop`,e=>{let t=e.dataTransfer?.files[0];t&&(e.preventDefault(),Pu(t))});async function Iu(){if(Lc){let e=await(await fetch(`/api/source`)).json();q=e.source,Z=String(e.name).split(`/`).pop()||Fc,Rc=e.files??{},document.title=`${e.name} — yuhwa`,Bc(e.name)}else{if(!Lu()){let e=null;try{e=localStorage.getItem(`yuhwa-files`),Ru(e?JSON.parse(e):{files:{[Fc]:localStorage.getItem(`yuhwa-source`)??kc}})}catch{Ru({files:{[Fc]:kc}})}}X[Z]=q}Lc&&(X={[Z]:q,...Rc}),G.value=q,Cu(),Q(!0)}function Lu(){let e=location.hash.match(/src=([\w-]+)/),t=location.hash.match(/files=([\w-]+)/);try{if(t)Ru(JSON.parse(Hc(t[1])));else if(e)Ru({files:{[Fc]:Hc(e[1])}});else return!1}catch{return Bc(`broken link`),!1}return!0}function Ru(e){uu.end(),X=Object.keys(e.files??{}).length?{...e.files}:{[Fc]:kc},Z=e.current&&e.current in X?e.current:Object.keys(X)[0],q=X[Z],Ic.clear(),Nc=[],Pc=[]}Iu(),addEventListener(`hashchange`,()=>{!Lc&&Lu()&&(G.value=q,Cu(),Q(!0))});