yuhwa 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +5 -3
  2. package/dist/astro.d.ts +1 -1
  3. package/dist/astro.js +4 -3
  4. package/dist/browser.d.ts +10 -4
  5. package/dist/browser.js +85 -22
  6. package/dist/canvas.d.ts +2 -0
  7. package/dist/canvas.js +40 -0
  8. package/dist/cli.js +485 -236
  9. package/dist/editor/assets/index-DWm3xV_v.js +689 -0
  10. package/dist/editor/assets/{lsp.worker-CMSpDTsX.js → lsp.worker-N6A9m364.js} +23 -17
  11. package/dist/editor/index.html +4 -1
  12. package/dist/{figure-QAwSU1Ry.d.ts → figure-BLHfxz_e.d.ts} +28 -5
  13. package/dist/{index-6ZPJGThY.d.ts → index-xVW43gqW.d.ts} +48 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +5 -3
  16. package/dist/ironmark.d.ts +1 -1
  17. package/dist/ironmark.js +1 -1
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +2 -1
  20. package/dist/lsp-node.js +46 -26
  21. package/dist/lsp-server.d.ts +5 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +1 -1
  24. package/dist/lsp.js +1 -1
  25. package/dist/markdown-it.d.ts +1 -1
  26. package/dist/markdown-it.js +5 -3
  27. package/dist/{node-CLu2Pp_2.js → node-CkrQnPFb.js} +90 -13
  28. package/dist/{plugin-Bs4eiAuz.js → parse--ljBMU60.js} +25 -307
  29. package/dist/plugin-CitzbblK.js +301 -0
  30. package/dist/{plugin-NSkNyoUj.d.ts → plugin-NMP_uf1a.d.ts} +15 -1
  31. package/dist/plugin.d.ts +1 -1
  32. package/dist/plugin.js +3 -1
  33. package/dist/raster-iqi6XRPU.js +299 -0
  34. package/dist/remark.d.ts +1 -1
  35. package/dist/remark.js +1 -1
  36. package/dist/rolldown-runtime-CEjnN5Q1.js +37 -0
  37. package/dist/{server-D6BSNC1P.js → server-BTYtmr6B.js} +41 -63
  38. package/dist/{server--jHjJjOS.d.ts → server-DMAOtqqK.d.ts} +1 -1
  39. package/dist/{service-D7DNWBAU.js → service-C60VdeKS.js} +34 -3
  40. package/dist/{service-Brvpt7Do.d.ts → service-DimTFsE3.d.ts} +2 -0
  41. package/dist/{shared-6aCU_HaV.js → shared-h8tkFLY4.js} +231 -21
  42. package/dist/{src-BjOhvTAB.js → src-NCXCTK_4.js} +81 -45
  43. package/dist/svg-uri-Dx8SGV-n.js +7 -0
  44. package/dist/vite.d.ts +1 -1
  45. package/dist/vite.js +3 -3
  46. package/dist/vuepress.d.ts +3 -2
  47. package/dist/vuepress.js +4 -2
  48. package/dist/watch-2VeW5DUN.js +35 -0
  49. package/dist/yuhwa.iife.js +55 -54
  50. package/dist/zoom-script-CaJ5MNUw.js +29 -0
  51. package/dist/{zoom-QeqB6QlH.js → zoom-yxhxX16c.js} +1 -1
  52. package/dist/zoom.d.ts +16 -7
  53. package/dist/zoom.js +2 -2
  54. package/package.json +19 -2
  55. package/skills/yuhwa/SKILL.md +12 -0
  56. package/dist/editor/assets/index-DAk6b1UB.js +0 -689
  57. package/dist/zoom-script-CVdAzMhX.js +0 -51
@@ -0,0 +1,689 @@
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 A=e=>{let t=e.length===4?e.slice(1).split(``).map(e=>e+e).join(``):e.slice(1);return[0,2,4].map(e=>parseInt(t.slice(e,e+2),16))},ee=(e,t,n)=>`#`+A(e).map((e,r)=>Math.round(e*n+A(t)[r]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``);function te(e,t,n){let r=k(e);return r?{fill:ee(r,T.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,t.dark?n?.14:.22:n?.07:.12),stroke:r,text:t.dark?ee(r,`#ffffff`,.45):ee(r,`#000000`,.55)}:void 0}var ne=new WeakMap,re=new WeakMap,j=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),M=[`solid`,`dashed`,`dotted`],ie=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t,ae={sans:h,serif:_,mono:g},oe=/^(serif|sans-serif|monospace|cursive|fantasy|math|emoji|system-ui|ui-(serif|sans-serif|monospace|rounded))$/i,se=e=>oe.test(e),ce=e=>e.split(`,`).map(e=>e.trim().replace(/^(['"])(.*)\1$/,`$2`)).filter(Boolean);function le(e){let t=e.split(`,`).map(e=>e.trim()).filter(Boolean),n=ce(e)[0]??`sans`,r=n===`mono`||/mono|code|courier/i.test(n),i=t.map(e=>ae[e]??e),a=t.at(-1)??``;return!ae[a]&&!se(a)&&i.push(r?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`),{font:i.join(`, `),mono:r}}var ue=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:M},"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 de(e,t,n){let r=n??S[t.base]??S.paper,i=j(t.dark,r.dark),a=(e,n,a)=>N(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?le(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:ie(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 fe(e,t,n=[]){let r=t[e],i=r.base??(S[e]?e:void 0);return de(e,r,i&&t[i]&&i!==e&&!n.includes(i)?fe(i,t,[...n,e]):S[i??`paper`]??S.paper)}var pe=e=>[...new Set([...C,...Object.keys(e??{})])];function me(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=he(fe(e,t))),r}return he(S[e??`paper`]??S.paper)}function he(e){let t=ne.get(e);return t||(t={...e,tone:n=>e.tone(n)??te(n,t,!1),groupTone:n=>e.groupTone(n)??te(n,t,!0),edgeTone:t=>e.edgeTone(t)??(k(t)?t:void 0)},ne.set(e,t)),t}var ge=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&d(t[1])&&(!t[2]||t[2]in p)||!!k(e)},_e=String.raw`#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z][\w-]*`;function N(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 ve(e)?e:void 0}var ve=e=>/^[\w\s#(),.%/+-]*$/.test(e),ye=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())},be=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),xe=e=>({...e,text:e.sub}),Se=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,Ce=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,we=/\*\*(.{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,Te=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`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),Ee=e=>e in Te?e:Object.keys(Te).find(t=>Te[t].aliases.includes(e));function De(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&Oe(i)){t.color=i;continue}let a=Ee(i);if(!a)return;let o=Te[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(!ge(s))return;t.color=s}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}var Oe=e=>Se.test(e)&&(e.startsWith(`#`)||d(e.replace(/-\d+$/,``)));function P(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(we))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&&Oe(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=De(t[5]),n=e?null:t[0].match(Ce);e?r({kind:`color`,text:t[6],...e}):n&&Oe(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]}):Oe(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 ke(e){let t=[];for(let n of e.matchAll(we))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 Ae=/[*~`[{]/;function je(e,t=!1){let n=Ae.test(e)?P(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function Me(e,t,n,r,i,a=!1,o=0){let s=je(e,a);return L(s,t,r,i,n)+(o?o*[...Re(s)].length:0)}var Ne=(e,t)=>e.reduce((e,t)=>Ae.test(t)?P(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),Pe=1.3,Fe=(e,t,n=Pe)=>Ne(e,t)*n,Ie=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${I(t)}" y="${I(n(i))}">${r(e)}</tspan>`).join(``);function Le(e,t,n,r=!1){let i=je(e,r);return i.every(e=>e.kind===`text`)?F(Re(i)):R(i,t,n)}var Re=e=>e.map(e=>e.text).join(``);function ze(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 F=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),I=e=>(Math.round(e*100)/100).toString(),Be=(e,t,n,r,i,a=``)=>`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central" font-size="${I(n)}" fill="${r}"${a}>${i}</text>`,Ve=(e,t,n)=>e&&N(e,t,t.dark?400:600)||n,He=.55,Ue=(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,Ue(o,i),n);o.w=o.kind===`chip`?s+e*He*2:s,a+=o.w}return a}var We=e=>e.reduce((e,t)=>e+(t.w??0),0);function Ge(e,t,n,r){if(e.color)return Ve(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 Ke(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=Ge(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="${I(t)}" y="${I(n-a/2)}" width="${I(e)}" height="${I(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(Be(t+r*He,n,r,l.color?u:i.text,F(l.text),` xml:space="preserve"`))}else{let a=Ue(l,s),o=l.italic?` font-style="italic"`:``;if(c.push(Be(t,n,l.size??r,u,F(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${I(a)},${I(n)}H${I(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="${Ge(e,t,n,r)}"`];return e.size&&i.push(`font-size="${I(e.size)}"`),e.weight?i.push(`font-weight="${e.weight}"`):e.kind===`bold`&&i.push(`font-weight="750"`),e.italic&&i.push(`font-style="italic"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${F(e.text)}</tspan>`}).join(``)}var qe=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function Je(e,t=`border-style`){let n=e[t];return n&&M.includes(n)?n:j(e.dashed,!1)?`dashed`:j(e.dotted,!1)?`dotted`:void 0}function Ye(e,t){let n=N(t[`edge-color`],e,e.dark?400:500),r=Xe(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 Xe(e){return Qe(e[`edge-width`])}var Ze=(e,t)=>{let n=qe(e,NaN);return n>=0?n:t},Qe=e=>{let t=qe(e,NaN);return t>0?t:void 0},$e=(e,t,n)=>({size:Qe(e[`font-size`])??t,weight:Qe(e[`font-weight`])??n,italic:j(e.italic,!1)}),et=(e,t)=>$e(e,t.fontSize*.86,500);function tt(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function nt(e,t){switch(e){case`dashed`:return`${I(t*4)} ${I(t*3)}`;case`dotted`:return`${I(t*.1)} ${I(t*2.6)}`;default:return null}}function rt(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=Ze(n.border??n[`stroke-width`],Ze(i[`stroke-width`],r.strokeWidth)),s=N(n.fill,r,r.dark?900:100)??a?.fill??r.node.fill,c=N(n.stroke,r,500)??a?.stroke??r.node.stroke,l=N(n.text,r,r.dark?100:800)??a?.text??r.node.text,u=$e(n,Qe(i[`font-size`])??r.fontSize,500),d=u.size;return{fill:s,stroke:c,text:l,sub:N(n[`sub-color`],r,500)??(a?l:r.node.sub),strokeWidth:o,dash:nt(Je(n),o),radius:Ze(n.radius,Ze(i.radius,r.radius)),fontSize:d,fontWeight:j(n.bold,!1)?650:u.weight,body:N(n[`body-color`],r,r.dark?100:800)??l,bodySize:Qe(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:Qe(n[`body-weight`])??400,lineHeight:Qe(n[`line-height`])??1.75,italic:u.italic,shadow:j(n.shadow,j(i.shadow,r.shadow!==null)),opacity:qe(n.opacity,1)}}function it(e,t){let n=e.props,r=n.color?t.groupTone(n.color):void 0;return{fill:N(n.fill,t,t.dark?950:50)??r?.fill??t.group.fill,stroke:N(n.stroke,t,300)??r?.stroke??t.group.stroke,text:N(n.text,t,700)??r?.text??t.group.text,dash:at(n,t.group.dash)}}function at(e,t){return ie(Je(e),t)}function ot(e,t,n){let r=t.theme;if(!r||!(S[r]||n?.[r])||r===e.name)return Ye(e,t);let i=Object.create(me(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,Ye(i,t)}function st(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&&ge(a)?a:void 0,c=e.background??e.fill,l=c===`none`||c===`transparent`?`none`:N(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`:N(e.stroke??s,t,300)??r?.stroke??t.group.stroke,text:N(e.text,t,t.dark?200:700)??r?.text??t.title,width:Ze(e[`border-width`],a&&!s&&!o?Ze(a,1):1),dash:at(e,null),radius:Ze(e.radius,Math.min(14,t.radius+4)),shadow:j(e.shadow,!1)}}function ct(e,t,n,r,i){let a=n.color?r.edgeTone(n.color)??N(n.color,r,500):void 0,o=N(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=Ze(n.width,s),l=Je(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=et(n,r);return{stroke:o,width:c,dash:nt(l,c)??(d?`${c*4} ${c*3}`:null),curve:u,text:N(n.text??n[`label-color`],r,700)??(a&&!r.dark?N(n.color,r,700):r.edge.text),fontSize:f.size,fontWeight:f.weight,italic:f.italic,labelBg:N(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:qe(n.opacity,1)}}var lt=[`top`,`right`,`bottom`,`left`],ut=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),dt=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),ft=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),pt=e=>Math.hypot(e.x,e.y),mt=e=>{let t=pt(e)||1;return{x:e.x/t,y:e.y/t}},ht=(e,t)=>pt(ft(e,t)),gt=e=>Math.round(e*100)/100;function _t(e,t,n,r){let i=ut(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 vt={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function yt(e,t,n){let r=ut(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function bt(e,t,n){let r=yt(t,n,e);return[e,r,vt[r]]}function xt(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&&Et(n,l));if(!u.length)return[n,r];let d=i?bt(n,e,ut(t)):[n],f=a?bt(r,t,ut(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=cn(e.shape,e,r,0),o=cn(t.shape,t,i,0),s=Bt({kind:`cubic`,segs:Nt(a,on[r],o,on[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}var St=(e,t)=>e&&(e===`none`||Kt.has(e))?e:t;function Ct(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;for(let l of e.edges){let u=t.get(l.from),d=t.get(l.to);if(!u||!d)continue;let f=tt(e,l),p=ct(e,l,f,n.theme,n.defaultCurve),m=e.layout.edges[l.key],h=!!m?.via?.length,g=(h?m.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),_=u!==d&&!g.length?a.get(i(l.from,l.to)):void 0;if(_&&_.length>1){let[t,r]=l.from<l.to?[u,d]:[d,u],i=mt(ft(ut(r),ut(t))),a=c.get(_);if(!a){let t=_.map(t=>{let r=s.get(t),a=r?.label?et(tt(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
2
+ `).map(e=>Me(e,a.size,a.weight,n.theme.mono,n.measure)))+18:0;return Math.max(o,Math.abs(i.y)*c+Math.abs(i.x)*o+6)}),r=t.reduce((e,t)=>e+t,0);a=new Map;let l=0;for(let e=0;e<_.length;e++)a.set(_[e],l+t[e]/2-r/2),l+=t[e];c.set(_,a)}let f=a.get(l.key),p=ut(u),m=ut(d);f&&g.push(dt({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},f))}let v=m?.ports?.[0]??f.exit??f[`from-side`],y=m?.ports?.[1]??f.enter??f[`to-side`],b=lt.includes(v)?v:null,x=lt.includes(y)?y:null,S=b??_t(u,g[0]??ut(d),g.length?null:d,n.direction),C=x??_t(d,g[g.length-1]??ut(u),g.length?null:u,n.direction);g.length||u===d||b&&x||([S,C]=xt(u,d,S,C,!b,!x,n.obstacles)),r.push({e:l,a:u,b:d,via:g,manualVia:h,sides:u===d?[`right`,`top`]:[S,C],t:[0,0],style:p,headKind:l.endHead||f.head?St(f.head,`arrow`):`none`,tailKind:l.startHead||f.tail?St(f.tail,`arrow`):`none`,labelOff:m?.label})}let l=new Map;for(let e of r)if(e.a!==e.b)for(let t of[0,1]){let n=t===0?e.a:e.b,r=t===0?e.via[0]??ut(e.b):e.via[e.via.length-1]??ut(e.a),i=`${n.id}\u0000${e.sides[t]}`;l.has(i)||l.set(i,[]),l.get(i).push({it:e,end:t,other:r})}for(let[e,t]of l){let n=e.split(`\0`)[1],i=n===`top`||n===`bottom`;t.sort((e,t)=>(i?e.other.x-t.other.x:e.other.y-t.other.y)||r.indexOf(e.it)-r.indexOf(t.it));let a=t.length;t.forEach((e,t)=>e.it.t[e.end]=a===1?0:(t+1)/(a+1)*2-1)}return r.map(e=>wt(e,n))}function wt(e,t){let{a:n,b:r,style:i}=e,a,o,s;if(n===r)o={x:n.x+n.w,y:n.y+n.h*.32},s={x:n.x+n.w*.68,y:n.y},a={kind:`cubic`,segs:[[o,dt(o,{x:52,y:0}),dt(s,{x:0,y:-52}),s]]};else{o=cn(n.shape,n,e.sides[0],e.t[0]),s=cn(r.shape,r,e.sides[1],e.t[1]);let c=on[e.sides[0]],l=on[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let i=e.via.map(e=>({...e}));i[0].y=o.y,i[i.length-1].y=s.y,a={kind:`poly`,pts:Ft(o,c,s,l,i,n,r,t.obstacles),radius:10}}else a=i.curve===`orthogonal`?{kind:`poly`,pts:Ft(o,c,s,l,e.via,n,r,t.obstacles),radius:10}:i.curve===`straight`?{kind:`poly`,pts:[o,...e.via,s],radius:e.via.length?6:0}:{kind:`cubic`,segs:Nt(o,c,s,l,e.via)}}let c=Bt(a),l,u=e.e.props.caption;if(e.e.label||u){let n=i.fontSize,{mono:r}=t.theme,a=e.e.label?e.e.label.split(`
3
+ `):[],o=a.length?Math.max(...a.map(e=>Me(e,n,i.fontWeight,r,t.measure)))+(t.theme.edge.labelStroke?18:12):0,s=Fe(a,n),d=a.length?a.length*s+6:0,f=n*.88,p=u?u.split(`
4
+ `):[],m=p.length?Math.max(...p.map(e=>Me(e,f,400,r,t.measure)))+8:0,h=Fe(p,f),g=p.length*h+(p.length?4:0),_=Math.max(o,m)/2,v=d?-d/2:0,y=(d?d/2:0)+g,b=e.e.props.rotate===`true`||e.e.props.rotate===``,x=e=>b?{x:e.x+v,y:e.y-_,w:y-v,h:_*2}:{x:e.x-_,y:e.y+v,w:_*2,h:y-v},S=e.labelOff?dt(Ht(c),e.labelOff):Ot(c,x,e,t),C=x(S);l={text:e.e.label??``,caption:u,...C,anchor:S,pill:{w:o,h:d},lineHeight:s,captionLineHeight:h,rotate:b}}let d=[],f=kt(i.width),p=jt(a,`end`),m=jt(a,`start`);return e.headKind!==`none`&&(d.push({at:s,angle:Math.atan2(p.y,p.x),kind:e.headKind}),Mt(a,`end`,At(e.headKind,f,i.width))),e.tailKind!==`none`&&(d.push({at:o,angle:Math.atan2(m.y,m.x),kind:e.tailKind}),Mt(a,`start`,At(e.tailKind,f,i.width))),{key:e.e.key,decl:e.e,d:Wt(a),samples:c,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:l,heads:d,style:i}}var Tt=[.5,.42,.58,.34,.66,.26,.74],Et=(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,Dt=(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 Ot(e,t,n,r){let i=Ut(e,.5),a=1/0;for(let n of Tt){let o=Ut(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)Et(s,e)&&(c+=4);for(let e of r.groups??[])Et(s,e.header)?c+=3:Et(s,e.box)&&!Dt(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}var kt=e=>7+e*2;function At(e,t,n){let r=Kt.get(e);return r?typeof r.inset==`function`?r.inset(t,n):r.inset??0:0}function jt(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(ht(n[e],n[n.length-1])>.5)return mt(ft(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(ht(n[e],n[0])>.5)return mt(ft(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return mt(ft(r,ht(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return mt(ft(n,ht(r,n)>.5?r:i))}function Mt(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=ht(r[i],r[a]);if(o<.5)return;r[i]=dt(r[i],mt(ft(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=mt(ft(ht(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=dt(t[3],r,n),ht(t[2],t[3])<n&&(t[2]=dt(t[3],r,n))}else{let t=e.segs[0],r=mt(ft(ht(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=dt(t[0],r,n)}}}function Nt(e,t,n,r,i){if(!i.length){let i=ht(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,dt(e,t,o),dt(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}:mt(ft(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=ht(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],dt(a[e],o[e],n),dt(a[e+1],o[e+1],-r),a[e+1]])}return s}var Pt=18;function Ft(e,t,n,r,i,a,o,s){let c=dt(e,t,Pt),l=dt(n,r,Pt),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=Lt([...u,...e,l,n]),r=zt(t,b);r<S&&(S=r,x=t)}return x}function It(e){let t=[];for(let n of e)(!t.length||ht(t[t.length-1],n)>.5)&&t.push(n);return t}function Lt(e){let t=It(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=mt(ft(t[e],r)),o=mt(ft(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 Rt(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 zt(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=ht(e[a-1],e[a]),a>=2){let t=mt(ft(e[a-1],e[a-2])),n=mt(ft(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)Rt(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}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+=ht(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=ht(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${gt(e.segs[0][0].x)},${gt(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${gt(n.x)},${gt(n.y)} ${gt(r.x)},${gt(r.y)} ${gt(i.x)},${gt(i.y)}`;return t}let t=It(e.pts),n=`M${gt(t[0].x)},${gt(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,ht(i,a)/2,ht(a,o)/2);if(s<.5){n+=`L${gt(a.x)},${gt(a.y)}`;continue}let c=dt(a,mt(ft(i,a)),s),l=dt(a,mt(ft(o,a)),s);n+=`L${gt(c.x)},${gt(c.y)}Q${gt(a.x)},${gt(a.y)} ${gt(l.x)},${gt(l.y)}`}let r=t[t.length-1];return n+`L${gt(r.x)},${gt(r.y)}`}var Gt=new Map,Kt=new Map,qt=[],Jt=[];function Yt(e,t,n,r,i,a=kt(i)){let o=Kt.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}var Xt=[],Zt=l({});function Qt(e){if(!e)return`rounded`;let t=e.toLowerCase();return Gt.has(t)?t:Zt[t]??`rounded`}function $t(e,t){return{w:Math.max(e+44,96),h:Math.max(t+28,48)}}function en(e,t,n){return Gt.get(e)?.size?.(t,n)??$t(t,n)}function tn(e){return Gt.get(e)?.textOffset??0}var z=e=>(Math.round(e*100)/100).toString();function nn(e,t,n){let r=Gt.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 rn(e,t){return Gt.get(e)?.detail?.(t)??null}function an(e,t,n,r,i){return i<=0?`M${z(e)},${z(t)}h${z(n)}v${z(r)}h${z(-n)}Z`:`M${z(e+i)},${z(t)}H${z(e+n-i)}A${z(i)},${z(i)} 0 0 1 ${z(e+n)},${z(t+i)}V${z(t+r-i)}A${z(i)},${z(i)} 0 0 1 ${z(e+n-i)},${z(t+r)}H${z(e+i)}A${z(i)},${z(i)} 0 0 1 ${z(e)},${z(t+r-i)}V${z(t+i)}A${z(i)},${z(i)} 0 0 1 ${z(e+i)},${z(t)}Z`}var on={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function sn(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 cn(e,t,n,r){let i=Gt.get(e);return i?.port?i.port(t,n,r):sn(t,n,r)}var ln=[`smooth`,`orthogonal`,`straight`],un=[`none`],dn=[`top`,`right`,`bottom`,`left`,`auto`],fn=[`below`,`above`,`right-of`,`left-of`,`rank`],pn=[`text`,`font-size`,`font-weight`,`italic`],mn=[`shape`,`color`,`fill`,`stroke`,...pn,`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`,...fn],hn=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...pn,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`],gn=[`color`,`fill`,`stroke`,...pn,`border-style`,`dashed`,`dotted`,`meta`,`caps`];[...pn];var _n=l({shape:[...Xt,...Object.keys(Zt)],"border-style":M,style:M,curve:ln,head:un,tail:un,exit:dn,"from-side":dn,enter:dn,"to-side":dn}),vn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],yn=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!ge(e),bn=e=>Tn(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`],Sn=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`];function Cn(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 wn(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=Cn(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function Tn(e,t){let[n,r]=wn(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function En(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let e=a?.[o]??r;if(!t.includes(o)){n===`node`&&hn.includes(o)?i(e,`"${o}" is an edge prop, but here it is on a node. On an edge line, edge props go after a colon: a -> b: [${o}]`):i(e,`Unknown ${n} prop "${o}"${Tn(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let c=_n[o],l=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(vn.includes(o)&&yn(s))i(e,`Unknown ${o} "${s}"${bn(s)}`);else if(c&&!c.includes(l)){let t=o===`shape`?Xt:c;i(e,`Unknown ${o} "${s}"${Tn(s,c)||` (use one of: ${t.join(`, `)})`}`)}else xn.includes(o)&&![`true`,`false`].includes(s)?i(e,`${o} expects true or false, got "${s}"`):Sn.includes(o)&&!(parseFloat(s)>=0&&Number.isFinite(parseFloat(s)))?i(e,`${o} expects a number of 0 or more, got "${s}"`):o===`link`&&!ye(s)&&i(e,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function Dn(e,t,n,r){if(t)for(let[i,a]of Object.entries(e)){let e=t[i];e!==void 0&&e!==`text`&&(e===`color`?ge(a)||r(n,`Unknown ${i} "${a}"${Tn(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}"${Tn(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}var On=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function kn(e){for(let[t,n]of Object.entries(e))if(fn.includes(t)&&n)return[t,n.trim()]}function An(e,t){let n=new Map;for(let r of e.nodes.values()){let i=tt(e,r),a=kn(i);if(!a)continue;let[o,s]=a,c=On(r,o);for(let e of Object.keys(i))e!==o&&fn.includes(e)&&r.ref&&t(On(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}"${Tn(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=kn(tt(e,s))[0];s.ref&&t(On(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}var jn=e=>e.toLowerCase().replace(/\d+/g,`#`);function Mn(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:jn(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=jn(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]=wn(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 Nn(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&&En(t.props,mn,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});An(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),En(t.props,hn,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&En(t.props,gn,`group`,t.ref.line,n,t.ref.propLines);Mn(e,n);let i=pe(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}"${Tn(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of vn)a[t]&&yn(a[t])&&n(e,`Unknown ${t} "${a[t]}"${bn(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!ge(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!M.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${M.join(`, `)})`),Dn(a,t?.(r.kind),e,n)}let a=[...new Set([...mn,...hn,...gn])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&En(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}var Pn=Object.keys(ue),Fn=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`]),In=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`}),Ln=new Map,Rn=new Map,zn=[],Bn=l({direction:[`right`,`down`,`left`,`up`],curve:[`smooth`,`orthogonal`,`straight`],panels:[`row`,`column`,`grid`,`wrap`]}),Vn=l({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),Hn=new Set([...f,`violet`]),Un=new Set([`smooth`,`orthogonal`,`straight`]),Wn=e=>Gt.has(e)||e in Zt,Gn=e=>/\.(yu|yuhwa)$/i.test(e);function Kn(e,t){if(/^[a-z][a-z0-9+.-]*:/i.test(t))return t;let n=t.startsWith(`/`)||!e?``:e.replace(/[^/]*$/,``),r=(n+t).startsWith(`/`),i=[];for(let e of(n+t).split(`/`))if(e&&e!==`.`){if(e===`..`&&i.length&&i[i.length-1]!==`..`)i.pop();else if(e===`..`&&r)continue;else i.push(e)}return(r?`/`:``)+i.join(`/`)}var qn=new Set([`top`,`right`,`bottom`,`left`,`auto`]),Jn=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,Yn=/^(<)?(--|-|\.\.|==|=)(>)?/,Xn=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,Zn=/^-?\d+(?:\.\d+)?/;function Qn(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
5
+ `:t===`t`?` `:t)}function $n(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:Qn(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(Xn)){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(Jn)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Zn)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Yn)){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 er(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 tr(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function nr(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)`),{}):B(e.value)}var rr=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function B(e=``){let t={},n=[],r=``,i=null,a=0;for(let t=0;t<e.length;t++){let o=e[t];i?(r+=o,o===`\\`?r+=e[++t]??``:o===i&&(i=null)):o===`"`||o===`'`?(i=o,r+=o):o===`(`?(a++,r+=o):o===`)`?(a=Math.max(0,a-1),r+=o):(o===`,`||o===`;`)&&!a?(n.push(r),r=``):r+=o}n.push(r);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`);if(r<0){let e=n.toLowerCase();Hn.has(e)?t.color=e:Wn(e)?t.shape=e:Un.has(e)?t.curve=e:ge(n)?t.color=n:t[e]=`true`;continue}let i=rr(n.slice(0,r)),a=n.slice(r+1).trim();/^(["']).*\1$/s.test(a)&&(a=Qn(a.slice(1,-1))),t[i]=a}return t}var ir=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},ar=/(?<!\[)\[([^[\]]*)\]\s*$/;function or(e,t){let n=e.match(ar),r=n?B(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function sr(e,t,n){let r=rr(t),[i,a]=or(e);n===null?delete a[r]:a[r]=n;let o=i.replace(/\s+$/,``),s=ur(a);return s?`${o} [${s}]`:o}var cr=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&ge(e.color)};function lr(e,t,n,r,i){let a=rr(n),[o,s]=or(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}=B(n),l=ur(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=ur(s);return u?`${l} [${u}]`:l}function ur(e){return Object.entries(e).map(([e,t])=>t===`true`&&!Hn.has(e)&&!Wn(e)&&!Un.has(e)&&!ge(e)?e:e===`color`&&ge(t)&&!Wn(t)&&!Un.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(t)?br(t):t}`).join(`, `)}function dr(e){let t=e.match(Yn),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 fr=1e5,pr=5e4,mr=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,hr=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,gr=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,_r=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,vr=new WeakMap;function yr(e){let t=[],n=``,r=null,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(r)o===`\\`?n+=o+(e[++a]??``):(n+=o,o===r&&(r=null));else{if(o===`"`||o===`'`)r=o;else if(`[({`.includes(o))i++;else if(`])}`.includes(o))i--;else if(o===`,`&&!i){t.push(n.trim()),n=``;continue}n+=o}}return(n.trim()||t.length)&&t.push(n.trim()),t}var br=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,xr=e=>/^(["']).*\1$/s.test(e.trim())?Qn(e.trim().slice(1,-1)):e.trim();function Sr(e,r={}){let i={settings:{},nodes:new Map,edges:[],groups:new Map,classes:l({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},a=e.split(/\r?\n/),o=r.seen??=new Set;r.file&&o.add(r.file);let s=new Map,u=[],d=(e,t)=>u.push([e,t]),p=!1,m=[],h=new Map,g=(e,t,n=`warning`)=>i.diagnostics.push({line:e+1,message:t,severity:n}),_,v=(e,t,n,r)=>{if(!(t in ue))return g(r,`Unknown theme key "${t}"${Tn(t,Pn)||` (keys: ${Pn.join(`, `)})`}`);ue[t].kind!==`color`||[`none`,`transparent`].includes(n)||n.includes(`$`)||ge(n)||g(r,`Unknown color "${n}" for ${t}${Tn(n,f)}`),e[t]=n},y=new Map,b=(e,t,n)=>{y.has(e)&&g(n,`Theme "${e}" is defined twice`),(i.themes??=l({}))[e]=t,y.set(e,n)},x=()=>{for(let e=m.length-1;e>=0;e--)if(m[e].kind===`group`)return m[e].id},S=e=>{let t=i.nodes.get(e);return t||(t={id:e,label:e,props:{},classes:[],implicit:!0,group:x()},i.nodes.set(e,t)),t},C=new Map,w=(e,t,n,r)=>{let i=t.value;e.labelRef={line:n,at:t.start,range:[t.start,t.end],generated:A||void 0};let a=C.get(e.id);a!==void 0&&e.label!==i&&g(n,`"${e.id}" already has the label "${e.label}" (line ${a+1}); this renames it to "${i}"`+(r?`. For an edge label write: ... -> ${e.id}: ${i}`:``)),e.label=i,C.set(e.id,n)},T=new Map,E=(e,t,n)=>{if(!r.resolve)return g(t,`Cannot import "${e}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let a=Kn(r.file,e);if(!Gn(a))return g(t,`Cannot import "${e}": imports must be .yu files`,`error`);let s=[...r.chain??(r.file?[r.file]:[])];if(s.includes(a))return g(t,`Import cycle: ${[...s,a].join(` -> `)}`,`error`);let c=n?`${a}{${n.map(e=>e.join(` as `)).join(`,`)}}`:a;if(o.has(c))return;let l;try{l=r.resolve(a)}catch{l=void 0}if(l===void 0)return g(t,`Cannot import "${e}": file not found (${a})`,`error`);let u=new Set(o),d=Sr(l,{resolve:r.resolve,file:a,chain:[...s,a],seen:u});for(let n of d.diagnostics)g(t,`${e}:${n.line}: ${n.message}`,n.severity);let f=wr(d,n,n=>g(t,`${e}: ${n}`,`error`));if(f===d)for(let e of u)o.add(e);o.add(c),Tr(i,f,h),(i.imports??=[]).push(a,...d.imports??[])},D=i.vars=l({}),O=i.defs=l({}),k=i.used=new Set;vr.set(O,O);let A=!1,ee=0,te=0,ne=new Set,re=null,j=e=>e.match(/^\s*/)[0].length,M=(e,t,n,r=!1)=>{let i=e.match(hr);if(i)return e.slice(0,e.length-i[2].length)+M(i[2],t,n,r);let a=e.length,o=e.replace(mr,(e,i,o)=>{let s=i??o;if(!s)return`$`;let c=n?.[s]??D[s];return n?.[s]===void 0&&c!==void 0&&k.add(`$`+s),c===void 0?(r||g(t,`Unknown variable "$${s}"${Tn(s,[...Object.keys(n??{}),...Object.keys(D)])}`),e):(a+=c.length)>fr?e:c});return a>fr&&g(t,`Variables make this line longer than ${fr} characters`,`error`),o},ie=(e,t,n)=>{if(ee>=16){ne.has(e.name)||g(n,`${e.name}(): calls nest too deep`,`error`),ne.add(e.name);return}if((te+=e.body.length)>pr){te-e.body.length<=pr&&g(n,`${e.name}(): components expand to more than ${pr} lines`,`error`);return}let r=yr(t),i=l({}),a=0;for(let t of r){let o=t.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(o&&e.params.some(e=>e.name===o[1]))i[o[1]]=xr(o[2]);else if(a<e.params.length)i[e.params[a++].name]=xr(t);else return void g(n,`${e.name}() takes ${e.params.length} argument(s), got ${r.length}`,`error`)}for(let t of e.params)if(!(t.name in i)){if(t.default===void 0)return void g(n,`${e.name}(): missing argument "${t.name}" (${e.params.map(e=>e.name).join(`, `)})`,`error`);i[t.name]=t.default}let o=m.length,s=A;A=!0,ee++;let c=e.body.map(e=>M(e,n,i)),u=vr.get(e)??O;for(let e of c)ae(e,n,!0,u);ee--,A=s,m.length>o&&(g(n,`${e.name}(): a block inside the component is not closed`,`error`),m.length=o)},ae=(e,t,n=!1,r=O)=>{if(/^\s*#(\s|$)/.test(e))return void g(t,`Comments start with "//", not "#"`,`error`);let a=m[m.length-1];if(a?.kind===`def`){for(let t of er($n(e).tokens))a.depth+=t===`{`?1:-1;if(a.depth>0)return void a.lines.push(e);m.pop(),e.trim()!==`}`&&g(t,`Expected "}" alone on the line that closes ${a.id}()`,`error`);let n=a.params,o=l(Object.fromEntries(n.map(e=>[e.name,`\${${e.name}}`]))),s={name:a.id,params:n,body:ze(a.lines).map(e=>M(e,t,o,!0))};vr.set(s,r),O[s.name]&&g(a.start,`Component "${s.name}" is defined twice`),O[s.name]=s,(i.defLines??={})[s.name]=a.start;return}let o=a?.kind===`body`||a?.kind===`panel`;if(!o&&a?.kind!==`layout`){let a=e.match(hr);if(a){D[a[1]]=xr(ir(n?a[2]:M(a[2],t)).trimEnd()),(i.varLines??={})[a[1]]=t;return}let o=e.match(gr);if(o){m.length&&g(t,`def must be at the top level`,`error`);let e=yr(o[2]).map(e=>{let n=e.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return n||g(t,`Bad parameter "${e}": def name(a, b = "default") {`,`error`),{name:n?.[1]??e,default:n?.[2]===void 0?void 0:xr(n[2])}});m.push({kind:`def`,id:o[1],start:t,lines:[],depth:1,params:e});return}let s=ir(e).match(_r);if(s){let i=r[s[1]]??O[s[1]];if(i){k.add(s[1]),ie(i,n?s[2]:M(s[2],t),t);return}if(!$n(e).tokens.some(e=>e.kind===`arrow`))return void g(t,`Unknown component "${s[1]}"${Tn(s[1],Object.keys(O))}`,`error`)}}let s=n||a?.kind===`layout`||!o&&/^\s*(import|export)\b/.test(e)?e:M(e,t,void 0,o),c=A;A||=s!==e,Te(s,t),A=c},oe=(e,t,n)=>{if(t.trim()===`}`){m.pop();let t=i.nodes.get(e.id);t.body=ze(e.lines),t.bodyLines=[e.start,n]}else e.lines.push(t)},se=(e,t,n)=>{t.trim()===`}`?(m.pop(),ce(e,n)):e.lines.push(t.slice(0,$n(t).codeEnd).trimEnd())},ce=(e,t)=>{let r=e.panel,i=e.lines.findIndex(e=>e.trim());r.body=ze(e.lines),r.lines=[e.start,t];try{r.data=Ln.get(r.kind).parse(r.body,r.props,(t,n)=>g(t<0?e.start:e.start+1+Math.max(0,i)+t,n))}catch(t){let i=c(`panel`,r.kind);g(e.start,`${i?`plugin "${i}": `:``}${r.kind} panel failed to parse: ${n(t)}`,`error`),r.failed=!0}},le=(e,t,n)=>{let r=t.slice(0,$n(t).codeEnd).trim();if(!r)return;if(r===`}`){m.pop(),b(e.id,e.props,e.start);return}let i=r.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);if(!i)return void g(n,`Expected "key: value" in theme ${e.id} (keys: ${Pn.join(`, `)})`,`error`);v(e.props,i[1].toLowerCase(),xr(i[2].trim()),n)},de=(e,t)=>{let n=e.slice(0,$n(e).codeEnd).trim();n&&(n.startsWith(`}`)?(m.pop(),i.layoutBlock[1]=t):(T.set(n.split(/\s+/)[0],t),Or(n,t,i,g)))},fe=e=>{m.length?m.pop():g(e,`Unmatched "}"`,`error`),re=null},me=(e,t,n)=>{if(m.length)g(t,`import must be at the top level`,`error`);else if(!e[1])g(t,`import needs a path: import "./shared.yu"`,`error`);else if(!n)e.length>2&&g(t,`Unexpected "${e[2].value}" after import path`,`error`),E(e[1].value,t);else{let n=Cr(e,t,g);n&&E(n.path,t,n.names)}},he=(e,t,n)=>{m.length&&g(n,`export must be at the top level`,`error`);let r=e[1].kind===`ident`&&e[2]?.value===`:`&&Fn.has(e[1].value.toLowerCase());if(r||e[1].value===`theme`&&e[2]?.kind===`ident`){let a=e[1].value.toLowerCase();return r&&!i.sharedSettings?.includes(a)&&(i.sharedSettings??=[]).push(a),ae(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)}p=!0;let a=e.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),o=e=>s.has(e)||s.set(e,n);if(e[1].value===`def`&&e[2])o(e[2].value);else if(e[1].value.startsWith(`$`)&&(e[2]?.value===`:`||e[2]?.value===`=`))o(e[1].value);else for(let t of e.slice(1))(t.kind===`ident`||t.kind===`class`)&&o(t.kind===`class`?`.${t.value}`:t.value);if(!a||e.slice(1).some(e=>e.kind===`ident`&&Ln.has(e.value)))return ae(t.slice(0,e[0].start)+` `.repeat(6)+t.slice(e[0].end),n)},_e=(e,t)=>{m.length&&g(t,`theme must be at the top level`,`error`);let n={},r=2;if(e[r]?.kind===`props`){for(let[i,a]of Object.entries(B(e[r].value)))v(n,i,a,t);r++}if(e[r]?.value===`{`){if(r++,e[r]?.value===`}`)r++;else if(r===e.length)return void m.push({kind:`theme`,id:e[1].value,start:t,props:n})}r<e.length&&g(t,`Unexpected "${e[r].value}" in theme ${e[1].value}`,`error`),b(e[1].value,n,t)},N=(e,t)=>{g(t,`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind (${[...Ln.keys()].join(`, `)})`+(In[e[0].value]&&Ln.has(In[e[0].value].split(` `)[0])?`: write "${In[e[0].value].replace(`ID`,e[1].value)} {"`:``))},ve=(e,t)=>{let n=e[0].value,r=1,a=e[r]?.kind===`ident`?e[r++].value:`${n}${i.panels.length+1}`,o=A?void 0:e[r]?.kind===`string`?{line:t,at:e[r].start,range:[e[r].start,e[r].end]}:{line:t,at:e[r-1].end},s=e[r]?.kind===`string`?e[r++].value:void 0,c={line:t,insertAt:e[r-1].end},l={};e[r]?.kind===`props`&&(l=B(e[r].value),c.props=[e[r].start,e[r].end],r++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,r!==e.length-1&&g(t,`Unexpected "${e[r].value}" in ${n} header`,`error`),m.length&&g(t,`${n} must be at the top level`,`error`);let u={kind:n,id:a,label:s,props:l,body:[],data:void 0,ref:A?void 0:c,labelRef:o};i.panels.push(u),m.push({kind:`panel`,id:a,start:t,lines:[],panel:u})},ye=(e,t)=>{m.length&&g(t,`layout block must be at top level`,`error`),i.layoutBlock=[t,t],e[2]?.value!==`}`&&m.push({kind:`layout`})},be=(e,t,n)=>{let r=2,a=e[1].value;e[1].kind===`string`&&(a=e[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,r=1);let o=i.groups.get(a)??{id:a,label:a,props:{},parent:x()};if(e[r]?.kind===`string`){let t=e[r++];o.label=t.value,o.labelRef={line:n,at:t.start,range:[t.start,t.end],id:r===2?a:void 0}}else o.labelRef??={line:n,at:e[1].end};for(A&&(o.labelRef.generated=!0);e[r]?.kind===`class`;)d(e[r].value,n),(o.classes??=[]).push(e[r++].value);let s={line:n,insertAt:e[r-1].end,generated:A||void 0};if(e[r]?.kind===`props`&&(Object.assign(o.props,B(e[r].value)),s.props=[e[r].start,e[r].end],r++),o.ref=s,re={indent:j(t),targets:[o]},i.groups.set(a,o),e[r]?.value!==`{`){g(n,`Expected "{" after group ${a}`,`error`);return}r++;let c=e.findIndex((e,t)=>t>=r&&e.value===`}`);if(c>=0){for(let t=r;t<c;t++)if(e[t].kind===`ident`){let n=S(e[t].value);n.group=a}}else m.push({kind:`group`,id:a})},xe=(e,t,n)=>{let r=e[e.length-1],a={};for(let t of e.slice(1))t.kind===`class`&&(i.classes[t.value]?Object.assign(a,i.classes[t.value]):g(n,`Unknown class ".${t.value}"${Tn(t.value,Object.keys(i.classes))}`));i.classes[e[0].value]={...i.classes[e[0].value],...a,...r.kind===`props`?B(r.value):{}},(i.classLines??={})[e[0].value]=n,re={indent:j(t),targets:[{props:i.classes[e[0].value]}]}},Se=(e,t,n,r,a)=>{let o=rr(e[0].value),s=t.slice(e[1].end,r).trim();/^(["']).*\1$/.test(s)&&(s=Qn(s.slice(1,-1)));let c=re&&j(t)>re.indent?re.targets:null,l=a?.kind===`group`?i.groups.get(a.id):void 0,u=c??(l?[l]:null);if(u){for(let e of u)e.props[o]=s||`true`,e.ref&&!A&&((e.ref.propLines??={})[o]=n);return}if(m.length&&g(n,`Setting "${o}" should be at the top level`),!Fn.has(o)){let t=e[0].value,r=s.startsWith(`{`)?`${t} [${s.slice(1,-1).trim()}]`:`${t} "${s}"`;g(n,`Unknown setting "${o}"${Tn(o,[...Fn])||`. For a node write ${r}`}`);return}o===`direction`&&(s=Vn[s.toLowerCase()]??s),o===`theme`&&(_=n);let d=o===`theme`?void 0:Bn[o];d&&s&&!s.includes(`$`)&&!d.includes(s)&&g(n,`Unknown ${o} "${s}"${Tn(s,d)||` (use one of: ${d.join(`, `)})`}`),i.settings[o]=s},Ce=(e,t,n,r)=>{let a=i.edges.length;if(Er(e,n,t.slice(0,r),i,S,h,g,w,d),re={indent:j(t),targets:i.edges.slice(a)},A){for(let e of i.edges.slice(a))e.ref&&(e.ref.generated=!0),e.labelRef&&(e.labelRef.generated=!0);for(let t of e)if(t.kind===`ident`){let e=i.nodes.get(t.value);e?.ref?.line===n&&(e.ref.generated=!0),e?.labelRef?.line===n&&(e.labelRef.generated=!0)}}},we=(e,t,n)=>{let r=0,i=!0;for(;r<e.length;){let a=e[r];if(a.kind===`punct`&&a.value===`,`){r++,i=!0;continue}if(!i&&a.kind===`ident`){let t=[e[r-1].value];for(;e[r]?.kind===`ident`;)t.push(e[r++].value);let i=t.join(` `),a=t[0].toLowerCase();g(n,a===`subgraph`||a===`end`?`"${t[0]}" is Mermaid syntax: write group id "Label" { ... }`:`"${i}" looks like a label: write ${t.join(`_`).toLowerCase()} "${i}" (or separate nodes with commas)`,`error`);break}if(a.kind===`punct`&&a.value===`{`&&r===e.length-1&&r>0&&e[r-1].kind!==`punct`){let t=e.slice(0,r).reverse().find(e=>e.kind===`ident`);m.push({kind:`body`,id:t.value,start:n,lines:[]});break}if(a.kind!==`ident`){g(n,`Unexpected "${a.value}"`,`error`);break}i=!1;let o=S(a.value);o.implicit=!1;let s=x();for(s&&o.group&&o.group!==s&&g(n,`"${a.value}" is already in group "${o.group}": a node lives in one group, so it moves to "${s}"`),s&&(o.group=s),r++,e[r]?.kind===`string`?w(o,e[r++],n,!1):o.labelRef??={line:n,at:a.end,generated:A||void 0};e[r]?.kind===`class`;){let t=e[r++].value;d(t,n),o.classes.includes(t)||o.classes.push(t)}let c={line:n,insertAt:e[r-1].end,generated:A||void 0};e[r]?.kind===`props`&&(tr(o,nr(e[r],o.id,n,g),n),c.props=[e[r].start,e[r].end],r++),o.ref=c,re={indent:j(t),targets:[o]}}},Te=(e,t)=>{let n=m[m.length-1];if(n?.kind===`body`)return oe(n,e,t);if(n?.kind===`panel`)return se(n,e,t);if(n?.kind===`theme`)return le(n,e,t);if(n?.kind===`layout`)return de(e,t);let{tokens:r,codeEnd:a}=$n(e);if(!r.length)return;let o=/^\s*%%/.test(e)?`Comments start with # or //`:/(--|==|-\.|->|=>)\|[^|]*\|/.test(e)?`Edge labels go after a colon: a -> b: label`:void 0;if(o)return void g(t,o,`error`);if(r[0].kind===`punct`&&r[0].value===`}`)return fe(t);let s=r[0].kind===`ident`?r[0].value:void 0,c=r[1]?.value===`{`&&r.some(e=>e.kind===`ident`&&e.value===`from`);if(s===`import`&&(r[1]?.kind===`string`||r.length===1||c))return me(r,t,c);if(s===`export`&&r.length>1&&r[1].kind!==`arrow`&&r[1].value!==`:`)return he(r,e,t);let l=s===void 0?void 0:Rn.get(s);if(l&&r[1]?.kind!==`arrow`&&r[1]?.value!==`:`&&r[1]?.value!==`,`)return void l.parse(e.slice(r[0].end,a).trim(),i,{line:t,warn:(e,n)=>g(t,e,n)});if(s===`theme`&&r[1]?.kind===`ident`&&(r[2]?.kind===`props`||r[2]?.value===`{`))return _e(r,t);let u=r[r.length-1].value===`{`;if(s!==void 0&&r.length>2&&!Ln.has(s)&&r[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&N(r,t),s!==void 0&&Ln.has(s)&&u&&(r[1]?.kind===`ident`||r[1]?.kind===`string`||r[1]?.kind===`props`||r[1]?.value===`{`))return ve(r,t);if(s===`layout`&&r[1]?.value===`{`)return ye(r,t);if(s===`group`&&(r[1]?.kind===`ident`||r[1]?.kind===`string`&&r.some(e=>e.value===`{`)))return be(r,e,t);let d=r[r.length-1];if(r[0].kind===`class`&&r.slice(1,-1).every(e=>e.kind===`class`)&&(d.kind===`props`||d.kind===`class`))return xe(r,e,t);if(s!==void 0&&r[1]?.kind===`punct`&&r[1].value===`:`)return Se(r,e,t,a,n);if(r.some(e=>e.kind===`arrow`))return Ce(r,e,t,a);we(r,e,t)};for(let e=0;e<a.length;e++)ae(a[e],e);for(let e of m)e.kind===`group`?g(a.length-1,`Group "${e.id}" is missing "}"`,`error`):e.kind===`body`?g(e.start,`Body of "${e.id}" is missing a closing "}" line`,`error`):e.kind===`panel`?(g(e.start,`${e.panel.kind} "${e.id}" is missing a closing "}" line`,`error`),ce(e,a.length-1)):e.kind===`def`?g(e.start,`def ${e.id}() is missing "}"`,`error`):e.kind===`theme`?g(e.start,`theme ${e.id} is missing "}"`,`error`):g(a.length-1,`layout block is missing "}"`,`error`);let Ee=pe(i.themes);for(let[e,t]of y){let n=i.themes[e].base;n&&n!==e&&!Ee.includes(n)&&g(t,`Unknown base theme "${n}"${Tn(n,Ee)}`)}let De=i.settings.theme;_!==void 0&&De&&!De.includes(`$`)&&(Ee.includes(De)||g(_,`Unknown theme "${De}"${Tn(De,Ee)||` (use one of: ${Ee.join(`, `)})`}`));let Oe=new Set;for(let[e,t]of u)i.classes[e]||Oe.has(`${t}.${e}`)||(Oe.add(`${t}.${e}`),g(t,`Unknown class ".${e}"`));if(p){let e=new Set(i.panels.map(e=>e.id));i.exports=[...s.keys()].filter(t=>t.startsWith(`.`)?t.slice(1)in i.classes:t.startsWith(`$`)?t.slice(1)in D:i.nodes.has(t)||i.groups.has(t)||e.has(t)||t in O||t in(i.themes??{}));for(let[e,t]of s)!i.exports.includes(e)&&!Ln.has(e)&&e!==`group`&&e!==`def`&&g(t,`export: "${e}" is not declared in this file`)}for(let e of i.panels){i.nodes.get(e.id)?.implicit&&i.nodes.delete(e.id);let t=i.layout.nodes[e.id];t&&(t.x!==void 0&&t.y!==void 0&&(Dr(i,e.id).at={x:t.x,y:t.y}),delete i.layout.nodes[e.id])}let P=new Map;for(let e of i.panels){let t=P.get(e.id);t?e.lines&&g(e.lines[0],`panel id "${e.id}" is already used${t.lines?` on line ${t.lines[0]+1}`:` by an import`}: layout, edges and edits can't tell them apart, rename one`):P.set(e.id,e)}for(let[e,t]of i.groups)i.nodes.has(e)&&g(i.edges.find(t=>t.ref&&(t.from===e||t.to===e))?.ref?.line??t.ref?.line??0,`"${e}" is both a node and a group. Edges connect nodes, not groups: use a node inside "${e}", or rename one of them`);Nn(i,e=>Ln.get(e)?.options),r.chain||t(i.diagnostics,()=>zn.forEach(e=>e(i)));for(let e of Object.keys(i.layout.nodes)){let t=T.get(e);t!==void 0&&!i.nodes.has(e)&&!i.groups.has(e)&&g(t,`layout: there is no node "${e}" (renamed or deleted?); remove this line${Tn(e,[...i.nodes.keys()])}`)}return i}function Cr(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 wr(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},u={settings:{},nodes:new Map,edges:[],groups:new Map,classes:l({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]},d=e=>a.get(e)?.replace(/^\./,``)??e,f=e=>a.get(`.${e}`)?.slice(1)??e,p=new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(u.groups.set(d(t.id),{...t,id:d(t.id),parent:t.parent&&u.groups.has(d(t.parent))?d(t.parent):void 0,classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e)));let m=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(m(t.id)){let e=t.group&&u.groups.has(d(t.group))?d(t.group):void 0;u.nodes.set(d(t.id),{...t,id:d(t.id),group:e,classes:t.classes.map(f)}),t.classes.forEach(e=>p.add(e))}for(let t of e.edges)if(m(t.from)&&m(t.to)){let e=d(t.from)+`->`+d(t.to)+(t.key.match(/#\d+$/)?.[0]??``);u.edges.push({...t,key:e,from:d(t.from),to:d(t.to),classes:t.classes?.map(f)}),t.classes?.forEach(e=>p.add(e))}for(let t of e.panels)o.has(t.id)&&u.panels.push({...t,id:d(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(o.has(t))for(let e of n.body)for(let t of $n(e).tokens)t.kind===`class`&&p.add(t.value);u.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||o.has(e));for(let t of u.sharedSettings)u.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(o.has(`.${t}`)||p.has(t))&&(u.classes[f(t)]=n);u.vars={};for(let[t,n]of Object.entries(e.vars??{}))o.has(`$${t}`)&&(u.vars[(a.get(`$${t}`)??`$${t}`).slice(1)]=n);u.defs={};for(let[t,n]of Object.entries(e.defs??{}))o.has(t)&&(u.defs[a.get(t)??t]=n);return u.themes=e.themes,u}function Tr(e,t,n){for(let n of t.sharedSettings??[])!(n in e.settings)&&n in t.settings&&(e.settings[n]=t.settings[n]);for(let[n,r]of Object.entries(t.classes))e.classes[n]={...r,...e.classes[n]};for(let n of t.groups.values())e.groups.has(n.id)||e.groups.set(n.id,{...n,props:{...n.props},ref:void 0,labelRef:void 0});for(let n of t.nodes.values()){let t=e.nodes.get(n.id);if(!t)e.nodes.set(n.id,{...n,props:{...n.props},classes:[...n.classes],ref:void 0,labelRef:void 0,bodyLines:void 0});else{t.implicit&&!n.implicit&&(t.label=n.label,t.implicit=!1),t.props={...n.props,...t.props};for(let e of n.classes)t.classes.includes(e)||t.classes.push(e);t.group??=n.group,!t.body&&n.body&&(t.body=n.body)}}for(let r of t.edges){let t=`${r.from}->${r.to}`,i=(n.get(t)??0)+1;n.set(t,i),e.edges.push({...r,key:i===1?t:`${t}#${i}`,ref:void 0,labelRef:void 0})}for(let n of t.panels)e.panels.push({...n,lines:void 0,ref:void 0,labelRef:void 0});for(let[n,r]of Object.entries(t.data??{}))n in(e.data??={})||(e.data[n]=r);t.layout.ranks?.length&&(e.layout.ranks??=[]).push(...t.layout.ranks);for(let[n,r]of Object.entries(t.vars??{}))(e.vars??={})[n]??=r;for(let[n,r]of Object.entries(t.defs??{}))(e.defs??={})[n]??=r;for(let[n,r]of Object.entries(t.themes??{}))(e.themes??=l({}))[n]??=r}function Er(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`?(tr(h,nr(e[l],f,t,o),t),g&&(h.ref={line:t,props:[e[l].start,e[l].end],insertAt:e[l].start}),l++):l>p&&g&&(h.ref={line:t,insertAt:e[l-1].end}),l>p&&(h.implicit=!1),l>p&&g&&!h.labelRef&&(h.labelRef={line:t,at:e[p-1].end})}return a},f=d();if(!f.length){o(t,`Edge needs a source node`,`error`);return}let p=[];for(;l<e.length&&e[l].kind===`arrow`;){let n=e[l++].value,r=d(!0);if(!r.length){o(t,`Edge "${n}" needs a target node`,`error`);return}p.push({from:f,to:r,arrow:n}),f=r}let m,h=[],g={},_={line:t,insertAt:e[l-1].end,prefix:`:`},v={line:t,at:e[l-1].end,colon:!1};if(e[l]?.kind===`punct`&&e[l].value===`:`){_.insertAt=v.at=e[l].end,v.colon=void 0,_.prefix=void 0,l++;let r=l;for(;l<e.length&&e[l].kind!==`class`&&e[l].kind!==`props`;)l++;for(l>r&&(m=l-r===1&&e[r].kind===`string`?e[r].value:n.slice(e[r].start,e[l-1].end).trim(),_.insertAt=e[l-1].end,v.range=[e[r].start,e[l-1].end]);e[l]?.kind===`class`;)c(e[l].value,t),h.push(e[l].value),_.insertAt=e[l++].end;e[l]?.kind===`props`&&(g=B(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=dr(e.arrow);for(let n of e.from)for(let i of e.to){let e=n,o=i,s=t.start,c=t.end;s&&!c&&([e,o]=[o,e],[s,c]=[!1,!0]);let l=`${e}->${o}`,u=(a.get(l)??0)+1;a.set(l,u);let d={key:u===1?l:`${l}#${u}`,from:e,to:o,label:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(d)}}}var Dr=(e,t)=>(e.layout.panels??={})[t]??={};function Or(e,t,n,r){let i=e.replace(/\s*->\s*/g,`->`).split(/\s+/),a=i[0],o=(e,t)=>{let n=[];for(let r=0;r<t;r++){let t=Number(i[e+r]);if(!Number.isFinite(t))return null;n.push(t)}return n},s=1;if(a===`rank`&&i[1]!==`at`&&i[1]!==`size`){let e=i.slice(1).filter(Boolean);if(e.length<2)return r(t,`rank needs two or more node ids: rank a b c`);(n.layout.ranks??=[]).push(e);return}if(a.includes(`->`)){let e=a.match(/^(.+?)->(.+?)(?:#(\d+))?$/);if(!e)return r(t,`Bad edge key "${a}"`);let c=`${e[1]}->${e[2]}${e[3]&&e[3]!==`1`?`#`+e[3]:``}`,l=n.layout.edges[c]??={};for(;s<i.length;){let e=i[s++];if(e===`via`)for(l.via=[];s+1<i.length&&Number.isFinite(Number(i[s]))&&Number.isFinite(Number(i[s+1]));)l.via.push({x:Number(i[s]),y:Number(i[s+1])}),s+=2;else if(e===`label`){let e=o(s,2);if(!e)return r(t,`label expects two numbers: dx dy`);l.label={x:e[0],y:e[1]},s+=2}else if(e===`ports`){let e=i[s],n=i[s+1];if(!qn.has(e)||!qn.has(n))return r(t,`ports expects two sides: top|right|bottom|left|auto`);l.ports=[e,n],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}return}let c=a.indexOf(`:`);if(c>0){let s=a.slice(0,c),l=a.slice(c+1),u=i[1]===`offset`?2:1,d=i.length-u,f=l&&(d===1||d===2)?o(u,d):null;if(!f)return r(t,`Bad panel part "${e.trim()}" (expected panel:part d, or panel:part dx dy)`);(Dr(n,s).parts??={})[l]={x:f[0],y:f[1]??0};return}if(n.panels.some(e=>e.id===a)){let e=i[1]===`at`&&i.length===4?o(2,2):null;if(!e)return r(t,`panel "${a}" takes only "at x y" in layout (its content sets the size)`);Dr(n,a).at={x:e[0],y:e[1]};return}let l=n.layout.nodes[a]??={};for(;s<i.length;){let e=i[s++];if(e===`at`){let e=o(s,2);if(!e)return r(t,`at expects two numbers: x y`);l.x=e[0],l.y=e[1],s+=2}else if(e===`size`){let e=o(s,2);if(!e)return r(t,`size expects two numbers: width height`);l.w=e[0],l.h=e[1],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}}function kr(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function Ar(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 jr(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 Mr={plugins:[],rows:[],frames:new Map,decorations:[],panels:Ln},Nr=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)},Pr=(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)}},Fr=()=>{},Ir=()=>``,Lr=()=>({w:0,h:0}),Rr={row:{parse:()=>null,finish:Fr,measure:Lr,render:Ir},frame:{inset:()=>({top:0}),render:Ir},decoration:{measure:()=>null,render:Ir},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:Ir,inset:()=>0},panel:{measure:Lr,render:Ir,handles:()=>[],parts:()=>[],editPart:()=>null},hook:{transform:Fr,afterLayout:Fr,postRender:e=>e}};function zr(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 Br(e){let t=e.name,n=(e,n,r)=>(e??[]).map(e=>zr(t,t=>n(e,t),e,r));return{rows:n(e.rows,e=>`row "${e.kind}"`,Rr.row),frames:n(e.frames,e=>`frame "${e.name}"`,Rr.frame),decorations:n(e.decorations,e=>`decoration "${e.name}"`,Rr.decoration),shapes:n(e.shapes,e=>`shape "${e.name}"`,Rr.shape),markers:n(e.markers,e=>`marker "${e.name}"`,Rr.marker),panels:n(e.panels,(e,t)=>`${e.name} panel ${t===`editPart`?`edit`:t}`,Rr.panel),statements:(e.statements??[]).map(e=>({...e,parse:i(t,e.keyword,e.parse.bind(e),Fr,(e,[,,t])=>t.warn(e,`error`))})),hooks:zr(t,e=>e,{transform:e.transform,afterLayout:e.afterLayout,postRender:e.postRender},Rr.hook)}}var Vr;function Hr(){let e=[Fn].map(e=>[e,[...e]]),t=[Ln,Rn,Gt,Kt,Mr.frames].map(e=>[e,[...e]]),n=[zn,qt,Jt,mn,hn,gn,xn,Sn,C,Xt,Mr.rows,Mr.decorations].map(e=>[e,[...e]]),r=Object.entries(_n).map(([e,t])=>[e,t,[...t]]),i={...S},a={...Zt};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(_n))delete _n[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),_n[e]=t;for(let e of Object.keys(S))delete S[e];Object.assign(S,i);for(let e of Object.keys(Zt))delete Zt[e];Object.assign(Zt,a),s()}}function Ur(e,t,n){let r=e.findIndex(n);r>=0?e[r]=t:e.push(t)}function Wr(...e){Vr??=Hr();for(let t of e){if(Mr.plugins.some(e=>e.name===t.name))continue;Mr.plugins.push(t);let e=Br(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)=>Ur(Mr.rows,e,e=>e.kind===t)),n(`decoration`,e.decorations,e=>e.name,(e,t)=>{Ur(Mr.decorations,e,e=>e.name===t),Fn.add(e.setting)}),n(`frame`,e.frames,e=>e.name,Mr.frames),n(`panel`,e.panels,e=>e.name,Ln),n(`statement`,e.statements,e=>e.keyword,Rn),n(`marker`,e.markers,e=>e.name,Kt),n(`shape`,e.shapes,e=>e.name,(e,t)=>{Gt.set(t,e),Xt.includes(t)||Xt.push(t);for(let n of e.aliases??[])Zt[n]=t}),Nr(_n.shape??=[],[...t.shapes?.map(e=>e.name)??[],...t.shapes?.flatMap(e=>e.aliases??[])??[]]),Pr(_n.head??=[],t.markers),_n.tail!==_n.head&&Pr(_n.tail??=[],t.markers);let{transform:r,afterLayout:i,postRender:a}=e.hooks;r&&zn.push(r),i&&qt.push(i),a&&Jt.push(a);for(let e of t.settings??[])Fn.add(e);Nr(mn,t.props?.node),Nr(hn,t.props?.edge),Nr(gn,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))Nr(_n[e]??=[],n);Nr(xn,t.bools),Nr(Sn,t.numbers)}Mr.frames.size&&Nr(_n.frame??=[],[...Mr.frames.keys()])}var Gr=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),Kr=new Set(`mwMW@%`.split(``)),qr=(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:Gr.has(t)?i+=.3:Kr.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},Jr=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,Yr;function Xr(e){return(t,n,r,i)=>{if(Yr===void 0)try{Yr=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{Yr=null}if(!Yr)return qr(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?Jr:e;return Yr.font=`${r} ${n}px ${a}`,Yr.measureText(t).width}}var Zr=(e,t)=>({w:e+44,h:t+28}),Qr=(e,t,n)=>sn(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*Math.sqrt(Math.max(0,1-n*n))),$r=({x:e,y:t,w:n,h:r})=>{let i=n/2,a=r/2;return`M${I(e+i-i)},${I(t+a)}a${I(i)},${I(a)} 0 1,0 ${I(i*2)},0a${I(i)},${I(a)} 0 1,0 ${I(-i*2)},0Z`},ei=(e,t)=>Math.min(t,e.w/2,e.h/2),ti={name:`shapes`,shapes:[{name:`rounded`,aliases:[`round`],path:(e,t)=>an(e.x,e.y,e.w,e.h,ei(e,t))},{name:`box`,aliases:[`rect`,`rectangle`,`square`],path:(e,t)=>an(e.x,e.y,e.w,e.h,Math.min(ei(e,t),3))},{name:`pill`,aliases:[`stadium`,`capsule`],size:(e,t)=>{let{w:n,h:r}=Zr(e,t);return{w:Math.max(n+8,96),h:Math.max(r,44)}},path:e=>an(e.x,e.y,e.w,e.h,e.h/2),port:(e,t,n)=>sn(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:$r,port:Qr},{name:`ellipse`,aliases:[`oval`],size:(e,t)=>({w:Math.max((e+16)*1.42,90),h:Math.max((t+12)*1.42,50)}),path:$r,port:Qr},{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${I(e+n/2)},${I(t)}L${I(e+n)},${I(t+r/2)}L${I(e+n/2)},${I(t+r)}L${I(e)},${I(t+r/2)}Z`,port:(e,t,n)=>sn(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*(1-Math.abs(n)))},{name:`hexagon`,size:(e,t)=>{let{w:n,h:r}=Zr(e,t),i=Math.max(r,48);return{w:n+i*.4,h:i}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(r*.3,n/4);return`M${I(e+i)},${I(t)}L${I(e+n-i)},${I(t)}L${I(e+n)},${I(t+r/2)}L${I(e+n-i)},${I(t+r)}L${I(e+i)},${I(t+r)}L${I(e)},${I(t+r/2)}Z`},port:(e,t,n)=>sn(e,t,n,.55,(t,n)=>t?e.h/2:e.w/2-Math.min(e.h*.3,e.w/4)*Math.abs(n))},{name:`cylinder`,aliases:[`database`,`db`,`storage`],textOffset:5,size:(e,t)=>{let{w:n,h:r}=Zr(e,t);return{w:Math.max(n,96),h:Math.max(r+18,66)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6),a=n/2;return`M${I(e)},${I(t+i)}a${I(a)},${I(i)} 0 0,1 ${I(n)},0L${I(e+n)},${I(t+r-i)}a${I(a)},${I(i)} 0 0,1 ${I(-n)},0Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6);return`M${I(e)},${I(t+i)}a${I(n/2)},${I(i)} 0 0,0 ${I(n)},0`},port:(e,t,n)=>sn(e,t,n,.75,(t,n)=>{if(!t)return e.w/2;let r=Math.min(9,e.h/6);return e.h/2-r+r*Math.sqrt(Math.max(0,1-n*n))})},{name:`parallelogram`,aliases:[`io`],size:(e,t)=>{let{w:n,h:r}=Zr(e,t);return{w:n+24,h:Math.max(r,48)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(16,n/5);return`M${I(e+i)},${I(t)}L${I(e+n)},${I(t)}L${I(e+n-i)},${I(t+r)}L${I(e)},${I(t+r)}Z`}},{name:`document`,aliases:[`doc`],textOffset:-4,size:(e,t)=>{let{w:n,h:r}=Zr(e,t);return{w:Math.max(n,96),h:Math.max(r+10,56)}},path:(e,t)=>{let{x:n,y:r,w:i,h:a}=e,o=ei(e,t),s=Math.min(8,a/6);return`M${I(n+o)},${I(r)}L${I(n+i-o)},${I(r)}Q${I(n+i)},${I(r)} ${I(n+i)},${I(r+o)}L${I(n+i)},${I(r+a-s)}C${I(n+i*.75)},${I(r+a-s*3)} ${I(n+i*.25)},${I(r+a+s)} ${I(n)},${I(r+a-s)}L${I(n)},${I(r+o)}Q${I(n)},${I(r)} ${I(n+o)},${I(r)}Z`}},{name:`note`,aliases:[`sticky`],size:(e,t)=>{let{w:n,h:r}=Zr(e,t);return{w:Math.max(n+8,96),h:Math.max(r,48)}},path:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${I(e)},${I(t)}L${I(e+n-i)},${I(t)}L${I(e+n)},${I(t+i)}L${I(e+n)},${I(t+r)}L${I(e)},${I(t+r)}Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${I(e+n-i)},${I(t)}L${I(e+n-i)},${I(t+i)}L${I(e+n)},${I(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,ei(e,t))}]},ni=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return(t,i)=>`${I(e.x+t*n-i*r)},${I(e.y+t*r+i*n)}`},ri={name:`markers`,markers:[{name:`arrow`,inset:e=>e*.8,render(e,t,{color:n,width:r,size:i}){let a=ni(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="${I(r*.5)}" stroke-linejoin="round"/>`}},{name:`open`,inset:(e,t)=>t*.8,render(e,t,{color:n,width:r,size:i}){let a=ni(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="${I(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]=ni(e,t)(-i,0).split(`,`);return`<circle cx="${a}" cy="${o}" r="${I(i)}" fill="${n}"/>`}},{name:`diamond`,inset:e=>e*1.6,render(e,t,{color:n,size:r}){let i=ni(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=ni(e,t);return`<path d="M${a(-4,i*.6)}L${a(-4,-i*.6)}" stroke="${n}" stroke-width="${I(r*1.2)}" stroke-linecap="round"/>`}}]},ii={name:`themes`,themes:[de(`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)},de(`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)},de(`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)`}),de(`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)}]},ai=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function oi(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)=>Ve(e,t.theme,t.theme.accent),ci=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${_e}))?:\\s*(.*)$`)),li={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=ci(`bars`,e);return t?{kind:`bars`,values:ai(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(oi(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="${I(t.x+n*r*.85)}" y="${I(a-c)}" width="${I(r*.55)}" height="${I(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},ui={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=ci(`spark`,e);return t?{kind:`spark`,values:ai(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]=oi(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`}${I(e)},${I(t)}`).join(``),p=si(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${I(t.x+t.w)},${I(l)}L${I(t.x)},${I(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="${I(m)}" cy="${I(h)}" r="2.6" fill="${p}"/>`}},di={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:P(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:P(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 Ke(e.label,t.x,s,r,a,o)+Be(t.x+t.w,s,r,a.sub,F(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${I(t.x)}" y="${I(c)}" width="${I(t.w)}" height="${I(l)}" rx="${I(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${I(t.x)}" y="${I(c)}" width="${I(Math.max(l,t.w*e.ratio))}" height="${I(l)}" rx="${I(l/2)}" fill="${u}"/>`:``)}},fi=1.75,pi={name:`charts`,rows:[li,ui,di,{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:P(t),label:P(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*fi;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*fi,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${I(e)},${I(t.y+r*.3)}V${I(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(Ke(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(Ke(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},mi=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function hi(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 gi=e=>e*1.8,_i={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=hi(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(P);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=>!Re(e[t])||mi.test(Re(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)+gi(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]-We(t):d;o.push(Ke(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+gi(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${I(t.x)},${I(e)}H${I(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},vi=[`#ff5f57`,`#febc2e`,`#28c840`],yi=e=>Math.round(e*2.3);function bi(e,t,n,r,i){let a=yi(t),o=Math.min(n,a/2,e.w/2),s=`M${I(e.x)},${I(e.y+a)}V${I(e.y+o)}A${I(o)},${I(o)} 0 0 1 ${I(e.x+o)},${I(e.y)}H${I(e.x+e.w-o)}A${I(o)},${I(o)} 0 0 1 ${I(e.x+e.w)},${I(e.y+o)}V${I(e.y+a)}Z`,c=t*.3,l=vi.map((n,r)=>`<circle cx="${I(e.x+t+r*c*3.3)}" cy="${I(e.y+a/2)}" r="${I(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${I(e.x)},${I(e.y+a)}H${I(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}var xi=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,Si={name:`browser`,inset:e=>({top:yi(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=yi(a),s=xi(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="${I(s)}" y="${I(u)}" width="${I(c-s)}" height="${I(l)}" rx="${I(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?Be(s+a*.7,e.y+o/2,d,n.sub,F(r)):``):``;return`<g class="frame">${bi(e,a,i,n.stroke,t.dark)}${f}</g>`}},Ci=(e,t)=>({name:e,inset:e=>({top:yi(e)}),render(e,{theme:n,col:r,arg:i,radius:a,fs:o}){let s=yi(o),c=i?Be(e.x+e.w/2,e.y+s/2,o*.78,r.sub,F(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${bi(e,o,a,r.stroke,n.dark)}${c}</g>`}}),wi={name:`frames`,frames:[Si,Ci(`window`,``),Ci(`terminal`,`❯ `)],props:{node:[`frame`]}},Ti=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),Ei=new Map,Di=(e,t,n)=>`${t}|${n}|${e}`;function Oi(e,t,n,r){return e.map(e=>L(P(e),t,n,r))}var ki={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=Ti(e);if(!r.length)return null;let i=t.fontSize*.82,a=Oi(r,i,t.mono,n);Ei.size>64&&Ei.clear(),Ei.set(Di(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=Ti(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=be(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${I(c)},${I(t.y)}H${I(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=Ei.get(Di(e,a,n.mono))??Oi(i,a,n.mono,qr),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="${I(m)}" y="${I(o)}" dominant-baseline="central" font-size="${I(a)}" xml:space="preserve">${R(P(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},Ai=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function ji(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return Ai.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 Mi=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 Ni(e,t,n){let{fs:r,sw:i,gap:a}=Mi(t);return e.map(e=>i+a+L(P(e.label),r,t.mono,n))}function Pi(e,t,n,r,i){let{sw:a,sh:o}=Mi(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="${I(o*3)} ${I(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${I(o)} ${I(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${I(t)},${I(n)}H${I(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${I(o)}"${s} fill="none"/>`+(c?`<path d="M${I(u)},${I(n)}L${I(u-l)},${I(n-l*.5)}L${I(u-l)},${I(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${I(t)},${I(n)}L${I(t+l)},${I(n-l*.5)}L${I(t+l)},${I(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=tt(i,t),a=rt(i,t,n,r),o=Qt(n.shape??i.settings.shape);return`<path d="${nn(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??N(e.key,r,400)??r.node.fill,u=c?.stroke??N(e.key,r,600)??r.node.stroke;return`<rect x="${I(s.x)}" y="${I(s.y)}" width="${I(s.w)}" height="${I(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function Fi(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 Ii=760,Li={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=ji(e);if(!n.length)return null;let{fs:r,space:i}=Mi(t),a=Ni(n,t,qr),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=Fi(a,Ii,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,Ii)}},render(e,t,n,{pad:r,d:i}){let a=ji(e),{fs:o,gap:s,space:c,sw:l}=Mi(n),u=Ni(a,n,qr),d=be(n),f=[];return Fi(u,Math.min(Ii,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(Pi(e,m,h,n,i)),e.label&&f.push(`<text x="${I(m+l+s)}" y="${I(h)}" dominant-baseline="central" font-size="${I(o)}" xml:space="preserve">${R(P(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},Ri=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,zi=/^(?:m|note|d)\d+$/,Bi=new RegExp(String.raw`^(participant|actor)\s+(${Ri})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?$`,`u`),Vi=new RegExp(String.raw`^(${Ri})\s*(-->|->|\.\.>|=>)\s*(${Ri})\s*(?::\s*(.*))?$`,`u`),Hi=new RegExp(String.raw`^(${Ri}\s*(?:-->|->|\.\.>|=>)\s*${Ri})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),Ui=new RegExp(String.raw`^(participant|actor)\s+(${Ri}(?:\s*,\s*${Ri})+)$`,`u`),Wi=new RegExp(String.raw`^note\s+(${Ri}(?:\s*,\s*${Ri})*)\s*:\s*(.*)$`,`u`),Gi=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,Ki=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],qi=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>Ki.includes(e))&&(!e.color||ge(e.color))},Ji=e=>or(e,qi),Yi={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function Xi(e,t,n){let r=[],i=[],a=0,o=e=>{let t=r.find(t=>t.id===e);return t||r.push(t={id:e,key:e,label:e,actor:!1,first:a}),t},s=0;e.forEach((e,t)=>{a=t;let r=e.trim();if(!r)return;let c;if(c=r.match(Bi)){let e=o(c[2]);e.decl=a,e.actor=c[1]===`actor`,c[3]!==void 0&&(e.label=c[3]);let t=c[4]&&B(c[4]).color;t&&(e.tone=t)}else if(c=r.match(Ui))for(let e of c[2].split(`,`)){let t=o(e.trim());t.actor=c[1]===`actor`,t.list??=a}else if(c=r.match(Wi)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=Ji(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(Vi)){o(c[1]),o(c[3]);let[e,t]=Ji(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:Yi[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(Gi))?i.push({kind:`divider`,text:c[1]}):(c=r.match(Hi))?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 Zi(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 Qi=Ar(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(P(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=Zi(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 $i(e,t){let n=nt(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function ea(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=Qi(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=be(r),d=n.props,f=N(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=$i(Je(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${I(c(t))},${I(h+o)}V${I(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="${I(c(a)-l/2)}" y="${I(t)}" width="${I(l)}" height="${I(o)}" rx="${I(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${I(r.strokeWidth)}"/><text x="${I(c(a))}" y="${I(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${I(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${F(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=Je(n,`style`)??(o.line===`thick`?`solid`:o.line),d=qe(n.width,o.line===`thick`||j(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=$i(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=P(i.num(o)+o.text),g=o.tone?Ve(o.tone,r,l):l,_=o.tone?{...u,text:g}:u;if(e===t){let t=c(e),n=v+a*1.6,i=n+a*1.3;m.push(`<path d="M${I(t)},${I(n)}H${I(t+26-8)}Q${I(t+26)},${I(n)} ${I(t+26)},${I(n+8)}V${I(i-8)}Q${I(t+26)},${I(i)} ${I(t+26-8)},${I(i)}H${I(t+2)}" fill="none" stroke="${g}" stroke-width="${I(d)}"${f}/>`),m.push(Yt({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${I(t+34)}" y="${I((n+i)/2)}" dominant-baseline="central" font-size="${I(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${I(c(e))},${I(s)}H${I(c(t)-n*2)}" stroke="${g}" stroke-width="${I(d)}"${f}/>`),m.push(Yt({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="${I((c(e)+c(t))/2)}" y="${I(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${I(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="${I(l)}" y="${I(p)}" width="${I(u-l)}" height="${I(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${I((l+u)/2)}" y="${I(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a)}" xml:space="preserve">${R(P(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${I(t.x)},${I(n)}H${I(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${I(c-s/2)}" y="${I(n-a*.85)}" width="${I(s)}" height="${I(a*1.7)}" rx="${I(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${I(c)}" y="${I(n)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a*.92)}" font-weight="600" fill="${r.node.sub}">${F(o.text)}</text>`))}v+=e}return m.join(``)}function ta(e,t,n){if(!e.parts.length)return[];let r=Qi(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 na={name:`sequence`,panels:[{name:`sequence`,guide:'`participant|actor id "Label" [color]` (`participant a, b, c` fixes the order), `a -> b: msg` (`-->` reply, `..>` dotted, `=>` thick, `a -> a` self call), `note a, b: text`, `--- section ---`. A message takes edge props at its end: `a -> b: retry [red, style: dotted]`.',layoutParts:"a participant id (`p-<id>` when the id looks like a row) moves its lifeline and the ones after it; `m<n>` (message), `note<n>`, `d<n>` (divider) add room above that row",syntax:`sequence id "Title" [numbered] { a -> b: message }`,parse:Xi,measure(e,t){let n=Qi(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:ea,handles:ta,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=Zi(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:jr((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]=sr(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${ur({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=Zi(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=Ji(e[s.at]),u=c;delete l.color;let d=ur(n?{color:n,...l}:l);return u=d?/:/.test(u.replace(/^.*?(-->|->|\.\.>|=>)/,``))||s.kind===`note`?`${u} [${d}]`:`${u}: [${d}]`:u.replace(/\s*:\s*$/,``),i[s.at]=u,i})}]};function ra(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}var ia=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,aa=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function oa(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]=or(i,cr),c=o.match(ia);c?r.push({when:c[1].trim(),tone:s.color??B(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)&&ia.test(or(r,cr)[0])&&t.push(n)}),t}var la=Ar(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(P(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>ra(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=ra(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+ra(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+ra(u,1)*a*1.45}});function ua(e,t,n){if(!e.length)return``;let r=n.theme,i=la(e,n),{fs:a}=i,o=be(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=Ve(n.tone,r,r.accent);return`<circle cx="${I(e)}" cy="${I(t)}" r="${I(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${I(e)}" cy="${I(t)}" r="${I(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${I(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${R(P(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${I(n)},${I(t.y+a*.5)}V${I(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="${I(n-16)}" y="${I(s)}" dominant-baseline="central" text-anchor="end" font-size="${I(a*.9)}" font-weight="600" fill="${Ve(e.tone,r,r.node.sub)}">${F(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${I(t.x)},${I(d)}H${I(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="${I(o)}" y="${I(t.y+a*.5)}" dominant-baseline="central" font-size="${I(a*.9)}" font-weight="600" fill="${Ve(e.tone,r,r.node.sub)}">${F(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 da={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:oa,measure(e,t){if(!e.length)return{w:0,h:0};let n=la(e,t);return{w:n.w,h:n.h}},render:ua,parts:e=>sa(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:jr((e,t,n,r)=>{let i=ca(e)[sa(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=lr(e[i],aa,`color`,n,cr),a}),handles(e,t,n){if(!e.length)return[];let r=la(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}`})}}]},fa=[`bar`,`column`,`line`,`pie`,`donut`],pa=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],ma=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,ha=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,ga=1e300;function _a(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}function va(e,t,n){let r=t.type??`bar`;fa.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${fa.join(`, `)})`);let i=[];return e.forEach((e,t)=>{let r=e.trim();if(!r)return;let[a,o]=or(r,cr),s=a.match(ma),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=ga)?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??B(s[2]).color,value:c}):n(t,`chart: cannot read "${r}" (expected "label: number")`)}),{type:fa.includes(r)?r:`bar`,items:i}}var ya=(e,t=``)=>`${Math.abs(e)<1e15?Math.round(e*100)/100:e}${t}`;function ba(e,t,n,r){return e.tone?Ve(e.tone,n.theme,n.theme.accent):r?m(pa[t%pa.length],n.theme.dark?400:500):n.theme.accent}var xa=Ar(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=i.unit??``,s=_a(e.items.map(e=>r(e.label,a,400,n.mono)),0),c=_a(e.items.map(e=>r(ya(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 Sa(e,t,n,r,i,a){let o=(n,r)=>`${I(e+n*Math.sin(r))},${I(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return Sa(e,t,n,r,o,a)+Sa(e,t,n,o,i,a)}return a?`M${o(n,r)}A${I(n)},${I(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${I(a)},${I(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${I(e)},${I(t)}L${o(n,r)}A${I(n)},${I(n)} 0 ${s} 1 ${o(n,i)}Z`}function Ca(e,t,n){if(!e.items.length)return``;let r=n.theme,i=xa(e,n),{fs:a,unit:o}=i,s=[],c=(e,t,n,i=`start`,o=r.node.text,s=400,c=a)=>`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${I(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${F(n)}</text>`,l=_a(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="${Sa(l,u,i.r,p,a,d)}" fill="${ba(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(s.push(c(l,u-a*.45,ya(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="${I(m)}" y="${I(g-a*.45)}" width="${I(a*.9)}" height="${I(a*.9)}" rx="2.5" fill="${ba(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,ya(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="${I(u)}" y="${I(p-a*.55)}" width="${I(d)}" height="${I(a*1.1)}" rx="3" fill="${r.group.fill}"/>`),s.push(`<rect x="${I(u)}" y="${I(p-a*.55)}" width="${I(m)}" height="${I(a*1.1)}" rx="3" fill="${ba(e,i,n,!1)}"/>`),s.push(c(u+d+10,p,ya(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${I(t.x)},${I(n)}H${I(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="${I(d(i)-t/2)}" y="${I(l)}" width="${I(t)}" height="${I(Math.max(2,u-l))}" rx="3" fill="${ba(e,i,n,!1)}"/>`),s.push(c(d(i),l-a*.8,ya(e.value,o),`middle`,r.node.text,600))})}else{let t=e.items.map((e,t)=>`${I(d(t))},${I(f(e.value))}`);s.push(`<path d="M${I(d(0))},${I(u)}L${t.join(`L`)}L${I(d(e.items.length-1))},${I(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=ba(e,t,n,!1);s.push(`<circle cx="${I(d(t))}" cy="${I(f(e.value))}" r="${I(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,ya(e.value,o),`middle`,r.node.text,600))})}return s.push(`<path d="M${I(t.x)},${I(u)}H${I(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 wa={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:va,measure(e,t){if(!e.items.length)return{w:0,h:0};let n=xa(e,t);return{w:n.w,h:n.h}},render:Ca,options:{type:[...fa],unit:`text`},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:jr((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim();return!/^(\/\/|#)/.test(n)&&ma.test(or(n,cr)[0])?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=lr(e[i],ha,`color`,n,cr),a}),handles(e,t,n){if(!e.items.length)return[];let r=xa(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},Ta=[`normal`,`highlight`,`reverse`],Ea=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Da=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,Oa=String.raw`(?:\s*\[([^\]]*)\])?`,ka=new RegExp(String.raw`^commit(?:\s+(.*?))?${Oa}$`,`u`),Aa=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${Da})(?:\s+from\s+(\S+))?${Oa}$`,`u`),ja=new RegExp(String.raw`^(?:checkout|switch)\s+(${Da})$`,`u`),Ma=new RegExp(String.raw`^merge\s+(${Da})(?:\s+(.*?))?${Oa}$`,`u`),Na=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${Oa}$`,`u`),Pa=/^tag\s+(\S+)$/;function Fa(e){let t=B(e??``);for(let e of Ta)t[e]===`true`&&(t.type=e,delete t[e]);return t}function Ia(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&&!Ta.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${Ta.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(Aa)){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=Fa(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(ja)){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(Ma)){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:xr(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},Fa(u[3]),t)}else if(u=l.match(Na)){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:xr(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},Fa(u[3]),t)}else(u=l.match(Pa))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(ka))?c({msg:xr(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},Fa(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function La(e,t,n){let r=e.branches[t]?.tone;return r?Ve(r,n.theme,n.theme.accent):m(Ea[t%Ea.length],n.theme.dark?400:500)}function Ra(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=new WeakMap,Ba=Ar(function(e,t){let n=JSON.stringify([t.fs,t.props,t.offsets]),r=za.get(e);if(r&&r.key===n&&r.theme===t.theme&&r.measure===t.measure)return r.G;let i=Va(e,t);return za.set(e,{key:n,theme:t.theme,measure:t.measure,G:i}),i});function Va(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=Ra(e),l=e=>s[e]?.x??0,u=e=>L(P(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 Ha=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function Ua(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${I(h.x)},${I(h.y)}L${I(g.x)},${I(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=Ha((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${I(h.x)},${I(h.y)}V${I(t-e)}C${I(h.x)},${I(t)} ${I(g.x)},${I(t)} ${I(g.x)},${I(t+e)}V${I(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=Ha((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${I(h.x)},${I(h.y)}H${I(S-x)}C${I(S)},${I(h.y)} ${I(S)},${I(g.y)} ${I(S+x)},${I(g.y)}H${I(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${I(i.x)},${I(i.y)}Q${I(e)},${I(n)} ${I(c.x)},${I(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${I(i.x)},${I(i.y)}C${I(p)},${I(i.y+u.y)} ${I(p)},${I(c.y+u.y)} ${I(c.x)},${I(c.y)}`})}),{lanes:u,bends:d,picks:f}}function Wa(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=Ba(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=be(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="${I(u)}" y="${I(t-d/2)}" width="${I(l)}" height="${I(d)}" rx="${I(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${I(u+l/2)}" y="${I(t)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a*.82)}" font-weight="600" fill="${o?s:r}">${F(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="${I(t.x)}" y="${I(o)}" dominant-baseline="central" font-size="${I(a)}" font-weight="600" fill="${La(e,r.lane,n)}">${F(r.label??r.name)}</text>`)}let f=Math.max(2,r.edgeWidth*1.4),p=Ua(e,i,t),m=(t,r)=>La(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="${La(e,e.commits[t.i].lane,n)}" stroke-width="${I(f*.7)}" stroke-dasharray="${I(f*1.6)} ${I(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="${I(f)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((p,m)=>{let{x:h,y:_}=u[m],v=p.tone?Ve(p.tone,r,La(e,p.lane,n)):La(e,p.lane,n);if(p.type===`highlight`){let e=o*1.1;l.push(`<rect x="${I(h-e)}" y="${I(_-e)}" width="${I(e*2)}" height="${I(e*2)}" rx="${I(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${I(f)}"/>`)}else if(p.type===`reverse`){let e=o*.55;l.push(`<circle cx="${I(h)}" cy="${I(_)}" r="${I(o)}" fill="${s}" stroke="${v}" stroke-width="${I(f)}"/><path d="M${I(h-e)},${I(_-e)}L${I(h+e)},${I(_+e)}M${I(h+e)},${I(_-e)}L${I(h-e)},${I(_+e)}" stroke="${v}" stroke-width="${I(f*.8)}" stroke-linecap="round"/>`)}else p.merge?l.push(`<circle cx="${I(h)}" cy="${I(_)}" r="${I(o*1.05)}" fill="${v}"/><circle cx="${I(h)}" cy="${I(_)}" r="${I(o*.4)}" fill="${s}"/>`):p.pick===void 0?l.push(`<circle cx="${I(h)}" cy="${I(_)}" r="${I(o)}" fill="${s}" stroke="${v}" stroke-width="${I(f)}"/>`):l.push(`<circle cx="${I(h)}" cy="${I(_)}" r="${I(o)}" fill="${s}" stroke="${v}" stroke-width="${I(f)}" stroke-dasharray="${I(f*1.2)} ${I(f)}"/>`);if(i.vertical){let o=t.x+i.textX;p.id&&(l.push(`<text x="${I(o)}" y="${I(_)}" dominant-baseline="central" font-size="${I(a)}" font-family="${F(g)}" fill="${r.node.sub}">${F(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,La(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="${I(o)}" y="${I(_)}" dominant-baseline="central" font-size="${I(a)}" xml:space="preserve">${R(P(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="${I(h)}" y="${I(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${R(P(p.msg),c,r,p.merge)}</text>`)}),l.join(``)}var Ga={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:Ia,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})),...Ra(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:jr((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[Ra(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=sr(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=Ba(e,t);return{w:n.w,h:n.h}},render:Wa,handles(e,t,n){if(!e.commits.length)return[];let r=Ba(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=Ua(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`}))]}}]},Ka=[`box`,`pill`,`plain`,`circle`],qa=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],Ja=/^[-*+]\s+/,Ya=e=>Qe(e)!==void 0,Xa={color:ge,shape:()=>!0,text:ge,"font-size":Ya,"font-weight":Ya},Za=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>Xa[t]?.(e[t]))},Qa=e=>or(e,Za);function $a(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]=Qa(o.replace(Ja,``));l.shape&&!Ka.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${Ka.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:Qe(l[`font-size`]),weight:Qe(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 eo(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 to=e=>e.reduce((e,t)=>Math.min(e,t),1/0),no=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function ro(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 io=[`both`,`vertical`,`right`,`left`,`down`,`up`],ao=Ar(function(e,t){let{theme:n,measure:r,props:i}=t,a=Qe(i[`font-size`])??t.fs*.9,o=io.includes(i.layout)?i.layout:`both`,s=o===`down`||o===`up`||o===`vertical`,c=i.colors===`mono`,l=eo(e),u=ro(l),d=new Map(l.map((e,t)=>[e,u[t]])),f=new Map,p=(e,t,i,o)=>{let s=Ka.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(P(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:qa[n%qa.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=to(D.map(e=>e.x)),k=to(D.map(e=>e.y));for(let e of D)e.x-=O,e.y-=k;return{all:D,vert:s,w:no(D.map(e=>e.x+e.w)),h:no(D.map(e=>e.y+e.h))}}),oo=(e,t)=>t?Ve(t,e,e.accent):e.accent;function so(e,t,n){if(!e)return``;let r=n.theme,i=ao(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=oo(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${I(s(n))},${I(c(r))}C${I(s(n))},${I(c((r+u)/2))} ${I(s(o))},${I(c((r+u)/2))} ${I(s(o))},${I(c(u))}`:`M${I(s(n))},${I(c(r))}C${I(s((n+o)/2))},${I(c(r))} ${I(s((n+o)/2))},${I(c(u))} ${I(s(o))},${I(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${I(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=N(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${I(m)},${I(h+e.h)}H${I(m+e.w)}" stroke="${t}" stroke-width="${I(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="${I(m)}" y="${I(h)}" width="${I(e.w)}" height="${I(e.h)}" rx="${I(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="${I(m+e.w/2)}" y="${I(g)}" dominant-baseline="central" text-anchor="middle" font-size="${I(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${R(P(e.node.text),be(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:io,colors:[`branches`,`mono`]},parse:$a,measure(e,t){if(!e)return{w:0,h:0};let n=ao(e,t);return{w:n.w,h:n.h}},render:so,parts(e){if(!e)return[];let t=eo(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 ro(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:jr((e,t,n,r)=>{if(!r)return null;let i=eo(r),a=i[ro(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=Qa(e[a.line]),u=ur(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=ao(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}}]},lo=864e5,uo=864e13,fo=2e3,po=1e3,mo=3660,ho=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],go=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,_o=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,vo=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function yo(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 bo(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:lo,w:7*lo}[t[2].toLowerCase()]:NaN}function xo(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s)return;let c=s.match(vo);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?B(t[2]).color:void 0);return}let[l,u]=or(s),d=l.match(go);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={...B(m),...u},_=g.milestone===`true`,v={line:t,date:NaN,after:[],len:NaN,endDate:NaN},y=h.split(`,`).map(e=>e.trim()).filter(Boolean),b=0,x=y[0]??``;/^after\s/i.test(x)?(v.after=x.slice(6).trim().split(/\s+/),b=1):Number.isNaN(yo(x))?x&&Number.isNaN(bo(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=yo(x),b=1);let S=y[b];S===void 0?!_&&x&&n(t,`gantt: task "${f}" needs a length, e.g. "${x}, 3d"`):(v.len=bo(S),Number.isNaN(v.len)&&(v.endDate=yo(S),Number.isNaN(v.endDate)&&n(t,`gantt: "${S}" is not a length (3h, 5d, 2w) or an end date`)));let C=g.progress===void 0?NaN:parseFloat(g.progress)/(g.progress.endsWith(`%`)?100:1);g.progress!==void 0&&!(C>=0&&C<=1)&&n(t,`gantt: progress "${g.progress}" must be 0% to 100%`),r.push({id:f,label:p?.replace(/\\(.)/g,`$1`)??f,tone:g.color??void 0,progress:Math.min(1,Math.max(0,C)),owner:g.owner,done:g.done===`true`,active:g.active===`true`,crit:g.crit===`true`,milestone:_,start:NaN,end:NaN,after:v.after,section:a.length-1}),i.push(v)});let s=new Map(r.map((e,t)=>[e.id,t])),c=r.map(()=>0),l=i.map(e=>e.date).filter(e=>!Number.isNaN(e)),u=l.length?l.reduce((e,t)=>Math.min(e,t)):Date.UTC(2025,0,1),d=e=>{let t=i[e];return t.after.length?t.after:Number.isNaN(t.date)&&e>0?[e-1]:[]},f=(e,t)=>{let a=r[e],o=i[e],s=o.date;return o.after.length?s=t.length?t.reduce((e,t)=>Math.max(e,t)):u:Number.isNaN(s)&&(e>0?s=t[0]:(n(o.line,`gantt: the first task needs a start date`),s=u)),a.start=s,a.end=a.milestone?s:Number.isNaN(o.len)?Number.isNaN(o.endDate)?s+lo:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=uo||(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 So(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!/^(\/\/|#)/.test(r)&&!vo.test(r)&&go.test(or(r)[0])&&t.push(n)}),t}function Co(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 wo=e=>{let t=new Date(e);return`${ho[t.getUTCMonth()]} ${t.getUTCDate()}`},To=e=>{let t=e/lo;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 Eo(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/lo)*lo;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=lo;for(;o<=t&&i.length<fo&&Number.isFinite(new Date(o).getTime());o+=a*lo)i.push({t:o,label:wo(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>=fo)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${ho[c]} ${s}`:ho[c]}),l=!1,c+=a}return i}return i}var Do={compact:1.6,normal:2.1,loose:2.7},Oo=Ar(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(Do[i.density??``]??Do.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>L(P(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/lo)*lo,_=Math.max(g+lo,Math.ceil(e.max/lo)*lo),v=(_-g)/lo,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*po/v),x=e=>h+(e-g)/lo*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?`${wo(e.start)} – ${wo(e.end)}`:e.milestone?wo(e.start):To(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 ko(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${I(n[0][0])},${I(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${I(u[0])},${I(u[1])}Q${I(a[0])},${I(a[1])} ${I(d[0])},${I(d[1])}`}let i=n[n.length-1];return`${r}L${I(i[0])},${I(i[1])}`}function Ao(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=Oo(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f=be(r),p=(e,t,n,i,a,s=!1)=>`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${I(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${R(P(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${I(o*.82)}" font-weight="500" fill="${r}">${F(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/lo<=mo)for(let e=a.min;e<a.max;e+=lo){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${I(c(e))}" y="${I(t.y+a.axisH*.8)}" width="${I(a.dayW)}" height="${I(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/lo)*lo:yo(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${wo(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 Eo(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${I(s)},${I(t.y+a.axisH*.75)}V${I(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${I(p)}" y="${I(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${I(o*.82)}" fill="${r.node.sub}">${F(e.label)}</text>`)}d.push(`<path d="M${I(t.x+a.labelW)},${I(t.y+a.axisH*.75)}H${I(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="${I(t.x-o*.4)}" y="${I(t.y+n.y)}" width="${I(T+o*.4)}" height="${I(a.rowH)}" rx="3" fill="${u}" opacity="0.16"/>`):e=0}for(let n of a.rows)if(n.section!==void 0){let s=t.y+n.y+a.secH/2,l=e.sectionTones[n.section],f=l?Ve(l,r,r.node.sub):r.node.sub;d.push(`<path d="M${I(t.x)},${I(t.y+n.y+1)}H${I(t.x+T)}" stroke="${u}" stroke-width="1" opacity="0.6"/>`,p(t.x,s,e.sections[n.section],700,f));let m=e.tasks.filter(e=>e.section===n.section);if(m.length&&i.summary!==`hide`){let e=c(Math.min(...m.map(e=>e.start))),t=Math.max(e+2,c(Math.max(...m.map(e=>e.end)))),n=o*.32;d.push(`<path d="M${I(e)},${I(s+n*1.6)}V${I(s-n/2)}H${I(t)}V${I(s+n*1.6)}" fill="none" stroke="${f}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${I(e)}" y="${I(s-n/2)}" width="${I(t-e)}" height="${I(n)}" fill="${f}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${I(c(h))},${I(t.y+a.axisH*.35)}V${I(l)}" stroke="${Ve(`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${I(g)},${I(_)}C${I(g+e)},${I(_)} ${I(b-e)},${I(y)} ${I(b)},${I(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=ko([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=ko([[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="${I(l)}" stroke-linejoin="round"/>`,Yt({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`?Co(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=Ve(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${I(t)},${I(s-a.ms)}L${I(t+a.ms)},${I(s)}L${I(t)},${I(s+a.ms)}L${I(t-a.ms)},${I(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?Ve(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${I(v)}" y="${I(x)}" width="${I(e)}" height="${I(b)}" rx="${I(S)}" ${t}${h}/>`,A=E===`outline`?1.6:e.crit||e.active?1.8:E===`soft`?1.2:0,ee=E===`soft`?u?.fill??r.node.fill:E===`outline`?`none`:f,te=(E===`solid`||E===`thin`)&&D?` fill-opacity="0.3"`:``;d.push(k(y,`fill="${ee}"${te}${A?` stroke="${T}" stroke-width="${A}"`:``}`));let ne=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;ne&&d.push(k(ne,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-ne>2&&d.push(`<rect x="${I(v+ne)}" y="${I(x)}" width="${I(y-ne)}" height="${I(b)}" rx="${I(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+ne-o*.2)?Co(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=Ve(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${I(b)}" y="${I(n-o*.55)}" width="${I(v)}" height="${I(o*1.1)}" rx="${I(o*.55)}" fill="${e}"/>`,`<text x="${I(b+v/2)}" y="${I(n)}" dominant-baseline="central" text-anchor="middle" font-size="${I(o*.72)}" font-weight="650" fill="${Co(e)}">${F(_)}</text>`)}return d.join(``)}var jo={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:xo,measure(e,t){if(!e.tasks.length)return{w:0,h:0};let n=Oo(e,t);return{w:n.w,h:n.h}},render:Ao,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:jr((e,t,n,r)=>{let i=So(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=lr(e[i],_o,`color`,n),a}),handles(e,t,n){if(!e.tasks.length)return[];let r=Oo(e,n);return r.rows.flatMap(n=>n.task===void 0?[]:[{part:e.tasks[n.task].id,x:t.x+r.labelW-r.fs*.5,y:t.y+n.y+2,axis:`y`,title:`move ${e.tasks[n.task].id}`}])}}]},Mo=/^([xy])-axis\s*:?\s*(.*)$/i,No=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,Po=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,Fo=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,Io=[`teal`,`blue`,`slate`,`amber`],Lo=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function Ro(e,t,n){let r={x:[``,``],y:[``,``],q:[{text:``},{text:``},{text:``},{text:``}],points:[],scale:1},i=[];e.forEach((e,t)=>{let a=e.trim();if(!a)return;let o=a.match(Mo);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=or(a,cr),l=s.match(No);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??B(l[2]).color};return}let u=s.match(Po);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??B(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=Lo(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 zo(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]=or(l,cr),d=new RegExp(Po,`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 Bo=Ar(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(P(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(P(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 Vo(e,t,n){let r=n.theme,i=Bo(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],u=be(r),d=o/2,f=[[d,0],[0,0],[0,d],[d,d]];e.q.forEach((e,t)=>{let n=e.tone??Io[t],i=r.tone(n)?.fill??m(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${I(s+f[t][0])}" y="${I(c+f[t][1])}" width="${I(d)}" height="${I(d)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=Ve(e.tone??Io[t],r,r.node.sub);l.push(`<text x="${I(s+f[t][0]+d/2)}" y="${I(c+f[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a)}" font-weight="700" xml:space="preserve">${R(P(e.text),{...u,text:n},r)}</text>`)}),l.push(`<rect x="${I(s)}" y="${I(c)}" width="${I(o)}" height="${I(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${I(s+d)},${I(c)}V${I(c+o)}M${I(s)},${I(c+d)}H${I(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let p=(e,t,n,i)=>n?`<text x="${I(e)}" y="${I(t)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${I(e)} ${I(t)})"`:``}>${F(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=Ve(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],d=i.labels[t];l.push(`<circle cx="${I(s+a)}" cy="${I(c+o)}" r="${I(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${I(s+d.x)}" y="${I(c+d.y+d.h/2)}" dominant-baseline="central" font-size="${I(i.lfs)}" xml:space="preserve">${R(P(e.name),u,r)}</text>`)}),l.join(``)}var Ho={name:`quadrant`,panels:[{name:`quadrant`,guide:"`x-axis Low -> High`, `y-axis Low -> High`, `q1..q4 [color]: label` (q1 top right, counter-clockwise), points `Name [color]: x, y` from 0 to 1.",layoutParts:"a point by its name (lower case, `-` for spaces), else `p<n>`, moves by `DX DY`; `size DX DY` grows the plot",syntax:`quadrant id "Title" { x-axis Low -> High; q1: Quick wins; Search: 0.3, 0.8 }`,parse:Ro,measure(e,t){let n=Bo(e,t);return{w:n.w,h:n.h}},render:Vo,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:jr((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>No.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]=lr(e[i],Fo,`color`,n,cr),o}),handles(e,t,n){let r=Bo(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)=>zo(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`}]}}]},Uo={high:`red`,medium:`amber`,low:`gray`};function Wo(e){let[t,n]=or(e);return{text:t.trim(),props:n}}var Go=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``),Ko=e=>e.match(/^\s*/)[0].length,qo=e=>!e.trim(),Jo=/^[-*]\s+/;function Yo(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function Xo(e,t,n){let r=[],i=Math.min(...e.filter(e=>!qo(e)).map(Ko)),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(qo(e))return;let d=e.trim(),f=Ko(e),p=c;if(c=t,Jo.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}=Wo(d.replace(Jo,``)),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`?(Uo[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:Uo[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}=Wo(d),g=Yo(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=Go(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 Zo(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=or(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=ur(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}var Qo=[`owner`,`ticket`,`priority`];function $o(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]?Ko(e[t.cards[0].start]):Ko(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=Xo(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=Ko(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,Ko(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?Qo:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&Yo(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=Zo(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=Xo(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]?Ko(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 es=Ar(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(P(e.text),i,n.mono,r,500),t,...e.details.map(e=>L(P(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 ts(e,t,n){if(!e.length)return``;let r=n.theme,i=es(e,n),{fs:a}=i,o=[],s=be(r),c=Math.min(r.radius,a*.6),l=Ve(`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="${I(d)}" y="${I(f)}" width="${I(i.colW)}" height="${I(i.h)}" rx="${I(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="${I(d+i.cpad+a*.35)}" cy="${I(h)}" r="${I(a*.32)}" fill="${Ve(e.tone,r,r.node.sub)}"/>`,`<text x="${I(d+i.cpad+a*1.05)}" y="${I(h)}" dominant-baseline="central" font-size="${I(a)}" font-weight="700" xml:space="preserve">${R(P(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="${I(v)}" y="${I(h-a*.6)}" width="${I(_)}" height="${I(a*1.2)}" rx="${I(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${I(v+_/2)}" y="${I(h)}" dominant-baseline="central" text-anchor="middle" font-size="${I(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${F(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="${I(l)}" y="${I(y)}" width="${I(f)}" height="${I(n.h)}" rx="${I(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${I(l)}" y="${I(y+c/2)}" width="3.5" height="${I(n.h-c)}" rx="1.75" fill="${Ve(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${I(l+i.pad)}" y="${I(m)}" dominant-baseline="central" font-size="${I(a)}" font-weight="500" xml:space="preserve">${R(P(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${I(l+i.pad)}" y="${I(m-a*.6)}" dominant-baseline="central" font-size="${I(a*.88)}" xml:space="preserve">${R(P(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="${I(t)}" y="${I(n-i.chipFs*.75)}" width="${I(e)}" height="${I(i.chipFs*1.5)}" rx="${I(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${I(t+e/2)}" y="${I(n)}" dominant-baseline="central" text-anchor="middle" font-size="${I(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${F(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}var ns={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:Xo,measure(e,t){if(!e.length)return{w:0,h:0};let n=es(e,t);return{w:n.w,h:n.h}},render:ts,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:$o,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=es(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}`}))}}]},rs={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},is=Object.keys(rs),as={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},os=[`collapsed`,`highlight`,`dim`,`folder`,`file`,...is],ss=[`color`,`icon`,`badge`,`note`,`size`,`status`],cs=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],ls=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,us=/^[-*+]\s+/,ds=/\s\[([^[\]]*)\]\s*$/,fs=/:\s|\s#\s|:$/,ps=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,ms=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,hs=/^(?:\.{3}|…)$/;function gs(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}}}function _s(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}var vs=e=>e.replace(/\/$/,``);function ys(e,t){for(let n of Object.keys(e))!os.includes(n)&&!ss.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[...ss.slice(1),...os].join(`, `)})`);e.status&&!is.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${is.join(`, `)})`),e.color&&!ve(e.color)&&delete e.color}var bs=100;function xs(e,t,n){let r=[],i=[],a=[],o=new Map,s=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let c=e.trim().match(ms);if(c){let e=B(c[2]);ys(e,e=>n(t,e));let r=c[1];a.push({re:gs(vs(r)),path:vs(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let l=e.match(ls)[0],u=e.slice(l.length),d=u.match(us);d&&(u=u.slice(d[0].length));let f=e.length-u.trimStart().length;if(u=u.trim(),!u||ps.test(u))return;let p=(l+(d?.[0]??``)).replace(/\t/g,` `).length,m={},h,g=u.match(ds);g&&(m=B(g[1]),h=[f+g.index,f+u.length],u=u.slice(0,g.index).trimEnd());let _,v=_s(u).match(fs);if(v&&v.index>0){_=u.slice(v.index+v[0].length).trim()||void 0,u=u.slice(0,v.index).trimEnd();let e=u.match(ds);e&&!g&&(m=B(e[1]),h=[f+e.index,f+u.length],u=u.slice(0,e.index).trimEnd())}ys(m,e=>n(t,e));let y={text:u,collapsed:!1,highlight:!1,dim:!1,line:t,children:[]};for(h&&(y.propSpan=h),o.set(y,{props:m,note:_});i.length&&i[i.length-1].indent>=p;)i.pop();i.length>=bs&&(s||n(t,`treeview: entries nest at most ${bs} levels deep`),s=!0,i.length=99),(i.length?i[i.length-1].node.children:r).push(y),i.push({indent:p,node:y})});let c=(e,t)=>{for(let n of e){let e=t+vs(n.text),{props:r,note:i}=o.get(n),s=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),l={};for(let t of a)(!t.folders||s)&&t.re.test(t.path?e:vs(n.text))&&(t.hits++,Object.assign(l,t.props));if(r.folder===`true`&&delete l.file,r.file===`true`&&delete l.folder,is.some(e=>r[e]===`true`)||r.status){for(let e of is)delete l[e];delete l.status}Object.assign(l,r),n.note=r.note??i??l.note,n.tone=l.color,n.icon=l.icon,n.badge=l.badge,n.size=l.size,n.status=is.find(e=>l[e]===`true`)??(is.includes(l.status)?l.status:void 0),n.collapsed=l.collapsed===`true`,n.highlight=l.highlight===`true`,n.dim=l.dim===`true`,n.type=l.folder===`true`?`folder`:l.file===`true`?`file`:void 0,c(n.children,e+`/`)}};c(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function Ss(e,t=[]){for(let n of e)t.push(n),Ss(n.children,t);return t}var Cs=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),ws=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},Ts={},V=(e,t,n)=>{for(let r of n.split(` `))Ts[r]=[t,e]};V(`blue`,`code`,`ts tsx mts cts py c cpp`),V(`amber`,`code`,`js jsx mjs cjs zig`),V(`green`,`code`,`vue`),V(`orange`,`code`,`svelte rs swift html`),V(`purple`,`code`,`astro kt h cs css`),V(`cyan`,`code`,`go`),V(`red`,`code`,`java rb`),V(`indigo`,`code`,`php lua`),V(`pink`,`code`,`scss`),V(`green`,`terminal`,`sh bash zsh fish ps1`),V(`blue`,`doc`,`md`),V(`amber`,`doc`,`mdx`),V(`gray`,`doc`,`txt rst`),V(`red`,`doc`,`pdf`),V(`green`,`doc`,`csv`),V(`purple`,`image`,`png jpg jpeg gif webp avif ico`),V(`amber`,`image`,`svg`),V(`red`,`font`,`woff woff2 ttf otf`),V(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),V(`amber`,`config`,`json`),V(`purple`,`config`,`yaml yml`),V(`gray`,`config`,`toml ini`),V(`orange`,`config`,`xml`),V(`slate`,`config`,`env`),V(`cyan`,`database`,`sql db sqlite`),V(`amber`,`package`,`zip tar gz`),V(`pink`,`yuhwa`,`yu yuhwa`);var Es=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function Ds(e){let t=vs(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`]:Ts[ws(t)]??[`file`,void 0]}var Os=`M3.5 1.5h6l3.5 3.5v9.5h-9.5z`,ks=`M9.5 1.5v3.5h3.5`;function As(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="${Os}" fill="${t}" stroke="${n}"/>${r(ks)}`;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 js=l({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function Ms(e){let t=new Map;for(let n of e)t.set(vs(n.text),(t.get(vs(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(vs(e.text))&&t.get(vs(e.text))===1&&!/^n\d+$/.test(vs(e.text))?vs(e.text):`n${n+1}`)}var Ns=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,Ps=e=>e!==void 0&&e!==`false`,Fs=(e,t,n)=>t.includes(e)?e:n,Is=e=>e&&ve(e)?e:void 0,Ls=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function Rs(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 Rs(r,t))n.add(e)}return t.set(e,n),n}var zs=[`color`,`mono`,`emoji`,`none`],Bs=[`solid`,`rounded`,`dashed`,`dotted`,`none`],Vs=[`none`,`name`,`folders`],Hs=[`collapsed`,`all`,`none`],Us=[`letter`,`dot`,`none`],Ws=Ar(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=Fs(i.icons,zs,zs[0]),s=Fs(i.sort,Vs,Vs[0]),c=i.counts===`true`?`all`:Fs(i.counts,Hs,Hs[0]),l=Fs(i.marks,Us,Us[0]),u=i.rollup!==`false`&&l!==`none`,d=Ps(i.compact),f=Ps(i.chevrons),p=Ns(i.depth),m=Is(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=Ns(i.indent)??y+a*.75,x=Ss(e),S=Ms(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(hs.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(Cs(n))-Number(Cs(e)):0)||Ls.compare(e.text,n.text))},A=e=>!e.note&&!e.badge&&!e.size&&!e.status&&!e.highlight&&!e.dim&&!e.icon&&!e.tone&&!e.collapsed,ee=[],te=(e,t,o)=>{let s=k(e);s.forEach((e,l)=>{let f=e,g=e=>e.collapsed||p!==void 0&&t+1>=p,_=[vs(f.text)];for(;d&&f.children.length===1&&Cs(f)&&Cs(f.children[0])&&A(f)&&!g(f);)f=f.children[0],_.push(vs(f.text));let v=Cs(f),y=!v&&hs.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`,Es.test(vs(f.text))?`gray`:m]:Ds(f.text),k=f.icon??T,ne=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,M=v&&u&&!f.status?Rs(f,w):void 0,ie={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:ne??`file`,iconTone:f.tone??(f.status?rs[f.status]:void 0)??(f.icon?void 0:D),iconText:ne?void 0:f.icon,textW:L(P(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:M?.size?M.size===1?[...M][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:ee.length*h,x:t*b};ee.push(ie),x&&te(f.children,t+1,ie)})};te(e,0);let ne=e=>e.more?e.x+_:e.x+_+g+v,re=e=>ne(e)+e.textW+a*.5,j=e=>(e.badgeW?re(e)+e.badgeW:ne(e)+e.textW)+a*.45,M=e=>e.countW?j(e)+e.countW:e.badgeW?re(e)+e.badgeW:ne(e)+e.textW,ie=i.notes===`inline`,ae=a*.88,oe=0;for(let e of ee)oe=Math.max(oe,M(e));let se=oe+a*1.6,ce=e=>ie?M(e)+a*.9:se,le=e=>e.node.note?L(P(e.node.note),ae,n.mono,r,400):0,ue=e=>l!==`none`&&(e.node.status&&as[e.node.status]!==``||e.rollup!==void 0),de=ee.some(ue),fe=a*4;for(let e of ee)fe=Math.max(fe,e.node.note?ce(e)+le(e):M(e));let pe=Math.max(0,...ee.map(e=>e.sizeW)),me=pe?fe+a*1.4+pe:fe,he=me+a*1.2;return{rows:ee,fs:a,smallFs:D,noteFs:ae,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:ne,badgeX:re,countX:j,noteX:ce,sizeRight:me,markX:he,mark:ue,w:de?he+a*.8:me,h:ee.length*h}}),Gs=e=>{let t=nt(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function Ks(e,t,n){if(!e.length)return``;let r=n.theme,i=Ws(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=Fs(a.lines,Bs,Bs[0]),f=(e,t)=>e?Ve(e,r,t):t,p=f(Is(a[`line-color`]),r.edge.stroke),m=Is(a[`highlight-color`]),h=Is(a[`badge-color`])??`blue`,g=f(Is(a[`note-color`]),r.node.sub),_=f(Is(a[`strike-color`]),r.node.sub),v=Ns(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=`fill="none" stroke="${p}" stroke-width="${I(Xe(a)??1)}" stroke-opacity="0.55"${Gs(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,b=Math.min(Ns(a.radius)??r.radius,(i.rowH-2)/2),x=I(o(-i.fs*.35)),S=I(i.w+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,C=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${x}" y="${I(s(e.y+1))}" width="${S}" height="${I(i.rowH-2)}" rx="${I(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="${x}" y="${I(s(e.y))}" width="${S}" height="${I(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${I(o(t))},${I(s(r))}V${I(s(p-a))}Q${I(o(t))},${I(s(p))} ${I(o(t+a))},${I(s(p))}H${I(o(n))}" ${y}/>`:`<path d="M${I(o(t))},${I(s(r))}V${I(s(p))}H${I(o(n))}" ${y}/>`)}else l.push(`<path d="M${I(o(t))},${I(s(p))}H${I(o(n))}" ${y}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${I(t-n)},${I(s(p)-n/2)}L${I(t)},${I(s(p)+n/2)}L${I(t+n)},${I(s(p)-n/2)}`:`M${I(t-n/2)},${I(s(p)-n)}L${I(t+n/2)},${I(s(p))}L${I(t-n/2)},${I(s(p)+n)}`;C.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`)C.push(`<text x="${I(t+i.iconW/2)}" y="${I(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${I(i.fs*.95)}">${F(e.iconText??js[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;C.push(`<g transform="translate(${I(t)},${I(n)}) scale(${I(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${As(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));C.push(`<line x1="${I(t-i.fs*.15)}" y1="${I(s(p))}" x2="${I(t+e.textW+i.fs*.15)}" y2="${I(s(p))}" stroke="${_}" stroke-width="${I(v)}" stroke-linecap="round"/>`)}let w=n.status?f(rs[n.status],r.node.text):void 0,T=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):w??r.node.text,E=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(C.push(`<text x="${I(o(i.textX(e)))}" y="${I(s(p))}" dominant-baseline="central" font-size="${I(i.fs)}"${E} xml:space="preserve">${R(P(e.label),be(r,T,T),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;C.push(`<rect x="${I(a)}" y="${I(s(p)-c/2)}" width="${I(e.badgeW)}" height="${I(c)}" rx="${I(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${I(a+e.badgeW/2)}" y="${I(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${I(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${F(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;C.push(`<rect x="${I(t)}" y="${I(s(p)-n/2)}" width="${I(e.countW)}" height="${I(n)}" rx="${I(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${I(t+e.countW/2)}" y="${I(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${I(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&C.push(`<text x="${I(o(i.noteX(e)))}" y="${I(s(p))}" dominant-baseline="central" font-size="${I(i.noteFs)}" xml:space="preserve">${R(P(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&C.push(`<text x="${I(o(i.sizeRight))}" y="${I(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${I(i.fs*.82)}" fill="${r.node.sub}">${F(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(rs[t],r.node.text);i.marks===`dot`||!n.status?C.push(`<circle cx="${I(o(i.markX))}" cy="${I(s(p))}" r="${I(i.fs*.22)}" fill="${a}"/>`):C.push(`<text x="${I(o(i.markX))}" y="${I(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${I(i.fs*.85)}" font-weight="700" fill="${a}">${as[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${C.join(``)}</g>`:C.join(``))}),c.join(``)+l.join(``)+u.join(``)}Wr(ti,ri,ii,pi,_i,wi,Li,ki,na,da,wa,Ga,co,jo,Ho,ns,{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`, `"+is.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:[...zs],lines:[...Bs],sort:[...Vs],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...Hs],marks:[...Us],rollup:[`true`,`false`],depth:`number`,indent:`number`,"folder-color":`color`,"line-color":`color`,"highlight-color":`color`,"badge-color":`color`,"note-color":`color`,"strike-color":`color`,"strike-width":`number`},parse:xs,measure(e,t){if(!e.length)return{w:0,h:0};let n=Ws(e,t);return{w:n.w,h:n.h}},render:Ks,parts(e){let t=Ss(e);return Ms(t).map((e,n)=>({id:e,label:t[n].text,kind:Cs(t[n])?`folder`:`file`,tone:t[n].tone}))},editPart:jr((e,t,n,r)=>{let i=Ss(r),a=i[Ms(i).indexOf(t)];if(!a)return null;let o=[...e],s=e[a.line],[c,l]=a.propSpan??[s.trimEnd().length,s.trimEnd().length],u=s.slice(c,l).match(/\[([^\]]*)\]/),{color:d,...f}=u?B(u[1]):{},p=ur(n?{color:n,...f}:f);return o[a.line]=s.slice(0,c)+(p?` [${p}]`:``)+s.slice(l),o})}]});function qs(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 Mr.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:P(e.slice(0,s)),right:P(e.slice(s+4).trim())}):t.push({kind:`text`,left:P(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}var Js=e=>Mr.rows.find(t=>t.kind===e.kind);function Ys(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=Js(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 Xs(e,t,n){let r=e.caps?Math.round(e.fontSize*.8*10)/10:e.fontSize,i=e.caps?r*.12:0,a=e.label?e.label.split(`
7
+ `):[],o=e.sub?e.sub.split(`
8
+ `):[],s=Math.round(e.fontSize*.82*10)/10,c=r*1.35,l=s*1.4,u=Math.round(r*1.15),d=e.caps?650:e.weight,f=(r,a,o)=>Me(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=>Me(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?Ys(qs(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?Mr.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 Zs(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(Be(c+e.iconSize/2,t,e.iconSize,a.text,F(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${I(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(Be(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,Le(i,e.caps?xe(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(Be(c,i+e.subLh/2,e.subSize,a.sub,Le(t,xe(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(Be(l,t,e.subSize,a.sub,Le(e.meta,xe(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${I(t)},${I(n)}H${I(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(Qs(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function Qs(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(Ke(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push(Ke(r.right,n-We(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${I(t)},${I(d+f/2)}H${I(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push(Js(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${F(g)}"`:``}>${o.join(``)}</g>`}function $s(e,t,n){let r=[];for(let i of e.split(`
9
+ `)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of ke(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function ec(e,t,n,r,i,a,o,s=!1,c=0){let l=s?r*.1:0,u=Math.round(r*.82*10)/10,d=e=>{let t=new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},f=d(e=>Me(e,r,i,a.mono,o,s,l)),p=d(e=>Me(e,u,400,a.mono,o)),m=$s(e,c,f),h=t?$s(t,c,p):[],g=Fe(m,r),_=Fe(h,u,1.35),v=Math.round(r*1.6),y=0;for(let e of m)y=Math.max(y,f(e));for(let e of h)y=Math.max(y,p(e));let b=m.length*g+h.length*_+(h.length?3:0);return n&&(b+=v+4,y=Math.max(y,v)),{lines:m,sub:h,icon:n,lineHeight:g,subSize:u,subLineHeight:_,iconSize:v,letterSpacing:l,caps:s,w:y,h:b}}function tc(e,t){let{title:n,subtitle:r}=e.settings;if(!n&&!r)return null;let i=t.fontSize*1.3,a=t.fontSize*.95;return{titleSize:i,subSize:a,h:(n?i*1.3:0)+(r?a*1.5:0)+10}}function nc(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 rc(e){let t=new Map;for(let n of e)n.forEach((e,r)=>{for(let i of e.path){let e=t.get(i)??[0,0];e[0]+=(r+.5)/n.length,e[1]++,t.set(i,e)}});return new Map([...t].map(([e,[t,n]])=>[e,t/n]))}function ic(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=rc(e),u=e=>`\0L${e}`,d=e=>`\0R${e}`,f=new Map(i.map(e=>[e.id,e.pos]));for(let e of o)f.set(u(e),-1/0).set(d(e),-1/0);let p=new Map([...f.keys()].map(e=>[e,[]])),m=new Map([...f.keys()].map(e=>[e,0])),h=(e,t,n)=>{p.get(e).push([t,n]),m.set(t,m.get(t)+1)};for(let t of e)for(let e=1;e<t.length;e++)h(t[e-1].id,t[e].id,r(t[e-1],t[e]));for(let[n,{members:r,gPath:i,r0:o,r1:f}]of a){let a=1/0,p=-1/0;for(let e of r){let r=e.path.length-e.path.indexOf(n),i=e.oExt/2+r*18+(t?r*26:0),o=e.oExt/2+r*18;h(u(n),e.id,i),h(e.id,d(n),o),a=Math.min(a,e.pos-i),p=Math.max(p,e.pos+o)}let m=(a+p)/2,g=e=>{let t=i.findIndex((t,n)=>e.path[n]!==t),n=e.path[t];return n===void 0?void 0:l.get(n)<l.get(i[t])};for(let t=o;t<=f;t++){let r=e[t],i=s[t].get(n),a;if(i)a=[i[0]-1,i[1]+1];else{let e=0,t=r.length;r.forEach((n,r)=>{let i=g(n);i===!0&&(e=Math.max(e,r+1)),i===!1&&(t=Math.min(t,r))});let n=e;for(;n<t&&r[n].pos<m;)n++;a=[n-1,n]}let[o,l]=a;o>=0&&h(r[o].id,u(n),r[o].oExt/2+c),l<r.length&&h(d(n),r[l].id,r[l].oExt/2+c)}}let g=new Map;for(let[e,t]of a){let n=t.gPath.slice(0,-1).join(`\0`);g.set(n,[...g.get(n)??[],e])}for(let e of g.values())for(let t of e)for(let n of e){let[e,r]=[a.get(t),a.get(n)];l.get(t)>=l.get(n)||e.r1<r.r0||r.r1<e.r0||h(d(t),u(n),c)}let _=[...m].filter(([,e])=>e===0).map(([e])=>e),v=new Set;for(;v.size<f.size;){if(!_.length){let e=``,t=1/0;for(let[n,r]of m)!v.has(n)&&r<t&&([e,t]=[n,r]);_.push(e)}let e=_.pop();if(!v.has(e)){v.add(e);for(let[t,n]of p.get(e))v.has(t)||(f.set(t,Math.max(f.get(t),f.get(e)+n)),m.set(t,m.get(t)-1),m.get(t)===0&&_.push(t))}}for(let e of i)e.pos=f.get(e.id)}function ac(e,t){let n=Object.create(e),r=N(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}=le(t.font));let i=N(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)`):N(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,Ye(n,t)}var oc=e=>e===`right`||e===`left`;function sc(e,n={}){return t(e.diagnostics,()=>cc(e,n))}function cc(e,t){let n=ac(me(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??qr,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=oc(i),o=Ze(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=Ze(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=tt(e,t),a=rt(e,t,i,n),o=Qt(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=Ze(i[`max-width`],Ze(e.settings.wrap,0)),l=ec(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c),p;t.body?.length||i.meta||i.frame?(l.card=Xs({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??pc(Ze(i.width,p.w)),g=m?.h??pc(Ze(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(qe(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=dc(e,d,i);m.unshift(...h.edges),mc(p,m);let g=hc(p,m),_=[...e.layout.ranks??[],...h.same].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);_.length&&fc(g,m,_);let v=new Set(m.flatMap(e=>[e.from,e.to])),y=new Map;for(let t of e.edges)if(t.props.constraint===`false`&&d.has(t.from)&&d.has(t.to))for(let[e,n]of[[t.from,t.to],[t.to,t.from]])!v.has(e)&&v.has(n)&&!y.has(e)&&(y.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){fc(g,m,[..._,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)y.set(e,t)}uc(e,h,g);let b=new Map;for(let t of p){let n=d.get(t);b.set(t,{id:t,real:!0,path:nc(e,n.decl.group),oExt:a?n.h:n.w,rExt:a?n.w:n.h,rank:g.get(t),pos:0,u:0})}let x=[],S=new Map;for(let e of m){let[t,n]=e.reversed?[e.to,e.from]:[e.from,e.to],r=g.get(t),i=g.get(n);if(e.hidden){x.push([t,n,2]);continue}if(i-r<=1){x.push([t,n,1]);continue}let a=b.get(t).path,o=b.get(n).path,s=[];for(let e=0;e<Math.min(a.length,o.length)&&a[e]===o[e];e++)s.push(a[e]);let c=t,l=[];for(let n=r+1;n<i;n++){let r=`\u0000${e.idx}:${n}`;b.set(r,{id:r,real:!1,path:s,oExt:6,rExt:0,rank:n,pos:0,u:0}),x.push([c,r,c===t?1:2]),l.push(r),c=r}x.push([c,n,1]),S.set(e.idx,e.reversed?l.reverse():l)}let C=Math.max(0,...[...b.values()].map(e=>e.rank)),w=Array.from({length:C+1},()=>[]);for(let e of b.values())w[e.rank].push(e);let T=new Map,E=new Map;for(let e of b.keys())T.set(e,[]),E.set(e,[]);for(let[e,t,n]of x)E.get(e).push([t,n]),T.get(t).push([e,n]);gc(w,T,E,y);let D=(e,t)=>{let n=0;for(;n<e.path.length&&n<t.path.length&&e.path[n]===t.path[n];)n++;let r=e.path.length-n,i=t.path.length-n,s=(r+i)*18+(r+i>0?10:0);a&&(s+=i*26);let c=!e.real&&!t.real?14:!e.real||!t.real?o*.6:o;return(e.oExt+t.oExt)/2+c+s};for(let e of w){let t=0;e.forEach((n,r)=>{r>0&&(t+=D(e[r-1],n)),n.pos=t})}let O=e=>e.length?e[e.length-1].pos-e[0].pos:0,k=Math.max(...w.map(O));for(let e of w){let t=(k-O(e))/2;for(let n of e)n.pos+=t}let A=e=>e.map(([e,t])=>[b.get(e),t]),ee=[],te=[],ne=[];for(let e of b.values())ee[e.u]=A(T.get(e.id)),te[e.u]=A(E.get(e.id)),ne[e.u]=[...ee[e.u],...te[e.u]];let re=w.map(e=>e.slice(1).map((t,n)=>D(e[n],t))),j=w.map((e,t)=>w.length-1-t),M=w.map((e,t)=>t);for(let e=0;e<16;e++){let t=e<12?e%2==0?`down`:`up`:`both`,n=t===`down`?ee:t===`up`?te:ne;for(let e of t===`up`?j:M){let t=w[e];if(!t.length)continue;let r=[],i=[];for(let e of t){let t=0,a=0;for(let[r,i]of n[e.u])a+=r.pos*i,t+=i;r.push(t?a/t:e.pos),i.push(t||.25)}let a=yc(r,i,re[e]);t.forEach((e,t)=>e.pos=a[t])}}ic(w,a,o,D);let ie=w.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),ae=Array(w.length).fill(0);e.edges.forEach(t=>{if(!t.label||!g.has(t.from)||!g.has(t.to))return;let i=Math.min(g.get(t.from),g.get(t.to));if(Math.abs(g.get(t.from)-g.get(t.to))!==1)return;let o=et(tt(e,t),n),s=t.label.split(`
10
+ `),c=a?Math.max(...s.map(e=>Me(e,o.size,o.weight,n.mono,r)))+16:s.length*Fe(s,o.size)+10;ae[i]=Math.max(ae[i],c)});let oe=[],se=0;for(let e=0;e<w.length;e++)oe.push(se+ie[e]/2),se+=ie[e]+Math.max(c,ae[e]+44);let ce=(e,t)=>{switch(i){case`right`:return{x:e,y:t};case`left`:return{x:-e,y:t};case`down`:return{x:t,y:e};case`up`:return{x:t,y:-e}}};for(let e of b.values()){if(!e.real)continue;let t=d.get(e.id),n=ce(oe[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}let le=new Map;for(let[e,t]of S)le.set(e,t.map(e=>{let t=b.get(e);return ce(oe[t.rank],t.pos)}));let ue=Math.max(0,...[...b.values()].map(e=>e.path.length)),de=1/0,fe=1/0;for(let e of d.values())de=Math.min(de,e.x),fe=Math.min(fe,e.y);if(d.size){let e=ue*18-de,t=ue*44-fe;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of le.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}let pe=Ze(e.settings[`max-width`],0),he=new Set,ge=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0);if(pe>0&&a&&d.size&&!ge){let t=new Map;for(let[e,n]of S)t.set(e,n.map(e=>b.get(e).rank));lc(e,d,g,le,t,he,{maxW:pe,dir:i,rankGap:c})}xc(e,d,a,o);let _e=[...d.values()].some(e=>e.pinned),N=Ec(e,d,n,r),ve=new Map;_e||e.edges.forEach((e,t)=>le.has(t)&&ve.set(e.key,le.get(t)));let ye=Ct(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:ve,channels:_e?void 0:he,obstacles:[...d.values()],groups:N.map(e=>({box:e,header:{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),be=t=>{if(!t.length)return[];let a=e.edges.filter(e=>!d.has(e.from)||!d.has(e.to));if(!a.length)return[];let o=new Map(d);for(let e of t)o.set(e.decl.id,{...e.box,id:e.decl.id,shape:`box`});return Ct({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:new Map,obstacles:[...o.values()]})},xe=jc(e,n,r,Dc(d,N,ye,[]));ye.push(...be(xe));let{bounds:Se,decor:Ce}=Oc(Dc(d,N,ye,xe),e,n,r),we={nodes:d,groups:N,edges:ye,bounds:Se,direction:i,theme:n,blocks:f,decor:Ce,panels:xe};for(let t of qt)t(we,e);return we}function lc(e,t,n,r,i,a,o){let s=Ze(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=new Map;for(let n of t.values()){let t=nc(e,n.decl.group).length;l.set(n.id,{x:n.x-t*18,y:n.y-t*44,w:n.w+2*t*18,h:n.h+t*62})}let u=Array(c+1).fill(!1),d=new Map;for(let r of t.values())for(let t of nc(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 uc(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=kn(tt(e,r))?.[0];if(!r.ref||!i)continue;let a=On(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 dc(e,t,n){let r=[],i=new Map,a=[],o=oc(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=kn(tt(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 fc(e,t,n){let r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));for(let i=0;i<50;i++){let i=!1;for(let t of n){let n=Math.max(...t.map(t=>e.get(t)));for(let r of t)e.get(r)!==n&&(e.set(r,n),i=!0)}for(let n of t){let[t,a]=n.reversed?[n.to,n.from]:[n.from,n.to];if(r.has(t)&&r.get(t)===r.get(a))continue;let o=e.get(t)+(n.len??1);e.get(a)<o&&(e.set(a,o),i=!0)}if(!i)return}}var pc=e=>Math.ceil(e/2)*2;function mc(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 hc(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 gc(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),vc(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),vc(a,u),l(a)}let i=m();i<g&&(g=i,h=e.map(e=>[...e]))}h.forEach((t,n)=>e[n]=t),_c(e)}function _c(e){let t=rc(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 vc(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 yc(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 bc(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 xc(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=>bc(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 Sc(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s}=Cc(e,t),c=e=>Me(e,i,a,t.mono,n,o,s),l=r.meta?Me(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:c,meta:l,lineHeight:Math.round(Fe(e.label.split(`
11
+ `),i)*10)/10}}function Cc(e,t){let n=j(e.props.caps,!1),r=$e(e.props,t.fontSize*.82,600),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}var wc=12;function Tc(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=Sc(s,a,o),l=28+Math.max(...c.text.split(`
12
+ `).map(c.width))+(c.meta?c.meta+wc:0);if(l<=n.w&&!c.text.includes(`
13
+ `))return;if(l>n.w){let a=n=>nc(e,n).includes(t),o=[],s=nc(e,t),c=(e,t,n)=>{let r=0;for(;r<t.length&&t[r]===s[r];)r++;let i=(t.length-n-r+s.length-1-r)*18;o.push({x:e.x-i,y:e.y-i,w:e.w+2*i,h:e.h+2*i})};for(let t of r.values())a(t.decl.group)||c(t,nc(e,t.decl.group),0);for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,nc(e,t),1);let u=-1/0,d=1/0;for(let e of o)e.y>=n.y+n.h+9||e.y+e.h<=n.y-9||(e.x+e.w<=n.x+1?u=Math.max(u,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=l-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-u));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let u=n.w-28-(c.meta?c.meta+wc:0),d=$s(c.text,Math.max(u,40),c.width);if(d.length===1)return;let f=(d.length-1)*c.lineHeight;return n.y-=f,n.h+=f,{lines:d,header:26+f,lineHeight:c.lineHeight}}function Ec(e,t,n,r){let i=t=>nc(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=Math.min(...a.map(e=>e.x))-18,u=Math.min(...a.map(e=>e.y))-18-26,d=Math.max(...a.map(e=>e.x+e.w))+18,f=Math.max(...a.map(e=>e.y+e.h))+18,p={x:l,y:u,w:d-l,h:f-u},m=Tc(e,c,p,t,o,n,r);o.set(c,p);let h=e.groups.get(c);s.push({id:c,decl:h,depth:i(c),...p,...m,style:it({...h,props:tt(e,h)},n)})}return s.sort((e,t)=>e.depth-t.depth)}function Dc(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 Oc(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=Ze(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=tc(t,n);u&&(o-=u.h,t.settings.title&&(s=Math.max(s,a+l+L(P(t.settings.title),u.titleSize,n.mono,r,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+L(P(t.settings.subtitle),u.subSize,n.mono,r)+l)));let d=[];for(let e of Mr.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 kc=(e,t)=>e?t*1.95:0;function Ac(e,t,n,r){return{theme:n,measure:r,fs:Qe(e.props[`font-size`])??n.fontSize,props:e.props,offsets:t}}function jc(e,t,n,r){let i=[];for(let r of e.panels){let a=Mr.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=Ac(r,o,ot(t,r.props,e.themes),n),c=r.failed?{w:0,h:0}:a.measure(r.data,s),l=kc(r.label,s.fs),u=r.label?Me(r.label,s.fs*1.05,$e(r.props,s.fs,650).weight,t.mono,n):0,d=pc(Math.max(c.w,u)+32),f=pc(c.h+l+32),p={x:0,y:0,w:d-32,h:c.h},m;i.push({decl:r,box:{x:0,y:0,w:d,h:f},inner:p,offsets:o,ctx:s,get handles(){return m??=!r.failed&&a.handles?.(r.data,p,s)||[]}})}if(!i.length)return i;let a=Ze(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+kc(t.decl.label,t.ctx.fs)}return i}var Mc=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`);function Nc(e,t){if(!t||!ye(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${Mc(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}var H=e=>(Math.round(e*100)/100).toString(),Pc=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?H(t):Mc(t)}"`,Fc=0;function Ic(e){let t=t=>Re(P((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?` (${Re(P(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&Re(P(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function Lc(e,n,r={}){return t(e.diagnostics,()=>Rc(e,n,r))}function Rc(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(Fc++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&Re(P(s)),l=Ic(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="${H(a.x)} ${H(a.y)} ${H(a.w)} ${H(a.h)}"`+Pc(`width`,n.width??a.w)+(n.width?``:Pc(`height`,a.h))+` role="img"${Pc(`aria-label`,c||`diagram`)}${l?Pc(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${Mc(r.font)}">`),c&&o.push(`<title>${Mc(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${Mc(l)}</desc>`);let f=[];d&&f.push(`<filter id="${i}-sh" x="-20%" y="-20%" width="140%" height="150%"><feDropShadow dx="0" dy="1.5" stdDeviation="2.2" flood-color="${r.shadow}"/></filter>`),r.grid&&f.push(`<pattern id="${i}-grid" width="24" height="24" patternUnits="userSpaceOnUse"><path d="M24 0H0V24" fill="none" stroke="${r.grid}" stroke-width="1"/></pattern>`);let p=n.snapGrid;p&&f.push(`<pattern id="${i}-snap" x="${-p/2}" y="${-p/2}" width="${p}" height="${p}" patternUnits="userSpaceOnUse"><circle cx="${p/2}" cy="${p/2}" r="0.9" fill="${r.node.sub}" opacity="0.35"/></pattern>`),f.length&&o.push(`<defs>${f.join(``)}</defs>`),u&&o.push(`<style>@keyframes ${i}-flow{to{stroke-dashoffset:var(--mf,-40px)}}.${i}-flow{animation:${i}-flow 1.2s linear infinite}@media (prefers-reduced-motion:reduce){.${i}-flow{animation:none}}</style>`),n.transparent||(o.push(`<rect x="${H(a.x)}" y="${H(a.y)}" width="${H(a.w)}" height="${H(a.h)}" fill="${r.background}"/>`),r.grid&&o.push(`<rect x="${H(a.x)}" y="${H(a.y)}" width="${H(a.w)}" height="${H(a.h)}" fill="url(#${i}-grid)"/>`)),p&&o.push(`<rect x="${H(a.x)}" y="${H(a.y)}" width="${H(a.w)}" height="${H(a.h)}" fill="url(#${i}-snap)" pointer-events="none"/>`);let m=tc(e,r);if(m){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=be(r,r.title);s&&(o.push(`<text x="${H(a.x+t)}" y="${H(n+m.titleSize*.8)}" font-size="${H(m.titleSize)}" font-weight="650" xml:space="preserve">${R(P(s),i,r)}</text>`),n+=m.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${H(a.x+t)}" y="${H(n+m.subSize*.95)}" font-size="${H(m.subSize)}" xml:space="preserve">${R(P(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=Mr.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:Ze(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(Bc(e,t,!!n.interactive));o.push(`</g><g class="edges">`);for(let e of t.edges)o.push(Hc(e,i,!!n.interactive));o.push(`</g>`),t.panels?.length&&o.push(`<g class="panels">${t.panels.map(e=>zc(e,t,n.measure,d?`${i}-sh`:null,i)).join(``)}</g>`),o.push(`<g class="nodes">`);for(let n of t.nodes.values())o.push(Gc(e,n,t,d?`${i}-sh`:null));o.push(`</g><g class="labels">`);for(let e of t.edges)e.label&&o.push(Wc(e,t));o.push(`</g></svg>`);let h=o.join(``);for(let n of Jt)h=n(h,e,t);return h}function zc(e,t,n,r,i){let a=t.theme,o=Mr.panels.get(e.decl.kind);if(!o)return``;let s=e.ctx.theme,c=st(e.decl.props,s,a),{box:l}=e,u=e.ctx.fs*1.05*.35,d=$e(e.decl.props,e.ctx.fs,650),f=[`<g${Pc(`data-panel`,e.decl.id)}${Pc(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${H(l.x)}" y="${H(l.y)}" width="${H(l.w)}" height="${H(l.h)}" rx="${H(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${H(c.width)}"${Pc(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${H(l.x+16)}" y="${H(l.y+16+u)}" dominant-baseline="central" font-size="${H(e.ctx.fs*1.05)}" font-weight="${d.weight}"${d.italic?` font-style="italic"`:``} fill="${c.text}" xml:space="preserve">${R(P(e.decl.label),be(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 Bc(e,t,n){let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=Cc(e.decl,r),c=e.decl.label,l=be(r,i.text,i.stroke),u=e.lines??[c],d=e.y+14+Math.round(s.size*.7),f=u.length>1?Ie(u,e.x+14,t=>d+t*e.lineHeight,e=>Le(e,l,r,s.caps)):Le(c,l,r,s.caps),p=c?`<text x="${H(e.x+14)}" y="${H(d)}" font-size="${H(s.size)}" font-weight="${s.weight}"${s.italic?` font-style="italic"`:``} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${f}</text>`:``,m=o.meta?`<text x="${H(e.x+e.w-14)}" y="${H(d)}" text-anchor="end" font-size="${H(a)}" fill="${r.node.sub}" xml:space="preserve">${Le(o.meta,xe(l),r)}</text>`:``;return`<g${Pc(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${H(e.x)}" y="${H(e.y)}" width="${H(e.w)}" height="${H(e.h)}" rx="${H(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${Pc(`stroke-dasharray`,i.dash)}/>`+p+m+`</g>`}function Vc(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:${H(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${H(-i)}px${a}"`}function Hc(e,t,n){let r=e.style,i=[];i.push(`<g${Pc(`data-edge`,e.key)}${r.opacity<1?Pc(`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="${H(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${H(e*3)} ${H(e*9)}`;i.push(a+` opacity="0.35"`+Pc(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+Pc(`stroke-dasharray`,n)+Vc(t,n)+`/>`,a+Pc(`stroke-dasharray`,n)+Vc(t,n,!0)+`/>`)}else i.push(a+Pc(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?Vc(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(Yt(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function Uc(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 Wc(e,t){let n=e.label,r=t.theme,i=e.style,a=i.fontSize,{x:o,y:s}=n.anchor,c=[],l=n.text?n.text.split(`
14
+ `):[],u=be(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=Ie(l,o,e=>m+e*p,e=>Le(e,u,r)),g=r.edge.labelStroke,_=`x="${H(o-d/2)}" y="${H(s-f/2)}" width="${H(d)}" height="${H(f)}" rx="${g?H(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...Uc(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${H(a)}" font-weight="${i.fontWeight}"${i.italic?` font-style="italic"`:``} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
15
+ `),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${H(o-(n.rotate?n.h:p)/2)}" y="${H(f)}" width="${H(n.rotate?n.h:p)}" height="${H(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=Ie(i,o,e=>f+d*(e+.5)+1,e=>Le(e,xe(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${H(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${H(o)} ${H(s)})"`:``;return`<g${Pc(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function Gc(e,t,n,r){let i=t.style,a=tt(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${Mc(a.tooltip)}</title>`:``;if(s.push(`<g${Pc(`data-node`,t.id)}${i.opacity<1?Pc(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${nn(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${H(i.strokeWidth)}"`+Pc(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=rn(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${H(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&Mr.frames.get(o.card.frame.name);e&&s.push(e.render(t,{theme:n.theme,col:{text:i.text,sub:i.sub,stroke:i.stroke},arg:o.card.frame.arg,radius:i.radius,fs:i.fontSize}));let r={text:i.text,sub:i.sub,stroke:i.stroke,body:i.body};s.push(Zs(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`);let c=s.join(``);return c=Nc(c,a.link),c}let l=t.x+t.w/2,u=t.y+t.h/2+tn(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${H(l)}" y="${H(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${H(o.iconSize)}">${Mc(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${H(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+(i.italic?` font-style="italic"`:``)+(o.letterSpacing?` letter-spacing="${H(o.letterSpacing)}"`:``),f={text:i.text,sub:i.sub,stroke:i.stroke},p=Ie(o.lines,l,e=>u+o.lineHeight*(e+.5),e=>Le(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=Ie(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>Le(e,xe(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${H(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}s.push(`</g>`);let m=s.join(``);return m=Nc(m,a.link),m}var Kc=new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),qc=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,Jc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,Yc=/^[\p{L}_][\p{L}\p{N}_-]*$/u,Xc=br;function Zc(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||(Yc.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=ur(r);return i?` [${i}]`:``}var Qc=e=>!!e&&typeof e==`object`&&!Array.isArray(e),$c=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&Jc.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),el=e=>Array.isArray(e)?e:[e];function tl(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)=>Qc(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||Qc(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))Yc.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?Xc(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)Jc.test(e)?Qc(n)?a.push(`.${e}${Zc(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`&&qc.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?``:` `+Xc(String(e.label))}${$c(e.class,t)}${Zc(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
16
+ `);return i.length?(i.some(e=>e.trim()===`}`)&&t.push(`node "${e.id}" body must not contain a line that is only "}"`),[`${n}${r} {`,...i.filter(e=>e.trim()!==`}`).map(e=>`${n} ${e}`),`${n}}`].join(`
17
+ `)):n+r},u=r(`groups`).filter(e=>c(e.id,`group`)),d=new Set(u.map(e=>e.id)),f=r(`nodes`).filter(e=>c(e.id,`node`));for(let e of f)e.group&&!d.has(e.group)&&c(e.group,`group`)&&(u.push({id:e.group}),d.add(e.group));let p=(e,n)=>{let r=` `.repeat(n);for(let t of f.filter(t=>(t.group||void 0)===e))a.push(l(t,r));for(let i of u.filter(t=>(t.parent||void 0)===e))a.push(`${r}group ${i.id}${i.label===void 0?``:` `+Xc(String(i.label))}${$c(i.class,t)}${Zc(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=el(e.from).filter(e=>c(e,`edge.from`)),r=el(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;Kc.has(i)||t.push(`edge arrow "${i}" must be one of ${[...Kc].join(` `)}`);let o=`${e.label===void 0?``:` `+Xc(String(e.label))}${$c(e.class,t)}${Zc(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${Kc.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
18
+ `).replace(/\n+$/,``)+`
19
+ `,errors:t}}var nl=e=>JSON.stringify(e),rl=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:nl(e);function il(e,t=!1){let n=e.trim();return(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),n=n.replace(/<br\s*\/?>/gi,`
20
+ `).replace(/<\/?(b|i|em|strong|span|code)[^>]*>/gi,``).replace(/&quot;|#quot;/g,`"`).replace(/&amp;/g,`&`).replace(/#59;/g,`;`).replace(/\bfa[bsr]?:fa-[\w-]+\s*/g,``).replace(/^`(.*)`$/s,`$1`),t||(n=n.replace(/\*\*(.+?)\*\*/g,`$1`)),n.trim()}var U=(e,t=!1)=>il(e,t).replace(/\s*\n\s*/g,` `);function al(e,t=ol){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 ol=new Set([`group`,`layout`,`import`,`export`,`def`]);function sl(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 cl(e,t,n,r,i){let a=[e,t];return n&&a.push(nl(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}function ll(e){let t=e.match(/^title\b\s*:?\s*(.*)$/i);return t?il(t[1]):void 0}function ul(e,t){return/^(accTitle|accDescr)\b/.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function dl(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 fl=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:nl(e),pl=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 ml(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=pl[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 hl=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],gl={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`};function _l(e,t){let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(nl(e.label));for(let t of e.classes)n.push(`.${t}`);let r=[];e.note&&r.push(`shape: note`),e.sub&&r.push(`sub: ${nl(e.sub)}`),e.style&&r.push(e.style),r.length&&n.push(`[${r.join(`, `)}]`);let i=e.rows.length?e.rows:[...e.attrs,...e.attrs.length&&e.methods.length?[`---`]:[],...e.methods];return i.length?(n.length===1&&n.push(nl(e.id)),[`${t}${n.join(` `)} {`,...i.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function vl(e,t,n,r,i,a,o){let s=[];for(let e of i.items)s.push(..._l(r.get(e),``));for(let e of a){s.push(`group ${e.id} ${nl(e.label)} {`);for(let t of e.items)s.push(..._l(r.get(t),` `));s.push(`}`)}o.length&&s.push(``);for(let e of o){let t=[e.label?fl(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);s.push(`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`)}return[...[e?`title: ${e}`:``,`direction: ${t}`].filter(Boolean),...n.length?[``,...n]:[],``,...s]}var yl=l({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),bl=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,xl=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,Sl=e=>e.replace(/~([^~]*)~/g,`<$1>`),Cl=e=>e.replace(/~[^~]*~/g,``),wl=(e,t)=>{let n=new Map,r={id:``,label:``,items:[]},i=[],a=r,o=[],s=[],c=`down`,l=t.title,u=0,d=e=>{let t=al(Cl(e)),r=n.get(t);return r||(r={id:t,attrs:[],methods:[],rows:[],classes:[]},(t!==e||/~/.test(e))&&(r.label=Sl(e.replace(/^"(.*)"$/,`$1`))),n.set(t,r),a.items.push(t)),r},f=(e,t)=>{let n=Sl(t.trim());if(!n)return;let r=n.match(/^<<(.+)>>$/);r?e.sub=`«${r[1].trim()}»`:(n.includes(`(`)?e.methods:e.attrs).push(n)};for(let p=0;p<e.length;p++){let m=e[p],h=m.text,g=e=>t.warn(m.line,e);if(/^(accTitle|accDescr)\b/.test(h)){t.warnOnce(`acc`,m.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let _=h.match(/^title\s*:?\s*(.*)$/);if(_){l=il(_[1]);continue}let v=h.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(v){c=gl[v[1].toUpperCase()];continue}let y=h.match(/^namespace\s+(\S+)\s*\{$/);if(y){a={id:al(y[1]),label:y[1],items:[]},i.push(a);continue}if(h===`}`){a===r?g(`"}" without a namespace`):a=r;continue}let b=h.match(/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/);if(b){let t=d(b[1]+(b[2]??``));if(b[3]!==void 0&&(t.label=U(b[3])),b[4]&&t.classes.push(b[4]),b[5]&&!b[6])for(;++p<e.length&&e[p].text!==`}`;)f(t,e[p].text);continue}let x=h.match(/^<<(.+)>>\s+(\S+)$/);if(x){d(x[2]).sub=`«${x[1].trim()}»`;continue}let S=h.match(/^note\s+for\s+(\S+)\s+"(.*)"$/);if(S){let e=`note${++u}`;n.set(e,{id:e,label:il(S[2]),attrs:[],methods:[],rows:[],classes:[],note:!0}),a.items.push(e),o.push({from:e,to:d(S[1]).id,arrow:`..`,props:[]});continue}let C=h.match(/^note\s+"(.*)"$/);if(C){let e=`note${++u}`;n.set(e,{id:e,label:il(C[1]),attrs:[],methods:[],rows:[],classes:[],note:!0}),a.items.push(e);continue}let w=h.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=ml(w[2],g);for(let t of w[1].split(`,`))s.push(`.${t.trim()} [${e}]`);continue}let T=h.match(/^cssClass\s+"([^"]+)"\s+([\w-]+)$/);if(T){for(let e of T[1].split(`,`))d(e.trim()).classes.push(T[2]);continue}let E=h.match(/^style\s+(\S+)\s+(.*)$/);if(E){d(E[1]).style=ml(E[2],g);continue}if(/^(click|callback|link)\b/.test(h)){t.warnOnce(`click`,m.line,`click, link and callback are skipped`);continue}let D=h.match(bl)??h.match(xl);if(D){let[,e,n,r,i,a,s,c,l]=D,u=[];r&&u.push(`tail: ${yl[r]}`),a&&u.push(`head: ${yl[a]}`),(r===`o`||a===`o`)&&t.warnOnce(`aggr`,m.line,`aggregation (o--) is drawn with a filled diamond, like composition`);let f=[n,s].filter(e=>e!==void 0);f.length&&u.push(`caption: ${nl(f.join(` to `))}`),o.push({from:d(e).id,to:d(c).id,arrow:i,props:u,label:l?U(l):void 0});continue}let O=h.match(/^([^\s:]+)\s*:\s*(.*)$/);O?f(d(O[1]),O[2]):g(`could not read "${h}"`)}return vl(l,c,s,n,r,i,o)},Tl={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},El={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Dl=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,Ol=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,kl=(e,t)=>{let n=new Map,r={id:``,label:``,items:[]},i=[],a=`down`,o=t.title,s=e=>{let t=e.replace(/^"(.*)"$/,`$1`),i=al(t),a=n.get(i);return a||(a={id:i,attrs:[],methods:[],rows:[],classes:[]},i!==t&&(a.label=t),n.set(i,a),r.items.push(i)),a};for(let n=0;n<e.length;n++){let r=e[n],c=r.text;if(/^(accTitle|accDescr)\b/.test(c)){t.warnOnce(`acc`,r.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let l=c.match(/^title\s*:?\s*(.*)$/);if(l){o=il(l[1]);continue}let u=c.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(u){a=gl[u[1].toUpperCase()];continue}let d=c.match(/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/);if(d){let r=s(d[1]);if(d[2]!==void 0&&(r.label=d[2]),d[3])continue;for(;++n<e.length&&e[n].text!==`}`;){let i=e[n].text.match(Ol);if(!i){t.warn(e[n].line,`could not read attribute "${e[n].text}"`);continue}let a=i[3].replace(/\s+/g,``).replace(/,/g,`, `),o=[i[1],i[2],a,i[4]??``].map(e=>e.replace(/\|/g,`/`));r.rows.push(`| ${o.join(` | `)} |`)}continue}let f=c.match(Dl);if(f){let[,e,t,n,r,a,o]=f;i.push({from:s(e).id,to:s(a).id,arrow:n===`..`?`..`:`--`,props:[`caption: ${nl(`${Tl[t]} to ${El[r]}`)}`],label:U(o)||void 0});continue}let p=c.match(/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/);p?s(p[1]).label=p[2]:/^(classDef|class|style)\b/.test(c)?t.warnOnce(`erstyle`,r.line,`ER styles and classes are skipped`):/^("[^"]*"|[\w-]+)$/.test(c)?s(c):t.warn(r.line,`could not read "${c}"`)}return vl(o,a,[],n,r,[],i)};function Al(e,t){let n=ll(e.text);return n!==void 0&&(t.title=n,!0)}var jl=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,Ml=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,Nl=(e,t)=>{let n={title:t.title},r=[],i=new Map,a=new Set,o=!1,s=(e,t,n=!1)=>{let o=e.trim(),s=i.get(o),c=!s;if(s||(s=al(o),i.set(o,s)),t!==void 0||c&&s!==o){let e=n?`actor`:`participant`,i=t??o;a.has(s)||r.push(i===s?`${e} ${s}`:`${e} ${s} ${nl(i)}`),a.add(s)}return s};for(let i of e){let e=i.text;if(ul(i,t)||Al(i,n))continue;if(e===`autonumber`||e.startsWith(`autonumber `)){o=!0;continue}let a=e.match(/^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/);if(a){let e=a[2];/@\{/.test(e)&&(t.warnOnce(`ptype`,i.line,`participant types (@{ "type": … }) are skipped`),e=e.replace(/@\{.*$/,``)),s(e,a[3]===void 0?e.trim():U(a[3]),a[1]===`actor`);continue}let c=e.match(/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i);if(c){let e=c[1].split(`,`).map(e=>s(e));r.push(`note ${e.join(`, `)}: ${U(c[2])}`);continue}let l=e.match(Ml);if(l){t.warnOnce(`block`,i.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[l[1],U(l[2])].filter(Boolean).join(` `)} ---`);continue}if(e===`end`)continue;if(/^rect\b/.test(e)){t.warnOnce(`rect`,i.line,`"rect" highlight boxes are skipped`);continue}let u=e.match(/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/);if(u){t.warnOnce(u[1],i.line,`"${u[1]}" is not supported and was skipped`);continue}let d=e.match(jl);if(d){let[,e,n,a,o,c]=d;a&&t.warnOnce(`act`,i.line,`activation markers (+/-) are skipped`),n.endsWith(`x`)&&t.warnOnce(`cross`,i.line,`cross arrow ends (-x) are drawn as normal arrows`),n.startsWith(`<<`)&&t.warnOnce(`bidi`,i.line,`two-way arrows (<<->>) are drawn one way`);let l=n.replace(/^<</,``).startsWith(`--`)?`-->`:`->`;r.push(`${s(e)} ${l} ${s(o)}: ${U(c)}`)}else t.warn(i.line,`could not read "${e}"`)}return cl(`sequence`,sl(n.title,`seq`),n.title,o?[`numbered`]:[],r)},Pl=(e,t)=>{let n={title:t.title},r=[],i,a=0;for(let o of e){let e=o.text;if(ul(o,t)||Al(o,n))continue;let s=e.match(/^section\s+(.*)$/);if(s){i=hl[a++%hl.length],t.warnOnce(`section`,o.line,`timeline sections become a colour per section`),r.push(`// ${U(s[1])}`);continue}let c=e.split(/\s*:\s*/).map(e=>U(e));if(e.startsWith(`:`)){if(!r.length||r[r.length-1].startsWith(`//`)){t.warn(o.line,`event detail "${e}" has no event above it`);continue}for(let e of c.slice(1).filter(Boolean))r.push(` - ${e}`);continue}let[l,u,...d]=c;if(!u)t.warn(o.line,`event "${l}" has no text`),r.push(`${l}${i?` [${i}]`:``}: ${l}`);else{r.push(`${l}${i?` [${i}]`:``}: ${u}`);for(let e of d.filter(Boolean))r.push(` - ${e}`)}}return cl(`timeline`,sl(n.title,`events`),n.title,[],r)},Fl=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function Il(e){let t={};for(let n of e.matchAll(Fl))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}var Ll=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``),Rl=(e,t)=>{let n={title:t.title},r=[],i=t.header.match(/^\s*(LR|TB|BT)\s*:?/);(i?.[1]===`TB`||i?.[1]===`BT`)&&r.push(`direction: down`),i?.[1]===`BT`&&t.warn(e[0]?.line??1,`bottom-to-top git graphs are drawn top to bottom`);let a=[],o=(e,t)=>{let n=e.type?.toUpperCase();n===`HIGHLIGHT`?t.push(`highlight`):n===`REVERSE`&&t.push(`reverse`)};for(let r of e){let e=r.text;if(ul(r,t)||Al(r,n))continue;let i=e.match(/^commit\b(.*)$/);if(i){let e=Il(i[1]),t=[];e.id&&t.push(`id: ${rl(Ll(e.id))}`),e.tag&&t.push(`tag: ${rl(e.tag)}`),o(e,t),a.push([`commit`,e.msg?nl(e.msg):``,t.length?`[${t.join(`, `)}]`:``].filter(Boolean).join(` `));continue}let s=e.match(/^branch\s+("[^"]*"|\S+)(.*)$/);if(s){let e=Il(s[2]);a.push(`branch ${Ll(s[1])}${e.order?` [order: ${e.order}]`:``}`);continue}let c=e.match(/^(checkout|switch)\s+(.+)$/);if(c){a.push(`${c[1]} ${Ll(c[2])}`);continue}let l=e.match(/^merge\s+("[^"]*"|\S+)(.*)$/);if(l){let e=Il(l[2]),t=[];e.id&&t.push(`id: ${rl(Ll(e.id))}`),e.tag&&t.push(`tag: ${rl(e.tag)}`),o(e,t),a.push(`merge ${Ll(l[1])}${t.length?` [${t.join(`, `)}]`:``}`);continue}let u=e.match(/^cherry-pick\b(.*)$/);if(u){let e=Il(u[1]);e.parent&&t.warnOnce(`parent`,r.line,`cherry-pick "parent" is skipped`),e.tag&&t.warnOnce(`cptag`,r.line,`cherry-pick "tag" is skipped`),e.id?a.push(`cherry-pick ${Ll(e.id)}`):t.warn(r.line,`cherry-pick needs an id`)}else t.warn(r.line,`could not read "${e}"`)}return cl(`git`,sl(n.title,`history`),n.title,r,a)},zl=e=>/[[\]:]|^"/.test(e)?nl(e):e,Bl=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=ll(r)??n.title);let i=[];for(let r of e){if(ul(r,t)||Al(r,n)||r.text===`showData`)continue;let e=r.text.match(/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/);e?i.push(`${zl(U(e[1]))}: ${e[2]}`):t.warn(r.line,`could not read "${r.text}"`)}return cl(`chart`,sl(n.title,`pie`),n.title,[`type: pie`],i)},Vl=(e,t)=>{let n={title:t.title},r=/\bhorizontal\b/.test(t.header),i=[],a=[];for(let r of e){let e=r.text;if(ul(r,t)||Al(r,n))continue;let o=e.match(/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/);if(o){let e=o[1].trim();e.startsWith(`[`)?i=dl(e).map(e=>U(e)):t.warnOnce(`xrange`,r.line,`a numeric x-axis range becomes 1, 2, 3, …`);continue}if(/^y-axis\b/.test(e)){t.warnOnce(`yaxis`,r.line,`the y-axis title and range are skipped; the chart scales to the data`);continue}let s=e.match(/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/);s?a.push({type:s[1],values:dl(s[2]),line:r.line}):t.warn(r.line,`could not read "${e}"`)}a.length>1&&t.warn(a[1].line,`each xychart series becomes its own chart; yuhwa charts plot one series`);let o=sl(n.title,`xy`),s=[];return a.forEach((e,t)=>{let a=e.values.map((e,t)=>`${zl(i[t]??String(t+1))}: ${e}`),c=e.type===`line`?`line`:r?`bar`:`column`;t&&s.push(``),s.push(...cl(`chart`,t?`${o}${t+1}`:o,n.title,[`type: ${c}`],a))}),a.length||s.push(...cl(`chart`,o,n.title,[`type: column`],[])),s},Hl=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(ul(i,t)||Al(i,n))continue;let a=e.match(/^section\s+(.*)$/);if(a){r.push(`// ${U(a[1])}`);continue}let o=e.match(/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/);if(o){o[3]&&t.warnOnce(`actors`,i.line,`journey actors are skipped; scores become a column chart`);let e=Number(o[2]),n=e<=2?`red`:e<4?`amber`:`green`;r.push(`${zl(U(o[1]))} [${n}]: ${o[2]}`)}else t.warn(i.line,`could not read "${e}"`)}return cl(`chart`,sl(n.title,`journey`),n.title,[`type: column`],r)},Ul=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function Wl(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 Ul){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:il(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:il(r,!0)}}var Gl=(e,t)=>{let n=[],r=[],i=0;for(let a of e){if(ul(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=Wl(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return cl(`mindmap`,sl(t.title,`map`),t.title,[`layout: both`],n)},Kl=new Set([`done`,`active`,`crit`,`milestone`]),ql=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,Jl=(e,t)=>{let n={title:t.title},r=new Set,i=[];for(let t of e){let e=t.text.match(/^([^:]+?)\s*:\s*(.*)$/);if(!e||/^(title|dateFormat|section)\b/.test(t.text)||ql.test(t.text))continue;let n=e[2].split(`,`).map(e=>e.trim()).filter(Boolean);i.push({l:t,label:e[1],items:n});let a=n.filter(e=>!Kl.has(e));a.length===3&&r.add(al(a[0]))}let a=new Map,o=0,s=()=>{let e;do e=`t${++o}`;while(r.has(e));return e},c=(e,n)=>{let r=e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/);return!r||[`h`,`d`,`w`].includes(r[2])?e:(t.warnOnce(`mins`,n,`minute and second lengths are rounded up to 1h`),`1h`)},l=e=>e.replace(/^after\s+(.*)$/,(e,t)=>`after `+t.split(/\s+/).map(e=>a.get(e)??al(e)).join(` `)),u=[],d=0,f=!0;for(let r of e){let e=r.text;if(ul(r,t)||Al(r,n))continue;let o=e.match(/^dateFormat\s+(.*)$/);if(o){/^YYYY-MM-DD( HH:mm)?$/.test(o[1].trim())||t.warn(r.line,`dateFormat "${o[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`);continue}if(ql.test(e)){let n=e.split(/\s+/)[0];t.warnOnce(n,r.line,`"${n}" is not supported and was skipped`);continue}let p=e.match(/^section\s+(.*)$/);if(p){u.push(`--- ${U(p[1])} ---`);continue}let m=i[d];if(!m||m.l!==r){t.warn(r.line,`could not read "${e}"`);continue}d++;let h=m.items.filter(e=>Kl.has(e)),g=m.items.filter(e=>!Kl.has(e)),_,v,y;g.length>=3?[_,v,y]=[al(g[0]),g[1],g[2]]:g.length===2?[_,v,y]=[s(),g[0],g[1]]:[_,y]=[s(),g[0]],g.length>=3&&a.set(g[0],_),g.length>3&&t.warn(r.line,`extra task fields "${g.slice(3).join(`, `)}" are skipped`),f&&!v&&t.warn(r.line,`the first task has no start date`),f=!1,y?.startsWith(`until `)&&(t.warnOnce(`until`,r.line,`"until" ends become a 1d length`),y=`1d`),y&&=c(y,r.line);let b=(h.includes(`milestone`)?[v?l(v):``]:[v?l(v):``,y??``]).filter(Boolean).join(`, `),x=[_,nl(U(m.label)),h.length?`[${h.join(`, `)}]`:``].filter(Boolean).join(` `);u.push(b?`${x}: ${b}`:x)}return cl(`gantt`,sl(n.title,`plan`),n.title,[],u)},Yl=(e,t)=>{let n={title:t.title},r=[];for(let i of e){let e=i.text;if(ul(i,t)||Al(i,n))continue;let a=e.match(/^([xy])-axis\s+(.*)$/);if(a){let[e,t]=a[2].split(/\s*-->\s*/).map(e=>U(e));r.push(`${a[1]}-axis ${e}${t?` -> ${t}`:``}`);continue}let o=e.match(/^quadrant-([1-4])\s+(.*)$/);if(o){r.push(`q${o[1]}: ${U(o[2])}`);continue}if(/^classDef\b/.test(e)){t.warnOnce(`qclass`,i.line,`quadrant point classes are skipped`);continue}let s=e.match(/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/);if(s){let n=Il(s[4].replace(/,/g,` `));/:::/.test(e)&&t.warnOnce(`qclass`,i.line,`quadrant point classes are skipped`),(n.radius||n[`stroke-color`]||n[`stroke-width`])&&t.warnOnce(`qstyle`,i.line,`point radius and stroke are skipped`);let a=n.color&&/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(n.color)?` [${n.color}]`:``;r.push(`${U(s[1])}${a}: ${s[2]}, ${s[3]}`)}else t.warn(i.line,`could not read "${e}"`)}return cl(`quadrant`,sl(n.title,`matrix`),n.title,[],r)},Xl=l({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`});function Zl(e){let t={},n=e.match(/@\{(.*)\}\s*$/),r=n?e.slice(0,n.index).trim():e;if(n)for(let e of n[1].matchAll(/([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g))t[e[1]]=e[2].trim().replace(/^(['"])(.*)\1$/,`$2`);let i=r.match(/^[\w-]*\[(.*)\]$/);return i&&(r=i[1]),{text:U(r,!0),meta:t}}var Ql=(e,t)=>{let n=[],r=Math.min(...e.filter(e=>!/^(accTitle|accDescr)\b/.test(e.text)).map(e=>e.indent));for(let i of e){if(ul(i,t))continue;let{text:e,meta:a}=Zl(i.text);if(i.indent<=r){n.push(e);continue}let o=[];if(a.assigned&&o.push(`owner: ${rl(a.assigned)}`),a.ticket&&o.push(`ticket: ${rl(a.ticket)}`),a.priority){let e=Xl[a.priority.toLowerCase()];e?(/very/i.test(a.priority)&&t.warnOnce(`very`,i.line,`"Very High" and "Very Low" priorities become high and low`),o.push(`priority: ${e}`)):t.warn(i.line,`priority "${a.priority}" is skipped`)}for(let[e,t]of Object.entries(a))![`assigned`,`ticket`,`priority`].includes(e)&&/^[\w-]+$/.test(e)&&o.push(`${e}: ${rl(t)}`);n.push(` - ${e}${o.length?` [${o.join(`, `)}]`:``}`)}return cl(`kanban`,sl(t.title,`board`),t.title,[],n)},$l={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},eu={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},tu=(e,t)=>{let n=new Map,r=new Map,i={id:``,label:``,items:[]},a=[i],o=[],s=[],c=`down`,l=t.title,u=0,d=()=>a[a.length-1],f=(e,t=`state`)=>{let i=al(e),a=n.get(i);return a?t!==`state`&&(a.kind=t):(a={id:i,kind:t,descs:[],classes:[]},i!==e.trim()&&(a.label=il(e)),n.set(i,a),r.has(i)||d().items.push(i)),a},p=e=>{let t=d(),r=e?`end`:`start`;if(!t[r]){let e=t.id?`${t.id}_${r}`:r;t[r]=e,n.set(e,{id:e,label:``,kind:r,descs:[],classes:[]}),t.items.push(e)}return t[r]},m=(e,t)=>{if(e===`[*]`)return p(t);let n=e.match(/^(.+?)(?::::([\w-]+))?$/);if(r.has(al(n[1])))return al(n[1]);let i=f(n[1]);return n[2]&&!i.classes.includes(n[2])&&i.classes.push(n[2]),i.id};for(let p=0;p<e.length;p++){let h=e[p],g=h.text,_=e=>t.warn(h.line,e);if(/^(accTitle|accDescr)\b/.test(g)){t.warnOnce(`acc`,h.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let v=g.match(/^title\s*:?\s*(.*)$/);if(v){l=il(v[1]);continue}let y=g.match(/^direction\s+(TD|TB|BT|LR|RL)$/i);if(y){a.length>1?t.warnOnce(`subdir`,h.line,`direction inside a composite state is skipped`):c=$l[y[1].toUpperCase()];continue}if(/^(hide empty description|scale\b)/.test(g))continue;if(g===`}`){a.length>1?a.pop():_(`"}" without a composite state`);continue}if(g===`--`){t.warnOnce(`conc`,h.line,`concurrent regions (--) are drawn as one region`);continue}let b=g.match(/^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/);if(b){let e=al(b[2]);if(n.delete(e))for(let t of[i,...r.values()])t.items=t.items.filter(t=>t!==e);let t={id:e,label:b[1]===void 0?b[2]:il(b[1]),items:[]};r.set(e,t),d().items.push(t),a.push(t);continue}let x=g.match(/^state\s+(\S+)\s+<<(fork|join|choice)>>$/);if(x){f(x[1],x[2]===`choice`?`choice`:`fork`).label=``;continue}let S=g.match(/^state\s+"([^"]*)"\s+as\s+(\S+)$/);if(S){f(S[2]).label=U(S[1]);continue}let C=g.match(/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/);if(C){let e=f(C[1]);C[2]&&e.descs.push(U(C[2]));continue}let w=g.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(w){let e=ml(w[2],_);for(let t of w[1].split(`,`))s.push(`.${t.trim()} [${e}]`);continue}let T=g.match(/^class\s+([\w,\s-]+?)\s+([\w-]+)$/);if(T){for(let e of T[1].split(`,`))f(e.trim()).classes.push(T[2]);continue}let E=g.match(/^style\s+([\w-]+)\s+(.*)$/);if(E){f(E[1]).style=ml(E[2],_);continue}let D=g.match(/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i);if(D){let t=D[2];if(t===void 0){let n=[];for(;++p<e.length&&e[p].text!==`end note`;)n.push(e[p].text);t=n.join(`
21
+ `)}let r=m(D[1].trim(),!1),i=`note${++u}`;n.set(i,{id:i,label:il(t),kind:`note`,descs:[],classes:[]}),d().items.push(i),o.push({from:i,to:r,dotted:!0});continue}let O=g.match(/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/);if(O){let e=m(O[1],!1),t=m(O[2],!0);o.push({from:e,to:t,label:O[3]?U(O[3]):void 0,line:h.line});continue}let k=g.match(/^([^\s:]+)\s*:\s*(.*)$/);k?f(k[1]).descs.push(U(k[2])):/^(click|link|callback)\b/.test(g)?t.warnOnce(`click`,h.line,`click handlers are skipped`):/^[\p{L}\p{N}_-]+$/u.test(g)?f(g):_(`could not read "${g}"`)}a.length>1&&t.warn(e[e.length-1]?.line??1,`composite state is missing "}"`);for(let e of o){let n=r.get(e.from),i=r.get(e.to);(n||i)&&t.warnOnce(`composite`,e.line??1,`edges to a composite state attach to its start or end inside`),n&&(e.from=n.end??ru(n)??e.from),i&&(e.to=i.start??nu(i)??e.to)}let h=new Set([...n.values()].map(e=>e.kind)),g=c===`right`||c===`left`,_=[];h.has(`start`)&&_.push(`.state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]`),h.has(`end`)&&_.push(`.state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]`),h.has(`fork`)&&_.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${g?8:70}, height: ${g?70:8}]`),h.has(`choice`)&&_.push(`.state-choice [shape: diamond, width: 28, height: 28]`);let v=[],y=(e,t)=>{let r=` `.repeat(t);for(let i of e.items){if(typeof i!=`string`){v.push(`${r}group ${i.id} ${nl(i.label)} {`),y(i,t+1),v.push(`${r}}`);continue}let e=n.get(i),a=[e.id],o=e.label??e.id;(o!==e.id||e.kind===`note`)&&a.push(nl(o));let s=eu[e.kind];s&&a.push(`.${s}`);for(let t of e.classes)a.push(`.${t}`);let c=[];e.kind===`note`&&c.push(`shape: note`),e.descs.length&&c.push(`sub: ${nl(e.descs.join(` / `))}`),e.style&&c.push(e.style),c.length&&a.push(`[${c.join(`, `)}]`),v.push(r+a.join(` `))}};y(i,0),o.length&&v.push(``);for(let e of o){let t=e.dotted?`..`:`->`;v.push(`${e.from} ${t} ${e.to}${e.label?`: `+fl(e.label):``}`)}let b=[l?`title: ${l}`:``,`direction: ${c}`].filter(Boolean),x=[..._,...s];return[...b,...x.length?[``,...x]:[],``,...v]};function nu(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??nu(t);if(e)return e}}function ru(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??ru(n);if(r)return r}}var iu=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*;?\s*$/i,au={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},ou=l({sequenceDiagram:Nl,timeline:Pl,gitGraph:Rl,pie:Bl,"xychart-beta":Vl,xychart:Vl,journey:Hl,mindmap:Gl,gantt:Jl,quadrantChart:Yl,kanban:Ql,stateDiagram:tu,"stateDiagram-v2":tu,classDiagram:wl,"classDiagram-v2":wl,erDiagram:kl}),su=/^(requirementDiagram|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|sankey(?:-beta)?|block(?:-beta)?|architecture(?:-beta)?|packet(?:-beta)?|radar(?:-beta)?|treemap(?:-beta)?|zenuml)$/;function cu(e){let t=e.findIndex(e=>e.trim());if(t<0||e[t].trim()!==`---`)return 0;let n=e.findIndex((e,n)=>n>t&&e.trim()===`---`);return n<0?0:n+1}function lu(e){for(let t=cu(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function uu(e){let t=e.split(`
22
+ `),n=lu(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 ou||su.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 du(e){let t=e.split(`
23
+ `),n=lu(t);if(n>=0&&iu.test(t[n]))return!0;let r=uu(e);return!!r&&r.type in ou}function fu(e){let t=uu(e);return t&&!(t.type in ou)?t.type:void 0}function pu(e){let t=uu(e),n=t&&ou[t.type];if(!t||!n)return vu(e);let r=[],i=new Set,a=e.split(`
24
+ `),o;for(let e=0;e<cu(a);e++){let t=a[e].match(/^\s*title\s*:\s*(.+)$/);t&&(o=il(t[1]))}let s=[];for(let e=t.index+1;e<a.length;e++){let t=a[e].replace(/%%.*$/,``).replace(/\s+$/,``),n=t.trim();if(!n)continue;let r=t.match(/^\s*/)[0];s.push({text:n,line:e+1,indent:r.replace(/\t/g,` `).length})}return{source:n(s,{header:t.rest.replace(/%%.*$/,``).trim(),title:o,warn:(e,t)=>r.push({line:e,message:t}),warnOnce(e,t,n){i.has(e)||(i.add(e),r.push({line:t,message:n}))}}).join(`
25
+ `).replace(/^\n+/,``)+`
26
+ `,warnings:r}}var mu=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],hu=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,gu=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,_u=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/;function vu(e){let t=[],n=[],r=[],i=new Map,a=new Set,o=[],s=0,c=new Set,l=e=>{let t=i.get(e);return t||(t=e.replace(/[^\p{L}\p{N}_-]/gu,`_`).replace(/-+$/,``),/^[\p{L}_]/u.test(t)||(t=`n`+t),ol.has(t)&&(t+=`_`),i.set(e,t),t)},u=()=>` `.repeat(s),d=e.split(`
27
+ `),f=cu(d);for(let e=0;e<d.length;e++){let i=n=>t.push({line:e+1,message:n});if(e<f){let t=d[e].match(/^\s*title\s*:\s*(.+)$/);t&&r.push(`title: ${t[1].trim().replace(/^(["'])(.*)\1$/,`$2`)}`);continue}let p=d[e].replace(/%%.*$/,``);for(let e of yu(p)){let t=e.trim();if(!t)continue;let d=t.match(iu);if(d){d[2]&&r.push(`direction: ${au[d[2].toUpperCase()]}`);continue}if(/^title\s*:?/i.test(t)&&s===0){r.push(`title: ${t.replace(/^title\s*:?\s*/i,``)}`);continue}if(/^direction\s+(TD|TB|BT|RL|LR)$/i.test(t)){s?i(`subgraph direction is not supported; the whole diagram uses one direction`):r.push(`direction: ${au[t.split(/\s+/)[1].toUpperCase()]}`);continue}let f=t.match(/^subgraph\s+(.*)$/);if(f){let e=f[1].trim(),t,r,i=e.match(/^([\w-]+)\s*\[(.*)\]$/);i?[t,r]=[l(i[1]),il(i[2])]:/^".*"$/.test(e)?[r,t]=[il(e),l(il(e).toLowerCase())]:/^[\w-]+$/.test(e)?[t,r]=[l(e),e]:[r,t]=[e,l(e.toLowerCase())],c.add(t),n.push(`${u()}group ${t} ${nl(r)} {`),s++;continue}if(t===`end`){s?(s--,n.push(`${u()}}`)):i(`"end" without subgraph`);continue}let p=t.match(/^classDef\s+([\w,-]+)\s+(.*)$/);if(p){let e=ml(p[2],i);for(let t of p[1].split(`,`))o.push(`.${t.trim()} [${e}]`);continue}let m=t.match(/^class\s+([\w,\s-]+?)\s+([\w-]+)$/);if(m){for(let e of m[1].split(`,`))n.push(`${u()}${l(e.trim())} .${m[2]}`);continue}let h=t.match(/^style\s+([\w-]+)\s+(.*)$/);if(h){let e=ml(h[2],i);e&&n.push(`${u()}${l(h[1])} [${e}]`);continue}if(/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/.test(t)){i(`"${t.split(/\s+/)[0]}" is not supported and was skipped`);continue}let g=bu(t,l,i);if(g){for(let e of g.nodes){let t=[e.id];e.label!==void 0&&e.label!==e.id&&t.push(nl(e.label));for(let n of e.classes)t.push(`.${n}`);e.shape&&t.push(`[shape: ${e.shape}]`),(!a.has(e.id)||t.length>1||s)&&(n.push(u()+t.join(` `)),a.add(e.id))}for(let e of g.edges){let t=[e.label?/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e.label)?e.label:nl(e.label):``,e.props?`[${e.props}]`:``].filter(Boolean).join(` `);n.push(`${u()}${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`)}}}}for(;s>0;)s--,n.push(`${u()}}`),t.push({line:d.length,message:`subgraph is missing "end"`});for(let e of c)a.has(e)&&t.push({line:1,message:`"${e}" is both a node and a subgraph; edges to subgraphs are not supported`});let p=[...r,...o.length?[``,...o]:[]];return{source:[...p,...p.length?[``]:[],...n].join(`
28
+ `)+`
29
+ `,warnings:t}}function yu(e){let t=[],n=0,r=``,i=0;for(let a=0;a<e.length;a++){let o=e[a];r?o===r&&(r=``):o===`"`?r=o:`[({`.includes(o)?n++:`)]}`.includes(o)?n=Math.max(0,n-1):o===`;`&&n===0&&(t.push(e.slice(i,a)),i=a+1)}return t.push(e.slice(i)),t}function bu(e,t,n){let r=0,i=e,a=()=>{for(;r<i.length&&/\s/.test(i[r]);)r++},o=[],s=()=>{a();let e=i.slice(r).match(hu);if(!e)return null;r+=e[0].length;let n={id:t(e[0]),classes:[]};for(let[e,t,a]of mu){if(!i.startsWith(e,r))continue;let o=xu(i,r+e.length,t);if(!(o<0)){n.label=il(i.slice(r+e.length,o)),n.shape=a||void 0,r=o+t.length;break}}for(;i.startsWith(`:::`,r);){let e=i.slice(r+3).match(/^[\w-]+/);if(!e)break;n.classes.push(e[0]),r+=3+e[0].length}return o.push(n),n},c=()=>{let e=[];for(;;){let t=s();if(!t)return e.length?e:null;if(e.push(t),a(),i[r]===`&`)r++;else return e}},l=c();if(!l)return n(`could not read "${e}"`),null;let u=[],d=l;for(;a(),!(r>=i.length);){let t=i.slice(r),a=t.match(gu),o,s,l,f;if(a&&/[->=]/.test(a[4]))[o,s,f]=[a[1],a[2],il(a[3])],l=a[4].endsWith(`>`)?`>`:a[5],r+=a[0].length;else{if(a=t.match(_u),!a){n(`could not read "${t}"`);break}[o,s,l]=[a[1],a[2],a[3]],f=a[4]===void 0?void 0:il(a[4]),r+=a[0].length}let p=s.startsWith(`=`),m=s.includes(`.`),h=!!l,g=!!o,_,v=[];_=g&&h?`<->`:!h&&!g?`--`:p?`=>`:m?`..>`:`->`,(_===`<->`||_===`--`)&&(p&&v.push(`width: 3`),m&&v.push(`style: dotted`)),l===`o`&&v.push(`head: dot`),l===`x`&&v.push(`head: bar`),o===`o`&&v.push(`tail: dot`),o===`x`&&v.push(`tail: bar`),g&&!h&&(_=`--`,v.push(`tail: arrow`));let y=c();if(!y){n(`link without a target in "${e}"`);break}for(let e of d)for(let t of y)u.push({from:e.id,to:t.id,arrow:_,label:f||void 0,props:v.join(`, `)||void 0});d=y}return{nodes:o,edges:u}}function xu(e,t,n){let r=!1;for(let i=t;i<e.length;i++)if(e[i]===`"`&&(r=!r),!r&&e.startsWith(n,i))return i;return-1}var Su=e=>Math.round(e),Cu=e=>e.split(/\r?\n/),wu=e=>e.includes(`\r
30
+ `)?`\r
31
+ `:`
32
+ `,Tu=(e,t)=>e.join(wu(t));function Eu(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 ${Su(r.x)} ${Su(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${Su(r.w)} ${Su(r.h)}`),e.length>1&&t.push(` `+e.join(` `))}for(let n of e.ranks??[])t.push(` rank ${n.join(` `)}`);for(let[n,r]of Object.entries(e.edges)){let e=[n];r.via?.length&&e.push(`via `+r.via.map(e=>`${Su(e.x)} ${Su(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(Su(r.label.x)||Su(r.label.y))&&e.push(`label ${Su(r.label.x)} ${Su(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 ${Su(r.at.x)} ${Su(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(Su(i.x)||Su(i.y))&&t.push(` ${n}:${e} ${Su(i.x)}${Su(i.y)?` ${Su(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
33
+ `)}\n}`:``}function Du(e,t,n=Sr(e)){let r=Eu(t),i=Cu(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
+ `):[]),Tu(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=wu(e);return a+o+o+r.split(`
35
+ `).join(o)+o}var Ou=e=>ur({v:e}).replace(/^v: /,``);function ku(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=B(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=ur(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 Au=(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 ju(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length,a=i>0&&t[i-1].trim()!==``&&n.layoutBlock?[r,``]:[r];return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),Tu(t,e)}var Mu=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Nu=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e);function Pu(e,t,n,r=Sr(e)){let i=Au(r,t);if(!i)return e;let a=Cu(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?ju(e,a,r,`${t.id} ${Mu(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+$/,``),Tu(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&Nu(n)?n:Mu(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),Tu(a,e)}var Fu={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function Iu(e,t,n,r,i=Sr(e)){n=rr(n);let a=Au(i,t);if(!a)return e;let o=Lu(e,t,n,r,i,a);for(let e of(Fu[n]??[]).filter(e=>e in a.props))o=Iu(o,t,e,null);return o}function Lu(e,t,n,r,i,a){let o=Cu(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:ju(e,o,i,`${t.id} [${ur({[n]:r})}]`);let c=s.propLines;if(c){let i=s.props?B(o[s.line].slice(s.props[0]+1,s.props[1]-1)):{};if(n in c)return r===null?o.splice(c[n],1):o[c[n]]=`${o[c[n]].match(/^\s*/)[0]}${n}: ${Ou(r)}`,n in i&&ku(o,s,t.kind,n,null),Tu(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${o[t].match(/^\s*/)[0]}${n}: ${Ou(r)}`),Tu(o,e)}}return ku(o,s,t.kind,n,r),Tu(o,e)}function Ru(e,t,n){let r=Cu(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 er($n(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}`,Tu(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}`),Tu(r,e)}function zu(e,t,n,r=Sr(e)){let i,a=Vu(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 Bu(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 Du(e,t.layout,t);let[o,s]=i.lines,c=Cu(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,$n(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return Du(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 Du(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 Tu(c,e)}function Vu(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&Ln.get(i.kind);if(!i?.lines||!a||i.failed||i.ref&&i.ref.generated)return e;let[o,s]=i.lines;if(s-o-1!==i.body.length)return e;let c=r(a,i);if(!c)return e;let l=Cu(e),u=l.slice(o+1,s).filter(e=>e.trim()),d=u.length?u.map(e=>e.match(/^\s*/)[0]).reduce((e,t)=>t.length<e.length?t:e):l[o].match(/^\s*/)[0]+` `;return l.splice(o+1,s-o-1,...c.map(e=>e.trim()?d+e:``)),Tu(l,e)}function Hu(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 Uu=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 Wu(e,t){return[...e.matchAll(RegExp(`${t}(?:="([^"]*)"|\\s*:\\s*([^;"}]+))`,`g`))].map(e=>Uu(e[1]??e[2]).trim())}function Gu(e){let t=new Set;for(let n of Wu(e,`font-family`))for(let e of n.split(`,`))t.add(xr(e).toLowerCase());return t}var Ku={normal:400,bold:700};function qu(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 Uu(e.slice(1,-1)))t.add(n.codePointAt(0));let r=new Set([400]);for(let t of Wu(e,`font-weight`)){let e=Ku[t]??Number(t);e>0&&r.add(e)}let i=Wu(e,`font-style`).some(e=>/^(?:italic|oblique)/.test(e));return{families:Gu(e),chars:t,weights:r,italic:i}}function Ju(e){let[t,n=t]=(e??`normal`).trim().split(/\s+/).map(e=>Ku[e]??(Number(e)||400));return[t,n]}function Yu(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 Xu(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)Yu(e,Ju(n.weight))<Yu(e,Ju(t.weight))&&(t=n);i.add(t)}}return e.filter(e=>i.has(e))}function Zu(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 Qu(e,t){let n=e.match(/url\(\s*(['"]?)(.*?)\1\s*\)/);if(n)try{return new URL(n[2],t).href}catch{return}}function $u(e,t){let n=Qu(e(`src`),t),r=xr(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 ed(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*\{([^}]*)\}/g)){let e=r[1],i=$u(t=>e.match(RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`,`i`))?.[1]??``,t);i&&n.push(i)}return n}var td=32;function nd(e,t,n){let r=e.get(t);return r||(e.set(t,r=n()),e.size>td&&e.delete(e.keys().next().value),r)}var rd=new Map,id;function ad(){return id??=od().finally(()=>id=void 0)}async function od(){if(typeof document>`u`)return[];let e=[],t=[],n=(t,i)=>{for(let a of Array.from(t))if(a instanceof CSSFontFaceRule){let t=$u(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(nd(rd,n,()=>fetch(n).then(e=>e.ok?e.text():``).then(e=>ed(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 sd(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 cd=new Map;function ld(e){return e.startsWith(`data:`)?Promise.resolve(e):nd(cd,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,${sd(new Uint8Array(t))}`).catch(()=>void 0))}var ud=e=>`"${e.replace(/["\\<>]/g,``)}"`,dd=e=>e.replace(/[;{}<>"\\]/g,``);async function fd(e,t=`page`){let n=qu(e),r=Xu((t===`page`?await ad():t).filter(e=>n.families.has(e.family.toLowerCase())&&Zu(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]=[Ju(t.weight),Ju(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 ld(e.url);return t?`@font-face{font-family:${ud(e.family)};src:url(${t});`+(e.weight?`font-weight:${dd(e.weight)};`:``)+(e.style?`font-style:${dd(e.style)};`:``)+(e.unicodeRange?`unicode-range:${dd(e.unicodeRange)};`:``)+`}`:``}))).join(``);return a?e.replace(/<svg\b[^>]*>/,e=>`${e}<style>${a}</style>`):e}async function pd(e){let t=typeof document>`u`?void 0:document.fonts;if(!t)return!1;let{families:n,chars:r,weights:i,italic:a}=qu(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 ${ud(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 md(e,t={}){let{width:n,height:r}=Hu(e),i=t.scale??(typeof devicePixelRatio==`number`&&devicePixelRatio>0?devicePixelRatio:1),a=t.fonts??`page`,o=a===!1?e:await fd(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 hd(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=tl(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`}))}}let t=fu(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(du(e)){let t=pu(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 gd=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}},_d=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}}}},vd=[{name:`Everything (showcase)`,source:`title: **Shopfront** platform
36
+ subtitle: everything yuhwa can draw, in one file
37
+ direction: right
38
+ theme: paper
39
+ panels: wrap
40
+ panel-gap: 40
41
+ legend: .svc Service | .store Datastore | .ext External | --> async | ..> optional | red Deprecated
42
+ footer: yuhwa showcase | {teal: v1.0} | 2026
43
+
44
+ // variables: replaced in labels, props, settings and panel bodies
45
+ $brand: indigo
46
+ $db: "Postgres 16"
47
+ $warn: rgb(234, 88, 12)
48
+
49
+ // classes, one built on another
50
+ .svc [color: $brand, shape: rounded]
51
+ .store [amber, cylinder]
52
+ .ext [color: hsl(330 70% 50%), dashed]
53
+ .primary .svc [bold, shadow]
54
+ .async [dashed, flow: true]
55
+
56
+ // a component: one service, its database and the edge between them
57
+ def service(id, label, lang = Go) {
58
+ $id "$label" .svc [sub: $lang]
59
+ \${id}_db "$label DB" .store
60
+ $id -> \${id}_db: SQL
61
+ }
62
+
63
+ // nodes: every shape, sub lines, icons, links and tooltips
64
+ user "Customer" [shape: circle, purple, icon: 🙂]
65
+ admin "Admin" [ellipse, #0ea5e9]
66
+ web "Storefront" [frame: browser shop.example.com] {
67
+ **Cart** || 3 items
68
+ ---
69
+ progress: 72% checkout funnel
70
+ spark: 3 5 4 6 8 7 9
71
+ }
72
+
73
+ group edge "Edge" [color: slate, dashed] {
74
+ cdn "CDN" [hexagon, teal, link: https://example.com, tooltip: cached at 40 PoPs]
75
+ waf "WAF" [parallelogram, color: tomato]
76
+ }
77
+
78
+ group core "Core services" [color: #4f46e5] {
79
+ gateway "API Gateway" .svc .primary [sub: "auth, rate limit"]
80
+ service(orders, Orders, Kotlin)
81
+ service(payments, Payments, lang: Rust)
82
+ group search "Search" [teal] {
83
+ indexer "Indexer" .svc
84
+ es "Elasticsearch" .store [color: $warn]
85
+ }
86
+ }
87
+
88
+ queue "Event bus" [diamond, lime]
89
+ stripe "Stripe" .ext [document]
90
+ legacy "Legacy ERP" [box, red, opacity: 0.7]
91
+ note "nightly sync,\\nbest effort" [note, yellow-100]
92
+
93
+ metrics "metrics" [meta: live, caps: true] {
94
+ stat: 99.98% uptime | 41ms p50
95
+ bars: 3 5 4 6 8 9 7
96
+ | service | p95 |
97
+ |----------|--------|
98
+ | orders | 120 ms |
99
+ | payments | 88 ms |
100
+ ✓ health || [[green: ok]]
101
+ }
102
+
103
+ // edges: every arrow, labels, captions and edge props
104
+ user -> web: browse
105
+ web -> cdn: assets [label-bg: lightyellow, curve: straight]
106
+ admin => cdn: purge [color: $brand, width: 3]
107
+ cdn -> waf -> gateway
108
+ gateway -> orders, payments
109
+ gateway <-> indexer: query [curve: orthogonal]
110
+ orders --> queue: OrderPlaced .async
111
+ queue ..> indexer: reindex [caption: within 2 s]
112
+ payments -> stripe: charge [head: dot, color: #db2777]
113
+ indexer -- es
114
+ queue -> legacy: export [dotted, red]
115
+ legacy .. note
116
+ stripe == metrics
117
+
118
+ // panels, in reading order: how it works, how it runs, what comes next
119
+ sequence login "Sign in" [numbered, lifeline-style: dotted] {
120
+ actor user "Customer" [purple]
121
+ participant web, db
122
+ participant api "API" [indigo]
123
+ user -> web: open /login
124
+ web -> api: POST /login
125
+ api -> db: find user
126
+ db --> api: row [width: 2]
127
+ api -> db: audit [red, dotted, head: open]
128
+ note api: checks the hash [amber]
129
+ --- session ---
130
+ api --> web: 200 + cookie [green]
131
+ web -> web: render
132
+ }
133
+
134
+ chart p95 "Latency p95" [type: column, unit: ms] {
135
+ checkout: 120
136
+ search [green]: 48
137
+ payments [hsl(330 70% 50%)]: 88
138
+ }
139
+
140
+ chart traffic "Traffic by region" [type: donut, unit: %, theme: midnight, shadow] {
141
+ EU: 46
142
+ US [indigo]: 31
143
+ APAC: 23
144
+ }
145
+
146
+ quadrant prio "Priorities" [background: lightyellow, border: orange, border-style: dashed, radius: 6] {
147
+ x-axis Low effort -> High effort
148
+ y-axis Low value -> High value
149
+ q1 [green]: Quick wins
150
+ q2: Big bets
151
+ q3: Fill-ins
152
+ q4 [red]: Money pit
153
+ Search [teal]: 0.25, 0.8
154
+ Billing: 0.7, 0.65
155
+ Exports [color: tomato]: 0.3, 0.3
156
+ }
157
+
158
+ // three looks for a gantt: a label column, names on solid bars, thin lines
159
+ gantt plan "Q1 plan" [today: 2026-01-20, weekends: show] {
160
+ --- Design [violet] ---
161
+ research "User research" [progress: 100%]: 2026-01-05, 5d
162
+ wireframes [done]: after research, 4d
163
+ review [milestone]: after wireframes
164
+ --- Build [teal] ---
165
+ api "Build API" [active, progress: 40%, owner: ana]: 2026-01-14, 2w
166
+ ui [crit, owner: kim]: after wireframes api, 10d
167
+ launch [milestone, red]: after ui
168
+ }
169
+
170
+ gantt release "Release 2.0" [theme: midnight, today: 2026-02-18, bars: solid, labels: bar, notes: dates, density: compact, arrows: curved, summary: hide] {
171
+ --- Beta [sky] ---
172
+ beta "Private beta" [progress: 80%]: 2026-02-02, 2w
173
+ feedback "Feedback round" [active]: after beta, 1w
174
+ --- GA [green] ---
175
+ docs "Docs" [progress: 30%]: 2026-02-16, 10d
176
+ ga "General availability" [milestone]: after feedback docs
177
+ }
178
+
179
+ gantt hiring "Hiring" [bars: thin, labels: bar, rows: plain, grid: none, scale: week, density: loose] {
180
+ sourcing "Sourcing" [blue, progress: 70%]: 2026-01-05, 3w
181
+ interviews "Interviews" [indigo]: after sourcing, 4w
182
+ offers "Offers" [green]: after interviews, 2w
183
+ start "First day" [milestone]: after offers
184
+ }
185
+
186
+ timeline roadmap "Roadmap" [border: 2] {
187
+ 2026 Q1: Private beta
188
+ - 40 design partners
189
+ 2026 Q2 [green]: **Launch**
190
+ 2026 Q3 [#0ea5e9]: Mobile app
191
+ 2026 Q4 [color: rgb(234, 88, 12)]: EU region
192
+ }
193
+
194
+ kanban sprint "Sprint 12" {
195
+ Todo [gray]
196
+ - Write docs [owner: ana, priority: high]
197
+ - **Fix** login [red]
198
+ Doing [blue, limit: 2]
199
+ - API v2 [ticket: MER-12]
200
+ needs the new auth flow
201
+ - Search tuning [owner: kim]
202
+ - Billing export
203
+ Done [green]
204
+ - Ship 1.0
205
+ }
206
+
207
+ git release_flow "Release flow" {
208
+ commit "init" [tag: v1.0]
209
+ branch feature/login [pink]
210
+ commit "login form"
211
+ commit "oauth"
212
+ checkout main
213
+ commit "hotfix" [id: fix, highlight, red]
214
+ merge feature/login [tag: v1.1]
215
+ branch release/1.0 from v1.0 [label: "1.0.x", #0ea5e9]
216
+ cherry-pick fix
217
+ }
218
+
219
+ // a file tree: rules, compact folders, counts, sizes and git status
220
+ treeview repo "Repo" [sort: folders, chevrons, compact, folder-color: $brand, rows: striped] {
221
+ match *.test.ts [dim]
222
+ match docs/ [collapsed]
223
+ services/
224
+ checkout/
225
+ main.go: entry point
226
+ cart.go [modified, size: 6 KB]
227
+ cart_test.go [added]
228
+ search/
229
+ index/
230
+ query.go [size: 3 KB]
231
+ web/
232
+ app/
233
+ page.tsx [badge: new]
234
+ page.test.ts
235
+ ...
236
+ docs/
237
+ intro.md
238
+ api.md
239
+ scripts/
240
+ deploy.sh
241
+ shop.yu [highlight] # this file
242
+ package.json
243
+ }
244
+
245
+ mindmap ideas "Launch plan" [layout: both] {
246
+ **Launch**
247
+ Marketing [pink]
248
+ Blog posts
249
+ Newsletter
250
+ Product
251
+ Beta [#16a34a]
252
+ - Pricing page
253
+ Sales [shape: pill]
254
+ Partners
255
+ }
256
+ `},{name:`Multi-file system`,source:`title: Shop platform
257
+ subtitle: three files, one diagram
258
+ legend: .svc Service | .store Datastore | .ext External | --> async
259
+
260
+ // the shared look: only what styles.yu exports
261
+ import { theme, .svc, .store, .ext, .async, $brand } from "./shared/styles.yu"
262
+ accent: $brand
263
+ // the orders group (with its members) and payments, renamed
264
+ import { orders, payments as billing } from "./services.yu"
265
+ // the release history panel
266
+ import "./release.yu"
267
+
268
+ user "Shopper" [circle, purple]
269
+ web "Storefront" .svc
270
+ sub: Next.js
271
+ stripe "Stripe" .ext
272
+
273
+ user -> web: browses [flow]
274
+ web -> orders-api: place order
275
+ orders-api -> billing: charge
276
+ billing -> stripe: API .async
277
+ `,files:{"shared/styles.yu":`// shared classes, imported by every diagram
278
+ // one theme for every file that imports it (a plain theme: line would stay here)
279
+ export theme: pastel
280
+ export $brand: blue
281
+ .svc
282
+ color: $brand
283
+ shape: rounded
284
+ .store [amber, cylinder]
285
+ .ext [slate, dashed]
286
+ .async
287
+ style: dashed
288
+ flow: true
289
+ .internal [red]
290
+
291
+ // .internal stays private to this file
292
+ export .svc, .store, .ext, .async
293
+ `,"services.yu":`import { theme, .svc, .store } from "./shared/styles.yu"
294
+
295
+ // one service: its API, its database and the line between them
296
+ def service(id, label, store, lang = Go) {
297
+ $id "$label" .svc
298
+ sub: $lang
299
+ $store .store
300
+ $id -> $store
301
+ }
302
+
303
+ export orders, payments, search
304
+
305
+ group orders "Orders" {
306
+ service(orders-api, "Orders API", orders-db, Kotlin)
307
+ }
308
+
309
+ payments "Payments" .svc
310
+ sub: Go
311
+ search "Search" .svc
312
+ `,"release.yu":`git release "Releases" {
313
+ commit "init" [tag: v0.1.0]
314
+ branch feature/cart
315
+ commit "cart model"
316
+ commit "checkout"
317
+ checkout main
318
+ commit "hotfix" [id: hotfix, type: highlight]
319
+ merge feature/cart [tag: v0.2.0]
320
+ branch release/0.2
321
+ cherry-pick hotfix
322
+ }
323
+ `}},{name:`Web app`,source:`title: Web app
324
+ direction: right
325
+
326
+ .svc [blue]
327
+
328
+ user "You" [circle, purple]
329
+ group app "Your app" {
330
+ web "Web app" .svc
331
+ sub: Next.js
332
+ api "API" .svc
333
+ }
334
+ db "Database" [cylinder, amber]
335
+
336
+ user -> web: visits
337
+ flow: true
338
+ web -> api
339
+ api -> db: SQL
340
+ `},{name:`Team ownership`,source:`title: Who owns what
341
+ subtitle: three teams, one request path
342
+ theme: pastel
343
+
344
+ .web [blue]
345
+ .platform [purple]
346
+ .data [green]
347
+
348
+ group web "Web team" .web {
349
+ meta: 5 people
350
+ site "Marketing site" .web
351
+ shop "Shop frontend" .web
352
+ }
353
+ group platform "Platform team" .platform {
354
+ meta: 4 people
355
+ gw "API gateway" .platform
356
+ auth "Auth" .platform
357
+ }
358
+ group data "Data team" .data {
359
+ meta: 3 people
360
+ wh "Warehouse" .data [cylinder]
361
+ bi "Dashboards" .data
362
+ }
363
+
364
+ site, shop -> gw
365
+ gw -> auth
366
+ gw ..> wh: events
367
+ flow: true
368
+ wh -> bi
369
+ `},{name:`Release dashboard`,source:`title: Shop release **v2.4**
370
+ subtitle: what ships on {green: Friday}
371
+ footer: **landfall** v2.4 | \`eu-central-1\` | updated {green: 2 min ago}
372
+ theme: midnight
373
+
374
+ app "Storefront" [frame: browser shop.example.com, blue] {
375
+ stat: 99.9% uptime | 42ms p95 | 1.2k rps
376
+ ---
377
+ spark blue: 3 5 4 6 8 7 9 12 10 14
378
+ }
379
+ ci "Pipeline" [frame: terminal ~/shop, meta: 42s] {
380
+ progress green: 72% tests
381
+ progress amber: 9/12 deploys
382
+ bars purple: 3 5 4 8 6 9
383
+ }
384
+ flags "Flags" [frame: window Settings] {
385
+ new-checkout || [[green: on]]
386
+ dark-mode || [[off]]
387
+ }
388
+
389
+ app -> ci: build
390
+ flow: true
391
+ ci -> flags
392
+ `},{name:`Service table`,source:`title: Service status
393
+ theme: terminal
394
+
395
+ api "api" [meta: v3.2, green] {
396
+ | route | p95 | rps |
397
+ |----------|-------|------|
398
+ | /orders | 42ms | 310 |
399
+ | /cart | 18ms | 920 |
400
+ }
401
+ db "postgres" [cylinder, amber]
402
+
403
+ api -> db: pool 20
404
+ `},{name:`Annotated sketch`,source:`theme: mono
405
+ curve: straight
406
+
407
+ a "Input" -> b "Parse" -> c "Layout" -> d "Render" -> e "SVG" [document]
408
+ note "deterministic:\\nsame input, same SVG" [note]
409
+ d -- note
410
+ style: dotted
411
+ constraint: false
412
+ `},{name:`Sign-in story`,source:`title: Sign in
413
+ subtitle: flow, sequence and numbers in one file
414
+ panels: row
415
+
416
+ web "Web" [blue] -> api "API" [blue] -> db "Postgres" [cylinder, amber]
417
+
418
+ sequence login "Sign in" [numbered] {
419
+ actor user "Customer" [purple]
420
+ participant web, api, db
421
+ user -> web: open /login
422
+ web -> api: POST /login
423
+ api -> db: find user
424
+ db --> api: row
425
+ note api: compares the **bcrypt** hash
426
+ api --> web: 200 + cookie
427
+ }
428
+
429
+ chart latency "Latency p95" [unit: ms] {
430
+ checkout: 120
431
+ search [green]: 48
432
+ login: 80
433
+ }
434
+ `},{name:`Git flow`,source:`title: Release flow
435
+ subtitle: trunk-based, short-lived branches
436
+
437
+ git flow "main and feature branches" {
438
+ commit "init" [tag: v0.1.0]
439
+ branch feature/login
440
+ commit "login form"
441
+ commit "oauth provider"
442
+ checkout main
443
+ commit "fix typo"
444
+ branch fix/cache [amber]
445
+ commit "cache headers"
446
+ checkout main
447
+ merge fix/cache [tag: v0.1.1]
448
+ merge feature/login [tag: v0.2.0]
449
+ commit "docs"
450
+ }
451
+ `},{name:`Project structure`,source:`title: Project structure
452
+ subtitle: what lives where, and what this PR touches
453
+ theme: paper
454
+ panels: wrap
455
+
456
+ treeview layout "acme" [sort: folders, chevrons, compact, counts: all, notes: column, lines: rounded, rows: striped, folder-color: teal, edge-color: teal, edge-width: 1.5, radius: 14, shadow] {
457
+ match **/*.test.ts [dim, icon: test]
458
+ match node_modules/ [collapsed]
459
+ match *.{png,svg} [purple]
460
+ apps/
461
+ web/
462
+ src/
463
+ main.ts: boots the app
464
+ router.ts
465
+ pages/
466
+ home.tsx [badge: new]
467
+ checkout.tsx
468
+ ...
469
+ public/
470
+ logo.svg
471
+ hero.png
472
+ api/
473
+ src/
474
+ main/
475
+ java/
476
+ com/
477
+ acme/
478
+ App.java: entry point
479
+ OrderController.java
480
+ build.gradle [icon: package]
481
+ packages/
482
+ ui/: shared components
483
+ Button.tsx [size: 2.1 KB]
484
+ Button.test.ts [size: 1.4 KB]
485
+ Card.tsx [size: 3.8 KB]
486
+ config/: lint and tsconfig presets
487
+ eslint.js
488
+ tsconfig.json
489
+ docs/ [collapsed]
490
+ intro.md
491
+ deploy.md
492
+ node_modules/
493
+ react/
494
+ .github/
495
+ workflows/
496
+ ci.yml: lint, test, build
497
+ pnpm-workspace.yaml
498
+ README.md [highlight]
499
+ }
500
+
501
+ treeview pr "feat: dark mode" [sort: folders, marks: letter, highlight-color: amber, line-color: gray, lines: dashed] {
502
+ src/
503
+ theme/
504
+ dark.ts [added, size: +120]
505
+ tokens.ts [modified, size: +8 −3]
506
+ old-colors.ts [deleted, size: −64]
507
+ App.tsx [modified, size: +2 −1]
508
+ tests/
509
+ theme.test.ts [added, size: +40]
510
+ .env [ignored]
511
+ CHANGELOG.md [modified, highlight]
512
+ }
513
+ `},{name:`Product overview`,source:`title: Checkout v2
514
+ subtitle: architecture, plan, branches and numbers in one file
515
+ panels: grid
516
+
517
+ .svc [blue]
518
+ web "Web" .svc -> api "API" .svc -> db "Orders" [cylinder, amber]
519
+ api -> queue "Events" [pill, teal]: publish
520
+ style: dashed
521
+
522
+ timeline plan "Roadmap" {
523
+ Jan: Design
524
+ Feb [blue]: Build
525
+ Mar [green]: **Launch**
526
+ }
527
+
528
+ git branches "Branches" {
529
+ commit "v1" [tag: v1.0]
530
+ branch checkout-v2
531
+ commit "new cart"
532
+ commit "payments"
533
+ checkout main
534
+ merge checkout-v2 [tag: v2.0]
535
+ }
536
+
537
+ chart conv "Conversion" [type: line, unit: %] {
538
+ Jan: 2.1
539
+ Feb: 2.4
540
+ Mar: 3.2
541
+ }
542
+ `}],yd=[{label:`Sequence diagram`,group:`Panels`,id:`seq`,text:`sequence {id} "Checkout" [numbered] {
543
+ actor user "Customer" [purple]
544
+ participant web, api, db
545
+ user -> web: add to cart
546
+ web -> api: POST /orders
547
+ api -> db: insert order
548
+ db --> api: id
549
+ note api: idempotency key
550
+ api --> web: 201 Created
551
+ }`},{label:`Timeline`,group:`Panels`,id:`plan`,text:`timeline {id} "Roadmap" {
552
+ 2026 Q1: Private beta
553
+ - 40 design partners
554
+ 2026 Q2 [green]: **Launch**
555
+ 2026 Q4 [amber]: EU region
556
+ }`},{label:`Bar chart`,group:`Panels`,id:`chart`,text:`chart {id} "Requests by service" [type: bar] {
557
+ api: 420
558
+ web: 310
559
+ worker [amber]: 95
560
+ }`},{label:`Donut chart`,group:`Panels`,id:`share`,text:`chart {id} "Traffic by region" [type: donut, unit: %] {
561
+ EU: 46
562
+ US: 31
563
+ APAC: 23
564
+ }`},{label:`Line chart`,group:`Panels`,id:`latency`,text:`chart {id} "p95 latency" [type: line, unit: ms] {
565
+ Mon: 120
566
+ Tue: 96
567
+ Wed: 140
568
+ Thu: 88
569
+ Fri: 72
570
+ }`},{label:`Git branches`,group:`Panels`,id:`git`,text:`git {id} "Release flow" {
571
+ commit "init" [tag: v1.0]
572
+ checkout -b feature/login
573
+ commit "login form"
574
+ commit "oauth"
575
+ checkout main
576
+ commit "hotfix" [id: fix, type: highlight, tag: v1.0.1]
577
+ merge feature/login [tag: v1.1]
578
+ branch release/1.0 from v1.0 [label: "1.0.x"]
579
+ cherry-pick fix
580
+ }`},{label:`Mind map`,group:`Panels`,id:`ideas`,text:`mindmap {id} "Launch plan" {
581
+ **Launch**
582
+ Marketing [pink]
583
+ Blog posts
584
+ Newsletter
585
+ Product
586
+ Beta [green]
587
+ Sales
588
+ }`},{label:`File tree`,group:`Panels`,id:`files`,text:`treeview {id} "my-app" [sort: folders, chevrons, compact] {
589
+ match *.test.ts [dim]
590
+ src/
591
+ index.ts: entry point
592
+ components/
593
+ Button.tsx [added]
594
+ Button.test.ts
595
+ util.ts [modified, size: 2 KB]
596
+ docs/ [collapsed]
597
+ intro.md
598
+ package.json
599
+ README.md [highlight]
600
+ }`},{label:`Gantt chart`,group:`Panels`,id:`plan`,text:`gantt {id} "Q1 plan" {
601
+ --- Design ---
602
+ research "User research": 2026-01-05, 5d
603
+ wireframes [blue]: after research, 4d
604
+ --- Build ---
605
+ api "Build API" [green, active]: after wireframes, 2w
606
+ launch [milestone]: after api
607
+ }`},{label:`Quadrant`,group:`Panels`,id:`prio`,text:`quadrant {id} "Priorities" {
608
+ x-axis Low effort -> High effort
609
+ y-axis Low value -> High value
610
+ q1: Quick wins
611
+ q2: Big bets
612
+ q3: Fill-ins
613
+ q4: Money pit
614
+ Search [teal]: 0.25, 0.8
615
+ Billing: 0.7, 0.65
616
+ }`},{label:`Kanban board`,group:`Panels`,id:`board`,text:`kanban {id} "Sprint" {
617
+ Todo [gray]
618
+ - Write docs [owner: ana]
619
+ Doing [blue, limit: 2]
620
+ - API v2 [ticket: MER-12]
621
+ Done [green]
622
+ - Ship 1.0
623
+ }`},{label:`Node`,group:`Graph`,id:`node`,text:`{id} "New node" [blue]`},{label:`Group`,group:`Graph`,id:`group`,text:`group {id} "New group" {
624
+ {id}_a "First"
625
+ {id}_b "Second"
626
+ }
627
+ {id}_a -> {id}_b`},{label:`Class (shared style)`,group:`Graph`,id:`style`,text:`.{id} [color: teal, shape: pill]`},{label:`Variable`,group:`Graph`,id:`color`,text:"${id}: teal"},{label:`Component (reusable nodes)`,group:`Graph`,id:`service`,text:`def {id}(id, label, lang = Go) {
628
+ $id "$label" [color: blue, sub: $lang]
629
+ $id-db [shape: cylinder, color: amber]
630
+ $id -> $id-db
631
+ }
632
+ {id}(first, "First")
633
+ {id}(second, "Second", Rust)`},{label:`Card with rows`,group:`Graph`,id:`card`,text:`{id} "orders" [meta: 12k/day, color: amber] {
634
+ | field | type |
635
+ |--------|-------|
636
+ | id | uuid |
637
+ | total | money |
638
+ ---
639
+ spark: 3 5 4 8 7 9
640
+ }`}],bd=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()}},xd=e=>`file:///`+e.split(`/`).map(encodeURIComponent).join(`/`),Sd=e=>decodeURIComponent(new URL(e).pathname).slice(1);function Cd(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 wd(e,t){let n=e.slice(0,t);return{line:n.split(`
642
+ `).length-1,character:t-(n.lastIndexOf(`
643
+ `)+1)}}function Td(e,t){let n=t.map(t=>({from:Cd(e,t.range.start),to:Cd(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 Ed(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 Dd=e=>e.replace(/[&<>]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`})[e]),Od=e=>Dd(e).replace(/\*\*([^*]+)\*\*/g,`<b>$1</b>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\n\n/g,`<br>`),kd={3:`ƒ`,6:`n`,7:`c`,9:`p`,10:`k`,12:`v`,14:`⌘`,17:`f`};function Ad(e){let{ta:t}=e,n=new bd(new Worker(new URL(new URL(`lsp.worker-N6A9m364.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=Sd(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(xd(i),a),r||=i===e.current());for(let e of o.keys())e in t||(o.delete(e),s.delete(e),n.close(xd(e)));return r}function l(){(c()||ne!==e.current())&&(te=new Map,ie(),oe())}async function u(i,a={},o=t.selectionStart){await r,c();let s=xd(e.current());return n.request(i,{textDocument:{uri:s},position:wd(t.value,o),...a})}function d(e){let n=Cd(t.value,e.start);t.focus(),t.setSelectionRange(n,Cd(t.value,e.end));let r=Ed(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=Td(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(Cd(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=kd[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=Ed(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?Cd(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=Od(r);let i=Ed(t,n.range?Cd(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[xd(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=Sd(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 A=document.createElement(`div`);A.className=`lsp-wrap`,t.replaceWith(A),A.append(k,t);let ee=new Map,te=new Map,ne=``,re=null,j=0,M=0;function ie(){k.style.width=t.clientWidth+`px`,k.style.height=t.clientHeight+`px`;let e=``;for(let[n,r]of t.value.split(`
644
+ `).entries()){n&&(e+=`
645
+ `);let t=re&&n>=re[0]&&n<=re[1];t&&(e+=`<span class="src-mark">`);let i=[...ee.get(n)??[],...te.get(n)??[]];if(!i.length)e+=Dd(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=Dd(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 ae(e){let t=new Map;for(let n of e)t.set(n.line,[...t.get(n.line)??[],n]);return t}function oe(){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:xd(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})}ee=ae(l),ne=i,ie()},30)}function se(){clearTimeout(M),M=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=ae((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||te.size)&&(te=i,ie())},120)}t.addEventListener(`input`,()=>{te=new Map,ie(),oe(),se()}),t.addEventListener(`scroll`,()=>k.scrollTop=t.scrollTop),t.addEventListener(`keyup`,e=>{(e.key.startsWith(`Arrow`)||e.key===`Home`||e.key===`End`||e.key===`PageUp`||e.key===`PageDown`)&&se()}),new ResizeObserver(()=>ie()).observe(t),ie(),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),t.addEventListener(`blur`,()=>{x(),E()}),t.addEventListener(`scroll`,()=>{x(),E()}),t.addEventListener(`click`,e=>{if(x(),E(),se(),e.metaKey||e.ctrlKey)return void O();w=window.setTimeout(()=>void T(),350)});function ce(e,n=!1){if(re=e,ie(),!e||!n)return;let r=Cd(t.value,{line:e[0],character:0}),i=Cd(t.value,{line:e[1]+1,character:0}),a=Ed(t,r).top,o=Ed(t,i).top,s=t.getBoundingClientRect();(a<s.top||o>s.bottom)&&(t.scrollTop+=a-s.top-t.clientHeight/3)}return{sync:l,mark:ce,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?.[xd(e.current())];return n?(f(n),!0):!1}}}var jd=` `;function Md(e,t){let n=e.slice(e.lastIndexOf(`
646
+ `,t-1)+1,t),r=n.match(/^[ \t]*/)[0],i=0;for(let e of er($n(n).tokens))i=Math.max(0,i+(e===`{`?1:-1));return i?r+jd:r}function Nd(e,t){let n=1;for(let r=e.lastIndexOf(`
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 er($n(i).tokens).reverse())if(n+=e===`}`?1:-1,!n)return i.match(/^[ \t]*/)[0];r=t-1}return``}function Pd(e,t){let n=Md(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 Fd(e,t,n){let r=e.lastIndexOf(`
650
+ `,t-1)+1,i=e.slice(r,t),a=i.match(/^[ \t]*/)[0],o=e.indexOf(`
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
+ `+Pd(e,t);return Md(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 Id(e,t,n,r=!1){let i=e.lastIndexOf(`
654
+ `,t-1)+1,a=n>t&&e[n-1]===`
655
+ `?n-1:n,o=e.indexOf(`
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?jd+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 Ld=class{diagram;L;snap;constructor(e,t,n){this.diagram=e,this.L=t,this.snap=n}pinAll(){for(let e of this.L.nodes.values()){let t=this.diagram.layout.nodes[e.id]??={};(t.x===void 0||t.y===void 0)&&(t.x=Math.round(e.x),t.y=Math.round(e.y))}}edgeOverride(e){return this.diagram.layout.edges[e]??={}}nearestSide(e,t){let n=this.L.nodes.get(e),r=(t.x-(n.x+n.w/2))/(n.w/2),i=(t.y-(n.y+n.h/2))/(n.h/2);return Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`bottom`:`top`}pinned(e,t){t&&this.pinAll();let n=t?this.L.nodes.get(e):this.L.panels.find(t=>t.decl.id===e).box,r=t?this.diagram.layout.nodes[e]??={}:((this.diagram.layout.panels??={})[e]??={}).at??={x:n.x,y:n.y};return r.x??=n.x,r.y??=n.y,{o:r,w:n.w,h:n.h}}centre(e,t){let{o:n,w:r,h:i}=this.pinned(e,t),a=n.x+r/2,o=n.y+i/2;return(e,t,s)=>{n.x=Math.round(this.snap(a+t.x,s)-r/2),n.y=Math.round(this.snap(o+t.y,s)-i/2)}}part(e,t){let n=((this.diagram.layout.panels??={})[e]??={}).parts??={},r=n[t.part]??{x:0,y:0},i=(e,t,n)=>Math.round(this.snap(e+t,n)-e);return(e,a,o)=>{let s=t.axis??`xy`;n[t.part]=s===`xy`?{x:r.x+i(t.x,a.x,o),y:r.y+i(t.y,a.y,o)}:{x:r.x+i(t[s],a[s],o),y:0}}}resize(e){let t=this.L.nodes.get(e),n=t.w,r=t.h;return this.pinAll(),(t,i,a)=>{let o=this.diagram.layout.nodes[e];o.w=Math.max(24,this.snap(n+i.x,a)),o.h=Math.max(16,this.snap(r+i.y,a))}}via(e,t,n){let r=this.L.edges.find(t=>t.key===e);this.pinAll();let i=this.edgeOverride(e);n&&Rd(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),Rd(r,n),r.via=n.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)})),i=Ud(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=>nc(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 Rd(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 zd(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 Bd(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 Vd(e){let t=[0];for(let n of e.via)t.push(zd(e.samples,n,t[t.length-1]));return t.push(zd(e.samples,e.end,t[t.length-1])),t}function Hd(e){let t=Vd(e);return t.slice(1).map((n,r)=>Bd(e.samples,(t[r]+n)/2))}function Ud(e,t){let n=Vd(e),r=zd(e.samples,t),i=0;for(;i<n.length-2&&r>n[i+1];)i++;return i}var Wd=[`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`],Gd,Kd=new Map;globalThis.document?.fonts?.addEventListener(`loadingdone`,()=>Kd.clear());function qd(e){if(se(e)||(Gd??=document.createElement(`canvas`).getContext(`2d`),!Gd))return!0;let t=Kd.get(e);if(t!==void 0)return t;let n=Gd,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 Kd.set(e,a),a}function Jd(e,t=qd){let n=ce(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:se(e)?t:e,missing:r}}r.push(e)}return{shown:`the browser default`,missing:r}}var W=e=>document.querySelector(e),G=W(`#source`),K=W(`#stage`),Yd=W(`#diagnostics`),Xd=W(`#inspector`),Zd=W(`#status`),Qd=W(`#theme`),$d=W(`#direction`),ef=W(`#curve`),tf=W(`#template`),nf=W(`#save`),rf=W(`#summary`),af=W(`#zoom-fit`),of=W(`#tabs`),sf=W(`#insert`),cf=`title: Hello yuhwa
659
+ direction: right
660
+
661
+ .svc [blue]
662
+
663
+ user "You" [shape: circle, purple]
664
+
665
+ group app "Your app" {
666
+ web "Web app" .svc [sub: "Next.js"]
667
+ api "API" .svc
668
+ }
669
+ db "Database" [shape: cylinder, amber]
670
+
671
+ user -> web: visits
672
+ web -> api
673
+ api -> db: SQL
674
+
675
+ // Drag boxes, edges and labels in the preview.
676
+ // Positions are written to the layout block below.
677
+ `,q=``,J,lf,Y=null,uf=0,df=null,ff=[],pf=[],mf=`main.yu`,X={[mf]:``},Z=mf,hf=new Map,gf=new URLSearchParams(location.search).has(`server`),_f={},vf=(e,t)=>t?.altKey?Math.round(e):Math.round(e/12)*12,yf=e=>{Zd.textContent=e,e&&setTimeout(()=>Zd.textContent===e&&(Zd.textContent=``),2e3)};function bf(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 xf(e){let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))}function Sf(){return K.querySelector(`svg`)}function Cf(e){let t=Sf(),n=new DOMPoint(e.clientX,e.clientY).matrixTransform(t.getScreenCTM().inverse());return{x:n.x,y:n.y}}function Q(e=!0){e&&(J=Sr(q,{file:Z,resolve:e=>e===Z?q:X[e]})),lf=sc(J,{measureFor:e=>Xr(e.font)});let t=Lc(J,lf,{interactive:!0,idPrefix:`ed`,snapGrid:12});K.innerHTML=t;let n=!J.nodes.size&&!J.panels.length&&!J.settings.title;if(K.classList.toggle(`is-empty`,n),n){let e=document.createElement(`p`);e.className=`empty-hint`,e.textContent=Object.keys(J.classes).length?`Nothing to draw yet: this file only defines classes. Import it from another file, or add a node.`:`Nothing to draw yet. Type a line like a -> b or pick something from Insert.`,K.append(e)}let r=Sf();Bf(r),Y&&!Hf(Y)&&(Y=null),Kf(r),e&&(pd(t),nm.sync(),qf(),Jf());let i=Df(Y);if(e||i!==wf){let e=Nf(Y);nm.mark(e,i!==wf);let t=Ef(e);i===wf&&t&&t===Tf||Cp(),wf=i,Tf=t}}var wf=``,Tf=``;function Ef(e){return!Y||!e?``:[q.split(`
678
+ `).slice(e[0],e[1]+1).join(`
679
+ `),JSON.stringify(J.layout),Object.keys(J.classes).join()].join(`
680
+ \0`)}var Df=e=>e?`${e.kind}:${e.id}${e.k?`#${e.k}`:``}`:``,Of=(e,t,n)=>{let r=n.k??0;for(let i of e)if(t(i)===n.id&&!r--)return i},kf=e=>Of(J.panels,e=>e.id,e),Af=e=>Of(lf.panels,e=>e.decl.id,e);function jf(e,t){return[...Sf()?.querySelectorAll(`[data-panel="${CSS.escape(t)}"]`)??[]].indexOf(e)}function Mf(e){let t=q.split(`
681
+ `),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 Nf(e){if(!e)return null;if(e.kind===`node`){let t=J.nodes.get(e.id);if(!t)return null;if(!t.ref||t.implicit){let t=J.edges.find(t=>(t.from===e.id||t.to===e.id)&&t.ref)?.ref.line;return t===void 0?null:[t,t]}let n=Math.max(t.ref.line,t.bodyLines?.[1]??0,...Object.values(t.ref.propLines??{}));return[t.ref.line,n]}if(e.kind===`edge`){let t=J.edges.find(t=>t.key===e.id)?.ref?.line;return t===void 0?null:[t,t]}if(e.kind===`group`){let t=J.groups.get(e.id)?.ref?.line;return t===void 0?null:[t,Mf(t)]}return kf(e)?.lines??null}function Pf(e){let t=null,n=1/0,r=r=>{let i=Nf(r);i&&e>=i[0]&&e<=i[1]&&i[1]-i[0]<n&&(t=r,n=i[1]-i[0])};for(let e of J.nodes.values())e.implicit||r({kind:`node`,id:e.id});for(let e of J.edges)r({kind:`edge`,id:e.key});for(let e of J.groups.keys())r({kind:`group`,id:e});let i=new Map;for(let e of J.panels){let t=i.get(e.id)??0;i.set(e.id,t+1),r({kind:`panel`,id:e.id,k:t})}return t&&Hf(t)?t:null}function Ff(e){let t={node:`data-node`,edge:`data-edge`,group:`data-group`,panel:`data-panel`}[e.kind],n=Sf()?.querySelectorAll(`[${t}="${CSS.escape(e.id)}"]`)[e.k??0];if(!n)return;let r=n.getBoundingClientRect(),i=K.getBoundingClientRect();r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom||K.scrollBy({left:r.left+r.width/2-(i.left+i.width/2),top:r.top+r.height/2-(i.top+i.height/2),behavior:`smooth`})}function If(){if(G.value!==q)return;let e=Pf(q.slice(0,G.selectionStart).split(`
682
+ `).length-1);Df(e)!==Df(Y)&&(Y=e,Q(!1),e&&Ff(e))}var Lf=.1,Rf=8,zf=()=>{let e=lf.bounds;return Math.min(1.5,Math.max(.2,Math.min((K.clientWidth-48)/e.w,(K.clientHeight-48)/e.h)))};function Bf(e){let t=lf.bounds,n=uf||zf();df?(e.setAttribute(`viewBox`,df.viewBox),e.setAttribute(`width`,String(df.w)),e.setAttribute(`height`,String(df.h))):(e.setAttribute(`width`,String(Math.round(t.w*n))),e.setAttribute(`height`,String(Math.round(t.h*n)))),af.textContent=`${Math.round((df?df.w/t.w:n)*100)}%`,af.title=uf?`Fit to view (⌘0)`:`Fitted to view`}function Vf(e,t){let n=Sf();if(!n||df)return;let r=e?Math.min(Rf,Math.max(Lf,e)):0;if(r===uf)return;let i=K.getBoundingClientRect(),a=t?.clientX??i.left+i.width/2,o=t?.clientY??i.top+i.height/2,s=n.getBoundingClientRect(),c=(a-s.left)/s.width,l=(o-s.top)/s.height;if(uf=r,Bf(n),n.querySelector(`:scope > .overlay`)?.remove(),Kf(n),!uf)return;let u=n.getBoundingClientRect();K.scrollLeft+=u.left+c*u.width-a,K.scrollTop+=u.top+l*u.height-o}function Hf(e){return e.kind===`node`?lf.nodes.has(e.id):e.kind===`group`?lf.groups.some(t=>t.id===e.id):e.kind===`panel`?!!Af(e):lf.edges.some(t=>t.key===e.id)}var Uf=`http://www.w3.org/2000/svg`;function Wf(e,t){let n=document.createElementNS(Uf,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,String(r));return n}var Gf=``;matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>Gf=``);function Kf(e){if(!Y)return;let t=Wf(`g`,{class:`overlay`}),n=lf.bounds.w/(e.width.baseVal.value||lf.bounds.w),r=Gf||=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||`#2563eb`,i=(e,i,a,o,s=`circle`)=>{let c={"data-handle":a,"data-i":o,stroke:r,"stroke-width":1.5*n,style:`cursor:move`};s===`square`?t.append(Wf(`rect`,{x:e-5*n,y:i-5*n,width:10*n,height:10*n,rx:2*n,fill:`#fff`,...c})):t.append(Wf(`circle`,{cx:e,cy:i,r:(s===`ring`?4:5.5)*n,fill:s===`ring`?`#fff`:r,...c}))};if(Y.kind===`node`){let e=lf.nodes.get(Y.id);t.append(Wf(`rect`,{x:e.x-4,y:e.y-4,width:e.w+8,height:e.h+8,rx:6,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),i(e.x+e.w+4,e.y+e.h+4,`resize`,0,`square`)}else if(Y.kind===`panel`){let e=Af(Y);t.append(Wf(`rect`,{x:e.box.x-3,y:e.box.y-3,width:e.box.w+6,height:e.box.h+6,rx:12,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),e.handles.forEach((n,r)=>{let a=!!J.layout.panels?.[e.decl.id]?.parts?.[n.part];i(n.x,n.y,`part`,r,a?`circle`:`ring`);let o=t.lastElementChild,s=Wf(`title`,{});s.textContent=`${n.title??n.part}${a?` · double-click to reset`:``}`,o.append(s),o.setAttribute(`style`,`cursor:${n.axis===`x`?`ew-resize`:n.axis===`y`?`ns-resize`:`move`}`)})}else if(Y.kind===`group`){let e=lf.groups.find(e=>e.id===Y.id);t.append(Wf(`rect`,{x:e.x-3,y:e.y-3,width:e.w+6,height:e.h+6,rx:14,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`}))}else{let e=lf.edges.find(e=>e.key===Y.id);t.append(Wf(`path`,{d:e.d,fill:`none`,stroke:r,"stroke-width":e.style.width+4,opacity:.25,"pointer-events":`none`}));let n=e=>{let n=Wf(`title`,{});n.textContent=e,t.lastElementChild.append(n)};Hd(e).forEach((e,t)=>{i(e.x,e.y,`mid`,t,`ring`),n(`drag to add a bend`)}),e.via.forEach((e,t)=>{i(e.x,e.y,`via`,t),n(`drag to move · right-click or double-click to remove`)}),i(e.start.x,e.start.y,`end`,0,`square`),n(`drag to pick a side · right-click to reset`),i(e.end.x,e.end.y,`end`,1,`square`),n(`drag to pick a side · right-click to reset`)}e.append(t)}function qf(){Yd.innerHTML=``;let e=nm.diagnostics(Z),t=e.filter(e=>e.severity===1).length,n=e.length-t,r=(e,t)=>`${e} ${t}${e===1?``:`s`}`;if(rf.textContent=`${r(J.nodes.size,`node`)} · ${r(J.edges.length,`edge`)}`,t||n){let e=document.createElement(`span`);e.className=`bad`,e.textContent=` · ${t?r(t,`error`):r(n,`warning`)}`,rf.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=()=>nm.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(),nm.fix(t)},e.append(n)}Yd.append(e)}}function Jf(){let e=pe(J.themes);if([...Qd.options].map(e=>e.value).join()!==e.join()){Qd.replaceChildren();for(let t of e)Qd.append(new Option(t,t))}Qd.value=e.includes(J.settings.theme)?J.settings.theme:`paper`,$d.value=J.settings.direction||`right`,ef.value=J.settings.curve||`smooth`}function Yf(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 Xf(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),Yf(e,i,!n)}var Zf=e=>e.replace(/\n/g,`\\n`),Qf=e=>e.replace(/\\n/g,`
683
+ `);function $f(e,t,n=`text`,r=``){let i=document.createElement(`input`);return i.type=n,i.value=n===`text`?Zf(e):e,i.placeholder=r,i.spellcheck=!1,n===`number`&&(i.step=`any`),i.onchange=()=>t(n===`text`?Qf(i.value.trim()):i.value),i.onkeydown=t=>{t.stopPropagation(),t.key===`Enter`?i.blur():t.key===`Escape`&&(i.value=n===`text`?Zf(e):e,i.blur())},i}function ep(e,t,n,r=``){return Yf(e,$f(t,n,`text`,r),!t,`text`)}function tp(e,t){let n=ep(`font`,e,t,`theme font`),r=document.getElementById(`font-list`);r||(r=document.createElement(`datalist`),r.id=`font-list`,document.body.append(r));let i=[...document.fonts].flatMap(e=>ce(e.family)),a=new Set([...Wd.filter((e,t)=>t<3||qd(e)),...i]);r.replaceChildren(...[...a].map(e=>Object.assign(document.createElement(`option`),{value:e}))),n.querySelector(`input`).setAttribute(`list`,`font-list`);let{shown:o,missing:s}=Jd(e?le(e).font:me(J.settings.theme,J.themes).font),c=document.createElement(`p`);return c.className=`hint`,c.textContent=e&&s.length?`${s.join(`, `)} ${s.length>1?`are`:`is`} not on this computer, so the editor shows ${o}. A viewer without the font sees the next one in the list.`:`Shown as ${o}.`,[n,c]}function $(e,t,n,r=``){return Yf(e,$f(t,n,`number`,r),!t,`text`)}function np(e,t,n){let r=document.createElement(`input`);return r.type=`checkbox`,r.checked=t,r.onchange=()=>n(r.checked),Yf(e,r,!t,`toggle`)}var rp=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function ip(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 ap=e=>!e||!rp.test(e)?`#888888`:e.length===4?`#${e.slice(1).split(``).map(e=>e+e).join(``)}`:e.toLowerCase();function op(e){let t=document.createElement(`i`);return t.className=e?`swatch`:`swatch none`,e&&t.style.setProperty(`--sw`,ip(e)??`transparent`),t}function sp(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`,ip(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`,ip(e)??`transparent`);let o=document.createElement(`input`);return o.type=`color`,o.value=ap(ip(e,500)),o.onchange=()=>t(o.value),i.append(o),n.append(i),n}function cp(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=$f(t,n,`text`,r||`#hex, rgb(), hsl(), tomato`);return c.classList.add(`color-text`),i.append(a,sp(t,e=>n(e)),c),i}function lp(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`,ip(t,500)??`transparent`),o.title=`pick a colour`;let s=document.createElement(`input`);s.type=`color`,s.value=ap(ip(t,500)),s.onchange=()=>n(s.value),o.append(s);let c=$f(t,n,`text`,r||`none`);return i.append(a,o,c),t&&i.append(pp(`×`,()=>n(``),`clear`)),i}function up(e){let t=e.kind===`node`?J.nodes.get(e.id):e.kind===`group`?J.groups.get(e.id):e.kind===`panel`?kf(e):J.edges.find(t=>t.key===e.id);return t&&(t.labelRef?!t.labelRef.generated:e.kind===`node`&&!t.ref)?t.label??``:null}function dp(e,t){t!==up(e)&&Ep(Pu(q,e,t,J))}function fp(e,t){let n=up(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=Zf(n),o.spellcheck=!1;let s=r||e.kind!==`group`&&e.kind!==`panel`?i.top+i.height/2-15:i.top+6,c=r||e.kind!==`group`&&e.kind!==`panel`?i.left+i.width/2-a/2:i.left+6;Object.assign(o.style,{top:`${s}px`,left:`${Math.max(4,c)}px`,width:`${a}px`}),document.body.append(o),o.focus(),o.select();let l=!1,u=t=>{l||(l=!0,o.remove(),t&&dp(e,Qf(o.value)))};o.onkeydown=e=>{e.stopPropagation(),e.key===`Enter`?u(!0):e.key===`Escape`&&u(!1)},o.onblur=()=>u(!0)}function pp(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,n&&(r.className=n),r.onclick=t,r}function mp(e,t,n){return t?pp(e,()=>{n(),Dp()}):null}function hp(e,...t){let n=t.filter(e=>!!e);if(!n.length)return;let r=document.createElement(`section`),i=document.createElement(`h3`);i.textContent=e;let a=document.createElement(`div`);a.className=`rows`,a.append(...n),r.append(i,a),Xd.append(r)}function gp(e){let t=document.createElement(`p`);return t.className=`hint`,t.innerHTML=e,t}var _p=null,vp={up:`↑`,down:`↓`,remove:`✕`};function yp(e,t){let n=n=>r=>t({op:`set`,id:e.id,key:n,value:r||null}),r=[sp(e.tone??``,n(`color`))],i=e.values??{},a=Object.entries(e.fields??{}).map(([e,t])=>t.length?Xf(e,t,i[e]??``,n(e)):ep(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`}`:vp[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 bp(e,t,n){let r=document.createElement(`div`);r.className=`parts`;let i=(t,n=!0)=>{let r=zu(q,e,t,J);if(r.source===q)return yf(`this part cannot be changed here`);_p=n&&r.id?`${e}:${r.id}`:null,Ep(r.source)},a=``;for(let n of t){if(n.kind!==a){a=n.kind;let e=document.createElement(`div`);e.className=`parts-kind`,e.textContent=a,r.append(e)}let t=`${e}:${n.id}`,o=document.createElement(`div`);o.className=`part`;let s=document.createElement(`button`);s.type=`button`,s.title=`edit ${n.id}`;let c=document.createElement(`span`);c.textContent=n.label;let l=document.createElement(`code`);l.textContent=n.tone??``,s.append(op(n.tone??``),c,l);let u=e=>{o.classList.toggle(`open`,e),o.replaceChildren(s,...e?yp(n,i):[])};s.onclick=()=>{let e=_p!==t;r.querySelector(`.part.open`)?.dispatchEvent(new Event(`close`)),_p=e?t:null,u(e)},o.addEventListener(`close`,()=>u(!1)),u(_p===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 xp=`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 Sp(){let e=J.settings,t=e=>t=>Ep(Ru(q,e,t||null)),n=document.createElement(`div`);n.className=`title`,n.innerHTML=`<small>diagram</small>settings`,Xd.append(n),hp(`Text`,ep(`title`,e.title??``,t(`title`)),ep(`subtitle`,e.subtitle??``,t(`subtitle`)),...tp(e.font??``,t(`font`)),$(`font size`,e[`font-size`]??``,t(`font-size`),`14`)),hp(`Style`,Xf(`theme`,[``,...pe(J.themes)],e.theme??``,t(`theme`)),lp(`accent`,e.accent??``,t(`accent`),`theme`),lp(`background`,e.background??``,t(`background`),`theme`),$(`radius`,e.radius??``,t(`radius`),`theme`),$(`stroke`,e[`stroke-width`]??``,t(`stroke-width`),`theme`),lp(`edge color`,e[`edge-color`]??``,t(`edge-color`),`theme`),$(`edge width`,e[`edge-width`]??``,t(`edge-width`),`theme`),np(`shadow`,!!e.shadow&&e.shadow!==`false`,e=>t(`shadow`)(e?`true`:``)),Xf(`shape`,[``,...Xt],e.shape??``,t(`shape`))),hp(`Layout`,Xf(`direction`,[``,`right`,`down`,`left`,`up`],e.direction??``,t(`direction`)),Xf(`curve`,[``,`smooth`,`orthogonal`,`straight`],e.curve??``,t(`curve`)),$(`gap`,e.gap??``,t(`gap`),`36`),$(`rank gap`,e[`rank-gap`]??``,t(`rank-gap`),`auto`),$(`padding`,e.padding??``,t(`padding`),`24`),$(`wrap`,e.wrap??``,t(`wrap`),`off`),Xf(`panels`,[``,`row`,`column`,`grid`,`wrap`],e.panels??``,t(`panels`)),$(`panel gap`,e[`panel-gap`]??``,t(`panel-gap`),`48`),np(`grid`,!!e.grid&&e.grid!==`false`,e=>t(`grid`)(e?`true`:``))),Xd.append(gp(xp))}function Cp(){if(Xd.innerHTML=``,!Y)return Sp();let e=Y,t=document.createElement(`div`);t.className=`title`;let n=document.createElement(`small`);n.textContent=e.kind;let r=document.createElement(`span`);r.textContent=e.id,t.append(n,r,pp(`×`,()=>{Y=null,Q(!1)},`clear`)),t.lastElementChild.setAttribute(`title`,`deselect (Esc)`),Xd.append(t);let i={kind:e.kind,id:e.id},a=e=>t=>Ep(Iu(q,i,e,t||null)),o=(e,t)=>np(e,!!t[e]&&t[e]!==`false`,t=>a(e)(t?`true`:``)),s=(e,t=`auto`,n={})=>[lp(`text`,e.text??e[`label-color`]??``,a(`text`),n.text),$(`font size`,e[`font-size`]??``,a(`font-size`),n[`font-size`]??t),$(`font weight`,e[`font-weight`]??``,a(`font-weight`),n[`font-weight`]??`auto`),o(`italic`,e)],c=up(i),l=c!==null&&ep(e.kind===`panel`?`title`:`label`,c,e=>dp(i,e));if(e.kind===`panel`){let t=kf(e),r=Mr.panels.get(t.kind);n.textContent=t.kind;let i=r?.options??{},c=!!t.ref&&!t.ref.generated;hp(`Text`,l,...c?s(t.props,`theme`):[]),c&&(hp(`Options`,...Object.entries(i).map(([e,n])=>{let r=kr(n),i=t.props[e]??``;switch(r.kind){case`select`:return Xf(e,[``,...r.values],i,a(e));case`flag`:return o(e,t.props);case`color`:return lp(e,i,a(e),`default`);case`number`:return $(e,i,a(e));case`text`:return ep(e,i,a(e));default:return r}})),hp(`Style`,cp(`color`,t.props.color??``,a(`color`)),Xf(`theme`,[``,...pe(J.themes)],t.props.theme??``,a(`theme`)),lp(`background`,t.props.background??t.props.fill??``,a(`background`),`theme`),lp(`border`,t.props.border??t.props.stroke??``,a(`border`),`theme`),Xf(`border style`,[``,`solid`,`dashed`,`dotted`],Je(t.props)??``,a(`border-style`)),$(`border width`,t.props[`border-width`]??``,a(`border-width`),`1`),lp(`edge color`,t.props[`edge-color`]??``,a(`edge-color`),`theme`),$(`edge width`,t.props[`edge-width`]??``,a(`edge-width`),`theme`),$(`radius`,t.props.radius??``,a(`radius`),`10`),o(`shadow`,t.props),np(`frame`,t.props.frame!==`false`,e=>a(`frame`)(e?``:`false`))));let u=!t.failed&&r?.parts?.(t.data)||[],d=c&&!!r?.editPart&&!!t.lines&&t.lines[1]-t.lines[0]-1===t.body.length;u.length&&hp(`Parts`,d?bp(e.id,u,r?.adds):gp(`Write the panel body on its own lines to colour its parts here.`));let f=J.layout.panels?.[e.id];hp(`Layout`,mp(`Unpin`,f?.at,()=>delete f.at),mp(`Reset layout`,f?.parts,()=>delete f.parts))}else if(e.kind===`node`){let n=J.nodes.get(e.id),r=Object.assign({},...n.classes.map(e=>J.classes[e]??{})),i=e=>n.props[e]??``;hp(`Text`,l,ep(`sub`,i(`sub`),a(`sub`),r.sub),...s(n.props,`auto`,r),o(`bold`,n.props),o(`mono`,n.props),$(`body size`,i(`body-size`),a(`body-size`),r[`body-size`]??`auto`),lp(`body colour`,i(`body-color`),a(`body-color`),r[`body-color`]??`from text`),ep(`icon`,i(`icon`),a(`icon`),r.icon),ep(`link`,i(`link`),a(`link`),r.link),ep(`tooltip`,i(`tooltip`),a(`tooltip`),r.tooltip)),hp(`Colour`,cp(`color`,i(`color`),a(`color`),r.color),lp(`fill`,i(`fill`),a(`fill`),r.fill??`from color`),lp(`stroke`,i(`stroke`),a(`stroke`),r.stroke??`from color`)),hp(`Shape`,Xf(`shape`,[``,...Xt],i(`shape`)||``,a(`shape`)),Xf(`border`,[``,`solid`,`dashed`,`dotted`],Je(n.props)??``,a(`border-style`)),$(`border width`,i(`stroke-width`),a(`stroke-width`),r[`stroke-width`]??`theme`),$(`radius`,i(`radius`),a(`radius`),r.radius??`theme`),$(`opacity`,i(`opacity`),a(`opacity`),`1`),o(`shadow`,n.props)),hp(`Size`,$(`width`,i(`width`),a(`width`),`auto`),$(`height`,i(`height`),a(`height`),`auto`),$(`max width`,i(`max-width`),a(`max-width`),`auto`),mp(`Unpin`,J.layout.nodes[e.id],()=>delete J.layout.nodes[e.id])),r.shape&&!n.props.shape&&(t.title=`shape ${r.shape} from class`)}else if(e.kind===`edge`){let t=J.edges.find(t=>t.key===e.id),n=e=>t.props[e]??``,r=[``,`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],i=[``,`top`,`right`,`bottom`,`left`,`auto`];hp(`Text`,l,...s(t.props),lp(`label bg`,n(`label-bg`),a(`label-bg`))),hp(`Line`,cp(`color`,n(`color`),a(`color`)),lp(`stroke`,n(`stroke`),a(`stroke`),`from color`),Xf(`style`,[``,`solid`,`dashed`,`dotted`],Je(t.props,`style`)??``,a(`style`)),$(`width`,n(`width`),a(`width`),`theme`),$(`opacity`,n(`opacity`),a(`opacity`),`1`),o(`flow`,t.props),o(`animate`,t.props)),hp(`Ends`,Xf(`head`,r,n(`head`),a(`head`)),Xf(`tail`,r,n(`tail`),a(`tail`)),Xf(`exit`,i,n(`exit`),a(`exit`)),Xf(`enter`,i,n(`enter`),a(`enter`))),hp(`Route`,Xf(`curve`,[``,`smooth`,`orthogonal`,`straight`],n(`curve`),a(`curve`)),o(`constraint`,t.props),mp(`Reset route`,J.layout.edges[e.id],()=>delete J.layout.edges[e.id])),t.ref&&J.edges.filter(e=>e.ref===t.ref).length>1&&Xd.append(gp(`Style applies to every edge on this line.`))}else{let t=J.groups.get(e.id),n=e=>t.props[e]??``;hp(`Text`,l,...s(t.props),o(`caps`,t.props)),hp(`Colour`,cp(`color`,n(`color`),a(`color`)),lp(`fill`,n(`fill`),a(`fill`),`from color`),lp(`stroke`,n(`stroke`),a(`stroke`),`from color`),Xf(`border`,[``,`solid`,`dashed`,`dotted`],Je(t.props)??``,a(`border-style`)))}}function wp(e){ff[ff.length-1]!==e&&ff.push(e),ff.length>200&&ff.shift(),pf.length=0}function Tp(e,t=!0){if(e===q)return;Xp.end(),t&&wp(q),q=e;let n=G.scrollTop;G.value=e,G.scrollTop=n,kp()}function Ep(e){Tp(e),Q(!0)}function Dp(){Ep(Du(q,J.layout,J))}var Op=0;function kp(){if(X[Z]=q,gf)Ap.changed(),clearTimeout(Op),Op=window.setTimeout(jp,500);else try{localStorage.setItem(`yuhwa-files`,JSON.stringify({files:X,current:Z}))}catch{}}var Ap=new _d(async()=>{let e=await fetch(`/api/source`,{method:`PUT`,body:JSON.stringify({files:X})});if(!e.ok)throw Error(`save failed`);let{written:t=[]}=await e.json();return t.length?`saved ${t.join(`, `)}`:`saved`},yf);function jp(){if(gf)return clearTimeout(Op),Ap.save()}var Mp=()=>new Ld(J,lf,vf),Np=null,Pp=null,Fp=!1,Ip=new Map,Lp=null;function Rp(e,t){Pp={x:e.clientX,y:e.clientY,left:K.scrollLeft,top:K.scrollTop,moved:!1,clear:t},K.setPointerCapture(e.pointerId),K.classList.add(`panning`),e.preventDefault()}var zp=()=>{let[e,t]=[...Ip.values()];return{x:(e.x+t.x)/2,y:(e.y+t.y)/2,d:Math.hypot(e.x-t.x,e.y-t.y)}};K.addEventListener(`wheel`,e=>{if(!(e.ctrlKey||e.metaKey)||Np||!Sf())return;e.preventDefault();let t=e.deltaMode===1?e.deltaY*16:e.deltaY;Vf(Yp()*Math.min(2,Math.max(.5,Math.exp(-t*.01))),e)},{passive:!1}),K.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||(Ip.set(e.pointerId,{x:e.clientX,y:e.clientY}),Ip.size!==2))return;if(Np){let{moved:e,finish:t}=Np;Np=null,df=null,K.classList.remove(`dragging`),e?t():Q()}Pp=null;let t=zp();Lp={d:t.d,z:Yp(),mid:t},e.stopImmediatePropagation()},{capture:!0}),K.addEventListener(`pointermove`,e=>{if(!Ip.has(e.pointerId)||(Ip.set(e.pointerId,{x:e.clientX,y:e.clientY}),!Lp||Ip.size!==2))return;let t=zp();Vf(Lp.z*t.d/Math.max(1,Lp.d),{clientX:t.x,clientY:t.y}),K.scrollLeft-=t.x-Lp.mid.x,K.scrollTop-=t.y-Lp.mid.y,Lp.mid=t,e.stopImmediatePropagation()},{capture:!0});var Bp=e=>{Ip.delete(e.pointerId),Ip.size<2&&(Lp=null)};K.addEventListener(`pointerup`,Bp,{capture:!0}),K.addEventListener(`pointercancel`,Bp,{capture:!0}),K.addEventListener(`pointerdown`,e=>{if(!Sf()||Lp)return;if(e.button===1||e.button===0&&Fp)return Rp(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 Rp(e,!0);let n=Cf(e),r=Sf();df={viewBox:r.getAttribute(`viewBox`),w:r.width.baseVal.value,h:r.height.baseVal.value};let i=Dp,a=()=>{},o=Mp();if(t.hasAttribute(`data-handle`)){let e=t.getAttribute(`data-handle`),r=Number(t.getAttribute(`data-i`));if(Y?.kind===`panel`&&e===`part`){let e=Y.id,t=Af(Y).handles[r];i=()=>Ep(Bu(q,J,e,t)),a=o.part(e,t)}else Y?.kind===`node`&&e===`resize`?a=o.resize(Y.id):Y?.kind===`edge`&&(e===`via`||e===`mid`?a=o.via(Y.id,r,e===`mid`?n:null):e===`end`&&(a=o.port(Y.id,r===0?0:1)))}else if(t.hasAttribute(`data-node`)){let e=t.getAttribute(`data-node`);Y={kind:`node`,id:e},a=o.centre(e,!0)}else if(t.hasAttribute(`data-edge-label`)){let e=t.getAttribute(`data-edge-label`);Y={kind:`edge`,id:e},a=o.label(e)}else if(t.hasAttribute(`data-edge`)){let e=t.getAttribute(`data-edge`);Y={kind:`edge`,id:e},a=o.bend(e,n)}else if(t.hasAttribute(`data-panel`)){let e=t.getAttribute(`data-panel`);Y={kind:`panel`,id:e,k:jf(t,e)},a=o.centre(e,!1)}else if(t.hasAttribute(`data-group`)){let e=t.getAttribute(`data-group`);Y={kind:`group`,id:e},a=o.group(e)}Np={move:a,finish:i,moved:!1,start:n},K.setPointerCapture(e.pointerId),Q(!1),e.preventDefault()}),K.addEventListener(`pointermove`,e=>{if(Pp){let t=e.clientX-Pp.x,n=e.clientY-Pp.y;if(!Pp.moved&&Math.hypot(t,n)<3)return;Pp.moved=!0,K.scrollLeft=Pp.left-t,K.scrollTop=Pp.top-n;return}if(!Np)return;let t=Cf(e),n={x:t.x-Np.start.x,y:t.y-Np.start.y};!Np.moved&&Math.hypot(n.x,n.y)<3||(Np.moved=!0,K.classList.add(`dragging`),Np.move(t,n,e),Vp||=requestAnimationFrame(()=>{Vp=0,Q(!1)}))});var Vp=0;function Hp(){if(Pp){let{moved:e,clear:t}=Pp;Pp=null,K.classList.remove(`panning`),!e&&t&&Y&&(Y=null,Q(!1));return}if(!Np)return;let{moved:e,finish:t}=Np;Np=null,df=null,K.classList.remove(`dragging`),e?t():Q()}K.addEventListener(`pointerup`,Hp),K.addEventListener(`pointercancel`,Hp);function Up(e,t){let n=J.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 Dp(),!0}K.addEventListener(`contextmenu`,e=>{let t=e.target,n=t.closest(`[data-handle]`);if(Y?.kind===`edge`&&n){Up(Y.id,n)&&e.preventDefault();return}let r=t.closest(`[data-edge]`)?.getAttribute(`data-edge`),i=r?J.layout.edges[r]:void 0;r&&i?.via&&(e.preventDefault(),delete i.via,Y={kind:`edge`,id:r},Dp())}),K.addEventListener(`dblclick`,e=>{let t=e.target,n=t.closest(`[data-handle]`),r=t.closest(`[data-edge-label]`);if(Y?.kind===`panel`&&n?.getAttribute(`data-handle`)===`part`){let e=Y.id,t=Af(Y)?.handles[Number(n.getAttribute(`data-i`))]?.part,r=J.layout.panels?.[e];if(!t||!r?.parts?.[t])return;delete r.parts[t],Object.keys(r.parts).length||delete r.parts,Dp()}else if(Y?.kind===`edge`&&n)Up(Y.id,n);else if(!n){let e=r??t.closest(`[data-node],[data-edge],[data-group],[data-panel]`);if(!e)return Vf(0);let[n,i]=r?[`edge`,r.getAttribute(`data-edge-label`)]:[`node`,`edge`,`group`,`panel`].map(t=>[t,e.getAttribute(`data-${t}`)]).find(([,e])=>e!==null),a=n===`edge`&&!r?K.querySelector(`[data-edge-label="${CSS.escape(i)}"]`)??e:e;fp({kind:n,id:i},a)}}),document.addEventListener(`keydown`,e=>{let t=e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLInputElement,n=e.metaKey||e.ctrlKey;if(n&&e.key.toLowerCase()===`s`){e.preventDefault(),jp();return}if(t)return;if(e.key===` `&&!e.repeat){Fp=!0,K.classList.add(`can-pan`),e.preventDefault();return}let r=n&&{"=":1.25,"+":1.25,"-":.8,_:.8,0:0,1:-1}[e.key];if(r!==void 0&&r!==!1){e.preventDefault(),Vf(r===-1?1:r&&Yp()*r);return}if(n&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?Gp():Wp();return}if(e.key===`Escape`){Y=null,Q(!1);return}let i={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};if(i[e.key]&&(Y?.kind===`node`||Y?.kind===`panel`)){e.preventDefault();let t=e.shiftKey?12:1,{o:n}=Mp().pinned(Y.id,Y.kind===`node`);n.x+=i[e.key].x*t,n.y+=i[e.key].y*t,Dp()}});function Wp(){let e=ff.pop();e!==void 0&&(pf.push(q),Tp(e,!1),Q(!0))}function Gp(){let e=pf.pop();e!==void 0&&(ff.push(q),Tp(e,!1),Q(!0))}for(let e of C)Qd.append(new Option(e,e));for(let e of vd)tf.append(new Option(e.name,e.name));tf.onchange=()=>{let e=vd.find(e=>e.name===tf.value);if(tf.value=``,e){if(e.files){if(gf)return yf(`multi-file templates need the browser editor`);if(X[Z]=q,Object.values(X).some(e=>e.trim()&&e!==cf)&&!confirm(`Replace all files with "${e.name}"?`))return;wm({files:{[mf]:e.source,...e.files},current:mf}),G.value=q,kp(),lm(),Q(!0)}else Ep(e.source)}},Qd.onchange=()=>Ep(Ru(q,`theme`,Qd.value===`paper`&&!/^\s*import\b/m.test(q)?null:Qd.value)),$d.onchange=()=>{J.layout.nodes={},J.layout.edges={};for(let e of Object.values(J.layout.panels??{}))delete e.at;Ep(Ru(Du(q,J.layout,J),`direction`,$d.value))},ef.onchange=()=>Ep(Ru(q,`curve`,ef.value===`smooth`?null:ef.value)),W(`#undo`).onclick=Wp,W(`#redo`).onclick=Gp,W(`#reset`).onclick=()=>{J.layout={nodes:{},edges:{}},Dp()};function Kp(){return Lc(J,sc(J,{measureFor:e=>Xr(e.font)}),{idPrefix:`yuhwa`})}async function qp(e,t){try{await navigator.clipboard.writeText(e),yf(`${t} copied`)}catch{yf(`clipboard blocked`)}}W(`#copy-svg`).onclick=()=>qp(Kp(),`SVG`),W(`#copy-md`).onclick=()=>qp("```yuhwa\n"+q.replace(/\s*$/,``)+"\n```\n",`Markdown`);function Jp(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=(J.settings.title||`diagram`).toLowerCase().replace(/[^\w]+/g,`-`)+t,n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}document.fonts?.addEventListener(`loadingdone`,()=>{Q(!1),Y||Cp()}),W(`#download`).onclick=()=>Jp(new Blob([Kp()],{type:`image/svg+xml`}),`.svg`),W(`#download-png`).onclick=async()=>{try{(await md(Kp(),{scale:2})).toBlob(e=>e?Jp(e,`.png`):yf(`PNG export failed`),`image/png`)}catch{yf(`PNG export failed`)}},W(`#share`).onclick=()=>{let e=Object.keys(X).length>1,t=`${location.origin}${location.pathname}#${e?`files=${bf(JSON.stringify({files:X,current:Z}))}`:`src=${bf(q)}`}`;history.replaceState(null,``,t),qp(t,`link`)},W(`#zoom-in`).onclick=()=>Vf(Yp()*1.25),W(`#zoom-out`).onclick=()=>Vf(Yp()/1.25),W(`#zoom-fit`).onclick=()=>Vf(+!uf);function Yp(){let e=Sf();return e?e.width.baseVal.value/lf.bounds.w:1}nf.hidden=!gf,nf.onclick=()=>void jp(),window.addEventListener(`beforeunload`,e=>{gf&&Ap.dirty&&e.preventDefault()}),window.addEventListener(`resize`,()=>uf||Q(!1)),document.addEventListener(`keyup`,e=>{e.key===` `&&(Fp=!1,K.classList.remove(`can-pan`))}),window.addEventListener(`blur`,()=>{Fp=!1,K.classList.remove(`can-pan`)});var Xp=new gd((e,t)=>{t&&wp(q),q=e,kp()},()=>Q(!0));G.addEventListener(`input`,()=>Xp.input(G.value)),G.addEventListener(`click`,If),G.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&If()}),G.addEventListener(`keydown`,e=>{if(e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let{value:t,selectionStart:n,selectionEnd:r}=G;if(e.key===`Tab`){e.preventDefault();let i=Id(t,n,r,e.shiftKey);if(i.text===t)return;let a=G.scrollTop;G.value=i.text,G.setSelectionRange(i.from,i.to),G.scrollTop=a,G.dispatchEvent(new Event(`input`));return}let i=t.lastIndexOf(`
684
+ `,n-1)+1,a;e.key===`Enter`&&!e.shiftKey?a=Fd(t,n,r):e.key===`}`&&n===r&&!t.slice(i,n).trim()&&(a={start:i,end:r,insert:Nd(t,n)+`}`}),a&&(e.preventDefault(),G.setRangeText(a.insert,a.start,a.end,`end`),a.caret!==void 0&&G.setSelectionRange(a.caret,a.caret),G.dispatchEvent(new Event(`input`)))});function Zp(e,t,n){let r=document.createElement(`div`);r.className=`split ${e}`,r.setAttribute(`role`,`separator`),t(r),r.addEventListener(`pointerdown`,e=>{e.preventDefault(),r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let t=e=>n(e),i=()=>{r.classList.remove(`dragging`),r.removeEventListener(`pointermove`,t),r.removeEventListener(`pointerup`,i);try{localStorage.setItem(`yuhwa-panes`,JSON.stringify(em))}catch{}uf||Q(!1)};r.addEventListener(`pointermove`,t),r.addEventListener(`pointerup`,i)})}var Qp=W(`main`),$p=W(`#left`),em={};try{em=JSON.parse(localStorage.getItem(`yuhwa-panes`)??`{}`)}catch{}var tm=()=>{em.left&&(Qp.style.gridTemplateColumns=`${em.left}px 1fr var(--side)`),em.diag&&Object.assign(Yd.style,{height:`${em.diag}px`,maxHeight:`none`})};Zp(`split-x`,e=>$p.append(e),e=>{em.left=Math.round(Math.min(Math.max(e.clientX-Qp.getBoundingClientRect().left,240),innerWidth-640)),tm()}),Zp(`split-y`,e=>Yd.before(e),e=>{let t=$p.getBoundingClientRect().bottom;em.diag=Math.round(Math.min(Math.max(t-e.clientY,40),$p.clientHeight-160)),tm()}),tm();var nm=Ad({ta:G,files:()=>({...X,[Z]:G.value}),current:()=>Z,commit:Ep,open:rm,status:yf,onDiagnostics:e=>{e===Z&&qf()}});function rm(e){if(e===Z||!(e in X))return;X[Z]=q,Xp.end(),hf.set(Z,{undo:ff,redo:pf}),Z=e,q=X[e];let t=hf.get(e);ff=t?.undo??[],pf=t?.redo??[],Y=null,G.value=q,G.scrollTop=0,kp(),lm(),Q(!0)}var im=e=>{let t=e.trim().replace(/^\.?\//,``).replace(/\s+/g,`-`);return t?/\.\w+$/.test(t)?t:`${t}.yu`:``};function am(e,t){let n=e;for(let t=2;n in X;t++)n=e.replace(/(\.\w+)?$/,`-${t}$1`);return X[n]=t,rm(n),n}function om(e){let t=Z.split(`/`).slice(0,-1),n=e.split(`/`),r=0;for(;r<t.length&&t[r]===n[r];)r++;let i=t.slice(r).map(()=>`..`);return(i.length?i.join(`/`)+`/`:`./`)+n.slice(r).join(`/`)}function sm(e){let t=im(prompt(`Rename file`,e)??``);if(!t||t===e)return;if(t in X)return yf(`${t} exists`);X[Z]=q,Xp.end();let n=X[e];delete X[e],X[t]=n;let r=e=>e.split(`/`).pop();for(let n of Object.keys(X))X[n]=X[n].replace(/^(\s*(?:\/\/\s*)?import\s+(?:\{[^}]*\}\s*from\s+)?")([^"]+)(")/gm,(n,i,a,o)=>r(a)===r(e)?i+a.slice(0,-r(e).length)+r(t)+o:n);Z===e&&(Z=t),q=X[Z],G.value=q,kp(),lm(),Q(!0)}function cm(e){Object.keys(X).length<2||(!X[e].trim()||confirm(`Delete ${e}?`))&&(e===Z&&rm(Object.keys(X).find(t=>t!==e)),delete X[e],hf.delete(e),kp(),lm(),Q(!0))}function lm(){of.innerHTML=``;for(let e of Object.keys(X)){let t=document.createElement(`button`);t.className=`tab`,t.setAttribute(`role`,`tab`),t.setAttribute(`aria-selected`,String(e===Z)),t.textContent=e,t.onclick=()=>rm(e),gf||(t.title=`${e}: double-click to rename`,t.ondblclick=()=>sm(e));let n=document.createElement(`span`);n.className=`x`,n.textContent=`×`,n.title=`Delete ${e}`,n.onclick=t=>{t.stopPropagation(),cm(e)},gf||t.append(n),of.append(t)}of.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`,inline:`nearest`}),um.hidden=gf,fm()}var um=W(`#add-file`);um.onclick=()=>{let e=im(prompt(`New file name`,`shared.yu`)??``);e&&yf(`${am(e,`// Shared classes and nodes. Use them from ${Z} with:\n// import "${om(e).replace(/^(\.\.\/)+/,`./`)}"\n\n.svc [blue]\n`)} added`)};function dm(e){let t=new Set([...J.nodes.keys(),...J.panels.map(e=>e.id),...J.groups.keys(),...Object.keys(J.classes),...Object.keys(J.vars??{}),...Object.keys(J.defs??{})]);for(let n=1;;n++){let r=n===1?e:`${e}${n}`;if(!t.has(r)&&!q.includes(`${r} `))return r}}function fm(){sf.replaceChildren(sf.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),sf.append(i)),i.append(new Option(n,r))};yd.forEach((e,n)=>t(e.group,e.label,`s${n}`));for(let e of Mr.panels.keys())yd.some(t=>t.text.startsWith(e+` `))||t(`Panels`,e,`k${e}`);for(let e of Object.keys(X))e!==Z&&t(`Import a file`,`import "${om(e)}"`,`f${e}`)}function pm(e,t=!1){let n=q.search(/^layout\s*\{/m),r=t?0:n>=0?n:q.length,i=q.slice(0,r).replace(/\s*$/,``),a=q.slice(r),o=i?t?``:`
685
+
686
+ `:``,s=t?`${e}\n${q}`:`${i}${o}${e}\n${a?`
687
+ `+a:``}`;Ep(s);let c=t?0:i.length+o.length;G.focus(),G.setSelectionRange(c,c+e.length);let l=s.slice(0,c).split(`
688
+ `).length;G.scrollTop=Math.max(0,(l-3)*parseFloat(getComputedStyle(G).lineHeight||`20`))}sf.onchange=()=>{let e=sf.value;if(sf.value=``,e.startsWith(`s`)){let t=yd[Number(e.slice(1))],n=dm(t.id);pm(t.text.replaceAll(`{id}`,n)),yf(`${t.label.toLowerCase()} added`)}else if(e.startsWith(`k`)){let t=Mr.panels.get(e.slice(1));pm(`${t.name} ${dm(t.name)} "${t.name}" {\n // ${t.syntax??``}\n}`)}else if(e.startsWith(`f`)){let t=`import "${om(e.slice(1))}"`;if(q.includes(t))return yf(`already imported`);pm(t,!0)}};var mm=W(`#import-dlg`),hm=W(`#import-text`),gm=W(`#import-msg`),_m=W(`#import-new`),vm=`imported.yu`;function ym(e=``,t=`imported.yu`){hm.value=e,vm=t,gm.textContent=``,gm.className=``,_m.checked=!gf,_m.disabled=gf,mm.showModal(),hm.focus()}W(`#import`).onclick=()=>ym();async function bm(e){ym(await e.text(),im(e.name.replace(/\.(mmd|mermaid|json|txt|md)$/,``)))}W(`#import-file`).onchange=async e=>{let t=e.target.files?.[0];t&&await bm(t),e.target.value=``};var xm=e=>e.match(/```(?:yuhwa|mermaid|json)[^\n]*\n([\s\S]*?)```/)?.[1]??e;W(`#import-go`).onclick=e=>{e.preventDefault();let t=xm(hm.value);if(!t.trim())return mm.close();let n=hd(t),r=n.diagnostics.filter(e=>e.severity===`error`);if(r.length||!n.source.trim()){gm.className=`error`,gm.textContent=r.map(e=>e.message).join(`
689
+ `)||`nothing to import`;return}let i=n.format===`yuhwa`?`yuhwa`:n.format===`json`?`JSON`:`Mermaid`;_m.checked?am(vm,n.source):Ep(n.source),mm.close();let a=n.diagnostics.length;yf(`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(),bm(t))});async function Sm(){if(gf){let e=await(await fetch(`/api/source`)).json();q=e.source,Z=String(e.name).split(`/`).pop()||mf,_f=e.files??{},document.title=`${e.name} — yuhwa`,yf(e.name)}else{if(!Cm()){let e=null;try{e=localStorage.getItem(`yuhwa-files`),wm(e?JSON.parse(e):{files:{[mf]:localStorage.getItem(`yuhwa-source`)??cf}})}catch{wm({files:{[mf]:cf}})}}X[Z]=q}gf&&(X={[Z]:q,..._f}),G.value=q,lm(),Q(!0)}function Cm(){let e=location.hash.match(/src=([\w-]+)/),t=location.hash.match(/files=([\w-]+)/);try{if(t)wm(JSON.parse(xf(t[1])));else if(e)wm({files:{[mf]:xf(e[1])}});else return!1}catch{return yf(`broken link`),!1}return!0}function wm(e){Xp.end(),X=Object.keys(e.files??{}).length?{...e.files}:{[mf]:cf},Z=e.current&&e.current in X?e.current:Object.keys(X)[0],q=X[Z],hf.clear(),ff=[],pf=[]}Sm(),addEventListener(`hashchange`,()=>{!gf&&Cm()&&(G.value=q,lm(),Q(!0))});