yuhwa 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +1,42 @@
1
- var Yuhwa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=null;function n(e,n){let r=t;t=e;try{return n()}finally{t=r}}function r(e,n,r,i=1){let a=`plugin "${e}": ${n} failed: ${r instanceof Error?r.message:String(r)}`;t&&!t.some(e=>e.message===a)&&t.push({line:i,message:a,severity:`error`})}function i(e,t,n,i){return function(...a){try{return n.apply(this,a)}catch(n){return r(e,t,n),i(...a)}}}let a=e=>Object.setPrototypeOf(e,null),o=a({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`]});o.violet=o.purple,o.rose=o.red,o.emerald=o.green,o.yellow=o.amber,o.grey=o.gray,o.sky=o.cyan;let s=e=>Object.hasOwn(o,e),c=[`slate`,`gray`,`red`,`orange`,`amber`,`lime`,`green`,`teal`,`cyan`,`blue`,`indigo`,`purple`,`pink`],l={50:0,100:1,200:2,300:3,400:4,500:5,600:6,700:7,800:8,900:9,950:10};function u(e,t){return o[e]?.[l[t]]}let d=`Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`,f=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,p=e=>o[e]&&{fill:u(e,50),stroke:u(e,300),text:u(e,900)},m=e=>o[e]&&{fill:u(e,50)+`b3`,stroke:u(e,200),text:u(e,700)},h=e=>o[e]&&{fill:u(e,950),stroke:u(e,600),text:u(e,100)},g=e=>o[e]&&{fill:u(e,950)+`80`,stroke:u(e,800),text:u(e,300)},_=a({paper:{name:`paper`,dark:!1,background:`#fbfaf7`,font:d,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:p,groupTone:m,edgeTone:e=>u(e,500)}}),v=Object.keys(_);function y(e){let t=e;t.edge.ink??=t.edge.text,_[t.name]=t,v.includes(t.name)||v.push(t.name)}let b=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,x=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(` `))),S=e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`),C=(e,t)=>e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e);function w(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=>S(C(e,255))).join(``);let t=(parseFloat(e[0])%360+360)%360/360,n=Math.min(1,C(e[1],1)/(e[1].endsWith(`%`)?1:100)),i=Math.min(1,C(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=>S(s(e)*255)).join(``)}let i=x.get(t);return i?`#`+i:void 0}let T=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))},E=(e,t,n)=>`#`+T(e).map((e,r)=>Math.round(e*n+T(t)[r]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``);function D(e,t,n){let r=w(e);if(!r)return;let i=b.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,a=t.dark?n?.14:.22:n?.07:.12;return{fill:E(r,i,a),stroke:r,text:t.dark?E(r,`#ffffff`,.45):E(r,`#000000`,.55)}}let O=/* @__PURE__ */ new WeakMap,k=/* @__PURE__ */ new WeakMap,A=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),j=[`solid`,`dashed`,`dotted`],ee=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t;function M(e){let t=e===`mono`||/mono|code|courier/i.test(e);return e===`mono`||e===`sans`?{font:t?f:d,mono:t}:{font:`${e}, ${t?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`}`,mono:t}}let te=a({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:j},"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 N(e,t,n){let r=n??_[t.base]??_.paper,i=A(t.dark,r.dark),a=(e,n,a)=>I(t[e],r,i?a:n),o=(e,n)=>{let r=parseFloat(t[e]);return Number.isFinite(r)&&r>=0?r:n},s=e=>!A(t[e],!0),c=s(`background`)?`none`:a(`background`,50,950)??r.background,l=a(`edge-text`,700,300)??r.edge.text,d=i!==r.dark,f=t.font?.trim(),v=f?M(f):{font:r.font,mono:r.mono};return{name:e,dark:i,background:c,font:v.font,mono:v.mono,fontSize:o(`font-size`,r.fontSize),node:{fill:a(`node-fill`,50,900)??r.node.fill,stroke:a(`node-stroke`,300,600)??r.node.stroke,text:a(`node-text`,900,100)??r.node.text,sub:a(`node-sub`,500,400)??r.node.sub},group:{fill:s(`group-fill`)?`none`:a(`group-fill`,50,950)??r.group.fill,stroke:a(`group-stroke`,200,800)??r.group.stroke,text:a(`group-text`,700,300)??r.group.text,dash:ee(t[`group-border`],r.group.dash)},edge:{stroke:a(`edge-color`,500,400)??r.edge.stroke,text:l,labelBg:a(`label-bg`,50,950)??(r.edge.labelBg===r.background||t.background?c:r.edge.labelBg),labelStroke:r.edge.labelStroke,ink:t[`edge-text`]?l:a(`edge-color`,600,300)??r.edge.ink},title:a(`title-color`,900,100)??r.title,accent:a(`accent`,600,400)??r.accent,strokeWidth:o(`stroke-width`,r.strokeWidth),edgeWidth:o(`edge-width`,r.edgeWidth),radius:o(`radius`,r.radius),shadow:s(`shadow`)?null:a(`shadow`,200,950)??(d?i?`rgba(0, 0, 0, 0.45)`:`rgba(15, 23, 42, 0.10)`:r.shadow),grid:s(`grid`)?null:a(`grid`,200,800)??r.grid,tone:d?i?h:p:r.tone,groupTone:d?i?g:m:r.groupTone,edgeTone:d?e=>u(e,i?400:500):r.edgeTone}}function ne(e,t,n=[]){let r=t[e],i=r.base??(_[e]?e:void 0);return N(e,r,i&&t[i]&&i!==e&&!n.includes(i)?ne(i,t,[...n,e]):_[i??`paper`]??_.paper)}let re=e=>[.../* @__PURE__ */ new Set([...v,...Object.keys(e??{})])];function P(e,t){if(e&&t?.[e]){let n=k.get(t);n||k.set(t,n=/* @__PURE__ */ new Map);let r=n.get(e);return r||n.set(e,r=ie(ne(e,t))),r}return ie(_[e??`paper`]??_.paper)}function ie(e){let t=O.get(e);return t||(t={...e,tone:n=>e.tone(n)??D(n,t,!1),groupTone:n=>e.groupTone(n)??D(n,t,!0),edgeTone:t=>e.edgeTone(t)??(w(t)?t:void 0)},O.set(e,t)),t}let F=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&s(t[1])&&(!t[2]||t[2]in l)||!!w(e)},ae=F,oe=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function I(e,t,n){if(!e)return;let r=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);if(r&&o[r[1]]){let e=r[2]?Number(r[2]):n;return u(r[1],e in l?e:n)}return se(e)?e:void 0}let 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())},L=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),le=e=>({...e,text:e.sub}),ue=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,de=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,fe=/\*\*(.{1,1000}?)\*\*|~~(.{1,1000}?)~~|`([^`]+)`|\[\[(.{1,1000}?)\]\]|\{([^{}|\n]{1,1000}?)[ ]?\|[ ]?(.{1,1000}?)\}|\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.{1,1000}?)\}|\*(.{1,1000}?)\*/g,pe=a({color:{aliases:[`text`],info:`text colour: a palette name or any CSS colour`,values:c},size:{aliases:[`font-size`],info:`font size, px`,values:[]},weight:{aliases:[`font-weight`],info:`font weight: 400, 600, 700 ...`,values:[`300`,`400`,`500`,`600`,`700`,`800`,`900`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),me=e=>e in pe?e:Object.keys(pe).find(t=>pe[t].aliases.includes(e));function he(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&ge(i)){t.color=i;continue}let a=me(i);if(!a)return;let o=pe[a].flag,s=r.length?r.join(`:`).trim():o?`true`:``;if(o){if(s!==`true`&&s!==`false`)return;s===`true`&&(a===`italic`?t.italic=!0:t.weight=700)}else if(a===`color`){if(!F(s))return;t.color=s}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}let ge=e=>ue.test(e)&&(e.startsWith(`#`)||s(e.replace(/-\d+$/,``)));function R(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(fe))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&&ge(e[1])?r({kind:`chip`,text:e[2],color:e[1]}):r({kind:`chip`,text:t[4]})}else if(t[5]!==void 0){let e=he(t[5]),n=e?null:t[0].match(de);e?r({kind:`color`,text:t[6],...e}):n&&ge(n[1])?r({kind:`color`,text:n[2],color:n[1]}):r({kind:`text`,text:t[0]})}else t[7]===void 0?r({kind:`muted`,text:t[9]}):ge(t[7])?r({kind:`color`,text:t[8],color:t[7]}):r({kind:`text`,text:t[0]});return r({kind:`text`,text:e.slice(n)}),t}function _e(e){let t=[];for(let n of e.matchAll(fe))t.push([n.index,n.index+n[0].length]);let n=[],r=``,i=0;for(let a=0;a<e.length;a++){for(;i<t.length&&t[i][1]<=a;)i++;let o=i<t.length&&t[i][0]<=a;e[a]===` `&&!o?(r&&n.push(r),r=``):r+=e[a]}return r&&n.push(r),n}let ve=/[*~`[{]/;function ye(e,t=!1){let n=ve.test(e)?R(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function be(e,t,n,r,i,a=!1,o=0){let s=ye(e,a);return H(s,t,r,i,n)+(o?o*[...Te(s)].length:0)}let xe=(e,t)=>e.reduce((e,t)=>ve.test(t)?R(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),Se=(e,t,n=1.3)=>xe(e,t)*n,Ce=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${B(t)}" y="${B(n(i))}">${r(e)}</tspan>`).join(``);function we(e,t,n,r=!1){let i=ye(e,r);return i.every(e=>e.kind===`text`)?z(Te(i)):U(i,t,n)}let Te=e=>e.map(e=>e.text).join(``);function Ee(e){let t=1/0;for(let n of e)n.trim()&&(t=Math.min(t,n.match(/^[ \t]*/)[0].length));let 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,` `))}let z=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),B=e=>(Math.round(e*100)/100).toString(),De=(e,t,n,r,i,a=``)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" font-size="${B(n)}" fill="${r}"${a}>${i}</text>`,V=(e,t,n)=>e&&I(e,t,t.dark?400:600)||n,Oe=.55,ke=(e,t)=>e.weight??(e.kind===`bold`?700:t);function H(e,t,n,r,i=400){let a=0;for(let o of e){let e=o.size??t,s=r(o.text,e,ke(o,i),n);o.w=o.kind===`chip`?s+e*Oe*2:s,a+=o.w}return a}let Ae=e=>e.reduce((e,t)=>e+(t.w??0),0);function je(e,t,n,r){if(e.color)return V(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 Me(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=je(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="${B(t)}" y="${B(n-a/2)}" width="${B(e)}" height="${B(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(De(t+r*Oe,n,r,l.color?u:i.text,z(l.text),` xml:space="preserve"`))}else{let a=ke(l,s),o=l.italic?` font-style="italic"`:``;if(c.push(De(t,n,l.size??r,u,z(l.text),` xml:space="preserve"${a===400?``:` font-weight="${a}"`}${o}`)),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${B(a)},${B(n)}H${B(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function U(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${je(e,t,n,r)}"`];return e.size&&i.push(`font-size="${B(e.size)}"`),e.weight?i.push(`font-weight="${e.weight}"`):e.kind===`bold`&&i.push(`font-weight="750"`),e.italic&&i.push(`font-style="italic"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${z(e.text)}</tspan>`}).join(``)}let Ne=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function Pe(e,t=`border-style`){let n=e[t];return n&&j.includes(n)?n:A(e.dashed,!1)?`dashed`:A(e.dotted,!1)?`dotted`:void 0}function Fe(e,t){let n=I(t[`edge-color`],e,e.dark?400:500),r=Ie(t);if(!n&&!r)return e;let i=Object.create(e);return n&&(i.edge={...e.edge,stroke:n,ink:n}),r&&(i.edgeWidth=r),i}function Ie(e){return Le(e[`edge-width`])}let W=(e,t)=>{let n=Ne(e,NaN);return n>=0?n:t},Le=e=>{let t=Ne(e,NaN);return t>0?t:void 0},Re=(e,t,n)=>({size:Le(e[`font-size`])??t,weight:Le(e[`font-weight`])??n,italic:A(e.italic,!1)}),ze=(e,t)=>Re(e,t.fontSize*.86,500);function Be(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function Ve(e,t){switch(e){case`dashed`:return`${B(t*4)} ${B(t*3)}`;case`dotted`:return`${B(t*.1)} ${B(t*2.6)}`;default:return null}}function He(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=W(n.border??n[`stroke-width`],W(i[`stroke-width`],r.strokeWidth)),s=I(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=I(n.stroke,r,500)??a?.stroke??r.node.stroke,l=I(n.text,r,r.dark?100:800)??a?.text??r.node.text,u=Re(n,Le(i[`font-size`])??r.fontSize,500),d=u.size;return{fill:s,stroke:c,text:l,sub:I(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:Ve(Pe(n),o),radius:W(n.radius,W(i.radius,r.radius)),fontSize:d,fontWeight:A(n.bold,!1)?650:u.weight,body:I(n[`body-color`],r,r.dark?100:800)??l,bodySize:Le(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:Le(n[`body-weight`])??400,lineHeight:Le(n[`line-height`])??1.75,italic:u.italic,shadow:A(n.shadow,A(i.shadow,r.shadow!==null)),opacity:Ne(n.opacity,1)}}function Ue(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:I(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:I(n.stroke,t,300)??r?.stroke??t.group.stroke,text:I(n.text,t,700)??r?.text??t.group.text,dash:We(n,t.group.dash)}}function We(e,t){return ee(Pe(e),t)}function Ge(e,t,n){let r=t.theme;if(!r||!(_[r]||n?.[r])||r===e.name)return Fe(e,t);let i=Object.create(P(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,Fe(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&&F(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:I(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`:I(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:I(e.text,t,t.dark?200:700)??r?.text??t.title,width:W(e[`border-width`],a&&!s&&!o?W(a,1):1),dash:We(e,null),radius:W(e.radius,Math.min(14,t.radius+4)),shadow:A(e.shadow,!1)}}function qe(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??I(n.color,r,500):void 0,o=I(n.stroke,r,r.dark?400:500)??a??r.edge.stroke,s=t.line===`thick`||A(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=W(n.width,s),l=Pe(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=A(n.flow??n.animate,!1),f=ze(n,r);return{stroke:o,width:c,dash:Ve(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:I(n.text??n[`label-color`],r,700)??(a&&!r.dark?I(n.color,r,700):r.edge.text),fontSize:f.size,fontWeight:f.weight,italic:f.italic,labelBg:I(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:Ne(n.opacity,1)}}let Je=[`top`,`right`,`bottom`,`left`],Ye=[`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],Xe=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),Ze=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),Qe=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),$e=e=>Math.hypot(e.x,e.y),et=e=>{let t=$e(e)||1;return{x:e.x/t,y:e.y/t}},tt=(e,t)=>$e(Qe(e,t)),G=e=>Math.round(e*100)/100;function nt(e,t,n,r){let i=Xe(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`}let rt={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function it(e,t,n){let r=Xe(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function at(e,t,n){let r=it(t,n,e);return[e,r,rt[r]]}function ot(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&&dt(n,l));if(!u.length)return[n,r];let d=i?at(n,e,Xe(t)):[n],f=a?at(r,t,Xe(e)):[r],p=d.flatMap(e=>f.map(t=>[e,t])),m=([e,t])=>+(e!==n)+ +(t!==r);p.sort((e,t)=>m(e)-m(t));let h=p[0],g=1/0;for(let n of p){let[r,i]=n,a=Wt(e.shape,e,r,0),o=Wt(t.shape,t,i,0),s=wt({kind:`cubic`,segs:vt(a,Ht[r],o,Ht[i],[])}),c=0;for(let e of u)s.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)&&c++;if(!c)return n;c<g&&([h,g]=[n,c])}return h}let st=(e,t)=>e&&(Ye.includes(e)||At.has(e))?e:t;function ct(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=/* @__PURE__ */ 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,s=new Map(e.edges.map(e=>[e.key,e])),c=/* @__PURE__ */ new Map;for(let l of e.edges){let u=t.get(l.from),d=t.get(l.to);if(!u||!d)continue;let f=Be(e,l),p=qe(e,l,f,n.theme,n.defaultCurve),m=e.layout.edges[l.key],h=!!m?.via?.length,g=(h?m.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),_=u!==d&&!g.length?a.get(i(l.from,l.to)):void 0;if(_&&_.length>1){let[t,r]=l.from<l.to?[u,d]:[d,u],i=et(Qe(Xe(r),Xe(t))),a=c.get(_);if(!a){let t=_.map(t=>{let r=s.get(t),a=r?.label?ze(Be(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
2
- `).map(e=>be(e,a.size,a.weight,n.theme.mono,n.measure)))+18:0;return Math.max(o,Math.abs(i.y)*c+Math.abs(i.x)*o+6)}),r=t.reduce((e,t)=>e+t,0);a=/* @__PURE__ */ new Map;let l=0;for(let e=0;e<_.length;e++)a.set(_[e],l+t[e]/2-r/2),l+=t[e];c.set(_,a)}let f=a.get(l.key),p=Xe(u),m=Xe(d);f&&g.push(Ze({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},f))}let v=m?.ports?.[0]??f.exit??f[`from-side`],y=m?.ports?.[1]??f.enter??f[`to-side`],b=Je.includes(v)?v:null,x=Je.includes(y)?y:null,S=b??nt(u,g[0]??Xe(d),g.length?null:d,n.direction),C=x??nt(d,g[g.length-1]??Xe(u),g.length?null:u,n.direction);g.length||u===d||b&&x||([S,C]=ot(u,d,S,C,!b,!x,n.obstacles)),r.push({e:l,a:u,b:d,via:g,manualVia:h,sides:u===d?[`right`,`top`]:[S,C],t:[0,0],style:p,headKind:l.endHead||f.head?st(f.head,`arrow`):`none`,tailKind:l.startHead||f.tail?st(f.tail,`arrow`):`none`,labelOff:m?.label})}let l=/* @__PURE__ */ 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]??Xe(e.b):e.via[e.via.length-1]??Xe(e.a),i=`${n.id}\u0000${e.sides[t]}`;l.has(i)||l.set(i,[]),l.get(i).push({it:e,end:t,other:r})}for(let[e,t]of l){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=>lt(e,n))}function lt(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,Ze(o,{x:52,y:0}),Ze(s,{x:0,y:-52}),s]]};else{o=Wt(n.shape,n,e.sides[0],e.t[0]),s=Wt(r.shape,r,e.sides[1],e.t[1]);let c=Ht[e.sides[0]],l=Ht[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let i=e.via.map(e=>({...e}));i[0].y=o.y,i[i.length-1].y=s.y,a={kind:`poly`,pts:yt(o,c,s,l,i,n,r,t.obstacles),radius:10}}else a=i.curve===`orthogonal`?{kind:`poly`,pts:yt(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:vt(o,c,s,l,e.via)}}let c=wt(a),l,u=e.e.props.caption;if(e.e.label||u){let n=i.fontSize,{mono:r}=t.theme,a=e.e.label?e.e.label.split(`
3
- `):[],o=a.length?Math.max(...a.map(e=>be(e,n,i.fontWeight,r,t.measure)))+(t.theme.edge.labelStroke?18:12):0,s=Se(a,n),d=a.length?a.length*s+6:0,f=n*.88,p=u?u.split(`
4
- `):[],m=p.length?Math.max(...p.map(e=>be(e,f,400,r,t.measure)))+8:0,h=Se(p,f),g=p.length*h+(p.length?4:0),_=Math.max(o,m)/2,v=d?-d/2:0,y=(d?d/2:0)+g,b=e.e.props.rotate===`true`||e.e.props.rotate===``,x=e=>b?{x:e.x+v,y:e.y-_,w:y-v,h:_*2}:{x:e.x-_,y:e.y+v,w:_*2,h:y-v},S=e.labelOff?Ze(Et(c),e.labelOff):pt(c,x,e,t),C=x(S);l={text:e.e.label??``,caption:u,...C,anchor:S,pill:{w:o,h:d},lineHeight:s,captionLineHeight:h,rotate:b}}let d=[],f=mt(i.width),p=gt(a,`end`),m=gt(a,`start`);return e.headKind!==`none`&&(d.push({at:s,angle:Math.atan2(p.y,p.x),kind:e.headKind}),_t(a,`end`,ht(e.headKind,f,i.width))),e.tailKind!==`none`&&(d.push({at:o,angle:Math.atan2(m.y,m.x),kind:e.tailKind}),_t(a,`start`,ht(e.tailKind,f,i.width))),{key:e.e.key,decl:e.e,d:Ot(a),samples:c,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:l,heads:d,style:i}}let ut=[.5,.42,.58,.34,.66,.26,.74],dt=(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,ft=(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 pt(e,t,n,r){let i=Dt(e,.5),a=1/0;for(let n of ut){let o=Dt(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)dt(s,e)&&(c+=4);for(let e of r.groups??[])dt(s,e.header)?c+=3:dt(s,e.box)&&!ft(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}let mt=e=>7+e*2;function ht(e,t,n){let r=At.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 gt(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(tt(n[e],n[n.length-1])>.5)return et(Qe(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(tt(n[e],n[0])>.5)return et(Qe(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return et(Qe(r,tt(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return et(Qe(n,tt(r,n)>.5?r:i))}function _t(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=tt(r[i],r[a]);if(o<.5)return;r[i]=Ze(r[i],et(Qe(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=et(Qe(tt(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=Ze(t[3],r,n),tt(t[2],t[3])<n&&(t[2]=Ze(t[3],r,n))}else{let t=e.segs[0],r=et(Qe(tt(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=Ze(t[0],r,n)}}}function vt(e,t,n,r,i){if(!i.length){let i=tt(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,Ze(e,t,o),Ze(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}:et(Qe(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=tt(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],Ze(a[e],o[e],n),Ze(a[e+1],o[e+1],-r),a[e+1]])}return s}function yt(e,t,n,r,i,a,o,s){let c=Ze(e,t,18),l=Ze(n,r,18),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=1/0,_=1/0,v=-1/0,y=-1/0;for(let e of[...u,...h.flat(),l,n])g=Math.min(g,e.x),_=Math.min(_,e.y),v=Math.max(v,e.x),y=Math.max(y,e.y);let b=s.filter(e=>e.x<v&&e.x+e.w>g&&e.y<y&&e.y+e.h>_),x=null,S=1/0;for(let e of h){let t=xt([...u,...e,l,n]),r=Ct(t,b);r<S&&(S=r,x=t)}return x}function bt(e){let t=[];for(let n of e)(!t.length||tt(t[t.length-1],n)>.5)&&t.push(n);return t}function xt(e){let t=bt(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=et(Qe(t[e],r)),o=et(Qe(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 St(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 Ct(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=tt(e[a-1],e[a]),a>=2){let t=et(Qe(e[a-1],e[a-2])),n=et(Qe(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)St(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}function wt(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(Tt(n,r,i,a,e/16));return t}function Tt(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 Et(e){return Dt(e,.5)}function Dt(e,t){let n=0;for(let t=1;t<e.length;t++)n+=tt(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=tt(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 Ot(e){if(e.kind===`cubic`){let t=`M${G(e.segs[0][0].x)},${G(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${G(n.x)},${G(n.y)} ${G(r.x)},${G(r.y)} ${G(i.x)},${G(i.y)}`;return t}let t=bt(e.pts),n=`M${G(t[0].x)},${G(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,tt(i,a)/2,tt(a,o)/2);if(s<.5){n+=`L${G(a.x)},${G(a.y)}`;continue}let c=Ze(a,et(Qe(i,a)),s),l=Ze(a,et(Qe(o,a)),s);n+=`L${G(c.x)},${G(c.y)}Q${G(a.x)},${G(a.y)} ${G(l.x)},${G(l.y)}`}let r=t[t.length-1];return n+`L${G(r.x)},${G(r.y)}`}let kt=/* @__PURE__ */ new Map,At=/* @__PURE__ */ new Map,jt=[],Mt=[];function Nt(e,t,n,r,i,a=mt(i)){let o=Math.cos(t),s=Math.sin(t),c=(t,n)=>`${B(e.x+t*o-n*s)},${B(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="${B(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="${B(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="${B(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="${B(i*1.2)}" stroke-linecap="round"/>`;default:{let o=At.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}}}let Pt=[`rounded`,`box`,`pill`,`circle`,`ellipse`,`diamond`,`hexagon`,`cylinder`,`parallelogram`,`document`,`note`,`text`],Ft=a({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 It(e){if(!e)return`rounded`;let t=e.toLowerCase();return Pt.includes(t)||kt.has(t)?t:Ft[t]??`rounded`}function Lt(e,t,n){let r=kt.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 Rt(e){return e===`cylinder`?5:e===`document`?-4:0}let K=e=>(Math.round(e*100)/100).toString();function zt(e,t,n){let r=kt.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 Vt(i,a,o,s,Math.min(c,3));case`pill`:return Vt(i,a,o,s,s/2);case`circle`:case`ellipse`:{let e=o/2,t=s/2,n=i+e;return`M${K(n-e)},${K(a+t)}a${K(e)},${K(t)} 0 1,0 ${K(e*2)},0a${K(e)},${K(t)} 0 1,0 ${K(-e*2)},0Z`}case`diamond`:return`M${K(i+o/2)},${K(a)}L${K(i+o)},${K(a+s/2)}L${K(i+o/2)},${K(a+s)}L${K(i)},${K(a+s/2)}Z`;case`hexagon`:{let e=Math.min(s*.3,o/4);return`M${K(i+e)},${K(a)}L${K(i+o-e)},${K(a)}L${K(i+o)},${K(a+s/2)}L${K(i+o-e)},${K(a+s)}L${K(i+e)},${K(a+s)}L${K(i)},${K(a+s/2)}Z`}case`parallelogram`:{let e=Math.min(16,o/5);return`M${K(i+e)},${K(a)}L${K(i+o)},${K(a)}L${K(i+o-e)},${K(a+s)}L${K(i)},${K(a+s)}Z`}case`cylinder`:{let e=Math.min(9,s/6),t=o/2;return`M${K(i)},${K(a+e)}a${K(t)},${K(e)} 0 0,1 ${K(o)},0L${K(i+o)},${K(a+s-e)}a${K(t)},${K(e)} 0 0,1 ${K(-o)},0Z`}case`document`:{let e=Math.min(8,s/6);return`M${K(i+c)},${K(a)}L${K(i+o-c)},${K(a)}Q${K(i+o)},${K(a)} ${K(i+o)},${K(a+c)}L${K(i+o)},${K(a+s-e)}C${K(i+o*.75)},${K(a+s-e*3)} ${K(i+o*.25)},${K(a+s+e)} ${K(i)},${K(a+s-e)}L${K(i)},${K(a+c)}Q${K(i)},${K(a)} ${K(i+c)},${K(a)}Z`}case`note`:{let e=Math.min(14,o/5,s/3);return`M${K(i)},${K(a)}L${K(i+o-e)},${K(a)}L${K(i+o)},${K(a+e)}L${K(i+o)},${K(a+s)}L${K(i)},${K(a+s)}Z`}default:return Vt(i,a,o,s,c)}}function Bt(e,t){let n=kt.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${K(r)},${K(i+e)}a${K(a/2)},${K(e)} 0 0,0 ${K(a)},0`}if(e===`note`){let e=Math.min(14,a/5,o/3);return`M${K(r+a-e)},${K(i)}L${K(r+a-e)},${K(i+e)}L${K(r+a)},${K(i+e)}`}return null}function Vt(e,t,n,r,i){return i<=0?`M${K(e)},${K(t)}h${K(n)}v${K(r)}h${K(-n)}Z`:`M${K(e+i)},${K(t)}H${K(e+n-i)}A${K(i)},${K(i)} 0 0 1 ${K(e+n)},${K(t+i)}V${K(t+r-i)}A${K(i)},${K(i)} 0 0 1 ${K(e+n-i)},${K(t+r)}H${K(e+i)}A${K(i)},${K(i)} 0 0 1 ${K(e)},${K(t+r-i)}V${K(t+i)}A${K(i)},${K(i)} 0 0 1 ${K(e+i)},${K(t)}Z`}let Ht={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function Ut(e){return e===`circle`||e===`ellipse`||e===`diamond`?.45:e===`hexagon`||e===`pill`?.55:.75}function Wt(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))*Ut(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}}let Gt=[`smooth`,`orthogonal`,`straight`],Kt=[`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],qt=[`top`,`right`,`bottom`,`left`,`auto`],Jt=[`below`,`above`,`right-of`,`left-of`,`rank`],Yt=[`text`,`font-size`,`font-weight`,`italic`],Xt=[`shape`,`color`,`fill`,`stroke`,...Yt,`sub`,`sub-color`,`icon`,`border`,`stroke-width`,`border-style`,`dashed`,`dotted`,`radius`,`bold`,`shadow`,`opacity`,`width`,`height`,`link`,`tooltip`,`meta`,`caps`,`mono`,`body-size`,`body-color`,`body-weight`,`line-height`,`max-width`,...Jt],Zt=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...Yt,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`],Qt=[`color`,`fill`,`stroke`,...Yt,`border-style`,`dashed`,`dotted`,`meta`,`caps`],$t=[`color`,`theme`,`background`,`fill`,`border`,`stroke`,...Yt,`border-width`,`border-style`,`radius`,`shadow`,`frame`,`edge-color`,`edge-width`],en=a({shape:[...Pt,...Object.keys(Ft)],"border-style":j,style:j,curve:Gt,head:Kt,tail:Kt,exit:qt,"from-side":qt,enter:qt,"to-side":qt}),tn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],nn=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!F(e),rn=e=>ln(e,c)||`: use a palette name (${c.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`,an=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`],on=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`];function sn(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 cn(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=sn(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function ln(e,t){let[n,r]=cn(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function un(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let e=a?.[o]??r;if(!t.includes(o)){n===`node`&&Zt.includes(o)?i(e,`"${o}" is an edge prop, but here it is on a node. On an edge line, edge props go after a colon: a -> b: [${o}]`):i(e,`Unknown ${n} prop "${o}"${ln(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let c=en[o],l=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(tn.includes(o)&&nn(s))i(e,`Unknown ${o} "${s}"${rn(s)}`);else if(c&&!c.includes(l)){let t=o===`shape`?Pt:c;i(e,`Unknown ${o} "${s}"${ln(s,c)||` (use one of: ${t.join(`, `)})`}`)}else an.includes(o)&&![`true`,`false`].includes(s)?i(e,`${o} expects true or false, got "${s}"`):on.includes(o)&&!(parseFloat(s)>=0&&Number.isFinite(parseFloat(s)))?i(e,`${o} expects a number of 0 or more, got "${s}"`):o===`link`&&!ce(s)&&i(e,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function dn(e,t,n,r){if(t)for(let[i,a]of Object.entries(e)){let e=t[i];e!==void 0&&e!==`text`&&(e===`color`?F(a)||r(n,`Unknown ${i} "${a}"${ln(a,c)||`: use a palette name, #hex, rgb(), hsl() or a CSS colour name`}`):e===`number`?Number.isFinite(parseFloat(a))||r(n,`${i} expects a number, got "${a}"`):e===`flag`?[`true`,`false`].includes(a)||r(n,`${i} expects true or false, got "${a}"`):e.includes(a.toLowerCase())||r(n,`Unknown ${i} "${a}"${ln(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}let fn=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function pn(e){for(let[t,n]of Object.entries(e))if(Jt.includes(t)&&n)return[t,n.trim()]}function mn(e,t){let n=/* @__PURE__ */ new Map;for(let r of e.nodes.values()){let i=Be(e,r),a=pn(i);if(!a)continue;let[o,s]=a,c=fn(r,o);for(let e of Object.keys(i))e!==o&&Jt.includes(e)&&r.ref&&t(fn(r,e),`${r.id} already has ${o}: ${s}, so ${e} is ignored. A node takes one placement prop`);if(s===r.id)r.ref&&t(c,`${o}: ${s} places ${r.id} next to itself; use another node's id`);else if(e.nodes.has(s))n.set(r.id,s);else{if(!r.ref)continue;e.groups.has(s)?t(c,`${o}: ${s} names a group; placement takes a node id`):t(c,`${o}: unknown node "${s}"${ln(s,[...e.nodes.keys()])}`)}}let r=/* @__PURE__ */ new Set;for(let i of n.keys()){let a=[],o=i;for(;o!==void 0&&!a.includes(o);)a.push(o),o=n.get(o);if(o!==i||r.has(i))continue;a.forEach(e=>r.add(e));let s=e.nodes.get(i),c=pn(Be(e,s))[0];s.ref&&t(fn(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}let hn=e=>e.toLowerCase().replace(/\d+/g,`#`);function gn(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:hn(e.id)}));if(!r.length||n.every(e=>!e.implicit||e.id.length<3))return;let i=/* @__PURE__ */ new Map;for(let t of e.edges)if(t.ref)for(let e of[t.from,t.to])i.has(e)||i.set(e,t.ref.line);for(let e of n){let n=i.get(e.id);if(!e.implicit||e.id.length<3||n===void 0)continue;let a=hn(e.id),o=e.id.length<7?1:2,s=r.filter(t=>t.series!==a&&Math.abs(t.id.length-e.id.length)<=o),[c,l]=cn(e.id,s.map(e=>e.id));l<=o&&t(n,`Node "${e.id}" is only used in edges (did you mean "${c}"?). If it is a separate node, declare it: ${e.id} "Label"`)}}function _n(e,t){let n=(t,n)=>e.diagnostics.push({line:t+1,message:n,severity:`warning`});for(let t of e.nodes.values())t.ref&&un(t.props,Xt,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});mn(e,n);let r=/* @__PURE__ */ new Set;for(let t of e.edges){if(!t.ref)continue;let e=t.ref.line;r.has(e)||(r.add(e),un(t.props,Zt,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&un(t.props,Qt,`group`,t.ref.line,n,t.ref.propLines);gn(e,n);let i=re(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)&&n(e,`Unknown theme "${a.theme}"${ln(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of tn)a[t]&&nn(a[t])&&n(e,`Unknown ${t} "${a[t]}"${rn(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!F(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!j.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${j.join(`, `)})`),dn(a,t?.(r.kind),e,n)}let a=[.../* @__PURE__ */ new Set([...Xt,...Zt,...Qt])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&un(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}let vn=Object.keys(te),yn=/* @__PURE__ */ new Set([`title`,`subtitle`,`theme`,`accent`,`direction`,`curve`,`gap`,`rank-gap`,`max-width`,`font`,`font-size`,`background`,`padding`,`shadow`,`radius`,`stroke-width`,`shape`,`grid`,`panels`,`panel-gap`,`wrap`,`edge-color`,`edge-width`]),bn=a({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`,tree:`treeview ID`,filetree:`treeview ID`}),xn=/* @__PURE__ */ new Map,Sn=/* @__PURE__ */ new Map,Cn=[],wn=a({direction:[`right`,`down`,`left`,`up`],curve:[`smooth`,`orthogonal`,`straight`],panels:[`row`,`column`,`grid`,`wrap`]}),Tn=a({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),En=/* @__PURE__ */ new Set([...c,`violet`]),Dn=/* @__PURE__ */ new Set([`smooth`,`orthogonal`,`straight`]),On=e=>Pt.includes(e)||e in Ft||kt.has(e),kn=e=>/\.(yu|yuhwa)$/i.test(e);function An(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(`/`)}let jn=/* @__PURE__ */ new Set([`top`,`right`,`bottom`,`left`,`auto`]),Mn=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,Nn=/^(<)?(--|-|\.\.|==|=)(>)?/,Pn=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,Fn=/^-?\d+(?:\.\d+)?/;function In(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
- `:t===`t`?` `:t)}function Ln(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:In(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(Pn)){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(Mn)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Fn)){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 Rn(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 zn(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function Bn(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)`),{}):q(e.value)}let Vn=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function q(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();En.has(e)?t.color=e:On(e)?t.shape=e:Dn.has(e)?t.curve=e:F(n)?t.color=n:t[e]=`true`;continue}let i=Vn(n.slice(0,r)),a=n.slice(r+1).trim();/^(["']).*\1$/s.test(a)&&(a=In(a.slice(1,-1))),t[i]=a}return t}let Hn=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},Un=/(?<!\[)\[([^[\]]*)\]\s*$/;function Wn(e,t){let n=e.match(Un),r=n?q(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function Gn(e,t,n){let r=Vn(t),[i,a]=Wn(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=Jn(a);return s?`${o} [${s}]`:o}let Kn=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&F(e.color)};function qn(e,t,n,r,i){let a=Vn(n),[o,s]=Wn(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}=q(n),l=Jn(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=Jn(s);return u?`${l} [${u}]`:l}function Jn(e){return Object.entries(e).map(([e,t])=>t===`true`&&!En.has(e)&&!On(e)&&!Dn.has(e)&&!F(e)?e:e===`color`&&F(t)&&!On(t)&&!Dn.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(t)?ir(t):t}`).join(`, `)}function Yn(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}}let Xn=1e5,Zn=5e4,Qn=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,$n=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,er=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,tr=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,nr=/* @__PURE__ */ new WeakMap;function rr(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}let ir=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,ar=e=>/^(["']).*\1$/s.test(e.trim())?In(e.trim().slice(1,-1)):e.trim();function or(e,t={}){let r={settings:{},nodes:/* @__PURE__ */ new Map,edges:[],groups:/* @__PURE__ */ new Map,classes:a({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},i=e.split(/\r?\n/),o=t.seen??=/* @__PURE__ */ new Set;t.file&&o.add(t.file);let s=/* @__PURE__ */ new Map,l=[],u=(e,t)=>l.push([e,t]),d=!1,f=[],p=/* @__PURE__ */ new Map,m=(e,t,n=`warning`)=>r.diagnostics.push({line:e+1,message:t,severity:n}),h,g=(e,t,n,r)=>{if(!(t in te))return m(r,`Unknown theme key "${t}"${ln(t,vn)||` (keys: ${vn.join(`, `)})`}`);te[t].kind!==`color`||[`none`,`transparent`].includes(n)||n.includes(`$`)||F(n)||m(r,`Unknown color "${n}" for ${t}${ln(n,c)}`),e[t]=n},_=/* @__PURE__ */ new Map,v=(e,t,n)=>{_.has(e)&&m(n,`Theme "${e}" is defined twice`),(r.themes??=a({}))[e]=t,_.set(e,n)},y=()=>{for(let e=f.length-1;e>=0;e--)if(f[e].kind===`group`)return f[e].id},b=e=>{let t=r.nodes.get(e);return t||(t={id:e,label:e,props:{},classes:[],implicit:!0,group:y()},r.nodes.set(e,t)),t},x=/* @__PURE__ */ new Map,S=(e,t,n,r)=>{let i=t.value;e.labelRef={line:n,at:t.start,range:[t.start,t.end],generated:O||void 0};let a=x.get(e.id);a!==void 0&&e.label!==i&&m(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,x.set(e.id,n)},C=/* @__PURE__ */ new Map,w=(e,n,i)=>{if(!t.resolve)return m(n,`Cannot import "${e}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let a=An(t.file,e);if(!kn(a))return m(n,`Cannot import "${e}": imports must be .yu files`,`error`);let s=[...t.chain??(t.file?[t.file]:[])];if(s.includes(a))return m(n,`Import cycle: ${[...s,a].join(` -> `)}`,`error`);let c=i?`${a}{${i.map(e=>e.join(` as `)).join(`,`)}}`:a;if(o.has(c))return;let l;try{l=t.resolve(a)}catch{l=void 0}if(l===void 0)return m(n,`Cannot import "${e}": file not found (${a})`,`error`);let u=new Set(o),d=or(l,{resolve:t.resolve,file:a,chain:[...s,a],seen:u});for(let t of d.diagnostics)m(n,`${e}:${t.line}: ${t.message}`,t.severity);let f=cr(d,i,t=>m(n,`${e}: ${t}`,`error`));if(f===d)for(let e of u)o.add(e);o.add(c),lr(r,f,p),(r.imports??=[]).push(a,...d.imports??[])},T=r.vars=a({}),E=r.defs=a({}),D=r.used=/* @__PURE__ */ new Set;nr.set(E,E);let O=!1,k=0,A=0,j=/* @__PURE__ */ new Set,ee=null,M=e=>e.match(/^\s*/)[0].length,N=(e,t,n,r=!1)=>{let i=e.match($n);if(i)return e.slice(0,e.length-i[2].length)+N(i[2],t,n,r);let a=e.length,o=e.replace(Qn,(e,i,o)=>{let s=i??o;if(!s)return`$`;let c=n?.[s]??T[s];return n?.[s]===void 0&&c!==void 0&&D.add(`$`+s),c===void 0?(r||m(t,`Unknown variable "$${s}"${ln(s,[...Object.keys(n??{}),...Object.keys(T)])}`),e):(a+=c.length)>Xn?e:c});return a>Xn&&m(t,`Variables make this line longer than ${Xn} characters`,`error`),o},ne=(e,t,n)=>{if(k>=16){j.has(e.name)||m(n,`${e.name}(): calls nest too deep`,`error`),j.add(e.name);return}if((A+=e.body.length)>Zn){A-e.body.length<=Zn&&m(n,`${e.name}(): components expand to more than ${Zn} lines`,`error`);return}let r=rr(t),i=a({}),o=0;for(let t of r){let a=t.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(a&&e.params.some(e=>e.name===a[1]))i[a[1]]=ar(a[2]);else if(o<e.params.length)i[e.params[o++].name]=ar(t);else return void m(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 m(n,`${e.name}(): missing argument "${t.name}" (${e.params.map(e=>e.name).join(`, `)})`,`error`);i[t.name]=t.default}let s=f.length,c=O;O=!0,k++;let l=e.body.map(e=>N(e,n,i)),u=nr.get(e)??E;for(let e of l)P(e,n,!0,u);k--,O=c,f.length>s&&(m(n,`${e.name}(): a block inside the component is not closed`,`error`),f.length=s)},P=(e,t,n=!1,i=E)=>{if(/^\s*#(\s|$)/.test(e))return void m(t,`Comments start with "//", not "#"`,`error`);let o=f[f.length-1];if(o?.kind===`def`){for(let t of Rn(Ln(e).tokens))o.depth+=t===`{`?1:-1;if(o.depth>0)return void o.lines.push(e);f.pop(),e.trim()!==`}`&&m(t,`Expected "}" alone on the line that closes ${o.id}()`,`error`);let n=o.params,s=a(Object.fromEntries(n.map(e=>[e.name,`\${${e.name}}`]))),c={name:o.id,params:n,body:Ee(o.lines).map(e=>N(e,t,s,!0))};nr.set(c,i),E[c.name]&&m(o.start,`Component "${c.name}" is defined twice`),E[c.name]=c,(r.defLines??={})[c.name]=o.start;return}let s=o?.kind===`body`||o?.kind===`panel`;if(!s&&o?.kind!==`layout`){let a=e.match($n);if(a){T[a[1]]=ar(Hn(n?a[2]:N(a[2],t)).trimEnd()),(r.varLines??={})[a[1]]=t;return}let o=e.match(er);if(o){f.length&&m(t,`def must be at the top level`,`error`);let e=rr(o[2]).map(e=>{let n=e.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return n||m(t,`Bad parameter "${e}": def name(a, b = "default") {`,`error`),{name:n?.[1]??e,default:n?.[2]===void 0?void 0:ar(n[2])}});f.push({kind:`def`,id:o[1],start:t,lines:[],depth:1,params:e});return}let s=Hn(e).match(tr);if(s){let r=i[s[1]]??E[s[1]];if(r){D.add(s[1]),ne(r,n?s[2]:N(s[2],t),t);return}if(!Ln(e).tokens.some(e=>e.kind===`arrow`))return void m(t,`Unknown component "${s[1]}"${ln(s[1],Object.keys(E))}`,`error`)}}let c=n||o?.kind===`layout`||!s&&/^\s*(import|export)\b/.test(e)?e:N(e,t,void 0,s),l=O;O||=c!==e,ve(c,t),O=l},ie=(e,t,n)=>{if(t.trim()===`}`){f.pop();let t=r.nodes.get(e.id);t.body=Ee(e.lines),t.bodyLines=[e.start,n]}else e.lines.push(t)},ae=(e,t,n)=>{t.trim()===`}`?(f.pop(),oe(e,n)):e.lines.push(t.slice(0,Ln(t).codeEnd).trimEnd())},oe=(e,t)=>{let n=e.panel,r=e.lines.findIndex(e=>e.trim());n.body=Ee(e.lines),n.lines=[e.start,t],n.data=xn.get(n.kind).parse(n.body,n.props,((t,n,i)=>m(t<0?e.start:e.start+1+Math.max(0,r)+t,n,i)))},I=(e,t,n)=>{let r=t.slice(0,Ln(t).codeEnd).trim();if(!r)return;if(r===`}`){f.pop(),v(e.id,e.props,e.start);return}let i=r.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);if(!i)return void m(n,`Expected "key: value" in theme ${e.id} (keys: ${vn.join(`, `)})`,`error`);g(e.props,i[1].toLowerCase(),ar(i[2].trim()),n)},se=(e,t)=>{let n=e.slice(0,Ln(e).codeEnd).trim();n&&(n.startsWith(`}`)?(f.pop(),r.layoutBlock[1]=t):(C.set(n.split(/\s+/)[0],t),fr(n,t,r,m)))},ce=e=>{f.length?f.pop():m(e,`Unmatched "}"`,`error`),ee=null},L=(e,t,n)=>{if(f.length)m(t,`import must be at the top level`,`error`);else if(!e[1])m(t,`import needs a path: import "./shared.yu"`,`error`);else if(!n)e.length>2&&m(t,`Unexpected "${e[2].value}" after import path`,`error`),w(e[1].value,t);else{let n=sr(e,t,m);n&&w(n.path,t,n.names)}},le=(e,t,n)=>{f.length&&m(n,`export must be at the top level`,`error`);let i=e[1].kind===`ident`&&e[2]?.value===`:`&&yn.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),P(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)}d=!0;let a=e.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),o=e=>s.has(e)||s.set(e,n);if(e[1].value===`def`&&e[2])o(e[2].value);else if(e[1].value.startsWith(`$`)&&(e[2]?.value===`:`||e[2]?.value===`=`))o(e[1].value);else for(let t of e.slice(1))(t.kind===`ident`||t.kind===`class`)&&o(t.kind===`class`?`.${t.value}`:t.value);if(!a||e.slice(1).some(e=>e.kind===`ident`&&xn.has(e.value)))return P(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)},ue=(e,t)=>{f.length&&m(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(q(e[r].value)))g(n,i,a,t);r++}if(e[r]?.value===`{`){if(r++,e[r]?.value===`}`)r++;else if(r===e.length)return void f.push({kind:`theme`,id:e[1].value,start:t,props:n})}r<e.length&&m(t,`Unexpected "${e[r].value}" in theme ${e[1].value}`,`error`),v(e[1].value,n,t)},de=(e,t)=>{m(t,`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...xn.keys()].join(`, `)})`+(bn[e[0].value]&&xn.has(bn[e[0].value].split(` `)[0])?`: write "${bn[e[0].value].replace(`ID`,e[1].value)} {"`:``))},fe=(e,t)=>{let n=e[0].value,i=1,a=e[i]?.kind===`ident`?e[i++].value:`${n}${r.panels.length+1}`,o=O?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,c={line:t,insertAt:e[i-1].end},l={};e[i]?.kind===`props`&&(l=q(e[i].value),c.props=[e[i].start,e[i].end],i++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,i!==e.length-1&&m(t,`Unexpected "${e[i].value}" in ${n} header`,`error`),f.length&&m(t,`${n} must be at the top level`,`error`);let u={kind:n,id:a,label:s,props:l,body:[],data:void 0,ref:O?void 0:c,labelRef:o};r.panels.push(u),f.push({kind:`panel`,id:a,start:t,lines:[],panel:u})},pe=(e,t)=>{f.length&&m(t,`layout block must be at top level`,`error`),r.layoutBlock=[t,t],e[2]?.value!==`}`&&f.push({kind:`layout`})},me=(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:y()};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(O&&(o.labelRef.generated=!0);e[i]?.kind===`class`;)u(e[i].value,n),(o.classes??=[]).push(e[i++].value);let s={line:n,insertAt:e[i-1].end,generated:O||void 0};if(e[i]?.kind===`props`&&(Object.assign(o.props,q(e[i].value)),s.props=[e[i].start,e[i].end],i++),o.ref=s,ee={indent:M(t),targets:[o]},r.groups.set(a,o),e[i]?.value!==`{`){m(n,`Expected "{" after group ${a}`,`error`);return}i++;let c=e.findIndex((e,t)=>t>=i&&e.value===`}`);if(c>=0){for(let t=i;t<c;t++)if(e[t].kind===`ident`){let n=b(e[t].value);n.group=a}}else f.push({kind:`group`,id:a})},he=(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]):m(n,`Unknown class ".${t.value}"${ln(t.value,Object.keys(r.classes))}`));r.classes[e[0].value]={...r.classes[e[0].value],...a,...i.kind===`props`?q(i.value):{}},(r.classLines??={})[e[0].value]=n,ee={indent:M(t),targets:[{props:r.classes[e[0].value]}]}},ge=(e,t,n,i,a)=>{let o=Vn(e[0].value),s=t.slice(e[1].end,i).trim();/^(["']).*\1$/.test(s)&&(s=In(s.slice(1,-1)));let c=ee&&M(t)>ee.indent?ee.targets:null,l=a?.kind===`group`?r.groups.get(a.id):void 0,u=c??(l?[l]:null);if(u){for(let e of u)e.props[o]=s||`true`,e.ref&&!O&&((e.ref.propLines??={})[o]=n);return}if(f.length&&m(n,`Setting "${o}" should be at the top level`),!yn.has(o)){let t=e[0].value,r=s.startsWith(`{`)?`${t} [${s.slice(1,-1).trim()}]`:`${t} "${s}"`;m(n,`Unknown setting "${o}"${ln(o,[...yn])||`. For a node write ${r}`}`);return}o===`direction`&&(s=Tn[s.toLowerCase()]??s),o===`theme`&&(h=n);let d=o===`theme`?void 0:wn[o];d&&s&&!s.includes(`$`)&&!d.includes(s)&&m(n,`Unknown ${o} "${s}"${ln(s,d)||` (use one of: ${d.join(`, `)})`}`),r.settings[o]=s},R=(e,t,n,i)=>{let a=r.edges.length;if(ur(e,n,t.slice(0,i),r,b,p,m,S,u),ee={indent:M(t),targets:r.edges.slice(a)},O){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)}}},_e=(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();m(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`);f.push({kind:`body`,id:t.value,start:n,lines:[]});break}if(a.kind!==`ident`){m(n,`Unexpected "${a.value}"`,`error`);break}i=!1;let o=b(a.value);o.implicit=!1;let s=y();for(s&&o.group&&o.group!==s&&m(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`?S(o,e[r++],n,!1):o.labelRef??={line:n,at:a.end,generated:O||void 0};e[r]?.kind===`class`;){let t=e[r++].value;u(t,n),o.classes.includes(t)||o.classes.push(t)}let c={line:n,insertAt:e[r-1].end,generated:O||void 0};e[r]?.kind===`props`&&(zn(o,Bn(e[r],o.id,n,m),n),c.props=[e[r].start,e[r].end],r++),o.ref=c,ee={indent:M(t),targets:[o]}}},ve=(e,t)=>{let n=f[f.length-1];if(n?.kind===`body`)return ie(n,e,t);if(n?.kind===`panel`)return ae(n,e,t);if(n?.kind===`theme`)return I(n,e,t);if(n?.kind===`layout`)return se(e,t);let{tokens:i,codeEnd:a}=Ln(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 m(t,o,`error`);if(i[0].kind===`punct`&&i[0].value===`}`)return ce(t);let s=i[0].kind===`ident`?i[0].value:void 0,c=i[1]?.value===`{`&&i.some(e=>e.kind===`ident`&&e.value===`from`);if(s===`import`&&(i[1]?.kind===`string`||i.length===1||c))return L(i,t,c);if(s===`export`&&i.length>1&&i[1].kind!==`arrow`&&i[1].value!==`:`)return le(i,e,t);let l=s===void 0?void 0:Sn.get(s);if(l&&i[1]?.kind!==`arrow`&&i[1]?.value!==`:`&&i[1]?.value!==`,`)return void l.parse(e.slice(i[0].end,a).trim(),r,{line:t,warn:(e,n)=>m(t,e,n)});if(s===`theme`&&i[1]?.kind===`ident`&&(i[2]?.kind===`props`||i[2]?.value===`{`))return ue(i,t);let u=i[i.length-1].value===`{`;if(s!==void 0&&i.length>2&&!xn.has(s)&&i[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&de(i,t),s!==void 0&&xn.has(s)&&u&&(i[1]?.kind===`ident`||i[1]?.kind===`string`||i[1]?.kind===`props`||i[1]?.value===`{`))return fe(i,t);if(s===`layout`&&i[1]?.value===`{`)return pe(i,t);if(s===`group`&&(i[1]?.kind===`ident`||i[1]?.kind===`string`&&i.some(e=>e.value===`{`)))return me(i,e,t);let d=i[i.length-1];if(i[0].kind===`class`&&i.slice(1,-1).every(e=>e.kind===`class`)&&(d.kind===`props`||d.kind===`class`))return he(i,e,t);if(s!==void 0&&i[1]?.kind===`punct`&&i[1].value===`:`)return ge(i,e,t,a,n);if(i.some(e=>e.kind===`arrow`))return R(i,e,t,a);_e(i,e,t)};for(let e=0;e<i.length;e++)P(i[e],e);for(let e of f)e.kind===`group`?m(i.length-1,`Group "${e.id}" is missing "}"`,`error`):e.kind===`body`?m(e.start,`Body of "${e.id}" is missing a closing "}" line`,`error`):e.kind===`panel`?(m(e.start,`${e.panel.kind} "${e.id}" is missing a closing "}" line`,`error`),oe(e,i.length-1)):e.kind===`def`?m(e.start,`def ${e.id}() is missing "}"`,`error`):e.kind===`theme`?m(e.start,`theme ${e.id} is missing "}"`,`error`):m(i.length-1,`layout block is missing "}"`,`error`);let ye=re(r.themes);for(let[e,t]of _){let n=r.themes[e].base;n&&n!==e&&!ye.includes(n)&&m(t,`Unknown base theme "${n}"${ln(n,ye)}`)}let be=r.settings.theme;h!==void 0&&be&&!be.includes(`$`)&&(ye.includes(be)||m(h,`Unknown theme "${be}"${ln(be,ye)||` (use one of: ${ye.join(`, `)})`}`));let xe=/* @__PURE__ */ new Set;for(let[e,t]of l)r.classes[e]||xe.has(`${t}.${e}`)||(xe.add(`${t}.${e}`),m(t,`Unknown class ".${e}"`));if(d){let e=new Set(r.panels.map(e=>e.id));r.exports=[...s.keys()].filter(t=>t.startsWith(`.`)?t.slice(1)in r.classes:t.startsWith(`$`)?t.slice(1)in T:r.nodes.has(t)||r.groups.has(t)||e.has(t)||t in E||t in(r.themes??{}));for(let[e,t]of s)!r.exports.includes(e)&&!xn.has(e)&&e!==`group`&&e!==`def`&&m(t,`export: "${e}" is not declared in this file`)}for(let e of r.panels){r.nodes.get(e.id)?.implicit&&r.nodes.delete(e.id);let t=r.layout.nodes[e.id];t&&(t.x!==void 0&&t.y!==void 0&&(dr(r,e.id).at={x:t.x,y:t.y}),delete r.layout.nodes[e.id])}let Se=/* @__PURE__ */ new Map;for(let e of r.panels){let t=Se.get(e.id);t?e.lines&&m(e.lines[0],`panel id "${e.id}" is already used${t.lines?` on line ${t.lines[0]+1}`:` by an import`}: layout, edges and edits can't tell them apart, rename one`):Se.set(e.id,e)}for(let[e,t]of r.groups)r.nodes.has(e)&&m(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`);_n(r,e=>xn.get(e)?.options),t.chain||n(r.diagnostics,()=>Cn.forEach(e=>e(r)));for(let e of Object.keys(r.layout.nodes)){let t=C.get(e);t!==void 0&&!r.nodes.has(e)&&!r.groups.has(e)&&m(t,`layout: there is no node "${e}" (renamed or deleted?); remove this line${ln(e,[...r.nodes.keys()])}`)}return r}function sr(e,t,n){let r=e.findIndex(e=>e.value===`}`),i=e=>(n(t,`${e}: import { a, b as c, .style } from "./file.yu"`,`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 cr(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=new Set(e.panels.map(e=>e.id));if(t)for(let[a,l]of t){let t=a.replace(/^\./,``);if(e.sharedSettings?.includes(a)&&!e.nodes.has(a)&&!e.groups.has(a)){l===a?s.add(a):n(`a setting keeps its name: import { ${a} }`);continue}let u=a.startsWith(`.`)?t in e.classes:a.startsWith(`$`)?a.slice(1)in(e.vars??{}):e.nodes.has(t)||e.groups.has(t)||c.has(t)||t in(e.defs??{});!u&&a in(e.themes??{})||(u?i(a)?(s.add(a),l!==a&&o.set(a,l)):n(`"${a}" is not exported (exports: ${r.join(`, `)||`none`})`):n(`no "${a}" to import${r?.length?` (exports: ${r.join(`, `)})`:``}`))}else for(let e of r)s.add(e);let l=t=>{for(let n=t;n;n=e.groups.get(n)?.parent)if(s.has(n))return!0;return!1},u={settings:{},nodes:/* @__PURE__ */ new Map,edges:[],groups:/* @__PURE__ */ new Map,classes:a({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},d=e=>o.get(e)?.replace(/^\./,``)??e,f=e=>o.get(`.${e}`)?.slice(1)??e,p=/* @__PURE__ */ new Set;for(let t of e.groups.values())(s.has(t.id)||l(t.parent))&&(u.groups.set(d(t.id),{...t,id:d(t.id),parent:t.parent&&u.groups.has(d(t.parent))?d(t.parent):void 0,classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e)));let m=t=>s.has(t)||l(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(m(t.id)){let e=t.group&&u.groups.has(d(t.group))?d(t.group):void 0;u.nodes.set(d(t.id),{...t,id:d(t.id),group:e,classes:t.classes.map(f)}),t.classes.forEach(e=>p.add(e))}for(let t of e.edges)if(m(t.from)&&m(t.to)){let e=d(t.from)+`->`+d(t.to)+(t.key.match(/#\d+$/)?.[0]??``);u.edges.push({...t,key:e,from:d(t.from),to:d(t.to),classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e))}for(let t of e.panels)s.has(t.id)&&u.panels.push({...t,id:d(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(s.has(t))for(let e of n.body)for(let t of Ln(e).tokens)t.kind===`class`&&p.add(t.value);u.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||s.has(e));for(let t of u.sharedSettings)u.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(s.has(`.${t}`)||p.has(t))&&(u.classes[f(t)]=n);u.vars={};for(let[t,n]of Object.entries(e.vars??{}))s.has(`$${t}`)&&(u.vars[(o.get(`$${t}`)??`$${t}`).slice(1)]=n);u.defs={};for(let[t,n]of Object.entries(e.defs??{}))s.has(t)&&(u.defs[o.get(t)??t]=n);return u.themes=e.themes,u}function lr(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??=a({}))[n]??=r}function ur(e,t,n,r,i,a,o,s,c){let l=0,u=!1,d=(n=!1)=>{let a=[],d=!0;for(;l<e.length;){if(e[l].kind===`punct`&&e[l].value===`,`){l++,d=!0;continue}if(e[l].kind!==`ident`)break;if(!d){let n=a.pop(),r=[n];for(;e[l]?.kind===`ident`;)r.push(e[l++].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}d=!1;let f=e[l++].value;a.push(f);let p=l,m=!r.nodes.has(f),h=i(f);if(e[l]?.kind===`string`){let r=e[l++],i=r.value;n&&m&&l===e.length&&!u&&/^[a-z][a-z ]*$/.test(i)&&o(t,`"${i}" becomes the label of node "${f}". For an edge label write: ... -> ${f}: ${i}`),s(h,r,t,!0),u=!0}for(;e[l]?.kind===`class`;){let n=e[l++].value;c(n,t),h.classes.includes(n)||h.classes.push(n)}let g=!h.ref||h.implicit;e[l]?.kind===`props`?(zn(h,Bn(e[l],f,t,o),t),g&&(h.ref={line:t,props:[e[l].start,e[l].end],insertAt:e[l].start}),l++):l>p&&g&&(h.ref={line:t,insertAt:e[l-1].end}),l>p&&(h.implicit=!1),l>p&&g&&!h.labelRef&&(h.labelRef={line:t,at:e[p-1].end})}return a},f=d();if(!f.length){o(t,`Edge needs a source node`,`error`);return}let p=[];for(;l<e.length&&e[l].kind===`arrow`;){let n=e[l++].value,r=d(!0);if(!r.length){o(t,`Edge "${n}" needs a target node`,`error`);return}p.push({from:f,to:r,arrow:n}),f=r}let m,h=[],g={},_={line:t,insertAt:e[l-1].end,prefix:`:`},v={line:t,at:e[l-1].end,colon:!1};if(e[l]?.kind===`punct`&&e[l].value===`:`){_.insertAt=v.at=e[l].end,v.colon=void 0,_.prefix=void 0,l++;let r=l;for(;l<e.length&&e[l].kind!==`class`&&e[l].kind!==`props`;)l++;for(l>r&&(m=l-r===1&&e[r].kind===`string`?e[r].value:n.slice(e[r].start,e[l-1].end).trim(),_.insertAt=e[l-1].end,v.range=[e[r].start,e[l-1].end]);e[l]?.kind===`class`;)c(e[l].value,t),h.push(e[l].value),_.insertAt=e[l++].end;e[l]?.kind===`props`&&(g=q(e[l].value),_.props=[e[l].start,e[l].end],l++)}if(l<e.length){let n=e[l].kind===`string`?` (edge labels go after a colon: a -> b: "label")`:``;o(t,`Unexpected "${e[l].value}" in edge${n}`,`error`)}for(let e of p){let t=Yn(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:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(d)}}}let dr=(e,t)=>(e.layout.panels??={})[t]??={};function fr(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(!jn.has(e)||!jn.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)`);(dr(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)`);dr(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 pr(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function mr(e){let t=/* @__PURE__ */ new WeakMap;return(n,r)=>{let i=t.get(r);if(i&&i.data===n)return i.g;let a=e(n,r);return t.set(r,{data:n,g:a}),a}}function hr(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}}}let J={plugins:[],rows:[],frames:/* @__PURE__ */ new Map,decorations:[],panels:xn},gr=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)},_r=Symbol(`yuhwa.failedPanel`),vr=()=>{};function yr(e){let t=e.name,n=(e,n,r)=>i(t,e,n,r),r=(e,t,r)=>t&&n(e,t.bind(void 0),r),a=(e,t,r)=>t&&n(e,(e,...n)=>e===_r?r:t(e,...n),()=>r);return{rows:(e.rows??[]).map(e=>({...e,parse:n(`row "${e.kind}"`,e.parse.bind(e),()=>null),finish:r(`row "${e.kind}"`,e.finish?.bind(e),vr),measure:n(`row "${e.kind}"`,e.measure.bind(e),()=>({w:0,h:0})),render:n(`row "${e.kind}"`,e.render.bind(e),()=>``)})),frames:(e.frames??[]).map(e=>({...e,inset:n(`frame "${e.name}"`,e.inset.bind(e),()=>({top:0})),render:n(`frame "${e.name}"`,e.render.bind(e),()=>``)})),decorations:(e.decorations??[]).map(e=>({...e,measure:n(`decoration "${e.name}"`,e.measure.bind(e),()=>null),render:n(`decoration "${e.name}"`,e.render.bind(e),()=>``)})),panels:(e.panels??[]).map(e=>{let r=`${e.name} panel`;return{...e,parse(n,i,a){try{return e.parse(n,i,a)}catch(e){return a(-1,`plugin "${t}": ${r} failed to parse: ${e instanceof Error?e.message:String(e)}`,`error`),_r}},measure:a(`${r} measure`,e.measure.bind(e),{w:0,h:0}),render:a(`${r} render`,e.render.bind(e),``),handles:a(`${r} handles`,e.handles?.bind(e),[]),parts:a(`${r} parts`,e.parts?.bind(e),[]),editPart:e.editPart&&n(`${r} edit`,(t,n,r)=>r===_r?null:e.editPart(t,n,r),()=>null)}}),statements:(e.statements??[]).map(e=>({...e,parse(n,r,i){try{e.parse(n,r,i)}catch(n){i.warn(`plugin "${t}": ${e.keyword} failed: ${n instanceof Error?n.message:String(n)}`,`error`)}}})),shapes:(e.shapes??[]).map(e=>({...e,path:n(`shape "${e.name}"`,e.path.bind(e),e=>`M${e.x},${e.y}h${e.w}v${e.h}h${-e.w}Z`),size:e.size&&n(`shape "${e.name}"`,(t,n)=>e.size(t,n),(e,t)=>({w:e,h:t})),detail:e.detail&&n(`shape "${e.name}"`,t=>e.detail(t),()=>null)})),markers:(e.markers??[]).map(e=>({...e,render:n(`marker "${e.name}"`,e.render.bind(e),()=>``),inset:typeof e.inset==`function`?n(`marker "${e.name}"`,e.inset.bind(e),()=>0):e.inset})),transform:e.transform&&n(`transform`,t=>e.transform(t),vr),afterLayout:e.afterLayout&&n(`afterLayout`,(t,n)=>e.afterLayout(t,n),vr),postRender:e.postRender&&n(`postRender`,(t,n,r)=>e.postRender(t,n,r),e=>e)}}let br=/* @__PURE__ */ new Map;function xr(e,t,n){let r=`${e} ${t}`,i=br.get(r);i&&i!==n&&console.warn(`yuhwa: plugin "${n}" replaces ${e} "${t}" of plugin "${i}"`),br.set(r,n)}let Sr;function Cr(){let e=[yn].map(e=>[e,[...e]]),t=[xn,Sn,kt,At,J.frames].map(e=>[e,[...e]]),n=[Cn,jt,Mt,Xt,Zt,Qt,an,on,v,J.rows,J.decorations].map(e=>[e,[...e]]),r=Object.entries(en).map(([e,t])=>[e,t,[...t]]),i={..._};return()=>{for(let[t,n]of e){t.clear();for(let e of n)t.add(e)}for(let[e,n]of t){e.clear();for(let[t,r]of n)e.set(t,r)}for(let[e,t]of n)e.splice(0,e.length,...t);for(let e of Object.keys(en))delete en[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),en[e]=t;for(let e of Object.keys(_))delete _[e];Object.assign(_,i),br.clear()}}function wr(...e){Sr??=Cr();for(let t of e){if(J.plugins.some(e=>e.name===t.name))continue;J.plugins.push(t);let e=yr(t);for(let e of t.themes??[])y(e);for(let n of e.rows){xr(`row`,n.kind,t.name);let e=J.rows.findIndex(e=>e.kind===n.kind);e>=0?J.rows[e]=n:J.rows.push(n)}for(let n of e.frames)xr(`frame`,n.name,t.name),J.frames.set(n.name,n);for(let t of e.decorations){let e=J.decorations.findIndex(e=>e.name===t.name);e>=0?J.decorations[e]=t:J.decorations.push(t),yn.add(t.setting)}for(let n of e.panels)xr(`panel`,n.name,t.name),xn.set(n.name,n);for(let n of e.statements)xr(`statement`,n.keyword,t.name),Sn.set(n.keyword,n);for(let n of e.shapes)xr(`shape`,n.name,t.name),kt.set(n.name,n);for(let n of e.markers)xr(`marker`,n.name,t.name),At.set(n.name,n);gr(en.shape??=[],t.shapes?.map(e=>e.name)),gr(en.head??=[],t.markers?.map(e=>e.name)),en.tail!==en.head&&gr(en.tail??=[],t.markers?.map(e=>e.name)),e.transform&&Cn.push(e.transform),e.afterLayout&&jt.push(e.afterLayout),e.postRender&&Mt.push(e.postRender);for(let e of t.settings??[])yn.add(e);gr(Xt,t.props?.node),gr(Zt,t.props?.edge),gr(Qt,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))gr(en[e]??=[],n);gr(an,t.bools),gr(on,t.numbers)}J.frames.size&&gr(en.frame??=[],[...J.frames.keys()])}let Tr={name:`themes`,themes:[N(`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:f,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:e=>o[e]&&{fill:`#0f3460`,stroke:u(e,300),text:u(e,100)},groupTone:e=>o[e]&&{fill:`none`,stroke:u(e,400),text:u(e,200)},edgeTone:e=>u(e,300)},{name:`mono`,dark:!1,background:`#ffffff`,font:d,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:e=>o[e]&&{fill:u(e,100),stroke:`#18181b`,text:`#18181b`},groupTone:e=>o[e]&&{fill:u(e,50),stroke:`#a1a1aa`,text:`#52525b`},edgeTone:e=>u(e,700)},{name:`pastel`,dark:!1,background:`#fdfcff`,font:d,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:e=>o[e]&&{fill:u(e,100),stroke:u(e,100),text:u(e,900)},groupTone:e=>o[e]&&{fill:u(e,50),stroke:u(e,50),text:u(e,700)},edgeTone:e=>u(e,300)},{name:`terminal`,dark:!0,background:`#0c0c10`,font:f,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:e=>o[e]&&{fill:u(e,950),stroke:u(e,700),text:u(e,200)},groupTone:e=>o[e]&&{fill:u(e,950)+`66`,stroke:u(e,900),text:u(e,300)},edgeTone:e=>u(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:e=>o[e]&&{fill:u(e,100),stroke:u(e,400),text:u(e,900)},groupTone:e=>o[e]&&{fill:u(e,100)+`99`,stroke:u(e,300),text:u(e,800)},edgeTone:e=>u(e,600)},N(`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:d,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:e=>o[e]&&{fill:u(e,100),stroke:u(e,800),text:u(e,950)},groupTone:e=>o[e]&&{fill:u(e,50),stroke:u(e,800),text:u(e,900)},edgeTone:e=>u(e,700)},N(`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)`}),N(`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:d,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:e=>o[e]&&{fill:u(e,900)+`cc`,stroke:u(e,500),text:u(e,100)},groupTone:e=>o[e]&&{fill:u(e,950)+`80`,stroke:u(e,900),text:u(e,300)},edgeTone:e=>u(e,300)}]},Er=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function Dr(e){let t=1/0,n=-1/0;for(let r of e)r<t&&(t=r),r>n&&(n=r);return[t,n]}let Or=(e,t)=>V(e,t.theme,t.theme.accent),kr=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${oe}))?:\\s*(.*)$`)),Ar={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=kr(`bars`,e);return t?{kind:`bars`,values:Er(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(Dr(e.values)[1],0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=Or(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${B(t.x+n*r*.85)}" y="${B(a-c)}" width="${B(r*.55)}" height="${B(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},jr={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=kr(`spark`,e);return t?{kind:`spark`,values:Er(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){if(!e.values.length)return``;let r=e.values.length===1?[e.values[0],e.values[0]]:e.values,{fs:i}=n,[a,o]=Dr(r),s=o/2-a/2,c=t.y+i*.45,l=t.y+t.h-i*.45,u=e=>s?(e/2-a/2)/s:.5,d=r.map((e,n)=>[t.x+n/(r.length-1)*t.w,l-u(e)*(l-c)]),f=d.map(([e,t],n)=>`${n?`L`:`M`}${B(e)},${B(t)}`).join(``),p=Or(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${B(t.x+t.w)},${B(l)}L${B(t.x)},${B(l)}Z" fill="${p}" fill-opacity="0.14"/><path d="${f}" fill="none" stroke="${p}" stroke-width="1.75" stroke-linejoin="round" stroke-linecap="round"/><circle cx="${B(m)}" cy="${B(h)}" r="2.6" fill="${p}"/>`}},Mr={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=kr(`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:R(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:R(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:H(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=Or(e.color,n);return Me(e.label,t.x,s,r,a,o)+De(t.x+t.w,s,r,a.sub,z(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${B(t.x)}" y="${B(c)}" width="${B(t.w)}" height="${B(l)}" rx="${B(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${B(t.x)}" y="${B(c)}" width="${B(Math.max(l,t.w*e.ratio))}" height="${B(l)}" rx="${B(l/2)}" fill="${u}"/>`:``)}},Nr=1.75,Pr={name:`charts`,rows:[Ar,jr,Mr,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=kr(`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:R(t),label:R(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*Nr;return e.ws=e.items.map(e=>Math.max(H(e.value,i,n,r,700),H(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*Nr,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:Or(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${B(e)},${B(t.y+r*.3)}V${B(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(Me(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(Me(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},Fr=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function Ir(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())}let Lr=e=>e*1.8,Rr={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=Ir(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(R);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=>!Te(e[t])||Fr.test(Te(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=>H(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+Lr(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]-Ae(t):d;o.push(Me(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+Lr(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${B(t.x)},${B(e)}H${B(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},zr=[`#ff5f57`,`#febc2e`,`#28c840`],Br=e=>Math.round(e*2.3);function Vr(e,t,n,r,i){let a=Br(t),o=Math.min(n,a/2,e.w/2),s=`M${B(e.x)},${B(e.y+a)}V${B(e.y+o)}A${B(o)},${B(o)} 0 0 1 ${B(e.x+o)},${B(e.y)}H${B(e.x+e.w-o)}A${B(o)},${B(o)} 0 0 1 ${B(e.x+e.w)},${B(e.y+o)}V${B(e.y+a)}Z`,c=t*.3,l=zr.map((n,r)=>`<circle cx="${B(e.x+t+r*c*3.3)}" cy="${B(e.y+a/2)}" r="${B(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${B(e.x)},${B(e.y+a)}H${B(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}let Hr=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,Ur={name:`browser`,inset:e=>({top:Br(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=Br(a),s=Hr(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="${B(s)}" y="${B(u)}" width="${B(c-s)}" height="${B(l)}" rx="${B(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?De(s+a*.7,e.y+o/2,d,n.sub,z(r)):``):``;return`<g class="frame">${Vr(e,a,i,n.stroke,t.dark)}${f}</g>`}},Wr=(e,t)=>({name:e,inset:e=>({top:Br(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=Br(o),c=i?De(e.x+e.w/2,e.y+s/2,o*.78,r.sub,z(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${Vr(e,o,a,r.stroke,n.dark)}${c}</g>`}}),Gr={name:`frames`,frames:[Ur,Wr(`window`,``),Wr(`terminal`,`❯ `)],props:{node:[`frame`]}},Kr=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),qr=new Set(`mwMW@%`.split(``)),Jr=(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:Kr.has(t)?i+=.3:qr.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},Yr;function Xr(e){return(t,n,r,i)=>{if(Yr===void 0)try{Yr=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{Yr=null}if(!Yr)return Jr(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`:e;return Yr.font=`${r} ${n}px ${a}`,Yr.measureText(t).width}}let Zr=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),Qr=/* @__PURE__ */ new Map,$r=(e,t,n)=>`${t}|${n}|${e}`;function ei(e,t,n,r){return e.map(e=>H(R(e),t,n,r))}let ti={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=Zr(e);if(!r.length)return null;let i=t.fontSize*.82,a=ei(r,i,t.mono,n);Qr.size>64&&Qr.clear(),Qr.set($r(e,i,t.mono),a);let o=a.reduce((e,t)=>e+t,0)+i*3*(r.length-1);return{bottom:i*2.8,w:o}},render(e,t,n,{pad:r}){let i=Zr(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=L(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${B(c)},${B(t.y)}H${B(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=Qr.get($r(e,a,n.mono))??ei(i,a,n.mono,Jr),f=i.length,p=f>1?(l-c-d.reduce((e,t)=>e+t,0))/(f-1):0,m=c;return i.forEach((e,t)=>{u.push(`<text x="${B(m)}" y="${B(o)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(R(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},ni=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function ri(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return ni.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}})}let ii=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 ai(e,t,n){let{fs:r,sw:i,gap:a}=ii(t);return e.map(e=>i+a+H(R(e.label),r,t.mono,n))}function oi(e,t,n,r,i){let{sw:a,sh:o}=ii(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="${B(o*3)} ${B(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${B(o)} ${B(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${B(t)},${B(n)}H${B(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${B(o)}"${s} fill="none"/>`+(c?`<path d="M${B(u)},${B(n)}L${B(u-l)},${B(n-l*.5)}L${B(u-l)},${B(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${B(t)},${B(n)}L${B(t+l)},${B(n-l*.5)}L${B(t+l)},${B(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=Be(i,t),a=He(i,t,n,r),o=It(n.shape??i.settings.shape);return`<path d="${zt(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??I(e.key,r,400)??r.node.fill,u=c?.stroke??I(e.key,r,600)??r.node.stroke;return`<rect x="${B(s.x)}" y="${B(s.y)}" width="${B(s.w)}" height="${B(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function si(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}let ci={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=ri(e);if(!n.length)return null;let{fs:r,space:i}=ii(t),a=ai(n,t,Jr),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=si(a,760,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,760)}},render(e,t,n,{pad:r,d:i}){let a=ri(e),{fs:o,gap:s,space:c,sw:l}=ii(n),u=ai(a,n,Jr),d=L(n),f=[];return si(u,Math.min(760,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(oi(e,m,h,n,i)),e.label&&f.push(`<text x="${B(m+l+s)}" y="${B(h)}" dominant-baseline="central" font-size="${B(o)}" xml:space="preserve">${U(R(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},li=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,ui=/^(?:m|note|d)\d+$/,di=new RegExp(String.raw`^(participant|actor)\s+(${li})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?$`,`u`),fi=new RegExp(String.raw`^(${li})\s*(-->|->|\.\.>|=>)\s*(${li})\s*(?::\s*(.*))?$`,`u`),pi=new RegExp(String.raw`^(${li}\s*(?:-->|->|\.\.>|=>)\s*${li})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),mi=new RegExp(String.raw`^(participant|actor)\s+(${li}(?:\s*,\s*${li})+)$`,`u`),hi=new RegExp(String.raw`^note\s+(${li}(?:\s*,\s*${li})*)\s*:\s*(.*)$`,`u`),gi=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,_i=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],vi=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>_i.includes(e))&&(!e.color||F(e.color))},yi=e=>Wn(e,vi),bi={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function xi(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,key:e,label:e,actor:!1,first:a}),t},s=0;e.forEach((e,t)=>{a=t;let r=e.trim();if(!r)return;let c;if(c=r.match(di)){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]&&q(c[4]).color;t&&(e.tone=t)}else if(c=r.match(mi))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(hi)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=yi(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(fi)){o(c[1]),o(c[3]);let[e,t]=yi(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:bi[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(gi))?i.push({kind:`divider`,text:c[1]}):(c=r.match(pi))?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 ---")`)});let c=new Set(r.map(e=>e.id));for(let e of r){if(!ui.test(e.id))continue;let t=`p-${e.id}`;for(;c.has(t);)t=`p-${t}`;c.add(t),e.key=t}return{parts:r,steps:i}}function Si(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}`)}let Ci=mr(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=>H(R(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].key))});let g=[l[0]/2];u.forEach((e,t)=>g.push(g[t]+e));let _=e=>{let t=g[Math.min(...e.over.map(d))];return e.over.length>1?t-20:Math.min(t-(s(e.text)+24)/2,t-20)},v=0;for(let t of e.steps)t.kind===`note`&&(v=Math.max(v,-_(t)));for(let e=0;e<g.length;e++)g[e]+=v;let y=e.parts.length?g[g.length-1]+l[l.length-1]/2+Math.max(0,p):0;for(let t of e.steps)if(t.kind===`note`){let e=t.over.map(d),n=_(t),r=s(t.text)+24;y=Math.max(y,n+r,t.over.length>1?g[Math.max(...e)]+20:0)}let b=e=>e.kind===`msg`?e.from===e.to?a*3.6:a*2.6:e.kind===`note`?a*2.6:a*2.4,x=Si(e),S=e.steps.map((e,t)=>Math.max(-b(e)*.3,h(x[t]))),C=c*2+a*1.4+e.steps.reduce((e,t,n)=>e+b(t)+S[n],0);return{fs:a,boxH:c,widths:l,xs:g,w:y,h:C,rowH:b,extra:S,parts:x,idx:d,num:f,textW:s,noteX:_}});function wi(e,t){let n=Ve(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function Ti(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=Ci(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=L(r),d=n.props,f=I(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=wi(Pe(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${B(c(t))},${B(h+o)}V${B(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="${B(c(a)-l/2)}" y="${B(t)}" width="${B(l)}" height="${B(o)}" rx="${B(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${B(r.strokeWidth)}"/><text x="${B(c(a))}" y="${B(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${B(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${z(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=Pe(n,`style`)??(o.line===`thick`?`solid`:o.line),d=Ne(n.width,o.line===`thick`||A(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=wi(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=R(i.num(o)+o.text),g=o.tone?V(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${B(t)},${B(n)}H${B(t+26-8)}Q${B(t+26)},${B(n)} ${B(t+26)},${B(n+8)}V${B(i-8)}Q${B(t+26)},${B(i)} ${B(t+26-8)},${B(i)}H${B(t+2)}" fill="none" stroke="${g}" stroke-width="${B(d)}"${f}/>`),m.push(Nt({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${B(t+34)}" y="${B((n+i)/2)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${B(c(e))},${B(s)}H${B(c(t)-n*2)}" stroke="${g}" stroke-width="${B(d)}"${f}/>`),m.push(Nt({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="${B((c(e)+c(t))/2)}" y="${B(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" xml:space="preserve">${U(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="${B(l)}" y="${B(p)}" width="${B(u-l)}" height="${B(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${B((l+u)/2)}" y="${B(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" xml:space="preserve">${U(R(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${B(t.x)},${B(n)}H${B(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${B(c-s/2)}" y="${B(n-a*.85)}" width="${B(s)}" height="${B(a*1.7)}" rx="${B(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${B(c)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.92)}" font-weight="600" fill="${r.node.sub}">${z(o.text)}</text>`))}v+=e}return m.join(``)}function Ei(e,t,n){if(!e.parts.length)return[];let r=Ci(e,n),i=e=>t.x+r.xs[e],a=e.parts.slice(1).map((e,n)=>({part:e.key,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:t.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}let Di={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 (`p-<id>` when the id looks like a row) 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:xi,measure(e,t){let n=Ci(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:Ti,handles:Ei,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=Si(e);return[...e.parts.map(e=>({id:e.key,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:hr((e,t,n,r)=>{let i=[...e],a=r.parts.find(e=>e.key===t);if(a){if(a.decl!==void 0)return i[a.decl]=Gn(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${Jn({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=Si(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=yi(e[s.at]),u=c;delete l.color;let d=Jn(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})}]};function Oi(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}let ki=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,Ai=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function ji(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]=Wn(i,Kn),c=o.match(ki);c?r.push({when:c[1].trim(),tone:s.color??q(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function Mi(e){let t=/* @__PURE__ */ 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 Ni(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#|[-*]\s)/.test(r)&&ki.test(Wn(r,Kn)[0])&&t.push(n)}),t}let Pi=mr(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)=>H(R(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>Oi(e.details.map(e=>s(e,a*.92)),s(e.title,a,600))),u=e.map(e=>1+e.details.length),d=Mi(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=Oi(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+Oi(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+Oi(u,1)*a*1.45}});function Fi(e,t,n){if(!e.length)return``;let r=n.theme,i=Pi(e,n),{fs:a}=i,o=L(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=V(n.tone,r,r.accent);return`<circle cx="${B(e)}" cy="${B(t)}" r="${B(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${B(e)}" cy="${B(t)}" r="${B(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${B(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${U(R(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${B(n)},${B(t.y+a*.5)}V${B(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="${B(n-16)}" y="${B(s)}" dominant-baseline="central" text-anchor="end" font-size="${B(a*.9)}" font-weight="600" fill="${V(e.tone,r,r.node.sub)}">${z(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${B(t.x)},${B(d)}H${B(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="${B(o)}" y="${B(t.y+a*.5)}" dominant-baseline="central" font-size="${B(a*.9)}" font-weight="600" fill="${V(e.tone,r,r.node.sub)}">${z(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(``)}let Ii={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:ji,measure(e,t){if(!e.length)return{w:0,h:0};let n=Pi(e,t);return{w:n.w,h:n.h}},render:Fi,parts:e=>Mi(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:hr((e,t,n,r)=>{let i=Ni(e)[Mi(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=qn(e[i],Ai,`color`,n,Kn),a}),handles(e,t,n){if(!e.length)return[];let r=Pi(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}`})}}]},Li=[`bar`,`column`,`line`,`pie`,`donut`],Ri=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],zi=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,Bi=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/;function Vi(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}function Hi(e,t,n){let r=t.type??`bar`;Li.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${Li.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=Wn(r,Kn),s=a.match(zi),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=1e300)?n(t,`chart: "${s[3].slice(0,24)}…" is too large a number`):s?i.push({label:s[1].trim().replace(/^"(.*)"$/,`$1`),tone:o.color??q(s[2]).color,value:c}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:Li.includes(r)?r:`bar`,items:i}}let Ui=(e,t=``)=>`${Math.abs(e)<1e15?Math.round(e*100)/100:e}${t}`;function Wi(e,t,n,r){return e.tone?V(e.tone,n.theme,n.theme.accent):r?u(Ri[t%Ri.length],n.theme.dark?400:500):n.theme.accent}let Gi=mr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=Vi(e.items.map(e=>r(e.label,a,400,n.mono)),0),c=Vi(e.items.map(e=>r(Ui(e.value,o),a,600,n.mono)),0),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-1)*r+a*1.4}}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 Ki(e,t,n,r,i,a){let o=(n,r)=>`${B(e+n*Math.sin(r))},${B(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return Ki(e,t,n,r,o,a)+Ki(e,t,n,o,i,a)}return a?`M${o(n,r)}A${B(n)},${B(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${B(a)},${B(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${B(e)},${B(t)}L${o(n,r)}A${B(n)},${B(n)} 0 ${s} 1 ${o(n,i)}Z`}function qi(e,t,n){if(!e.items.length)return``;let r=n.theme,i=Gi(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${B(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${z(n)}</text>`,l=Vi(e.items.map(e=>e.value),0)||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="${Ki(l,u,i.r,p,a,d)}" fill="${Wi(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,Ui(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="${B(m)}" y="${B(g-a*.45)}" width="${B(a*.9)}" height="${B(a*.9)}" rx="2.5" fill="${Wi(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,Ui(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="${B(u)}" y="${B(p-a*.55)}" width="${B(d)}" height="${B(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${B(u)}" y="${B(p-a*.55)}" width="${B(m)}" height="${B(a*1.1)}" rx="3" fill="${Wi(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,Ui(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${B(t.x)},${B(n)}H${B(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="${B(d(i)-t/2)}" y="${B(l)}" width="${B(t)}" height="${B(Math.max(2,u-l))}" rx="3" fill="${Wi(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,Ui(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${B(d(t))},${B(f(e.value))}`);s.push(`<path d="M${B(d(0))},${B(u)}L${t.join(`L`)}L${B(d(e.items.length-1))},${B(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=Wi(e,t,n,!1);s.push(`<circle cx="${B(d(t))}" cy="${B(f(e.value))}" r="${B(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,Ui(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${B(t.x)},${B(u)}H${B(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(``)}let Ji={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:Hi,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=Gi(e,t);return{w:n.w,h:n.h}},render:qi,options:{type:[...Li],unit:`text`},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:hr((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim();return!/^(\/\/|#)/.test(n)&&zi.test(Wn(n,Kn)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=qn(e[i],Bi,`color`,n,Kn),a}),handles(e,t,n){if(!e.items.length)return[];let r=Gi(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},Yi=[`normal`,`highlight`,`reverse`],Xi=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Zi=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,Qi=String.raw`(?:\s*\[([^\]]*)\])?`,$i=new RegExp(String.raw`^commit(?:\s+(.*?))?${Qi}$`,`u`),ea=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${Zi})(?:\s+from\s+(\S+))?${Qi}$`,`u`),ta=new RegExp(String.raw`^(?:checkout|switch)\s+(${Zi})$`,`u`),na=new RegExp(String.raw`^merge\s+(${Zi})(?:\s+(.*?))?${Qi}$`,`u`),ra=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${Qi}$`,`u`),ia=/^tag\s+(\S+)$/;function aa(e){let t=q(e??``);for(let e of Yi)t[e]===`true`&&(t.type=e,delete t[e]);return t}function oa(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&&!Yi.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${Yi.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(ea)){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=aa(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(ta)){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(na)){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:ar(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},aa(u[3]),t)}else if(u=l.match(ra)){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:ar(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},aa(u[3]),t)}else(u=l.match(ia))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match($i))?c({msg:ar(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},aa(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function sa(e,t,n){let r=e.branches[t]?.tone;return r?V(r,n.theme,n.theme.accent):u(Xi[t%Xi.length],n.theme.dark?400:500)}function ca(e){let t=new Set(e.branches.map(e=>e.name));return e.commits.map(e=>{let n=e.id??e.tags[0];return!n||t.has(n)||/\s/.test(n)?``:(t.add(n),n)}).map((e,n)=>{if(e)return e;e=`c${n+1}`;for(let r=2;t.has(e);r++)e=`c${n+1}-${r}`;return t.add(e),e})}let la=/* @__PURE__ */ new WeakMap,ua=mr(function(e,t){let n=JSON.stringify([t.fs,t.props,t.offsets]),r=la.get(e);if(r&&r.key===n&&r.theme===t.theme&&r.measure===t.measure)return r.G;let i=da(e,t);return la.set(e,{key:n,theme:t.theme,measure:t.measure,G:i}),i});function da(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=ca(e),l=e=>s[e]?.x??0,u=e=>H(R(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=/* @__PURE__ */ 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:/* @__PURE__ */ new Map,labelW:x,top:E,pos:D,w:C,h:E+y+a*2}}let fa=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function pa(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${B(h.x)},${B(h.y)}L${B(g.x)},${B(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=fa((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${B(h.x)},${B(h.y)}V${B(t-e)}C${B(h.x)},${B(t)} ${B(g.x)},${B(t)} ${B(g.x)},${B(t+e)}V${B(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=m?g.x-b(f,!y)-r*.7:h.x+b(p,y)+r*.7,C=fa(S+v,h.x+x,g.x-x);d.push({i:f,k:m,part:_,handle:{x:C,y:(h.y+g.y)/2},d:`M${B(h.x)},${B(h.y)}H${B(C-x)}C${B(C)},${B(h.y)} ${B(C)},${B(g.y)} ${B(C+x)},${B(g.y)}H${B(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${B(i.x)},${B(i.y)}Q${B(e)},${B(n)} ${B(c.x)},${B(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${B(i.x)},${B(i.y)}C${B(p)},${B(i.y+u.y)} ${B(p)},${B(c.y+u.y)} ${B(c.x)},${B(c.y)}`})}),{lanes:u,bends:d,picks:f}}function ma(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=ua(e,n),{fs:a,r:o}=i,s=n.props.color&&r.groupTone(n.props.color)?.fill||[r.group.fill,r.background,r.node.fill].find(e=>e&&e!==`none`),c=L(r),l=[],u=i.pos.map(e=>({x:t.x+e.x,y:t.y+e.y})),d=(e,t,n,r,o,c)=>{let l=i.pillW(n),u=c===`middle`?e-l/2:e,d=a*1.3;return`<rect x="${B(u)}" y="${B(t-d/2)}" width="${B(l)}" height="${B(d)}" rx="${B(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${B(u+l/2)}" y="${B(t)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.82)}" font-weight="600" fill="${o?s:r}">${z(n)}</text>`};if(!i.vertical)for(let r of i.used){let o=t.y+i.top+i.lanePos[i.slot.get(r.lane)];l.push(`<text x="${B(t.x)}" y="${B(o)}" dominant-baseline="central" font-size="${B(a)}" font-weight="600" fill="${sa(e,r.lane,n)}">${z(r.label??r.name)}</text>`)}let p=Math.max(2,r.edgeWidth*1.4),m=pa(e,i,t),h=(t,r)=>sa(e,r?e.commits[e.commits[t].parents[r]].lane:e.commits[t].lane,n);for(let t of m.picks)l.push(`<path d="${t.d}" fill="none" stroke="${sa(e,e.commits[t.i].lane,n)}" stroke-width="${B(p*.7)}" stroke-dasharray="${B(p*1.6)} ${B(p*1.6)}" opacity="0.8"/>`);for(let e of[...m.bends,...m.lanes])l.push(`<path d="${e.d}" fill="none" stroke="${h(e.i,e.k)}" stroke-width="${B(p)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((m,h)=>{let{x:g,y:_}=u[h],v=m.tone?V(m.tone,r,sa(e,m.lane,n)):sa(e,m.lane,n);if(m.type===`highlight`){let e=o*1.1;l.push(`<rect x="${B(g-e)}" y="${B(_-e)}" width="${B(e*2)}" height="${B(e*2)}" rx="${B(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${B(p)}"/>`)}else if(m.type===`reverse`){let e=o*.55;l.push(`<circle cx="${B(g)}" cy="${B(_)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(p)}"/><path d="M${B(g-e)},${B(_-e)}L${B(g+e)},${B(_+e)}M${B(g+e)},${B(_-e)}L${B(g-e)},${B(_+e)}" stroke="${v}" stroke-width="${B(p*.8)}" stroke-linecap="round"/>`)}else m.merge?l.push(`<circle cx="${B(g)}" cy="${B(_)}" r="${B(o*1.05)}" fill="${v}"/><circle cx="${B(g)}" cy="${B(_)}" r="${B(o*.4)}" fill="${s}"/>`):m.pick===void 0?l.push(`<circle cx="${B(g)}" cy="${B(_)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(p)}"/>`):l.push(`<circle cx="${B(g)}" cy="${B(_)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(p)}" stroke-dasharray="${B(p*1.2)} ${B(p)}"/>`);if(i.vertical){let o=t.x+i.textX;m.id&&(l.push(`<text x="${B(o)}" y="${B(_)}" dominant-baseline="central" font-size="${B(a)}" font-family="${z(f)}" fill="${r.node.sub}">${z(m.id)}</text>`),o+=n.measure(m.id,a,400,!0)+a*.6);for(let t of i.heads.get(h)??[]){let r=t.label??t.name;l.push(d(o,_,r,sa(e,t.lane,n),!1,`start`)),o+=i.pillW(r)+a*.4}for(let e of m.tags)l.push(d(o,_,e,v,!0,`start`)),o+=i.pillW(e)+a*.4;m.msg&&l.push(`<text x="${B(o)}" y="${B(_)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(R(m.msg),c,r,m.merge)}</text>`)}else m.tags.forEach((e,t)=>l.push(d(g,_-a*1.45-t*a*1.5,e,v,!0,`middle`))),m.msg&&l.push(`<text x="${B(g)}" y="${B(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${U(R(m.msg),c,r,m.merge)}</text>`)}),l.join(``)}let ha={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:oa,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})),...ca(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:hr((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[ca(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=Gn(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=ua(e,t);return{w:n.w,h:n.h}},render:ma,handles(e,t,n){if(!e.commits.length)return[];let r=ua(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=pa(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`}))]}}]},ga=[`box`,`pill`,`plain`,`circle`],_a=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],va=/^[-*+]\s+/,ya=e=>Le(e)!==void 0,ba={color:F,shape:()=>!0,text:F,"font-size":ya,"font-weight":ya},xa=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>ba[t]?.(e[t]))},Sa=e=>Wn(e,xa);function Ca(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,l]=Sa(o.replace(va,``));l.shape&&!ga.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${ga.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:Le(l[`font-size`]),weight:Le(l[`font-weight`]),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 wa(e){let t=[],n=[e];for(;n.length;){let e=n.pop();t.push(e);for(let t=e.children.length-1;t>=0;t--)n.push(e.children[t])}return t}let Ta=e=>e.reduce((e,t)=>Math.min(e,t),1/0),Ea=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function Da(e){let t=/* @__PURE__ */ 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}`)}let Oa=[`both`,`vertical`,`right`,`left`,`down`,`up`],ka=mr(function(e,t){let{theme:n,measure:r,props:i}=t,a=Le(i[`font-size`])??t.fs*.9,o=Oa.includes(i.layout)?i.layout:`both`,s=o===`down`||o===`up`||o===`vertical`,c=i.colors===`mono`,l=wa(e),u=Da(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=/* @__PURE__ */ new Map,p=(e,t,i,o)=>{let s=ga.includes(e.shape??``)?e.shape:t===0?`pill`:t===1?`box`:`plain`,c=e.size??(t===0?a*1.2:t===1?a:a*.92),l=e.weight??(t===0?700:t===1?600:400),u=H(R(e.text),c,n.mono,r,l),p=s===`plain`?{x:a*.15,y:a*.3}:{x:c*(t?.8:1.1),y:c*.5},m=u+p.x*2,h=c*1.25+p.y*2;s===`circle`&&(m=h=Math.max(m,h));let g={node:e,part:d.get(e),depth:t,side:0,color:e.tone??i,shape:s,font:c,weight:l,x:0,y:0,w:m,h,parent:o};return f.set(e,g),g};p(e,0,e.tone);for(let e of l){let t=f.get(e);e.children.forEach((e,n)=>p(e,t.depth+1,e.tone??(t.depth===0?c?void 0:_a[n%_a.length]:t.color),t))}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,_=/* @__PURE__ */ new Map,v=(e,t)=>{let n=f.get(e),r=0;return t.forEach((e,t)=>{r+=_.get(e)+(t?m(n.depth):0)+h(e,t,n.depth)}),Math.max(g(n),r)};for(let e=l.length-1;e>=0;e--)_.set(l[e],v(l[e],l[e].children));let y=e.children,b=y,x=[];if((o===`both`||o===`vertical`)&&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=o===`left`||o===`up`||o===`vertical`?-1:1,C=e=>s?a*1.9:e===0?a*2.6:a*1.7,w=[],T=(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=n,s?(a.x=i+o/2-a.w/2,a.y=n>0?e.y+e.h+C(e.depth):e.y-C(e.depth)-a.h):(a.y=i+o/2-a.h/2,a.x=n>0?e.x+e.w+C(e.depth):e.x-C(e.depth)-a.w),i+=o,w.push([a,t.children,n])})},E=f.get(e);for(w.push([E,b,S],[E,x,-S]);w.length;)T(...w.pop());let D=l.map(e=>f.get(e)),O=Ta(D.map(e=>e.x)),k=Ta(D.map(e=>e.y));for(let e of D)e.x-=O,e.y-=k;return{all:D,vert:s,w:Ea(D.map(e=>e.x+e.w)),h:Ea(D.map(e=>e.y+e.h))}}),Aa=(e,t)=>t?V(t,e,e.accent):e.accent;function ja(e,t,n){if(!e)return``;let r=n.theme,i=ka(e,n),a=[],o=[],s=e=>t.x+e,c=e=>t.y+e,l=(e,t)=>i.vert?[e.x+e.w/2,t>0?e.y+e.h:e.y]:[t>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=Aa(r,e.color);if(e.parent){let[n,r]=l(e.parent,e.side),[o,u]=l(e,-e.side),d=Math.max(1.4,3.6-e.depth*.7),f=i.vert?`M${B(s(n))},${B(c(r))}C${B(s(n))},${B(c((r+u)/2))} ${B(s(o))},${B(c((r+u)/2))} ${B(s(o))},${B(c(u))}`:`M${B(s(n))},${B(c(r))}C${B(s((n+o)/2))},${B(c(r))} ${B(s((n+o)/2))},${B(c(u))} ${B(s(o))},${B(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${B(d)}" 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=I(e.node.ink,r,r.dark?100:800)??(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${B(m)},${B(h+e.h)}H${B(m+e.w)}" stroke="${t}" stroke-width="${B(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="${B(m)}" y="${B(h)}" width="${B(e.w)}" height="${B(e.h)}" rx="${B(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="${B(m+e.w/2)}" y="${B(g)}" dominant-baseline="central" text-anchor="middle" font-size="${B(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${U(R(e.node.text),L(r,p,f),r)}</text>`)}return a.join(``)+o.join(``)}let Ma={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, `[text: red, font-size: 18, font-weight: 700]` styles its text.",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:Oa,colors:[`branches`,`mono`]},parse:Ca,measure(e,t){if(!e)return{w:0,h:0};let n=ka(e,t);return{w:n.w,h:n.h}},render:ja,parts(e){if(!e)return[];let t=wa(e),n=/* @__PURE__ */ new Map([[e,0]]);for(let e of t)for(let t of e.children)n.set(t,n.get(e)+1);return Da(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:hr((e,t,n,r)=>{if(!r)return null;let i=wa(r),a=i[Da(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=Sa(e[a.line]),u=Jn(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=ka(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.vert?e.x:e.side<0?e.x+e.w:e.x),y:t.y+e.y+e.h/2,axis:r.vert?`x`:`y`,title:`move ${e.node.text}`})}return i}}]},Y=864e5,Na=2e3,Pa=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Fa=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,Ia=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,La=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function Ra(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=/* @__PURE__ */ new Date(0);return s.setUTCFullYear(+n,r-1,+i),s.setUTCHours(+a,+o,0,0),s.getUTCFullYear()===+n&&s.getUTCMonth()===r-1&&s.getUTCDate()===+i?s.getTime():NaN}function za(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:Y,w:7*Y}[t[2].toLowerCase()]:NaN}function Ba(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s)return;let c=s.match(La);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?q(t[2]).color:void 0);return}let[l,u]=Wn(s),d=l.match(Fa);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={...q(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(Ra(x))?x&&Number.isNaN(za(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=Ra(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=za(S),Number.isNaN(v.len)&&(v.endDate=Ra(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?l.reduce((e,t)=>Math.min(e,t)):Date.UTC(2025,0,1),d=e=>{let t=i[e];return t.after.length?t.after:Number.isNaN(t.date)&&e>0?[e-1]:[]},f=(e,t)=>{let a=r[e],o=i[e],s=o.date;return o.after.length?s=t.length?t.reduce((e,t)=>Math.max(e,t)):u:Number.isNaN(s)&&(e>0?s=t[0]:(n(o.line,`gantt: the first task needs a start date`),s=u)),a.start=s,a.end=a.milestone?s:Number.isNaN(o.len)?Number.isNaN(o.endDate)?s+Y:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=864e13||(n(o.line,`gantt: task "${a.id}" ends past the last date a chart can show`),a.end=s),c[e]=2,a.end},p=e=>{if(c[e]!==0)return;c[e]=1;let t=[{i:e,deps:d(e),k:0,ends:[]}];for(;t.length;){let e=t[t.length-1];if(e.k<e.deps.length){let a=e.deps[e.k++],o=typeof a==`number`?a:s.get(a);o===void 0?n(i[e.i].line,`gantt: "after ${a}": no task "${a}"`):c[o]===2?e.ends.push(r[o].end):c[o]===1?(n(i[o].line,`gantt: "${r[o].id}" depends on itself through "after"`),e.ends.push(u)):(c[o]=1,t.push({i:o,deps:d(o),k:0,ends:[]}));continue}t.pop();let a=f(e.i,e.ends);t.length&&t[t.length-1].ends.push(a)}};r.forEach((e,t)=>p(t));let m=r.length?1/0:0,h=r.length?-1/0:0;for(let e of r)m=Math.min(m,e.start),h=Math.max(h,e.end);return{tasks:r,sections:a,sectionTones:o,min:m,max:h}}function Va(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!La.test(r)&&Fa.test(Wn(r)[0])&&t.push(n)}),t}function Ha(e){let t=w(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`}let Ua=e=>{let t=new Date(e);return`${Pa[t.getUTCMonth()]} ${t.getUTCDate()}`},Wa=e=>{let t=e/Y;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 Ga(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/Y)*Y;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=Y;for(;o<=t&&i.length<Na&&Number.isFinite(new Date(o).getTime());o+=a*Y)i.push({t:o,label:Ua(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(!Number.isFinite(e)||e>t||i.length>=Na)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${Pa[c]} ${s}`:Pa[c]}),l=!1,c+=a}return i}return i}let Ka={compact:1.6,normal:2.1,loose:2.7},qa=mr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(Ka[i.density??``]??Ka.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>H(R(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/Y)*Y,_=Math.max(g+Y,Math.ceil(e.max/Y)*Y),v=(_-g)/Y,y={day:a*2.4,week:a*.8,month:a*.22}[i.scale??``],b=Math.min(y??Math.min(a*3,Math.max(a*.35,a*38/v)),a*1e3/v),x=e=>h+(e-g)/Y*b,S=v*b,C=[],w=c,T=-1;for(e.tasks.forEach((e,n)=>{for(;T<e.section;)T++,C.push({y:w,section:T}),w+=s;w+=Math.max(-o*.4,t.offsets[e.id]?.x??0),C.push({y:w,task:n}),w+=o});T<e.sections.length-1;)C.push({y:w,section:++T}),w+=s;let E=Math.max(a*1.25,o*.62),D=Math.min(E,a*1.3)*.5,O=a*.5,k=h+S;return{fs:a,rowH:o,secH:s,axisH:c,labelW:h,min:g,max:_,dayW:b,x,plotW:S,rows:C,barH:E,ms:D,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?`${Ua(e.start)} – ${Ua(e.end)}`:e.milestone?Ua(e.start):Wa(e.end-e.start),t].filter(Boolean).join(` · `),r=x(e.start),o=e.milestone?r+D:x(e.end),s=e.milestone||u?0:o-r-O*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+O,s:g,kind:`label`,w:_}),n&&f(n)<=c-_-O?m.push({x:o-O,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+O,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&&(k=Math.max(k,v-a*.7)),{inner:m,after:y}}),name:p,w:k,h:w}});function Ja(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${B(n[0][0])},${B(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${B(u[0])},${B(u[1])}Q${B(a[0])},${B(a[1])} ${B(d[0])},${B(d[1])}`}let i=n[n.length-1];return`${r}L${B(i[0])},${B(i[1])}`}function Ya(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=qa(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f=L(r),p=(e,t,n,i,a,s=!1)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${B(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${U(R(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${B(o*.82)}" font-weight="500" fill="${r}">${z(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/Y<=3660)for(let e=a.min;e<a.max;e+=Y){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${B(c(e))}" y="${B(t.y+a.axisH*.8)}" width="${B(a.dayW)}" height="${B(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/Y)*Y:Ra(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${Ua(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 Ga(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${B(s)},${B(t.y+a.axisH*.75)}V${B(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${B(p)}" y="${B(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${B(o*.82)}" fill="${r.node.sub}">${z(e.label)}</text>`)}d.push(`<path d="M${B(t.x+a.labelW)},${B(t.y+a.axisH*.75)}H${B(t.x+a.labelW+a.plotW)}" stroke="${u}" stroke-width="1.5"/>`);let x=/* @__PURE__ */ 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="${B(t.x-o*.4)}" y="${B(t.y+n.y)}" width="${B(T+o*.4)}" height="${B(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?V(l,r,r.node.sub):r.node.sub;d.push(`<path d="M${B(t.x)},${B(t.y+n.y+1)}H${B(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${B(e)},${B(s+n*1.6)}V${B(s-n/2)}H${B(t)}V${B(s+n*1.6)}" fill="none" stroke="${f}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${B(e)}" y="${B(s-n/2)}" width="${B(t-e)}" height="${B(n)}" fill="${f}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${B(c(h))},${B(t.y+a.axisH*.35)}V${B(l)}" stroke="${V(`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${B(g)},${B(_)}C${B(g+e)},${B(_)} ${B(b-e)},${B(y)} ${B(b)},${B(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=Ja([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=Ja([[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="${B(l)}" stroke-linejoin="round"/>`,Nt({x:v,y},0,`arrow`,s,l,u))}})}let E=i.bars===`solid`||i.bars===`outline`||i.bars===`thin`?i.bars:`soft`,D=/* @__PURE__ */ new Map,O=e=>{let r=`${e}|${E}`,i=D.get(r);if(!i){i=`${n.idPrefix??`mg`}-hatch-${Math.round(t.x)}-${Math.round(t.y)}-${D.size}`,D.set(r,i);let a=E===`solid`?Ha(e):e;d.push(`<defs><pattern id="${i}" patternUnits="userSpaceOnUse" width="7" height="7" patternTransform="rotate(45)"><rect width="3" height="7" fill="${a}" opacity="${E===`solid`?.28:.22}"/></pattern></defs>`)}return i};if(e.tasks.forEach((e,n)=>{let s=C(n),l=w(e),u=l?r.tone(l):void 0,f=V(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${B(t)},${B(s-a.ms)}L${B(t+a.ms)},${B(s)}L${B(t)},${B(s+a.ms)}L${B(t-a.ms)},${B(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?V(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${B(v)}" y="${B(x)}" width="${B(e)}" height="${B(b)}" rx="${B(S)}" ${t}${h}/>`,A=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,j=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,ee=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(k(y,`fill="${j}"${ee}${A?` stroke="${T}" stroke-width="${A}"`:``}`));let M=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;M&&d.push(k(M,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-M>2&&d.push(`<rect x="${B(v+M)}" y="${B(x)}" width="${B(y-M)}" height="${B(b)}" rx="${B(S)}" fill="url(#${O(f)})"/>`);for(let e of g){let n=t.x+e.x+(e.end?0:e.w),i=E===`solid`&&(!D||n<=v+M-o*.2)?Ha(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=V(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${B(b)}" y="${B(n-o*.55)}" width="${B(v)}" height="${B(o*1.1)}" rx="${B(o*.55)}" fill="${e}"/>`,`<text x="${B(b+v/2)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(o*.72)}" font-weight="650" fill="${Ha(e)}">${z(_)}</text>`)}return d.join(``)}let Xa={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:`text`,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:Ba,measure(e,t){if(!e.tasks.length)return{w:0,h:0};let n=qa(e,t);return{w:n.w,h:n.h}},render:Ya,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:hr((e,t,n,r)=>{let i=Va(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=qn(e[i],Ia,`color`,n),a}),handles(e,t,n){if(!e.tasks.length)return[];let r=qa(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}`}])}}]},Za=/^([xy])-axis\s*:?\s*(.*)$/i,Qa=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,$a=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,eo=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,to=[`teal`,`blue`,`slate`,`amber`],no=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function ro(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(Za);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=Wn(a,Kn),l=s.match(Qa);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??q(l[2]).color};return}let u=s.match($a);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??q(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=/* @__PURE__ */ 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=no(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 io(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]=Wn(l,Kn),d=new RegExp($a,`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}let ao=mr(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=[],p=i*2,m=/* @__PURE__ */ new Map,h=0,g=0,_=e=>{f.push(e),h=Math.max(h,e.w),g=Math.max(g,e.h);let t=Math.floor(e.x/p)*1048576+Math.floor(e.y/p),n=m.get(t);n?n.push(e):m.set(t,[e])};for(let e of d)_({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=H(R(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;_({x:s-a/2,y:c-i*.6,w:a,h:i*1.2})});let v=(e,t)=>{let n=0,r=Math.floor((e.x+e.w)/p),i=Math.floor((e.y-g)/p),a=Math.floor((e.y+e.h)/p);for(let o=Math.floor((e.x-h)/p);o<=r;o++)for(let r=i;r<=a;r++){let i=m.get(o*1048576+r);if(i)for(let r of i){let i=Math.min(e.x+e.w,r.x+r.w)-Math.max(e.x,r.x);if(i<=0)continue;let a=Math.min(e.y+e.h,r.y+r.h)-Math.max(e.y,r.y);if(!(a<=0)&&(n+=i*a,n>=t))return n}}return n},y=l+4,b=e.points.map(()=>({x:0,y:0,w:0,h:0})),x=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 x){let i=d[t],a=H(R(e.points[t].name),u,n.mono,r),s=u*1.2,c=[{x:i.x+y,y:i.y-s/2,w:a,h:s},{x:i.x-y-a,y:i.y-s/2,w:a,h:s},{x:i.x-a/2,y:i.y-y-s,w:a,h:s},{x:i.x-a/2,y:i.y+y,w:a,h:s},{x:i.x+y*.7,y:i.y-y*.7-s,w:a,h:s},{x:i.x+y*.7,y:i.y+y*.7,w:a,h:s},{x:i.x-y*.7-a,y:i.y-y*.7-s,w:a,h:s},{x:i.x-y*.7-a,y:i.y+y*.7,w:a,h:s}],l=c[0],f=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-.01-t*s*4;if(n<=0)continue;let r=v(e,n)+t*s*4;r<f-.01&&([l,f]=[e,r])}b[t]=l,_(l)}return{fs:i,lfs:u,S:o,left:s,bottom:c,r:l,pts:d,labels:b,w:s+o,h:o+c}});function oo(e,t,n){let r=n.theme,i=ao(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],d=L(r),f=o/2,p=[[f,0],[0,0],[0,f],[f,f]];e.q.forEach((e,t)=>{let n=e.tone??to[t],i=r.tone(n)?.fill??u(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${B(s+p[t][0])}" y="${B(c+p[t][1])}" width="${B(f)}" height="${B(f)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=e.tone??to[t],i=V(n,r,r.node.sub);l.push(`<text x="${B(s+p[t][0]+f/2)}" y="${B(c+p[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" font-weight="700" xml:space="preserve">${U(R(e.text),{...d,text:i},r)}</text>`)}),l.push(`<rect x="${B(s)}" y="${B(c)}" width="${B(o)}" height="${B(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${B(s+f)},${B(c)}V${B(c+o)}M${B(s)},${B(c+f)}H${B(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let m=(e,t,n,i)=>n?`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${B(e)} ${B(t)})"`:``}>${z(n)}</text>`:``,h=c+o+i.bottom/2;l.push(m(s+f/2,h,e.x[0],!1),m(s+f*1.5,h,e.x[1],!1));let g=t.x+i.left/2;return l.push(m(g,c+f*1.5,e.y[0],!0),m(g,c+f/2,e.y[1],!0)),e.points.forEach((e,t)=>{let n=V(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],u=i.labels[t];l.push(`<circle cx="${B(s+a)}" cy="${B(c+o)}" r="${B(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${B(s+u.x)}" y="${B(c+u.y+u.h/2)}" dominant-baseline="central" font-size="${B(i.lfs)}" xml:space="preserve">${U(R(e.name),d,r)}</text>`)}),l.join(``)}let so={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:ro,measure(e,t){let n=ao(e,t);return{w:n.w,h:n.h}},render:oo,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:hr((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>Qa.test(e.trim())&&e.trim()[1]===a[1]),i<0){let t=n?` [${n}]`:``;return[...e,`q${a[1]}${t}:`]}}else i=r.points.find(e=>e.id===t)?.line;if(i===void 0)return null;let o=[...e];return o[i]=qn(e[i],eo,`color`,n,Kn),o}),handles(e,t,n){let r=ao(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)=>io(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`}]}}]},co={high:`red`,medium:`amber`,low:`gray`};function lo(e){let[t,n]=Wn(e);return{text:t.trim(),props:n}}let uo=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``),fo=e=>e.match(/^\s*/)[0].length,po=e=>!e.trim(),mo=/^[-*]\s+/;function ho(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function go(e,t,n){let r=[],i=Math.min(...e.filter(e=>!po(e)).map(fo)),a,o=0,s=0,c=-1,l=/* @__PURE__ */ new Set,u=(e,t)=>{e&&e.end<0&&(e.end=t)};return e.forEach((e,t)=>{if(po(e))return;let d=e.trim(),f=fo(e),p=c;if(c=t,mo.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}=lo(d.replace(mo,``)),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`?(co[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:co[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}=lo(d),g=ho(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=uo(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,cards:[]}),a=void 0}),u(a,c+1),u(r[r.length-1],c+1),r}function _o(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=Wn(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=Jn(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}let vo=[`owner`,`ticket`,`priority`];function yo(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]?fo(e[t.cards[0].start]):fo(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=go(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=fo(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,fo(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?vo:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&ho(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=_o(e[l.start],(e,t)=>r===`text`?a||e:(i===null||i===``?delete t[r]:t[r]=i,e));let h=p(s,m);if(a){let e=go(s,{},()=>{})[m[0]];if((m[1]===void 0?e?.title:e?.cards[m[1]]?.text)!==a)return null}return h}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]?fo(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}}}let bo=mr(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(H(R(e.text),i,n.mono,r,500),t,...e.details.map(e=>H(R(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 xo(e,t,n){if(!e.length)return``;let r=n.theme,i=bo(e,n),{fs:a}=i,o=[],s=L(r),c=Math.min(r.radius,a*.6),l=V(`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="${B(d)}" y="${B(f)}" width="${B(i.colW)}" height="${B(i.h)}" rx="${B(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="${B(d+i.cpad+a*.35)}" cy="${B(h)}" r="${B(a*.32)}" fill="${V(e.tone,r,r.node.sub)}"/>`,`<text x="${B(d+i.cpad+a*1.05)}" y="${B(h)}" dominant-baseline="central" font-size="${B(a)}" font-weight="700" xml:space="preserve">${U(R(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="${B(v)}" y="${B(h-a*.6)}" width="${B(_)}" height="${B(a*1.2)}" rx="${B(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${B(v+_/2)}" y="${B(h)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${z(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="${B(l)}" y="${B(y)}" width="${B(f)}" height="${B(n.h)}" rx="${B(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${B(l)}" y="${B(y+c/2)}" width="3.5" height="${B(n.h-c)}" rx="1.75" fill="${V(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${B(l+i.pad)}" y="${B(m)}" dominant-baseline="central" font-size="${B(a)}" font-weight="500" xml:space="preserve">${U(R(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${B(l+i.pad)}" y="${B(m-a*.6)}" dominant-baseline="central" font-size="${B(a*.88)}" xml:space="preserve">${U(R(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="${B(t)}" y="${B(n-i.chipFs*.75)}" width="${B(e)}" height="${B(i.chipFs*1.5)}" rx="${B(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${B(t+e/2)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${z(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}let So={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]
6
- - Write docs [owner: ana] }`,parse:go,measure(e,t){if(!e.length)return{w:0,h:0};let n=bo(e,t);return{w:n.w,h:n.h}},render:xo,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:yo,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=bo(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}`}))}}]},Co={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},wo=Object.keys(Co),To={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},Eo=[`collapsed`,`highlight`,`dim`,`folder`,`file`,...wo],Do=[`color`,`icon`,`badge`,`note`,`size`,`status`],Oo=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],ko=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,Ao=/^[-*+]\s+/,jo=/\s\[([^[\]]*)\]\s*$/,Mo=/:\s|\s#\s|:$/,No=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,Po=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,Fo=/^(?:\.{3}|…)$/;function Io(e){let t=[],n=e=>t.push(e)-1,r=0,i=t=>{let n=[[]];for(;r<e.length;){let a=e[r++],o=n[n.length-1];if(a===`*`)e[r]===`*`?(r++,e[r]===`/`?(r++,o.push({t:`**/`})):o.push({t:`**`})):o.push({t:`*`});else if(a===`?`)o.push({t:`?`});else if(a===`{`)o.push({t:`alt`,alts:i(!0)});else if(a===`}`&&t)return n;else a===`,`&&t?n.push([]):o.push({t:`lit`,c:a.toLowerCase()})}return n},a=(e,r)=>{for(let i=e.length-1;i>=0;i--){let o=e[i];if(o.t===`lit`)r=n({k:`char`,c:o.c,next:r});else if(o.t===`?`)r=n({k:`seg`,next:r});else if(o.t===`*`||o.t===`**`){let e=n({k:`split`,outs:[]}),i=n({k:o.t===`*`?`seg`:`any`,next:e});t[e].outs.push(i,r),r=e}else if(o.t===`**/`){let e=n({k:`split`,outs:[]}),i=n({k:`any`,next:e}),a=n({k:`char`,c:`/`,next:r});t[e].outs.push(i,a),r=n({k:`split`,outs:[e,r]})}else r=n({k:`split`,outs:o.alts.map(e=>a(e,r))})}return r},o=i(!1),s=a(o.length>1?[{t:`alt`,alts:o}]:o[0],n({k:`end`})),c=e=>{let n=/* @__PURE__ */ new Set,r=[...e];for(;r.length;){let e=r.pop();if(n.has(e))continue;n.add(e);let i=t[e];i.k===`split`&&r.push(...i.outs)}return n},l=c([s]);return{test(e){let n=l,r=e.toLowerCase();for(let e=0;e<r.length;e++){let i=r[e],a=[];for(let e of n){let n=t[e];n.k!==`split`&&n.k!==`end`&&(n.k===`char`?n.c===i:n.k!==`seg`||i!==`/`)&&a.push(n.next)}if(!a.length)return!1;n=c(a)}for(let e of n)if(t[e].k===`end`)return!0;return!1}}}function Lo(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}let Ro=e=>e.replace(/\/$/,``);function zo(e,t){for(let n of Object.keys(e))!Eo.includes(n)&&!Do.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[...Do.slice(1),...Eo].join(`, `)})`);e.status&&!wo.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${wo.join(`, `)})`),e.color&&!se(e.color)&&delete e.color}function Bo(e,t,n){let r=[],i=[],a=[],o=/* @__PURE__ */ new Map,s=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let c=e.trim().match(Po);if(c){let e=q(c[2]);zo(e,e=>n(t,e));let r=c[1];a.push({re:Io(Ro(r)),path:Ro(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let l=e.match(ko)[0],u=e.slice(l.length),d=u.match(Ao);d&&(u=u.slice(d[0].length));let f=e.length-u.trimStart().length;if(u=u.trim(),!u||No.test(u))return;let p=(l+(d?.[0]??``)).replace(/\t/g,` `).length,m={},h,g=u.match(jo);g&&(m=q(g[1]),h=[f+g.index,f+u.length],u=u.slice(0,g.index).trimEnd());let _,v=Lo(u).match(Mo);if(v&&v.index>0){_=u.slice(v.index+v[0].length).trim()||void 0,u=u.slice(0,v.index).trimEnd();let e=u.match(jo);e&&!g&&(m=q(e[1]),h=[f+e.index,f+u.length],u=u.slice(0,e.index).trimEnd())}zo(m,e=>n(t,e));let y={text:u,collapsed:!1,highlight:!1,dim:!1,line:t,children:[]};for(h&&(y.propSpan=h),o.set(y,{props:m,note:_});i.length&&i[i.length-1].indent>=p;)i.pop();i.length>=100&&(s||n(t,`treeview: entries nest at most 100 levels deep`),s=!0,i.length=99),(i.length?i[i.length-1].node.children:r).push(y),i.push({indent:p,node:y})});let c=(e,t)=>{for(let n of e){let e=t+Ro(n.text),{props:r,note:i}=o.get(n),s=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),l={};for(let t of a)(!t.folders||s)&&t.re.test(t.path?e:Ro(n.text))&&(t.hits++,Object.assign(l,t.props));if(r.folder===`true`&&delete l.file,r.file===`true`&&delete l.folder,wo.some(e=>r[e]===`true`)||r.status){for(let e of wo)delete l[e];delete l.status}Object.assign(l,r),n.note=r.note??i??l.note,n.tone=l.color,n.icon=l.icon,n.badge=l.badge,n.size=l.size,n.status=wo.find(e=>l[e]===`true`)??(wo.includes(l.status)?l.status:void 0),n.collapsed=l.collapsed===`true`,n.highlight=l.highlight===`true`,n.dim=l.dim===`true`,n.type=l.folder===`true`?`folder`:l.file===`true`?`file`:void 0,c(n.children,e+`/`)}};c(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function Vo(e,t=[]){for(let n of e)t.push(n),Vo(n.children,t);return t}let Ho=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),Uo=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},Wo={},X=(e,t,n)=>{for(let r of n.split(` `))Wo[r]=[t,e]};X(`blue`,`code`,`ts tsx mts cts py c cpp`),X(`amber`,`code`,`js jsx mjs cjs zig`),X(`green`,`code`,`vue`),X(`orange`,`code`,`svelte rs swift html`),X(`purple`,`code`,`astro kt h cs css`),X(`cyan`,`code`,`go`),X(`red`,`code`,`java rb`),X(`indigo`,`code`,`php lua`),X(`pink`,`code`,`scss`),X(`green`,`terminal`,`sh bash zsh fish ps1`),X(`blue`,`doc`,`md`),X(`amber`,`doc`,`mdx`),X(`gray`,`doc`,`txt rst`),X(`red`,`doc`,`pdf`),X(`green`,`doc`,`csv`),X(`purple`,`image`,`png jpg jpeg gif webp avif ico`),X(`amber`,`image`,`svg`),X(`red`,`font`,`woff woff2 ttf otf`),X(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),X(`amber`,`config`,`json`),X(`purple`,`config`,`yaml yml`),X(`gray`,`config`,`toml ini`),X(`orange`,`config`,`xml`),X(`slate`,`config`,`env`),X(`cyan`,`database`,`sql db sqlite`),X(`amber`,`package`,`zip tar gz`),X(`pink`,`yuhwa`,`yu yuhwa`);let Go=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function Ko(e){let t=Ro(e).toLowerCase();return/(^|\.)lock$|-lock\.(json|yaml)$|^lockfile$/.test(t)?[`lock`,`gray`]:/^\.git(ignore|attributes|modules|keep)?$/.test(t)?[`git`,`orange`]:/^(package\.json|cargo\.toml|go\.mod|pyproject\.toml|gemfile|composer\.json|pom\.xml|build\.gradle)$/.test(t)?[`package`,`red`]:/^(dockerfile|makefile|\.env.*|\.editorconfig|\.npmrc|\.prettierrc.*|tsconfig.*\.json)$/.test(t)?[`config`,`slate`]:/^(readme|license|licence|changelog|contributing)(\..*)?$/.test(t)?[`doc`,`blue`]:/\.(test|spec)\.[a-z]+$|^test_.*\.py$|_test\.go$/.test(t)?[`test`,`green`]:Wo[Uo(t)]??[`file`,void 0]}function qo(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="M3.5 1.5h6l3.5 3.5v9.5h-9.5z" fill="${t}" stroke="${n}"/>${r(`M9.5 1.5v3.5h3.5`)}`;switch(e){case`folder`:return`<path d="M1.5 4.5a1 1 0 0 1 1-1h3.6l1.6 1.8h5.8a1 1 0 0 1 1 1v6.7a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1z" fill="${t}" stroke="${n}"/>`;case`folder-open`:return`<path d="M1.5 12.5v-8a1 1 0 0 1 1-1h3.6l1.6 1.8h5a1 1 0 0 1 1 1v1.2" fill="none" stroke="${n}"/><path d="M3.4 7.5h11.3l-1.9 6H1.5z" fill="${t}" stroke="${n}" stroke-linejoin="round"/>`;case`code`:return i+r(`M6.6 8.2l-1.6 1.9 1.6 1.9M9.4 8.2l1.6 1.9-1.6 1.9`);case`doc`:return i+r(`M5.8 8h4.4M5.8 10.2h4.4M5.8 12.4h2.8`);case`image`:return i+`<path d="M5 13l2.1-2.8 1.5 1.6 1.4-1.8L11.8 13z" fill="${n}"/><circle cx="6.4" cy="7.8" r="1" fill="${n}"/>`;case`config`:return i+r(`M5.5 8.6h5M5.5 11.6h5`)+`<circle cx="7" cy="8.6" r="1.1" fill="${t}" stroke="${n}"/><circle cx="9" cy="11.6" r="1.1" fill="${t}" stroke="${n}"/>`;case`lock`:return`<rect x="3.5" y="7" width="9" height="7.5" rx="1.3" fill="${t}" stroke="${n}"/>${r(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)}<circle cx="8" cy="10.7" r="1" fill="${n}"/>`;case`package`:return`<path d="M8 1.8l5.6 3.1v6.2L8 14.2l-5.6-3.1V4.9z" fill="${t}" stroke="${n}" stroke-linejoin="round"/>${r(`M2.4 4.9L8 8l5.6-3.1M8 8v6.2`)}`;case`git`:return r(`M5 5.6v4.8M11 7.6c0 2.4-6 1.6-6 2.8`)+[[5,4],[5,12],[11,6]].map(([e,r])=>`<circle cx="${e}" cy="${r}" r="1.6" fill="${t}" stroke="${n}"/>`).join(``);case`database`:return`<path d="M3 4v8c0 1.1 2.2 2 5 2s5-.9 5-2V4" fill="${t}" stroke="${n}"/><ellipse cx="8" cy="4" rx="5" ry="2" fill="${t}" stroke="${n}"/>`+r(`M3 8c0 1.1 2.2 2 5 2s5-.9 5-2`);case`test`:return`<path d="M6.4 2v4.3L2.9 12.4a1.2 1.2 0 0 0 1 1.8h8.2a1.2 1.2 0 0 0 1-1.8L9.6 6.3V2" fill="${t}" stroke="${n}"/>`+r(`M5.4 2h5.2M4.6 9.8h6.8`);case`font`:return i+r(`M5.5 13l2.5-6 2.5 6M6.4 11h3.2`);case`media`:return i+`<path d="M6.6 7.8l4 2.4-4 2.4z" fill="${n}"/>`;case`terminal`:return`<rect x="1.5" y="2.5" width="13" height="11" rx="1.5" fill="${t}" stroke="${n}"/>`+r(`M4.5 6.3l2.2 1.9-2.2 1.9M8.3 10.6h3.2`);case`yuhwa`:return i+`<circle cx="6.2" cy="9" r="1.2" fill="${n}"/><circle cx="9.8" cy="11.6" r="1.2" fill="${n}"/>${r(`M7.1 9.7l1.8 1.3`)}`;default:return i}}let Jo=a({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function Yo(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(Ro(n.text),(t.get(Ro(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(Ro(e.text))&&t.get(Ro(e.text))===1&&!/^n\d+$/.test(Ro(e.text))?Ro(e.text):`n${n+1}`)}let Xo=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,Zo=e=>e!==void 0&&e!==`false`,Qo=(e,t,n)=>t.includes(e)?e:n,$o=e=>e&&se(e)?e:void 0,es=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function ts(e,t){let n=t.get(e);if(n)return n;n=/* @__PURE__ */ new Set;for(let r of e.children){r.status&&r.status!==`ignored`&&n.add(r.status);for(let e of ts(r,t))n.add(e)}return t.set(e,n),n}let ns=[`color`,`mono`,`emoji`,`none`],rs=[`solid`,`rounded`,`dashed`,`dotted`,`none`],is=[`none`,`name`,`folders`],as=[`collapsed`,`all`,`none`],os=[`letter`,`dot`,`none`],ss=mr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=Qo(i.icons,ns,ns[0]),s=Qo(i.sort,is,is[0]),c=i.counts===`true`?`all`:Qo(i.counts,as,as[0]),l=Qo(i.marks,os,os[0]),u=i.rollup!==`false`&&l!==`none`,d=Zo(i.compact),f=Zo(i.chevrons),p=Xo(i.depth),m=$o(i[`folder-color`])??`amber`,h=a*({compact:1.45,relaxed:2.15}[i.spacing]??1.8),g=o===`none`?0:a*1.1,_=f?a*.85:0,v=o===`none`?0:a*.45,y=_+(g?g/2:a*.3),b=Xo(i.indent)??y+a*.75,x=Vo(e),S=Yo(x),C=new Map(x.map((e,t)=>[e,S[t]])),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map,E=e=>{let t=T.get(e);return t===void 0&&T.set(e,t=e.children.reduce((e,t)=>e+1+E(t),0)),t},D=a*.7,O=e=>r(e,D,600,n.mono)+a*.8,k=e=>{if(s===`none`)return e;let t=e=>Number(Fo.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(Ho(n))-Number(Ho(e)):0)||es.compare(e.text,n.text))},A=e=>!e.note&&!e.badge&&!e.size&&!e.status&&!e.highlight&&!e.dim&&!e.icon&&!e.tone&&!e.collapsed,j=[],ee=(e,t,o)=>{let s=k(e);s.forEach((e,l)=>{let f=e,g=e=>e.collapsed||p!==void 0&&t+1>=p,_=[Ro(f.text)];for(;d&&f.children.length===1&&Ho(f)&&Ho(f.children[0])&&A(f)&&!g(f);)f=f.children[0],_.push(Ro(f.text));let v=Ho(f),y=!v&&Fo.test(f.text),x=v&&!g(f)&&f.children.length>0,S=y?`…`:_.length>1?_.join(`/`)+(f.text.endsWith(`/`)?`/`:``):f.text;i.slashes===`false`?S=S.replace(/\/$/,``):i.slashes===`true`&&v&&!S.endsWith(`/`)&&(S+=`/`);let[T,D]=v?[x?`folder-open`:`folder`,Go.test(Ro(f.text))?`gray`:m]:Ko(f.text),k=f.icon??T,M=Oo.includes(k)?k:void 0,te=v?600:400,N=v&&(c===`all`||c===`collapsed`&&!x)&&f.children.length?String(E(f)):void 0,ne=v&&u&&!f.status?ts(f,w):void 0,re={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:M??`file`,iconTone:f.tone??(f.status?Co[f.status]:void 0)??(f.icon?void 0:D),iconText:M?void 0:f.icon,textW:H(R(S),a,n.mono,r,te),badgeW:f.badge?r(f.badge,a*.72,600,n.mono)+a*.9:0,count:N,countW:N?O(N):0,rollup:ne?.size?ne.size===1?[...ne][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:j.length*h,x:t*b};j.push(re),x&&ee(f.children,t+1,re)})};ee(e,0);let M=e=>e.more?e.x+_:e.x+_+g+v,te=e=>M(e)+e.textW+a*.5,N=e=>(e.badgeW?te(e)+e.badgeW:M(e)+e.textW)+a*.45,ne=e=>e.countW?N(e)+e.countW:e.badgeW?te(e)+e.badgeW:M(e)+e.textW,re=i.notes===`inline`,P=a*.88,ie=0;for(let e of j)ie=Math.max(ie,ne(e));let F=ie+a*1.6,ae=e=>re?ne(e)+a*.9:F,oe=e=>e.node.note?H(R(e.node.note),P,n.mono,r,400):0,I=e=>l!==`none`&&(e.node.status&&To[e.node.status]!==``||e.rollup!==void 0),se=j.some(I),ce=a*4;for(let e of j)ce=Math.max(ce,e.node.note?ae(e)+oe(e):ne(e));let L=Math.max(0,...j.map(e=>e.sizeW)),le=L?ce+a*1.4+L:ce,ue=le+a*1.2;return{rows:j,fs:a,smallFs:D,noteFs:P,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:M,badgeX:te,countX:N,noteX:ae,sizeRight:le,markX:ue,mark:I,w:se?ue+a*.8:le,h:j.length*h}}),cs=e=>{let t=Ve(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function ls(e,t,n){if(!e.length)return``;let r=n.theme,i=ss(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=Qo(a.lines,rs,rs[0]),f=(e,t)=>e?V(e,r,t):t,p=f($o(a[`line-color`]),r.edge.stroke),m=$o(a[`highlight-color`]),h=$o(a[`badge-color`])??`blue`,g=f($o(a[`note-color`]),r.node.sub),_=f($o(a[`strike-color`]),r.node.sub),v=Xo(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=Ie(a)??1,b=`fill="none" stroke="${p}" stroke-width="${B(y)}" stroke-opacity="0.55"${cs(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,x=Math.min(Xo(a.radius)??r.radius,(i.rowH-2)/2),S=B(o(-i.fs*.35)),C=B(i.w+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,y=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${S}" y="${B(s(e.y+1))}" width="${C}" height="${B(i.rowH-2)}" rx="${B(a.radius?x:Math.min(r.radius,i.rowH/3))}" fill="${o?.fill??r.accent}"${o?``:` fill-opacity="0.14"`}/>`)}else a.rows===`striped`&&t%2==1&&c.push(`<rect x="${S}" y="${B(s(e.y))}" width="${C}" height="${B(i.rowH)}" fill="${r.node.text}" fill-opacity="0.045"/>`);if(d!==`none`&&e.parent){let t=e.parent.x+i.anchor,n=Math.max(t,e.x-i.fs*.2);if(e.last){let r=e.parent.y+i.rowH/2+(i.iconW?i.iconW/2+i.fs*.1:i.fs*.5),a=d===`rounded`?Math.min(i.fs*.45,n-t,p-r):0;l.push(a>0?`<path d="M${B(o(t))},${B(s(r))}V${B(s(p-a))}Q${B(o(t))},${B(s(p))} ${B(o(t+a))},${B(s(p))}H${B(o(n))}" ${b}/>`:`<path d="M${B(o(t))},${B(s(r))}V${B(s(p))}H${B(o(n))}" ${b}/>`)}else l.push(`<path d="M${B(o(t))},${B(s(p))}H${B(o(n))}" ${b}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${B(t-n)},${B(s(p)-n/2)}L${B(t)},${B(s(p)+n/2)}L${B(t+n)},${B(s(p)-n/2)}`:`M${B(t-n/2)},${B(s(p)-n)}L${B(t+n/2)},${B(s(p))}L${B(t-n/2)},${B(s(p)+n)}`;y.push(`<path d="${a}" fill="none" stroke="${r.node.sub}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>`)}if(i.iconW&&!e.more){let t=o(e.x+i.chevW),n=s(p-i.iconW/2);if(e.iconText||i.icons===`emoji`)y.push(`<text x="${B(t+i.iconW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.95)}">${z(e.iconText??Jo[e.icon]??`📄`)}</text>`);else{let a=i.icons===`mono`,o=!a&&e.iconTone?r.tone(e.iconTone):void 0,s=a||!e.iconTone?r.node.sub:f(e.iconTone,r.node.sub),c=o?.fill??r.node.fill;y.push(`<g transform="translate(${B(t)},${B(n)}) scale(${B(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${qo(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));y.push(`<line x1="${B(t-i.fs*.15)}" y1="${B(s(p))}" x2="${B(t+e.textW+i.fs*.15)}" y2="${B(s(p))}" stroke="${_}" stroke-width="${B(v)}" stroke-linecap="round"/>`)}let w=n.status?f(Co[n.status],r.node.text):void 0,T=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):w??r.node.text,E=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(y.push(`<text x="${B(o(i.textX(e)))}" y="${B(s(p))}" dominant-baseline="central" font-size="${B(i.fs)}"${E} xml:space="preserve">${U(R(e.label),L(r,T,T),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;y.push(`<rect x="${B(a)}" y="${B(s(p)-c/2)}" width="${B(e.badgeW)}" height="${B(c)}" rx="${B(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${B(a+e.badgeW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${z(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;y.push(`<rect x="${B(t)}" y="${B(s(p)-n/2)}" width="${B(e.countW)}" height="${B(n)}" rx="${B(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${B(t+e.countW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&y.push(`<text x="${B(o(i.noteX(e)))}" y="${B(s(p))}" dominant-baseline="central" font-size="${B(i.noteFs)}" xml:space="preserve">${U(R(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&y.push(`<text x="${B(o(i.sizeRight))}" y="${B(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${B(i.fs*.82)}" fill="${r.node.sub}">${z(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(Co[t],r.node.text);i.marks===`dot`||!n.status?y.push(`<circle cx="${B(o(i.markX))}" cy="${B(s(p))}" r="${B(i.fs*.22)}" fill="${a}"/>`):y.push(`<text x="${B(o(i.markX))}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.85)}" font-weight="700" fill="${a}">${To[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${y.join(``)}</g>`:y.join(``))}),c.join(``)+l.join(``)+u.join(``)}let us=[Tr,Pr,Rr,Gr,ci,ti,Di,Ii,Ji,ha,Ma,Xa,so,So,{name:`treeview`,panels:[{name:`treeview`,guide:"indentation is the tree (several top-level entries are fine); `-` bullets and the `├──` / `│` prefixes of `tree` output are optional; `...` stands for more files. A folder has children, ends in `/` or says `[folder]`. `name: note` or `name # note` adds a note. Trailing props: a colour, `icon: "+Oo.join(`|`)+"|<emoji>`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `"+wo.join(`|`)+"`. `match <glob> [props]` gives every matching entry those props (`*`, `**`, `?`, `{a,b}`; a trailing `/` matches folders only).",syntax:`treeview id "Title" [icons: color] { match *.test.ts [dim]\\n src/\\n index.ts: entry\\n util.ts [modified] }`,options:{icons:[...ns],lines:[...rs],sort:[...is],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...as],marks:[...os],rollup:[`true`,`false`],depth:`number`,indent:`number`,"folder-color":`color`,"line-color":`color`,"highlight-color":`color`,"badge-color":`color`,"note-color":`color`,"strike-color":`color`,"strike-width":`number`},parse:Bo,measure(e,t){if(!e.length)return{w:0,h:0};let n=ss(e,t);return{w:n.w,h:n.h}},render:ls,parts(e){let t=Vo(e);return Yo(t).map((e,n)=>({id:e,label:t[n].text,kind:Ho(t[n])?`folder`:`file`,tone:t[n].tone}))},editPart:hr((e,t,n,r)=>{let i=Vo(r),a=i[Yo(i).indexOf(t)];if(!a)return null;let o=[...e],s=e[a.line],[c,l]=a.propSpan??[s.trimEnd().length,s.trimEnd().length],u=s.slice(c,l).match(/\[([^\]]*)\]/),{color:d,...f}=u?q(u[1]):{},p=Jn(n?{color:n,...f}:f);return o[a.line]=s.slice(0,c)+(p?` [${p}]`:``)+s.slice(l),o})}]}];wr(...us);function ds(e){let t=[],n=/* @__PURE__ */ 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 J.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:R(e.slice(0,s)),right:R(e.slice(s+4).trim())}):t.push({kind:`text`,left:R(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}let fs=e=>J.rows.find(t=>t.kind===e.kind);function ps(e,t,n,r,i,a={}){let{weight:o}=a,s=t*(a.lineHeight??1.75),c={fs:t,lh:s,mono:n,measure:r,theme:i},l=[],u=[],d=0,f=0;for(let i of e){let e=s;if(i.kind===`text`){let e=i;d=Math.max(d,H(e.left,t,n,r,o)+(e.right?t*2+H(e.right,t,n,r,o):0))}else if(i.kind===`rule`)e=t*1.1;else if(i.kind===`gap`)e=t*.6;else{let t=fs(i)?.measure(i,c)??{w:0,h:0};d=Math.max(d,t.w),e=t.h}l.push(f),u.push(e),f+=e}return{rows:e,fs:t,lh:s,mono:n,weight:o,ys:l,hs:u,w:d,h:f}}function ms(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.label.split(`
1
+ var Yuhwa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=null;function n(e,n){let r=t;t=e;try{return n()}finally{t=r}}let r=e=>e instanceof Error?e.message:String(e),i=e=>{t&&!t.some(t=>t.message===e)&&t.push({line:1,message:e,severity:`error`})};function a(e,t,n,a,o=i){return function(...i){try{return n.apply(this,i)}catch(n){return o(`plugin "${e}": ${t} failed: ${r(n)}`,i),a(...i)}}}let o=/* @__PURE__ */ new Map;function s(e,t,n){let r=`${e} ${t}`,i=o.get(r);i&&i!==n&&console.warn(`yuhwa: plugin "${n}" replaces ${e} "${t}" of plugin "${i}"`),o.set(r,n)}let c=()=>o.clear(),l=(e,t)=>o.get(`${e} ${t}`),u=e=>Object.setPrototypeOf(e,null),d=u({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`]});d.violet=d.purple,d.rose=d.red,d.emerald=d.green,d.yellow=d.amber,d.grey=d.gray,d.sky=d.cyan;let f=e=>Object.hasOwn(d,e),p=[`slate`,`gray`,`red`,`orange`,`amber`,`lime`,`green`,`teal`,`cyan`,`blue`,`indigo`,`purple`,`pink`],m={50:0,100:1,200:2,300:3,400:4,500:5,600:6,700:7,800:8,900:9,950:10};function h(e,t){return d[e]?.[m[t]]}let g=`Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`,_=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,v=e=>d[e]&&{fill:h(e,50),stroke:h(e,300),text:h(e,900)},y=e=>d[e]&&{fill:h(e,50)+`b3`,stroke:h(e,200),text:h(e,700)},b=e=>d[e]&&{fill:h(e,950),stroke:h(e,600),text:h(e,100)},x=e=>d[e]&&{fill:h(e,950)+`80`,stroke:h(e,800),text:h(e,300)},S=u({paper:{name:`paper`,dark:!1,background:`#fbfaf7`,font:g,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:v,groupTone:y,edgeTone:e=>h(e,500)}}),C=Object.keys(S);function w(e){let t=e;t.edge.ink??=t.edge.text,S[t.name]=t,C.includes(t.name)||C.push(t.name)}let T=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,E=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(` `))),D=e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`),O=(e,t)=>e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e);function k(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=>D(O(e,255))).join(``);let t=(parseFloat(e[0])%360+360)%360/360,n=Math.min(1,O(e[1],1)/(e[1].endsWith(`%`)?1:100)),i=Math.min(1,O(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=>D(s(e)*255)).join(``)}let i=E.get(t);return i?`#`+i:void 0}let A=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))},j=(e,t,n)=>`#`+A(e).map((e,r)=>Math.round(e*n+A(t)[r]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``);function ee(e,t,n){let r=k(e);if(!r)return;let i=T.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,a=t.dark?n?.14:.22:n?.07:.12;return{fill:j(r,i,a),stroke:r,text:t.dark?j(r,`#ffffff`,.45):j(r,`#000000`,.55)}}let M=/* @__PURE__ */ new WeakMap,te=/* @__PURE__ */ new WeakMap,N=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),P=[`solid`,`dashed`,`dotted`],ne=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t;function F(e){let t=e===`mono`||/mono|code|courier/i.test(e);return e===`mono`||e===`sans`?{font:t?_:g,mono:t}:{font:`${e}, ${t?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`}`,mono:t}}let re=u({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:P},"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 ie(e,t,n){let r=n??S[t.base]??S.paper,i=N(t.dark,r.dark),a=(e,n,a)=>L(t[e],r,i?a:n),o=(e,n)=>{let r=parseFloat(t[e]);return Number.isFinite(r)&&r>=0?r:n},s=e=>!N(t[e],!0),c=s(`background`)?`none`:a(`background`,50,950)??r.background,l=a(`edge-text`,700,300)??r.edge.text,u=i!==r.dark,d=t.font?.trim(),f=d?F(d):{font:r.font,mono:r.mono};return{name:e,dark:i,background:c,font:f.font,mono:f.mono,fontSize:o(`font-size`,r.fontSize),node:{fill:a(`node-fill`,50,900)??r.node.fill,stroke:a(`node-stroke`,300,600)??r.node.stroke,text:a(`node-text`,900,100)??r.node.text,sub:a(`node-sub`,500,400)??r.node.sub},group:{fill:s(`group-fill`)?`none`:a(`group-fill`,50,950)??r.group.fill,stroke:a(`group-stroke`,200,800)??r.group.stroke,text:a(`group-text`,700,300)??r.group.text,dash:ne(t[`group-border`],r.group.dash)},edge:{stroke:a(`edge-color`,500,400)??r.edge.stroke,text:l,labelBg:a(`label-bg`,50,950)??(r.edge.labelBg===r.background||t.background?c:r.edge.labelBg),labelStroke:r.edge.labelStroke,ink:t[`edge-text`]?l:a(`edge-color`,600,300)??r.edge.ink},title:a(`title-color`,900,100)??r.title,accent:a(`accent`,600,400)??r.accent,strokeWidth:o(`stroke-width`,r.strokeWidth),edgeWidth:o(`edge-width`,r.edgeWidth),radius:o(`radius`,r.radius),shadow:s(`shadow`)?null:a(`shadow`,200,950)??(u?i?`rgba(0, 0, 0, 0.45)`:`rgba(15, 23, 42, 0.10)`:r.shadow),grid:s(`grid`)?null:a(`grid`,200,800)??r.grid,tone:u?i?b:v:r.tone,groupTone:u?i?x:y:r.groupTone,edgeTone:u?e=>h(e,i?400:500):r.edgeTone}}function ae(e,t,n=[]){let r=t[e],i=r.base??(S[e]?e:void 0);return ie(e,r,i&&t[i]&&i!==e&&!n.includes(i)?ae(i,t,[...n,e]):S[i??`paper`]??S.paper)}let oe=e=>[.../* @__PURE__ */ new Set([...C,...Object.keys(e??{})])];function se(e,t){if(e&&t?.[e]){let n=te.get(t);n||te.set(t,n=/* @__PURE__ */ new Map);let r=n.get(e);return r||n.set(e,r=ce(ae(e,t))),r}return ce(S[e??`paper`]??S.paper)}function ce(e){let t=M.get(e);return t||(t={...e,tone:n=>e.tone(n)??ee(n,t,!1),groupTone:n=>e.groupTone(n)??ee(n,t,!0),edgeTone:t=>e.edgeTone(t)??(k(t)?t:void 0)},M.set(e,t)),t}let I=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&f(t[1])&&(!t[2]||t[2]in m)||!!k(e)},le=I,ue=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function L(e,t,n){if(!e)return;let r=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);if(r&&d[r[1]]){let e=r[2]?Number(r[2]):n;return h(r[1],e in m?e:n)}return de(e)?e:void 0}let de=e=>/^[\w\s#(),.%/+-]*$/.test(e),fe=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())},pe=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),me=e=>({...e,text:e.sub}),he=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,ge=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,_e=/\*\*(.{1,1000}?)\*\*|~~(.{1,1000}?)~~|`([^`]+)`|\[\[(.{1,1000}?)\]\]|\{([^{}|\n]{1,1000}?)[ ]?\|[ ]?(.{1,1000}?)\}|\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.{1,1000}?)\}|\*(.{1,1000}?)\*/g,ve=u({color:{aliases:[`text`],info:`text colour: a palette name or any CSS colour`,values:p},size:{aliases:[`font-size`],info:`font size, px`,values:[]},weight:{aliases:[`font-weight`],info:`font weight: 400, 600, 700 ...`,values:[`300`,`400`,`500`,`600`,`700`,`800`,`900`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),ye=e=>e in ve?e:Object.keys(ve).find(t=>ve[t].aliases.includes(e));function be(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&xe(i)){t.color=i;continue}let a=ye(i);if(!a)return;let o=ve[a].flag,s=r.length?r.join(`:`).trim():o?`true`:``;if(o){if(s!==`true`&&s!==`false`)return;s===`true`&&(a===`italic`?t.italic=!0:t.weight=700)}else if(a===`color`){if(!I(s))return;t.color=s}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}let xe=e=>he.test(e)&&(e.startsWith(`#`)||f(e.replace(/-\d+$/,``)));function R(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(_e))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&&xe(e[1])?r({kind:`chip`,text:e[2],color:e[1]}):r({kind:`chip`,text:t[4]})}else if(t[5]!==void 0){let e=be(t[5]),n=e?null:t[0].match(ge);e?r({kind:`color`,text:t[6],...e}):n&&xe(n[1])?r({kind:`color`,text:n[2],color:n[1]}):r({kind:`text`,text:t[0]})}else t[7]===void 0?r({kind:`muted`,text:t[9]}):xe(t[7])?r({kind:`color`,text:t[8],color:t[7]}):r({kind:`text`,text:t[0]});return r({kind:`text`,text:e.slice(n)}),t}function Se(e){let t=[];for(let n of e.matchAll(_e))t.push([n.index,n.index+n[0].length]);let n=[],r=``,i=0;for(let a=0;a<e.length;a++){for(;i<t.length&&t[i][1]<=a;)i++;let o=i<t.length&&t[i][0]<=a;e[a]===` `&&!o?(r&&n.push(r),r=``):r+=e[a]}return r&&n.push(r),n}let Ce=/[*~`[{]/;function we(e,t=!1){let n=Ce.test(e)?R(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function Te(e,t,n,r,i,a=!1,o=0){let s=we(e,a);return H(s,t,r,i,n)+(o?o*[...Ae(s)].length:0)}let Ee=(e,t)=>e.reduce((e,t)=>Ce.test(t)?R(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),De=(e,t,n=1.3)=>Ee(e,t)*n,Oe=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${B(t)}" y="${B(n(i))}">${r(e)}</tspan>`).join(``);function ke(e,t,n,r=!1){let i=we(e,r);return i.every(e=>e.kind===`text`)?z(Ae(i)):U(i,t,n)}let Ae=e=>e.map(e=>e.text).join(``);function je(e){let t=1/0;for(let n of e)n.trim()&&(t=Math.min(t,n.match(/^[ \t]*/)[0].length));let 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,` `))}let z=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),B=e=>(Math.round(e*100)/100).toString(),Me=(e,t,n,r,i,a=``)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" font-size="${B(n)}" fill="${r}"${a}>${i}</text>`,V=(e,t,n)=>e&&L(e,t,t.dark?400:600)||n,Ne=.55,Pe=(e,t)=>e.weight??(e.kind===`bold`?700:t);function H(e,t,n,r,i=400){let a=0;for(let o of e){let e=o.size??t,s=r(o.text,e,Pe(o,i),n);o.w=o.kind===`chip`?s+e*Ne*2:s,a+=o.w}return a}let Fe=e=>e.reduce((e,t)=>e+(t.w??0),0);function Ie(e,t,n,r){if(e.color)return V(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 Le(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=Ie(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="${B(t)}" y="${B(n-a/2)}" width="${B(e)}" height="${B(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(Me(t+r*Ne,n,r,l.color?u:i.text,z(l.text),` xml:space="preserve"`))}else{let a=Pe(l,s),o=l.italic?` font-style="italic"`:``;if(c.push(Me(t,n,l.size??r,u,z(l.text),` xml:space="preserve"${a===400?``:` font-weight="${a}"`}${o}`)),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${B(a)},${B(n)}H${B(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function U(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${Ie(e,t,n,r)}"`];return e.size&&i.push(`font-size="${B(e.size)}"`),e.weight?i.push(`font-weight="${e.weight}"`):e.kind===`bold`&&i.push(`font-weight="750"`),e.italic&&i.push(`font-style="italic"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${z(e.text)}</tspan>`}).join(``)}let Re=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function ze(e,t=`border-style`){let n=e[t];return n&&P.includes(n)?n:N(e.dashed,!1)?`dashed`:N(e.dotted,!1)?`dotted`:void 0}function Be(e,t){let n=L(t[`edge-color`],e,e.dark?400:500),r=Ve(t);if(!n&&!r)return e;let i=Object.create(e);return n&&(i.edge={...e.edge,stroke:n,ink:n}),r&&(i.edgeWidth=r),i}function Ve(e){return Ue(e[`edge-width`])}let He=(e,t)=>{let n=Re(e,NaN);return n>=0?n:t},Ue=e=>{let t=Re(e,NaN);return t>0?t:void 0},We=(e,t,n)=>({size:Ue(e[`font-size`])??t,weight:Ue(e[`font-weight`])??n,italic:N(e.italic,!1)}),Ge=(e,t)=>We(e,t.fontSize*.86,500);function Ke(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function qe(e,t){switch(e){case`dashed`:return`${B(t*4)} ${B(t*3)}`;case`dotted`:return`${B(t*.1)} ${B(t*2.6)}`;default:return null}}function Je(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=He(n.border??n[`stroke-width`],He(i[`stroke-width`],r.strokeWidth)),s=L(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=L(n.stroke,r,500)??a?.stroke??r.node.stroke,l=L(n.text,r,r.dark?100:800)??a?.text??r.node.text,u=We(n,Ue(i[`font-size`])??r.fontSize,500),d=u.size;return{fill:s,stroke:c,text:l,sub:L(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:qe(ze(n),o),radius:He(n.radius,He(i.radius,r.radius)),fontSize:d,fontWeight:N(n.bold,!1)?650:u.weight,body:L(n[`body-color`],r,r.dark?100:800)??l,bodySize:Ue(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:Ue(n[`body-weight`])??400,lineHeight:Ue(n[`line-height`])??1.75,italic:u.italic,shadow:N(n.shadow,N(i.shadow,r.shadow!==null)),opacity:Re(n.opacity,1)}}function Ye(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:L(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:L(n.stroke,t,300)??r?.stroke??t.group.stroke,text:L(n.text,t,700)??r?.text??t.group.text,dash:Xe(n,t.group.dash)}}function Xe(e,t){return ne(ze(e),t)}function Ze(e,t,n){let r=t.theme;if(!r||!(S[r]||n?.[r])||r===e.name)return Be(e,t);let i=Object.create(se(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,Be(i,t)}function Qe(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&&I(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:L(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`:L(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:L(e.text,t,t.dark?200:700)??r?.text??t.title,width:He(e[`border-width`],a&&!s&&!o?He(a,1):1),dash:Xe(e,null),radius:He(e.radius,Math.min(14,t.radius+4)),shadow:N(e.shadow,!1)}}function $e(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??L(n.color,r,500):void 0,o=L(n.stroke,r,r.dark?400:500)??a??r.edge.stroke,s=t.line===`thick`||N(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=He(n.width,s),l=ze(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=N(n.flow??n.animate,!1),f=Ge(n,r);return{stroke:o,width:c,dash:qe(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:L(n.text??n[`label-color`],r,700)??(a&&!r.dark?L(n.color,r,700):r.edge.text),fontSize:f.size,fontWeight:f.weight,italic:f.italic,labelBg:L(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:Re(n.opacity,1)}}let et=[`top`,`right`,`bottom`,`left`],tt=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),nt=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),rt=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),it=e=>Math.hypot(e.x,e.y),at=e=>{let t=it(e)||1;return{x:e.x/t,y:e.y/t}},ot=(e,t)=>it(rt(e,t)),W=e=>Math.round(e*100)/100;function st(e,t,n,r){let i=tt(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`}let ct={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function lt(e,t,n){let r=tt(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function ut(e,t,n){let r=lt(t,n,e);return[e,r,ct[r]]}function dt(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&&gt(n,l));if(!u.length)return[n,r];let d=i?ut(n,e,tt(t)):[n],f=a?ut(r,t,tt(e)):[r],p=d.flatMap(e=>f.map(t=>[e,t])),m=([e,t])=>+(e!==n)+ +(t!==r);p.sort((e,t)=>m(e)-m(t));let h=p[0],g=1/0;for(let n of p){let[r,i]=n,a=Xt(e.shape,e,r,0),o=Xt(t.shape,t,i,0),s=kt({kind:`cubic`,segs:Ct(a,Jt[r],o,Jt[i],[])}),c=0;for(let e of u)s.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)&&c++;if(!c)return n;c<g&&([h,g]=[n,c])}return h}let ft=(e,t)=>e&&(e===`none`||Ft.has(e))?e:t;function pt(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=/* @__PURE__ */ 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,s=new Map(e.edges.map(e=>[e.key,e])),c=/* @__PURE__ */ new Map;for(let l of e.edges){let u=t.get(l.from),d=t.get(l.to);if(!u||!d)continue;let f=Ke(e,l),p=$e(e,l,f,n.theme,n.defaultCurve),m=e.layout.edges[l.key],h=!!m?.via?.length,g=(h?m.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),_=u!==d&&!g.length?a.get(i(l.from,l.to)):void 0;if(_&&_.length>1){let[t,r]=l.from<l.to?[u,d]:[d,u],i=at(rt(tt(r),tt(t))),a=c.get(_);if(!a){let t=_.map(t=>{let r=s.get(t),a=r?.label?Ge(Ke(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
2
+ `).map(e=>Te(e,a.size,a.weight,n.theme.mono,n.measure)))+18:0;return Math.max(o,Math.abs(i.y)*c+Math.abs(i.x)*o+6)}),r=t.reduce((e,t)=>e+t,0);a=/* @__PURE__ */ new Map;let l=0;for(let e=0;e<_.length;e++)a.set(_[e],l+t[e]/2-r/2),l+=t[e];c.set(_,a)}let f=a.get(l.key),p=tt(u),m=tt(d);f&&g.push(nt({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},f))}let v=m?.ports?.[0]??f.exit??f[`from-side`],y=m?.ports?.[1]??f.enter??f[`to-side`],b=et.includes(v)?v:null,x=et.includes(y)?y:null,S=b??st(u,g[0]??tt(d),g.length?null:d,n.direction),C=x??st(d,g[g.length-1]??tt(u),g.length?null:u,n.direction);g.length||u===d||b&&x||([S,C]=dt(u,d,S,C,!b,!x,n.obstacles)),r.push({e:l,a:u,b:d,via:g,manualVia:h,sides:u===d?[`right`,`top`]:[S,C],t:[0,0],style:p,headKind:l.endHead||f.head?ft(f.head,`arrow`):`none`,tailKind:l.startHead||f.tail?ft(f.tail,`arrow`):`none`,labelOff:m?.label})}let l=/* @__PURE__ */ 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]??tt(e.b):e.via[e.via.length-1]??tt(e.a),i=`${n.id}\u0000${e.sides[t]}`;l.has(i)||l.set(i,[]),l.get(i).push({it:e,end:t,other:r})}for(let[e,t]of l){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=>mt(e,n))}function mt(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,nt(o,{x:52,y:0}),nt(s,{x:0,y:-52}),s]]};else{o=Xt(n.shape,n,e.sides[0],e.t[0]),s=Xt(r.shape,r,e.sides[1],e.t[1]);let c=Jt[e.sides[0]],l=Jt[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let i=e.via.map(e=>({...e}));i[0].y=o.y,i[i.length-1].y=s.y,a={kind:`poly`,pts:wt(o,c,s,l,i,n,r,t.obstacles),radius:10}}else a=i.curve===`orthogonal`?{kind:`poly`,pts:wt(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:Ct(o,c,s,l,e.via)}}let c=kt(a),l,u=e.e.props.caption;if(e.e.label||u){let n=i.fontSize,{mono:r}=t.theme,a=e.e.label?e.e.label.split(`
3
+ `):[],o=a.length?Math.max(...a.map(e=>Te(e,n,i.fontWeight,r,t.measure)))+(t.theme.edge.labelStroke?18:12):0,s=De(a,n),d=a.length?a.length*s+6:0,f=n*.88,p=u?u.split(`
4
+ `):[],m=p.length?Math.max(...p.map(e=>Te(e,f,400,r,t.measure)))+8:0,h=De(p,f),g=p.length*h+(p.length?4:0),_=Math.max(o,m)/2,v=d?-d/2:0,y=(d?d/2:0)+g,b=e.e.props.rotate===`true`||e.e.props.rotate===``,x=e=>b?{x:e.x+v,y:e.y-_,w:y-v,h:_*2}:{x:e.x-_,y:e.y+v,w:_*2,h:y-v},S=e.labelOff?nt(jt(c),e.labelOff):vt(c,x,e,t),C=x(S);l={text:e.e.label??``,caption:u,...C,anchor:S,pill:{w:o,h:d},lineHeight:s,captionLineHeight:h,rotate:b}}let d=[],f=yt(i.width),p=xt(a,`end`),m=xt(a,`start`);return e.headKind!==`none`&&(d.push({at:s,angle:Math.atan2(p.y,p.x),kind:e.headKind}),St(a,`end`,bt(e.headKind,f,i.width))),e.tailKind!==`none`&&(d.push({at:o,angle:Math.atan2(m.y,m.x),kind:e.tailKind}),St(a,`start`,bt(e.tailKind,f,i.width))),{key:e.e.key,decl:e.e,d:Nt(a),samples:c,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:l,heads:d,style:i}}let ht=[.5,.42,.58,.34,.66,.26,.74],gt=(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,_t=(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 vt(e,t,n,r){let i=Mt(e,.5),a=1/0;for(let n of ht){let o=Mt(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)gt(s,e)&&(c+=4);for(let e of r.groups??[])gt(s,e.header)?c+=3:gt(s,e.box)&&!_t(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}let yt=e=>7+e*2;function bt(e,t,n){let r=Ft.get(e);return r?typeof r.inset==`function`?r.inset(t,n):r.inset??0:0}function xt(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(ot(n[e],n[n.length-1])>.5)return at(rt(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(ot(n[e],n[0])>.5)return at(rt(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return at(rt(r,ot(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return at(rt(n,ot(r,n)>.5?r:i))}function St(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=ot(r[i],r[a]);if(o<.5)return;r[i]=nt(r[i],at(rt(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=at(rt(ot(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=nt(t[3],r,n),ot(t[2],t[3])<n&&(t[2]=nt(t[3],r,n))}else{let t=e.segs[0],r=at(rt(ot(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=nt(t[0],r,n)}}}function Ct(e,t,n,r,i){if(!i.length){let i=ot(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,nt(e,t,o),nt(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}:at(rt(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=ot(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],nt(a[e],o[e],n),nt(a[e+1],o[e+1],-r),a[e+1]])}return s}function wt(e,t,n,r,i,a,o,s){let c=nt(e,t,18),l=nt(n,r,18),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=1/0,_=1/0,v=-1/0,y=-1/0;for(let e of[...u,...h.flat(),l,n])g=Math.min(g,e.x),_=Math.min(_,e.y),v=Math.max(v,e.x),y=Math.max(y,e.y);let b=s.filter(e=>e.x<v&&e.x+e.w>g&&e.y<y&&e.y+e.h>_),x=null,S=1/0;for(let e of h){let t=Et([...u,...e,l,n]),r=Ot(t,b);r<S&&(S=r,x=t)}return x}function Tt(e){let t=[];for(let n of e)(!t.length||ot(t[t.length-1],n)>.5)&&t.push(n);return t}function Et(e){let t=Tt(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=at(rt(t[e],r)),o=at(rt(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 Dt(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 Ot(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=ot(e[a-1],e[a]),a>=2){let t=at(rt(e[a-1],e[a-2])),n=at(rt(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)Dt(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}function kt(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(At(n,r,i,a,e/16));return t}function At(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 jt(e){return Mt(e,.5)}function Mt(e,t){let n=0;for(let t=1;t<e.length;t++)n+=ot(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=ot(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 Nt(e){if(e.kind===`cubic`){let t=`M${W(e.segs[0][0].x)},${W(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${W(n.x)},${W(n.y)} ${W(r.x)},${W(r.y)} ${W(i.x)},${W(i.y)}`;return t}let t=Tt(e.pts),n=`M${W(t[0].x)},${W(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,ot(i,a)/2,ot(a,o)/2);if(s<.5){n+=`L${W(a.x)},${W(a.y)}`;continue}let c=nt(a,at(rt(i,a)),s),l=nt(a,at(rt(o,a)),s);n+=`L${W(c.x)},${W(c.y)}Q${W(a.x)},${W(a.y)} ${W(l.x)},${W(l.y)}`}let r=t[t.length-1];return n+`L${W(r.x)},${W(r.y)}`}let Pt=/* @__PURE__ */ new Map,Ft=/* @__PURE__ */ new Map,It=[],Lt=[];function Rt(e,t,n,r,i,a=yt(i)){let o=Ft.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}let zt=[],Bt=u({});function Vt(e){if(!e)return`rounded`;let t=e.toLowerCase();return Pt.has(t)?t:Bt[t]??`rounded`}function Ht(e,t){return{w:Math.max(e+44,96),h:Math.max(t+28,48)}}function Ut(e,t,n){return Pt.get(e)?.size?.(t,n)??Ht(t,n)}function Wt(e){return Pt.get(e)?.textOffset??0}let G=e=>(Math.round(e*100)/100).toString();function Gt(e,t,n){let r=Pt.get(e);return r?r.path(t,n):qt(t.x,t.y,t.w,t.h,Math.min(n,t.w/2,t.h/2))}function Kt(e,t){return Pt.get(e)?.detail?.(t)??null}function qt(e,t,n,r,i){return i<=0?`M${G(e)},${G(t)}h${G(n)}v${G(r)}h${G(-n)}Z`:`M${G(e+i)},${G(t)}H${G(e+n-i)}A${G(i)},${G(i)} 0 0 1 ${G(e+n)},${G(t+i)}V${G(t+r-i)}A${G(i)},${G(i)} 0 0 1 ${G(e+n-i)},${G(t+r)}H${G(e+i)}A${G(i)},${G(i)} 0 0 1 ${G(e)},${G(t+r-i)}V${G(t+i)}A${G(i)},${G(i)} 0 0 1 ${G(e+i)},${G(t)}Z`}let Jt={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function Yt(e,t,n,r=.75,i){let a=e.x+e.w/2,o=e.y+e.h/2,s=Math.max(-1,Math.min(1,n))*r,c=t===`top`||t===`bottom`,l=t===`bottom`||t===`right`?1:-1,u=s*(c?e.w/2:e.h/2),d=i?i(c,s,u):c?e.h/2:e.w/2;return c?{x:a+u,y:o+l*d}:{x:a+l*d,y:o+u}}function Xt(e,t,n,r){let i=Pt.get(e);return i?.port?i.port(t,n,r):Yt(t,n,r)}let Zt=[`smooth`,`orthogonal`,`straight`],Qt=[`none`],$t=[`top`,`right`,`bottom`,`left`,`auto`],en=[`below`,`above`,`right-of`,`left-of`,`rank`],tn=[`text`,`font-size`,`font-weight`,`italic`],nn=[`shape`,`color`,`fill`,`stroke`,...tn,`sub`,`sub-color`,`icon`,`border`,`stroke-width`,`border-style`,`dashed`,`dotted`,`radius`,`bold`,`shadow`,`opacity`,`width`,`height`,`link`,`tooltip`,`meta`,`caps`,`mono`,`body-size`,`body-color`,`body-weight`,`line-height`,`max-width`,...en],rn=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...tn,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`],an=[`color`,`fill`,`stroke`,...tn,`border-style`,`dashed`,`dotted`,`meta`,`caps`],on=[`color`,`theme`,`background`,`fill`,`border`,`stroke`,...tn,`border-width`,`border-style`,`radius`,`shadow`,`frame`,`edge-color`,`edge-width`],sn=u({shape:[...zt,...Object.keys(Bt)],"border-style":P,style:P,curve:Zt,head:Qt,tail:Qt,exit:$t,"from-side":$t,enter:$t,"to-side":$t}),cn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],ln=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!I(e),un=e=>hn(e,p)||`: use a palette name (${p.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`,dn=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`],fn=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`];function pn(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 mn(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=pn(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function hn(e,t){let[n,r]=mn(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function gn(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let e=a?.[o]??r;if(!t.includes(o)){n===`node`&&rn.includes(o)?i(e,`"${o}" is an edge prop, but here it is on a node. On an edge line, edge props go after a colon: a -> b: [${o}]`):i(e,`Unknown ${n} prop "${o}"${hn(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let c=sn[o],l=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(cn.includes(o)&&ln(s))i(e,`Unknown ${o} "${s}"${un(s)}`);else if(c&&!c.includes(l)){let t=o===`shape`?zt:c;i(e,`Unknown ${o} "${s}"${hn(s,c)||` (use one of: ${t.join(`, `)})`}`)}else dn.includes(o)&&![`true`,`false`].includes(s)?i(e,`${o} expects true or false, got "${s}"`):fn.includes(o)&&!(parseFloat(s)>=0&&Number.isFinite(parseFloat(s)))?i(e,`${o} expects a number of 0 or more, got "${s}"`):o===`link`&&!fe(s)&&i(e,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function _n(e,t,n,r){if(t)for(let[i,a]of Object.entries(e)){let e=t[i];e!==void 0&&e!==`text`&&(e===`color`?I(a)||r(n,`Unknown ${i} "${a}"${hn(a,p)||`: use a palette name, #hex, rgb(), hsl() or a CSS colour name`}`):e===`number`?Number.isFinite(parseFloat(a))||r(n,`${i} expects a number, got "${a}"`):e===`flag`?[`true`,`false`].includes(a)||r(n,`${i} expects true or false, got "${a}"`):e.includes(a.toLowerCase())||r(n,`Unknown ${i} "${a}"${hn(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}let vn=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function yn(e){for(let[t,n]of Object.entries(e))if(en.includes(t)&&n)return[t,n.trim()]}function bn(e,t){let n=/* @__PURE__ */ new Map;for(let r of e.nodes.values()){let i=Ke(e,r),a=yn(i);if(!a)continue;let[o,s]=a,c=vn(r,o);for(let e of Object.keys(i))e!==o&&en.includes(e)&&r.ref&&t(vn(r,e),`${r.id} already has ${o}: ${s}, so ${e} is ignored. A node takes one placement prop`);if(s===r.id)r.ref&&t(c,`${o}: ${s} places ${r.id} next to itself; use another node's id`);else if(e.nodes.has(s))n.set(r.id,s);else{if(!r.ref)continue;e.groups.has(s)?t(c,`${o}: ${s} names a group; placement takes a node id`):t(c,`${o}: unknown node "${s}"${hn(s,[...e.nodes.keys()])}`)}}let r=/* @__PURE__ */ new Set;for(let i of n.keys()){let a=[],o=i;for(;o!==void 0&&!a.includes(o);)a.push(o),o=n.get(o);if(o!==i||r.has(i))continue;a.forEach(e=>r.add(e));let s=e.nodes.get(i),c=yn(Ke(e,s))[0];s.ref&&t(vn(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}let xn=e=>e.toLowerCase().replace(/\d+/g,`#`);function Sn(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:xn(e.id)}));if(!r.length||n.every(e=>!e.implicit||e.id.length<3))return;let i=/* @__PURE__ */ new Map;for(let t of e.edges)if(t.ref)for(let e of[t.from,t.to])i.has(e)||i.set(e,t.ref.line);for(let e of n){let n=i.get(e.id);if(!e.implicit||e.id.length<3||n===void 0)continue;let a=xn(e.id),o=e.id.length<7?1:2,s=r.filter(t=>t.series!==a&&Math.abs(t.id.length-e.id.length)<=o),[c,l]=mn(e.id,s.map(e=>e.id));l<=o&&t(n,`Node "${e.id}" is only used in edges (did you mean "${c}"?). If it is a separate node, declare it: ${e.id} "Label"`)}}function Cn(e,t){let n=(t,n)=>e.diagnostics.push({line:t+1,message:n,severity:`warning`});for(let t of e.nodes.values())t.ref&&gn(t.props,nn,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});bn(e,n);let r=/* @__PURE__ */ new Set;for(let t of e.edges){if(!t.ref)continue;let e=t.ref.line;r.has(e)||(r.add(e),gn(t.props,rn,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&gn(t.props,an,`group`,t.ref.line,n,t.ref.propLines);Sn(e,n);let i=oe(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)&&n(e,`Unknown theme "${a.theme}"${hn(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of cn)a[t]&&ln(a[t])&&n(e,`Unknown ${t} "${a[t]}"${un(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!I(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!P.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${P.join(`, `)})`),_n(a,t?.(r.kind),e,n)}let a=[.../* @__PURE__ */ new Set([...nn,...rn,...an])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&gn(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}let wn=Object.keys(re),Tn=/* @__PURE__ */ new Set([`title`,`subtitle`,`theme`,`accent`,`direction`,`curve`,`gap`,`rank-gap`,`max-width`,`font`,`font-size`,`background`,`padding`,`shadow`,`radius`,`stroke-width`,`shape`,`grid`,`panels`,`panel-gap`,`wrap`,`edge-color`,`edge-width`]),En=u({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`,tree:`treeview ID`,filetree:`treeview ID`}),Dn=/* @__PURE__ */ new Map,On=/* @__PURE__ */ new Map,kn=[],An=u({direction:[`right`,`down`,`left`,`up`],curve:[`smooth`,`orthogonal`,`straight`],panels:[`row`,`column`,`grid`,`wrap`]}),jn=u({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),Mn=/* @__PURE__ */ new Set([...p,`violet`]),Nn=/* @__PURE__ */ new Set([`smooth`,`orthogonal`,`straight`]),Pn=e=>Pt.has(e)||e in Bt,Fn=e=>/\.(yu|yuhwa)$/i.test(e);function In(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(`/`)}let Ln=/* @__PURE__ */ new Set([`top`,`right`,`bottom`,`left`,`auto`]),Rn=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,zn=/^(<)?(--|-|\.\.|==|=)(>)?/,Bn=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,Vn=/^-?\d+(?:\.\d+)?/;function Hn(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
+ `:t===`t`?` `:t)}function Un(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:Hn(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(Bn)){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(Rn)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Vn)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(zn)){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 Wn(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 Gn(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function Kn(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)`),{}):K(e.value)}let qn=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function K(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();Mn.has(e)?t.color=e:Pn(e)?t.shape=e:Nn.has(e)?t.curve=e:I(n)?t.color=n:t[e]=`true`;continue}let i=qn(n.slice(0,r)),a=n.slice(r+1).trim();/^(["']).*\1$/s.test(a)&&(a=Hn(a.slice(1,-1))),t[i]=a}return t}let Jn=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},Yn=/(?<!\[)\[([^[\]]*)\]\s*$/;function Xn(e,t){let n=e.match(Yn),r=n?K(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function Zn(e,t,n){let r=qn(t),[i,a]=Xn(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=er(a);return s?`${o} [${s}]`:o}let Qn=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&I(e.color)};function $n(e,t,n,r,i){let a=qn(n),[o,s]=Xn(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}=K(n),l=er(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=er(s);return u?`${l} [${u}]`:l}function er(e){return Object.entries(e).map(([e,t])=>t===`true`&&!Mn.has(e)&&!Pn(e)&&!Nn.has(e)&&!I(e)?e:e===`color`&&I(t)&&!Pn(t)&&!Nn.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(t)?ur(t):t}`).join(`, `)}function tr(e){let t=e.match(zn),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}}let nr=1e5,rr=5e4,ir=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,ar=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,or=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,sr=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,cr=/* @__PURE__ */ new WeakMap;function lr(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}let ur=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,dr=e=>/^(["']).*\1$/s.test(e.trim())?Hn(e.trim().slice(1,-1)):e.trim();function fr(e,t={}){let i={settings:{},nodes:/* @__PURE__ */ new Map,edges:[],groups:/* @__PURE__ */ new Map,classes:u({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},a=e.split(/\r?\n/),o=t.seen??=/* @__PURE__ */ new Set;t.file&&o.add(t.file);let s=/* @__PURE__ */ new Map,c=[],d=(e,t)=>c.push([e,t]),f=!1,m=[],h=/* @__PURE__ */ new Map,g=(e,t,n=`warning`)=>i.diagnostics.push({line:e+1,message:t,severity:n}),_,v=(e,t,n,r)=>{if(!(t in re))return g(r,`Unknown theme key "${t}"${hn(t,wn)||` (keys: ${wn.join(`, `)})`}`);re[t].kind!==`color`||[`none`,`transparent`].includes(n)||n.includes(`$`)||I(n)||g(r,`Unknown color "${n}" for ${t}${hn(n,p)}`),e[t]=n},y=/* @__PURE__ */ new Map,b=(e,t,n)=>{y.has(e)&&g(n,`Theme "${e}" is defined twice`),(i.themes??=u({}))[e]=t,y.set(e,n)},x=()=>{for(let e=m.length-1;e>=0;e--)if(m[e].kind===`group`)return m[e].id},S=e=>{let t=i.nodes.get(e);return t||(t={id:e,label:e,props:{},classes:[],implicit:!0,group:x()},i.nodes.set(e,t)),t},C=/* @__PURE__ */ new Map,w=(e,t,n,r)=>{let i=t.value;e.labelRef={line:n,at:t.start,range:[t.start,t.end],generated:A||void 0};let a=C.get(e.id);a!==void 0&&e.label!==i&&g(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,C.set(e.id,n)},T=/* @__PURE__ */ new Map,E=(e,n,r)=>{if(!t.resolve)return g(n,`Cannot import "${e}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let a=In(t.file,e);if(!Fn(a))return g(n,`Cannot import "${e}": imports must be .yu files`,`error`);let s=[...t.chain??(t.file?[t.file]:[])];if(s.includes(a))return g(n,`Import cycle: ${[...s,a].join(` -> `)}`,`error`);let c=r?`${a}{${r.map(e=>e.join(` as `)).join(`,`)}}`:a;if(o.has(c))return;let l;try{l=t.resolve(a)}catch{l=void 0}if(l===void 0)return g(n,`Cannot import "${e}": file not found (${a})`,`error`);let u=new Set(o),d=fr(l,{resolve:t.resolve,file:a,chain:[...s,a],seen:u});for(let t of d.diagnostics)g(n,`${e}:${t.line}: ${t.message}`,t.severity);let f=mr(d,r,t=>g(n,`${e}: ${t}`,`error`));if(f===d)for(let e of u)o.add(e);o.add(c),hr(i,f,h),(i.imports??=[]).push(a,...d.imports??[])},D=i.vars=u({}),O=i.defs=u({}),k=i.used=/* @__PURE__ */ new Set;cr.set(O,O);let A=!1,j=0,ee=0,M=/* @__PURE__ */ new Set,te=null,N=e=>e.match(/^\s*/)[0].length,P=(e,t,n,r=!1)=>{let i=e.match(ar);if(i)return e.slice(0,e.length-i[2].length)+P(i[2],t,n,r);let a=e.length,o=e.replace(ir,(e,i,o)=>{let s=i??o;if(!s)return`$`;let c=n?.[s]??D[s];return n?.[s]===void 0&&c!==void 0&&k.add(`$`+s),c===void 0?(r||g(t,`Unknown variable "$${s}"${hn(s,[...Object.keys(n??{}),...Object.keys(D)])}`),e):(a+=c.length)>nr?e:c});return a>nr&&g(t,`Variables make this line longer than ${nr} characters`,`error`),o},ne=(e,t,n)=>{if(j>=16){M.has(e.name)||g(n,`${e.name}(): calls nest too deep`,`error`),M.add(e.name);return}if((ee+=e.body.length)>rr){ee-e.body.length<=rr&&g(n,`${e.name}(): components expand to more than ${rr} lines`,`error`);return}let r=lr(t),i=u({}),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]]=dr(o[2]);else if(a<e.params.length)i[e.params[a++].name]=dr(t);else return void g(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 g(n,`${e.name}(): missing argument "${t.name}" (${e.params.map(e=>e.name).join(`, `)})`,`error`);i[t.name]=t.default}let o=m.length,s=A;A=!0,j++;let c=e.body.map(e=>P(e,n,i)),l=cr.get(e)??O;for(let e of c)F(e,n,!0,l);j--,A=s,m.length>o&&(g(n,`${e.name}(): a block inside the component is not closed`,`error`),m.length=o)},F=(e,t,n=!1,r=O)=>{if(/^\s*#(\s|$)/.test(e))return void g(t,`Comments start with "//", not "#"`,`error`);let a=m[m.length-1];if(a?.kind===`def`){for(let t of Wn(Un(e).tokens))a.depth+=t===`{`?1:-1;if(a.depth>0)return void a.lines.push(e);m.pop(),e.trim()!==`}`&&g(t,`Expected "}" alone on the line that closes ${a.id}()`,`error`);let n=a.params,o=u(Object.fromEntries(n.map(e=>[e.name,`\${${e.name}}`]))),s={name:a.id,params:n,body:je(a.lines).map(e=>P(e,t,o,!0))};cr.set(s,r),O[s.name]&&g(a.start,`Component "${s.name}" is defined twice`),O[s.name]=s,(i.defLines??={})[s.name]=a.start;return}let o=a?.kind===`body`||a?.kind===`panel`;if(!o&&a?.kind!==`layout`){let a=e.match(ar);if(a){D[a[1]]=dr(Jn(n?a[2]:P(a[2],t)).trimEnd()),(i.varLines??={})[a[1]]=t;return}let o=e.match(or);if(o){m.length&&g(t,`def must be at the top level`,`error`);let e=lr(o[2]).map(e=>{let n=e.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return n||g(t,`Bad parameter "${e}": def name(a, b = "default") {`,`error`),{name:n?.[1]??e,default:n?.[2]===void 0?void 0:dr(n[2])}});m.push({kind:`def`,id:o[1],start:t,lines:[],depth:1,params:e});return}let s=Jn(e).match(sr);if(s){let i=r[s[1]]??O[s[1]];if(i){k.add(s[1]),ne(i,n?s[2]:P(s[2],t),t);return}if(!Un(e).tokens.some(e=>e.kind===`arrow`))return void g(t,`Unknown component "${s[1]}"${hn(s[1],Object.keys(O))}`,`error`)}}let s=n||a?.kind===`layout`||!o&&/^\s*(import|export)\b/.test(e)?e:P(e,t,void 0,o),c=A;A||=s!==e,xe(s,t),A=c},ie=(e,t,n)=>{if(t.trim()===`}`){m.pop();let t=i.nodes.get(e.id);t.body=je(e.lines),t.bodyLines=[e.start,n]}else e.lines.push(t)},ae=(e,t,n)=>{t.trim()===`}`?(m.pop(),se(e,n)):e.lines.push(t.slice(0,Un(t).codeEnd).trimEnd())},se=(e,t)=>{let n=e.panel,i=e.lines.findIndex(e=>e.trim());n.body=je(e.lines),n.lines=[e.start,t];try{n.data=Dn.get(n.kind).parse(n.body,n.props,(t,n)=>g(t<0?e.start:e.start+1+Math.max(0,i)+t,n))}catch(t){let i=l(`panel`,n.kind);g(e.start,`${i?`plugin "${i}": `:``}${n.kind} panel failed to parse: ${r(t)}`,`error`),n.failed=!0}},ce=(e,t,n)=>{let r=t.slice(0,Un(t).codeEnd).trim();if(!r)return;if(r===`}`){m.pop(),b(e.id,e.props,e.start);return}let i=r.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);if(!i)return void g(n,`Expected "key: value" in theme ${e.id} (keys: ${wn.join(`, `)})`,`error`);v(e.props,i[1].toLowerCase(),dr(i[2].trim()),n)},le=(e,t)=>{let n=e.slice(0,Un(e).codeEnd).trim();n&&(n.startsWith(`}`)?(m.pop(),i.layoutBlock[1]=t):(T.set(n.split(/\s+/)[0],t),vr(n,t,i,g)))},ue=e=>{m.length?m.pop():g(e,`Unmatched "}"`,`error`),te=null},L=(e,t,n)=>{if(m.length)g(t,`import must be at the top level`,`error`);else if(!e[1])g(t,`import needs a path: import "./shared.yu"`,`error`);else if(!n)e.length>2&&g(t,`Unexpected "${e[2].value}" after import path`,`error`),E(e[1].value,t);else{let n=pr(e,t,g);n&&E(n.path,t,n.names)}},de=(e,t,n)=>{m.length&&g(n,`export must be at the top level`,`error`);let r=e[1].kind===`ident`&&e[2]?.value===`:`&&Tn.has(e[1].value.toLowerCase());if(r||e[1].value===`theme`&&e[2]?.kind===`ident`){let a=e[1].value.toLowerCase();return r&&!i.sharedSettings?.includes(a)&&(i.sharedSettings??=[]).push(a),F(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)}f=!0;let a=e.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),o=e=>s.has(e)||s.set(e,n);if(e[1].value===`def`&&e[2])o(e[2].value);else if(e[1].value.startsWith(`$`)&&(e[2]?.value===`:`||e[2]?.value===`=`))o(e[1].value);else for(let t of e.slice(1))(t.kind===`ident`||t.kind===`class`)&&o(t.kind===`class`?`.${t.value}`:t.value);if(!a||e.slice(1).some(e=>e.kind===`ident`&&Dn.has(e.value)))return F(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)},fe=(e,t)=>{m.length&&g(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(K(e[r].value)))v(n,i,a,t);r++}if(e[r]?.value===`{`){if(r++,e[r]?.value===`}`)r++;else if(r===e.length)return void m.push({kind:`theme`,id:e[1].value,start:t,props:n})}r<e.length&&g(t,`Unexpected "${e[r].value}" in theme ${e[1].value}`,`error`),b(e[1].value,n,t)},pe=(e,t)=>{g(t,`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...Dn.keys()].join(`, `)})`+(En[e[0].value]&&Dn.has(En[e[0].value].split(` `)[0])?`: write "${En[e[0].value].replace(`ID`,e[1].value)} {"`:``))},me=(e,t)=>{let n=e[0].value,r=1,a=e[r]?.kind===`ident`?e[r++].value:`${n}${i.panels.length+1}`,o=A?void 0:e[r]?.kind===`string`?{line:t,at:e[r].start,range:[e[r].start,e[r].end]}:{line:t,at:e[r-1].end},s=e[r]?.kind===`string`?e[r++].value:void 0,c={line:t,insertAt:e[r-1].end},l={};e[r]?.kind===`props`&&(l=K(e[r].value),c.props=[e[r].start,e[r].end],r++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,r!==e.length-1&&g(t,`Unexpected "${e[r].value}" in ${n} header`,`error`),m.length&&g(t,`${n} must be at the top level`,`error`);let u={kind:n,id:a,label:s,props:l,body:[],data:void 0,ref:A?void 0:c,labelRef:o};i.panels.push(u),m.push({kind:`panel`,id:a,start:t,lines:[],panel:u})},he=(e,t)=>{m.length&&g(t,`layout block must be at top level`,`error`),i.layoutBlock=[t,t],e[2]?.value!==`}`&&m.push({kind:`layout`})},ge=(e,t,n)=>{let r=2,a=e[1].value;e[1].kind===`string`&&(a=e[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,r=1);let o=i.groups.get(a)??{id:a,label:a,props:{},parent:x()};if(e[r]?.kind===`string`){let t=e[r++];o.label=t.value,o.labelRef={line:n,at:t.start,range:[t.start,t.end],id:r===2?a:void 0}}else o.labelRef??={line:n,at:e[1].end};for(A&&(o.labelRef.generated=!0);e[r]?.kind===`class`;)d(e[r].value,n),(o.classes??=[]).push(e[r++].value);let s={line:n,insertAt:e[r-1].end,generated:A||void 0};if(e[r]?.kind===`props`&&(Object.assign(o.props,K(e[r].value)),s.props=[e[r].start,e[r].end],r++),o.ref=s,te={indent:N(t),targets:[o]},i.groups.set(a,o),e[r]?.value!==`{`){g(n,`Expected "{" after group ${a}`,`error`);return}r++;let c=e.findIndex((e,t)=>t>=r&&e.value===`}`);if(c>=0){for(let t=r;t<c;t++)if(e[t].kind===`ident`){let n=S(e[t].value);n.group=a}}else m.push({kind:`group`,id:a})},_e=(e,t,n)=>{let r=e[e.length-1],a={};for(let t of e.slice(1))t.kind===`class`&&(i.classes[t.value]?Object.assign(a,i.classes[t.value]):g(n,`Unknown class ".${t.value}"${hn(t.value,Object.keys(i.classes))}`));i.classes[e[0].value]={...i.classes[e[0].value],...a,...r.kind===`props`?K(r.value):{}},(i.classLines??={})[e[0].value]=n,te={indent:N(t),targets:[{props:i.classes[e[0].value]}]}},ve=(e,t,n,r,a)=>{let o=qn(e[0].value),s=t.slice(e[1].end,r).trim();/^(["']).*\1$/.test(s)&&(s=Hn(s.slice(1,-1)));let c=te&&N(t)>te.indent?te.targets:null,l=a?.kind===`group`?i.groups.get(a.id):void 0,u=c??(l?[l]:null);if(u){for(let e of u)e.props[o]=s||`true`,e.ref&&!A&&((e.ref.propLines??={})[o]=n);return}if(m.length&&g(n,`Setting "${o}" should be at the top level`),!Tn.has(o)){let t=e[0].value,r=s.startsWith(`{`)?`${t} [${s.slice(1,-1).trim()}]`:`${t} "${s}"`;g(n,`Unknown setting "${o}"${hn(o,[...Tn])||`. For a node write ${r}`}`);return}o===`direction`&&(s=jn[s.toLowerCase()]??s),o===`theme`&&(_=n);let d=o===`theme`?void 0:An[o];d&&s&&!s.includes(`$`)&&!d.includes(s)&&g(n,`Unknown ${o} "${s}"${hn(s,d)||` (use one of: ${d.join(`, `)})`}`),i.settings[o]=s},ye=(e,t,n,r)=>{let a=i.edges.length;if(gr(e,n,t.slice(0,r),i,S,h,g,w,d),te={indent:N(t),targets:i.edges.slice(a)},A){for(let e of i.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=i.nodes.get(t.value);e?.ref?.line===n&&(e.ref.generated=!0),e?.labelRef?.line===n&&(e.labelRef.generated=!0)}}},be=(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();g(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`);m.push({kind:`body`,id:t.value,start:n,lines:[]});break}if(a.kind!==`ident`){g(n,`Unexpected "${a.value}"`,`error`);break}i=!1;let o=S(a.value);o.implicit=!1;let s=x();for(s&&o.group&&o.group!==s&&g(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`?w(o,e[r++],n,!1):o.labelRef??={line:n,at:a.end,generated:A||void 0};e[r]?.kind===`class`;){let t=e[r++].value;d(t,n),o.classes.includes(t)||o.classes.push(t)}let c={line:n,insertAt:e[r-1].end,generated:A||void 0};e[r]?.kind===`props`&&(Gn(o,Kn(e[r],o.id,n,g),n),c.props=[e[r].start,e[r].end],r++),o.ref=c,te={indent:N(t),targets:[o]}}},xe=(e,t)=>{let n=m[m.length-1];if(n?.kind===`body`)return ie(n,e,t);if(n?.kind===`panel`)return ae(n,e,t);if(n?.kind===`theme`)return ce(n,e,t);if(n?.kind===`layout`)return le(e,t);let{tokens:r,codeEnd:a}=Un(e);if(!r.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 g(t,o,`error`);if(r[0].kind===`punct`&&r[0].value===`}`)return ue(t);let s=r[0].kind===`ident`?r[0].value:void 0,c=r[1]?.value===`{`&&r.some(e=>e.kind===`ident`&&e.value===`from`);if(s===`import`&&(r[1]?.kind===`string`||r.length===1||c))return L(r,t,c);if(s===`export`&&r.length>1&&r[1].kind!==`arrow`&&r[1].value!==`:`)return de(r,e,t);let l=s===void 0?void 0:On.get(s);if(l&&r[1]?.kind!==`arrow`&&r[1]?.value!==`:`&&r[1]?.value!==`,`)return void l.parse(e.slice(r[0].end,a).trim(),i,{line:t,warn:(e,n)=>g(t,e,n)});if(s===`theme`&&r[1]?.kind===`ident`&&(r[2]?.kind===`props`||r[2]?.value===`{`))return fe(r,t);let u=r[r.length-1].value===`{`;if(s!==void 0&&r.length>2&&!Dn.has(s)&&r[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&pe(r,t),s!==void 0&&Dn.has(s)&&u&&(r[1]?.kind===`ident`||r[1]?.kind===`string`||r[1]?.kind===`props`||r[1]?.value===`{`))return me(r,t);if(s===`layout`&&r[1]?.value===`{`)return he(r,t);if(s===`group`&&(r[1]?.kind===`ident`||r[1]?.kind===`string`&&r.some(e=>e.value===`{`)))return ge(r,e,t);let d=r[r.length-1];if(r[0].kind===`class`&&r.slice(1,-1).every(e=>e.kind===`class`)&&(d.kind===`props`||d.kind===`class`))return _e(r,e,t);if(s!==void 0&&r[1]?.kind===`punct`&&r[1].value===`:`)return ve(r,e,t,a,n);if(r.some(e=>e.kind===`arrow`))return ye(r,e,t,a);be(r,e,t)};for(let e=0;e<a.length;e++)F(a[e],e);for(let e of m)e.kind===`group`?g(a.length-1,`Group "${e.id}" is missing "}"`,`error`):e.kind===`body`?g(e.start,`Body of "${e.id}" is missing a closing "}" line`,`error`):e.kind===`panel`?(g(e.start,`${e.panel.kind} "${e.id}" is missing a closing "}" line`,`error`),se(e,a.length-1)):e.kind===`def`?g(e.start,`def ${e.id}() is missing "}"`,`error`):e.kind===`theme`?g(e.start,`theme ${e.id} is missing "}"`,`error`):g(a.length-1,`layout block is missing "}"`,`error`);let R=oe(i.themes);for(let[e,t]of y){let n=i.themes[e].base;n&&n!==e&&!R.includes(n)&&g(t,`Unknown base theme "${n}"${hn(n,R)}`)}let Se=i.settings.theme;_!==void 0&&Se&&!Se.includes(`$`)&&(R.includes(Se)||g(_,`Unknown theme "${Se}"${hn(Se,R)||` (use one of: ${R.join(`, `)})`}`));let Ce=/* @__PURE__ */ new Set;for(let[e,t]of c)i.classes[e]||Ce.has(`${t}.${e}`)||(Ce.add(`${t}.${e}`),g(t,`Unknown class ".${e}"`));if(f){let e=new Set(i.panels.map(e=>e.id));i.exports=[...s.keys()].filter(t=>t.startsWith(`.`)?t.slice(1)in i.classes:t.startsWith(`$`)?t.slice(1)in D:i.nodes.has(t)||i.groups.has(t)||e.has(t)||t in O||t in(i.themes??{}));for(let[e,t]of s)!i.exports.includes(e)&&!Dn.has(e)&&e!==`group`&&e!==`def`&&g(t,`export: "${e}" is not declared in this file`)}for(let e of i.panels){i.nodes.get(e.id)?.implicit&&i.nodes.delete(e.id);let t=i.layout.nodes[e.id];t&&(t.x!==void 0&&t.y!==void 0&&(_r(i,e.id).at={x:t.x,y:t.y}),delete i.layout.nodes[e.id])}let we=/* @__PURE__ */ new Map;for(let e of i.panels){let t=we.get(e.id);t?e.lines&&g(e.lines[0],`panel id "${e.id}" is already used${t.lines?` on line ${t.lines[0]+1}`:` by an import`}: layout, edges and edits can't tell them apart, rename one`):we.set(e.id,e)}for(let[e,t]of i.groups)i.nodes.has(e)&&g(i.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`);Cn(i,e=>Dn.get(e)?.options),t.chain||n(i.diagnostics,()=>kn.forEach(e=>e(i)));for(let e of Object.keys(i.layout.nodes)){let t=T.get(e);t!==void 0&&!i.nodes.has(e)&&!i.groups.has(e)&&g(t,`layout: there is no node "${e}" (renamed or deleted?); remove this line${hn(e,[...i.nodes.keys()])}`)}return i}function pr(e,t,n){let r=e.findIndex(e=>e.value===`}`),i=e=>(n(t,`${e}: import { a, b as c, .style } from "./file.yu"`,`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 mr(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ 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:/* @__PURE__ */ new Map,edges:[],groups:/* @__PURE__ */ new Map,classes:u({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},d=e=>a.get(e)?.replace(/^\./,``)??e,f=e=>a.get(`.${e}`)?.slice(1)??e,p=/* @__PURE__ */ new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(l.groups.set(d(t.id),{...t,id:d(t.id),parent:t.parent&&l.groups.has(d(t.parent))?d(t.parent):void 0,classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e)));let m=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(m(t.id)){let e=t.group&&l.groups.has(d(t.group))?d(t.group):void 0;l.nodes.set(d(t.id),{...t,id:d(t.id),group:e,classes:t.classes.map(f)}),t.classes.forEach(e=>p.add(e))}for(let t of e.edges)if(m(t.from)&&m(t.to)){let e=d(t.from)+`->`+d(t.to)+(t.key.match(/#\d+$/)?.[0]??``);l.edges.push({...t,key:e,from:d(t.from),to:d(t.to),classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e))}for(let t of e.panels)o.has(t.id)&&l.panels.push({...t,id:d(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 Un(e).tokens)t.kind===`class`&&p.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}`)||p.has(t))&&(l.classes[f(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 hr(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??=u({}))[n]??=r}function gr(e,t,n,r,i,a,o,s,c){let l=0,u=!1,d=(n=!1)=>{let a=[],d=!0;for(;l<e.length;){if(e[l].kind===`punct`&&e[l].value===`,`){l++,d=!0;continue}if(e[l].kind!==`ident`)break;if(!d){let n=a.pop(),r=[n];for(;e[l]?.kind===`ident`;)r.push(e[l++].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}d=!1;let f=e[l++].value;a.push(f);let p=l,m=!r.nodes.has(f),h=i(f);if(e[l]?.kind===`string`){let r=e[l++],i=r.value;n&&m&&l===e.length&&!u&&/^[a-z][a-z ]*$/.test(i)&&o(t,`"${i}" becomes the label of node "${f}". For an edge label write: ... -> ${f}: ${i}`),s(h,r,t,!0),u=!0}for(;e[l]?.kind===`class`;){let n=e[l++].value;c(n,t),h.classes.includes(n)||h.classes.push(n)}let g=!h.ref||h.implicit;e[l]?.kind===`props`?(Gn(h,Kn(e[l],f,t,o),t),g&&(h.ref={line:t,props:[e[l].start,e[l].end],insertAt:e[l].start}),l++):l>p&&g&&(h.ref={line:t,insertAt:e[l-1].end}),l>p&&(h.implicit=!1),l>p&&g&&!h.labelRef&&(h.labelRef={line:t,at:e[p-1].end})}return a},f=d();if(!f.length){o(t,`Edge needs a source node`,`error`);return}let p=[];for(;l<e.length&&e[l].kind===`arrow`;){let n=e[l++].value,r=d(!0);if(!r.length){o(t,`Edge "${n}" needs a target node`,`error`);return}p.push({from:f,to:r,arrow:n}),f=r}let m,h=[],g={},_={line:t,insertAt:e[l-1].end,prefix:`:`},v={line:t,at:e[l-1].end,colon:!1};if(e[l]?.kind===`punct`&&e[l].value===`:`){_.insertAt=v.at=e[l].end,v.colon=void 0,_.prefix=void 0,l++;let r=l;for(;l<e.length&&e[l].kind!==`class`&&e[l].kind!==`props`;)l++;for(l>r&&(m=l-r===1&&e[r].kind===`string`?e[r].value:n.slice(e[r].start,e[l-1].end).trim(),_.insertAt=e[l-1].end,v.range=[e[r].start,e[l-1].end]);e[l]?.kind===`class`;)c(e[l].value,t),h.push(e[l].value),_.insertAt=e[l++].end;e[l]?.kind===`props`&&(g=K(e[l].value),_.props=[e[l].start,e[l].end],l++)}if(l<e.length){let n=e[l].kind===`string`?` (edge labels go after a colon: a -> b: "label")`:``;o(t,`Unexpected "${e[l].value}" in edge${n}`,`error`)}for(let e of p){let t=tr(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:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(d)}}}let _r=(e,t)=>(e.layout.panels??={})[t]??={};function vr(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(!Ln.has(e)||!Ln.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)`);(_r(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)`);_r(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 yr(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function br(e){let t=/* @__PURE__ */ new WeakMap;return(n,r)=>{let i=t.get(r);if(i&&i.data===n)return i.g;let a=e(n,r);return t.set(r,{data:n,g:a}),a}}function xr(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}}}let q={plugins:[],rows:[],frames:/* @__PURE__ */ new Map,decorations:[],panels:Dn},Sr=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)},Cr=(e,t)=>{for(let n of t??[]){if(e.includes(n.name))continue;let t=e.indexOf(`none`);e.splice(t<0?e.length:t,0,n.name)}},wr=()=>{},Tr=()=>``,Er=()=>({w:0,h:0}),Dr={row:{parse:()=>null,finish:wr,measure:Er,render:Tr},frame:{inset:()=>({top:0}),render:Tr},decoration:{measure:()=>null,render:Tr},shape:{path:e=>qt(e.x,e.y,e.w,e.h,0),size:(e,t)=>({w:e,h:t}),detail:()=>null,port:e=>({x:e.x+e.w/2,y:e.y+e.h/2})},marker:{render:Tr,inset:()=>0},panel:{measure:Er,render:Tr,handles:()=>[],parts:()=>[],editPart:()=>null},hook:{transform:wr,afterLayout:wr,postRender:e=>e}};function Or(e,t,n,r){let i={...n};for(let[o,s]of Object.entries(r)){let r=i[o];typeof r==`function`&&(i[o]=a(e,t(o),r.bind(n),s))}return i}function kr(e){let t=e.name,n=(e,n,r)=>(e??[]).map(e=>Or(t,t=>n(e,t),e,r));return{rows:n(e.rows,e=>`row "${e.kind}"`,Dr.row),frames:n(e.frames,e=>`frame "${e.name}"`,Dr.frame),decorations:n(e.decorations,e=>`decoration "${e.name}"`,Dr.decoration),shapes:n(e.shapes,e=>`shape "${e.name}"`,Dr.shape),markers:n(e.markers,e=>`marker "${e.name}"`,Dr.marker),panels:n(e.panels,(e,t)=>`${e.name} panel ${t===`editPart`?`edit`:t}`,Dr.panel),statements:(e.statements??[]).map(e=>({...e,parse:a(t,e.keyword,e.parse.bind(e),wr,(e,[,,t])=>t.warn(e,`error`))})),hooks:Or(t,e=>e,{transform:e.transform,afterLayout:e.afterLayout,postRender:e.postRender},Dr.hook)}}let Ar;function jr(){let e=[Tn].map(e=>[e,[...e]]),t=[Dn,On,Pt,Ft,q.frames].map(e=>[e,[...e]]),n=[kn,It,Lt,nn,rn,an,dn,fn,C,zt,q.rows,q.decorations].map(e=>[e,[...e]]),r=Object.entries(sn).map(([e,t])=>[e,t,[...t]]),i={...S},a={...Bt};return()=>{for(let[t,n]of e){t.clear();for(let e of n)t.add(e)}for(let[e,n]of t){e.clear();for(let[t,r]of n)e.set(t,r)}for(let[e,t]of n)e.splice(0,e.length,...t);for(let e of Object.keys(sn))delete sn[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),sn[e]=t;for(let e of Object.keys(S))delete S[e];Object.assign(S,i);for(let e of Object.keys(Bt))delete Bt[e];Object.assign(Bt,a),c()}}function Mr(e,t,n){let r=e.findIndex(n);r>=0?e[r]=t:e.push(t)}function Nr(...e){Ar??=jr();for(let t of e){if(q.plugins.some(e=>e.name===t.name))continue;q.plugins.push(t);let e=kr(t),n=(e,n,r,i)=>{for(let a of n){let n=r(a);s(e,n,t.name),typeof i==`function`?i(a,n):i.set(n,a)}};for(let e of t.themes??[])w(e);n(`row`,e.rows,e=>e.kind,(e,t)=>Mr(q.rows,e,e=>e.kind===t)),n(`decoration`,e.decorations,e=>e.name,(e,t)=>{Mr(q.decorations,e,e=>e.name===t),Tn.add(e.setting)}),n(`frame`,e.frames,e=>e.name,q.frames),n(`panel`,e.panels,e=>e.name,Dn),n(`statement`,e.statements,e=>e.keyword,On),n(`marker`,e.markers,e=>e.name,Ft),n(`shape`,e.shapes,e=>e.name,(e,t)=>{Pt.set(t,e),zt.includes(t)||zt.push(t);for(let n of e.aliases??[])Bt[n]=t}),Sr(sn.shape??=[],[...t.shapes?.map(e=>e.name)??[],...t.shapes?.flatMap(e=>e.aliases??[])??[]]),Cr(sn.head??=[],t.markers),sn.tail!==sn.head&&Cr(sn.tail??=[],t.markers);let{transform:r,afterLayout:i,postRender:a}=e.hooks;r&&kn.push(r),i&&It.push(i),a&&Lt.push(a);for(let e of t.settings??[])Tn.add(e);Sr(nn,t.props?.node),Sr(rn,t.props?.edge),Sr(an,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))Sr(sn[e]??=[],n);Sr(dn,t.bools),Sr(fn,t.numbers)}q.frames.size&&Sr(sn.frame??=[],[...q.frames.keys()])}let Pr=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),Fr=new Set(`mwMW@%`.split(``)),Ir=(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:Pr.has(t)?i+=.3:Fr.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},Lr;function Rr(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 Ir(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`:e;return Lr.font=`${r} ${n}px ${a}`,Lr.measureText(t).width}}let zr=(e,t)=>({w:e+44,h:t+28}),Br=(e,t,n)=>Yt(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*Math.sqrt(Math.max(0,1-n*n))),Vr=({x:e,y:t,w:n,h:r})=>{let i=n/2,a=r/2,o=e+i;return`M${B(o-i)},${B(t+a)}a${B(i)},${B(a)} 0 1,0 ${B(i*2)},0a${B(i)},${B(a)} 0 1,0 ${B(-i*2)},0Z`},Hr=(e,t)=>Math.min(t,e.w/2,e.h/2),Ur={name:`shapes`,shapes:[{name:`rounded`,aliases:[`round`],path:(e,t)=>qt(e.x,e.y,e.w,e.h,Hr(e,t))},{name:`box`,aliases:[`rect`,`rectangle`,`square`],path:(e,t)=>qt(e.x,e.y,e.w,e.h,Math.min(Hr(e,t),3))},{name:`pill`,aliases:[`stadium`,`capsule`],size:(e,t)=>{let{w:n,h:r}=zr(e,t);return{w:Math.max(n+8,96),h:Math.max(r,44)}},path:e=>qt(e.x,e.y,e.w,e.h,e.h/2),port:(e,t,n)=>Yt(e,t,n,.55,(t,n,r)=>{if(t)return e.h/2;let i=e.h/2;return e.w/2-i+Math.sqrt(Math.max(0,i*i-r*r))})},{name:`circle`,size:(e,t)=>{let n=Math.max(Math.hypot(e,t)+16,64);return{w:n,h:n}},path:Vr,port:Br},{name:`ellipse`,aliases:[`oval`],size:(e,t)=>({w:Math.max((e+16)*1.42,90),h:Math.max((t+12)*1.42,50)}),path:Vr,port:Br},{name:`diamond`,aliases:[`rhombus`,`decision`],size:(e,t)=>({w:Math.max(e*1.6+40,100),h:Math.max(t*1.8+32,70)}),path:({x:e,y:t,w:n,h:r})=>`M${B(e+n/2)},${B(t)}L${B(e+n)},${B(t+r/2)}L${B(e+n/2)},${B(t+r)}L${B(e)},${B(t+r/2)}Z`,port:(e,t,n)=>Yt(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*(1-Math.abs(n)))},{name:`hexagon`,size:(e,t)=>{let{w:n,h:r}=zr(e,t),i=Math.max(r,48);return{w:n+i*.4,h:i}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(r*.3,n/4);return`M${B(e+i)},${B(t)}L${B(e+n-i)},${B(t)}L${B(e+n)},${B(t+r/2)}L${B(e+n-i)},${B(t+r)}L${B(e+i)},${B(t+r)}L${B(e)},${B(t+r/2)}Z`},port:(e,t,n)=>Yt(e,t,n,.55,(t,n)=>t?e.h/2:e.w/2-Math.min(e.h*.3,e.w/4)*Math.abs(n))},{name:`cylinder`,aliases:[`database`,`db`,`storage`],textOffset:5,size:(e,t)=>{let{w:n,h:r}=zr(e,t);return{w:Math.max(n,96),h:Math.max(r+18,66)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6),a=n/2;return`M${B(e)},${B(t+i)}a${B(a)},${B(i)} 0 0,1 ${B(n)},0L${B(e+n)},${B(t+r-i)}a${B(a)},${B(i)} 0 0,1 ${B(-n)},0Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6);return`M${B(e)},${B(t+i)}a${B(n/2)},${B(i)} 0 0,0 ${B(n)},0`},port:(e,t,n)=>Yt(e,t,n,.75,(t,n)=>{if(!t)return e.w/2;let r=Math.min(9,e.h/6);return e.h/2-r+r*Math.sqrt(Math.max(0,1-n*n))})},{name:`parallelogram`,aliases:[`io`],size:(e,t)=>{let{w:n,h:r}=zr(e,t);return{w:n+24,h:Math.max(r,48)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(16,n/5);return`M${B(e+i)},${B(t)}L${B(e+n)},${B(t)}L${B(e+n-i)},${B(t+r)}L${B(e)},${B(t+r)}Z`}},{name:`document`,aliases:[`doc`],textOffset:-4,size:(e,t)=>{let{w:n,h:r}=zr(e,t);return{w:Math.max(n,96),h:Math.max(r+10,56)}},path:(e,t)=>{let{x:n,y:r,w:i,h:a}=e,o=Hr(e,t),s=Math.min(8,a/6);return`M${B(n+o)},${B(r)}L${B(n+i-o)},${B(r)}Q${B(n+i)},${B(r)} ${B(n+i)},${B(r+o)}L${B(n+i)},${B(r+a-s)}C${B(n+i*.75)},${B(r+a-s*3)} ${B(n+i*.25)},${B(r+a+s)} ${B(n)},${B(r+a-s)}L${B(n)},${B(r+o)}Q${B(n)},${B(r)} ${B(n+o)},${B(r)}Z`}},{name:`note`,aliases:[`sticky`],size:(e,t)=>{let{w:n,h:r}=zr(e,t);return{w:Math.max(n+8,96),h:Math.max(r,48)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${B(e)},${B(t)}L${B(e+n-i)},${B(t)}L${B(e+n)},${B(t+i)}L${B(e+n)},${B(t+r)}L${B(e)},${B(t+r)}Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${B(e+n-i)},${B(t)}L${B(e+n-i)},${B(t+i)}L${B(e+n)},${B(t+i)}`}},{name:`text`,aliases:[`label`,`plain`,`none`],size:(e,t)=>({w:e+12,h:t+8}),path:(e,t)=>qt(e.x,e.y,e.w,e.h,Hr(e,t))}]},Wr=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return(t,i)=>`${B(e.x+t*n-i*r)},${B(e.y+t*r+i*n)}`},Gr={name:`markers`,markers:[{name:`arrow`,inset:e=>e*.8,render(e,t,{color:n,width:r,size:i}){let a=Wr(e,t);return`<path d="M${a(0,0)}L${a(-i,i*.5)}Q${a(-i*.78,0)} ${a(-i,-i*.5)}Z" fill="${n}" stroke="${n}" stroke-width="${B(r*.5)}" stroke-linejoin="round"/>`}},{name:`open`,inset:(e,t)=>t*.8,render(e,t,{color:n,width:r,size:i}){let a=Wr(e,t);return`<path d="M${a(-i*.95,i*.55)}L${a(0,0)}L${a(-i*.95,-i*.55)}" fill="none" stroke="${n}" stroke-width="${B(r)}" stroke-linecap="round" stroke-linejoin="round"/>`}},{name:`dot`,inset:e=>e*.7,render(e,t,{color:n,size:r}){let i=r*.36,[a,o]=Wr(e,t)(-i,0).split(`,`);return`<circle cx="${a}" cy="${o}" r="${B(i)}" fill="${n}"/>`}},{name:`diamond`,inset:e=>e*1.6,render(e,t,{color:n,size:r}){let i=Wr(e,t);return`<path d="M${i(0,0)}L${i(-r*.8,r*.45)}L${i(-r*1.6,0)}L${i(-r*.8,-r*.45)}Z" fill="${n}"/>`}},{name:`bar`,render(e,t,{color:n,width:r,size:i}){let a=Wr(e,t);return`<path d="M${a(-4,i*.6)}L${a(-4,-i*.6)}" stroke="${n}" stroke-width="${B(r*1.2)}" stroke-linecap="round"/>`}}]},Kr={name:`themes`,themes:[ie(`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:_,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:e=>d[e]&&{fill:`#0f3460`,stroke:h(e,300),text:h(e,100)},groupTone:e=>d[e]&&{fill:`none`,stroke:h(e,400),text:h(e,200)},edgeTone:e=>h(e,300)},{name:`mono`,dark:!1,background:`#ffffff`,font:g,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:e=>d[e]&&{fill:h(e,100),stroke:`#18181b`,text:`#18181b`},groupTone:e=>d[e]&&{fill:h(e,50),stroke:`#a1a1aa`,text:`#52525b`},edgeTone:e=>h(e,700)},{name:`pastel`,dark:!1,background:`#fdfcff`,font:g,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:e=>d[e]&&{fill:h(e,100),stroke:h(e,100),text:h(e,900)},groupTone:e=>d[e]&&{fill:h(e,50),stroke:h(e,50),text:h(e,700)},edgeTone:e=>h(e,300)},{name:`terminal`,dark:!0,background:`#0c0c10`,font:_,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:e=>d[e]&&{fill:h(e,950),stroke:h(e,700),text:h(e,200)},groupTone:e=>d[e]&&{fill:h(e,950)+`66`,stroke:h(e,900),text:h(e,300)},edgeTone:e=>h(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:e=>d[e]&&{fill:h(e,100),stroke:h(e,400),text:h(e,900)},groupTone:e=>d[e]&&{fill:h(e,100)+`99`,stroke:h(e,300),text:h(e,800)},edgeTone:e=>h(e,600)},ie(`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:g,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:e=>d[e]&&{fill:h(e,100),stroke:h(e,800),text:h(e,950)},groupTone:e=>d[e]&&{fill:h(e,50),stroke:h(e,800),text:h(e,900)},edgeTone:e=>h(e,700)},ie(`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)`}),ie(`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:g,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:e=>d[e]&&{fill:h(e,900)+`cc`,stroke:h(e,500),text:h(e,100)},groupTone:e=>d[e]&&{fill:h(e,950)+`80`,stroke:h(e,900),text:h(e,300)},edgeTone:e=>h(e,300)}]},qr=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function Jr(e){let t=1/0,n=-1/0;for(let r of e)r<t&&(t=r),r>n&&(n=r);return[t,n]}let Yr=(e,t)=>V(e,t.theme,t.theme.accent),Xr=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${ue}))?:\\s*(.*)$`)),Zr={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=Xr(`bars`,e);return t?{kind:`bars`,values:qr(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(Jr(e.values)[1],0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=Yr(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${B(t.x+n*r*.85)}" y="${B(a-c)}" width="${B(r*.55)}" height="${B(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},Qr={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=Xr(`spark`,e);return t?{kind:`spark`,values:qr(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){if(!e.values.length)return``;let r=e.values.length===1?[e.values[0],e.values[0]]:e.values,{fs:i}=n,[a,o]=Jr(r),s=o/2-a/2,c=t.y+i*.45,l=t.y+t.h-i*.45,u=e=>s?(e/2-a/2)/s:.5,d=r.map((e,n)=>[t.x+n/(r.length-1)*t.w,l-u(e)*(l-c)]),f=d.map(([e,t],n)=>`${n?`L`:`M`}${B(e)},${B(t)}`).join(``),p=Yr(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${B(t.x+t.w)},${B(l)}L${B(t.x)},${B(l)}Z" fill="${p}" fill-opacity="0.14"/><path d="${f}" fill="none" stroke="${p}" stroke-width="1.75" stroke-linejoin="round" stroke-linecap="round"/><circle cx="${B(m)}" cy="${B(h)}" r="2.6" fill="${p}"/>`}},$r={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=Xr(`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:R(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:R(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:H(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=Yr(e.color,n);return Le(e.label,t.x,s,r,a,o)+Me(t.x+t.w,s,r,a.sub,z(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${B(t.x)}" y="${B(c)}" width="${B(t.w)}" height="${B(l)}" rx="${B(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${B(t.x)}" y="${B(c)}" width="${B(Math.max(l,t.w*e.ratio))}" height="${B(l)}" rx="${B(l/2)}" fill="${u}"/>`:``)}},ei=1.75,ti={name:`charts`,rows:[Zr,Qr,$r,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=Xr(`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:R(t),label:R(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*ei;return e.ws=e.items.map(e=>Math.max(H(e.value,i,n,r,700),H(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*ei,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:Yr(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${B(e)},${B(t.y+r*.3)}V${B(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(Le(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(Le(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},ni=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function ri(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())}let ii=e=>e*1.8,ai={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=ri(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(R);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=>!Ae(e[t])||ni.test(Ae(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=>H(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+ii(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]-Fe(t):d;o.push(Le(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+ii(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${B(t.x)},${B(e)}H${B(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},oi=[`#ff5f57`,`#febc2e`,`#28c840`],si=e=>Math.round(e*2.3);function ci(e,t,n,r,i){let a=si(t),o=Math.min(n,a/2,e.w/2),s=`M${B(e.x)},${B(e.y+a)}V${B(e.y+o)}A${B(o)},${B(o)} 0 0 1 ${B(e.x+o)},${B(e.y)}H${B(e.x+e.w-o)}A${B(o)},${B(o)} 0 0 1 ${B(e.x+e.w)},${B(e.y+o)}V${B(e.y+a)}Z`,c=t*.3,l=oi.map((n,r)=>`<circle cx="${B(e.x+t+r*c*3.3)}" cy="${B(e.y+a/2)}" r="${B(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${B(e.x)},${B(e.y+a)}H${B(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}let li=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,ui={name:`browser`,inset:e=>({top:si(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=si(a),s=li(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="${B(s)}" y="${B(u)}" width="${B(c-s)}" height="${B(l)}" rx="${B(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?Me(s+a*.7,e.y+o/2,d,n.sub,z(r)):``):``;return`<g class="frame">${ci(e,a,i,n.stroke,t.dark)}${f}</g>`}},di=(e,t)=>({name:e,inset:e=>({top:si(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=si(o),c=i?Me(e.x+e.w/2,e.y+s/2,o*.78,r.sub,z(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${ci(e,o,a,r.stroke,n.dark)}${c}</g>`}}),fi={name:`frames`,frames:[ui,di(`window`,``),di(`terminal`,`❯ `)],props:{node:[`frame`]}},pi=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),mi=/* @__PURE__ */ new Map,hi=(e,t,n)=>`${t}|${n}|${e}`;function gi(e,t,n,r){return e.map(e=>H(R(e),t,n,r))}let _i={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=pi(e);if(!r.length)return null;let i=t.fontSize*.82,a=gi(r,i,t.mono,n);mi.size>64&&mi.clear(),mi.set(hi(e,i,t.mono),a);let o=a.reduce((e,t)=>e+t,0)+i*3*(r.length-1);return{bottom:i*2.8,w:o}},render(e,t,n,{pad:r}){let i=pi(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=pe(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${B(c)},${B(t.y)}H${B(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=mi.get(hi(e,a,n.mono))??gi(i,a,n.mono,Ir),f=i.length,p=f>1?(l-c-d.reduce((e,t)=>e+t,0))/(f-1):0,m=c;return i.forEach((e,t)=>{u.push(`<text x="${B(m)}" y="${B(o)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(R(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},vi=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function yi(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return vi.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}})}let bi=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 xi(e,t,n){let{fs:r,sw:i,gap:a}=bi(t);return e.map(e=>i+a+H(R(e.label),r,t.mono,n))}function Si(e,t,n,r,i){let{sw:a,sh:o}=bi(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="${B(o*3)} ${B(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${B(o)} ${B(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${B(t)},${B(n)}H${B(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${B(o)}"${s} fill="none"/>`+(c?`<path d="M${B(u)},${B(n)}L${B(u-l)},${B(n-l*.5)}L${B(u-l)},${B(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${B(t)},${B(n)}L${B(t+l)},${B(n-l*.5)}L${B(t+l)},${B(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=Ke(i,t),a=Je(i,t,n,r),o=Vt(n.shape??i.settings.shape);return`<path d="${Gt(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??L(e.key,r,400)??r.node.fill,u=c?.stroke??L(e.key,r,600)??r.node.stroke;return`<rect x="${B(s.x)}" y="${B(s.y)}" width="${B(s.w)}" height="${B(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function Ci(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}let wi={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=yi(e);if(!n.length)return null;let{fs:r,space:i}=bi(t),a=xi(n,t,Ir),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=Ci(a,760,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,760)}},render(e,t,n,{pad:r,d:i}){let a=yi(e),{fs:o,gap:s,space:c,sw:l}=bi(n),u=xi(a,n,Ir),d=pe(n),f=[];return Ci(u,Math.min(760,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(Si(e,m,h,n,i)),e.label&&f.push(`<text x="${B(m+l+s)}" y="${B(h)}" dominant-baseline="central" font-size="${B(o)}" xml:space="preserve">${U(R(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},Ti=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,Ei=/^(?:m|note|d)\d+$/,Di=new RegExp(String.raw`^(participant|actor)\s+(${Ti})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?$`,`u`),Oi=new RegExp(String.raw`^(${Ti})\s*(-->|->|\.\.>|=>)\s*(${Ti})\s*(?::\s*(.*))?$`,`u`),ki=new RegExp(String.raw`^(${Ti}\s*(?:-->|->|\.\.>|=>)\s*${Ti})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),Ai=new RegExp(String.raw`^(participant|actor)\s+(${Ti}(?:\s*,\s*${Ti})+)$`,`u`),ji=new RegExp(String.raw`^note\s+(${Ti}(?:\s*,\s*${Ti})*)\s*:\s*(.*)$`,`u`),Mi=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,Ni=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],Pi=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>Ni.includes(e))&&(!e.color||I(e.color))},Fi=e=>Xn(e,Pi),Ii={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function Li(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,key:e,label:e,actor:!1,first:a}),t},s=0;e.forEach((e,t)=>{a=t;let r=e.trim();if(!r)return;let c;if(c=r.match(Di)){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]&&K(c[4]).color;t&&(e.tone=t)}else if(c=r.match(Ai))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(ji)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=Fi(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(Oi)){o(c[1]),o(c[3]);let[e,t]=Fi(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:Ii[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(Mi))?i.push({kind:`divider`,text:c[1]}):(c=r.match(ki))?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 ---")`)});let c=new Set(r.map(e=>e.id));for(let e of r){if(!Ei.test(e.id))continue;let t=`p-${e.id}`;for(;c.has(t);)t=`p-${t}`;c.add(t),e.key=t}return{parts:r,steps:i}}function Ri(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}`)}let zi=br(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=>H(R(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].key))});let g=[l[0]/2];u.forEach((e,t)=>g.push(g[t]+e));let _=e=>{let t=g[Math.min(...e.over.map(d))];return e.over.length>1?t-20:Math.min(t-(s(e.text)+24)/2,t-20)},v=0;for(let t of e.steps)t.kind===`note`&&(v=Math.max(v,-_(t)));for(let e=0;e<g.length;e++)g[e]+=v;let y=e.parts.length?g[g.length-1]+l[l.length-1]/2+Math.max(0,p):0;for(let t of e.steps)if(t.kind===`note`){let e=t.over.map(d),n=_(t),r=s(t.text)+24;y=Math.max(y,n+r,t.over.length>1?g[Math.max(...e)]+20:0)}let b=e=>e.kind===`msg`?e.from===e.to?a*3.6:a*2.6:e.kind===`note`?a*2.6:a*2.4,x=Ri(e),S=e.steps.map((e,t)=>Math.max(-b(e)*.3,h(x[t]))),C=c*2+a*1.4+e.steps.reduce((e,t,n)=>e+b(t)+S[n],0);return{fs:a,boxH:c,widths:l,xs:g,w:y,h:C,rowH:b,extra:S,parts:x,idx:d,num:f,textW:s,noteX:_}});function Bi(e,t){let n=qe(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function Vi(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=zi(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=pe(r),d=n.props,f=L(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=Bi(ze(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${B(c(t))},${B(h+o)}V${B(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="${B(c(a)-l/2)}" y="${B(t)}" width="${B(l)}" height="${B(o)}" rx="${B(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${B(r.strokeWidth)}"/><text x="${B(c(a))}" y="${B(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${B(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${z(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=ze(n,`style`)??(o.line===`thick`?`solid`:o.line),d=Re(n.width,o.line===`thick`||N(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=Bi(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=R(i.num(o)+o.text),g=o.tone?V(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${B(t)},${B(n)}H${B(t+26-8)}Q${B(t+26)},${B(n)} ${B(t+26)},${B(n+8)}V${B(i-8)}Q${B(t+26)},${B(i)} ${B(t+26-8)},${B(i)}H${B(t+2)}" fill="none" stroke="${g}" stroke-width="${B(d)}"${f}/>`),m.push(Rt({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${B(t+34)}" y="${B((n+i)/2)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${B(c(e))},${B(s)}H${B(c(t)-n*2)}" stroke="${g}" stroke-width="${B(d)}"${f}/>`),m.push(Rt({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="${B((c(e)+c(t))/2)}" y="${B(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" xml:space="preserve">${U(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="${B(l)}" y="${B(p)}" width="${B(u-l)}" height="${B(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${B((l+u)/2)}" y="${B(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" xml:space="preserve">${U(R(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${B(t.x)},${B(n)}H${B(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${B(c-s/2)}" y="${B(n-a*.85)}" width="${B(s)}" height="${B(a*1.7)}" rx="${B(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${B(c)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.92)}" font-weight="600" fill="${r.node.sub}">${z(o.text)}</text>`))}v+=e}return m.join(``)}function Hi(e,t,n){if(!e.parts.length)return[];let r=zi(e,n),i=e=>t.x+r.xs[e],a=e.parts.slice(1).map((e,n)=>({part:e.key,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:t.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}let Ui={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 (`p-<id>` when the id looks like a row) 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:Li,measure(e,t){let n=zi(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:Vi,handles:Hi,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=Ri(e);return[...e.parts.map(e=>({id:e.key,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:xr((e,t,n,r)=>{let i=[...e],a=r.parts.find(e=>e.key===t);if(a){if(a.decl!==void 0)return i[a.decl]=Zn(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${er({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=Ri(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=Fi(e[s.at]),u=c;delete l.color;let d=er(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})}]};function Wi(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}let Gi=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,Ki=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function qi(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]=Xn(i,Qn),c=o.match(Gi);c?r.push({when:c[1].trim(),tone:s.color??K(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function Ji(e){let t=/* @__PURE__ */ 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 Yi(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#|[-*]\s)/.test(r)&&Gi.test(Xn(r,Qn)[0])&&t.push(n)}),t}let Xi=br(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)=>H(R(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>Wi(e.details.map(e=>s(e,a*.92)),s(e.title,a,600))),u=e.map(e=>1+e.details.length),d=Ji(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=Wi(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+Wi(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+Wi(u,1)*a*1.45}});function Zi(e,t,n){if(!e.length)return``;let r=n.theme,i=Xi(e,n),{fs:a}=i,o=pe(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=V(n.tone,r,r.accent);return`<circle cx="${B(e)}" cy="${B(t)}" r="${B(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${B(e)}" cy="${B(t)}" r="${B(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${B(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${U(R(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${B(n)},${B(t.y+a*.5)}V${B(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="${B(n-16)}" y="${B(s)}" dominant-baseline="central" text-anchor="end" font-size="${B(a*.9)}" font-weight="600" fill="${V(e.tone,r,r.node.sub)}">${z(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${B(t.x)},${B(d)}H${B(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="${B(o)}" y="${B(t.y+a*.5)}" dominant-baseline="central" font-size="${B(a*.9)}" font-weight="600" fill="${V(e.tone,r,r.node.sub)}">${z(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(``)}let Qi={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:qi,measure(e,t){if(!e.length)return{w:0,h:0};let n=Xi(e,t);return{w:n.w,h:n.h}},render:Zi,parts:e=>Ji(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:xr((e,t,n,r)=>{let i=Yi(e)[Ji(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=$n(e[i],Ki,`color`,n,Qn),a}),handles(e,t,n){if(!e.length)return[];let r=Xi(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}`})}}]},$i=[`bar`,`column`,`line`,`pie`,`donut`],ea=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],ta=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,na=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/;function ra(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}function ia(e,t,n){let r=t.type??`bar`;$i.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${$i.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=Xn(r,Qn),s=a.match(ta),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=1e300)?n(t,`chart: "${s[3].slice(0,24)}…" is too large a number`):s?i.push({label:s[1].trim().replace(/^"(.*)"$/,`$1`),tone:o.color??K(s[2]).color,value:c}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:$i.includes(r)?r:`bar`,items:i}}let aa=(e,t=``)=>`${Math.abs(e)<1e15?Math.round(e*100)/100:e}${t}`;function oa(e,t,n,r){return e.tone?V(e.tone,n.theme,n.theme.accent):r?h(ea[t%ea.length],n.theme.dark?400:500):n.theme.accent}let sa=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=ra(e.items.map(e=>r(e.label,a,400,n.mono)),0),c=ra(e.items.map(e=>r(aa(e.value,o),a,600,n.mono)),0),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-1)*r+a*1.4}}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 ca(e,t,n,r,i,a){let o=(n,r)=>`${B(e+n*Math.sin(r))},${B(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return ca(e,t,n,r,o,a)+ca(e,t,n,o,i,a)}return a?`M${o(n,r)}A${B(n)},${B(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${B(a)},${B(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${B(e)},${B(t)}L${o(n,r)}A${B(n)},${B(n)} 0 ${s} 1 ${o(n,i)}Z`}function la(e,t,n){if(!e.items.length)return``;let r=n.theme,i=sa(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${B(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${z(n)}</text>`,l=ra(e.items.map(e=>e.value),0)||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="${ca(l,u,i.r,p,a,d)}" fill="${oa(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,aa(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="${B(m)}" y="${B(g-a*.45)}" width="${B(a*.9)}" height="${B(a*.9)}" rx="2.5" fill="${oa(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,aa(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="${B(u)}" y="${B(p-a*.55)}" width="${B(d)}" height="${B(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${B(u)}" y="${B(p-a*.55)}" width="${B(m)}" height="${B(a*1.1)}" rx="3" fill="${oa(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,aa(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${B(t.x)},${B(n)}H${B(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="${B(d(i)-t/2)}" y="${B(l)}" width="${B(t)}" height="${B(Math.max(2,u-l))}" rx="3" fill="${oa(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,aa(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${B(d(t))},${B(f(e.value))}`);s.push(`<path d="M${B(d(0))},${B(u)}L${t.join(`L`)}L${B(d(e.items.length-1))},${B(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=oa(e,t,n,!1);s.push(`<circle cx="${B(d(t))}" cy="${B(f(e.value))}" r="${B(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,aa(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${B(t.x)},${B(u)}H${B(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(``)}let ua={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:ia,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=sa(e,t);return{w:n.w,h:n.h}},render:la,options:{type:[...$i],unit:`text`},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:xr((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim();return!/^(\/\/|#)/.test(n)&&ta.test(Xn(n,Qn)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=$n(e[i],na,`color`,n,Qn),a}),handles(e,t,n){if(!e.items.length)return[];let r=sa(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},da=[`normal`,`highlight`,`reverse`],fa=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],pa=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,ma=String.raw`(?:\s*\[([^\]]*)\])?`,ha=new RegExp(String.raw`^commit(?:\s+(.*?))?${ma}$`,`u`),ga=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${pa})(?:\s+from\s+(\S+))?${ma}$`,`u`),_a=new RegExp(String.raw`^(?:checkout|switch)\s+(${pa})$`,`u`),va=new RegExp(String.raw`^merge\s+(${pa})(?:\s+(.*?))?${ma}$`,`u`),ya=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${ma}$`,`u`),ba=/^tag\s+(\S+)$/;function xa(e){let t=K(e??``);for(let e of da)t[e]===`true`&&(t.type=e,delete t[e]);return t}function Sa(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&&!da.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${da.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(ga)){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=xa(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(_a)){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(va)){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:dr(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},xa(u[3]),t)}else if(u=l.match(ya)){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:dr(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},xa(u[3]),t)}else(u=l.match(ba))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(ha))?c({msg:dr(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},xa(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function Ca(e,t,n){let r=e.branches[t]?.tone;return r?V(r,n.theme,n.theme.accent):h(fa[t%fa.length],n.theme.dark?400:500)}function wa(e){let t=new Set(e.branches.map(e=>e.name));return e.commits.map(e=>{let n=e.id??e.tags[0];return!n||t.has(n)||/\s/.test(n)?``:(t.add(n),n)}).map((e,n)=>{if(e)return e;e=`c${n+1}`;for(let r=2;t.has(e);r++)e=`c${n+1}-${r}`;return t.add(e),e})}let Ta=/* @__PURE__ */ new WeakMap,Ea=br(function(e,t){let n=JSON.stringify([t.fs,t.props,t.offsets]),r=Ta.get(e);if(r&&r.key===n&&r.theme===t.theme&&r.measure===t.measure)return r.G;let i=Da(e,t);return Ta.set(e,{key:n,theme:t.theme,measure:t.measure,G:i}),i});function Da(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=wa(e),l=e=>s[e]?.x??0,u=e=>H(R(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=/* @__PURE__ */ 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:/* @__PURE__ */ new Map,labelW:x,top:E,pos:D,w:C,h:E+y+a*2}}let Oa=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function ka(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${B(h.x)},${B(h.y)}L${B(g.x)},${B(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=Oa((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${B(h.x)},${B(h.y)}V${B(t-e)}C${B(h.x)},${B(t)} ${B(g.x)},${B(t)} ${B(g.x)},${B(t+e)}V${B(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=m?g.x-b(f,!y)-r*.7:h.x+b(p,y)+r*.7,C=Oa(S+v,h.x+x,g.x-x);d.push({i:f,k:m,part:_,handle:{x:C,y:(h.y+g.y)/2},d:`M${B(h.x)},${B(h.y)}H${B(C-x)}C${B(C)},${B(h.y)} ${B(C)},${B(g.y)} ${B(C+x)},${B(g.y)}H${B(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${B(i.x)},${B(i.y)}Q${B(e)},${B(n)} ${B(c.x)},${B(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${B(i.x)},${B(i.y)}C${B(p)},${B(i.y+u.y)} ${B(p)},${B(c.y+u.y)} ${B(c.x)},${B(c.y)}`})}),{lanes:u,bends:d,picks:f}}function Aa(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=Ea(e,n),{fs:a,r:o}=i,s=n.props.color&&r.groupTone(n.props.color)?.fill||[r.group.fill,r.background,r.node.fill].find(e=>e&&e!==`none`),c=pe(r),l=[],u=i.pos.map(e=>({x:t.x+e.x,y:t.y+e.y})),d=(e,t,n,r,o,c)=>{let l=i.pillW(n),u=c===`middle`?e-l/2:e,d=a*1.3;return`<rect x="${B(u)}" y="${B(t-d/2)}" width="${B(l)}" height="${B(d)}" rx="${B(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${B(u+l/2)}" y="${B(t)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.82)}" font-weight="600" fill="${o?s:r}">${z(n)}</text>`};if(!i.vertical)for(let r of i.used){let o=t.y+i.top+i.lanePos[i.slot.get(r.lane)];l.push(`<text x="${B(t.x)}" y="${B(o)}" dominant-baseline="central" font-size="${B(a)}" font-weight="600" fill="${Ca(e,r.lane,n)}">${z(r.label??r.name)}</text>`)}let f=Math.max(2,r.edgeWidth*1.4),p=ka(e,i,t),m=(t,r)=>Ca(e,r?e.commits[e.commits[t].parents[r]].lane:e.commits[t].lane,n);for(let t of p.picks)l.push(`<path d="${t.d}" fill="none" stroke="${Ca(e,e.commits[t.i].lane,n)}" stroke-width="${B(f*.7)}" stroke-dasharray="${B(f*1.6)} ${B(f*1.6)}" opacity="0.8"/>`);for(let e of[...p.bends,...p.lanes])l.push(`<path d="${e.d}" fill="none" stroke="${m(e.i,e.k)}" stroke-width="${B(f)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((p,m)=>{let{x:h,y:g}=u[m],v=p.tone?V(p.tone,r,Ca(e,p.lane,n)):Ca(e,p.lane,n);if(p.type===`highlight`){let e=o*1.1;l.push(`<rect x="${B(h-e)}" y="${B(g-e)}" width="${B(e*2)}" height="${B(e*2)}" rx="${B(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${B(f)}"/>`)}else if(p.type===`reverse`){let e=o*.55;l.push(`<circle cx="${B(h)}" cy="${B(g)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(f)}"/><path d="M${B(h-e)},${B(g-e)}L${B(h+e)},${B(g+e)}M${B(h+e)},${B(g-e)}L${B(h-e)},${B(g+e)}" stroke="${v}" stroke-width="${B(f*.8)}" stroke-linecap="round"/>`)}else p.merge?l.push(`<circle cx="${B(h)}" cy="${B(g)}" r="${B(o*1.05)}" fill="${v}"/><circle cx="${B(h)}" cy="${B(g)}" r="${B(o*.4)}" fill="${s}"/>`):p.pick===void 0?l.push(`<circle cx="${B(h)}" cy="${B(g)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(f)}"/>`):l.push(`<circle cx="${B(h)}" cy="${B(g)}" r="${B(o)}" fill="${s}" stroke="${v}" stroke-width="${B(f)}" stroke-dasharray="${B(f*1.2)} ${B(f)}"/>`);if(i.vertical){let o=t.x+i.textX;p.id&&(l.push(`<text x="${B(o)}" y="${B(g)}" dominant-baseline="central" font-size="${B(a)}" font-family="${z(_)}" fill="${r.node.sub}">${z(p.id)}</text>`),o+=n.measure(p.id,a,400,!0)+a*.6);for(let t of i.heads.get(m)??[]){let r=t.label??t.name;l.push(d(o,g,r,Ca(e,t.lane,n),!1,`start`)),o+=i.pillW(r)+a*.4}for(let e of p.tags)l.push(d(o,g,e,v,!0,`start`)),o+=i.pillW(e)+a*.4;p.msg&&l.push(`<text x="${B(o)}" y="${B(g)}" dominant-baseline="central" font-size="${B(a)}" xml:space="preserve">${U(R(p.msg),c,r,p.merge)}</text>`)}else p.tags.forEach((e,t)=>l.push(d(h,g-a*1.45-t*a*1.5,e,v,!0,`middle`))),p.msg&&l.push(`<text x="${B(h)}" y="${B(g+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${U(R(p.msg),c,r,p.merge)}</text>`)}),l.join(``)}let ja={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:Sa,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})),...wa(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:xr((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[wa(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=Zn(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=Ea(e,t);return{w:n.w,h:n.h}},render:Aa,handles(e,t,n){if(!e.commits.length)return[];let r=Ea(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=ka(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`}))]}}]},Ma=[`box`,`pill`,`plain`,`circle`],Na=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],Pa=/^[-*+]\s+/,Fa=e=>Ue(e)!==void 0,Ia={color:I,shape:()=>!0,text:I,"font-size":Fa,"font-weight":Fa},La=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>Ia[t]?.(e[t]))},Ra=e=>Xn(e,La);function za(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,l]=Ra(o.replace(Pa,``));l.shape&&!Ma.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${Ma.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:Ue(l[`font-size`]),weight:Ue(l[`font-weight`]),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 Ba(e){let t=[],n=[e];for(;n.length;){let e=n.pop();t.push(e);for(let t=e.children.length-1;t>=0;t--)n.push(e.children[t])}return t}let Va=e=>e.reduce((e,t)=>Math.min(e,t),1/0),Ha=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function Ua(e){let t=/* @__PURE__ */ 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}`)}let Wa=[`both`,`vertical`,`right`,`left`,`down`,`up`],Ga=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=Ue(i[`font-size`])??t.fs*.9,o=Wa.includes(i.layout)?i.layout:`both`,s=o===`down`||o===`up`||o===`vertical`,c=i.colors===`mono`,l=Ba(e),u=Ua(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=/* @__PURE__ */ new Map,p=(e,t,i,o)=>{let s=Ma.includes(e.shape??``)?e.shape:t===0?`pill`:t===1?`box`:`plain`,c=e.size??(t===0?a*1.2:t===1?a:a*.92),l=e.weight??(t===0?700:t===1?600:400),u=H(R(e.text),c,n.mono,r,l),p=s===`plain`?{x:a*.15,y:a*.3}:{x:c*(t?.8:1.1),y:c*.5},m=u+p.x*2,h=c*1.25+p.y*2;s===`circle`&&(m=h=Math.max(m,h));let g={node:e,part:d.get(e),depth:t,side:0,color:e.tone??i,shape:s,font:c,weight:l,x:0,y:0,w:m,h,parent:o};return f.set(e,g),g};p(e,0,e.tone);for(let e of l){let t=f.get(e);e.children.forEach((e,n)=>p(e,t.depth+1,e.tone??(t.depth===0?c?void 0:Na[n%Na.length]:t.color),t))}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,_=/* @__PURE__ */ new Map,v=(e,t)=>{let n=f.get(e),r=0;return t.forEach((e,t)=>{r+=_.get(e)+(t?m(n.depth):0)+h(e,t,n.depth)}),Math.max(g(n),r)};for(let e=l.length-1;e>=0;e--)_.set(l[e],v(l[e],l[e].children));let y=e.children,b=y,x=[];if((o===`both`||o===`vertical`)&&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=o===`left`||o===`up`||o===`vertical`?-1:1,C=e=>s?a*1.9:e===0?a*2.6:a*1.7,w=[],T=(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=n,s?(a.x=i+o/2-a.w/2,a.y=n>0?e.y+e.h+C(e.depth):e.y-C(e.depth)-a.h):(a.y=i+o/2-a.h/2,a.x=n>0?e.x+e.w+C(e.depth):e.x-C(e.depth)-a.w),i+=o,w.push([a,t.children,n])})},E=f.get(e);for(w.push([E,b,S],[E,x,-S]);w.length;)T(...w.pop());let D=l.map(e=>f.get(e)),O=Va(D.map(e=>e.x)),k=Va(D.map(e=>e.y));for(let e of D)e.x-=O,e.y-=k;return{all:D,vert:s,w:Ha(D.map(e=>e.x+e.w)),h:Ha(D.map(e=>e.y+e.h))}}),Ka=(e,t)=>t?V(t,e,e.accent):e.accent;function qa(e,t,n){if(!e)return``;let r=n.theme,i=Ga(e,n),a=[],o=[],s=e=>t.x+e,c=e=>t.y+e,l=(e,t)=>i.vert?[e.x+e.w/2,t>0?e.y+e.h:e.y]:[t>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=Ka(r,e.color);if(e.parent){let[n,r]=l(e.parent,e.side),[o,u]=l(e,-e.side),d=Math.max(1.4,3.6-e.depth*.7),f=i.vert?`M${B(s(n))},${B(c(r))}C${B(s(n))},${B(c((r+u)/2))} ${B(s(o))},${B(c((r+u)/2))} ${B(s(o))},${B(c(u))}`:`M${B(s(n))},${B(c(r))}C${B(s((n+o)/2))},${B(c(r))} ${B(s((n+o)/2))},${B(c(u))} ${B(s(o))},${B(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${B(d)}" 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=L(e.node.ink,r,r.dark?100:800)??(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${B(m)},${B(h+e.h)}H${B(m+e.w)}" stroke="${t}" stroke-width="${B(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="${B(m)}" y="${B(h)}" width="${B(e.w)}" height="${B(e.h)}" rx="${B(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="${B(m+e.w/2)}" y="${B(g)}" dominant-baseline="central" text-anchor="middle" font-size="${B(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${U(R(e.node.text),pe(r,p,f),r)}</text>`)}return a.join(``)+o.join(``)}let Ja={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, `[text: red, font-size: 18, font-weight: 700]` styles its text.",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:Wa,colors:[`branches`,`mono`]},parse:za,measure(e,t){if(!e)return{w:0,h:0};let n=Ga(e,t);return{w:n.w,h:n.h}},render:qa,parts(e){if(!e)return[];let t=Ba(e),n=/* @__PURE__ */ new Map([[e,0]]);for(let e of t)for(let t of e.children)n.set(t,n.get(e)+1);return Ua(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:xr((e,t,n,r)=>{if(!r)return null;let i=Ba(r),a=i[Ua(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=Ra(e[a.line]),u=er(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=Ga(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.vert?e.x:e.side<0?e.x+e.w:e.x),y:t.y+e.y+e.h/2,axis:r.vert?`x`:`y`,title:`move ${e.node.text}`})}return i}}]},J=864e5,Ya=2e3,Xa=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Za=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,Qa=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,$a=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function eo(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=/* @__PURE__ */ new Date(0);return s.setUTCFullYear(+n,r-1,+i),s.setUTCHours(+a,+o,0,0),s.getUTCFullYear()===+n&&s.getUTCMonth()===r-1&&s.getUTCDate()===+i?s.getTime():NaN}function to(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:J,w:7*J}[t[2].toLowerCase()]:NaN}function no(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s)return;let c=s.match($a);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?K(t[2]).color:void 0);return}let[l,u]=Xn(s),d=l.match(Za);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={...K(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(eo(x))?x&&Number.isNaN(to(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=eo(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=to(S),Number.isNaN(v.len)&&(v.endDate=eo(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?l.reduce((e,t)=>Math.min(e,t)):Date.UTC(2025,0,1),d=e=>{let t=i[e];return t.after.length?t.after:Number.isNaN(t.date)&&e>0?[e-1]:[]},f=(e,t)=>{let a=r[e],o=i[e],s=o.date;return o.after.length?s=t.length?t.reduce((e,t)=>Math.max(e,t)):u:Number.isNaN(s)&&(e>0?s=t[0]:(n(o.line,`gantt: the first task needs a start date`),s=u)),a.start=s,a.end=a.milestone?s:Number.isNaN(o.len)?Number.isNaN(o.endDate)?s+J:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=864e13||(n(o.line,`gantt: task "${a.id}" ends past the last date a chart can show`),a.end=s),c[e]=2,a.end},p=e=>{if(c[e]!==0)return;c[e]=1;let t=[{i:e,deps:d(e),k:0,ends:[]}];for(;t.length;){let e=t[t.length-1];if(e.k<e.deps.length){let a=e.deps[e.k++],o=typeof a==`number`?a:s.get(a);o===void 0?n(i[e.i].line,`gantt: "after ${a}": no task "${a}"`):c[o]===2?e.ends.push(r[o].end):c[o]===1?(n(i[o].line,`gantt: "${r[o].id}" depends on itself through "after"`),e.ends.push(u)):(c[o]=1,t.push({i:o,deps:d(o),k:0,ends:[]}));continue}t.pop();let a=f(e.i,e.ends);t.length&&t[t.length-1].ends.push(a)}};r.forEach((e,t)=>p(t));let m=r.length?1/0:0,h=r.length?-1/0:0;for(let e of r)m=Math.min(m,e.start),h=Math.max(h,e.end);return{tasks:r,sections:a,sectionTones:o,min:m,max:h}}function ro(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!$a.test(r)&&Za.test(Xn(r)[0])&&t.push(n)}),t}function io(e){let t=k(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`}let ao=e=>{let t=new Date(e);return`${Xa[t.getUTCMonth()]} ${t.getUTCDate()}`},oo=e=>{let t=e/J;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 so(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/J)*J;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=J;for(;o<=t&&i.length<Ya&&Number.isFinite(new Date(o).getTime());o+=a*J)i.push({t:o,label:ao(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(!Number.isFinite(e)||e>t||i.length>=Ya)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${Xa[c]} ${s}`:Xa[c]}),l=!1,c+=a}return i}return i}let co={compact:1.6,normal:2.1,loose:2.7},lo=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(co[i.density??``]??co.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>H(R(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/J)*J,_=Math.max(g+J,Math.ceil(e.max/J)*J),v=(_-g)/J,y={day:a*2.4,week:a*.8,month:a*.22}[i.scale??``],b=Math.min(y??Math.min(a*3,Math.max(a*.35,a*38/v)),a*1e3/v),x=e=>h+(e-g)/J*b,S=v*b,C=[],w=c,T=-1;for(e.tasks.forEach((e,n)=>{for(;T<e.section;)T++,C.push({y:w,section:T}),w+=s;w+=Math.max(-o*.4,t.offsets[e.id]?.x??0),C.push({y:w,task:n}),w+=o});T<e.sections.length-1;)C.push({y:w,section:++T}),w+=s;let E=Math.max(a*1.25,o*.62),D=Math.min(E,a*1.3)*.5,O=a*.5,k=h+S;return{fs:a,rowH:o,secH:s,axisH:c,labelW:h,min:g,max:_,dayW:b,x,plotW:S,rows:C,barH:E,ms:D,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?`${ao(e.start)} – ${ao(e.end)}`:e.milestone?ao(e.start):oo(e.end-e.start),t].filter(Boolean).join(` · `),r=x(e.start),o=e.milestone?r+D:x(e.end),s=e.milestone||u?0:o-r-O*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+O,s:g,kind:`label`,w:_}),n&&f(n)<=c-_-O?m.push({x:o-O,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+O,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&&(k=Math.max(k,v-a*.7)),{inner:m,after:y}}),name:p,w:k,h:w}});function uo(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${B(n[0][0])},${B(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${B(u[0])},${B(u[1])}Q${B(a[0])},${B(a[1])} ${B(d[0])},${B(d[1])}`}let i=n[n.length-1];return`${r}L${B(i[0])},${B(i[1])}`}function fo(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=lo(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f=pe(r),p=(e,t,n,i,a,s=!1)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${B(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${U(R(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${B(o*.82)}" font-weight="500" fill="${r}">${z(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/J<=3660)for(let e=a.min;e<a.max;e+=J){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${B(c(e))}" y="${B(t.y+a.axisH*.8)}" width="${B(a.dayW)}" height="${B(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/J)*J:eo(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${ao(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 so(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${B(s)},${B(t.y+a.axisH*.75)}V${B(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${B(p)}" y="${B(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${B(o*.82)}" fill="${r.node.sub}">${z(e.label)}</text>`)}d.push(`<path d="M${B(t.x+a.labelW)},${B(t.y+a.axisH*.75)}H${B(t.x+a.labelW+a.plotW)}" stroke="${u}" stroke-width="1.5"/>`);let x=/* @__PURE__ */ 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="${B(t.x-o*.4)}" y="${B(t.y+n.y)}" width="${B(T+o*.4)}" height="${B(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?V(l,r,r.node.sub):r.node.sub;d.push(`<path d="M${B(t.x)},${B(t.y+n.y+1)}H${B(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${B(e)},${B(s+n*1.6)}V${B(s-n/2)}H${B(t)}V${B(s+n*1.6)}" fill="none" stroke="${f}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${B(e)}" y="${B(s-n/2)}" width="${B(t-e)}" height="${B(n)}" fill="${f}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${B(c(h))},${B(t.y+a.axisH*.35)}V${B(l)}" stroke="${V(`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${B(g)},${B(_)}C${B(g+e)},${B(_)} ${B(b-e)},${B(y)} ${B(b)},${B(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=uo([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=uo([[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="${B(l)}" stroke-linejoin="round"/>`,Rt({x:v,y},0,`arrow`,s,l,u))}})}let E=i.bars===`solid`||i.bars===`outline`||i.bars===`thin`?i.bars:`soft`,D=/* @__PURE__ */ new Map,O=e=>{let r=`${e}|${E}`,i=D.get(r);if(!i){i=`${n.idPrefix??`mg`}-hatch-${Math.round(t.x)}-${Math.round(t.y)}-${D.size}`,D.set(r,i);let a=E===`solid`?io(e):e;d.push(`<defs><pattern id="${i}" patternUnits="userSpaceOnUse" width="7" height="7" patternTransform="rotate(45)"><rect width="3" height="7" fill="${a}" opacity="${E===`solid`?.28:.22}"/></pattern></defs>`)}return i};if(e.tasks.forEach((e,n)=>{let s=C(n),l=w(e),u=l?r.tone(l):void 0,f=V(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${B(t)},${B(s-a.ms)}L${B(t+a.ms)},${B(s)}L${B(t)},${B(s+a.ms)}L${B(t-a.ms)},${B(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?V(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${B(v)}" y="${B(x)}" width="${B(e)}" height="${B(b)}" rx="${B(S)}" ${t}${h}/>`,A=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,j=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,ee=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(k(y,`fill="${j}"${ee}${A?` stroke="${T}" stroke-width="${A}"`:``}`));let M=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;M&&d.push(k(M,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-M>2&&d.push(`<rect x="${B(v+M)}" y="${B(x)}" width="${B(y-M)}" height="${B(b)}" rx="${B(S)}" fill="url(#${O(f)})"/>`);for(let e of g){let n=t.x+e.x+(e.end?0:e.w),i=E===`solid`&&(!D||n<=v+M-o*.2)?io(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=V(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${B(b)}" y="${B(n-o*.55)}" width="${B(v)}" height="${B(o*1.1)}" rx="${B(o*.55)}" fill="${e}"/>`,`<text x="${B(b+v/2)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(o*.72)}" font-weight="650" fill="${io(e)}">${z(_)}</text>`)}return d.join(``)}let po={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:`text`,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:no,measure(e,t){if(!e.tasks.length)return{w:0,h:0};let n=lo(e,t);return{w:n.w,h:n.h}},render:fo,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:xr((e,t,n,r)=>{let i=ro(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=$n(e[i],Qa,`color`,n),a}),handles(e,t,n){if(!e.tasks.length)return[];let r=lo(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}`}])}}]},mo=/^([xy])-axis\s*:?\s*(.*)$/i,ho=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,go=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,_o=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,vo=[`teal`,`blue`,`slate`,`amber`],yo=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function bo(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(mo);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=Xn(a,Qn),l=s.match(ho);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??K(l[2]).color};return}let u=s.match(go);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??K(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=/* @__PURE__ */ 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=yo(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 xo(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]=Xn(l,Qn),d=new RegExp(go,`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}let So=br(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=[],p=i*2,m=/* @__PURE__ */ new Map,h=0,g=0,_=e=>{f.push(e),h=Math.max(h,e.w),g=Math.max(g,e.h);let t=Math.floor(e.x/p)*1048576+Math.floor(e.y/p),n=m.get(t);n?n.push(e):m.set(t,[e])};for(let e of d)_({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=H(R(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;_({x:s-a/2,y:c-i*.6,w:a,h:i*1.2})});let v=(e,t)=>{let n=0,r=Math.floor((e.x+e.w)/p),i=Math.floor((e.y-g)/p),a=Math.floor((e.y+e.h)/p);for(let o=Math.floor((e.x-h)/p);o<=r;o++)for(let r=i;r<=a;r++){let i=m.get(o*1048576+r);if(i)for(let r of i){let i=Math.min(e.x+e.w,r.x+r.w)-Math.max(e.x,r.x);if(i<=0)continue;let a=Math.min(e.y+e.h,r.y+r.h)-Math.max(e.y,r.y);if(!(a<=0)&&(n+=i*a,n>=t))return n}}return n},y=l+4,b=e.points.map(()=>({x:0,y:0,w:0,h:0})),x=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 x){let i=d[t],a=H(R(e.points[t].name),u,n.mono,r),s=u*1.2,c=[{x:i.x+y,y:i.y-s/2,w:a,h:s},{x:i.x-y-a,y:i.y-s/2,w:a,h:s},{x:i.x-a/2,y:i.y-y-s,w:a,h:s},{x:i.x-a/2,y:i.y+y,w:a,h:s},{x:i.x+y*.7,y:i.y-y*.7-s,w:a,h:s},{x:i.x+y*.7,y:i.y+y*.7,w:a,h:s},{x:i.x-y*.7-a,y:i.y-y*.7-s,w:a,h:s},{x:i.x-y*.7-a,y:i.y+y*.7,w:a,h:s}],l=c[0],f=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-.01-t*s*4;if(n<=0)continue;let r=v(e,n)+t*s*4;r<f-.01&&([l,f]=[e,r])}b[t]=l,_(l)}return{fs:i,lfs:u,S:o,left:s,bottom:c,r:l,pts:d,labels:b,w:s+o,h:o+c}});function Co(e,t,n){let r=n.theme,i=So(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],u=pe(r),d=o/2,f=[[d,0],[0,0],[0,d],[d,d]];e.q.forEach((e,t)=>{let n=e.tone??vo[t],i=r.tone(n)?.fill??h(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${B(s+f[t][0])}" y="${B(c+f[t][1])}" width="${B(d)}" height="${B(d)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=e.tone??vo[t],i=V(n,r,r.node.sub);l.push(`<text x="${B(s+f[t][0]+d/2)}" y="${B(c+f[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a)}" font-weight="700" xml:space="preserve">${U(R(e.text),{...u,text:i},r)}</text>`)}),l.push(`<rect x="${B(s)}" y="${B(c)}" width="${B(o)}" height="${B(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${B(s+d)},${B(c)}V${B(c+o)}M${B(s)},${B(c+d)}H${B(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let p=(e,t,n,i)=>n?`<text x="${B(e)}" y="${B(t)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${B(e)} ${B(t)})"`:``}>${z(n)}</text>`:``,m=c+o+i.bottom/2;l.push(p(s+d/2,m,e.x[0],!1),p(s+d*1.5,m,e.x[1],!1));let g=t.x+i.left/2;return l.push(p(g,c+d*1.5,e.y[0],!0),p(g,c+d/2,e.y[1],!0)),e.points.forEach((e,t)=>{let n=V(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],d=i.labels[t];l.push(`<circle cx="${B(s+a)}" cy="${B(c+o)}" r="${B(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${B(s+d.x)}" y="${B(c+d.y+d.h/2)}" dominant-baseline="central" font-size="${B(i.lfs)}" xml:space="preserve">${U(R(e.name),u,r)}</text>`)}),l.join(``)}let wo={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:bo,measure(e,t){let n=So(e,t);return{w:n.w,h:n.h}},render:Co,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:xr((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>ho.test(e.trim())&&e.trim()[1]===a[1]),i<0){let t=n?` [${n}]`:``;return[...e,`q${a[1]}${t}:`]}}else i=r.points.find(e=>e.id===t)?.line;if(i===void 0)return null;let o=[...e];return o[i]=$n(e[i],_o,`color`,n,Qn),o}),handles(e,t,n){let r=So(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)=>xo(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`}]}}]},To={high:`red`,medium:`amber`,low:`gray`};function Eo(e){let[t,n]=Xn(e);return{text:t.trim(),props:n}}let Do=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``),Oo=e=>e.match(/^\s*/)[0].length,ko=e=>!e.trim(),Ao=/^[-*]\s+/;function jo(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function Mo(e,t,n){let r=[],i=Math.min(...e.filter(e=>!ko(e)).map(Oo)),a,o=0,s=0,c=-1,l=/* @__PURE__ */ new Set,u=(e,t)=>{e&&e.end<0&&(e.end=t)};return e.forEach((e,t)=>{if(ko(e))return;let d=e.trim(),f=Oo(e),p=c;if(c=t,Ao.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}=Eo(d.replace(Ao,``)),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`?(To[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:To[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}=Eo(d),g=jo(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=Do(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,cards:[]}),a=void 0}),u(a,c+1),u(r[r.length-1],c+1),r}function No(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=Xn(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=er(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}let Po=[`owner`,`ticket`,`priority`];function Fo(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]?Oo(e[t.cards[0].start]):Oo(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=Mo(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=Oo(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,Oo(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?Po:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&jo(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=No(e[l.start],(e,t)=>r===`text`?a||e:(i===null||i===``?delete t[r]:t[r]=i,e));let h=p(s,m);if(a){let e=Mo(s,{},()=>{})[m[0]];if((m[1]===void 0?e?.title:e?.cards[m[1]]?.text)!==a)return null}return h}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]?Oo(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}}}let Io=br(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(H(R(e.text),i,n.mono,r,500),t,...e.details.map(e=>H(R(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 Lo(e,t,n){if(!e.length)return``;let r=n.theme,i=Io(e,n),{fs:a}=i,o=[],s=pe(r),c=Math.min(r.radius,a*.6),l=V(`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="${B(d)}" y="${B(f)}" width="${B(i.colW)}" height="${B(i.h)}" rx="${B(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="${B(d+i.cpad+a*.35)}" cy="${B(h)}" r="${B(a*.32)}" fill="${V(e.tone,r,r.node.sub)}"/>`,`<text x="${B(d+i.cpad+a*1.05)}" y="${B(h)}" dominant-baseline="central" font-size="${B(a)}" font-weight="700" xml:space="preserve">${U(R(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="${B(v)}" y="${B(h-a*.6)}" width="${B(_)}" height="${B(a*1.2)}" rx="${B(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${B(v+_/2)}" y="${B(h)}" dominant-baseline="central" text-anchor="middle" font-size="${B(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${z(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="${B(l)}" y="${B(y)}" width="${B(f)}" height="${B(n.h)}" rx="${B(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${B(l)}" y="${B(y+c/2)}" width="3.5" height="${B(n.h-c)}" rx="1.75" fill="${V(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${B(l+i.pad)}" y="${B(m)}" dominant-baseline="central" font-size="${B(a)}" font-weight="500" xml:space="preserve">${U(R(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${B(l+i.pad)}" y="${B(m-a*.6)}" dominant-baseline="central" font-size="${B(a*.88)}" xml:space="preserve">${U(R(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="${B(t)}" y="${B(n-i.chipFs*.75)}" width="${B(e)}" height="${B(i.chipFs*1.5)}" rx="${B(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${B(t+e/2)}" y="${B(n)}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${z(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}let Ro={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]
6
+ - Write docs [owner: ana] }`,parse:Mo,measure(e,t){if(!e.length)return{w:0,h:0};let n=Io(e,t);return{w:n.w,h:n.h}},render:Lo,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:Fo,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=Io(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}`}))}}]},zo={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},Bo=Object.keys(zo),Vo={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},Ho=[`collapsed`,`highlight`,`dim`,`folder`,`file`,...Bo],Uo=[`color`,`icon`,`badge`,`note`,`size`,`status`],Wo=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],Go=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,Ko=/^[-*+]\s+/,qo=/\s\[([^[\]]*)\]\s*$/,Jo=/:\s|\s#\s|:$/,Yo=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,Xo=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,Zo=/^(?:\.{3}|…)$/;function Qo(e){let t=[],n=e=>t.push(e)-1,r=0,i=t=>{let n=[[]];for(;r<e.length;){let a=e[r++],o=n[n.length-1];if(a===`*`)e[r]===`*`?(r++,e[r]===`/`?(r++,o.push({t:`**/`})):o.push({t:`**`})):o.push({t:`*`});else if(a===`?`)o.push({t:`?`});else if(a===`{`)o.push({t:`alt`,alts:i(!0)});else if(a===`}`&&t)return n;else a===`,`&&t?n.push([]):o.push({t:`lit`,c:a.toLowerCase()})}return n},a=(e,r)=>{for(let i=e.length-1;i>=0;i--){let o=e[i];if(o.t===`lit`)r=n({k:`char`,c:o.c,next:r});else if(o.t===`?`)r=n({k:`seg`,next:r});else if(o.t===`*`||o.t===`**`){let e=n({k:`split`,outs:[]}),i=n({k:o.t===`*`?`seg`:`any`,next:e});t[e].outs.push(i,r),r=e}else if(o.t===`**/`){let e=n({k:`split`,outs:[]}),i=n({k:`any`,next:e}),a=n({k:`char`,c:`/`,next:r});t[e].outs.push(i,a),r=n({k:`split`,outs:[e,r]})}else r=n({k:`split`,outs:o.alts.map(e=>a(e,r))})}return r},o=i(!1),s=a(o.length>1?[{t:`alt`,alts:o}]:o[0],n({k:`end`})),c=e=>{let n=/* @__PURE__ */ new Set,r=[...e];for(;r.length;){let e=r.pop();if(n.has(e))continue;n.add(e);let i=t[e];i.k===`split`&&r.push(...i.outs)}return n},l=c([s]);return{test(e){let n=l,r=e.toLowerCase();for(let e=0;e<r.length;e++){let i=r[e],a=[];for(let e of n){let n=t[e];n.k!==`split`&&n.k!==`end`&&(n.k===`char`?n.c===i:n.k!==`seg`||i!==`/`)&&a.push(n.next)}if(!a.length)return!1;n=c(a)}for(let e of n)if(t[e].k===`end`)return!0;return!1}}}function $o(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}let es=e=>e.replace(/\/$/,``);function ts(e,t){for(let n of Object.keys(e))!Ho.includes(n)&&!Uo.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[...Uo.slice(1),...Ho].join(`, `)})`);e.status&&!Bo.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${Bo.join(`, `)})`),e.color&&!de(e.color)&&delete e.color}function ns(e,t,n){let r=[],i=[],a=[],o=/* @__PURE__ */ new Map,s=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let c=e.trim().match(Xo);if(c){let e=K(c[2]);ts(e,e=>n(t,e));let r=c[1];a.push({re:Qo(es(r)),path:es(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let l=e.match(Go)[0],u=e.slice(l.length),d=u.match(Ko);d&&(u=u.slice(d[0].length));let f=e.length-u.trimStart().length;if(u=u.trim(),!u||Yo.test(u))return;let p=(l+(d?.[0]??``)).replace(/\t/g,` `).length,m={},h,g=u.match(qo);g&&(m=K(g[1]),h=[f+g.index,f+u.length],u=u.slice(0,g.index).trimEnd());let _,v=$o(u).match(Jo);if(v&&v.index>0){_=u.slice(v.index+v[0].length).trim()||void 0,u=u.slice(0,v.index).trimEnd();let e=u.match(qo);e&&!g&&(m=K(e[1]),h=[f+e.index,f+u.length],u=u.slice(0,e.index).trimEnd())}ts(m,e=>n(t,e));let y={text:u,collapsed:!1,highlight:!1,dim:!1,line:t,children:[]};for(h&&(y.propSpan=h),o.set(y,{props:m,note:_});i.length&&i[i.length-1].indent>=p;)i.pop();i.length>=100&&(s||n(t,`treeview: entries nest at most 100 levels deep`),s=!0,i.length=99),(i.length?i[i.length-1].node.children:r).push(y),i.push({indent:p,node:y})});let c=(e,t)=>{for(let n of e){let e=t+es(n.text),{props:r,note:i}=o.get(n),s=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),l={};for(let t of a)(!t.folders||s)&&t.re.test(t.path?e:es(n.text))&&(t.hits++,Object.assign(l,t.props));if(r.folder===`true`&&delete l.file,r.file===`true`&&delete l.folder,Bo.some(e=>r[e]===`true`)||r.status){for(let e of Bo)delete l[e];delete l.status}Object.assign(l,r),n.note=r.note??i??l.note,n.tone=l.color,n.icon=l.icon,n.badge=l.badge,n.size=l.size,n.status=Bo.find(e=>l[e]===`true`)??(Bo.includes(l.status)?l.status:void 0),n.collapsed=l.collapsed===`true`,n.highlight=l.highlight===`true`,n.dim=l.dim===`true`,n.type=l.folder===`true`?`folder`:l.file===`true`?`file`:void 0,c(n.children,e+`/`)}};c(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function rs(e,t=[]){for(let n of e)t.push(n),rs(n.children,t);return t}let is=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),as=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},os={},Y=(e,t,n)=>{for(let r of n.split(` `))os[r]=[t,e]};Y(`blue`,`code`,`ts tsx mts cts py c cpp`),Y(`amber`,`code`,`js jsx mjs cjs zig`),Y(`green`,`code`,`vue`),Y(`orange`,`code`,`svelte rs swift html`),Y(`purple`,`code`,`astro kt h cs css`),Y(`cyan`,`code`,`go`),Y(`red`,`code`,`java rb`),Y(`indigo`,`code`,`php lua`),Y(`pink`,`code`,`scss`),Y(`green`,`terminal`,`sh bash zsh fish ps1`),Y(`blue`,`doc`,`md`),Y(`amber`,`doc`,`mdx`),Y(`gray`,`doc`,`txt rst`),Y(`red`,`doc`,`pdf`),Y(`green`,`doc`,`csv`),Y(`purple`,`image`,`png jpg jpeg gif webp avif ico`),Y(`amber`,`image`,`svg`),Y(`red`,`font`,`woff woff2 ttf otf`),Y(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),Y(`amber`,`config`,`json`),Y(`purple`,`config`,`yaml yml`),Y(`gray`,`config`,`toml ini`),Y(`orange`,`config`,`xml`),Y(`slate`,`config`,`env`),Y(`cyan`,`database`,`sql db sqlite`),Y(`amber`,`package`,`zip tar gz`),Y(`pink`,`yuhwa`,`yu yuhwa`);let ss=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function cs(e){let t=es(e).toLowerCase();return/(^|\.)lock$|-lock\.(json|yaml)$|^lockfile$/.test(t)?[`lock`,`gray`]:/^\.git(ignore|attributes|modules|keep)?$/.test(t)?[`git`,`orange`]:/^(package\.json|cargo\.toml|go\.mod|pyproject\.toml|gemfile|composer\.json|pom\.xml|build\.gradle)$/.test(t)?[`package`,`red`]:/^(dockerfile|makefile|\.env.*|\.editorconfig|\.npmrc|\.prettierrc.*|tsconfig.*\.json)$/.test(t)?[`config`,`slate`]:/^(readme|license|licence|changelog|contributing)(\..*)?$/.test(t)?[`doc`,`blue`]:/\.(test|spec)\.[a-z]+$|^test_.*\.py$|_test\.go$/.test(t)?[`test`,`green`]:os[as(t)]??[`file`,void 0]}function ls(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="M3.5 1.5h6l3.5 3.5v9.5h-9.5z" fill="${t}" stroke="${n}"/>${r(`M9.5 1.5v3.5h3.5`)}`;switch(e){case`folder`:return`<path d="M1.5 4.5a1 1 0 0 1 1-1h3.6l1.6 1.8h5.8a1 1 0 0 1 1 1v6.7a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1z" fill="${t}" stroke="${n}"/>`;case`folder-open`:return`<path d="M1.5 12.5v-8a1 1 0 0 1 1-1h3.6l1.6 1.8h5a1 1 0 0 1 1 1v1.2" fill="none" stroke="${n}"/><path d="M3.4 7.5h11.3l-1.9 6H1.5z" fill="${t}" stroke="${n}" stroke-linejoin="round"/>`;case`code`:return i+r(`M6.6 8.2l-1.6 1.9 1.6 1.9M9.4 8.2l1.6 1.9-1.6 1.9`);case`doc`:return i+r(`M5.8 8h4.4M5.8 10.2h4.4M5.8 12.4h2.8`);case`image`:return i+`<path d="M5 13l2.1-2.8 1.5 1.6 1.4-1.8L11.8 13z" fill="${n}"/><circle cx="6.4" cy="7.8" r="1" fill="${n}"/>`;case`config`:return i+r(`M5.5 8.6h5M5.5 11.6h5`)+`<circle cx="7" cy="8.6" r="1.1" fill="${t}" stroke="${n}"/><circle cx="9" cy="11.6" r="1.1" fill="${t}" stroke="${n}"/>`;case`lock`:return`<rect x="3.5" y="7" width="9" height="7.5" rx="1.3" fill="${t}" stroke="${n}"/>${r(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)}<circle cx="8" cy="10.7" r="1" fill="${n}"/>`;case`package`:return`<path d="M8 1.8l5.6 3.1v6.2L8 14.2l-5.6-3.1V4.9z" fill="${t}" stroke="${n}" stroke-linejoin="round"/>${r(`M2.4 4.9L8 8l5.6-3.1M8 8v6.2`)}`;case`git`:return r(`M5 5.6v4.8M11 7.6c0 2.4-6 1.6-6 2.8`)+[[5,4],[5,12],[11,6]].map(([e,r])=>`<circle cx="${e}" cy="${r}" r="1.6" fill="${t}" stroke="${n}"/>`).join(``);case`database`:return`<path d="M3 4v8c0 1.1 2.2 2 5 2s5-.9 5-2V4" fill="${t}" stroke="${n}"/><ellipse cx="8" cy="4" rx="5" ry="2" fill="${t}" stroke="${n}"/>`+r(`M3 8c0 1.1 2.2 2 5 2s5-.9 5-2`);case`test`:return`<path d="M6.4 2v4.3L2.9 12.4a1.2 1.2 0 0 0 1 1.8h8.2a1.2 1.2 0 0 0 1-1.8L9.6 6.3V2" fill="${t}" stroke="${n}"/>`+r(`M5.4 2h5.2M4.6 9.8h6.8`);case`font`:return i+r(`M5.5 13l2.5-6 2.5 6M6.4 11h3.2`);case`media`:return i+`<path d="M6.6 7.8l4 2.4-4 2.4z" fill="${n}"/>`;case`terminal`:return`<rect x="1.5" y="2.5" width="13" height="11" rx="1.5" fill="${t}" stroke="${n}"/>`+r(`M4.5 6.3l2.2 1.9-2.2 1.9M8.3 10.6h3.2`);case`yuhwa`:return i+`<circle cx="6.2" cy="9" r="1.2" fill="${n}"/><circle cx="9.8" cy="11.6" r="1.2" fill="${n}"/>${r(`M7.1 9.7l1.8 1.3`)}`;default:return i}}let us=u({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function ds(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(es(n.text),(t.get(es(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(es(e.text))&&t.get(es(e.text))===1&&!/^n\d+$/.test(es(e.text))?es(e.text):`n${n+1}`)}let fs=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,ps=e=>e!==void 0&&e!==`false`,ms=(e,t,n)=>t.includes(e)?e:n,hs=e=>e&&de(e)?e:void 0,gs=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function _s(e,t){let n=t.get(e);if(n)return n;n=/* @__PURE__ */ new Set;for(let r of e.children){r.status&&r.status!==`ignored`&&n.add(r.status);for(let e of _s(r,t))n.add(e)}return t.set(e,n),n}let vs=[`color`,`mono`,`emoji`,`none`],ys=[`solid`,`rounded`,`dashed`,`dotted`,`none`],bs=[`none`,`name`,`folders`],xs=[`collapsed`,`all`,`none`],Ss=[`letter`,`dot`,`none`],Cs=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=ms(i.icons,vs,vs[0]),s=ms(i.sort,bs,bs[0]),c=i.counts===`true`?`all`:ms(i.counts,xs,xs[0]),l=ms(i.marks,Ss,Ss[0]),u=i.rollup!==`false`&&l!==`none`,d=ps(i.compact),f=ps(i.chevrons),p=fs(i.depth),m=hs(i[`folder-color`])??`amber`,h=a*({compact:1.45,relaxed:2.15}[i.spacing]??1.8),g=o===`none`?0:a*1.1,_=f?a*.85:0,v=o===`none`?0:a*.45,y=_+(g?g/2:a*.3),b=fs(i.indent)??y+a*.75,x=rs(e),S=ds(x),C=new Map(x.map((e,t)=>[e,S[t]])),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Map,E=e=>{let t=T.get(e);return t===void 0&&T.set(e,t=e.children.reduce((e,t)=>e+1+E(t),0)),t},D=a*.7,O=e=>r(e,D,600,n.mono)+a*.8,k=e=>{if(s===`none`)return e;let t=e=>Number(Zo.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(is(n))-Number(is(e)):0)||gs.compare(e.text,n.text))},A=e=>!e.note&&!e.badge&&!e.size&&!e.status&&!e.highlight&&!e.dim&&!e.icon&&!e.tone&&!e.collapsed,j=[],ee=(e,t,o)=>{let s=k(e);s.forEach((e,l)=>{let f=e,g=e=>e.collapsed||p!==void 0&&t+1>=p,_=[es(f.text)];for(;d&&f.children.length===1&&is(f)&&is(f.children[0])&&A(f)&&!g(f);)f=f.children[0],_.push(es(f.text));let v=is(f),y=!v&&Zo.test(f.text),x=v&&!g(f)&&f.children.length>0,S=y?`…`:_.length>1?_.join(`/`)+(f.text.endsWith(`/`)?`/`:``):f.text;i.slashes===`false`?S=S.replace(/\/$/,``):i.slashes===`true`&&v&&!S.endsWith(`/`)&&(S+=`/`);let[T,D]=v?[x?`folder-open`:`folder`,ss.test(es(f.text))?`gray`:m]:cs(f.text),k=f.icon??T,M=Wo.includes(k)?k:void 0,te=v?600:400,N=v&&(c===`all`||c===`collapsed`&&!x)&&f.children.length?String(E(f)):void 0,P=v&&u&&!f.status?_s(f,w):void 0,ne={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:M??`file`,iconTone:f.tone??(f.status?zo[f.status]:void 0)??(f.icon?void 0:D),iconText:M?void 0:f.icon,textW:H(R(S),a,n.mono,r,te),badgeW:f.badge?r(f.badge,a*.72,600,n.mono)+a*.9:0,count:N,countW:N?O(N):0,rollup:P?.size?P.size===1?[...P][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:j.length*h,x:t*b};j.push(ne),x&&ee(f.children,t+1,ne)})};ee(e,0);let M=e=>e.more?e.x+_:e.x+_+g+v,te=e=>M(e)+e.textW+a*.5,N=e=>(e.badgeW?te(e)+e.badgeW:M(e)+e.textW)+a*.45,P=e=>e.countW?N(e)+e.countW:e.badgeW?te(e)+e.badgeW:M(e)+e.textW,ne=i.notes===`inline`,F=a*.88,re=0;for(let e of j)re=Math.max(re,P(e));let ie=re+a*1.6,ae=e=>ne?P(e)+a*.9:ie,oe=e=>e.node.note?H(R(e.node.note),F,n.mono,r,400):0,se=e=>l!==`none`&&(e.node.status&&Vo[e.node.status]!==``||e.rollup!==void 0),ce=j.some(se),I=a*4;for(let e of j)I=Math.max(I,e.node.note?ae(e)+oe(e):P(e));let le=Math.max(0,...j.map(e=>e.sizeW)),ue=le?I+a*1.4+le:I,L=ue+a*1.2;return{rows:j,fs:a,smallFs:D,noteFs:F,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:M,badgeX:te,countX:N,noteX:ae,sizeRight:ue,markX:L,mark:se,w:ce?L+a*.8:ue,h:j.length*h}}),ws=e=>{let t=qe(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function Ts(e,t,n){if(!e.length)return``;let r=n.theme,i=Cs(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=ms(a.lines,ys,ys[0]),f=(e,t)=>e?V(e,r,t):t,p=f(hs(a[`line-color`]),r.edge.stroke),m=hs(a[`highlight-color`]),h=hs(a[`badge-color`])??`blue`,g=f(hs(a[`note-color`]),r.node.sub),_=f(hs(a[`strike-color`]),r.node.sub),v=fs(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=Ve(a)??1,b=`fill="none" stroke="${p}" stroke-width="${B(y)}" stroke-opacity="0.55"${ws(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,x=Math.min(fs(a.radius)??r.radius,(i.rowH-2)/2),S=B(o(-i.fs*.35)),C=B(i.w+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,y=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${S}" y="${B(s(e.y+1))}" width="${C}" height="${B(i.rowH-2)}" rx="${B(a.radius?x:Math.min(r.radius,i.rowH/3))}" fill="${o?.fill??r.accent}"${o?``:` fill-opacity="0.14"`}/>`)}else a.rows===`striped`&&t%2==1&&c.push(`<rect x="${S}" y="${B(s(e.y))}" width="${C}" height="${B(i.rowH)}" fill="${r.node.text}" fill-opacity="0.045"/>`);if(d!==`none`&&e.parent){let t=e.parent.x+i.anchor,n=Math.max(t,e.x-i.fs*.2);if(e.last){let r=e.parent.y+i.rowH/2+(i.iconW?i.iconW/2+i.fs*.1:i.fs*.5),a=d===`rounded`?Math.min(i.fs*.45,n-t,p-r):0;l.push(a>0?`<path d="M${B(o(t))},${B(s(r))}V${B(s(p-a))}Q${B(o(t))},${B(s(p))} ${B(o(t+a))},${B(s(p))}H${B(o(n))}" ${b}/>`:`<path d="M${B(o(t))},${B(s(r))}V${B(s(p))}H${B(o(n))}" ${b}/>`)}else l.push(`<path d="M${B(o(t))},${B(s(p))}H${B(o(n))}" ${b}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${B(t-n)},${B(s(p)-n/2)}L${B(t)},${B(s(p)+n/2)}L${B(t+n)},${B(s(p)-n/2)}`:`M${B(t-n/2)},${B(s(p)-n)}L${B(t+n/2)},${B(s(p))}L${B(t-n/2)},${B(s(p)+n)}`;y.push(`<path d="${a}" fill="none" stroke="${r.node.sub}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>`)}if(i.iconW&&!e.more){let t=o(e.x+i.chevW),n=s(p-i.iconW/2);if(e.iconText||i.icons===`emoji`)y.push(`<text x="${B(t+i.iconW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.95)}">${z(e.iconText??us[e.icon]??`📄`)}</text>`);else{let a=i.icons===`mono`,o=!a&&e.iconTone?r.tone(e.iconTone):void 0,s=a||!e.iconTone?r.node.sub:f(e.iconTone,r.node.sub),c=o?.fill??r.node.fill;y.push(`<g transform="translate(${B(t)},${B(n)}) scale(${B(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${ls(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));y.push(`<line x1="${B(t-i.fs*.15)}" y1="${B(s(p))}" x2="${B(t+e.textW+i.fs*.15)}" y2="${B(s(p))}" stroke="${_}" stroke-width="${B(v)}" stroke-linecap="round"/>`)}let w=n.status?f(zo[n.status],r.node.text):void 0,T=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):w??r.node.text,E=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(y.push(`<text x="${B(o(i.textX(e)))}" y="${B(s(p))}" dominant-baseline="central" font-size="${B(i.fs)}"${E} xml:space="preserve">${U(R(e.label),pe(r,T,T),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;y.push(`<rect x="${B(a)}" y="${B(s(p)-c/2)}" width="${B(e.badgeW)}" height="${B(c)}" rx="${B(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${B(a+e.badgeW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${z(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;y.push(`<rect x="${B(t)}" y="${B(s(p)-n/2)}" width="${B(e.countW)}" height="${B(n)}" rx="${B(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${B(t+e.countW/2)}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&y.push(`<text x="${B(o(i.noteX(e)))}" y="${B(s(p))}" dominant-baseline="central" font-size="${B(i.noteFs)}" xml:space="preserve">${U(R(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&y.push(`<text x="${B(o(i.sizeRight))}" y="${B(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${B(i.fs*.82)}" fill="${r.node.sub}">${z(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(zo[t],r.node.text);i.marks===`dot`||!n.status?y.push(`<circle cx="${B(o(i.markX))}" cy="${B(s(p))}" r="${B(i.fs*.22)}" fill="${a}"/>`):y.push(`<text x="${B(o(i.markX))}" y="${B(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${B(i.fs*.85)}" font-weight="700" fill="${a}">${Vo[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${y.join(``)}</g>`:y.join(``))}),c.join(``)+l.join(``)+u.join(``)}let Es={name:`treeview`,panels:[{name:`treeview`,guide:"indentation is the tree (several top-level entries are fine); `-` bullets and the `├──` / `│` prefixes of `tree` output are optional; `...` stands for more files. A folder has children, ends in `/` or says `[folder]`. `name: note` or `name # note` adds a note. Trailing props: a colour, `icon: "+Wo.join(`|`)+"|<emoji>`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `"+Bo.join(`|`)+"`. `match <glob> [props]` gives every matching entry those props (`*`, `**`, `?`, `{a,b}`; a trailing `/` matches folders only).",syntax:`treeview id "Title" [icons: color] { match *.test.ts [dim]\\n src/\\n index.ts: entry\\n util.ts [modified] }`,options:{icons:[...vs],lines:[...ys],sort:[...bs],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...xs],marks:[...Ss],rollup:[`true`,`false`],depth:`number`,indent:`number`,"folder-color":`color`,"line-color":`color`,"highlight-color":`color`,"badge-color":`color`,"note-color":`color`,"strike-color":`color`,"strike-width":`number`},parse:ns,measure(e,t){if(!e.length)return{w:0,h:0};let n=Cs(e,t);return{w:n.w,h:n.h}},render:Ts,parts(e){let t=rs(e);return ds(t).map((e,n)=>({id:e,label:t[n].text,kind:is(t[n])?`folder`:`file`,tone:t[n].tone}))},editPart:xr((e,t,n,r)=>{let i=rs(r),a=i[ds(i).indexOf(t)];if(!a)return null;let o=[...e],s=e[a.line],[c,l]=a.propSpan??[s.trimEnd().length,s.trimEnd().length],u=s.slice(c,l).match(/\[([^\]]*)\]/),{color:d,...f}=u?K(u[1]):{},p=er(n?{color:n,...f}:f);return o[a.line]=s.slice(0,c)+(p?` [${p}]`:``)+s.slice(l),o})}]},Ds=[Ur,Gr,Kr,ti,ai,fi,wi,_i,Ui,Qi,ua,ja,Ja,po,wo,Ro,Es];Nr(...Ds);function Os(e){let t=[],n=/* @__PURE__ */ 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 q.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:R(e.slice(0,s)),right:R(e.slice(s+4).trim())}):t.push({kind:`text`,left:R(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}let ks=e=>q.rows.find(t=>t.kind===e.kind);function As(e,t,n,r,i,a={}){let{weight:o}=a,s=t*(a.lineHeight??1.75),c={fs:t,lh:s,mono:n,measure:r,theme:i},l=[],u=[],d=0,f=0;for(let i of e){let e=s;if(i.kind===`text`){let e=i;d=Math.max(d,H(e.left,t,n,r,o)+(e.right?t*2+H(e.right,t,n,r,o):0))}else if(i.kind===`rule`)e=t*1.1;else if(i.kind===`gap`)e=t*.6;else{let t=ks(i)?.measure(i,c)??{w:0,h:0};d=Math.max(d,t.w),e=t.h}l.push(f),u.push(e),f+=e}return{rows:e,fs:t,lh:s,mono:n,weight:o,ys:l,hs:u,w:d,h:f}}function js(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.label.split(`
7
7
  `):[],o=e.sub?e.sub.split(`
8
- `):[],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=(r,a,o)=>be(r,a,o,t.mono,n,e.caps,i),p=0;a.forEach((t,n)=>{p=Math.max(p,f(t,r,d)+(n===0&&e.icon?u+8:0))});let m=e=>be(e,s,400,t.mono,n);for(let e of o)p=Math.max(p,m(e));e.meta&&(p+=s*2.4+m(e.meta)),!a.length&&e.meta&&(p=m(e.meta));let h=a.length||e.meta?Math.max(a.length*c,e.meta?l:0)+(o.length?o.length*l+2:0):0,g=e.body?.length?ps(ds(e.body),e.bodySize,e.mono,n,t,{weight:e.bodyWeight,lineHeight:e.lineHeight}):void 0,_=!e.frameless&&!!g&&h>0,v=g&&h>0?_?21:8:0,y=e.frameless?4:14,b=e.frame?.trim().match(/^(\S+)\s*(.*)$/),x=b?J.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=h+v+(g?.h??0)+(e.frameless?y*2:y*1.7)+C+w;return{pad:y,frameless:e.frameless,labelWeight:d,metaW:e.meta?m(e.meta):0,label:a,sub:o,icon:e.icon,meta:e.meta,caps:e.caps,italic:!!e.italic,labelSize:r,labelLh:c,subSize:s,subLh:l,iconSize:u,letterSpacing:i,headH:h,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 hs(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(De(c+e.iconSize/2,t,e.iconSize,a.text,z(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${B(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(De(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,we(i,e.caps?le(a):a,o,e.caps),` font-weight="${e.labelWeight}"${r}${e.italic?` font-style="italic"`:``} xml:space="preserve"`)));let i=u+e.label.length*e.labelLh+2;for(let t of e.sub)s.push(De(c,i+e.subLh/2,e.subSize,a.sub,we(t,le(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(De(l,t,e.subSize,a.sub,we(e.meta,le(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${B(t)},${B(n)}H${B(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(gs(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function gs(e,t,n,r,i,a){let o=[],s=e.fs,c={fs:s,lh:e.lh,mono:e.mono,measure:()=>0,theme:a,col:i};return e.rows.forEach((l,u)=>{let d=r+e.ys[u],f=e.hs[u];if(l.kind===`text`){let r=l,c=d+f/2;o.push(Me(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push(Me(r.right,n-Ae(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${B(t)},${B(d+f/2)}H${B(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push(fs(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${z(f)}"`:``}>${o.join(``)}</g>`}function _s(e,t,n){let r=[];for(let i of e.split(`
9
- `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of _e(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function vs(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=e=>{let t=/* @__PURE__ */ new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},f=d(e=>be(e,r,i,a.mono,o,s,l)),p=d(e=>be(e,u,400,a.mono,o)),m=_s(e,c,f),h=t?_s(t,c,p):[],g=Se(m,r),_=Se(h,u,1.35),v=Math.round(r*1.6),y=0;for(let e of m)y=Math.max(y,f(e));for(let e of h)y=Math.max(y,p(e));let b=m.length*g+h.length*_+(h.length?3:0);return n&&(b+=v+4,y=Math.max(y,v)),{lines:m,sub:h,icon:n,lineHeight:g,subSize:u,subLineHeight:_,iconSize:v,letterSpacing:l,caps:s,w:y,h:b}}function ys(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 bs(e,t){let n=[],r=/* @__PURE__ */ new Set,i=t;for(;i&&e.groups.has(i)&&!r.has(i);)r.add(i),n.push(i),i=e.groups.get(i).parent;return n.reverse()}function xs(e){let t=/* @__PURE__ */ 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 Ss(e,t,n,r){let i=e.flat(),a=/* @__PURE__ */ 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=/* @__PURE__ */ 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=xs(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=/* @__PURE__ */ 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=/* @__PURE__ */ 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 Cs(e,t){let n=Object.create(e),r=I(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}=M(t.font));let i=I(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=A(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)`):I(t.grid,e,e.dark?800:200)??e.grid:null),A(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,Fe(n,t)}let ws=e=>e===`right`||e===`left`;function Ts(e,t={}){return n(e.diagnostics,()=>Es(e,t))}function Es(e,t){let n=Cs(P(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??Jr,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=ws(i),o=W(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=W(e.settings[`rank-gap`],s?96:72),l=[`smooth`,`orthogonal`,`straight`].includes(e.settings.curve)?e.settings.curve:`smooth`,u=e.settings.shape,d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map;for(let t of e.nodes.values()){let i=Be(e,t),a=He(e,t,i,n),o=It(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=W(i[`max-width`],W(e.settings.wrap,0)),l=vs(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c),p;t.body?.length||i.meta||i.frame?(l.card=ms({label:t.label,sub:i.sub,icon:i.icon,meta:i.meta,caps:s,italic:a.italic,body:t.body,mono:i.mono!==`false`,frameless:o===`text`,fontSize:a.fontSize,weight:a.fontWeight,frame:i.frame,bodySize:a.bodySize,bodyWeight:a.bodyWeight,lineHeight:a.lineHeight},n,r),p={w:l.card.w,h:l.card.h}):p=Lt(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??js(W(i.width,p.w)),g=m?.h??js(W(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(Ne(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=ks(e,d,i);m.unshift(...h.edges),Ms(p,m);let g=Ns(p,m),_=[...e.layout.ranks??[],...h.same].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);_.length&&As(g,m,_);let v=new Set(m.flatMap(e=>[e.from,e.to])),y=/* @__PURE__ */ 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]])!v.has(e)&&v.has(n)&&!y.has(e)&&(y.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){As(g,m,[..._,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)y.set(e,t)}Os(e,h,g);let b=/* @__PURE__ */ new Map;for(let t of p){let n=d.get(t);b.set(t,{id:t,real:!0,path:bs(e,n.decl.group),oExt:a?n.h:n.w,rExt:a?n.w:n.h,rank:g.get(t),pos:0,u:0})}let x=[],S=/* @__PURE__ */ new Map;for(let e of m){let[t,n]=e.reversed?[e.to,e.from]:[e.from,e.to],r=g.get(t),i=g.get(n);if(e.hidden){x.push([t,n,2]);continue}if(i-r<=1){x.push([t,n,1]);continue}let a=b.get(t).path,o=b.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}`;b.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0,u:0}),x.push([c,r,c===t?1:2]),l.push(r),c=r}x.push([c,n,1]),S.set(e.idx,e.reversed?l.reverse():l)}let C=Math.max(0,...[...b.values()].map(e=>e.rank)),w=Array.from({length:C+1},()=>[]);for(let e of b.values())w[e.rank].push(e);let T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map;for(let e of b.keys())T.set(e,[]),E.set(e,[]);for(let[e,t,n]of x)E.get(e).push([t,n]),T.get(t).push([e,n]);Ps(w,T,E,y);let D=(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 w){let t=0;e.forEach((n,r)=>{r>0&&(t+=D(e[r-1],n)),n.pos=t})}let O=e=>e.length?e[e.length-1].pos-e[0].pos:0,k=Math.max(...w.map(O));for(let e of w){let t=(k-O(e))/2;for(let n of e)n.pos+=t}let A=e=>e.map(([e,t])=>[b.get(e),t]),j=[],ee=[],M=[];for(let e of b.values())j[e.u]=A(T.get(e.id)),ee[e.u]=A(E.get(e.id)),M[e.u]=[...j[e.u],...ee[e.u]];let te=w.map(e=>e.slice(1).map((t,n)=>D(e[n],t))),N=w.map((e,t)=>w.length-1-t),ne=w.map((e,t)=>t);for(let e=0;e<16;e++){let t=e<12?e%2==0?`down`:`up`:`both`,n=t===`down`?j:t===`up`?ee:M;for(let e of t===`up`?N:ne){let t=w[e];if(!t.length)continue;let r=[],i=[];for(let e of t){let t=0,a=0;for(let[r,i]of n[e.u])a+=r.pos*i,t+=i;r.push(t?a/t:e.pos),i.push(t||.25)}let a=Ls(r,i,te[e]);t.forEach((e,t)=>e.pos=a[t])}}Ss(w,a,o,D);let re=w.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),ie=Array(w.length).fill(0);e.edges.forEach(t=>{if(!t.label||!g.has(t.from)||!g.has(t.to))return;let i=Math.min(g.get(t.from),g.get(t.to));if(Math.abs(g.get(t.from)-g.get(t.to))!==1)return;let o=ze(Be(e,t),n),s=t.label.split(`
10
- `),c=a?Math.max(...s.map(e=>be(e,o.size,o.weight,n.mono,r)))+16:s.length*Se(s,o.size)+10;ie[i]=Math.max(ie[i],c)});let F=[],ae=0;for(let e=0;e<w.length;e++)F.push(ae+re[e]/2),ae+=re[e]+Math.max(c,ie[e]+44);let oe=(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 b.values()){if(!e.real)continue;let t=d.get(e.id),n=oe(F[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}let I=/* @__PURE__ */ new Map;for(let[e,t]of S)I.set(e,t.map(e=>{let t=b.get(e);return oe(F[t.rank],t.pos)}));let se=Math.max(0,...[...b.values()].map(e=>e.path.length)),ce=1/0,L=1/0;for(let e of d.values())ce=Math.min(ce,e.x),L=Math.min(L,e.y);if(d.size){let e=se*18-ce,t=se*44-L;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of I.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}let le=W(e.settings[`max-width`],0),ue=/* @__PURE__ */ new Set,de=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0);if(le>0&&a&&d.size&&!de){let t=/* @__PURE__ */ new Map;for(let[e,n]of S)t.set(e,n.map(e=>b.get(e).rank));Ds(e,d,g,I,t,ue,{maxW:le,dir:i,rankGap:c})}zs(e,d,a,o);let fe=[...d.values()].some(e=>e.pinned),pe=Us(e,d,n,r),me=/* @__PURE__ */ new Map;fe||e.edges.forEach((e,t)=>I.has(t)&&me.set(e.key,I.get(t)));let he=ct(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:me,channels:fe?void 0:ue,obstacles:[...d.values()],groups:pe.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),ge=t=>{if(!t.length)return[];let a=e.edges.filter(e=>!d.has(e.from)||!d.has(e.to));if(!a.length)return[];let o=new Map(d);for(let e of t)o.set(e.decl.id,{...e.box,id:e.decl.id,shape:`box`});return ct({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:/* @__PURE__ */ new Map,obstacles:[...o.values()]})},R=Js(e,n,r,Ws(d,pe,he,[]));he.push(...ge(R));let{bounds:_e,decor:ve}=Gs(Ws(d,pe,he,R),e,n,r),ye={nodes:d,groups:pe,edges:he,bounds:_e,direction:i,theme:n,blocks:f,decor:ve,panels:R};for(let t of jt)t(ye,e);return ye}function Ds(e,t,n,r,i,a,o){let s=W(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=/* @__PURE__ */ new Map;for(let n of t.values()){let t=bs(e,n.decl.group).length;l.set(n.id,{x:n.x-t*18,y:n.y-t*44,w:n.w+2*t*18,h:n.h+t*62})}let u=Array(c+1).fill(!1),d=/* @__PURE__ */ new Map;for(let r of t.values())for(let t of bs(e,r.decl.group)){let e=n.get(r.id),i=d.get(t)??[e,e];d.set(t,[Math.min(i[0],e),Math.max(i[1],e)])}for(let[e,t]of d.values())for(let n=e;n<t;n++)u[n]=!0;let f=Array.from({length:c+1},()=>[]);for(let e of t.values())f[n.get(e.id)].push(l.get(e.id));let p=e=>({x0:Math.min(...e.map(e=>e.x)),x1:Math.max(...e.map(e=>e.x+e.w)),y0:Math.min(...e.map(e=>e.y)),y1:Math.max(...e.map(e=>e.y+e.h))}),m=p([...l.values()]);if(m.x1-m.x0+2*s<=o.maxW)return;let h=Math.min(o.rankGap/2,36),g=Array(c+1).fill(0),_=0,v=[],y=0;for(;y<=c;){let e=y;for(;e<c&&u[e];)e++;let t=f.slice(y,e+1).flat(),n=[...v,...t];if(v.length&&t.length){let e=p(n);e.x1-e.x0+2*s+2*h>o.maxW&&(_++,v=[])}v.push(...t);for(let t=y;t<=e;t++)g[t]=_;y=e+1}if(_===0)return;let b=Array.from({length:_+1},(e,t)=>p(f.filter((e,n)=>g[n]===t).flat())),x=[],S=[],C=m.y0;for(let e of b)Number.isFinite(e.x0)?(x.push({x:o.dir===`left`?m.x1-e.x1:m.x0-e.x0,y:C-e.y0}),S.push(C),C+=e.y1-e.y0+o.rankGap):(x.push({x:0,y:0}),S.push(C));let w=e=>g[n.get(e)];for(let e of t.values()){let t=x[w(e.id)];e.x+=t.x,e.y+=t.y}let T=f.map((e,r)=>{let i=[...t.values()].filter(e=>n.get(e.id)===r);return i.length?p(i):void 0}),E=o.dir===`left`?-1:1,D=(e,t)=>{let n=T[e],r=E*t>0?n.x1:n.x0,i=T[e+t];return i&&g[e+t]===g[e]?(r+(E*t>0?i.x0:i.x1))/2:r+E*t*h};e.edges.forEach((e,s)=>{if(!t.has(e.from)||!t.has(e.to)||e.from===e.to)return;let[c,l]=[w(e.from),w(e.to)];if(c===l){let e=x[c],t=r.get(s);if(t&&i.get(s).every(e=>g[e]===c))for(let n of t)n.x+=e.x,n.y+=e.y;else r.delete(s);return}let u=t.get(e.from),d=t.get(e.to),f=D(n.get(e.from),1),p=D(n.get(e.to),-1),m=S[Math.max(c,l)]-o.rankGap/2;a.add(e.key),r.set(s,[{x:f,y:u.y+u.h/2},{x:f,y:m},{x:p,y:m},{x:p,y:d.y+d.h/2}])})}function Os(e,t,n){let r=[];for(let e of t.edges)n.get(e.to)<=n.get(e.from)&&r.push([e.byNode,e.from===e.byNode?e.to:e.from]);for(let[e,[i]]of t.order)n.get(e)!==n.get(i)&&r.push([e,i]);for(let[e,i]of t.same)n.get(e)!==n.get(i)&&r.push([e,i]);for(let[t,n]of r){let r=e.nodes.get(t),i=pn(Be(e,r))?.[0];if(!r.ref||!i)continue;let a=fn(r,i)+1,o=`${t} [${i}: ${n}] cannot be met: the edges between them run the other way, and the edges win`;e.diagnostics.some(e=>e.line===a&&e.message===o)||e.diagnostics.push({line:a,message:o,severity:`warning`})}}function ks(e,t,n){let r=[],i=/* @__PURE__ */ new Map,a=[],o=ws(n),s={right:`right-of`,left:`left-of`,down:`below`,up:`above`}[n],c={right:`left-of`,left:`right-of`,down:`above`,up:`below`}[n];for(let n of t.values()){let l=pn(Be(e,n.decl));if(!l)continue;let[u,d]=l;if(d===n.id||!t.has(d))continue;let f={idx:-1,reversed:!1,len:1,hidden:!0,byNode:n.id};u===s?r.push({from:d,to:n.id,...f}):u===c?r.push({from:n.id,to:d,...f}):u===`rank`?a.push([n.id,d]):i.set(n.id,[d,u===(o?`below`:`right-of`)?1:-1])}return{edges:r,order:i,same:a}}function As(e,t,n){let r=/* @__PURE__ */ 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}}let js=e=>Math.ceil(e/2)*2;function Ms(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t,[]);for(let e of t)n.get(e.from).push(e);let r=/* @__PURE__ */ 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 Ns(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ 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=/* @__PURE__ */ 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 Ps(e,t,n,r=/* @__PURE__ */ new Map){let i=/* @__PURE__ */ new Map;for(let t of e)for(let e of t)e.u=i.size,i.set(e.id,e.u);let a=i.size,o=Array(a),s=Array(a);for(let[e,r]of i)o[r]=t.get(e).map(([e])=>i.get(e)),s[r]=n.get(e).map(([e])=>i.get(e));let c=new Int32Array(a),l=e=>e.forEach((e,t)=>c[e.u]=t),u=new Float64Array(a),d=new Int32Array(a);e.forEach((e,t)=>e.forEach(e=>d[e.u]=t));let f=[];for(let[e,[t,n]]of r){let r=i.get(e),a=i.get(t);r!==void 0&&a!==void 0&&f.push([r,a,n])}let p=e=>{for(let t=0;t<Math.min(r.size,8);t++)for(let[t,n,r]of f)d[t]===e&&d[n]===e&&(u[t]=u[n]+r*.001)};e.forEach((e,t)=>{e.forEach((e,t)=>u[e.u]=t),p(t),Is(e,u),l(e)});let m=()=>{let t=0;for(let n=0;n<e.length-1;n++){let r=e[n+1].length,i=new Int32Array(r+1),a=0;for(let o of e[n]){let e=s[o.u].map(e=>c[e]);e.length>1&&e.sort((e,t)=>e-t);for(let n of e){let e=0;for(let t=n+1;t>0;t-=t&-t)e+=i[t];t+=a-e}for(let t of e)for(let e=t+1;e<=r;e+=e&-e)i[e]++;a+=e.length}}return t},h=e.map(e=>[...e]),g=m();for(let t=0;t<24&&g>0;t++){let n=t%2==0,r=n?o:s;for(let t=1;t<e.length;t++){let i=n?t:e.length-1-t,a=e[i];for(let e of a){let t=r[e.u],n=0;for(let e of t)n+=c[e];u[e.u]=t.length?n/t.length:c[e.u]}p(i),Is(a,u),l(a)}let i=m();i<g&&(g=i,h=e.map(e=>[...e]))}h.forEach((t,n)=>e[n]=t),Fs(e)}function Fs(e){let t=xs(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 Is(e,t){if(e.every(e=>!e.path.length)){let n=e.map((e,n)=>({v:e,orig:n,b:t[e.u]}));n.sort((e,t)=>e.b-t.b||e.orig-t.orig),n.forEach((t,n)=>e[n]=t.v);return}let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;for(let n of e)for(let e of n.path){let i=r.get(e)??[0,0];i[0]+=t[n.u],i[1]++,r.set(e,i)}for(let[e,[t,i]]of r)n.set(e,t/i);let i=e.map((e,r)=>({v:e,orig:r,ent:[...e.path,e.id],val:[...e.path.map(e=>n.get(e)),t[e.u]]}));i.sort((e,t)=>{let n=Math.max(e.ent.length,t.ent.length);for(let r=0;r<n;r++){if(e.ent[r]===t.ent[r])continue;let n=e.val[r]??0,i=t.val[r]??0;return n===i?e.orig-t.orig:n-i}return e.orig-t.orig}),i.forEach((t,n)=>e[n]=t.v)}function Ls(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 Rs(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 zs(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=>Rs(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 Bs(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s}=Vs(e,t),c=e=>be(e,i,a,t.mono,n,o,s),l=r.meta?be(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:c,meta:l,lineHeight:Math.round(Se(e.label.split(`
11
- `),i)*10)/10}}function Vs(e,t){let n=A(e.props.caps,!1),r=Re(e.props,t.fontSize*.82,600),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}function Hs(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=Bs(s,a,o),l=28+Math.max(...c.text.split(`
8
+ `):[],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=(r,a,o)=>Te(r,a,o,t.mono,n,e.caps,i),p=0;a.forEach((t,n)=>{p=Math.max(p,f(t,r,d)+(n===0&&e.icon?u+8:0))});let m=e=>Te(e,s,400,t.mono,n);for(let e of o)p=Math.max(p,m(e));e.meta&&(p+=s*2.4+m(e.meta)),!a.length&&e.meta&&(p=m(e.meta));let h=a.length||e.meta?Math.max(a.length*c,e.meta?l:0)+(o.length?o.length*l+2:0):0,g=e.body?.length?As(Os(e.body),e.bodySize,e.mono,n,t,{weight:e.bodyWeight,lineHeight:e.lineHeight}):void 0,_=!e.frameless&&!!g&&h>0,v=g&&h>0?_?21:8:0,y=e.frameless?4:14,b=e.frame?.trim().match(/^(\S+)\s*(.*)$/),x=b?q.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=h+v+(g?.h??0)+(e.frameless?y*2:y*1.7)+C+w;return{pad:y,frameless:e.frameless,labelWeight:d,metaW:e.meta?m(e.meta):0,label:a,sub:o,icon:e.icon,meta:e.meta,caps:e.caps,italic:!!e.italic,labelSize:r,labelLh:c,subSize:s,subLh:l,iconSize:u,letterSpacing:i,headH:h,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 Ms(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,z(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${B(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(Me(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,ke(i,e.caps?me(a):a,o,e.caps),` font-weight="${e.labelWeight}"${r}${e.italic?` font-style="italic"`:``} xml:space="preserve"`)));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,ke(t,me(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(Me(l,t,e.subSize,a.sub,ke(e.meta,me(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${B(t)},${B(n)}H${B(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(Ns(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function Ns(e,t,n,r,i,a){let o=[],s=e.fs,c={fs:s,lh:e.lh,mono:e.mono,measure:()=>0,theme:a,col:i};return e.rows.forEach((l,u)=>{let d=r+e.ys[u],f=e.hs[u];if(l.kind===`text`){let r=l,c=d+f/2;o.push(Le(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push(Le(r.right,n-Fe(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${B(t)},${B(d+f/2)}H${B(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push(ks(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${z(_)}"`:``}>${o.join(``)}</g>`}function Ps(e,t,n){let r=[];for(let i of e.split(`
9
+ `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of Se(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function Fs(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=e=>{let t=/* @__PURE__ */ new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},f=d(e=>Te(e,r,i,a.mono,o,s,l)),p=d(e=>Te(e,u,400,a.mono,o)),m=Ps(e,c,f),h=t?Ps(t,c,p):[],g=De(m,r),_=De(h,u,1.35),v=Math.round(r*1.6),y=0;for(let e of m)y=Math.max(y,f(e));for(let e of h)y=Math.max(y,p(e));let b=m.length*g+h.length*_+(h.length?3:0);return n&&(b+=v+4,y=Math.max(y,v)),{lines:m,sub:h,icon:n,lineHeight:g,subSize:u,subLineHeight:_,iconSize:v,letterSpacing:l,caps:s,w:y,h:b}}function Is(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 Ls(e,t){let n=[],r=/* @__PURE__ */ new Set,i=t;for(;i&&e.groups.has(i)&&!r.has(i);)r.add(i),n.push(i),i=e.groups.get(i).parent;return n.reverse()}function Rs(e){let t=/* @__PURE__ */ 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 zs(e,t,n,r){let i=e.flat(),a=/* @__PURE__ */ 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=/* @__PURE__ */ 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=Rs(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=/* @__PURE__ */ 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=/* @__PURE__ */ 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 Bs(e,t){let n=Object.create(e),r=L(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}=F(t.font));let i=L(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=N(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)`):L(t.grid,e,e.dark?800:200)??e.grid:null),N(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,Be(n,t)}let Vs=e=>e===`right`||e===`left`;function Hs(e,t={}){return n(e.diagnostics,()=>Us(e,t))}function Us(e,t){let n=Bs(se(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??Ir,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=Vs(i),o=He(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=He(e.settings[`rank-gap`],s?96:72),l=[`smooth`,`orthogonal`,`straight`].includes(e.settings.curve)?e.settings.curve:`smooth`,u=e.settings.shape,d=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Map;for(let t of e.nodes.values()){let i=Ke(e,t),a=Je(e,t,i,n),o=Vt(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=He(i[`max-width`],He(e.settings.wrap,0)),l=Fs(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c),p;t.body?.length||i.meta||i.frame?(l.card=js({label:t.label,sub:i.sub,icon:i.icon,meta:i.meta,caps:s,italic:a.italic,body:t.body,mono:i.mono!==`false`,frameless:o===`text`,fontSize:a.fontSize,weight:a.fontWeight,frame:i.frame,bodySize:a.bodySize,bodyWeight:a.bodyWeight,lineHeight:a.lineHeight},n,r),p={w:l.card.w,h:l.card.h}):p=Ut(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??Js(He(i.width,p.w)),g=m?.h??Js(He(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(Re(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=Ks(e,d,i);m.unshift(...h.edges),Ys(p,m);let g=Xs(p,m),_=[...e.layout.ranks??[],...h.same].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);_.length&&qs(g,m,_);let v=new Set(m.flatMap(e=>[e.from,e.to])),y=/* @__PURE__ */ 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]])!v.has(e)&&v.has(n)&&!y.has(e)&&(y.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){qs(g,m,[..._,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)y.set(e,t)}Gs(e,h,g);let b=/* @__PURE__ */ new Map;for(let t of p){let n=d.get(t);b.set(t,{id:t,real:!0,path:Ls(e,n.decl.group),oExt:a?n.h:n.w,rExt:a?n.w:n.h,rank:g.get(t),pos:0,u:0})}let x=[],S=/* @__PURE__ */ new Map;for(let e of m){let[t,n]=e.reversed?[e.to,e.from]:[e.from,e.to],r=g.get(t),i=g.get(n);if(e.hidden){x.push([t,n,2]);continue}if(i-r<=1){x.push([t,n,1]);continue}let a=b.get(t).path,o=b.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}`;b.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0,u:0}),x.push([c,r,c===t?1:2]),l.push(r),c=r}x.push([c,n,1]),S.set(e.idx,e.reversed?l.reverse():l)}let C=Math.max(0,...[...b.values()].map(e=>e.rank)),w=Array.from({length:C+1},()=>[]);for(let e of b.values())w[e.rank].push(e);let T=/* @__PURE__ */ new Map,E=/* @__PURE__ */ new Map;for(let e of b.keys())T.set(e,[]),E.set(e,[]);for(let[e,t,n]of x)E.get(e).push([t,n]),T.get(t).push([e,n]);Zs(w,T,E,y);let D=(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 w){let t=0;e.forEach((n,r)=>{r>0&&(t+=D(e[r-1],n)),n.pos=t})}let O=e=>e.length?e[e.length-1].pos-e[0].pos:0,k=Math.max(...w.map(O));for(let e of w){let t=(k-O(e))/2;for(let n of e)n.pos+=t}let A=e=>e.map(([e,t])=>[b.get(e),t]),j=[],ee=[],M=[];for(let e of b.values())j[e.u]=A(T.get(e.id)),ee[e.u]=A(E.get(e.id)),M[e.u]=[...j[e.u],...ee[e.u]];let te=w.map(e=>e.slice(1).map((t,n)=>D(e[n],t))),N=w.map((e,t)=>w.length-1-t),P=w.map((e,t)=>t);for(let e=0;e<16;e++){let t=e<12?e%2==0?`down`:`up`:`both`,n=t===`down`?j:t===`up`?ee:M;for(let e of t===`up`?N:P){let t=w[e];if(!t.length)continue;let r=[],i=[];for(let e of t){let t=0,a=0;for(let[r,i]of n[e.u])a+=r.pos*i,t+=i;r.push(t?a/t:e.pos),i.push(t||.25)}let a=ec(r,i,te[e]);t.forEach((e,t)=>e.pos=a[t])}}zs(w,a,o,D);let ne=w.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),F=Array(w.length).fill(0);e.edges.forEach(t=>{if(!t.label||!g.has(t.from)||!g.has(t.to))return;let i=Math.min(g.get(t.from),g.get(t.to));if(Math.abs(g.get(t.from)-g.get(t.to))!==1)return;let o=Ge(Ke(e,t),n),s=t.label.split(`
10
+ `),c=a?Math.max(...s.map(e=>Te(e,o.size,o.weight,n.mono,r)))+16:s.length*De(s,o.size)+10;F[i]=Math.max(F[i],c)});let re=[],ie=0;for(let e=0;e<w.length;e++)re.push(ie+ne[e]/2),ie+=ne[e]+Math.max(c,F[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 b.values()){if(!e.real)continue;let t=d.get(e.id),n=ae(re[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}let oe=/* @__PURE__ */ new Map;for(let[e,t]of S)oe.set(e,t.map(e=>{let t=b.get(e);return ae(re[t.rank],t.pos)}));let ce=Math.max(0,...[...b.values()].map(e=>e.path.length)),I=1/0,le=1/0;for(let e of d.values())I=Math.min(I,e.x),le=Math.min(le,e.y);if(d.size){let e=ce*18-I,t=ce*44-le;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)}let ue=He(e.settings[`max-width`],0),L=/* @__PURE__ */ new Set,de=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0);if(ue>0&&a&&d.size&&!de){let t=/* @__PURE__ */ new Map;for(let[e,n]of S)t.set(e,n.map(e=>b.get(e).rank));Ws(e,d,g,oe,t,L,{maxW:ue,dir:i,rankGap:c})}nc(e,d,a,o);let fe=[...d.values()].some(e=>e.pinned),pe=oc(e,d,n,r),me=/* @__PURE__ */ new Map;fe||e.edges.forEach((e,t)=>oe.has(t)&&me.set(e.key,oe.get(t)));let he=pt(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:me,channels:fe?void 0:L,obstacles:[...d.values()],groups:pe.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),ge=t=>{if(!t.length)return[];let a=e.edges.filter(e=>!d.has(e.from)||!d.has(e.to));if(!a.length)return[];let o=new Map(d);for(let e of t)o.set(e.decl.id,{...e.box,id:e.decl.id,shape:`box`});return pt({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:/* @__PURE__ */ new Map,obstacles:[...o.values()]})},_e=dc(e,n,r,sc(d,pe,he,[]));he.push(...ge(_e));let{bounds:ve,decor:ye}=cc(sc(d,pe,he,_e),e,n,r),be={nodes:d,groups:pe,edges:he,bounds:ve,direction:i,theme:n,blocks:f,decor:ye,panels:_e};for(let t of It)t(be,e);return be}function Ws(e,t,n,r,i,a,o){let s=He(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=/* @__PURE__ */ new Map;for(let n of t.values()){let t=Ls(e,n.decl.group).length;l.set(n.id,{x:n.x-t*18,y:n.y-t*44,w:n.w+2*t*18,h:n.h+t*62})}let u=Array(c+1).fill(!1),d=/* @__PURE__ */ new Map;for(let r of t.values())for(let t of Ls(e,r.decl.group)){let e=n.get(r.id),i=d.get(t)??[e,e];d.set(t,[Math.min(i[0],e),Math.max(i[1],e)])}for(let[e,t]of d.values())for(let n=e;n<t;n++)u[n]=!0;let f=Array.from({length:c+1},()=>[]);for(let e of t.values())f[n.get(e.id)].push(l.get(e.id));let p=e=>({x0:Math.min(...e.map(e=>e.x)),x1:Math.max(...e.map(e=>e.x+e.w)),y0:Math.min(...e.map(e=>e.y)),y1:Math.max(...e.map(e=>e.y+e.h))}),m=p([...l.values()]);if(m.x1-m.x0+2*s<=o.maxW)return;let h=Math.min(o.rankGap/2,36),g=Array(c+1).fill(0),_=0,v=[],y=0;for(;y<=c;){let e=y;for(;e<c&&u[e];)e++;let t=f.slice(y,e+1).flat(),n=[...v,...t];if(v.length&&t.length){let e=p(n);e.x1-e.x0+2*s+2*h>o.maxW&&(_++,v=[])}v.push(...t);for(let t=y;t<=e;t++)g[t]=_;y=e+1}if(_===0)return;let b=Array.from({length:_+1},(e,t)=>p(f.filter((e,n)=>g[n]===t).flat())),x=[],S=[],C=m.y0;for(let e of b)Number.isFinite(e.x0)?(x.push({x:o.dir===`left`?m.x1-e.x1:m.x0-e.x0,y:C-e.y0}),S.push(C),C+=e.y1-e.y0+o.rankGap):(x.push({x:0,y:0}),S.push(C));let w=e=>g[n.get(e)];for(let e of t.values()){let t=x[w(e.id)];e.x+=t.x,e.y+=t.y}let T=f.map((e,r)=>{let i=[...t.values()].filter(e=>n.get(e.id)===r);return i.length?p(i):void 0}),E=o.dir===`left`?-1:1,D=(e,t)=>{let n=T[e],r=E*t>0?n.x1:n.x0,i=T[e+t];return i&&g[e+t]===g[e]?(r+(E*t>0?i.x0:i.x1))/2:r+E*t*h};e.edges.forEach((e,s)=>{if(!t.has(e.from)||!t.has(e.to)||e.from===e.to)return;let[c,l]=[w(e.from),w(e.to)];if(c===l){let e=x[c],t=r.get(s);if(t&&i.get(s).every(e=>g[e]===c))for(let n of t)n.x+=e.x,n.y+=e.y;else r.delete(s);return}let u=t.get(e.from),d=t.get(e.to),f=D(n.get(e.from),1),p=D(n.get(e.to),-1),m=S[Math.max(c,l)]-o.rankGap/2;a.add(e.key),r.set(s,[{x:f,y:u.y+u.h/2},{x:f,y:m},{x:p,y:m},{x:p,y:d.y+d.h/2}])})}function Gs(e,t,n){let r=[];for(let e of t.edges)n.get(e.to)<=n.get(e.from)&&r.push([e.byNode,e.from===e.byNode?e.to:e.from]);for(let[e,[i]]of t.order)n.get(e)!==n.get(i)&&r.push([e,i]);for(let[e,i]of t.same)n.get(e)!==n.get(i)&&r.push([e,i]);for(let[t,n]of r){let r=e.nodes.get(t),i=yn(Ke(e,r))?.[0];if(!r.ref||!i)continue;let a=vn(r,i)+1,o=`${t} [${i}: ${n}] cannot be met: the edges between them run the other way, and the edges win`;e.diagnostics.some(e=>e.line===a&&e.message===o)||e.diagnostics.push({line:a,message:o,severity:`warning`})}}function Ks(e,t,n){let r=[],i=/* @__PURE__ */ new Map,a=[],o=Vs(n),s={right:`right-of`,left:`left-of`,down:`below`,up:`above`}[n],c={right:`left-of`,left:`right-of`,down:`above`,up:`below`}[n];for(let n of t.values()){let l=yn(Ke(e,n.decl));if(!l)continue;let[u,d]=l;if(d===n.id||!t.has(d))continue;let f={idx:-1,reversed:!1,len:1,hidden:!0,byNode:n.id};u===s?r.push({from:d,to:n.id,...f}):u===c?r.push({from:n.id,to:d,...f}):u===`rank`?a.push([n.id,d]):i.set(n.id,[d,u===(o?`below`:`right-of`)?1:-1])}return{edges:r,order:i,same:a}}function qs(e,t,n){let r=/* @__PURE__ */ 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}}let Js=e=>Math.ceil(e/2)*2;function Ys(e,t){let n=/* @__PURE__ */ new Map;for(let t of e)n.set(t,[]);for(let e of t)n.get(e.from).push(e);let r=/* @__PURE__ */ 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 Xs(e,t){let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ 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=/* @__PURE__ */ 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 Zs(e,t,n,r=/* @__PURE__ */ new Map){let i=/* @__PURE__ */ new Map;for(let t of e)for(let e of t)e.u=i.size,i.set(e.id,e.u);let a=i.size,o=Array(a),s=Array(a);for(let[e,r]of i)o[r]=t.get(e).map(([e])=>i.get(e)),s[r]=n.get(e).map(([e])=>i.get(e));let c=new Int32Array(a),l=e=>e.forEach((e,t)=>c[e.u]=t),u=new Float64Array(a),d=new Int32Array(a);e.forEach((e,t)=>e.forEach(e=>d[e.u]=t));let f=[];for(let[e,[t,n]]of r){let r=i.get(e),a=i.get(t);r!==void 0&&a!==void 0&&f.push([r,a,n])}let p=e=>{for(let t=0;t<Math.min(r.size,8);t++)for(let[t,n,r]of f)d[t]===e&&d[n]===e&&(u[t]=u[n]+r*.001)};e.forEach((e,t)=>{e.forEach((e,t)=>u[e.u]=t),p(t),$s(e,u),l(e)});let m=()=>{let t=0;for(let n=0;n<e.length-1;n++){let r=e[n+1].length,i=new Int32Array(r+1),a=0;for(let o of e[n]){let e=s[o.u].map(e=>c[e]);e.length>1&&e.sort((e,t)=>e-t);for(let n of e){let e=0;for(let t=n+1;t>0;t-=t&-t)e+=i[t];t+=a-e}for(let t of e)for(let e=t+1;e<=r;e+=e&-e)i[e]++;a+=e.length}}return t},h=e.map(e=>[...e]),g=m();for(let t=0;t<24&&g>0;t++){let n=t%2==0,r=n?o:s;for(let t=1;t<e.length;t++){let i=n?t:e.length-1-t,a=e[i];for(let e of a){let t=r[e.u],n=0;for(let e of t)n+=c[e];u[e.u]=t.length?n/t.length:c[e.u]}p(i),$s(a,u),l(a)}let i=m();i<g&&(g=i,h=e.map(e=>[...e]))}h.forEach((t,n)=>e[n]=t),Qs(e)}function Qs(e){let t=Rs(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 $s(e,t){if(e.every(e=>!e.path.length)){let n=e.map((e,n)=>({v:e,orig:n,b:t[e.u]}));n.sort((e,t)=>e.b-t.b||e.orig-t.orig),n.forEach((t,n)=>e[n]=t.v);return}let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;for(let n of e)for(let e of n.path){let i=r.get(e)??[0,0];i[0]+=t[n.u],i[1]++,r.set(e,i)}for(let[e,[t,i]]of r)n.set(e,t/i);let i=e.map((e,r)=>({v:e,orig:r,ent:[...e.path,e.id],val:[...e.path.map(e=>n.get(e)),t[e.u]]}));i.sort((e,t)=>{let n=Math.max(e.ent.length,t.ent.length);for(let r=0;r<n;r++){if(e.ent[r]===t.ent[r])continue;let n=e.val[r]??0,i=t.val[r]??0;return n===i?e.orig-t.orig:n-i}return e.orig-t.orig}),i.forEach((t,n)=>e[n]=t.v)}function ec(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 tc(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 nc(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=>tc(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 rc(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s}=ic(e,t),c=e=>Te(e,i,a,t.mono,n,o,s),l=r.meta?Te(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:c,meta:l,lineHeight:Math.round(De(e.label.split(`
11
+ `),i)*10)/10}}function ic(e,t){let n=N(e.props.caps,!1),r=We(e.props,t.fontSize*.82,600),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}function ac(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=rc(s,a,o),l=28+Math.max(...c.text.split(`
12
12
  `).map(c.width))+(c.meta?c.meta+12:0);if(l<=n.w&&!c.text.includes(`
13
- `))return;if(l>n.w){let a=n=>bs(e,n).includes(t),o=[],s=bs(e,t),c=(e,t,n)=>{let r=0;for(;r<t.length&&t[r]===s[r];)r++;let i=(t.length-n-r+s.length-1-r)*18;o.push({x:e.x-i,y:e.y-i,w:e.w+2*i,h:e.h+2*i})};for(let t of r.values())a(t.decl.group)||c(t,bs(e,t.decl.group),0);for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,bs(e,t),1);let u=-1/0,d=1/0;for(let e of o)e.y>=n.y+n.h+9||e.y+e.h<=n.y-9||(e.x+e.w<=n.x+1?u=Math.max(u,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=l-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-u));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let u=n.w-28-(c.meta?c.meta+12:0),d=_s(c.text,Math.max(u,40),c.width);if(d.length===1)return;let f=(d.length-1)*c.lineHeight;return n.y-=f,n.h+=f,{lines:d,header:26+f,lineHeight:c.lineHeight}}function Us(e,t,n,r){let i=t=>bs(e,t).length,a=[...e.groups.keys()].sort((e,t)=>i(t)-i(e)),o=/* @__PURE__ */ new Map,s=[];for(let c of a){let a=[];for(let e of t.values())e.decl.group===c&&a.push(e);for(let[t,n]of o)e.groups.get(t).parent===c&&a.push(n);if(!a.length)continue;let l=Math.min(...a.map(e=>e.x))-18,u=Math.min(...a.map(e=>e.y))-18-26,d=Math.max(...a.map(e=>e.x+e.w))+18,f=Math.max(...a.map(e=>e.y+e.h))+18,p={x:l,y:u,w:d-l,h:f-u},m=Hs(e,c,p,t,o,n,r);o.set(c,p);let h=e.groups.get(c);s.push({id:c,decl:h,depth:i(c),...p,...m??{},style:Ue({...h,props:Be(e,h)},n)})}return s.sort((e,t)=>e.depth-t.depth)}function Ws(e,t,n,r){let i=1/0,a=1/0,o=-1/0,s=-1/0,c=e=>{i=Math.min(i,e.x),a=Math.min(a,e.y),o=Math.max(o,e.x+(e.w??0)),s=Math.max(s,e.y+(e.h??0))};for(let t of e.values())c(t);for(let e of t)c(e);for(let e of n){for(let t of e.samples)c(t);e.label&&c(e.label)}for(let e of r)c(e.box);return Number.isFinite(i)?{x:i,y:a,w:o-i,h:s-a}:null}function Gs(e,t,n,r){let i=t.panels.length?0:100,[a,o,s,c]=e?[e.x,e.y,e.x+e.w,e.y+e.h]:[0,0,i,i],l=W(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=ys(t,n);u&&(o-=u.h,t.settings.title&&(s=Math.max(s,a+l+H(R(t.settings.title),u.titleSize,n.mono,r,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+H(R(t.settings.subtitle),u.subSize,n.mono,r)+l)));let d=[];for(let e of J.decorations){let i=t.settings[e.setting];if(!i)continue;let u=e.measure(i,n,r,t);u&&(u.w&&(s=Math.max(s,a+l*2+u.w)),u.bottom&&(d.push({name:e.name,value:i,area:{x:a,y:c,w:0,h:u.bottom}}),c+=u.bottom),u.top&&(o-=u.top,d.push({name:e.name,value:i,area:{x:a,y:o,w:0,h:u.top}})))}let f={x:Math.floor(a),y:Math.floor(o),w:Math.ceil(s-a),h:Math.ceil(c-o)};for(let e of d)e.area.x=f.x,e.area.w=f.w;return{bounds:f,decor:d}}let Ks=(e,t)=>e?t*2.3:0;function qs(e,t,n,r){return{theme:n,measure:r,fs:Le(e.props[`font-size`])??n.fontSize,props:e.props,offsets:t}}function Js(e,t,n,r){let i=[];for(let r of e.panels){let a=J.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=qs(r,o,Ge(t,r.props,e.themes),n),c=a.measure(r.data,s),l=Ks(r.label,s.fs),u=r.label?be(r.label,s.fs*1.05,Re(r.props,s.fs,650).weight,t.mono,n):0,d=js(Math.max(c.w,u)+32),f=js(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=W(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 t of i){let n=e.layout.panels?.[t.decl.id]?.at;n&&(t.box.x=n.x,t.box.y=n.y),t.inner.x=t.box.x+16,t.inner.y=t.box.y+16+Ks(t.decl.label,t.ctx.fs)}return i}let Ys=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`);function Xs(e,t){if(!t||!ce(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${Ys(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}let Z=e=>(Math.round(e*100)/100).toString(),Zs=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?Z(t):Ys(t)}"`,Qs=0;function $s(e){let t=t=>Te(R((e.nodes.get(t)??e.panels.find(e=>e.id===t))?.label??t)),n=e.edges.slice(0,40).map(e=>`${t(e.from)} to ${t(e.to)}${e.label?` (${Te(R(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&Te(R(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function ec(e,t,r={}){return n(e.diagnostics,()=>tc(e,t,r))}function tc(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(Qs++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&Te(R(s)),l=$s(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)}"`+Zs(`width`,n.width??a.w)+(n.width?``:Zs(`height`,a.h))+` role="img"${Zs(`aria-label`,c||`diagram`)}${l?Zs(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${Ys(r.font)}">`),c&&o.push(`<title>${Ys(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${Ys(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=ys(e,r);if(m){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=L(r,r.title);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">${U(R(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">${U(R(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=J.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:W(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(rc(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(ac(e,i,!!n.interactive));o.push(`</g>`),t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>nc(e,t,n.measure,d?`${i}-sh`:null,i)).join(``)}</g>`),o.push(`<g class="nodes">`);for(let n of t.nodes.values())o.push(cc(e,n,t,d?`${i}-sh`:null));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(sc(e,t));o.push(`</g></svg>`);let h=o.join(``);for(let n of Mt)h=n(h,e,t);return h}function nc(e,t,n,r,i){let a=t.theme,o=J.panels.get(e.decl.kind);if(!o)return``;let s=e.ctx.theme,c=Ke(e.decl.props,s,a),{box:l}=e,u=Ks(e.decl.label,e.ctx.fs),d=Re(e.decl.props,e.ctx.fs,650),f=[`<g${Zs(`data-panel`,e.decl.id)}${Zs(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${Z(l.x)}" y="${Z(l.y)}" width="${Z(l.w)}" height="${Z(l.h)}" rx="${Z(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${Z(c.width)}"${Zs(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${Z(l.x+16)}" y="${Z(l.y+16+u*.32)}" dominant-baseline="central" font-size="${Z(e.ctx.fs*1.05)}" font-weight="${d.weight}"${d.italic?` font-style="italic"`:``} fill="${c.text}" xml:space="preserve">${U(R(e.decl.label),L(s,c.text),s)}</text>`),e.ctx.idPrefix=`${i}-${e.decl.id}`,f.push(o.render(e.decl.data,e.inner,!n||n===e.ctx.measure?e.ctx:{...e.ctx,measure:n})),f.push(`</g>`),f.join(``)}function rc(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=Vs(e.decl,r),c=e.decl.label,l=L(r,i.text,i.stroke),u=e.lines??[c],d=u.length>1?Ce(u,e.x+18-4,t=>e.y+17+t*e.lineHeight,e=>we(e,l,r,s.caps)):we(c,l,r,s.caps),f=c?`<text x="${Z(e.x+18-4)}" y="${Z(e.y+17)}" font-size="${Z(s.size)}" font-weight="${s.weight}"${s.italic?` font-style="italic"`:``} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${d}</text>`:``,p=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}" xml:space="preserve">${we(o.meta,le(l),r)}</text>`:``;return`<g${Zs(`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"${Zs(`stroke-dasharray`,i.dash)}/>`+f+p+`</g>`}function ic(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 ac(e,t,n){let r=e.style,i=[];i.push(`<g${Zs(`data-edge`,e.key)}${r.opacity<1?Zs(`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"`+Zs(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+Zs(`stroke-dasharray`,n)+ic(t,n)+`/>`,a+Zs(`stroke-dasharray`,n)+ic(t,n,!0)+`/>`)}else i.push(a+Zs(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?ic(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(Nt(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function oc(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 sc(e,t){let n=e.label,r=t.theme,i=e.style,a=i.fontSize,{x:o,y:s}=n.anchor,c=[],l=n.text?n.text.split(`
14
- `):[],u=L(r,i.text,i.stroke);if(l.length){let{w:d,h:f}=n.pill,p=n.lineHeight,m=s-(l.length-1)*p/2,h=Ce(l,o,e=>m+e*p,e=>we(e,u,r)),g=r.edge.labelStroke,_=`x="${Z(o-d/2)}" y="${Z(s-f/2)}" width="${Z(d)}" height="${Z(f)}" rx="${g?Z(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...oc(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${Z(a)}" font-weight="${i.fontWeight}"${i.italic?` font-style="italic"`:``} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
15
- `),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${Z(o-(n.rotate?n.h:p)/2)}" y="${Z(f)}" width="${Z(n.rotate?n.h:p)}" height="${Z(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=Ce(i,o,e=>f+d*(e+.5)+1,e=>we(e,le(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${Z(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${Z(o)} ${Z(s)})"`:``;return`<g${Zs(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function cc(e,t,n,r){let i=t.style,a=Be(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${Ys(a.tooltip)}</title>`:``;if(s.push(`<g${Zs(`data-node`,t.id)}${i.opacity<1?Zs(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${zt(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${Z(i.strokeWidth)}"`+Zs(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=Bt(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&&J.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}));let r={text:i.text,sub:i.sub,stroke:i.stroke,body:i.body};s.push(hs(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`);let c=s.join(``);return c=Xs(c,a.link),c}let l=t.x+t.w/2,u=t.y+t.h/2+Rt(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)}">${Ys(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={text:i.text,sub:i.sub,stroke:i.stroke},p=Ce(o.lines,l,e=>u+o.lineHeight*(e+.5),e=>we(e,f,n.theme,o.caps));if(s.push(`<text ${d} xml:space="preserve">${p}</text>`),u+=o.lines.length*o.lineHeight,o.sub.length){u+=3;let e=Ce(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>we(e,le(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${Z(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}s.push(`</g>`);let m=s.join(``);return m=Xs(m,a.link),m}let lc=/* @__PURE__ */ new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),uc=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,dc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,fc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,pc=ir;function mc(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||(fc.test(i)?r[i]=typeof a==`object`?JSON.stringify(a):String(a):n.push(`prop name ${JSON.stringify(i)} must use only letters, digits, "_" and "-"`));let i=Jn(r);return i?` [${i}]`:``}let hc=e=>!!e&&typeof e==`object`&&!Array.isArray(e),gc=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&dc.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),_c=e=>Array.isArray(e)?e:[e];function vc(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=e=>{let r=n[e];return r==null?[]:Array.isArray(r)?r.filter((n,r)=>hc(n)||(t.push(`${e}[${r}] must be an object`),!1)):(t.push(`"${e}" must be an array`),[])},i=e=>{let r=n[e];return r==null||hc(r)?r??{}:(t.push(`"${e}" must be an object`),{})},a=[],o={...i(`settings`)};for(let e of[`title`,`direction`,`theme`])n[e]!==void 0&&(o[e]=n[e]);for(let[e,n]of Object.entries(o))fc.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?pc(String(n)):String(n)}`):t.push(`setting name ${JSON.stringify(e)} must use only letters, digits, "_" and "-"`);a.length&&a.push(``);let s=Object.entries(i(`classes`));for(let[e,n]of s)dc.test(e)?hc(n)?a.push(`.${e}${mc(n,[],t)}`):t.push(`class "${e}" must be an object of props`):t.push(`class name ${JSON.stringify(e)} is not a valid name`);s.length&&a.push(``);let c=(e,n)=>typeof e==`string`&&uc.test(e)?!0:(t.push(`${n} id ${JSON.stringify(e)} must start with a letter and use only letters, digits, "_" and "-"`),!1),l=(e,n)=>{let r=`${e.id}${e.label===void 0?``:` `+pc(String(e.label))}${gc(e.class,t)}${mc(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
13
+ `))return;if(l>n.w){let a=n=>Ls(e,n).includes(t),o=[],s=Ls(e,t),c=(e,t,n)=>{let r=0;for(;r<t.length&&t[r]===s[r];)r++;let i=(t.length-n-r+s.length-1-r)*18;o.push({x:e.x-i,y:e.y-i,w:e.w+2*i,h:e.h+2*i})};for(let t of r.values())a(t.decl.group)||c(t,Ls(e,t.decl.group),0);for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,Ls(e,t),1);let u=-1/0,d=1/0;for(let e of o)e.y>=n.y+n.h+9||e.y+e.h<=n.y-9||(e.x+e.w<=n.x+1?u=Math.max(u,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=l-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-u));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let u=n.w-28-(c.meta?c.meta+12:0),d=Ps(c.text,Math.max(u,40),c.width);if(d.length===1)return;let f=(d.length-1)*c.lineHeight;return n.y-=f,n.h+=f,{lines:d,header:26+f,lineHeight:c.lineHeight}}function oc(e,t,n,r){let i=t=>Ls(e,t).length,a=[...e.groups.keys()].sort((e,t)=>i(t)-i(e)),o=/* @__PURE__ */ new Map,s=[];for(let c of a){let a=[];for(let e of t.values())e.decl.group===c&&a.push(e);for(let[t,n]of o)e.groups.get(t).parent===c&&a.push(n);if(!a.length)continue;let l=Math.min(...a.map(e=>e.x))-18,u=Math.min(...a.map(e=>e.y))-18-26,d=Math.max(...a.map(e=>e.x+e.w))+18,f=Math.max(...a.map(e=>e.y+e.h))+18,p={x:l,y:u,w:d-l,h:f-u},m=ac(e,c,p,t,o,n,r);o.set(c,p);let h=e.groups.get(c);s.push({id:c,decl:h,depth:i(c),...p,...m,style:Ye({...h,props:Ke(e,h)},n)})}return s.sort((e,t)=>e.depth-t.depth)}function sc(e,t,n,r){let i=1/0,a=1/0,o=-1/0,s=-1/0,c=e=>{i=Math.min(i,e.x),a=Math.min(a,e.y),o=Math.max(o,e.x+(e.w??0)),s=Math.max(s,e.y+(e.h??0))};for(let t of e.values())c(t);for(let e of t)c(e);for(let e of n){for(let t of e.samples)c(t);e.label&&c(e.label)}for(let e of r)c(e.box);return Number.isFinite(i)?{x:i,y:a,w:o-i,h:s-a}:null}function cc(e,t,n,r){let i=t.panels.length?0:100,[a,o,s,c]=e?[e.x,e.y,e.x+e.w,e.y+e.h]:[0,0,i,i],l=He(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=Is(t,n);u&&(o-=u.h,t.settings.title&&(s=Math.max(s,a+l+H(R(t.settings.title),u.titleSize,n.mono,r,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+H(R(t.settings.subtitle),u.subSize,n.mono,r)+l)));let d=[];for(let e of q.decorations){let i=t.settings[e.setting];if(!i)continue;let u=e.measure(i,n,r,t);u&&(u.w&&(s=Math.max(s,a+l*2+u.w)),u.bottom&&(d.push({name:e.name,value:i,area:{x:a,y:c,w:0,h:u.bottom}}),c+=u.bottom),u.top&&(o-=u.top,d.push({name:e.name,value:i,area:{x:a,y:o,w:0,h:u.top}})))}let f={x:Math.floor(a),y:Math.floor(o),w:Math.ceil(s-a),h:Math.ceil(c-o)};for(let e of d)e.area.x=f.x,e.area.w=f.w;return{bounds:f,decor:d}}let lc=(e,t)=>e?t*2.3:0;function uc(e,t,n,r){return{theme:n,measure:r,fs:Ue(e.props[`font-size`])??n.fontSize,props:e.props,offsets:t}}function dc(e,t,n,r){let i=[];for(let r of e.panels){let a=q.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=uc(r,o,Ze(t,r.props,e.themes),n),c=r.failed?{w:0,h:0}:a.measure(r.data,s),l=lc(r.label,s.fs),u=r.label?Te(r.label,s.fs*1.05,We(r.props,s.fs,650).weight,t.mono,n):0,d=Js(Math.max(c.w,u)+32),f=Js(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??=!r.failed&&a.handles?.(r.data,p,s)||[]}})}if(!i.length)return i;let a=He(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 t of i){let n=e.layout.panels?.[t.decl.id]?.at;n&&(t.box.x=n.x,t.box.y=n.y),t.inner.x=t.box.x+16,t.inner.y=t.box.y+16+lc(t.decl.label,t.ctx.fs)}return i}let fc=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`);function pc(e,t){if(!t||!fe(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${fc(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}let X=e=>(Math.round(e*100)/100).toString(),Z=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?X(t):fc(t)}"`,mc=0;function hc(e){let t=t=>Ae(R((e.nodes.get(t)??e.panels.find(e=>e.id===t))?.label??t)),n=e.edges.slice(0,40).map(e=>`${t(e.from)} to ${t(e.to)}${e.label?` (${Ae(R(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&Ae(R(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function gc(e,t,r={}){return n(e.diagnostics,()=>_c(e,t,r))}function _c(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(mc++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&Ae(R(s)),l=hc(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="${X(a.x)} ${X(a.y)} ${X(a.w)} ${X(a.h)}"`+Z(`width`,n.width??a.w)+(n.width?``:Z(`height`,a.h))+` role="img"${Z(`aria-label`,c||`diagram`)}${l?Z(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${fc(r.font)}">`),c&&o.push(`<title>${fc(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${fc(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="${X(a.x)}" y="${X(a.y)}" width="${X(a.w)}" height="${X(a.h)}" fill="${r.background}"/>`),r.grid&&o.push(`<rect x="${X(a.x)}" y="${X(a.y)}" width="${X(a.w)}" height="${X(a.h)}" fill="url(#${i}-grid)"/>`)),p&&o.push(`<rect x="${X(a.x)}" y="${X(a.y)}" width="${X(a.w)}" height="${X(a.h)}" fill="url(#${i}-snap)" pointer-events="none"/>`);let m=Is(e,r);if(m){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=pe(r,r.title);s&&(o.push(`<text x="${X(a.x+t)}" y="${X(n+m.titleSize*.8)}" font-size="${X(m.titleSize)}" font-weight="650" xml:space="preserve">${U(R(s),i,r)}</text>`),n+=m.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${X(a.x+t)}" y="${X(n+m.subSize*.95)}" font-size="${X(m.subSize)}" xml:space="preserve">${U(R(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=q.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:He(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(yc(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(xc(e,i,!!n.interactive));o.push(`</g>`),t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>vc(e,t,n.measure,d?`${i}-sh`:null,i)).join(``)}</g>`),o.push(`<g class="nodes">`);for(let n of t.nodes.values())o.push(wc(e,n,t,d?`${i}-sh`:null));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(Cc(e,t));o.push(`</g></svg>`);let h=o.join(``);for(let n of Lt)h=n(h,e,t);return h}function vc(e,t,n,r,i){let a=t.theme,o=q.panels.get(e.decl.kind);if(!o)return``;let s=e.ctx.theme,c=Qe(e.decl.props,s,a),{box:l}=e,u=lc(e.decl.label,e.ctx.fs),d=We(e.decl.props,e.ctx.fs,650),f=[`<g${Z(`data-panel`,e.decl.id)}${Z(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${X(l.x)}" y="${X(l.y)}" width="${X(l.w)}" height="${X(l.h)}" rx="${X(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${X(c.width)}"${Z(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${X(l.x+16)}" y="${X(l.y+16+u*.32)}" dominant-baseline="central" font-size="${X(e.ctx.fs*1.05)}" font-weight="${d.weight}"${d.italic?` font-style="italic"`:``} fill="${c.text}" xml:space="preserve">${U(R(e.decl.label),pe(s,c.text),s)}</text>`),e.ctx.idPrefix=`${i}-${e.decl.id}`,e.decl.failed||f.push(o.render(e.decl.data,e.inner,!n||n===e.ctx.measure?e.ctx:{...e.ctx,measure:n})),f.push(`</g>`),f.join(``)}function yc(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=ic(e.decl,r),c=e.decl.label,l=pe(r,i.text,i.stroke),u=e.lines??[c],d=u.length>1?Oe(u,e.x+18-4,t=>e.y+17+t*e.lineHeight,e=>ke(e,l,r,s.caps)):ke(c,l,r,s.caps),f=c?`<text x="${X(e.x+18-4)}" y="${X(e.y+17)}" font-size="${X(s.size)}" font-weight="${s.weight}"${s.italic?` font-style="italic"`:``} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${d}</text>`:``,p=o.meta?`<text x="${X(e.x+e.w-18+4)}" y="${X(e.y+17)}" text-anchor="end" font-size="${X(a)}" fill="${r.node.sub}" xml:space="preserve">${ke(o.meta,me(l),r)}</text>`:``;return`<g${Z(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${X(e.x)}" y="${X(e.y)}" width="${X(e.w)}" height="${X(e.h)}" rx="${X(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${Z(`stroke-dasharray`,i.dash)}/>`+f+p+`</g>`}function bc(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:${X(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${X(-i)}px${a}"`}function xc(e,t,n){let r=e.style,i=[];i.push(`<g${Z(`data-edge`,e.key)}${r.opacity<1?Z(`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="${X(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${X(e*3)} ${X(e*9)}`;i.push(a+` opacity="0.35"`+Z(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+Z(`stroke-dasharray`,n)+bc(t,n)+`/>`,a+Z(`stroke-dasharray`,n)+bc(t,n,!0)+`/>`)}else i.push(a+Z(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?bc(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(Rt(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function Sc(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 Cc(e,t){let n=e.label,r=t.theme,i=e.style,a=i.fontSize,{x:o,y:s}=n.anchor,c=[],l=n.text?n.text.split(`
14
+ `):[],u=pe(r,i.text,i.stroke);if(l.length){let{w:d,h:f}=n.pill,p=n.lineHeight,m=s-(l.length-1)*p/2,h=Oe(l,o,e=>m+e*p,e=>ke(e,u,r)),g=r.edge.labelStroke,_=`x="${X(o-d/2)}" y="${X(s-f/2)}" width="${X(d)}" height="${X(f)}" rx="${g?X(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...Sc(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${X(a)}" font-weight="${i.fontWeight}"${i.italic?` font-style="italic"`:``} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
15
+ `),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${X(o-(n.rotate?n.h:p)/2)}" y="${X(f)}" width="${X(n.rotate?n.h:p)}" height="${X(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=Oe(i,o,e=>f+d*(e+.5)+1,e=>ke(e,me(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${X(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${X(o)} ${X(s)})"`:``;return`<g${Z(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function wc(e,t,n,r){let i=t.style,a=Ke(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${fc(a.tooltip)}</title>`:``;if(s.push(`<g${Z(`data-node`,t.id)}${i.opacity<1?Z(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${Gt(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${X(i.strokeWidth)}"`+Z(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=Kt(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${X(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&q.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}));let r={text:i.text,sub:i.sub,stroke:i.stroke,body:i.body};s.push(Ms(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`);let c=s.join(``);return c=pc(c,a.link),c}let l=t.x+t.w/2,u=t.y+t.h/2+Wt(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${X(l)}" y="${X(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${X(o.iconSize)}">${fc(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${X(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+(i.italic?` font-style="italic"`:``)+(o.letterSpacing?` letter-spacing="${X(o.letterSpacing)}"`:``),f={text:i.text,sub:i.sub,stroke:i.stroke},p=Oe(o.lines,l,e=>u+o.lineHeight*(e+.5),e=>ke(e,f,n.theme,o.caps));if(s.push(`<text ${d} xml:space="preserve">${p}</text>`),u+=o.lines.length*o.lineHeight,o.sub.length){u+=3;let e=Oe(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>ke(e,me(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${X(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}s.push(`</g>`);let m=s.join(``);return m=pc(m,a.link),m}let Tc=/* @__PURE__ */ new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),Ec=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,Dc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,Oc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,kc=ur;function Ac(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||(Oc.test(i)?r[i]=typeof a==`object`?JSON.stringify(a):String(a):n.push(`prop name ${JSON.stringify(i)} must use only letters, digits, "_" and "-"`));let i=er(r);return i?` [${i}]`:``}let jc=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Mc=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&Dc.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),Nc=e=>Array.isArray(e)?e:[e];function Pc(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=e=>{let r=n[e];return r==null?[]:Array.isArray(r)?r.filter((n,r)=>jc(n)||(t.push(`${e}[${r}] must be an object`),!1)):(t.push(`"${e}" must be an array`),[])},i=e=>{let r=n[e];return r==null||jc(r)?r??{}:(t.push(`"${e}" must be an object`),{})},a=[],o={...i(`settings`)};for(let e of[`title`,`direction`,`theme`])n[e]!==void 0&&(o[e]=n[e]);for(let[e,n]of Object.entries(o))Oc.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?kc(String(n)):String(n)}`):t.push(`setting name ${JSON.stringify(e)} must use only letters, digits, "_" and "-"`);a.length&&a.push(``);let s=Object.entries(i(`classes`));for(let[e,n]of s)Dc.test(e)?jc(n)?a.push(`.${e}${Ac(n,[],t)}`):t.push(`class "${e}" must be an object of props`):t.push(`class name ${JSON.stringify(e)} is not a valid name`);s.length&&a.push(``);let c=(e,n)=>typeof e==`string`&&Ec.test(e)?!0:(t.push(`${n} id ${JSON.stringify(e)} must start with a letter and use only letters, digits, "_" and "-"`),!1),l=(e,n)=>{let r=`${e.id}${e.label===void 0?``:` `+kc(String(e.label))}${Mc(e.class,t)}${Ac(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
16
16
  `);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(`
17
- `)):n+r},u=r(`groups`).filter(e=>c(e.id,`group`)),d=new Set(u.map(e=>e.id)),f=r(`nodes`).filter(e=>c(e.id,`node`));for(let e of f)e.group&&!d.has(e.group)&&c(e.group,`group`)&&(u.push({id:e.group}),d.add(e.group));let p=(e,n)=>{let r=` `.repeat(n);for(let t of f.filter(t=>(t.group||void 0)===e))a.push(l(t,r));for(let i of u.filter(t=>(t.parent||void 0)===e))a.push(`${r}group ${i.id}${i.label===void 0?``:` `+pc(String(i.label))}${gc(i.class,t)}${mc(i,[`id`,`label`,`parent`,`class`],t)} {`),p(i.id,n+1),a.push(`${r}}`)};for(let e of u)e.parent&&!d.has(e.parent)&&t.push(`group "${e.id}" has unknown parent "${e.parent}"`);p(void 0,0),(f.length||u.length)&&a.push(``);for(let e of r(`edges`)){if(e.from===void 0||e.to===void 0){t.push(`edge ${JSON.stringify(e)} needs "from" and "to"`);continue}let n=_c(e.from).filter(e=>c(e,`edge.from`)),r=_c(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;lc.has(i)||t.push(`edge arrow "${i}" must be one of ${[...lc].join(` `)}`);let o=`${e.label===void 0?``:` `+pc(String(e.label))}${gc(e.class,t)}${mc(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${lc.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
17
+ `)):n+r},u=r(`groups`).filter(e=>c(e.id,`group`)),d=new Set(u.map(e=>e.id)),f=r(`nodes`).filter(e=>c(e.id,`node`));for(let e of f)e.group&&!d.has(e.group)&&c(e.group,`group`)&&(u.push({id:e.group}),d.add(e.group));let p=(e,n)=>{let r=` `.repeat(n);for(let t of f.filter(t=>(t.group||void 0)===e))a.push(l(t,r));for(let i of u.filter(t=>(t.parent||void 0)===e))a.push(`${r}group ${i.id}${i.label===void 0?``:` `+kc(String(i.label))}${Mc(i.class,t)}${Ac(i,[`id`,`label`,`parent`,`class`],t)} {`),p(i.id,n+1),a.push(`${r}}`)};for(let e of u)e.parent&&!d.has(e.parent)&&t.push(`group "${e.id}" has unknown parent "${e.parent}"`);p(void 0,0),(f.length||u.length)&&a.push(``);for(let e of r(`edges`)){if(e.from===void 0||e.to===void 0){t.push(`edge ${JSON.stringify(e)} needs "from" and "to"`);continue}let n=Nc(e.from).filter(e=>c(e,`edge.from`)),r=Nc(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;Tc.has(i)||t.push(`edge arrow "${i}" must be one of ${[...Tc].join(` `)}`);let o=`${e.label===void 0?``:` `+kc(String(e.label))}${Mc(e.class,t)}${Ac(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${Tc.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
18
18
  `).replace(/\n+$/,``)+`
19
- `,errors:t}}let Q=e=>JSON.stringify(e),yc=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:Q(e);function bc(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,`
20
- `).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()}let $=(e,t=!1)=>bc(e,t).replace(/\s*\n\s*/g,` `);function xc(e,t=Sc){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}let Sc=/* @__PURE__ */ new Set([`group`,`layout`,`import`,`export`,`def`]);function Cc(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 wc(e,t,n,r,i){let a=[e,t];return n&&a.push(Q(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}function Tc(e){let t=e.match(/^title\b\s*:?\s*(.*)$/i);return t?bc(t[1]):void 0}function Ec(e,t){return/^(accTitle|accDescr)\b/.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function Dc(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}let Oc=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:Q(e),kc=a({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 Ac(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=kc[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(`, `)}let jc=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Mc={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`};function Nc(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(Q(e.label));for(let t of e.classes)n.push(`.${t}`);let r=[];e.note&&r.push(`shape: note`),e.sub&&r.push(`sub: ${Q(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(Q(e.id)),[`${t}${n.join(` `)} {`,...i.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function Pc(e,t,n,r,i,a,o){let s=[];for(let e of i.items)s.push(...Nc(r.get(e),``));for(let e of a){s.push(`group ${e.id} ${Q(e.label)} {`);for(let t of e.items)s.push(...Nc(r.get(t),` `));s.push(`}`)}o.length&&s.push(``);for(let e of o){let t=[e.label?Oc(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]}let Fc=a({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),Ic=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,Lc=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,Rc=e=>e.replace(/~([^~]*)~/g,`<$1>`),zc=e=>e.replace(/~[^~]*~/g,``),Bc=(e,t)=>{let n=/* @__PURE__ */ new Map,r={id:``,label:``,items:[]},i=[],a=r,o=[],s=[],c=`down`,l=t.title,u=0,d=e=>{let t=xc(zc(e)),r=n.get(t);return r||(r={id:t,attrs:[],methods:[],rows:[],classes:[]},(t!==e||/~/.test(e))&&(r.label=Rc(e.replace(/^"(.*)"$/,`$1`))),n.set(t,r),a.items.push(t)),r},f=(e,t)=>{let n=Rc(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=bc(_[1]);continue}let v=h.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(v){c=Mc[v[1].toUpperCase()];continue}let y=h.match(/^namespace\s+(\S+)\s*\{$/);if(y){a={id:xc(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=$(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:bc(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:bc(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=Ac(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=Ac(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(Ic)??h.match(Lc);if(D){let[,e,n,r,i,a,s,c,l]=D,u=[];r&&u.push(`tail: ${Fc[r]}`),a&&u.push(`head: ${Fc[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: ${Q(f.join(` to `))}`),o.push({from:d(e).id,to:d(c).id,arrow:i,props:u,label:l?$(l):void 0});continue}let O=h.match(/^([^\s:]+)\s*:\s*(.*)$/);O?f(d(O[1]),O[2]):g(`could not read "${h}"`)}return Pc(l,c,s,n,r,i,o)},Vc={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},Hc={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Uc=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,Wc=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,Gc=(e,t)=>{let n=/* @__PURE__ */ new Map,r={id:``,label:``,items:[]},i=[],a=`down`,o=t.title,s=e=>{let t=e.replace(/^"(.*)"$/,`$1`),i=xc(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=bc(l[1]);continue}let u=c.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(u){a=Mc[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(Wc);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(Uc);if(f){let[,e,t,n,r,a,o]=f;i.push({from:s(e).id,to:s(a).id,arrow:n===`..`?`..`:`--`,props:[`caption: ${Q(`${Vc[t]} to ${Hc[r]}`)}`],label:$(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 Pc(o,a,[],n,r,[],i)};function Kc(e,t){let n=Tc(e.text);return n!==void 0&&(t.title=n,!0)}let qc=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,Jc=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,Yc=(e,t)=>{let n={title:t.title},r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=!1,s=(e,t,n=!1)=>{let o=e.trim(),s=i.get(o),c=!s;if(s||(s=xc(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} ${Q(i)}`),a.add(s)}return s};for(let i of e){let e=i.text;if(Ec(i,t)||Kc(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():$(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(`, `)}: ${$(c[2])}`);continue}let l=e.match(Jc);if(l){t.warnOnce(`block`,i.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[l[1],$(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(qc);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)}: ${$(c)}`)}else t.warn(i.line,`could not read "${e}"`)}return wc(`sequence`,Cc(n.title,`seq`),n.title,o?[`numbered`]:[],r)},Xc=(e,t)=>{let n={title:t.title},r=[],i,a=0;for(let o of e){let e=o.text;if(Ec(o,t)||Kc(o,n))continue;let s=e.match(/^section\s+(.*)$/);if(s){i=jc[a++%jc.length],t.warnOnce(`section`,o.line,`timeline sections become a colour per section`),r.push(`// ${$(s[1])}`);continue}let c=e.split(/\s*:\s*/).map(e=>$(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 wc(`timeline`,Cc(n.title,`events`),n.title,[],r)},Zc=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function Qc(e){let t={};for(let n of e.matchAll(Zc))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}let $c=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``),el=(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(Ec(r,t)||Kc(r,n))continue;let i=e.match(/^commit\b(.*)$/);if(i){let e=Qc(i[1]),t=[];e.id&&t.push(`id: ${yc($c(e.id))}`),e.tag&&t.push(`tag: ${yc(e.tag)}`),o(e,t),a.push([`commit`,e.msg?Q(e.msg):``,t.length?`[${t.join(`, `)}]`:``].filter(Boolean).join(` `));continue}let s=e.match(/^branch\s+("[^"]*"|\S+)(.*)$/);if(s){let e=Qc(s[2]);a.push(`branch ${$c(s[1])}${e.order?` [order: ${e.order}]`:``}`);continue}let c=e.match(/^(checkout|switch)\s+(.+)$/);if(c){a.push(`${c[1]} ${$c(c[2])}`);continue}let l=e.match(/^merge\s+("[^"]*"|\S+)(.*)$/);if(l){let e=Qc(l[2]),t=[];e.id&&t.push(`id: ${yc($c(e.id))}`),e.tag&&t.push(`tag: ${yc(e.tag)}`),o(e,t),a.push(`merge ${$c(l[1])}${t.length?` [${t.join(`, `)}]`:``}`);continue}let u=e.match(/^cherry-pick\b(.*)$/);if(u){let e=Qc(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 ${$c(e.id)}`):t.warn(r.line,`cherry-pick needs an id`)}else t.warn(r.line,`could not read "${e}"`)}return wc(`git`,Cc(n.title,`history`),n.title,r,a)},tl=e=>/[[\]:]|^"/.test(e)?Q(e):e,nl=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=Tc(r)??n.title);let i=[];for(let r of e){if(Ec(r,t)||Kc(r,n)||r.text===`showData`)continue;let e=r.text.match(/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/);e?i.push(`${tl($(e[1]))}: ${e[2]}`):t.warn(r.line,`could not read "${r.text}"`)}return wc(`chart`,Cc(n.title,`pie`),n.title,[`type: pie`],i)},rl=(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(Ec(r,t)||Kc(r,n))continue;let o=e.match(/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/);if(o){let e=o[1].trim();e.startsWith(`[`)?i=Dc(e).map(e=>$(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:Dc(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=Cc(n.title,`xy`),s=[];return a.forEach((e,t)=>{let a=e.values.map((e,t)=>`${tl(i[t]??String(t+1))}: ${e}`),c=e.type===`line`?`line`:r?`bar`:`column`;t&&s.push(``),s.push(...wc(`chart`,t?`${o}${t+1}`:o,n.title,[`type: ${c}`],a))}),a.length||s.push(...wc(`chart`,o,n.title,[`type: column`],[])),s},il=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(Ec(i,t)||Kc(i,n))continue;let a=e.match(/^section\s+(.*)$/);if(a){r.push(`// ${$(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(`${tl($(o[1]))} [${n}]: ${o[2]}`)}else t.warn(i.line,`could not read "${e}"`)}return wc(`chart`,Cc(n.title,`journey`),n.title,[`type: column`],r)},al=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function ol(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 al){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:bc(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:bc(r,!0)}}let sl=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(Ec(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=ol(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return wc(`mindmap`,Cc(t.title,`map`),t.title,[`layout: both`],n)},cl=/* @__PURE__ */ new Set([`done`,`active`,`crit`,`milestone`]),ll=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,ul=(e,t)=>{let n={title:t.title},r=/* @__PURE__ */ new Set,i=[];for(let t of e){let e=t.text.match(/^([^:]+?)\s*:\s*(.*)$/);if(!e||/^(title|dateFormat|section)\b/.test(t.text)||ll.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=>!cl.has(e));a.length===3&&r.add(xc(a[0]))}let a=/* @__PURE__ */ 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)??xc(e)).join(` `)),u=[],d=0,f=!0;for(let r of e){let e=r.text;if(Ec(r,t)||Kc(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(ll.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(`--- ${$(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=>cl.has(e)),g=m.items.filter(e=>!cl.has(e)),_,v,y;g.length>=3?[_,v,y]=[xc(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=[_,Q($(m.label)),h.length?`[${h.join(`, `)}]`:``].filter(Boolean).join(` `);u.push(b?`${x}: ${b}`:x)}return wc(`gantt`,Cc(n.title,`plan`),n.title,[],u)},dl=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(Ec(i,t)||Kc(i,n))continue;let a=e.match(/^([xy])-axis\s+(.*)$/);if(a){let[e,t]=a[2].split(/\s*-->\s*/).map(e=>$(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]}: ${$(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=Qc(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(`${$(s[1])}${a}: ${s[2]}, ${s[3]}`)}else t.warn(i.line,`could not read "${e}"`)}return wc(`quadrant`,Cc(n.title,`matrix`),n.title,[],r)},fl=a({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`});function pl(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:$(r,!0),meta:t}}let ml=(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(Ec(i,t))continue;let{text:e,meta:a}=pl(i.text);if(i.indent<=r){n.push(e);continue}let o=[];if(a.assigned&&o.push(`owner: ${yc(a.assigned)}`),a.ticket&&o.push(`ticket: ${yc(a.ticket)}`),a.priority){let e=fl[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}: ${yc(t)}`);n.push(` - ${e}${o.length?` [${o.join(`, `)}]`:``}`)}return wc(`kanban`,Cc(t.title,`board`),t.title,[],n)},hl={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},gl={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},_l=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ 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=xc(e),a=n.get(i);return a?t!==`state`&&(a.kind=t):(a={id:i,kind:t,descs:[],classes:[]},i!==e.trim()&&(a.label=bc(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(xc(n[1])))return xc(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=bc(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=hl[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=xc(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]:bc(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=$(S[1]);continue}let C=g.match(/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/);if(C){let e=f(C[1]);C[2]&&e.descs.push($(C[2]));continue}let w=g.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=Ac(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=Ac(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(`
21
- `)}let r=m(D[1].trim(),!1),i=`note${++u}`;n.set(i,{id:i,label:bc(t),kind:`note`,descs:[],classes:[]}),d().items.push(i),o.push({from:i,to:r,dotted:!0});continue}let O=g.match(/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/);if(O){let e=m(O[1],!1),t=m(O[2],!0);o.push({from:e,to:t,label:O[3]?$(O[3]):void 0,line:h.line});continue}let k=g.match(/^([^\s:]+)\s*:\s*(.*)$/);k?f(k[1]).descs.push($(k[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??yl(n)??e.from),i&&(e.to=i.start??vl(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} ${Q(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(Q(o));let s=gl[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: ${Q(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?`: `+Oc(e.label):``}`)}let b=[l?`title: ${l}`:``,`direction: ${c}`].filter(Boolean),x=[..._,...s];return[...b,...x.length?[``,...x]:[],``,...v]};function vl(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??vl(t);if(e)return e}}function yl(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??yl(n);if(r)return r}}let bl=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*;?\s*$/i,xl={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Sl=a({sequenceDiagram:Yc,timeline:Xc,gitGraph:el,pie:nl,"xychart-beta":rl,xychart:rl,journey:il,mindmap:sl,gantt:ul,quadrantChart:dl,kanban:ml,stateDiagram:_l,"stateDiagram-v2":_l,classDiagram:Bc,"classDiagram-v2":Bc,erDiagram:Gc}),Cl=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function wl(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 Tl(e){for(let t=wl(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function El(e){let t=e.split(`
22
- `),n=Tl(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 Sl||Cl.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 Dl(e){let t=e.split(`
23
- `),n=Tl(t);if(n>=0&&bl.test(t[n]))return!0;let r=El(e);return!!r&&r.type in Sl}function Ol(e){let t=El(e);return t&&!(t.type in Sl)?t.type:void 0}function kl(e){let t=El(e),n=t&&Sl[t.type];if(!t||!n)return Pl(e);let r=[],i=/* @__PURE__ */ new Set,a=e.split(`
24
- `),o;for(let e=0;e<wl(a);e++){let t=a[e].match(/^\s*title\s*:\s*(.+)$/);t&&(o=bc(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(`
19
+ `,errors:t}}let Q=e=>JSON.stringify(e),Fc=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:Q(e);function Ic(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,`
20
+ `).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()}let $=(e,t=!1)=>Ic(e,t).replace(/\s*\n\s*/g,` `);function Lc(e,t=Rc){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}let Rc=/* @__PURE__ */ new Set([`group`,`layout`,`import`,`export`,`def`]);function zc(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 Bc(e,t,n,r,i){let a=[e,t];return n&&a.push(Q(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}function Vc(e){let t=e.match(/^title\b\s*:?\s*(.*)$/i);return t?Ic(t[1]):void 0}function Hc(e,t){return/^(accTitle|accDescr)\b/.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function Uc(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}let Wc=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:Q(e),Gc=u({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 Kc(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=Gc[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(`, `)}let qc=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Jc={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`};function Yc(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(Q(e.label));for(let t of e.classes)n.push(`.${t}`);let r=[];e.note&&r.push(`shape: note`),e.sub&&r.push(`sub: ${Q(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(Q(e.id)),[`${t}${n.join(` `)} {`,...i.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function Xc(e,t,n,r,i,a,o){let s=[];for(let e of i.items)s.push(...Yc(r.get(e),``));for(let e of a){s.push(`group ${e.id} ${Q(e.label)} {`);for(let t of e.items)s.push(...Yc(r.get(t),` `));s.push(`}`)}o.length&&s.push(``);for(let e of o){let t=[e.label?Wc(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]}let Zc=u({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),Qc=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,$c=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,el=e=>e.replace(/~([^~]*)~/g,`<$1>`),tl=e=>e.replace(/~[^~]*~/g,``),nl=(e,t)=>{let n=/* @__PURE__ */ new Map,r={id:``,label:``,items:[]},i=[],a=r,o=[],s=[],c=`down`,l=t.title,u=0,d=e=>{let t=Lc(tl(e)),r=n.get(t);return r||(r={id:t,attrs:[],methods:[],rows:[],classes:[]},(t!==e||/~/.test(e))&&(r.label=el(e.replace(/^"(.*)"$/,`$1`))),n.set(t,r),a.items.push(t)),r},f=(e,t)=>{let n=el(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=Ic(_[1]);continue}let v=h.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(v){c=Jc[v[1].toUpperCase()];continue}let y=h.match(/^namespace\s+(\S+)\s*\{$/);if(y){a={id:Lc(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=$(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:Ic(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:Ic(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=Kc(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=Kc(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(Qc)??h.match($c);if(D){let[,e,n,r,i,a,s,c,l]=D,u=[];r&&u.push(`tail: ${Zc[r]}`),a&&u.push(`head: ${Zc[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: ${Q(f.join(` to `))}`),o.push({from:d(e).id,to:d(c).id,arrow:i,props:u,label:l?$(l):void 0});continue}let O=h.match(/^([^\s:]+)\s*:\s*(.*)$/);O?f(d(O[1]),O[2]):g(`could not read "${h}"`)}return Xc(l,c,s,n,r,i,o)},rl={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},il={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},al=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,ol=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,sl=(e,t)=>{let n=/* @__PURE__ */ new Map,r={id:``,label:``,items:[]},i=[],a=`down`,o=t.title,s=e=>{let t=e.replace(/^"(.*)"$/,`$1`),i=Lc(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=Ic(l[1]);continue}let u=c.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(u){a=Jc[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(ol);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(al);if(f){let[,e,t,n,r,a,o]=f;i.push({from:s(e).id,to:s(a).id,arrow:n===`..`?`..`:`--`,props:[`caption: ${Q(`${rl[t]} to ${il[r]}`)}`],label:$(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 Xc(o,a,[],n,r,[],i)};function cl(e,t){let n=Vc(e.text);return n!==void 0&&(t.title=n,!0)}let ll=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,ul=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,dl=(e,t)=>{let n={title:t.title},r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=!1,s=(e,t,n=!1)=>{let o=e.trim(),s=i.get(o),c=!s;if(s||(s=Lc(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} ${Q(i)}`),a.add(s)}return s};for(let i of e){let e=i.text;if(Hc(i,t)||cl(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():$(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(`, `)}: ${$(c[2])}`);continue}let l=e.match(ul);if(l){t.warnOnce(`block`,i.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[l[1],$(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(ll);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)}: ${$(c)}`)}else t.warn(i.line,`could not read "${e}"`)}return Bc(`sequence`,zc(n.title,`seq`),n.title,o?[`numbered`]:[],r)},fl=(e,t)=>{let n={title:t.title},r=[],i,a=0;for(let o of e){let e=o.text;if(Hc(o,t)||cl(o,n))continue;let s=e.match(/^section\s+(.*)$/);if(s){i=qc[a++%qc.length],t.warnOnce(`section`,o.line,`timeline sections become a colour per section`),r.push(`// ${$(s[1])}`);continue}let c=e.split(/\s*:\s*/).map(e=>$(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 Bc(`timeline`,zc(n.title,`events`),n.title,[],r)},pl=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function ml(e){let t={};for(let n of e.matchAll(pl))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}let hl=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``),gl=(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(Hc(r,t)||cl(r,n))continue;let i=e.match(/^commit\b(.*)$/);if(i){let e=ml(i[1]),t=[];e.id&&t.push(`id: ${Fc(hl(e.id))}`),e.tag&&t.push(`tag: ${Fc(e.tag)}`),o(e,t),a.push([`commit`,e.msg?Q(e.msg):``,t.length?`[${t.join(`, `)}]`:``].filter(Boolean).join(` `));continue}let s=e.match(/^branch\s+("[^"]*"|\S+)(.*)$/);if(s){let e=ml(s[2]);a.push(`branch ${hl(s[1])}${e.order?` [order: ${e.order}]`:``}`);continue}let c=e.match(/^(checkout|switch)\s+(.+)$/);if(c){a.push(`${c[1]} ${hl(c[2])}`);continue}let l=e.match(/^merge\s+("[^"]*"|\S+)(.*)$/);if(l){let e=ml(l[2]),t=[];e.id&&t.push(`id: ${Fc(hl(e.id))}`),e.tag&&t.push(`tag: ${Fc(e.tag)}`),o(e,t),a.push(`merge ${hl(l[1])}${t.length?` [${t.join(`, `)}]`:``}`);continue}let u=e.match(/^cherry-pick\b(.*)$/);if(u){let e=ml(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 ${hl(e.id)}`):t.warn(r.line,`cherry-pick needs an id`)}else t.warn(r.line,`could not read "${e}"`)}return Bc(`git`,zc(n.title,`history`),n.title,r,a)},_l=e=>/[[\]:]|^"/.test(e)?Q(e):e,vl=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=Vc(r)??n.title);let i=[];for(let r of e){if(Hc(r,t)||cl(r,n)||r.text===`showData`)continue;let e=r.text.match(/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/);e?i.push(`${_l($(e[1]))}: ${e[2]}`):t.warn(r.line,`could not read "${r.text}"`)}return Bc(`chart`,zc(n.title,`pie`),n.title,[`type: pie`],i)},yl=(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(Hc(r,t)||cl(r,n))continue;let o=e.match(/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/);if(o){let e=o[1].trim();e.startsWith(`[`)?i=Uc(e).map(e=>$(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:Uc(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=zc(n.title,`xy`),s=[];return a.forEach((e,t)=>{let a=e.values.map((e,t)=>`${_l(i[t]??String(t+1))}: ${e}`),c=e.type===`line`?`line`:r?`bar`:`column`;t&&s.push(``),s.push(...Bc(`chart`,t?`${o}${t+1}`:o,n.title,[`type: ${c}`],a))}),a.length||s.push(...Bc(`chart`,o,n.title,[`type: column`],[])),s},bl=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(Hc(i,t)||cl(i,n))continue;let a=e.match(/^section\s+(.*)$/);if(a){r.push(`// ${$(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(`${_l($(o[1]))} [${n}]: ${o[2]}`)}else t.warn(i.line,`could not read "${e}"`)}return Bc(`chart`,zc(n.title,`journey`),n.title,[`type: column`],r)},xl=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function Sl(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 xl){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:Ic(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:Ic(r,!0)}}let Cl=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(Hc(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=Sl(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return Bc(`mindmap`,zc(t.title,`map`),t.title,[`layout: both`],n)},wl=/* @__PURE__ */ new Set([`done`,`active`,`crit`,`milestone`]),Tl=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,El=(e,t)=>{let n={title:t.title},r=/* @__PURE__ */ new Set,i=[];for(let t of e){let e=t.text.match(/^([^:]+?)\s*:\s*(.*)$/);if(!e||/^(title|dateFormat|section)\b/.test(t.text)||Tl.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=>!wl.has(e));a.length===3&&r.add(Lc(a[0]))}let a=/* @__PURE__ */ 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)??Lc(e)).join(` `)),u=[],d=0,f=!0;for(let r of e){let e=r.text;if(Hc(r,t)||cl(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(Tl.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(`--- ${$(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=>wl.has(e)),g=m.items.filter(e=>!wl.has(e)),_,v,y;g.length>=3?[_,v,y]=[Lc(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=[_,Q($(m.label)),h.length?`[${h.join(`, `)}]`:``].filter(Boolean).join(` `);u.push(b?`${x}: ${b}`:x)}return Bc(`gantt`,zc(n.title,`plan`),n.title,[],u)},Dl=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(Hc(i,t)||cl(i,n))continue;let a=e.match(/^([xy])-axis\s+(.*)$/);if(a){let[e,t]=a[2].split(/\s*-->\s*/).map(e=>$(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]}: ${$(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=ml(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(`${$(s[1])}${a}: ${s[2]}, ${s[3]}`)}else t.warn(i.line,`could not read "${e}"`)}return Bc(`quadrant`,zc(n.title,`matrix`),n.title,[],r)},Ol=u({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`});function kl(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:$(r,!0),meta:t}}let Al=(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(Hc(i,t))continue;let{text:e,meta:a}=kl(i.text);if(i.indent<=r){n.push(e);continue}let o=[];if(a.assigned&&o.push(`owner: ${Fc(a.assigned)}`),a.ticket&&o.push(`ticket: ${Fc(a.ticket)}`),a.priority){let e=Ol[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}: ${Fc(t)}`);n.push(` - ${e}${o.length?` [${o.join(`, `)}]`:``}`)}return Bc(`kanban`,zc(t.title,`board`),t.title,[],n)},jl={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Ml={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},Nl=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ 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=Lc(e),a=n.get(i);return a?t!==`state`&&(a.kind=t):(a={id:i,kind:t,descs:[],classes:[]},i!==e.trim()&&(a.label=Ic(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(Lc(n[1])))return Lc(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=Ic(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=jl[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=Lc(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]:Ic(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=$(S[1]);continue}let C=g.match(/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/);if(C){let e=f(C[1]);C[2]&&e.descs.push($(C[2]));continue}let w=g.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=Kc(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=Kc(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(`
21
+ `)}let r=m(D[1].trim(),!1),i=`note${++u}`;n.set(i,{id:i,label:Ic(t),kind:`note`,descs:[],classes:[]}),d().items.push(i),o.push({from:i,to:r,dotted:!0});continue}let O=g.match(/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/);if(O){let e=m(O[1],!1),t=m(O[2],!0);o.push({from:e,to:t,label:O[3]?$(O[3]):void 0,line:h.line});continue}let k=g.match(/^([^\s:]+)\s*:\s*(.*)$/);k?f(k[1]).descs.push($(k[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??Fl(n)??e.from),i&&(e.to=i.start??Pl(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} ${Q(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(Q(o));let s=Ml[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: ${Q(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?`: `+Wc(e.label):``}`)}let b=[l?`title: ${l}`:``,`direction: ${c}`].filter(Boolean),x=[..._,...s];return[...b,...x.length?[``,...x]:[],``,...v]};function Pl(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??Pl(t);if(e)return e}}function Fl(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??Fl(n);if(r)return r}}let Il=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*;?\s*$/i,Ll={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Rl=u({sequenceDiagram:dl,timeline:fl,gitGraph:gl,pie:vl,"xychart-beta":yl,xychart:yl,journey:bl,mindmap:Cl,gantt:El,quadrantChart:Dl,kanban:Al,stateDiagram:Nl,"stateDiagram-v2":Nl,classDiagram:nl,"classDiagram-v2":nl,erDiagram:sl}),zl=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function Bl(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 Vl(e){for(let t=Bl(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function Hl(e){let t=e.split(`
22
+ `),n=Vl(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 Rl||zl.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 Ul(e){let t=e.split(`
23
+ `),n=Vl(t);if(n>=0&&Il.test(t[n]))return!0;let r=Hl(e);return!!r&&r.type in Rl}function Wl(e){let t=Hl(e);return t&&!(t.type in Rl)?t.type:void 0}function Gl(e){let t=Hl(e),n=t&&Rl[t.type];if(!t||!n)return Xl(e);let r=[],i=/* @__PURE__ */ new Set,a=e.split(`
24
+ `),o;for(let e=0;e<Bl(a);e++){let t=a[e].match(/^\s*title\s*:\s*(.+)$/);t&&(o=Ic(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(`
25
25
  `).replace(/^\n+/,``)+`
26
- `,warnings:r}}let Al=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],jl=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,Ml=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,Nl=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/;function Pl(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=[],s=0,c=/* @__PURE__ */ 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),Sc.has(t)&&(t+=`_`),i.set(e,t),t)},u=()=>` `.repeat(s),d=e.split(`
27
- `),f=wl(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 Fl(p)){let t=e.trim();if(!t)continue;let d=t.match(bl);if(d){d[2]&&r.push(`direction: ${xl[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: ${xl[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]),bc(i[2])]:/^".*"$/.test(e)?[r,t]=[bc(e),l(bc(e).toLowerCase())]:/^[\w-]+$/.test(e)?[t,r]=[l(e),e]:[r,t]=[e,l(e.toLowerCase())],c.add(t),n.push(`${u()}group ${t} ${Q(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=Ac(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=Ac(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=Il(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(Q(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:Q(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(`
26
+ `,warnings:r}}let Kl=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],ql=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,Jl=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,Yl=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/;function Xl(e){let t=[],n=[],r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=[],s=0,c=/* @__PURE__ */ 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),Rc.has(t)&&(t+=`_`),i.set(e,t),t)},u=()=>` `.repeat(s),d=e.split(`
27
+ `),f=Bl(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 Zl(p)){let t=e.trim();if(!t)continue;let d=t.match(Il);if(d){d[2]&&r.push(`direction: ${Ll[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: ${Ll[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]),Ic(i[2])]:/^".*"$/.test(e)?[r,t]=[Ic(e),l(Ic(e).toLowerCase())]:/^[\w-]+$/.test(e)?[t,r]=[l(e),e]:[r,t]=[e,l(e.toLowerCase())],c.add(t),n.push(`${u()}group ${t} ${Q(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=Kc(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=Kc(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=Ql(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(Q(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:Q(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(`
28
28
  `)+`
29
- `,warnings:t}}function Fl(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 Il(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(jl);if(!e)return null;r+=e[0].length;let n={id:t(e[0]),classes:[]};for(let[e,t,a]of Al){if(!i.startsWith(e,r))continue;let o=Ll(i,r+e.length,t);if(!(o<0)){n.label=bc(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(Ml),o,s,l,f;if(a&&/[->=]/.test(a[4]))[o,s,f]=[a[1],a[2],bc(a[3])],l=a[4].endsWith(`>`)?`>`:a[5],r+=a[0].length;else{if(a=t.match(Nl),!a){n(`could not read "${t}"`);break}[o,s,l]=[a[1],a[2],a[3]],f=a[4]===void 0?void 0:bc(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 Ll(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}let Rl=e=>Math.round(e),zl=e=>e.split(/\r?\n/),Bl=e=>e.includes(`\r
29
+ `,warnings:t}}function Zl(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 Ql(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(ql);if(!e)return null;r+=e[0].length;let n={id:t(e[0]),classes:[]};for(let[e,t,a]of Kl){if(!i.startsWith(e,r))continue;let o=$l(i,r+e.length,t);if(!(o<0)){n.label=Ic(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(Jl),o,s,l,f;if(a&&/[->=]/.test(a[4]))[o,s,f]=[a[1],a[2],Ic(a[3])],l=a[4].endsWith(`>`)?`>`:a[5],r+=a[0].length;else{if(a=t.match(Yl),!a){n(`could not read "${t}"`);break}[o,s,l]=[a[1],a[2],a[3]],f=a[4]===void 0?void 0:Ic(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 $l(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}let eu=e=>Math.round(e),tu=e=>e.split(/\r?\n/),nu=e=>e.includes(`\r
30
30
  `)?`\r
31
31
  `:`
32
- `,Vl=(e,t)=>e.join(Bl(t));function Hl(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 ${Rl(r.x)} ${Rl(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${Rl(r.w)} ${Rl(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=>`${Rl(e.x)} ${Rl(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(Rl(r.label.x)||Rl(r.label.y))&&e.push(`label ${Rl(r.label.x)} ${Rl(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 ${Rl(r.at.x)} ${Rl(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(Rl(i.x)||Rl(i.y))&&t.push(` ${n}:${e} ${Rl(i.x)}${Rl(i.y)?` ${Rl(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
33
- `)}\n}`:``}function Ul(e,t,n=or(e)){let r=Hl(t),i=zl(e);if(n.layoutBlock){let[t,a]=n.layoutBlock,o=!r&&t>0&&i[t-1].trim()===``?t-1:t;return i.splice(o,a-o+1,...r?r.split(`
34
- `):[]),Vl(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=Bl(e);return a+o+o+r.split(`
35
- `).join(o)+o}let Wl=e=>Jn({v:e}).replace(/^v: /,``);function Gl(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=q(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=Jn(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+$/,``)}}let Kl=(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 ql(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length,a=i>0&&t[i-1].trim()!==``&&n.layoutBlock?[r,``]:[r];return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),Vl(t,e)}let Jl=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Yl=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e),Xl={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function Zl(e,t,n,r,i=or(e)){n=Vn(n);let a=Kl(i,t);if(!a)return e;let o=Ql(e,t,n,r,i,a);for(let e of(Xl[n]??[]).filter(e=>e in a.props))o=Zl(o,t,e,null);return o}function Ql(e,t,n,r,i,a){let o=zl(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:ql(e,o,i,`${t.id} [${Jn({[n]:r})}]`);let c=s.propLines;if(c){let i=s.props?q(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}: ${Wl(r)}`,n in i&&Gl(o,s,t.kind,n,null),Vl(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${o[t].match(/^\s*/)[0]}${n}: ${Wl(r)}`),Vl(o,e)}}return Gl(o,s,t.kind,n,r),Vl(o,e)}function $l(e,t,n,r=or(e)){let i,a=eu(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 eu(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&xn.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=zl(e),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:``)),Vl(l,e)}let tu=/^<!--\s*yuhwa(?:\s+([\w.-]+))?\s*$/,nu=/^(```+|~~~+)\s*yuhwa(?:\s+([\w.-]+))?\s*$/;function ru(e,t,n,r){if(n){let i=`<picture><source media="(prefers-color-scheme: dark)" srcset="${n}"><img alt="${e}" src="${t}"></picture>`;return r?`<a href="${r.replace(/"/g,`%22`)}">${i}</a>`:i}return r?`[![${e}](${t})](${r})`:`![${e}](${t})`}let iu=e=>e.match(/^\[(!\[[^\]]*\]\([^)]*\))\]\([^)]*\)$/)?.[1]??e.match(/^<a href="[^"]*">(<picture>.*<\/picture>)<\/a>$/)?.[1]??e;function au(e,t=`diagram`,n=`diagrams`){let r=e.split(`
36
- `),i=[],a=/* @__PURE__ */ new Set;for(let e=0;e<r.length;e++){let o=r[e],s=o.match(tu),c,l,u;if(s)c=`comment`,u=s[1],l=e=>e.trim()===`-->`;else if(s=o.match(nu)){c=`fence`,u=s[2];let e=s[1];l=t=>t.trim()===e}else continue;let d=e+1;for(;d<r.length&&!l(r[d]);)d++;if(d>=r.length)break;let f=i.length,p=u??`${t}-${f+1}`;for(;a.has(p);)p+=`-`+(f+1);a.add(p);let m={index:f,name:p,source:r.slice(e+1,d).join(`
37
- `),kind:c,start:e,end:d},h=d+1;for(;h<r.length&&r[h].trim()===``&&h<=d+1;)h++;let g=iu(r[h]?.trim()??``),_=ou(n,`${p}.svg`);(g===ru(p,_)||g===ru(p,_,ou(n,`${p}.dark.svg`)))&&(m.image=[h,h]),i.push(m),e=d}return i}let ou=(e,t)=>e?e.replace(/\/+$/,``)+`/`+t:t,su=e=>[...e].join(`, `),cu=e=>su([...e].map(e=>"`"+e+"`")),lu=[...J.panels.values()],uu={color:`<colour>`,number:`N`,text:`…`},du=su([...yn].map(e=>wn[e]?`${e} (${wn[e].join(`|`)})`:e)),fu=lu.map(e=>{let t=Object.entries(e.options??{}).map(([e,t])=>{let n=pr(t);return n.kind===`select`?`${e}: ${n.values.join(`|`)}`:n.kind===`flag`?e:`${e}: ${uu[n.kind]}`}),n=e.guide??(e.syntax?"`"+e.syntax+"`":``);return`- \`${e.name}\`: ${n}${t.length?` Header: ${cu(t)}.`:``}`}).join(`
38
- `),pu=lu.filter(e=>e.layoutParts).map(e=>`- \`${e.name}\`: ${e.layoutParts}.`).join(`
39
- `),mu=`# yuhwa — diagram language reference (for AI tools)
32
+ `,ru=(e,t)=>e.join(nu(t));function iu(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 ${eu(r.x)} ${eu(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${eu(r.w)} ${eu(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=>`${eu(e.x)} ${eu(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(eu(r.label.x)||eu(r.label.y))&&e.push(`label ${eu(r.label.x)} ${eu(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 ${eu(r.at.x)} ${eu(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(eu(i.x)||eu(i.y))&&t.push(` ${n}:${e} ${eu(i.x)}${eu(i.y)?` ${eu(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
33
+ `)}\n}`:``}function au(e,t,n=fr(e)){let r=iu(t),i=tu(e);if(n.layoutBlock){let[t,a]=n.layoutBlock,o=!r&&t>0&&i[t-1].trim()===``?t-1:t;return i.splice(o,a-o+1,...r?r.split(`
34
+ `):[]),ru(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=nu(e);return a+o+o+r.split(`
35
+ `).join(o)+o}let ou=e=>er({v:e}).replace(/^v: /,``);function su(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=K(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=er(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+$/,``)}}let cu=(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 lu(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length,a=i>0&&t[i-1].trim()!==``&&n.layoutBlock?[r,``]:[r];return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),ru(t,e)}let uu=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,du=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e),fu={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function pu(e,t,n,r,i=fr(e)){n=qn(n);let a=cu(i,t);if(!a)return e;let o=mu(e,t,n,r,i,a);for(let e of(fu[n]??[]).filter(e=>e in a.props))o=pu(o,t,e,null);return o}function mu(e,t,n,r,i,a){let o=tu(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:lu(e,o,i,`${t.id} [${er({[n]:r})}]`);let c=s.propLines;if(c){let i=s.props?K(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}: ${ou(r)}`,n in i&&su(o,s,t.kind,n,null),ru(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${o[t].match(/^\s*/)[0]}${n}: ${ou(r)}`),ru(o,e)}}return su(o,s,t.kind,n,r),ru(o,e)}function hu(e,t,n,r=fr(e)){let i,a=gu(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 gu(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&Dn.get(i.kind);if(!i?.lines||!a||i.failed||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=tu(e),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:``)),ru(l,e)}let _u=/^<!--\s*yuhwa(?:\s+([\w.-]+))?\s*$/,vu=/^(```+|~~~+)\s*yuhwa(?:\s+([\w.-]+))?\s*$/;function yu(e,t,n,r){if(n){let i=`<picture><source media="(prefers-color-scheme: dark)" srcset="${n}"><img alt="${e}" src="${t}"></picture>`;return r?`<a href="${r.replace(/"/g,`%22`)}">${i}</a>`:i}return r?`[![${e}](${t})](${r})`:`![${e}](${t})`}let bu=e=>e.match(/^\[(!\[[^\]]*\]\([^)]*\))\]\([^)]*\)$/)?.[1]??e.match(/^<a href="[^"]*">(<picture>.*<\/picture>)<\/a>$/)?.[1]??e;function xu(e,t=`diagram`,n=`diagrams`){let r=e.split(`
36
+ `),i=[],a=/* @__PURE__ */ new Set;for(let e=0;e<r.length;e++){let o=r[e],s=o.match(_u),c,l,u;if(s)c=`comment`,u=s[1],l=e=>e.trim()===`-->`;else if(s=o.match(vu)){c=`fence`,u=s[2];let e=s[1];l=t=>t.trim()===e}else continue;let d=e+1;for(;d<r.length&&!l(r[d]);)d++;if(d>=r.length)break;let f=i.length,p=u??`${t}-${f+1}`;for(;a.has(p);)p+=`-`+(f+1);a.add(p);let m={index:f,name:p,source:r.slice(e+1,d).join(`
37
+ `),kind:c,start:e,end:d},h=d+1;for(;h<r.length&&r[h].trim()===``&&h<=d+1;)h++;let g=bu(r[h]?.trim()??``),_=Su(n,`${p}.svg`);(g===yu(p,_)||g===yu(p,_,Su(n,`${p}.dark.svg`)))&&(m.image=[h,h]),i.push(m),e=d}return i}let Su=(e,t)=>e?e.replace(/\/+$/,``)+`/`+t:t,Cu=e=>[...e].join(`, `),wu=e=>Cu([...e].map(e=>"`"+e+"`")),Tu=[...q.panels.values()],Eu={color:`<colour>`,number:`N`,text:`…`},Du=Cu([...Tn].map(e=>An[e]?`${e} (${An[e].join(`|`)})`:e)),Ou=Tu.map(e=>{let t=Object.entries(e.options??{}).map(([e,t])=>{let n=yr(t);return n.kind===`select`?`${e}: ${n.values.join(`|`)}`:n.kind===`flag`?e:`${e}: ${Eu[n.kind]}`}),n=e.guide??(e.syntax?"`"+e.syntax+"`":``);return`- \`${e.name}\`: ${n}${t.length?` Header: ${wu(t)}.`:``}`}).join(`
38
+ `),ku=Tu.filter(e=>e.layoutParts).map(e=>`- \`${e.name}\`: ${e.layoutParts}.`).join(`
39
+ `),Au=`# yuhwa — diagram language reference (for AI tools)
40
40
 
41
41
  yuhwa is a text diagram language that renders to a self-contained SVG. One
42
42
  statement per line. \`//\` at line start or after a space starts a comment, so
@@ -69,7 +69,7 @@ orders --> queue "Events" [shape: hexagon]: publish [flow: true]
69
69
 
70
70
  ## Statements
71
71
 
72
- - Setting: \`key: value\` at top level. Keys: ${du}.
72
+ - Setting: \`key: value\` at top level. Keys: ${Du}.
73
73
  - Node: \`id "Label" .class [props]\`; label, classes and props are optional.
74
74
  Ids: letters (any script), digits, \`_\`, inner \`-\`; start with a letter or \`_\`.
75
75
  The label defaults to the id; multi-word labels need quotes. \`\\n\` breaks a
@@ -108,19 +108,19 @@ orders --> queue "Events" [shape: hexagon]: publish [flow: true]
108
108
  ## Values
109
109
 
110
110
  - \`color\` sets fill, border and text in one: \`[blue]\` or \`[color: blue]\`.
111
- Palette: ${su(c)}; shades like blue-600; any CSS colour. The colour
112
- props (${su(tn)}) take the same values and colour one part.
113
- - Shapes: ${su(Pt)}.
114
- - Line styles: ${su(en.style)}. Heads: ${su(en.head)}. Sides (\`exit\`, \`enter\`): ${su(en.exit)}.
115
- - Themes: ${su(v)}. Define one with \`theme brand [base: midnight, accent: orange]\`
111
+ Palette: ${Cu(p)}; shades like blue-600; any CSS colour. The colour
112
+ props (${Cu(cn)}) take the same values and colour one part.
113
+ - Shapes: ${Cu(zt)}.
114
+ - Line styles: ${Cu(sn.style)}. Heads: ${Cu(sn.head)}. Sides (\`exit\`, \`enter\`): ${Cu(sn.exit)}.
115
+ - Themes: ${Cu(C)}. Define one with \`theme brand [base: midnight, accent: orange]\`
116
116
  or \`theme brand {\` and one \`key: value\` per line, then \`theme: brand\`.
117
- Keys: ${su(Object.keys(te))}.
117
+ Keys: ${Cu(Object.keys(re))}.
118
118
 
119
119
  ## Props
120
120
 
121
- - Node: ${su(Xt)}.
122
- - Edge: ${su(Zt)}.
123
- - Group: ${su(Qt)}.
121
+ - Node: ${Cu(nn)}.
122
+ - Edge: ${Cu(rn)}.
123
+ - Group: ${Cu(an)}.
124
124
 
125
125
  \`sub\` is a second, smaller line; \`icon\` an emoji before the label; \`link\`
126
126
  makes a node clickable; \`flow: true\` animates an edge; \`constraint: false\`
@@ -128,7 +128,7 @@ keeps an edge out of the layout; \`shape: text\` is an annotation without a box.
128
128
  \`below: <id>\`, \`above\`, \`right-of\`, \`left-of\` and \`rank\` place a node next to another
129
129
  node without drawing an edge; do not use invisible edges for that. The \`max-width: <px>\` setting
130
130
  wraps the ranks of a right or left diagram into rows that fit that width.
131
- \`frame: <kind> <text>\` draws window chrome: ${su(J.frames.keys())}.
131
+ \`frame: <kind> <text>\` draws window chrome: ${Cu(q.frames.keys())}.
132
132
 
133
133
  ## Card bodies
134
134
 
@@ -146,7 +146,7 @@ checks "checks" [meta: 42s, caps: true] {
146
146
  \`\`\`
147
147
 
148
148
  Lines: text, \`left || right\` (right-aligned part), \`---\` divider, empty gap.
149
- Rows: ${cu(J.rows.map(e=>e.syntax??e.kind))}; a \`|---|\` row makes a table header.
149
+ Rows: ${wu(q.rows.map(e=>e.syntax??e.kind))}; a \`|---|\` row makes a table header.
150
150
  Inline markup (in every text: labels, \`sub\`, edge labels, group and panel titles,
151
151
  \`title\`, \`subtitle\`, \`footer\`): \`**bold**\`, \`*muted*\`, \`~~strike~~\`, \`\`code\`\`,
152
152
  \`[[chip]]\` / \`[[green: chip]]\`, \`{red: text}\`, and styled spans
@@ -179,10 +179,10 @@ chart p95 "Latency p95" [type: column, unit: ms] {
179
179
  }
180
180
  \`\`\`
181
181
 
182
- Every panel takes ${cu($t)}; \`frame: false\` drops the box. Body
182
+ Every panel takes ${wu(on)}; \`frame: false\` drops the box. Body
183
183
  lines take \`[props]\` before the colon or at the end of the line.
184
184
 
185
- ${fu}
185
+ ${Ou}
186
186
 
187
187
  ## Imports
188
188
 
@@ -214,7 +214,7 @@ layout {
214
214
  \`panel at X Y\` pins a panel. \`panel:part D\` (\`panel:part DX DY\` for free
215
215
  parts) nudges one part:
216
216
 
217
- ${pu}
217
+ ${ku}
218
218
 
219
219
  ## JSON and Mermaid input
220
220
 
@@ -248,7 +248,7 @@ panel. \`yuhwa convert file.mmd\` prints the yuhwa source.
248
248
 
249
249
  Keep labels short and put detail in \`sub\`. One colour per kind of thing,
250
250
  defined once as a class. 5 to 20 nodes read best; split larger systems.
251
- `;function hu(e){let t=0x811c9dc5;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0).toString(36)}function gu(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=vc(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=Ol(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(Dl(e)){let t=kl(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:[]}}function _u(e,t={}){let{source:n,format:r,diagnostics:i}=gu(e),a=or(n,{resolve:t.resolve,file:t.file});a.diagnostics.unshift(...i);let o=Ts(a,t);return{svg:ec(a,o,{idPrefix:`yuhwa-${hu(n+(t.theme??``))}`,...t}),source:n,format:r,diagram:a,layout:o,diagnostics:a.diagnostics}}function vu(e,t={}){e.yuhwaZoom?.destroy();let n=e.ownerDocument,r=n.defaultView??window;if(!n.getElementById(`yuhwa-zoom-css`)){let e=n.createElement(`style`);e.id=`yuhwa-zoom-css`,e.textContent=`
251
+ `;function ju(e){let t=0x811c9dc5;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0).toString(36)}function Mu(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=Pc(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=Wl(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(Ul(e)){let t=Gl(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:[]}}function Nu(e,t={}){let{source:n,format:r,diagnostics:i}=Mu(e),a=fr(n,{resolve:t.resolve,file:t.file});a.diagnostics.unshift(...i);let o=Hs(a,t);return{svg:gc(a,o,{idPrefix:`yuhwa-${ju(n+(t.theme??``))}`,...t}),source:n,format:r,diagram:a,layout:o,diagnostics:a.diagnostics}}function Pu(e,t={}){e.yuhwaZoom?.destroy();let n=e.ownerDocument,r=n.defaultView??window;if(!n.getElementById(`yuhwa-zoom-css`)){let e=n.createElement(`style`);e.id=`yuhwa-zoom-css`,e.textContent=`
252
252
  .yuhwa-zoom{position:relative;display:block;overflow:hidden;touch-action:pan-x pan-y;-webkit-user-select:none;user-select:none;outline:none}
253
253
  .yuhwa-zoom:focus-visible{box-shadow:0 0 0 2px Highlight}
254
254
  .yuhwa-zoom[data-zoomed]{cursor:grab;touch-action:none}
@@ -268,12 +268,12 @@ defined once as a class. 5 to 20 nodes read best; split larger systems.
268
268
  .yuhwa-zoom-bar button:disabled{opacity:.35;cursor:default;background:none}
269
269
  .yuhwa-zoom-hint{position:absolute;left:50%;bottom:10px;transform:translateX(-50%);padding:5px 10px;border-radius:6px;background:rgba(20,20,20,.78);color:#fff;font:12px/1.3 system-ui,sans-serif;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .2s}
270
270
  .yuhwa-zoom-hint[data-show]{opacity:1}
271
- @media (prefers-reduced-motion:reduce){.yuhwa-zoom-stage.yuhwa-zoom-anim,.yuhwa-zoom-hint,.yuhwa-zoom-bar{transition:none}}`,n.head.append(e)}let i=t.min??1,a=Math.max(t.max??8,i),o=1,s=0,c=0,l=!e.hasAttribute(`tabindex`),u=e.style.height;e.classList.add(`yuhwa-zoom`),t.height&&(e.classList.add(`yuhwa-zoom-fixed`),e.style.height=t.height),l&&(e.tabIndex=0);let d=n.createElement(`div`);d.className=`yuhwa-zoom-stage`,d.append(...e.childNodes),e.append(d);let f=e=>`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="${e}" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`,p=(e,t,r)=>{let i=n.createElement(`button`);return i.type=`button`,i.title=e,i.setAttribute(`aria-label`,e),i.innerHTML=t,i.addEventListener(`click`,e=>{e.stopPropagation(),r()}),i},m=n.createElement(`div`);m.className=`yuhwa-zoom-bar`;let h=p(`Zoom out (−)`,f(`M3.5 8h9`),()=>S(1/1.5,void 0,!0)),g=p(`Reset zoom (0)`,`100%`,()=>C()),_=p(`Zoom in (+)`,f(`M3.5 8h9M8 3.5v9`),()=>S(1.5,void 0,!0));m.append(h,g,_),n.fullscreenEnabled&&e.requestFullscreen&&m.append(p(`Full screen`,f(`M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10`),()=>n.fullscreenElement===e?n.exitFullscreen():e.requestFullscreen().catch(()=>{}))),t.controls!==!1&&e.append(m);let v=n.createElement(`div`);v.className=`yuhwa-zoom-hint`,v.setAttribute(`aria-hidden`,`true`),v.textContent=/Mac|iP/.test(r.navigator.platform)?`Pinch or ⌘ + scroll to zoom`:`Ctrl + scroll to zoom`,e.append(v);let y=0,b=()=>{v.setAttribute(`data-show`,``),r.clearTimeout(y),y=r.setTimeout(()=>v.removeAttribute(`data-show`),1400)},x=(t=!1)=>{let n=e.clientWidth,r=e.clientHeight,l=n-n*o,u=r-r*o;s=Math.min(Math.max(s,Math.min(0,l)),Math.max(0,l)),c=Math.min(Math.max(c,Math.min(0,u)),Math.max(0,u)),d.classList.toggle(`yuhwa-zoom-anim`,t),d.style.transform=o===1&&!s&&!c?``:`translate(${s}px, ${c}px) scale(${o})`,e.toggleAttribute(`data-zoomed`,o>1.001);let f=`${Math.round(o*100)}%`;g.textContent!==f&&(g.textContent=f),h.disabled=o<=i+.001,_.disabled=o>=a-.001},S=(t,n,r=!1)=>{let l=n??{x:e.clientWidth/2,y:e.clientHeight/2},u=Math.min(a,Math.max(i,o*t));s=l.x-(l.x-s)*u/o,c=l.y-(l.y-c)*u/o,o=u,x(r)},C=(e=!0)=>{o=1,s=c=0,x(e)},w=t=>{let n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},T=r=>{let i=r.deltaMode===1?16:r.deltaMode===2?e.clientHeight:1,a=r.deltaX*i,l=r.deltaY*i;if(r.ctrlKey||r.metaKey||t.wheel||n.fullscreenElement===e)r.preventDefault(),S(Math.exp(-l*(Math.abs(l)<50?.01:.002)),w(r));else if(o>1.001){let e=s,t=c;s-=a,c-=l,x(),(s!==e||c!==t)&&r.preventDefault()}else Math.abs(l)>Math.abs(a)&&b()},E=/* @__PURE__ */ new Map,D=null,O=0,k=()=>{let[e,t]=[...E.values()];return{d:Math.hypot(e.x-t.x,e.y-t.y)||1,x:(e.x+t.x)/2,y:(e.y+t.y)/2}},A=t=>{if(!(t.pointerType===`mouse`&&t.button!==0||m.contains(t.target))){if(E.size===0&&(O=0),E.set(t.pointerId,w(t)),E.size===2){D=k();for(let t of E.keys())e.setPointerCapture?.(t)}else E.size===1&&o>1.001&&(e.setPointerCapture?.(t.pointerId),e.setAttribute(`data-dragging`,``))}},j=t=>{let n=E.get(t.pointerId);if(!n)return;let r=w(t);if(E.set(t.pointerId,r),E.size>=2&&D){let e=k();s+=e.x-D.x,c+=e.y-D.y,S(e.d/D.d,e),O+=Math.abs(e.d-D.d)+Math.abs(e.x-D.x)+Math.abs(e.y-D.y),D=e}else e.hasAttribute(`data-dragging`)&&(s+=r.x-n.x,c+=r.y-n.y,O+=Math.abs(r.x-n.x)+Math.abs(r.y-n.y),x())},ee=t=>{E.delete(t.pointerId),D=E.size>=2?k():null,E.size===0&&e.removeAttribute(`data-dragging`)},M=e=>{O>4&&!m.contains(e.target)&&(e.preventDefault(),e.stopPropagation())},te=e=>{m.contains(e.target)||(e.preventDefault(),o>=a-.001?C():S(2,w(e),!0))},N=t=>{if(t.target!==e||t.altKey||t.ctrlKey||t.metaKey)return;let n={ArrowLeft:[60,0],ArrowRight:[-60,0],ArrowUp:[0,60],ArrowDown:[0,-60]};if(t.key===`+`||t.key===`=`)S(1.5,void 0,!0);else if(t.key===`-`||t.key===`_`)S(1/1.5,void 0,!0);else if(t.key===`0`)C();else if(n[t.key]&&o>1.001){let e=s,r=c;if(s+=n[t.key][0],c+=n[t.key][1],x(!0),s===e&&c===r)return}else return;t.preventDefault()},ne=e=>e.preventDefault(),re=new AbortController,P=re.signal;e.addEventListener(`wheel`,T,{passive:!1,signal:P}),e.addEventListener(`pointerdown`,A,{signal:P}),e.addEventListener(`pointermove`,j,{signal:P}),e.addEventListener(`pointerup`,ee,{signal:P}),e.addEventListener(`pointercancel`,ee,{signal:P}),e.addEventListener(`click`,M,{capture:!0,signal:P}),e.addEventListener(`dblclick`,te,{signal:P}),e.addEventListener(`keydown`,N,{signal:P}),e.addEventListener(`dragstart`,ne,{signal:P}),n.addEventListener(`fullscreenchange`,()=>C(!1),{signal:P});let ie=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>x());ie?.observe(e),x();let F={get scale(){return o},zoom:(e,t)=>S(e,t,!0),reset:()=>C(),destroy(){re.abort(),ie?.disconnect(),r.clearTimeout(y),m.remove(),v.remove(),d.parentNode===e&&(e.append(...d.childNodes),d.remove()),e.classList.remove(`yuhwa-zoom`,`yuhwa-zoom-fixed`),e.removeAttribute(`data-zoomed`),e.removeAttribute(`data-dragging`),e.style.height=u,l&&e.removeAttribute(`tabindex`),delete e.yuhwaZoom}};return e.yuhwaZoom=F,F}function yu(e){let t=e?.trim();if(t&&t!==`true`)return/^\d+(\.\d+)?$/.test(t)?`${t}px`:t}function bu(){return typeof matchMedia==`function`&&matchMedia(`(prefers-color-scheme: dark)`).matches}function xu(e,t={}){let n=t.theme;if(!n||n===`auto`){let t=e.match(/^\s*theme\s*:\s*(\S+)/m);t&&t[1]!==`auto`||(n=bu()?`midnight`:`paper`)}return _u(e,{measureFor:e=>Xr(e.font),...t,theme:n})}let Su=/^\s*import\s+(?:\{[^}]*\}\s*from\s+)?"([^"]+)"/gm;async function Cu(e,t,n=wu){let r={},i=[[e,t]];for(;i.length;){let[e,t]=i.shift(),a=[...e.matchAll(Su)].map(e=>An(t,e[1])).filter(e=>kn(e)&&!(e in r));await Promise.all(a.map(async e=>{r[e]=``;try{r[e]=await n(e),i.push([r[e],e])}catch{delete r[e]}}))}return r}let wu=e=>fetch(e).then(t=>t.ok?t.text():Promise.reject(/* @__PURE__ */ Error(`${e}: HTTP ${t.status}`)));function Tu(e){e&&(e.removeAttribute(`height`),e.style.maxWidth=`100%`,e.style.height=`auto`,e.style.display=`block`)}function Eu(e=document,t={}){e.querySelectorAll(`pre > code.language-yuhwa, pre > code.lang-yuhwa, pre.yuhwa, div.yuhwa:not([data-rendered])`).forEach(e=>{let n=e.tagName===`CODE`?e.parentElement:e,r=e.textContent??``,i=document.createElement(`div`);i.className=`yuhwa`,i.dataset.rendered=`true`,i.dataset.source=r;let a=!1;try{let e=xu(r,{theme:n.dataset.theme,...t});i.innerHTML=e.svg,Tu(i.querySelector(`svg`));for(let t of e.diagnostics)console.warn(`yuhwa:${t.line}: ${t.message}`);a=!0}catch(e){i.textContent=`yuhwa error: ${e.message}`,i.style.color=`crimson`}n.replaceWith(i),a&&n.dataset.zoom!==void 0&&vu(i,{height:yu(n.dataset.zoom)})})}let Du=typeof HTMLElement>`u`?class{}:HTMLElement;var Ou=class extends Du{static observedAttributes=[`theme`,`src`,`zoom`,`wheel`];#e=null;#t=null;#n=0;#r;#i={};get source(){return this.#e??``}set source(e){this.#n++,this.#e=e,this.#o()}connectedCallback(){if(document.readyState===`loading`&&!this.textContent?.trim()&&!this.hasAttribute(`src`))return void document.addEventListener(`DOMContentLoaded`,()=>this.connectedCallback(),{once:!0});this.#e===null&&!this.hasAttribute(`src`)&&(this.#e=this.textContent??``),this.#a()}attributeChangedCallback(){this.isConnected&&this.#a()}#a(){let e=this.getAttribute(`src`);if(e===this.#t)return this.#o();let t=++this.#n;if(this.#t=e,!e)return this.#o();let n=new URL(e,location.href),r=n.origin===location.origin?n.pathname:n.href;wu(n.href).then(async e=>{if(t!==this.#n)return;let n=await Cu(e,r);t===this.#n&&(this.#i=n,this.#r=r,this.source=e)}).catch(e=>{t===this.#n&&this.#s(e.message)})}#o(){if(this.#e!==null)try{let e=this.#i,t=xu(this.#e,{theme:this.getAttribute(`theme`)??void 0,file:this.#r,resolve:t=>e[t]});this.yuhwaZoom?.destroy(),this.innerHTML=t.svg,Tu(this.querySelector(`svg`));let n=this.getAttribute(`zoom`);if(this.setAttribute(`role`,n===null?`img`:`group`),n!==null&&vu(this,{height:yu(n),wheel:this.hasAttribute(`wheel`)}),!this.hasAttribute(`aria-label`)||this.dataset.autoLabel){let e=t.diagram.settings.title;e?(this.setAttribute(`aria-label`,e),this.dataset.autoLabel=`1`):this.dataset.autoLabel&&(this.removeAttribute(`aria-label`),delete this.dataset.autoLabel)}for(let e of t.diagnostics)console.warn(`yuhwa:${e.line}: ${e.message}`);this.dispatchEvent(new CustomEvent(`yuhwa:render`,{detail:{diagnostics:t.diagnostics,format:t.format}}))}catch(e){this.#s(e.message)}}#s(e){this.textContent=`yuhwa error: ${e}`,this.style.color=`crimson`}};return typeof customElements<`u`&&!customElements.get(`yuhwa-diagram`)&&customElements.define(`yuhwa-diagram`,Ou),typeof document<`u`&&(document.currentScript?.hasAttribute(`data-manual`)||(document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Eu()):Eu())),e.BOOLS=an,e.COLORS=tn,e.EDGE_PROPS=Zt,e.ENUMS=en,e.GRID=12,e.GROUP_PROPS=Qt,e.GUIDE=mu,e.KNOWN_SETTINGS=yn,e.NODE_PROPS=Xt,e.NUMBERS=on,e.PANELS=xn,e.PANEL_PROPS=$t,e.RAMPS=o,e.SETTING_VALUES=wn,e.SHAPES=Pt,e.THEMES=_,e.THEME_KEYS=te,e.THEME_NAMES=v,e.TONES=c,e.YuhwaDiagram=Ou,e.approxMeasure=Jr,e.blockBraces=Rn,e.builtins=us,e.canvasMeasure=Xr,e.chart=Ji,e.charts=Pr,e.createTheme=N,e.dashFor=Ve,e.editPart=$l,e.fetchImports=Cu,e.findBlocks=au,e.footer=ti,e.formatLayout=Hl,e.frames=Gr,e.fromJSON=vc,e.fromMermaid=kl,e.getTheme=P,e.git=ha,e.groupPath=bs,e.hash=hu,e.isMermaid=Dl,e.isSafeCss=se,e.isSafeLink=ce,e.isToneOrHex=ae,e.isYuhwaPath=kn,e.joinPath=An,e.layout=Ts,e.legend=ci,e.lex=Ln,e.lineStyle=Pe,e.lint=_n,e.onlyColor=Kn,e.optionKind=pr,e.parse=or,e.parseInline=R,e.parseProps=q,e.perPass=mr,e.processMarkdown=function(e,t={}){let n=t.outDir??`diagrams`,r=au(e,t.baseName,n),i=e.split(`
272
- `),a=[],o=[];for(let e of[...r].reverse()){let r={resolve:t.resolve,file:t.file},s=_u(e.source,r);for(let t of s.diagnostics)o.push({block:e.name,line:t.line,message:t.message,severity:t.severity});let c=ou(n,`${e.name}.svg`);a.push({path:c,svg:s.svg+`
273
- `});let l=s.diagram.imports?.length?void 0:t.view?.(e.source),u=ru(e.name,c,void 0,l);if(t.dark){let t=_u(e.source,{...r,theme:`midnight`}),i=ou(n,`${e.name}.dark.svg`);a.push({path:i,svg:t.svg+`
274
- `}),u=ru(e.name,c,i,l)}let d=[];e.kind===`fence`&&!t.keepFences?d.push(`<!--yuhwa ${e.name}`,...e.source.split(`
271
+ @media (prefers-reduced-motion:reduce){.yuhwa-zoom-stage.yuhwa-zoom-anim,.yuhwa-zoom-hint,.yuhwa-zoom-bar{transition:none}}`,n.head.append(e)}let i=t.min??1,a=Math.max(t.max??8,i),o=1,s=0,c=0,l=!e.hasAttribute(`tabindex`),u=e.style.height;e.classList.add(`yuhwa-zoom`),t.height&&(e.classList.add(`yuhwa-zoom-fixed`),e.style.height=t.height),l&&(e.tabIndex=0);let d=n.createElement(`div`);d.className=`yuhwa-zoom-stage`,d.append(...e.childNodes),e.append(d);let f=e=>`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="${e}" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>`,p=(e,t,r)=>{let i=n.createElement(`button`);return i.type=`button`,i.title=e,i.setAttribute(`aria-label`,e),i.innerHTML=t,i.addEventListener(`click`,e=>{e.stopPropagation(),r()}),i},m=n.createElement(`div`);m.className=`yuhwa-zoom-bar`;let h=p(`Zoom out (−)`,f(`M3.5 8h9`),()=>S(1/1.5,void 0,!0)),g=p(`Reset zoom (0)`,`100%`,()=>C()),_=p(`Zoom in (+)`,f(`M3.5 8h9M8 3.5v9`),()=>S(1.5,void 0,!0));m.append(h,g,_),n.fullscreenEnabled&&e.requestFullscreen&&m.append(p(`Full screen`,f(`M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10`),()=>n.fullscreenElement===e?n.exitFullscreen():e.requestFullscreen().catch(()=>{}))),t.controls!==!1&&e.append(m);let v=n.createElement(`div`);v.className=`yuhwa-zoom-hint`,v.setAttribute(`aria-hidden`,`true`),v.textContent=/Mac|iP/.test(r.navigator.platform)?`Pinch or ⌘ + scroll to zoom`:`Ctrl + scroll to zoom`,e.append(v);let y=0,b=()=>{v.setAttribute(`data-show`,``),r.clearTimeout(y),y=r.setTimeout(()=>v.removeAttribute(`data-show`),1400)},x=(t=!1)=>{let n=e.clientWidth,r=e.clientHeight,l=n-n*o,u=r-r*o;s=Math.min(Math.max(s,Math.min(0,l)),Math.max(0,l)),c=Math.min(Math.max(c,Math.min(0,u)),Math.max(0,u)),d.classList.toggle(`yuhwa-zoom-anim`,t),d.style.transform=o===1&&!s&&!c?``:`translate(${s}px, ${c}px) scale(${o})`,e.toggleAttribute(`data-zoomed`,o>1.001);let f=`${Math.round(o*100)}%`;g.textContent!==f&&(g.textContent=f),h.disabled=o<=i+.001,_.disabled=o>=a-.001},S=(t,n,r=!1)=>{let l=n??{x:e.clientWidth/2,y:e.clientHeight/2},u=Math.min(a,Math.max(i,o*t));s=l.x-(l.x-s)*u/o,c=l.y-(l.y-c)*u/o,o=u,x(r)},C=(e=!0)=>{o=1,s=c=0,x(e)},w=t=>{let n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},T=r=>{let i=r.deltaMode===1?16:r.deltaMode===2?e.clientHeight:1,a=r.deltaX*i,l=r.deltaY*i;if(r.ctrlKey||r.metaKey||t.wheel||n.fullscreenElement===e)r.preventDefault(),S(Math.exp(-l*(Math.abs(l)<50?.01:.002)),w(r));else if(o>1.001){let e=s,t=c;s-=a,c-=l,x(),(s!==e||c!==t)&&r.preventDefault()}else Math.abs(l)>Math.abs(a)&&b()},E=/* @__PURE__ */ new Map,D=null,O=0,k=()=>{let[e,t]=[...E.values()];return{d:Math.hypot(e.x-t.x,e.y-t.y)||1,x:(e.x+t.x)/2,y:(e.y+t.y)/2}},A=t=>{if(!(t.pointerType===`mouse`&&t.button!==0||m.contains(t.target))){if(E.size===0&&(O=0),E.set(t.pointerId,w(t)),E.size===2){D=k();for(let t of E.keys())e.setPointerCapture?.(t)}else E.size===1&&o>1.001&&(e.setPointerCapture?.(t.pointerId),e.setAttribute(`data-dragging`,``))}},j=t=>{let n=E.get(t.pointerId);if(!n)return;let r=w(t);if(E.set(t.pointerId,r),E.size>=2&&D){let e=k();s+=e.x-D.x,c+=e.y-D.y,S(e.d/D.d,e),O+=Math.abs(e.d-D.d)+Math.abs(e.x-D.x)+Math.abs(e.y-D.y),D=e}else e.hasAttribute(`data-dragging`)&&(s+=r.x-n.x,c+=r.y-n.y,O+=Math.abs(r.x-n.x)+Math.abs(r.y-n.y),x())},ee=t=>{E.delete(t.pointerId),D=E.size>=2?k():null,E.size===0&&e.removeAttribute(`data-dragging`)},M=e=>{O>4&&!m.contains(e.target)&&(e.preventDefault(),e.stopPropagation())},te=e=>{m.contains(e.target)||(e.preventDefault(),o>=a-.001?C():S(2,w(e),!0))},N=t=>{if(t.target!==e||t.altKey||t.ctrlKey||t.metaKey)return;let n={ArrowLeft:[60,0],ArrowRight:[-60,0],ArrowUp:[0,60],ArrowDown:[0,-60]};if(t.key===`+`||t.key===`=`)S(1.5,void 0,!0);else if(t.key===`-`||t.key===`_`)S(1/1.5,void 0,!0);else if(t.key===`0`)C();else if(n[t.key]&&o>1.001){let e=s,r=c;if(s+=n[t.key][0],c+=n[t.key][1],x(!0),s===e&&c===r)return}else return;t.preventDefault()},P=e=>e.preventDefault(),ne=new AbortController,F=ne.signal;e.addEventListener(`wheel`,T,{passive:!1,signal:F}),e.addEventListener(`pointerdown`,A,{signal:F}),e.addEventListener(`pointermove`,j,{signal:F}),e.addEventListener(`pointerup`,ee,{signal:F}),e.addEventListener(`pointercancel`,ee,{signal:F}),e.addEventListener(`click`,M,{capture:!0,signal:F}),e.addEventListener(`dblclick`,te,{signal:F}),e.addEventListener(`keydown`,N,{signal:F}),e.addEventListener(`dragstart`,P,{signal:F}),n.addEventListener(`fullscreenchange`,()=>C(!1),{signal:F});let re=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>x());re?.observe(e),x();let ie={get scale(){return o},zoom:(e,t)=>S(e,t,!0),reset:()=>C(),destroy(){ne.abort(),re?.disconnect(),r.clearTimeout(y),m.remove(),v.remove(),d.parentNode===e&&(e.append(...d.childNodes),d.remove()),e.classList.remove(`yuhwa-zoom`,`yuhwa-zoom-fixed`),e.removeAttribute(`data-zoomed`),e.removeAttribute(`data-dragging`),e.style.height=u,l&&e.removeAttribute(`tabindex`),delete e.yuhwaZoom}};return e.yuhwaZoom=ie,ie}function Fu(e){let t=e?.trim();if(t&&t!==`true`)return/^\d+(\.\d+)?$/.test(t)?`${t}px`:t}function Iu(){return typeof matchMedia==`function`&&matchMedia(`(prefers-color-scheme: dark)`).matches}function Lu(e,t={}){let n=t.theme;if(!n||n===`auto`){let t=e.match(/^\s*theme\s*:\s*(\S+)/m);t&&t[1]!==`auto`||(n=Iu()?`midnight`:`paper`)}return Nu(e,{measureFor:e=>Rr(e.font),...t,theme:n})}let Ru=/^\s*import\s+(?:\{[^}]*\}\s*from\s+)?"([^"]+)"/gm;async function zu(e,t,n=Bu){let r={},i=[[e,t]];for(;i.length;){let[e,t]=i.shift(),a=[...e.matchAll(Ru)].map(e=>In(t,e[1])).filter(e=>Fn(e)&&!(e in r));await Promise.all(a.map(async e=>{r[e]=``;try{r[e]=await n(e),i.push([r[e],e])}catch{delete r[e]}}))}return r}let Bu=e=>fetch(e).then(t=>t.ok?t.text():Promise.reject(/* @__PURE__ */ Error(`${e}: HTTP ${t.status}`)));function Vu(e){e&&(e.removeAttribute(`height`),e.style.maxWidth=`100%`,e.style.height=`auto`,e.style.display=`block`)}function Hu(e=document,t={}){e.querySelectorAll(`pre > code.language-yuhwa, pre > code.lang-yuhwa, pre.yuhwa, div.yuhwa:not([data-rendered])`).forEach(e=>{let n=e.tagName===`CODE`?e.parentElement:e,r=e.textContent??``,i=document.createElement(`div`);i.className=`yuhwa`,i.dataset.rendered=`true`,i.dataset.source=r;let a=!1;try{let e=Lu(r,{theme:n.dataset.theme,...t});i.innerHTML=e.svg,Vu(i.querySelector(`svg`));for(let t of e.diagnostics)console.warn(`yuhwa:${t.line}: ${t.message}`);a=!0}catch(e){i.textContent=`yuhwa error: ${e.message}`,i.style.color=`crimson`}n.replaceWith(i),a&&n.dataset.zoom!==void 0&&Pu(i,{height:Fu(n.dataset.zoom)})})}let Uu=typeof HTMLElement>`u`?class{}:HTMLElement;var Wu=class extends Uu{static observedAttributes=[`theme`,`src`,`zoom`,`wheel`];#e=null;#t=null;#n=0;#r;#i={};get source(){return this.#e??``}set source(e){this.#n++,this.#e=e,this.#o()}connectedCallback(){if(document.readyState===`loading`&&!this.textContent?.trim()&&!this.hasAttribute(`src`))return void document.addEventListener(`DOMContentLoaded`,()=>this.connectedCallback(),{once:!0});this.#e===null&&!this.hasAttribute(`src`)&&(this.#e=this.textContent??``),this.#a()}attributeChangedCallback(){this.isConnected&&this.#a()}#a(){let e=this.getAttribute(`src`);if(e===this.#t)return this.#o();let t=++this.#n;if(this.#t=e,!e)return this.#o();let n=new URL(e,location.href),r=n.origin===location.origin?n.pathname:n.href;Bu(n.href).then(async e=>{if(t!==this.#n)return;let n=await zu(e,r);t===this.#n&&(this.#i=n,this.#r=r,this.source=e)}).catch(e=>{t===this.#n&&this.#s(e.message)})}#o(){if(this.#e!==null)try{let e=this.#i,t=Lu(this.#e,{theme:this.getAttribute(`theme`)??void 0,file:this.#r,resolve:t=>e[t]});this.yuhwaZoom?.destroy(),this.innerHTML=t.svg,Vu(this.querySelector(`svg`));let n=this.getAttribute(`zoom`);if(this.setAttribute(`role`,n===null?`img`:`group`),n!==null&&Pu(this,{height:Fu(n),wheel:this.hasAttribute(`wheel`)}),!this.hasAttribute(`aria-label`)||this.dataset.autoLabel){let e=t.diagram.settings.title;e?(this.setAttribute(`aria-label`,e),this.dataset.autoLabel=`1`):this.dataset.autoLabel&&(this.removeAttribute(`aria-label`),delete this.dataset.autoLabel)}for(let e of t.diagnostics)console.warn(`yuhwa:${e.line}: ${e.message}`);this.dispatchEvent(new CustomEvent(`yuhwa:render`,{detail:{diagnostics:t.diagnostics,format:t.format}}))}catch(e){this.#s(e.message)}}#s(e){this.textContent=`yuhwa error: ${e}`,this.style.color=`crimson`}};return typeof customElements<`u`&&!customElements.get(`yuhwa-diagram`)&&customElements.define(`yuhwa-diagram`,Wu),typeof document<`u`&&(document.currentScript?.hasAttribute(`data-manual`)||(document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Hu()):Hu())),e.BOOLS=dn,e.COLORS=cn,e.EDGE_PROPS=rn,e.ENUMS=sn,e.GRID=12,e.GROUP_PROPS=an,e.GUIDE=Au,e.KNOWN_SETTINGS=Tn,e.NODE_PROPS=nn,e.NUMBERS=fn,e.PANELS=Dn,e.PANEL_PROPS=on,e.RAMPS=d,e.SETTING_VALUES=An,e.SHAPES=zt,e.THEMES=S,e.THEME_KEYS=re,e.THEME_NAMES=C,e.TONES=p,e.YuhwaDiagram=Wu,e.approxMeasure=Ir,e.blockBraces=Wn,e.builtins=Ds,e.canvasMeasure=Rr,e.chart=ua,e.charts=ti,e.createTheme=ie,e.dashFor=qe,e.editPart=hu,e.esc=z,e.fetchImports=zu,e.findBlocks=xu,e.footer=_i,e.formatLayout=iu,e.frames=fi,e.fromJSON=Pc,e.fromMermaid=Gl,e.gantt=po,e.getTheme=se,e.git=ja,e.groupPath=Ls,e.hash=ju,e.isMermaid=Ul,e.isSafeCss=de,e.isSafeLink=fe,e.isToneOrHex=le,e.isYuhwaPath=Fn,e.joinPath=In,e.kanban=Ro,e.layout=Hs,e.legend=wi,e.lex=Un,e.lineStyle=ze,e.lint=Cn,e.markers=Gr,e.mindmap=Ja,e.onlyColor=Qn,e.optionKind=yr,e.parse=fr,e.parseInline=R,e.parseProps=K,e.perPass=br,e.portOn=Yt,e.processMarkdown=function(e,t={}){let n=t.outDir??`diagrams`,r=xu(e,t.baseName,n),i=e.split(`
272
+ `),a=[],o=[];for(let e of[...r].reverse()){let r={resolve:t.resolve,file:t.file},s=Nu(e.source,r);for(let t of s.diagnostics)o.push({block:e.name,line:t.line,message:t.message,severity:t.severity});let c=Su(n,`${e.name}.svg`);a.push({path:c,svg:s.svg+`
273
+ `});let l=s.diagram.imports?.length?void 0:t.view?.(e.source),u=yu(e.name,c,void 0,l);if(t.dark){let t=Nu(e.source,{...r,theme:`midnight`}),i=Su(n,`${e.name}.dark.svg`);a.push({path:i,svg:t.svg+`
274
+ `}),u=yu(e.name,c,i,l)}let d=[];e.kind===`fence`&&!t.keepFences?d.push(`<!--yuhwa ${e.name}`,...e.source.split(`
275
275
  `),`-->`):d.push(...i.slice(e.start,e.end+1)),d.push(u);let f=e.image?e.image[1]:e.end;i.splice(e.start,f-e.start+1,...d)}return a.reverse(),{markdown:i.join(`
276
- `),files:a,blocks:r,diagnostics:o}},e.ramp=u,e.recolor=hr,e.registerTheme=y,e.registry=J,e.render=xu,e.renderHead=Nt,e.renderSegs=Me,e.renderSvg=ec,e.replaceBlockSource=function(e,t,n){let r=au(e)[t];if(!r)throw Error(`No yuhwa block #${t}`);let i=e.split(`
276
+ `),files:a,blocks:r,diagnostics:o}},e.quadrant=wo,e.ramp=h,e.recolor=xr,e.registerTheme=w,e.registry=q,e.render=Lu,e.renderHead=Rt,e.renderSegs=Le,e.renderSvg=gc,e.replaceBlockSource=function(e,t,n){let r=xu(e)[t];if(!r)throw Error(`No yuhwa block #${t}`);let i=e.split(`
277
277
  `);return i.splice(r.start+1,r.end-r.start-1,...n.split(`
278
278
  `)),i.join(`
279
- `)},e.run=Eu,e.segsW=H,e.sequence=Di,e.serializeProps=Jn,e.setLabel=function(e,t,n,r=or(e)){let i=Kl(r,t);if(!i)return e;let a=zl(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?ql(e,a,r,`${t.id} ${Jl(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+$/,``),Vl(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&Yl(n)?n:Jl(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),Vl(a,e)},e.setLineProp=qn,e.setPartTone=function(e,t,n,r,i=or(e)){return $l(e,t,{op:`set`,id:n,key:`color`,value:r},i).source},e.setProp=Zl,e.setSetting=function(e,t,n){let r=zl(e),i=RegExp(`^(export\\s+)?${t.replace(/[-]/g,`\\-`)}\\s*:`),a=0,o=r.findIndex(e=>{if(a===0&&i.test(e))return!0;for(let t of Rn(Ln(e).tokens))a=Math.max(0,a+(t===`{`?1:-1));return!1});if(o>=0)return n===null?r.splice(o,1):r[o]=`${r[o].match(i)[1]??``}${t}: ${n}`,Vl(r,e);if(n===null)return e;let s=0;for(;s<r.length&&/^(export\s+)?[\w-]+\s*:(?!:)/.test(r[s])&&!r[s].includes(`->`)||/^\s*(\/\/|#)/.test(r[s]??``);)s++;return r.splice(s,0,`${t}: ${n}`),Vl(r,e)},e.setTrailingProp=Gn,e.splitTrailingProps=Wn,e.tables=Rr,e.themeNames=re,e.themes=Tr,e.timeline=Ii,e.toSource=gu,e.tspans=U,e.unuse=function(e){if(!Sr||!J.plugins.some(t=>t.name===e))return!1;let t=J.plugins.filter(t=>t.name!==e);return J.plugins.length=0,Sr(),wr(...t),!0},e.use=wr,e.writeLayout=Ul,e.writePanelDrag=function(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 Ul(e,t.layout,t);let[o,s]=i.lines,c=zl(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,Ln(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return Ul(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 Ul(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 Vl(c,e)},e.zoomHeight=yu,e.zoomable=vu,e})({});
279
+ `)},e.run=Hu,e.segsW=H,e.sequence=Ui,e.serializeProps=er,e.setLabel=function(e,t,n,r=fr(e)){let i=cu(r,t);if(!i)return e;let a=tu(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?lu(e,a,r,`${t.id} ${uu(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+$/,``),ru(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&du(n)?n:uu(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),ru(a,e)},e.setLineProp=$n,e.setPartTone=function(e,t,n,r,i=fr(e)){return hu(e,t,{op:`set`,id:n,key:`color`,value:r},i).source},e.setProp=pu,e.setSetting=function(e,t,n){let r=tu(e),i=RegExp(`^(export\\s+)?${t.replace(/[-]/g,`\\-`)}\\s*:`),a=0,o=r.findIndex(e=>{if(a===0&&i.test(e))return!0;for(let t of Wn(Un(e).tokens))a=Math.max(0,a+(t===`{`?1:-1));return!1});if(o>=0)return n===null?r.splice(o,1):r[o]=`${r[o].match(i)[1]??``}${t}: ${n}`,ru(r,e);if(n===null)return e;let s=0;for(;s<r.length&&/^(export\s+)?[\w-]+\s*:(?!:)/.test(r[s])&&!r[s].includes(`->`)||/^\s*(\/\/|#)/.test(r[s]??``);)s++;return r.splice(s,0,`${t}: ${n}`),ru(r,e)},e.setTrailingProp=Zn,e.shapes=Ur,e.splitTrailingProps=Xn,e.tables=ai,e.themeNames=oe,e.themes=Kr,e.timeline=Qi,e.toSource=Mu,e.treeview=Es,e.tspans=U,e.unuse=function(e){if(!Ar||!q.plugins.some(t=>t.name===e))return!1;let t=q.plugins.filter(t=>t.name!==e);return q.plugins.length=0,Ar(),Nr(...t),!0},e.use=Nr,e.writeLayout=au,e.writePanelDrag=function(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 au(e,t.layout,t);let[o,s]=i.lines,c=tu(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,Un(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return au(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 au(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 ru(c,e)},e.zoomHeight=Fu,e.zoomable=Pu,e})({});