yuhwa 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,38 @@
1
- (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=null;function t(t,n){let r=e;e=t;try{return n()}finally{e=r}}var n=e=>e instanceof Error?e.message:String(e),r=t=>{e&&!e.some(e=>e.message===t)&&e.push({line:1,message:t,severity:`error`})};function i(e,t,i,a,o=r){return function(...r){try{return i.apply(this,r)}catch(i){return o(`plugin "${e}": ${t} failed: ${n(i)}`,r),a(...r)}}}var a=new Map;function o(e,t,n){let r=`${e} ${t}`,i=a.get(r);i&&i!==n&&console.warn(`yuhwa: plugin "${n}" replaces ${e} "${t}" of plugin "${i}"`),a.set(r,n)}var s=()=>a.clear(),c=(e,t)=>a.get(`${e} ${t}`),l=e=>Object.setPrototypeOf(e,null),u=l({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`]});u.violet=u.purple,u.rose=u.red,u.emerald=u.green,u.yellow=u.amber,u.grey=u.gray,u.sky=u.cyan;var d=e=>Object.hasOwn(u,e),f=[`slate`,`gray`,`red`,`orange`,`amber`,`lime`,`green`,`teal`,`cyan`,`blue`,`indigo`,`purple`,`pink`],p={50:0,100:1,200:2,300:3,400:4,500:5,600:6,700:7,800:8,900:9,950:10};function m(e,t){return u[e]?.[p[t]]}var h=`Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`,g=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,_=`ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif`,v=e=>u[e]&&{fill:m(e,50),stroke:m(e,300),text:m(e,900)},y=e=>u[e]&&{fill:m(e,50)+`b3`,stroke:m(e,200),text:m(e,700)},b=e=>u[e]&&{fill:m(e,950),stroke:m(e,600),text:m(e,100)},x=e=>u[e]&&{fill:m(e,950)+`80`,stroke:m(e,800),text:m(e,300)},S=l({paper:{name:`paper`,dark:!1,background:`#fbfaf7`,font:h,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=>m(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)}var 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}var ee=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))},te=(e,t,n)=>{let r=ee(t);return`#`+ee(e).map((e,t)=>Math.round(e*n+r[t]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``)};function ne(e,t,n){let r=k(e);return r?{fill:te(r,T.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,t.dark?n?.14:.22:n?.07:.12),stroke:r,text:t.dark?te(r,`#ffffff`,.45):te(r,`#000000`,.55)}:void 0}var A=new WeakMap,re=new WeakMap,j=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),ie=[`solid`,`dashed`,`dotted`],ae=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t,oe={sans:h,serif:_,mono:g},se=/^(serif|sans-serif|monospace|cursive|fantasy|math|emoji|system-ui|ui-(serif|sans-serif|monospace|rounded))$/i,ce=e=>se.test(e),le=e=>e.split(`,`).map(e=>e.trim().replace(/^(['"])(.*)\1$/,`$2`)).filter(Boolean);function ue(e){let t=e.split(`,`).map(e=>e.trim()).filter(Boolean),n=le(e)[0]??`sans`,r=n===`mono`||/mono|code|courier/i.test(n),i=t.map(e=>oe[e]??e),a=t.at(-1)??``;return!oe[a]&&!ce(a)&&i.push(r?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`),{font:i.join(`, `),mono:r}}function de(e){if(!e||!/^[\w\s'",.-]+$/.test(e))return;let t=fe.get(e);return t||fe.set(e,t=ue(e)),t}var fe=new Map,pe=l({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:ie},"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 me(e,t,n){let r=n??S[t.base]??S.paper,i=j(t.dark,r.dark),a=(e,n,a)=>M(t[e],r,i?a:n),o=(e,n)=>{let r=parseFloat(t[e]);return Number.isFinite(r)&&r>=0?r:n},s=e=>!j(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?ue(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:ae(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=>m(e,i?400:500):r.edgeTone}}function he(e,t,n=[]){let r=t[e],i=r.base??(S[e]?e:void 0);return me(e,r,i&&t[i]&&i!==e&&!n.includes(i)?he(i,t,[...n,e]):S[i??`paper`]??S.paper)}var ge=e=>[...new Set([...C,...Object.keys(e??{})])];function _e(e,t){if(e&&t?.[e]){let n=re.get(t);n||re.set(t,n=new Map);let r=n.get(e);return r||n.set(e,r=ve(he(e,t))),r}return ve(S[e??`paper`]??S.paper)}function ve(e){let t=A.get(e);return t||(t={...e,tone:n=>e.tone(n)??ne(n,t,!1),groupTone:n=>e.groupTone(n)??ne(n,t,!0),edgeTone:t=>e.edgeTone(t)??(k(t)?t:void 0)},A.set(e,t)),t}var ye=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&d(t[1])&&(!t[2]||t[2]in p)||!!k(e)},be=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function M(e,t,n){if(!e)return;let r=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);if(r&&u[r[1]]){let e=r[2]?Number(r[2]):n;return m(r[1],e in p?e:n)}return xe(e)?e:void 0}var xe=e=>/^[\w\s#(),.%/+-]*$/.test(e),Se=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())},Ce=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),we=e=>({...e,text:e.sub}),Te=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,Ee=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,De=/\*\*(.{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,Oe=l({color:{aliases:[`text`],info:`text colour: a palette name or any CSS colour`,values:f},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`]},font:{aliases:[`family`,`font-family`],info:`font: sans, serif, mono or a font name`,values:[`sans`,`serif`,`mono`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),ke=e=>e in Oe?e:Object.keys(Oe).find(t=>Oe[t].aliases.includes(e));function Ae(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&je(i)){t.color=i;continue}let a=ke(i);if(!a)return;let o=Oe[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(!ye(s))return;t.color=s}else if(a===`font`){let e=de(s);if(!e)return;t.font=e.font,t.mono=e.mono}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}var je=e=>Te.test(e)&&(e.startsWith(`#`)||d(e.replace(/-\d+$/,``)));function N(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(De))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&&je(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=Ae(t[5]),n=e?null:t[0].match(Ee);e?r({kind:`color`,text:t[6],...e}):n&&je(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]}):je(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 Me(e){let t=[];for(let n of e.matchAll(De))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}var Ne=/[*~`[{]/;function Pe(e,t=!1){let n=Ne.test(e)?N(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function Fe(e,t,n,r,i,a=!1,o=0){let s=Pe(e,a);return L(s,t,r,i,n)+(o?o*[...He(s)].length:0)}var Ie=(e,t)=>e.reduce((e,t)=>Ne.test(t)?N(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),Le=1.3,Re=(e,t,n=Le)=>Ie(e,t)*n,ze=`dominant-baseline="inherit"`,Be=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${F(t)}" y="${F(n(i))}" ${ze}>${r(e)}</tspan>`).join(``);function Ve(e,t,n,r=!1){let i=Pe(e,r);return i.every(e=>e.kind===`text`)?P(He(i)):R(i,t,n)}var He=e=>e.map(e=>e.text).join(``);function Ue(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,` `))}var P=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),We=(e,t)=>(e?` font-style="italic"`:``)+(t?` font-family="${P(t)}"`:``),F=e=>(Math.round(e*100)/100).toString(),Ge=(e,t,n,r,i,a=``)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" font-size="${F(n)}" fill="${r}"${a}>${i}</text>`,I=(e,t,n)=>e&&M(e,t,t.dark?400:600)||n,Ke=.55,qe=(e,t)=>e.weight??(e.kind===`bold`?700:t);function L(e,t,n,r,i=400){let a=0;for(let o of e){let e=o.size??t,s=r(o.text,e,qe(o,i),o.mono??n);o.w=o.kind===`chip`?s+e*Ke*2:s,a+=o.w}return a}var Je=e=>e.reduce((e,t)=>e+(t.w??0),0);function Ye(e,t,n,r){if(e.color)return I(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 Xe(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=Ye(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="${F(t)}" y="${F(n-a/2)}" width="${F(e)}" height="${F(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(Ge(t+r*Ke,n,r,l.color?u:i.text,P(l.text),` xml:space="preserve"`))}else{let a=qe(l,s),o=We(l.italic,l.font);if(c.push(Ge(t,n,l.size??r,u,P(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${F(a)},${F(n)}H${F(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function R(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${Ye(e,t,n,r)}"`,ze];return e.size&&i.push(`font-size="${F(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.font&&i.push(`font-family="${P(e.font)}"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${P(e.text)}</tspan>`}).join(``)}var Ze=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function Qe(e,t=`border-style`){let n=e[t];return n&&ie.includes(n)?n:j(e.dashed,!1)?`dashed`:j(e.dotted,!1)?`dotted`:void 0}function $e(e,t){let n=M(t[`edge-color`],e,e.dark?400:500),r=et(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 et(e){return tt(e[`edge-width`])}var z=(e,t)=>{let n=Ze(e,NaN);return n>=0?n:t},tt=e=>{let t=Ze(e,NaN);return t>0?t:void 0},nt=(e,t,n,r)=>{let i=de(e.font);return{size:tt(e[`font-size`])??t,weight:tt(e[`font-weight`])??n,italic:j(e.italic,!1),family:i?.font,mono:i?.mono??r.mono}},rt=(e,t)=>nt(e,t.fontSize*.86,500,t);function it(e,t){let n=[],r=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 at(e,t,n){return st(e,t)[n]??ot(e,t.group,n)?.value}function ot(e,t,n){for(let r of it(e,t).reverse()){let t=st(e,e.groups.get(r))[n];if(t!==void 0)return{group:r,value:t}}}function st(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function ct(e){let t=e?.split(/[\s,]+/).filter(Boolean)??[],n=t.map(e=>Number(e.replace(/px$/,``)));if(!t.length||t.length>4||n.some(e=>!(e>=0)||!Number.isFinite(e)))return null;let[r,i=r,a=r,o=i]=n;return{top:r,right:i,bottom:a,left:o}}function lt(e,t,n){let r=e.groups.get(t);return(r&&ct(st(e,r).padding))??{top:n,right:n,bottom:n,left:n}}function ut(e,t,n){let r=ot(e,t,`gap`);return r?z(r.value,n):n}function dt(e,t){switch(e){case`dashed`:return`${F(t*4)} ${F(t*3)}`;case`dotted`:return`${F(t*.1)} ${F(t*2.6)}`;default:return null}}function ft(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=z(n.border??n[`stroke-width`],z(i[`stroke-width`],r.strokeWidth)),s=M(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=M(n.stroke,r,500)??a?.stroke??r.node.stroke,l=M(n.text,r,r.dark?100:800)??a?.text??r.node.text,u=nt(n,tt(i[`font-size`])??r.fontSize,500,r),d=u.size;return{fill:s,stroke:c,text:l,sub:M(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:dt(Qe(n),o),radius:z(n.radius,z(i.radius,r.radius)),fontSize:d,fontWeight:j(n.bold,!1)?650:u.weight,body:M(n[`body-color`],r,r.dark?100:800)??l,bodySize:tt(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:tt(n[`body-weight`])??400,lineHeight:tt(n[`line-height`])??1.75,italic:u.italic,family:u.family,mono:u.mono,shadow:j(n.shadow,j(i.shadow,r.shadow!==null)),opacity:Ze(n.opacity,1)}}function pt(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:M(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:M(n.stroke,t,300)??r?.stroke??t.group.stroke,text:M(n.text,t,700)??r?.text??t.group.text,dash:mt(n,t.group.dash)}}function mt(e,t){return ae(Qe(e),t)}function ht(e,t,n){let r=t.theme;if(!r||!(S[r]||n?.[r])||r===e.name)return $e(e,t);let i=Object.create(_e(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,$e(i,t)}function gt(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&&ye(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:M(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`:M(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:M(e.text,t,t.dark?200:700)??r?.text??t.title,width:z(e[`border-width`],a&&!s&&!o?z(a,1):1),dash:mt(e,null),radius:z(e.radius,Math.min(14,t.radius+4)),shadow:j(e.shadow,!1)}}function _t(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??M(n.color,r,500):void 0,o=M(n.stroke,r,r.dark?400:500)??a??r.edge.stroke,s=t.line===`thick`||j(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=z(n.width,s),l=Qe(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=j(n.flow??n.animate,!1),f=rt(n,r);return{stroke:o,width:c,dash:dt(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:M(n.text??n[`label-color`],r,700)??(a&&!r.dark?M(n.color,r,700):r.edge.text),fontSize:f.size,fontWeight:f.weight,italic:f.italic,family:f.family,mono:f.mono,labelBg:M(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:Ze(n.opacity,1)}}var vt=[`center`,`left`,`right`,`top`,`bottom`],yt=`[${vt.join(`|`)}]`;function bt(e){let t=vt.find(t=>t===e[0]);return t?[t,e.slice(1)]:[`center`,e]}function xt(e,t){return(e===`rank`||e===`align`)&&t!==`at`&&t!==`size`}function St(e){let t=[],n=[...[...e.nodes.values()].map(e=>[e,!1]),...[...e.groups.values()].map(e=>[e,!0])];for(let[r,i]of n){let n=st(e,r).align?.trim();if(n){let[e,a]=bt(n.split(/\s+/));t.push({decl:r,group:i,value:n,side:e,rest:a})}}return t}function Ct(e){let t=[...e.layout.aligns??[]],n=St(e),r=new Map;if(n.some(e=>e.group&&!e.rest.length)){let t=(e,t)=>e&&(r.get(e)?.push(t)??r.set(e,[t]));e.nodes.forEach(e=>t(e.group,e.id)),e.groups.forEach(e=>t(e.parent,e.id))}let i=[];for(let{decl:e,group:a,side:o,rest:s}of n)s[0]?t.push({side:o,ids:[e.id,s[0]]}):a&&(r.get(e.id)?.length??0)>1&&i.push({side:o,ids:r.get(e.id),within:e.id});for(let e of t){let t=i.filter(t=>!t.within&&t.side===e.side&&t.ids.some(t=>e.ids.includes(t))),n=new Set([...t.flatMap(e=>e.ids),...e.ids]);i.splice(0,i.length,...i.filter(e=>!t.includes(e)),{side:e.side,ids:[...n]})}return i}function wt(e,t,n,r,i){if(!i.length){let i=Lt(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}:It(Pt(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=Lt(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}var Tt=18;function Et(e,t,n,r,i,a,o,s){let c=Nt(e,t,Tt),l=Nt(n,r,Tt),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=Ot([...u,...e,l,n]),r=At(t,b);r<S&&(S=r,x=t)}return x}function Dt(e){let t=[];for(let n of e)(!t.length||Lt(t[t.length-1],n)>.5)&&t.push(n);return t}function Ot(e){let t=Dt(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=It(Pt(t[e],r)),o=It(Pt(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 kt(e,t,n){let r=n.x+2,i=n.x+n.w-2,a=n.y+2,o=n.y+n.h-2;return Math.abs(e.y-t.y)<.5?e.y<=a||e.y>=o?!1:Math.max(e.x,t.x)>r&&Math.min(e.x,t.x)<i:Math.abs(e.x-t.x)<.5?e.x<=r||e.x>=i?!1:Math.max(e.y,t.y)>a&&Math.min(e.y,t.y)<o:!1}function At(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=Lt(e[a-1],e[a]),a>=2){let t=It(Pt(e[a-1],e[a-2])),n=It(Pt(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)kt(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}var jt=[`top`,`right`,`bottom`,`left`],Mt=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}),Pt=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Ft=e=>Math.hypot(e.x,e.y),It=e=>{let t=Ft(e)||1;return{x:e.x/t,y:e.y/t}},Lt=(e,t)=>Ft(Pt(e,t)),B=e=>Math.round(e*100)/100,Rt=(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,zt=(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 Bt(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(Vt(n,r,i,a,e/16));return t}function Vt(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 Ht(e){return Ut(e,.5)}function Ut(e,t){let n=0;for(let t=1;t<e.length;t++)n+=Lt(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=Lt(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 Wt(e){if(e.kind===`cubic`){let t=`M${B(e.segs[0][0].x)},${B(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${B(n.x)},${B(n.y)} ${B(r.x)},${B(r.y)} ${B(i.x)},${B(i.y)}`;return t}let t=Dt(e.pts),n=`M${B(t[0].x)},${B(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,Lt(i,a)/2,Lt(a,o)/2);if(s<.5){n+=`L${B(a.x)},${B(a.y)}`;continue}let c=Nt(a,It(Pt(i,a)),s),l=Nt(a,It(Pt(o,a)),s);n+=`L${B(c.x)},${B(c.y)}Q${B(a.x)},${B(a.y)} ${B(l.x)},${B(l.y)}`}let r=t[t.length-1];return n+`L${B(r.x)},${B(r.y)}`}function Gt(e,t,n,r){let i=Mt(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`}var Kt={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function qt(e,t,n){let r=Mt(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function Jt(e,t,n){let r=qt(t,n,e);return[e,r,Kt[r]]}function Yt(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&&Rt(n,l));if(!u.length)return[n,r];let d=i?Jt(n,e,Mt(t)):[n],f=a?Jt(r,t,Mt(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=Nn(e.shape,e,r,0),o=Nn(t.shape,t,i,0),s=Bt({kind:`cubic`,segs:wt(a,jn[r],o,jn[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}function Xt(e,t){return t===0?e.via[0]??Mt(e.b):e.via[e.via.length-1]??Mt(e.a)}function Zt(e){let t=new Map;for(let n of e){let{stroke:e,width:r,dash:i,curve:a,flow:o,opacity:s}=n.style,c=[e,r,i,a,o,s].join(`\0`);for(let e of[0,1]){if(!n.mergeable[e])continue;let r=e===0?n.a:n.b,i=n.sides[e],a=e===0?n.tailKind:n.headKind,o=[e,r.id,i,a,c].join(`\0`),s=t.get(o);s?s.members.push(n):t.set(o,{members:[n],lead:n,end:e,node:r,side:i,reach:0})}}let n=[...t.values()].filter(e=>e.members.length>1);for(let e of n)for(let t of e.members)t.merged[e.end]=e;return n}var Qt=16,$t=.4;function en(e){return e.filter(e=>{let{end:t,node:n}=e,r=Nn(n.shape,n,e.side,0),i=jn[e.side],a=e=>(e.x-r.x)*i.x+(e.y-r.y)*i.y;if(e.reach=Math.min(...e.members.map(e=>{let n=t===0?e.via[0]:e.via[e.via.length-1];if(n)return a(n);let r=t===0?e.b:e.a,i=[r,{x:r.x+r.w,y:r.y},{x:r.x,y:r.y+r.h},{x:r.x+r.w,y:r.y+r.h}];return Math.min(...i.map(a))}))*$t,e.reach>=Qt)return!0;for(let n of e.members)n.merged[t]=void 0;return!1})}function tn(e){for(let t of e){let{end:e,lead:n}=t;t.junction=Nt(Nn(t.node.shape,t.node,t.side,n.t[e]),jn[t.side],t.reach);for(let r of t.members)r.t[e]=n.t[e]}}var nn=[.5,.42,.58,.34,.66,.26,.74];function rn(e,t,n,r){let i=Ut(e,.5),a=1/0;for(let n of nn){let o=Ut(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)Rt(s,e)&&(c+=4);for(let e of r.groups??[])Rt(s,e.header)?c+=3:Rt(s,e.box)&&!zt(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}var an=e=>7+e*2;function on(e,t,n){let r=vn.get(e);return r?typeof r.inset==`function`?r.inset(t,n):r.inset??0:0}function sn(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(Lt(n[e],n[n.length-1])>.5)return It(Pt(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(Lt(n[e],n[0])>.5)return It(Pt(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return It(Pt(r,Lt(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return It(Pt(n,Lt(r,n)>.5?r:i))}function cn(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=Lt(r[i],r[a]);if(o<.5)return;r[i]=Nt(r[i],It(Pt(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=It(Pt(Lt(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=Nt(t[3],r,n),Lt(t[2],t[3])<n&&(t[2]=Nt(t[3],r,n))}else{let t=e.segs[0],r=It(Pt(Lt(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=Nt(t[0],r,n)}}}var ln={both:[!0,!0],out:[!0,!1],in:[!1,!0],none:[!1,!1]},un={right:`right`,down:`bottom`,left:`left`,up:`top`};function dn(e,t,n){return n===`right`?t.x>=e.x+e.w:n===`left`?t.x+t.w<=e.x:n===`down`?t.y>=e.y+e.h:t.y+t.h<=e.y}var fn=(e,t)=>e&&(e===`none`||vn.has(e))?e:t;function pn(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=new Map;for(let t of e.edges){if(t.from===t.to||e.layout.edges[t.key]?.via?.length||n.dummyVia.get(t.key)?.length)continue;let r=i(t.from,t.to);a.has(r)||a.set(r,[]),a.get(r).push(t.key)}let o=n.theme.fontSize*2.1,s=new Map(e.edges.map(e=>[e.key,e])),c=new Map,l=new Map,u=t=>{let n=l.get(t);if(!n){let r=e.nodes.get(t);n=ln[(r&&at(e,r,`merge`))??e.settings.merge??`none`]??ln.none,l.set(t,n)}return n};for(let l of e.edges){let d=t.get(l.from),f=t.get(l.to);if(!d||!f)continue;let p=st(e,l),m=_t(e,l,p,n.theme,n.defaultCurve),h=e.layout.edges[l.key],g=!!h?.via?.length,_=(g?h.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),v=d!==f&&!_.length?a.get(i(l.from,l.to)):void 0;if(v&&v.length>1){let[t,r]=l.from<l.to?[d,f]:[f,d],i=It(Pt(Mt(r),Mt(t))),a=c.get(v);if(!a){let t=v.map(t=>{let r=s.get(t),a=r?.label?rt(st(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
2
- `).map(e=>Fe(e,a.size,a.weight,a.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=new Map;let l=0;for(let e=0;e<v.length;e++)a.set(v[e],l+t[e]/2-r/2),l+=t[e];c.set(v,a)}let u=a.get(l.key),p=Mt(d),m=Mt(f);u&&_.push(Nt({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},u))}let y=h?.ports?.[0]??p.exit??p[`from-side`],b=h?.ports?.[1]??p.enter??p[`to-side`],x=jt.includes(y)?y:null,S=jt.includes(b)?b:null,C=x??Gt(d,_[0]??Mt(f),_.length?null:f,n.direction),w=S??Gt(f,_[_.length-1]??Mt(d),_.length?null:d,n.direction);_.length||d===f||x&&S||([C,w]=Yt(d,f,C,w,!x,!S,n.obstacles));let T=d===f||g||(v?.length??0)>1?[!1,!1]:p.merge?ln[p.merge]??ln.none:[u(l.from)[0],u(l.to)[1]];dn(d,f,n.direction)&&(C=T[0]&&!x?un[n.direction]:C,w=T[1]&&!S?Kt[un[n.direction]]:w),r.push({e:l,a:d,b:f,via:_,manualVia:g,sides:d===f?[`right`,`top`]:[C,w],t:[0,0],style:m,headKind:l.endHead||p.head?fn(p.head,`arrow`):`none`,tailKind:l.startHead||p.tail?fn(p.tail,`arrow`):`none`,labelOff:h?.label,mergeable:T,merged:[void 0,void 0]})}let d=en(Zt(r)),f=new Map,p=(e,t,n,r,i)=>{let a=i.map(e=>Xt(e,t)),o={x:a.reduce((e,t)=>e+t.x,0)/a.length,y:a.reduce((e,t)=>e+t.y,0)/a.length},s=`${n.id}\u0000${r}`,c=f.get(s)??{side:r,list:[]};f.set(s,c),c.list.push({it:e,end:t,other:o})};for(let e of r)if(e.a!==e.b)for(let t of[0,1])e.merged[t]||p(e,t,t===0?e.a:e.b,e.sides[t],[e]);for(let e of d)p(e.lead,e.end,e.node,e.side,e.members);let m=new Map(r.map((e,t)=>[e,t]));for(let{side:e,list:t}of f.values()){let n=e===`top`||e===`bottom`;t.sort((e,t)=>(n?e.other.x-t.other.x:e.other.y-t.other.y)||m.get(e.it)-m.get(t.it));let r=t.length;t.forEach((e,t)=>e.it.t[e.end]=r===1?0:(t+1)/(r+1)*2-1)}return tn(d),r.map(e=>mn(e,n))}function mn(e,t){let{a:n,b:r,style:i}=e,a,o,s;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]]}):(o=Nn(n.shape,n,e.sides[0],e.t[0]),s=Nn(r.shape,r,e.sides[1],e.t[1]),a=hn(e,t,e.merged[0]?.junction??o,e.merged[1]?.junction??s));let c=e.e.props.caption,l=e.e.label||c?Bt(a):void 0,[u,d]=e.merged,f=u?.lead===e,p=d?.lead===e;f&&gn(a,`start`,o),p&&gn(a,`end`,s);let m=l&&!f&&!p?l:Bt(a),h;if(l){let n=i.fontSize,{mono:r}=t.theme,a=e.e.label?e.e.label.split(`
1
+ (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=null;function t(t,n){let r=e;e=t;try{return n()}finally{e=r}}var n=e=>e instanceof Error?e.message:String(e),r=t=>{e&&!e.some(e=>e.message===t)&&e.push({line:1,message:t,severity:`error`})};function i(e,t,i,a,o=r){return function(...r){try{return i.apply(this,r)}catch(i){return o(`plugin "${e}": ${t} failed: ${n(i)}`,r),a(...r)}}}var a=new Map;function o(e,t,n){let r=`${e} ${t}`,i=a.get(r);i&&i!==n&&console.warn(`yuhwa: plugin "${n}" replaces ${e} "${t}" of plugin "${i}"`),a.set(r,n)}var s=()=>a.clear(),c=(e,t)=>a.get(`${e} ${t}`),l=e=>Object.setPrototypeOf(e,null),u=l({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`]});u.violet=u.purple,u.rose=u.red,u.emerald=u.green,u.yellow=u.amber,u.grey=u.gray,u.sky=u.cyan;var d=e=>Object.hasOwn(u,e),f=[`slate`,`gray`,`red`,`orange`,`amber`,`lime`,`green`,`teal`,`cyan`,`blue`,`indigo`,`purple`,`pink`],p={50:0,100:1,200:2,300:3,400:4,500:5,600:6,700:7,800:8,900:9,950:10};function m(e,t){return u[e]?.[p[t]]}var h=`Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif`,g=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,_=`ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif`,v=e=>u[e]&&{fill:m(e,50),stroke:m(e,300),text:m(e,900)},y=e=>u[e]&&{fill:m(e,50)+`b3`,stroke:m(e,200),text:m(e,700)},b=e=>u[e]&&{fill:m(e,950),stroke:m(e,600),text:m(e,100)},x=e=>u[e]&&{fill:m(e,950)+`80`,stroke:m(e,800),text:m(e,300)},S=l({paper:{name:`paper`,dark:!1,background:`#fbfaf7`,font:h,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=>m(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)}var 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}var ee=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))},te=(e,t,n)=>{let r=ee(t);return`#`+ee(e).map((e,t)=>Math.round(e*n+r[t]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``)};function ne(e,t,n){let r=k(e);return r?{fill:te(r,T.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,t.dark?n?.14:.22:n?.07:.12),stroke:r,text:t.dark?te(r,`#ffffff`,.45):te(r,`#000000`,.55)}:void 0}var A=new WeakMap,re=new WeakMap,j=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),ie=[`solid`,`dashed`,`dotted`],ae=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t,oe={sans:h,serif:_,mono:g},se=/^(serif|sans-serif|monospace|cursive|fantasy|math|emoji|system-ui|ui-(serif|sans-serif|monospace|rounded))$/i,ce=e=>se.test(e),le=e=>e.split(`,`).map(e=>e.trim().replace(/^(['"])(.*)\1$/,`$2`)).filter(Boolean);function ue(e){let t=e.split(`,`).map(e=>e.trim()).filter(Boolean),n=le(e)[0]??`sans`,r=n===`mono`||/mono|code|courier/i.test(n),i=t.map(e=>oe[e]??e),a=t.at(-1)??``;return!oe[a]&&!ce(a)&&i.push(r?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`),{font:i.join(`, `),mono:r}}function de(e){if(!e||!/^[\w\s'",.-]+$/.test(e))return;let t=fe.get(e);return t||fe.set(e,t=ue(e)),t}var fe=new Map,pe=l({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:ie},"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 me(e,t,n){let r=n??S[t.base]??S.paper,i=j(t.dark,r.dark),a=(e,n,a)=>M(t[e],r,i?a:n),o=(e,n)=>{let r=parseFloat(t[e]);return Number.isFinite(r)&&r>=0?r:n},s=e=>!j(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?ue(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:ae(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=>m(e,i?400:500):r.edgeTone}}function he(e,t,n=[]){let r=t[e],i=r.base??(S[e]?e:void 0);return me(e,r,i&&t[i]&&i!==e&&!n.includes(i)?he(i,t,[...n,e]):S[i??`paper`]??S.paper)}var ge=e=>[...new Set([...C,...Object.keys(e??{})])];function _e(e,t){if(e&&t?.[e]){let n=re.get(t);n||re.set(t,n=new Map);let r=n.get(e);return r||n.set(e,r=ve(he(e,t))),r}return ve(S[e??`paper`]??S.paper)}function ve(e){let t=A.get(e);return t||(t={...e,tone:n=>e.tone(n)??ne(n,t,!1),groupTone:n=>e.groupTone(n)??ne(n,t,!0),edgeTone:t=>e.edgeTone(t)??(k(t)?t:void 0)},A.set(e,t)),t}var ye=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&d(t[1])&&(!t[2]||t[2]in p)||!!k(e)},be=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function M(e,t,n){if(!e)return;let r=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);if(r&&u[r[1]]){let e=r[2]?Number(r[2]):n;return m(r[1],e in p?e:n)}return xe(e)?e:void 0}var xe=e=>/^[\w\s#(),.%/+-]*$/.test(e),Se=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())},Ce=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),we=e=>({...e,text:e.sub}),Te=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,Ee=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,De=/\*\*(.{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,Oe=l({color:{aliases:[`text`],info:`text colour: a palette name or any CSS colour`,values:f},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`]},font:{aliases:[`family`,`font-family`],info:`font: sans, serif, mono or a font name`,values:[`sans`,`serif`,`mono`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),ke=e=>e in Oe?e:Object.keys(Oe).find(t=>Oe[t].aliases.includes(e));function Ae(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&je(i)){t.color=i;continue}let a=ke(i);if(!a)return;let o=Oe[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(!ye(s))return;t.color=s}else if(a===`font`){let e=de(s);if(!e)return;t.font=e.font,t.mono=e.mono}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}var je=e=>Te.test(e)&&(e.startsWith(`#`)||d(e.replace(/-\d+$/,``)));function N(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(De))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&&je(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=Ae(t[5]),n=e?null:t[0].match(Ee);e?r({kind:`color`,text:t[6],...e}):n&&je(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]}):je(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 Me(e){let t=[];for(let n of e.matchAll(De))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}var Ne=/[*~`[{]/;function Pe(e,t=!1){let n=Ne.test(e)?N(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function Fe(e,t,n,r,i,a=!1,o=0){let s=Pe(e,a);return L(s,t,r,i,n)+(o?o*[...Ge(s)].length:0)}var Ie=(e,t)=>e.reduce((e,t)=>Ne.test(t)?N(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),Le=1.3,Re=(e,t,n=Le)=>Ie(e,t)*n,ze=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${F(t)}" y="${F(n(i))}">${r(e)}</tspan>`).join(``),Be=.35,Ve=/<text\b([^>]*)>([\s\S]*?)<\/text>/g,He=/(\s)y="(-?[\d.]+)"/;function Ue(e){return e.replace(Ve,(e,t,n)=>{if(!t.includes(`dominant-baseline="central"`))return e;let r=Number(/\sfont-size="([\d.]+)"/.exec(t)?.[1]);if(!r)return e;let i=e=>e.replace(He,(e,t,n)=>`${t}y="${F(Number(n)+r*Be)}"`);return`<text${i(t.replace(` dominant-baseline="central"`,``))}>${n.replace(/<tspan\b[^>]*>/g,i)}</text>`})}function We(e,t,n,r=!1){let i=Pe(e,r);return i.every(e=>e.kind===`text`)?P(Ge(i)):R(i,t,n)}var Ge=e=>e.map(e=>e.text).join(``);function Ke(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,` `))}var P=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),qe=(e,t)=>(e?` font-style="italic"`:``)+(t?` font-family="${P(t)}"`:``),F=e=>(Math.round(e*100)/100).toString(),Je=(e,t,n,r,i,a=``)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" font-size="${F(n)}" fill="${r}"${a}>${i}</text>`,I=(e,t,n)=>e&&M(e,t,t.dark?400:600)||n,Ye=.55,Xe=(e,t)=>e.weight??(e.kind===`bold`?700:t);function L(e,t,n,r,i=400){let a=0;for(let o of e){let e=o.size??t,s=r(o.text,e,Xe(o,i),o.mono??n);o.w=o.kind===`chip`?s+e*Ye*2:s,a+=o.w}return a}var Ze=e=>e.reduce((e,t)=>e+(t.w??0),0);function Qe(e,t,n,r){if(e.color)return I(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 $e(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=Qe(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="${F(t)}" y="${F(n-a/2)}" width="${F(e)}" height="${F(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(Je(t+r*Ye,n,r,l.color?u:i.text,P(l.text),` xml:space="preserve"`))}else{let a=Xe(l,s),o=qe(l.italic,l.font);if(c.push(Je(t,n,l.size??r,u,P(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${F(a)},${F(n)}H${F(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function R(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${Qe(e,t,n,r)}"`];return e.size&&i.push(`font-size="${F(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.font&&i.push(`font-family="${P(e.font)}"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${P(e.text)}</tspan>`}).join(``)}var et=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function tt(e,t=`border-style`){let n=e[t];return n&&ie.includes(n)?n:j(e.dashed,!1)?`dashed`:j(e.dotted,!1)?`dotted`:void 0}function nt(e,t){let n=M(t[`edge-color`],e,e.dark?400:500),r=rt(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 rt(e){return it(e[`edge-width`])}var z=(e,t)=>{let n=et(e,NaN);return n>=0?n:t},it=e=>{let t=et(e,NaN);return t>0?t:void 0},at=(e,t,n,r)=>{let i=de(e.font);return{size:it(e[`font-size`])??t,weight:it(e[`font-weight`])??n,italic:j(e.italic,!1),family:i?.font,mono:i?.mono??r.mono}},ot=(e,t)=>at(e,t.fontSize*.86,500,t);function st(e,t){let n=[],r=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 ct(e,t,n){return ut(e,t)[n]??lt(e,t.group,n)?.value}function lt(e,t,n){for(let r of st(e,t).reverse()){let t=ut(e,e.groups.get(r))[n];if(t!==void 0)return{group:r,value:t}}}function ut(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function dt(e){let t=e?.split(/[\s,]+/).filter(Boolean)??[],n=t.map(e=>Number(e.replace(/px$/,``)));if(!t.length||t.length>4||n.some(e=>!(e>=0)||!Number.isFinite(e)))return null;let[r,i=r,a=r,o=i]=n;return{top:r,right:i,bottom:a,left:o}}function ft(e,t,n){let r=e.groups.get(t);return(r&&dt(ut(e,r).padding))??{top:n,right:n,bottom:n,left:n}}function pt(e,t,n){let r=lt(e,t,`gap`);return r?z(r.value,n):n}function mt(e,t){switch(e){case`dashed`:return`${F(t*4)} ${F(t*3)}`;case`dotted`:return`${F(t*.1)} ${F(t*2.6)}`;default:return null}}function ht(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=z(n.border??n[`stroke-width`],z(i[`stroke-width`],r.strokeWidth)),s=M(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=M(n.stroke,r,500)??a?.stroke??r.node.stroke,l=M(n.text,r,r.dark?100:800)??a?.text??r.node.text,u=at(n,it(i[`font-size`])??r.fontSize,500,r),d=u.size;return{fill:s,stroke:c,text:l,sub:M(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:mt(tt(n),o),radius:z(n.radius,z(i.radius,r.radius)),fontSize:d,fontWeight:j(n.bold,!1)?650:u.weight,body:M(n[`body-color`],r,r.dark?100:800)??l,bodySize:it(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:it(n[`body-weight`])??400,lineHeight:it(n[`line-height`])??1.75,italic:u.italic,family:u.family,mono:u.mono,shadow:j(n.shadow,j(i.shadow,r.shadow!==null)),opacity:et(n.opacity,1)}}function gt(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:M(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:M(n.stroke,t,300)??r?.stroke??t.group.stroke,text:M(n.text,t,700)??r?.text??t.group.text,dash:_t(n,t.group.dash)}}function _t(e,t){return ae(tt(e),t)}function vt(e,t,n){let r=t.theme;if(!r||!(S[r]||n?.[r])||r===e.name)return nt(e,t);let i=Object.create(_e(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,nt(i,t)}function yt(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&&ye(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:M(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`:M(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:M(e.text,t,t.dark?200:700)??r?.text??t.title,width:z(e[`border-width`],a&&!s&&!o?z(a,1):1),dash:_t(e,null),radius:z(e.radius,Math.min(14,t.radius+4)),shadow:j(e.shadow,!1)}}function bt(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??M(n.color,r,500):void 0,o=M(n.stroke,r,r.dark?400:500)??a??r.edge.stroke,s=t.line===`thick`||j(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=z(n.width,s),l=tt(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=j(n.flow??n.animate,!1),f=ot(n,r);return{stroke:o,width:c,dash:mt(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:M(n.text??n[`label-color`],r,700)??(a&&!r.dark?M(n.color,r,700):r.edge.text),fontSize:f.size,fontWeight:f.weight,italic:f.italic,family:f.family,mono:f.mono,labelBg:M(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:et(n.opacity,1)}}var xt=[`center`,`left`,`right`,`top`,`bottom`],St=`[${xt.join(`|`)}]`;function Ct(e){let t=xt.find(t=>t===e[0]);return t?[t,e.slice(1)]:[`center`,e]}function wt(e,t){return(e===`rank`||e===`align`)&&t!==`at`&&t!==`size`}function Tt(e){let t=[],n=[...[...e.nodes.values()].map(e=>[e,!1]),...[...e.groups.values()].map(e=>[e,!0])];for(let[r,i]of n){let n=ut(e,r).align?.trim();if(n){let[e,a]=Ct(n.split(/\s+/));t.push({decl:r,group:i,value:n,side:e,rest:a})}}return t}function Et(e){let t=[...e.layout.aligns??[]],n=Tt(e),r=new Map;if(n.some(e=>e.group&&!e.rest.length)){let t=(e,t)=>e&&(r.get(e)?.push(t)??r.set(e,[t]));e.nodes.forEach(e=>t(e.group,e.id)),e.groups.forEach(e=>t(e.parent,e.id))}let i=[];for(let{decl:e,group:a,side:o,rest:s}of n)s[0]?t.push({side:o,ids:[e.id,s[0]]}):a&&(r.get(e.id)?.length??0)>1&&i.push({side:o,ids:r.get(e.id),within:e.id});for(let e of t){let t=i.filter(t=>!t.within&&t.side===e.side&&t.ids.some(t=>e.ids.includes(t))),n=new Set([...t.flatMap(e=>e.ids),...e.ids]);i.splice(0,i.length,...i.filter(e=>!t.includes(e)),{side:e.side,ids:[...n]})}return i}function Dt(e,t,n,r,i){if(!i.length){let i=Bt(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,It(e,t,o),It(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}:zt(Lt(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=Bt(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],It(a[e],o[e],n),It(a[e+1],o[e+1],-r),a[e+1]])}return s}var Ot=18;function kt(e,t,n,r,i,a,o,s){let c=It(e,t,Ot),l=It(n,r,Ot),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=jt([...u,...e,l,n]),r=Nt(t,b);r<S&&(S=r,x=t)}return x}function At(e){let t=[];for(let n of e)(!t.length||Bt(t[t.length-1],n)>.5)&&t.push(n);return t}function jt(e){let t=At(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=zt(Lt(t[e],r)),o=zt(Lt(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 Mt(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 Nt(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=Bt(e[a-1],e[a]),a>=2){let t=zt(Lt(e[a-1],e[a-2])),n=zt(Lt(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)Mt(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}var Pt=[`top`,`right`,`bottom`,`left`],Ft=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),It=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),Lt=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Rt=e=>Math.hypot(e.x,e.y),zt=e=>{let t=Rt(e)||1;return{x:e.x/t,y:e.y/t}},Bt=(e,t)=>Rt(Lt(e,t)),B=e=>Math.round(e*100)/100,Vt=(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,Ht=(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 Ut(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(Wt(n,r,i,a,e/16));return t}function Wt(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 Gt(e){return Kt(e,.5)}function Kt(e,t){let n=0;for(let t=1;t<e.length;t++)n+=Bt(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=Bt(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 qt(e){if(e.kind===`cubic`){let t=`M${B(e.segs[0][0].x)},${B(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${B(n.x)},${B(n.y)} ${B(r.x)},${B(r.y)} ${B(i.x)},${B(i.y)}`;return t}let t=At(e.pts),n=`M${B(t[0].x)},${B(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,Bt(i,a)/2,Bt(a,o)/2);if(s<.5){n+=`L${B(a.x)},${B(a.y)}`;continue}let c=It(a,zt(Lt(i,a)),s),l=It(a,zt(Lt(o,a)),s);n+=`L${B(c.x)},${B(c.y)}Q${B(a.x)},${B(a.y)} ${B(l.x)},${B(l.y)}`}let r=t[t.length-1];return n+`L${B(r.x)},${B(r.y)}`}function Jt(e,t,n,r){let i=Ft(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`}var Yt={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function Xt(e,t,n){let r=Ft(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function Zt(e,t,n){let r=Xt(t,n,e);return[e,r,Yt[r]]}function Qt(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&&Vt(n,l));if(!u.length)return[n,r];let d=i?Zt(n,e,Ft(t)):[n],f=a?Zt(r,t,Ft(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=In(e.shape,e,r,0),o=In(t.shape,t,i,0),s=Ut({kind:`cubic`,segs:Dt(a,Pn[r],o,Pn[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}function $t(e,t){return t===0?e.via[0]??Ft(e.b):e.via[e.via.length-1]??Ft(e.a)}function en(e){let t=new Map;for(let n of e){let{stroke:e,width:r,dash:i,curve:a,flow:o,opacity:s}=n.style,c=[e,r,i,a,o,s].join(`\0`);for(let e of[0,1]){if(!n.mergeable[e])continue;let r=e===0?n.a:n.b,i=n.sides[e],a=e===0?n.tailKind:n.headKind,o=[e,r.id,i,a,c].join(`\0`),s=t.get(o);s?s.members.push(n):t.set(o,{members:[n],lead:n,end:e,node:r,side:i,reach:0})}}let n=[...t.values()].filter(e=>e.members.length>1);for(let e of n)for(let t of e.members)t.merged[e.end]=e;return n}var tn=16,nn=.4;function rn(e){return e.filter(e=>{let{end:t,node:n}=e,r=In(n.shape,n,e.side,0),i=Pn[e.side],a=e=>(e.x-r.x)*i.x+(e.y-r.y)*i.y;if(e.reach=Math.min(...e.members.map(e=>{let n=t===0?e.via[0]:e.via[e.via.length-1];if(n)return a(n);let r=t===0?e.b:e.a,i=[r,{x:r.x+r.w,y:r.y},{x:r.x,y:r.y+r.h},{x:r.x+r.w,y:r.y+r.h}];return Math.min(...i.map(a))}))*nn,e.reach>=tn)return!0;for(let n of e.members)n.merged[t]=void 0;return!1})}function an(e){for(let t of e){let{end:e,lead:n}=t;t.junction=It(In(t.node.shape,t.node,t.side,n.t[e]),Pn[t.side],t.reach);for(let r of t.members)r.t[e]=n.t[e]}}var on=[.5,.42,.58,.34,.66,.26,.74];function sn(e,t,n,r){let i=Kt(e,.5),a=1/0;for(let n of on){let o=Kt(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)Vt(s,e)&&(c+=4);for(let e of r.groups??[])Vt(s,e.header)?c+=3:Vt(s,e.box)&&!Ht(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}var cn=e=>7+e*2;function ln(e,t,n){let r=xn.get(e);return r?typeof r.inset==`function`?r.inset(t,n):r.inset??0:0}function un(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(Bt(n[e],n[n.length-1])>.5)return zt(Lt(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(Bt(n[e],n[0])>.5)return zt(Lt(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return zt(Lt(r,Bt(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return zt(Lt(n,Bt(r,n)>.5?r:i))}function dn(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=Bt(r[i],r[a]);if(o<.5)return;r[i]=It(r[i],zt(Lt(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=zt(Lt(Bt(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=It(t[3],r,n),Bt(t[2],t[3])<n&&(t[2]=It(t[3],r,n))}else{let t=e.segs[0],r=zt(Lt(Bt(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=It(t[0],r,n)}}}var fn={both:[!0,!0],out:[!0,!1],in:[!1,!0],none:[!1,!1]},pn={right:`right`,down:`bottom`,left:`left`,up:`top`};function mn(e,t,n){return n===`right`?t.x>=e.x+e.w:n===`left`?t.x+t.w<=e.x:n===`down`?t.y>=e.y+e.h:t.y+t.h<=e.y}var hn=(e,t)=>e&&(e===`none`||xn.has(e))?e:t;function gn(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=new Map;for(let t of e.edges){if(t.from===t.to||e.layout.edges[t.key]?.via?.length||n.dummyVia.get(t.key)?.length)continue;let r=i(t.from,t.to);a.has(r)||a.set(r,[]),a.get(r).push(t.key)}let o=n.theme.fontSize*2.1,s=new Map(e.edges.map(e=>[e.key,e])),c=new Map,l=new Map,u=t=>{let n=l.get(t);if(!n){let r=e.nodes.get(t);n=fn[(r&&ct(e,r,`merge`))??e.settings.merge??`none`]??fn.none,l.set(t,n)}return n};for(let l of e.edges){let d=t.get(l.from),f=t.get(l.to);if(!d||!f)continue;let p=ut(e,l),m=bt(e,l,p,n.theme,n.defaultCurve),h=e.layout.edges[l.key],g=!!h?.via?.length,_=(g?h.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),v=d!==f&&!_.length?a.get(i(l.from,l.to)):void 0;if(v&&v.length>1){let[t,r]=l.from<l.to?[d,f]:[f,d],i=zt(Lt(Ft(r),Ft(t))),a=c.get(v);if(!a){let t=v.map(t=>{let r=s.get(t),a=r?.label?ot(ut(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
2
+ `).map(e=>Fe(e,a.size,a.weight,a.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=new Map;let l=0;for(let e=0;e<v.length;e++)a.set(v[e],l+t[e]/2-r/2),l+=t[e];c.set(v,a)}let u=a.get(l.key),p=Ft(d),m=Ft(f);u&&_.push(It({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},u))}let y=h?.ports?.[0]??p.exit??p[`from-side`],b=h?.ports?.[1]??p.enter??p[`to-side`],x=Pt.includes(y)?y:null,S=Pt.includes(b)?b:null,C=x??Jt(d,_[0]??Ft(f),_.length?null:f,n.direction),w=S??Jt(f,_[_.length-1]??Ft(d),_.length?null:d,n.direction);_.length||d===f||x&&S||([C,w]=Qt(d,f,C,w,!x,!S,n.obstacles));let T=d===f||g||(v?.length??0)>1?[!1,!1]:p.merge?fn[p.merge]??fn.none:[u(l.from)[0],u(l.to)[1]];mn(d,f,n.direction)&&(C=T[0]&&!x?pn[n.direction]:C,w=T[1]&&!S?Yt[pn[n.direction]]:w),r.push({e:l,a:d,b:f,via:_,manualVia:g,sides:d===f?[`right`,`top`]:[C,w],t:[0,0],style:m,headKind:l.endHead||p.head?hn(p.head,`arrow`):`none`,tailKind:l.startHead||p.tail?hn(p.tail,`arrow`):`none`,labelOff:h?.label,mergeable:T,merged:[void 0,void 0]})}let d=rn(en(r)),f=new Map,p=(e,t,n,r,i)=>{let a=i.map(e=>$t(e,t)),o={x:a.reduce((e,t)=>e+t.x,0)/a.length,y:a.reduce((e,t)=>e+t.y,0)/a.length},s=`${n.id}\u0000${r}`,c=f.get(s)??{side:r,list:[]};f.set(s,c),c.list.push({it:e,end:t,other:o})};for(let e of r)if(e.a!==e.b)for(let t of[0,1])e.merged[t]||p(e,t,t===0?e.a:e.b,e.sides[t],[e]);for(let e of d)p(e.lead,e.end,e.node,e.side,e.members);let m=new Map(r.map((e,t)=>[e,t]));for(let{side:e,list:t}of f.values()){let n=e===`top`||e===`bottom`;t.sort((e,t)=>(n?e.other.x-t.other.x:e.other.y-t.other.y)||m.get(e.it)-m.get(t.it));let r=t.length;t.forEach((e,t)=>e.it.t[e.end]=r===1?0:(t+1)/(r+1)*2-1)}return an(d),r.map(e=>_n(e,n))}function _n(e,t){let{a:n,b:r,style:i}=e,a,o,s;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,It(o,{x:52,y:0}),It(s,{x:0,y:-52}),s]]}):(o=In(n.shape,n,e.sides[0],e.t[0]),s=In(r.shape,r,e.sides[1],e.t[1]),a=vn(e,t,e.merged[0]?.junction??o,e.merged[1]?.junction??s));let c=e.e.props.caption,l=e.e.label||c?Ut(a):void 0,[u,d]=e.merged,f=u?.lead===e,p=d?.lead===e;f&&yn(a,`start`,o),p&&yn(a,`end`,s);let m=l&&!f&&!p?l:Ut(a),h;if(l){let n=i.fontSize,{mono:r}=t.theme,a=e.e.label?e.e.label.split(`
3
3
  `):[],o=a.length?Math.max(...a.map(e=>Fe(e,n,i.fontWeight,r,t.measure)))+(t.theme.edge.labelStroke?18:12):0,s=Re(a,n),u=a.length?a.length*s+6:0,d=n*.88,f=c?c.split(`
4
- `):[],p=f.length?Math.max(...f.map(e=>Fe(e,d,400,r,t.measure)))+8:0,m=Re(f,d),g=f.length*m+(f.length?4:0),_=Math.max(o,p)/2,v=u?-u/2:0,y=(u?u/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(Ht(l),e.labelOff):rn(l,x,e,t),C=x(S);h={text:e.e.label??``,caption:c,...C,anchor:S,pill:{w:o,h:u},lineHeight:s,captionLineHeight:m,rotate:b}}let g=[],_=an(i.width),v=sn(a,`end`),y=sn(a,`start`);return e.headKind!==`none`&&(!d||p)&&(g.push({at:s,angle:Math.atan2(v.y,v.x),kind:e.headKind}),cn(a,`end`,on(e.headKind,_,i.width))),e.tailKind!==`none`&&(!u||f)&&(g.push({at:o,angle:Math.atan2(y.y,y.x),kind:e.tailKind}),cn(a,`start`,on(e.tailKind,_,i.width))),{key:e.e.key,decl:e.e,d:Wt(a),samples:m,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:h,heads:g,style:i}}function hn(e,t,n,r){let{a:i,b:a,style:o}=e,s=jn[e.sides[0]],c=jn[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let o=e.via.map(e=>({...e}));return o[0].y=n.y,o[o.length-1].y=r.y,{kind:`poly`,pts:Et(n,s,r,c,o,i,a,t.obstacles),radius:10}}return o.curve===`orthogonal`?{kind:`poly`,pts:Et(n,s,r,c,e.via,i,a,t.obstacles),radius:10}:o.curve===`straight`?{kind:`poly`,pts:[n,...e.via,r],radius:e.via.length?6:0}:{kind:`cubic`,segs:wt(n,s,r,c,e.via)}}function gn(e,t,n){if(e.kind===`poly`){t===`start`?e.pts.unshift(n):e.pts.push(n);return}let[r,i]=t===`start`?[n,e.segs[0][0]]:[e.segs[e.segs.length-1][3],n],a=Pt(i,r),o=[r,Nt(r,a,1/3),Nt(r,a,2/3),i];t===`start`?e.segs.unshift(o):e.segs.push(o)}var _n=new Map,vn=new Map,yn=[],bn=[];function xn(e,t,n,r,i,a=an(i)){let o=vn.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}var Sn=[],Cn=l({});function wn(e){if(!e)return`rounded`;let t=e.toLowerCase();return _n.has(t)?t:Cn[t]??`rounded`}function Tn(e,t){return{w:Math.max(e+44,96),h:Math.max(t+28,48)}}function En(e,t,n){return _n.get(e)?.size?.(t,n)??Tn(t,n)}function Dn(e){return _n.get(e)?.textOffset??0}function On(e,t,n){let r=_n.get(e);return r?r.path(t,n):An(t.x,t.y,t.w,t.h,Math.min(n,t.w/2,t.h/2))}function kn(e,t){return _n.get(e)?.detail?.(t)??null}function An(e,t,n,r,i){return i<=0?`M${F(e)},${F(t)}h${F(n)}v${F(r)}h${F(-n)}Z`:`M${F(e+i)},${F(t)}H${F(e+n-i)}A${F(i)},${F(i)} 0 0 1 ${F(e+n)},${F(t+i)}V${F(t+r-i)}A${F(i)},${F(i)} 0 0 1 ${F(e+n-i)},${F(t+r)}H${F(e+i)}A${F(i)},${F(i)} 0 0 1 ${F(e)},${F(t+r-i)}V${F(t+i)}A${F(i)},${F(i)} 0 0 1 ${F(e+i)},${F(t)}Z`}var jn={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function Mn(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 Nn(e,t,n,r){let i=_n.get(e);return i?.port?i.port(t,n,r):Mn(t,n,r)}var Pn=[`smooth`,`orthogonal`,`straight`],Fn=[`none`],In=[...jt,`auto`],Ln=[`below`,`above`,`right-of`,`left-of`,`rank`],Rn=[`text`,`font`,`font-size`,`font-weight`,`italic`],zn=[`shape`,`color`,`fill`,`stroke`,...Rn,`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`,...Ln,`align`,`merge`],Bn=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...Rn,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`,`merge`],Vn=[`color`,`fill`,`stroke`,...Rn,`border-style`,`dashed`,`dotted`,`meta`,`caps`,`align`,`merge`,`gap`,`padding`];[...Rn];var Hn={width:`the smallest width of the panel's frame, in pixels`,height:`the smallest height of the panel's frame, in pixels`,frame:"`false` drops the box",theme:`a theme name`,border:"`none`, a palette name or any CSS colour"},Un=l({shape:[...Sn,...Object.keys(Cn)],"border-style":ie,style:ie,curve:Pn,head:Fn,tail:Fn,exit:In,"from-side":In,enter:In,"to-side":In,merge:[`none`,`in`,`out`,`both`]}),Wn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],Gn=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!ye(e),Kn=e=>$n(e,f)||`: use a palette name (${f.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`,qn=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`],Jn=1e5,Yn=e=>Number.isFinite(e)&&Math.abs(e)<=1e5,Xn=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`,`gap`];function Zn(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 Qn(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=Zn(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function $n(e,t){let[n,r]=Qn(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function er(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let c=a?.[o]??r;if(!t.includes(o)){n===`node`&&Bn.includes(o)?i(c,`"${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}]`):o===`label`||o===`name`||o===`title`?i(c,`"${o}" is not a prop. A label follows the id in quotes: id "${s}"; an edge label follows a colon: a -> b: ${s}`):i(c,`Unknown ${n} prop "${o}"${$n(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let l=Un[o],u=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(Wn.includes(o)&&Gn(s))i(c,`Unknown ${o} "${s}"${Kn(s)}`);else if(l&&!l.includes(u)){let e=o===`shape`?Sn:l;i(c,`Unknown ${o} "${s}"${$n(s,l)||` (use one of: ${e.join(`, `)})`}`)}else if(qn.includes(o)&&![`true`,`false`].includes(s))i(c,`${o} expects true or false, got "${s}"`);else if(Xn.includes(o)){let t=parseFloat(s);t>=0&&Number.isFinite(t)?t>1e5&&(i(c,`${o} is at most ${Jn}, got "${s}"`),e[o]=String(Jn)):i(c,`${o} expects a number of 0 or more, got "${s}"`)}else o===`padding`&&!ct(s)?i(c,`padding expects 1 to 4 numbers of 0 or more, like CSS (top right bottom left), got "${s}"`):o===`link`&&!Se(s)&&i(c,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function tr(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`?ye(a)||r(n,`Unknown ${i} "${a}"${$n(a,f)||`: 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}"${$n(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}var nr=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function rr(e){for(let[t,n]of Object.entries(e))if(Ln.includes(t)&&n)return[t,n.trim()]}function ir(e,t){let n=t=>e.nodes.has(t)||e.groups.has(t);for(let{decl:r,group:i,value:a,rest:o}of St(e)){let s=r.ref&&nr(r,`align`),[c]=o;s!==void 0&&(o.length>1?t(s,`align takes one id: align: ${yt} id`):c?c===r.id?t(s,`align: ${c} lines ${r.id} up with itself; use another id`):n(c)||t(s,`align: unknown node or group "${c}"${$n(c,[...e.nodes.keys(),...e.groups.keys()])}`):i||t(s,`align: ${a} needs an id to line up with: align: ${a} other`))}}function ar(e,t){let n=new Map;for(let r of e.nodes.values()){let i=st(e,r),a=rr(i);if(!a)continue;let[o,s]=a,c=nr(r,o);for(let e of Object.keys(i))e!==o&&Ln.includes(e)&&r.ref&&t(nr(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}"${$n(s,[...e.nodes.keys()])}`)}}let r=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=rr(st(e,s))[0];s.ref&&t(nr(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}var or=e=>e.toLowerCase().replace(/\d+/g,`#`);function sr(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:or(e.id)}));if(!r.length||n.every(e=>!e.implicit||e.id.length<3))return;let i=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=or(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]=Qn(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 cr(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&&er(t.props,zn,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});ar(e,n),ir(e,n);let r=new Set;for(let t of e.edges){if(!t.ref)continue;let e=t.ref.line;r.has(e)||(r.add(e),er(t.props,Bn,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&er(t.props,Vn,`group`,t.ref.line,n,t.ref.propLines);sr(e,n);let i=ge(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}"${$n(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of Wn)a[t]&&Gn(a[t])&&n(e,`Unknown ${t} "${a[t]}"${Kn(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!ye(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!ie.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${ie.join(`, `)})`),tr(a,t?.(r.kind),e,n)}let a=[...new Set([...zn,...Bn,...Vn])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&er(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}var lr=[`group`,`import`,`export`,`layout`,`def`,`theme`],ur=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`,`merge`]),dr=[...ur],fr=l({direction:[`right`,`down`,`left`,`up`],curve:Un.curve,panels:[`row`,`column`,`grid`,`wrap`],merge:Un.merge}),pr=l({direction:"which way the flow runs: `right`, `down`, `left` or `up`",curve:"how edges bend: `smooth`, `orthogonal` or `straight`",gap:"space between nodes in the same rank, px. A group's `gap` overrides it for its members","rank-gap":"space between ranks, px: between columns in `right`/`left`, between rows in `down`/`up`. Default 72, or 96 with groups. A group's `gap` overrides it where only the group's own edges cross",padding:"space around the whole diagram, px. A group's `padding` is the space inside its border","max-width":`fit the diagram into this width, px: ranks wrap into rows`,wrap:`wrap node labels wider than this, px`,merge:"edges that share a node and side join into one line there. A node's, group's or edge's `merge` overrides it",panels:"how panels line up next to the graph: `row`, `column`, `grid` or `wrap`","panel-gap":`space between the graph and the panels, px`}),mr=l({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),hr=new Set(fr.curve),gr=new Map,_r=new Map,vr=[];function yr(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function br(e){let t=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}}}var V={plugins:[],rows:[],frames:new Map,decorations:[],panels:gr},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=>An(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 a={...n};for(let[o,s]of Object.entries(r)){let r=a[o];typeof r==`function`&&(a[o]=i(e,t(o),r.bind(n),s))}return a}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:i(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)}}var Ar;function jr(){let e=[ur].map(e=>[e,[...e]]),t=[gr,_r,_n,vn,V.frames].map(e=>[e,[...e]]),n=[vr,yn,bn,zn,Bn,Vn,qn,Xn,C,Sn,V.rows,V.decorations].map(e=>[e,[...e]]),r=Object.entries(Un).map(([e,t])=>[e,t,[...t]]),i={...S},a={...Cn};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(Un))delete Un[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),Un[e]=t;for(let e of Object.keys(S))delete S[e];Object.assign(S,i);for(let e of Object.keys(Cn))delete Cn[e];Object.assign(Cn,a),s()}}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(V.plugins.some(e=>e.name===t.name))continue;V.plugins.push(t);let e=kr(t),n=(e,n,r,i)=>{for(let a of n){let n=r(a);o(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(V.rows,e,e=>e.kind===t)),n(`decoration`,e.decorations,e=>e.name,(e,t)=>{Mr(V.decorations,e,e=>e.name===t),ur.add(e.setting)}),n(`frame`,e.frames,e=>e.name,V.frames),n(`panel`,e.panels,e=>e.name,gr),n(`statement`,e.statements,e=>e.keyword,_r),n(`marker`,e.markers,e=>e.name,vn),n(`shape`,e.shapes,e=>e.name,(e,t)=>{_n.set(t,e),Sn.includes(t)||Sn.push(t);for(let n of e.aliases??[])Cn[n]=t}),Sr(Un.shape??=[],[...t.shapes?.map(e=>e.name)??[],...t.shapes?.flatMap(e=>e.aliases??[])??[]]),Cr(Un.head??=[],t.markers),Un.tail!==Un.head&&Cr(Un.tail??=[],t.markers);let{transform:r,afterLayout:i,postRender:a}=e.hooks;r&&vr.push(r),i&&yn.push(i),a&&bn.push(a);for(let e of t.settings??[])ur.add(e);Sr(zn,t.props?.node),Sr(Bn,t.props?.edge),Sr(Vn,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))Sr(Un[e]??=[],n);Sr(qn,t.bools),Sr(Xn,t.numbers)}V.frames.size&&Sr(Un.frame??=[],[...V.frames.keys()])}var 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)?g:e;return Lr.font=`${r} ${n}px ${a}`,Lr.measureText(t).width}}var zr=new Set([...f,`violet`]),Br=e=>_n.has(e)||e in Cn,Vr=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,Hr=/^(<)?(--|-|\.\.|==|=)(>)?/,Ur=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,Wr=/^(.*?)((?:\s+\.[\p{L}_][\p{L}\p{N}_-]*)*)\s*(\[[^\]]*\])?$/su,Gr=/^-?\d+(?:\.\d+)?/;function Kr(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
- `:t===`t`?` `:t)}function qr(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:Kr(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(Ur)){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(Vr)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Gr)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Hr)){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 Jr(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 Yr(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function Xr(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)`),{}):H(e.value)}var Zr=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function H(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(`:`),i=r>=0?r:/^[\w-]+\s*=/.test(n)?n.indexOf(`=`):-1;if(i<0){let e=n.toLowerCase();zr.has(e)?t.color=e:Br(e)?t.shape=e:hr.has(e)?t.curve=e:ye(n)?t.color=n:t[e]=`true`;continue}let a=Zr(n.slice(0,i)),o=n.slice(i+1).trim();/^(["']).*\1$/s.test(o)&&(o=Kr(o.slice(1,-1))),t[a]=o}return t}var Qr=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},$r=/(?<!\[)\[([^[\]]*)\]\s*$/;function ei(e,t){let n=e.match($r),r=n?H(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function ti(e,t,n){let r=Zr(t),[i,a]=ei(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=ii(a);return s?`${o} [${s}]`:o}var ni=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&ye(e.color)};function ri(e,t,n,r,i){let a=Zr(n),[o,s]=ei(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}=H(n),l=ii(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=ii(s);return u?`${l} [${u}]`:l}function ii(e){return Object.entries(e).map(([e,t])=>t===`true`&&!zr.has(e)&&!Br(e)&&!hr.has(e)&&!ye(e)?e:e===`color`&&ye(t)&&!Br(t)&&!hr.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${ai(t)}`).join(`, `)}function ai(e){return/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(e)?si(e):e}function oi(e){let t=e.match(Hr),n=!!t[1],r=!!t[3],i=t[2],a;return a=i.startsWith(`=`)?`thick`:i===`..`?`dotted`:i===`--`&&(n||r)?`dashed`:`solid`,{start:n,end:r,line:a}}var si=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,ci=e=>/^(["']).*\1$/s.test(e.trim())?Kr(e.trim().slice(1,-1)):e.trim(),li=(e,t)=>({w:e+44,h:t+28}),ui=(e,t,n)=>Mn(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*Math.sqrt(Math.max(0,1-n*n))),di=({x:e,y:t,w:n,h:r})=>{let i=n/2,a=r/2;return`M${F(e+i-i)},${F(t+a)}a${F(i)},${F(a)} 0 1,0 ${F(i*2)},0a${F(i)},${F(a)} 0 1,0 ${F(-i*2)},0Z`},fi=(e,t)=>Math.min(t,e.w/2,e.h/2),pi={name:`shapes`,shapes:[{name:`rounded`,aliases:[`round`],path:(e,t)=>An(e.x,e.y,e.w,e.h,fi(e,t))},{name:`box`,aliases:[`rect`,`rectangle`,`square`],path:(e,t)=>An(e.x,e.y,e.w,e.h,Math.min(fi(e,t),3))},{name:`pill`,aliases:[`stadium`,`capsule`],size:(e,t)=>{let{w:n,h:r}=li(e,t);return{w:Math.max(n+8,96),h:Math.max(r,44)}},path:e=>An(e.x,e.y,e.w,e.h,e.h/2),port:(e,t,n)=>Mn(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:di,port:ui},{name:`ellipse`,aliases:[`oval`],size:(e,t)=>({w:Math.max((e+16)*1.42,90),h:Math.max((t+12)*1.42,50)}),path:di,port:ui},{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${F(e+n/2)},${F(t)}L${F(e+n)},${F(t+r/2)}L${F(e+n/2)},${F(t+r)}L${F(e)},${F(t+r/2)}Z`,port:(e,t,n)=>Mn(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}=li(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${F(e+i)},${F(t)}L${F(e+n-i)},${F(t)}L${F(e+n)},${F(t+r/2)}L${F(e+n-i)},${F(t+r)}L${F(e+i)},${F(t+r)}L${F(e)},${F(t+r/2)}Z`},port:(e,t,n)=>Mn(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}=li(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${F(e)},${F(t+i)}a${F(a)},${F(i)} 0 0,1 ${F(n)},0L${F(e+n)},${F(t+r-i)}a${F(a)},${F(i)} 0 0,1 ${F(-n)},0Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6);return`M${F(e)},${F(t+i)}a${F(n/2)},${F(i)} 0 0,0 ${F(n)},0`},port:(e,t,n)=>Mn(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}=li(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${F(e+i)},${F(t)}L${F(e+n)},${F(t)}L${F(e+n-i)},${F(t+r)}L${F(e)},${F(t+r)}Z`}},{name:`document`,aliases:[`doc`],textOffset:-4,size:(e,t)=>{let{w:n,h:r}=li(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=fi(e,t),s=Math.min(8,a/6);return`M${F(n+o)},${F(r)}L${F(n+i-o)},${F(r)}Q${F(n+i)},${F(r)} ${F(n+i)},${F(r+o)}L${F(n+i)},${F(r+a-s)}C${F(n+i*.75)},${F(r+a-s*3)} ${F(n+i*.25)},${F(r+a+s)} ${F(n)},${F(r+a-s)}L${F(n)},${F(r+o)}Q${F(n)},${F(r)} ${F(n+o)},${F(r)}Z`}},{name:`note`,aliases:[`sticky`],size:(e,t)=>{let{w:n,h:r}=li(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${F(e)},${F(t)}L${F(e+n-i)},${F(t)}L${F(e+n)},${F(t+i)}L${F(e+n)},${F(t+r)}L${F(e)},${F(t+r)}Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${F(e+n-i)},${F(t)}L${F(e+n-i)},${F(t+i)}L${F(e+n)},${F(t+i)}`}},{name:`text`,aliases:[`label`,`plain`,`none`],size:(e,t)=>({w:e+12,h:t+8}),path:(e,t)=>An(e.x,e.y,e.w,e.h,fi(e,t))}]},mi=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return(t,i)=>`${F(e.x+t*n-i*r)},${F(e.y+t*r+i*n)}`},hi={name:`markers`,markers:[{name:`arrow`,inset:e=>e*.8,render(e,t,{color:n,width:r,size:i}){let a=mi(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="${F(r*.5)}" stroke-linejoin="round"/>`}},{name:`open`,inset:(e,t)=>t*.8,render(e,t,{color:n,width:r,size:i}){let a=mi(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="${F(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]=mi(e,t)(-i,0).split(`,`);return`<circle cx="${a}" cy="${o}" r="${F(i)}" fill="${n}"/>`}},{name:`diamond`,inset:e=>e*1.6,render(e,t,{color:n,size:r}){let i=mi(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=mi(e,t);return`<path d="M${a(-4,i*.6)}L${a(-4,-i*.6)}" stroke="${n}" stroke-width="${F(r*1.2)}" stroke-linecap="round"/>`}}]},gi={name:`themes`,themes:[me(`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:g,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=>u[e]&&{fill:`#0f3460`,stroke:m(e,300),text:m(e,100)},groupTone:e=>u[e]&&{fill:`none`,stroke:m(e,400),text:m(e,200)},edgeTone:e=>m(e,300)},{name:`mono`,dark:!1,background:`#ffffff`,font:h,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=>u[e]&&{fill:m(e,100),stroke:`#18181b`,text:`#18181b`},groupTone:e=>u[e]&&{fill:m(e,50),stroke:`#a1a1aa`,text:`#52525b`},edgeTone:e=>m(e,700)},{name:`pastel`,dark:!1,background:`#fdfcff`,font:h,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=>u[e]&&{fill:m(e,100),stroke:m(e,100),text:m(e,900)},groupTone:e=>u[e]&&{fill:m(e,50),stroke:m(e,50),text:m(e,700)},edgeTone:e=>m(e,300)},{name:`terminal`,dark:!0,background:`#0c0c10`,font:g,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=>u[e]&&{fill:m(e,950),stroke:m(e,700),text:m(e,200)},groupTone:e=>u[e]&&{fill:m(e,950)+`66`,stroke:m(e,900),text:m(e,300)},edgeTone:e=>m(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=>u[e]&&{fill:m(e,100),stroke:m(e,400),text:m(e,900)},groupTone:e=>u[e]&&{fill:m(e,100)+`99`,stroke:m(e,300),text:m(e,800)},edgeTone:e=>m(e,600)},me(`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:h,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=>u[e]&&{fill:m(e,100),stroke:m(e,800),text:m(e,950)},groupTone:e=>u[e]&&{fill:m(e,50),stroke:m(e,800),text:m(e,900)},edgeTone:e=>m(e,700)},me(`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)`}),me(`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:h,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=>u[e]&&{fill:m(e,900)+`cc`,stroke:m(e,500),text:m(e,100)},groupTone:e=>u[e]&&{fill:m(e,950)+`80`,stroke:m(e,900),text:m(e,300)},edgeTone:e=>m(e,300)}]},_i=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function vi(e){let t=1/0,n=-1/0;for(let r of e)r<t&&(t=r),r>n&&(n=r);return[t,n]}var yi=(e,t)=>I(e,t.theme,t.theme.accent),bi=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${be}))?:\\s*(.*)$`)),xi={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=bi(`bars`,e);return t?{kind:`bars`,values:_i(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(vi(e.values)[1],0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=yi(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${F(t.x+n*r*.85)}" y="${F(a-c)}" width="${F(r*.55)}" height="${F(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},Si={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=bi(`spark`,e);return t?{kind:`spark`,values:_i(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]=vi(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`}${F(e)},${F(t)}`).join(``),p=yi(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${F(t.x+t.w)},${F(l)}L${F(t.x)},${F(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="${F(m)}" cy="${F(h)}" r="2.6" fill="${p}"/>`}},Ci={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=bi(`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:N(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:N(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:L(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=yi(e.color,n);return Xe(e.label,t.x,s,r,a,o)+Ge(t.x+t.w,s,r,a.sub,P(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${F(t.x)}" y="${F(c)}" width="${F(t.w)}" height="${F(l)}" rx="${F(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${F(t.x)}" y="${F(c)}" width="${F(Math.max(l,t.w*e.ratio))}" height="${F(l)}" rx="${F(l/2)}" fill="${u}"/>`:``)}},wi=1.75,Ti={name:`charts`,rows:[xi,Si,Ci,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=bi(`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:N(t),label:N(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*wi;return e.ws=e.items.map(e=>Math.max(L(e.value,i,n,r,700),L(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*wi,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:yi(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${F(e)},${F(t.y+r*.3)}V${F(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(Xe(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(Xe(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},Ei=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function Di(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}var Oi=e=>e*1.8,ki={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=Di(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(N);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=>!He(e[t])||Ei.test(He(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=>L(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+Oi(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]-Je(t):d;o.push(Xe(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+Oi(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${F(t.x)},${F(e)}H${F(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},Ai=[`#ff5f57`,`#febc2e`,`#28c840`],ji=e=>Math.round(e*2.3);function Mi(e,t,n,r,i){let a=ji(t),o=Math.min(n,a/2,e.w/2),s=`M${F(e.x)},${F(e.y+a)}V${F(e.y+o)}A${F(o)},${F(o)} 0 0 1 ${F(e.x+o)},${F(e.y)}H${F(e.x+e.w-o)}A${F(o)},${F(o)} 0 0 1 ${F(e.x+e.w)},${F(e.y+o)}V${F(e.y+a)}Z`,c=t*.3,l=Ai.map((n,r)=>`<circle cx="${F(e.x+t+r*c*3.3)}" cy="${F(e.y+a/2)}" r="${F(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${F(e.x)},${F(e.y+a)}H${F(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}var Ni=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,Pi={name:`browser`,inset:e=>({top:ji(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=ji(a),s=Ni(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="${F(s)}" y="${F(u)}" width="${F(c-s)}" height="${F(l)}" rx="${F(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?Ge(s+a*.7,e.y+o/2,d,n.sub,P(r)):``):``;return`<g class="frame">${Mi(e,a,i,n.stroke,t.dark)}${f}</g>`}},Fi=(e,t)=>({name:e,inset:e=>({top:ji(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=ji(o),c=i?Ge(e.x+e.w/2,e.y+s/2,o*.78,r.sub,P(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${Mi(e,o,a,r.stroke,n.dark)}${c}</g>`}}),Ii={name:`frames`,frames:[Pi,Fi(`window`,``),Fi(`terminal`,`❯ `)],props:{node:[`frame`]}},Li=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),Ri=new Map,zi=(e,t,n)=>`${t}|${n}|${e}`;function Bi(e,t,n,r){return e.map(e=>L(N(e),t,n,r))}var Vi={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=Li(e);if(!r.length)return null;let i=t.fontSize*.82,a=Bi(r,i,t.mono,n);Ri.size>64&&Ri.clear(),Ri.set(zi(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=Li(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=Ce(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${F(c)},${F(t.y)}H${F(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=Ri.get(zi(e,a,n.mono))??Bi(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="${F(m)}" y="${F(o)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(N(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},Hi=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function Ui(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return Hi.test(t)?{kind:`arrow`,key:t,label:r}:t.startsWith(`.`)?{kind:`class`,key:t.slice(1),label:r||t.slice(1)}:{kind:`color`,key:t,label:r||t}})}var Wi=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 Gi(e,t,n){let{fs:r,sw:i,gap:a}=Wi(t);return e.map(e=>i+a+L(N(e.label),r,t.mono,n))}function Ki(e,t,n,r,i){let{sw:a,sh:o}=Wi(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="${F(o*3)} ${F(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${F(o)} ${F(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${F(t)},${F(n)}H${F(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${F(o)}"${s} fill="none"/>`+(c?`<path d="M${F(u)},${F(n)}L${F(u-l)},${F(n-l*.5)}L${F(u-l)},${F(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${F(t)},${F(n)}L${F(t+l)},${F(n-l*.5)}L${F(t+l)},${F(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=st(i,t),a=ft(i,t,n,r),o=wn(n.shape??i.settings.shape);return`<path d="${On(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??M(e.key,r,400)??r.node.fill,u=c?.stroke??M(e.key,r,600)??r.node.stroke;return`<rect x="${F(s.x)}" y="${F(s.y)}" width="${F(s.w)}" height="${F(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function qi(e,t,n){let r=[[]],i=0;return e.forEach((e,a)=>{let o=r[r.length-1];o.length&&i+n+e>t?(r.push([a]),i=e):(o.push(a),i+=(o.length>1?n:0)+e)}),r}var Ji=760,Yi={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=Ui(e);if(!n.length)return null;let{fs:r,space:i}=Wi(t),a=Gi(n,t,Ir),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=qi(a,Ji,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,Ji)}},render(e,t,n,{pad:r,d:i}){let a=Ui(e),{fs:o,gap:s,space:c,sw:l}=Wi(n),u=Gi(a,n,Ir),d=Ce(n),f=[];return qi(u,Math.min(Ji,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(Ki(e,m,h,n,i)),e.label&&f.push(`<text x="${F(m+l+s)}" y="${F(h)}" dominant-baseline="central" font-size="${F(o)}" xml:space="preserve">${R(N(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},Xi=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,Zi=/^(?:m|note|d)\d+$/,Qi=new RegExp(String.raw`^(${Xi})\s*(-->|->|\.\.>|=>)\s*(${Xi})\s*(?::\s*(.*))?$`,`u`),$i=new RegExp(String.raw`^(${Xi}\s*(?:-->|->|\.\.>|=>)\s*${Xi})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),ea=String.raw`${Xi}(?:\s+"[^"]*")?(?:\s*\[[^\]]*\])?`,ta=new RegExp(String.raw`^(participant|actor)\s+(${ea}(?:\s*,\s*${ea})*)$`,`u`),na=new RegExp(String.raw`(${Xi})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?`,`gu`),ra=new RegExp(String.raw`^note\s+(${Xi}(?:\s*,\s*${Xi})*)\s*:\s*(.*)$`,`u`),ia=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,aa=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],oa=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>aa.includes(e))&&(!e.color||ye(e.color))},sa=e=>ei(e,oa),ca={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function la(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(ta)){let e=[...c[2].matchAll(na)];for(let[,t,n,r]of e){let i=o(t);i.actor=c[1]===`actor`,e.length===1?i.decl=a:i.list??=a,n!==void 0&&(i.label=n);let s=r&&H(r).color;s&&(i.tone=s)}}else if(c=r.match(ra)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=sa(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(Qi)){o(c[1]),o(c[3]);let[e,t]=sa(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:ca[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(ia))?i.push({kind:`divider`,text:c[1]}):(c=r.match($i))?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(!Zi.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 ua(e){let t={note:0,divider:0};return e.steps.map(e=>e.kind===`msg`?`m${e.n}`:e.kind===`note`?`note${++t.note}`:`d${++t.divider}`)}var da=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=>L(N(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=ua(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 fa(e,t){let n=dt(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function pa(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=da(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=Ce(r),d=n.props,f=M(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=fa(Qe(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${F(c(t))},${F(h+o)}V${F(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="${F(c(a)-l/2)}" y="${F(t)}" width="${F(l)}" height="${F(o)}" rx="${F(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${F(r.strokeWidth)}"/><text x="${F(c(a))}" y="${F(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${F(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${P(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=Qe(n,`style`)??(o.line===`thick`?`solid`:o.line),d=Ze(n.width,o.line===`thick`||j(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=fa(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=N(i.num(o)+o.text),g=I(o.tone,r,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${F(t)},${F(n)}H${F(t+26-8)}Q${F(t+26)},${F(n)} ${F(t+26)},${F(n+8)}V${F(i-8)}Q${F(t+26)},${F(i)} ${F(t+26-8)},${F(i)}H${F(t+2)}" fill="none" stroke="${g}" stroke-width="${F(d)}"${f}/>`),m.push(xn({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${F(t+34)}" y="${F((n+i)/2)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${F(c(e))},${F(s)}H${F(c(t)-n*2)}" stroke="${g}" stroke-width="${F(d)}"${f}/>`),m.push(xn({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="${F((c(e)+c(t))/2)}" y="${F(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" xml:space="preserve">${R(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="${F(l)}" y="${F(p)}" width="${F(u-l)}" height="${F(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${F((l+u)/2)}" y="${F(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" xml:space="preserve">${R(N(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${F(t.x)},${F(n)}H${F(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${F(c-s/2)}" y="${F(n-a*.85)}" width="${F(s)}" height="${F(a*1.7)}" rx="${F(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${F(c)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.92)}" font-weight="600" fill="${r.node.sub}">${P(o.text)}</text>`))}v+=e}return m.join(``)}function ma(e,t,n){if(!e.parts.length)return[];let r=da(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}var ha={name:`sequence`,panels:[{name:`sequence`,guide:'`participant|actor id "Label" [color]` (`participant a "A", b, c` lists several and 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:la,measure(e,t){let n=da(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:pa,handles:ma,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=ua(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]=ti(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${ii({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=ua(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=sa(e[s.at]),u=c;delete l.color;let d=ii(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})}]},ga=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],_a=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function va(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}var ya=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,ba=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function xa(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]=ei(i,ni),c=o.match(ya);c?r.push({when:c[1].trim(),tone:s.color??H(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function Sa(e){let t=new Set;return e.map((e,n)=>{let r=!/\s/.test(e.when)&&!t.has(e.when)&&!/^e\d+$/.test(e.when)?e.when:`e${n+1}`;return t.add(r),r})}function Ca(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#|[-*]\s)/.test(r)&&ya.test(ei(r,ni)[0])&&t.push(n)}),t}var wa=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)=>L(N(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>va(e.details.map(e=>s(e,a*.92)),s(e.title,a,600))),u=e.map(e=>1+e.details.length),d=Sa(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=va(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+va(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+va(u,1)*a*1.45}});function Ta(e,t,n){if(!e.length)return``;let r=n.theme,i=wa(e,n),{fs:a}=i,o=Ce(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=I(n.tone,r,r.accent);return`<circle cx="${F(e)}" cy="${F(t)}" r="${F(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${F(e)}" cy="${F(t)}" r="${F(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${F(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${R(N(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${F(n)},${F(t.y+a*.5)}V${F(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="${F(n-16)}" y="${F(s)}" dominant-baseline="central" text-anchor="end" font-size="${F(a*.9)}" font-weight="600" fill="${I(e.tone,r,r.node.sub)}">${P(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${F(t.x)},${F(d)}H${F(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="${F(o)}" y="${F(t.y+a*.5)}" dominant-baseline="central" font-size="${F(a*.9)}" font-weight="600" fill="${I(e.tone,r,r.node.sub)}">${P(e.when)}</text>`),c.push(l(o+a*.42,d,e)),c.push(u(o,d+a*1.55,e.title,a,600,`start`,!1)),e.details.forEach((e,t)=>c.push(u(o,d+a*1.55+(t+1)*a*1.45,e,a*.92,400,`start`,!0)))}),c.join(``)}var Ea={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:xa,measure(e,t){if(!e.length)return{w:0,h:0};let n=wa(e,t);return{w:n.w,h:n.h}},render:Ta,parts:e=>Sa(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=Ca(e)[Sa(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=ri(e[i],ba,`color`,n,ni),a}),handles(e,t,n){if(!e.length)return[];let r=wa(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}`})}}]},Da=[`bar`,`column`,`line`,`pie`,`donut`],Oa=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,ka=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,Aa=1e300;function ja(e,t,n){let r=t.type??`bar`;Da.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${Da.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=ei(r,ni),s=a.match(Oa),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=Aa)?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??H(s[2]).color,value:c}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:Da.includes(r)?r:`bar`,items:i}}var Ma=(e,t=``)=>`${Math.abs(e)<1e15?Math.round(e*100)/100:e}${t}`;function Na(e,t,n,r){return e.tone?I(e.tone,n.theme,n.theme.accent):r?m(ga[t%ga.length],n.theme.dark?400:500):n.theme.accent}var Pa=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=va(e.items.map(e=>r(e.label,a,400,n.mono)),0),c=va(e.items.map(e=>r(Ma(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 Fa(e,t,n,r,i,a){let o=(n,r)=>`${F(e+n*Math.sin(r))},${F(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return Fa(e,t,n,r,o,a)+Fa(e,t,n,o,i,a)}return a?`M${o(n,r)}A${F(n)},${F(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${F(a)},${F(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${F(e)},${F(t)}L${o(n,r)}A${F(n)},${F(n)} 0 ${s} 1 ${o(n,i)}Z`}function Ia(e,t,n){if(!e.items.length)return``;let r=n.theme,i=Pa(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${F(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${P(n)}</text>`,l=va(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="${Fa(l,u,i.r,p,a,d)}" fill="${Na(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,Ma(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="${F(m)}" y="${F(g-a*.45)}" width="${F(a*.9)}" height="${F(a*.9)}" rx="2.5" fill="${Na(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,Ma(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="${F(u)}" y="${F(p-a*.55)}" width="${F(d)}" height="${F(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${F(u)}" y="${F(p-a*.55)}" width="${F(m)}" height="${F(a*1.1)}" rx="3" fill="${Na(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,Ma(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${F(t.x)},${F(n)}H${F(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="${F(d(i)-t/2)}" y="${F(l)}" width="${F(t)}" height="${F(Math.max(2,u-l))}" rx="3" fill="${Na(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,Ma(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${F(d(t))},${F(f(e.value))}`);s.push(`<path d="M${F(d(0))},${F(u)}L${t.join(`L`)}L${F(d(e.items.length-1))},${F(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=Na(e,t,n,!1);s.push(`<circle cx="${F(d(t))}" cy="${F(f(e.value))}" r="${F(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,Ma(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${F(t.x)},${F(u)}H${F(t.x+t.w)}" stroke="${r.node.stroke}" stroke-width="1"/>`),e.items.forEach((e,t)=>s.push(c(d(t),u+a*1.1,e.label,`middle`,r.node.sub))),s.join(``)}var La={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:ja,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=Pa(e,t);return{w:n.w,h:n.h}},render:Ia,options:{type:[...Da],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)&&Oa.test(ei(n,ni)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=ri(e[i],ka,`color`,n,ni),a}),handles(e,t,n){if(!e.items.length)return[];let r=Pa(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},Ra=[`normal`,`highlight`,`reverse`],za=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,Ba=String.raw`(?:\s*\[([^\]]*)\])?`,Va=new RegExp(String.raw`^commit(?:\s+(.*?))?${Ba}$`,`u`),Ha=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${za})(?:\s+from\s+(\S+))?${Ba}$`,`u`),Ua=new RegExp(String.raw`^(?:checkout|switch)\s+(${za})$`,`u`),Wa=new RegExp(String.raw`^merge\s+(${za})(?:\s+(.*?))?${Ba}$`,`u`),Ga=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${Ba}$`,`u`),Ka=/^tag\s+(\S+)$/;function qa(e){let t=H(e??``);for(let e of Ra)t[e]===`true`&&(t.type=e,delete t[e]);return t}function Ja(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&&!Ra.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${Ra.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(Ha)){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=qa(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(Ua)){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(Wa)){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:ci(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},qa(u[3]),t)}else if(u=l.match(Ga)){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:ci(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},qa(u[3]),t)}else(u=l.match(Ka))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(Va))?c({msg:ci(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},qa(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function Ya(e,t,n){let r=e.branches[t]?.tone;return r?I(r,n.theme,n.theme.accent):m(ga[t%ga.length],n.theme.dark?400:500)}function Xa(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})}var Za=br(Qa);function Qa(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=Xa(e),l=e=>s[e]?.x??0,u=e=>L(N(e),a,n.mono,r),d=e=>r(e,a*.82,600,n.mono)+a*1.1,f=a*.5,p=e=>(e.order??e.lane)-(e.order===void 0?0:.5),m=new Set(e.commits.map(e=>e.lane)),h=e.branches.filter(e=>m.has(e.lane)).sort((e,t)=>p(e)-p(t)),g=new Map(h.map((e,t)=>[e.lane,t])),_=o?a*1.7:a*4,v=[];h.forEach((e,t)=>{let n=Math.max(t?f*3-_:0,l(e.name));v.push((t?v[t-1]+_:0)+n)});let y=v[v.length-1]??0,b=o?e.commits.map(()=>a*2.1):e.commits.map(e=>Math.max(a*2.6,u(e.msg)+a*2,...e.tags.map(e=>d(e)+a*.6))),x=o?0:Math.max(0,...h.map(e=>r(e.label??e.name,a,600,n.mono)))+a*1.4,S=[];b.forEach((e,t)=>{let n=t?S[t-1]+b[t-1]/2:x,r=Math.max(f*3-(t?b[t-1]/2:0)-e/2,l(c[t]));S.push(n+e/2+r)});let C=e.commits.length?S[S.length-1]+b[b.length-1]/2:0,w={fs:a,r:f,vertical:o,parts:c,off:s,used:h,slot:g,pillW:d,textW:u,spans:b,at:S,gap:e=>(S[e-1]+b[e-1]/2+S[e]-b[e]/2)/2,lanePos:v};if(o){let t=_,n=y+t+a*.6,i=new Map;for(let e of h)i.set(e.head,[...i.get(e.head)??[],e]);let o=e.commits.map((e,t)=>{let n=[...(i.get(t)??[]).map(e=>e.label??e.name),...e.tags].reduce((e,t)=>e+d(t)+a*.4,0);return(e.id?r(e.id,a,400,!0)+a*.6:0)+n+u(e.msg)}),s=e.commits.map((e,n)=>({x:t/2+v[g.get(e.lane)??0],y:S[n]}));return{...w,laneW:t,textX:n,heads:i,labelW:x,top:0,pos:s,w:n+Math.max(0,...o),h:C}}let T=Math.max(0,...e.commits.filter(e=>g.get(e.lane)===0).map(e=>e.tags.length)),E=a*.6+T*a*1.5,D=e.commits.map((e,t)=>({x:S[t],y:E+v[g.get(e.lane)??0]}));return{...w,laneW:0,textX:0,heads:new Map,labelW:x,top:E,pos:D,w:C,h:E+y+a*2}}var $a=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function eo(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${F(h.x)},${F(h.y)}L${F(g.x)},${F(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=$a((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${F(h.x)},${F(h.y)}V${F(t-e)}C${F(h.x)},${F(t)} ${F(g.x)},${F(t)} ${F(g.x)},${F(t+e)}V${F(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=$a((m?g.x-b(f,!y)-r*.7:h.x+b(p,y)+r*.7)+v,h.x+x,g.x-x);d.push({i:f,k:m,part:_,handle:{x:S,y:(h.y+g.y)/2},d:`M${F(h.x)},${F(h.y)}H${F(S-x)}C${F(S)},${F(h.y)} ${F(S)},${F(g.y)} ${F(S+x)},${F(g.y)}H${F(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${F(i.x)},${F(i.y)}Q${F(e)},${F(n)} ${F(c.x)},${F(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${F(i.x)},${F(i.y)}C${F(p)},${F(i.y+u.y)} ${F(p)},${F(c.y+u.y)} ${F(c.x)},${F(c.y)}`})}),{lanes:u,bends:d,picks:f}}function to(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=Za(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=Ce(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="${F(u)}" y="${F(t-d/2)}" width="${F(l)}" height="${F(d)}" rx="${F(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${F(u+l/2)}" y="${F(t)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.82)}" font-weight="600" fill="${o?s:r}">${P(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="${F(t.x)}" y="${F(o)}" dominant-baseline="central" font-size="${F(a)}" font-weight="600" fill="${Ya(e,r.lane,n)}">${P(r.label??r.name)}</text>`)}let f=Math.max(2,r.edgeWidth*1.4),p=eo(e,i,t),m=(t,r)=>Ya(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="${Ya(e,e.commits[t.i].lane,n)}" stroke-width="${F(f*.7)}" stroke-dasharray="${F(f*1.6)} ${F(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="${F(f)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((p,m)=>{let{x:h,y:_}=u[m],v=I(p.tone,r,Ya(e,p.lane,n));if(p.type===`highlight`){let e=o*1.1;l.push(`<rect x="${F(h-e)}" y="${F(_-e)}" width="${F(e*2)}" height="${F(e*2)}" rx="${F(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${F(f)}"/>`)}else if(p.type===`reverse`){let e=o*.55;l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}"/><path d="M${F(h-e)},${F(_-e)}L${F(h+e)},${F(_+e)}M${F(h+e)},${F(_-e)}L${F(h-e)},${F(_+e)}" stroke="${v}" stroke-width="${F(f*.8)}" stroke-linecap="round"/>`)}else p.merge?l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o*1.05)}" fill="${v}"/><circle cx="${F(h)}" cy="${F(_)}" r="${F(o*.4)}" fill="${s}"/>`):p.pick===void 0?l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}"/>`):l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}" stroke-dasharray="${F(f*1.2)} ${F(f)}"/>`);if(i.vertical){let o=t.x+i.textX;p.id&&(l.push(`<text x="${F(o)}" y="${F(_)}" dominant-baseline="central" font-size="${F(a)}" font-family="${P(g)}" fill="${r.node.sub}">${P(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,_,r,Ya(e,t.lane,n),!1,`start`)),o+=i.pillW(r)+a*.4}for(let e of p.tags)l.push(d(o,_,e,v,!0,`start`)),o+=i.pillW(e)+a*.4;p.msg&&l.push(`<text x="${F(o)}" y="${F(_)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(N(p.msg),c,r,p.merge)}</text>`)}else p.tags.forEach((e,t)=>l.push(d(h,_-a*1.45-t*a*1.5,e,v,!0,`middle`))),p.msg&&l.push(`<text x="${F(h)}" y="${F(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${R(N(p.msg),c,r,p.merge)}</text>`)}),l.join(``)}var no={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:Ja,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})),...Xa(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[Xa(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=ti(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=Za(e,t);return{w:n.w,h:n.h}},render:to,handles(e,t,n){if(!e.commits.length)return[];let r=Za(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=eo(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`}))]}}]},ro=[`box`,`pill`,`plain`,`circle`],io=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],ao=/^[-*+]\s+/,oo=e=>tt(e)!==void 0,so={color:ye,shape:()=>!0,text:ye,"font-size":oo,"font-weight":oo},co=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>so[t]?.(e[t]))},lo=e=>ei(e,co);function uo(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]=lo(o.replace(ao,``));l.shape&&!ro.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${ro.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:tt(l[`font-size`]),weight:tt(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 fo(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}var po=e=>e.reduce((e,t)=>Math.min(e,t),1/0),mo=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function ho(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return e.map((e,n)=>/^[\w-]+$/.test(e.text)&&t.get(e.text)===1&&!/^n\d+$/.test(e.text)?e.text:`n${n+1}`)}var go=[`both`,`vertical`,`right`,`left`,`down`,`up`],_o=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=tt(i[`font-size`])??t.fs*.9,o=go.includes(i.layout)?i.layout:`both`,s=o===`down`||o===`up`||o===`vertical`,c=i.colors===`mono`,l=fo(e),u=ho(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=new Map,p=(e,t,i,o)=>{let s=ro.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=L(N(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:io[n%io.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,_=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=po(D.map(e=>e.x)),k=po(D.map(e=>e.y));for(let e of D)e.x-=O,e.y-=k;return{all:D,vert:s,w:mo(D.map(e=>e.x+e.w)),h:mo(D.map(e=>e.y+e.h))}}),vo=(e,t)=>I(t,e,e.accent);function yo(e,t,n){if(!e)return``;let r=n.theme,i=_o(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=vo(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${F(s(n))},${F(c(r))}C${F(s(n))},${F(c((r+u)/2))} ${F(s(o))},${F(c((r+u)/2))} ${F(s(o))},${F(c(u))}`:`M${F(s(n))},${F(c(r))}C${F(s((n+o)/2))},${F(c(r))} ${F(s((n+o)/2))},${F(c(u))} ${F(s(o))},${F(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${F(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=M(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${F(m)},${F(h+e.h)}H${F(m+e.w)}" stroke="${t}" stroke-width="${F(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="${F(m)}" y="${F(h)}" width="${F(e.w)}" height="${F(e.h)}" rx="${F(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="${F(m+e.w/2)}" y="${F(g)}" dominant-baseline="central" text-anchor="middle" font-size="${F(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${R(N(e.node.text),Ce(r,p,f),r)}</text>`)}return a.join(``)+o.join(``)}var bo={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:go,colors:[`branches`,`mono`]},parse:uo,measure(e,t){if(!e)return{w:0,h:0};let n=_o(e,t);return{w:n.w,h:n.h}},render:yo,parts(e){if(!e)return[];let t=fo(e),n=new Map([[e,0]]);for(let e of t)for(let t of e.children)n.set(t,n.get(e)+1);return ho(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=fo(r),a=i[ho(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=lo(e[a.line]),u=ii(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=_o(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}}]},xo=864e5,So=864e13,Co=1e3,wo=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],To=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,Eo=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,Do=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function Oo(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=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 ko(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:xo,w:7*xo}[t[2].toLowerCase()]:NaN}function Ao(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s)return;let c=s.match(Do);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?H(t[2]).color:void 0);return}let[l,u]=ei(s),d=l.match(To);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={...H(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]??``,S=Oo(x);/^after\s/i.test(x)?(v.after=x.slice(6).trim().split(/\s+/),b=1):Number.isNaN(S)?x&&Number.isNaN(ko(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=S,b=1);let C=y[b];C===void 0?!_&&x&&n(t,`gantt: task "${f}" needs a length, e.g. "${x}, 3d"`):(v.len=ko(C),Number.isNaN(v.len)&&(v.endDate=Oo(C),Number.isNaN(v.endDate)&&n(t,`gantt: "${C}" is not a length (3h, 5d, 2w) or an end date`)));let w=g.progress===void 0?NaN:parseFloat(g.progress)/(g.progress.endsWith(`%`)?100:1);g.progress!==void 0&&!(w>=0&&w<=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,progress:Math.min(1,Math.max(0,w)),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+xo:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=So||(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 jo(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!Do.test(r)&&To.test(ei(r)[0])&&t.push(n)}),t}var Mo=e=>{let t=new Date(e);return`${wo[t.getUTCMonth()]} ${t.getUTCDate()}`},No=e=>{let t=e/xo;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 Po(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/xo)*xo;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=xo;for(;o<=t&&i.length<2e3&&Number.isFinite(new Date(o).getTime());o+=a*xo)i.push({t:o,label:Mo(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>=2e3)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${wo[c]} ${s}`:wo[c]}),l=!1,c+=a}return i}return i}function Fo(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`}var Io={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*(Io[i.density??``]??Io.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>L(N(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/xo)*xo,_=Math.max(g+xo,Math.ceil(e.max/xo)*xo),v=(_-g)/xo,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*Co/v),x=e=>h+(e-g)/xo*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?`${Mo(e.start)} – ${Mo(e.end)}`:e.milestone?Mo(e.start):No(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 Ro(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${F(n[0][0])},${F(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${F(u[0])},${F(u[1])}Q${F(a[0])},${F(a[1])} ${F(d[0])},${F(d[1])}`}let i=n[n.length-1];return`${r}L${F(i[0])},${F(i[1])}`}function zo(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=Ce(r),p=(e,t,n,i,a,s=!1)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${F(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${R(N(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${F(o*.82)}" font-weight="500" fill="${r}">${P(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/864e5<=3660)for(let e=a.min;e<a.max;e+=xo){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${F(c(e))}" y="${F(t.y+a.axisH*.8)}" width="${F(a.dayW)}" height="${F(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/xo)*xo:Oo(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${Mo(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 Po(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${F(s)},${F(t.y+a.axisH*.75)}V${F(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${F(p)}" y="${F(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${F(o*.82)}" fill="${r.node.sub}">${P(e.label)}</text>`)}d.push(`<path d="M${F(t.x+a.labelW)},${F(t.y+a.axisH*.75)}H${F(t.x+a.labelW+a.plotW)}" stroke="${u}" stroke-width="1.5"/>`);let x=new Map;for(let e of a.rows)e.task!==void 0&&x.set(e.task,e.y);let S=e=>t.y+x.get(e),C=e=>S(e)+a.rowH/2,w=t=>t.tone??e.sectionTones[t.section]??(t.crit?`red`:void 0),T=a.labelW+a.plotW;if(i.rows!==`plain`){let e=0;for(let n of a.rows)n.section===void 0?e++%2&&d.push(`<rect x="${F(t.x-o*.4)}" y="${F(t.y+n.y)}" width="${F(T+o*.4)}" height="${F(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=I(e.sectionTones[n.section],r,r.node.sub);d.push(`<path d="M${F(t.x)},${F(t.y+n.y+1)}H${F(t.x+T)}" stroke="${u}" stroke-width="1" opacity="0.6"/>`,p(t.x,s,e.sections[n.section],700,l));let f=e.tasks.filter(e=>e.section===n.section);if(f.length&&i.summary!==`hide`){let e=c(Math.min(...f.map(e=>e.start))),t=Math.max(e+2,c(Math.max(...f.map(e=>e.end)))),n=o*.32;d.push(`<path d="M${F(e)},${F(s+n*1.6)}V${F(s-n/2)}H${F(t)}V${F(s+n*1.6)}" fill="none" stroke="${l}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${F(e)}" y="${F(s-n/2)}" width="${F(t-e)}" height="${F(n)}" fill="${l}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${F(c(h))},${F(t.y+a.axisH*.35)}V${F(l)}" stroke="${I(`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${F(g)},${F(_)}C${F(g+e)},${F(_)} ${F(b-e)},${F(y)} ${F(b)},${F(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=Ro([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=Ro([[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="${F(l)}" stroke-linejoin="round"/>`,xn({x:v,y},0,`arrow`,s,l,u))}})}let E=i.bars===`solid`||i.bars===`outline`||i.bars===`thin`?i.bars:`soft`,D=new Map,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`?Fo(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=I(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${F(t)},${F(s-a.ms)}L${F(t+a.ms)},${F(s)}L${F(t)},${F(s+a.ms)}L${F(t-a.ms)},${F(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?I(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${F(v)}" y="${F(x)}" width="${F(e)}" height="${F(b)}" rx="${F(S)}" ${t}${h}/>`,ee=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,te=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,ne=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(k(y,`fill="${te}"${ne}${ee?` stroke="${T}" stroke-width="${ee}"`:``}`));let A=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;A&&d.push(k(A,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-A>2&&d.push(`<rect x="${F(v+A)}" y="${F(x)}" width="${F(y-A)}" height="${F(b)}" rx="${F(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+A-o*.2)?Fo(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=I(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${F(b)}" y="${F(n-o*.55)}" width="${F(v)}" height="${F(o*1.1)}" rx="${F(o*.55)}" fill="${e}"/>`,`<text x="${F(b+v/2)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(o*.72)}" font-weight="650" fill="${Fo(e)}">${P(_)}</text>`)}return d.join(``)}function Bo(e,t){if(!e.tasks.length)return{w:0,h:0};let n=Lo(e,t);return{w:n.w,h:n.h}}function Vo(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}`}])}var Ho={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:Ao,measure:Bo,render:zo,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=jo(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=ri(e[i],Eo,`color`,n),a}),handles:Vo}]},Uo=/^([xy])-axis\s*:?\s*(.*)$/i,Wo=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,Go=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,Ko=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,qo=[`teal`,`blue`,`slate`,`amber`];function Jo(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(Uo);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=ei(a,ni),l=s.match(Wo);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??H(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??H(u[2]).color,x:+u[3],y:+u[4],line:t})});let a=i.some(e=>e.x>1||e.y>1)?100:1;r.scale=a;let o=new Set;return i.forEach((e,t)=>{let i=e.x/a,s=e.y/a;(i<0||i>1||s<0||s>1)&&(n(e.line,`quadrant: "${e.name}" is outside the chart (values go from 0 to ${a})`),i=Math.min(1,Math.max(0,i)),s=Math.min(1,Math.max(0,s)));let c=_a(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 Yo(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]=ei(l,ni),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}var Xo=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=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=L(N(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=L(N(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 Zo(e,t,n){let r=n.theme,i=Xo(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],u=Ce(r),d=o/2,f=[[d,0],[0,0],[0,d],[d,d]];e.q.forEach((e,t)=>{let n=e.tone??qo[t],i=r.tone(n)?.fill??m(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${F(s+f[t][0])}" y="${F(c+f[t][1])}" width="${F(d)}" height="${F(d)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=I(e.tone??qo[t],r,r.node.sub);l.push(`<text x="${F(s+f[t][0]+d/2)}" y="${F(c+f[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" font-weight="700" xml:space="preserve">${R(N(e.text),{...u,text:n},r)}</text>`)}),l.push(`<rect x="${F(s)}" y="${F(c)}" width="${F(o)}" height="${F(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${F(s+d)},${F(c)}V${F(c+o)}M${F(s)},${F(c+d)}H${F(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let p=(e,t,n,i)=>n?`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${F(e)} ${F(t)})"`:``}>${P(n)}</text>`:``,h=c+o+i.bottom/2;l.push(p(s+d/2,h,e.x[0],!1),p(s+d*1.5,h,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=I(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],d=i.labels[t];l.push(`<circle cx="${F(s+a)}" cy="${F(c+o)}" r="${F(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${F(s+d.x)}" y="${F(c+d.y+d.h/2)}" dominant-baseline="central" font-size="${F(i.lfs)}" xml:space="preserve">${R(N(e.name),u,r)}</text>`)}),l.join(``)}var Qo={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:Jo,measure(e,t){let n=Xo(e,t);return{w:n.w,h:n.h}},render:Zo,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=>Wo.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]=ri(e[i],Ko,`color`,n,ni),o}),handles(e,t,n){let r=Xo(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)=>Yo(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`}]}}]},$o={high:`red`,medium:`amber`,low:`gray`};function es(e){let[t,n]=ei(e);return{text:t.trim(),props:n}}var ts=e=>e.match(/^\s*/)[0].length,ns=e=>!e.trim(),rs=/^[-*]\s+/;function is(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function as(e,t,n){let r=[],i=Math.min(...e.filter(e=>!ns(e)).map(ts)),a,o=0,s=0,c=-1,l=new Set,u=(e,t)=>{e&&e.end<0&&(e.end=t)};return e.forEach((e,t)=>{if(ns(e))return;let d=e.trim(),f=ts(e),p=c;if(c=t,rs.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}=es(d.replace(rs,``)),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`?($o[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:$o[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}=es(d),g=is(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=_a(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 os(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=ei(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=ii(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}var ss=[`owner`,`ticket`,`priority`];function cs(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]?ts(e[t.cards[0].start]):ts(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=as(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=ts(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,ts(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?ss:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&is(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=os(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=as(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]?ts(e[n[0].start]):0;return a.splice(n.length?n[n.length-1].end:e.length,0,` `.repeat(t)+`New column`),p(a,[n.length])}return i?(a.splice(i.end,0,d(i)+`- New card`),p(a,[r,-1])):null}}}var ls=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(L(N(e.text),i,n.mono,r,500),t,...e.details.map(e=>L(N(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 us(e,t,n){if(!e.length)return``;let r=n.theme,i=ls(e,n),{fs:a}=i,o=[],s=Ce(r),c=Math.min(r.radius,a*.6),l=I(`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="${F(d)}" y="${F(f)}" width="${F(i.colW)}" height="${F(i.h)}" rx="${F(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="${F(d+i.cpad+a*.35)}" cy="${F(h)}" r="${F(a*.32)}" fill="${I(e.tone,r,r.node.sub)}"/>`,`<text x="${F(d+i.cpad+a*1.05)}" y="${F(h)}" dominant-baseline="central" font-size="${F(a)}" font-weight="700" xml:space="preserve">${R(N(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="${F(v)}" y="${F(h-a*.6)}" width="${F(_)}" height="${F(a*1.2)}" rx="${F(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${F(v+_/2)}" y="${F(h)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${P(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="${F(l)}" y="${F(y)}" width="${F(f)}" height="${F(n.h)}" rx="${F(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${F(l)}" y="${F(y+c/2)}" width="3.5" height="${F(n.h-c)}" rx="1.75" fill="${I(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${F(l+i.pad)}" y="${F(m)}" dominant-baseline="central" font-size="${F(a)}" font-weight="500" xml:space="preserve">${R(N(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${F(l+i.pad)}" y="${F(m-a*.6)}" dominant-baseline="central" font-size="${F(a*.88)}" xml:space="preserve">${R(N(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="${F(t)}" y="${F(n-i.chipFs*.75)}" width="${F(e)}" height="${F(i.chipFs*1.5)}" rx="${F(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${F(t+e/2)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${P(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}var ds={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:as,measure(e,t){if(!e.length)return{w:0,h:0};let n=ls(e,t);return{w:n.w,h:n.h}},render:us,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:cs,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=ls(e,n);return e.slice(1).map((e,n)=>({part:e.id,x:t.x+r.at[n+1],y:t.y+r.headH/2,axis:`x`,title:`move ${e.title}`}))}}]};function fs(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=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}}}var ps={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},ms=Object.keys(ps),hs={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},gs=[`collapsed`,`highlight`,`dim`,`folder`,`file`,...ms],_s=[`color`,`icon`,`badge`,`note`,`size`,`status`],vs=e=>ms.find(t=>e[t]===`true`)??(ms.includes(e.status)?e.status:void 0);function ys(e){for(let t of ms)delete e[t];delete e.status}var bs=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],xs=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,Ss=/^[-*+]\s+/,Cs=/\s\[([^[\]]*)\]\s*$/,ws=/:\s|\s#\s|:$/,Ts=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,Es=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,Ds=/^(?:\.{3}|…)$/;function Os(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}var ks=e=>e.replace(/\/$/,``);function As(e,t){for(let n of Object.keys(e))!gs.includes(n)&&!_s.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[..._s.slice(1),...gs].join(`, `)})`);e.status&&!ms.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${ms.join(`, `)})`),e.color&&!xe(e.color)&&delete e.color}var js=100;function Ms(e,t,n){let r=[],i=[],a=[],o=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let s=e.trim().match(Es);if(s){let e=H(s[2]);As(e,e=>n(t,e));let r=s[1];a.push({re:fs(ks(r)),path:ks(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let c=e.match(xs)[0],l=e.slice(c.length),u=l.match(Ss);u&&(l=l.slice(u[0].length));let d=e.length-l.trimStart().length;if(l=l.trim(),!l||Ts.test(l))return;let f=(c+(u?.[0]??``)).replace(/\t/g,` `).length,p={},m,h=l.match(Cs);h&&(p=H(h[1]),m=[d+h.index,d+l.length],l=l.slice(0,h.index).trimEnd());let g,_=Os(l).match(ws);if(_&&_.index>0){g=l.slice(_.index+_[0].length).trim()||void 0,l=l.slice(0,_.index).trimEnd();let e=l.match(Cs);e&&!h&&(p=H(e[1]),m=[d+e.index,d+l.length],l=l.slice(0,e.index).trimEnd())}As(p,e=>n(t,e));let v={text:l,collapsed:!1,highlight:!1,dim:!1,line:t,lead:e.slice(0,d),depth:0,own:{props:p,note:p.note??g},children:[]};for(m&&(v.propSpan=m);i.length&&i[i.length-1].indent>=f;)i.pop();i.length>=js&&(o||n(t,`treeview: entries nest at most ${js} levels deep`),o=!0,i.length=99),v.depth=i.length,(i.length?i[i.length-1].node.children:r).push(v),i.push({indent:f,node:v})});let s=(e,t)=>{for(let n of e){let e=t+ks(n.text),{props:r,note:i}=n.own,o=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),c={};for(let t of a)(!t.folders||o)&&t.re.test(t.path?e:ks(n.text))&&(t.hits++,Object.assign(c,t.props));r.folder===`true`&&delete c.file,r.file===`true`&&delete c.folder,(ms.some(e=>r[e]===`true`)||r.status)&&ys(c),Object.assign(c,r),n.note=i??c.note,n.tone=c.color,n.icon=c.icon,n.badge=c.badge,n.size=c.size,n.status=vs(c),n.collapsed=c.collapsed===`true`,n.highlight=c.highlight===`true`,n.dim=c.dim===`true`,n.type=c.folder===`true`?`folder`:c.file===`true`?`file`:void 0,s(n.children,e+`/`)}};s(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function Ns(e,t=[]){for(let n of e)t.push(n),Ns(n.children,t);return t}var Ps=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),Fs=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},Is={},U=(e,t,n)=>{for(let r of n.split(` `))Is[r]=[t,e]};U(`blue`,`code`,`ts tsx mts cts py c cpp`),U(`amber`,`code`,`js jsx mjs cjs zig`),U(`green`,`code`,`vue`),U(`orange`,`code`,`svelte rs swift html`),U(`purple`,`code`,`astro kt h cs css`),U(`cyan`,`code`,`go`),U(`red`,`code`,`java rb`),U(`indigo`,`code`,`php lua`),U(`pink`,`code`,`scss`),U(`green`,`terminal`,`sh bash zsh fish ps1`),U(`blue`,`doc`,`md`),U(`amber`,`doc`,`mdx`),U(`gray`,`doc`,`txt rst`),U(`red`,`doc`,`pdf`),U(`green`,`doc`,`csv`),U(`purple`,`image`,`png jpg jpeg gif webp avif ico`),U(`amber`,`image`,`svg`),U(`red`,`font`,`woff woff2 ttf otf`),U(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),U(`amber`,`config`,`json`),U(`purple`,`config`,`yaml yml`),U(`gray`,`config`,`toml ini`),U(`orange`,`config`,`xml`),U(`slate`,`config`,`env`),U(`cyan`,`database`,`sql db sqlite`),U(`amber`,`package`,`zip tar gz`),U(`pink`,`yuhwa`,`yu yuhwa`);var Ls=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function Rs(e){let t=ks(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`]:Is[Fs(t)]??[`file`,void 0]}var zs=`M3.5 1.5h6l3.5 3.5v9.5h-9.5z`,Bs=`M9.5 1.5v3.5h3.5`;function Vs(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="${zs}" fill="${t}" stroke="${n}"/>${r(Bs)}`;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}}var Hs=l({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function Us(e){let t=new Map;for(let n of e)t.set(ks(n.text),(t.get(ks(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(ks(e.text))&&t.get(ks(e.text))===1&&!/^n\d+$/.test(ks(e.text))?ks(e.text):`n${n+1}`)}var Ws=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,Gs=e=>e!==void 0&&e!==`false`,Ks=(e,t,n)=>t.includes(e)?e:n,qs=e=>e&&xe(e)?e:void 0,Js=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function Ys(e,t){let n=t.get(e);if(n)return n;n=new Set;for(let r of e.children){r.status&&r.status!==`ignored`&&n.add(r.status);for(let e of Ys(r,t))n.add(e)}return t.set(e,n),n}var Xs=[`color`,`mono`,`emoji`,`none`],Zs=[`solid`,`rounded`,`dashed`,`dotted`,`none`],Qs=[`none`,`name`,`folders`],$s=[`collapsed`,`all`,`none`],ec=[`letter`,`dot`,`none`],tc=br(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=Ks(i.icons,Xs,Xs[0]),s=Ks(i.sort,Qs,Qs[0]),c=i.counts===`true`?`all`:Ks(i.counts,$s,$s[0]),l=Ks(i.marks,ec,ec[0]),u=i.rollup!==`false`&&l!==`none`,d=Gs(i.compact),f=Gs(i.chevrons),p=Ws(i.depth),m=qs(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=Ws(i.indent)??y+a*.75,x=Ns(e),S=Us(x),C=new Map(x.map((e,t)=>[e,S[t]])),w=new Map,T=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(Ds.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(Ps(n))-Number(Ps(e)):0)||Js.compare(e.text,n.text))},ee=e=>!e.note&&!e.badge&&!e.size&&!e.status&&!e.highlight&&!e.dim&&!e.icon&&!e.tone&&!e.collapsed,te=[],ne=(e,t,o)=>{let s=k(e);s.forEach((e,l)=>{let f=e,g=e=>e.collapsed||p!==void 0&&t+1>=p,_=[ks(f.text)];for(;d&&f.children.length===1&&Ps(f)&&Ps(f.children[0])&&ee(f)&&!g(f);)f=f.children[0],_.push(ks(f.text));let v=Ps(f),y=!v&&Ds.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`,Ls.test(ks(f.text))?`gray`:m]:Rs(f.text),k=f.icon??T,A=bs.includes(k)?k:void 0,re=v?600:400,j=v&&(c===`all`||c===`collapsed`&&!x)&&f.children.length?String(E(f)):void 0,ie=v&&u&&!f.status?Ys(f,w):void 0,ae={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:A??`file`,iconTone:f.tone??(f.status?ps[f.status]:void 0)??(f.icon?void 0:D),iconText:A?void 0:f.icon,textW:L(N(S),a,n.mono,r,re),badgeW:f.badge?r(f.badge,a*.72,600,n.mono)+a*.9:0,count:j,countW:j?O(j):0,rollup:ie?.size?ie.size===1?[...ie][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:te.length*h,x:t*b};te.push(ae),x&&ne(f.children,t+1,ae)})};ne(e,0);let A=e=>e.more?e.x+_:e.x+_+g+v,re=e=>A(e)+e.textW+a*.5,j=e=>(e.badgeW?re(e)+e.badgeW:A(e)+e.textW)+a*.45,ie=e=>e.countW?j(e)+e.countW:e.badgeW?re(e)+e.badgeW:A(e)+e.textW,ae=i.notes===`inline`,oe=a*.88,se=0;for(let e of te)se=Math.max(se,ie(e));let ce=se+a*1.6,le=e=>ae?ie(e)+a*.9:ce,ue=e=>e.node.note?L(N(e.node.note),oe,n.mono,r,400):0,de=e=>l!==`none`&&(e.node.status&&hs[e.node.status]!==``||e.rollup!==void 0),fe=te.some(de),pe=a*4;for(let e of te)pe=Math.max(pe,e.node.note?le(e)+ue(e):ie(e));let me=Math.max(0,...te.map(e=>e.sizeW)),he=me?pe+a*1.4+me:pe,ge=he+a*1.2;return{rows:te,fs:a,smallFs:D,noteFs:oe,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:A,badgeX:re,countX:j,noteX:le,sizeRight:he,markX:ge,mark:de,w:fe?ge+a*.8:he,h:te.length*h}}),nc=e=>{let t=dt(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function rc(e,t){if(!e.length)return{w:0,h:0};let n=tc(e,t);return{w:n.w,h:n.h}}function ic(e,t,n){if(!e.length)return``;let r=n.theme,i=tc(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=Ks(a.lines,Zs,Zs[0]),f=(e,t)=>I(e,r,t),p=f(qs(a[`line-color`]),r.edge.stroke),m=qs(a[`highlight-color`]),h=qs(a[`badge-color`])??`blue`,g=f(qs(a[`note-color`]),r.node.sub),_=f(qs(a[`strike-color`]),r.node.sub),v=Ws(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=`fill="none" stroke="${p}" stroke-width="${F(et(a)??1)}" stroke-opacity="0.55"${nc(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,b=Math.min(Ws(a.radius)??r.radius,(i.rowH-2)/2),x=Math.max(0,t.w-i.w),S=i.sizeRight+x,C=i.markX+x,w=F(o(-i.fs*.35)),T=F(i.w+x+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,x=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${w}" y="${F(s(e.y+1))}" width="${T}" height="${F(i.rowH-2)}" rx="${F(a.radius?b: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="${w}" y="${F(s(e.y))}" width="${T}" height="${F(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${F(o(t))},${F(s(r))}V${F(s(p-a))}Q${F(o(t))},${F(s(p))} ${F(o(t+a))},${F(s(p))}H${F(o(n))}" ${y}/>`:`<path d="M${F(o(t))},${F(s(r))}V${F(s(p))}H${F(o(n))}" ${y}/>`)}else l.push(`<path d="M${F(o(t))},${F(s(p))}H${F(o(n))}" ${y}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${F(t-n)},${F(s(p)-n/2)}L${F(t)},${F(s(p)+n/2)}L${F(t+n)},${F(s(p)-n/2)}`:`M${F(t-n/2)},${F(s(p)-n)}L${F(t+n/2)},${F(s(p))}L${F(t-n/2)},${F(s(p)+n)}`;x.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`)x.push(`<text x="${F(t+i.iconW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.95)}">${P(e.iconText??Hs[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;x.push(`<g transform="translate(${F(t)},${F(n)}) scale(${F(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${Vs(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));x.push(`<line x1="${F(t-i.fs*.15)}" y1="${F(s(p))}" x2="${F(t+e.textW+i.fs*.15)}" y2="${F(s(p))}" stroke="${_}" stroke-width="${F(v)}" stroke-linecap="round"/>`)}let E=n.status?f(ps[n.status],r.node.text):void 0,D=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):E??r.node.text,O=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(x.push(`<text x="${F(o(i.textX(e)))}" y="${F(s(p))}" dominant-baseline="central" font-size="${F(i.fs)}"${O} xml:space="preserve">${R(N(e.label),Ce(r,D,D),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;x.push(`<rect x="${F(a)}" y="${F(s(p)-c/2)}" width="${F(e.badgeW)}" height="${F(c)}" rx="${F(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${F(a+e.badgeW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${P(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;x.push(`<rect x="${F(t)}" y="${F(s(p)-n/2)}" width="${F(e.countW)}" height="${F(n)}" rx="${F(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${F(t+e.countW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&x.push(`<text x="${F(o(i.noteX(e)))}" y="${F(s(p))}" dominant-baseline="central" font-size="${F(i.noteFs)}" xml:space="preserve">${R(N(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&x.push(`<text x="${F(o(S))}" y="${F(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${F(i.fs*.82)}" fill="${r.node.sub}">${P(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(ps[t],r.node.text);i.marks===`dot`||!n.status?x.push(`<circle cx="${F(o(C))}" cy="${F(s(p))}" r="${F(i.fs*.22)}" fill="${a}"/>`):x.push(`<text x="${F(o(C))}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.85)}" font-weight="700" fill="${a}">${hs[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${x.join(``)}</g>`:x.join(``))}),c.join(``)+l.join(``)+u.join(``)}var ac={text:[],note:[],status:[``,...ms],icon:[``,...bs],badge:[],size:[],collapsed:[``,`true`],highlight:[``,`true`],dim:[``,`true`]},oc=e=>e.children.length?oc(e.children.at(-1)):e.line+1;function sc(e,t,n,r){let i=ii(r);return e.lead+t+(n?`: ${n}`:``)+(i?` [${i}]`:``)}function cc(e,t){let n=e?e.children[0]:t[0],r=e=>e.replace(/[^\s\-*+]/gu,` `).replace(/[-*+](?!\s)/g,` `);if(n)return r(n.lead);if(!e)return``;let i=e.lead.match(/[-*+]\s+$/)?.[0]??``;return` `.repeat(r(e.lead).length-i.length+2)+i}function lc(e,t,n){let r=Ns(n),i=Us(r),a=t.id===void 0?-1:i.indexOf(t.id),o=r[a],s=(e,t,n)=>{if(t===void 0)return{body:e};let r=Ns(n??Ms(e,{},()=>{}));return{body:e,id:Us(r)[r.findIndex(e=>e.line===t)]}},c=e=>r.find(t=>t.children.includes(e))?.children??n;switch(t.op){case`set`:{if(!o)return null;let{key:n}=t,r=t.value?.trim()||null;if(r&&/[\r\n]/.test(r)||n!==`color`&&!(n in ac)||ac[n]?.length&&r&&!ac[n].includes(r)&&n!==`icon`||n===`color`&&r&&!xe(r))return null;let i=[...e],c=o.text,l=o.own.note;if(n===`text`||n===`note`){if(n===`text`){if(!r)return null;c=r}else l=r??void 0;let{note:e,...t}=o.own.props;i[o.line]=sc(o,c,l,t)}else{let{color:t,...a}=o.own.props;n===`status`?(ys(a),r&&(a[r]=`true`)):n!==`color`&&(r?a[n]=r:delete a[n]);let s=n===`color`?r:t,c=ii(s?{color:s,...a}:a),l=e[o.line],[u,d]=o.propSpan??[l.trimEnd().length,l.trimEnd().length];i[o.line]=l.slice(0,u)+(c?` [${c}]`:``)+l.slice(d)}let u=Ms(i,{},()=>{}),d=Ns(u)[a];return!d||d.text!==c||d.own.note!==l?null:s(i,o.line,u)}case`up`:case`down`:{if(!o)return null;let n=c(o),r=n.indexOf(o),i=t.op===`up`,a=n[i?r-1:r+1];if(!a)return null;let[l,u]=i?[a,o]:[o,a],d=[...e],f=e.slice(l.line,u.line),p=e.slice(u.line,oc(u));return d.splice(l.line,f.length+p.length,...p,...f),s(d,i?l.line:l.line+p.length)}case`remove`:{if(!o)return null;let t=[...e];return t.splice(o.line,oc(o)-o.line),s(t)}case`add`:{if(t.id!==void 0&&!o)return null;let r=[...e],i=o?oc(o):n.length?oc(n[n.length-1]):e.length;return r.splice(i,0,cc(o,n)+`new-file`),s(r,i)}}}Nr(pi,hi,gi,Ti,ki,Ii,Yi,Vi,ha,Ea,La,no,bo,Ho,Qo,ds,{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: "+bs.join(`|`)+"|<emoji>`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `"+ms.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:[...Xs],lines:[...Zs],sort:[...Qs],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...$s],marks:[...ec],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`},help:{icons:`how files and folders are drawn: coloured glyphs, one colour, emoji or no icon`,lines:`the guide lines that join an entry to its folder`,sort:`reorder entries: as written, by name, or folders first`,notes:`notes in their own column, or right after the name`,chevrons:`an open/closed arrow before each folder`,rows:`every other row shaded`,spacing:`the row height`,slashes:"a `/` after folder names",compact:"fold a folder whose only child is a folder into one `a/b/` row",counts:`how many entries a folder holds: on collapsed folders, on all, or none`,marks:`the git status column on the right: letters (M, A, D, R), dots, or none`,rollup:`a dot on folders that hold changed files`,depth:`show this many levels; deeper folders are drawn collapsed`,indent:`how far each level is indented, in pixels`,"folder-color":`the folder icon colour`,"line-color":`the guide line colour`,"highlight-color":`the band behind highlighted entries`,"badge-color":`the badge colour`,"note-color":`the note text colour`,"strike-color":`the line through deleted entries`,"strike-width":`how thick the line through deleted entries is`},parse:Ms,measure:rc,render:ic,parts(e){let t=Ns(e);return Us(t).map((e,n)=>{let r=t[n],i=r.own.props,a=Ps(r);return{id:e,label:r.text,kind:`entry`,depth:r.depth,tone:r.tone,fields:ac,values:{text:r.text,note:r.own.note??``,status:vs(i)??``,icon:i.icon??``,badge:i.badge??``,size:i.size??``,collapsed:i.collapsed===`true`?`true`:``,highlight:i.highlight===`true`?`true`:``,dim:i.dim===`true`?`true`:``},actions:a?[`up`,`down`,`remove`,`add`]:[`up`,`down`,`remove`],...a?{adds:`entry`}:{}}})},editPart:lc,adds:`entry`}]});var uc=e=>JSON.stringify(e),dc=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:uc(e);function fc(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,`
7
- `).replace(/<\/?(b|i|em|strong|span|code)[^>]*>/gi,``).replace(/&quot;|#quot;/g,`"`).replace(/&amp;/g,`&`).replace(/#59;/g,`;`).replace(/\bfa[bsr]?:fa-[\w-]+\s*/g,``).replace(/^`(.*)`$/s,`$1`),t||(n=n.replace(/\*\*(.+?)\*\*/g,`$1`)),n.trim()}var W=(e,t=!1)=>fc(e,t).replace(/\s*\n\s*/g,` `);function pc(e,t=mc){let n=e.trim().replace(/^"(.*)"$/,`$1`).replace(/[^\p{L}\p{N}_-]+/gu,`_`).replace(/^[-_]+(?=.)|-+$/g,``);return/^[\p{L}_]/u.test(n)||(n=`n`+n),t.has(n)&&(n+=`_`),n}var mc=new Set(lr);function hc(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 gc(e,t,n,r,i){let a=[e,t];return n&&a.push(uc(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}var _c=/^title\b(?!\s*(?:[-=.~<>&|[({]|:::))\s*:?\s*(.*)$/,vc=new RegExp(_c.source,`i`);function yc(e,t=!0){let n=e.match(t?vc:_c);return n?fc(n[1]):void 0}var bc=/^(accTitle|accDescr)\b/;function xc(e,t){return bc.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function Sc(e,t,n){for(;e.index<e.lines.length;e.index++){let r=e.lines[e.index];!xc(r,t)&&!n(r)&&t.warn(r.line,`could not read "${r.text}"`)}}var Cc={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},wc=/^direction\s+(TD|TB|BT|LR|RL)$/i,Tc=/^style\s+(\S+)\s+(.*)$/;function Ec(e,t){let n=e.match(Tc);return n?{target:n[1],props:Mc(n[2],t)}:void 0}var Dc=/^classDef\s+([\w,-]+)\s+(.*)$/;function Oc(e,t){let n=e.match(Dc);if(!n)return;let r=Mc(n[2],t);return n[1].split(`,`).map(e=>`.${e.trim()} [${r}]`)}function kc(e){let t=e.trim().replace(/^\[|\]$/g,``),n=[],r=``,i=!1;for(let e of t)e===`"`?i=!i:e===`,`&&!i?(n.push(r.trim()),r=``):r+=e;return r.trim()&&n.push(r.trim()),n}var Ac=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:uc(e),jc=l({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 Mc(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=jc[a];s?(o=s===`border-style`?`dashed`:o.replace(/px$/,``),s===`font-weight`&&o===`bold`?n.push(`bold`):n.push(`${s}: ${o}`)):t(`style "${a}" is not supported and was skipped`)}return n.join(`, `)}var Nc=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Pc=()=>({settings:{},nodes:new Map,edges:[],groups:new Map,classes:l({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]}),Fc=Object.keys(pe),Ic=e=>e.match(/^\s*/)[0].length,Lc=(e,t,n)=>void e.classUses.push([t,n]);function Rc(e){for(let t=e.stack.length-1;t>=0;t--)if(e.stack[t].kind===`group`)return e.stack[t].id}function zc(e,t){let n=e.d.nodes.get(t);return n||(n={id:t,label:t,props:{},classes:[],implicit:!0,group:Rc(e)},e.d.nodes.set(t,n)),n}function Bc(e,t,n,r,i){let a=n.value;t.labelRef={line:r,at:n.start,range:[n.start,n.end],generated:e.gen||void 0};let o=e.labelled.get(t.id);o!==void 0&&t.label!==a&&e.warn(r,`"${t.id}" already has the label "${t.label}" (line ${o+1}); this renames it to "${a}"`+(i?`. For an edge label write: ... -> ${t.id}: ${a}`:``)),t.label=a,e.labelled.set(t.id,r)}function Vc(e,t,n,r,i){if(!(n in pe))return e.warn(i,`Unknown theme key "${n}"${$n(n,Fc)||` (keys: ${Fc.join(`, `)})`}`);pe[n].kind!==`color`||[`none`,`transparent`].includes(r)||r.includes(`$`)||ye(r)||e.warn(i,`Unknown color "${r}" for ${n}${$n(r,f)}`),t[n]=r}function Hc(e,t,n,r){e.themeLines.has(t)&&e.warn(r,`Theme "${t}" is defined twice`),(e.d.themes??=l({}))[t]=n,e.themeLines.set(t,r)}function Uc(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 Wc(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),a=new Map,o=new Set,s=new Set(e.panels.map(e=>e.id));if(t)for(let[c,l]of t){let t=c.replace(/^\./,``);if(e.sharedSettings?.includes(c)&&!e.nodes.has(c)&&!e.groups.has(c)){l===c?o.add(c):n(`a setting keeps its name: import { ${c} }`);continue}let u=c.startsWith(`.`)?t in e.classes:c.startsWith(`$`)?c.slice(1)in(e.vars??{}):e.nodes.has(t)||e.groups.has(t)||s.has(t)||t in(e.defs??{});!u&&c in(e.themes??{})||(u?i(c)?(o.add(c),l!==c&&a.set(c,l)):n(`"${c}" is not exported (exports: ${r.join(`, `)||`none`})`):n(`no "${c}" to import${r?.length?` (exports: ${r.join(`, `)})`:``}`))}else for(let e of r)o.add(e);let c=t=>{for(let n=t;n;n=e.groups.get(n)?.parent)if(o.has(n))return!0;return!1},l=Pc(),u=e=>a.get(e)?.replace(/^\./,``)??e,d=e=>a.get(`.${e}`)?.slice(1)??e,f=new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(l.groups.set(u(t.id),{...t,id:u(t.id),parent:t.parent&&l.groups.has(u(t.parent))?u(t.parent):void 0,classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e)));let p=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(p(t.id)){let e=t.group&&l.groups.has(u(t.group))?u(t.group):void 0;l.nodes.set(u(t.id),{...t,id:u(t.id),group:e,classes:t.classes.map(d)}),t.classes.forEach(e=>f.add(e))}for(let t of e.edges)if(p(t.from)&&p(t.to)){let e=u(t.from)+`->`+u(t.to)+(t.key.match(/#\d+$/)?.[0]??``);l.edges.push({...t,key:e,from:u(t.from),to:u(t.to),classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e))}for(let t of e.panels)o.has(t.id)&&l.panels.push({...t,id:u(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(o.has(t))for(let e of n.body)for(let t of qr(e).tokens)t.kind===`class`&&f.add(t.value);l.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||o.has(e));for(let t of l.sharedSettings)l.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(o.has(`.${t}`)||f.has(t))&&(l.classes[d(t)]=n);l.vars={};for(let[t,n]of Object.entries(e.vars??{}))o.has(`$${t}`)&&(l.vars[(a.get(`$${t}`)??`$${t}`).slice(1)]=n);l.defs={};for(let[t,n]of Object.entries(e.defs??{}))o.has(t)&&(l.defs[a.get(t)??t]=n);return l.themes=e.themes,l}function Gc(e,t,n){let r=`${t}->${n}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`}function Kc(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)e.edges.push({...r,key:Gc(n,r.from,r.to),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),t.layout.aligns?.length&&(e.layout.aligns??=[]).push(...t.layout.aligns);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??=l({}))[n]??=r}function qc(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`?(Yr(h,Xr(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){let n=e[0]?.kind===`string`?e[0].value:``;o(t,`Edge needs a source node${n.trim()?`: a label needs an id, write ${pc(n.toLowerCase())} ${si(n)}`:``}`,`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=H(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=oi(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={key:Gc(a,e,o),from:e,to:o,label:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(l)}}}var Jc=(e,t)=>(e.layout.panels??={})[t]??={};function Yc(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(!Yn(t))return null;n.push(t)}return n},s=1,c=xt(a,i[1]);if(c&&a===`rank`){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(c&&a===`align`){let[e,a]=bt(i.slice(1).filter(Boolean));if(a.length<2)return r(t,`align needs two or more ids: align ${yt} a b c`);(n.layout.aligns??=[]).push({side:e,ids:a});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`){l.via=[];for(let e=o(s,2);e;e=o(s,2))l.via.push({x:e[0],y:e[1]}),s+=2}else if(e===`label`){let e=o(s,2);if(!e)return r(t,`label expects two numbers: dx dy (each within ±${Jn})`);l.label={x:e[0],y:e[1]},s+=2}else if(e===`ports`){let e=i[s],n=i[s+1];if(!In.includes(e)||!In.includes(n))return r(t,`ports expects two sides: ${In.join(`|`)}`);l.ports=[e,n],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}return}let l=a.indexOf(`:`);if(l>0){let s=a.slice(0,l),c=a.slice(l+1),u=i[1]===`offset`?2:1,d=i.length-u,f=c&&(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)`);(Jc(n,s).parts??={})[c]={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)`);Jc(n,a).at={x:e[0],y:e[1]};return}let u=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 (each within ±${Jn})`);u.x=e[0],u.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 (each within ±${Jn})`);u.w=e[0],u.h=e[1],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}}function Xc(e,t,n,r){switch(t?.kind){case`body`:return Zc(e,t,n,r),!0;case`panel`:return Qc(e,t,n,r),!0;case`theme`:return el(e,t,n,r),!0;case`layout`:return tl(e,n,r),!0;default:return!1}}function Zc(e,t,n,r){if(n.trim()===`}`){e.stack.pop();let n=e.d.nodes.get(t.id);n.body=Ue(t.lines),n.bodyLines=[t.start,r]}else t.lines.push(n)}function Qc(e,t,n,r){n.trim()===`}`?(e.stack.pop(),$c(e,t,r)):t.lines.push(n.slice(0,qr(n).codeEnd).trimEnd())}function $c(e,t,r){let i=t.panel,a=t.lines.findIndex(e=>e.trim());i.body=Ue(t.lines),i.lines=[t.start,r];try{i.data=gr.get(i.kind).parse(i.body,i.props,(n,r)=>e.warn(n<0?t.start:t.start+1+Math.max(0,a)+n,r))}catch(r){let a=c(`panel`,i.kind);e.warn(t.start,`${a?`plugin "${a}": `:``}${i.kind} panel failed to parse: ${n(r)}`,`error`),i.failed=!0}}function el(e,t,n,r){let i=n.slice(0,qr(n).codeEnd).trim();if(!i)return;if(i===`}`){e.stack.pop(),Hc(e,t.id,t.props,t.start);return}let a=i.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);a?Vc(e,t.props,a[1].toLowerCase(),ci(a[2].trim()),r):e.warn(r,`Expected "key: value" in theme ${t.id} (keys: ${Fc.join(`, `)})`,`error`)}function tl(e,t,n){let r=t.slice(0,qr(t).codeEnd).trim();r&&(r.startsWith(`}`)?(e.stack.pop(),e.d.layoutBlock[1]=n):(e.layoutLines.set(r.split(/\s+/)[0],n),Yc(r,n,e.d,e.warn)))}function nl(e,t){if(!e.stack.length)e.warn(t,`Unmatched "}"`,`error`);else{let n=e.stack.pop(),r=n.kind===`group`?e.d.groups.get(n.id):void 0;r?.ref&&(r.ref.end=t)}e.lastDecl=null}function rl(e,t,n){e.stack.length&&e.warn(n,`theme must be at the top level`,`error`);let r={},i=2;if(t[i]?.kind===`props`){for(let[a,o]of Object.entries(H(t[i].value)))Vc(e,r,a,o,n);i++}if(t[i]?.value===`{`){if(i++,t[i]?.value===`}`)i++;else if(i===t.length){e.stack.push({kind:`theme`,id:t[1].value,start:n,props:r});return}}i<t.length&&e.warn(n,`Unexpected "${t[i].value}" in theme ${t[1].value}`,`error`),Hc(e,t[1].value,r,n)}function il(e,t,n){let r=t[0].value,i=1,a=t[i]?.kind===`ident`?t[i++].value:`${r}${e.d.panels.length+1}`,o=e.gen?void 0:t[i]?.kind===`string`?{line:n,at:t[i].start,range:[t[i].start,t[i].end]}:{line:n,at:t[i-1].end},s=t[i]?.kind===`string`?t[i++].value:void 0,c={line:n,insertAt:t[i-1].end},l={};t[i]?.kind===`props`&&(l=H(t[i].value),c.props=[t[i].start,t[i].end],i++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,i!==t.length-1&&e.warn(n,`Unexpected "${t[i].value}" in ${r} header`,`error`),e.stack.length&&e.warn(n,`${r} must be at the top level`,`error`);let u={kind:r,id:a,label:s,props:l,body:[],data:void 0,ref:e.gen?void 0:c,labelRef:o};e.d.panels.push(u),e.stack.push({kind:`panel`,id:a,start:n,lines:[],panel:u})}function al(e,t,n){e.stack.length&&e.warn(n,`layout block must be at top level`,`error`),e.d.layoutBlock=[n,n],t[2]?.value!==`}`&&e.stack.push({kind:`layout`})}function ol(e){let t=e.lines.length-1;for(let n of e.stack)n.kind===`group`?e.warn(t,`Group "${n.id}" is missing "}"`,`error`):n.kind===`body`?e.warn(n.start,`Body of "${n.id}" is missing a closing "}" line`,`error`):n.kind===`panel`?(e.warn(n.start,`${n.panel.kind} "${n.id}" is missing a closing "}" line`,`error`),$c(e,n,t)):n.kind===`def`?e.warn(n.start,`def ${n.id}() is missing "}"`,`error`):n.kind===`theme`?e.warn(n.start,`theme ${n.id} is missing "}"`,`error`):e.warn(t,`layout block is missing "}"`,`error`)}var sl=1e5,cl=5e4,ll=16,ul=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,dl=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,fl=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,pl=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,ml=new WeakMap;function hl(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}function gl(e,t,n,r,i=!1){let a=t.match(dl);if(a)return t.slice(0,t.length-a[2].length)+gl(e,a[2],n,r,i);let o=t.length,s=t.replace(ul,(t,a,s)=>{let c=a??s;if(!c)return`$`;let l=r?.[c]??e.vars[c];return r?.[c]===void 0&&l!==void 0&&e.used.add(`$`+c),l===void 0?(i||e.warn(n,`Unknown variable "$${c}"${$n(c,[...Object.keys(r??{}),...Object.keys(e.vars)])}`),t):(o+=l.length)>sl?t:l});return o>sl&&e.warn(n,`Variables make this line longer than ${sl} characters`,`error`),s}function _l(e,t,n,r){if(e.depth>=ll){e.tooDeep.has(t.name)||e.warn(r,`${t.name}(): calls nest too deep`,`error`),e.tooDeep.add(t.name);return}if((e.expanded+=t.body.length)>cl){e.expanded-t.body.length<=cl&&e.warn(r,`${t.name}(): components expand to more than ${cl} lines`,`error`);return}let i=hl(n),a=l({}),o=0;for(let n of i){let s=n.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(s&&t.params.some(e=>e.name===s[1]))a[s[1]]=ci(s[2]);else if(o<t.params.length)a[t.params[o++].name]=ci(n);else{e.warn(r,`${t.name}() takes ${t.params.length} argument(s), got ${i.length}`,`error`);return}}for(let n of t.params)if(!(n.name in a)){if(n.default===void 0){e.warn(r,`${t.name}(): missing argument "${n.name}" (${t.params.map(e=>e.name).join(`, `)})`,`error`);return}a[n.name]=n.default}let s=e.stack.length,c=e.gen;e.gen=!0,e.depth++;let u=t.body.map(t=>gl(e,t,r,a)),d=ml.get(t)??e.defs;for(let t of u)e.step(t,r,!0,d);e.depth--,e.gen=c,e.stack.length>s&&(e.warn(r,`${t.name}(): a block inside the component is not closed`,`error`),e.stack.length=s)}function vl(e,t,n,r,i){for(let e of Jr(qr(n).tokens))t.depth+=e===`{`?1:-1;if(t.depth>0){t.lines.push(n);return}e.stack.pop(),n.trim()!==`}`&&e.warn(r,`Expected "}" alone on the line that closes ${t.id}()`,`error`);let a=t.params,o=l(Object.fromEntries(a.map(e=>[e.name,`\${${e.name}}`]))),s={name:t.id,params:a,body:Ue(t.lines).map(t=>gl(e,t,r,o,!0))};ml.set(s,i),e.defs[s.name]&&e.warn(t.start,`Component "${s.name}" is defined twice`),e.defs[s.name]=s,(e.d.defLines??={})[s.name]=t.start}function yl(e,t,n,r,i){let a=t.match(dl);if(a)return e.vars[a[1]]=ci(Qr(r?a[2]:gl(e,a[2],n)).trimEnd()),(e.d.varLines??={})[a[1]]=n,!0;let o=t.match(fl);if(o){e.stack.length&&e.warn(n,`def must be at the top level`,`error`);let t=hl(o[2]).map(t=>{let r=t.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return r||e.warn(n,`Bad parameter "${t}": def name(a, b = "default") {`,`error`),{name:r?.[1]??t,default:r?.[2]===void 0?void 0:ci(r[2])}});return e.stack.push({kind:`def`,id:o[1],start:n,lines:[],depth:1,params:t}),!0}let s=Qr(t).match(pl);if(s){let a=i[s[1]]??e.defs[s[1]];if(a)return e.used.add(s[1]),_l(e,a,r?s[2]:gl(e,s[2],n),n),!0;if(!qr(t).tokens.some(e=>e.kind===`arrow`))return e.warn(n,`Unknown component "${s[1]}"${$n(s[1],Object.keys(e.defs))}`,`error`),!0}return!1}var bl=new Set([...zn,...Bn]);function xl(e,t,n,r){let i=2,a=t[1].value;t[1].kind===`string`&&(a=t[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,i=1);let o=e.d.groups.get(a)??{id:a,label:a,props:{},parent:Rc(e)};if(t[i]?.kind===`string`){let e=t[i++];o.label=e.value,o.labelRef={line:r,at:e.start,range:[e.start,e.end],id:i===2?a:void 0}}else o.labelRef??={line:r,at:t[1].end};for(e.gen&&(o.labelRef.generated=!0);t[i]?.kind===`class`;)Lc(e,t[i].value,r),(o.classes??=[]).push(t[i++].value);let s={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};if(t[i]?.kind===`props`&&(Object.assign(o.props,H(t[i].value)),s.props=[t[i].start,t[i].end],i++),o.ref=s,e.lastDecl={indent:Ic(n),targets:[o]},e.d.groups.set(a,o),t[i]?.value!==`{`){e.warn(r,`Expected "{" after group ${a}`,`error`);return}i++;let c=t.findIndex((e,t)=>t>=i&&e.value===`}`);if(c>=0){s.end=r;for(let n=i;n<c;n++)t[n].kind===`ident`&&(zc(e,t[n].value).group=a)}else e.stack.push({kind:`group`,id:a})}function Sl(e,t,n,r){let{classes:i}=e.d,a=t[t.length-1],o={};for(let n of t.slice(1))n.kind===`class`&&(i[n.value]?Object.assign(o,i[n.value]):e.warn(r,`Unknown class ".${n.value}"${$n(n.value,Object.keys(i))}`));i[t[0].value]={...i[t[0].value],...o,...a.kind===`props`?H(a.value):{}},(e.d.classLines??={})[t[0].value]=r,e.lastDecl={indent:Ic(n),targets:[{props:i[t[0].value]}]}}function Cl(e,t,n,r,i){let a=n.slice(t[1].end,i).trim();if(t[0].kind!==`ident`||!a)return!1;let o,s=a.match(/^\{(.*)\}$/s);if(s)o=`[${s[1].trim()}]`;else if(/^["']/.test(a))o=a;else{let e=a.match(Wr);o=`${si(e[1].trim())}${e[2]}${e[3]?` ${e[3]}`:``}`}let c=e.gen;return e.gen=!0,e.statement(`${n.match(/^\s*/)[0]}${t[0].value} ${o}`,r),e.gen=c,!0}function wl(e,t,n,r,i,a){let o=Zr(t[0].value),s=n.slice(t[1].end,i).trim();/^(["']).*\1$/.test(s)&&(s=Kr(s.slice(1,-1)));let c=e.lastDecl&&Ic(n)>e.lastDecl.indent?e.lastDecl.targets:null,l=a?.kind===`group`?e.d.groups.get(a.id):void 0,u=l?Vn:dr,d=ur.has(o)||u.includes(o),f=d?``:$n(o,u);if((!c||c[0]===l)&&!d&&!f&&!bl.has(o)&&Cl(e,t,n,r,i))return;let p=c??(l?[l]:null);if(p){for(let t of p)t.props[o]=s||`true`,t.ref&&!e.gen&&((t.ref.propLines??={})[o]=r);return}if(e.stack.length&&e.warn(r,`Setting "${o}" should be at the top level`),!ur.has(o)){let n=bl.has(o)?`. "${o}" is a prop: put it in brackets after a node, e.g. a [${o}: ${s||`…`}]`:`. For a node write ${t[0].value} "Label"`;e.warn(r,`Unknown setting "${o}"${(l?$n(o,dr):f)||n}`);return}o===`direction`&&(s=mr[s.toLowerCase()]??s),o===`theme`&&(e.themeLine=r);let m=o===`theme`?void 0:fr[o];m&&s&&!s.includes(`$`)&&!m.includes(s)&&e.warn(r,`Unknown ${o} "${s}"${$n(s,m)||` (use one of: ${m.join(`, `)})`}`),e.d.settings[o]=s}function Tl(e,t,n,r,i){let{d:a}=e,o=a.edges.length;if(qc(t,r,n.slice(0,i),a,t=>zc(e,t),e.edgeCount,e.warn,(t,n,r,i)=>Bc(e,t,n,r,i),(t,n)=>Lc(e,t,n)),e.lastDecl={indent:Ic(n),targets:a.edges.slice(o)},e.gen){for(let e of a.edges.slice(o))e.ref&&(e.ref.generated=!0),e.labelRef&&(e.labelRef.generated=!0);for(let e of t)if(e.kind===`ident`){let t=a.nodes.get(e.value);t?.ref?.line===r&&(t.ref.generated=!0),t?.labelRef?.line===r&&(t.labelRef.generated=!0)}}}function El(e,t,n,r){let i=0,a=!0;for(;i<t.length;){let o=t[i];if(o.kind===`punct`&&o.value===`,`){i++,a=!0;continue}if(!a&&o.kind===`ident`){let n=[t[i-1].value];for(;t[i]?.kind===`ident`;)n.push(t[i++].value);let a=n.join(` `),o=n[0].toLowerCase();e.warn(r,o===`subgraph`||o===`end`?`"${n[0]}" is Mermaid syntax: write group id "Label" { ... }`:`"${a}" looks like a label: write ${n.join(`_`).toLowerCase()} "${a}" (or separate nodes with commas)`,`error`);break}if(o.kind===`punct`&&o.value===`{`&&i===t.length-1&&i>0&&t[i-1].kind!==`punct`){let n=t.slice(0,i).reverse().find(e=>e.kind===`ident`);e.stack.push({kind:`body`,id:n.value,start:r,lines:[]});break}if(o.kind!==`ident`){e.warn(r,`Unexpected "${o.value}"`,`error`);break}a=!1;let s=zc(e,o.value);s.implicit=!1;let c=Rc(e);for(c&&s.group&&s.group!==c&&e.warn(r,`"${o.value}" is already in group "${s.group}": a node lives in one group, so it moves to "${c}"`),c&&(s.group=c),i++,t[i]?.kind===`string`?Bc(e,s,t[i++],r,!1):s.labelRef??={line:r,at:o.end,generated:e.gen||void 0};t[i]?.kind===`class`;){let n=t[i++].value;Lc(e,n,r),s.classes.includes(n)||s.classes.push(n)}let l={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};t[i]?.kind===`props`&&(Yr(s,Xr(t[i],s.id,r,e.warn),r),l.props=[t[i].start,t[i].end],i++),s.ref=l,e.lastDecl={indent:Ic(n),targets:[s]}}}function Dl(e){jl(e),Ml(e),e.hasExport&&Nl(e),Pl(e),Fl(e),cr(e.d,e=>gr.get(e)?.options),e.opts.chain||t(e.d.diagnostics,()=>vr.forEach(t=>t(e.d))),Il(e),e.opts.chain||Al(e)}var Ol=2e3,kl=2e3;function Al(e){let{nodes:t,edges:n}=e.d;t.size<=Ol&&n.length<=kl||(e.warn(0,`Diagram too large to lay out: ${t.size} nodes and ${n.length} edges (at most ${Ol} nodes and ${kl} edges). The graph is not drawn; split it into files or panels`,`error`),t.clear(),n.length=0,e.d.groups.clear())}function jl(e){let t=ge(e.d.themes);for(let[n,r]of e.themeLines){let i=e.d.themes[n].base;i&&i!==n&&!t.includes(i)&&e.warn(r,`Unknown base theme "${i}"${$n(i,t)}`)}let n=e.d.settings.theme;e.themeLine!==void 0&&n&&!n.includes(`$`)&&!t.includes(n)&&e.warn(e.themeLine,`Unknown theme "${n}"${$n(n,t)||` (use one of: ${t.join(`, `)})`}`)}function Ml(e){let t=new Set;for(let[n,r]of e.classUses)e.d.classes[n]||t.has(`${r}.${n}`)||(t.add(`${r}.${n}`),e.warn(r,`Unknown class ".${n}"`))}function Nl(e){let{d:t}=e,n=new Set(t.panels.map(e=>e.id));t.exports=[...e.exported.keys()].filter(r=>r.startsWith(`.`)?r.slice(1)in t.classes:r.startsWith(`$`)?r.slice(1)in e.vars:t.nodes.has(r)||t.groups.has(r)||n.has(r)||r in e.defs||r in(t.themes??{}));for(let[n,r]of e.exported)!t.exports.includes(n)&&!gr.has(n)&&n!==`group`&&n!==`def`&&e.warn(r,`export: "${n}" is not declared in this file`)}function Pl(e){let{d:t}=e;for(let e of t.panels){t.nodes.get(e.id)?.implicit&&t.nodes.delete(e.id);let n=t.layout.nodes[e.id];n&&(n.x!==void 0&&n.y!==void 0&&(Jc(t,e.id).at={x:n.x,y:n.y}),delete t.layout.nodes[e.id])}}function Fl(e){let{d:t}=e,n=new Map;for(let r of t.panels){let t=n.get(r.id);t?r.lines&&e.warn(r.lines[0],`panel id "${r.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`):n.set(r.id,r)}for(let[n,r]of t.groups)if(t.nodes.has(n)){let i=t.edges.find(e=>e.ref&&(e.from===n||e.to===n))?.ref?.line??r.ref?.line??0;e.warn(i,`"${n}" is both a node and a group. Edges connect nodes, not groups: use a node inside "${n}", or rename one of them`)}}function Il(e){let{d:t}=e;for(let n of Object.keys(t.layout.nodes)){let r=e.layoutLines.get(n);r!==void 0&&!t.nodes.has(n)&&!t.groups.has(n)&&e.warn(r,`layout: there is no node "${n}" (renamed or deleted?); remove this line${$n(n,[...t.nodes.keys()])}`)}}var Ll=l({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`});function Rl(e,t){return/^\s*%%/.test(t)?`Comments start with //`:/(--|==|-\.|->|=>)\|[^|]*\|/.test(t)?`Edge labels go after a colon: a -> b: label`:zl(e,t)}function zl(e,t){let n=e[0]?.value;if([`def`,`export`,`import`].includes(n)||_r.has(n)||gr.has(n))return;let r=[],i=!1;for(let n=0;n<e.length-1;n++){let[a,o]=[e[n],e[n+1]];if(a.kind!==`ident`||o.start!==a.end)continue;let s,c=``;if(o.kind===`props`&&!/[:=,]/.test(o.value)&&/[A-Z\s?!]/.test(o.value)&&!ye(o.value)){let e=o.value.match(/^\((.*)\)$/s);s=e?e[1]:o.value,c=e?` [cylinder]`:``}else if(o.kind===`punct`&&o.value===`{`&&t.includes(`}`,o.end))s=t.slice(o.end,t.indexOf(`}`,o.end)),c=` [diamond]`;else if(o.kind===`word`&&o.value.startsWith(`(`)){let e=o.value.match(/^(\(\(|\(\[|\()(.*?)(\)\)|\]\)|\))$/);e&&(s=e[2],c=e[1]===`((`?` [circle]`:e[1]===`([`?` [pill]`:``)}s!==void 0&&(i||=c!==``||o.kind!==`props`,r.push(`${a.value} ${si(s.trim())}${c}`))}return i?`Mermaid node shapes: write ${r.join(`, `)}`:void 0}function Bl(e){let t=Ll[e[0].value];return`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...gr.keys()].join(`, `)})`+(t&&gr.has(t.split(` `)[0])?`: write "${t.replace(`ID`,e[1].value)} {"`:``)}var Vl=e=>/\.(yu|yuhwa)$/i.test(e);function Hl(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(`/`)}function Ul(e,t,n,r){let{opts:i,merged:a}=e;if(!i.resolve)return e.warn(n,`Cannot import "${t}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let o=Hl(i.file,t);if(!Vl(o))return e.warn(n,`Cannot import "${t}": imports must be .yu files`,`error`);let s=[...i.chain??(i.file?[i.file]:[])];if(s.includes(o))return e.warn(n,`Import cycle: ${[...s,o].join(` -> `)}`,`error`);let c=r?`${o}{${r.map(e=>e.join(` as `)).join(`,`)}}`:o;if(a.has(c))return;let l;try{l=i.resolve(o)}catch{l=void 0}if(l==null)return e.warn(n,`Cannot import "${t}": file not found (${o})`,`error`);if(typeof l!=`string`){let r=l instanceof Promise?`a Promise (resolve must be synchronous)`:typeof l;return e.warn(n,`Cannot import "${t}": the resolver returned ${r}, not the source text`,`error`)}let u=new Set(a),d=e.parse(l,{resolve:i.resolve,file:o,chain:[...s,o],seen:u});for(let r of d.diagnostics)e.warn(n,`${t}:${r.line}: ${r.message}`,r.severity);let f=Wc(d,r,r=>e.warn(n,`${t}: ${r}`,`error`));if(f===d)for(let e of u)a.add(e);a.add(c),Kc(e.d,f,e.edgeCount),(e.d.imports??=[]).push(o,...d.imports??[])}function Wl(e,t,n,r){if(e.stack.length)e.warn(n,`import must be at the top level`,`error`);else if(!t[1])e.warn(n,`import needs a path: import "./shared.yu"`,`error`);else if(!r)t.length>2&&e.warn(n,`Unexpected "${t[2].value}" after import path`,`error`),Ul(e,t[1].value,n);else{let r=Uc(t,n,e.warn);r&&Ul(e,r.path,n,r.names)}}function Gl(e,t,n,r){let i=()=>e.step(n.slice(0,t[0].start)+` `.repeat(6)+n.slice(t[0].end),r);e.stack.length&&e.warn(r,`export must be at the top level`,`error`);let a=t[1].kind===`ident`&&t[2]?.value===`:`&&ur.has(t[1].value.toLowerCase());if(a||t[1].value===`theme`&&t[2]?.kind===`ident`){let n=t[1].value.toLowerCase();return a&&!e.d.sharedSettings?.includes(n)&&(e.d.sharedSettings??=[]).push(n),i()}e.hasExport=!0;let o=t.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),s=t=>e.exported.has(t)||e.exported.set(t,r);if(t[1].value===`def`&&t[2])s(t[2].value);else if(t[1].value.startsWith(`$`)&&(t[2]?.value===`:`||t[2]?.value===`=`))s(t[1].value);else for(let e of t.slice(1))(e.kind===`ident`||e.kind===`class`)&&s(e.kind===`class`?`.${e.value}`:e.value);if(!o||t.slice(1).some(e=>e.kind===`ident`&&gr.has(e.value)))return i()}function Kl(e,t={}){let n=Pc(),r=t.seen??=new Set;t.file&&r.add(t.file);let i={d:n,opts:t,lines:e.split(/\r?\n/),stack:[],merged:r,edgeCount:new Map,exported:new Map,hasExport:!1,classUses:[],themeLines:new Map,labelled:new Map,layoutLines:new Map,vars:n.vars=l({}),defs:n.defs=l({}),used:n.used=new Set,gen:!1,depth:0,expanded:0,tooDeep:new Set,lastDecl:null,warn:(e,t,r=`warning`)=>n.diagnostics.push({line:e+1,message:t,severity:r}),step:(e,t,n,r)=>ql(i,e,t,n,r),statement:(e,t)=>Jl(i,e,t),parse:Kl};ml.set(i.defs,i.defs);for(let e=0;e<i.lines.length;e++)ql(i,i.lines[e],e);return ol(i),Dl(i),n}function ql(e,t,n,r=!1,i=e.defs){if(/^\s*#(\s|$)/.test(t)){e.warn(n,`Comments start with "//", not "#"`,`error`);return}let a=e.stack[e.stack.length-1];if(a?.kind===`def`)return vl(e,a,t,n,i);let o=a?.kind===`body`||a?.kind===`panel`;if(!o&&a?.kind!==`layout`&&yl(e,t,n,r,i))return;let s=r||a?.kind===`layout`||!o&&/^\s*(import|export)\b/.test(t)?t:gl(e,t,n,void 0,o),c=e.gen;e.gen||=s!==t,Jl(e,s,n),e.gen=c}function Jl(e,t,n){let r=e.stack[e.stack.length-1];if(Xc(e,r,t,n))return;let{tokens:i,codeEnd:a}=qr(t);if(!i.length)return;let o=Rl(i,t);if(o){e.warn(n,o,`error`);return}if(i[0].kind===`punct`&&i[0].value===`}`)return nl(e,n);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 Wl(e,i,n,c);if(s===`export`&&i.length>1&&i[1].kind!==`arrow`&&i[1].value!==`:`)return Gl(e,i,t,n);let l=s===void 0?void 0:_r.get(s);if(l&&i[1]?.kind!==`arrow`&&i[1]?.value!==`:`&&i[1]?.value!==`,`){l.parse(t.slice(i[0].end,a).trim(),e.d,{line:n,warn:(t,r)=>e.warn(n,t,r)});return}if(s===`theme`&&i[1]?.kind===`ident`&&(i[2]?.kind===`props`||i[2]?.value===`{`))return rl(e,i,n);let u=i[i.length-1].value===`{`;if(s!==void 0&&i.length>2&&!gr.has(s)&&i[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&e.warn(n,Bl(i)),s!==void 0&&gr.has(s)&&u&&(i[1]?.kind===`ident`||i[1]?.kind===`string`||i[1]?.kind===`props`||i[1]?.value===`{`))return il(e,i,n);if(s===`layout`&&i[1]?.value===`{`)return al(e,i,n);if(s===`group`&&(i[1]?.kind===`ident`||i[1]?.kind===`string`&&i.some(e=>e.value===`{`)))return xl(e,i,t,n);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 Sl(e,i,t,n);if(s!==void 0&&i[1]?.kind===`punct`&&i[1].value===`:`)return wl(e,i,t,n,a,r);if(i.some(e=>e.kind===`arrow`))return Tl(e,i,t,n,a);El(e,i,t,n)}function Yl(e){let t=[],n=new Map;for(let r of e){let e=r.replace(/\s+$/,``),i=e.trim();if(!i){t.push({kind:`gap`});continue}if(/^-{3,}$/.test(i)){t.push({kind:`rule`});continue}let a=t[t.length-1],o=!1;for(let e of V.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:N(e.slice(0,s)),right:N(e.slice(s+4).trim())}):t.push({kind:`text`,left:N(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}var Xl=e=>V.rows.find(t=>t.kind===e.kind);function Zl(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,L(e.left,t,n,r,o)+(e.right?t*2+L(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=Xl(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 Ql(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(`
4
+ `):[],p=f.length?Math.max(...f.map(e=>Fe(e,d,400,r,t.measure)))+8:0,m=Re(f,d),g=f.length*m+(f.length?4:0),_=Math.max(o,p)/2,v=u?-u/2:0,y=(u?u/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?It(Gt(l),e.labelOff):sn(l,x,e,t),C=x(S);h={text:e.e.label??``,caption:c,...C,anchor:S,pill:{w:o,h:u},lineHeight:s,captionLineHeight:m,rotate:b}}let g=[],_=cn(i.width),v=un(a,`end`),y=un(a,`start`);return e.headKind!==`none`&&(!d||p)&&(g.push({at:s,angle:Math.atan2(v.y,v.x),kind:e.headKind}),dn(a,`end`,ln(e.headKind,_,i.width))),e.tailKind!==`none`&&(!u||f)&&(g.push({at:o,angle:Math.atan2(y.y,y.x),kind:e.tailKind}),dn(a,`start`,ln(e.tailKind,_,i.width))),{key:e.e.key,decl:e.e,d:qt(a),samples:m,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:h,heads:g,style:i}}function vn(e,t,n,r){let{a:i,b:a,style:o}=e,s=Pn[e.sides[0]],c=Pn[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let o=e.via.map(e=>({...e}));return o[0].y=n.y,o[o.length-1].y=r.y,{kind:`poly`,pts:kt(n,s,r,c,o,i,a,t.obstacles),radius:10}}return o.curve===`orthogonal`?{kind:`poly`,pts:kt(n,s,r,c,e.via,i,a,t.obstacles),radius:10}:o.curve===`straight`?{kind:`poly`,pts:[n,...e.via,r],radius:e.via.length?6:0}:{kind:`cubic`,segs:Dt(n,s,r,c,e.via)}}function yn(e,t,n){if(e.kind===`poly`){t===`start`?e.pts.unshift(n):e.pts.push(n);return}let[r,i]=t===`start`?[n,e.segs[0][0]]:[e.segs[e.segs.length-1][3],n],a=Lt(i,r),o=[r,It(r,a,1/3),It(r,a,2/3),i];t===`start`?e.segs.unshift(o):e.segs.push(o)}var bn=new Map,xn=new Map,Sn=[],Cn=[];function wn(e,t,n,r,i,a=cn(i)){let o=xn.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}var Tn=[],En=l({});function Dn(e){if(!e)return`rounded`;let t=e.toLowerCase();return bn.has(t)?t:En[t]??`rounded`}function On(e,t){return{w:Math.max(e+44,96),h:Math.max(t+28,48)}}function kn(e,t,n){return bn.get(e)?.size?.(t,n)??On(t,n)}function An(e){return bn.get(e)?.textOffset??0}function jn(e,t,n){let r=bn.get(e);return r?r.path(t,n):Nn(t.x,t.y,t.w,t.h,Math.min(n,t.w/2,t.h/2))}function Mn(e,t){return bn.get(e)?.detail?.(t)??null}function Nn(e,t,n,r,i){return i<=0?`M${F(e)},${F(t)}h${F(n)}v${F(r)}h${F(-n)}Z`:`M${F(e+i)},${F(t)}H${F(e+n-i)}A${F(i)},${F(i)} 0 0 1 ${F(e+n)},${F(t+i)}V${F(t+r-i)}A${F(i)},${F(i)} 0 0 1 ${F(e+n-i)},${F(t+r)}H${F(e+i)}A${F(i)},${F(i)} 0 0 1 ${F(e)},${F(t+r-i)}V${F(t+i)}A${F(i)},${F(i)} 0 0 1 ${F(e+i)},${F(t)}Z`}var Pn={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function Fn(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 In(e,t,n,r){let i=bn.get(e);return i?.port?i.port(t,n,r):Fn(t,n,r)}var Ln=[`smooth`,`orthogonal`,`straight`],Rn=[`none`],zn=[...Pt,`auto`],Bn=[`below`,`above`,`right-of`,`left-of`,`rank`],Vn=[`text`,`font`,`font-size`,`font-weight`,`italic`],Hn=[`shape`,`color`,`fill`,`stroke`,...Vn,`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`,...Bn,`align`,`merge`],Un=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...Vn,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`,`merge`],Wn=[`color`,`fill`,`stroke`,...Vn,`border-style`,`dashed`,`dotted`,`meta`,`caps`,`align`,`merge`,`gap`,`padding`];[...Vn];var Gn={width:`the smallest width of the panel's frame, in pixels`,height:`the smallest height of the panel's frame, in pixels`,frame:"`false` drops the box",theme:`a theme name`,border:"`none`, a palette name or any CSS colour"},Kn=l({shape:[...Tn,...Object.keys(En)],"border-style":ie,style:ie,curve:Ln,head:Rn,tail:Rn,exit:zn,"from-side":zn,enter:zn,"to-side":zn,merge:[`none`,`in`,`out`,`both`]}),qn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],Jn=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!ye(e),Yn=e=>nr(e,f)||`: use a palette name (${f.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`,Xn=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`],Zn=1e5,Qn=e=>Number.isFinite(e)&&Math.abs(e)<=1e5,$n=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`,`gap`];function er(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 tr(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=er(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function nr(e,t){let[n,r]=tr(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function rr(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let c=a?.[o]??r;if(!t.includes(o)){n===`node`&&Un.includes(o)?i(c,`"${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}]`):o===`label`||o===`name`||o===`title`?i(c,`"${o}" is not a prop. A label follows the id in quotes: id "${s}"; an edge label follows a colon: a -> b: ${s}`):i(c,`Unknown ${n} prop "${o}"${nr(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let l=Kn[o],u=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(qn.includes(o)&&Jn(s))i(c,`Unknown ${o} "${s}"${Yn(s)}`);else if(l&&!l.includes(u)){let e=o===`shape`?Tn:l;i(c,`Unknown ${o} "${s}"${nr(s,l)||` (use one of: ${e.join(`, `)})`}`)}else if(Xn.includes(o)&&![`true`,`false`].includes(s))i(c,`${o} expects true or false, got "${s}"`);else if($n.includes(o)){let t=parseFloat(s);t>=0&&Number.isFinite(t)?t>1e5&&(i(c,`${o} is at most ${Zn}, got "${s}"`),e[o]=String(Zn)):i(c,`${o} expects a number of 0 or more, got "${s}"`)}else o===`padding`&&!dt(s)?i(c,`padding expects 1 to 4 numbers of 0 or more, like CSS (top right bottom left), got "${s}"`):o===`link`&&!Se(s)&&i(c,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function ir(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`?ye(a)||r(n,`Unknown ${i} "${a}"${nr(a,f)||`: 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}"${nr(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}var ar=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function or(e){for(let[t,n]of Object.entries(e))if(Bn.includes(t)&&n)return[t,n.trim()]}function sr(e,t){let n=t=>e.nodes.has(t)||e.groups.has(t);for(let{decl:r,group:i,value:a,rest:o}of Tt(e)){let s=r.ref&&ar(r,`align`),[c]=o;s!==void 0&&(o.length>1?t(s,`align takes one id: align: ${St} id`):c?c===r.id?t(s,`align: ${c} lines ${r.id} up with itself; use another id`):n(c)||t(s,`align: unknown node or group "${c}"${nr(c,[...e.nodes.keys(),...e.groups.keys()])}`):i||t(s,`align: ${a} needs an id to line up with: align: ${a} other`))}}function cr(e,t){let n=new Map;for(let r of e.nodes.values()){let i=ut(e,r),a=or(i);if(!a)continue;let[o,s]=a,c=ar(r,o);for(let e of Object.keys(i))e!==o&&Bn.includes(e)&&r.ref&&t(ar(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}"${nr(s,[...e.nodes.keys()])}`)}}let r=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=or(ut(e,s))[0];s.ref&&t(ar(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}var lr=e=>e.toLowerCase().replace(/\d+/g,`#`);function ur(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:lr(e.id)}));if(!r.length||n.every(e=>!e.implicit||e.id.length<3))return;let i=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=lr(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]=tr(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 dr(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&&rr(t.props,Hn,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});cr(e,n),sr(e,n);let r=new Set;for(let t of e.edges){if(!t.ref)continue;let e=t.ref.line;r.has(e)||(r.add(e),rr(t.props,Un,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&rr(t.props,Wn,`group`,t.ref.line,n,t.ref.propLines);ur(e,n);let i=ge(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}"${nr(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of qn)a[t]&&Jn(a[t])&&n(e,`Unknown ${t} "${a[t]}"${Yn(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!ye(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!ie.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${ie.join(`, `)})`),ir(a,t?.(r.kind),e,n)}let a=[...new Set([...Hn,...Un,...Wn])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&rr(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}var fr=[`group`,`import`,`export`,`layout`,`def`,`theme`],pr=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`,`merge`]),mr=[...pr],hr=l({direction:[`right`,`down`,`left`,`up`],curve:Kn.curve,panels:[`row`,`column`,`grid`,`wrap`],merge:Kn.merge}),gr=l({direction:"which way the flow runs: `right`, `down`, `left` or `up`",curve:"how edges bend: `smooth`, `orthogonal` or `straight`",gap:"space between nodes in the same rank, px. A group's `gap` overrides it for its members","rank-gap":"space between ranks, px: between columns in `right`/`left`, between rows in `down`/`up`. Default 72, or 96 with groups. A group's `gap` overrides it where only the group's own edges cross",padding:"space around the whole diagram, px. A group's `padding` is the space inside its border","max-width":`fit the diagram into this width, px: ranks wrap into rows`,wrap:`wrap node labels wider than this, px`,merge:"edges that share a node and side join into one line there. A node's, group's or edge's `merge` overrides it",panels:"how panels line up next to the graph: `row`, `column`, `grid` or `wrap`","panel-gap":`space between the graph and the panels, px`}),_r=l({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),vr=new Set(hr.curve),yr=new Map,br=new Map,xr=[];function Sr(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function Cr(e){let t=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 wr(e){return(t,n,r)=>{if(n.op!==`set`||n.key!==`color`)return null;let i=e(t,n.id,n.value||null,r);return i&&{body:i,id:n.id}}}var V={plugins:[],rows:[],frames:new Map,decorations:[],panels:yr},Tr=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)},Er=(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)}},Dr=()=>{},Or=()=>``,kr=()=>({w:0,h:0}),Ar={row:{parse:()=>null,finish:Dr,measure:kr,render:Or},frame:{inset:()=>({top:0}),render:Or},decoration:{measure:()=>null,render:Or},shape:{path:e=>Nn(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:Or,inset:()=>0},panel:{measure:kr,render:Or,handles:()=>[],parts:()=>[],editPart:()=>null},hook:{transform:Dr,afterLayout:Dr,postRender:e=>e}};function jr(e,t,n,r){let a={...n};for(let[o,s]of Object.entries(r)){let r=a[o];typeof r==`function`&&(a[o]=i(e,t(o),r.bind(n),s))}return a}function Mr(e){let t=e.name,n=(e,n,r)=>(e??[]).map(e=>jr(t,t=>n(e,t),e,r));return{rows:n(e.rows,e=>`row "${e.kind}"`,Ar.row),frames:n(e.frames,e=>`frame "${e.name}"`,Ar.frame),decorations:n(e.decorations,e=>`decoration "${e.name}"`,Ar.decoration),shapes:n(e.shapes,e=>`shape "${e.name}"`,Ar.shape),markers:n(e.markers,e=>`marker "${e.name}"`,Ar.marker),panels:n(e.panels,(e,t)=>`${e.name} panel ${t===`editPart`?`edit`:t}`,Ar.panel),statements:(e.statements??[]).map(e=>({...e,parse:i(t,e.keyword,e.parse.bind(e),Dr,(e,[,,t])=>t.warn(e,`error`))})),hooks:jr(t,e=>e,{transform:e.transform,afterLayout:e.afterLayout,postRender:e.postRender},Ar.hook)}}var Nr;function Pr(){let e=[pr].map(e=>[e,[...e]]),t=[yr,br,bn,xn,V.frames].map(e=>[e,[...e]]),n=[xr,Sn,Cn,Hn,Un,Wn,Xn,$n,C,Tn,V.rows,V.decorations].map(e=>[e,[...e]]),r=Object.entries(Kn).map(([e,t])=>[e,t,[...t]]),i={...S},a={...En};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(Kn))delete Kn[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),Kn[e]=t;for(let e of Object.keys(S))delete S[e];Object.assign(S,i);for(let e of Object.keys(En))delete En[e];Object.assign(En,a),s()}}function Fr(e,t,n){let r=e.findIndex(n);r>=0?e[r]=t:e.push(t)}function Ir(...e){Nr??=Pr();for(let t of e){if(V.plugins.some(e=>e.name===t.name))continue;V.plugins.push(t);let e=Mr(t),n=(e,n,r,i)=>{for(let a of n){let n=r(a);o(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)=>Fr(V.rows,e,e=>e.kind===t)),n(`decoration`,e.decorations,e=>e.name,(e,t)=>{Fr(V.decorations,e,e=>e.name===t),pr.add(e.setting)}),n(`frame`,e.frames,e=>e.name,V.frames),n(`panel`,e.panels,e=>e.name,yr),n(`statement`,e.statements,e=>e.keyword,br),n(`marker`,e.markers,e=>e.name,xn),n(`shape`,e.shapes,e=>e.name,(e,t)=>{bn.set(t,e),Tn.includes(t)||Tn.push(t);for(let n of e.aliases??[])En[n]=t}),Tr(Kn.shape??=[],[...t.shapes?.map(e=>e.name)??[],...t.shapes?.flatMap(e=>e.aliases??[])??[]]),Er(Kn.head??=[],t.markers),Kn.tail!==Kn.head&&Er(Kn.tail??=[],t.markers);let{transform:r,afterLayout:i,postRender:a}=e.hooks;r&&xr.push(r),i&&Sn.push(i),a&&Cn.push(a);for(let e of t.settings??[])pr.add(e);Tr(Hn,t.props?.node),Tr(Un,t.props?.edge),Tr(Wn,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))Tr(Kn[e]??=[],n);Tr(Xn,t.bools),Tr($n,t.numbers)}V.frames.size&&Tr(Kn.frame??=[],[...V.frames.keys()])}var Lr=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),Rr=new Set(`mwMW@%`.split(``)),zr=(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:Lr.has(t)?i+=.3:Rr.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},Br;function Vr(e){return(t,n,r,i)=>{if(Br===void 0)try{Br=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{Br=null}if(!Br)return zr(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?g:e;return Br.font=`${r} ${n}px ${a}`,Br.measureText(t).width}}var Hr=new Set([...f,`violet`]),Ur=e=>bn.has(e)||e in En,Wr=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,Gr=/^(<)?(--|-|\.\.|==|=)(>)?/,Kr=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,qr=/^(.*?)((?:\s+\.[\p{L}_][\p{L}\p{N}_-]*)*)\s*(\[[^\]]*\])?$/su,Jr=/^-?\d+(?:\.\d+)?/;function Yr(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
+ `:t===`t`?` `:t)}function Xr(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:Yr(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(Kr)){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(Wr)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Jr)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Gr)){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 Zr(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 Qr(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function $r(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)`),{}):H(e.value)}var ei=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function H(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(`:`),i=r>=0?r:/^[\w-]+\s*=/.test(n)?n.indexOf(`=`):-1;if(i<0){let e=n.toLowerCase();Hr.has(e)?t.color=e:Ur(e)?t.shape=e:vr.has(e)?t.curve=e:ye(n)?t.color=n:t[e]=`true`;continue}let a=ei(n.slice(0,i)),o=n.slice(i+1).trim();/^(["']).*\1$/s.test(o)&&(o=Yr(o.slice(1,-1))),t[a]=o}return t}var ti=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},ni=/(?<!\[)\[([^[\]]*)\]\s*$/;function ri(e,t){let n=e.match(ni),r=n?H(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function ii(e,t,n){let r=ei(t),[i,a]=ri(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=si(a);return s?`${o} [${s}]`:o}var ai=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&ye(e.color)};function oi(e,t,n,r,i){let a=ei(n),[o,s]=ri(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}=H(n),l=si(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=si(s);return u?`${l} [${u}]`:l}function si(e){return Object.entries(e).map(([e,t])=>t===`true`&&!Hr.has(e)&&!Ur(e)&&!vr.has(e)&&!ye(e)?e:e===`color`&&ye(t)&&!Ur(t)&&!vr.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${ci(t)}`).join(`, `)}function ci(e){return/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(e)?ui(e):e}function li(e){let t=e.match(Gr),n=!!t[1],r=!!t[3],i=t[2],a;return a=i.startsWith(`=`)?`thick`:i===`..`?`dotted`:i===`--`&&(n||r)?`dashed`:`solid`,{start:n,end:r,line:a}}var ui=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,di=e=>/^(["']).*\1$/s.test(e.trim())?Yr(e.trim().slice(1,-1)):e.trim(),fi=(e,t)=>({w:e+44,h:t+28}),pi=(e,t,n)=>Fn(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*Math.sqrt(Math.max(0,1-n*n))),mi=({x:e,y:t,w:n,h:r})=>{let i=n/2,a=r/2;return`M${F(e+i-i)},${F(t+a)}a${F(i)},${F(a)} 0 1,0 ${F(i*2)},0a${F(i)},${F(a)} 0 1,0 ${F(-i*2)},0Z`},hi=(e,t)=>Math.min(t,e.w/2,e.h/2),gi={name:`shapes`,shapes:[{name:`rounded`,aliases:[`round`],path:(e,t)=>Nn(e.x,e.y,e.w,e.h,hi(e,t))},{name:`box`,aliases:[`rect`,`rectangle`,`square`],path:(e,t)=>Nn(e.x,e.y,e.w,e.h,Math.min(hi(e,t),3))},{name:`pill`,aliases:[`stadium`,`capsule`],size:(e,t)=>{let{w:n,h:r}=fi(e,t);return{w:Math.max(n+8,96),h:Math.max(r,44)}},path:e=>Nn(e.x,e.y,e.w,e.h,e.h/2),port:(e,t,n)=>Fn(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:mi,port:pi},{name:`ellipse`,aliases:[`oval`],size:(e,t)=>({w:Math.max((e+16)*1.42,90),h:Math.max((t+12)*1.42,50)}),path:mi,port:pi},{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${F(e+n/2)},${F(t)}L${F(e+n)},${F(t+r/2)}L${F(e+n/2)},${F(t+r)}L${F(e)},${F(t+r/2)}Z`,port:(e,t,n)=>Fn(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}=fi(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${F(e+i)},${F(t)}L${F(e+n-i)},${F(t)}L${F(e+n)},${F(t+r/2)}L${F(e+n-i)},${F(t+r)}L${F(e+i)},${F(t+r)}L${F(e)},${F(t+r/2)}Z`},port:(e,t,n)=>Fn(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}=fi(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${F(e)},${F(t+i)}a${F(a)},${F(i)} 0 0,1 ${F(n)},0L${F(e+n)},${F(t+r-i)}a${F(a)},${F(i)} 0 0,1 ${F(-n)},0Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6);return`M${F(e)},${F(t+i)}a${F(n/2)},${F(i)} 0 0,0 ${F(n)},0`},port:(e,t,n)=>Fn(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}=fi(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${F(e+i)},${F(t)}L${F(e+n)},${F(t)}L${F(e+n-i)},${F(t+r)}L${F(e)},${F(t+r)}Z`}},{name:`document`,aliases:[`doc`],textOffset:-4,size:(e,t)=>{let{w:n,h:r}=fi(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=hi(e,t),s=Math.min(8,a/6);return`M${F(n+o)},${F(r)}L${F(n+i-o)},${F(r)}Q${F(n+i)},${F(r)} ${F(n+i)},${F(r+o)}L${F(n+i)},${F(r+a-s)}C${F(n+i*.75)},${F(r+a-s*3)} ${F(n+i*.25)},${F(r+a+s)} ${F(n)},${F(r+a-s)}L${F(n)},${F(r+o)}Q${F(n)},${F(r)} ${F(n+o)},${F(r)}Z`}},{name:`note`,aliases:[`sticky`],size:(e,t)=>{let{w:n,h:r}=fi(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${F(e)},${F(t)}L${F(e+n-i)},${F(t)}L${F(e+n)},${F(t+i)}L${F(e+n)},${F(t+r)}L${F(e)},${F(t+r)}Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${F(e+n-i)},${F(t)}L${F(e+n-i)},${F(t+i)}L${F(e+n)},${F(t+i)}`}},{name:`text`,aliases:[`label`,`plain`,`none`],size:(e,t)=>({w:e+12,h:t+8}),path:(e,t)=>Nn(e.x,e.y,e.w,e.h,hi(e,t))}]},_i=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return(t,i)=>`${F(e.x+t*n-i*r)},${F(e.y+t*r+i*n)}`},vi={name:`markers`,markers:[{name:`arrow`,inset:e=>e*.8,render(e,t,{color:n,width:r,size:i}){let a=_i(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="${F(r*.5)}" stroke-linejoin="round"/>`}},{name:`open`,inset:(e,t)=>t*.8,render(e,t,{color:n,width:r,size:i}){let a=_i(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="${F(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]=_i(e,t)(-i,0).split(`,`);return`<circle cx="${a}" cy="${o}" r="${F(i)}" fill="${n}"/>`}},{name:`diamond`,inset:e=>e*1.6,render(e,t,{color:n,size:r}){let i=_i(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=_i(e,t);return`<path d="M${a(-4,i*.6)}L${a(-4,-i*.6)}" stroke="${n}" stroke-width="${F(r*1.2)}" stroke-linecap="round"/>`}}]},yi={name:`themes`,themes:[me(`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:g,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=>u[e]&&{fill:`#0f3460`,stroke:m(e,300),text:m(e,100)},groupTone:e=>u[e]&&{fill:`none`,stroke:m(e,400),text:m(e,200)},edgeTone:e=>m(e,300)},{name:`mono`,dark:!1,background:`#ffffff`,font:h,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=>u[e]&&{fill:m(e,100),stroke:`#18181b`,text:`#18181b`},groupTone:e=>u[e]&&{fill:m(e,50),stroke:`#a1a1aa`,text:`#52525b`},edgeTone:e=>m(e,700)},{name:`pastel`,dark:!1,background:`#fdfcff`,font:h,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=>u[e]&&{fill:m(e,100),stroke:m(e,100),text:m(e,900)},groupTone:e=>u[e]&&{fill:m(e,50),stroke:m(e,50),text:m(e,700)},edgeTone:e=>m(e,300)},{name:`terminal`,dark:!0,background:`#0c0c10`,font:g,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=>u[e]&&{fill:m(e,950),stroke:m(e,700),text:m(e,200)},groupTone:e=>u[e]&&{fill:m(e,950)+`66`,stroke:m(e,900),text:m(e,300)},edgeTone:e=>m(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=>u[e]&&{fill:m(e,100),stroke:m(e,400),text:m(e,900)},groupTone:e=>u[e]&&{fill:m(e,100)+`99`,stroke:m(e,300),text:m(e,800)},edgeTone:e=>m(e,600)},me(`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:h,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=>u[e]&&{fill:m(e,100),stroke:m(e,800),text:m(e,950)},groupTone:e=>u[e]&&{fill:m(e,50),stroke:m(e,800),text:m(e,900)},edgeTone:e=>m(e,700)},me(`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)`}),me(`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:h,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=>u[e]&&{fill:m(e,900)+`cc`,stroke:m(e,500),text:m(e,100)},groupTone:e=>u[e]&&{fill:m(e,950)+`80`,stroke:m(e,900),text:m(e,300)},edgeTone:e=>m(e,300)}]},bi=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function xi(e){let t=1/0,n=-1/0;for(let r of e)r<t&&(t=r),r>n&&(n=r);return[t,n]}var Si=(e,t)=>I(e,t.theme,t.theme.accent),Ci=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${be}))?:\\s*(.*)$`)),wi={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=Ci(`bars`,e);return t?{kind:`bars`,values:bi(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(xi(e.values)[1],0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=Si(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${F(t.x+n*r*.85)}" y="${F(a-c)}" width="${F(r*.55)}" height="${F(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},Ti={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=Ci(`spark`,e);return t?{kind:`spark`,values:bi(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]=xi(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`}${F(e)},${F(t)}`).join(``),p=Si(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${F(t.x+t.w)},${F(l)}L${F(t.x)},${F(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="${F(m)}" cy="${F(h)}" r="2.6" fill="${p}"/>`}},Ei={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=Ci(`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:N(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:N(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:L(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=Si(e.color,n);return $e(e.label,t.x,s,r,a,o)+Je(t.x+t.w,s,r,a.sub,P(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${F(t.x)}" y="${F(c)}" width="${F(t.w)}" height="${F(l)}" rx="${F(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${F(t.x)}" y="${F(c)}" width="${F(Math.max(l,t.w*e.ratio))}" height="${F(l)}" rx="${F(l/2)}" fill="${u}"/>`:``)}},Di=1.75,Oi={name:`charts`,rows:[wi,Ti,Ei,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=Ci(`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:N(t),label:N(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*Di;return e.ws=e.items.map(e=>Math.max(L(e.value,i,n,r,700),L(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*Di,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:Si(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${F(e)},${F(t.y+r*.3)}V${F(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push($e(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push($e(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},ki=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function Ai(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}var ji=e=>e*1.8,Mi={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=Ai(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(N);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=>!Ge(e[t])||ki.test(Ge(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=>L(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+ji(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]-Ze(t):d;o.push($e(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+ji(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${F(t.x)},${F(e)}H${F(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},Ni=[`#ff5f57`,`#febc2e`,`#28c840`],Pi=e=>Math.round(e*2.3);function Fi(e,t,n,r,i){let a=Pi(t),o=Math.min(n,a/2,e.w/2),s=`M${F(e.x)},${F(e.y+a)}V${F(e.y+o)}A${F(o)},${F(o)} 0 0 1 ${F(e.x+o)},${F(e.y)}H${F(e.x+e.w-o)}A${F(o)},${F(o)} 0 0 1 ${F(e.x+e.w)},${F(e.y+o)}V${F(e.y+a)}Z`,c=t*.3,l=Ni.map((n,r)=>`<circle cx="${F(e.x+t+r*c*3.3)}" cy="${F(e.y+a/2)}" r="${F(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${F(e.x)},${F(e.y+a)}H${F(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}var Ii=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,Li={name:`browser`,inset:e=>({top:Pi(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=Pi(a),s=Ii(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="${F(s)}" y="${F(u)}" width="${F(c-s)}" height="${F(l)}" rx="${F(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?Je(s+a*.7,e.y+o/2,d,n.sub,P(r)):``):``;return`<g class="frame">${Fi(e,a,i,n.stroke,t.dark)}${f}</g>`}},Ri=(e,t)=>({name:e,inset:e=>({top:Pi(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=Pi(o),c=i?Je(e.x+e.w/2,e.y+s/2,o*.78,r.sub,P(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${Fi(e,o,a,r.stroke,n.dark)}${c}</g>`}}),zi={name:`frames`,frames:[Li,Ri(`window`,``),Ri(`terminal`,`❯ `)],props:{node:[`frame`]}},Bi=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),Vi=new Map,Hi=(e,t,n)=>`${t}|${n}|${e}`;function Ui(e,t,n,r){return e.map(e=>L(N(e),t,n,r))}var Wi={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=Bi(e);if(!r.length)return null;let i=t.fontSize*.82,a=Ui(r,i,t.mono,n);Vi.size>64&&Vi.clear(),Vi.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=Bi(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=Ce(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${F(c)},${F(t.y)}H${F(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=Vi.get(Hi(e,a,n.mono))??Ui(i,a,n.mono,zr),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="${F(m)}" y="${F(o)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(N(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},Gi=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function Ki(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return Gi.test(t)?{kind:`arrow`,key:t,label:r}:t.startsWith(`.`)?{kind:`class`,key:t.slice(1),label:r||t.slice(1)}:{kind:`color`,key:t,label:r||t}})}var qi=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 Ji(e,t,n){let{fs:r,sw:i,gap:a}=qi(t);return e.map(e=>i+a+L(N(e.label),r,t.mono,n))}function Yi(e,t,n,r,i){let{sw:a,sh:o}=qi(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="${F(o*3)} ${F(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${F(o)} ${F(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${F(t)},${F(n)}H${F(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${F(o)}"${s} fill="none"/>`+(c?`<path d="M${F(u)},${F(n)}L${F(u-l)},${F(n-l*.5)}L${F(u-l)},${F(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${F(t)},${F(n)}L${F(t+l)},${F(n-l*.5)}L${F(t+l)},${F(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=ut(i,t),a=ht(i,t,n,r),o=Dn(n.shape??i.settings.shape);return`<path d="${jn(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??M(e.key,r,400)??r.node.fill,u=c?.stroke??M(e.key,r,600)??r.node.stroke;return`<rect x="${F(s.x)}" y="${F(s.y)}" width="${F(s.w)}" height="${F(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function Xi(e,t,n){let r=[[]],i=0;return e.forEach((e,a)=>{let o=r[r.length-1];o.length&&i+n+e>t?(r.push([a]),i=e):(o.push(a),i+=(o.length>1?n:0)+e)}),r}var Zi=760,Qi={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=Ki(e);if(!n.length)return null;let{fs:r,space:i}=qi(t),a=Ji(n,t,zr),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=Xi(a,Zi,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,Zi)}},render(e,t,n,{pad:r,d:i}){let a=Ki(e),{fs:o,gap:s,space:c,sw:l}=qi(n),u=Ji(a,n,zr),d=Ce(n),f=[];return Xi(u,Math.min(Zi,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(Yi(e,m,h,n,i)),e.label&&f.push(`<text x="${F(m+l+s)}" y="${F(h)}" dominant-baseline="central" font-size="${F(o)}" xml:space="preserve">${R(N(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},$i=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,ea=/^(?:m|note|d)\d+$/,ta=new RegExp(String.raw`^(${$i})\s*(-->|->|\.\.>|=>)\s*(${$i})\s*(?::\s*(.*))?$`,`u`),na=new RegExp(String.raw`^(${$i}\s*(?:-->|->|\.\.>|=>)\s*${$i})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),ra=String.raw`${$i}(?:\s+"[^"]*")?(?:\s*\[[^\]]*\])?`,ia=new RegExp(String.raw`^(participant|actor)\s+(${ra}(?:\s*,\s*${ra})*)$`,`u`),aa=new RegExp(String.raw`(${$i})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?`,`gu`),oa=new RegExp(String.raw`^note\s+(${$i}(?:\s*,\s*${$i})*)\s*:\s*(.*)$`,`u`),sa=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,ca=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],la=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>ca.includes(e))&&(!e.color||ye(e.color))},ua=e=>ri(e,la),da={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function fa(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(ia)){let e=[...c[2].matchAll(aa)];for(let[,t,n,r]of e){let i=o(t);i.actor=c[1]===`actor`,e.length===1?i.decl=a:i.list??=a,n!==void 0&&(i.label=n);let s=r&&H(r).color;s&&(i.tone=s)}}else if(c=r.match(oa)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=ua(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(ta)){o(c[1]),o(c[3]);let[e,t]=ua(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:da[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(sa))?i.push({kind:`divider`,text:c[1]}):(c=r.match(na))?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(!ea.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 pa(e){let t={note:0,divider:0};return e.steps.map(e=>e.kind===`msg`?`m${e.n}`:e.kind===`note`?`note${++t.note}`:`d${++t.divider}`)}var ma=Cr(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=>L(N(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=pa(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 ha(e,t){let n=mt(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function ga(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=ma(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=Ce(r),d=n.props,f=M(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=ha(tt(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${F(c(t))},${F(h+o)}V${F(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="${F(c(a)-l/2)}" y="${F(t)}" width="${F(l)}" height="${F(o)}" rx="${F(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${F(r.strokeWidth)}"/><text x="${F(c(a))}" y="${F(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${F(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${P(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=tt(n,`style`)??(o.line===`thick`?`solid`:o.line),d=et(n.width,o.line===`thick`||j(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=ha(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=N(i.num(o)+o.text),g=I(o.tone,r,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${F(t)},${F(n)}H${F(t+26-8)}Q${F(t+26)},${F(n)} ${F(t+26)},${F(n+8)}V${F(i-8)}Q${F(t+26)},${F(i)} ${F(t+26-8)},${F(i)}H${F(t+2)}" fill="none" stroke="${g}" stroke-width="${F(d)}"${f}/>`),m.push(wn({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${F(t+34)}" y="${F((n+i)/2)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${F(c(e))},${F(s)}H${F(c(t)-n*2)}" stroke="${g}" stroke-width="${F(d)}"${f}/>`),m.push(wn({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="${F((c(e)+c(t))/2)}" y="${F(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" xml:space="preserve">${R(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="${F(l)}" y="${F(p)}" width="${F(u-l)}" height="${F(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${F((l+u)/2)}" y="${F(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" xml:space="preserve">${R(N(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${F(t.x)},${F(n)}H${F(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${F(c-s/2)}" y="${F(n-a*.85)}" width="${F(s)}" height="${F(a*1.7)}" rx="${F(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${F(c)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.92)}" font-weight="600" fill="${r.node.sub}">${P(o.text)}</text>`))}v+=e}return m.join(``)}function _a(e,t,n){if(!e.parts.length)return[];let r=ma(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}var va={name:`sequence`,panels:[{name:`sequence`,guide:'`participant|actor id "Label" [color]` (`participant a "A", b, c` lists several and 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:fa,measure(e,t){let n=ma(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:ga,handles:_a,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=pa(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:wr((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]=ii(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${si({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=pa(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=ua(e[s.at]),u=c;delete l.color;let d=si(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})}]},ya=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],ba=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function xa(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}var Sa=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,Ca=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function wa(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]=ri(i,ai),c=o.match(Sa);c?r.push({when:c[1].trim(),tone:s.color??H(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function Ta(e){let t=new Set;return e.map((e,n)=>{let r=!/\s/.test(e.when)&&!t.has(e.when)&&!/^e\d+$/.test(e.when)?e.when:`e${n+1}`;return t.add(r),r})}function Ea(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#|[-*]\s)/.test(r)&&Sa.test(ri(r,ai)[0])&&t.push(n)}),t}var Da=Cr(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)=>L(N(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>xa(e.details.map(e=>s(e,a*.92)),s(e.title,a,600))),u=e.map(e=>1+e.details.length),d=Ta(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=xa(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+xa(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+xa(u,1)*a*1.45}});function Oa(e,t,n){if(!e.length)return``;let r=n.theme,i=Da(e,n),{fs:a}=i,o=Ce(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=I(n.tone,r,r.accent);return`<circle cx="${F(e)}" cy="${F(t)}" r="${F(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${F(e)}" cy="${F(t)}" r="${F(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${F(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${R(N(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${F(n)},${F(t.y+a*.5)}V${F(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="${F(n-16)}" y="${F(s)}" dominant-baseline="central" text-anchor="end" font-size="${F(a*.9)}" font-weight="600" fill="${I(e.tone,r,r.node.sub)}">${P(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${F(t.x)},${F(d)}H${F(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="${F(o)}" y="${F(t.y+a*.5)}" dominant-baseline="central" font-size="${F(a*.9)}" font-weight="600" fill="${I(e.tone,r,r.node.sub)}">${P(e.when)}</text>`),c.push(l(o+a*.42,d,e)),c.push(u(o,d+a*1.55,e.title,a,600,`start`,!1)),e.details.forEach((e,t)=>c.push(u(o,d+a*1.55+(t+1)*a*1.45,e,a*.92,400,`start`,!0)))}),c.join(``)}var ka={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:wa,measure(e,t){if(!e.length)return{w:0,h:0};let n=Da(e,t);return{w:n.w,h:n.h}},render:Oa,parts:e=>Ta(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:wr((e,t,n,r)=>{let i=Ea(e)[Ta(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=oi(e[i],Ca,`color`,n,ai),a}),handles(e,t,n){if(!e.length)return[];let r=Da(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}`})}}]},Aa=[`bar`,`column`,`line`,`pie`,`donut`],ja=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,Ma=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,Na=1e300;function Pa(e,t,n){let r=t.type??`bar`;Aa.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${Aa.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=ri(r,ai),s=a.match(ja),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=Na)?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??H(s[2]).color,value:c}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:Aa.includes(r)?r:`bar`,items:i}}var Fa=(e,t=``)=>`${Math.abs(e)<1e15?Math.round(e*100)/100:e}${t}`;function Ia(e,t,n,r){return e.tone?I(e.tone,n.theme,n.theme.accent):r?m(ya[t%ya.length],n.theme.dark?400:500):n.theme.accent}var La=Cr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=xa(e.items.map(e=>r(e.label,a,400,n.mono)),0),c=xa(e.items.map(e=>r(Fa(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 Ra(e,t,n,r,i,a){let o=(n,r)=>`${F(e+n*Math.sin(r))},${F(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return Ra(e,t,n,r,o,a)+Ra(e,t,n,o,i,a)}return a?`M${o(n,r)}A${F(n)},${F(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${F(a)},${F(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${F(e)},${F(t)}L${o(n,r)}A${F(n)},${F(n)} 0 ${s} 1 ${o(n,i)}Z`}function za(e,t,n){if(!e.items.length)return``;let r=n.theme,i=La(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${F(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${P(n)}</text>`,l=xa(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="${Ra(l,u,i.r,p,a,d)}" fill="${Ia(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,Fa(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="${F(m)}" y="${F(g-a*.45)}" width="${F(a*.9)}" height="${F(a*.9)}" rx="2.5" fill="${Ia(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,Fa(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="${F(u)}" y="${F(p-a*.55)}" width="${F(d)}" height="${F(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${F(u)}" y="${F(p-a*.55)}" width="${F(m)}" height="${F(a*1.1)}" rx="3" fill="${Ia(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,Fa(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${F(t.x)},${F(n)}H${F(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="${F(d(i)-t/2)}" y="${F(l)}" width="${F(t)}" height="${F(Math.max(2,u-l))}" rx="3" fill="${Ia(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,Fa(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${F(d(t))},${F(f(e.value))}`);s.push(`<path d="M${F(d(0))},${F(u)}L${t.join(`L`)}L${F(d(e.items.length-1))},${F(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=Ia(e,t,n,!1);s.push(`<circle cx="${F(d(t))}" cy="${F(f(e.value))}" r="${F(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,Fa(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${F(t.x)},${F(u)}H${F(t.x+t.w)}" stroke="${r.node.stroke}" stroke-width="1"/>`),e.items.forEach((e,t)=>s.push(c(d(t),u+a*1.1,e.label,`middle`,r.node.sub))),s.join(``)}var Ba={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:Pa,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=La(e,t);return{w:n.w,h:n.h}},render:za,options:{type:[...Aa],unit:`text`},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:wr((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim();return!/^(\/\/|#)/.test(n)&&ja.test(ri(n,ai)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=oi(e[i],Ma,`color`,n,ai),a}),handles(e,t,n){if(!e.items.length)return[];let r=La(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},Va=[`normal`,`highlight`,`reverse`],Ha=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,Ua=String.raw`(?:\s*\[([^\]]*)\])?`,Wa=new RegExp(String.raw`^commit(?:\s+(.*?))?${Ua}$`,`u`),Ga=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${Ha})(?:\s+from\s+(\S+))?${Ua}$`,`u`),Ka=new RegExp(String.raw`^(?:checkout|switch)\s+(${Ha})$`,`u`),qa=new RegExp(String.raw`^merge\s+(${Ha})(?:\s+(.*?))?${Ua}$`,`u`),Ja=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${Ua}$`,`u`),Ya=/^tag\s+(\S+)$/;function Xa(e){let t=H(e??``);for(let e of Va)t[e]===`true`&&(t.type=e,delete t[e]);return t}function Za(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&&!Va.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${Va.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(Ka)){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(qa)){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:di(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},Xa(u[3]),t)}else if(u=l.match(Ja)){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:di(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},Xa(u[3]),t)}else(u=l.match(Ya))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(Wa))?c({msg:di(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 Qa(e,t,n){let r=e.branches[t]?.tone;return r?I(r,n.theme,n.theme.accent):m(ya[t%ya.length],n.theme.dark?400:500)}function $a(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})}var eo=Cr(to);function to(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=$a(e),l=e=>s[e]?.x??0,u=e=>L(N(e),a,n.mono,r),d=e=>r(e,a*.82,600,n.mono)+a*1.1,f=a*.5,p=e=>(e.order??e.lane)-(e.order===void 0?0:.5),m=new Set(e.commits.map(e=>e.lane)),h=e.branches.filter(e=>m.has(e.lane)).sort((e,t)=>p(e)-p(t)),g=new Map(h.map((e,t)=>[e.lane,t])),_=o?a*1.7:a*4,v=[];h.forEach((e,t)=>{let n=Math.max(t?f*3-_:0,l(e.name));v.push((t?v[t-1]+_:0)+n)});let y=v[v.length-1]??0,b=o?e.commits.map(()=>a*2.1):e.commits.map(e=>Math.max(a*2.6,u(e.msg)+a*2,...e.tags.map(e=>d(e)+a*.6))),x=o?0:Math.max(0,...h.map(e=>r(e.label??e.name,a,600,n.mono)))+a*1.4,S=[];b.forEach((e,t)=>{let n=t?S[t-1]+b[t-1]/2:x,r=Math.max(f*3-(t?b[t-1]/2:0)-e/2,l(c[t]));S.push(n+e/2+r)});let C=e.commits.length?S[S.length-1]+b[b.length-1]/2:0,w={fs:a,r:f,vertical:o,parts:c,off:s,used:h,slot:g,pillW:d,textW:u,spans:b,at:S,gap:e=>(S[e-1]+b[e-1]/2+S[e]-b[e]/2)/2,lanePos:v};if(o){let t=_,n=y+t+a*.6,i=new Map;for(let e of h)i.set(e.head,[...i.get(e.head)??[],e]);let o=e.commits.map((e,t)=>{let n=[...(i.get(t)??[]).map(e=>e.label??e.name),...e.tags].reduce((e,t)=>e+d(t)+a*.4,0);return(e.id?r(e.id,a,400,!0)+a*.6:0)+n+u(e.msg)}),s=e.commits.map((e,n)=>({x:t/2+v[g.get(e.lane)??0],y:S[n]}));return{...w,laneW:t,textX:n,heads:i,labelW:x,top:0,pos:s,w:n+Math.max(0,...o),h:C}}let T=Math.max(0,...e.commits.filter(e=>g.get(e.lane)===0).map(e=>e.tags.length)),E=a*.6+T*a*1.5,D=e.commits.map((e,t)=>({x:S[t],y:E+v[g.get(e.lane)??0]}));return{...w,laneW:0,textX:0,heads:new Map,labelW:x,top:E,pos:D,w:C,h:E+y+a*2}}var no=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function ro(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${F(h.x)},${F(h.y)}L${F(g.x)},${F(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=no((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${F(h.x)},${F(h.y)}V${F(t-e)}C${F(h.x)},${F(t)} ${F(g.x)},${F(t)} ${F(g.x)},${F(t+e)}V${F(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=no((m?g.x-b(f,!y)-r*.7:h.x+b(p,y)+r*.7)+v,h.x+x,g.x-x);d.push({i:f,k:m,part:_,handle:{x:S,y:(h.y+g.y)/2},d:`M${F(h.x)},${F(h.y)}H${F(S-x)}C${F(S)},${F(h.y)} ${F(S)},${F(g.y)} ${F(S+x)},${F(g.y)}H${F(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${F(i.x)},${F(i.y)}Q${F(e)},${F(n)} ${F(c.x)},${F(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${F(i.x)},${F(i.y)}C${F(p)},${F(i.y+u.y)} ${F(p)},${F(c.y+u.y)} ${F(c.x)},${F(c.y)}`})}),{lanes:u,bends:d,picks:f}}function io(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=eo(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=Ce(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="${F(u)}" y="${F(t-d/2)}" width="${F(l)}" height="${F(d)}" rx="${F(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${F(u+l/2)}" y="${F(t)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.82)}" font-weight="600" fill="${o?s:r}">${P(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="${F(t.x)}" y="${F(o)}" dominant-baseline="central" font-size="${F(a)}" font-weight="600" fill="${Qa(e,r.lane,n)}">${P(r.label??r.name)}</text>`)}let f=Math.max(2,r.edgeWidth*1.4),p=ro(e,i,t),m=(t,r)=>Qa(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="${Qa(e,e.commits[t.i].lane,n)}" stroke-width="${F(f*.7)}" stroke-dasharray="${F(f*1.6)} ${F(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="${F(f)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((p,m)=>{let{x:h,y:_}=u[m],v=I(p.tone,r,Qa(e,p.lane,n));if(p.type===`highlight`){let e=o*1.1;l.push(`<rect x="${F(h-e)}" y="${F(_-e)}" width="${F(e*2)}" height="${F(e*2)}" rx="${F(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${F(f)}"/>`)}else if(p.type===`reverse`){let e=o*.55;l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}"/><path d="M${F(h-e)},${F(_-e)}L${F(h+e)},${F(_+e)}M${F(h+e)},${F(_-e)}L${F(h-e)},${F(_+e)}" stroke="${v}" stroke-width="${F(f*.8)}" stroke-linecap="round"/>`)}else p.merge?l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o*1.05)}" fill="${v}"/><circle cx="${F(h)}" cy="${F(_)}" r="${F(o*.4)}" fill="${s}"/>`):p.pick===void 0?l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}"/>`):l.push(`<circle cx="${F(h)}" cy="${F(_)}" r="${F(o)}" fill="${s}" stroke="${v}" stroke-width="${F(f)}" stroke-dasharray="${F(f*1.2)} ${F(f)}"/>`);if(i.vertical){let o=t.x+i.textX;p.id&&(l.push(`<text x="${F(o)}" y="${F(_)}" dominant-baseline="central" font-size="${F(a)}" font-family="${P(g)}" fill="${r.node.sub}">${P(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,_,r,Qa(e,t.lane,n),!1,`start`)),o+=i.pillW(r)+a*.4}for(let e of p.tags)l.push(d(o,_,e,v,!0,`start`)),o+=i.pillW(e)+a*.4;p.msg&&l.push(`<text x="${F(o)}" y="${F(_)}" dominant-baseline="central" font-size="${F(a)}" xml:space="preserve">${R(N(p.msg),c,r,p.merge)}</text>`)}else p.tags.forEach((e,t)=>l.push(d(h,_-a*1.45-t*a*1.5,e,v,!0,`middle`))),p.msg&&l.push(`<text x="${F(h)}" y="${F(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${R(N(p.msg),c,r,p.merge)}</text>`)}),l.join(``)}var ao={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:Za,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})),...$a(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:wr((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[$a(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=ii(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=eo(e,t);return{w:n.w,h:n.h}},render:io,handles(e,t,n){if(!e.commits.length)return[];let r=eo(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=ro(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`}))]}}]},oo=[`box`,`pill`,`plain`,`circle`],so=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],co=/^[-*+]\s+/,lo=e=>it(e)!==void 0,uo={color:ye,shape:()=>!0,text:ye,"font-size":lo,"font-weight":lo},fo=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>uo[t]?.(e[t]))},po=e=>ri(e,fo);function mo(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]=po(o.replace(co,``));l.shape&&!oo.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${oo.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:it(l[`font-size`]),weight:it(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 ho(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}var go=e=>e.reduce((e,t)=>Math.min(e,t),1/0),_o=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function vo(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return e.map((e,n)=>/^[\w-]+$/.test(e.text)&&t.get(e.text)===1&&!/^n\d+$/.test(e.text)?e.text:`n${n+1}`)}var yo=[`both`,`vertical`,`right`,`left`,`down`,`up`],bo=Cr(function(e,t){let{theme:n,measure:r,props:i}=t,a=it(i[`font-size`])??t.fs*.9,o=yo.includes(i.layout)?i.layout:`both`,s=o===`down`||o===`up`||o===`vertical`,c=i.colors===`mono`,l=ho(e),u=vo(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=new Map,p=(e,t,i,o)=>{let s=oo.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=L(N(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:so[n%so.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,_=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=go(D.map(e=>e.x)),k=go(D.map(e=>e.y));for(let e of D)e.x-=O,e.y-=k;return{all:D,vert:s,w:_o(D.map(e=>e.x+e.w)),h:_o(D.map(e=>e.y+e.h))}}),xo=(e,t)=>I(t,e,e.accent);function So(e,t,n){if(!e)return``;let r=n.theme,i=bo(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=xo(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${F(s(n))},${F(c(r))}C${F(s(n))},${F(c((r+u)/2))} ${F(s(o))},${F(c((r+u)/2))} ${F(s(o))},${F(c(u))}`:`M${F(s(n))},${F(c(r))}C${F(s((n+o)/2))},${F(c(r))} ${F(s((n+o)/2))},${F(c(u))} ${F(s(o))},${F(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${F(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=M(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${F(m)},${F(h+e.h)}H${F(m+e.w)}" stroke="${t}" stroke-width="${F(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="${F(m)}" y="${F(h)}" width="${F(e.w)}" height="${F(e.h)}" rx="${F(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="${F(m+e.w/2)}" y="${F(g)}" dominant-baseline="central" text-anchor="middle" font-size="${F(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${R(N(e.node.text),Ce(r,p,f),r)}</text>`)}return a.join(``)+o.join(``)}var Co={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:yo,colors:[`branches`,`mono`]},parse:mo,measure(e,t){if(!e)return{w:0,h:0};let n=bo(e,t);return{w:n.w,h:n.h}},render:So,parts(e){if(!e)return[];let t=ho(e),n=new Map([[e,0]]);for(let e of t)for(let t of e.children)n.set(t,n.get(e)+1);return vo(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:wr((e,t,n,r)=>{if(!r)return null;let i=ho(r),a=i[vo(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=po(e[a.line]),u=si(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=bo(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}}]},wo=864e5,To=864e13,Eo=1e3,Do=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Oo=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,ko=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,Ao=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function jo(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=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 Mo(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:wo,w:7*wo}[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(Ao);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?H(t[2]).color:void 0);return}let[l,u]=ri(s),d=l.match(Oo);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={...H(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]??``,S=jo(x);/^after\s/i.test(x)?(v.after=x.slice(6).trim().split(/\s+/),b=1):Number.isNaN(S)?x&&Number.isNaN(Mo(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=S,b=1);let C=y[b];C===void 0?!_&&x&&n(t,`gantt: task "${f}" needs a length, e.g. "${x}, 3d"`):(v.len=Mo(C),Number.isNaN(v.len)&&(v.endDate=jo(C),Number.isNaN(v.endDate)&&n(t,`gantt: "${C}" is not a length (3h, 5d, 2w) or an end date`)));let w=g.progress===void 0?NaN:parseFloat(g.progress)/(g.progress.endsWith(`%`)?100:1);g.progress!==void 0&&!(w>=0&&w<=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,progress:Math.min(1,Math.max(0,w)),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+wo:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=To||(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 Po(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!Ao.test(r)&&Oo.test(ri(r)[0])&&t.push(n)}),t}var Fo=e=>{let t=new Date(e);return`${Do[t.getUTCMonth()]} ${t.getUTCDate()}`},Io=e=>{let t=e/wo;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 Lo(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/wo)*wo;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=wo;for(;o<=t&&i.length<2e3&&Number.isFinite(new Date(o).getTime());o+=a*wo)i.push({t:o,label:Fo(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>=2e3)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${Do[c]} ${s}`:Do[c]}),l=!1,c+=a}return i}return i}function Ro(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`}var zo={compact:1.6,normal:2.1,loose:2.7},Bo=Cr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(zo[i.density??``]??zo.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>L(N(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/wo)*wo,_=Math.max(g+wo,Math.ceil(e.max/wo)*wo),v=(_-g)/wo,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*Eo/v),x=e=>h+(e-g)/wo*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?`${Fo(e.start)} – ${Fo(e.end)}`:e.milestone?Fo(e.start):Io(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 Vo(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${F(n[0][0])},${F(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${F(u[0])},${F(u[1])}Q${F(a[0])},${F(a[1])} ${F(d[0])},${F(d[1])}`}let i=n[n.length-1];return`${r}L${F(i[0])},${F(i[1])}`}function Ho(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=Bo(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f=Ce(r),p=(e,t,n,i,a,s=!1)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${F(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${R(N(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${F(o*.82)}" font-weight="500" fill="${r}">${P(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/864e5<=3660)for(let e=a.min;e<a.max;e+=wo){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${F(c(e))}" y="${F(t.y+a.axisH*.8)}" width="${F(a.dayW)}" height="${F(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/wo)*wo:jo(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${Fo(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 Lo(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${F(s)},${F(t.y+a.axisH*.75)}V${F(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${F(p)}" y="${F(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${F(o*.82)}" fill="${r.node.sub}">${P(e.label)}</text>`)}d.push(`<path d="M${F(t.x+a.labelW)},${F(t.y+a.axisH*.75)}H${F(t.x+a.labelW+a.plotW)}" stroke="${u}" stroke-width="1.5"/>`);let x=new Map;for(let e of a.rows)e.task!==void 0&&x.set(e.task,e.y);let S=e=>t.y+x.get(e),C=e=>S(e)+a.rowH/2,w=t=>t.tone??e.sectionTones[t.section]??(t.crit?`red`:void 0),T=a.labelW+a.plotW;if(i.rows!==`plain`){let e=0;for(let n of a.rows)n.section===void 0?e++%2&&d.push(`<rect x="${F(t.x-o*.4)}" y="${F(t.y+n.y)}" width="${F(T+o*.4)}" height="${F(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=I(e.sectionTones[n.section],r,r.node.sub);d.push(`<path d="M${F(t.x)},${F(t.y+n.y+1)}H${F(t.x+T)}" stroke="${u}" stroke-width="1" opacity="0.6"/>`,p(t.x,s,e.sections[n.section],700,l));let f=e.tasks.filter(e=>e.section===n.section);if(f.length&&i.summary!==`hide`){let e=c(Math.min(...f.map(e=>e.start))),t=Math.max(e+2,c(Math.max(...f.map(e=>e.end)))),n=o*.32;d.push(`<path d="M${F(e)},${F(s+n*1.6)}V${F(s-n/2)}H${F(t)}V${F(s+n*1.6)}" fill="none" stroke="${l}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${F(e)}" y="${F(s-n/2)}" width="${F(t-e)}" height="${F(n)}" fill="${l}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${F(c(h))},${F(t.y+a.axisH*.35)}V${F(l)}" stroke="${I(`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${F(g)},${F(_)}C${F(g+e)},${F(_)} ${F(b-e)},${F(y)} ${F(b)},${F(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=Vo([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=Vo([[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="${F(l)}" stroke-linejoin="round"/>`,wn({x:v,y},0,`arrow`,s,l,u))}})}let E=i.bars===`solid`||i.bars===`outline`||i.bars===`thin`?i.bars:`soft`,D=new Map,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`?Ro(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=I(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${F(t)},${F(s-a.ms)}L${F(t+a.ms)},${F(s)}L${F(t)},${F(s+a.ms)}L${F(t-a.ms)},${F(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?I(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${F(v)}" y="${F(x)}" width="${F(e)}" height="${F(b)}" rx="${F(S)}" ${t}${h}/>`,ee=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,te=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,ne=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(k(y,`fill="${te}"${ne}${ee?` stroke="${T}" stroke-width="${ee}"`:``}`));let A=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;A&&d.push(k(A,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-A>2&&d.push(`<rect x="${F(v+A)}" y="${F(x)}" width="${F(y-A)}" height="${F(b)}" rx="${F(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+A-o*.2)?Ro(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=I(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${F(b)}" y="${F(n-o*.55)}" width="${F(v)}" height="${F(o*1.1)}" rx="${F(o*.55)}" fill="${e}"/>`,`<text x="${F(b+v/2)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(o*.72)}" font-weight="650" fill="${Ro(e)}">${P(_)}</text>`)}return d.join(``)}function Uo(e,t){if(!e.tasks.length)return{w:0,h:0};let n=Bo(e,t);return{w:n.w,h:n.h}}function Wo(e,t,n){if(!e.tasks.length)return[];let r=Bo(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}`}])}var Go={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:Uo,render:Ho,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:wr((e,t,n,r)=>{let i=Po(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=oi(e[i],ko,`color`,n),a}),handles:Wo}]},Ko=/^([xy])-axis\s*:?\s*(.*)$/i,qo=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,Jo=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,Yo=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,Xo=[`teal`,`blue`,`slate`,`amber`];function Zo(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(Ko);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=ri(a,ai),l=s.match(qo);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??H(l[2]).color};return}let u=s.match(Jo);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??H(u[2]).color,x:+u[3],y:+u[4],line:t})});let a=i.some(e=>e.x>1||e.y>1)?100:1;r.scale=a;let o=new Set;return i.forEach((e,t)=>{let i=e.x/a,s=e.y/a;(i<0||i>1||s<0||s>1)&&(n(e.line,`quadrant: "${e.name}" is outside the chart (values go from 0 to ${a})`),i=Math.min(1,Math.max(0,i)),s=Math.min(1,Math.max(0,s)));let c=ba(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 Qo(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]=ri(l,ai),d=new RegExp(Jo,`d`).exec(u.trimEnd());if(!d?.indices?.[3]||!d.indices[4])return null;let[f,p]=d.indices[3],[m,h]=d.indices[4],g=s?1:t.scale,_=o((c===n?r:c.x)*g),v=o((c===n?i:c.y)*g);a[c.line]=l.slice(0,f)+_+l.slice(p,m)+v+l.slice(h)}return a}var $o=Cr(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=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=L(N(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=L(N(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 es(e,t,n){let r=n.theme,i=$o(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],u=Ce(r),d=o/2,f=[[d,0],[0,0],[0,d],[d,d]];e.q.forEach((e,t)=>{let n=e.tone??Xo[t],i=r.tone(n)?.fill??m(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${F(s+f[t][0])}" y="${F(c+f[t][1])}" width="${F(d)}" height="${F(d)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=I(e.tone??Xo[t],r,r.node.sub);l.push(`<text x="${F(s+f[t][0]+d/2)}" y="${F(c+f[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a)}" font-weight="700" xml:space="preserve">${R(N(e.text),{...u,text:n},r)}</text>`)}),l.push(`<rect x="${F(s)}" y="${F(c)}" width="${F(o)}" height="${F(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${F(s+d)},${F(c)}V${F(c+o)}M${F(s)},${F(c+d)}H${F(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let p=(e,t,n,i)=>n?`<text x="${F(e)}" y="${F(t)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${F(e)} ${F(t)})"`:``}>${P(n)}</text>`:``,h=c+o+i.bottom/2;l.push(p(s+d/2,h,e.x[0],!1),p(s+d*1.5,h,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=I(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],d=i.labels[t];l.push(`<circle cx="${F(s+a)}" cy="${F(c+o)}" r="${F(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${F(s+d.x)}" y="${F(c+d.y+d.h/2)}" dominant-baseline="central" font-size="${F(i.lfs)}" xml:space="preserve">${R(N(e.name),u,r)}</text>`)}),l.join(``)}var ts={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:Zo,measure(e,t){let n=$o(e,t);return{w:n.w,h:n.h}},render:es,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:wr((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>qo.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]=oi(e[i],Yo,`color`,n,ai),o}),handles(e,t,n){let r=$o(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)=>Qo(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`}]}}]},ns={high:`red`,medium:`amber`,low:`gray`};function rs(e){let[t,n]=ri(e);return{text:t.trim(),props:n}}var is=e=>e.match(/^\s*/)[0].length,as=e=>!e.trim(),os=/^[-*]\s+/;function ss(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function cs(e,t,n){let r=[],i=Math.min(...e.filter(e=>!as(e)).map(is)),a,o=0,s=0,c=-1,l=new Set,u=(e,t)=>{e&&e.end<0&&(e.end=t)};return e.forEach((e,t)=>{if(as(e))return;let d=e.trim(),f=is(e),p=c;if(c=t,os.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}=rs(d.replace(os,``)),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`?(ns[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:ns[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}=rs(d),g=ss(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=ba(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 ls(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=ri(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=si(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}var us=[`owner`,`ticket`,`priority`];function ds(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]?is(e[t.cards[0].start]):is(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=cs(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=is(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,is(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?us:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&ss(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=ls(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=cs(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]?is(e[n[0].start]):0;return a.splice(n.length?n[n.length-1].end:e.length,0,` `.repeat(t)+`New column`),p(a,[n.length])}return i?(a.splice(i.end,0,d(i)+`- New card`),p(a,[r,-1])):null}}}var fs=Cr(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(L(N(e.text),i,n.mono,r,500),t,...e.details.map(e=>L(N(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 ps(e,t,n){if(!e.length)return``;let r=n.theme,i=fs(e,n),{fs:a}=i,o=[],s=Ce(r),c=Math.min(r.radius,a*.6),l=I(`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="${F(d)}" y="${F(f)}" width="${F(i.colW)}" height="${F(i.h)}" rx="${F(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="${F(d+i.cpad+a*.35)}" cy="${F(h)}" r="${F(a*.32)}" fill="${I(e.tone,r,r.node.sub)}"/>`,`<text x="${F(d+i.cpad+a*1.05)}" y="${F(h)}" dominant-baseline="central" font-size="${F(a)}" font-weight="700" xml:space="preserve">${R(N(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="${F(v)}" y="${F(h-a*.6)}" width="${F(_)}" height="${F(a*1.2)}" rx="${F(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${F(v+_/2)}" y="${F(h)}" dominant-baseline="central" text-anchor="middle" font-size="${F(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${P(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="${F(l)}" y="${F(y)}" width="${F(f)}" height="${F(n.h)}" rx="${F(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${F(l)}" y="${F(y+c/2)}" width="3.5" height="${F(n.h-c)}" rx="1.75" fill="${I(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${F(l+i.pad)}" y="${F(m)}" dominant-baseline="central" font-size="${F(a)}" font-weight="500" xml:space="preserve">${R(N(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${F(l+i.pad)}" y="${F(m-a*.6)}" dominant-baseline="central" font-size="${F(a*.88)}" xml:space="preserve">${R(N(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="${F(t)}" y="${F(n-i.chipFs*.75)}" width="${F(e)}" height="${F(i.chipFs*1.5)}" rx="${F(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${F(t+e/2)}" y="${F(n)}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${P(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}var ms={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:cs,measure(e,t){if(!e.length)return{w:0,h:0};let n=fs(e,t);return{w:n.w,h:n.h}},render:ps,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:ds,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=fs(e,n);return e.slice(1).map((e,n)=>({part:e.id,x:t.x+r.at[n+1],y:t.y+r.headH/2,axis:`x`,title:`move ${e.title}`}))}}]};function hs(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=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}}}var gs={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},_s=Object.keys(gs),vs={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},ys=[`collapsed`,`highlight`,`dim`,`folder`,`file`,..._s],bs=[`color`,`icon`,`badge`,`note`,`size`,`status`],xs=e=>_s.find(t=>e[t]===`true`)??(_s.includes(e.status)?e.status:void 0);function Ss(e){for(let t of _s)delete e[t];delete e.status}var Cs=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],ws=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,Ts=/^[-*+]\s+/,Es=/\s\[([^[\]]*)\]\s*$/,Ds=/:\s|\s#\s|:$/,Os=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,ks=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,As=/^(?:\.{3}|…)$/;function js(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}var Ms=e=>e.replace(/\/$/,``);function Ns(e,t){for(let n of Object.keys(e))!ys.includes(n)&&!bs.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[...bs.slice(1),...ys].join(`, `)})`);e.status&&!_s.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${_s.join(`, `)})`),e.color&&!xe(e.color)&&delete e.color}var Ps=100;function Fs(e,t,n){let r=[],i=[],a=[],o=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let s=e.trim().match(ks);if(s){let e=H(s[2]);Ns(e,e=>n(t,e));let r=s[1];a.push({re:hs(Ms(r)),path:Ms(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let c=e.match(ws)[0],l=e.slice(c.length),u=l.match(Ts);u&&(l=l.slice(u[0].length));let d=e.length-l.trimStart().length;if(l=l.trim(),!l||Os.test(l))return;let f=(c+(u?.[0]??``)).replace(/\t/g,` `).length,p={},m,h=l.match(Es);h&&(p=H(h[1]),m=[d+h.index,d+l.length],l=l.slice(0,h.index).trimEnd());let g,_=js(l).match(Ds);if(_&&_.index>0){g=l.slice(_.index+_[0].length).trim()||void 0,l=l.slice(0,_.index).trimEnd();let e=l.match(Es);e&&!h&&(p=H(e[1]),m=[d+e.index,d+l.length],l=l.slice(0,e.index).trimEnd())}Ns(p,e=>n(t,e));let v={text:l,collapsed:!1,highlight:!1,dim:!1,line:t,lead:e.slice(0,d),depth:0,own:{props:p,note:p.note??g},children:[]};for(m&&(v.propSpan=m);i.length&&i[i.length-1].indent>=f;)i.pop();i.length>=Ps&&(o||n(t,`treeview: entries nest at most ${Ps} levels deep`),o=!0,i.length=99),v.depth=i.length,(i.length?i[i.length-1].node.children:r).push(v),i.push({indent:f,node:v})});let s=(e,t)=>{for(let n of e){let e=t+Ms(n.text),{props:r,note:i}=n.own,o=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),c={};for(let t of a)(!t.folders||o)&&t.re.test(t.path?e:Ms(n.text))&&(t.hits++,Object.assign(c,t.props));r.folder===`true`&&delete c.file,r.file===`true`&&delete c.folder,(_s.some(e=>r[e]===`true`)||r.status)&&Ss(c),Object.assign(c,r),n.note=i??c.note,n.tone=c.color,n.icon=c.icon,n.badge=c.badge,n.size=c.size,n.status=xs(c),n.collapsed=c.collapsed===`true`,n.highlight=c.highlight===`true`,n.dim=c.dim===`true`,n.type=c.folder===`true`?`folder`:c.file===`true`?`file`:void 0,s(n.children,e+`/`)}};s(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function Is(e,t=[]){for(let n of e)t.push(n),Is(n.children,t);return t}var Ls=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),Rs=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},zs={},U=(e,t,n)=>{for(let r of n.split(` `))zs[r]=[t,e]};U(`blue`,`code`,`ts tsx mts cts py c cpp`),U(`amber`,`code`,`js jsx mjs cjs zig`),U(`green`,`code`,`vue`),U(`orange`,`code`,`svelte rs swift html`),U(`purple`,`code`,`astro kt h cs css`),U(`cyan`,`code`,`go`),U(`red`,`code`,`java rb`),U(`indigo`,`code`,`php lua`),U(`pink`,`code`,`scss`),U(`green`,`terminal`,`sh bash zsh fish ps1`),U(`blue`,`doc`,`md`),U(`amber`,`doc`,`mdx`),U(`gray`,`doc`,`txt rst`),U(`red`,`doc`,`pdf`),U(`green`,`doc`,`csv`),U(`purple`,`image`,`png jpg jpeg gif webp avif ico`),U(`amber`,`image`,`svg`),U(`red`,`font`,`woff woff2 ttf otf`),U(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),U(`amber`,`config`,`json`),U(`purple`,`config`,`yaml yml`),U(`gray`,`config`,`toml ini`),U(`orange`,`config`,`xml`),U(`slate`,`config`,`env`),U(`cyan`,`database`,`sql db sqlite`),U(`amber`,`package`,`zip tar gz`),U(`pink`,`yuhwa`,`yu yuhwa`);var Bs=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function Vs(e){let t=Ms(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`]:zs[Rs(t)]??[`file`,void 0]}var Hs=`M3.5 1.5h6l3.5 3.5v9.5h-9.5z`,Us=`M9.5 1.5v3.5h3.5`;function Ws(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="${Hs}" fill="${t}" stroke="${n}"/>${r(Us)}`;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}}var Gs=l({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function Ks(e){let t=new Map;for(let n of e)t.set(Ms(n.text),(t.get(Ms(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(Ms(e.text))&&t.get(Ms(e.text))===1&&!/^n\d+$/.test(Ms(e.text))?Ms(e.text):`n${n+1}`)}var qs=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,Js=e=>e!==void 0&&e!==`false`,Ys=(e,t,n)=>t.includes(e)?e:n,Xs=e=>e&&xe(e)?e:void 0,Zs=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function Qs(e,t){let n=t.get(e);if(n)return n;n=new Set;for(let r of e.children){r.status&&r.status!==`ignored`&&n.add(r.status);for(let e of Qs(r,t))n.add(e)}return t.set(e,n),n}var $s=[`color`,`mono`,`emoji`,`none`],ec=[`solid`,`rounded`,`dashed`,`dotted`,`none`],tc=[`none`,`name`,`folders`],nc=[`collapsed`,`all`,`none`],rc=[`letter`,`dot`,`none`],ic=Cr(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=Ys(i.icons,$s,$s[0]),s=Ys(i.sort,tc,tc[0]),c=i.counts===`true`?`all`:Ys(i.counts,nc,nc[0]),l=Ys(i.marks,rc,rc[0]),u=i.rollup!==`false`&&l!==`none`,d=Js(i.compact),f=Js(i.chevrons),p=qs(i.depth),m=Xs(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=qs(i.indent)??y+a*.75,x=Is(e),S=Ks(x),C=new Map(x.map((e,t)=>[e,S[t]])),w=new Map,T=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(As.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(Ls(n))-Number(Ls(e)):0)||Zs.compare(e.text,n.text))},ee=e=>!e.note&&!e.badge&&!e.size&&!e.status&&!e.highlight&&!e.dim&&!e.icon&&!e.tone&&!e.collapsed,te=[],ne=(e,t,o)=>{let s=k(e);s.forEach((e,l)=>{let f=e,g=e=>e.collapsed||p!==void 0&&t+1>=p,_=[Ms(f.text)];for(;d&&f.children.length===1&&Ls(f)&&Ls(f.children[0])&&ee(f)&&!g(f);)f=f.children[0],_.push(Ms(f.text));let v=Ls(f),y=!v&&As.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`,Bs.test(Ms(f.text))?`gray`:m]:Vs(f.text),k=f.icon??T,A=Cs.includes(k)?k:void 0,re=v?600:400,j=v&&(c===`all`||c===`collapsed`&&!x)&&f.children.length?String(E(f)):void 0,ie=v&&u&&!f.status?Qs(f,w):void 0,ae={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:A??`file`,iconTone:f.tone??(f.status?gs[f.status]:void 0)??(f.icon?void 0:D),iconText:A?void 0:f.icon,textW:L(N(S),a,n.mono,r,re),badgeW:f.badge?r(f.badge,a*.72,600,n.mono)+a*.9:0,count:j,countW:j?O(j):0,rollup:ie?.size?ie.size===1?[...ie][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:te.length*h,x:t*b};te.push(ae),x&&ne(f.children,t+1,ae)})};ne(e,0);let A=e=>e.more?e.x+_:e.x+_+g+v,re=e=>A(e)+e.textW+a*.5,j=e=>(e.badgeW?re(e)+e.badgeW:A(e)+e.textW)+a*.45,ie=e=>e.countW?j(e)+e.countW:e.badgeW?re(e)+e.badgeW:A(e)+e.textW,ae=i.notes===`inline`,oe=a*.88,se=0;for(let e of te)se=Math.max(se,ie(e));let ce=se+a*1.6,le=e=>ae?ie(e)+a*.9:ce,ue=e=>e.node.note?L(N(e.node.note),oe,n.mono,r,400):0,de=e=>l!==`none`&&(e.node.status&&vs[e.node.status]!==``||e.rollup!==void 0),fe=te.some(de),pe=a*4;for(let e of te)pe=Math.max(pe,e.node.note?le(e)+ue(e):ie(e));let me=Math.max(0,...te.map(e=>e.sizeW)),he=me?pe+a*1.4+me:pe,ge=he+a*1.2;return{rows:te,fs:a,smallFs:D,noteFs:oe,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:A,badgeX:re,countX:j,noteX:le,sizeRight:he,markX:ge,mark:de,w:fe?ge+a*.8:he,h:te.length*h}}),ac=e=>{let t=mt(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function oc(e,t){if(!e.length)return{w:0,h:0};let n=ic(e,t);return{w:n.w,h:n.h}}function sc(e,t,n){if(!e.length)return``;let r=n.theme,i=ic(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=Ys(a.lines,ec,ec[0]),f=(e,t)=>I(e,r,t),p=f(Xs(a[`line-color`]),r.edge.stroke),m=Xs(a[`highlight-color`]),h=Xs(a[`badge-color`])??`blue`,g=f(Xs(a[`note-color`]),r.node.sub),_=f(Xs(a[`strike-color`]),r.node.sub),v=qs(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=`fill="none" stroke="${p}" stroke-width="${F(rt(a)??1)}" stroke-opacity="0.55"${ac(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,b=Math.min(qs(a.radius)??r.radius,(i.rowH-2)/2),x=Math.max(0,t.w-i.w),S=i.sizeRight+x,C=i.markX+x,w=F(o(-i.fs*.35)),T=F(i.w+x+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,x=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${w}" y="${F(s(e.y+1))}" width="${T}" height="${F(i.rowH-2)}" rx="${F(a.radius?b: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="${w}" y="${F(s(e.y))}" width="${T}" height="${F(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${F(o(t))},${F(s(r))}V${F(s(p-a))}Q${F(o(t))},${F(s(p))} ${F(o(t+a))},${F(s(p))}H${F(o(n))}" ${y}/>`:`<path d="M${F(o(t))},${F(s(r))}V${F(s(p))}H${F(o(n))}" ${y}/>`)}else l.push(`<path d="M${F(o(t))},${F(s(p))}H${F(o(n))}" ${y}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${F(t-n)},${F(s(p)-n/2)}L${F(t)},${F(s(p)+n/2)}L${F(t+n)},${F(s(p)-n/2)}`:`M${F(t-n/2)},${F(s(p)-n)}L${F(t+n/2)},${F(s(p))}L${F(t-n/2)},${F(s(p)+n)}`;x.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`)x.push(`<text x="${F(t+i.iconW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.95)}">${P(e.iconText??Gs[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;x.push(`<g transform="translate(${F(t)},${F(n)}) scale(${F(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${Ws(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));x.push(`<line x1="${F(t-i.fs*.15)}" y1="${F(s(p))}" x2="${F(t+e.textW+i.fs*.15)}" y2="${F(s(p))}" stroke="${_}" stroke-width="${F(v)}" stroke-linecap="round"/>`)}let E=n.status?f(gs[n.status],r.node.text):void 0,D=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):E??r.node.text,O=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(x.push(`<text x="${F(o(i.textX(e)))}" y="${F(s(p))}" dominant-baseline="central" font-size="${F(i.fs)}"${O} xml:space="preserve">${R(N(e.label),Ce(r,D,D),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;x.push(`<rect x="${F(a)}" y="${F(s(p)-c/2)}" width="${F(e.badgeW)}" height="${F(c)}" rx="${F(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${F(a+e.badgeW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${P(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;x.push(`<rect x="${F(t)}" y="${F(s(p)-n/2)}" width="${F(e.countW)}" height="${F(n)}" rx="${F(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${F(t+e.countW/2)}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&x.push(`<text x="${F(o(i.noteX(e)))}" y="${F(s(p))}" dominant-baseline="central" font-size="${F(i.noteFs)}" xml:space="preserve">${R(N(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&x.push(`<text x="${F(o(S))}" y="${F(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${F(i.fs*.82)}" fill="${r.node.sub}">${P(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(gs[t],r.node.text);i.marks===`dot`||!n.status?x.push(`<circle cx="${F(o(C))}" cy="${F(s(p))}" r="${F(i.fs*.22)}" fill="${a}"/>`):x.push(`<text x="${F(o(C))}" y="${F(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${F(i.fs*.85)}" font-weight="700" fill="${a}">${vs[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${x.join(``)}</g>`:x.join(``))}),c.join(``)+l.join(``)+u.join(``)}var cc={text:[],note:[],status:[``,..._s],icon:[``,...Cs],badge:[],size:[],collapsed:[``,`true`],highlight:[``,`true`],dim:[``,`true`]},lc=e=>e.children.length?lc(e.children.at(-1)):e.line+1;function uc(e,t,n,r){let i=si(r);return e.lead+t+(n?`: ${n}`:``)+(i?` [${i}]`:``)}function dc(e,t){let n=e?e.children[0]:t[0],r=e=>e.replace(/[^\s\-*+]/gu,` `).replace(/[-*+](?!\s)/g,` `);if(n)return r(n.lead);if(!e)return``;let i=e.lead.match(/[-*+]\s+$/)?.[0]??``;return` `.repeat(r(e.lead).length-i.length+2)+i}function fc(e,t,n){let r=Is(n),i=Ks(r),a=t.id===void 0?-1:i.indexOf(t.id),o=r[a],s=(e,t,n)=>{if(t===void 0)return{body:e};let r=Is(n??Fs(e,{},()=>{}));return{body:e,id:Ks(r)[r.findIndex(e=>e.line===t)]}},c=e=>r.find(t=>t.children.includes(e))?.children??n;switch(t.op){case`set`:{if(!o)return null;let{key:n}=t,r=t.value?.trim()||null;if(r&&/[\r\n]/.test(r)||n!==`color`&&!(n in cc)||cc[n]?.length&&r&&!cc[n].includes(r)&&n!==`icon`||n===`color`&&r&&!xe(r))return null;let i=[...e],c=o.text,l=o.own.note;if(n===`text`||n===`note`){if(n===`text`){if(!r)return null;c=r}else l=r??void 0;let{note:e,...t}=o.own.props;i[o.line]=uc(o,c,l,t)}else{let{color:t,...a}=o.own.props;n===`status`?(Ss(a),r&&(a[r]=`true`)):n!==`color`&&(r?a[n]=r:delete a[n]);let s=n===`color`?r:t,c=si(s?{color:s,...a}:a),l=e[o.line],[u,d]=o.propSpan??[l.trimEnd().length,l.trimEnd().length];i[o.line]=l.slice(0,u)+(c?` [${c}]`:``)+l.slice(d)}let u=Fs(i,{},()=>{}),d=Is(u)[a];return!d||d.text!==c||d.own.note!==l?null:s(i,o.line,u)}case`up`:case`down`:{if(!o)return null;let n=c(o),r=n.indexOf(o),i=t.op===`up`,a=n[i?r-1:r+1];if(!a)return null;let[l,u]=i?[a,o]:[o,a],d=[...e],f=e.slice(l.line,u.line),p=e.slice(u.line,lc(u));return d.splice(l.line,f.length+p.length,...p,...f),s(d,i?l.line:l.line+p.length)}case`remove`:{if(!o)return null;let t=[...e];return t.splice(o.line,lc(o)-o.line),s(t)}case`add`:{if(t.id!==void 0&&!o)return null;let r=[...e],i=o?lc(o):n.length?lc(n[n.length-1]):e.length;return r.splice(i,0,dc(o,n)+`new-file`),s(r,i)}}}Ir(gi,vi,yi,Oi,Mi,zi,Qi,Wi,va,ka,Ba,ao,Co,Go,ts,ms,{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: "+Cs.join(`|`)+"|<emoji>`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `"+_s.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:[...$s],lines:[...ec],sort:[...tc],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...nc],marks:[...rc],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`},help:{icons:`how files and folders are drawn: coloured glyphs, one colour, emoji or no icon`,lines:`the guide lines that join an entry to its folder`,sort:`reorder entries: as written, by name, or folders first`,notes:`notes in their own column, or right after the name`,chevrons:`an open/closed arrow before each folder`,rows:`every other row shaded`,spacing:`the row height`,slashes:"a `/` after folder names",compact:"fold a folder whose only child is a folder into one `a/b/` row",counts:`how many entries a folder holds: on collapsed folders, on all, or none`,marks:`the git status column on the right: letters (M, A, D, R), dots, or none`,rollup:`a dot on folders that hold changed files`,depth:`show this many levels; deeper folders are drawn collapsed`,indent:`how far each level is indented, in pixels`,"folder-color":`the folder icon colour`,"line-color":`the guide line colour`,"highlight-color":`the band behind highlighted entries`,"badge-color":`the badge colour`,"note-color":`the note text colour`,"strike-color":`the line through deleted entries`,"strike-width":`how thick the line through deleted entries is`},parse:Fs,measure:oc,render:sc,parts(e){let t=Is(e);return Ks(t).map((e,n)=>{let r=t[n],i=r.own.props,a=Ls(r);return{id:e,label:r.text,kind:`entry`,depth:r.depth,tone:r.tone,fields:cc,values:{text:r.text,note:r.own.note??``,status:xs(i)??``,icon:i.icon??``,badge:i.badge??``,size:i.size??``,collapsed:i.collapsed===`true`?`true`:``,highlight:i.highlight===`true`?`true`:``,dim:i.dim===`true`?`true`:``},actions:a?[`up`,`down`,`remove`,`add`]:[`up`,`down`,`remove`],...a?{adds:`entry`}:{}}})},editPart:fc,adds:`entry`}]});var pc=e=>JSON.stringify(e),mc=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:pc(e);function hc(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,`
7
+ `).replace(/<\/?(b|i|em|strong|span|code)[^>]*>/gi,``).replace(/&quot;|#quot;/g,`"`).replace(/&amp;/g,`&`).replace(/#59;/g,`;`).replace(/\bfa[bsr]?:fa-[\w-]+\s*/g,``).replace(/^`(.*)`$/s,`$1`),t||(n=n.replace(/\*\*(.+?)\*\*/g,`$1`)),n.trim()}var W=(e,t=!1)=>hc(e,t).replace(/\s*\n\s*/g,` `);function gc(e,t=_c){let n=e.trim().replace(/^"(.*)"$/,`$1`).replace(/[^\p{L}\p{N}_-]+/gu,`_`).replace(/^[-_]+(?=.)|-+$/g,``);return/^[\p{L}_]/u.test(n)||(n=`n`+n),t.has(n)&&(n+=`_`),n}var _c=new Set(fr);function vc(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 yc(e,t,n,r,i){let a=[e,t];return n&&a.push(pc(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}var bc=/^title\b(?!\s*(?:[-=.~<>&|[({]|:::))\s*:?\s*(.*)$/,xc=new RegExp(bc.source,`i`);function Sc(e,t=!0){let n=e.match(t?xc:bc);return n?hc(n[1]):void 0}var Cc=/^(accTitle|accDescr)\b/;function wc(e,t){return Cc.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function Tc(e,t,n){for(;e.index<e.lines.length;e.index++){let r=e.lines[e.index];!wc(r,t)&&!n(r)&&t.warn(r.line,`could not read "${r.text}"`)}}var Ec={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Dc=/^direction\s+(TD|TB|BT|LR|RL)$/i,Oc=/^style\s+(\S+)\s+(.*)$/;function kc(e,t){let n=e.match(Oc);return n?{target:n[1],props:Fc(n[2],t)}:void 0}var Ac=/^classDef\s+([\w,-]+)\s+(.*)$/;function jc(e,t){let n=e.match(Ac);if(!n)return;let r=Fc(n[2],t);return n[1].split(`,`).map(e=>`.${e.trim()} [${r}]`)}function Mc(e){let t=e.trim().replace(/^\[|\]$/g,``),n=[],r=``,i=!1;for(let e of t)e===`"`?i=!i:e===`,`&&!i?(n.push(r.trim()),r=``):r+=e;return r.trim()&&n.push(r.trim()),n}var Nc=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:pc(e),Pc=l({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 Fc(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=Pc[a];s?(o=s===`border-style`?`dashed`:o.replace(/px$/,``),s===`font-weight`&&o===`bold`?n.push(`bold`):n.push(`${s}: ${o}`)):t(`style "${a}" is not supported and was skipped`)}return n.join(`, `)}var Ic=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Lc=()=>({settings:{},nodes:new Map,edges:[],groups:new Map,classes:l({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]}),Rc=Object.keys(pe),zc=e=>e.match(/^\s*/)[0].length,Bc=(e,t,n)=>void e.classUses.push([t,n]);function Vc(e){for(let t=e.stack.length-1;t>=0;t--)if(e.stack[t].kind===`group`)return e.stack[t].id}function Hc(e,t){let n=e.d.nodes.get(t);return n||(n={id:t,label:t,props:{},classes:[],implicit:!0,group:Vc(e)},e.d.nodes.set(t,n)),n}function Uc(e,t,n,r,i){let a=n.value;t.labelRef={line:r,at:n.start,range:[n.start,n.end],generated:e.gen||void 0};let o=e.labelled.get(t.id);o!==void 0&&t.label!==a&&e.warn(r,`"${t.id}" already has the label "${t.label}" (line ${o+1}); this renames it to "${a}"`+(i?`. For an edge label write: ... -> ${t.id}: ${a}`:``)),t.label=a,e.labelled.set(t.id,r)}function Wc(e,t,n,r,i){if(!(n in pe))return e.warn(i,`Unknown theme key "${n}"${nr(n,Rc)||` (keys: ${Rc.join(`, `)})`}`);pe[n].kind!==`color`||[`none`,`transparent`].includes(r)||r.includes(`$`)||ye(r)||e.warn(i,`Unknown color "${r}" for ${n}${nr(r,f)}`),t[n]=r}function Gc(e,t,n,r){e.themeLines.has(t)&&e.warn(r,`Theme "${t}" is defined twice`),(e.d.themes??=l({}))[t]=n,e.themeLines.set(t,r)}function Kc(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 qc(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),a=new Map,o=new Set,s=new Set(e.panels.map(e=>e.id));if(t)for(let[c,l]of t){let t=c.replace(/^\./,``);if(e.sharedSettings?.includes(c)&&!e.nodes.has(c)&&!e.groups.has(c)){l===c?o.add(c):n(`a setting keeps its name: import { ${c} }`);continue}let u=c.startsWith(`.`)?t in e.classes:c.startsWith(`$`)?c.slice(1)in(e.vars??{}):e.nodes.has(t)||e.groups.has(t)||s.has(t)||t in(e.defs??{});!u&&c in(e.themes??{})||(u?i(c)?(o.add(c),l!==c&&a.set(c,l)):n(`"${c}" is not exported (exports: ${r.join(`, `)||`none`})`):n(`no "${c}" to import${r?.length?` (exports: ${r.join(`, `)})`:``}`))}else for(let e of r)o.add(e);let c=t=>{for(let n=t;n;n=e.groups.get(n)?.parent)if(o.has(n))return!0;return!1},l=Lc(),u=e=>a.get(e)?.replace(/^\./,``)??e,d=e=>a.get(`.${e}`)?.slice(1)??e,f=new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(l.groups.set(u(t.id),{...t,id:u(t.id),parent:t.parent&&l.groups.has(u(t.parent))?u(t.parent):void 0,classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e)));let p=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(p(t.id)){let e=t.group&&l.groups.has(u(t.group))?u(t.group):void 0;l.nodes.set(u(t.id),{...t,id:u(t.id),group:e,classes:t.classes.map(d)}),t.classes.forEach(e=>f.add(e))}for(let t of e.edges)if(p(t.from)&&p(t.to)){let e=u(t.from)+`->`+u(t.to)+(t.key.match(/#\d+$/)?.[0]??``);l.edges.push({...t,key:e,from:u(t.from),to:u(t.to),classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e))}for(let t of e.panels)o.has(t.id)&&l.panels.push({...t,id:u(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(o.has(t))for(let e of n.body)for(let t of Xr(e).tokens)t.kind===`class`&&f.add(t.value);l.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||o.has(e));for(let t of l.sharedSettings)l.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(o.has(`.${t}`)||f.has(t))&&(l.classes[d(t)]=n);l.vars={};for(let[t,n]of Object.entries(e.vars??{}))o.has(`$${t}`)&&(l.vars[(a.get(`$${t}`)??`$${t}`).slice(1)]=n);l.defs={};for(let[t,n]of Object.entries(e.defs??{}))o.has(t)&&(l.defs[a.get(t)??t]=n);return l.themes=e.themes,l}function Jc(e,t,n){let r=`${t}->${n}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`}function Yc(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)e.edges.push({...r,key:Jc(n,r.from,r.to),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),t.layout.aligns?.length&&(e.layout.aligns??=[]).push(...t.layout.aligns);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??=l({}))[n]??=r}function Xc(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`?(Qr(h,$r(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){let n=e[0]?.kind===`string`?e[0].value:``;o(t,`Edge needs a source node${n.trim()?`: a label needs an id, write ${gc(n.toLowerCase())} ${ui(n)}`:``}`,`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=H(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=li(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={key:Jc(a,e,o),from:e,to:o,label:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(l)}}}var Zc=(e,t)=>(e.layout.panels??={})[t]??={};function Qc(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(!Qn(t))return null;n.push(t)}return n},s=1,c=wt(a,i[1]);if(c&&a===`rank`){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(c&&a===`align`){let[e,a]=Ct(i.slice(1).filter(Boolean));if(a.length<2)return r(t,`align needs two or more ids: align ${St} a b c`);(n.layout.aligns??=[]).push({side:e,ids:a});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`){l.via=[];for(let e=o(s,2);e;e=o(s,2))l.via.push({x:e[0],y:e[1]}),s+=2}else if(e===`label`){let e=o(s,2);if(!e)return r(t,`label expects two numbers: dx dy (each within ±${Zn})`);l.label={x:e[0],y:e[1]},s+=2}else if(e===`ports`){let e=i[s],n=i[s+1];if(!zn.includes(e)||!zn.includes(n))return r(t,`ports expects two sides: ${zn.join(`|`)}`);l.ports=[e,n],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}return}let l=a.indexOf(`:`);if(l>0){let s=a.slice(0,l),c=a.slice(l+1),u=i[1]===`offset`?2:1,d=i.length-u,f=c&&(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)`);(Zc(n,s).parts??={})[c]={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)`);Zc(n,a).at={x:e[0],y:e[1]};return}let u=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 (each within ±${Zn})`);u.x=e[0],u.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 (each within ±${Zn})`);u.w=e[0],u.h=e[1],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}}function $c(e,t,n,r){switch(t?.kind){case`body`:return el(e,t,n,r),!0;case`panel`:return tl(e,t,n,r),!0;case`theme`:return rl(e,t,n,r),!0;case`layout`:return il(e,n,r),!0;default:return!1}}function el(e,t,n,r){if(n.trim()===`}`){e.stack.pop();let n=e.d.nodes.get(t.id);n.body=Ke(t.lines),n.bodyLines=[t.start,r]}else t.lines.push(n)}function tl(e,t,n,r){n.trim()===`}`?(e.stack.pop(),nl(e,t,r)):t.lines.push(n.slice(0,Xr(n).codeEnd).trimEnd())}function nl(e,t,r){let i=t.panel,a=t.lines.findIndex(e=>e.trim());i.body=Ke(t.lines),i.lines=[t.start,r];try{i.data=yr.get(i.kind).parse(i.body,i.props,(n,r)=>e.warn(n<0?t.start:t.start+1+Math.max(0,a)+n,r))}catch(r){let a=c(`panel`,i.kind);e.warn(t.start,`${a?`plugin "${a}": `:``}${i.kind} panel failed to parse: ${n(r)}`,`error`),i.failed=!0}}function rl(e,t,n,r){let i=n.slice(0,Xr(n).codeEnd).trim();if(!i)return;if(i===`}`){e.stack.pop(),Gc(e,t.id,t.props,t.start);return}let a=i.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);a?Wc(e,t.props,a[1].toLowerCase(),di(a[2].trim()),r):e.warn(r,`Expected "key: value" in theme ${t.id} (keys: ${Rc.join(`, `)})`,`error`)}function il(e,t,n){let r=t.slice(0,Xr(t).codeEnd).trim();r&&(r.startsWith(`}`)?(e.stack.pop(),e.d.layoutBlock[1]=n):(e.layoutLines.set(r.split(/\s+/)[0],n),Qc(r,n,e.d,e.warn)))}function al(e,t){if(!e.stack.length)e.warn(t,`Unmatched "}"`,`error`);else{let n=e.stack.pop(),r=n.kind===`group`?e.d.groups.get(n.id):void 0;r?.ref&&(r.ref.end=t)}e.lastDecl=null}function ol(e,t,n){e.stack.length&&e.warn(n,`theme must be at the top level`,`error`);let r={},i=2;if(t[i]?.kind===`props`){for(let[a,o]of Object.entries(H(t[i].value)))Wc(e,r,a,o,n);i++}if(t[i]?.value===`{`){if(i++,t[i]?.value===`}`)i++;else if(i===t.length){e.stack.push({kind:`theme`,id:t[1].value,start:n,props:r});return}}i<t.length&&e.warn(n,`Unexpected "${t[i].value}" in theme ${t[1].value}`,`error`),Gc(e,t[1].value,r,n)}function sl(e,t,n){let r=t[0].value,i=1,a=t[i]?.kind===`ident`?t[i++].value:`${r}${e.d.panels.length+1}`,o=e.gen?void 0:t[i]?.kind===`string`?{line:n,at:t[i].start,range:[t[i].start,t[i].end]}:{line:n,at:t[i-1].end},s=t[i]?.kind===`string`?t[i++].value:void 0,c={line:n,insertAt:t[i-1].end},l={};t[i]?.kind===`props`&&(l=H(t[i].value),c.props=[t[i].start,t[i].end],i++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,i!==t.length-1&&e.warn(n,`Unexpected "${t[i].value}" in ${r} header`,`error`),e.stack.length&&e.warn(n,`${r} must be at the top level`,`error`);let u={kind:r,id:a,label:s,props:l,body:[],data:void 0,ref:e.gen?void 0:c,labelRef:o};e.d.panels.push(u),e.stack.push({kind:`panel`,id:a,start:n,lines:[],panel:u})}function cl(e,t,n){e.stack.length&&e.warn(n,`layout block must be at top level`,`error`),e.d.layoutBlock=[n,n],t[2]?.value!==`}`&&e.stack.push({kind:`layout`})}function ll(e){let t=e.lines.length-1;for(let n of e.stack)n.kind===`group`?e.warn(t,`Group "${n.id}" is missing "}"`,`error`):n.kind===`body`?e.warn(n.start,`Body of "${n.id}" is missing a closing "}" line`,`error`):n.kind===`panel`?(e.warn(n.start,`${n.panel.kind} "${n.id}" is missing a closing "}" line`,`error`),nl(e,n,t)):n.kind===`def`?e.warn(n.start,`def ${n.id}() is missing "}"`,`error`):n.kind===`theme`?e.warn(n.start,`theme ${n.id} is missing "}"`,`error`):e.warn(t,`layout block is missing "}"`,`error`)}var ul=1e5,dl=5e4,fl=16,pl=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,ml=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,hl=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,gl=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,_l=new WeakMap;function vl(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}function yl(e,t,n,r,i=!1){let a=t.match(ml);if(a)return t.slice(0,t.length-a[2].length)+yl(e,a[2],n,r,i);let o=t.length,s=t.replace(pl,(t,a,s)=>{let c=a??s;if(!c)return`$`;let l=r?.[c]??e.vars[c];return r?.[c]===void 0&&l!==void 0&&e.used.add(`$`+c),l===void 0?(i||e.warn(n,`Unknown variable "$${c}"${nr(c,[...Object.keys(r??{}),...Object.keys(e.vars)])}`),t):(o+=l.length)>ul?t:l});return o>ul&&e.warn(n,`Variables make this line longer than ${ul} characters`,`error`),s}function bl(e,t,n,r){if(e.depth>=fl){e.tooDeep.has(t.name)||e.warn(r,`${t.name}(): calls nest too deep`,`error`),e.tooDeep.add(t.name);return}if((e.expanded+=t.body.length)>dl){e.expanded-t.body.length<=dl&&e.warn(r,`${t.name}(): components expand to more than ${dl} lines`,`error`);return}let i=vl(n),a=l({}),o=0;for(let n of i){let s=n.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(s&&t.params.some(e=>e.name===s[1]))a[s[1]]=di(s[2]);else if(o<t.params.length)a[t.params[o++].name]=di(n);else{e.warn(r,`${t.name}() takes ${t.params.length} argument(s), got ${i.length}`,`error`);return}}for(let n of t.params)if(!(n.name in a)){if(n.default===void 0){e.warn(r,`${t.name}(): missing argument "${n.name}" (${t.params.map(e=>e.name).join(`, `)})`,`error`);return}a[n.name]=n.default}let s=e.stack.length,c=e.gen;e.gen=!0,e.depth++;let u=t.body.map(t=>yl(e,t,r,a)),d=_l.get(t)??e.defs;for(let t of u)e.step(t,r,!0,d);e.depth--,e.gen=c,e.stack.length>s&&(e.warn(r,`${t.name}(): a block inside the component is not closed`,`error`),e.stack.length=s)}function xl(e,t,n,r,i){for(let e of Zr(Xr(n).tokens))t.depth+=e===`{`?1:-1;if(t.depth>0){t.lines.push(n);return}e.stack.pop(),n.trim()!==`}`&&e.warn(r,`Expected "}" alone on the line that closes ${t.id}()`,`error`);let a=t.params,o=l(Object.fromEntries(a.map(e=>[e.name,`\${${e.name}}`]))),s={name:t.id,params:a,body:Ke(t.lines).map(t=>yl(e,t,r,o,!0))};_l.set(s,i),e.defs[s.name]&&e.warn(t.start,`Component "${s.name}" is defined twice`),e.defs[s.name]=s,(e.d.defLines??={})[s.name]=t.start}function Sl(e,t,n,r,i){let a=t.match(ml);if(a)return e.vars[a[1]]=di(ti(r?a[2]:yl(e,a[2],n)).trimEnd()),(e.d.varLines??={})[a[1]]=n,!0;let o=t.match(hl);if(o){e.stack.length&&e.warn(n,`def must be at the top level`,`error`);let t=vl(o[2]).map(t=>{let r=t.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return r||e.warn(n,`Bad parameter "${t}": def name(a, b = "default") {`,`error`),{name:r?.[1]??t,default:r?.[2]===void 0?void 0:di(r[2])}});return e.stack.push({kind:`def`,id:o[1],start:n,lines:[],depth:1,params:t}),!0}let s=ti(t).match(gl);if(s){let a=i[s[1]]??e.defs[s[1]];if(a)return e.used.add(s[1]),bl(e,a,r?s[2]:yl(e,s[2],n),n),!0;if(!Xr(t).tokens.some(e=>e.kind===`arrow`))return e.warn(n,`Unknown component "${s[1]}"${nr(s[1],Object.keys(e.defs))}`,`error`),!0}return!1}var Cl=new Set([...Hn,...Un]);function wl(e,t,n,r){let i=2,a=t[1].value;t[1].kind===`string`&&(a=t[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,i=1);let o=e.d.groups.get(a)??{id:a,label:a,props:{},parent:Vc(e)};if(t[i]?.kind===`string`){let e=t[i++];o.label=e.value,o.labelRef={line:r,at:e.start,range:[e.start,e.end],id:i===2?a:void 0}}else o.labelRef??={line:r,at:t[1].end};for(e.gen&&(o.labelRef.generated=!0);t[i]?.kind===`class`;)Bc(e,t[i].value,r),(o.classes??=[]).push(t[i++].value);let s={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};if(t[i]?.kind===`props`&&(Object.assign(o.props,H(t[i].value)),s.props=[t[i].start,t[i].end],i++),o.ref=s,e.lastDecl={indent:zc(n),targets:[o]},e.d.groups.set(a,o),t[i]?.value!==`{`){e.warn(r,`Expected "{" after group ${a}`,`error`);return}i++;let c=t.findIndex((e,t)=>t>=i&&e.value===`}`);if(c>=0){s.end=r;for(let n=i;n<c;n++)t[n].kind===`ident`&&(Hc(e,t[n].value).group=a)}else e.stack.push({kind:`group`,id:a})}function Tl(e,t,n,r){let{classes:i}=e.d,a=t[t.length-1],o={};for(let n of t.slice(1))n.kind===`class`&&(i[n.value]?Object.assign(o,i[n.value]):e.warn(r,`Unknown class ".${n.value}"${nr(n.value,Object.keys(i))}`));i[t[0].value]={...i[t[0].value],...o,...a.kind===`props`?H(a.value):{}},(e.d.classLines??={})[t[0].value]=r,e.lastDecl={indent:zc(n),targets:[{props:i[t[0].value]}]}}function El(e,t,n,r,i){let a=n.slice(t[1].end,i).trim();if(t[0].kind!==`ident`||!a)return!1;let o,s=a.match(/^\{(.*)\}$/s);if(s)o=`[${s[1].trim()}]`;else if(/^["']/.test(a))o=a;else{let e=a.match(qr);o=`${ui(e[1].trim())}${e[2]}${e[3]?` ${e[3]}`:``}`}let c=e.gen;return e.gen=!0,e.statement(`${n.match(/^\s*/)[0]}${t[0].value} ${o}`,r),e.gen=c,!0}function Dl(e,t,n,r,i,a){let o=ei(t[0].value),s=n.slice(t[1].end,i).trim();/^(["']).*\1$/.test(s)&&(s=Yr(s.slice(1,-1)));let c=e.lastDecl&&zc(n)>e.lastDecl.indent?e.lastDecl.targets:null,l=a?.kind===`group`?e.d.groups.get(a.id):void 0,u=l?Wn:mr,d=pr.has(o)||u.includes(o),f=d?``:nr(o,u);if((!c||c[0]===l)&&!d&&!f&&!Cl.has(o)&&El(e,t,n,r,i))return;let p=c??(l?[l]:null);if(p){for(let t of p)t.props[o]=s||`true`,t.ref&&!e.gen&&((t.ref.propLines??={})[o]=r);return}if(e.stack.length&&e.warn(r,`Setting "${o}" should be at the top level`),!pr.has(o)){let n=Cl.has(o)?`. "${o}" is a prop: put it in brackets after a node, e.g. a [${o}: ${s||`…`}]`:`. For a node write ${t[0].value} "Label"`;e.warn(r,`Unknown setting "${o}"${(l?nr(o,mr):f)||n}`);return}o===`direction`&&(s=_r[s.toLowerCase()]??s),o===`theme`&&(e.themeLine=r);let m=o===`theme`?void 0:hr[o];m&&s&&!s.includes(`$`)&&!m.includes(s)&&e.warn(r,`Unknown ${o} "${s}"${nr(s,m)||` (use one of: ${m.join(`, `)})`}`),e.d.settings[o]=s}function Ol(e,t,n,r,i){let{d:a}=e,o=a.edges.length;if(Xc(t,r,n.slice(0,i),a,t=>Hc(e,t),e.edgeCount,e.warn,(t,n,r,i)=>Uc(e,t,n,r,i),(t,n)=>Bc(e,t,n)),e.lastDecl={indent:zc(n),targets:a.edges.slice(o)},e.gen){for(let e of a.edges.slice(o))e.ref&&(e.ref.generated=!0),e.labelRef&&(e.labelRef.generated=!0);for(let e of t)if(e.kind===`ident`){let t=a.nodes.get(e.value);t?.ref?.line===r&&(t.ref.generated=!0),t?.labelRef?.line===r&&(t.labelRef.generated=!0)}}}function kl(e,t,n,r){let i=0,a=!0;for(;i<t.length;){let o=t[i];if(o.kind===`punct`&&o.value===`,`){i++,a=!0;continue}if(!a&&o.kind===`ident`){let n=[t[i-1].value];for(;t[i]?.kind===`ident`;)n.push(t[i++].value);let a=n.join(` `),o=n[0].toLowerCase();e.warn(r,o===`subgraph`||o===`end`?`"${n[0]}" is Mermaid syntax: write group id "Label" { ... }`:`"${a}" looks like a label: write ${n.join(`_`).toLowerCase()} "${a}" (or separate nodes with commas)`,`error`);break}if(o.kind===`punct`&&o.value===`{`&&i===t.length-1&&i>0&&t[i-1].kind!==`punct`){let n=t.slice(0,i).reverse().find(e=>e.kind===`ident`);e.stack.push({kind:`body`,id:n.value,start:r,lines:[]});break}if(o.kind!==`ident`){e.warn(r,`Unexpected "${o.value}"`,`error`);break}a=!1;let s=Hc(e,o.value);s.implicit=!1;let c=Vc(e);for(c&&s.group&&s.group!==c&&e.warn(r,`"${o.value}" is already in group "${s.group}": a node lives in one group, so it moves to "${c}"`),c&&(s.group=c),i++,t[i]?.kind===`string`?Uc(e,s,t[i++],r,!1):s.labelRef??={line:r,at:o.end,generated:e.gen||void 0};t[i]?.kind===`class`;){let n=t[i++].value;Bc(e,n,r),s.classes.includes(n)||s.classes.push(n)}let l={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};t[i]?.kind===`props`&&(Qr(s,$r(t[i],s.id,r,e.warn),r),l.props=[t[i].start,t[i].end],i++),s.ref=l,e.lastDecl={indent:zc(n),targets:[s]}}}function Al(e){Pl(e),Fl(e),e.hasExport&&Il(e),Ll(e),Rl(e),dr(e.d,e=>yr.get(e)?.options),e.opts.chain||t(e.d.diagnostics,()=>xr.forEach(t=>t(e.d))),zl(e),e.opts.chain||Nl(e)}var jl=2e3,Ml=2e3;function Nl(e){let{nodes:t,edges:n}=e.d;t.size<=jl&&n.length<=Ml||(e.warn(0,`Diagram too large to lay out: ${t.size} nodes and ${n.length} edges (at most ${jl} nodes and ${Ml} edges). The graph is not drawn; split it into files or panels`,`error`),t.clear(),n.length=0,e.d.groups.clear())}function Pl(e){let t=ge(e.d.themes);for(let[n,r]of e.themeLines){let i=e.d.themes[n].base;i&&i!==n&&!t.includes(i)&&e.warn(r,`Unknown base theme "${i}"${nr(i,t)}`)}let n=e.d.settings.theme;e.themeLine!==void 0&&n&&!n.includes(`$`)&&!t.includes(n)&&e.warn(e.themeLine,`Unknown theme "${n}"${nr(n,t)||` (use one of: ${t.join(`, `)})`}`)}function Fl(e){let t=new Set;for(let[n,r]of e.classUses)e.d.classes[n]||t.has(`${r}.${n}`)||(t.add(`${r}.${n}`),e.warn(r,`Unknown class ".${n}"`))}function Il(e){let{d:t}=e,n=new Set(t.panels.map(e=>e.id));t.exports=[...e.exported.keys()].filter(r=>r.startsWith(`.`)?r.slice(1)in t.classes:r.startsWith(`$`)?r.slice(1)in e.vars:t.nodes.has(r)||t.groups.has(r)||n.has(r)||r in e.defs||r in(t.themes??{}));for(let[n,r]of e.exported)!t.exports.includes(n)&&!yr.has(n)&&n!==`group`&&n!==`def`&&e.warn(r,`export: "${n}" is not declared in this file`)}function Ll(e){let{d:t}=e;for(let e of t.panels){t.nodes.get(e.id)?.implicit&&t.nodes.delete(e.id);let n=t.layout.nodes[e.id];n&&(n.x!==void 0&&n.y!==void 0&&(Zc(t,e.id).at={x:n.x,y:n.y}),delete t.layout.nodes[e.id])}}function Rl(e){let{d:t}=e,n=new Map;for(let r of t.panels){let t=n.get(r.id);t?r.lines&&e.warn(r.lines[0],`panel id "${r.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`):n.set(r.id,r)}for(let[n,r]of t.groups)if(t.nodes.has(n)){let i=t.edges.find(e=>e.ref&&(e.from===n||e.to===n))?.ref?.line??r.ref?.line??0;e.warn(i,`"${n}" is both a node and a group. Edges connect nodes, not groups: use a node inside "${n}", or rename one of them`)}}function zl(e){let{d:t}=e;for(let n of Object.keys(t.layout.nodes)){let r=e.layoutLines.get(n);r!==void 0&&!t.nodes.has(n)&&!t.groups.has(n)&&e.warn(r,`layout: there is no node "${n}" (renamed or deleted?); remove this line${nr(n,[...t.nodes.keys()])}`)}}var Bl=l({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`});function Vl(e,t){return/^\s*%%/.test(t)?`Comments start with //`:/(--|==|-\.|->|=>)\|[^|]*\|/.test(t)?`Edge labels go after a colon: a -> b: label`:Hl(e,t)}function Hl(e,t){let n=e[0]?.value;if([`def`,`export`,`import`].includes(n)||br.has(n)||yr.has(n))return;let r=[],i=!1;for(let n=0;n<e.length-1;n++){let[a,o]=[e[n],e[n+1]];if(a.kind!==`ident`||o.start!==a.end)continue;let s,c=``;if(o.kind===`props`&&!/[:=,]/.test(o.value)&&/[A-Z\s?!]/.test(o.value)&&!ye(o.value)){let e=o.value.match(/^\((.*)\)$/s);s=e?e[1]:o.value,c=e?` [cylinder]`:``}else if(o.kind===`punct`&&o.value===`{`&&t.includes(`}`,o.end))s=t.slice(o.end,t.indexOf(`}`,o.end)),c=` [diamond]`;else if(o.kind===`word`&&o.value.startsWith(`(`)){let e=o.value.match(/^(\(\(|\(\[|\()(.*?)(\)\)|\]\)|\))$/);e&&(s=e[2],c=e[1]===`((`?` [circle]`:e[1]===`([`?` [pill]`:``)}s!==void 0&&(i||=c!==``||o.kind!==`props`,r.push(`${a.value} ${ui(s.trim())}${c}`))}return i?`Mermaid node shapes: write ${r.join(`, `)}`:void 0}function Ul(e){let t=Bl[e[0].value];return`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...yr.keys()].join(`, `)})`+(t&&yr.has(t.split(` `)[0])?`: write "${t.replace(`ID`,e[1].value)} {"`:``)}var Wl=e=>/\.(yu|yuhwa)$/i.test(e);function Gl(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(`/`)}function Kl(e,t,n,r){let{opts:i,merged:a}=e;if(!i.resolve)return e.warn(n,`Cannot import "${t}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let o=Gl(i.file,t);if(!Wl(o))return e.warn(n,`Cannot import "${t}": imports must be .yu files`,`error`);let s=[...i.chain??(i.file?[i.file]:[])];if(s.includes(o))return e.warn(n,`Import cycle: ${[...s,o].join(` -> `)}`,`error`);let c=r?`${o}{${r.map(e=>e.join(` as `)).join(`,`)}}`:o;if(a.has(c))return;let l;try{l=i.resolve(o)}catch{l=void 0}if(l==null)return e.warn(n,`Cannot import "${t}": file not found (${o})`,`error`);if(typeof l!=`string`){let r=l instanceof Promise?`a Promise (resolve must be synchronous)`:typeof l;return e.warn(n,`Cannot import "${t}": the resolver returned ${r}, not the source text`,`error`)}let u=new Set(a),d=e.parse(l,{resolve:i.resolve,file:o,chain:[...s,o],seen:u});for(let r of d.diagnostics)e.warn(n,`${t}:${r.line}: ${r.message}`,r.severity);let f=qc(d,r,r=>e.warn(n,`${t}: ${r}`,`error`));if(f===d)for(let e of u)a.add(e);a.add(c),Yc(e.d,f,e.edgeCount),(e.d.imports??=[]).push(o,...d.imports??[])}function ql(e,t,n,r){if(e.stack.length)e.warn(n,`import must be at the top level`,`error`);else if(!t[1])e.warn(n,`import needs a path: import "./shared.yu"`,`error`);else if(!r)t.length>2&&e.warn(n,`Unexpected "${t[2].value}" after import path`,`error`),Kl(e,t[1].value,n);else{let r=Kc(t,n,e.warn);r&&Kl(e,r.path,n,r.names)}}function Jl(e,t,n,r){let i=()=>e.step(n.slice(0,t[0].start)+` `.repeat(6)+n.slice(t[0].end),r);e.stack.length&&e.warn(r,`export must be at the top level`,`error`);let a=t[1].kind===`ident`&&t[2]?.value===`:`&&pr.has(t[1].value.toLowerCase());if(a||t[1].value===`theme`&&t[2]?.kind===`ident`){let n=t[1].value.toLowerCase();return a&&!e.d.sharedSettings?.includes(n)&&(e.d.sharedSettings??=[]).push(n),i()}e.hasExport=!0;let o=t.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),s=t=>e.exported.has(t)||e.exported.set(t,r);if(t[1].value===`def`&&t[2])s(t[2].value);else if(t[1].value.startsWith(`$`)&&(t[2]?.value===`:`||t[2]?.value===`=`))s(t[1].value);else for(let e of t.slice(1))(e.kind===`ident`||e.kind===`class`)&&s(e.kind===`class`?`.${e.value}`:e.value);if(!o||t.slice(1).some(e=>e.kind===`ident`&&yr.has(e.value)))return i()}function Yl(e,t={}){let n=Lc(),r=t.seen??=new Set;t.file&&r.add(t.file);let i={d:n,opts:t,lines:e.split(/\r?\n/),stack:[],merged:r,edgeCount:new Map,exported:new Map,hasExport:!1,classUses:[],themeLines:new Map,labelled:new Map,layoutLines:new Map,vars:n.vars=l({}),defs:n.defs=l({}),used:n.used=new Set,gen:!1,depth:0,expanded:0,tooDeep:new Set,lastDecl:null,warn:(e,t,r=`warning`)=>n.diagnostics.push({line:e+1,message:t,severity:r}),step:(e,t,n,r)=>Xl(i,e,t,n,r),statement:(e,t)=>Zl(i,e,t),parse:Yl};_l.set(i.defs,i.defs);for(let e=0;e<i.lines.length;e++)Xl(i,i.lines[e],e);return ll(i),Al(i),n}function Xl(e,t,n,r=!1,i=e.defs){if(/^\s*#(\s|$)/.test(t)){e.warn(n,`Comments start with "//", not "#"`,`error`);return}let a=e.stack[e.stack.length-1];if(a?.kind===`def`)return xl(e,a,t,n,i);let o=a?.kind===`body`||a?.kind===`panel`;if(!o&&a?.kind!==`layout`&&Sl(e,t,n,r,i))return;let s=r||a?.kind===`layout`||!o&&/^\s*(import|export)\b/.test(t)?t:yl(e,t,n,void 0,o),c=e.gen;e.gen||=s!==t,Zl(e,s,n),e.gen=c}function Zl(e,t,n){let r=e.stack[e.stack.length-1];if($c(e,r,t,n))return;let{tokens:i,codeEnd:a}=Xr(t);if(!i.length)return;let o=Vl(i,t);if(o){e.warn(n,o,`error`);return}if(i[0].kind===`punct`&&i[0].value===`}`)return al(e,n);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 ql(e,i,n,c);if(s===`export`&&i.length>1&&i[1].kind!==`arrow`&&i[1].value!==`:`)return Jl(e,i,t,n);let l=s===void 0?void 0:br.get(s);if(l&&i[1]?.kind!==`arrow`&&i[1]?.value!==`:`&&i[1]?.value!==`,`){l.parse(t.slice(i[0].end,a).trim(),e.d,{line:n,warn:(t,r)=>e.warn(n,t,r)});return}if(s===`theme`&&i[1]?.kind===`ident`&&(i[2]?.kind===`props`||i[2]?.value===`{`))return ol(e,i,n);let u=i[i.length-1].value===`{`;if(s!==void 0&&i.length>2&&!yr.has(s)&&i[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&e.warn(n,Ul(i)),s!==void 0&&yr.has(s)&&u&&(i[1]?.kind===`ident`||i[1]?.kind===`string`||i[1]?.kind===`props`||i[1]?.value===`{`))return sl(e,i,n);if(s===`layout`&&i[1]?.value===`{`)return cl(e,i,n);if(s===`group`&&(i[1]?.kind===`ident`||i[1]?.kind===`string`&&i.some(e=>e.value===`{`)))return wl(e,i,t,n);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 Tl(e,i,t,n);if(s!==void 0&&i[1]?.kind===`punct`&&i[1].value===`:`)return Dl(e,i,t,n,a,r);if(i.some(e=>e.kind===`arrow`))return Ol(e,i,t,n,a);kl(e,i,t,n)}function Ql(e){let t=[],n=new Map;for(let r of e){let e=r.replace(/\s+$/,``),i=e.trim();if(!i){t.push({kind:`gap`});continue}if(/^-{3,}$/.test(i)){t.push({kind:`rule`});continue}let a=t[t.length-1],o=!1;for(let e of V.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:N(e.slice(0,s)),right:N(e.slice(s+4).trim())}):t.push({kind:`text`,left:N(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}var $l=e=>V.rows.find(t=>t.kind===e.kind);function eu(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,L(e.left,t,n,r,o)+(e.right?t*2+L(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=$l(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 tu(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(`
8
8
  `):[],o=e.sub?e.sub.split(`
9
- `):[],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)=>Fe(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=>Fe(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?Zl(Yl(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?V.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 $l(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(Ge(c+e.iconSize/2,t,e.iconSize,a.text,P(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${F(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(Ge(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,Ve(i,e.caps?we(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(Ge(c,i+e.subLh/2,e.subSize,a.sub,Ve(t,we(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(Ge(l,t,e.subSize,a.sub,Ve(e.meta,we(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${F(t)},${F(n)}H${F(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(eu(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function eu(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(Xe(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push(Xe(r.right,n-Je(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${F(t)},${F(d+f/2)}H${F(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push(Xl(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${P(g)}"`:``}>${o.join(``)}</g>`}function tu(e,t){let n={top:0,right:0,bottom:0,left:0};for(let r of t){let t=e.get(r);n.top+=t.top+26,n.right+=t.right,n.bottom+=t.bottom,n.left+=t.left}return n}function nu(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function ru(e,t,n){let r=new Map;for(let i of e){let e=t.get(i);if(e){let t=n.get(i);r.get(t)?.push(e)??r.set(t,[e])}}return[...r.values()]}function iu(e,t,n){let r=[];for(let i of e.split(`
10
- `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of Me(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function au(e,t,n,r,i,a,o,s=!1,c=0,l=a.mono){let u=s?r*.1:0,d=Math.round(r*.82*10)/10,f=e=>{let t=new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},p=f(e=>Fe(e,r,i,l,o,s,u)),m=f(e=>Fe(e,d,400,l,o)),h=iu(e,c,p),g=t?iu(t,c,m):[],_=Re(h,r),v=Re(g,d,1.35),y=Math.round(r*1.6),b=0;for(let e of h)b=Math.max(b,p(e));for(let e of g)b=Math.max(b,m(e));let x=h.length*_+g.length*v+(g.length?3:0);return n&&(x+=y+4,b=Math.max(b,y)),{lines:h,sub:g,icon:n,lineHeight:_,subSize:d,subLineHeight:v,iconSize:y,letterSpacing:u,caps:s,w:b,h:x}}function ou(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}}var su=e=>e===`right`||e===`left`,cu=(e,t=0)=>Math.ceil(Math.max(e,t)/2)*2;function lu(e){let t=new Map,n=new Map;for(let r of e){let e=new Set,i=new Map;r.forEach((n,a)=>{n.path.forEach((o,s)=>{let c=t.get(o)??[0,0];if(c[0]+=(a+.5)/r.length,c[1]++,t.set(o,c),!e.has(o)){e.add(o);let t=s?n.path[s-1]:``;i.set(t,[...i.get(t)??[],o])}})});for(let e of i.values())e.forEach((t,r)=>{let i=n.get(t)??new Map;n.set(t,i);for(let t of e.slice(r+1))i.set(t,(i.get(t)??0)+1)})}let r=new Map([...t].map(([e,[t,n]])=>[e,t/n])),i=new Map,a=new Map([...r.keys()].map(e=>[e,0]));for(let[e,t]of n)for(let[r,o]of t)o>(n.get(r)?.get(e)??0)&&(i.set(e,[...i.get(e)??[],r]),a.set(r,a.get(r)+1));let o=[...r.keys()].sort((e,t)=>r.get(e)-r.get(t)),s=new Map;for(;o.length;){let e=Math.max(0,o.findIndex(e=>a.get(e)===0)),t=o.splice(e,1)[0];s.set(t,s.size);for(let e of i.get(t)??[])a.set(e,a.get(e)-1)}return s}function uu(e,t,n,r){let i=e.flat(),a=new Map;for(let e of i)e.path.forEach((t,n)=>{let r=a.get(t);r||a.set(t,r={members:[],gPath:e.path.slice(0,n+1),r0:e.rank,r1:e.rank}),r.members.push(e),r.r0=Math.min(r.r0,e.rank),r.r1=Math.max(r.r1,e.rank)});let o=[...a.keys()];if(!o.length)return;let s=e.map(e=>{let t=new Map;return e.forEach((e,n)=>{for(let r of e.path){let e=t.get(r);e?e[1]=n:t.set(r,[n,n])}}),t}),c=n*.5+6,l=lu(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.slice(e.path.indexOf(n)),i=e.oExt/2+r.reduce((e,n)=>e+t.low(n),0),o=e.oExt/2+r.reduce((e,n)=>e+t.high(n),0);h(u(n),e.id,i),h(e.id,d(n),o),a=Math.min(a,e.pos-i),p=Math.max(p,e.pos+o)}let m=(a+p)/2,g=e=>{let t=i.findIndex((t,n)=>e.path[n]!==t),n=e.path[t];return n===void 0?void 0:l.get(n)<l.get(i[t])};for(let t=o;t<=f;t++){let r=e[t],i=s[t].get(n),a;if(i)a=[i[0]-1,i[1]+1];else{let e=0,t=r.length;r.forEach((n,r)=>{let i=g(n);i===!0&&(e=Math.max(e,r+1)),i===!1&&(t=Math.min(t,r))});let n=e;for(;n<t&&r[n].pos<m;)n++;a=[n-1,n]}let[o,l]=a;o>=0&&h(r[o].id,u(n),r[o].oExt/2+c),l<r.length&&h(d(n),r[l].id,r[l].oExt/2+c)}}let g=new Map;for(let[e,t]of a){let n=t.gPath.slice(0,-1).join(`\0`);g.set(n,[...g.get(n)??[],e])}for(let e of g.values())for(let t of e)for(let n of e){let[e,r]=[a.get(t),a.get(n)];l.get(t)>=l.get(n)||e.r1<r.r0||r.r1<e.r0||h(d(t),u(n),c)}let _=[...m].filter(([,e])=>e===0).map(([e])=>e),v=new Set;for(;v.size<f.size;){if(!_.length){let e=``,t=1/0;for(let[n,r]of m)!v.has(n)&&r<t&&([e,t]=[n,r]);_.push(e)}let e=_.pop();if(!v.has(e)){v.add(e);for(let[t,n]of p.get(e))v.has(t)||(f.set(t,Math.max(f.get(t),f.get(e)+n)),m.set(t,m.get(t)-1),m.get(t)===0&&_.push(t))}}for(let e of i)e.pos=f.get(e.id)}function du(e,t){let n=new Map;for(let t of e)n.set(t,[]);for(let e of t)n.get(e.from).push(e);let r=new Map,i=e=>{let t=[[e,0]];for(r.set(e,1);t.length;){let e=t[t.length-1],i=n.get(e[0]);if(e[1]>=i.length){r.set(e[0],2),t.pop();continue}let a=i[e[1]++],o=r.get(a.to);o===1?a.reversed=!0:o||(r.set(a.to,1),t.push([a.to,0]))}};for(let t of e)r.get(t)||i(t)}function fu(e,t){let n=new Map,r=new Map,i=new Map;for(let t of e)n.set(t,[]),i.set(t,[]),r.set(t,0);for(let e of t){let[t,a]=e.reversed?[e.to,e.from]:[e.from,e.to];n.get(t).push([a,e.len??1]),i.get(a).push(t),r.set(a,r.get(a)+1)}let a=new Map,o=e.filter(e=>r.get(e)===0),s=[];for(let e of o)a.set(e,0);for(;o.length;){let e=o.shift();s.push(e);for(let[t,i]of n.get(e))a.set(t,Math.max(a.get(t)??0,a.get(e)+i)),r.set(t,r.get(t)-1),r.get(t)===0&&o.push(t)}for(let t of e)a.has(t)||a.set(t,0);for(let e=s.length-1;e>=0;e--){let t=s[e],r=n.get(t);r.length&&!i.get(t).length&&a.set(t,Math.max(0,Math.min(...r.map(([e,t])=>a.get(e)-t))))}return a}function pu(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=rr(st(e,r))?.[0];if(!r.ref||!i)continue;let a=nr(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 mu(e,t,n){let r=[],i=new Map,a=[],o=su(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=rr(st(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 hu(e,t,n){let r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));for(let i=0;i<50;i++){let i=!1;for(let t of n){let n=Math.max(...t.map(t=>e.get(t)));for(let r of t)e.get(r)!==n&&(e.set(r,n),i=!0)}for(let n of t){let[t,a]=n.reversed?[n.to,n.from]:[n.from,n.to];if(r.has(t)&&r.get(t)===r.get(a))continue;let o=e.get(t)+(n.len??1);e.get(a)<o&&(e.set(a,o),i=!0)}if(!i)return}}function gu(e,t){let n=new Set,r=new Map;if(e.length)for(let e of t.values())for(let t of e.path)r.get(t)?.push(e)??r.set(t,[e]);for(let{side:i,ids:a,within:o}of e){let e=a.map(e=>t.has(e)?[t.get(e)]:r.get(e)??[]).filter(e=>e.some(e=>e.real));if(o&&(e=_u(e)),e.length<2)continue;let s=e.map(e=>{let t=e.filter(e=>e.real),n=Math.min(...t.map(e=>e.pos-e.oExt/2)),r=Math.max(...t.map(e=>e.pos+e.oExt/2));return i===`left`||i===`top`?n:i===`right`||i===`bottom`?r:(n+r)/2}),c=s.reduce((e,t)=>e+t,0)/s.length;e.forEach((e,t)=>{for(let r of e)r.pos+=c-s[t],n.add(r)})}return n}function _u(e){let t=[];for(let n of e){let e=new Set(n.filter(e=>e.real).map(e=>e.rank)),r=t.filter(t=>t.some(t=>t.real&&e.has(t.rank)));t.splice(0,t.length,...t.filter(e=>!r.includes(e)),[...r.flat(),...n])}return t}function vu(e,t,n){for(let{side:r,ids:i}of e){let[e,a]=r===`top`||r===`bottom`?[`y`,`h`]:[`x`,`w`];for(let o of ru(i,t,n))if(r===`top`||r===`left`){let t=Math.min(...o.map(t=>t[e]));o.forEach(n=>n[e]=t)}else{let t=Math.max(...o.map(t=>t[e]+t[a]));o.forEach(n=>n[e]=t-n[a])}}}function yu(e,t,n,r=new Map){let i=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),xu(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),xu(a,u),l(a)}let i=m();i<g&&(g=i,h=e.map(e=>[...e]))}h.forEach((t,n)=>e[n]=t),bu(e)}function bu(e){let t=lu(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 xu(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=new Map,r=new Map;for(let n of e)for(let e of n.path){let i=r.get(e)??[0,0];i[0]+=t[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 Su(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 Cu(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 wu(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s,mono:c}=Tu(e,t),l=e=>Fe(e,i,a,c,n,o,s),u=r.meta?Fe(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:l,meta:u,lineHeight:Math.round(Re(e.label.split(`
11
- `),i)*10)/10}}function Tu(e,t){let n=j(e.props.caps,!1),r=nt(e.props,t.fontSize*.82,600,t),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}var Eu=14,Du=12;function Ou(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=wu(s,a,o),l=Math.max(...c.text.split(`
12
- `).map(c.width)),u=2*Eu+l+(c.meta?c.meta+Du:0);if(u<=n.w&&!c.text.includes(`
13
- `))return;if(u>n.w){let a=n=>it(e,n).includes(t),o=[],s=it(e,t),c=(t,n,r)=>{let i=nu(n,s),a=[...n.slice(i,n.length-r),...s.slice(i,s.length-1)].reduce((t,n)=>{let r=lt(e,n,18);return t+Math.max(r.top,r.right,r.bottom,r.left)},0);o.push({x:t.x-a,y:t.y-a,w:t.w+2*a,h:t.h+2*a})};for(let n of r.values()){let r=it(e,n.decl.group);r.includes(t)||c(n,r,0)}for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,it(e,t),1);let l=-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?l=Math.max(l,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=u-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-l));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let d=n.w-2*Eu-(c.meta?c.meta+Du:0),f=iu(c.text,Math.max(d,40),c.width);if(f.length===1)return;let p=(f.length-1)*c.lineHeight;return n.y-=p,n.h+=p,{lines:f,header:26+p,lineHeight:c.lineHeight}}function ku(e,t,n,r){let i=t=>it(e,t).length,a=[...e.groups.keys()].sort((e,t)=>i(t)-i(e)),o=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=lt(e,c,18),u=Math.min(...a.map(e=>e.x))-l.left,d=Math.min(...a.map(e=>e.y))-l.top-26,f=Math.max(...a.map(e=>e.x+e.w))+l.right,p=Math.max(...a.map(e=>e.y+e.h))+l.bottom,m={x:u,y:d,w:f-u,h:p-d},h=Ou(e,c,m,t,o,n,r);o.set(c,m);let g=e.groups.get(c);s.push({id:c,decl:g,depth:i(c),...m,...h,style:pt({...g,props:st(e,g)},n)})}return s.sort((e,t)=>e.depth-t.depth)}function Au(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 ju(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=z(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=ou(t,n);u&&(o-=u.h,t.settings.title&&(s=Math.max(s,a+l+L(N(t.settings.title),u.titleSize,n.mono,r,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+L(N(t.settings.subtitle),u.subSize,n.mono,r)+l)));let d=[];for(let e of V.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}}var Mu=(e,t)=>e?t*1.95:0;function Nu(e,t,n,r){return{theme:n,measure:r,fs:tt(e.props[`font-size`])??n.fontSize,props:e.props,offsets:t}}function Pu(e,t,n,r){let i=[];for(let r of e.panels){let a=V.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=Nu(r,o,ht(t,r.props,e.themes),n),c=r.failed?{w:0,h:0}:a.measure(r.data,s),l=Mu(r.label,s.fs),u=nt(r.props,s.fs,650,t),d=r.label?Fe(r.label,s.fs*1.05,u.weight,u.mono,n):0,f=cu(Math.max(c.w,d)+32,tt(r.props.width)),p=cu(c.h+l+32,tt(r.props.height)),m={x:0,y:0,w:f-32,h:r.props.height?p-l-32:c.h},h;i.push({decl:r,box:{x:0,y:0,w:f,h:p},inner:m,offsets:o,ctx:s,get handles(){return h??=!r.failed&&a.handles?.(r.data,m,s)||[]}})}if(!i.length)return i;let a=z(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+Mu(t.decl.label,t.ctx.fs)}return i}function Fu(e,t,n,r,i,a,o){let s=z(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=new Map;for(let e of t.values()){let t=o.frames.get(e.id);l.set(e.id,{x:e.x-t.left,y:e.y-t.top,w:e.w+t.left+t.right,h:e.h+t.top+t.bottom})}let u=Array(c+1).fill(!1),d=new Map;for(let r of t.values())for(let t of it(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 Iu(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=>Cu(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 Lu(e,t,n,r,i,a){let[o,s]=r?[`y`,`h`]:[`x`,`w`],c=e=>ru(e,t,n).map(e=>e.sort((e,t)=>e[o]-t[o])),l=new Map;for(let e of t.values())e.decl.group&&(l.get(e.decl.group)?.push(e.id)??l.set(e.decl.group,[e.id]));for(let[n,r]of l){if(!r.some(e=>t.get(e).pinned))continue;let i=ut(e,n,NaN);if(!Number.isNaN(i))for(let e of c(r))e.forEach((t,n)=>n&&(t[o]=e[n-1][o]+e[n-1][s]+i))}for(let{side:e,ids:n,within:r}of i){let i=r?c(n):n.flatMap(e=>t.has(e)?[[t.get(e)]]:[]),a=i.map(t=>e===`center`?t[0][o]+t[0][s]/2:e===`top`||e===`left`?t[0][o]:t[0][o]+t[0][s]),l=e===`center`?a.reduce((e,t)=>e+t,0)/a.length:e===`top`||e===`left`?Math.min(...a):Math.max(...a);i.forEach((e,t)=>e.forEach(e=>e[o]+=l-a[t]))}vu(a,t,n)}function Ru(e,t){let n=Object.create(e),r=M(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}=ue(t.font));let i=M(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=j(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)`):M(t.grid,e,e.dark?800:200)??e.grid:null),j(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,$e(n,t)}var zu=2e4;function Bu(e,t){let n=e=>e.hidden?0:Math.abs(t.get(e.to)-t.get(e.from))-1,r=0;for(let t of e)r+=Math.max(0,n(t));let i=new Set;if(r<=zu)return i;let a=e.map(e=>({idx:e.idx,n:n(e)})).filter(e=>e.n>0).sort((e,t)=>t.n-e.n);for(let e of a){if(r<=zu)break;i.add(e.idx),r-=e.n}return i}function Vu(e,n={}){return t(e.diagnostics,()=>Hu(e,n))}function Hu(e,t){let n=Ru(_e(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=su(i),o=z(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=z(e.settings[`rank-gap`],s?96:72),l=[`smooth`,`orthogonal`,`straight`].includes(e.settings.curve)?e.settings.curve:`smooth`,u=e.settings.shape,d=new Map,f=new Map;for(let t of e.nodes.values()){let i=st(e,t),a=ft(e,t,i,n),o=wn(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=z(i[`max-width`],z(e.settings.wrap,0)),l=au(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c,a.mono),p;t.body?.length||i.meta||i.frame?(l.card=Ql({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=En(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??cu(z(i.width,p.w)),g=m?.h??cu(z(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(Ze(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=mu(e,d,i);m.unshift(...h.edges),du(p,m);let g=fu(p,m),_=a?[`center`,`top`,`bottom`]:[`center`,`left`,`right`],v=[],y=[];for(let t of Ct(e))(_.includes(t.side)?v:y).push(t);let b=[...e.layout.ranks??[],...h.same,...y.filter(e=>!e.within).map(e=>e.ids)].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);b.length&&hu(g,m,b);let x=new Set(m.flatMap(e=>[e.from,e.to])),S=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]])!x.has(e)&&x.has(n)&&!S.has(e)&&(S.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){hu(g,m,[...b,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)S.set(e,t)}pu(e,h,g);let C=new Map;for(let t of p){let n=d.get(t);C.set(t,{id:t,real:!0,path:it(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 w=[],T=new Map,E=Bu(m,g);E.size&&e.diagnostics.push({line:0,message:`${E.size} long edges are drawn straight: routing them around nodes would take more than ${zu} bends`,severity:`warning`});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){w.push([t,n,2]);continue}if(i-r<=1||E.has(e.idx)){w.push([t,n,1]);continue}let a=C.get(t).path,o=C.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}`;C.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0,u:0}),w.push([c,r,c===t?1:2]),l.push(r),c=r}w.push([c,n,1]),T.set(e.idx,e.reversed?l.reverse():l)}let D=0;for(let e of C.values())D=Math.max(D,e.rank);let O=Array.from({length:D+1},()=>[]);for(let e of C.values())O[e.rank].push(e);let k=new Map,ee=new Map;for(let e of C.keys())k.set(e,[]),ee.set(e,[]);for(let[e,t,n]of w)ee.get(e).push([t,n]),k.get(t).push([e,n]);yu(O,k,ee,S);let te=new Map([...e.groups.keys()].map(t=>[t,lt(e,t,18)])),ne=new Map([...e.groups.keys()].map(t=>[t,ut(e,t,o)])),A=(e,t)=>te.get(e)[t]+(t===`top`?26:0),re={low:e=>A(e,a?`top`:`left`),high:e=>A(e,a?`bottom`:`right`),start:e=>A(e,Kt[un[i]]),end:e=>A(e,un[i])},j=(e,t)=>e.reduce((e,n)=>e+t(n),0),ie=(e,t)=>{let n=nu(e.path,t.path),r=e.path.slice(n),i=t.path.slice(n),a=j(r,re.high)+j(i,re.low)+(r.length+i.length>0?10:0),s=n?ne.get(e.path[n-1]):o,c=!e.real&&!t.real?14:!e.real||!t.real?s*.6:s;return(e.oExt+t.oExt)/2+c+a};for(let e of O){let t=0;e.forEach((n,r)=>{r>0&&(t+=ie(e[r-1],n)),n.pos=t})}let ae=e=>e.length?e[e.length-1].pos-e[0].pos:0,oe=Math.max(...O.map(ae));for(let e of O){let t=(oe-ae(e))/2;for(let n of e)n.pos+=t}let se=e=>e.map(([e,t])=>[C.get(e),t]),ce=[],le=[],ue=[];for(let e of C.values())ce[e.u]=se(k.get(e.id)),le[e.u]=se(ee.get(e.id)),ue[e.u]=[...ce[e.u],...le[e.u]];let de=O.map(e=>e.slice(1).map((t,n)=>ie(e[n],t))),fe=O.map((e,t)=>O.length-1-t),pe=O.map((e,t)=>t),me=(e,t)=>{let n=e===`down`?ce:e===`up`?le:ue;for(let r of e===`up`?fe:pe){let e=O[r];if(!e.length)continue;let i=[],a=[];for(let r of e){if(t?.has(r)){i.push(r.pos),a.push(1e3);continue}let e=0,o=0;for(let[t,i]of n[r.u])o+=t.pos*i,e+=i;i.push(e?o/e:r.pos),a.push(e||.25)}let o=Su(i,a,de[r]);e.forEach((e,t)=>e.pos=o[t])}};for(let e=0;e<12;e++)me(e%2==0?`down`:`up`);let he=gu(v,C);for(let e=0;e<4;e++)me(`both`,he);uu(O,re,o,ie);let ge=O.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),ve=Array(O.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=rt(st(e,t),n),s=t.label.split(`
14
- `),c=a?Math.max(...s.map(e=>Fe(e,o.size,o.weight,o.mono,r)))+16:s.length*Re(s,o.size)+10;ve[i]=Math.max(ve[i],c)});let ye=new Map;for(let e of C.values())for(let t of e.path){let n=ye.get(t);ye.set(t,n?[Math.min(n[0],e.rank),Math.max(n[1],e.rank)]:[e.rank,e.rank])}let be=Array(O.length).fill(0),M=Array(O.length).fill(0);for(let e of C.values()){let t=j(e.path.filter(t=>ye.get(t)[1]===e.rank),re.end),n=j(e.path.filter(t=>ye.get(t)[0]===e.rank),re.start);be[e.rank]=Math.max(be[e.rank],t),M[e.rank]=Math.max(M[e.rank],n)}let xe=Array(O.length).fill(-1),Se=Array(O.length).fill(!1),Ce=new Map([...e.groups.keys()].map(t=>[t,ut(e,t,NaN)]));for(let t of e.edges){let[e,n]=[g.get(t.from),g.get(t.to)];if(e===void 0||n===void 0||e===n)continue;let r=C.get(t.from).path,i=nu(r,C.get(t.to).path),a=i?Ce.get(r[i-1]):NaN,o=Number.isNaN(a)?c:Math.max(a,20);for(let t=Math.min(e,n);t<Math.max(e,n);t++)xe[t]=Math.max(xe[t],o),Se[t]||=Number.isNaN(a)}let we=[],Te=0;for(let e=0;e<O.length;e++){we.push(Te+ge[e]/2);let t=e+1<O.length?be[e]+M[e+1]:0,n=t?t+24:0,r=xe[e]>=0&&!Se[e],i=xe[e]<0?c:xe[e];Te+=ge[e]+Math.max(i,ve[e]+(r?20:44),n)}let Ee=(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 C.values()){if(!e.real)continue;let t=d.get(e.id),n=Ee(we[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}vu(y,d,g);let De=new Map;for(let[e,t]of T)De.set(e,t.map(e=>{let t=C.get(e);return Ee(we[t.rank],t.pos)}));let Oe=new Map([...d.values()].map(e=>[e.id,tu(te,C.get(e.id).path)])),ke=1/0,Ae=1/0;for(let e of d.values())ke=Math.min(ke,e.x-Oe.get(e.id).left),Ae=Math.min(Ae,e.y-Oe.get(e.id).top);if(d.size){let e=-ke,t=-Ae;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of De.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}let je=z(e.settings[`max-width`],0),N=new Set,Me=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0);if(je>0&&a&&d.size&&!Me){let t=new Map;for(let[e,n]of T)t.set(e,n.map(e=>C.get(e).rank));Fu(e,d,g,De,t,N,{maxW:je,dir:i,rankGap:c,frames:Oe})}Iu(e,d,a,o);let Ne=[...d.values()].some(e=>e.pinned);Ne&&Lu(e,d,g,a,v,y);let Pe=ku(e,d,n,r),Ie=new Map;Ne||e.edges.forEach((e,t)=>De.has(t)&&Ie.set(e.key,De.get(t)));let Le=pn(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:Ie,channels:Ne?void 0:N,obstacles:[...d.values()],groups:Pe.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),ze=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 pn({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:new Map,obstacles:[...o.values()]})},Be=Pu(e,n,r,Au(d,Pe,Le,[]));Le.push(...ze(Be));let{bounds:Ve,decor:He}=ju(Au(d,Pe,Le,Be),e,n,r),Ue={nodes:d,groups:Pe,edges:Le,bounds:Ve,direction:i,theme:n,blocks:f,decor:He,panels:Be};for(let t of yn)t(Ue,e);return Ue}function Uu(e,t){if(!t||!Se(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${P(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}var G=e=>(Math.round(e*100)/100).toString(),Wu=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?G(t):P(t)}"`,Gu=0;function Ku(e){let t=t=>He(N((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?` (${He(N(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&He(N(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function qu(e,n,r={}){return t(e.diagnostics,()=>Ju(e,n,r))}function Ju(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(Gu++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&He(N(s)),l=Ku(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="${G(a.x)} ${G(a.y)} ${G(a.w)} ${G(a.h)}"`+Wu(`width`,n.width??a.w)+(n.width?``:Wu(`height`,a.h))+` role="img"${Wu(`aria-label`,c||`diagram`)}${l?Wu(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${P(r.font)}">`),c&&o.push(`<title>${P(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${P(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>`);let m=`x="${G(a.x)}" y="${G(a.y)}" width="${G(a.w)}" height="${G(a.h)}"`;n.transparent||(o.push(`<rect ${m} fill="${r.background}"/>`),r.grid&&o.push(`<rect ${m} fill="url(#${i}-grid)"/>`)),p&&o.push(`<rect ${m} fill="url(#${i}-snap)" pointer-events="none"/>`);let h=ou(e,r);if(h){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=Ce(r,r.title);s&&(o.push(`<text x="${G(a.x+t)}" y="${G(n+h.titleSize*.8)}" font-size="${G(h.titleSize)}" font-weight="650" xml:space="preserve">${R(N(s),i,r)}</text>`),n+=h.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${G(a.x+t)}" y="${G(n+h.subSize*.95)}" font-size="${G(h.subSize)}" xml:space="preserve">${R(N(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=V.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:z(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(Xu(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(Qu(e,i,!!n.interactive));o.push(`</g>`);let g=d?`${i}-sh`:null;t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>Yu(e,t,n.measure,g,i)).join(``)}</g>`),o.push(`<g class="nodes">`);for(let n of t.nodes.values())o.push(td(e,n,t,g));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(ed(e,t));o.push(`</g></svg>`);let _=o.join(``);for(let n of bn)_=n(_,e,t);return _}function Yu(e,t,n,r,i){let a=t.theme,o=V.panels.get(e.decl.kind);if(!o)return``;let s=e.ctx.theme,c=gt(e.decl.props,s,a),{box:l}=e,u=e.ctx.fs*1.05*.35,d=nt(e.decl.props,e.ctx.fs,650,s),f=[`<g${Wu(`data-panel`,e.decl.id)}${Wu(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${G(l.x)}" y="${G(l.y)}" width="${G(l.w)}" height="${G(l.h)}" rx="${G(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${G(c.width)}"${Wu(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${G(l.x+16)}" y="${G(l.y+16+u)}" dominant-baseline="central" font-size="${G(e.ctx.fs*1.05)}" font-weight="${d.weight}"${We(d.italic,d.family)} fill="${c.text}" xml:space="preserve">${R(N(e.decl.label),Ce(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 Xu(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=Tu(e.decl,r),c=e.decl.label,l=Ce(r,i.text,i.stroke),u=e.lines??[c],d=e.y+14+Math.round(s.size*.7),f=u.length>1?Be(u,e.x+14,t=>d+t*e.lineHeight,e=>Ve(e,l,r,s.caps)):Ve(c,l,r,s.caps),p=c?`<text x="${G(e.x+14)}" y="${G(d)}" font-size="${G(s.size)}" font-weight="${s.weight}"${We(s.italic,s.family)} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${f}</text>`:``,m=o.meta?`<text x="${G(e.x+e.w-14)}" y="${G(d)}" text-anchor="end" font-size="${G(a)}" fill="${r.node.sub}" xml:space="preserve">${Ve(o.meta,we(l),r)}</text>`:``;return`<g${Wu(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${G(e.x)}" y="${G(e.y)}" width="${G(e.w)}" height="${G(e.h)}" rx="${G(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${Wu(`stroke-dasharray`,i.dash)}/>`+p+m+`</g>`}function Zu(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:${G(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${G(-i)}px${a}"`}function Qu(e,t,n){let r=e.style,i=[];i.push(`<g${Wu(`data-edge`,e.key)}${r.opacity<1?Wu(`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="${G(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${G(e*3)} ${G(e*9)}`;i.push(a+` opacity="0.35"`+Wu(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+Wu(`stroke-dasharray`,n)+Zu(t,n)+`/>`,a+Wu(`stroke-dasharray`,n)+Zu(t,n,!0)+`/>`)}else i.push(a+Wu(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?Zu(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(xn(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function $u(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 ed(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(`
15
- `):[],u=Ce(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=Be(l,o,e=>m+e*p,e=>Ve(e,u,r)),g=r.edge.labelStroke,_=`x="${G(o-d/2)}" y="${G(s-f/2)}" width="${G(d)}" height="${G(f)}" rx="${g?G(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...$u(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${G(a)}" font-weight="${i.fontWeight}"${We(i.italic,i.family)} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
16
- `),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${G(o-(n.rotate?n.h:p)/2)}" y="${G(f)}" width="${G(n.rotate?n.h:p)}" height="${G(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=Be(i,o,e=>f+d*(e+.5)+1,e=>Ve(e,we(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${G(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${G(o)} ${G(s)})"`:``;return`<g${Wu(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function td(e,t,n,r){let i=t.style,a=st(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${P(a.tooltip)}</title>`:``;if(s.push(`<g${Wu(`data-node`,t.id)}${i.opacity<1?Wu(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${On(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${G(i.strokeWidth)}"`+Wu(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=kn(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${G(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&V.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};return s.push($l(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`),Uu(s.join(``),a.link)}let l=t.x+t.w/2,u=t.y+t.h/2+Dn(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${G(l)}" y="${G(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${G(o.iconSize)}">${P(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${G(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+We(i.italic,i.family)+(o.letterSpacing?` letter-spacing="${G(o.letterSpacing)}"`:``),f={text:i.text,sub:i.sub,stroke:i.stroke},p=Be(o.lines,l,e=>u+o.lineHeight*(e+.5),e=>Ve(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=Be(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>Ve(e,we(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${G(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}return s.push(`</g>`),Uu(s.join(``),a.link)}var nd=new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),rd=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,id=/^[\p{L}_][\p{L}\p{N}_-]*$/u,ad=/^[\p{L}_][\p{L}\p{N}_-]*$/u,od=si;function sd(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||(ad.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=ii(r);return i?` [${i}]`:``}var cd=e=>!!e&&typeof e==`object`&&!Array.isArray(e),ld=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&id.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),ud=e=>Array.isArray(e)?e:[e];function dd(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)=>cd(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||cd(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))ad.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?od(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)id.test(e)?cd(n)?a.push(`.${e}${sd(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`&&rd.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?``:` `+od(String(e.label))}${ld(e.class,t)}${sd(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
9
+ `):[],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)=>Fe(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=>Fe(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?eu(Ql(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?V.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 nu(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(Je(c+e.iconSize/2,t,e.iconSize,a.text,P(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${F(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(Je(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,We(i,e.caps?we(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(Je(c,i+e.subLh/2,e.subSize,a.sub,We(t,we(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(Je(l,t,e.subSize,a.sub,We(e.meta,we(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${F(t)},${F(n)}H${F(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(ru(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function ru(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($e(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push($e(r.right,n-Ze(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${F(t)},${F(d+f/2)}H${F(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push($l(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${P(g)}"`:``}>${o.join(``)}</g>`}function iu(e,t){let n={top:0,right:0,bottom:0,left:0};for(let r of t){let t=e.get(r);n.top+=t.top+26,n.right+=t.right,n.bottom+=t.bottom,n.left+=t.left}return n}function au(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function ou(e,t,n){let r=new Map;for(let i of e){let e=t.get(i);if(e){let t=n.get(i);r.get(t)?.push(e)??r.set(t,[e])}}return[...r.values()]}function su(e,t,n){let r=[];for(let i of e.split(`
10
+ `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of Me(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function cu(e,t,n,r,i,a,o,s=!1,c=0,l=a.mono){let u=s?r*.1:0,d=Math.round(r*.82*10)/10,f=e=>{let t=new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},p=f(e=>Fe(e,r,i,l,o,s,u)),m=f(e=>Fe(e,d,400,l,o)),h=su(e,c,p),g=t?su(t,c,m):[],_=Re(h,r),v=Re(g,d,1.35),y=Math.round(r*1.6),b=0;for(let e of h)b=Math.max(b,p(e));for(let e of g)b=Math.max(b,m(e));let x=h.length*_+g.length*v+(g.length?3:0);return n&&(x+=y+4,b=Math.max(b,y)),{lines:h,sub:g,icon:n,lineHeight:_,subSize:d,subLineHeight:v,iconSize:y,letterSpacing:u,caps:s,w:b,h:x}}function lu(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}}var uu=e=>e===`right`||e===`left`,du=(e,t=0)=>Math.ceil(Math.max(e,t)/2)*2;function fu(e){let t=new Map,n=new Map;for(let r of e){let e=new Set,i=new Map;r.forEach((n,a)=>{n.path.forEach((o,s)=>{let c=t.get(o)??[0,0];if(c[0]+=(a+.5)/r.length,c[1]++,t.set(o,c),!e.has(o)){e.add(o);let t=s?n.path[s-1]:``;i.set(t,[...i.get(t)??[],o])}})});for(let e of i.values())e.forEach((t,r)=>{let i=n.get(t)??new Map;n.set(t,i);for(let t of e.slice(r+1))i.set(t,(i.get(t)??0)+1)})}let r=new Map([...t].map(([e,[t,n]])=>[e,t/n])),i=new Map,a=new Map([...r.keys()].map(e=>[e,0]));for(let[e,t]of n)for(let[r,o]of t)o>(n.get(r)?.get(e)??0)&&(i.set(e,[...i.get(e)??[],r]),a.set(r,a.get(r)+1));let o=[...r.keys()].sort((e,t)=>r.get(e)-r.get(t)),s=new Map;for(;o.length;){let e=Math.max(0,o.findIndex(e=>a.get(e)===0)),t=o.splice(e,1)[0];s.set(t,s.size);for(let e of i.get(t)??[])a.set(e,a.get(e)-1)}return s}function pu(e,t,n,r){let i=e.flat(),a=new Map;for(let e of i)e.path.forEach((t,n)=>{let r=a.get(t);r||a.set(t,r={members:[],gPath:e.path.slice(0,n+1),r0:e.rank,r1:e.rank}),r.members.push(e),r.r0=Math.min(r.r0,e.rank),r.r1=Math.max(r.r1,e.rank)});let o=[...a.keys()];if(!o.length)return;let s=e.map(e=>{let t=new Map;return e.forEach((e,n)=>{for(let r of e.path){let e=t.get(r);e?e[1]=n:t.set(r,[n,n])}}),t}),c=n*.5+6,l=fu(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.slice(e.path.indexOf(n)),i=e.oExt/2+r.reduce((e,n)=>e+t.low(n),0),o=e.oExt/2+r.reduce((e,n)=>e+t.high(n),0);h(u(n),e.id,i),h(e.id,d(n),o),a=Math.min(a,e.pos-i),p=Math.max(p,e.pos+o)}let m=(a+p)/2,g=e=>{let t=i.findIndex((t,n)=>e.path[n]!==t),n=e.path[t];return n===void 0?void 0:l.get(n)<l.get(i[t])};for(let t=o;t<=f;t++){let r=e[t],i=s[t].get(n),a;if(i)a=[i[0]-1,i[1]+1];else{let e=0,t=r.length;r.forEach((n,r)=>{let i=g(n);i===!0&&(e=Math.max(e,r+1)),i===!1&&(t=Math.min(t,r))});let n=e;for(;n<t&&r[n].pos<m;)n++;a=[n-1,n]}let[o,l]=a;o>=0&&h(r[o].id,u(n),r[o].oExt/2+c),l<r.length&&h(d(n),r[l].id,r[l].oExt/2+c)}}let g=new Map;for(let[e,t]of a){let n=t.gPath.slice(0,-1).join(`\0`);g.set(n,[...g.get(n)??[],e])}for(let e of g.values())for(let t of e)for(let n of e){let[e,r]=[a.get(t),a.get(n)];l.get(t)>=l.get(n)||e.r1<r.r0||r.r1<e.r0||h(d(t),u(n),c)}let _=[...m].filter(([,e])=>e===0).map(([e])=>e),v=new Set;for(;v.size<f.size;){if(!_.length){let e=``,t=1/0;for(let[n,r]of m)!v.has(n)&&r<t&&([e,t]=[n,r]);_.push(e)}let e=_.pop();if(!v.has(e)){v.add(e);for(let[t,n]of p.get(e))v.has(t)||(f.set(t,Math.max(f.get(t),f.get(e)+n)),m.set(t,m.get(t)-1),m.get(t)===0&&_.push(t))}}for(let e of i)e.pos=f.get(e.id)}function mu(e,t){let n=new Map;for(let t of e)n.set(t,[]);for(let e of t)n.get(e.from).push(e);let r=new Map,i=e=>{let t=[[e,0]];for(r.set(e,1);t.length;){let e=t[t.length-1],i=n.get(e[0]);if(e[1]>=i.length){r.set(e[0],2),t.pop();continue}let a=i[e[1]++],o=r.get(a.to);o===1?a.reversed=!0:o||(r.set(a.to,1),t.push([a.to,0]))}};for(let t of e)r.get(t)||i(t)}function hu(e,t){let n=new Map,r=new Map,i=new Map;for(let t of e)n.set(t,[]),i.set(t,[]),r.set(t,0);for(let e of t){let[t,a]=e.reversed?[e.to,e.from]:[e.from,e.to];n.get(t).push([a,e.len??1]),i.get(a).push(t),r.set(a,r.get(a)+1)}let a=new Map,o=e.filter(e=>r.get(e)===0),s=[];for(let e of o)a.set(e,0);for(;o.length;){let e=o.shift();s.push(e);for(let[t,i]of n.get(e))a.set(t,Math.max(a.get(t)??0,a.get(e)+i)),r.set(t,r.get(t)-1),r.get(t)===0&&o.push(t)}for(let t of e)a.has(t)||a.set(t,0);for(let e=s.length-1;e>=0;e--){let t=s[e],r=n.get(t);r.length&&!i.get(t).length&&a.set(t,Math.max(0,Math.min(...r.map(([e,t])=>a.get(e)-t))))}return a}function gu(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=or(ut(e,r))?.[0];if(!r.ref||!i)continue;let a=ar(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 _u(e,t,n){let r=[],i=new Map,a=[],o=uu(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=or(ut(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 vu(e,t,n){let r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));for(let i=0;i<50;i++){let i=!1;for(let t of n){let n=Math.max(...t.map(t=>e.get(t)));for(let r of t)e.get(r)!==n&&(e.set(r,n),i=!0)}for(let n of t){let[t,a]=n.reversed?[n.to,n.from]:[n.from,n.to];if(r.has(t)&&r.get(t)===r.get(a))continue;let o=e.get(t)+(n.len??1);e.get(a)<o&&(e.set(a,o),i=!0)}if(!i)return}}function yu(e,t){let n=new Set,r=new Map;if(e.length)for(let e of t.values())for(let t of e.path)r.get(t)?.push(e)??r.set(t,[e]);for(let{side:i,ids:a,within:o}of e){let e=a.map(e=>t.has(e)?[t.get(e)]:r.get(e)??[]).filter(e=>e.some(e=>e.real));if(o&&(e=bu(e)),e.length<2)continue;let s=e.map(e=>{let t=e.filter(e=>e.real),n=Math.min(...t.map(e=>e.pos-e.oExt/2)),r=Math.max(...t.map(e=>e.pos+e.oExt/2));return i===`left`||i===`top`?n:i===`right`||i===`bottom`?r:(n+r)/2}),c=s.reduce((e,t)=>e+t,0)/s.length;e.forEach((e,t)=>{for(let r of e)r.pos+=c-s[t],n.add(r)})}return n}function bu(e){let t=[];for(let n of e){let e=new Set(n.filter(e=>e.real).map(e=>e.rank)),r=t.filter(t=>t.some(t=>t.real&&e.has(t.rank)));t.splice(0,t.length,...t.filter(e=>!r.includes(e)),[...r.flat(),...n])}return t}function xu(e,t,n){for(let{side:r,ids:i}of e){let[e,a]=r===`top`||r===`bottom`?[`y`,`h`]:[`x`,`w`];for(let o of ou(i,t,n))if(r===`top`||r===`left`){let t=Math.min(...o.map(t=>t[e]));o.forEach(n=>n[e]=t)}else{let t=Math.max(...o.map(t=>t[e]+t[a]));o.forEach(n=>n[e]=t-n[a])}}}function Su(e,t,n,r=new Map){let i=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),wu(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),wu(a,u),l(a)}let i=m();i<g&&(g=i,h=e.map(e=>[...e]))}h.forEach((t,n)=>e[n]=t),Cu(e)}function Cu(e){let t=fu(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 wu(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=new Map,r=new Map;for(let n of e)for(let e of n.path){let i=r.get(e)??[0,0];i[0]+=t[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 Tu(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 Eu(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 Du(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s,mono:c}=Ou(e,t),l=e=>Fe(e,i,a,c,n,o,s),u=r.meta?Fe(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:l,meta:u,lineHeight:Math.round(Re(e.label.split(`
11
+ `),i)*10)/10}}function Ou(e,t){let n=j(e.props.caps,!1),r=at(e.props,t.fontSize*.82,600,t),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}var ku=14,Au=12;function ju(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=Du(s,a,o),l=Math.max(...c.text.split(`
12
+ `).map(c.width)),u=2*ku+l+(c.meta?c.meta+Au:0);if(u<=n.w&&!c.text.includes(`
13
+ `))return;if(u>n.w){let a=n=>st(e,n).includes(t),o=[],s=st(e,t),c=(t,n,r)=>{let i=au(n,s),a=[...n.slice(i,n.length-r),...s.slice(i,s.length-1)].reduce((t,n)=>{let r=ft(e,n,18);return t+Math.max(r.top,r.right,r.bottom,r.left)},0);o.push({x:t.x-a,y:t.y-a,w:t.w+2*a,h:t.h+2*a})};for(let n of r.values()){let r=st(e,n.decl.group);r.includes(t)||c(n,r,0)}for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,st(e,t),1);let l=-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?l=Math.max(l,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=u-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-l));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let d=n.w-2*ku-(c.meta?c.meta+Au:0),f=su(c.text,Math.max(d,40),c.width);if(f.length===1)return;let p=(f.length-1)*c.lineHeight;return n.y-=p,n.h+=p,{lines:f,header:26+p,lineHeight:c.lineHeight}}function Mu(e,t,n,r){let i=t=>st(e,t).length,a=[...e.groups.keys()].sort((e,t)=>i(t)-i(e)),o=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=ft(e,c,18),u=Math.min(...a.map(e=>e.x))-l.left,d=Math.min(...a.map(e=>e.y))-l.top-26,f=Math.max(...a.map(e=>e.x+e.w))+l.right,p=Math.max(...a.map(e=>e.y+e.h))+l.bottom,m={x:u,y:d,w:f-u,h:p-d},h=ju(e,c,m,t,o,n,r);o.set(c,m);let g=e.groups.get(c);s.push({id:c,decl:g,depth:i(c),...m,...h,style:gt({...g,props:ut(e,g)},n)})}return s.sort((e,t)=>e.depth-t.depth)}function Nu(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 Pu(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=z(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=lu(t,n);u&&(o-=u.h,t.settings.title&&(s=Math.max(s,a+l+L(N(t.settings.title),u.titleSize,n.mono,r,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+L(N(t.settings.subtitle),u.subSize,n.mono,r)+l)));let d=[];for(let e of V.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}}var Fu=(e,t)=>e?t*1.95:0;function Iu(e,t,n,r){return{theme:n,measure:r,fs:it(e.props[`font-size`])??n.fontSize,props:e.props,offsets:t}}function Lu(e,t,n,r){let i=[];for(let r of e.panels){let a=V.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=Iu(r,o,vt(t,r.props,e.themes),n),c=r.failed?{w:0,h:0}:a.measure(r.data,s),l=Fu(r.label,s.fs),u=at(r.props,s.fs,650,t),d=r.label?Fe(r.label,s.fs*1.05,u.weight,u.mono,n):0,f=du(Math.max(c.w,d)+32,it(r.props.width)),p=du(c.h+l+32,it(r.props.height)),m={x:0,y:0,w:f-32,h:r.props.height?p-l-32:c.h},h;i.push({decl:r,box:{x:0,y:0,w:f,h:p},inner:m,offsets:o,ctx:s,get handles(){return h??=!r.failed&&a.handles?.(r.data,m,s)||[]}})}if(!i.length)return i;let a=z(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+Fu(t.decl.label,t.ctx.fs)}return i}function Ru(e,t,n,r,i,a,o){let s=z(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=new Map;for(let e of t.values()){let t=o.frames.get(e.id);l.set(e.id,{x:e.x-t.left,y:e.y-t.top,w:e.w+t.left+t.right,h:e.h+t.top+t.bottom})}let u=Array(c+1).fill(!1),d=new Map;for(let r of t.values())for(let t of st(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 zu(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=>Eu(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 Bu(e,t,n,r,i,a){let[o,s]=r?[`y`,`h`]:[`x`,`w`],c=e=>ou(e,t,n).map(e=>e.sort((e,t)=>e[o]-t[o])),l=new Map;for(let e of t.values())e.decl.group&&(l.get(e.decl.group)?.push(e.id)??l.set(e.decl.group,[e.id]));for(let[n,r]of l){if(!r.some(e=>t.get(e).pinned))continue;let i=pt(e,n,NaN);if(!Number.isNaN(i))for(let e of c(r))e.forEach((t,n)=>n&&(t[o]=e[n-1][o]+e[n-1][s]+i))}for(let{side:e,ids:n,within:r}of i){let i=r?c(n):n.flatMap(e=>t.has(e)?[[t.get(e)]]:[]),a=i.map(t=>e===`center`?t[0][o]+t[0][s]/2:e===`top`||e===`left`?t[0][o]:t[0][o]+t[0][s]),l=e===`center`?a.reduce((e,t)=>e+t,0)/a.length:e===`top`||e===`left`?Math.min(...a):Math.max(...a);i.forEach((e,t)=>e.forEach(e=>e[o]+=l-a[t]))}xu(a,t,n)}function Vu(e,t){let n=Object.create(e),r=M(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}=ue(t.font));let i=M(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=j(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)`):M(t.grid,e,e.dark?800:200)??e.grid:null),j(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,nt(n,t)}var Hu=2e4;function Uu(e,t){let n=e=>e.hidden?0:Math.abs(t.get(e.to)-t.get(e.from))-1,r=0;for(let t of e)r+=Math.max(0,n(t));let i=new Set;if(r<=Hu)return i;let a=e.map(e=>({idx:e.idx,n:n(e)})).filter(e=>e.n>0).sort((e,t)=>t.n-e.n);for(let e of a){if(r<=Hu)break;i.add(e.idx),r-=e.n}return i}function Wu(e,n={}){return t(e.diagnostics,()=>Gu(e,n))}function Gu(e,t){let n=Vu(_e(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??zr,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=uu(i),o=z(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=z(e.settings[`rank-gap`],s?96:72),l=[`smooth`,`orthogonal`,`straight`].includes(e.settings.curve)?e.settings.curve:`smooth`,u=e.settings.shape,d=new Map,f=new Map;for(let t of e.nodes.values()){let i=ut(e,t),a=ht(e,t,i,n),o=Dn(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=z(i[`max-width`],z(e.settings.wrap,0)),l=cu(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c,a.mono),p;t.body?.length||i.meta||i.frame?(l.card=tu({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=kn(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??du(z(i.width,p.w)),g=m?.h??du(z(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(et(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=_u(e,d,i);m.unshift(...h.edges),mu(p,m);let g=hu(p,m),_=a?[`center`,`top`,`bottom`]:[`center`,`left`,`right`],v=[],y=[];for(let t of Et(e))(_.includes(t.side)?v:y).push(t);let b=[...e.layout.ranks??[],...h.same,...y.filter(e=>!e.within).map(e=>e.ids)].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);b.length&&vu(g,m,b);let x=new Set(m.flatMap(e=>[e.from,e.to])),S=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]])!x.has(e)&&x.has(n)&&!S.has(e)&&(S.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){vu(g,m,[...b,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)S.set(e,t)}gu(e,h,g);let C=new Map;for(let t of p){let n=d.get(t);C.set(t,{id:t,real:!0,path:st(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 w=[],T=new Map,E=Uu(m,g);E.size&&e.diagnostics.push({line:0,message:`${E.size} long edges are drawn straight: routing them around nodes would take more than ${Hu} bends`,severity:`warning`});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){w.push([t,n,2]);continue}if(i-r<=1||E.has(e.idx)){w.push([t,n,1]);continue}let a=C.get(t).path,o=C.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}`;C.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0,u:0}),w.push([c,r,c===t?1:2]),l.push(r),c=r}w.push([c,n,1]),T.set(e.idx,e.reversed?l.reverse():l)}let D=0;for(let e of C.values())D=Math.max(D,e.rank);let O=Array.from({length:D+1},()=>[]);for(let e of C.values())O[e.rank].push(e);let k=new Map,ee=new Map;for(let e of C.keys())k.set(e,[]),ee.set(e,[]);for(let[e,t,n]of w)ee.get(e).push([t,n]),k.get(t).push([e,n]);Su(O,k,ee,S);let te=new Map([...e.groups.keys()].map(t=>[t,ft(e,t,18)])),ne=new Map([...e.groups.keys()].map(t=>[t,pt(e,t,o)])),A=(e,t)=>te.get(e)[t]+(t===`top`?26:0),re={low:e=>A(e,a?`top`:`left`),high:e=>A(e,a?`bottom`:`right`),start:e=>A(e,Yt[pn[i]]),end:e=>A(e,pn[i])},j=(e,t)=>e.reduce((e,n)=>e+t(n),0),ie=(e,t)=>{let n=au(e.path,t.path),r=e.path.slice(n),i=t.path.slice(n),a=j(r,re.high)+j(i,re.low)+(r.length+i.length>0?10:0),s=n?ne.get(e.path[n-1]):o,c=!e.real&&!t.real?14:!e.real||!t.real?s*.6:s;return(e.oExt+t.oExt)/2+c+a};for(let e of O){let t=0;e.forEach((n,r)=>{r>0&&(t+=ie(e[r-1],n)),n.pos=t})}let ae=e=>e.length?e[e.length-1].pos-e[0].pos:0,oe=Math.max(...O.map(ae));for(let e of O){let t=(oe-ae(e))/2;for(let n of e)n.pos+=t}let se=e=>e.map(([e,t])=>[C.get(e),t]),ce=[],le=[],ue=[];for(let e of C.values())ce[e.u]=se(k.get(e.id)),le[e.u]=se(ee.get(e.id)),ue[e.u]=[...ce[e.u],...le[e.u]];let de=O.map(e=>e.slice(1).map((t,n)=>ie(e[n],t))),fe=O.map((e,t)=>O.length-1-t),pe=O.map((e,t)=>t),me=(e,t)=>{let n=e===`down`?ce:e===`up`?le:ue;for(let r of e===`up`?fe:pe){let e=O[r];if(!e.length)continue;let i=[],a=[];for(let r of e){if(t?.has(r)){i.push(r.pos),a.push(1e3);continue}let e=0,o=0;for(let[t,i]of n[r.u])o+=t.pos*i,e+=i;i.push(e?o/e:r.pos),a.push(e||.25)}let o=Tu(i,a,de[r]);e.forEach((e,t)=>e.pos=o[t])}};for(let e=0;e<12;e++)me(e%2==0?`down`:`up`);let he=yu(v,C);for(let e=0;e<4;e++)me(`both`,he);pu(O,re,o,ie);let ge=O.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),ve=Array(O.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=ot(ut(e,t),n),s=t.label.split(`
14
+ `),c=a?Math.max(...s.map(e=>Fe(e,o.size,o.weight,o.mono,r)))+16:s.length*Re(s,o.size)+10;ve[i]=Math.max(ve[i],c)});let ye=new Map;for(let e of C.values())for(let t of e.path){let n=ye.get(t);ye.set(t,n?[Math.min(n[0],e.rank),Math.max(n[1],e.rank)]:[e.rank,e.rank])}let be=Array(O.length).fill(0),M=Array(O.length).fill(0);for(let e of C.values()){let t=j(e.path.filter(t=>ye.get(t)[1]===e.rank),re.end),n=j(e.path.filter(t=>ye.get(t)[0]===e.rank),re.start);be[e.rank]=Math.max(be[e.rank],t),M[e.rank]=Math.max(M[e.rank],n)}let xe=Array(O.length).fill(-1),Se=Array(O.length).fill(!1),Ce=new Map([...e.groups.keys()].map(t=>[t,pt(e,t,NaN)]));for(let t of e.edges){let[e,n]=[g.get(t.from),g.get(t.to)];if(e===void 0||n===void 0||e===n)continue;let r=C.get(t.from).path,i=au(r,C.get(t.to).path),a=i?Ce.get(r[i-1]):NaN,o=Number.isNaN(a)?c:Math.max(a,20);for(let t=Math.min(e,n);t<Math.max(e,n);t++)xe[t]=Math.max(xe[t],o),Se[t]||=Number.isNaN(a)}let we=[],Te=0;for(let e=0;e<O.length;e++){we.push(Te+ge[e]/2);let t=e+1<O.length?be[e]+M[e+1]:0,n=t?t+24:0,r=xe[e]>=0&&!Se[e],i=xe[e]<0?c:xe[e];Te+=ge[e]+Math.max(i,ve[e]+(r?20:44),n)}let Ee=(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 C.values()){if(!e.real)continue;let t=d.get(e.id),n=Ee(we[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}xu(y,d,g);let De=new Map;for(let[e,t]of T)De.set(e,t.map(e=>{let t=C.get(e);return Ee(we[t.rank],t.pos)}));let Oe=new Map([...d.values()].map(e=>[e.id,iu(te,C.get(e.id).path)])),ke=1/0,Ae=1/0;for(let e of d.values())ke=Math.min(ke,e.x-Oe.get(e.id).left),Ae=Math.min(Ae,e.y-Oe.get(e.id).top);if(d.size){let e=-ke,t=-Ae;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of De.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}let je=z(e.settings[`max-width`],0),N=new Set,Me=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0);if(je>0&&a&&d.size&&!Me){let t=new Map;for(let[e,n]of T)t.set(e,n.map(e=>C.get(e).rank));Ru(e,d,g,De,t,N,{maxW:je,dir:i,rankGap:c,frames:Oe})}zu(e,d,a,o);let Ne=[...d.values()].some(e=>e.pinned);Ne&&Bu(e,d,g,a,v,y);let Pe=Mu(e,d,n,r),Ie=new Map;Ne||e.edges.forEach((e,t)=>De.has(t)&&Ie.set(e.key,De.get(t)));let Le=gn(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:Ie,channels:Ne?void 0:N,obstacles:[...d.values()],groups:Pe.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),ze=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 gn({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:new Map,obstacles:[...o.values()]})},Be=Lu(e,n,r,Nu(d,Pe,Le,[]));Le.push(...ze(Be));let{bounds:Ve,decor:He}=Pu(Nu(d,Pe,Le,Be),e,n,r),Ue={nodes:d,groups:Pe,edges:Le,bounds:Ve,direction:i,theme:n,blocks:f,decor:He,panels:Be};for(let t of Sn)t(Ue,e);return Ue}function Ku(e,t){if(!t||!Se(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${P(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}var G=e=>(Math.round(e*100)/100).toString(),qu=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?G(t):P(t)}"`,Ju=0;function Yu(e){let t=t=>Ge(N((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?` (${Ge(N(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&Ge(N(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function Xu(e,n,r={}){return t(e.diagnostics,()=>Zu(e,n,r))}function Zu(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(Ju++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&Ge(N(s)),l=Yu(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="${G(a.x)} ${G(a.y)} ${G(a.w)} ${G(a.h)}"`+qu(`width`,n.width??a.w)+(n.width?``:qu(`height`,a.h))+` role="img"${qu(`aria-label`,c||`diagram`)}${l?qu(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${P(r.font)}">`),c&&o.push(`<title>${P(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${P(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>`);let m=`x="${G(a.x)}" y="${G(a.y)}" width="${G(a.w)}" height="${G(a.h)}"`;n.transparent||(o.push(`<rect ${m} fill="${r.background}"/>`),r.grid&&o.push(`<rect ${m} fill="url(#${i}-grid)"/>`)),p&&o.push(`<rect ${m} fill="url(#${i}-snap)" pointer-events="none"/>`);let h=lu(e,r);if(h){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=Ce(r,r.title);s&&(o.push(`<text x="${G(a.x+t)}" y="${G(n+h.titleSize*.8)}" font-size="${G(h.titleSize)}" font-weight="650" xml:space="preserve">${R(N(s),i,r)}</text>`),n+=h.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${G(a.x+t)}" y="${G(n+h.subSize*.95)}" font-size="${G(h.subSize)}" xml:space="preserve">${R(N(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=V.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:z(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($u(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(td(e,i,!!n.interactive));o.push(`</g>`);let g=d?`${i}-sh`:null;t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>Qu(e,t,n.measure,g,i)).join(``)}</g>`),o.push(`<g class="nodes">`);for(let n of t.nodes.values())o.push(id(e,n,t,g));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(rd(e,t));o.push(`</g></svg>`);let _=o.join(``);for(let n of Cn)_=n(_,e,t);return Ue(_)}function Qu(e,t,n,r,i){let a=t.theme,o=V.panels.get(e.decl.kind);if(!o)return``;let s=e.ctx.theme,c=yt(e.decl.props,s,a),{box:l}=e,u=e.ctx.fs*1.05*.35,d=at(e.decl.props,e.ctx.fs,650,s),f=[`<g${qu(`data-panel`,e.decl.id)}${qu(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${G(l.x)}" y="${G(l.y)}" width="${G(l.w)}" height="${G(l.h)}" rx="${G(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${G(c.width)}"${qu(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${G(l.x+16)}" y="${G(l.y+16+u)}" dominant-baseline="central" font-size="${G(e.ctx.fs*1.05)}" font-weight="${d.weight}"${qe(d.italic,d.family)} fill="${c.text}" xml:space="preserve">${R(N(e.decl.label),Ce(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 $u(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=Ou(e.decl,r),c=e.decl.label,l=Ce(r,i.text,i.stroke),u=e.lines??[c],d=e.y+14+Math.round(s.size*.7),f=u.length>1?ze(u,e.x+14,t=>d+t*e.lineHeight,e=>We(e,l,r,s.caps)):We(c,l,r,s.caps),p=c?`<text x="${G(e.x+14)}" y="${G(d)}" font-size="${G(s.size)}" font-weight="${s.weight}"${qe(s.italic,s.family)} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${f}</text>`:``,m=o.meta?`<text x="${G(e.x+e.w-14)}" y="${G(d)}" text-anchor="end" font-size="${G(a)}" fill="${r.node.sub}" xml:space="preserve">${We(o.meta,we(l),r)}</text>`:``;return`<g${qu(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${G(e.x)}" y="${G(e.y)}" width="${G(e.w)}" height="${G(e.h)}" rx="${G(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${qu(`stroke-dasharray`,i.dash)}/>`+p+m+`</g>`}function ed(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:${G(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${G(-i)}px${a}"`}function td(e,t,n){let r=e.style,i=[];i.push(`<g${qu(`data-edge`,e.key)}${r.opacity<1?qu(`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="${G(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${G(e*3)} ${G(e*9)}`;i.push(a+` opacity="0.35"`+qu(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+qu(`stroke-dasharray`,n)+ed(t,n)+`/>`,a+qu(`stroke-dasharray`,n)+ed(t,n,!0)+`/>`)}else i.push(a+qu(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?ed(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(wn(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function nd(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 rd(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(`
15
+ `):[],u=Ce(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=ze(l,o,e=>m+e*p,e=>We(e,u,r)),g=r.edge.labelStroke,_=`x="${G(o-d/2)}" y="${G(s-f/2)}" width="${G(d)}" height="${G(f)}" rx="${g?G(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...nd(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${G(a)}" font-weight="${i.fontWeight}"${qe(i.italic,i.family)} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
16
+ `),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${G(o-(n.rotate?n.h:p)/2)}" y="${G(f)}" width="${G(n.rotate?n.h:p)}" height="${G(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=ze(i,o,e=>f+d*(e+.5)+1,e=>We(e,we(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${G(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${G(o)} ${G(s)})"`:``;return`<g${qu(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function id(e,t,n,r){let i=t.style,a=ut(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${P(a.tooltip)}</title>`:``;if(s.push(`<g${qu(`data-node`,t.id)}${i.opacity<1?qu(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${jn(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${G(i.strokeWidth)}"`+qu(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=Mn(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${G(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&V.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};return s.push(nu(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`),Ku(s.join(``),a.link)}let l=t.x+t.w/2,u=t.y+t.h/2+An(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${G(l)}" y="${G(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${G(o.iconSize)}">${P(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${G(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+qe(i.italic,i.family)+(o.letterSpacing?` letter-spacing="${G(o.letterSpacing)}"`:``),f={text:i.text,sub:i.sub,stroke:i.stroke},p=ze(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=ze(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>We(e,we(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${G(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}return s.push(`</g>`),Ku(s.join(``),a.link)}var ad=new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),od=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,sd=/^[\p{L}_][\p{L}\p{N}_-]*$/u,cd=/^[\p{L}_][\p{L}\p{N}_-]*$/u,ld=ui;function ud(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||(cd.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=si(r);return i?` [${i}]`:``}var dd=e=>!!e&&typeof e==`object`&&!Array.isArray(e),fd=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&sd.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),pd=e=>Array.isArray(e)?e:[e];function md(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)=>dd(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||dd(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))cd.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?ld(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)sd.test(e)?dd(n)?a.push(`.${e}${ud(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`&&od.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?``:` `+ld(String(e.label))}${fd(e.class,t)}${ud(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
17
17
  `);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(`
18
- `)):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?``:` `+od(String(i.label))}${ld(i.class,t)}${sd(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=ud(e.from).filter(e=>c(e,`edge.from`)),r=ud(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;nd.has(i)||t.push(`edge arrow "${i}" must be one of ${[...nd].join(` `)}`);let o=`${e.label===void 0?``:` `+od(String(e.label))}${ld(e.class,t)}${sd(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${nd.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
18
+ `)):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?``:` `+ld(String(i.label))}${fd(i.class,t)}${ud(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=pd(e.from).filter(e=>c(e,`edge.from`)),r=pd(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;ad.has(i)||t.push(`edge arrow "${i}" must be one of ${[...ad].join(` `)}`);let o=`${e.label===void 0?``:` `+ld(String(e.label))}${fd(e.class,t)}${ud(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${ad.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
19
19
  `).replace(/\n+$/,``)+`
20
- `,errors:t}}var fd=/^"(.*)"$/;function pd(e){return{id:e,attrs:[],methods:[],rows:[],classes:[]}}function md(e,t){return{ctx:t,lines:e,index:0,cards:new Map,root:{id:``,label:``,items:[]},rels:[],direction:`down`,title:t.title}}function hd(e,t){Sc(e,e.ctx,({text:n,line:r})=>t.some(t=>t(n,e,r)))}function gd(e,t){for(;++e.index<e.lines.length&&e.lines[e.index].text!==`}`;)t(e.lines[e.index])}var _d=(e,t)=>{let n=yc(e,!1);return n!==void 0&&(t.title=n),n!==void 0},vd=(e,t)=>{let n=e.match(wc);return n&&(t.direction=Cc[n[1].toUpperCase()]),!!n};function yd(e){let t=[e.id];e.label!==void 0&&e.label!==e.id&&t.push(uc(e.label));for(let n of e.classes)t.push(`.${n}`);let n=[];return e.note&&n.push(`shape: note`),e.sub&&n.push(`sub: ${uc(e.sub)}`),e.style&&n.push(e.style),n.length&&t.push(`[${n.join(`, `)}]`),t}function bd(e){if(e.rows.length)return e.rows;let t=e.attrs.length&&e.methods.length?[`---`]:[];return[...e.attrs,...t,...e.methods]}function xd(e,t){let n=yd(e),r=bd(e);return r.length?(n.length===1&&n.push(uc(e.id)),[`${t}${n.join(` `)} {`,...r.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function Sd(e){let t=[e.label?Ac(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);return`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`}function Cd(e,t,n){let r=(t,n)=>t.items.flatMap(t=>xd(e.cards.get(t),n)),i=r(e.root,``);for(let e of n)i.push(`group ${e.id} ${uc(e.label)} {`,...r(e,` `),`}`);return e.rels.length&&i.push(``),i.push(...e.rels.map(Sd)),[...[e.title?`title: ${e.title}`:``,`direction: ${e.direction}`].filter(Boolean),...t.length?[``,...t]:[],``,...i]}var wd=l({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),Td=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,Ed=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,Dd=/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/,Od=/^namespace\s+(\S+)\s*\{$/,kd=/^<<(.+)>>$/,Ad=/^<<(.+)>>\s+(\S+)$/,jd=/^note\s+for\s+(\S+)\s+"(.*)"$/,Md=/^note\s+"(.*)"$/,Nd=/^cssClass\s+"([^"]+)"\s+([\w-]+)$/,Pd=/^(click|callback|link)\b/,Fd=/^([^\s:]+)\s*:\s*(.*)$/,Id=e=>e.replace(/~([^~]*)~/g,`<$1>`),Ld=e=>e.replace(/~[^~]*~/g,``),Rd=e=>`«${e.trim()}»`;function zd(e,t){let n=pc(Ld(t)),r=e.cards.get(n);return r||(r=pd(n),(n!==t||/~/.test(t))&&(r.label=Id(t.replace(fd,`$1`))),e.cards.set(n,r),e.scope.items.push(n)),r}function Bd(e,t){let n=Id(t.trim());if(!n)return;let r=n.match(kd);r?e.sub=Rd(r[1]):(n.includes(`(`)?e.methods:e.attrs).push(n)}function Vd(e,t){let n=`note${++e.notes}`;return e.cards.set(n,{...pd(n),label:fc(t),note:!0}),e.scope.items.push(n),n}var Hd=[_d,vd,(e,t)=>{let n=e.match(Od);return n&&(t.scope={id:pc(n[1]),label:n[1],items:[]},t.scopes.push(t.scope)),!!n},(e,t,n)=>e===`}`&&(t.scope===t.root?t.ctx.warn(n,`"}" without a namespace`):t.scope=t.root,!0),(e,t)=>{let n=e.match(Dd);if(!n)return!1;let[,r,i,a,o,s,c]=n,l=zd(t,r+(i??``));return a!==void 0&&(l.label=W(a)),o&&l.classes.push(o),s&&!c&&gd(t,e=>Bd(l,e.text)),!0},(e,t)=>{let n=e.match(Ad);return n&&(zd(t,n[2]).sub=Rd(n[1])),!!n},(e,t)=>{let n=e.match(jd);if(n){let e=Vd(t,n[2]);t.rels.push({from:e,to:zd(t,n[1]).id,arrow:`..`,props:[]})}return!!n},(e,t)=>{let n=e.match(Md);return n&&Vd(t,n[1]),!!n},(e,t,n)=>{let r=Oc(e,e=>t.ctx.warn(n,e));return t.classDefs.push(...r??[]),!!r},(e,t)=>{let n=e.match(Nd);if(n)for(let e of n[1].split(`,`))zd(t,e.trim()).classes.push(n[2]);return!!n},(e,t,n)=>{let r=Ec(e,e=>t.ctx.warn(n,e));return r&&(zd(t,r.target).style=r.props),!!r},(e,t,n)=>Pd.test(e)?(t.ctx.warnOnce(`click`,n,`click, link and callback are skipped`),!0):!1,(e,t,n)=>{let r=e.match(Td)??e.match(Ed);if(!r)return!1;let[,i,a,o,s,c,l,u,d]=r,f=[];o&&f.push(`tail: ${wd[o]}`),c&&f.push(`head: ${wd[c]}`),(o===`o`||c===`o`)&&t.ctx.warnOnce(`aggr`,n,`aggregation (o--) is drawn with a filled diamond, like composition`);let p=[a,l].filter(e=>e!==void 0);return p.length&&f.push(`caption: ${uc(p.join(` to `))}`),t.rels.push({from:zd(t,i).id,to:zd(t,u).id,arrow:s,props:f,label:d?W(d):void 0}),!0},(e,t)=>{let n=e.match(Fd);return n&&Bd(zd(t,n[1]),n[2]),!!n}],Ud=(e,t)=>{let n=md(e,t),r={...n,scopes:[],scope:n.root,classDefs:[],notes:0};return hd(r,Hd),Cd(r,r.classDefs,r.scopes)},Wd={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},Gd={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Kd=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,qd=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,Jd=/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/,Yd=/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/,Xd=/^(classDef|class|style)\b/,Zd=/^("[^"]*"|[\w-]+)$/;function Qd(e,t){let n=t.replace(fd,`$1`),r=pc(n),i=e.cards.get(r);return i||(i=pd(r),r!==n&&(i.label=n),e.cards.set(r,i),e.root.items.push(r)),i}function $d(e,t,n){let r=n.text.match(qd);if(!r){e.ctx.warn(n.line,`could not read attribute "${n.text}"`);return}let[,i,a,o,s]=r,c=[i,a,o.replace(/\s+/g,``).replace(/,/g,`, `),s??``].map(e=>e.replace(/\|/g,`/`));t.rows.push(`| ${c.join(` | `)} |`)}var ef=[_d,vd,(e,t)=>{let n=e.match(Jd);if(!n)return!1;let[,r,i,a]=n,o=Qd(t,r);return i!==void 0&&(o.label=i),a||gd(t,e=>$d(t,o,e)),!0},(e,t)=>{let n=e.match(Kd);if(!n)return!1;let[,r,i,a,o,s,c]=n;return t.rels.push({from:Qd(t,r).id,to:Qd(t,s).id,arrow:a===`..`?`..`:`--`,props:[`caption: ${uc(`${Wd[i]} to ${Gd[o]}`)}`],label:W(c)||void 0}),!0},(e,t)=>{let n=e.match(Yd);return n&&(Qd(t,n[1]).label=n[2]),!!n},(e,t,n)=>Xd.test(e)?(t.ctx.warnOnce(`erstyle`,n,`ER styles and classes are skipped`),!0):!1,(e,t)=>Zd.test(e)?(Qd(t,e),!0):!1],tf=(e,t)=>{let n=md(e,t);return hd(n,ef),Cd(n,[],[])},nf=/^section\s+(.*)$/;function rf(e,t){let n=yc(e.text);return n!==void 0&&(t.title=n,!0)}function af(e,t,n,r){Sc({lines:e,index:0},t,e=>rf(e,n)||r(e))}function of(e,t){return t.length?`${e} [${t.join(`, `)}]`:e}function sf(e,t){for(let n of t.filter(Boolean))e.push(` - ${n}`)}var cf=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function lf(e){let t={};for(let n of e.matchAll(cf))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}var uf=e=>/[[\]:]|^"/.test(e)?uc(e):e,df=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,ff=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,pf=/^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/,mf=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i,hf=/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/;function gf(e){let t=new Map,n=new Set;return(r,i,a=!1)=>{let o=r.trim(),s=t.get(o),c=!s;if(s||(s=pc(o),t.set(o,s)),i!==void 0||c&&s!==o){let t=a?`actor`:`participant`,r=i??o;n.has(s)||e.push(r===s?`${t} ${s}`:`${t} ${s} ${uc(r)}`),n.add(s)}return s}}function _f(e,t,n,r){return t&&n.warnOnce(`act`,r,`activation markers (+/-) are skipped`),e.endsWith(`x`)&&n.warnOnce(`cross`,r,`cross arrow ends (-x) are drawn as normal arrows`),e.startsWith(`<<`)&&n.warnOnce(`bidi`,r,`two-way arrows (<<->>) are drawn one way`),e.replace(/^<</,``).startsWith(`--`)?`-->`:`->`}var vf=(e,t)=>{let n={title:t.title},r=[],i=gf(r),a=!1,o=e=>{let n=e.text.match(pf);if(!n)return!1;let[,r,a,o]=n,s=a;return/@\{/.test(s)&&(t.warnOnce(`ptype`,e.line,`participant types (@{ "type": … }) are skipped`),s=s.replace(/@\{.*$/,``)),i(s,o===void 0?s.trim():W(o),r===`actor`),!0},s=e=>{let t=e.text.match(mf);if(!t)return!1;let n=t[1].split(`,`).map(e=>i(e));return r.push(`note ${n.join(`, `)}: ${W(t[2])}`),!0},c=e=>{let n=e.text.match(ff);return n?(t.warnOnce(`block`,e.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[n[1],W(n[2])].filter(Boolean).join(` `)} ---`),!0):!1},l=e=>{if(/^rect\b/.test(e.text))return t.warnOnce(`rect`,e.line,`"rect" highlight boxes are skipped`),!0;let n=e.text.match(hf);return n?(t.warnOnce(n[1],e.line,`"${n[1]}" is not supported and was skipped`),!0):!1},u=e=>{let n=e.text.match(df);if(!n)return!1;let[,a,o,s,c,l]=n,u=_f(o,s,t,e.line);return r.push(`${i(a)} ${u} ${i(c)}: ${W(l)}`),!0};return af(e,t,n,e=>e.text===`autonumber`||e.text.startsWith(`autonumber `)?(a=!0,!0):o(e)||s(e)||c(e)||e.text===`end`||l(e)||u(e)),gc(`sequence`,hc(n.title,`seq`),n.title,a?[`numbered`]:[],r)},yf=/^commit\b(.*)$/,bf=/^branch\s+("[^"]*"|\S+)(.*)$/,xf=/^(checkout|switch)\s+(.+)$/,Sf=/^merge\s+("[^"]*"|\S+)(.*)$/,Cf=/^cherry-pick\b(.*)$/,wf=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``);function Tf(e){let t=[];e.id&&t.push(`id: ${dc(wf(e.id))}`),e.tag&&t.push(`tag: ${dc(e.tag)}`);let n=e.type?.toUpperCase();return n===`HIGHLIGHT`?t.push(`highlight`):n===`REVERSE`&&t.push(`reverse`),t}function Ef(e,t){let n=t.header.match(/^\s*(LR|TB|BT)\s*:?/)?.[1];return n===`BT`&&t.warn(e[0]?.line??1,`bottom-to-top git graphs are drawn top to bottom`),n===`TB`||n===`BT`?[`direction: down`]:[]}var Df=(e,t)=>{let n={title:t.title},r=Ef(e,t),i=[],a=(e,n)=>{n.parent&&t.warnOnce(`parent`,e.line,`cherry-pick "parent" is skipped`),n.tag&&t.warnOnce(`cptag`,e.line,`cherry-pick "tag" is skipped`),n.id?i.push(`cherry-pick ${wf(n.id)}`):t.warn(e.line,`cherry-pick needs an id`)};return af(e,t,n,e=>{let t=e.text,n;if(n=t.match(yf)){let e=lf(n[1]);i.push(of(e.msg?`commit ${uc(e.msg)}`:`commit`,Tf(e)))}else if(n=t.match(bf)){let e=lf(n[2]).order;i.push(of(`branch ${wf(n[1])}`,e?[`order: ${e}`]:[]))}else if(n=t.match(xf))i.push(`${n[1]} ${wf(n[2])}`);else if(n=t.match(Sf))i.push(of(`merge ${wf(n[1])}`,Tf(lf(n[2]))));else if(n=t.match(Cf))a(e,lf(n[1]));else return!1;return!0}),gc(`git`,hc(n.title,`history`),n.title,r,i)},Of=/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/,kf=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=yc(r)??n.title);let i=[];return af(e,t,n,e=>{if(e.text===`showData`)return!0;let t=e.text.match(Of);return t&&i.push(`${uf(W(t[1]))}: ${t[2]}`),!!t}),gc(`chart`,hc(n.title,`pie`),n.title,[`type: pie`],i)},Af=/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/,jf=/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/;function Mf(e,t,n,r){let i=hc(r,`xy`);if(!e.length)return gc(`chart`,i,r,[`type: column`],[]);let a=[];return e.forEach((e,o)=>{let s=e.values.map((e,n)=>`${uf(t[n]??String(n+1))}: ${e}`),c=e.type===`line`?`line`:n?`bar`:`column`;o&&a.push(``),a.push(...gc(`chart`,o?`${i}${o+1}`:i,r,[`type: ${c}`],s))}),a}var Nf=(e,t)=>{let n={title:t.title},r=[],i=[];return af(e,t,n,e=>{let n=e.text.match(Af);if(n){let i=n[1].trim();return i.startsWith(`[`)?r=kc(i).map(e=>W(e)):t.warnOnce(`xrange`,e.line,`a numeric x-axis range becomes 1, 2, 3, …`),!0}if(/^y-axis\b/.test(e.text))return t.warnOnce(`yaxis`,e.line,`the y-axis title and range are skipped; the chart scales to the data`),!0;let a=e.text.match(jf);return a&&i.push({type:a[1],values:kc(a[2]),line:e.line}),!!a}),i.length>1&&t.warn(i[1].line,`each xychart series becomes its own chart; yuhwa charts plot one series`),Mf(i,r,/\bhorizontal\b/.test(t.header),n.title)},Pf=/^([xy])-axis\s+(.*)$/,Ff=/^quadrant-([1-4])\s+(.*)$/,If=/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/,Lf=/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i;function Rf(e,t,n){let[,r,i,a,o]=t,s=lf(o.replace(/,/g,` `));/:::/.test(e.text)&&n.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`),(s.radius||s[`stroke-color`]||s[`stroke-width`])&&n.warnOnce(`qstyle`,e.line,`point radius and stroke are skipped`);let c=s.color&&Lf.test(s.color)?` [${s.color}]`:``;return`${W(r)}${c}: ${i}, ${a}`}var zf=(e,t)=>{let n={title:t.title},r=[];return af(e,t,n,e=>{let n=e.text,i;if(i=n.match(Pf)){let[e,t]=i[2].split(/\s*-->\s*/).map(e=>W(e));r.push(`${i[1]}-axis ${e}${t?` -> ${t}`:``}`)}else if(i=n.match(Ff))r.push(`q${i[1]}: ${W(i[2])}`);else if(/^classDef\b/.test(n))t.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`);else if(i=n.match(If))r.push(Rf(e,i,t));else return!1;return!0}),gc(`quadrant`,hc(n.title,`matrix`),n.title,[],r)},Bf=new Set([`done`,`active`,`crit`,`milestone`]),Vf=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,Hf=/^([^:]+?)\s*:\s*(.*)$/,Uf=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/;function Wf(e){let t=new Set,n=[];for(let r of e){let e=r.text.match(Hf);if(!e||/^(title|dateFormat|section)\b/.test(r.text)||Vf.test(r.text)||bc.test(r.text))continue;let i=e[2].split(`,`).map(e=>e.trim()).filter(Boolean);n.push({l:r,label:e[1],items:i});let a=i.filter(e=>!Bf.has(e));a.length===3&&t.add(pc(a[0]))}return{tasks:n,taken:t}}function Gf(e){let t=0;return()=>{let n;do n=`t${++t}`;while(e.has(n));return n}}function Kf(e,t,n){let r=e.match(Uf);return!r||[`h`,`d`,`w`].includes(r[2])?e:(t.warnOnce(`mins`,n,`minute and second lengths are rounded up to 1h`),`1h`)}function qf(e,t){return e.replace(/^after\s+(.*)$/,(e,n)=>`after `+n.split(/\s+/).map(e=>t.get(e)??pc(e)).join(` `))}var Jf=(e,t)=>{let n={title:t.title},{tasks:r,taken:i}=Wf(e),a=Gf(i),o=new Map,s=[],c=0,l=!0,u=e=>e.length>=3?{id:pc(e[0]),from:e[1],to:e[2]}:e.length===2?{id:a(),from:e[0],to:e[1]}:{id:a(),to:e[0]},d=(e,n)=>{let r=n.items.filter(e=>Bf.has(e)),i=n.items.filter(e=>!Bf.has(e)),{id:a,from:c,to:d}=u(i);i.length>=3&&o.set(i[0],a),i.length>3&&t.warn(e.line,`extra task fields "${i.slice(3).join(`, `)}" are skipped`),l&&!c&&t.warn(e.line,`the first task has no start date`),l=!1;let f=d;f?.startsWith(`until `)&&(t.warnOnce(`until`,e.line,`"until" ends become a 1d length`),f=`1d`),f&&=Kf(f,t,e.line);let p=c?qf(c,o):``,m=(r.includes(`milestone`)?[p]:[p,f??``]).filter(Boolean).join(`, `),h=[a,uc(W(n.label)),r.length?`[${r.join(`, `)}]`:``].filter(Boolean).join(` `);s.push(m?`${h}: ${m}`:h)};return af(e,t,n,e=>{let n=e.text,i=n.match(/^dateFormat\s+(.*)$/);if(i)return/^YYYY-MM-DD( HH:mm)?$/.test(i[1].trim())||t.warn(e.line,`dateFormat "${i[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`),!0;if(Vf.test(n)){let r=n.split(/\s+/)[0];return t.warnOnce(r,e.line,`"${r}" is not supported and was skipped`),!0}let a=n.match(nf);if(a)return s.push(`--- ${W(a[1])} ---`),!0;let o=r[c];return!o||o.l!==e?!1:(c++,d(e,o),!0)}),gc(`gantt`,hc(n.title,`plan`),n.title,[],s)},Yf=(e,t)=>{let n={title:t.title},r=[],i,a=0,o=(e,[n,a,...o])=>{let s=i?` [${i}]`:``;a?(r.push(`${n}${s}: ${a}`),sf(r,o)):(t.warn(e.line,`event "${n}" has no text`),r.push(`${n}${s}: ${n}`))},s=(e,n)=>{!r.length||r[r.length-1].startsWith(`//`)?t.warn(e.line,`event detail "${e.text}" has no event above it`):sf(r,n.slice(1))};return af(e,t,n,e=>{let n=e.text.match(nf);if(n)return i=Nc[a++%Nc.length],t.warnOnce(`section`,e.line,`timeline sections become a colour per section`),r.push(`// ${W(n[1])}`),!0;let c=e.text.split(/\s*:\s*/).map(e=>W(e));return e.text.startsWith(`:`)?s(e,c):o(e,c),!0}),gc(`timeline`,hc(n.title,`events`),n.title,[],r)},Xf=/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/,Zf=e=>e<=2?`red`:e<4?`amber`:`green`,Qf=(e,t)=>{let n={title:t.title},r=[];return af(e,t,n,e=>{let n=e.text.match(nf);if(n)return r.push(`// ${W(n[1])}`),!0;let i=e.text.match(Xf);if(!i)return!1;let[,a,o,s]=i;return s&&t.warnOnce(`actors`,e.line,`journey actors are skipped; scores become a column chart`),r.push(`${uf(W(a))} [${Zf(Number(o))}]: ${o}`),!0}),gc(`chart`,hc(n.title,`journey`),n.title,[`type: column`],r)},$f=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function ep(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 $f){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:fc(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:fc(r,!0)}}var tp=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(xc(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=ep(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return gc(`mindmap`,hc(t.title,`map`),t.title,[`layout: both`],n)},np=l({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`}),rp=/([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g,ip=[`assigned`,`ticket`,`priority`];function ap(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(rp))t[e[1]]=e[2].trim().replace(/^(['"])(.*)\1$/,`$2`);let i=r.match(/^[\w-]*\[(.*)\]$/);return i&&(r=i[1]),{text:W(r,!0),meta:t}}function op(e,t,n){let r=[];if(e.assigned&&r.push(`owner: ${dc(e.assigned)}`),e.ticket&&r.push(`ticket: ${dc(e.ticket)}`),e.priority){let i=np[e.priority.toLowerCase()];i?(/very/i.test(e.priority)&&t.warnOnce(`very`,n,`"Very High" and "Very Low" priorities become high and low`),r.push(`priority: ${i}`)):t.warn(n,`priority "${e.priority}" is skipped`)}for(let[t,n]of Object.entries(e))!ip.includes(t)&&/^[\w-]+$/.test(t)&&r.push(`${t}: ${dc(n)}`);return r}var sp=(e,t)=>{let n=[],r=Math.min(...e.filter(e=>!bc.test(e.text)).map(e=>e.indent));for(let i of e){if(xc(i,t))continue;let{text:e,meta:a}=ap(i.text);i.indent<=r?n.push(e):n.push(of(` - ${e}`,op(a,t,i.line)))}return gc(`kanban`,hc(t.title,`board`),t.title,[],n)},cp={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},lp=/^(hide empty description|scale\b)/,up=/^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/,dp=/^state\s+(\S+)\s+<<(fork|join|choice)>>$/,fp=/^state\s+"([^"]*)"\s+as\s+(\S+)$/,pp=/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/,mp=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,hp=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i,gp=/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/,_p=/^([^\s:]+)\s*:\s*(.*)$/,vp=/^(click|link|callback)\b/,yp=/^[\p{L}\p{N}_-]+$/u,bp=/^(.+?)(?::::([\w-]+))?$/,xp=class e{nodes=new Map;boxes=new Map;root={id:``,label:``,items:[]};stack=[this.root];edges=[];classDefs=[];direction=`down`;title;noteCount=0;cursor;ctx;constructor(e,t){this.cursor={lines:e,index:0},this.ctx=t,this.title=t.title}convert(){return Sc(this.cursor,this.ctx,t=>e.HANDLERS.some(e=>e.call(this,t.text,t))),this.stack.length>1&&this.ctx.warn(this.cursor.lines[this.cursor.lines.length-1]?.line??1,`composite state is missing "}"`),this.attachCompositeEdges(),this.write()}static HANDLERS=[e.prototype.readSkipped,e.prototype.readTitle,e.prototype.readDirection,e.prototype.readCompositeClose,e.prototype.readConcurrency,e.prototype.readCompositeOpen,e.prototype.readPseudoState,e.prototype.readStateAlias,e.prototype.readStateDeclaration,e.prototype.readClassDef,e.prototype.readClass,e.prototype.readStyle,e.prototype.readNote,e.prototype.readTransition,e.prototype.readDescription,e.prototype.readClick,e.prototype.readBareName];get current(){return this.stack[this.stack.length-1]}node(e,t=`state`){let n=pc(e),r=this.nodes.get(n);if(r)return t!==`state`&&(r.kind=t),r;let i={id:n,kind:t,descs:[],classes:[]};return n!==e.trim()&&(i.label=fc(e)),this.nodes.set(n,i),this.boxes.has(n)||this.current.items.push(n),i}pseudo(e){let t=this.current,n=e?`end`:`start`;if(!t[n]){let e=t.id?`${t.id}_${n}`:n;t[n]=e,this.nodes.set(e,{id:e,label:``,kind:n,descs:[],classes:[]}),t.items.push(e)}return t[n]}endpoint(e,t){if(e===`[*]`)return this.pseudo(t);let[,n,r]=e.match(bp);if(this.boxes.has(pc(n)))return pc(n);let i=this.node(n);return r&&!i.classes.includes(r)&&i.classes.push(r),i.id}readSkipped(e){return lp.test(e)}readTitle(e){let t=yc(e,!1);return t!==void 0&&(this.title=t),t!==void 0}readDirection(e,t){let n=e.match(wc);return n?(this.stack.length>1?this.ctx.warnOnce(`subdir`,t.line,`direction inside a composite state is skipped`):this.direction=Cc[n[1].toUpperCase()],!0):!1}readCompositeClose(e,t){return e===`}`&&(this.stack.length>1?this.stack.pop():this.ctx.warn(t.line,`"}" without a composite state`),!0)}readConcurrency(e,t){return e===`--`&&(this.ctx.warnOnce(`conc`,t.line,`concurrent regions (--) are drawn as one region`),!0)}readCompositeOpen(e){let t=e.match(up);if(!t)return!1;let[,n,r]=t,i=pc(r);if(this.nodes.delete(i))for(let e of[this.root,...this.boxes.values()])e.items=e.items.filter(e=>e!==i);let a={id:i,label:n===void 0?r:fc(n),items:[]};return this.boxes.set(i,a),this.current.items.push(a),this.stack.push(a),!0}readPseudoState(e){let t=e.match(dp);return t&&(this.node(t[1],t[2]===`choice`?`choice`:`fork`).label=``),!!t}readStateAlias(e){let t=e.match(fp);return t&&(this.node(t[2]).label=W(t[1])),!!t}readStateDeclaration(e){let t=e.match(pp);if(!t)return!1;let n=this.node(t[1]);return t[2]&&n.descs.push(W(t[2])),!0}readClassDef(e,t){let n=Oc(e,e=>this.ctx.warn(t.line,e));return this.classDefs.push(...n??[]),!!n}readClass(e){let t=e.match(mp);if(!t)return!1;for(let e of t[1].split(`,`))this.node(e.trim()).classes.push(t[2]);return!0}readStyle(e,t){let n=Ec(e,e=>this.ctx.warn(t.line,e));return n&&(this.node(n.target).style=n.props),!!n}readNote(e){let t=e.match(hp);if(!t)return!1;let n=t[2]??this.readNoteBody(),r=this.endpoint(t[1].trim(),!1),i=`note${++this.noteCount}`;return this.nodes.set(i,{id:i,label:fc(n),kind:`note`,descs:[],classes:[]}),this.current.items.push(i),this.edges.push({from:i,to:r,dotted:!0}),!0}readNoteBody(){let e=[];for(;++this.cursor.index<this.cursor.lines.length&&this.cursor.lines[this.cursor.index].text!==`end note`;)e.push(this.cursor.lines[this.cursor.index].text);return e.join(`
21
- `)}readTransition(e,t){let n=e.match(gp);if(!n)return!1;let r=this.endpoint(n[1],!1),i=this.endpoint(n[2],!0);return this.edges.push({from:r,to:i,label:n[3]?W(n[3]):void 0,line:t.line}),!0}readDescription(e){let t=e.match(_p);return t&&this.node(t[1]).descs.push(W(t[2])),!!t}readClick(e,t){return vp.test(e)?(this.ctx.warnOnce(`click`,t.line,`click handlers are skipped`),!0):!1}readBareName(e){return yp.test(e)?(this.node(e),!0):!1}attachCompositeEdges(){for(let e of this.edges){let t=this.boxes.get(e.from),n=this.boxes.get(e.to);(t||n)&&this.ctx.warnOnce(`composite`,e.line??1,`edges to a composite state attach to its start or end inside`),t&&(e.from=t.end??Ep(t)??e.from),n&&(e.to=n.start??Tp(n)??e.to)}}write(){let e=[];this.writeBox(this.root,0,e),this.edges.length&&e.push(``);for(let t of this.edges)e.push(wp(t));let t=[this.title?`title: ${this.title}`:``,`direction: ${this.direction}`].filter(Boolean),n=[...this.pseudoClassDefs(),...this.classDefs];return[...t,...n.length?[``,...n]:[],``,...e]}writeBox(e,t,n){let r=` `.repeat(t);for(let i of e.items)typeof i==`string`?n.push(r+Cp(this.nodes.get(i))):(n.push(`${r}group ${i.id} ${uc(i.label)} {`),this.writeBox(i,t+1,n),n.push(`${r}}`))}pseudoClassDefs(){let e=new Set([...this.nodes.values()].map(e=>e.kind)),t=this.direction===`right`||this.direction===`left`,n=[];return e.has(`start`)&&n.push(`.state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]`),e.has(`end`)&&n.push(`.state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]`),e.has(`fork`)&&n.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${t?8:70}, height: ${t?70:8}]`),e.has(`choice`)&&n.push(`.state-choice [shape: diamond, width: 28, height: 28]`),n}},Sp=(e,t)=>new xp(e,t).convert();function Cp(e){let t=[e.id],n=e.label??e.id;(n!==e.id||e.kind===`note`)&&t.push(uc(n));let r=cp[e.kind];r&&t.push(`.${r}`);for(let n of e.classes)t.push(`.${n}`);let i=[];return e.kind===`note`&&i.push(`shape: note`),e.descs.length&&i.push(`sub: ${uc(e.descs.join(` / `))}`),e.style&&i.push(e.style),i.length&&t.push(`[${i.join(`, `)}]`),t.join(` `)}function wp(e){let t=e.dotted?`..`:`->`;return`${e.from} ${t} ${e.to}${e.label?`: `+Ac(e.label):``}`}function Tp(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??Tp(t);if(e)return e}}function Ep(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??Ep(n);if(r)return r}}var Dp=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*(?:;.*)?$/i;function Op(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}var kp=/%%.*$/,Ap=/^\s*title\s*:\s*(.+)$/;function jp(e){return e.replace(kp,``)}function Mp(e){let t;for(let n=0;n<Op(e);n++){let r=e[n].match(Ap);r&&(t=fc(r[1]))}return t}function Np(e,t){let n=[];for(let r=t;r<e.length;r++){let t=jp(e[r]).replace(/\s+$/,``),i=t.trim();if(!i)continue;let a=t.match(/^\s*/)[0];n.push({text:i,line:r+1,indent:a.replace(/\t/g,` `).length})}return n}var Pp=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],Fp=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,Ip=/^[\w-]+/,Lp=`:::`,Rp=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,zp=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/,Bp=class{pos=0;nodes=[];edges=[];text;toId;warn;constructor(e,t,n){this.text=e,this.toId=t,this.warn=n}read(){let e=this.readNodeGroup();if(!e)return this.warn(`could not read "${this.text}"`),null;let t=e;for(;!this.atEnd();){let e=this.readLink();if(!e){this.warn(`could not read "${this.text.slice(this.pos)}"`);break}let n=this.readNodeGroup();if(!n){this.warn(`link without a target in "${this.text}"`);break}this.addEdges(t,n,e),t=n}return{nodes:this.nodes,edges:this.edges}}atEnd(){return this.skipSpace(),this.pos>=this.text.length}skipSpace(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}rest(){return this.text.slice(this.pos)}readNodeGroup(){let e=[];for(;;){let t=this.readNode();if(!t)return e.length?e:null;if(e.push(t),this.skipSpace(),this.text[this.pos]!==`&`)return e;this.pos++}}readNode(){this.skipSpace();let e=this.rest().match(Fp);if(!e)return null;this.pos+=e[0].length;let t={id:this.toId(e[0]),classes:[]};return this.readShape(t),this.readClasses(t),this.nodes.push(t),t}readShape(e){for(let[t,n,r]of Pp){if(!this.text.startsWith(t,this.pos))continue;let i=this.pos+t.length,a=Gp(this.text,i,n);if(!(a<0)){e.label=fc(this.text.slice(i,a)),e.shape=r||void 0,this.pos=a+n.length;return}}}readClasses(e){for(;this.text.startsWith(Lp,this.pos);){let t=this.text.slice(this.pos+3).match(Ip);if(!t)return;e.classes.push(t[0]),this.pos+=3+t[0].length}}readLink(){let e=this.rest(),t=e.match(Rp);if(t&&/[->=]/.test(t[4])){this.pos+=t[0].length;let[,e,n,r,i,a]=t;return{start:e,body:n,end:i.endsWith(`>`)?`>`:a,label:fc(r)}}let n=e.match(zp);if(!n)return null;this.pos+=n[0].length;let[,r,i,a,o]=n;return{start:r,body:i,end:a,label:o===void 0?void 0:fc(o)}}addEdges(e,t,n){let{arrow:r,props:i}=Hp(n);for(let a of e)for(let e of t)this.edges.push({from:a.id,to:e.id,arrow:r,label:n.label||void 0,props:i})}},Vp={o:`dot`,x:`bar`};function Hp({start:e,body:t,end:n}){let r=t.startsWith(`=`),i=t.includes(`.`),a=e&&n?`<->`:n?r?`=>`:i?`..>`:`->`:`--`,o=[];return(a===`<->`||a===`--`)&&Up(o,r,i),Wp(o,e,n),e&&!n&&o.push(`tail: arrow`),{arrow:a,props:o}}function Up(e,t,n){t&&e.push(`width: 3`),n&&e.push(`style: dotted`)}function Wp(e,t,n){n&&n in Vp&&e.push(`head: ${Vp[n]}`),t&&t in Vp&&e.push(`tail: ${Vp[t]}`)}function Gp(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}function Kp(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}var qp=/^subgraph\s+(.*)$/,Jp=/^([\w-]+)\s*\[(.*)\]$/,Yp=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,Xp=/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/,Zp=/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u;function Qp(e){let t=e.split(`
22
- `),n=new $p(Mp(t));for(let e=Op(t);e<t.length;e++)for(let r of Kp(jp(t[e])))n.statement(r.trim(),e+1);return n.finish(t.length)}var $p=class{warnings=[];settings=[];classDefs=[];body=[];ids=new Map;declared=new Set;groupIds=new Set;depth=0;openEdges=new Map;line=0;constructor(e){e!==void 0&&this.settings.push(`title: ${e}`)}statement(e,t){e&&(this.line=t,this.header(e)||this.title(e)||this.direction(e)||this.subgraph(e)||this.end(e)||this.classDef(e)||this.classAssign(e)||this.style(e)||this.unsupported(e)||this.nodesAndEdges(e))}finish(e){for(;this.depth>0;)this.closeGroup(),this.warnings.push({line:e,message:`subgraph is missing "end"`});for(let e of this.groupIds)this.declared.has(e)&&this.warnings.push({line:1,message:`"${e}" is both a node and a subgraph; edges to subgraphs are not supported`});let t=[...this.settings,...this.classDefs.length?[``,...this.classDefs]:[]],n=this.body.map(e=>typeof e==`string`?e:tm(e));return{source:[...t,...t.length?[``]:[],...n].join(`
20
+ `,errors:t}}var hd=/^"(.*)"$/;function gd(e){return{id:e,attrs:[],methods:[],rows:[],classes:[]}}function _d(e,t){return{ctx:t,lines:e,index:0,cards:new Map,root:{id:``,label:``,items:[]},rels:[],direction:`down`,title:t.title}}function vd(e,t){Tc(e,e.ctx,({text:n,line:r})=>t.some(t=>t(n,e,r)))}function yd(e,t){for(;++e.index<e.lines.length&&e.lines[e.index].text!==`}`;)t(e.lines[e.index])}var bd=(e,t)=>{let n=Sc(e,!1);return n!==void 0&&(t.title=n),n!==void 0},xd=(e,t)=>{let n=e.match(Dc);return n&&(t.direction=Ec[n[1].toUpperCase()]),!!n};function Sd(e){let t=[e.id];e.label!==void 0&&e.label!==e.id&&t.push(pc(e.label));for(let n of e.classes)t.push(`.${n}`);let n=[];return e.note&&n.push(`shape: note`),e.sub&&n.push(`sub: ${pc(e.sub)}`),e.style&&n.push(e.style),n.length&&t.push(`[${n.join(`, `)}]`),t}function Cd(e){if(e.rows.length)return e.rows;let t=e.attrs.length&&e.methods.length?[`---`]:[];return[...e.attrs,...t,...e.methods]}function wd(e,t){let n=Sd(e),r=Cd(e);return r.length?(n.length===1&&n.push(pc(e.id)),[`${t}${n.join(` `)} {`,...r.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function Td(e){let t=[e.label?Nc(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);return`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`}function Ed(e,t,n){let r=(t,n)=>t.items.flatMap(t=>wd(e.cards.get(t),n)),i=r(e.root,``);for(let e of n)i.push(`group ${e.id} ${pc(e.label)} {`,...r(e,` `),`}`);return e.rels.length&&i.push(``),i.push(...e.rels.map(Td)),[...[e.title?`title: ${e.title}`:``,`direction: ${e.direction}`].filter(Boolean),...t.length?[``,...t]:[],``,...i]}var Dd=l({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),Od=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,kd=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,Ad=/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/,jd=/^namespace\s+(\S+)\s*\{$/,Md=/^<<(.+)>>$/,Nd=/^<<(.+)>>\s+(\S+)$/,Pd=/^note\s+for\s+(\S+)\s+"(.*)"$/,Fd=/^note\s+"(.*)"$/,Id=/^cssClass\s+"([^"]+)"\s+([\w-]+)$/,Ld=/^(click|callback|link)\b/,Rd=/^([^\s:]+)\s*:\s*(.*)$/,zd=e=>e.replace(/~([^~]*)~/g,`<$1>`),Bd=e=>e.replace(/~[^~]*~/g,``),Vd=e=>`«${e.trim()}»`;function Hd(e,t){let n=gc(Bd(t)),r=e.cards.get(n);return r||(r=gd(n),(n!==t||/~/.test(t))&&(r.label=zd(t.replace(hd,`$1`))),e.cards.set(n,r),e.scope.items.push(n)),r}function Ud(e,t){let n=zd(t.trim());if(!n)return;let r=n.match(Md);r?e.sub=Vd(r[1]):(n.includes(`(`)?e.methods:e.attrs).push(n)}function Wd(e,t){let n=`note${++e.notes}`;return e.cards.set(n,{...gd(n),label:hc(t),note:!0}),e.scope.items.push(n),n}var Gd=[bd,xd,(e,t)=>{let n=e.match(jd);return n&&(t.scope={id:gc(n[1]),label:n[1],items:[]},t.scopes.push(t.scope)),!!n},(e,t,n)=>e===`}`&&(t.scope===t.root?t.ctx.warn(n,`"}" without a namespace`):t.scope=t.root,!0),(e,t)=>{let n=e.match(Ad);if(!n)return!1;let[,r,i,a,o,s,c]=n,l=Hd(t,r+(i??``));return a!==void 0&&(l.label=W(a)),o&&l.classes.push(o),s&&!c&&yd(t,e=>Ud(l,e.text)),!0},(e,t)=>{let n=e.match(Nd);return n&&(Hd(t,n[2]).sub=Vd(n[1])),!!n},(e,t)=>{let n=e.match(Pd);if(n){let e=Wd(t,n[2]);t.rels.push({from:e,to:Hd(t,n[1]).id,arrow:`..`,props:[]})}return!!n},(e,t)=>{let n=e.match(Fd);return n&&Wd(t,n[1]),!!n},(e,t,n)=>{let r=jc(e,e=>t.ctx.warn(n,e));return t.classDefs.push(...r??[]),!!r},(e,t)=>{let n=e.match(Id);if(n)for(let e of n[1].split(`,`))Hd(t,e.trim()).classes.push(n[2]);return!!n},(e,t,n)=>{let r=kc(e,e=>t.ctx.warn(n,e));return r&&(Hd(t,r.target).style=r.props),!!r},(e,t,n)=>Ld.test(e)?(t.ctx.warnOnce(`click`,n,`click, link and callback are skipped`),!0):!1,(e,t,n)=>{let r=e.match(Od)??e.match(kd);if(!r)return!1;let[,i,a,o,s,c,l,u,d]=r,f=[];o&&f.push(`tail: ${Dd[o]}`),c&&f.push(`head: ${Dd[c]}`),(o===`o`||c===`o`)&&t.ctx.warnOnce(`aggr`,n,`aggregation (o--) is drawn with a filled diamond, like composition`);let p=[a,l].filter(e=>e!==void 0);return p.length&&f.push(`caption: ${pc(p.join(` to `))}`),t.rels.push({from:Hd(t,i).id,to:Hd(t,u).id,arrow:s,props:f,label:d?W(d):void 0}),!0},(e,t)=>{let n=e.match(Rd);return n&&Ud(Hd(t,n[1]),n[2]),!!n}],Kd=(e,t)=>{let n=_d(e,t),r={...n,scopes:[],scope:n.root,classDefs:[],notes:0};return vd(r,Gd),Ed(r,r.classDefs,r.scopes)},qd={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},Jd={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Yd=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,Xd=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,Zd=/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/,Qd=/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/,$d=/^(classDef|class|style)\b/,ef=/^("[^"]*"|[\w-]+)$/;function tf(e,t){let n=t.replace(hd,`$1`),r=gc(n),i=e.cards.get(r);return i||(i=gd(r),r!==n&&(i.label=n),e.cards.set(r,i),e.root.items.push(r)),i}function nf(e,t,n){let r=n.text.match(Xd);if(!r){e.ctx.warn(n.line,`could not read attribute "${n.text}"`);return}let[,i,a,o,s]=r,c=[i,a,o.replace(/\s+/g,``).replace(/,/g,`, `),s??``].map(e=>e.replace(/\|/g,`/`));t.rows.push(`| ${c.join(` | `)} |`)}var rf=[bd,xd,(e,t)=>{let n=e.match(Zd);if(!n)return!1;let[,r,i,a]=n,o=tf(t,r);return i!==void 0&&(o.label=i),a||yd(t,e=>nf(t,o,e)),!0},(e,t)=>{let n=e.match(Yd);if(!n)return!1;let[,r,i,a,o,s,c]=n;return t.rels.push({from:tf(t,r).id,to:tf(t,s).id,arrow:a===`..`?`..`:`--`,props:[`caption: ${pc(`${qd[i]} to ${Jd[o]}`)}`],label:W(c)||void 0}),!0},(e,t)=>{let n=e.match(Qd);return n&&(tf(t,n[1]).label=n[2]),!!n},(e,t,n)=>$d.test(e)?(t.ctx.warnOnce(`erstyle`,n,`ER styles and classes are skipped`),!0):!1,(e,t)=>ef.test(e)?(tf(t,e),!0):!1],af=(e,t)=>{let n=_d(e,t);return vd(n,rf),Ed(n,[],[])},of=/^section\s+(.*)$/;function sf(e,t){let n=Sc(e.text);return n!==void 0&&(t.title=n,!0)}function cf(e,t,n,r){Tc({lines:e,index:0},t,e=>sf(e,n)||r(e))}function lf(e,t){return t.length?`${e} [${t.join(`, `)}]`:e}function uf(e,t){for(let n of t.filter(Boolean))e.push(` - ${n}`)}var df=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function ff(e){let t={};for(let n of e.matchAll(df))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}var pf=e=>/[[\]:]|^"/.test(e)?pc(e):e,mf=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,hf=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,gf=/^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/,_f=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i,vf=/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/;function yf(e){let t=new Map,n=new Set;return(r,i,a=!1)=>{let o=r.trim(),s=t.get(o),c=!s;if(s||(s=gc(o),t.set(o,s)),i!==void 0||c&&s!==o){let t=a?`actor`:`participant`,r=i??o;n.has(s)||e.push(r===s?`${t} ${s}`:`${t} ${s} ${pc(r)}`),n.add(s)}return s}}function bf(e,t,n,r){return t&&n.warnOnce(`act`,r,`activation markers (+/-) are skipped`),e.endsWith(`x`)&&n.warnOnce(`cross`,r,`cross arrow ends (-x) are drawn as normal arrows`),e.startsWith(`<<`)&&n.warnOnce(`bidi`,r,`two-way arrows (<<->>) are drawn one way`),e.replace(/^<</,``).startsWith(`--`)?`-->`:`->`}var xf=(e,t)=>{let n={title:t.title},r=[],i=yf(r),a=!1,o=e=>{let n=e.text.match(gf);if(!n)return!1;let[,r,a,o]=n,s=a;return/@\{/.test(s)&&(t.warnOnce(`ptype`,e.line,`participant types (@{ "type": … }) are skipped`),s=s.replace(/@\{.*$/,``)),i(s,o===void 0?s.trim():W(o),r===`actor`),!0},s=e=>{let t=e.text.match(_f);if(!t)return!1;let n=t[1].split(`,`).map(e=>i(e));return r.push(`note ${n.join(`, `)}: ${W(t[2])}`),!0},c=e=>{let n=e.text.match(hf);return n?(t.warnOnce(`block`,e.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[n[1],W(n[2])].filter(Boolean).join(` `)} ---`),!0):!1},l=e=>{if(/^rect\b/.test(e.text))return t.warnOnce(`rect`,e.line,`"rect" highlight boxes are skipped`),!0;let n=e.text.match(vf);return n?(t.warnOnce(n[1],e.line,`"${n[1]}" is not supported and was skipped`),!0):!1},u=e=>{let n=e.text.match(mf);if(!n)return!1;let[,a,o,s,c,l]=n,u=bf(o,s,t,e.line);return r.push(`${i(a)} ${u} ${i(c)}: ${W(l)}`),!0};return cf(e,t,n,e=>e.text===`autonumber`||e.text.startsWith(`autonumber `)?(a=!0,!0):o(e)||s(e)||c(e)||e.text===`end`||l(e)||u(e)),yc(`sequence`,vc(n.title,`seq`),n.title,a?[`numbered`]:[],r)},Sf=/^commit\b(.*)$/,Cf=/^branch\s+("[^"]*"|\S+)(.*)$/,wf=/^(checkout|switch)\s+(.+)$/,Tf=/^merge\s+("[^"]*"|\S+)(.*)$/,Ef=/^cherry-pick\b(.*)$/,Df=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``);function Of(e){let t=[];e.id&&t.push(`id: ${mc(Df(e.id))}`),e.tag&&t.push(`tag: ${mc(e.tag)}`);let n=e.type?.toUpperCase();return n===`HIGHLIGHT`?t.push(`highlight`):n===`REVERSE`&&t.push(`reverse`),t}function kf(e,t){let n=t.header.match(/^\s*(LR|TB|BT)\s*:?/)?.[1];return n===`BT`&&t.warn(e[0]?.line??1,`bottom-to-top git graphs are drawn top to bottom`),n===`TB`||n===`BT`?[`direction: down`]:[]}var Af=(e,t)=>{let n={title:t.title},r=kf(e,t),i=[],a=(e,n)=>{n.parent&&t.warnOnce(`parent`,e.line,`cherry-pick "parent" is skipped`),n.tag&&t.warnOnce(`cptag`,e.line,`cherry-pick "tag" is skipped`),n.id?i.push(`cherry-pick ${Df(n.id)}`):t.warn(e.line,`cherry-pick needs an id`)};return cf(e,t,n,e=>{let t=e.text,n;if(n=t.match(Sf)){let e=ff(n[1]);i.push(lf(e.msg?`commit ${pc(e.msg)}`:`commit`,Of(e)))}else if(n=t.match(Cf)){let e=ff(n[2]).order;i.push(lf(`branch ${Df(n[1])}`,e?[`order: ${e}`]:[]))}else if(n=t.match(wf))i.push(`${n[1]} ${Df(n[2])}`);else if(n=t.match(Tf))i.push(lf(`merge ${Df(n[1])}`,Of(ff(n[2]))));else if(n=t.match(Ef))a(e,ff(n[1]));else return!1;return!0}),yc(`git`,vc(n.title,`history`),n.title,r,i)},jf=/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/,Mf=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=Sc(r)??n.title);let i=[];return cf(e,t,n,e=>{if(e.text===`showData`)return!0;let t=e.text.match(jf);return t&&i.push(`${pf(W(t[1]))}: ${t[2]}`),!!t}),yc(`chart`,vc(n.title,`pie`),n.title,[`type: pie`],i)},Nf=/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/,Pf=/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/;function Ff(e,t,n,r){let i=vc(r,`xy`);if(!e.length)return yc(`chart`,i,r,[`type: column`],[]);let a=[];return e.forEach((e,o)=>{let s=e.values.map((e,n)=>`${pf(t[n]??String(n+1))}: ${e}`),c=e.type===`line`?`line`:n?`bar`:`column`;o&&a.push(``),a.push(...yc(`chart`,o?`${i}${o+1}`:i,r,[`type: ${c}`],s))}),a}var If=(e,t)=>{let n={title:t.title},r=[],i=[];return cf(e,t,n,e=>{let n=e.text.match(Nf);if(n){let i=n[1].trim();return i.startsWith(`[`)?r=Mc(i).map(e=>W(e)):t.warnOnce(`xrange`,e.line,`a numeric x-axis range becomes 1, 2, 3, …`),!0}if(/^y-axis\b/.test(e.text))return t.warnOnce(`yaxis`,e.line,`the y-axis title and range are skipped; the chart scales to the data`),!0;let a=e.text.match(Pf);return a&&i.push({type:a[1],values:Mc(a[2]),line:e.line}),!!a}),i.length>1&&t.warn(i[1].line,`each xychart series becomes its own chart; yuhwa charts plot one series`),Ff(i,r,/\bhorizontal\b/.test(t.header),n.title)},Lf=/^([xy])-axis\s+(.*)$/,Rf=/^quadrant-([1-4])\s+(.*)$/,zf=/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/,Bf=/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i;function Vf(e,t,n){let[,r,i,a,o]=t,s=ff(o.replace(/,/g,` `));/:::/.test(e.text)&&n.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`),(s.radius||s[`stroke-color`]||s[`stroke-width`])&&n.warnOnce(`qstyle`,e.line,`point radius and stroke are skipped`);let c=s.color&&Bf.test(s.color)?` [${s.color}]`:``;return`${W(r)}${c}: ${i}, ${a}`}var Hf=(e,t)=>{let n={title:t.title},r=[];return cf(e,t,n,e=>{let n=e.text,i;if(i=n.match(Lf)){let[e,t]=i[2].split(/\s*-->\s*/).map(e=>W(e));r.push(`${i[1]}-axis ${e}${t?` -> ${t}`:``}`)}else if(i=n.match(Rf))r.push(`q${i[1]}: ${W(i[2])}`);else if(/^classDef\b/.test(n))t.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`);else if(i=n.match(zf))r.push(Vf(e,i,t));else return!1;return!0}),yc(`quadrant`,vc(n.title,`matrix`),n.title,[],r)},Uf=new Set([`done`,`active`,`crit`,`milestone`]),Wf=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,Gf=/^([^:]+?)\s*:\s*(.*)$/,Kf=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/;function qf(e){let t=new Set,n=[];for(let r of e){let e=r.text.match(Gf);if(!e||/^(title|dateFormat|section)\b/.test(r.text)||Wf.test(r.text)||Cc.test(r.text))continue;let i=e[2].split(`,`).map(e=>e.trim()).filter(Boolean);n.push({l:r,label:e[1],items:i});let a=i.filter(e=>!Uf.has(e));a.length===3&&t.add(gc(a[0]))}return{tasks:n,taken:t}}function Jf(e){let t=0;return()=>{let n;do n=`t${++t}`;while(e.has(n));return n}}function Yf(e,t,n){let r=e.match(Kf);return!r||[`h`,`d`,`w`].includes(r[2])?e:(t.warnOnce(`mins`,n,`minute and second lengths are rounded up to 1h`),`1h`)}function Xf(e,t){return e.replace(/^after\s+(.*)$/,(e,n)=>`after `+n.split(/\s+/).map(e=>t.get(e)??gc(e)).join(` `))}var Zf=(e,t)=>{let n={title:t.title},{tasks:r,taken:i}=qf(e),a=Jf(i),o=new Map,s=[],c=0,l=!0,u=e=>e.length>=3?{id:gc(e[0]),from:e[1],to:e[2]}:e.length===2?{id:a(),from:e[0],to:e[1]}:{id:a(),to:e[0]},d=(e,n)=>{let r=n.items.filter(e=>Uf.has(e)),i=n.items.filter(e=>!Uf.has(e)),{id:a,from:c,to:d}=u(i);i.length>=3&&o.set(i[0],a),i.length>3&&t.warn(e.line,`extra task fields "${i.slice(3).join(`, `)}" are skipped`),l&&!c&&t.warn(e.line,`the first task has no start date`),l=!1;let f=d;f?.startsWith(`until `)&&(t.warnOnce(`until`,e.line,`"until" ends become a 1d length`),f=`1d`),f&&=Yf(f,t,e.line);let p=c?Xf(c,o):``,m=(r.includes(`milestone`)?[p]:[p,f??``]).filter(Boolean).join(`, `),h=[a,pc(W(n.label)),r.length?`[${r.join(`, `)}]`:``].filter(Boolean).join(` `);s.push(m?`${h}: ${m}`:h)};return cf(e,t,n,e=>{let n=e.text,i=n.match(/^dateFormat\s+(.*)$/);if(i)return/^YYYY-MM-DD( HH:mm)?$/.test(i[1].trim())||t.warn(e.line,`dateFormat "${i[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`),!0;if(Wf.test(n)){let r=n.split(/\s+/)[0];return t.warnOnce(r,e.line,`"${r}" is not supported and was skipped`),!0}let a=n.match(of);if(a)return s.push(`--- ${W(a[1])} ---`),!0;let o=r[c];return!o||o.l!==e?!1:(c++,d(e,o),!0)}),yc(`gantt`,vc(n.title,`plan`),n.title,[],s)},Qf=(e,t)=>{let n={title:t.title},r=[],i,a=0,o=(e,[n,a,...o])=>{let s=i?` [${i}]`:``;a?(r.push(`${n}${s}: ${a}`),uf(r,o)):(t.warn(e.line,`event "${n}" has no text`),r.push(`${n}${s}: ${n}`))},s=(e,n)=>{!r.length||r[r.length-1].startsWith(`//`)?t.warn(e.line,`event detail "${e.text}" has no event above it`):uf(r,n.slice(1))};return cf(e,t,n,e=>{let n=e.text.match(of);if(n)return i=Ic[a++%Ic.length],t.warnOnce(`section`,e.line,`timeline sections become a colour per section`),r.push(`// ${W(n[1])}`),!0;let c=e.text.split(/\s*:\s*/).map(e=>W(e));return e.text.startsWith(`:`)?s(e,c):o(e,c),!0}),yc(`timeline`,vc(n.title,`events`),n.title,[],r)},$f=/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/,ep=e=>e<=2?`red`:e<4?`amber`:`green`,tp=(e,t)=>{let n={title:t.title},r=[];return cf(e,t,n,e=>{let n=e.text.match(of);if(n)return r.push(`// ${W(n[1])}`),!0;let i=e.text.match($f);if(!i)return!1;let[,a,o,s]=i;return s&&t.warnOnce(`actors`,e.line,`journey actors are skipped; scores become a column chart`),r.push(`${pf(W(a))} [${ep(Number(o))}]: ${o}`),!0}),yc(`chart`,vc(n.title,`journey`),n.title,[`type: column`],r)},np=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function rp(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 np){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:hc(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:hc(r,!0)}}var ip=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(wc(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=rp(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return yc(`mindmap`,vc(t.title,`map`),t.title,[`layout: both`],n)},ap=l({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`}),op=/([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g,sp=[`assigned`,`ticket`,`priority`];function cp(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(op))t[e[1]]=e[2].trim().replace(/^(['"])(.*)\1$/,`$2`);let i=r.match(/^[\w-]*\[(.*)\]$/);return i&&(r=i[1]),{text:W(r,!0),meta:t}}function lp(e,t,n){let r=[];if(e.assigned&&r.push(`owner: ${mc(e.assigned)}`),e.ticket&&r.push(`ticket: ${mc(e.ticket)}`),e.priority){let i=ap[e.priority.toLowerCase()];i?(/very/i.test(e.priority)&&t.warnOnce(`very`,n,`"Very High" and "Very Low" priorities become high and low`),r.push(`priority: ${i}`)):t.warn(n,`priority "${e.priority}" is skipped`)}for(let[t,n]of Object.entries(e))!sp.includes(t)&&/^[\w-]+$/.test(t)&&r.push(`${t}: ${mc(n)}`);return r}var up=(e,t)=>{let n=[],r=Math.min(...e.filter(e=>!Cc.test(e.text)).map(e=>e.indent));for(let i of e){if(wc(i,t))continue;let{text:e,meta:a}=cp(i.text);i.indent<=r?n.push(e):n.push(lf(` - ${e}`,lp(a,t,i.line)))}return yc(`kanban`,vc(t.title,`board`),t.title,[],n)},dp={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},fp=/^(hide empty description|scale\b)/,pp=/^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/,mp=/^state\s+(\S+)\s+<<(fork|join|choice)>>$/,hp=/^state\s+"([^"]*)"\s+as\s+(\S+)$/,gp=/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/,_p=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,vp=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i,yp=/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/,bp=/^([^\s:]+)\s*:\s*(.*)$/,xp=/^(click|link|callback)\b/,Sp=/^[\p{L}\p{N}_-]+$/u,Cp=/^(.+?)(?::::([\w-]+))?$/,wp=class e{nodes=new Map;boxes=new Map;root={id:``,label:``,items:[]};stack=[this.root];edges=[];classDefs=[];direction=`down`;title;noteCount=0;cursor;ctx;constructor(e,t){this.cursor={lines:e,index:0},this.ctx=t,this.title=t.title}convert(){return Tc(this.cursor,this.ctx,t=>e.HANDLERS.some(e=>e.call(this,t.text,t))),this.stack.length>1&&this.ctx.warn(this.cursor.lines[this.cursor.lines.length-1]?.line??1,`composite state is missing "}"`),this.attachCompositeEdges(),this.write()}static HANDLERS=[e.prototype.readSkipped,e.prototype.readTitle,e.prototype.readDirection,e.prototype.readCompositeClose,e.prototype.readConcurrency,e.prototype.readCompositeOpen,e.prototype.readPseudoState,e.prototype.readStateAlias,e.prototype.readStateDeclaration,e.prototype.readClassDef,e.prototype.readClass,e.prototype.readStyle,e.prototype.readNote,e.prototype.readTransition,e.prototype.readDescription,e.prototype.readClick,e.prototype.readBareName];get current(){return this.stack[this.stack.length-1]}node(e,t=`state`){let n=gc(e),r=this.nodes.get(n);if(r)return t!==`state`&&(r.kind=t),r;let i={id:n,kind:t,descs:[],classes:[]};return n!==e.trim()&&(i.label=hc(e)),this.nodes.set(n,i),this.boxes.has(n)||this.current.items.push(n),i}pseudo(e){let t=this.current,n=e?`end`:`start`;if(!t[n]){let e=t.id?`${t.id}_${n}`:n;t[n]=e,this.nodes.set(e,{id:e,label:``,kind:n,descs:[],classes:[]}),t.items.push(e)}return t[n]}endpoint(e,t){if(e===`[*]`)return this.pseudo(t);let[,n,r]=e.match(Cp);if(this.boxes.has(gc(n)))return gc(n);let i=this.node(n);return r&&!i.classes.includes(r)&&i.classes.push(r),i.id}readSkipped(e){return fp.test(e)}readTitle(e){let t=Sc(e,!1);return t!==void 0&&(this.title=t),t!==void 0}readDirection(e,t){let n=e.match(Dc);return n?(this.stack.length>1?this.ctx.warnOnce(`subdir`,t.line,`direction inside a composite state is skipped`):this.direction=Ec[n[1].toUpperCase()],!0):!1}readCompositeClose(e,t){return e===`}`&&(this.stack.length>1?this.stack.pop():this.ctx.warn(t.line,`"}" without a composite state`),!0)}readConcurrency(e,t){return e===`--`&&(this.ctx.warnOnce(`conc`,t.line,`concurrent regions (--) are drawn as one region`),!0)}readCompositeOpen(e){let t=e.match(pp);if(!t)return!1;let[,n,r]=t,i=gc(r);if(this.nodes.delete(i))for(let e of[this.root,...this.boxes.values()])e.items=e.items.filter(e=>e!==i);let a={id:i,label:n===void 0?r:hc(n),items:[]};return this.boxes.set(i,a),this.current.items.push(a),this.stack.push(a),!0}readPseudoState(e){let t=e.match(mp);return t&&(this.node(t[1],t[2]===`choice`?`choice`:`fork`).label=``),!!t}readStateAlias(e){let t=e.match(hp);return t&&(this.node(t[2]).label=W(t[1])),!!t}readStateDeclaration(e){let t=e.match(gp);if(!t)return!1;let n=this.node(t[1]);return t[2]&&n.descs.push(W(t[2])),!0}readClassDef(e,t){let n=jc(e,e=>this.ctx.warn(t.line,e));return this.classDefs.push(...n??[]),!!n}readClass(e){let t=e.match(_p);if(!t)return!1;for(let e of t[1].split(`,`))this.node(e.trim()).classes.push(t[2]);return!0}readStyle(e,t){let n=kc(e,e=>this.ctx.warn(t.line,e));return n&&(this.node(n.target).style=n.props),!!n}readNote(e){let t=e.match(vp);if(!t)return!1;let n=t[2]??this.readNoteBody(),r=this.endpoint(t[1].trim(),!1),i=`note${++this.noteCount}`;return this.nodes.set(i,{id:i,label:hc(n),kind:`note`,descs:[],classes:[]}),this.current.items.push(i),this.edges.push({from:i,to:r,dotted:!0}),!0}readNoteBody(){let e=[];for(;++this.cursor.index<this.cursor.lines.length&&this.cursor.lines[this.cursor.index].text!==`end note`;)e.push(this.cursor.lines[this.cursor.index].text);return e.join(`
21
+ `)}readTransition(e,t){let n=e.match(yp);if(!n)return!1;let r=this.endpoint(n[1],!1),i=this.endpoint(n[2],!0);return this.edges.push({from:r,to:i,label:n[3]?W(n[3]):void 0,line:t.line}),!0}readDescription(e){let t=e.match(bp);return t&&this.node(t[1]).descs.push(W(t[2])),!!t}readClick(e,t){return xp.test(e)?(this.ctx.warnOnce(`click`,t.line,`click handlers are skipped`),!0):!1}readBareName(e){return Sp.test(e)?(this.node(e),!0):!1}attachCompositeEdges(){for(let e of this.edges){let t=this.boxes.get(e.from),n=this.boxes.get(e.to);(t||n)&&this.ctx.warnOnce(`composite`,e.line??1,`edges to a composite state attach to its start or end inside`),t&&(e.from=t.end??kp(t)??e.from),n&&(e.to=n.start??Op(n)??e.to)}}write(){let e=[];this.writeBox(this.root,0,e),this.edges.length&&e.push(``);for(let t of this.edges)e.push(Dp(t));let t=[this.title?`title: ${this.title}`:``,`direction: ${this.direction}`].filter(Boolean),n=[...this.pseudoClassDefs(),...this.classDefs];return[...t,...n.length?[``,...n]:[],``,...e]}writeBox(e,t,n){let r=` `.repeat(t);for(let i of e.items)typeof i==`string`?n.push(r+Ep(this.nodes.get(i))):(n.push(`${r}group ${i.id} ${pc(i.label)} {`),this.writeBox(i,t+1,n),n.push(`${r}}`))}pseudoClassDefs(){let e=new Set([...this.nodes.values()].map(e=>e.kind)),t=this.direction===`right`||this.direction===`left`,n=[];return e.has(`start`)&&n.push(`.state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]`),e.has(`end`)&&n.push(`.state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]`),e.has(`fork`)&&n.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${t?8:70}, height: ${t?70:8}]`),e.has(`choice`)&&n.push(`.state-choice [shape: diamond, width: 28, height: 28]`),n}},Tp=(e,t)=>new wp(e,t).convert();function Ep(e){let t=[e.id],n=e.label??e.id;(n!==e.id||e.kind===`note`)&&t.push(pc(n));let r=dp[e.kind];r&&t.push(`.${r}`);for(let n of e.classes)t.push(`.${n}`);let i=[];return e.kind===`note`&&i.push(`shape: note`),e.descs.length&&i.push(`sub: ${pc(e.descs.join(` / `))}`),e.style&&i.push(e.style),i.length&&t.push(`[${i.join(`, `)}]`),t.join(` `)}function Dp(e){let t=e.dotted?`..`:`->`;return`${e.from} ${t} ${e.to}${e.label?`: `+Nc(e.label):``}`}function Op(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??Op(t);if(e)return e}}function kp(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??kp(n);if(r)return r}}var Ap=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*(?:;.*)?$/i;function jp(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}var Mp=/%%.*$/,Np=/^\s*title\s*:\s*(.+)$/;function Pp(e){return e.replace(Mp,``)}function Fp(e){let t;for(let n=0;n<jp(e);n++){let r=e[n].match(Np);r&&(t=hc(r[1]))}return t}function Ip(e,t){let n=[];for(let r=t;r<e.length;r++){let t=Pp(e[r]).replace(/\s+$/,``),i=t.trim();if(!i)continue;let a=t.match(/^\s*/)[0];n.push({text:i,line:r+1,indent:a.replace(/\t/g,` `).length})}return n}var Lp=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],Rp=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,zp=/^[\w-]+/,Bp=`:::`,Vp=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,Hp=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/,Up=class{pos=0;nodes=[];edges=[];text;toId;warn;constructor(e,t,n){this.text=e,this.toId=t,this.warn=n}read(){let e=this.readNodeGroup();if(!e)return this.warn(`could not read "${this.text}"`),null;let t=e;for(;!this.atEnd();){let e=this.readLink();if(!e){this.warn(`could not read "${this.text.slice(this.pos)}"`);break}let n=this.readNodeGroup();if(!n){this.warn(`link without a target in "${this.text}"`);break}this.addEdges(t,n,e),t=n}return{nodes:this.nodes,edges:this.edges}}atEnd(){return this.skipSpace(),this.pos>=this.text.length}skipSpace(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}rest(){return this.text.slice(this.pos)}readNodeGroup(){let e=[];for(;;){let t=this.readNode();if(!t)return e.length?e:null;if(e.push(t),this.skipSpace(),this.text[this.pos]!==`&`)return e;this.pos++}}readNode(){this.skipSpace();let e=this.rest().match(Rp);if(!e)return null;this.pos+=e[0].length;let t={id:this.toId(e[0]),classes:[]};return this.readShape(t),this.readClasses(t),this.nodes.push(t),t}readShape(e){for(let[t,n,r]of Lp){if(!this.text.startsWith(t,this.pos))continue;let i=this.pos+t.length,a=Jp(this.text,i,n);if(!(a<0)){e.label=hc(this.text.slice(i,a)),e.shape=r||void 0,this.pos=a+n.length;return}}}readClasses(e){for(;this.text.startsWith(Bp,this.pos);){let t=this.text.slice(this.pos+3).match(zp);if(!t)return;e.classes.push(t[0]),this.pos+=3+t[0].length}}readLink(){let e=this.rest(),t=e.match(Vp);if(t&&/[->=]/.test(t[4])){this.pos+=t[0].length;let[,e,n,r,i,a]=t;return{start:e,body:n,end:i.endsWith(`>`)?`>`:a,label:hc(r)}}let n=e.match(Hp);if(!n)return null;this.pos+=n[0].length;let[,r,i,a,o]=n;return{start:r,body:i,end:a,label:o===void 0?void 0:hc(o)}}addEdges(e,t,n){let{arrow:r,props:i}=Gp(n);for(let a of e)for(let e of t)this.edges.push({from:a.id,to:e.id,arrow:r,label:n.label||void 0,props:i})}},Wp={o:`dot`,x:`bar`};function Gp({start:e,body:t,end:n}){let r=t.startsWith(`=`),i=t.includes(`.`),a=e&&n?`<->`:n?r?`=>`:i?`..>`:`->`:`--`,o=[];return(a===`<->`||a===`--`)&&Kp(o,r,i),qp(o,e,n),e&&!n&&o.push(`tail: arrow`),{arrow:a,props:o}}function Kp(e,t,n){t&&e.push(`width: 3`),n&&e.push(`style: dotted`)}function qp(e,t,n){n&&n in Wp&&e.push(`head: ${Wp[n]}`),t&&t in Wp&&e.push(`tail: ${Wp[t]}`)}function Jp(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}function Yp(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}var Xp=/^subgraph\s+(.*)$/,Zp=/^([\w-]+)\s*\[(.*)\]$/,Qp=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,$p=/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/,em=/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u;function tm(e){let t=e.split(`
22
+ `),n=new nm(Fp(t));for(let e=jp(t);e<t.length;e++)for(let r of Yp(Pp(t[e])))n.statement(r.trim(),e+1);return n.finish(t.length)}var nm=class{warnings=[];settings=[];classDefs=[];body=[];ids=new Map;declared=new Set;groupIds=new Set;depth=0;openEdges=new Map;line=0;constructor(e){e!==void 0&&this.settings.push(`title: ${e}`)}statement(e,t){e&&(this.line=t,this.header(e)||this.title(e)||this.direction(e)||this.subgraph(e)||this.end(e)||this.classDef(e)||this.classAssign(e)||this.style(e)||this.unsupported(e)||this.nodesAndEdges(e))}finish(e){for(;this.depth>0;)this.closeGroup(),this.warnings.push({line:e,message:`subgraph is missing "end"`});for(let e of this.groupIds)this.declared.has(e)&&this.warnings.push({line:1,message:`"${e}" is both a node and a subgraph; edges to subgraphs are not supported`});let t=[...this.settings,...this.classDefs.length?[``,...this.classDefs]:[]],n=this.body.map(e=>typeof e==`string`?e:im(e));return{source:[...t,...t.length?[``]:[],...n].join(`
23
23
  `)+`
24
- `,warnings:this.warnings}}header(e){let t=e.match(Dp);return t?(t[2]&&this.settings.push(`direction: ${Cc[t[2].toUpperCase()]}`),!0):!1}title(e){let t=yc(e);return t===void 0||this.depth>0?!1:(this.settings.push(`title: ${t}`),!0)}direction(e){let t=e.match(wc);return t?(this.depth>0?this.warn(`subgraph direction is not supported; the whole diagram uses one direction`):this.settings.push(`direction: ${Cc[t[1].toUpperCase()]}`),!0):!1}subgraph(e){let t=e.match(qp);if(!t)return!1;let{id:n,title:r}=this.subgraphIdAndTitle(t[1].trim());return this.groupIds.add(n),this.write(`group ${n} ${uc(r)} {`),this.depth++,this.openEdges=new Map,!0}subgraphIdAndTitle(e){let t=e.match(Jp);if(t)return{id:this.toId(t[1]),title:fc(t[2])};if(/^".*"$/.test(e)){let t=fc(e);return{id:this.toId(t.toLowerCase()),title:t}}return/^[\w-]+$/.test(e)?{id:this.toId(e),title:e}:{id:this.toId(e.toLowerCase()),title:e}}end(e){return e===`end`&&(this.depth>0?this.closeGroup():this.warn(`"end" without subgraph`),!0)}closeGroup(){this.depth--,this.openEdges=new Map,this.write(`}`)}classDef(e){let t=Oc(e,e=>this.warn(e));return this.classDefs.push(...t??[]),!!t}classAssign(e){let t=e.match(Yp);if(!t)return!1;for(let e of t[1].split(`,`))this.write(`${this.toId(e.trim())} .${t[2]}`);return!0}style(e){let t=Ec(e,e=>this.warn(e));return t?.props&&this.write(`${this.toId(t.target)} [${t.props}]`),!!t}unsupported(e){return Xp.test(e)?(this.warn(`"${e.split(/\s+/)[0]}" is not supported and was skipped`),!0):!1}nodesAndEdges(e){let t=new Bp(e,e=>this.toId(e),e=>this.warn(e)).read();if(!t)return;let n=new Set(t.edges.flatMap(e=>[e.from,e.to]));for(let e of t.nodes)this.writeNode(e,n.has(e.id));for(let e of t.edges)this.writeEdge(e)}writeNode(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(uc(e.label));for(let t of e.classes)n.push(`.${t}`);e.shape&&n.push(`[shape: ${e.shape}]`);let r=n.length===1,i=this.depth>0;this.declared.has(e.id)&&r&&!i||(this.declared.add(e.id),r&&!i&&t||this.write(n.join(` `)))}writeEdge(e){let t=em(e),n=`${this.indent()}${e.from} ${e.arrow} `,r=`${n}\0${t}`,i=this.openEdges.get(r);if(i){i.targets.push(e.to);return}let a={head:n,targets:[e.to],tail:t};this.openEdges.set(r,a),this.body.push(a)}warn(e){this.warnings.push({line:this.line,message:e})}write(e){this.body.push(this.indent()+e)}indent(){return` `.repeat(this.depth)}toId(e){let t=this.ids.get(e);return t===void 0&&(t=pc(e),this.ids.set(e,t)),t}};function em(e){return[e.label?Zp.test(e.label)?e.label:uc(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `)}function tm({head:e,targets:t,tail:n}){return`${e}${t.join(`, `)}${n?`: `+n:``}`}var nm=l({sequenceDiagram:vf,timeline:Yf,gitGraph:Df,pie:kf,"xychart-beta":Nf,xychart:Nf,journey:Qf,mindmap:tp,gantt:Jf,quadrantChart:zf,kanban:sp,stateDiagram:Sp,"stateDiagram-v2":Sp,classDiagram:Ud,"classDiagram-v2":Ud,erDiagram:tf}),rm=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function im(e){for(let t=Op(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function am(e){let t=e.split(`
25
- `),n=im(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 nm||rm.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 om(e){let t=e.split(`
26
- `),n=im(t);if(n>=0&&Dp.test(t[n]))return!0;let r=am(e);return!!r&&r.type in nm}function sm(e){let t=am(e);return t&&!(t.type in nm)?t.type:void 0}function cm(e){let t=am(e),n=t&&nm[t.type];if(!t||!n)return Qp(e);let r=e.split(`
27
- `),i=[],a=new Set;return{source:n(Np(r,t.index+1),{header:jp(t.rest).trim(),title:Mp(r),warn:(e,t)=>i.push({line:e,message:t}),warnOnce(e,t,n){a.has(e)||(a.add(e),i.push({line:t,message:n}))}}).join(`
24
+ `,warnings:this.warnings}}header(e){let t=e.match(Ap);return t?(t[2]&&this.settings.push(`direction: ${Ec[t[2].toUpperCase()]}`),!0):!1}title(e){let t=Sc(e);return t===void 0||this.depth>0?!1:(this.settings.push(`title: ${t}`),!0)}direction(e){let t=e.match(Dc);return t?(this.depth>0?this.warn(`subgraph direction is not supported; the whole diagram uses one direction`):this.settings.push(`direction: ${Ec[t[1].toUpperCase()]}`),!0):!1}subgraph(e){let t=e.match(Xp);if(!t)return!1;let{id:n,title:r}=this.subgraphIdAndTitle(t[1].trim());return this.groupIds.add(n),this.write(`group ${n} ${pc(r)} {`),this.depth++,this.openEdges=new Map,!0}subgraphIdAndTitle(e){let t=e.match(Zp);if(t)return{id:this.toId(t[1]),title:hc(t[2])};if(/^".*"$/.test(e)){let t=hc(e);return{id:this.toId(t.toLowerCase()),title:t}}return/^[\w-]+$/.test(e)?{id:this.toId(e),title:e}:{id:this.toId(e.toLowerCase()),title:e}}end(e){return e===`end`&&(this.depth>0?this.closeGroup():this.warn(`"end" without subgraph`),!0)}closeGroup(){this.depth--,this.openEdges=new Map,this.write(`}`)}classDef(e){let t=jc(e,e=>this.warn(e));return this.classDefs.push(...t??[]),!!t}classAssign(e){let t=e.match(Qp);if(!t)return!1;for(let e of t[1].split(`,`))this.write(`${this.toId(e.trim())} .${t[2]}`);return!0}style(e){let t=kc(e,e=>this.warn(e));return t?.props&&this.write(`${this.toId(t.target)} [${t.props}]`),!!t}unsupported(e){return $p.test(e)?(this.warn(`"${e.split(/\s+/)[0]}" is not supported and was skipped`),!0):!1}nodesAndEdges(e){let t=new Up(e,e=>this.toId(e),e=>this.warn(e)).read();if(!t)return;let n=new Set(t.edges.flatMap(e=>[e.from,e.to]));for(let e of t.nodes)this.writeNode(e,n.has(e.id));for(let e of t.edges)this.writeEdge(e)}writeNode(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(pc(e.label));for(let t of e.classes)n.push(`.${t}`);e.shape&&n.push(`[shape: ${e.shape}]`);let r=n.length===1,i=this.depth>0;this.declared.has(e.id)&&r&&!i||(this.declared.add(e.id),r&&!i&&t||this.write(n.join(` `)))}writeEdge(e){let t=rm(e),n=`${this.indent()}${e.from} ${e.arrow} `,r=`${n}\0${t}`,i=this.openEdges.get(r);if(i){i.targets.push(e.to);return}let a={head:n,targets:[e.to],tail:t};this.openEdges.set(r,a),this.body.push(a)}warn(e){this.warnings.push({line:this.line,message:e})}write(e){this.body.push(this.indent()+e)}indent(){return` `.repeat(this.depth)}toId(e){let t=this.ids.get(e);return t===void 0&&(t=gc(e),this.ids.set(e,t)),t}};function rm(e){return[e.label?em.test(e.label)?e.label:pc(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `)}function im({head:e,targets:t,tail:n}){return`${e}${t.join(`, `)}${n?`: `+n:``}`}var am=l({sequenceDiagram:xf,timeline:Qf,gitGraph:Af,pie:Mf,"xychart-beta":If,xychart:If,journey:tp,mindmap:ip,gantt:Zf,quadrantChart:Hf,kanban:up,stateDiagram:Tp,"stateDiagram-v2":Tp,classDiagram:Kd,"classDiagram-v2":Kd,erDiagram:af}),om=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function sm(e){for(let t=jp(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function cm(e){let t=e.split(`
25
+ `),n=sm(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 am||om.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 lm(e){let t=e.split(`
26
+ `),n=sm(t);if(n>=0&&Ap.test(t[n]))return!0;let r=cm(e);return!!r&&r.type in am}function um(e){let t=cm(e);return t&&!(t.type in am)?t.type:void 0}function dm(e){let t=cm(e),n=t&&am[t.type];if(!t||!n)return tm(e);let r=e.split(`
27
+ `),i=[],a=new Set;return{source:n(Ip(r,t.index+1),{header:Pp(t.rest).trim(),title:Fp(r),warn:(e,t)=>i.push({line:e,message:t}),warnOnce(e,t,n){a.has(e)||(a.add(e),i.push({line:t,message:n}))}}).join(`
28
28
  `).replace(/^\n+/,``)+`
29
- `,warnings:i}}var lm=e=>Math.round(e),um=e=>e.split(/\r?\n/),dm=e=>e.includes(`\r
29
+ `,warnings:i}}var fm=e=>Math.round(e),pm=e=>e.split(/\r?\n/),mm=e=>e.includes(`\r
30
30
  `)?`\r
31
31
  `:`
32
- `,fm=(e,t)=>e.join(dm(t));function pm(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 ${lm(r.x)} ${lm(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${lm(r.w)} ${lm(r.h)}`),e.length>1&&t.push(` `+e.join(` `))}for(let n of e.ranks??[])t.push(` rank ${n.join(` `)}`);for(let n of e.aligns??[])t.push(` align ${n.side===`center`?``:n.side+` `}${n.ids.join(` `)}`);for(let[n,r]of Object.entries(e.edges)){let e=[n];r.via?.length&&e.push(`via `+r.via.map(e=>`${lm(e.x)} ${lm(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(lm(r.label.x)||lm(r.label.y))&&e.push(`label ${lm(r.label.x)} ${lm(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 ${lm(r.at.x)} ${lm(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(lm(i.x)||lm(i.y))&&t.push(` ${n}:${e} ${lm(i.x)}${lm(i.y)?` ${lm(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
33
- `)}\n}`:``}function mm(e,t,n=Kl(e)){let r=pm(t),i=um(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
- `):[]),fm(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=dm(e);return a+o+o+r.split(`
35
- `).join(o)+o}function hm(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=H(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=ii(o),u=l?`[${l}]`:``,d=a.slice(0,s),f=a.slice(c);if(e[t.line]=t.props?d+u+f:d+(u?(t.prefix??``)+` `+u:``)+f,!l&&t.props){let r=d.replace(/\s+$/,``);n===`edge`&&r.endsWith(`:`)&&!f.trim()&&(r=r.slice(0,-1).replace(/\s+$/,``)),e[t.line]=(r+f).replace(/\s+$/,``)}}var gm=(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 _m(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length;n.layoutBlock&&i>1&&!t[i-1].trim()&&t[i-2].trim()&&i--;let a=n.layoutBlock&&i>0&&t[i-1].trim()&&t[i].trim()?[...r,``]:r;return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),fm(t,e)}var vm=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,ym=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e);function bm(e,t,n,r=Kl(e)){let i=gm(r,t);if(!i)return e;let a=um(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?_m(e,a,r,[`${t.id} ${vm(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+$/,``),fm(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&ym(n)?n:vm(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),fm(a,e)}var xm={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function Sm(e,t,n,r,i=Kl(e)){n=Zr(n);let a=gm(i,t);if(!a)return e;let o=Cm(e,t,n,r,i,a);for(let e of(xm[n]??[]).filter(e=>e in a.props))o=Sm(o,t,e,null);return o}function Cm(e,t,n,r,i,a){let o=um(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:_m(e,o,i,[`${t.id} [${ii({[n]:r})}]`]);let c=s.propLines;if(c){let i=s.props?H(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]]=`${Om(o[c[n]])}${n}: ${ai(r)}`,n in i&&hm(o,s,t.kind,n,null),fm(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${Om(o[t])}${n}: ${ai(r)}`),fm(o,e)}}return hm(o,s,t.kind,n,r),fm(o,e)}function wm(e,t,n){let r=um(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 Jr(qr(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}`,fm(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}`),fm(r,e)}function Tm(e,t,n,r=Kl(e)){let i,a=Dm(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 Em(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 mm(e,t.layout,t);let[o,s]=i.lines,c=um(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,qr(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return mm(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 mm(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 fm(c,e)}function Dm(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&gr.get(i.kind);if(!i?.lines||!a||i.failed||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=um(e),u=km(l,o,s);return l.splice(o+1,s-o-1,...c.map(e=>e.trim()?u+e:``)),fm(l,e)}var Om=e=>e.match(/^\s*/)[0];function km(e,t,n){let r=e.slice(t+1,n).filter(e=>e.trim());return r.length?r.map(Om).reduce((e,t)=>t.length<e.length?t:e):Om(e[t])+` `}function Am(e,t,n=Kl(e)){let{from:r,to:i}=t;return n.edges.some(e=>e.from===r&&e.to===i)?e:_m(e,um(e),n,[`${r} -> ${i}`])}function jm(e,t,n=Kl(e)){let{id:r,label:i,from:a,group:o}=t,s=r+(i?` `+vm(i):``),c=a?`${a} -> ${r}`:null,l=um(e),u=o?n.groups.get(o)?.ref:void 0;if(u&&!u.generated&&u.end!==void 0&&u.end>u.line){let t=km(l,u.line,u.end),i=c&&n.nodes.get(a)?.group===o;l.splice(u.end,0,t+s,...i?[t+c]:[]);let d=fm(l,e);return a&&!i?Am(d,{from:a,to:r}):d}return _m(e,l,n,c?[s,c]:[s])}function Mm(e,t,n=new Map){let r=new Set;for(let[e,n]of t)for(let t=e;t<=n;t++)r.add(t);let i=[];return e.forEach((e,t)=>{let a=n.get(t);a?i.push(...a):r.has(t)||(e.trim()||!r.has(t-1)||i.length&&i[i.length-1].trim())&&i.push(e)}),i}function Nm(e,t){return e.aligns?.some(e=>e.ids.includes(t))?(e.aligns=e.aligns.map(e=>({...e,ids:e.ids.filter(e=>e!==t)})).filter(e=>e.ids.length>1),!0):!1}function Pm(e,t,n=Kl(e)){let r=um(e),i=[],a=new Map,o=e=>{for(let t of Object.values(e.propLines??{}))i.push([t,t])},s=(e,t)=>n.edges.some(n=>n.ref?.line===e&&!t(n)),c=(e,t)=>[...n.nodes.values(),...n.groups.values(),...n.edges].some(n=>n!==t&&n.ref?.line===e),l=t=>{let n=fm(Mm(r,i,a),e),o=Kl(n),s=structuredClone(o.layout);return t(s)&&(n=mm(n,s,o)),n};switch(t.kind){case`edge`:{let r=n.edges.find(e=>e.key===t.id);return!r?.ref||r.ref.generated||c(r.ref.line,r)?e:(i.push([r.ref.line,r.ref.line]),o(r.ref),l(e=>!!e.edges[r.key]&&delete e.edges[r.key]))}case`node`:{let u=n.nodes.get(t.id);if(!u)return e;let d=e=>e.from===u.id||e.to===u.id,f=new Set;for(let t of n.edges.filter(d)){if(!t.ref||t.ref.generated)return e;f.add(t.ref.line),o(t.ref)}for(let t of f){if(s(t,d))return e;i.push([t,t])}if(u.ref&&!f.has(u.ref.line)){let t=u.ref.line;if(u.ref.generated||c(t,u))return e;i.push(u.bodyLines?[t,Math.max(t,u.bodyLines[1])]:[t,t]),o(u.ref)}let p=Kl(fm(Mm(r,i),e));if(p.nodes.has(u.id))return e;for(let e of f){let t=n.edges.filter(t=>t.ref?.line===e).flatMap(e=>[e.from,e.to]).filter((e,t,n)=>e!==u.id&&!p.nodes.has(e)&&n.indexOf(e)===t);t.length&&a.set(e,t.map(t=>Om(r[e])+t))}return l(e=>{let t=u.id in e.nodes;delete e.nodes[u.id];for(let r of n.edges)d(r)&&e.edges[r.key]&&(t=delete e.edges[r.key]);return e.ranks?.some(e=>e.includes(u.id))&&(e.ranks=e.ranks.map(e=>e.filter(e=>e!==u.id)).filter(e=>e.length>1),t=!0),Nm(e,u.id)||t})}case`group`:{let s=n.groups.get(t.id),u=s?.ref;if(!u||u.generated||u.end===void 0||u.end<=u.line||c(u.line,s))return e;let d=r.slice(u.line+1,u.end),f=Math.max(0,km(r,u.line,u.end).length-Om(r[u.line]).length);return d.forEach((e,t)=>{let n=Math.min(f,Om(e).length);n&&a.set(u.line+1+t,[e.slice(n)])}),i.push([u.line,u.line],[u.end,u.end]),o(u),l(e=>Nm(e,s.id))}case`panel`:{let r=n.panels.find(e=>e.id===t.id);return!r?.lines||r.ref?.generated?e:(i.push(r.lines),l(e=>!!e.panels?.[r.id]&&delete e.panels[r.id]))}}}function Fm(e){let t=e.match(/<svg\b[^>]*>/)?.[0]??``,n=e=>Number(t.match(RegExp(`\\s${e}="([\\d.]+)"`))?.[1]),r=t.match(/\sviewBox="([^"]+)"/)?.[1].trim().split(/[\s,]+/).map(Number)??[],i=n(`width`)||r[2]||300;return{width:i,height:n(`height`)||(r[2]&&r[3]?i*r[3]/r[2]:150)}}var Im=e=>e.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t))).replace(/&#x([\da-f]+);/gi,(e,t)=>String.fromCodePoint(parseInt(t,16))).replace(/&amp;/g,`&`);function Lm(e,t){return[...e.matchAll(RegExp(`${t}(?:="([^"]*)"|\\s*:\\s*([^;"}]+))`,`g`))].map(e=>Im(e[1]??e[2]).trim())}function Rm(e){let t=new Set;for(let n of Lm(e,`font-family`))for(let e of n.split(`,`))t.add(ci(e).toLowerCase());return t}var zm={normal:400,bold:700};function Bm(e){let t=new Set,n=e.replace(/<style\b[^>]*>[\s\S]*?<\/style>/g,``).match(/>[^<]+</g)??[];for(let e of n)for(let n of Im(e.slice(1,-1)))t.add(n.codePointAt(0));let r=new Set([400]);for(let t of Lm(e,`font-weight`)){let e=zm[t]??Number(t);e>0&&r.add(e)}let i=Lm(e,`font-style`).some(e=>/^(?:italic|oblique)/.test(e));return{families:Rm(e),chars:t,weights:r,italic:i}}function Vm(e){let[t,n=t]=(e??`normal`).trim().split(/\s+/).map(e=>zm[e]??(Number(e)||400));return[t,n]}function Hm(e,[t,n]){if(e>=t&&e<=n)return 0;let r=e<t?t:n,i=Math.abs(r-e);return e>=400&&e<=500?(r>e&&r<=500?1e3:r<e?2e3:3e3)+i:((e<400?r<e:r>e)?1e3:2e3)+i}function Um(e,{weights:t,italic:n}){let r=new Map;for(let t of e){let e=`${t.family.toLowerCase()}|${t.unicodeRange??``}`;r.set(e,[...r.get(e)??[],t])}let i=new Set,a=e=>/italic|oblique/i.test(e.style??``);for(let e of r.values())for(let r of n?[!1,!0]:[!1]){let n=e.filter(e=>a(e)===r),o=n.length?n:e;for(let e of t){let t=o[0];for(let n of o)Hm(e,Vm(n.weight))<Hm(e,Vm(t.weight))&&(t=n);i.add(t)}}return e.filter(e=>i.has(e))}function Wm(e,t){if(!e?.trim())return!0;let n=e.split(`,`).map(e=>{let[t,n]=e.trim().replace(/^u\+/i,``).split(`-`);return n===void 0?[parseInt(t.replace(/\?/g,`0`),16),parseInt(t.replace(/\?/g,`f`),16)]:[parseInt(t,16),parseInt(n.replace(/^u\+/i,``),16)]});for(let e of t)if(n.some(([t,n])=>e>=t&&e<=n))return!0;return!1}function Gm(e,t){let n=e.match(/url\(\s*(['"]?)(.*?)\1\s*\)/);if(n)try{return new URL(n[2],t).href}catch{return}}function Km(e,t){let n=Gm(e(`src`),t),r=ci(e(`font-family`));if(n&&r)return{family:r,url:n,weight:e(`font-weight`).trim()||void 0,style:e(`font-style`).trim()||void 0,unicodeRange:e(`unicode-range`).trim()||void 0}}function qm(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*\{([^}]*)\}/g)){let e=r[1],i=Km(t=>e.match(RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`,`i`))?.[1]??``,t);i&&n.push(i)}return n}var Jm=32;function Ym(e,t,n){let r=e.get(t);return r||(e.set(t,r=n()),e.size>Jm&&e.delete(e.keys().next().value),r)}var Xm=new Map,Zm;function Qm(){return Zm??=$m().finally(()=>Zm=void 0)}async function $m(){if(typeof document>`u`)return[];let e=[],t=[],n=(t,i)=>{for(let a of Array.from(t))if(a instanceof CSSFontFaceRule){let t=Km(e=>a.style.getPropertyValue(e),i);t&&e.push(t)}else a instanceof CSSImportRule?a.styleSheet&&r(a.styleSheet):`cssRules`in a&&n(a.cssRules,i)},r=e=>{let r=e.href??location.href;try{n(e.cssRules,r)}catch{let n=e.href;if(!n)return;t.push(Ym(Xm,n,()=>fetch(n).then(e=>e.ok?e.text():``).then(e=>qm(e,n)).catch(()=>[])))}};for(let e of Array.from(document.styleSheets))r(e);for(let n of await Promise.all(t))e.push(...n);return e}function eh(e){let t=e.toBase64;if(t)return t.call(e);let n=``;for(let t=0;t<e.length;t+=32768)n+=String.fromCharCode(...e.subarray(t,t+32768));return btoa(n)}var th=new Map;function nh(e){return e.startsWith(`data:`)?Promise.resolve(e):Ym(th,e,()=>fetch(e).then(e=>e.ok?e.arrayBuffer():Promise.reject(Error(String(e.status)))).then(t=>`data:font/${e.match(/\.(woff2?|ttf|otf)(?:[?#]|$)/i)?.[1].toLowerCase()??`woff2`};base64,${eh(new Uint8Array(t))}`).catch(()=>void 0))}var rh=e=>`"${e.replace(/["\\<>]/g,``)}"`,ih=e=>e.replace(/[;{}<>"\\]/g,``);async function ah(e,t=`page`){let n=Bm(e),r=Um((t===`page`?await Qm():t).filter(e=>n.families.has(e.family.toLowerCase())&&Wm(e.unicodeRange,n.chars)),n),i=new Map;for(let e of r){let t=i.get(e.url);if(!t)i.set(e.url,e);else{let[n,r]=[Vm(t.weight),Vm(e.weight)];i.set(e.url,{...t,weight:`${Math.min(n[0],r[0])} ${Math.max(n[1],r[1])}`})}}let a=(await Promise.all([...i.values()].map(async e=>{let t=await nh(e.url);return t?`@font-face{font-family:${rh(e.family)};src:url(${t});`+(e.weight?`font-weight:${ih(e.weight)};`:``)+(e.style?`font-style:${ih(e.style)};`:``)+(e.unicodeRange?`unicode-range:${ih(e.unicodeRange)};`:``)+`}`:``}))).join(``);return a?e.replace(/<svg\b[^>]*>/,e=>`${e}<style>${a}</style>`):e}async function oh(e){let t=typeof document>`u`?void 0:document.fonts;if(!t)return!1;let{families:n,chars:r,weights:i,italic:a}=Bm(e),o=String.fromCodePoint(...r)||`a`,s=[];for(let e of n)for(let t of i)for(let n of a?[`normal`,`italic`]:[`normal`])s.push(`${n} ${t} 16px ${rh(e)}`);let c=s.filter(e=>{try{return!t.check(e,o)}catch{return!1}});return c.length?(await Promise.all(c.map(e=>t.load(e,o).catch(()=>[])))).some(e=>e.length>0):!1}async function sh(e,t={}){let{width:n,height:r}=Fm(e),i=t.scale??(typeof devicePixelRatio==`number`&&devicePixelRatio>0?devicePixelRatio:1),a=t.fonts??`page`,o=a===!1?e:await ah(e,a),s=URL.createObjectURL(new Blob([o],{type:`image/svg+xml`})),c=new Image;c.src=s;try{await c.decode()}finally{URL.revokeObjectURL(s)}let l=t.canvas??document.createElement(`canvas`);l.width=Math.max(1,Math.round(n*i)),l.height=Math.max(1,Math.round(r*i));let u=l.getContext(`2d`);if(!u)throw Error(`yuhwa: no 2d canvas context`);return t.background&&(u.fillStyle=t.background,u.fillRect(0,0,l.width,l.height)),u.drawImage(c,0,0,l.width,l.height),l}function ch(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=dd(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=sm(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(om(e)){let t=cm(e);return{source:t.source,format:`mermaid`,diagnostics:t.warnings.map(e=>({...e,message:`mermaid: ${e.message}`,severity:`warning`}))}}return{source:e,format:`yuhwa`,diagnostics:[]}}var lh=class{timer;apply;redraw;constructor(e,t){this.apply=e,this.redraw=t}input(e){this.apply(e,this.timer===void 0),this.end(),this.timer=setTimeout(()=>{this.timer=void 0,this.redraw()},150)}end(){clearTimeout(this.timer),this.timer=void 0}},uh=class{revision=0;acknowledged=0;active=!1;write;status;constructor(e,t){this.write=e,this.status=t}get dirty(){return this.revision!==this.acknowledged}changed(){this.revision++}async save(){if(!this.active&&this.dirty){this.active=!0;try{for(;this.dirty;){let e=this.revision,t=await this.write();this.acknowledged=e,this.dirty||this.status(t)}}catch{this.status(`save failed`)}finally{this.active=!1}}}},dh=[{name:`Everything (showcase)`,source:`title: **Shopfront** platform
32
+ `,hm=(e,t)=>e.join(mm(t));function gm(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 ${fm(r.x)} ${fm(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${fm(r.w)} ${fm(r.h)}`),e.length>1&&t.push(` `+e.join(` `))}for(let n of e.ranks??[])t.push(` rank ${n.join(` `)}`);for(let n of e.aligns??[])t.push(` align ${n.side===`center`?``:n.side+` `}${n.ids.join(` `)}`);for(let[n,r]of Object.entries(e.edges)){let e=[n];r.via?.length&&e.push(`via `+r.via.map(e=>`${fm(e.x)} ${fm(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(fm(r.label.x)||fm(r.label.y))&&e.push(`label ${fm(r.label.x)} ${fm(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 ${fm(r.at.x)} ${fm(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(fm(i.x)||fm(i.y))&&t.push(` ${n}:${e} ${fm(i.x)}${fm(i.y)?` ${fm(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
33
+ `)}\n}`:``}function _m(e,t,n=Yl(e)){let r=gm(t),i=pm(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
+ `):[]),hm(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=mm(e);return a+o+o+r.split(`
35
+ `).join(o)+o}function vm(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=H(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=si(o),u=l?`[${l}]`:``,d=a.slice(0,s),f=a.slice(c);if(e[t.line]=t.props?d+u+f:d+(u?(t.prefix??``)+` `+u:``)+f,!l&&t.props){let r=d.replace(/\s+$/,``);n===`edge`&&r.endsWith(`:`)&&!f.trim()&&(r=r.slice(0,-1).replace(/\s+$/,``)),e[t.line]=(r+f).replace(/\s+$/,``)}}var ym=(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 bm(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length;n.layoutBlock&&i>1&&!t[i-1].trim()&&t[i-2].trim()&&i--;let a=n.layoutBlock&&i>0&&t[i-1].trim()&&t[i].trim()?[...r,``]:r;return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),hm(t,e)}var xm=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Sm=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e);function Cm(e,t,n,r=Yl(e)){let i=ym(r,t);if(!i)return e;let a=pm(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?bm(e,a,r,[`${t.id} ${xm(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+$/,``),hm(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&Sm(n)?n:xm(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),hm(a,e)}var wm={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function Tm(e,t,n,r,i=Yl(e)){n=ei(n);let a=ym(i,t);if(!a)return e;let o=Em(e,t,n,r,i,a);for(let e of(wm[n]??[]).filter(e=>e in a.props))o=Tm(o,t,e,null);return o}function Em(e,t,n,r,i,a){let o=pm(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:bm(e,o,i,[`${t.id} [${si({[n]:r})}]`]);let c=s.propLines;if(c){let i=s.props?H(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]]=`${jm(o[c[n]])}${n}: ${ci(r)}`,n in i&&vm(o,s,t.kind,n,null),hm(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${jm(o[t])}${n}: ${ci(r)}`),hm(o,e)}}return vm(o,s,t.kind,n,r),hm(o,e)}function Dm(e,t,n){let r=pm(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 Zr(Xr(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}`,hm(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}`),hm(r,e)}function Om(e,t,n,r=Yl(e)){let i,a=Am(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 km(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 _m(e,t.layout,t);let[o,s]=i.lines,c=pm(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,Xr(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return _m(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 _m(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 hm(c,e)}function Am(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&yr.get(i.kind);if(!i?.lines||!a||i.failed||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=pm(e),u=Mm(l,o,s);return l.splice(o+1,s-o-1,...c.map(e=>e.trim()?u+e:``)),hm(l,e)}var jm=e=>e.match(/^\s*/)[0];function Mm(e,t,n){let r=e.slice(t+1,n).filter(e=>e.trim());return r.length?r.map(jm).reduce((e,t)=>t.length<e.length?t:e):jm(e[t])+` `}function Nm(e,t,n=Yl(e)){let{from:r,to:i}=t;return n.edges.some(e=>e.from===r&&e.to===i)?e:bm(e,pm(e),n,[`${r} -> ${i}`])}function Pm(e,t,n=Yl(e)){let{id:r,label:i,from:a,group:o}=t,s=r+(i?` `+xm(i):``),c=a?`${a} -> ${r}`:null,l=pm(e),u=o?n.groups.get(o)?.ref:void 0;if(u&&!u.generated&&u.end!==void 0&&u.end>u.line){let t=Mm(l,u.line,u.end),i=c&&n.nodes.get(a)?.group===o;l.splice(u.end,0,t+s,...i?[t+c]:[]);let d=hm(l,e);return a&&!i?Nm(d,{from:a,to:r}):d}return bm(e,l,n,c?[s,c]:[s])}function Fm(e,t,n=new Map){let r=new Set;for(let[e,n]of t)for(let t=e;t<=n;t++)r.add(t);let i=[];return e.forEach((e,t)=>{let a=n.get(t);a?i.push(...a):r.has(t)||(e.trim()||!r.has(t-1)||i.length&&i[i.length-1].trim())&&i.push(e)}),i}function Im(e,t){return e.aligns?.some(e=>e.ids.includes(t))?(e.aligns=e.aligns.map(e=>({...e,ids:e.ids.filter(e=>e!==t)})).filter(e=>e.ids.length>1),!0):!1}function Lm(e,t,n=Yl(e)){let r=pm(e),i=[],a=new Map,o=e=>{for(let t of Object.values(e.propLines??{}))i.push([t,t])},s=(e,t)=>n.edges.some(n=>n.ref?.line===e&&!t(n)),c=(e,t)=>[...n.nodes.values(),...n.groups.values(),...n.edges].some(n=>n!==t&&n.ref?.line===e),l=t=>{let n=hm(Fm(r,i,a),e),o=Yl(n),s=structuredClone(o.layout);return t(s)&&(n=_m(n,s,o)),n};switch(t.kind){case`edge`:{let r=n.edges.find(e=>e.key===t.id);return!r?.ref||r.ref.generated||c(r.ref.line,r)?e:(i.push([r.ref.line,r.ref.line]),o(r.ref),l(e=>!!e.edges[r.key]&&delete e.edges[r.key]))}case`node`:{let u=n.nodes.get(t.id);if(!u)return e;let d=e=>e.from===u.id||e.to===u.id,f=new Set;for(let t of n.edges.filter(d)){if(!t.ref||t.ref.generated)return e;f.add(t.ref.line),o(t.ref)}for(let t of f){if(s(t,d))return e;i.push([t,t])}if(u.ref&&!f.has(u.ref.line)){let t=u.ref.line;if(u.ref.generated||c(t,u))return e;i.push(u.bodyLines?[t,Math.max(t,u.bodyLines[1])]:[t,t]),o(u.ref)}let p=Yl(hm(Fm(r,i),e));if(p.nodes.has(u.id))return e;for(let e of f){let t=n.edges.filter(t=>t.ref?.line===e).flatMap(e=>[e.from,e.to]).filter((e,t,n)=>e!==u.id&&!p.nodes.has(e)&&n.indexOf(e)===t);t.length&&a.set(e,t.map(t=>jm(r[e])+t))}return l(e=>{let t=u.id in e.nodes;delete e.nodes[u.id];for(let r of n.edges)d(r)&&e.edges[r.key]&&(t=delete e.edges[r.key]);return e.ranks?.some(e=>e.includes(u.id))&&(e.ranks=e.ranks.map(e=>e.filter(e=>e!==u.id)).filter(e=>e.length>1),t=!0),Im(e,u.id)||t})}case`group`:{let s=n.groups.get(t.id),u=s?.ref;if(!u||u.generated||u.end===void 0||u.end<=u.line||c(u.line,s))return e;let d=r.slice(u.line+1,u.end),f=Math.max(0,Mm(r,u.line,u.end).length-jm(r[u.line]).length);return d.forEach((e,t)=>{let n=Math.min(f,jm(e).length);n&&a.set(u.line+1+t,[e.slice(n)])}),i.push([u.line,u.line],[u.end,u.end]),o(u),l(e=>Im(e,s.id))}case`panel`:{let r=n.panels.find(e=>e.id===t.id);return!r?.lines||r.ref?.generated?e:(i.push(r.lines),l(e=>!!e.panels?.[r.id]&&delete e.panels[r.id]))}}}function Rm(e){let t=e.match(/<svg\b[^>]*>/)?.[0]??``,n=e=>Number(t.match(RegExp(`\\s${e}="([\\d.]+)"`))?.[1]),r=t.match(/\sviewBox="([^"]+)"/)?.[1].trim().split(/[\s,]+/).map(Number)??[],i=n(`width`)||r[2]||300;return{width:i,height:n(`height`)||(r[2]&&r[3]?i*r[3]/r[2]:150)}}var zm=e=>e.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t))).replace(/&#x([\da-f]+);/gi,(e,t)=>String.fromCodePoint(parseInt(t,16))).replace(/&amp;/g,`&`);function Bm(e,t){return[...e.matchAll(RegExp(`${t}(?:="([^"]*)"|\\s*:\\s*([^;"}]+))`,`g`))].map(e=>zm(e[1]??e[2]).trim())}function Vm(e){let t=new Set;for(let n of Bm(e,`font-family`))for(let e of n.split(`,`))t.add(di(e).toLowerCase());return t}var Hm={normal:400,bold:700};function Um(e){let t=new Set,n=e.replace(/<style\b[^>]*>[\s\S]*?<\/style>/g,``).match(/>[^<]+</g)??[];for(let e of n)for(let n of zm(e.slice(1,-1)))t.add(n.codePointAt(0));let r=new Set([400]);for(let t of Bm(e,`font-weight`)){let e=Hm[t]??Number(t);e>0&&r.add(e)}let i=Bm(e,`font-style`).some(e=>/^(?:italic|oblique)/.test(e));return{families:Vm(e),chars:t,weights:r,italic:i}}function Wm(e){let[t,n=t]=(e??`normal`).trim().split(/\s+/).map(e=>Hm[e]??(Number(e)||400));return[t,n]}function Gm(e,[t,n]){if(e>=t&&e<=n)return 0;let r=e<t?t:n,i=Math.abs(r-e);return e>=400&&e<=500?(r>e&&r<=500?1e3:r<e?2e3:3e3)+i:((e<400?r<e:r>e)?1e3:2e3)+i}function Km(e,{weights:t,italic:n}){let r=new Map;for(let t of e){let e=`${t.family.toLowerCase()}|${t.unicodeRange??``}`;r.set(e,[...r.get(e)??[],t])}let i=new Set,a=e=>/italic|oblique/i.test(e.style??``);for(let e of r.values())for(let r of n?[!1,!0]:[!1]){let n=e.filter(e=>a(e)===r),o=n.length?n:e;for(let e of t){let t=o[0];for(let n of o)Gm(e,Wm(n.weight))<Gm(e,Wm(t.weight))&&(t=n);i.add(t)}}return e.filter(e=>i.has(e))}function qm(e,t){if(!e?.trim())return!0;let n=e.split(`,`).map(e=>{let[t,n]=e.trim().replace(/^u\+/i,``).split(`-`);return n===void 0?[parseInt(t.replace(/\?/g,`0`),16),parseInt(t.replace(/\?/g,`f`),16)]:[parseInt(t,16),parseInt(n.replace(/^u\+/i,``),16)]});for(let e of t)if(n.some(([t,n])=>e>=t&&e<=n))return!0;return!1}function Jm(e,t){let n=e.match(/url\(\s*(['"]?)(.*?)\1\s*\)/);if(n)try{return new URL(n[2],t).href}catch{return}}function Ym(e,t){let n=Jm(e(`src`),t),r=di(e(`font-family`));if(n&&r)return{family:r,url:n,weight:e(`font-weight`).trim()||void 0,style:e(`font-style`).trim()||void 0,unicodeRange:e(`unicode-range`).trim()||void 0}}function Xm(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*\{([^}]*)\}/g)){let e=r[1],i=Ym(t=>e.match(RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`,`i`))?.[1]??``,t);i&&n.push(i)}return n}var Zm=32;function Qm(e,t,n){let r=e.get(t);return r||(e.set(t,r=n()),e.size>Zm&&e.delete(e.keys().next().value),r)}var $m=new Map,eh;function th(){return eh??=nh().finally(()=>eh=void 0)}async function nh(){if(typeof document>`u`)return[];let e=[],t=[],n=(t,i)=>{for(let a of Array.from(t))if(a instanceof CSSFontFaceRule){let t=Ym(e=>a.style.getPropertyValue(e),i);t&&e.push(t)}else a instanceof CSSImportRule?a.styleSheet&&r(a.styleSheet):`cssRules`in a&&n(a.cssRules,i)},r=e=>{let r=e.href??location.href;try{n(e.cssRules,r)}catch{let n=e.href;if(!n)return;t.push(Qm($m,n,()=>fetch(n).then(e=>e.ok?e.text():``).then(e=>Xm(e,n)).catch(()=>[])))}};for(let e of Array.from(document.styleSheets))r(e);for(let n of await Promise.all(t))e.push(...n);return e}function rh(e){let t=e.toBase64;if(t)return t.call(e);let n=``;for(let t=0;t<e.length;t+=32768)n+=String.fromCharCode(...e.subarray(t,t+32768));return btoa(n)}var ih=new Map;function ah(e){return e.startsWith(`data:`)?Promise.resolve(e):Qm(ih,e,()=>fetch(e).then(e=>e.ok?e.arrayBuffer():Promise.reject(Error(String(e.status)))).then(t=>`data:font/${e.match(/\.(woff2?|ttf|otf)(?:[?#]|$)/i)?.[1].toLowerCase()??`woff2`};base64,${rh(new Uint8Array(t))}`).catch(()=>void 0))}var oh=e=>`"${e.replace(/["\\<>]/g,``)}"`,sh=e=>e.replace(/[;{}<>"\\]/g,``);async function ch(e,t=`page`){let n=Um(e),r=Km((t===`page`?await th():t).filter(e=>n.families.has(e.family.toLowerCase())&&qm(e.unicodeRange,n.chars)),n),i=new Map;for(let e of r){let t=i.get(e.url);if(!t)i.set(e.url,e);else{let[n,r]=[Wm(t.weight),Wm(e.weight)];i.set(e.url,{...t,weight:`${Math.min(n[0],r[0])} ${Math.max(n[1],r[1])}`})}}let a=(await Promise.all([...i.values()].map(async e=>{let t=await ah(e.url);return t?`@font-face{font-family:${oh(e.family)};src:url(${t});`+(e.weight?`font-weight:${sh(e.weight)};`:``)+(e.style?`font-style:${sh(e.style)};`:``)+(e.unicodeRange?`unicode-range:${sh(e.unicodeRange)};`:``)+`}`:``}))).join(``);return a?e.replace(/<svg\b[^>]*>/,e=>`${e}<style>${a}</style>`):e}async function lh(e){let t=typeof document>`u`?void 0:document.fonts;if(!t)return!1;let{families:n,chars:r,weights:i,italic:a}=Um(e),o=String.fromCodePoint(...r)||`a`,s=[];for(let e of n)for(let t of i)for(let n of a?[`normal`,`italic`]:[`normal`])s.push(`${n} ${t} 16px ${oh(e)}`);let c=s.filter(e=>{try{return!t.check(e,o)}catch{return!1}});return c.length?(await Promise.all(c.map(e=>t.load(e,o).catch(()=>[])))).some(e=>e.length>0):!1}async function uh(e,t={}){let{width:n,height:r}=Rm(e),i=t.scale??(typeof devicePixelRatio==`number`&&devicePixelRatio>0?devicePixelRatio:1),a=t.fonts??`page`,o=a===!1?e:await ch(e,a),s=URL.createObjectURL(new Blob([o],{type:`image/svg+xml`})),c=new Image;c.src=s;try{await c.decode()}finally{URL.revokeObjectURL(s)}let l=t.canvas??document.createElement(`canvas`);l.width=Math.max(1,Math.round(n*i)),l.height=Math.max(1,Math.round(r*i));let u=l.getContext(`2d`);if(!u)throw Error(`yuhwa: no 2d canvas context`);return t.background&&(u.fillStyle=t.background,u.fillRect(0,0,l.width,l.height)),u.drawImage(c,0,0,l.width,l.height),l}function dh(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=md(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=um(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(lm(e)){let t=dm(e);return{source:t.source,format:`mermaid`,diagnostics:t.warnings.map(e=>({...e,message:`mermaid: ${e.message}`,severity:`warning`}))}}return{source:e,format:`yuhwa`,diagnostics:[]}}var fh=class{timer;apply;redraw;constructor(e,t){this.apply=e,this.redraw=t}input(e){this.apply(e,this.timer===void 0),this.end(),this.timer=setTimeout(()=>{this.timer=void 0,this.redraw()},150)}end(){clearTimeout(this.timer),this.timer=void 0}},ph=class{revision=0;acknowledged=0;active=!1;write;status;constructor(e,t){this.write=e,this.status=t}get dirty(){return this.revision!==this.acknowledged}changed(){this.revision++}async save(){if(!this.active&&this.dirty){this.active=!0;try{for(;this.dirty;){let e=this.revision,t=await this.write();this.acknowledged=e,this.dirty||this.status(t)}}catch{this.status(`save failed`)}finally{this.active=!1}}}},mh=[{name:`Everything (showcase)`,source:`title: **Shopfront** platform
36
36
  subtitle: everything yuhwa can draw, in one file
37
37
  direction: right
38
38
  theme: paper
@@ -539,7 +539,7 @@ chart conv "Conversion" [type: line, unit: %] {
539
539
  Feb: 2.4
540
540
  Mar: 3.2
541
541
  }
542
- `}],fh=[{label:`Sequence diagram`,group:`Panels`,id:`seq`,text:`sequence {id} "Checkout" [numbered] {
542
+ `}],hh=[{label:`Sequence diagram`,group:`Panels`,id:`seq`,text:`sequence {id} "Checkout" [numbered] {
543
543
  actor user "Customer" [purple]
544
544
  participant web, api, db
545
545
  user -> web: add to cart
@@ -637,26 +637,26 @@ chart conv "Conversion" [type: line, unit: %] {
637
637
  | total | money |
638
638
  ---
639
639
  spark: 3 5 4 8 7 9
640
- }`}],ph=class{worker;id=0;pending=new Map;handlers=new Map;versions=new Map;constructor(e){this.worker=e,e.addEventListener(`message`,e=>this.receive(e.data))}receive(e){if(e&&typeof e==`object`){if(`id`in e&&!(`method`in e)){let t=this.pending.get(e.id);if(!t)return;this.pending.delete(e.id),e.error?t.reject(Error(e.error.message)):t.resolve(e.result)}else if(`method`in e){`id`in e&&this.worker.postMessage({jsonrpc:`2.0`,id:e.id,result:null});for(let t of this.handlers.get(e.method)??[])t(e.params)}}}request(e,t){let n=++this.id;return new Promise((r,i)=>{this.pending.set(n,{resolve:r,reject:i}),this.worker.postMessage({jsonrpc:`2.0`,id:n,method:e,params:t})})}notify(e,t){this.worker.postMessage({jsonrpc:`2.0`,method:e,params:t})}on(e,t){let n=this.handlers.get(e);return n||this.handlers.set(e,n=new Set),n.add(t),()=>n.delete(t)}async initialize(){let e=await this.request(`initialize`,{processId:null,rootUri:null,capabilities:{}});return this.notify(`initialized`,{}),e}open(e,t){this.versions.set(e,1),this.notify(`textDocument/didOpen`,{textDocument:{uri:e,languageId:`yuhwa`,version:1,text:t}})}change(e,t){if(!this.versions.has(e))return this.open(e,t);let n=this.versions.get(e)+1;this.versions.set(e,n),this.notify(`textDocument/didChange`,{textDocument:{uri:e,version:n},contentChanges:[{text:t}]})}close(e){this.versions.delete(e)&&this.notify(`textDocument/didClose`,{textDocument:{uri:e}})}dispose(){this.worker.terminate();for(let e of this.pending.values())e.reject(Error(`client disposed`));this.pending.clear()}},mh=e=>`file:///`+e.split(`/`).map(encodeURIComponent).join(`/`),hh=e=>decodeURIComponent(new URL(e).pathname).slice(1);function gh(e,t){let n=0;for(let r=0;r<t.line;r++){let t=e.indexOf(`
641
- `,n);if(t<0)return e.length;n=t+1}return Math.min(n+t.character,e.length)}function _h(e,t){let n=e.slice(0,t);return{line:n.split(`
640
+ }`}],gh=class{worker;id=0;pending=new Map;handlers=new Map;versions=new Map;constructor(e){this.worker=e,e.addEventListener(`message`,e=>this.receive(e.data))}receive(e){if(e&&typeof e==`object`){if(`id`in e&&!(`method`in e)){let t=this.pending.get(e.id);if(!t)return;this.pending.delete(e.id),e.error?t.reject(Error(e.error.message)):t.resolve(e.result)}else if(`method`in e){`id`in e&&this.worker.postMessage({jsonrpc:`2.0`,id:e.id,result:null});for(let t of this.handlers.get(e.method)??[])t(e.params)}}}request(e,t){let n=++this.id;return new Promise((r,i)=>{this.pending.set(n,{resolve:r,reject:i}),this.worker.postMessage({jsonrpc:`2.0`,id:n,method:e,params:t})})}notify(e,t){this.worker.postMessage({jsonrpc:`2.0`,method:e,params:t})}on(e,t){let n=this.handlers.get(e);return n||this.handlers.set(e,n=new Set),n.add(t),()=>n.delete(t)}async initialize(){let e=await this.request(`initialize`,{processId:null,rootUri:null,capabilities:{}});return this.notify(`initialized`,{}),e}open(e,t){this.versions.set(e,1),this.notify(`textDocument/didOpen`,{textDocument:{uri:e,languageId:`yuhwa`,version:1,text:t}})}change(e,t){if(!this.versions.has(e))return this.open(e,t);let n=this.versions.get(e)+1;this.versions.set(e,n),this.notify(`textDocument/didChange`,{textDocument:{uri:e,version:n},contentChanges:[{text:t}]})}close(e){this.versions.delete(e)&&this.notify(`textDocument/didClose`,{textDocument:{uri:e}})}dispose(){this.worker.terminate();for(let e of this.pending.values())e.reject(Error(`client disposed`));this.pending.clear()}},_h=e=>`file:///`+e.split(`/`).map(encodeURIComponent).join(`/`),vh=e=>decodeURIComponent(new URL(e).pathname).slice(1);function yh(e,t){let n=0;for(let r=0;r<t.line;r++){let t=e.indexOf(`
641
+ `,n);if(t<0)return e.length;n=t+1}return Math.min(n+t.character,e.length)}function bh(e,t){let n=e.slice(0,t);return{line:n.split(`
642
642
  `).length-1,character:t-(n.lastIndexOf(`
643
- `)+1)}}function vh(e,t){let n=t.map(t=>({from:gh(e,t.range.start),to:gh(e,t.range.end),text:t.newText})).sort((e,t)=>t.from-e.from);for(let t of n)e=e.slice(0,t.from)+t.text+e.slice(t.to);return e}function yh(e,t){let n=getComputedStyle(e),r=document.createElement(`div`);for(let e of[`font`,`letterSpacing`,`lineHeight`,`padding`,`border`,`boxSizing`,`tabSize`,`textIndent`,`wordSpacing`])r.style[e]=n[e];Object.assign(r.style,{position:`absolute`,visibility:`hidden`,whiteSpace:`pre-wrap`,overflowWrap:`break-word`,width:e.clientWidth+`px`,top:`0`,left:`-9999px`}),r.textContent=e.value.slice(0,t);let i=document.createElement(`span`);i.textContent=`​`,r.append(i),document.body.append(r);let a=e.getBoundingClientRect(),o={left:a.left+i.offsetLeft-e.scrollLeft,top:a.top+i.offsetTop-e.scrollTop,height:parseFloat(n.lineHeight)||i.offsetHeight};return r.remove(),o}var bh=e=>e.replace(/[&<>]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`})[e]),xh=e=>bh(e).replace(/\*\*([^*]+)\*\*/g,`<b>$1</b>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\n\n/g,`<br>`),Sh={3:`ƒ`,6:`n`,7:`c`,9:`p`,10:`k`,12:`v`,14:`⌘`,17:`f`};function Ch(e){let{ta:t}=e,n=new ph(new Worker(new URL(new URL(`lsp.worker-DE33sIum.js`,import.meta.url).href,``+import.meta.url),{type:`module`})),r=n.initialize(),i=!1,a=[];r.then(e=>{a=e.capabilities.semanticTokensProvider.legend.tokenTypes,i=!0,l()});let o=new Map,s=new Map;n.on(`textDocument/publishDiagnostics`,t=>{let n=hh(t.uri);s.set(n,t.diagnostics),e.onDiagnostics(n)});function c(){if(!i)return!1;let t=e.files(),r=!1;for(let[i,a]of Object.entries(t))o.get(i)!==a&&(o.set(i,a),n.change(mh(i),a),r||=i===e.current());for(let e of o.keys())e in t||(o.delete(e),s.delete(e),n.close(mh(e)));return r}function l(){(c()||A!==e.current())&&(ne=new Map,ae(),se())}async function u(i,a={},o=t.selectionStart){await r,c();let s=mh(e.current());return n.request(i,{textDocument:{uri:s},position:_h(t.value,o),...a})}function d(e){let n=gh(t.value,e.start);t.focus(),t.setSelectionRange(n,gh(t.value,e.end));let r=yh(t,n),i=t.getBoundingClientRect();(r.top<i.top||r.top+r.height>i.bottom)&&(t.scrollTop+=r.top-i.top-t.clientHeight/3)}function f(n){let r=t.selectionStart,i=vh(t.value,n);e.commit(i),t.setSelectionRange(r,r)}let p=document.createElement(`div`);p.className=`lsp-complete`,p.hidden=!0,p.setAttribute(`role`,`listbox`),document.body.append(p);let m=[],h=0,g=0,_=e=>{let n=e.textEdit&&`range`in e.textEdit?e.textEdit.range:void 0;return n?t.value.slice(gh(t.value,n.start),t.selectionStart):``};async function v(e){let n=++g,r=await u(`textDocument/completion`);if(n!==g||document.activeElement!==t)return;let i=r?.length?_(r[0]):``,a=i.toLowerCase();if(m=(r??[]).filter(e=>e.label!==i&&e.label.toLowerCase().startsWith(a)).slice(0,60),!m.length||!i&&!e&&!y())return x();h=0,b()}let y=()=>/[.[",/:>]\s?$/.test(t.value.slice(0,t.selectionStart));function b(){p.innerHTML=``,m.forEach((e,t)=>{let n=document.createElement(`div`);n.className=`item`+(t===h?` active`:``),n.setAttribute(`role`,`option`);let r=document.createElement(`span`);r.className=`kind`,r.textContent=Sh[e.kind??0]??`·`;let i=document.createElement(`span`);if(i.className=`label`,i.textContent=e.label,n.append(r,i),e.detail){let t=document.createElement(`span`);t.className=`detail`,t.textContent=e.detail,n.append(t)}n.onmousedown=e=>{e.preventDefault(),S(t)},p.append(n)});let e=yh(t,t.selectionStart);p.hidden=!1;let n=e.top+e.height+p.offsetHeight<innerHeight;p.style.left=Math.min(e.left,innerWidth-p.offsetWidth-8)+`px`,p.style.top=(n?e.top+e.height+2:e.top-p.offsetHeight-2)+`px`,p.children[h]?.scrollIntoView({block:`nearest`})}function x(){g++,m=[],p.hidden=!0}function S(e){let n=m[e];if(x(),!n)return;let r=n.textEdit&&`range`in n.textEdit?n.textEdit:void 0,i=r?.newText??n.label,a=r?gh(t.value,r.range.start):t.selectionStart;t.setRangeText(i,a,t.selectionStart,`end`),t.dispatchEvent(new Event(`input`)),/[:(]\s?$/.test(i)&&v(!0)}let C=document.createElement(`div`);C.className=`lsp-hover`,C.hidden=!0,document.body.append(C);let w=0;async function T(){let e=t.selectionStart;if(e!==t.selectionEnd)return;let n=await u(`textDocument/hover`);if(!n||t.selectionStart!==e||!p.hidden)return;let r=typeof n.contents==`object`&&`value`in n.contents?n.contents.value:String(n.contents);C.innerHTML=xh(r);let i=yh(t,n.range?gh(t.value,n.range.start):e);C.hidden=!1,C.style.left=Math.min(i.left,innerWidth-C.offsetWidth-8)+`px`,C.style.top=i.top-C.offsetHeight-4+`px`}let E=()=>{clearTimeout(w),C.hidden=!0};async function D(){try{let t=await u(`textDocument/prepareRename`),n=prompt(`Rename ${t.placeholder} to`,t.placeholder)?.trim();if(!n||n===t.placeholder)return;let r=(await u(`textDocument/rename`,{newName:n})).changes[mh(e.current())]??[];f(r),e.status(`renamed ${r.length} place${r.length===1?``:`s`}`)}catch(t){e.status(t.message)}}async function O(){let t=await u(`textDocument/definition`);if(!t)return e.status(`no definition here`);let n=hh(t.uri);if(n!==e.current()){if(!(n in e.files()))return e.status(`${n} is not open`);e.open(n)}d(t.range)}let k=document.createElement(`pre`);k.className=`lsp-paint`,k.setAttribute(`aria-hidden`,`true`);let ee=document.createElement(`div`);ee.className=`lsp-wrap`,t.replaceWith(ee),ee.append(k,t);let te=new Map,ne=new Map,A=``,re=null,j=0,ie=0;function ae(){k.style.width=t.clientWidth+`px`,k.style.height=t.clientHeight+`px`;let e=``;for(let[n,r]of t.value.split(`
643
+ `)+1)}}function xh(e,t){let n=t.map(t=>({from:yh(e,t.range.start),to:yh(e,t.range.end),text:t.newText})).sort((e,t)=>t.from-e.from);for(let t of n)e=e.slice(0,t.from)+t.text+e.slice(t.to);return e}function Sh(e,t){let n=getComputedStyle(e),r=document.createElement(`div`);for(let e of[`font`,`letterSpacing`,`lineHeight`,`padding`,`border`,`boxSizing`,`tabSize`,`textIndent`,`wordSpacing`])r.style[e]=n[e];Object.assign(r.style,{position:`absolute`,visibility:`hidden`,whiteSpace:`pre-wrap`,overflowWrap:`break-word`,width:e.clientWidth+`px`,top:`0`,left:`-9999px`}),r.textContent=e.value.slice(0,t);let i=document.createElement(`span`);i.textContent=`​`,r.append(i),document.body.append(r);let a=e.getBoundingClientRect(),o={left:a.left+i.offsetLeft-e.scrollLeft,top:a.top+i.offsetTop-e.scrollTop,height:parseFloat(n.lineHeight)||i.offsetHeight};return r.remove(),o}var Ch=e=>e.replace(/[&<>]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`})[e]),wh=e=>Ch(e).replace(/\*\*([^*]+)\*\*/g,`<b>$1</b>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\n\n/g,`<br>`),Th={3:`ƒ`,6:`n`,7:`c`,9:`p`,10:`k`,12:`v`,14:`⌘`,17:`f`};function Eh(e){let{ta:t}=e,n=new gh(new Worker(new URL(new URL(`lsp.worker-B8uA5kfW.js`,import.meta.url).href,``+import.meta.url),{type:`module`})),r=n.initialize(),i=!1,a=[];r.then(e=>{a=e.capabilities.semanticTokensProvider.legend.tokenTypes,i=!0,l()});let o=new Map,s=new Map;n.on(`textDocument/publishDiagnostics`,t=>{let n=vh(t.uri);s.set(n,t.diagnostics),e.onDiagnostics(n)});function c(){if(!i)return!1;let t=e.files(),r=!1;for(let[i,a]of Object.entries(t))o.get(i)!==a&&(o.set(i,a),n.change(_h(i),a),r||=i===e.current());for(let e of o.keys())e in t||(o.delete(e),s.delete(e),n.close(_h(e)));return r}function l(){(c()||A!==e.current())&&(ne=new Map,ae(),se())}async function u(i,a={},o=t.selectionStart){await r,c();let s=_h(e.current());return n.request(i,{textDocument:{uri:s},position:bh(t.value,o),...a})}function d(e){let n=yh(t.value,e.start);t.focus(),t.setSelectionRange(n,yh(t.value,e.end));let r=Sh(t,n),i=t.getBoundingClientRect();(r.top<i.top||r.top+r.height>i.bottom)&&(t.scrollTop+=r.top-i.top-t.clientHeight/3)}function f(n){let r=t.selectionStart,i=xh(t.value,n);e.commit(i),t.setSelectionRange(r,r)}let p=document.createElement(`div`);p.className=`lsp-complete`,p.hidden=!0,p.setAttribute(`role`,`listbox`),document.body.append(p);let m=[],h=0,g=0,_=e=>{let n=e.textEdit&&`range`in e.textEdit?e.textEdit.range:void 0;return n?t.value.slice(yh(t.value,n.start),t.selectionStart):``};async function v(e){let n=++g,r=await u(`textDocument/completion`);if(n!==g||document.activeElement!==t)return;let i=r?.length?_(r[0]):``,a=i.toLowerCase();if(m=(r??[]).filter(e=>e.label!==i&&e.label.toLowerCase().startsWith(a)).slice(0,60),!m.length||!i&&!e&&!y())return x();h=0,b()}let y=()=>/[.[",/:>]\s?$/.test(t.value.slice(0,t.selectionStart));function b(){p.innerHTML=``,m.forEach((e,t)=>{let n=document.createElement(`div`);n.className=`item`+(t===h?` active`:``),n.setAttribute(`role`,`option`);let r=document.createElement(`span`);r.className=`kind`,r.textContent=Th[e.kind??0]??`·`;let i=document.createElement(`span`);if(i.className=`label`,i.textContent=e.label,n.append(r,i),e.detail){let t=document.createElement(`span`);t.className=`detail`,t.textContent=e.detail,n.append(t)}n.onmousedown=e=>{e.preventDefault(),S(t)},p.append(n)});let e=Sh(t,t.selectionStart);p.hidden=!1;let n=e.top+e.height+p.offsetHeight<innerHeight;p.style.left=Math.min(e.left,innerWidth-p.offsetWidth-8)+`px`,p.style.top=(n?e.top+e.height+2:e.top-p.offsetHeight-2)+`px`,p.children[h]?.scrollIntoView({block:`nearest`})}function x(){g++,m=[],p.hidden=!0}function S(e){let n=m[e];if(x(),!n)return;let r=n.textEdit&&`range`in n.textEdit?n.textEdit:void 0,i=r?.newText??n.label,a=r?yh(t.value,r.range.start):t.selectionStart;t.setRangeText(i,a,t.selectionStart,`end`),t.dispatchEvent(new Event(`input`)),/[:(]\s?$/.test(i)&&v(!0)}let C=document.createElement(`div`);C.className=`lsp-hover`,C.hidden=!0,document.body.append(C);let w=0;async function T(){let e=t.selectionStart;if(e!==t.selectionEnd)return;let n=await u(`textDocument/hover`);if(!n||t.selectionStart!==e||!p.hidden)return;let r=typeof n.contents==`object`&&`value`in n.contents?n.contents.value:String(n.contents);C.innerHTML=wh(r);let i=Sh(t,n.range?yh(t.value,n.range.start):e);C.hidden=!1,C.style.left=Math.min(i.left,innerWidth-C.offsetWidth-8)+`px`,C.style.top=i.top-C.offsetHeight-4+`px`}let E=()=>{clearTimeout(w),C.hidden=!0};async function D(){try{let t=await u(`textDocument/prepareRename`),n=prompt(`Rename ${t.placeholder} to`,t.placeholder)?.trim();if(!n||n===t.placeholder)return;let r=(await u(`textDocument/rename`,{newName:n})).changes[_h(e.current())]??[];f(r),e.status(`renamed ${r.length} place${r.length===1?``:`s`}`)}catch(t){e.status(t.message)}}async function O(){let t=await u(`textDocument/definition`);if(!t)return e.status(`no definition here`);let n=vh(t.uri);if(n!==e.current()){if(!(n in e.files()))return e.status(`${n} is not open`);e.open(n)}d(t.range)}let k=document.createElement(`pre`);k.className=`lsp-paint`,k.setAttribute(`aria-hidden`,`true`);let ee=document.createElement(`div`);ee.className=`lsp-wrap`,t.replaceWith(ee),ee.append(k,t);let te=new Map,ne=new Map,A=``,re=null,j=0,ie=0;function ae(){k.style.width=t.clientWidth+`px`,k.style.height=t.clientHeight+`px`;let e=``;for(let[n,r]of t.value.split(`
644
644
  `).entries()){n&&(e+=`
645
- `);let t=re&&n>=re[0]&&n<=re[1];t&&(e+=`<span class="src-mark">`);let i=[...te.get(n)??[],...ne.get(n)??[]];if(!i.length)e+=bh(r);else{let t=[...new Set([0,r.length,...i.flatMap(e=>[e.start,e.end])])].filter(e=>e<=r.length).sort((e,t)=>e-t);for(let n=0;n<t.length-1;n++){let[a,o]=[t[n],t[n+1]],s=i.filter(e=>e.start<=a&&e.end>=o).map(e=>e.cls),c=bh(r.slice(a,o));e+=s.length?`<span class="${s.join(` `)}">${c}</span>`:c}}t&&(e+=`</span>`)}k.innerHTML=e+` `,k.scrollTop=t.scrollTop}function oe(e){let t=new Map;for(let n of e){let e=t.get(n.line);e?e.push(n):t.set(n.line,[n])}return t}function se(){clearTimeout(j),j=window.setTimeout(async()=>{await r,c();let[i,o]=[e.current(),t.value],s=await n.request(`textDocument/semanticTokens/full`,{textDocument:{uri:mh(i)}});if(e.current()!==i||t.value!==o)return;let l=[];for(let e=0,t=0,n=0;e<s.data.length;e+=5){t+=s.data[e],n=s.data[e]?s.data[e+1]:n+s.data[e+1];let r=`t-${a[s.data[e+3]]}`+(s.data[e+4]&1?` t-decl`:``);l.push({line:t,start:n,end:n+s.data[e+2],cls:r})}te=oe(l),A=i,ae()},30)}function ce(){clearTimeout(ie),ie=window.setTimeout(async()=>{let e=t.selectionStart,n=t.value,r=e===t.selectionEnd?await u(`textDocument/documentHighlight`):null;if(t.value!==n||t.selectionStart!==e)return;let i=oe((r&&r.length>1?r:[]).map(e=>({line:e.range.start.line,start:e.range.start.character,end:e.range.end.character,cls:e.kind===3?`mark mark-decl`:`mark`})));(i.size||ne.size)&&(ne=i,ae())},120)}t.addEventListener(`input`,()=>{ne=new Map,ae(),se(),ce()}),t.addEventListener(`scroll`,()=>k.scrollTop=t.scrollTop),t.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&ce()}),new ResizeObserver(()=>ae()).observe(t),ae(),t.addEventListener(`input`,e=>{if(E(),!(e instanceof InputEvent)||e.inputType!==`insertText`)return x();v(!1)}),t.addEventListener(`keydown`,e=>{E();let t=!p.hidden;if(t&&(e.key===`ArrowDown`||e.key===`ArrowUp`))h=(h+(e.key===`ArrowDown`?1:m.length-1))%m.length,b();else if(t&&(e.key===`Enter`||e.key===`Tab`))S(h);else if(t&&e.key===`Escape`)x();else if(e.key===` `&&e.ctrlKey)v(!0);else if(e.key===`F2`)D();else if(e.key===`F12`)O();else{t&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`Home`||e.key===`End`)&&x();return}e.preventDefault(),e.stopImmediatePropagation()},!0);let le=()=>{x(),E()};t.addEventListener(`blur`,le),t.addEventListener(`scroll`,le),t.addEventListener(`click`,e=>{x(),E(),ce(),e.metaKey||e.ctrlKey?O():w=window.setTimeout(()=>void T(),350)});function ue(e,n=!1){if(re=e,ae(),!e||!n)return;let r=gh(t.value,{line:e[0],character:0}),i=gh(t.value,{line:e[1]+1,character:0}),a=yh(t,r).top,o=yh(t,i).top,s=t.getBoundingClientRect();(a<s.top||o>s.bottom)&&(t.scrollTop+=a-s.top-t.clientHeight/3)}return{sync:l,mark:ue,diagnostics:e=>s.get(e)??[],reveal:d,async fix(t){let n=(await u(`textDocument/codeAction`,{range:t.range,context:{diagnostics:[t]}}))?.[0]?.edit?.changes?.[mh(e.current())];return n?(f(n),!0):!1}}}var wh=` `;function Th(e,t){let n=e.slice(e.lastIndexOf(`
646
- `,t-1)+1,t),r=n.match(/^[ \t]*/)[0],i=0;for(let e of Jr(qr(n).tokens))i=Math.max(0,i+(e===`{`?1:-1));return i?r+wh:r}function Eh(e,t){let n=1;for(let r=e.lastIndexOf(`
645
+ `);let t=re&&n>=re[0]&&n<=re[1];t&&(e+=`<span class="src-mark">`);let i=[...te.get(n)??[],...ne.get(n)??[]];if(!i.length)e+=Ch(r);else{let t=[...new Set([0,r.length,...i.flatMap(e=>[e.start,e.end])])].filter(e=>e<=r.length).sort((e,t)=>e-t);for(let n=0;n<t.length-1;n++){let[a,o]=[t[n],t[n+1]],s=i.filter(e=>e.start<=a&&e.end>=o).map(e=>e.cls),c=Ch(r.slice(a,o));e+=s.length?`<span class="${s.join(` `)}">${c}</span>`:c}}t&&(e+=`</span>`)}k.innerHTML=e+` `,k.scrollTop=t.scrollTop}function oe(e){let t=new Map;for(let n of e){let e=t.get(n.line);e?e.push(n):t.set(n.line,[n])}return t}function se(){clearTimeout(j),j=window.setTimeout(async()=>{await r,c();let[i,o]=[e.current(),t.value],s=await n.request(`textDocument/semanticTokens/full`,{textDocument:{uri:_h(i)}});if(e.current()!==i||t.value!==o)return;let l=[];for(let e=0,t=0,n=0;e<s.data.length;e+=5){t+=s.data[e],n=s.data[e]?s.data[e+1]:n+s.data[e+1];let r=`t-${a[s.data[e+3]]}`+(s.data[e+4]&1?` t-decl`:``);l.push({line:t,start:n,end:n+s.data[e+2],cls:r})}te=oe(l),A=i,ae()},30)}function ce(){clearTimeout(ie),ie=window.setTimeout(async()=>{let e=t.selectionStart,n=t.value,r=e===t.selectionEnd?await u(`textDocument/documentHighlight`):null;if(t.value!==n||t.selectionStart!==e)return;let i=oe((r&&r.length>1?r:[]).map(e=>({line:e.range.start.line,start:e.range.start.character,end:e.range.end.character,cls:e.kind===3?`mark mark-decl`:`mark`})));(i.size||ne.size)&&(ne=i,ae())},120)}t.addEventListener(`input`,()=>{ne=new Map,ae(),se(),ce()}),t.addEventListener(`scroll`,()=>k.scrollTop=t.scrollTop),t.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&ce()}),new ResizeObserver(()=>ae()).observe(t),ae(),t.addEventListener(`input`,e=>{if(E(),!(e instanceof InputEvent)||e.inputType!==`insertText`)return x();v(!1)}),t.addEventListener(`keydown`,e=>{E();let t=!p.hidden;if(t&&(e.key===`ArrowDown`||e.key===`ArrowUp`))h=(h+(e.key===`ArrowDown`?1:m.length-1))%m.length,b();else if(t&&(e.key===`Enter`||e.key===`Tab`))S(h);else if(t&&e.key===`Escape`)x();else if(e.key===` `&&e.ctrlKey)v(!0);else if(e.key===`F2`)D();else if(e.key===`F12`)O();else{t&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`Home`||e.key===`End`)&&x();return}e.preventDefault(),e.stopImmediatePropagation()},!0);let le=()=>{x(),E()};t.addEventListener(`blur`,le),t.addEventListener(`scroll`,le),t.addEventListener(`click`,e=>{x(),E(),ce(),e.metaKey||e.ctrlKey?O():w=window.setTimeout(()=>void T(),350)});function ue(e,n=!1){if(re=e,ae(),!e||!n)return;let r=yh(t.value,{line:e[0],character:0}),i=yh(t.value,{line:e[1]+1,character:0}),a=Sh(t,r).top,o=Sh(t,i).top,s=t.getBoundingClientRect();(a<s.top||o>s.bottom)&&(t.scrollTop+=a-s.top-t.clientHeight/3)}return{sync:l,mark:ue,diagnostics:e=>s.get(e)??[],reveal:d,async fix(t){let n=(await u(`textDocument/codeAction`,{range:t.range,context:{diagnostics:[t]}}))?.[0]?.edit?.changes?.[_h(e.current())];return n?(f(n),!0):!1}}}var Dh=` `;function Oh(e,t){let n=e.slice(e.lastIndexOf(`
646
+ `,t-1)+1,t),r=n.match(/^[ \t]*/)[0],i=0;for(let e of Zr(Xr(n).tokens))i=Math.max(0,i+(e===`{`?1:-1));return i?r+Dh:r}function kh(e,t){let n=1;for(let r=e.lastIndexOf(`
647
647
  `,t-1);r>=0;){let t=r>0?e.lastIndexOf(`
648
- `,r-1)+1:0,i=e.slice(t,e[r-1]===`\r`?r-1:r);for(let e of Jr(qr(i).tokens).reverse())if(n+=e===`}`?1:-1,!n)return i.match(/^[ \t]*/)[0];r=t-1}return``}function Dh(e,t){let n=Th(e,t),r=e.slice(e.lastIndexOf(`
649
- `,t-1)+1,t);return n+((n===r.match(/^[ \t]*/)[0]?r.match(/^[ \t]*([-*] +)\S/)?.[1]:void 0)??``)}function Oh(e,t,n){let r=e.lastIndexOf(`
648
+ `,r-1)+1:0,i=e.slice(t,e[r-1]===`\r`?r-1:r);for(let e of Zr(Xr(i).tokens).reverse())if(n+=e===`}`?1:-1,!n)return i.match(/^[ \t]*/)[0];r=t-1}return``}function Ah(e,t){let n=Oh(e,t),r=e.slice(e.lastIndexOf(`
649
+ `,t-1)+1,t);return n+((n===r.match(/^[ \t]*/)[0]?r.match(/^[ \t]*([-*] +)\S/)?.[1]:void 0)??``)}function jh(e,t,n){let r=e.lastIndexOf(`
650
650
  `,t-1)+1,i=e.slice(r,t),a=i.match(/^[ \t]*/)[0],o=e.indexOf(`
651
651
  `,n),s=e.slice(n,o<0?e.length:o);if(/^[ \t]*[-*] *$/.test(i)&&!s.trim())return{start:r,end:n,insert:a};let c=`
652
- `+Dh(e,t);return Th(e,t)!==a&&/^[ \t]*\}/.test(s)?{start:t,end:n,insert:c+`
653
- `+a,caret:t+c.length}:{start:t,end:n,insert:c}}function kh(e,t,n,r=!1){let i=e.lastIndexOf(`
652
+ `+Ah(e,t);return Oh(e,t)!==a&&/^[ \t]*\}/.test(s)?{start:t,end:n,insert:c+`
653
+ `+a,caret:t+c.length}:{start:t,end:n,insert:c}}function Mh(e,t,n,r=!1){let i=e.lastIndexOf(`
654
654
  `,t-1)+1,a=n>t&&e[n-1]===`
655
655
  `?n-1:n,o=e.indexOf(`
656
656
  `,a),s=o<0?e.length:o,c=e.slice(i,s).split(`
657
- `),l=[],u=[],d=i;for(let e of c){let t=e.match(/^ */)[0].length,n=r?-Math.min(2,t):c.length>1&&!e.trim()?0:2;l.push([d,n]),u.push(n>0?wh+e:e.slice(-n)),d+=e.length+1}let f=(e,t)=>{let n=e;for(let[r,i]of l)i>0&&(e>r||e===r&&!t)?n+=i:i<0&&e>=r&&(n-=Math.min(-i,e-r));return n};return{text:e.slice(0,i)+u.join(`
658
- `)+e.slice(s),from:f(t,t<n),to:f(n,!1)}}var Ah=class{diagram;L;snap;constructor(e,t,n){this.diagram=e,this.L=t,this.snap=n}pinAll(){for(let e of this.L.nodes.values()){let t=this.diagram.layout.nodes[e.id]??={};(t.x===void 0||t.y===void 0)&&(t.x=Math.round(e.x),t.y=Math.round(e.y))}}edgeOverride(e){return this.diagram.layout.edges[e]??={}}nearestSide(e,t){let n=this.L.nodes.get(e),r=(t.x-(n.x+n.w/2))/(n.w/2),i=(t.y-(n.y+n.h/2))/(n.h/2);return Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`bottom`:`top`}pinned(e,t){t&&this.pinAll();let n=t?this.L.nodes.get(e):this.L.panels.find(t=>t.decl.id===e).box,r=t?this.diagram.layout.nodes[e]??={}:((this.diagram.layout.panels??={})[e]??={}).at??={x:n.x,y:n.y};return r.x??=n.x,r.y??=n.y,{o:r,w:n.w,h:n.h}}centre(e,t){let{o:n,w:r,h:i}=this.pinned(e,t),a=n.x+r/2,o=n.y+i/2;return(e,t,s)=>{n.x=Math.round(this.snap(a+t.x,s)-r/2),n.y=Math.round(this.snap(o+t.y,s)-i/2)}}part(e,t){let n=((this.diagram.layout.panels??={})[e]??={}).parts??={},r=n[t.part]??{x:0,y:0},i=(e,t,n)=>Math.round(this.snap(e+t,n)-e);return(e,a,o)=>{let s=t.axis??`xy`;n[t.part]=s===`xy`?{x:r.x+i(t.x,a.x,o),y:r.y+i(t.y,a.y,o)}:{x:r.x+i(t[s],a[s],o),y:0}}}panelSize(e,t){let{w:n,h:r}=t;return(t,i,a)=>{e.props.width=String(Math.max(40,this.snap(n+i.x,a))),e.props.height=String(Math.max(24,this.snap(r+i.y,a)))}}resize(e){let t=this.L.nodes.get(e),n=t.w,r=t.h;return this.pinAll(),(t,i,a)=>{let o=this.diagram.layout.nodes[e];o.w=Math.max(24,this.snap(n+i.x,a)),o.h=Math.max(16,this.snap(r+i.y,a))}}via(e,t,n){let r=this.L.edges.find(t=>t.key===e);this.pinAll();let i=this.edgeOverride(e);n&&jh(i,r);let a=i.via=r.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)}));n&&a.splice(t,0,{x:Math.round(n.x),y:Math.round(n.y)});let o={...a[t]};return(e,n,r)=>{a[t]={x:this.snap(o.x+n.x,r),y:this.snap(o.y+n.y,r)}}}port(e,t){let n=this.L.edges.find(t=>t.key===e),r=this.edgeOverride(e),i=t===0?n.decl.from:n.decl.to;return e=>{let n=r.ports?[...r.ports]:[`auto`,`auto`];n[t]=this.nearestSide(i,e),r.ports=n}}label(e){let t=this.edgeOverride(e),n=t.label?{...t.label}:{x:0,y:0};return(e,r)=>{t.label={x:Math.round(n.x+r.x),y:Math.round(n.y+r.y)}}}bend(e,t){let n=this.L.edges.find(t=>t.key===e),r=null,i=0;return(a,o,s)=>{r||(this.pinAll(),r=this.edgeOverride(e),jh(r,n),r.via=n.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)})),i=Ih(n,t),r.via.splice(i,0,{x:Math.round(t.x),y:Math.round(t.y)})),r.via[i]={x:this.snap(t.x+o.x,s),y:this.snap(t.y+o.y,s)}}}group(e){let{diagram:t}=this;this.pinAll();let n=[...t.nodes.values()].filter(n=>it(t,n.group).includes(e)).map(e=>e.id),r=n.map(e=>({...t.layout.nodes[e]})),i=Object.entries(t.layout.edges).filter(([e])=>{let r=t.edges.find(t=>t.key===e);return r&&n.includes(r.from)&&n.includes(r.to)}).map(([e,t])=>({o:t,via:(t.via??[]).map(e=>({...e})),k:e}));return(e,a,o)=>{let s=this.snap(a.x,o),c=this.snap(a.y,o);n.forEach((e,n)=>{t.layout.nodes[e].x=r[n].x+s,t.layout.nodes[e].y=r[n].y+c});for(let e of i)e.o.via=e.via.map(e=>({x:e.x+s,y:e.y+c}))}}};function jh(e,t){if(t.manualVia||t.decl.from===t.decl.to)return;let[n,r]=e.ports??[`auto`,`auto`];e.ports=[n===`auto`?t.sides[0]:n,r===`auto`?t.sides[1]:r]}function Mh(e,t,n=0){let r=1/0,i=n,a=0;for(let o=1;o<e.length;o++){let s=e[o-1],c=e[o],l=Math.hypot(c.x-s.x,c.y-s.y);if(a+l>=n){let e=l?Math.max(0,Math.min(1,((t.x-s.x)*(c.x-s.x)+(t.y-s.y)*(c.y-s.y))/(l*l))):0,o=Math.hypot(t.x-(s.x+e*(c.x-s.x)),t.y-(s.y+e*(c.y-s.y)));o<r&&(r=o,i=Math.max(n,a+e*l))}a+=l}return i}function Nh(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=Math.hypot(i.x-r.x,i.y-r.y);if(t<=a&&a>0)return{x:r.x+(i.x-r.x)*t/a,y:r.y+(i.y-r.y)*t/a};t-=a}return{...e[e.length-1]}}function Ph(e){let t=[0];for(let n of e.via)t.push(Mh(e.samples,n,t[t.length-1]));return t.push(Mh(e.samples,e.end,t[t.length-1])),t}function Fh(e){let t=Ph(e);return t.slice(1).map((n,r)=>Nh(e.samples,(t[r]+n)/2))}function Ih(e,t){let n=Ph(e),r=Mh(e.samples,t),i=0;for(;i<n.length-2&&r>n[i+1];)i++;return i}var K=e=>document.querySelector(e),q=K(`#source`),J=K(`#stage`),Lh=K(`#diagnostics`),Rh=K(`#inspector`),zh=K(`#status`),Bh=K(`#theme`),Vh=K(`#direction`),Hh=K(`#curve`),Uh=K(`#template`),Wh=K(`#save`),Gh=K(`#summary`),Kh=K(`#zoom-fit`),qh=K(`#tabs`),Jh=K(`#insert`),Yh=(e,t)=>t?.altKey?Math.round(e):Math.round(e/12)*12,Xh=e=>{zh.textContent=e,e&&setTimeout(()=>zh.textContent===e&&(zh.textContent=``),2e3)};function Zh(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Qh(e){let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))}function $h(){return J.querySelector(`svg`)}function eg(e){let t=$h(),n=new DOMPoint(e.clientX,e.clientY).matrixTransform(t.getScreenCTM().inverse());return{x:n.x,y:n.y}}var tg=e=>`M${e.x} ${e.y}h${e.w}v${e.h}h${-e.w}Z`;function ng(e,t,n){let r=e.direction===`right`||e.direction===`left`,[i,a,o,s]=r?[`x`,`w`,`y`,`h`]:[`y`,`h`,`x`,`w`],c=(e,t,n,i)=>r?{x:e,y:n,w:t-e,h:i-n}:{x:n,y:e,w:i-n,h:t-e},l=[...e.nodes.values()].filter(e=>!t.group||e.decl.group===t.group),u=t.group?e.groups.find(e=>e.id===t.group):void 0;if(t.kind===`padding`){if(!t.group){let t=e.bounds,r=n;return[tg(t)+tg({x:t.x+r,y:t.y+r,w:t.w-2*r,h:t.h-2*r})]}let r=[...l,...e.groups.filter(e=>e.decl.parent===t.group)];return u&&r.length?[tg(u)+tg(rg(r))]:[]}if(t.kind===`panel-gap`){let t=[...e.nodes.values(),...e.groups];if(!t.length)return[];let n=rg(t);return e.panels.flatMap(({box:e})=>{let t=(e,t,n,r)=>[Math.max(e,n),Math.min(t,r)],[r,i]=t(n.y,n.y+n.h,e.y,e.y+e.h),[a,o]=t(n.x,n.x+n.w,e.x,e.x+e.w);return e.x>=n.x+n.w&&i>r?[tg({x:n.x+n.w,y:r,w:e.x-n.x-n.w,h:i-r})]:e.y>=n.y+n.h&&o>a?[tg({x:a,y:n.y+n.h,w:o-a,h:e.y-n.y-n.h})]:[]})}let d=(e,t)=>e[i]<t[i]+t[a]&&t[i]<e[i]+e[a];if(t.kind===`gap`){let e=[],t=[...l].sort((e,t)=>e[o]-t[o]);for(let[n,r]of t.entries()){let l=t.slice(n+1).find(e=>d(r,e)&&e[o]>=r[o]+r[s]);if(l){let t=Math.max(r[i],l[i]),n=Math.min(r[i]+r[a],l[i]+l[a]);e.push(tg(c(t,n,r[o]+r[s],l[o])))}}return e}if(!l.length)return[];let f=l.map(e=>[e[i],e[i]+e[a]]).sort((e,t)=>e[0]-t[0]),p=[];for(let[e,t]of f){let n=p[p.length-1];n&&e<n[1]?n[1]=Math.max(n[1],t):p.push([e,t])}let m=Math.min(...l.map(e=>e[o])),h=Math.max(...l.map(e=>e[o]+e[s]));return p.slice(1).map((e,t)=>tg(c(p[t][1],e[0],m,h)))}function rg(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y));return{x:t,y:n,w:Math.max(...e.map(e=>e.x+e.w))-t,h:Math.max(...e.map(e=>e.y+e.h))-n}}var ig=`main.yu`,Y={source:``,diagram:void 0,L:void 0,selection:null,spacing:null,zoom:0,frozen:null,files:{[ig]:``},current:ig,drag:null},ag=new Map,og=new URLSearchParams(location.search).has(`server`),sg=e=>e?`${e.kind}:${e.id}${e.k?`#${e.k}`:``}`:``,cg=(e,t,n)=>{let r=n.k??0;for(let i of e)if(t(i)===n.id&&!r--)return i},lg=e=>cg(Y.diagram.panels,e=>e.id,e),ug=e=>cg(Y.L.panels,e=>e.decl.id,e),dg={rebuild:fg,commit:fg,commitLayout:fg,deleteSelection:fg,addNodeAt:fg};function fg(){throw Error(`editor: app hooks are not installed yet`)}var pg=`http://www.w3.org/2000/svg`;function mg(e,t){let n=document.createElementNS(pg,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,String(r));return n}var hg=``;matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>hg=``);function gg(e){if(!Y.selection&&!Y.spacing)return;let t=mg(`g`,{class:`overlay`}),n=Y.L.bounds.w/(e.width.baseVal.value||Y.L.bounds.w),r=hg||=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||`#2563eb`;if(Y.spacing){let e=Number(Y.diagram.settings.padding??24),i=Y.spacing.kind===`gap`&&Y.spacing.group?[Y.spacing,{...Y.spacing,kind:`rank-gap`}]:[Y.spacing];for(let a of i.flatMap(t=>ng(Y.L,t,e)))t.append(mg(`path`,{d:a,"fill-rule":`evenodd`,fill:r,"fill-opacity":.22,stroke:r,"stroke-width":n,"stroke-dasharray":`${3*n} ${2*n}`,"pointer-events":`none`}))}if(!Y.selection){e.append(t);return}let i=(e,n,i)=>t.append(mg(`rect`,{x:e.x-n,y:e.y-n,width:e.w+2*n,height:e.h+2*n,rx:i,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),a=(e,i,a,o,s=`circle`)=>{let c={"data-handle":a,"data-i":o,stroke:r,"stroke-width":1.5*n,style:`cursor:move`};s===`square`?t.append(mg(`rect`,{x:e-5*n,y:i-5*n,width:10*n,height:10*n,rx:2*n,fill:`#fff`,...c})):t.append(mg(`circle`,{cx:e,cy:i,r:(s===`ring`?4:5.5)*n,fill:s===`ring`?`#fff`:r,...c}))};if(Y.selection.kind===`node`){let e=Y.L.nodes.get(Y.selection.id);i(e,4,6),a(e.x+e.w+4,e.y+e.h+4,`resize`,0,`square`)}else if(Y.selection.kind===`panel`){let e=ug(Y.selection);i(e.box,3,12),a(e.box.x+e.box.w+3,e.box.y+e.box.h+3,`resize`,0,`square`);let n=t.lastElementChild;n.setAttribute(`style`,`cursor:nwse-resize`);let r=mg(`title`,{});r.textContent=`drag to set the smallest frame size · double-click to reset`,n.append(r),e.handles.forEach((n,r)=>{let i=!!Y.diagram.layout.panels?.[e.decl.id]?.parts?.[n.part];a(n.x,n.y,`part`,r,i?`circle`:`ring`);let o=t.lastElementChild,s=mg(`title`,{});s.textContent=`${n.title??n.part}${i?` · double-click to reset`:``}`,o.append(s),o.setAttribute(`style`,`cursor:${n.axis===`x`?`ew-resize`:n.axis===`y`?`ns-resize`:`move`}`)})}else if(Y.selection.kind===`group`)i(Y.L.groups.find(e=>e.id===Y.selection.id),3,14);else{let e=Y.L.edges.find(e=>e.key===Y.selection.id);t.append(mg(`path`,{d:e.d,fill:`none`,stroke:r,"stroke-width":e.style.width+4,opacity:.25,"pointer-events":`none`}));let n=e=>{let n=mg(`title`,{});n.textContent=e,t.lastElementChild.append(n)};Fh(e).forEach((e,t)=>{a(e.x,e.y,`mid`,t,`ring`),n(`drag to add a bend`)}),e.via.forEach((e,t)=>{a(e.x,e.y,`via`,t),n(`drag to move · right-click or double-click to remove`)}),a(e.start.x,e.start.y,`end`,0,`square`),n(`drag to pick a side · right-click to reset`),a(e.end.x,e.end.y,`end`,1,`square`),n(`drag to pick a side · right-click to reset`)}e.append(t)}var _g=.1,vg=8,yg=()=>{let e=Y.L.bounds;return Math.min(1.5,Math.max(.2,Math.min((J.clientWidth-48)/e.w,(J.clientHeight-48)/e.h)))};function bg(e){let t=Y.L.bounds,n=Y.zoom||yg();Y.frozen?(e.setAttribute(`viewBox`,Y.frozen.viewBox),e.setAttribute(`width`,String(Y.frozen.w)),e.setAttribute(`height`,String(Y.frozen.h))):(e.setAttribute(`width`,String(Math.round(t.w*n))),e.setAttribute(`height`,String(Math.round(t.h*n)))),Kh.textContent=`${Math.round((Y.frozen?Y.frozen.w/t.w:n)*100)}%`,Kh.title=Y.zoom?`Fit to view (⌘0)`:`Fitted to view`}function xg(e,t){let n=$h();if(!n||Y.frozen)return;let r=e?Math.min(vg,Math.max(_g,e)):0;if(r===Y.zoom)return;let i=J.getBoundingClientRect(),a=t?.clientX??i.left+i.width/2,o=t?.clientY??i.top+i.height/2,s=n.getBoundingClientRect(),c=(a-s.left)/s.width,l=(o-s.top)/s.height;if(Y.zoom=r,bg(n),n.querySelector(`:scope > .overlay`)?.remove(),gg(n),!Y.zoom)return;let u=n.getBoundingClientRect();J.scrollLeft+=u.left+c*u.width-a,J.scrollTop+=u.top+l*u.height-o}function Sg(e){return e.kind===`node`?Y.L.nodes.has(e.id):e.kind===`group`?Y.L.groups.some(t=>t.id===e.id):e.kind===`panel`?!!ug(e):Y.L.edges.some(t=>t.key===e.id)}var Cg=[`sans`,`serif`,`mono`,`Inter`,`Helvetica`,`Arial`,`Verdana`,`Segoe UI`,`Roboto`,`Ubuntu`,`Georgia`,`Times New Roman`,`Palatino`,`Cambria`,`Menlo`,`Consolas`,`Courier New`,`JetBrains Mono`,`Fira Code`],wg,Tg=new Map;globalThis.document?.fonts?.addEventListener(`loadingdone`,()=>Tg.clear());function Eg(e){if(ce(e)||(wg??=document.createElement(`canvas`).getContext(`2d`),!wg))return!0;let t=Tg.get(e);if(t!==void 0)return t;let n=wg,r=e=>(n.font=`72px ${e}`,n.measureText(`mmmwwwiiilllQ@&10`).width),i=JSON.stringify(e),a=[`monospace`,`serif`,`sans-serif`].some(e=>r(`${i}, ${e}`)!==r(e));return Tg.set(e,a),a}function Dg(e,t=Eg){let n=le(e),r=[];for(let e of n){if(t(e)){let t=e===`system-ui`?`the system font`:`the system ${e.replace(/^ui-/,``)} font`;return{shown:ce(e)?t:e,missing:r}}r.push(e)}return{shown:`the browser default`,missing:r}}function Og(e,t,n=!1,r=``){let i=document.createElement(`label`);i.className=`field ${r}`.trim(),i.classList.toggle(`unset`,n);let a=document.createElement(`span`);return a.textContent=e,i.append(a,t),i}function X(e,t,n,r){let i=document.createElement(`select`);for(let e of t)i.append(new Option(e||`default`,e));return n&&!t.includes(n)&&i.append(new Option(n,n)),i.value=n,i.onchange=()=>r(i.value),Og(e,i,!n)}var kg=e=>e.replace(/\n/g,`\\n`),Ag=e=>e.replace(/\\n/g,`
659
- `);function jg(e,t,n=`text`,r=``){let i=document.createElement(`input`);return i.type=n,i.value=n===`text`?kg(e):e,i.placeholder=r,i.spellcheck=!1,n===`number`&&(i.step=`any`),i.onchange=()=>t(n===`text`?Ag(i.value.trim()):i.value),i.onkeydown=t=>{t.stopPropagation(),t.key===`Enter`?i.blur():t.key===`Escape`&&(i.value=n===`text`?kg(e):e,i.blur())},i}function Mg(e){let t=ot(Y.diagram,e,`gap`);return t?`${t.value} from ${t.group}`:`${Y.diagram.settings.gap??`36`} from diagram`}function Ng(e){let t=document.createElement(`p`);return t.className=`scope`,t.textContent=e,t}function Pg(e,t){let n=e=>{Y.spacing=e?t:null;let n=$h();n&&(n.querySelector(`:scope > .overlay`)?.remove(),gg(n))};return e.addEventListener(`mouseenter`,()=>n(!0)),e.addEventListener(`mouseleave`,()=>n(e.contains(document.activeElement))),e.addEventListener(`focusin`,()=>n(!0)),e.addEventListener(`focusout`,()=>n(!1)),e}function Fg(e,t){return $g(t,pr[e]?.replace(/`/g,``))}function Ig(e,t,n,r=``){return Og(e,jg(t,n,`text`,r),!t,`text`)}function Lg(){let e=`font-list`;if(document.getElementById(e))return e;let t=Object.assign(document.createElement(`datalist`),{id:e}),n=()=>{let e=[...document.fonts].flatMap(e=>le(e.family)),n=new Set([...Cg.filter((e,t)=>t<3||Eg(e)),...e]);t.replaceChildren(...[...n].map(e=>Object.assign(document.createElement(`option`),{value:e})))};return n(),document.fonts.addEventListener(`loadingdone`,n),document.body.append(t),e}function Rg(e,t,n=!1){let r=Ig(`font`,e,t,n?`diagram font`:`theme font`);if(r.querySelector(`input`).setAttribute(`list`,Lg()),n&&!e)return[r];let{shown:i,missing:a}=Dg(e?ue(e).font:_e(Y.diagram.settings.theme,Y.diagram.themes).font),o=document.createElement(`p`);return o.className=`hint`,o.textContent=e&&a.length?`${a.join(`, `)} ${a.length>1?`are`:`is`} not on this computer, so the editor shows ${i}. A viewer without the font sees the next one in the list.`:`Shown as ${i}.`,[r,o]}function Z(e,t,n,r=``){return Og(e,jg(t,n,`number`,r),!t,`text`)}function zg(e,t,n){let r=document.createElement(`input`);return r.type=`checkbox`,r.checked=t,r.onchange=()=>n(r.checked),Og(e,r,!t,`toggle`)}var Bg=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function Vg(e,t=400){if(!e)return;let n=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);return(n&&m(n[1],n[2]?Number(n[2]):t))??(CSS.supports(`color`,e)?e:void 0)}var Hg=e=>!e||!Bg.test(e)?`#888888`:e.length===4?`#${e.slice(1).split(``).map(e=>e+e).join(``)}`:e.toLowerCase();function Ug(e){let t=document.createElement(`i`);return t.className=e?`swatch`:`swatch none`,e&&t.style.setProperty(`--sw`,Vg(e)??`transparent`),t}function Wg(e,t){let n=document.createElement(`div`);n.className=`palette`;let r=(n,r)=>{let i=document.createElement(`button`);return i.type=`button`,i.className=`dot${n?``:` none`}${n===e?` on`:``}`,i.title=r,i.setAttribute(`aria-label`,r),n&&i.style.setProperty(`--sw`,Vg(n)??`transparent`),i.onclick=()=>t(n),i};n.append(r(``,`default`),...f.map(e=>r(e,e)));let i=document.createElement(`label`),a=!!e&&!f.includes(e);i.className=`dot custom${a?` on`:``}`,i.title=`custom colour`,a&&i.style.setProperty(`--sw`,Vg(e)??`transparent`);let o=document.createElement(`input`);return o.type=`color`,o.value=Hg(Vg(e,500)),o.onchange=()=>t(o.value),i.append(o),n.append(i),n}function Gg(e,t,n,r=``){let i=document.createElement(`div`);i.className=`color-field`;let a=document.createElement(`div`);a.className=`color-head`;let o=document.createElement(`span`);o.textContent=e;let s=document.createElement(`code`);s.textContent=t||(r?`${r} (class)`:`default`),a.append(o,s);let c=jg(t,n,`text`,r||`#hex, rgb(), hsl(), tomato`);return c.classList.add(`color-text`),i.append(a,Wg(t,n),c),i}function Kg(e,t,n,r=``){let i=document.createElement(`div`);i.className=`field color`,i.classList.toggle(`unset`,!t);let a=document.createElement(`span`);a.textContent=e;let o=document.createElement(`label`);o.className=`dot${t?``:` none`}`,o.style.setProperty(`--sw`,Vg(t,500)??`transparent`),o.title=`pick a colour`;let s=document.createElement(`input`);s.type=`color`,s.value=Hg(Vg(t,500)),s.onchange=()=>n(s.value),o.append(s);let c=jg(t,n,`text`,r||`none`);return i.append(a,o,c),t&&i.append(Xg(`×`,()=>n(``),`clear`)),i}function qg(e){let t=e.kind===`node`?Y.diagram.nodes.get(e.id):e.kind===`group`?Y.diagram.groups.get(e.id):e.kind===`panel`?lg(e):Y.diagram.edges.find(t=>t.key===e.id);return t&&(t.labelRef?!t.labelRef.generated:e.kind===`node`&&!t.ref)?t.label??``:null}function Jg(e,t){t!==qg(e)&&dg.commit(bm(Y.source,e,t,Y.diagram))}function Yg(e,t){let n=qg(e);if(n===null)return;let r=e.kind===`group`||e.kind===`panel`?t.querySelector(`:scope > text`):null,i=(r??t).getBoundingClientRect(),a=Math.max(i.width+24,140),o=document.createElement(`input`);o.className=`label-edit`,o.value=kg(n),o.spellcheck=!1;let s=r||e.kind!==`group`&&e.kind!==`panel`,c=s?i.top+i.height/2-15:i.top+6,l=s?i.left+i.width/2-a/2:i.left+6;Object.assign(o.style,{top:`${c}px`,left:`${Math.max(4,l)}px`,width:`${a}px`}),document.body.append(o),o.focus(),o.select();let u=!1,d=t=>{u||(u=!0,o.remove(),t&&Jg(e,Ag(o.value)))};o.onkeydown=e=>{e.stopPropagation(),e.key===`Enter`?d(!0):e.key===`Escape`&&d(!1)},o.onblur=()=>d(!0)}function Xg(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,n&&(r.className=n),r.onclick=t,r}function Zg(e,t,n){return t?Xg(e,()=>{n(),dg.commitLayout()}):null}var Qg=new Set((()=>{try{return JSON.parse(localStorage.getItem(`yuhwa-folded`)??`[]`)}catch{return[]}})());function Q(e,...t){let n=t.filter(e=>!!e);if(!n.length)return;let r=document.createElement(`section`);r.classList.toggle(`folded`,Qg.has(e));let i=document.createElement(`h3`),a=document.createElement(`button`);a.type=`button`,a.textContent=e,a.setAttribute(`aria-expanded`,String(!Qg.has(e))),a.onclick=()=>{let t=r.classList.toggle(`folded`);a.setAttribute(`aria-expanded`,String(!t)),t?Qg.add(e):Qg.delete(e);try{localStorage.setItem(`yuhwa-folded`,JSON.stringify([...Qg]))}catch{}},i.append(a);let o=document.createElement(`div`);o.className=`rows`,o.append(...n),r.append(i,o),Rh.append(r)}function $g(e,t){if(!t)return e;let n=document.createElement(`i`);return n.className=`info`,n.tabIndex=0,n.textContent=`i`,n.setAttribute(`aria-label`,t),n.dataset.tip=t,n.onclick=e=>e.preventDefault(),e.querySelector(`:scope > span`)?.append(n),e}function e_(e){let t=document.createElement(`p`);return t.className=`hint`,t.innerHTML=e,t}var t_=null,n_={up:`↑`,down:`↓`,remove:`✕`};function r_(e,t){let n=n=>r=>t({op:`set`,id:e.id,key:n,value:r||null}),r=[Wg(e.tone??``,n(`color`))],i=e.values??{},a=Object.entries(e.fields??{}).map(([e,t])=>t.length===2&&t[0]===``&&t[1]===`true`?zg(e,i[e]===`true`,t=>n(e)(t?`true`:``)):t.length?X(e,t,i[e]??``,n(e)):Ig(e,i[e]??``,n(e)));if(a.length){let e=document.createElement(`div`);e.className=`rows`,e.append(...a),r.push(e)}if(e.actions?.length){let n=document.createElement(`div`);n.className=`part-actions`;for(let r of e.actions){let i=document.createElement(`button`);i.type=`button`,i.textContent=r===`add`?`+ ${e.adds??`add`}`:n_[r],i.title=r===`add`?`add to ${e.label}`:`${r} ${e.id}`,i.onclick=()=>t({op:r,id:e.id}),n.append(i)}r.push(n)}return r}function i_(e,t,n){let r=document.createElement(`div`);r.className=`parts`;let i=(t,n=!0)=>{let r=Tm(Y.source,e,t,Y.diagram);if(r.source===Y.source)return Xh(`this part cannot be changed here`);t_=n&&r.id?`${e}:${r.id}`:null,dg.commit(r.source)},a=``;for(let n of t){if(n.kind!==a){a=n.kind;let e=document.createElement(`div`);e.className=`parts-kind`,e.textContent=a,r.append(e)}let t=`${e}:${n.id}`,o=document.createElement(`div`);o.className=`part`,n.depth&&(o.style.marginLeft=`${Math.min(n.depth,8)*12}px`);let s=document.createElement(`button`);s.type=`button`,s.title=`edit ${n.id}`;let c=document.createElement(`span`);c.textContent=n.label;let l=document.createElement(`code`);l.textContent=n.tone??``,s.append(Ug(n.tone??``),c,l);let u=e=>{o.classList.toggle(`open`,e),o.replaceChildren(s,...e?r_(n,i):[])};s.onclick=()=>{let e=t_!==t;r.querySelector(`.part.open`)?.dispatchEvent(new Event(`close`)),t_=e?t:null,u(e)},o.addEventListener(`close`,()=>u(!1)),u(t_===t),r.append(o)}if(n){let e=document.createElement(`button`);e.type=`button`,e.className=`part-add`,e.textContent=`+ ${n}`,e.onclick=()=>i({op:`add`}),r.append(e)}return r}var a_=[``,...Un.style],o_=[``,...fr.curve],s_=`Click a box, edge, group or panel to style it · double-click to edit its text · drag to move · drag an edge to bend it · drag a panel's dots to adjust it · double-click a bend or dot to reset it · <kbd>alt</kbd> no snapping · <kbd>←</kbd><kbd>→</kbd> nudge`;function c_(){let e=Y.diagram.settings,t=e=>t=>dg.commit(wm(Y.source,e,t||null)),n=e.direction===`down`||e.direction===`up`,r=document.createElement(`div`);r.className=`title`,r.innerHTML=`<small>diagram</small>settings`,Rh.append(r,Ng(`Whole diagram. Groups, nodes and edges can override some of these with their own props.`)),Q(`Text`,Ig(`title`,e.title??``,t(`title`)),Ig(`subtitle`,e.subtitle??``,t(`subtitle`)),...Rg(e.font??``,t(`font`)),Z(`font size`,e[`font-size`]??``,t(`font-size`),`14`)),Q(`Style`,X(`theme`,[``,...ge(Y.diagram.themes)],e.theme??``,t(`theme`)),Kg(`accent`,e.accent??``,t(`accent`),`theme`),Kg(`background`,e.background??``,t(`background`),`theme`),Z(`radius`,e.radius??``,t(`radius`),`theme`),Z(`stroke`,e[`stroke-width`]??``,t(`stroke-width`),`theme`),Kg(`edge color`,e[`edge-color`]??``,t(`edge-color`),`theme`),Z(`edge width`,e[`edge-width`]??``,t(`edge-width`),`theme`),zg(`shadow`,!!e.shadow&&e.shadow!==`false`,e=>t(`shadow`)(e?`true`:``)),X(`shape`,[``,...Sn],e.shape??``,t(`shape`))),Q(`Layout`,X(`direction`,[``,...fr.direction],e.direction??``,t(`direction`)),X(`curve`,o_,e.curve??``,t(`curve`)),X(`merge`,[``,...fr.merge],e.merge??``,t(`merge`)),Pg(Fg(`gap`,Z(`node gap`,e.gap??``,t(`gap`),`36`)),{kind:`gap`}),Pg(Fg(`rank-gap`,Z(n?`row gap`:`column gap`,e[`rank-gap`]??``,t(`rank-gap`),`auto`)),{kind:`rank-gap`}),Pg(Fg(`padding`,Z(`padding`,e.padding??``,t(`padding`),`24`)),{kind:`padding`}),Fg(`wrap`,Z(`wrap`,e.wrap??``,t(`wrap`),`off`)),Fg(`panels`,X(`panels`,[``,...fr.panels],e.panels??``,t(`panels`))),Pg(Fg(`panel-gap`,Z(`panel gap`,e[`panel-gap`]??``,t(`panel-gap`),`48`)),{kind:`panel-gap`}),zg(`grid`,!!e.grid&&e.grid!==`false`,e=>t(`grid`)(e?`true`:``))),Rh.append(e_(s_))}function l_(){if(Rh.innerHTML=``,!Y.selection)return c_();let e=Y.selection,t=document.createElement(`div`);t.className=`title`;let n=document.createElement(`small`);n.textContent=e.kind;let r=document.createElement(`span`);r.textContent=e.id;let i=Xg(`Delete`,dg.deleteSelection,`delete`);i.title=`delete this ${e.kind} (Delete)`;let a=Xg(`×`,()=>{Y.selection=null,dg.rebuild(!1)},`clear`);a.title=`deselect (Esc)`,t.append(n,r,i,a),Rh.append(t,Ng(`Only this ${e.kind}. Empty fields fall back to its classes, then the diagram settings.`));let o={kind:e.kind,id:e.id},s=e=>t=>dg.commit(Sm(Y.source,o,e,t||null)),c=(e,t)=>zg(e,!!t[e]&&t[e]!==`false`,t=>s(e)(t?`true`:``)),l=(e,t=`auto`,n={})=>[Kg(`text`,e.text??e[`label-color`]??``,s(`text`),n.text),...Rg(e.font??``,s(`font`),!0),Z(`font size`,e[`font-size`]??``,s(`font-size`),n[`font-size`]??t),Z(`font weight`,e[`font-weight`]??``,s(`font-weight`),n[`font-weight`]??`auto`),c(`italic`,e)],u=(e,t,n)=>{let r=(e.align??``).trim().split(/\s+/).filter(Boolean),i=vt.includes(r[0])?r[0]:``,a=r.slice(+!!i).join(` `),o=(e,t)=>s(`align`)([e,t.trim()].filter(Boolean).join(` `));return[X(`merge`,[``,...Un.merge],e.merge??``,s(`merge`)),X(n&&!a?`align members`:`align`,[``,...vt],i,e=>o(e,a)),Ig(`align with`,a,e=>o(i,e),t.align??(n?`id, or empty for the members`:`id`))]},d=qg(o),f=d!==null&&Ig(e.kind===`panel`?`title`:`label`,d,e=>Jg(o,e));if(e.kind===`panel`){let t=lg(e),r=V.panels.get(t.kind);n.textContent=t.kind;let i=r?.options??{},a=!!t.ref&&!t.ref.generated;Q(`Text`,f,...a?l(t.props,`theme`):[]),a&&(Q(`Options`,...Object.entries(i).map(([e,n])=>{let i=yr(n),a=t.props[e]??``;return $g((()=>{switch(i.kind){case`select`:return X(e,[``,...i.values],a,s(e));case`flag`:return c(e,t.props);case`color`:return Kg(e,a,s(e),`default`);case`number`:return Z(e,a,s(e));case`text`:return Ig(e,a,s(e));default:return i}})(),r?.help?.[e])})),Q(`Size`,$g(Z(`width`,t.props.width??``,s(`width`),`auto`),Hn.width),$g(Z(`height`,t.props.height??``,s(`height`),`auto`),Hn.height),e_(`Or drag the square at the frame’s corner on the canvas.`)),Q(`Style`,Gg(`color`,t.props.color??``,s(`color`)),X(`theme`,[``,...ge(Y.diagram.themes)],t.props.theme??``,s(`theme`)),Kg(`background`,t.props.background??t.props.fill??``,s(`background`),`theme`),Kg(`border`,t.props.border??t.props.stroke??``,s(`border`),`theme`),X(`border style`,a_,Qe(t.props)??``,s(`border-style`)),Z(`border width`,t.props[`border-width`]??``,s(`border-width`),`1`),Kg(`edge color`,t.props[`edge-color`]??``,s(`edge-color`),`theme`),Z(`edge width`,t.props[`edge-width`]??``,s(`edge-width`),`theme`),Z(`radius`,t.props.radius??``,s(`radius`),`10`),c(`shadow`,t.props),zg(`frame`,t.props.frame!==`false`,e=>s(`frame`)(e?``:`false`))));let o=!t.failed&&r?.parts?.(t.data)||[],u=a&&!!r?.editPart&&!!t.lines&&t.lines[1]-t.lines[0]-1===t.body.length;o.length&&Q(`Parts`,u?i_(e.id,o,r?.adds):e_(`Write the panel body on its own lines to colour its parts here.`));let d=Y.diagram.layout.panels?.[e.id];Q(`Layout`,Zg(`Unpin`,d?.at,()=>delete d.at),Zg(`Reset layout`,d?.parts,()=>delete d.parts))}else if(e.kind===`node`){let n=Y.diagram.nodes.get(e.id),r=Object.assign({},...n.classes.map(e=>Y.diagram.classes[e]??{})),i=e=>n.props[e]??``;Q(`Text`,f,Ig(`sub`,i(`sub`),s(`sub`),r.sub),...l(n.props,`auto`,r),c(`bold`,n.props),c(`mono`,n.props),Z(`body size`,i(`body-size`),s(`body-size`),r[`body-size`]??`auto`),Kg(`body colour`,i(`body-color`),s(`body-color`),r[`body-color`]??`from text`),Ig(`icon`,i(`icon`),s(`icon`),r.icon),Ig(`link`,i(`link`),s(`link`),r.link),Ig(`tooltip`,i(`tooltip`),s(`tooltip`),r.tooltip)),Q(`Colour`,Gg(`color`,i(`color`),s(`color`),r.color),Kg(`fill`,i(`fill`),s(`fill`),r.fill??`from color`),Kg(`stroke`,i(`stroke`),s(`stroke`),r.stroke??`from color`)),Q(`Shape`,X(`shape`,[``,...Sn],i(`shape`),s(`shape`)),X(`border`,a_,Qe(n.props)??``,s(`border-style`)),Z(`border width`,i(`stroke-width`),s(`stroke-width`),r[`stroke-width`]??`theme`),Z(`radius`,i(`radius`),s(`radius`),r.radius??`theme`),Z(`opacity`,i(`opacity`),s(`opacity`),`1`),c(`shadow`,n.props));let a=[...Y.diagram.nodes.keys()].filter(t=>t!==e.id);Q(`Connect`,Xg(`+ Connected node`,()=>dg.addNodeAt({from:e.id,group:n.group})),a.length>0&&X(`connect to`,[``,...a],``,t=>t&&dg.commit(Am(Y.source,{from:e.id,to:t},Y.diagram)))),Q(`Size`,Z(`width`,i(`width`),s(`width`),`auto`),Z(`height`,i(`height`),s(`height`),`auto`),Z(`max width`,i(`max-width`),s(`max-width`),`auto`)),Q(`Layout`,...u(n.props,r,!1),Zg(`Unpin`,Y.diagram.layout.nodes[e.id],()=>delete Y.diagram.layout.nodes[e.id])),r.shape&&!n.props.shape&&(t.title=`shape ${r.shape} from class`)}else if(e.kind===`edge`){let t=Y.diagram.edges.find(t=>t.key===e.id),n=e=>t.props[e]??``,r=[``,`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],i=[``,`top`,`right`,`bottom`,`left`,`auto`];Q(`Text`,f,...l(t.props),Kg(`label bg`,n(`label-bg`),s(`label-bg`))),Q(`Line`,Gg(`color`,n(`color`),s(`color`)),Kg(`stroke`,n(`stroke`),s(`stroke`),`from color`),X(`style`,a_,Qe(t.props,`style`)??``,s(`style`)),Z(`width`,n(`width`),s(`width`),`theme`),Z(`opacity`,n(`opacity`),s(`opacity`),`1`),c(`flow`,t.props),c(`animate`,t.props)),Q(`Ends`,X(`head`,r,n(`head`),s(`head`)),X(`tail`,r,n(`tail`),s(`tail`)),X(`exit`,i,n(`exit`),s(`exit`)),X(`enter`,i,n(`enter`),s(`enter`))),Q(`Route`,X(`curve`,o_,n(`curve`),s(`curve`)),c(`constraint`,t.props),X(`merge`,[``,...Un.merge],n(`merge`),s(`merge`)),Zg(`Reset route`,Y.diagram.layout.edges[e.id],()=>delete Y.diagram.layout.edges[e.id])),t.ref&&Y.diagram.edges.filter(e=>e.ref===t.ref).length>1&&Rh.append(e_(`Style applies to every edge on this line.`))}else{let t=Y.diagram.groups.get(e.id),n=e=>t.props[e]??``;Q(`Text`,f,...l(t.props),c(`caps`,t.props)),Q(`Colour`,Gg(`color`,n(`color`),s(`color`)),Kg(`fill`,n(`fill`),s(`fill`),`from color`),Kg(`stroke`,n(`stroke`),s(`stroke`),`from color`),X(`border`,a_,Qe(t.props)??``,s(`border-style`))),Q(`Content`,Xg(`+ Node inside`,()=>dg.addNodeAt({group:e.id}))),Q(`Layout`,...u(t.props,{},!0),Pg($g(Z(`gap`,n(`gap`),s(`gap`),Mg(t.parent)),`Space between this group's members and between its ranks, px. Only this group. Empty: the parent group's gap, else the diagram's node gap.`),{kind:`gap`,group:e.id}),Pg($g(Ig(`padding`,n(`padding`),s(`padding`),`18, or y x, or top right bottom left`),`Space inside this group's border, px, like CSS: all, y x, top x bottom, or top right bottom left. Only this group.`),{kind:`padding`,group:e.id}))}}Object.assign(dg,{rebuild:$,commit:E_,commitLayout:D_,deleteSelection:O_,addNodeAt:k_});var u_=`title: Hello yuhwa
657
+ `),l=[],u=[],d=i;for(let e of c){let t=e.match(/^ */)[0].length,n=r?-Math.min(2,t):c.length>1&&!e.trim()?0:2;l.push([d,n]),u.push(n>0?Dh+e:e.slice(-n)),d+=e.length+1}let f=(e,t)=>{let n=e;for(let[r,i]of l)i>0&&(e>r||e===r&&!t)?n+=i:i<0&&e>=r&&(n-=Math.min(-i,e-r));return n};return{text:e.slice(0,i)+u.join(`
658
+ `)+e.slice(s),from:f(t,t<n),to:f(n,!1)}}var Nh=class{diagram;L;snap;constructor(e,t,n){this.diagram=e,this.L=t,this.snap=n}pinAll(){for(let e of this.L.nodes.values()){let t=this.diagram.layout.nodes[e.id]??={};(t.x===void 0||t.y===void 0)&&(t.x=Math.round(e.x),t.y=Math.round(e.y))}}edgeOverride(e){return this.diagram.layout.edges[e]??={}}nearestSide(e,t){let n=this.L.nodes.get(e),r=(t.x-(n.x+n.w/2))/(n.w/2),i=(t.y-(n.y+n.h/2))/(n.h/2);return Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`bottom`:`top`}pinned(e,t){t&&this.pinAll();let n=t?this.L.nodes.get(e):this.L.panels.find(t=>t.decl.id===e).box,r=t?this.diagram.layout.nodes[e]??={}:((this.diagram.layout.panels??={})[e]??={}).at??={x:n.x,y:n.y};return r.x??=n.x,r.y??=n.y,{o:r,w:n.w,h:n.h}}centre(e,t){let{o:n,w:r,h:i}=this.pinned(e,t),a=n.x+r/2,o=n.y+i/2;return(e,t,s)=>{n.x=Math.round(this.snap(a+t.x,s)-r/2),n.y=Math.round(this.snap(o+t.y,s)-i/2)}}part(e,t){let n=((this.diagram.layout.panels??={})[e]??={}).parts??={},r=n[t.part]??{x:0,y:0},i=(e,t,n)=>Math.round(this.snap(e+t,n)-e);return(e,a,o)=>{let s=t.axis??`xy`;n[t.part]=s===`xy`?{x:r.x+i(t.x,a.x,o),y:r.y+i(t.y,a.y,o)}:{x:r.x+i(t[s],a[s],o),y:0}}}panelSize(e,t){let{w:n,h:r}=t;return(t,i,a)=>{e.props.width=String(Math.max(40,this.snap(n+i.x,a))),e.props.height=String(Math.max(24,this.snap(r+i.y,a)))}}resize(e){let t=this.L.nodes.get(e),n=t.w,r=t.h;return this.pinAll(),(t,i,a)=>{let o=this.diagram.layout.nodes[e];o.w=Math.max(24,this.snap(n+i.x,a)),o.h=Math.max(16,this.snap(r+i.y,a))}}via(e,t,n){let r=this.L.edges.find(t=>t.key===e);this.pinAll();let i=this.edgeOverride(e);n&&Ph(i,r);let a=i.via=r.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)}));n&&a.splice(t,0,{x:Math.round(n.x),y:Math.round(n.y)});let o={...a[t]};return(e,n,r)=>{a[t]={x:this.snap(o.x+n.x,r),y:this.snap(o.y+n.y,r)}}}port(e,t){let n=this.L.edges.find(t=>t.key===e),r=this.edgeOverride(e),i=t===0?n.decl.from:n.decl.to;return e=>{let n=r.ports?[...r.ports]:[`auto`,`auto`];n[t]=this.nearestSide(i,e),r.ports=n}}label(e){let t=this.edgeOverride(e),n=t.label?{...t.label}:{x:0,y:0};return(e,r)=>{t.label={x:Math.round(n.x+r.x),y:Math.round(n.y+r.y)}}}bend(e,t){let n=this.L.edges.find(t=>t.key===e),r=null,i=0;return(a,o,s)=>{r||(this.pinAll(),r=this.edgeOverride(e),Ph(r,n),r.via=n.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)})),i=zh(n,t),r.via.splice(i,0,{x:Math.round(t.x),y:Math.round(t.y)})),r.via[i]={x:this.snap(t.x+o.x,s),y:this.snap(t.y+o.y,s)}}}group(e){let{diagram:t}=this;this.pinAll();let n=[...t.nodes.values()].filter(n=>st(t,n.group).includes(e)).map(e=>e.id),r=n.map(e=>({...t.layout.nodes[e]})),i=Object.entries(t.layout.edges).filter(([e])=>{let r=t.edges.find(t=>t.key===e);return r&&n.includes(r.from)&&n.includes(r.to)}).map(([e,t])=>({o:t,via:(t.via??[]).map(e=>({...e})),k:e}));return(e,a,o)=>{let s=this.snap(a.x,o),c=this.snap(a.y,o);n.forEach((e,n)=>{t.layout.nodes[e].x=r[n].x+s,t.layout.nodes[e].y=r[n].y+c});for(let e of i)e.o.via=e.via.map(e=>({x:e.x+s,y:e.y+c}))}}};function Ph(e,t){if(t.manualVia||t.decl.from===t.decl.to)return;let[n,r]=e.ports??[`auto`,`auto`];e.ports=[n===`auto`?t.sides[0]:n,r===`auto`?t.sides[1]:r]}function Fh(e,t,n=0){let r=1/0,i=n,a=0;for(let o=1;o<e.length;o++){let s=e[o-1],c=e[o],l=Math.hypot(c.x-s.x,c.y-s.y);if(a+l>=n){let e=l?Math.max(0,Math.min(1,((t.x-s.x)*(c.x-s.x)+(t.y-s.y)*(c.y-s.y))/(l*l))):0,o=Math.hypot(t.x-(s.x+e*(c.x-s.x)),t.y-(s.y+e*(c.y-s.y)));o<r&&(r=o,i=Math.max(n,a+e*l))}a+=l}return i}function Ih(e,t){for(let n=1;n<e.length;n++){let r=e[n-1],i=e[n],a=Math.hypot(i.x-r.x,i.y-r.y);if(t<=a&&a>0)return{x:r.x+(i.x-r.x)*t/a,y:r.y+(i.y-r.y)*t/a};t-=a}return{...e[e.length-1]}}function Lh(e){let t=[0];for(let n of e.via)t.push(Fh(e.samples,n,t[t.length-1]));return t.push(Fh(e.samples,e.end,t[t.length-1])),t}function Rh(e){let t=Lh(e);return t.slice(1).map((n,r)=>Ih(e.samples,(t[r]+n)/2))}function zh(e,t){let n=Lh(e),r=Fh(e.samples,t),i=0;for(;i<n.length-2&&r>n[i+1];)i++;return i}var K=e=>document.querySelector(e),q=K(`#source`),J=K(`#stage`),Bh=K(`#diagnostics`),Vh=K(`#inspector`),Hh=K(`#status`),Uh=K(`#theme`),Wh=K(`#direction`),Gh=K(`#curve`),Kh=K(`#template`),qh=K(`#save`),Jh=K(`#summary`),Yh=K(`#zoom-fit`),Xh=K(`#tabs`),Zh=K(`#insert`),Qh=(e,t)=>t?.altKey?Math.round(e):Math.round(e/12)*12,$h=e=>{Hh.textContent=e,e&&setTimeout(()=>Hh.textContent===e&&(Hh.textContent=``),2e3)};function eg(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function tg(e){let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))}function ng(){return J.querySelector(`svg`)}function rg(e){let t=ng(),n=new DOMPoint(e.clientX,e.clientY).matrixTransform(t.getScreenCTM().inverse());return{x:n.x,y:n.y}}var ig=e=>`M${e.x} ${e.y}h${e.w}v${e.h}h${-e.w}Z`;function ag(e,t,n){let r=e.direction===`right`||e.direction===`left`,[i,a,o,s]=r?[`x`,`w`,`y`,`h`]:[`y`,`h`,`x`,`w`],c=(e,t,n,i)=>r?{x:e,y:n,w:t-e,h:i-n}:{x:n,y:e,w:i-n,h:t-e},l=[...e.nodes.values()].filter(e=>!t.group||e.decl.group===t.group),u=t.group?e.groups.find(e=>e.id===t.group):void 0;if(t.kind===`padding`){if(!t.group){let t=e.bounds,r=n;return[ig(t)+ig({x:t.x+r,y:t.y+r,w:t.w-2*r,h:t.h-2*r})]}let r=[...l,...e.groups.filter(e=>e.decl.parent===t.group)];return u&&r.length?[ig(u)+ig(og(r))]:[]}if(t.kind===`panel-gap`){let t=[...e.nodes.values(),...e.groups];if(!t.length)return[];let n=og(t);return e.panels.flatMap(({box:e})=>{let t=(e,t,n,r)=>[Math.max(e,n),Math.min(t,r)],[r,i]=t(n.y,n.y+n.h,e.y,e.y+e.h),[a,o]=t(n.x,n.x+n.w,e.x,e.x+e.w);return e.x>=n.x+n.w&&i>r?[ig({x:n.x+n.w,y:r,w:e.x-n.x-n.w,h:i-r})]:e.y>=n.y+n.h&&o>a?[ig({x:a,y:n.y+n.h,w:o-a,h:e.y-n.y-n.h})]:[]})}let d=(e,t)=>e[i]<t[i]+t[a]&&t[i]<e[i]+e[a];if(t.kind===`gap`){let e=[],t=[...l].sort((e,t)=>e[o]-t[o]);for(let[n,r]of t.entries()){let l=t.slice(n+1).find(e=>d(r,e)&&e[o]>=r[o]+r[s]);if(l){let t=Math.max(r[i],l[i]),n=Math.min(r[i]+r[a],l[i]+l[a]);e.push(ig(c(t,n,r[o]+r[s],l[o])))}}return e}if(!l.length)return[];let f=l.map(e=>[e[i],e[i]+e[a]]).sort((e,t)=>e[0]-t[0]),p=[];for(let[e,t]of f){let n=p[p.length-1];n&&e<n[1]?n[1]=Math.max(n[1],t):p.push([e,t])}let m=Math.min(...l.map(e=>e[o])),h=Math.max(...l.map(e=>e[o]+e[s]));return p.slice(1).map((e,t)=>ig(c(p[t][1],e[0],m,h)))}function og(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y));return{x:t,y:n,w:Math.max(...e.map(e=>e.x+e.w))-t,h:Math.max(...e.map(e=>e.y+e.h))-n}}var sg=`main.yu`,Y={source:``,diagram:void 0,L:void 0,selection:null,spacing:null,zoom:0,frozen:null,files:{[sg]:``},current:sg,drag:null},cg=new Map,lg=new URLSearchParams(location.search).has(`server`),ug=e=>e?`${e.kind}:${e.id}${e.k?`#${e.k}`:``}`:``,dg=(e,t,n)=>{let r=n.k??0;for(let i of e)if(t(i)===n.id&&!r--)return i},fg=e=>dg(Y.diagram.panels,e=>e.id,e),pg=e=>dg(Y.L.panels,e=>e.decl.id,e),mg={rebuild:hg,commit:hg,commitLayout:hg,deleteSelection:hg,addNodeAt:hg};function hg(){throw Error(`editor: app hooks are not installed yet`)}var gg=`http://www.w3.org/2000/svg`;function _g(e,t){let n=document.createElementNS(gg,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,String(r));return n}var vg=``;matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>vg=``);function yg(e){if(!Y.selection&&!Y.spacing)return;let t=_g(`g`,{class:`overlay`}),n=Y.L.bounds.w/(e.width.baseVal.value||Y.L.bounds.w),r=vg||=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||`#2563eb`;if(Y.spacing){let e=Number(Y.diagram.settings.padding??24),i=Y.spacing.kind===`gap`&&Y.spacing.group?[Y.spacing,{...Y.spacing,kind:`rank-gap`}]:[Y.spacing];for(let a of i.flatMap(t=>ag(Y.L,t,e)))t.append(_g(`path`,{d:a,"fill-rule":`evenodd`,fill:r,"fill-opacity":.22,stroke:r,"stroke-width":n,"stroke-dasharray":`${3*n} ${2*n}`,"pointer-events":`none`}))}if(!Y.selection){e.append(t);return}let i=(e,n,i)=>t.append(_g(`rect`,{x:e.x-n,y:e.y-n,width:e.w+2*n,height:e.h+2*n,rx:i,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),a=(e,i,a,o,s=`circle`)=>{let c={"data-handle":a,"data-i":o,stroke:r,"stroke-width":1.5*n,style:`cursor:move`};s===`square`?t.append(_g(`rect`,{x:e-5*n,y:i-5*n,width:10*n,height:10*n,rx:2*n,fill:`#fff`,...c})):t.append(_g(`circle`,{cx:e,cy:i,r:(s===`ring`?4:5.5)*n,fill:s===`ring`?`#fff`:r,...c}))};if(Y.selection.kind===`node`){let e=Y.L.nodes.get(Y.selection.id);i(e,4,6),a(e.x+e.w+4,e.y+e.h+4,`resize`,0,`square`)}else if(Y.selection.kind===`panel`){let e=pg(Y.selection);i(e.box,3,12),a(e.box.x+e.box.w+3,e.box.y+e.box.h+3,`resize`,0,`square`);let n=t.lastElementChild;n.setAttribute(`style`,`cursor:nwse-resize`);let r=_g(`title`,{});r.textContent=`drag to set the smallest frame size · double-click to reset`,n.append(r),e.handles.forEach((n,r)=>{let i=!!Y.diagram.layout.panels?.[e.decl.id]?.parts?.[n.part];a(n.x,n.y,`part`,r,i?`circle`:`ring`);let o=t.lastElementChild,s=_g(`title`,{});s.textContent=`${n.title??n.part}${i?` · double-click to reset`:``}`,o.append(s),o.setAttribute(`style`,`cursor:${n.axis===`x`?`ew-resize`:n.axis===`y`?`ns-resize`:`move`}`)})}else if(Y.selection.kind===`group`)i(Y.L.groups.find(e=>e.id===Y.selection.id),3,14);else{let e=Y.L.edges.find(e=>e.key===Y.selection.id);t.append(_g(`path`,{d:e.d,fill:`none`,stroke:r,"stroke-width":e.style.width+4,opacity:.25,"pointer-events":`none`}));let n=e=>{let n=_g(`title`,{});n.textContent=e,t.lastElementChild.append(n)};Rh(e).forEach((e,t)=>{a(e.x,e.y,`mid`,t,`ring`),n(`drag to add a bend`)}),e.via.forEach((e,t)=>{a(e.x,e.y,`via`,t),n(`drag to move · right-click or double-click to remove`)}),a(e.start.x,e.start.y,`end`,0,`square`),n(`drag to pick a side · right-click to reset`),a(e.end.x,e.end.y,`end`,1,`square`),n(`drag to pick a side · right-click to reset`)}e.append(t)}var bg=.1,xg=8,Sg=()=>{let e=Y.L.bounds;return Math.min(1.5,Math.max(.2,Math.min((J.clientWidth-48)/e.w,(J.clientHeight-48)/e.h)))};function Cg(e){let t=Y.L.bounds,n=Y.zoom||Sg();Y.frozen?(e.setAttribute(`viewBox`,Y.frozen.viewBox),e.setAttribute(`width`,String(Y.frozen.w)),e.setAttribute(`height`,String(Y.frozen.h))):(e.setAttribute(`width`,String(Math.round(t.w*n))),e.setAttribute(`height`,String(Math.round(t.h*n)))),Yh.textContent=`${Math.round((Y.frozen?Y.frozen.w/t.w:n)*100)}%`,Yh.title=Y.zoom?`Fit to view (⌘0)`:`Fitted to view`}function wg(e,t){let n=ng();if(!n||Y.frozen)return;let r=e?Math.min(xg,Math.max(bg,e)):0;if(r===Y.zoom)return;let i=J.getBoundingClientRect(),a=t?.clientX??i.left+i.width/2,o=t?.clientY??i.top+i.height/2,s=n.getBoundingClientRect(),c=(a-s.left)/s.width,l=(o-s.top)/s.height;if(Y.zoom=r,Cg(n),n.querySelector(`:scope > .overlay`)?.remove(),yg(n),!Y.zoom)return;let u=n.getBoundingClientRect();J.scrollLeft+=u.left+c*u.width-a,J.scrollTop+=u.top+l*u.height-o}function Tg(e){return e.kind===`node`?Y.L.nodes.has(e.id):e.kind===`group`?Y.L.groups.some(t=>t.id===e.id):e.kind===`panel`?!!pg(e):Y.L.edges.some(t=>t.key===e.id)}var Eg=[`sans`,`serif`,`mono`,`Inter`,`Helvetica`,`Arial`,`Verdana`,`Segoe UI`,`Roboto`,`Ubuntu`,`Georgia`,`Times New Roman`,`Palatino`,`Cambria`,`Menlo`,`Consolas`,`Courier New`,`JetBrains Mono`,`Fira Code`],Dg,Og=new Map;globalThis.document?.fonts?.addEventListener(`loadingdone`,()=>Og.clear());function kg(e){if(ce(e)||(Dg??=document.createElement(`canvas`).getContext(`2d`),!Dg))return!0;let t=Og.get(e);if(t!==void 0)return t;let n=Dg,r=e=>(n.font=`72px ${e}`,n.measureText(`mmmwwwiiilllQ@&10`).width),i=JSON.stringify(e),a=[`monospace`,`serif`,`sans-serif`].some(e=>r(`${i}, ${e}`)!==r(e));return Og.set(e,a),a}function Ag(e,t=kg){let n=le(e),r=[];for(let e of n){if(t(e)){let t=e===`system-ui`?`the system font`:`the system ${e.replace(/^ui-/,``)} font`;return{shown:ce(e)?t:e,missing:r}}r.push(e)}return{shown:`the browser default`,missing:r}}function jg(e,t,n=!1,r=``){let i=document.createElement(`label`);i.className=`field ${r}`.trim(),i.classList.toggle(`unset`,n);let a=document.createElement(`span`);return a.textContent=e,i.append(a,t),i}function X(e,t,n,r){let i=document.createElement(`select`);for(let e of t)i.append(new Option(e||`default`,e));return n&&!t.includes(n)&&i.append(new Option(n,n)),i.value=n,i.onchange=()=>r(i.value),jg(e,i,!n)}var Mg=e=>e.replace(/\n/g,`\\n`),Ng=e=>e.replace(/\\n/g,`
659
+ `);function Pg(e,t,n=`text`,r=``){let i=document.createElement(`input`);return i.type=n,i.value=n===`text`?Mg(e):e,i.placeholder=r,i.spellcheck=!1,n===`number`&&(i.step=`any`),i.onchange=()=>t(n===`text`?Ng(i.value.trim()):i.value),i.onkeydown=t=>{t.stopPropagation(),t.key===`Enter`?i.blur():t.key===`Escape`&&(i.value=n===`text`?Mg(e):e,i.blur())},i}function Fg(e){let t=lt(Y.diagram,e,`gap`);return t?`${t.value} from ${t.group}`:`${Y.diagram.settings.gap??`36`} from diagram`}function Ig(e){let t=document.createElement(`p`);return t.className=`scope`,t.textContent=e,t}function Lg(e,t){let n=e=>{Y.spacing=e?t:null;let n=ng();n&&(n.querySelector(`:scope > .overlay`)?.remove(),yg(n))};return e.addEventListener(`mouseenter`,()=>n(!0)),e.addEventListener(`mouseleave`,()=>n(e.contains(document.activeElement))),e.addEventListener(`focusin`,()=>n(!0)),e.addEventListener(`focusout`,()=>n(!1)),e}function Rg(e,t){return n_(t,gr[e]?.replace(/`/g,``))}function zg(e,t,n,r=``){return jg(e,Pg(t,n,`text`,r),!t,`text`)}function Bg(){let e=`font-list`;if(document.getElementById(e))return e;let t=Object.assign(document.createElement(`datalist`),{id:e}),n=()=>{let e=[...document.fonts].flatMap(e=>le(e.family)),n=new Set([...Eg.filter((e,t)=>t<3||kg(e)),...e]);t.replaceChildren(...[...n].map(e=>Object.assign(document.createElement(`option`),{value:e})))};return n(),document.fonts.addEventListener(`loadingdone`,n),document.body.append(t),e}function Vg(e,t,n=!1){let r=zg(`font`,e,t,n?`diagram font`:`theme font`);if(r.querySelector(`input`).setAttribute(`list`,Bg()),n&&!e)return[r];let{shown:i,missing:a}=Ag(e?ue(e).font:_e(Y.diagram.settings.theme,Y.diagram.themes).font),o=document.createElement(`p`);return o.className=`hint`,o.textContent=e&&a.length?`${a.join(`, `)} ${a.length>1?`are`:`is`} not on this computer, so the editor shows ${i}. A viewer without the font sees the next one in the list.`:`Shown as ${i}.`,[r,o]}function Z(e,t,n,r=``){return jg(e,Pg(t,n,`number`,r),!t,`text`)}function Hg(e,t,n){let r=document.createElement(`input`);return r.type=`checkbox`,r.checked=t,r.onchange=()=>n(r.checked),jg(e,r,!t,`toggle`)}var Ug=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function Wg(e,t=400){if(!e)return;let n=e.match(/^([a-z]+)(?:-(\d{2,3}))?$/);return(n&&m(n[1],n[2]?Number(n[2]):t))??(CSS.supports(`color`,e)?e:void 0)}var Gg=e=>!e||!Ug.test(e)?`#888888`:e.length===4?`#${e.slice(1).split(``).map(e=>e+e).join(``)}`:e.toLowerCase();function Kg(e){let t=document.createElement(`i`);return t.className=e?`swatch`:`swatch none`,e&&t.style.setProperty(`--sw`,Wg(e)??`transparent`),t}function qg(e,t){let n=document.createElement(`div`);n.className=`palette`;let r=(n,r)=>{let i=document.createElement(`button`);return i.type=`button`,i.className=`dot${n?``:` none`}${n===e?` on`:``}`,i.title=r,i.setAttribute(`aria-label`,r),n&&i.style.setProperty(`--sw`,Wg(n)??`transparent`),i.onclick=()=>t(n),i};n.append(r(``,`default`),...f.map(e=>r(e,e)));let i=document.createElement(`label`),a=!!e&&!f.includes(e);i.className=`dot custom${a?` on`:``}`,i.title=`custom colour`,a&&i.style.setProperty(`--sw`,Wg(e)??`transparent`);let o=document.createElement(`input`);return o.type=`color`,o.value=Gg(Wg(e,500)),o.onchange=()=>t(o.value),i.append(o),n.append(i),n}function Jg(e,t,n,r=``){let i=document.createElement(`div`);i.className=`color-field`;let a=document.createElement(`div`);a.className=`color-head`;let o=document.createElement(`span`);o.textContent=e;let s=document.createElement(`code`);s.textContent=t||(r?`${r} (class)`:`default`),a.append(o,s);let c=Pg(t,n,`text`,r||`#hex, rgb(), hsl(), tomato`);return c.classList.add(`color-text`),i.append(a,qg(t,n),c),i}function Yg(e,t,n,r=``){let i=document.createElement(`div`);i.className=`field color`,i.classList.toggle(`unset`,!t);let a=document.createElement(`span`);a.textContent=e;let o=document.createElement(`label`);o.className=`dot${t?``:` none`}`,o.style.setProperty(`--sw`,Wg(t,500)??`transparent`),o.title=`pick a colour`;let s=document.createElement(`input`);s.type=`color`,s.value=Gg(Wg(t,500)),s.onchange=()=>n(s.value),o.append(s);let c=Pg(t,n,`text`,r||`none`);return i.append(a,o,c),t&&i.append($g(`×`,()=>n(``),`clear`)),i}function Xg(e){let t=e.kind===`node`?Y.diagram.nodes.get(e.id):e.kind===`group`?Y.diagram.groups.get(e.id):e.kind===`panel`?fg(e):Y.diagram.edges.find(t=>t.key===e.id);return t&&(t.labelRef?!t.labelRef.generated:e.kind===`node`&&!t.ref)?t.label??``:null}function Zg(e,t){t!==Xg(e)&&mg.commit(Cm(Y.source,e,t,Y.diagram))}function Qg(e,t){let n=Xg(e);if(n===null)return;let r=e.kind===`group`||e.kind===`panel`?t.querySelector(`:scope > text`):null,i=(r??t).getBoundingClientRect(),a=Math.max(i.width+24,140),o=document.createElement(`input`);o.className=`label-edit`,o.value=Mg(n),o.spellcheck=!1;let s=r||e.kind!==`group`&&e.kind!==`panel`,c=s?i.top+i.height/2-15:i.top+6,l=s?i.left+i.width/2-a/2:i.left+6;Object.assign(o.style,{top:`${c}px`,left:`${Math.max(4,l)}px`,width:`${a}px`}),document.body.append(o),o.focus(),o.select();let u=!1,d=t=>{u||(u=!0,o.remove(),t&&Zg(e,Ng(o.value)))};o.onkeydown=e=>{e.stopPropagation(),e.key===`Enter`?d(!0):e.key===`Escape`&&d(!1)},o.onblur=()=>d(!0)}function $g(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,n&&(r.className=n),r.onclick=t,r}function e_(e,t,n){return t?$g(e,()=>{n(),mg.commitLayout()}):null}var t_=new Set((()=>{try{return JSON.parse(localStorage.getItem(`yuhwa-folded`)??`[]`)}catch{return[]}})());function Q(e,...t){let n=t.filter(e=>!!e);if(!n.length)return;let r=document.createElement(`section`);r.classList.toggle(`folded`,t_.has(e));let i=document.createElement(`h3`),a=document.createElement(`button`);a.type=`button`,a.textContent=e,a.setAttribute(`aria-expanded`,String(!t_.has(e))),a.onclick=()=>{let t=r.classList.toggle(`folded`);a.setAttribute(`aria-expanded`,String(!t)),t?t_.add(e):t_.delete(e);try{localStorage.setItem(`yuhwa-folded`,JSON.stringify([...t_]))}catch{}},i.append(a);let o=document.createElement(`div`);o.className=`rows`,o.append(...n),r.append(i,o),Vh.append(r)}function n_(e,t){if(!t)return e;let n=document.createElement(`i`);return n.className=`info`,n.tabIndex=0,n.textContent=`i`,n.setAttribute(`aria-label`,t),n.dataset.tip=t,n.onclick=e=>e.preventDefault(),e.querySelector(`:scope > span`)?.append(n),e}function r_(e){let t=document.createElement(`p`);return t.className=`hint`,t.innerHTML=e,t}var i_=null,a_={up:`↑`,down:`↓`,remove:`✕`};function o_(e,t){let n=n=>r=>t({op:`set`,id:e.id,key:n,value:r||null}),r=[qg(e.tone??``,n(`color`))],i=e.values??{},a=Object.entries(e.fields??{}).map(([e,t])=>t.length===2&&t[0]===``&&t[1]===`true`?Hg(e,i[e]===`true`,t=>n(e)(t?`true`:``)):t.length?X(e,t,i[e]??``,n(e)):zg(e,i[e]??``,n(e)));if(a.length){let e=document.createElement(`div`);e.className=`rows`,e.append(...a),r.push(e)}if(e.actions?.length){let n=document.createElement(`div`);n.className=`part-actions`;for(let r of e.actions){let i=document.createElement(`button`);i.type=`button`,i.textContent=r===`add`?`+ ${e.adds??`add`}`:a_[r],i.title=r===`add`?`add to ${e.label}`:`${r} ${e.id}`,i.onclick=()=>t({op:r,id:e.id}),n.append(i)}r.push(n)}return r}function s_(e,t,n){let r=document.createElement(`div`);r.className=`parts`;let i=(t,n=!0)=>{let r=Om(Y.source,e,t,Y.diagram);if(r.source===Y.source)return $h(`this part cannot be changed here`);i_=n&&r.id?`${e}:${r.id}`:null,mg.commit(r.source)},a=``;for(let n of t){if(n.kind!==a){a=n.kind;let e=document.createElement(`div`);e.className=`parts-kind`,e.textContent=a,r.append(e)}let t=`${e}:${n.id}`,o=document.createElement(`div`);o.className=`part`,n.depth&&(o.style.marginLeft=`${Math.min(n.depth,8)*12}px`);let s=document.createElement(`button`);s.type=`button`,s.title=`edit ${n.id}`;let c=document.createElement(`span`);c.textContent=n.label;let l=document.createElement(`code`);l.textContent=n.tone??``,s.append(Kg(n.tone??``),c,l);let u=e=>{o.classList.toggle(`open`,e),o.replaceChildren(s,...e?o_(n,i):[])};s.onclick=()=>{let e=i_!==t;r.querySelector(`.part.open`)?.dispatchEvent(new Event(`close`)),i_=e?t:null,u(e)},o.addEventListener(`close`,()=>u(!1)),u(i_===t),r.append(o)}if(n){let e=document.createElement(`button`);e.type=`button`,e.className=`part-add`,e.textContent=`+ ${n}`,e.onclick=()=>i({op:`add`}),r.append(e)}return r}var c_=[``,...Kn.style],l_=[``,...hr.curve],u_=`Click a box, edge, group or panel to style it · double-click to edit its text · drag to move · drag an edge to bend it · drag a panel's dots to adjust it · double-click a bend or dot to reset it · <kbd>alt</kbd> no snapping · <kbd>←</kbd><kbd>→</kbd> nudge`;function d_(){let e=Y.diagram.settings,t=e=>t=>mg.commit(Dm(Y.source,e,t||null)),n=e.direction===`down`||e.direction===`up`,r=document.createElement(`div`);r.className=`title`,r.innerHTML=`<small>diagram</small>settings`,Vh.append(r,Ig(`Whole diagram. Groups, nodes and edges can override some of these with their own props.`)),Q(`Text`,zg(`title`,e.title??``,t(`title`)),zg(`subtitle`,e.subtitle??``,t(`subtitle`)),...Vg(e.font??``,t(`font`)),Z(`font size`,e[`font-size`]??``,t(`font-size`),`14`)),Q(`Style`,X(`theme`,[``,...ge(Y.diagram.themes)],e.theme??``,t(`theme`)),Yg(`accent`,e.accent??``,t(`accent`),`theme`),Yg(`background`,e.background??``,t(`background`),`theme`),Z(`radius`,e.radius??``,t(`radius`),`theme`),Z(`stroke`,e[`stroke-width`]??``,t(`stroke-width`),`theme`),Yg(`edge color`,e[`edge-color`]??``,t(`edge-color`),`theme`),Z(`edge width`,e[`edge-width`]??``,t(`edge-width`),`theme`),Hg(`shadow`,!!e.shadow&&e.shadow!==`false`,e=>t(`shadow`)(e?`true`:``)),X(`shape`,[``,...Tn],e.shape??``,t(`shape`))),Q(`Layout`,X(`direction`,[``,...hr.direction],e.direction??``,t(`direction`)),X(`curve`,l_,e.curve??``,t(`curve`)),X(`merge`,[``,...hr.merge],e.merge??``,t(`merge`)),Lg(Rg(`gap`,Z(`node gap`,e.gap??``,t(`gap`),`36`)),{kind:`gap`}),Lg(Rg(`rank-gap`,Z(n?`row gap`:`column gap`,e[`rank-gap`]??``,t(`rank-gap`),`auto`)),{kind:`rank-gap`}),Lg(Rg(`padding`,Z(`padding`,e.padding??``,t(`padding`),`24`)),{kind:`padding`}),Rg(`wrap`,Z(`wrap`,e.wrap??``,t(`wrap`),`off`)),Rg(`panels`,X(`panels`,[``,...hr.panels],e.panels??``,t(`panels`))),Lg(Rg(`panel-gap`,Z(`panel gap`,e[`panel-gap`]??``,t(`panel-gap`),`48`)),{kind:`panel-gap`}),Hg(`grid`,!!e.grid&&e.grid!==`false`,e=>t(`grid`)(e?`true`:``))),Vh.append(r_(u_))}function f_(){if(Vh.innerHTML=``,!Y.selection)return d_();let e=Y.selection,t=document.createElement(`div`);t.className=`title`;let n=document.createElement(`small`);n.textContent=e.kind;let r=document.createElement(`span`);r.textContent=e.id;let i=$g(`Delete`,mg.deleteSelection,`delete`);i.title=`delete this ${e.kind} (Delete)`;let a=$g(`×`,()=>{Y.selection=null,mg.rebuild(!1)},`clear`);a.title=`deselect (Esc)`,t.append(n,r,i,a),Vh.append(t,Ig(`Only this ${e.kind}. Empty fields fall back to its classes, then the diagram settings.`));let o={kind:e.kind,id:e.id},s=e=>t=>mg.commit(Tm(Y.source,o,e,t||null)),c=(e,t)=>Hg(e,!!t[e]&&t[e]!==`false`,t=>s(e)(t?`true`:``)),l=(e,t=`auto`,n={})=>[Yg(`text`,e.text??e[`label-color`]??``,s(`text`),n.text),...Vg(e.font??``,s(`font`),!0),Z(`font size`,e[`font-size`]??``,s(`font-size`),n[`font-size`]??t),Z(`font weight`,e[`font-weight`]??``,s(`font-weight`),n[`font-weight`]??`auto`),c(`italic`,e)],u=(e,t,n)=>{let r=(e.align??``).trim().split(/\s+/).filter(Boolean),i=xt.includes(r[0])?r[0]:``,a=r.slice(+!!i).join(` `),o=(e,t)=>s(`align`)([e,t.trim()].filter(Boolean).join(` `));return[X(`merge`,[``,...Kn.merge],e.merge??``,s(`merge`)),X(n&&!a?`align members`:`align`,[``,...xt],i,e=>o(e,a)),zg(`align with`,a,e=>o(i,e),t.align??(n?`id, or empty for the members`:`id`))]},d=Xg(o),f=d!==null&&zg(e.kind===`panel`?`title`:`label`,d,e=>Zg(o,e));if(e.kind===`panel`){let t=fg(e),r=V.panels.get(t.kind);n.textContent=t.kind;let i=r?.options??{},a=!!t.ref&&!t.ref.generated;Q(`Text`,f,...a?l(t.props,`theme`):[]),a&&(Q(`Options`,...Object.entries(i).map(([e,n])=>{let i=Sr(n),a=t.props[e]??``;return n_((()=>{switch(i.kind){case`select`:return X(e,[``,...i.values],a,s(e));case`flag`:return c(e,t.props);case`color`:return Yg(e,a,s(e),`default`);case`number`:return Z(e,a,s(e));case`text`:return zg(e,a,s(e));default:return i}})(),r?.help?.[e])})),Q(`Size`,n_(Z(`width`,t.props.width??``,s(`width`),`auto`),Gn.width),n_(Z(`height`,t.props.height??``,s(`height`),`auto`),Gn.height),r_(`Or drag the square at the frame’s corner on the canvas.`)),Q(`Style`,Jg(`color`,t.props.color??``,s(`color`)),X(`theme`,[``,...ge(Y.diagram.themes)],t.props.theme??``,s(`theme`)),Yg(`background`,t.props.background??t.props.fill??``,s(`background`),`theme`),Yg(`border`,t.props.border??t.props.stroke??``,s(`border`),`theme`),X(`border style`,c_,tt(t.props)??``,s(`border-style`)),Z(`border width`,t.props[`border-width`]??``,s(`border-width`),`1`),Yg(`edge color`,t.props[`edge-color`]??``,s(`edge-color`),`theme`),Z(`edge width`,t.props[`edge-width`]??``,s(`edge-width`),`theme`),Z(`radius`,t.props.radius??``,s(`radius`),`10`),c(`shadow`,t.props),Hg(`frame`,t.props.frame!==`false`,e=>s(`frame`)(e?``:`false`))));let o=!t.failed&&r?.parts?.(t.data)||[],u=a&&!!r?.editPart&&!!t.lines&&t.lines[1]-t.lines[0]-1===t.body.length;o.length&&Q(`Parts`,u?s_(e.id,o,r?.adds):r_(`Write the panel body on its own lines to colour its parts here.`));let d=Y.diagram.layout.panels?.[e.id];Q(`Layout`,e_(`Unpin`,d?.at,()=>delete d.at),e_(`Reset layout`,d?.parts,()=>delete d.parts))}else if(e.kind===`node`){let n=Y.diagram.nodes.get(e.id),r=Object.assign({},...n.classes.map(e=>Y.diagram.classes[e]??{})),i=e=>n.props[e]??``;Q(`Text`,f,zg(`sub`,i(`sub`),s(`sub`),r.sub),...l(n.props,`auto`,r),c(`bold`,n.props),c(`mono`,n.props),Z(`body size`,i(`body-size`),s(`body-size`),r[`body-size`]??`auto`),Yg(`body colour`,i(`body-color`),s(`body-color`),r[`body-color`]??`from text`),zg(`icon`,i(`icon`),s(`icon`),r.icon),zg(`link`,i(`link`),s(`link`),r.link),zg(`tooltip`,i(`tooltip`),s(`tooltip`),r.tooltip)),Q(`Colour`,Jg(`color`,i(`color`),s(`color`),r.color),Yg(`fill`,i(`fill`),s(`fill`),r.fill??`from color`),Yg(`stroke`,i(`stroke`),s(`stroke`),r.stroke??`from color`)),Q(`Shape`,X(`shape`,[``,...Tn],i(`shape`),s(`shape`)),X(`border`,c_,tt(n.props)??``,s(`border-style`)),Z(`border width`,i(`stroke-width`),s(`stroke-width`),r[`stroke-width`]??`theme`),Z(`radius`,i(`radius`),s(`radius`),r.radius??`theme`),Z(`opacity`,i(`opacity`),s(`opacity`),`1`),c(`shadow`,n.props));let a=[...Y.diagram.nodes.keys()].filter(t=>t!==e.id);Q(`Connect`,$g(`+ Connected node`,()=>mg.addNodeAt({from:e.id,group:n.group})),a.length>0&&X(`connect to`,[``,...a],``,t=>t&&mg.commit(Nm(Y.source,{from:e.id,to:t},Y.diagram)))),Q(`Size`,Z(`width`,i(`width`),s(`width`),`auto`),Z(`height`,i(`height`),s(`height`),`auto`),Z(`max width`,i(`max-width`),s(`max-width`),`auto`)),Q(`Layout`,...u(n.props,r,!1),e_(`Unpin`,Y.diagram.layout.nodes[e.id],()=>delete Y.diagram.layout.nodes[e.id])),r.shape&&!n.props.shape&&(t.title=`shape ${r.shape} from class`)}else if(e.kind===`edge`){let t=Y.diagram.edges.find(t=>t.key===e.id),n=e=>t.props[e]??``,r=[``,`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],i=[``,`top`,`right`,`bottom`,`left`,`auto`];Q(`Text`,f,...l(t.props),Yg(`label bg`,n(`label-bg`),s(`label-bg`))),Q(`Line`,Jg(`color`,n(`color`),s(`color`)),Yg(`stroke`,n(`stroke`),s(`stroke`),`from color`),X(`style`,c_,tt(t.props,`style`)??``,s(`style`)),Z(`width`,n(`width`),s(`width`),`theme`),Z(`opacity`,n(`opacity`),s(`opacity`),`1`),c(`flow`,t.props),c(`animate`,t.props)),Q(`Ends`,X(`head`,r,n(`head`),s(`head`)),X(`tail`,r,n(`tail`),s(`tail`)),X(`exit`,i,n(`exit`),s(`exit`)),X(`enter`,i,n(`enter`),s(`enter`))),Q(`Route`,X(`curve`,l_,n(`curve`),s(`curve`)),c(`constraint`,t.props),X(`merge`,[``,...Kn.merge],n(`merge`),s(`merge`)),e_(`Reset route`,Y.diagram.layout.edges[e.id],()=>delete Y.diagram.layout.edges[e.id])),t.ref&&Y.diagram.edges.filter(e=>e.ref===t.ref).length>1&&Vh.append(r_(`Style applies to every edge on this line.`))}else{let t=Y.diagram.groups.get(e.id),n=e=>t.props[e]??``;Q(`Text`,f,...l(t.props),c(`caps`,t.props)),Q(`Colour`,Jg(`color`,n(`color`),s(`color`)),Yg(`fill`,n(`fill`),s(`fill`),`from color`),Yg(`stroke`,n(`stroke`),s(`stroke`),`from color`),X(`border`,c_,tt(t.props)??``,s(`border-style`))),Q(`Content`,$g(`+ Node inside`,()=>mg.addNodeAt({group:e.id}))),Q(`Layout`,...u(t.props,{},!0),Lg(n_(Z(`gap`,n(`gap`),s(`gap`),Fg(t.parent)),`Space between this group's members and between its ranks, px. Only this group. Empty: the parent group's gap, else the diagram's node gap.`),{kind:`gap`,group:e.id}),Lg(n_(zg(`padding`,n(`padding`),s(`padding`),`18, or y x, or top right bottom left`),`Space inside this group's border, px, like CSS: all, y x, top x bottom, or top right bottom left. Only this group.`),{kind:`padding`,group:e.id}))}}Object.assign(mg,{rebuild:$,commit:k_,commitLayout:A_,deleteSelection:j_,addNodeAt:M_});var p_=`title: Hello yuhwa
660
660
  direction: right
661
661
 
662
662
  .svc [blue]
@@ -675,15 +675,15 @@ api -> db: SQL
675
675
 
676
676
  // Drag boxes, edges and labels in the preview.
677
677
  // Positions are written to the layout block below.
678
- `,d_=[],f_=[];function $(e=!0){e&&(Y.diagram=Kl(Y.source,{file:Y.current,resolve:e=>e===Y.current?Y.source:Y.files[e]})),Y.L=Vu(Y.diagram,{measureFor:e=>Rr(e.font)});let t=qu(Y.diagram,Y.L,{interactive:!0,idPrefix:`ed`,snapGrid:12});J.innerHTML=t;let n=!Y.diagram.nodes.size&&!Y.diagram.panels.length&&!Y.diagram.settings.title;if(J.classList.toggle(`is-empty`,n),n){let e=document.createElement(`p`);e.className=`empty-hint`,e.textContent=Object.keys(Y.diagram.classes).length?`Nothing to draw yet: this file only defines classes. Import it from another file, or add a node.`:`Nothing to draw yet. Type a line like a -> b or pick something from Add. Double-click the canvas for a new node.`,J.append(e)}let r=$h();bg(r),Y.selection&&!Sg(Y.selection)&&(Y.selection=null),gg(r),e&&(oh(t),o1.sync(),S_(),C_());let i=sg(Y.selection);if(e||i!==p_){let e=v_(Y.selection);o1.mark(e,i!==p_);let t=h_(e);i===p_&&t&&t===m_||l_(),p_=i,m_=t}}var p_=``,m_=``;function h_(e){return!Y.selection||!e?``:[Y.source.split(`
678
+ `,m_=[],h_=[];function $(e=!0){e&&(Y.diagram=Yl(Y.source,{file:Y.current,resolve:e=>e===Y.current?Y.source:Y.files[e]})),Y.L=Wu(Y.diagram,{measureFor:e=>Vr(e.font)});let t=Xu(Y.diagram,Y.L,{interactive:!0,idPrefix:`ed`,snapGrid:12});J.innerHTML=t;let n=!Y.diagram.nodes.size&&!Y.diagram.panels.length&&!Y.diagram.settings.title;if(J.classList.toggle(`is-empty`,n),n){let e=document.createElement(`p`);e.className=`empty-hint`,e.textContent=Object.keys(Y.diagram.classes).length?`Nothing to draw yet: this file only defines classes. Import it from another file, or add a node.`:`Nothing to draw yet. Type a line like a -> b or pick something from Add. Double-click the canvas for a new node.`,J.append(e)}let r=ng();Cg(r),Y.selection&&!Tg(Y.selection)&&(Y.selection=null),yg(r),e&&(lh(t),l1.sync(),T_(),E_());let i=ug(Y.selection);if(e||i!==g_){let e=x_(Y.selection);l1.mark(e,i!==g_);let t=v_(e);i===g_&&t&&t===__||f_(),g_=i,__=t}}var g_=``,__=``;function v_(e){return!Y.selection||!e?``:[Y.source.split(`
679
679
  `).slice(e[0],e[1]+1).join(`
680
680
  `),JSON.stringify(Y.diagram.layout),Object.keys(Y.diagram.classes).join()].join(`
681
- \0`)}function g_(e,t){return[...$h()?.querySelectorAll(`[data-panel="${CSS.escape(t)}"]`)??[]].indexOf(e)}function __(e){let t=Y.source.split(`
682
- `),n=0;for(let r=e;r<t.length;r++){for(let e of t[r].replace(/"[^"]*"/g,``))if(e===`{`)n++;else if(e===`}`&&--n===0)return r;if(!n)return e}return e}function v_(e){if(!e)return null;if(e.kind===`node`){let t=Y.diagram.nodes.get(e.id);if(!t)return null;if(!t.ref||t.implicit){let t=Y.diagram.edges.find(t=>(t.from===e.id||t.to===e.id)&&t.ref)?.ref.line;return t===void 0?null:[t,t]}let n=Math.max(t.ref.line,t.bodyLines?.[1]??0,...Object.values(t.ref.propLines??{}));return[t.ref.line,n]}if(e.kind===`edge`){let t=Y.diagram.edges.find(t=>t.key===e.id)?.ref?.line;return t===void 0?null:[t,t]}if(e.kind===`group`){let t=Y.diagram.groups.get(e.id)?.ref?.line;return t===void 0?null:[t,__(t)]}return lg(e)?.lines??null}function y_(e){let t=null,n=1/0,r=r=>{let i=v_(r);i&&e>=i[0]&&e<=i[1]&&i[1]-i[0]<n&&(t=r,n=i[1]-i[0])};for(let e of Y.diagram.nodes.values())e.implicit||r({kind:`node`,id:e.id});for(let e of Y.diagram.edges)r({kind:`edge`,id:e.key});for(let e of Y.diagram.groups.keys())r({kind:`group`,id:e});let i=new Map;for(let e of Y.diagram.panels){let t=i.get(e.id)??0;i.set(e.id,t+1),r({kind:`panel`,id:e.id,k:t})}return t&&Sg(t)?t:null}function b_(e){let t={node:`data-node`,edge:`data-edge`,group:`data-group`,panel:`data-panel`}[e.kind],n=$h()?.querySelectorAll(`[${t}="${CSS.escape(e.id)}"]`)[e.k??0];if(!n)return;let r=n.getBoundingClientRect(),i=J.getBoundingClientRect();r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom||J.scrollBy({left:r.left+r.width/2-(i.left+i.width/2),top:r.top+r.height/2-(i.top+i.height/2),behavior:`smooth`})}function x_(){if(q.value!==Y.source)return;let e=y_(Y.source.slice(0,q.selectionStart).split(`
683
- `).length-1);sg(e)!==sg(Y.selection)&&(Y.selection=e,$(!1),e&&b_(e))}function S_(){Lh.innerHTML=``;let e=o1.diagnostics(Y.current),t=e.filter(e=>e.severity===1).length,n=e.length-t,r=(e,t)=>`${e} ${t}${e===1?``:`s`}`;if(Gh.textContent=`${r(Y.diagram.nodes.size,`node`)} · ${r(Y.diagram.edges.length,`edge`)}`,t||n){let e=document.createElement(`span`);e.className=`bad`,e.textContent=` · ${t?r(t,`error`):r(n,`warning`)}`,Gh.append(e)}for(let t of e){let e=document.createElement(`div`);e.className=t.severity===1?`error`:`warning`;let n=typeof t.message==`string`?t.message:t.message.value;e.textContent=`${t.range.start.line+1}: ${n}`,e.onclick=()=>o1.reveal(t.range);let r=n.match(/did you mean "([^"\n]+)"/);if(r){let n=document.createElement(`button`);n.className=`fix`,n.textContent=`use ${r[1]}`,n.onclick=e=>{e.stopPropagation(),o1.fix(t)},e.append(n)}Lh.append(e)}}function C_(){let e=ge(Y.diagram.themes);[...Bh.options].map(e=>e.value).join()!==e.join()&&Bh.replaceChildren(...e.map(e=>new Option(e,e))),Bh.value=e.includes(Y.diagram.settings.theme)?Y.diagram.settings.theme:`paper`,Vh.value=Y.diagram.settings.direction||`right`,Hh.value=Y.diagram.settings.curve||`smooth`}function w_(e){d_[d_.length-1]!==e&&d_.push(e),d_.length>200&&d_.shift(),f_.length=0}function T_(e,t=!0){if(e===Y.source)return;e1.end(),t&&w_(Y.source),Y.source=e;let n=q.scrollTop;q.value=e,q.scrollTop=n,j_()}function E_(e){T_(e),$(!0)}function D_(){E_(mm(Y.source,Y.diagram.layout,Y.diagram))}function O_(){if(!Y.selection)return;let{kind:e,id:t}=Y.selection,n=Pm(Y.source,{kind:e,id:t},Y.diagram);if(n===Y.source)return Xh(`this ${e} cannot be deleted here, edit the source`);Y.selection=null,E_(n),Xh(`${e} ${t} deleted`)}function k_(e,t){let n=h1(`node`),r=jm(Y.source,{id:n,label:`New node`,...e},Y.diagram);if(r===Y.source)return Xh(`cannot add a node here`);if(Y.selection={kind:`node`,id:n},E_(r),t&&Y.L.nodes.has(n)){let{o:e,w:r,h:i}=P_().pinned(n,!0);e.x=Math.round(Yh(t.x)-r/2),e.y=Math.round(Yh(t.y)-i/2),T_(mm(Y.source,Y.diagram.layout,Y.diagram),!1),$(!0)}let i=J.querySelector(`[data-node="${CSS.escape(n)}"]`);i&&Yg({kind:`node`,id:n},i)}var A_=0;function j_(){if(Y.files[Y.current]=Y.source,og)M_.changed(),clearTimeout(A_),A_=window.setTimeout(N_,500);else try{localStorage.setItem(`yuhwa-files`,JSON.stringify({files:Y.files,current:Y.current}))}catch{}}var M_=new uh(async()=>{let e=await fetch(`/api/source`,{method:`PUT`,body:JSON.stringify({files:Y.files})});if(!e.ok)throw Error(`save failed`);let{written:t=[]}=await e.json();return t.length?`saved ${t.join(`, `)}`:`saved`},Xh);function N_(){if(og)return clearTimeout(A_),M_.save()}var P_=()=>new Ah(Y.diagram,Y.L,Yh),F_=null,I_=!1,L_=new Map,R_=null;function z_(e,t){F_={x:e.clientX,y:e.clientY,left:J.scrollLeft,top:J.scrollTop,moved:!1,clear:t},J.setPointerCapture(e.pointerId),J.classList.add(`panning`),e.preventDefault()}var B_=()=>{let[e,t]=[...L_.values()];return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,d:Math.hypot(e.x-t.x,e.y-t.y)}};J.addEventListener(`wheel`,e=>{if(!(e.ctrlKey||e.metaKey)||Y.drag||!$h())return;e.preventDefault();let t=e.deltaMode===1?e.deltaY*16:e.deltaY;xg(Q_()*Math.min(2,Math.max(.5,Math.exp(-t*.01))),e)},{passive:!1}),J.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||(L_.set(e.pointerId,{x:e.clientX,y:e.clientY}),L_.size!==2))return;W_(),F_=null;let t=B_();R_={d:t.d,z:Q_(),mid:t},e.stopImmediatePropagation()},{capture:!0}),J.addEventListener(`pointermove`,e=>{if(!L_.has(e.pointerId)||(L_.set(e.pointerId,{x:e.clientX,y:e.clientY}),!R_||L_.size!==2))return;let t=B_();xg(R_.z*t.d/Math.max(1,R_.d),{clientX:t.x,clientY:t.y}),J.scrollLeft-=t.x-R_.mid.x,J.scrollTop-=t.y-R_.mid.y,R_.mid=t,e.stopImmediatePropagation()},{capture:!0});var V_=e=>{L_.delete(e.pointerId),L_.size<2&&(R_=null)};J.addEventListener(`pointerup`,V_,{capture:!0}),J.addEventListener(`pointercancel`,V_,{capture:!0}),J.addEventListener(`pointerdown`,e=>{if(!$h()||R_)return;if(e.button===1||e.button===0&&I_)return z_(e,!1);if(e.button!==0)return;let t=e.target.closest(`[data-handle],[data-node],[data-edge-label],[data-edge],[data-group],[data-panel]`);if(!t)return z_(e,!0);let n=eg(e),r=$h();Y.frozen={viewBox:r.getAttribute(`viewBox`),w:r.width.baseVal.value,h:r.height.baseVal.value};let i=D_,a=()=>{},o=P_();if(t.hasAttribute(`data-handle`)){let e=t.getAttribute(`data-handle`),r=Number(t.getAttribute(`data-i`));if(Y.selection?.kind===`panel`&&e===`part`){let e=Y.selection.id,t=ug(Y.selection).handles[r];i=()=>E_(Em(Y.source,Y.diagram,e,t)),a=o.part(e,t)}else if(Y.selection?.kind===`panel`&&e===`resize`){let e={kind:`panel`,id:Y.selection.id},t=lg(Y.selection);a=o.panelSize(t,ug(Y.selection).box),i=()=>{let{width:n,height:r}=t.props;E_(Sm(Sm(Y.source,e,`width`,n),e,`height`,r))}}else Y.selection?.kind===`node`&&e===`resize`?a=o.resize(Y.selection.id):Y.selection?.kind===`edge`&&(e===`via`||e===`mid`?a=o.via(Y.selection.id,r,e===`mid`?n:null):e===`end`&&(a=o.port(Y.selection.id,r===0?0:1)))}else if(t.hasAttribute(`data-node`)){let e=t.getAttribute(`data-node`);Y.selection={kind:`node`,id:e},a=o.centre(e,!0)}else if(t.hasAttribute(`data-edge-label`)){let e=t.getAttribute(`data-edge-label`);Y.selection={kind:`edge`,id:e},a=o.label(e)}else if(t.hasAttribute(`data-edge`)){let e=t.getAttribute(`data-edge`);Y.selection={kind:`edge`,id:e},a=o.bend(e,n)}else if(t.hasAttribute(`data-panel`)){let e=t.getAttribute(`data-panel`);Y.selection={kind:`panel`,id:e,k:g_(t,e)},a=o.centre(e,!1)}else if(t.hasAttribute(`data-group`)){let e=t.getAttribute(`data-group`);Y.selection={kind:`group`,id:e},a=o.group(e)}Y.drag={move:a,finish:i,moved:!1,start:n},J.setPointerCapture(e.pointerId),$(!1),e.preventDefault()}),J.addEventListener(`pointermove`,e=>{if(F_){let t=e.clientX-F_.x,n=e.clientY-F_.y;if(!F_.moved&&Math.hypot(t,n)<3)return;F_.moved=!0,J.scrollLeft=F_.left-t,J.scrollTop=F_.top-n;return}if(!Y.drag)return;let t=eg(e),n={x:t.x-Y.drag.start.x,y:t.y-Y.drag.start.y};!Y.drag.moved&&Math.hypot(n.x,n.y)<3||(Y.drag.moved=!0,J.classList.add(`dragging`),Y.drag.move(t,n,e),H_||=requestAnimationFrame(()=>{H_=0,$(!1)}))});var H_=0;function U_(){if(F_){let{moved:e,clear:t}=F_;F_=null,J.classList.remove(`panning`),!e&&t&&Y.selection&&(Y.selection=null,$(!1))}else W_()}function W_(){if(!Y.drag)return;let{moved:e,finish:t}=Y.drag;Y.drag=null,Y.frozen=null,J.classList.remove(`dragging`),e?t():$()}J.addEventListener(`pointerup`,U_),J.addEventListener(`pointercancel`,U_);function G_(e,t){let n=Y.diagram.layout.edges[e],r=Number(t.getAttribute(`data-i`));if(!n)return!1;if(t.getAttribute(`data-handle`)===`via`&&n.via)n.via.splice(r,1),n.via.length||delete n.via;else if(t.getAttribute(`data-handle`)===`end`&&n.ports)n.ports[r]=`auto`;else return!1;return D_(),!0}J.addEventListener(`contextmenu`,e=>{let t=e.target,n=t.closest(`[data-handle]`);if(Y.selection?.kind===`edge`&&n){G_(Y.selection.id,n)&&e.preventDefault();return}let r=t.closest(`[data-edge]`)?.getAttribute(`data-edge`),i=r?Y.diagram.layout.edges[r]:void 0;r&&i?.via&&(e.preventDefault(),delete i.via,Y.selection={kind:`edge`,id:r},D_())}),J.addEventListener(`dblclick`,e=>{let t=e.target,n=t.closest(`[data-handle]`),r=t.closest(`[data-edge-label]`);if(Y.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`part`){let e=Y.selection.id,t=ug(Y.selection)?.handles[Number(n.getAttribute(`data-i`))]?.part,r=Y.diagram.layout.panels?.[e];if(!t||!r?.parts?.[t])return;delete r.parts[t],Object.keys(r.parts).length||delete r.parts,D_()}else if(Y.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`resize`){let e={kind:`panel`,id:Y.selection.id};E_(Sm(Sm(Y.source,e,`width`,null),e,`height`,null))}else if(Y.selection?.kind===`edge`&&n)G_(Y.selection.id,n);else if(!n){let n=r??t.closest(`[data-node],[data-edge],[data-group],[data-panel]`);if(!n)return k_({},eg(e));let[i,a]=r?[`edge`,r.getAttribute(`data-edge-label`)]:[`node`,`edge`,`group`,`panel`].map(e=>[e,n.getAttribute(`data-${e}`)]).find(([,e])=>e!==null),o=i===`edge`&&!r?J.querySelector(`[data-edge-label="${CSS.escape(a)}"]`)??n:n;Yg({kind:i,id:a},o)}}),document.addEventListener(`keydown`,e=>{let t=e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLInputElement,n=e.metaKey||e.ctrlKey;if(n&&e.key.toLowerCase()===`s`){e.preventDefault(),N_();return}if(t)return;if(e.key===` `&&!e.repeat){I_=!0,J.classList.add(`can-pan`),e.preventDefault();return}let r=n&&{"=":1.25,"+":1.25,"-":.8,_:.8,0:0,1:-1}[e.key];if(r!==void 0&&r!==!1){e.preventDefault(),xg(r===-1?1:r&&Q_()*r);return}if(n&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?q_():K_();return}if(e.key===`Escape`){Y.selection=null,$(!1);return}if((e.key===`Delete`||e.key===`Backspace`)&&Y.selection){e.preventDefault(),O_();return}let i={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};if(i[e.key]&&(Y.selection?.kind===`node`||Y.selection?.kind===`panel`)){e.preventDefault();let t=e.shiftKey?12:1,{o:n}=P_().pinned(Y.selection.id,Y.selection.kind===`node`);n.x+=i[e.key].x*t,n.y+=i[e.key].y*t,D_()}});function K_(){let e=d_.pop();e!==void 0&&(f_.push(Y.source),T_(e,!1),$(!0))}function q_(){let e=f_.pop();e!==void 0&&(d_.push(Y.source),T_(e,!1),$(!0))}Bh.replaceChildren(...C.map(e=>new Option(e,e)));for(let[e,t]of[[Vh,`direction`],[Hh,`curve`]])e.replaceChildren(...fr[t].map(e=>new Option(e,e)));for(let e of dh)Uh.append(new Option(e.name,e.name));Uh.onchange=()=>{let e=dh.find(e=>e.name===Uh.value);if(Uh.value=``,e){if(e.files){if(og)return Xh(`multi-file templates need the browser editor`);if(Y.files[Y.current]=Y.source,Object.values(Y.files).some(e=>e.trim()&&e!==u_)&&!confirm(`Replace all files with "${e.name}"?`))return;O1({files:{[ig]:e.source,...e.files},current:ig}),q.value=Y.source,j_(),p1(),$(!0)}else E_(e.source)}},Bh.onchange=()=>E_(wm(Y.source,`theme`,Bh.value===`paper`&&!/^\s*import\b/m.test(Y.source)?null:Bh.value)),Vh.onchange=()=>{Y.diagram.layout.nodes={},Y.diagram.layout.edges={};for(let e of Object.values(Y.diagram.layout.panels??{}))delete e.at;E_(wm(mm(Y.source,Y.diagram.layout,Y.diagram),`direction`,Vh.value))},Hh.onchange=()=>E_(wm(Y.source,`curve`,Hh.value===`smooth`?null:Hh.value)),K(`#undo`).onclick=K_,K(`#redo`).onclick=q_,K(`#reset`).onclick=()=>{Y.diagram.layout={nodes:{},edges:{}},D_()};function J_(){return qu(Y.diagram,Vu(Y.diagram,{measureFor:e=>Rr(e.font)}),{idPrefix:`yuhwa`})}async function Y_(e,t){try{await navigator.clipboard.writeText(e),Xh(`${t} copied`)}catch{Xh(`clipboard blocked`)}}K(`#copy-svg`).onclick=()=>Y_(J_(),`SVG`),K(`#copy-md`).onclick=()=>Y_("```yuhwa\n"+Y.source.replace(/\s*$/,``)+"\n```\n",`Markdown`);function X_(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=(Y.diagram.settings.title||`diagram`).toLowerCase().replace(/[^\w]+/g,`-`)+t,n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}document.fonts?.addEventListener(`loadingdone`,()=>{$(!1),Y.selection||l_()}),K(`#download`).onclick=()=>X_(new Blob([J_()],{type:`image/svg+xml`}),`.svg`),K(`#download-png`).onclick=async()=>{try{(await sh(J_(),{scale:2})).toBlob(e=>e?X_(e,`.png`):Xh(`PNG export failed`),`image/png`)}catch{Xh(`PNG export failed`)}};var Z_=K(`#export`);Z_.querySelector(`.menu-list`).addEventListener(`click`,e=>{e.target.closest(`button`)&&(Z_.open=!1)}),document.addEventListener(`pointerdown`,e=>{Z_.open&&!Z_.contains(e.target)&&(Z_.open=!1)}),Z_.addEventListener(`keydown`,e=>{e.key===`Escape`&&(Z_.open=!1,Z_.querySelector(`summary`).focus())}),K(`#share`).onclick=()=>{let e=Object.keys(Y.files).length>1,t=`${location.origin}${location.pathname}#${e?`files=${Zh(JSON.stringify({files:Y.files,current:Y.current}))}`:`src=${Zh(Y.source)}`}`;history.replaceState(null,``,t),Y_(t,`link`)},K(`#zoom-in`).onclick=()=>xg(Q_()*1.25),K(`#zoom-out`).onclick=()=>xg(Q_()/1.25),K(`#zoom-fit`).onclick=()=>xg(+!Y.zoom);function Q_(){let e=$h();return e?e.width.baseVal.value/Y.L.bounds.w:1}Wh.hidden=!og,Wh.onclick=()=>void N_(),window.addEventListener(`beforeunload`,e=>{og&&M_.dirty&&e.preventDefault()}),window.addEventListener(`resize`,()=>Y.zoom||$(!1));var $_=()=>{I_=!1,J.classList.remove(`can-pan`)};document.addEventListener(`keyup`,e=>{e.key===` `&&$_()}),window.addEventListener(`blur`,$_);var e1=new lh((e,t)=>{t&&w_(Y.source),Y.source=e,j_()},()=>$(!0));q.addEventListener(`input`,()=>e1.input(q.value)),q.addEventListener(`click`,x_),q.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&x_()}),q.addEventListener(`keydown`,e=>{if(e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let{value:t,selectionStart:n,selectionEnd:r}=q;if(e.key===`Tab`){e.preventDefault();let i=kh(t,n,r,e.shiftKey);if(i.text===t)return;let a=q.scrollTop;q.value=i.text,q.setSelectionRange(i.from,i.to),q.scrollTop=a,q.dispatchEvent(new Event(`input`));return}let i=t.lastIndexOf(`
684
- `,n-1)+1,a;e.key===`Enter`&&!e.shiftKey?a=Oh(t,n,r):e.key===`}`&&n===r&&!t.slice(i,n).trim()&&(a={start:i,end:r,insert:Eh(t,n)+`}`}),a&&(e.preventDefault(),q.setRangeText(a.insert,a.start,a.end,`end`),a.caret!==void 0&&q.setSelectionRange(a.caret,a.caret),q.dispatchEvent(new Event(`input`)))});function t1(e,t,n){let r=document.createElement(`div`);r.className=`split ${e}`,r.setAttribute(`role`,`separator`),t(r),r.addEventListener(`pointerdown`,e=>{e.preventDefault(),r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let t=()=>{r.classList.remove(`dragging`),r.removeEventListener(`pointermove`,n),r.removeEventListener(`pointerup`,t);try{localStorage.setItem(`yuhwa-panes`,JSON.stringify(i1))}catch{}Y.zoom||$(!1)};r.addEventListener(`pointermove`,n),r.addEventListener(`pointerup`,t)})}var n1=K(`main`),r1=K(`#left`),i1={};try{i1=JSON.parse(localStorage.getItem(`yuhwa-panes`)??`{}`)}catch{}var a1=()=>{i1.left&&(n1.style.gridTemplateColumns=`${i1.left}px 1fr var(--side)`),i1.diag&&Object.assign(Lh.style,{height:`${i1.diag}px`,maxHeight:`none`})};t1(`split-x`,e=>r1.append(e),e=>{i1.left=Math.round(Math.min(Math.max(e.clientX-n1.getBoundingClientRect().left,240),innerWidth-640)),a1()}),t1(`split-y`,e=>Lh.before(e),e=>{let t=r1.getBoundingClientRect().bottom;i1.diag=Math.round(Math.min(Math.max(t-e.clientY,40),r1.clientHeight-160)),a1()}),a1();var o1=Ch({ta:q,files:()=>({...Y.files,[Y.current]:q.value}),current:()=>Y.current,commit:E_,open:s1,status:Xh,onDiagnostics:e=>{e===Y.current&&S_()}});function s1(e){if(e===Y.current||!(e in Y.files))return;Y.files[Y.current]=Y.source,e1.end(),ag.set(Y.current,{undo:d_,redo:f_}),Y.current=e,Y.source=Y.files[e];let t=ag.get(e);d_=t?.undo??[],f_=t?.redo??[],Y.selection=null,q.value=Y.source,q.scrollTop=0,j_(),p1(),$(!0)}var c1=e=>{let t=e.trim().replace(/^\.?\//,``).replace(/\s+/g,`-`);return t?/\.\w+$/.test(t)?t:`${t}.yu`:``};function l1(e,t){let n=e;for(let t=2;n in Y.files;t++)n=e.replace(/(\.\w+)?$/,`-${t}$1`);return Y.files[n]=t,s1(n),n}function u1(e){let t=Y.current.split(`/`).slice(0,-1),n=e.split(`/`),r=0;for(;r<t.length&&t[r]===n[r];)r++;let i=t.slice(r).map(()=>`..`);return(i.length?i.join(`/`)+`/`:`./`)+n.slice(r).join(`/`)}function d1(e){let t=c1(prompt(`Rename file`,e)??``);if(!t||t===e)return;if(t in Y.files)return Xh(`${t} exists`);Y.files[Y.current]=Y.source,e1.end();let n=Y.files[e];delete Y.files[e],Y.files[t]=n;let r=e=>e.split(`/`).pop();for(let n of Object.keys(Y.files))Y.files[n]=Y.files[n].replace(/^(\s*(?:\/\/\s*)?import\s+(?:\{[^}]*\}\s*from\s+)?")([^"]+)(")/gm,(n,i,a,o)=>r(a)===r(e)?i+a.slice(0,-r(e).length)+r(t)+o:n);Y.current===e&&(Y.current=t),Y.source=Y.files[Y.current],q.value=Y.source,j_(),p1(),$(!0)}function f1(e){Object.keys(Y.files).length<2||(!Y.files[e].trim()||confirm(`Delete ${e}?`))&&(e===Y.current&&s1(Object.keys(Y.files).find(t=>t!==e)),delete Y.files[e],ag.delete(e),j_(),p1(),$(!0))}function p1(){qh.innerHTML=``;for(let e of Object.keys(Y.files)){let t=document.createElement(`button`);t.className=`tab`,t.setAttribute(`role`,`tab`),t.setAttribute(`aria-selected`,String(e===Y.current)),t.textContent=e,t.onclick=()=>s1(e),og||(t.title=`${e}: double-click to rename`,t.ondblclick=()=>d1(e));let n=document.createElement(`span`);n.className=`x`,n.textContent=`×`,n.title=`Delete ${e}`,n.onclick=t=>{t.stopPropagation(),f1(e)},og||t.append(n),qh.append(t)}qh.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`,inline:`nearest`}),m1.hidden=og,g1()}var m1=K(`#add-file`);m1.onclick=()=>{let e=c1(prompt(`New file name`,`shared.yu`)??``);e&&Xh(`${l1(e,`// Shared classes and nodes. Use them from ${Y.current} with:\n// import "${u1(e).replace(/^(\.\.\/)+/,`./`)}"\n\n.svc [blue]\n`)} added`)};function h1(e){let t=new Set([...Y.diagram.nodes.keys(),...Y.diagram.panels.map(e=>e.id),...Y.diagram.groups.keys(),...Object.keys(Y.diagram.classes),...Object.keys(Y.diagram.vars??{}),...Object.keys(Y.diagram.defs??{})]);for(let n=1;;n++){let r=n===1?e:`${e}${n}`;if(!t.has(r)&&!Y.source.includes(`${r} `))return r}}function g1(){Jh.replaceChildren(Jh.options[0]);let e=new Map,t=(t,n,r)=>{let i=e.get(t);i||(i=document.createElement(`optgroup`),i.label=t,e.set(t,i),Jh.append(i)),i.append(new Option(n,r))};fh.forEach((e,n)=>t(e.group,e.label,`s${n}`));for(let e of V.panels.keys())fh.some(t=>t.text.startsWith(e+` `))||t(`Panels`,e,`k${e}`);for(let e of Object.keys(Y.files))e!==Y.current&&t(`Import a file`,`import "${u1(e)}"`,`f${e}`)}function _1(e,t=!1){let n=Y.source.search(/^layout\s*\{/m),r=t?0:n>=0?n:Y.source.length,i=Y.source.slice(0,r).replace(/\s*$/,``),a=Y.source.slice(r),o=i?t?``:`
681
+ \0`)}function y_(e,t){return[...ng()?.querySelectorAll(`[data-panel="${CSS.escape(t)}"]`)??[]].indexOf(e)}function b_(e){let t=Y.source.split(`
682
+ `),n=0;for(let r=e;r<t.length;r++){for(let e of t[r].replace(/"[^"]*"/g,``))if(e===`{`)n++;else if(e===`}`&&--n===0)return r;if(!n)return e}return e}function x_(e){if(!e)return null;if(e.kind===`node`){let t=Y.diagram.nodes.get(e.id);if(!t)return null;if(!t.ref||t.implicit){let t=Y.diagram.edges.find(t=>(t.from===e.id||t.to===e.id)&&t.ref)?.ref.line;return t===void 0?null:[t,t]}let n=Math.max(t.ref.line,t.bodyLines?.[1]??0,...Object.values(t.ref.propLines??{}));return[t.ref.line,n]}if(e.kind===`edge`){let t=Y.diagram.edges.find(t=>t.key===e.id)?.ref?.line;return t===void 0?null:[t,t]}if(e.kind===`group`){let t=Y.diagram.groups.get(e.id)?.ref?.line;return t===void 0?null:[t,b_(t)]}return fg(e)?.lines??null}function S_(e){let t=null,n=1/0,r=r=>{let i=x_(r);i&&e>=i[0]&&e<=i[1]&&i[1]-i[0]<n&&(t=r,n=i[1]-i[0])};for(let e of Y.diagram.nodes.values())e.implicit||r({kind:`node`,id:e.id});for(let e of Y.diagram.edges)r({kind:`edge`,id:e.key});for(let e of Y.diagram.groups.keys())r({kind:`group`,id:e});let i=new Map;for(let e of Y.diagram.panels){let t=i.get(e.id)??0;i.set(e.id,t+1),r({kind:`panel`,id:e.id,k:t})}return t&&Tg(t)?t:null}function C_(e){let t={node:`data-node`,edge:`data-edge`,group:`data-group`,panel:`data-panel`}[e.kind],n=ng()?.querySelectorAll(`[${t}="${CSS.escape(e.id)}"]`)[e.k??0];if(!n)return;let r=n.getBoundingClientRect(),i=J.getBoundingClientRect();r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom||J.scrollBy({left:r.left+r.width/2-(i.left+i.width/2),top:r.top+r.height/2-(i.top+i.height/2),behavior:`smooth`})}function w_(){if(q.value!==Y.source)return;let e=S_(Y.source.slice(0,q.selectionStart).split(`
683
+ `).length-1);ug(e)!==ug(Y.selection)&&(Y.selection=e,$(!1),e&&C_(e))}function T_(){Bh.innerHTML=``;let e=l1.diagnostics(Y.current),t=e.filter(e=>e.severity===1).length,n=e.length-t,r=(e,t)=>`${e} ${t}${e===1?``:`s`}`;if(Jh.textContent=`${r(Y.diagram.nodes.size,`node`)} · ${r(Y.diagram.edges.length,`edge`)}`,t||n){let e=document.createElement(`span`);e.className=`bad`,e.textContent=` · ${t?r(t,`error`):r(n,`warning`)}`,Jh.append(e)}for(let t of e){let e=document.createElement(`div`);e.className=t.severity===1?`error`:`warning`;let n=typeof t.message==`string`?t.message:t.message.value;e.textContent=`${t.range.start.line+1}: ${n}`,e.onclick=()=>l1.reveal(t.range);let r=n.match(/did you mean "([^"\n]+)"/);if(r){let n=document.createElement(`button`);n.className=`fix`,n.textContent=`use ${r[1]}`,n.onclick=e=>{e.stopPropagation(),l1.fix(t)},e.append(n)}Bh.append(e)}}function E_(){let e=ge(Y.diagram.themes);[...Uh.options].map(e=>e.value).join()!==e.join()&&Uh.replaceChildren(...e.map(e=>new Option(e,e))),Uh.value=e.includes(Y.diagram.settings.theme)?Y.diagram.settings.theme:`paper`,Wh.value=Y.diagram.settings.direction||`right`,Gh.value=Y.diagram.settings.curve||`smooth`}function D_(e){m_[m_.length-1]!==e&&m_.push(e),m_.length>200&&m_.shift(),h_.length=0}function O_(e,t=!0){if(e===Y.source)return;r1.end(),t&&D_(Y.source),Y.source=e;let n=q.scrollTop;q.value=e,q.scrollTop=n,P_()}function k_(e){O_(e),$(!0)}function A_(){k_(_m(Y.source,Y.diagram.layout,Y.diagram))}function j_(){if(!Y.selection)return;let{kind:e,id:t}=Y.selection,n=Lm(Y.source,{kind:e,id:t},Y.diagram);if(n===Y.source)return $h(`this ${e} cannot be deleted here, edit the source`);Y.selection=null,k_(n),$h(`${e} ${t} deleted`)}function M_(e,t){let n=v1(`node`),r=Pm(Y.source,{id:n,label:`New node`,...e},Y.diagram);if(r===Y.source)return $h(`cannot add a node here`);if(Y.selection={kind:`node`,id:n},k_(r),t&&Y.L.nodes.has(n)){let{o:e,w:r,h:i}=L_().pinned(n,!0);e.x=Math.round(Qh(t.x)-r/2),e.y=Math.round(Qh(t.y)-i/2),O_(_m(Y.source,Y.diagram.layout,Y.diagram),!1),$(!0)}let i=J.querySelector(`[data-node="${CSS.escape(n)}"]`);i&&Qg({kind:`node`,id:n},i)}var N_=0;function P_(){if(Y.files[Y.current]=Y.source,lg)F_.changed(),clearTimeout(N_),N_=window.setTimeout(I_,500);else try{localStorage.setItem(`yuhwa-files`,JSON.stringify({files:Y.files,current:Y.current}))}catch{}}var F_=new ph(async()=>{let e=await fetch(`/api/source`,{method:`PUT`,body:JSON.stringify({files:Y.files})});if(!e.ok)throw Error(`save failed`);let{written:t=[]}=await e.json();return t.length?`saved ${t.join(`, `)}`:`saved`},$h);function I_(){if(lg)return clearTimeout(N_),F_.save()}var L_=()=>new Nh(Y.diagram,Y.L,Qh),R_=null,z_=!1,B_=new Map,V_=null;function H_(e,t){R_={x:e.clientX,y:e.clientY,left:J.scrollLeft,top:J.scrollTop,moved:!1,clear:t},J.setPointerCapture(e.pointerId),J.classList.add(`panning`),e.preventDefault()}var U_=()=>{let[e,t]=[...B_.values()];return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,d:Math.hypot(e.x-t.x,e.y-t.y)}};J.addEventListener(`wheel`,e=>{if(!(e.ctrlKey||e.metaKey)||Y.drag||!ng())return;e.preventDefault();let t=e.deltaMode===1?e.deltaY*16:e.deltaY;wg(t1()*Math.min(2,Math.max(.5,Math.exp(-t*.01))),e)},{passive:!1}),J.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||(B_.set(e.pointerId,{x:e.clientX,y:e.clientY}),B_.size!==2))return;q_(),R_=null;let t=U_();V_={d:t.d,z:t1(),mid:t},e.stopImmediatePropagation()},{capture:!0}),J.addEventListener(`pointermove`,e=>{if(!B_.has(e.pointerId)||(B_.set(e.pointerId,{x:e.clientX,y:e.clientY}),!V_||B_.size!==2))return;let t=U_();wg(V_.z*t.d/Math.max(1,V_.d),{clientX:t.x,clientY:t.y}),J.scrollLeft-=t.x-V_.mid.x,J.scrollTop-=t.y-V_.mid.y,V_.mid=t,e.stopImmediatePropagation()},{capture:!0});var W_=e=>{B_.delete(e.pointerId),B_.size<2&&(V_=null)};J.addEventListener(`pointerup`,W_,{capture:!0}),J.addEventListener(`pointercancel`,W_,{capture:!0}),J.addEventListener(`pointerdown`,e=>{if(!ng()||V_)return;if(e.button===1||e.button===0&&z_)return H_(e,!1);if(e.button!==0)return;let t=e.target.closest(`[data-handle],[data-node],[data-edge-label],[data-edge],[data-group],[data-panel]`);if(!t)return H_(e,!0);let n=rg(e),r=ng();Y.frozen={viewBox:r.getAttribute(`viewBox`),w:r.width.baseVal.value,h:r.height.baseVal.value};let i=A_,a=()=>{},o=L_();if(t.hasAttribute(`data-handle`)){let e=t.getAttribute(`data-handle`),r=Number(t.getAttribute(`data-i`));if(Y.selection?.kind===`panel`&&e===`part`){let e=Y.selection.id,t=pg(Y.selection).handles[r];i=()=>k_(km(Y.source,Y.diagram,e,t)),a=o.part(e,t)}else if(Y.selection?.kind===`panel`&&e===`resize`){let e={kind:`panel`,id:Y.selection.id},t=fg(Y.selection);a=o.panelSize(t,pg(Y.selection).box),i=()=>{let{width:n,height:r}=t.props;k_(Tm(Tm(Y.source,e,`width`,n),e,`height`,r))}}else Y.selection?.kind===`node`&&e===`resize`?a=o.resize(Y.selection.id):Y.selection?.kind===`edge`&&(e===`via`||e===`mid`?a=o.via(Y.selection.id,r,e===`mid`?n:null):e===`end`&&(a=o.port(Y.selection.id,r===0?0:1)))}else if(t.hasAttribute(`data-node`)){let e=t.getAttribute(`data-node`);Y.selection={kind:`node`,id:e},a=o.centre(e,!0)}else if(t.hasAttribute(`data-edge-label`)){let e=t.getAttribute(`data-edge-label`);Y.selection={kind:`edge`,id:e},a=o.label(e)}else if(t.hasAttribute(`data-edge`)){let e=t.getAttribute(`data-edge`);Y.selection={kind:`edge`,id:e},a=o.bend(e,n)}else if(t.hasAttribute(`data-panel`)){let e=t.getAttribute(`data-panel`);Y.selection={kind:`panel`,id:e,k:y_(t,e)},a=o.centre(e,!1)}else if(t.hasAttribute(`data-group`)){let e=t.getAttribute(`data-group`);Y.selection={kind:`group`,id:e},a=o.group(e)}Y.drag={move:a,finish:i,moved:!1,start:n},J.setPointerCapture(e.pointerId),$(!1),e.preventDefault()}),J.addEventListener(`pointermove`,e=>{if(R_){let t=e.clientX-R_.x,n=e.clientY-R_.y;if(!R_.moved&&Math.hypot(t,n)<3)return;R_.moved=!0,J.scrollLeft=R_.left-t,J.scrollTop=R_.top-n;return}if(!Y.drag)return;let t=rg(e),n={x:t.x-Y.drag.start.x,y:t.y-Y.drag.start.y};!Y.drag.moved&&Math.hypot(n.x,n.y)<3||(Y.drag.moved=!0,J.classList.add(`dragging`),Y.drag.move(t,n,e),G_||=requestAnimationFrame(()=>{G_=0,$(!1)}))});var G_=0;function K_(){if(R_){let{moved:e,clear:t}=R_;R_=null,J.classList.remove(`panning`),!e&&t&&Y.selection&&(Y.selection=null,$(!1))}else q_()}function q_(){if(!Y.drag)return;let{moved:e,finish:t}=Y.drag;Y.drag=null,Y.frozen=null,J.classList.remove(`dragging`),e?t():$()}J.addEventListener(`pointerup`,K_),J.addEventListener(`pointercancel`,K_);function J_(e,t){let n=Y.diagram.layout.edges[e],r=Number(t.getAttribute(`data-i`));if(!n)return!1;if(t.getAttribute(`data-handle`)===`via`&&n.via)n.via.splice(r,1),n.via.length||delete n.via;else if(t.getAttribute(`data-handle`)===`end`&&n.ports)n.ports[r]=`auto`;else return!1;return A_(),!0}J.addEventListener(`contextmenu`,e=>{let t=e.target,n=t.closest(`[data-handle]`);if(Y.selection?.kind===`edge`&&n){J_(Y.selection.id,n)&&e.preventDefault();return}let r=t.closest(`[data-edge]`)?.getAttribute(`data-edge`),i=r?Y.diagram.layout.edges[r]:void 0;r&&i?.via&&(e.preventDefault(),delete i.via,Y.selection={kind:`edge`,id:r},A_())}),J.addEventListener(`dblclick`,e=>{let t=e.target,n=t.closest(`[data-handle]`),r=t.closest(`[data-edge-label]`);if(Y.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`part`){let e=Y.selection.id,t=pg(Y.selection)?.handles[Number(n.getAttribute(`data-i`))]?.part,r=Y.diagram.layout.panels?.[e];if(!t||!r?.parts?.[t])return;delete r.parts[t],Object.keys(r.parts).length||delete r.parts,A_()}else if(Y.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`resize`){let e={kind:`panel`,id:Y.selection.id};k_(Tm(Tm(Y.source,e,`width`,null),e,`height`,null))}else if(Y.selection?.kind===`edge`&&n)J_(Y.selection.id,n);else if(!n){let n=r??t.closest(`[data-node],[data-edge],[data-group],[data-panel]`);if(!n)return M_({},rg(e));let[i,a]=r?[`edge`,r.getAttribute(`data-edge-label`)]:[`node`,`edge`,`group`,`panel`].map(e=>[e,n.getAttribute(`data-${e}`)]).find(([,e])=>e!==null),o=i===`edge`&&!r?J.querySelector(`[data-edge-label="${CSS.escape(a)}"]`)??n:n;Qg({kind:i,id:a},o)}}),document.addEventListener(`keydown`,e=>{let t=e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLInputElement,n=e.metaKey||e.ctrlKey;if(n&&e.key.toLowerCase()===`s`){e.preventDefault(),I_();return}if(t)return;if(e.key===` `&&!e.repeat){z_=!0,J.classList.add(`can-pan`),e.preventDefault();return}let r=n&&{"=":1.25,"+":1.25,"-":.8,_:.8,0:0,1:-1}[e.key];if(r!==void 0&&r!==!1){e.preventDefault(),wg(r===-1?1:r&&t1()*r);return}if(n&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?X_():Y_();return}if(e.key===`Escape`){Y.selection=null,$(!1);return}if((e.key===`Delete`||e.key===`Backspace`)&&Y.selection){e.preventDefault(),j_();return}let i={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};if(i[e.key]&&(Y.selection?.kind===`node`||Y.selection?.kind===`panel`)){e.preventDefault();let t=e.shiftKey?12:1,{o:n}=L_().pinned(Y.selection.id,Y.selection.kind===`node`);n.x+=i[e.key].x*t,n.y+=i[e.key].y*t,A_()}});function Y_(){let e=m_.pop();e!==void 0&&(h_.push(Y.source),O_(e,!1),$(!0))}function X_(){let e=h_.pop();e!==void 0&&(m_.push(Y.source),O_(e,!1),$(!0))}Uh.replaceChildren(...C.map(e=>new Option(e,e)));for(let[e,t]of[[Wh,`direction`],[Gh,`curve`]])e.replaceChildren(...hr[t].map(e=>new Option(e,e)));for(let e of mh)Kh.append(new Option(e.name,e.name));Kh.onchange=()=>{let e=mh.find(e=>e.name===Kh.value);if(Kh.value=``,e){if(e.files){if(lg)return $h(`multi-file templates need the browser editor`);if(Y.files[Y.current]=Y.source,Object.values(Y.files).some(e=>e.trim()&&e!==p_)&&!confirm(`Replace all files with "${e.name}"?`))return;j1({files:{[sg]:e.source,...e.files},current:sg}),q.value=Y.source,P_(),g1(),$(!0)}else k_(e.source)}},Uh.onchange=()=>k_(Dm(Y.source,`theme`,Uh.value===`paper`&&!/^\s*import\b/m.test(Y.source)?null:Uh.value)),Wh.onchange=()=>{Y.diagram.layout.nodes={},Y.diagram.layout.edges={};for(let e of Object.values(Y.diagram.layout.panels??{}))delete e.at;k_(Dm(_m(Y.source,Y.diagram.layout,Y.diagram),`direction`,Wh.value))},Gh.onchange=()=>k_(Dm(Y.source,`curve`,Gh.value===`smooth`?null:Gh.value)),K(`#undo`).onclick=Y_,K(`#redo`).onclick=X_,K(`#reset`).onclick=()=>{Y.diagram.layout={nodes:{},edges:{}},A_()};function Z_(){return Xu(Y.diagram,Wu(Y.diagram,{measureFor:e=>Vr(e.font)}),{idPrefix:`yuhwa`})}async function Q_(e,t){try{await navigator.clipboard.writeText(e),$h(`${t} copied`)}catch{$h(`clipboard blocked`)}}K(`#copy-svg`).onclick=()=>Q_(Z_(),`SVG`),K(`#copy-md`).onclick=()=>Q_("```yuhwa\n"+Y.source.replace(/\s*$/,``)+"\n```\n",`Markdown`);function $_(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=(Y.diagram.settings.title||`diagram`).toLowerCase().replace(/[^\w]+/g,`-`)+t,n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}document.fonts?.addEventListener(`loadingdone`,()=>{$(!1),Y.selection||f_()}),K(`#download`).onclick=()=>$_(new Blob([Z_()],{type:`image/svg+xml`}),`.svg`),K(`#download-png`).onclick=async()=>{try{(await uh(Z_(),{scale:2})).toBlob(e=>e?$_(e,`.png`):$h(`PNG export failed`),`image/png`)}catch{$h(`PNG export failed`)}};var e1=K(`#export`);e1.querySelector(`.menu-list`).addEventListener(`click`,e=>{e.target.closest(`button`)&&(e1.open=!1)}),document.addEventListener(`pointerdown`,e=>{e1.open&&!e1.contains(e.target)&&(e1.open=!1)}),e1.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e1.open=!1,e1.querySelector(`summary`).focus())}),K(`#share`).onclick=()=>{let e=Object.keys(Y.files).length>1,t=`${location.origin}${location.pathname}#${e?`files=${eg(JSON.stringify({files:Y.files,current:Y.current}))}`:`src=${eg(Y.source)}`}`;history.replaceState(null,``,t),Q_(t,`link`)},K(`#zoom-in`).onclick=()=>wg(t1()*1.25),K(`#zoom-out`).onclick=()=>wg(t1()/1.25),K(`#zoom-fit`).onclick=()=>wg(+!Y.zoom);function t1(){let e=ng();return e?e.width.baseVal.value/Y.L.bounds.w:1}qh.hidden=!lg,qh.onclick=()=>void I_(),window.addEventListener(`beforeunload`,e=>{lg&&F_.dirty&&e.preventDefault()}),window.addEventListener(`resize`,()=>Y.zoom||$(!1));var n1=()=>{z_=!1,J.classList.remove(`can-pan`)};document.addEventListener(`keyup`,e=>{e.key===` `&&n1()}),window.addEventListener(`blur`,n1);var r1=new fh((e,t)=>{t&&D_(Y.source),Y.source=e,P_()},()=>$(!0));q.addEventListener(`input`,()=>r1.input(q.value)),q.addEventListener(`click`,w_),q.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&w_()}),q.addEventListener(`keydown`,e=>{if(e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let{value:t,selectionStart:n,selectionEnd:r}=q;if(e.key===`Tab`){e.preventDefault();let i=Mh(t,n,r,e.shiftKey);if(i.text===t)return;let a=q.scrollTop;q.value=i.text,q.setSelectionRange(i.from,i.to),q.scrollTop=a,q.dispatchEvent(new Event(`input`));return}let i=t.lastIndexOf(`
684
+ `,n-1)+1,a;e.key===`Enter`&&!e.shiftKey?a=jh(t,n,r):e.key===`}`&&n===r&&!t.slice(i,n).trim()&&(a={start:i,end:r,insert:kh(t,n)+`}`}),a&&(e.preventDefault(),q.setRangeText(a.insert,a.start,a.end,`end`),a.caret!==void 0&&q.setSelectionRange(a.caret,a.caret),q.dispatchEvent(new Event(`input`)))});function i1(e,t,n){let r=document.createElement(`div`);r.className=`split ${e}`,r.setAttribute(`role`,`separator`),t(r),r.addEventListener(`pointerdown`,e=>{e.preventDefault(),r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let t=()=>{r.classList.remove(`dragging`),r.removeEventListener(`pointermove`,n),r.removeEventListener(`pointerup`,t);try{localStorage.setItem(`yuhwa-panes`,JSON.stringify(s1))}catch{}Y.zoom||$(!1)};r.addEventListener(`pointermove`,n),r.addEventListener(`pointerup`,t)})}var a1=K(`main`),o1=K(`#left`),s1={};try{s1=JSON.parse(localStorage.getItem(`yuhwa-panes`)??`{}`)}catch{}var c1=()=>{s1.left&&(a1.style.gridTemplateColumns=`${s1.left}px 1fr var(--side)`),s1.diag&&Object.assign(Bh.style,{height:`${s1.diag}px`,maxHeight:`none`})};i1(`split-x`,e=>o1.append(e),e=>{s1.left=Math.round(Math.min(Math.max(e.clientX-a1.getBoundingClientRect().left,240),innerWidth-640)),c1()}),i1(`split-y`,e=>Bh.before(e),e=>{let t=o1.getBoundingClientRect().bottom;s1.diag=Math.round(Math.min(Math.max(t-e.clientY,40),o1.clientHeight-160)),c1()}),c1();var l1=Eh({ta:q,files:()=>({...Y.files,[Y.current]:q.value}),current:()=>Y.current,commit:k_,open:u1,status:$h,onDiagnostics:e=>{e===Y.current&&T_()}});function u1(e){if(e===Y.current||!(e in Y.files))return;Y.files[Y.current]=Y.source,r1.end(),cg.set(Y.current,{undo:m_,redo:h_}),Y.current=e,Y.source=Y.files[e];let t=cg.get(e);m_=t?.undo??[],h_=t?.redo??[],Y.selection=null,q.value=Y.source,q.scrollTop=0,P_(),g1(),$(!0)}var d1=e=>{let t=e.trim().replace(/^\.?\//,``).replace(/\s+/g,`-`);return t?/\.\w+$/.test(t)?t:`${t}.yu`:``};function f1(e,t){let n=e;for(let t=2;n in Y.files;t++)n=e.replace(/(\.\w+)?$/,`-${t}$1`);return Y.files[n]=t,u1(n),n}function p1(e){let t=Y.current.split(`/`).slice(0,-1),n=e.split(`/`),r=0;for(;r<t.length&&t[r]===n[r];)r++;let i=t.slice(r).map(()=>`..`);return(i.length?i.join(`/`)+`/`:`./`)+n.slice(r).join(`/`)}function m1(e){let t=d1(prompt(`Rename file`,e)??``);if(!t||t===e)return;if(t in Y.files)return $h(`${t} exists`);Y.files[Y.current]=Y.source,r1.end();let n=Y.files[e];delete Y.files[e],Y.files[t]=n;let r=e=>e.split(`/`).pop();for(let n of Object.keys(Y.files))Y.files[n]=Y.files[n].replace(/^(\s*(?:\/\/\s*)?import\s+(?:\{[^}]*\}\s*from\s+)?")([^"]+)(")/gm,(n,i,a,o)=>r(a)===r(e)?i+a.slice(0,-r(e).length)+r(t)+o:n);Y.current===e&&(Y.current=t),Y.source=Y.files[Y.current],q.value=Y.source,P_(),g1(),$(!0)}function h1(e){Object.keys(Y.files).length<2||(!Y.files[e].trim()||confirm(`Delete ${e}?`))&&(e===Y.current&&u1(Object.keys(Y.files).find(t=>t!==e)),delete Y.files[e],cg.delete(e),P_(),g1(),$(!0))}function g1(){Xh.innerHTML=``;for(let e of Object.keys(Y.files)){let t=document.createElement(`button`);t.className=`tab`,t.setAttribute(`role`,`tab`),t.setAttribute(`aria-selected`,String(e===Y.current)),t.textContent=e,t.onclick=()=>u1(e),lg||(t.title=`${e}: double-click to rename`,t.ondblclick=()=>m1(e));let n=document.createElement(`span`);n.className=`x`,n.textContent=`×`,n.title=`Delete ${e}`,n.onclick=t=>{t.stopPropagation(),h1(e)},lg||t.append(n),Xh.append(t)}Xh.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`,inline:`nearest`}),_1.hidden=lg,y1()}var _1=K(`#add-file`);_1.onclick=()=>{let e=d1(prompt(`New file name`,`shared.yu`)??``);e&&$h(`${f1(e,`// Shared classes and nodes. Use them from ${Y.current} with:\n// import "${p1(e).replace(/^(\.\.\/)+/,`./`)}"\n\n.svc [blue]\n`)} added`)};function v1(e){let t=new Set([...Y.diagram.nodes.keys(),...Y.diagram.panels.map(e=>e.id),...Y.diagram.groups.keys(),...Object.keys(Y.diagram.classes),...Object.keys(Y.diagram.vars??{}),...Object.keys(Y.diagram.defs??{})]);for(let n=1;;n++){let r=n===1?e:`${e}${n}`;if(!t.has(r)&&!Y.source.includes(`${r} `))return r}}function y1(){Zh.replaceChildren(Zh.options[0]);let e=new Map,t=(t,n,r)=>{let i=e.get(t);i||(i=document.createElement(`optgroup`),i.label=t,e.set(t,i),Zh.append(i)),i.append(new Option(n,r))};hh.forEach((e,n)=>t(e.group,e.label,`s${n}`));for(let e of V.panels.keys())hh.some(t=>t.text.startsWith(e+` `))||t(`Panels`,e,`k${e}`);for(let e of Object.keys(Y.files))e!==Y.current&&t(`Import a file`,`import "${p1(e)}"`,`f${e}`)}function b1(e,t=!1){let n=Y.source.search(/^layout\s*\{/m),r=t?0:n>=0?n:Y.source.length,i=Y.source.slice(0,r).replace(/\s*$/,``),a=Y.source.slice(r),o=i?t?``:`
685
685
 
686
686
  `:``,s=t?`${e}\n${Y.source}`:`${i}${o}${e}\n${a?`
687
- `+a:``}`;E_(s);let c=t?0:i.length+o.length;q.focus(),q.setSelectionRange(c,c+e.length);let l=s.slice(0,c).split(`
688
- `).length;q.scrollTop=Math.max(0,(l-3)*parseFloat(getComputedStyle(q).lineHeight||`20`))}Jh.onchange=()=>{let e=Jh.value;if(Jh.value=``,e.startsWith(`s`)){let t=fh[Number(e.slice(1))],n=h1(t.id);_1(t.text.replaceAll(`{id}`,n)),Xh(`${t.label.toLowerCase()} added`)}else if(e.startsWith(`k`)){let t=V.panels.get(e.slice(1));_1(`${t.name} ${h1(t.name)} "${t.name}" {\n // ${t.syntax??``}\n}`)}else if(e.startsWith(`f`)){let t=`import "${u1(e.slice(1))}"`;if(Y.source.includes(t))return Xh(`already imported`);_1(t,!0)}};var v1=K(`#import-dlg`),y1=K(`#import-text`),b1=K(`#import-msg`),x1=K(`#import-new`),S1=`imported.yu`;function C1(e=``,t=`imported.yu`){y1.value=e,S1=t,b1.textContent=``,b1.className=``,x1.checked=!og,x1.disabled=og,v1.showModal(),y1.focus()}K(`#import`).onclick=()=>C1();async function w1(e){C1(await e.text(),c1(e.name.replace(/\.(mmd|mermaid|json|txt|md)$/,``)))}K(`#import-file`).onchange=async e=>{let t=e.target.files?.[0];t&&await w1(t),e.target.value=``};var T1=e=>e.match(/```(?:yuhwa|mermaid|json)[^\n]*\n([\s\S]*?)```/)?.[1]??e;K(`#import-go`).onclick=e=>{e.preventDefault();let t=T1(y1.value);if(!t.trim())return v1.close();let n=ch(t),r=n.diagnostics.filter(e=>e.severity===`error`);if(r.length||!n.source.trim()){b1.className=`error`,b1.textContent=r.map(e=>e.message).join(`
689
- `)||`nothing to import`;return}let i=n.format===`yuhwa`?`yuhwa`:n.format===`json`?`JSON`:`Mermaid`;x1.checked?l1(S1,n.source):E_(n.source),v1.close();let a=n.diagnostics.length;Xh(`imported ${i}${a?` (${a} warning${a>1?`s`:``})`:``}`)},addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),addEventListener(`drop`,e=>{let t=e.dataTransfer?.files[0];t&&(e.preventDefault(),w1(t))});async function E1(){if(og){let e=await(await fetch(`/api/source`)).json();Y.source=e.source,Y.current=String(e.name).split(`/`).pop()||`main.yu`,Y.files={[Y.current]:Y.source,...e.files},document.title=`${e.name} — yuhwa`,Xh(e.name)}else{if(!D1()){let e=null;try{e=localStorage.getItem(`yuhwa-files`),O1(e?JSON.parse(e):{files:{[ig]:localStorage.getItem(`yuhwa-source`)??u_}})}catch{O1({files:{[ig]:u_}})}}Y.files[Y.current]=Y.source}q.value=Y.source,p1(),$(!0)}function D1(){let e=location.hash.match(/src=([\w-]+)/),t=location.hash.match(/files=([\w-]+)/);try{if(t)O1(JSON.parse(Qh(t[1])));else if(e)O1({files:{[ig]:Qh(e[1])}});else return!1}catch{return Xh(`broken link`),!1}return!0}function O1(e){e1.end(),Y.files=Object.keys(e.files??{}).length?{...e.files}:{[ig]:u_},Y.current=e.current&&e.current in Y.files?e.current:Object.keys(Y.files)[0],Y.source=Y.files[Y.current],ag.clear(),d_=[],f_=[]}E1(),addEventListener(`hashchange`,()=>{!og&&D1()&&(q.value=Y.source,p1(),$(!0))});
687
+ `+a:``}`;k_(s);let c=t?0:i.length+o.length;q.focus(),q.setSelectionRange(c,c+e.length);let l=s.slice(0,c).split(`
688
+ `).length;q.scrollTop=Math.max(0,(l-3)*parseFloat(getComputedStyle(q).lineHeight||`20`))}Zh.onchange=()=>{let e=Zh.value;if(Zh.value=``,e.startsWith(`s`)){let t=hh[Number(e.slice(1))],n=v1(t.id);b1(t.text.replaceAll(`{id}`,n)),$h(`${t.label.toLowerCase()} added`)}else if(e.startsWith(`k`)){let t=V.panels.get(e.slice(1));b1(`${t.name} ${v1(t.name)} "${t.name}" {\n // ${t.syntax??``}\n}`)}else if(e.startsWith(`f`)){let t=`import "${p1(e.slice(1))}"`;if(Y.source.includes(t))return $h(`already imported`);b1(t,!0)}};var x1=K(`#import-dlg`),S1=K(`#import-text`),C1=K(`#import-msg`),w1=K(`#import-new`),T1=`imported.yu`;function E1(e=``,t=`imported.yu`){S1.value=e,T1=t,C1.textContent=``,C1.className=``,w1.checked=!lg,w1.disabled=lg,x1.showModal(),S1.focus()}K(`#import`).onclick=()=>E1();async function D1(e){E1(await e.text(),d1(e.name.replace(/\.(mmd|mermaid|json|txt|md)$/,``)))}K(`#import-file`).onchange=async e=>{let t=e.target.files?.[0];t&&await D1(t),e.target.value=``};var O1=e=>e.match(/```(?:yuhwa|mermaid|json)[^\n]*\n([\s\S]*?)```/)?.[1]??e;K(`#import-go`).onclick=e=>{e.preventDefault();let t=O1(S1.value);if(!t.trim())return x1.close();let n=dh(t),r=n.diagnostics.filter(e=>e.severity===`error`);if(r.length||!n.source.trim()){C1.className=`error`,C1.textContent=r.map(e=>e.message).join(`
689
+ `)||`nothing to import`;return}let i=n.format===`yuhwa`?`yuhwa`:n.format===`json`?`JSON`:`Mermaid`;w1.checked?f1(T1,n.source):k_(n.source),x1.close();let a=n.diagnostics.length;$h(`imported ${i}${a?` (${a} warning${a>1?`s`:``})`:``}`)},addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),addEventListener(`drop`,e=>{let t=e.dataTransfer?.files[0];t&&(e.preventDefault(),D1(t))});async function k1(){if(lg){let e=await(await fetch(`/api/source`)).json();Y.source=e.source,Y.current=String(e.name).split(`/`).pop()||`main.yu`,Y.files={[Y.current]:Y.source,...e.files},document.title=`${e.name} — yuhwa`,$h(e.name)}else{if(!A1()){let e=null;try{e=localStorage.getItem(`yuhwa-files`),j1(e?JSON.parse(e):{files:{[sg]:localStorage.getItem(`yuhwa-source`)??p_}})}catch{j1({files:{[sg]:p_}})}}Y.files[Y.current]=Y.source}q.value=Y.source,g1(),$(!0)}function A1(){let e=location.hash.match(/src=([\w-]+)/),t=location.hash.match(/files=([\w-]+)/);try{if(t)j1(JSON.parse(tg(t[1])));else if(e)j1({files:{[sg]:tg(e[1])}});else return!1}catch{return $h(`broken link`),!1}return!0}function j1(e){r1.end(),Y.files=Object.keys(e.files??{}).length?{...e.files}:{[sg]:p_},Y.current=e.current&&e.current in Y.files?e.current:Object.keys(Y.files)[0],Y.source=Y.files[Y.current],cg.clear(),m_=[],h_=[]}k1(),addEventListener(`hashchange`,()=>{!lg&&A1()&&(q.value=Y.source,g1(),$(!0))});