yuhwa 1.8.2 → 1.9.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.
- package/dist/{index-0qJC6glR.d.ts → api-DHkPcxuZ.d.ts} +18 -22
- package/dist/{src-BWFm7GlK.js → api-DZunc9Tf.js} +6142 -8752
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/browser.d.ts +26 -3
- package/dist/browser.js +103 -32
- package/dist/canvas.js +1 -1
- package/dist/cli.js +65 -39
- package/dist/editor/assets/index-DuDUY7_0.js +842 -0
- package/dist/editor/assets/lsp.worker-DrpLBfKZ.js +55 -0
- package/dist/editor/index.html +1 -1
- package/dist/{figure-Cn5Ls_0U.d.ts → figure-Dlri_efy.d.ts} +1 -1
- package/dist/grammar-BgXa5hBR.js +974 -0
- package/dist/index-Bab6qq3T.d.ts +2 -0
- package/dist/index-rUYmvQft.d.ts +20 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +7 -5
- package/dist/ironmark.d.ts +1 -1
- package/dist/ironmark.js +1 -1
- package/dist/{lex-DIq2EFvl.js → lex-BgngnZsA.js} +49 -17
- package/dist/llms.txt +23 -6
- package/dist/lsp-browser.js +1 -1
- package/dist/lsp-node.js +6 -4
- package/dist/lsp-server.js +1 -1
- package/dist/lsp.js +1 -1
- package/dist/markdown-it.d.ts +1 -1
- package/dist/markdown-it.js +2 -2
- package/dist/{node-GljwUyhc.js → node-DoenSsSL.js} +4 -3
- package/dist/plugin-CUnb4PAy.js +970 -0
- package/dist/plugin-DGmREJ8U.d.ts +9 -0
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.js +3 -3
- package/dist/plugins-CUSZZfpe.js +8675 -0
- package/dist/plugins.d.ts +12 -0
- package/dist/plugins.js +3 -0
- package/dist/{raster-Bqtxssxh.js → raster-CA2EZVsH.js} +8 -8
- package/dist/remark.d.ts +1 -1
- package/dist/remark.js +1 -1
- package/dist/satteri.d.ts +1 -1
- package/dist/satteri.js +1 -1
- package/dist/{server-8-F7RVrN.js → server-CMv83EL8.js} +2 -2
- package/dist/{service-S1OY7wrO.js → service-DUPpv6QR.js} +31 -8
- package/dist/{plugin-COlq-EO9.d.ts → shapes-dSoHjzhn.d.ts} +109 -13
- package/dist/{shared-Bhnvepka.js → shared-BNy-W1fR.js} +14227 -6170
- package/dist/slim.d.ts +12 -0
- package/dist/slim.js +5 -0
- package/dist/src-DegXsZtj.js +337 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +3 -2
- package/dist/vuepress.d.ts +1 -1
- package/dist/vuepress.js +1 -1
- package/dist/yuhwa.iife.js +79 -55
- package/package.json +11 -1
- package/dist/editor/assets/index-BzQE05yU.js +0 -689
- package/dist/editor/assets/lsp.worker-B8uA5kfW.js +0 -36
- package/dist/plugin-3vxnUvv9.js +0 -307
|
@@ -0,0 +1,842 @@
|
|
|
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`,code:`limit`})};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={auto:{light:`paper`,dark:`midnight`}},w=Object.keys(S),T=[...w,...Object.keys(C)],E=(e,t)=>e&&!t?.[e]&&Object.hasOwn(C,e)?C[e]:void 0;function D(e){let t=e;t.edge.ink??=t.edge.text,S[t.name]=t,T.includes(t.name)||(w.push(t.name),T.splice(w.length-1,0,t.name))}var O=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,k=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(` `))),A=e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`),ee=(e,t)=>e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e);function te(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=>A(ee(e,255))).join(``);let t=(parseFloat(e[0])%360+360)%360/360,n=Math.min(1,ee(e[1],1)/(e[1].endsWith(`%`)?1:100)),i=Math.min(1,ee(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=>A(s(e)*255)).join(``)}let i=k.get(t);return i?`#`+i:void 0}var j=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))},ne=(e,t,n)=>{let r=j(t);return`#`+j(e).map((e,t)=>Math.round(e*n+r[t]*(1-n))).map(e=>e.toString(16).padStart(2,`0`)).join(``)};function re(e,t,n){let r=te(e);return r?{fill:ne(r,O.test(t.background)?t.background:t.dark?`#000000`:`#ffffff`,t.dark?n?.14:.22:n?.07:.12),stroke:r,text:t.dark?ne(r,`#ffffff`,.45):ne(r,`#000000`,.55)}:void 0}var ie=new WeakMap,ae=new WeakMap,M=(e,t)=>e===void 0?t:![`false`,`no`,`off`,`0`,`none`].includes(e.toLowerCase()),oe=[`solid`,`dashed`,`dotted`],se=(e,t)=>e===`dashed`?`6 4`:e===`dotted`?`1.5 4`:e===`solid`?null:t,ce={sans:h,serif:_,mono:g},le=/^(serif|sans-serif|monospace|cursive|fantasy|math|emoji|system-ui|ui-(serif|sans-serif|monospace|rounded))$/i,ue=e=>le.test(e),de=e=>e.split(`,`).map(e=>e.trim().replace(/^(['"])(.*)\1$/,`$2`)).filter(Boolean);function fe(e){let t=e.split(`,`).map(e=>e.trim()).filter(Boolean),n=de(e)[0]??`sans`,r=n===`mono`||/mono|code|courier/i.test(n),i=t.map(e=>ce[e]??e),a=t.at(-1)??``;return!ce[a]&&!ue(a)&&i.push(r?`ui-monospace, monospace`:`ui-sans-serif, system-ui, sans-serif`),{font:i.join(`, `),mono:r}}function pe(e){if(!e||!/^[\w\s'",.-]+$/.test(e))return;let t=me.get(e);return t||me.set(e,t=fe(e)),t}var me=new Map,he=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:oe},"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 ge(e,t,n){let r=n??S[t.base]??S.paper,i=M(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=>!M(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?fe(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:se(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 _e(e,t,n=[]){let r=t[e],i=r.base??(S[e]?e:void 0);return ge(e,r,i&&t[i]&&i!==e&&!n.includes(i)?_e(i,t,[...n,e]):S[i??`paper`]??S[E(i)?.light??`paper`]??S.paper)}var ve=e=>[...new Set([...T,...Object.keys(e??{})])];function ye(e,t){if(e&&t?.[e]){let n=ae.get(t);n||ae.set(t,n=new Map);let r=n.get(e);return r||n.set(e,r=be(_e(e,t))),r}return be(S[e??`paper`]??S[E(e)?.light??`paper`]??S.paper)}function be(e){let t=ie.get(e);return t||(t={...e,tone:n=>e.tone(n)??re(n,t,!1),groupTone:n=>e.groupTone(n)??re(n,t,!0),edgeTone:t=>e.edgeTone(t)??(te(t)?t:void 0)},ie.set(e,t)),t}var xe=e=>{let t=e.toLowerCase().match(/^([a-z]+)(?:-(\d{2,3}))?$/);return!!t&&d(t[1])&&(!t[2]||t[2]in p)||!!te(e)},Se=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 Ce(e)?e:void 0}var Ce=e=>/^[\w\s#(),.%/+-]*$/.test(e),we=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())},P=(e,t=e.node.text,n=e.node.stroke)=>({text:t,sub:e.node.sub,stroke:n}),Te=e=>({...e,text:e.sub}),Ee=/^(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?)$/,De=/^\{(#[0-9a-fA-F]{3,8}|[a-z]+(?:-\d{2,3})?):[ ]?(.+)\}$/,Oe=/\*\*(.{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,ke=l({color:{aliases:[`text`],info:`text colour: a palette name or any CSS colour`,values:f},size:{aliases:[`font-size`],info:`font size, px`,values:[]},weight:{aliases:[`font-weight`],info:`font weight: 400, 600, 700 ...`,values:[`300`,`400`,`500`,`600`,`700`,`800`,`900`]},font:{aliases:[`family`,`font-family`],info:`font: sans, serif, mono or a font name`,values:[`sans`,`serif`,`mono`]},italic:{aliases:[],info:`italic text`,values:[`true`,`false`],flag:!0},bold:{aliases:[],info:`bold text, weight 700`,values:[`true`,`false`],flag:!0}}),Ae=e=>e in ke?e:Object.keys(ke).find(t=>ke[t].aliases.includes(e));function je(e){let t={};for(let n of e.split(`,`)){let[e,...r]=n.split(`:`),i=e.trim();if(!r.length&&Me(i)){t.color=i;continue}let a=Ae(i);if(!a)return;let o=ke[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(!xe(s))return;t.color=s}else if(a===`font`){let e=pe(s);if(!e)return;t.font=e.font,t.mono=e.mono}else{let e=parseFloat(s);if(!(e>0&&e<=1e3))return;a===`size`?t.size=e:t.weight=e}}return t}var Me=e=>Ee.test(e)&&(e.startsWith(`#`)||d(e.replace(/-\d+$/,``)));function F(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(Oe))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&&Me(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=je(t[5]),n=e?null:t[0].match(De);e?r({kind:`color`,text:t[6],...e}):n&&Me(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]}):Me(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 Ne(e){let t=[];for(let n of e.matchAll(Oe))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 Pe=/[*~`[{]/;function Fe(e,t=!1){let n=Pe.test(e)?F(e):e?[{kind:`text`,text:e}]:[];if(t)for(let e of n)e.text=e.text.toUpperCase();return n}function Ie(e,t,n,r,i,a=!1,o=0){let s=Fe(e,a);return z(s,t,r,i,n)+(o?o*[...Ke(s)].length:0)}var Le=(e,t)=>e.reduce((e,t)=>Pe.test(t)?F(t).reduce((e,t)=>Math.max(e,t.size??0),e):e,t),Re=1.3,ze=(e,t,n=Re)=>Le(e,t)*n,Be=(e,t,n,r)=>e.map((e,i)=>`<tspan x="${L(t)}" y="${L(n(i))}">${r(e)}</tspan>`).join(``),Ve=.35,He=/<text\b([^>]*)>([\s\S]*?)<\/text>/g,Ue=/(\s)y="(-?[\d.]+)"/;function We(e){return e.replace(He,(e,t,n)=>{if(!t.includes(`dominant-baseline="central"`))return e;let r=Number(/\sfont-size="([\d.]+)"/.exec(t)?.[1]);if(!r)return e;let i=e=>e.replace(Ue,(e,t,n)=>`${t}y="${L(Number(n)+r*Ve)}"`);return`<text${i(t.replace(` dominant-baseline="central"`,``))}>${n.replace(/<tspan\b[^>]*>/g,i)}</text>`})}function Ge(e,t,n,r=!1){let i=Fe(e,r);return i.every(e=>e.kind===`text`)?I(Ke(i)):B(i,t,n)}var Ke=e=>e.map(e=>e.text).join(``);function qe(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 I=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`),Je=(e,t)=>(e?` font-style="italic"`:``)+(t?` font-family="${I(t)}"`:``),L=e=>(Math.round(e*100)/100).toString(),Ye=(e,t,n,r,i,a=``)=>`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central" font-size="${L(n)}" fill="${r}"${a}>${i}</text>`,R=(e,t,n)=>e&&N(e,t,t.dark?400:600)||n,Xe=.55,Ze=(e,t)=>e.weight??(e.kind===`bold`?700:t);function z(e,t,n,r,i=400){let a=0;for(let o of e){let e=o.size??t,s=r(o.text,e,Ze(o,i),o.mono??n);o.w=o.kind===`chip`?s+e*Xe*2:s,a+=o.w}return a}var Qe=e=>e.reduce((e,t)=>e+(t.w??0),0);function $e(e,t,n,r){if(e.color)return R(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 et(e,t,n,r,i,a,o=!1,s=400){let c=[];for(let l of e){let e=l.w??0,u=$e(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="${L(t)}" y="${L(n-a/2)}" width="${L(e)}" height="${L(a)}" rx="4" fill="${o}" stroke="${l.color?u:i.stroke}" stroke-width="1"/>`),c.push(Ye(t+r*Xe,n,r,l.color?u:i.text,I(l.text),` xml:space="preserve"`))}else{let a=Ze(l,s),o=Je(l.italic,l.font);if(c.push(Ye(t,n,l.size??r,u,I(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${L(a)},${L(n)}H${L(t+e)}" stroke="${i.sub}" stroke-width="1"/>`)}}t+=e}return c.join(``)}function B(e,t,n,r=!1){return e.map(e=>{let i=[`fill="${$e(e,t,n,r)}"`];return e.size&&i.push(`font-size="${L(e.size)}"`),e.weight?i.push(`font-weight="${e.weight}"`):e.kind===`bold`&&i.push(`font-weight="750"`),e.italic&&i.push(`font-style="italic"`),e.font&&i.push(`font-family="${I(e.font)}"`),e.kind===`strike`&&i.push(`text-decoration="line-through"`),e.kind===`chip`&&i.push(`font-weight="600"`),`<tspan ${i.join(` `)}>${I(e.text)}</tspan>`}).join(``)}var tt=(e,t)=>{let n=e===void 0?NaN:parseFloat(e);return Number.isFinite(n)?n:t};function nt(e,t=`border-style`){let n=e[t];return n&&oe.includes(n)?n:M(e.dashed,!1)?`dashed`:M(e.dotted,!1)?`dotted`:void 0}function rt(e,t){let n=N(t[`edge-color`],e,e.dark?400:500),r=it(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 it(e){return ot(e[`edge-width`])}var at=(e,t)=>{let n=tt(e,NaN);return n>=0?n:t},ot=e=>{let t=tt(e,NaN);return t>0?t:void 0},st=(e,t,n,r)=>{let i=pe(e.font);return{size:ot(e[`font-size`])??t,weight:ot(e[`font-weight`])??n,italic:M(e.italic,!1),family:i?.font,mono:i?.mono??r.mono}},ct=(e,t)=>st(e,t.fontSize*.86,500,t);function lt(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 ut(e,t){return!t.parent&&M(pt(e,t).lane??e.settings.lanes,!1)}function dt(e,t,n){return pt(e,t)[n]??ft(e,t.group,n)?.value}function ft(e,t,n){for(let r of lt(e,t).reverse()){let t=pt(e,e.groups.get(r))[n];if(t!==void 0)return{group:r,value:t}}}function pt(e,t){let n={};for(let r of t.classes??[])Object.assign(n,e.classes[r]);return Object.assign(n,t.props)}function mt(e){let t=e?.split(/[\s,]+/).filter(Boolean)??[],n=t.map(e=>Number(e.replace(/px$/,``)));if(!t.length||t.length>4||n.some(e=>!(e>=0)||!Number.isFinite(e)))return null;let[r,i=r,a=r,o=i]=n;return{top:r,right:i,bottom:a,left:o}}function ht(e,t,n){let r=e.groups.get(t);return(r&&mt(pt(e,r).padding))??{top:n,right:n,bottom:n,left:n}}function gt(e,t,n){let r=ft(e,t,`gap`);return r?at(r.value,n):n}function _t(e,t){switch(e){case`dashed`:return`${L(t*4)} ${L(t*3)}`;case`dotted`:return`${L(t*.1)} ${L(t*2.6)}`;default:return null}}function vt(e,t,n,r){let i=e.settings,a=n.color?r.tone(n.color):void 0,o=at(n.border??n[`stroke-width`],at(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=st(n,ot(i[`font-size`])??r.fontSize,500,r),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:_t(nt(n),o),radius:at(n.radius,at(i.radius,r.radius)),fontSize:d,fontWeight:M(n.bold,!1)?650:u.weight,body:N(n[`body-color`],r,r.dark?100:800)??l,bodySize:ot(n[`body-size`])??Math.round(d*.86*10)/10,bodyWeight:ot(n[`body-weight`])??400,lineHeight:ot(n[`line-height`])??1.75,italic:u.italic,family:u.family,mono:u.mono,shadow:M(n.shadow,M(i.shadow,r.shadow!==null)),opacity:tt(n.opacity,1)}}function yt(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:bt(n,t.group.dash)}}function bt(e,t){return se(nt(e),t)}function xt(e,t,n){let r=t.theme;if(!r||!(S[r]||n?.[r])||r===e.name)return rt(e,t);let i=Object.create(ye(r,n));return i.font=e.font,i.mono=e.mono,i.fontSize=e.fontSize,rt(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&&xe(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:at(e[`border-width`],a&&!s&&!o?at(a,1):1),dash:bt(e,null),radius:at(e.radius,Math.min(14,t.radius+4)),shadow:M(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`||M(n.thick,!1)?r.edgeWidth*2:r.edgeWidth,c=at(n.width,s),l=nt(n,`style`)??(t.line===`dashed`||t.line===`dotted`?t.line:void 0),u=[`smooth`,`orthogonal`,`straight`].includes(n.curve)?n.curve:i,d=M(n.flow??n.animate,!1),f=ct(n,r);return{stroke:o,width:c,dash:_t(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,family:f.family,mono:f.mono,labelBg:N(n[`label-bg`],r,r.dark?900:50)??r.edge.labelBg,flow:d,opacity:tt(n.opacity,1)}}var wt=[`center`,`left`,`right`,`top`,`bottom`],Tt=`[${wt.join(`|`)}]`;function Et(e){let t=wt.find(t=>t===e[0]);return t?[t,e.slice(1)]:[`center`,e]}function Dt(e,t){return(e===`rank`||e===`align`)&&t!==`at`&&t!==`size`}function Ot(e){let t=[],n=[...[...e.nodes.values()].map(e=>[e,!1]),...[...e.groups.values()].map(e=>[e,!0])];for(let[r,i]of n){let n=pt(e,r).align?.trim();if(n){let[e,a]=Et(n.split(/\s+/));t.push({decl:r,group:i,value:n,side:e,rest:a})}}return t}function kt(e){let t=[...e.layout.aligns??[]],n=Ot(e),r=new Map;if(n.some(e=>e.group&&!e.rest.length)){let t=(e,t)=>e&&(r.get(e)?.push(t)??r.set(e,[t]));e.nodes.forEach(e=>t(e.group,e.id)),e.groups.forEach(e=>t(e.parent,e.id))}let i=[];for(let{decl:e,group:a,side:o,rest:s}of n)s[0]?t.push({side:o,ids:[e.id,s[0]]}):a&&(r.get(e.id)?.length??0)>1&&i.push({side:o,ids:r.get(e.id),within:e.id});for(let e of t){let t=i.filter(t=>!t.within&&t.side===e.side&&t.ids.some(t=>e.ids.includes(t))),n=new Set([...t.flatMap(e=>e.ids),...e.ids]);i.splice(0,i.length,...i.filter(e=>!t.includes(e)),{side:e.side,ids:[...n]})}return i}function At(e,t,n,r,i){if(!i.length){let i=Ut(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,zt(e,t,o),zt(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}:Ht(Bt(a[n+1],a[n-1]))),s=[];for(let e=0;e<a.length-1;e++){let t=Ut(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],zt(a[e],o[e],n),zt(a[e+1],o[e+1],-r),a[e+1]])}return s}var jt=18;function Mt(e,t,n,r,i,a,o,s){let c=zt(e,t,jt),l=zt(n,r,jt),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=Pt([...u,...e,l,n]),r=It(t,b);r<S&&(S=r,x=t)}return x}function Nt(e){let t=[];for(let n of e)(!t.length||Ut(t[t.length-1],n)>.5)&&t.push(n);return t}function Pt(e){let t=Nt(e),n=[];for(let e=0;e<t.length;e++){if(n.length>=1&&e<t.length-1){let r=n[n.length-1],i=t[e+1],a=Ht(Bt(t[e],r)),o=Ht(Bt(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 Ft(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 It(e,t){let n=0,r=0,i=0;for(let a=1;a<e.length;a++){if(n+=Ut(e[a-1],e[a]),a>=2){let t=Ht(Bt(e[a-1],e[a-2])),n=Ht(Bt(e[a],e[a-1]));t.x*n.x+t.y*n.y<-.5&&r++}for(let n of t)Ft(e[a-1],e[a],n)&&i++}return n+(e.length-2)*18+r*600+i*400}var Lt=[`top`,`right`,`bottom`,`left`],Rt=e=>({x:e.x+e.w/2,y:e.y+e.h/2}),zt=(e,t,n=1)=>({x:e.x+t.x*n,y:e.y+t.y*n}),Bt=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Vt=e=>Math.hypot(e.x,e.y),Ht=e=>{let t=Vt(e)||1;return{x:e.x/t,y:e.y/t}},Ut=(e,t)=>Vt(Bt(e,t)),Wt=e=>Math.round(e*100)/100,Gt=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,Kt=(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 qt(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(Jt(n,r,i,a,e/16));return t}function Jt(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 Yt(e){return Xt(e,.5)}function Xt(e,t){let n=0;for(let t=1;t<e.length;t++)n+=Ut(e[t-1],e[t]);let r=n*t;for(let t=1;t<e.length;t++){let n=Ut(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 Zt(e){if(e.kind===`cubic`){let t=`M${Wt(e.segs[0][0].x)},${Wt(e.segs[0][0].y)}`;for(let[,n,r,i]of e.segs)t+=`C${Wt(n.x)},${Wt(n.y)} ${Wt(r.x)},${Wt(r.y)} ${Wt(i.x)},${Wt(i.y)}`;return t}let t=Nt(e.pts),n=`M${Wt(t[0].x)},${Wt(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,Ut(i,a)/2,Ut(a,o)/2);if(s<.5){n+=`L${Wt(a.x)},${Wt(a.y)}`;continue}let c=zt(a,Ht(Bt(i,a)),s),l=zt(a,Ht(Bt(o,a)),s);n+=`L${Wt(c.x)},${Wt(c.y)}Q${Wt(a.x)},${Wt(a.y)} ${Wt(l.x)},${Wt(l.y)}`}let r=t[t.length-1];return n+`L${Wt(r.x)},${Wt(r.y)}`}function Qt(e,t,n,r){let i=Rt(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 $t={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function en(e,t,n){let r=Rt(e);return n===`left`||n===`right`?t.y>=r.y?`bottom`:`top`:t.x>=r.x?`right`:`left`}function tn(e,t,n){let r=en(t,n,e);return[e,r,$t[r]]}function nn(e,t,n,r,i,a,o){let s=Math.min(e.x,t.x)-80,c=Math.min(e.y,t.y)-80,l={x:s,y:c,w:Math.max(e.x+e.w,t.x+t.w)+80-s,h:Math.max(e.y+e.h,t.y+t.h)+80-c},u=o.filter(n=>n!==e&&n!==t&&Gt(n,l));if(!u.length)return[n,r];let d=i?tn(n,e,Rt(t)):[n],f=a?tn(r,t,Rt(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=Bn(e.shape,e,r,0),o=Bn(t.shape,t,i,0),s=qt({kind:`cubic`,segs:At(a,Rn[r],o,Rn[i],[])}),c=0;for(let e of u)s.some(t=>t.x>e.x+2&&t.x<e.x+e.w-2&&t.y>e.y+2&&t.y<e.y+e.h-2)&&c++;if(!c)return n;c<g&&([h,g]=[n,c])}return h}function rn(e,t){return t===0?e.via[0]??Rt(e.b):e.via[e.via.length-1]??Rt(e.a)}function an(e){let t=new Map;for(let n of e){let{stroke:e,width:r,dash:i,curve:a,flow:o,opacity:s}=n.style,c=[e,r,i,a,o,s].join(`\0`);for(let e of[0,1]){if(!n.mergeable[e])continue;let r=e===0?n.a:n.b,i=n.sides[e],a=e===0?n.tailKind:n.headKind,o=[e,r.id,i,a,c].join(`\0`),s=t.get(o);s?s.members.push(n):t.set(o,{members:[n],lead:n,end:e,node:r,side:i,reach:0})}}let n=[...t.values()].filter(e=>e.members.length>1);for(let e of n)for(let t of e.members)t.merged[e.end]=e;return n}var on=16,sn=.4;function cn(e){return e.filter(e=>{let{end:t,node:n}=e,r=Bn(n.shape,n,e.side,0),i=Rn[e.side],a=e=>(e.x-r.x)*i.x+(e.y-r.y)*i.y;if(e.reach=Math.min(...e.members.map(e=>{let n=t===0?e.via[0]:e.via[e.via.length-1];if(n)return a(n);let r=t===0?e.b:e.a,i=[r,{x:r.x+r.w,y:r.y},{x:r.x,y:r.y+r.h},{x:r.x+r.w,y:r.y+r.h}];return Math.min(...i.map(a))}))*sn,e.reach>=on)return!0;for(let n of e.members)n.merged[t]=void 0;return!1})}function ln(e){for(let t of e){let{end:e,lead:n}=t;t.junction=zt(Bn(t.node.shape,t.node,t.side,n.t[e]),Rn[t.side],t.reach);for(let r of t.members)r.t[e]=n.t[e]}}var un=[.5,.42,.58,.34,.66,.26,.74];function dn(e,t,n,r){let i=Xt(e,.5),a=1/0;for(let n of un){let o=Xt(e,n),s=t(o),c=Math.abs(n-.5);for(let e of r.obstacles)Gt(s,e)&&(c+=4);for(let e of r.groups??[])Gt(s,e.header)?c+=3:Gt(s,e.box)&&!Kt(s,e.box)&&(c+=2);if(c<a&&(a=c,i=o),c<1)break}return i}var fn=e=>7+e*2;function pn(e,t,n){let r=Tn.get(e);return r?typeof r.inset==`function`?r.inset(t,n):r.inset??0:0}function mn(e,t){if(e.kind===`poly`){let n=e.pts;if(t===`end`){for(let e=n.length-2;e>=0;e--)if(Ut(n[e],n[n.length-1])>.5)return Ht(Bt(n[n.length-1],n[e]))}else for(let e=1;e<n.length;e++)if(Ut(n[e],n[0])>.5)return Ht(Bt(n[0],n[e]));return{x:1,y:0}}if(t===`end`){let[t,,n,r]=e.segs[e.segs.length-1];return Ht(Bt(r,Ut(n,r)>.5?n:t))}let[n,r,,i]=e.segs[0];return Ht(Bt(n,Ut(r,n)>.5?r:i))}function hn(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=Ut(r[i],r[a]);if(o<.5)return;r[i]=zt(r[i],Ht(Bt(r[a],r[i])),Math.min(n,o*.9))}else if(t===`end`){let t=e.segs[e.segs.length-1],r=Ht(Bt(Ut(t[2],t[3])>.5?t[2]:t[0],t[3]));t[3]=zt(t[3],r,n),Ut(t[2],t[3])<n&&(t[2]=zt(t[3],r,n))}else{let t=e.segs[0],r=Ht(Bt(Ut(t[1],t[0])>.5?t[1]:t[3],t[0]));t[0]=zt(t[0],r,n)}}}var gn={both:[!0,!0],out:[!0,!1],in:[!1,!0],none:[!1,!1]},_n={right:`right`,down:`bottom`,left:`left`,up:`top`};function vn(e,t,n){return n===`right`?t.x>=e.x+e.w:n===`left`?t.x+t.w<=e.x:n===`down`?t.y>=e.y+e.h:t.y+t.h<=e.y}var yn=(e,t)=>e&&(e===`none`||Tn.has(e))?e:t;function bn(e,t,n){let r=[],i=(e,t)=>e<t?`${e}\u0000${t}`:`${t}\u0000${e}`,a=new Map;for(let t of e.edges){if(t.from===t.to||e.layout.edges[t.key]?.via?.length||n.dummyVia.get(t.key)?.length)continue;let r=i(t.from,t.to);a.has(r)||a.set(r,[]),a.get(r).push(t.key)}let o=n.theme.fontSize*2.1,s=new Map(e.edges.map(e=>[e.key,e])),c=new Map,l=new Map,u=t=>{let n=l.get(t);if(!n){let r=e.nodes.get(t);n=gn[(r&&dt(e,r,`merge`))??e.settings.merge??`none`]??gn.none,l.set(t,n)}return n};for(let l of e.edges){let d=t.get(l.from),f=t.get(l.to);if(!d||!f)continue;let p=pt(e,l),m=Ct(e,l,p,n.theme,n.defaultCurve),h=e.layout.edges[l.key],g=!!h?.via?.length,_=(g?h.via:n.dummyVia.get(l.key)??[]).map(e=>({...e})),v=d!==f&&!_.length?a.get(i(l.from,l.to)):void 0;if(v&&v.length>1){let[t,r]=l.from<l.to?[d,f]:[f,d],i=Ht(Bt(Rt(r),Rt(t))),a=c.get(v);if(!a){let t=v.map(t=>{let r=s.get(t),a=r?.label?ct(pt(e,r),n.theme):void 0,c=a?Math.max(...r.label.split(`
|
|
2
|
+
`).map(e=>Ie(e,a.size,a.weight,a.mono,n.measure)))+18:0;return Math.max(o,Math.abs(i.y)*c+Math.abs(i.x)*o+6)}),r=t.reduce((e,t)=>e+t,0);a=new Map;let l=0;for(let e=0;e<v.length;e++)a.set(v[e],l+t[e]/2-r/2),l+=t[e];c.set(v,a)}let u=a.get(l.key),p=Rt(d),m=Rt(f);u&&_.push(zt({x:(p.x+m.x)/2,y:(p.y+m.y)/2},{x:-i.y,y:i.x},u))}let y=h?.ports?.[0]??p.exit??p[`from-side`],b=h?.ports?.[1]??p.enter??p[`to-side`],x=Lt.includes(y)?y:null,S=Lt.includes(b)?b:null,C=x??Qt(d,_[0]??Rt(f),_.length?null:f,n.direction),w=S??Qt(f,_[_.length-1]??Rt(d),_.length?null:d,n.direction);_.length||d===f||x&&S||([C,w]=nn(d,f,C,w,!x,!S,n.obstacles));let T=d===f||g||(v?.length??0)>1?[!1,!1]:p.merge?gn[p.merge]??gn.none:[u(l.from)[0],u(l.to)[1]];vn(d,f,n.direction)&&(C=T[0]&&!x?_n[n.direction]:C,w=T[1]&&!S?$t[_n[n.direction]]:w),r.push({e:l,a:d,b:f,via:_,manualVia:g,sides:d===f?[`right`,`top`]:[C,w],t:[0,0],style:m,headKind:l.endHead||p.head?yn(p.head,`arrow`):`none`,tailKind:l.startHead||p.tail?yn(p.tail,`arrow`):`none`,labelOff:h?.label,mergeable:T,merged:[void 0,void 0]})}let d=cn(an(r)),f=new Map,p=(e,t,n,r,i)=>{let a=i.map(e=>rn(e,t)),o={x:a.reduce((e,t)=>e+t.x,0)/a.length,y:a.reduce((e,t)=>e+t.y,0)/a.length},s=`${n.id}\u0000${r}`,c=f.get(s)??{side:r,list:[]};f.set(s,c),c.list.push({it:e,end:t,other:o})};for(let e of r)if(e.a!==e.b)for(let t of[0,1])e.merged[t]||p(e,t,t===0?e.a:e.b,e.sides[t],[e]);for(let e of d)p(e.lead,e.end,e.node,e.side,e.members);let m=new Map(r.map((e,t)=>[e,t]));for(let{side:e,list:t}of f.values()){let n=e===`top`||e===`bottom`;t.sort((e,t)=>(n?e.other.x-t.other.x:e.other.y-t.other.y)||m.get(e.it)-m.get(t.it));let r=t.length;t.forEach((e,t)=>e.it.t[e.end]=r===1?0:(t+1)/(r+1)*2-1)}return ln(d),r.map(e=>xn(e,n))}function xn(e,t){let{a:n,b:r,style:i}=e,a,o,s;n===r?(o={x:n.x+n.w,y:n.y+n.h*.32},s={x:n.x+n.w*.68,y:n.y},a={kind:`cubic`,segs:[[o,zt(o,{x:52,y:0}),zt(s,{x:0,y:-52}),s]]}):(o=Bn(n.shape,n,e.sides[0],e.t[0]),s=Bn(r.shape,r,e.sides[1],e.t[1]),a=Sn(e,t,e.merged[0]?.junction??o,e.merged[1]?.junction??s));let c=e.e.props.caption,l=e.e.label||c?qt(a):void 0,[u,d]=e.merged,f=u?.lead===e,p=d?.lead===e;f&&Cn(a,`start`,o),p&&Cn(a,`end`,s);let m=l&&!f&&!p?l:qt(a),h;if(l){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=>Ie(e,n,i.fontWeight,r,t.measure)))+(t.theme.edge.labelStroke?18:12):0,s=ze(a,n),u=a.length?a.length*s+6:0,d=n*.88,f=c?c.split(`
|
|
4
|
+
`):[],p=f.length?Math.max(...f.map(e=>Ie(e,d,400,r,t.measure)))+8:0,m=ze(f,d),g=f.length*m+(f.length?4:0),_=Math.max(o,p)/2,v=u?-u/2:0,y=(u?u/2:0)+g,b=e.e.props.rotate===`true`||e.e.props.rotate===``,x=e=>b?{x:e.x+v,y:e.y-_,w:y-v,h:_*2}:{x:e.x-_,y:e.y+v,w:_*2,h:y-v},S=e.labelOff?zt(Yt(l),e.labelOff):dn(l,x,e,t),C=x(S);h={text:e.e.label??``,caption:c,...C,anchor:S,pill:{w:o,h:u},lineHeight:s,captionLineHeight:m,rotate:b}}let g=[],_=fn(i.width),v=mn(a,`end`),y=mn(a,`start`);return e.headKind!==`none`&&(!d||p)&&(g.push({at:s,angle:Math.atan2(v.y,v.x),kind:e.headKind}),hn(a,`end`,pn(e.headKind,_,i.width))),e.tailKind!==`none`&&(!u||f)&&(g.push({at:o,angle:Math.atan2(y.y,y.x),kind:e.tailKind}),hn(a,`start`,pn(e.tailKind,_,i.width))),{key:e.e.key,decl:e.e,d:Zt(a),samples:m,start:o,end:s,sides:e.sides,via:e.via,manualVia:e.manualVia,label:h,heads:g,style:i}}function Sn(e,t,n,r){let{a:i,b:a,style:o}=e,s=Rn[e.sides[0]],c=Rn[e.sides[1]];if(t.channels?.has(e.e.key)&&e.via.length>=2){let o=e.via.map(e=>({...e}));return o[0].y=n.y,o[o.length-1].y=r.y,{kind:`poly`,pts:Mt(n,s,r,c,o,i,a,t.obstacles),radius:10}}return o.curve===`orthogonal`?{kind:`poly`,pts:Mt(n,s,r,c,e.via,i,a,t.obstacles),radius:10}:o.curve===`straight`?{kind:`poly`,pts:[n,...e.via,r],radius:e.via.length?6:0}:{kind:`cubic`,segs:At(n,s,r,c,e.via)}}function Cn(e,t,n){if(e.kind===`poly`){t===`start`?e.pts.unshift(n):e.pts.push(n);return}let[r,i]=t===`start`?[n,e.segs[0][0]]:[e.segs[e.segs.length-1][3],n],a=Bt(i,r),o=[r,zt(r,a,1/3),zt(r,a,2/3),i];t===`start`?e.segs.unshift(o):e.segs.push(o)}var wn=new Map,Tn=new Map,En=[],Dn=[];function On(e,t,n,r,i,a=fn(i)){let o=Tn.get(n);return o?o.render(e,t,{color:r,width:i,size:a}):``}var kn=[],An=l({});function jn(e){if(!e)return`rounded`;let t=e.toLowerCase();return wn.has(t)?t:An[t]??`rounded`}function Mn(e,t){return{w:Math.max(e+44,96),h:Math.max(t+28,48)}}function Nn(e,t,n){return wn.get(e)?.size?.(t,n)??Mn(t,n)}function Pn(e){return wn.get(e)?.textOffset??0}function Fn(e,t,n){let r=wn.get(e);return r?r.path(t,n):Ln(t.x,t.y,t.w,t.h,Math.min(n,t.w/2,t.h/2))}function In(e,t){return wn.get(e)?.detail?.(t)??null}function Ln(e,t,n,r,i){return i<=0?`M${L(e)},${L(t)}h${L(n)}v${L(r)}h${L(-n)}Z`:`M${L(e+i)},${L(t)}H${L(e+n-i)}A${L(i)},${L(i)} 0 0 1 ${L(e+n)},${L(t+i)}V${L(t+r-i)}A${L(i)},${L(i)} 0 0 1 ${L(e+n-i)},${L(t+r)}H${L(e+i)}A${L(i)},${L(i)} 0 0 1 ${L(e)},${L(t+r-i)}V${L(t+i)}A${L(i)},${L(i)} 0 0 1 ${L(e+i)},${L(t)}Z`}var Rn={top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}};function zn(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 Bn(e,t,n,r){let i=wn.get(e);return i?.port?i.port(t,n,r):zn(t,n,r)}var Vn=[`smooth`,`orthogonal`,`straight`],Hn=[`none`],Un=[...Lt,`auto`],Wn=[`below`,`above`,`right-of`,`left-of`,`rank`],Gn=[`text`,`font`,`font-size`,`font-weight`,`italic`],Kn=[`shape`,`color`,`fill`,`stroke`,...Gn,`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`,...Wn,`align`,`merge`],qn=[`style`,`width`,`color`,`stroke`,`curve`,`head`,`tail`,`flow`,`animate`,`opacity`,...Gn,`label-color`,`label-bg`,`dashed`,`dotted`,`thick`,`exit`,`from-side`,`enter`,`to-side`,`constraint`,`caption`,`rotate`,`length`,`merge`],Jn=[`color`,`fill`,`stroke`,...Gn,`border-style`,`dashed`,`dotted`,`meta`,`caps`,`align`,`merge`,`gap`,`padding`,`lane`];[...Gn];var Yn={width:`the smallest width of the panel's frame, in pixels`,height:`the smallest height of the panel's frame, in pixels`,frame:"`false` drops the box",theme:`a theme name`,border:"`none`, a palette name or any CSS colour"},Xn=l({shape:[...kn,...Object.keys(An)],"border-style":oe,style:oe,curve:Vn,head:Hn,tail:Hn,exit:Un,"from-side":Un,enter:Un,"to-side":Un,merge:[`none`,`in`,`out`,`both`]}),Zn=[`color`,`fill`,`stroke`,`text`,`sub-color`,`body-color`,`label-color`,`label-bg`,`background`,`edge-color`],Qn=e=>![`none`,`transparent`,`currentcolor`,`inherit`].includes(e.toLowerCase())&&!/^var\(--[\w-]+\)$/.test(e)&&!xe(e),$n=e=>or(e,f)||`: use a palette name (${f.join(`, `)}), #hex, rgb(), hsl() or a CSS colour name`,er=[`dashed`,`dotted`,`thick`,`bold`,`italic`,`shadow`,`flow`,`animate`,`constraint`,`caps`,`mono`,`rotate`,`lane`],tr=1e5,nr=e=>Number.isFinite(e)&&Math.abs(e)<=1e5,rr=[`border`,`stroke-width`,`radius`,`font-size`,`font-weight`,`opacity`,`width`,`height`,`max-width`,`length`,`body-size`,`body-weight`,`line-height`,`gap`];function ir(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 ar(e,t){let n=e.toLowerCase(),r=``,i=1/0;for(let e of t){let t=ir(n,e.toLowerCase());t<i&&([r,i]=[e,t])}return[r,i]}function or(e,t){let[n,r]=ar(e,t);return r<=(e.length<=3?1:Math.max(2,Math.floor(e.length/3)))?` (did you mean "${n}"?)`:``}function sr(e,t,n,r,i,a){for(let[o,s]of Object.entries(e)){let c=a?.[o]??r;if(!t.includes(o)){n===`node`&&qn.includes(o)?i(c,`"${o}" is an edge prop, but here it is on a node. On an edge line, edge props go after a colon: a -> b: [${o}]`):o===`label`||o===`name`||o===`title`?i(c,`"${o}" is not a prop. A label follows the id in quotes: id "${s}"; an edge label follows a colon: a -> b: ${s}`):i(c,`Unknown ${n} prop "${o}"${or(o,t)||` (${n} props: ${t.join(`, `)})`}`);continue}let l=Xn[o],u=o===`frame`?s.trim().split(/\s+/)[0].toLowerCase():s.toLowerCase();if(Zn.includes(o)&&Qn(s))i(c,`Unknown ${o} "${s}"${$n(s)}`);else if(l&&!l.includes(u)){let e=o===`shape`?kn:l,t=e.length?` (use one of: ${e.join(`, `)})`:` (none registered: use the ${o}s plugin)`;i(c,`Unknown ${o} "${s}"${or(s,l)||t}`)}else if(er.includes(o)&&![`true`,`false`].includes(s))i(c,`${o} expects true or false, got "${s}"`);else if(rr.includes(o)){let t=parseFloat(s);t>=0&&Number.isFinite(t)?t>1e5&&(i(c,`${o} is at most ${tr}, got "${s}"`),e[o]=String(tr)):i(c,`${o} expects a number of 0 or more, got "${s}"`)}else o===`padding`&&!mt(s)?i(c,`padding expects 1 to 4 numbers of 0 or more, like CSS (top right bottom left), got "${s}"`):o===`link`&&!we(s)&&i(c,`link "${s}" is not rendered: use http(s), mailto, an #anchor or a relative path`)}}function cr(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`?xe(a)||r(n,`Unknown ${i} "${a}"${or(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}"${or(a,[...e])||` (use one of: ${e.join(`, `)})`}`))}}var lr=(e,t)=>e.ref?.propLines?.[t]??e.propAt?.[t]??e.ref?.line;function ur(e){for(let[t,n]of Object.entries(e))if(Wn.includes(t)&&n)return[t,n.trim()]}function dr(e,t){let n=t=>e.nodes.has(t)||e.groups.has(t);for(let{decl:r,group:i,value:a,rest:o}of Ot(e)){let s=r.ref&&lr(r,`align`),[c]=o;s!==void 0&&(o.length>1?t(s,`align takes one id: align: ${Tt} id`):c?c===r.id?t(s,`align: ${c} lines ${r.id} up with itself; use another id`):n(c)||t(s,`align: unknown node or group "${c}"${or(c,[...e.nodes.keys(),...e.groups.keys()])}`):i||t(s,`align: ${a} needs an id to line up with: align: ${a} other`))}}function fr(e,t){let n=new Map;for(let r of e.nodes.values()){let i=pt(e,r),a=ur(i);if(!a)continue;let[o,s]=a,c=lr(r,o);for(let e of Object.keys(i))e!==o&&Wn.includes(e)&&r.ref&&t(lr(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}"${or(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=ur(pt(e,s))[0];s.ref&&t(lr(s,c),`placement loop: ${[...a,i].join(` → `)}. These nodes cannot all be placed; remove one placement prop`)}}var pr=e=>e.toLowerCase().replace(/\d+/g,`#`);function mr(e,t){let n=[...e.nodes.values()],r=n.filter(e=>!e.implicit).map(e=>({id:e.id,series:pr(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=pr(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]=ar(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 hr(e,t){let n=(t,n)=>e.diagnostics.push({line:t+1,message:n,severity:`warning`,code:`lint`});for(let t of e.nodes.values())t.ref&&sr(t.props,Kn,`node`,t.ref.line,n,{...t.propAt,...t.ref.propLines});fr(e,n),dr(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),sr(t.props,qn,`edge`,e,n,t.ref.propLines))}for(let t of e.groups.values())t.ref&&sr(t.props,Jn,`group`,t.ref.line,n,t.ref.propLines);mr(e,n);let i=ve(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}"${or(a.theme,i)||` (themes: ${i.join(`, `)})`}`);for(let t of Zn)a[t]&&Qn(a[t])&&n(e,`Unknown ${t} "${a[t]}"${$n(a[t])}`);let o=a.border;o&&![`none`,`false`].includes(o)&&!xe(o)&&!Number.isFinite(parseFloat(o))&&n(e,`border takes a colour, a width or none, got "${o}"`),a[`border-style`]&&!oe.includes(a[`border-style`])&&n(e,`Unknown border-style "${a[`border-style`]}" (use one of: ${oe.join(`, `)})`),cr(a,t?.(r.kind),e,n)}let a=[...new Set([...Kn,...qn,...Jn])];for(let[t,r]of Object.entries(e.classes)){let i=e.classLines?.[t];i!==void 0&&sr(r,a,`class .${t}`,i,n)}e.diagnostics.sort((e,t)=>e.line-t.line)}var gr=[`group`,`import`,`export`,`layout`,`def`,`theme`],_r=new Set(`title.subtitle.theme.accent.direction.curve.gap.rank-gap.max-width.font.font-size.background.padding.shadow.radius.stroke-width.shape.grid.panels.panel-gap.wrap.edge-color.edge-width.merge.look.lanes`.split(`.`)),vr=[..._r],yr=l({direction:[`right`,`down`,`left`,`up`],curve:Xn.curve,panels:[`row`,`column`,`grid`,`wrap`],merge:Xn.merge,look:[`clean`,`sketch`],lanes:[`on`,`off`]}),br=l({direction:"which way the flow runs: `right`, `down`, `left` or `up`",curve:"how edges bend: `smooth`, `orthogonal` or `straight`",gap:"space between nodes in the same rank, px. A group's `gap` overrides it for its members","rank-gap":"space between ranks, px: between columns in `right`/`left`, between rows in `down`/`up`. Default 72, or 96 with groups. A group's `gap` overrides it where only the group's own edges cross",padding:"space around the whole diagram, px. A group's `padding` is the space inside its border","max-width":`fit the diagram into this width, px: ranks wrap into rows`,wrap:`wrap node labels wider than this, px`,merge:"edges that share a node and side join into one line there. A node's, group's or edge's `merge` overrides it",panels:"how panels line up next to the graph: `row`, `column`, `grid` or `wrap`","panel-gap":`space between the graph and the panels, px`,look:"`sketch` draws lines and shapes as if by hand; text stays crisp. Default `clean`",lanes:"top-level groups become swimlanes: bands across the whole diagram, in the order they are declared. A group's `lane` prop overrides it"}),xr=l({lr:`right`,rl:`left`,tb:`down`,td:`down`,bt:`up`}),Sr=new Set(yr.curve),Cr=new Map,wr=new Map,Tr=[],Er=new Set([...f,`violet`]),Dr=e=>wn.has(e)||e in An,Or=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u,kr=/^(<)?(--|-|\.\.|==|=)(>)?/,Ar=/^\.[\p{L}_][\p{L}\p{N}_-]*/u,jr=/^(.*?)((?:\s+\.[\p{L}_][\p{L}\p{N}_-]*)*)\s*(\[[^\]]*\])?$/su,Mr=/^-?\d+(?:\.\d+)?/;function Nr(e){return e.replace(/\\(n|t|"|'|\\)/g,(e,t)=>t===`n`?`
|
|
5
|
+
`:t===`t`?` `:t)}function Pr(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:Nr(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(Ar)){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(Or)){t.push({kind:`ident`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(Mr)){t.push({kind:`number`,value:o[0],start:n,end:n+o[0].length}),n+=o[0].length;continue}if(o=a.match(kr)){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 Fr(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 Ir(e,t,n){Object.assign(e.props,t);for(let r in t)(e.propAt??={})[r]=n}function Lr(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)`),{}):V(e.value)}var Rr=e=>{let t=e.trim().toLowerCase();return t===`tone`?`color`:t};function V(e=``){let t={},n=[],r=``,i=null,a=0;for(let t=0;t<e.length;t++){let o=e[t];i?(r+=o,o===`\\`?r+=e[++t]??``:o===i&&(i=null)):o===`"`||o===`'`?(i=o,r+=o):o===`(`?(a++,r+=o):o===`)`?(a=Math.max(0,a-1),r+=o):(o===`,`||o===`;`)&&!a?(n.push(r),r=``):r+=o}n.push(r);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`),i=r>=0?r:/^[\w-]+\s*=/.test(n)?n.indexOf(`=`):-1;if(i<0){let e=n.toLowerCase();Er.has(e)?t.color=e:Dr(e)?t.shape=e:Sr.has(e)?t.curve=e:xe(n)?t.color=n:t[e]=`true`;continue}let a=Rr(n.slice(0,i)),o=n.slice(i+1).trim();/^(["']).*\1$/s.test(o)&&(o=Nr(o.slice(1,-1))),t[a]=o}return t}var zr=e=>{let t=e.search(/\s\/\//);return t<0?e:e.slice(0,t).trimEnd()},Br=/(?<!\[)\[([^[\]]*)\]\s*$/;function Vr(e,t){let n=e.match(Br),r=n?V(n[1]):void 0;return r&&(!t||t(r))?[e.slice(0,n.index).trimEnd(),r]:[e,{}]}function Hr(e,t,n,r){let i=Rr(t),[a,o]=Vr(e,r);n===null?delete o[i]:o[i]=n;let s=a.replace(/\s+$/,``),c=Gr(o);return c?`${s} [${c}]`:s}var Ur=e=>{let t=Object.keys(e);return t.length===1&&t[0]===`color`&&xe(e.color)};function Wr(e,t,n,r,i){let a=Rr(n),[o,s]=Vr(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}=V(n),l=Gr(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=Gr(s);return u?`${l} [${u}]`:l}function Gr(e){return Object.entries(e).map(([e,t])=>t===`true`&&!Er.has(e)&&!Dr(e)&&!Sr.has(e)&&!xe(e)?e:e===`color`&&xe(t)&&!Dr(t)&&!Sr.has(t.toLowerCase())&&!/[;[\]]/.test(t)?t:`${e}: ${Kr(t)}`).join(`, `)}function Kr(e){return/[,;[\]"'()\n\r]|^\s|\s$|^$/.test(e)?Jr(e):e}function qr(e){let t=e.match(kr),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 Jr=e=>`"${e.replace(/[\\"]/g,`\\$&`).replace(/\r\n?|\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,H=e=>/^(["']).*\1$/s.test(e.trim())?Nr(e.trim().slice(1,-1)):e.trim(),Yr=new Map;function Xr(e,t){return/^\s*%%/.test(t)?`Comments start with //`:/(--|==|-\.|->|=>)\|[^|]*\|/.test(t)?`Edge labels go after a colon: a -> b: label`:Zr(e,t)}function Zr(e,t){let n=e[0]?.value;if([`def`,`export`,`import`].includes(n)||wr.has(n)||Cr.has(n))return;let r=[],i=!1;for(let n=0;n<e.length-1;n++){let[a,o]=[e[n],e[n+1]];if(a.kind!==`ident`||o.start!==a.end)continue;let s,c=``;if(o.kind===`props`&&!/[:=,]/.test(o.value)&&/[A-Z\s?!]/.test(o.value)&&!xe(o.value)){let e=o.value.match(/^\((.*)\)$/s);s=e?e[1]:o.value,c=e?` [cylinder]`:``}else if(o.kind===`punct`&&o.value===`{`&&t.includes(`}`,o.end))s=t.slice(o.end,t.indexOf(`}`,o.end)),c=` [diamond]`;else if(o.kind===`word`&&o.value.startsWith(`(`)){let e=o.value.match(/^(\(\(|\(\[|\()(.*?)(\)\)|\]\)|\))$/);e&&(s=e[2],c=e[1]===`((`?` [circle]`:e[1]===`([`?` [pill]`:``)}s!==void 0&&(i||=c!==``||o.kind!==`props`,r.push(`${a.value} ${Jr(s.trim())}${c}`))}return i?`Mermaid node shapes: write ${r.join(`, `)}`:void 0}function Qr(e){let t=Yr.get(e[0].value);return`"${e[0].value} ${e[1].value} {" reads as two nodes; "${e[0].value}" is not a panel kind${Cr.size?` (${[...Cr.keys()].join(`, `)})`:`: none is registered`}`+(t?`: write "${t.replace(`ID`,e[1].value)} {"`:``)}function $r(e){return typeof e==`string`?{kind:e}:{kind:`select`,values:e}}function ei(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 ti(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 ni={plugins:[],rows:[],frames:new Map,decorations:[],panels:Cr},ri=(e,t)=>{for(let n of t??[])e.includes(n)||e.push(n)},ii=(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)}},ai=()=>{},oi=()=>``,si=()=>({w:0,h:0}),ci={row:{parse:()=>null,finish:ai,measure:si,render:oi},frame:{inset:()=>({top:0}),render:oi},decoration:{measure:()=>null,render:oi},shape:{path:e=>Ln(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:oi,inset:()=>0},panel:{measure:si,render:oi,handles:()=>[],parts:()=>[],editPart:()=>null},hook:{transform:ai,afterLayout:ai,postRender:e=>e}};function li(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 ui(e){let t=e.name,n=(e,n,r)=>(e??[]).map(e=>li(t,t=>n(e,t),e,r));return{rows:n(e.rows,e=>`row "${e.kind}"`,ci.row),frames:n(e.frames,e=>`frame "${e.name}"`,ci.frame),decorations:n(e.decorations,e=>`decoration "${e.name}"`,ci.decoration),shapes:n(e.shapes,e=>`shape "${e.name}"`,ci.shape),markers:n(e.markers,e=>`marker "${e.name}"`,ci.marker),panels:n(e.panels,(e,t)=>`${e.name} panel ${t===`editPart`?`edit`:t}`,ci.panel),statements:(e.statements??[]).map(e=>({...e,parse:i(t,e.keyword,e.parse.bind(e),ai,(e,[,,t])=>t.warn(e,`error`))})),hooks:li(t,e=>e,{transform:e.transform,afterLayout:e.afterLayout,postRender:e.postRender},ci.hook)}}var di;function fi(){let e=[_r].map(e=>[e,[...e]]),t=[Cr,Yr,wr,wn,Tn,ni.frames].map(e=>[e,[...e]]),n=[Tr,En,Dn,Kn,qn,Jn,er,rr,T,w,kn,ni.rows,ni.decorations].map(e=>[e,[...e]]),r=Object.entries(Xn).map(([e,t])=>[e,t,[...t]]),i={...S},a={...An};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(Xn))delete Xn[e];for(let[e,t,n]of r)t.splice(0,t.length,...n),Xn[e]=t;for(let e of Object.keys(S))delete S[e];Object.assign(S,i);for(let e of Object.keys(An))delete An[e];Object.assign(An,a),s()}}function pi(e,t,n){let r=e.findIndex(n);r>=0?e[r]=t:e.push(t)}function mi(...e){di??=fi();for(let t of e){if(ni.plugins.some(e=>e.name===t.name))continue;ni.plugins.push(t);let e=ui(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??[])D(e);n(`row`,e.rows,e=>e.kind,(e,t)=>pi(ni.rows,e,e=>e.kind===t)),n(`decoration`,e.decorations,e=>e.name,(e,t)=>{pi(ni.decorations,e,e=>e.name===t),_r.add(e.setting)}),n(`frame`,e.frames,e=>e.name,ni.frames),n(`panel`,e.panels,e=>e.name,Cr),n(`panel alias`,(t.panels??[]).flatMap(e=>Object.entries(e.aliases??{}).map(([t,n])=>[t,e.name,n])),([e])=>e,([,e,t],n)=>Yr.set(n,`${e} ID${t?` ${t}`:``}`)),n(`statement`,e.statements,e=>e.keyword,wr),n(`marker`,e.markers,e=>e.name,Tn),n(`shape`,e.shapes,e=>e.name,(e,t)=>{wn.set(t,e),kn.includes(t)||kn.push(t);for(let n of e.aliases??[])An[n]=t}),ri(Xn.shape??=[],[...t.shapes?.map(e=>e.name)??[],...t.shapes?.flatMap(e=>e.aliases??[])??[]]),ii(Xn.head??=[],t.markers),Xn.tail!==Xn.head&&ii(Xn.tail??=[],t.markers);let{transform:r,afterLayout:i,postRender:a}=e.hooks;r&&Tr.push(r),i&&En.push(i),a&&Dn.push(a);for(let e of t.settings??[])_r.add(e);ri(Kn,t.props?.node),ri(qn,t.props?.edge),ri(Jn,t.props?.group);for(let[e,n]of Object.entries(t.enums??{}))ri(Xn[e]??=[],n);ri(er,t.bools),ri(rr,t.numbers)}ni.frames.size&&ri(Xn.frame??=[],[...ni.frames.keys()])}var hi=new Set(`iljtfr.,;:'!|()[]{} "\``.split(``)),gi=new Set(`mwMW@%`.split(``)),_i=(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:hi.has(t)?i+=.3:gi.has(t)?i+=.86:i+=t>=`A`&&t<=`Z`?.66:t>=`0`&&t<=`9`?.58:.54}return i*t*(n>=600?1.05:1)},vi=1.08;function yi(e){return e===_i?(e,t,n,r)=>_i(e,t,n,r)*vi:e}var bi;function xi(e){return(t,n,r,i)=>{if(bi===void 0)try{bi=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{bi=null}if(!bi)return _i(t,n,r,i);let a=i&&!/mono|courier|consolas|menlo/i.test(e)?g:e;return bi.font=`${r} ${n}px ${a}`,bi.measureText(t).width}}var Si={join:{1:`│`,4:`│`,5:`│`,2:`─`,8:`─`,10:`─`,6:`╭`,12:`╮`,3:`╰`,9:`╯`,7:`├`,13:`┤`,14:`┬`,11:`┴`,15:`┼`},dashH:`╌`,dashV:`╎`,thickH:`━`,thickV:`┃`,head:{top:`▼`,bottom:`▲`,left:`▶`,right:`◀`},square:`┌┐└┘`,round:`╭╮╰╯`,diamond:`╱╲╲╱`,h:`─`,v:`│`},Ci={join:{1:`|`,4:`|`,5:`|`,2:`-`,8:`-`,10:`-`},dashH:`.`,dashV:`:`,thickH:`=`,thickV:`#`,head:{top:`v`,bottom:`^`,left:`>`,right:`<`},square:`++++`,round:`++++`,diamond:`/\\\\/`,h:`-`,v:`|`},wi=e=>Ke(F(e)),Ti=(e,t)=>({w:e+44,h:t+28}),Ei=(e,t,n)=>zn(e,t,n,.45,(t,n)=>(t?e.h/2:e.w/2)*Math.sqrt(Math.max(0,1-n*n))),Di=({x:e,y:t,w:n,h:r})=>{let i=n/2,a=r/2;return`M${L(e+i-i)},${L(t+a)}a${L(i)},${L(a)} 0 1,0 ${L(i*2)},0a${L(i)},${L(a)} 0 1,0 ${L(-i*2)},0Z`},Oi=30,ki=62,Ai=(e,t)=>Math.min(t,e.w/2,e.h/2),ji={name:`shapes`,shapes:[{name:`rounded`,aliases:[`round`],path:(e,t)=>Ln(e.x,e.y,e.w,e.h,Ai(e,t))},{name:`box`,aliases:[`rect`,`rectangle`,`square`],textCorners:`square`,path:(e,t)=>Ln(e.x,e.y,e.w,e.h,Math.min(Ai(e,t),3))},{name:`pill`,aliases:[`stadium`,`capsule`],size:(e,t)=>{let{w:n,h:r}=Ti(e,t);return{w:Math.max(n+8,96),h:Math.max(r,44)}},path:e=>Ln(e.x,e.y,e.w,e.h,e.h/2),port:(e,t,n)=>zn(e,t,n,.55,(t,n,r)=>{if(t)return e.h/2;let i=e.h/2;return e.w/2-i+Math.sqrt(Math.max(0,i*i-r*r))})},{name:`circle`,size:(e,t)=>{let n=Math.max(Math.hypot(e,t)+16,64);return{w:n,h:n}},path:Di,port:Ei},{name:`ellipse`,aliases:[`oval`],size:(e,t)=>({w:Math.max((e+16)*1.42,90),h:Math.max((t+12)*1.42,50)}),path:Di,port:Ei},{name:`diamond`,aliases:[`rhombus`,`decision`],textCorners:`diamond`,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${L(e+n/2)},${L(t)}L${L(e+n)},${L(t+r/2)}L${L(e+n/2)},${L(t+r)}L${L(e)},${L(t+r/2)}Z`,port:(e,t,n)=>zn(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}=Ti(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${L(e+i)},${L(t)}L${L(e+n-i)},${L(t)}L${L(e+n)},${L(t+r/2)}L${L(e+n-i)},${L(t+r)}L${L(e+i)},${L(t+r)}L${L(e)},${L(t+r/2)}Z`},port:(e,t,n)=>zn(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}=Ti(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${L(e)},${L(t+i)}a${L(a)},${L(i)} 0 0,1 ${L(n)},0L${L(e+n)},${L(t+r-i)}a${L(a)},${L(i)} 0 0,1 ${L(-n)},0Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(9,r/6);return`M${L(e)},${L(t+i)}a${L(n/2)},${L(i)} 0 0,0 ${L(n)},0`},port:(e,t,n)=>zn(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}=Ti(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${L(e+i)},${L(t)}L${L(e+n)},${L(t)}L${L(e+n-i)},${L(t+r)}L${L(e)},${L(t+r)}Z`}},{name:`document`,aliases:[`doc`],textOffset:-4,size:(e,t)=>{let{w:n,h:r}=Ti(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=Ai(e,t),s=Math.min(8,a/6);return`M${L(n+o)},${L(r)}L${L(n+i-o)},${L(r)}Q${L(n+i)},${L(r)} ${L(n+i)},${L(r+o)}L${L(n+i)},${L(r+a-s)}C${L(n+i*.75)},${L(r+a-s*3)} ${L(n+i*.25)},${L(r+a+s)} ${L(n)},${L(r+a-s)}L${L(n)},${L(r+o)}Q${L(n)},${L(r)} ${L(n+o)},${L(r)}Z`}},{name:`note`,aliases:[`sticky`],textCorners:`square`,size:(e,t)=>{let{w:n,h:r}=Ti(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${L(e)},${L(t)}L${L(e+n-i)},${L(t)}L${L(e+n)},${L(t+i)}L${L(e+n)},${L(t+r)}L${L(e)},${L(t+r)}Z`},detail:({x:e,y:t,w:n,h:r})=>{let i=Math.min(14,n/5,r/3);return`M${L(e+n-i)},${L(t)}L${L(e+n-i)},${L(t+i)}L${L(e+n)},${L(t+i)}`}},{name:`person`,textOffset:Oi/2,size:(e,t)=>{let{w:n,h:r}=Ti(e,t);return{w:Math.max(n,96),h:Math.max(r,48)+Oi}},path:(e,t)=>{let n=Oi/2-1,r=e.x+e.w/2,i={x:e.x,y:e.y+Oi,w:e.w,h:e.h-Oi};return Ln(i.x,i.y,i.w,i.h,Math.max(Ai(i,t),10))+`M${L(r-n)},${L(e.y+n)}a${L(n)},${L(n)} 0 1,0 ${L(28)},0a${L(n)},${L(n)} 0 1,0 ${L(-28)},0Z`},port:(e,t,n)=>t===`top`?{x:e.x+e.w/2+n*(Oi/2-4),y:e.y}:zn({x:e.x,y:e.y+Oi,w:e.w,h:e.h-Oi},t,n)},{name:`actor`,aliases:[`stickman`],textOffset:ki/2,size:(e,t)=>({w:Math.max(e+16,56),h:t+ki+12}),path:({x:e,y:t,w:n})=>{let r=e+n/2,i=t+16+2,a=i+22;return`M${L(r-8)},${L(t+8+1)}a${L(8)},${L(8)} 0 1,0 ${L(16)},0a${L(8)},${L(8)} 0 1,0 ${L(-16)},0ZM${L(r)},${L(i)}L${L(r)},${L(a)}M${L(r-15)},${L(i+8)}L${L(r+15)},${L(i+8)}M${L(r)},${L(a)}L${L(r-12)},${L(a+18)}M${L(r)},${L(a)}L${L(r+12)},${L(a+18)}`}},{name:`text`,aliases:[`label`,`plain`,`none`],textCorners:`none`,size:(e,t)=>({w:e+12,h:t+8}),path:(e,t)=>Ln(e.x,e.y,e.w,e.h,Ai(e,t))}]},Mi=(e,t)=>{let n=Math.cos(t),r=Math.sin(t);return(t,i)=>`${L(e.x+t*n-i*r)},${L(e.y+t*r+i*n)}`},Ni={name:`markers`,markers:[{name:`arrow`,inset:e=>e*.8,render(e,t,{color:n,width:r,size:i}){let a=Mi(e,t);return`<path d="M${a(0,0)}L${a(-i,i*.5)}Q${a(-i*.78,0)} ${a(-i,-i*.5)}Z" fill="${n}" stroke="${n}" stroke-width="${L(r*.5)}" stroke-linejoin="round"/>`}},{name:`open`,inset:(e,t)=>t*.8,render(e,t,{color:n,width:r,size:i}){let a=Mi(e,t);return`<path d="M${a(-i*.95,i*.55)}L${a(0,0)}L${a(-i*.95,-i*.55)}" fill="none" stroke="${n}" stroke-width="${L(r)}" stroke-linecap="round" stroke-linejoin="round"/>`}},{name:`dot`,inset:e=>e*.7,render(e,t,{color:n,size:r}){let i=r*.36,[a,o]=Mi(e,t)(-i,0).split(`,`);return`<circle cx="${a}" cy="${o}" r="${L(i)}" fill="${n}"/>`}},{name:`diamond`,inset:e=>e*1.6,render(e,t,{color:n,size:r}){let i=Mi(e,t);return`<path d="M${i(0,0)}L${i(-r*.8,r*.45)}L${i(-r*1.6,0)}L${i(-r*.8,-r*.45)}Z" fill="${n}"/>`}},{name:`bar`,render(e,t,{color:n,width:r,size:i}){let a=Mi(e,t);return`<path d="M${a(-4,i*.6)}L${a(-4,-i*.6)}" stroke="${n}" stroke-width="${L(r*1.2)}" stroke-linecap="round"/>`}}]},Pi={name:`themes`,themes:[ge(`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)},ge(`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)},ge(`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)`}),ge(`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)}]},Fi=e=>e.split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));function Ii(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 Li=(e,t)=>R(e,t.theme,t.theme.accent),Ri=(e,t)=>t.match(RegExp(`^${e}(?:\\s+(${Se}))?:\\s*(.*)$`)),zi={kind:`bars`,syntax:`bars [color]: 3 5 4 8 6`,parse(e){let t=Ri(`bars`,e);return t?{kind:`bars`,values:Fi(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(Ii(e.values)[1],0)||1,a=t.y+t.h-r*.35,o=t.h-r*.7,s=Li(e.color,n);return e.values.map((e,n)=>{let c=Math.max(1.5,Math.max(0,e)/i*o);return`<rect x="${L(t.x+n*r*.85)}" y="${L(a-c)}" width="${L(r*.55)}" height="${L(c)}" rx="1.5" fill="${s}"/>`}).join(``)}},Bi={kind:`spark`,syntax:`spark [color]: 3 5 4 8 6`,parse(e){let t=Ri(`spark`,e);return t?{kind:`spark`,values:Fi(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]=Ii(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`}${L(e)},${L(t)}`).join(``),p=Li(e.color,n),[m,h]=d[d.length-1];return`<path d="${f}L${L(t.x+t.w)},${L(l)}L${L(t.x)},${L(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="${L(m)}" cy="${L(h)}" r="2.6" fill="${p}"/>`}},Vi={kind:`progress`,syntax:`progress [color]: 72% Label`,parse(e){let t=Ri(`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:F(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:F(n[4]),color:t[1]}},measure:(e,{fs:t,lh:n,mono:r,measure:i})=>({w:z(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=Li(e.color,n);return et(e.label,t.x,s,r,a,o)+Ye(t.x+t.w,s,r,a.sub,I(e.value),` text-anchor="end" font-weight="600"`)+`<rect x="${L(t.x)}" y="${L(c)}" width="${L(t.w)}" height="${L(l)}" rx="${L(l/2)}" fill="${a.stroke}" fill-opacity="0.45"/>`+(e.ratio>0?`<rect x="${L(t.x)}" y="${L(c)}" width="${L(Math.max(l,t.w*e.ratio))}" height="${L(l)}" rx="${L(l/2)}" fill="${u}"/>`:``)}},Hi=1.75,Ui={name:`charts`,rows:[zi,Bi,Vi,{kind:`stat`,syntax:`stat [color]: 99.9% uptime | 42ms p95`,parse(e){let t=Ri(`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:F(t),label:F(n.join(` `))}}),color:t[1]}:null},measure(e,{fs:t,mono:n,measure:r}){let i=t*Hi;return e.ws=e.items.map(e=>Math.max(z(e.value,i,n,r,700),z(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*Hi,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:Li(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${L(e)},${L(t.y+r*.3)}V${L(t.y+t.h-r*.3)}" stroke="${i.stroke}" stroke-width="1"/>`)}u.push(et(e.value,f,t.y+o*.62,o,d,a,!1,700)),u.push(et(e.label,f,t.y+o*1.25+r*.6,r*.9,i,a,!0)),f+=c[n]+l}),u.join(``)}}]},Wi=/^[-+~±]?[\d.,]+\s?(%|ms|s|m|h|d|k|kb|mb|gb|x|\/s)?$|^[-–—]$/i;function Gi(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 Ki=e=>e*1.8,qi={name:`tables`,rows:[{kind:`table`,syntax:`| a | b |`,parse(e,t){if(!e.startsWith(`|`))return null;let n=Gi(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(F);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=>!Ke(e[t])||Wi.test(Ke(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=>z(e[a],t,r,i)))),{w:e.cols.reduce((e,t)=>e+t,0)+Ki(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]-Qe(t):d;o.push(et(t,c,u,n,i,a,e.header&&l===0)),d+=s[r]+Ki(n)})}),e.header){let e=t.y+r+n*.25;o.push(`<path d="M${L(t.x)},${L(e)}H${L(t.x+t.w)}" stroke="${i.stroke}" stroke-width="1"/>`)}return o.join(``)}}]},Ji=[`#ff5f57`,`#febc2e`,`#28c840`],Yi=e=>Math.round(e*2.3);function Xi(e,t,n,r,i){let a=Yi(t),o=Math.min(n,a/2,e.w/2),s=`M${L(e.x)},${L(e.y+a)}V${L(e.y+o)}A${L(o)},${L(o)} 0 0 1 ${L(e.x+o)},${L(e.y)}H${L(e.x+e.w-o)}A${L(o)},${L(o)} 0 0 1 ${L(e.x+e.w)},${L(e.y+o)}V${L(e.y+a)}Z`,c=t*.3,l=Ji.map((n,r)=>`<circle cx="${L(e.x+t+r*c*3.3)}" cy="${L(e.y+a/2)}" r="${L(c)}" fill="${n}"/>`).join(``);return`<path d="${s}" fill="${r}" fill-opacity="${i?.35:.3}"/><path d="M${L(e.x)},${L(e.y+a)}H${L(e.x+e.w)}" stroke="${r}" stroke-width="1"/>`+l}var Zi=(e,t)=>e.x+t+t*.3*6.6+t*.3+t*.9,Qi={name:`browser`,inset:e=>({top:Yi(e)}),render(e,{theme:t,col:n,arg:r,radius:i,fs:a}){let o=Yi(a),s=Zi(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="${L(s)}" y="${L(u)}" width="${L(c-s)}" height="${L(l)}" rx="${L(l/2)}" fill="${t.background===`none`?t.node.fill:t.background}" stroke="${n.stroke}" stroke-width="1"/>`+(r?Ye(s+a*.7,e.y+o/2,d,n.sub,I(r)):``):``;return`<g class="frame">${Xi(e,a,i,n.stroke,t.dark)}${f}</g>`}},$i=(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?Ye(e.x+e.w/2,e.y+s/2,o*.78,r.sub,I(t+i),` text-anchor="middle" font-weight="500"`):``;return`<g class="frame">${Xi(e,o,a,r.stroke,n.dark)}${c}</g>`}}),ea={name:`frames`,frames:[Qi,$i(`window`,``),$i(`terminal`,`❯ `)],props:{node:[`frame`]}},ta=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean),na=new Map,ra=(e,t,n)=>`${t}|${n}|${e}`;function ia(e,t,n,r){return e.map(e=>z(F(e),t,n,r))}var aa={name:`footer`,decorations:[{name:`footer`,setting:`footer`,measure(e,t,n){let r=ta(e);if(!r.length)return null;let i=t.fontSize*.82,a=ia(r,i,t.mono,n);na.size>64&&na.clear(),na.set(ra(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=ta(e),a=n.fontSize*.82,o=t.y+t.h*.55,s=P(n),c=t.x+r,l=t.x+t.w-r,u=[`<path d="M${L(c)},${L(t.y)}H${L(l)}" stroke="${n.group.stroke}" stroke-width="1"/>`],d=na.get(ra(e,a,n.mono))??ia(i,a,n.mono,_i),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="${L(m)}" y="${L(o)}" dominant-baseline="central" font-size="${L(a)}" xml:space="preserve">${B(F(e),s,n,!0)}</text>`),m+=d[t]+p}),`<g class="footer">${u.join(``)}</g>`}}]},oa=/^(<->|==>|=>|-->|\.\.>|->|--)$/;function sa(e){return e.split(`|`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,...n]=e.split(/\s+/),r=n.join(` `);return oa.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 ca=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 la(e,t,n){let{fs:r,sw:i,gap:a}=ca(t);return e.map(e=>i+a+z(F(e.label),r,t.mono,n))}function ua(e,t,n,r,i){let{sw:a,sh:o}=ca(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="${L(o*3)} ${L(o*2.5)}"`:e.key.startsWith(`..`)?` stroke-dasharray="${L(o)} ${L(o*2)}"`:``,c=e.key.endsWith(`>`),l=5+o*1.5,u=t+a;return`<path d="M${L(t)},${L(n)}H${L(u-(c?l*.6:0))}" stroke="${i}" stroke-width="${L(o)}"${s} fill="none"/>`+(c?`<path d="M${L(u)},${L(n)}L${L(u-l)},${L(n-l*.5)}L${L(u-l)},${L(n+l*.5)}Z" fill="${i}"/>`:``)+(e.key.startsWith(`<`)?`<path d="M${L(t)},${L(n)}L${L(t+l)},${L(n-l*.5)}L${L(t+l)},${L(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=pt(i,t),a=vt(i,t,n,r),o=jn(n.shape??i.settings.shape);return`<path d="${Fn(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="${L(s.x)}" y="${L(s.y)}" width="${L(s.w)}" height="${L(s.h)}" rx="3" fill="${l}" stroke="${u}" stroke-width="1.2"/>`}function da(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 fa=760,pa={name:`legend`,decorations:[{name:`legend`,setting:`legend`,measure(e,t){let n=sa(e);if(!n.length)return null;let{fs:r,space:i}=ca(t),a=la(n,t,_i),o=a.reduce((e,t)=>e+t,0)+i*(a.length-1),s=da(a,fa,i).length;return{bottom:r*1.4+s*r*1.9,w:Math.min(o,fa)}},render(e,t,n,{pad:r,d:i}){let a=sa(e),{fs:o,gap:s,space:c,sw:l}=ca(n),u=la(a,n,_i),d=P(n),f=[];return da(u,Math.min(fa,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(ua(e,m,h,n,i)),e.label&&f.push(`<text x="${L(m+l+s)}" y="${L(h)}" dominant-baseline="central" font-size="${L(o)}" xml:space="preserve">${B(F(e.label),d,n,!0)}</text>`),m+=u[t]+c}}),`<g class="legend">${f.join(``)}</g>`}}]},ma=String.raw`[\p{L}_](?:[\p{L}\p{N}_-]*[\p{L}\p{N}_])?`,ha=/^(?:m|note|d)\d+$/,ga=new RegExp(String.raw`^(${ma})\s*(-->|->|\.\.>|=>)\s*(${ma})\s*(?::\s*(.*))?$`,`u`),_a=new RegExp(String.raw`^(${ma}\s*(?:-->|->|\.\.>|=>)\s*${ma})\s*\[([^\]]*)\]\s*(?::\s*(.*))?$`,`u`),va=String.raw`${ma}(?:\s+"[^"]*")?(?:\s*\[[^\]]*\])?`,ya=new RegExp(String.raw`^(participant|actor)\s+(${va}(?:\s*,\s*${va})*)$`,`u`),ba=new RegExp(String.raw`(${ma})(?:\s+"([^"]*)")?(?:\s*\[([^\]]*)\])?`,`gu`),xa=new RegExp(String.raw`^note\s+(${ma}(?:\s*,\s*${ma})*)\s*:\s*(.*)$`,`u`),Sa=/^(?:-{3,}|={2,})\s*(.*?)\s*(?:-{3,}|={2,})?$/,Ca=[`color`,`width`,`style`,`dashed`,`dotted`,`thick`,`head`],wa=e=>{let t=Object.keys(e);return t.length>0&&t.every(e=>Ca.includes(e))&&(!e.color||xe(e.color))},Ta=e=>Vr(e,wa),Ea={"->":`solid`,"-->":`dashed`,"..>":`dotted`,"=>":`thick`};function Da(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(ya)){let e=[...c[2].matchAll(ba)];for(let[,t,n,r]of e){let i=o(t);i.actor=c[1]===`actor`,e.length===1?i.decl=a:i.list??=a,n!==void 0&&(i.label=n);let s=r&&V(r).color;s&&(i.tone=s)}}else if(c=r.match(xa)){let e=c[1].split(`,`).map(e=>e.trim());e.forEach(o);let[t,n]=Ta(c[2]);i.push({kind:`note`,over:e,text:t,tone:n.color,at:a})}else if(c=r.match(ga)){o(c[1]),o(c[3]);let[e,t]=Ta(c[4]??``),{color:n,...r}=t;i.push({kind:`msg`,from:c[1],to:c[3],text:e.trim().replace(/^"(.*)"$/,`$1`),line:Ea[c[2]],n:++s,tone:n,props:r,at:a})}else(c=r.match(Sa))?i.push({kind:`divider`,text:c[1]}):(c=r.match(_a))?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(!ha.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 Oa(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 ka=ei(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=>z(F(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=Oa(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 Aa(e,t){let n=_t(e,t);return n?` stroke-dasharray="${n}"${e===`dotted`?` stroke-linecap="round"`:``}`:``}function ja(e,t,n){if(!e.parts.length)return``;let r=n.theme,i=ka(e,n),{fs:a,boxH:o,xs:s}=i,c=e=>t.x+s[e],l=r.edge.ink,u=P(r),d=n.props,f=N(d.lifeline,r,r.dark?600:300)??r.node.stroke,p=Aa(nt(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${L(c(t))},${L(h+o)}V${L(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="${L(c(a)-l/2)}" y="${L(t)}" width="${L(l)}" height="${L(o)}" rx="${L(u)}" fill="${s?.fill??r.node.fill}" stroke="${s?.stroke??r.node.stroke}" stroke-width="${L(r.strokeWidth)}"/><text x="${L(c(a))}" y="${L(t+o/2)}" dominant-baseline="central" text-anchor="middle" font-size="${L(n.fs)}" font-weight="600" fill="${s?.text??r.node.text}">${I(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=nt(n,`style`)??(o.line===`thick`?`solid`:o.line),d=tt(n.width,o.line===`thick`||M(n.thick,!1)?r.edgeWidth*2:r.edgeWidth),f=Aa(s,d),p=n.head??(o.line===`dashed`?`open`:`arrow`),h=F(i.num(o)+o.text),g=R(o.tone,r,l),_=o.tone?{...u,text:g}:u;if(e===t){let t=c(e),n=v+a*1.6,i=n+a*1.3;m.push(`<path d="M${L(t)},${L(n)}H${L(t+26-8)}Q${L(t+26)},${L(n)} ${L(t+26)},${L(n+8)}V${L(i-8)}Q${L(t+26)},${L(i)} ${L(t+26-8)},${L(i)}H${L(t+2)}" fill="none" stroke="${g}" stroke-width="${L(d)}"${f}/>`),m.push(On({x:t+1,y:i},Math.PI,p,g,d,5+d*1.4)),m.push(`<text x="${L(t+34)}" y="${L((n+i)/2)}" dominant-baseline="central" font-size="${L(a)}" xml:space="preserve">${B(h,_,r)}</text>`)}else{let n=Math.sign(t-e),s=v+a*1.85;m.push(`<path d="M${L(c(e))},${L(s)}H${L(c(t)-n*2)}" stroke="${g}" stroke-width="${L(d)}"${f}/>`),m.push(On({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="${L((c(e)+c(t))/2)}" y="${L(s-a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" xml:space="preserve">${B(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="${L(l)}" y="${L(p)}" width="${L(u-l)}" height="${L(f)}" rx="4" fill="${d.fill}" stroke="${d.stroke}" stroke-width="1"/>`),m.push(`<text x="${L((l+u)/2)}" y="${L(p+f/2)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" xml:space="preserve">${B(F(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${L(t.x)},${L(n)}H${L(t.x+t.w)}" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="4 4"/>`),s&&(m.push(`<rect x="${L(c-s/2)}" y="${L(n-a*.85)}" width="${L(s)}" height="${L(a*1.7)}" rx="${L(a*.85)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${r.group.stroke}" stroke-width="1"/>`),m.push(`<text x="${L(c)}" y="${L(n)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.92)}" font-weight="600" fill="${r.node.sub}">${I(o.text)}</text>`))}v+=e}return m.join(``)}function Ma(e,t,n){if(!e.parts.length)return[];let r=ka(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}function Na(e,t){let n=t.ascii?Ci:Si,r=e=>n.join[e]??`+`,i=e=>[...e].length,a=e=>wi(e.label),o=new Map(e.parts.map((e,t)=>[e.id,t])),s=e.parts.map(e=>Math.ceil((i(a(e))+4)/2)),c=[];e.parts.forEach((e,t)=>{c[t]=t?c[t-1]+s[t-1]+s[t]+2:s[0]});for(let t=0;t<2;t++)for(let t of e.steps){if(t.kind!==`msg`)continue;let e=o.get(t.from),n=o.get(t.to),r=Math.min(e,n),a=Math.max(e,n),s=i(wi(t.text)),l=r===a?a+1<c.length?a+1:-1:a;if(l<0)continue;let u=r===a?s+6:s+4,d=c[r]+u-c[l];if(d>0)for(let e=l;e<c.length;e++)c[e]+=d}let l=c[c.length-1]+s[s.length-1]+40,u=()=>Array(l).fill(` `),d=()=>{let e=u();return c.forEach(t=>e[t]=n.v),e},f=(e,t,n)=>[...n].forEach((n,r)=>e[t+r]=n),p=[],[m,h,g,_]=[...n.round],v=[u(),u(),u()];e.parts.forEach((e,t)=>{let o=a(e),l=c[t]-s[t],u=c[t]+s[t];f(v[0],l,m+n.h.repeat(u-l-1)+h),f(v[1],l,n.v),f(v[1],u,n.v),f(v[1],c[t]-Math.floor(i(o)/2),o),f(v[2],l,g+n.h.repeat(u-l-1)+_),v[2][c[t]]=r(14)}),p.push(...v);for(let t of e.steps){if(t.kind===`divider`){let e=u(),r=` ${wi(t.text)} `,a=c[c.length-1]+s[s.length-1];f(e,0,n.dashH.repeat(a+1)),f(e,Math.max(0,Math.floor((a-i(r))/2)),r),p.push(e);continue}if(t.kind===`note`){let e=d(),n=t.over.map(e=>c[o.get(e)??0]),r=`[ ${wi(t.text)} ]`,a=Math.round((Math.min(...n)+Math.max(...n))/2);f(e,Math.max(0,a-Math.floor(i(r)/2)),r),p.push(e);continue}let e=o.get(t.from),a=o.get(t.to),l=wi(t.text),m=t.line===`thick`?n.thickH:t.line===`solid`?n.h:n.dashH,h=d(),g=d();if(e===a){let t=c[e];f(h,t+1,m.repeat(2)+r(12)+` `+l),f(g,t+1,n.head.right+m+r(9)),p.push(h,g);continue}let _=c[Math.min(e,a)],v=c[Math.max(e,a)];f(h,Math.round((_+v)/2)-Math.floor(i(l)/2),l);let y=e<a?m.repeat(v-_-2)+n.head.left:n.head.right+m.repeat(v-_-2);f(g,_+1,y),p.push(h,g)}return p.push(d()),p.map(e=>e.join(``).replace(/\s+$/,``))}var Pa={name:`sequence`,panels:[{name:`sequence`,aliases:{sequenceDiagram:``},guide:'`participant|actor id "Label" [color]` (`participant a "A", b, c` lists several and fixes the order), `a -> b: msg` (`-->` reply, `..>` dotted, `=>` thick, `a -> a` self call), `note a, b: text`, `--- section ---`. A message takes edge props at its end: `a -> b: retry [red, style: dotted]`.',layoutParts:"a participant id (`p-<id>` when the id looks like a row) moves its lifeline and the ones after it; `m<n>` (message), `note<n>`, `d<n>` (divider) add room above that row",syntax:`sequence id "Title" [numbered] { a -> b: message }`,parse:Da,measure(e,t){let n=ka(e,t);return{w:n.w,h:e.parts.length?n.h:0}},render:ja,handles:Ma,options:{numbered:`flag`,lifeline:`color`,"lifeline-style":[`dashed`,`dotted`,`solid`]},parts(e){let t=Oa(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:ti((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]=Hr(e[a.decl],`color`,n),i;if(n===null)return i;let t=`${a.actor?`actor`:`participant`} ${a.id} [${Gr({color:n})}]`;return a.list===void 0?i.splice(a.first,0,t):i.splice(a.list+1,0,t),i}let o=Oa(r).indexOf(t),s=r.steps[o];if(!s||s.kind===`divider`)return null;let[c,l]=Ta(e[s.at]),u=c;delete l.color;let d=Gr(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}),text:Na}]},Fa=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],Ia=[`blue`,`green`,`amber`,`purple`,`pink`,`teal`,`orange`,`indigo`,`cyan`,`red`,`lime`],La=/^[-*+]\s+/;function Ra(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 za=e=>e.toLowerCase().replace(/[*~`{}[\]]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``);function Ba(e,t,n,r){let i=za(e);return(!i||t.has(i)||r.test(i))&&(i=n),t.add(i),i}function Va(e,t,n=1){let r=``,i=n,a=e.length-1;for(;i<=a;){let n=i+a>>1,o=e.slice(0,n).trimEnd()+`…`;t(o)?(r=o,i=n+1):a=n-1}return r}function Ha(e,t){let n=t;for(let t of e)t>n&&(n=t);return n}var Ua=e=>/^(\/\/|#|%%)/.test(e.trimStart()),Wa=(e,t)=>e??Fa[t%Fa.length],Ga=e=>e.match(/^\s*/)[0].replace(/\t/g,` `).length;function Ka(e=0){let t=[];return{parent(n){for(;t.length>e&&t[t.length-1].indent>=n;)t.pop();return t[t.length-1]?.node},push(e,n){t.push({indent:e,node:n})},enter(e,n){return this.parent(e),t.push({indent:e,node:n}),t.length-1},get depth(){return t.length},cut(e){return t.length=e,t[e-1]?.node}}}var qa=(e,t,n=t[0])=>t.includes(e)?e:n,Ja=(e,t=2)=>Number(e.toFixed(t)),Ya=[[1e12,`T`],[1e9,`B`],[1e6,`M`],[1e3,`k`]];function Xa(e,t={}){let{format:n=`plain`,decimals:r,total:i=0,unit:a=``}=t,o;if(n===`percent`)o=`${i?r===void 0?Ja(e/i*100,1):(e/i*100).toFixed(r):0}%`;else if(n===`compact`){let t=Ya.find(([t])=>Math.abs(e)>=t),n=t?e/t[0]:e;o=(r===void 0?String(Ja(n,1)):n.toFixed(r))+(t?.[1]??``)}else o=Math.abs(e)>=1e15?String(e):n===`thousands`?(r===void 0?Ja(e):Number(e.toFixed(r))).toLocaleString(`en-US`,{minimumFractionDigits:r??0,maximumFractionDigits:r??2}):r===void 0?String(Ja(e)):e.toFixed(r);return/^[$€£¥₹₩]$/.test(a)?`${a}${o}`:`${o}${a}`}var Za=/^(.+?)(?:\s*\[([^\]]+)\])?:\s+(.*)$/,Qa=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(:\s+.*)$/;function $a(e,t,n){let r=[];return e.forEach((e,t)=>{let i=e.trim();if(!i||Ua(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]=Vr(i,Ur),c=o.match(Za);c?r.push({when:c[1].trim(),tone:s.color??V(c[2]).color,title:c[3],details:[]}):n(t,`timeline: cannot read "${i}" (expected "when: title" or "- detail")`)}),r}function eo(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 to(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!Ua(r)&&!/^[-*]\s/.test(r)&&Za.test(Vr(r,Ur)[0])&&t.push(n)}),t}var no=ei(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)=>z(F(e),t,n.mono,r,i),c=e.map(e=>r(e.when,a*.9,600,n.mono)),l=e.map(e=>Ha(e.details.map(e=>s(e,a*.92)),s(e.title,a,600))),u=e.map(e=>1+e.details.length),d=eo(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=Ha(c,0)+18;return{fs:a,vertical:o,left:e,at:m,parts:d,w:e+22+Ha(l,0),h:h+a*.6}}return{fs:a,vertical:o,left:0,at:m,parts:d,w:h,h:a*3.4+Ha(u,1)*a*1.45}});function ro(e,t,n){if(!e.length)return``;let r=n.theme,i=no(e,n),{fs:a}=i,o=P(r),s=r.group.stroke,c=[],l=(e,t,n)=>{let i=R(n.tone,r,r.accent);return`<circle cx="${L(e)}" cy="${L(t)}" r="${L(a*.42)}" fill="${r.background===`none`?r.node.fill:r.background}" stroke="${i}" stroke-width="2.5"/><circle cx="${L(e)}" cy="${L(t)}" r="${L(a*.18)}" fill="${i}"/>`},u=(e,t,n,i,a,s,c)=>`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central" text-anchor="${s}" font-size="${L(i)}"${a===400?``:` font-weight="${a}"`} xml:space="preserve">${B(F(n),o,r,c)}</text>`;if(i.vertical){let n=t.x+i.left;return c.push(`<path d="M${L(n)},${L(t.y+a*.5)}V${L(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="${L(n-16)}" y="${L(s)}" dominant-baseline="central" text-anchor="end" font-size="${L(a*.9)}" font-weight="600" fill="${R(e.tone,r,r.node.sub)}">${I(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${L(t.x)},${L(d)}H${L(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="${L(o)}" y="${L(t.y+a*.5)}" dominant-baseline="central" font-size="${L(a*.9)}" font-weight="600" fill="${R(e.tone,r,r.node.sub)}">${I(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 io={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:$a,measure(e,t){if(!e.length)return{w:0,h:0};let n=no(e,t);return{w:n.w,h:n.h}},render:ro,parts:e=>eo(e).map((t,n)=>({id:t,label:`${e[n].when}: ${e[n].title}`,kind:`event`,tone:e[n].tone})),editPart:ti((e,t,n,r)=>{let i=to(e)[eo(r).indexOf(t)];if(i===void 0)return null;let a=[...e];return a[i]=Wr(e[i],Qa,`color`,n,Ur),a}),handles(e,t,n){if(!e.length)return[];let r=no(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}`})}}]},ao=[`bar`,`column`,`line`,`pie`,`donut`,`radar`],oo=String.raw`-?\d+(?:\.\d+)?`,so=new RegExp(String.raw`^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(${oo}(?:\s*,\s*${oo})*)\s*$`),co=/^axes\s*:\s*(.*)$/i,lo=[`circle`,`polygon`],uo=[`right`,`bottom`,`none`],fo=[`min`,`max`,`ticks`,`grid`,`legend`],po=/^(.+?)(?:\s*\[([^\]]+)\])?\s*:\s*(-?\d+(?:\.\d+)?)\s*%?$/,mo=/^(\s*.+?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,ho=1e300;function go(e,t,n){let r=t.type??`bar`;ao.includes(r)||n(-1,`chart: unknown type "${t.type}" (use ${ao.join(`, `)})`);let i=ao.includes(r)?r:`bar`;if(i===`radar`)return yo(e,n);for(let e of fo)t[e]!==void 0&&n(-1,`chart: "${e}" only applies to type: radar`);return _o(e,i,n)}function _o(e,t,n){let r=[];return e.forEach((e,t)=>{let i=e.trim();if(!i||Ua(i))return;let[a,o]=Vr(i,Ur),s=a.match(po),c=s?Number(s[3]):NaN;s&&!(Math.abs(c)<=ho)?n(t,`chart: "${s[3].slice(0,24)}…" is too large a number`):s?r.push({label:H(s[1]),tone:o.color??V(s[2]).color,value:c}):n(t,`chart: cannot read "${i}" (expected "label: number")`)}),{type:t,items:r}}function vo(e){return[...e.matchAll(/\s*("(?:[^"\\]|\\.)*"|[^,]+)\s*(?:,|$)/g)].map(e=>H(e[1]))}function yo(e,t){let n=[],r;e.forEach((e,i)=>{let a=e.trim();if(!a||Ua(a))return;let o=a.match(co);if(o){r=vo(o[1]).filter(Boolean);return}let[s,c]=Vr(a,Ur),l=s.match(so),u=l?l[3].split(`,`).map(Number):[];l?u.some(e=>!(Math.abs(e)<=ho))?t(i,`chart: "${a.slice(0,24)}…" has too large a number`):n.push({label:H(l[1]),tone:c.color??V(l[2]).color,values:u,line:i}):t(i,`chart: cannot read "${a}" (expected "axes: a, b, c" or "series: 1, 2, 3")`)});let i=r?.length??Ha(n.map(e=>e.values.length),0);!r&&n.length?t(-1,`chart: a radar chart needs an "axes: a, b, c" line naming its axes`):r&&r.length<3&&t(-1,`chart: a radar chart needs at least 3 axes, got ${r.length}`);for(let e of n)r&&e.values.length!==i&&t(e.line,`chart: "${e.label}" has ${e.values.length} values for ${i} axes`),e.values=Array.from({length:i},(t,n)=>e.values[n]??0);return{type:`radar`,items:n,axes:r??Array.from({length:i},(e,t)=>String(t+1))}}function bo(e){if(!(e>0))return 1;let t=10**Math.floor(Math.log10(e));return([1,2,2.5,5,10].find(n=>n*t>=e-1e-9)??10)*t}function xo(e,t,n,r){return e.tone?R(e.tone,n.theme,n.theme.accent):r?m(Wa(void 0,t),n.theme.dark?400:500):n.theme.accent}function So(e,t,n,r){let{theme:i,measure:a,props:o}=t,s=e.axes,c=Math.max(t.fs*3,t.fs*8+Math.min(r.x,r.y)/2),l=Ha(s.map(e=>a(e,n,600,i.mono)),0)+n*.9,u=n*1.7,d=qa(o.legend,uo,`right`),f=d!==`none`&&e.items.length>0,p=Ha(e.items.map(e=>a(e.label,n,400,i.mono)),0),m=(c+l)*2,h=(c+u)*2,g=e.items.flatMap(e=>e.values),_=Number.isFinite(parseFloat(o.min))?parseFloat(o.min):g.reduce((e,t)=>Math.min(e,t),0),v=Ha(g,_),y=Number.isFinite(parseFloat(o.max))?parseFloat(o.max):_+bo(v-_),b=y>_?y:_+1,x=Math.min(20,Math.max(1,Math.round(parseFloat(o.ticks))||5)),S=n*1.6+p+n*1.4,C=f&&d===`right`,w=C?1:Math.max(1,Math.floor(m/S)),T=f?C?e.items.length:Math.ceil(e.items.length/w):0,E=T*n*1.75;return{fs:n,unit:o.unit??``,plotH:h,r:c,cx:l+c,cy:u+c+(C?Math.max(0,(E-h)/2):0),lo:_,hi:b,ticks:x,grid:qa(o.grid,lo),legend:f?d:`none`,itemW:S,perRow:w,w:C?m+n*1.2+n*1.6+p:m,h:C?Math.max(h,E):h+(T?n*.6+E:0)}}function Co(e,t,n,r){let{theme:i,measure:a,props:o}=t,s=o.unit??``,c=Ha(e.items.map(e=>a(e.label,n,400,i.mono)),0),l=Ha(e.items.map(e=>a(Xa(e.value,{unit:s}),n,600,i.mono)),0),u=e.items.reduce((e,t)=>e+Math.max(0,t.value),0),d=Math.max(1,e.items.length),f=Math.max(t.fs*2,t.fs*5.2+(r.x+r.y)/4),p=s===`%`?-10:a(`100%`,n,400,i.mono);switch(e.type){case`pie`:case`donut`:return{fs:n,unit:s,lw:c,vw:l,total:u,r:f,colW:0,plotH:0,w:f*2+28+n*1.6+c+14+l+10+p,h:Math.max(f*2,e.items.length*n*1.75)};case`bar`:{let i=Math.max(t.fs*3,t.fs*14+r.x),a=Math.max(n*1.4,n*2+r.y/d);return{fs:n,unit:s,lw:c,vw:l,total:u,r:f,colW:0,plotH:0,barMax:i,pitch:a,w:c+12+i+10+l,h:(e.items.length-1)*a+n*1.4}}default:{let i=Math.max(n*2.5,Math.max(n*3,c+12,l+12)+r.x/d),a=Math.max(t.fs*3,t.fs*9+r.y);return{fs:n,unit:s,lw:c,vw:l,total:u,r:f,colW:i,plotH:a,w:i*e.items.length,h:a+n*3.2}}}}function wo(e,t,n,r,i,a){let o=(n,r)=>`${L(e+n*Math.sin(r))},${L(t-n*Math.cos(r))}`,s=+(i-r>Math.PI);if(i-r>=Math.PI*2-1e-6){let o=r+Math.PI;return wo(e,t,n,r,o,a)+wo(e,t,n,o,i,a)}return a?`M${o(n,r)}A${L(n)},${L(n)} 0 ${s} 1 ${o(n,i)}L${o(a,i)}A${L(a)},${L(a)} 0 ${s} 0 ${o(a,r)}Z`:`M${L(e)},${L(t)}L${o(n,r)}A${L(n)},${L(n)} 0 ${s} 1 ${o(n,i)}Z`}var To=(e,t)=>(n,r,i,a=`start`,o=e.node.text,s=400,c=t)=>`<text x="${L(n)}" y="${L(r)}" dominant-baseline="central" text-anchor="${a}" font-size="${L(c)}"${s===400?``:` font-weight="${s}"`} fill="${o}">${I(i)}</text>`;function Eo(e,t,n,r,i){let a=n.theme,{fs:o,unit:s}=r,c=[],l=Ha(e.items.map(e=>e.value),0)||1;if(e.type===`pie`||e.type===`donut`){let l=t.x+r.r,u=t.y+r.h/2,d=e.type===`donut`?r.r*.6:0,f=a.background===`none`?a.node.fill:a.background,p=0;e.items.forEach((e,t)=>{let i=Math.max(0,e.value);if(!i||!r.total)return;let a=p+i/r.total*Math.PI*2;c.push(`<path d="${wo(l,u,r.r,p,a,d)}" fill="${xo(e,t,n,!0)}" stroke="${f}" stroke-width="2" stroke-linejoin="round"/>`),p=a}),d&&(c.push(i(l,u-o*.45,Xa(r.total,{unit:s}),`middle`,a.node.text,700,o*1.35)),c.push(i(l,u+o*.85,`total`,`middle`,a.node.sub,400,o*.85)));let m=t.x+r.r*2+28,h=e.items.length*o*1.75,g=t.y+(r.h-h)/2+o*.875;return e.items.forEach((e,l)=>{c.push(`<rect x="${L(m)}" y="${L(g-o*.45)}" width="${L(o*.9)}" height="${L(o*.9)}" rx="2.5" fill="${xo(e,l,n,!0)}"/>`),c.push(i(m+o*1.6,g,e.label)),c.push(i(m+o*1.6+r.lw+14+r.vw,g,Xa(e.value,{unit:s}),`end`,a.node.text,600)),r.total&&s!==`%`&&c.push(i(t.x+t.w,g,`${Math.round(Math.max(0,e.value)/r.total*100)}%`,`end`,a.node.sub)),g+=o*1.75}),c.join(``)}if(e.type===`bar`){let u=t.x+r.lw+12,{barMax:d,pitch:f}=r;return e.items.forEach((e,r)=>{let p=t.y+r*f+o*.7,m=Math.max(2,Math.max(0,e.value)/l*d);c.push(i(u-12,p,e.label,`end`,a.node.sub)),c.push(`<rect x="${L(u)}" y="${L(p-o*.55)}" width="${L(d)}" height="${L(o*1.1)}" rx="3" fill="${a.group.fill}"/>`),c.push(`<rect x="${L(u)}" y="${L(p-o*.55)}" width="${L(m)}" height="${L(o*1.1)}" rx="3" fill="${xo(e,r,n,!1)}"/>`),c.push(i(u+d+10,p,Xa(e.value,{unit:s}),`start`,a.node.text,600))}),c.join(``)}let u=t.y+o*1.6+r.plotH,d=e=>t.x+r.colW*(e+.5),f=e=>u-Math.max(0,e)/l*r.plotH;for(let e=1;e<=3;e++){let n=u-r.plotH*e/4;c.push(`<path d="M${L(t.x)},${L(n)}H${L(t.x+t.w)}" stroke="${a.group.stroke}" stroke-width="1" stroke-dasharray="2 4" opacity="0.8"/>`)}if(e.type===`column`){let t=Math.min(r.colW*.62,o*3.2);e.items.forEach((e,r)=>{let l=f(e.value);c.push(`<rect x="${L(d(r)-t/2)}" y="${L(l)}" width="${L(t)}" height="${L(Math.max(2,u-l))}" rx="3" fill="${xo(e,r,n,!1)}"/>`),c.push(i(d(r),l-o*.8,Xa(e.value,{unit:s}),`middle`,a.node.text,600))})}else{let t=e.items.map((e,t)=>`${L(d(t))},${L(f(e.value))}`);c.push(`<path d="M${L(d(0))},${L(u)}L${t.join(`L`)}L${L(d(e.items.length-1))},${L(u)}Z" fill="${a.accent}" opacity="0.12"/>`),c.push(`<path d="M${t.join(`L`)}" fill="none" stroke="${a.accent}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>`),e.items.forEach((e,t)=>{let r=xo(e,t,n,!1);c.push(`<circle cx="${L(d(t))}" cy="${L(f(e.value))}" r="${L(o*.32)}" fill="${a.background===`none`?a.node.fill:a.background}" stroke="${r}" stroke-width="2"/>`),c.push(i(d(t),f(e.value)-o*.95,Xa(e.value,{unit:s}),`middle`,a.node.text,600))})}return c.push(`<path d="M${L(t.x)},${L(u)}H${L(t.x+t.w)}" stroke="${a.node.stroke}" stroke-width="1"/>`),e.items.forEach((e,t)=>c.push(i(d(t),u+o*1.1,e.label,`middle`,a.node.sub))),c.join(``)}function Do(e,t,n,r,i){let a=n.theme,{fs:o,r:s}=r,c=e.axes,l=c.length,u=t.x+r.cx,d=t.y+r.cy,f=[],p=e=>-Math.PI/2+Math.PI*2*e/Math.max(1,l),m=(e,t)=>[u+t*Math.cos(p(e)),d+t*Math.sin(p(e))],h=e=>Math.min(1,Math.max(0,(e-r.lo)/(r.hi-r.lo)))*s,g=e=>r.grid===`polygon`&&l>=3?`<path d="M${c.map((t,n)=>m(n,e).map(L).join(`,`)).join(`L`)}Z"`:`<circle cx="${L(u)}" cy="${L(d)}" r="${L(e)}"`,_=a.background===`none`?a.node.fill:a.background,v=a.node.sub;f.push(`${g(s)} fill="${a.group.fill}" stroke="${v}" stroke-width="1.2" stroke-opacity="0.45"/>`);for(let e=1;e<r.ticks;e++)f.push(`${g(s*e/r.ticks)} fill="none" stroke="${v}" stroke-width="1" stroke-opacity="0.25"/>`);f.push(`<path d="${c.map((e,t)=>`M${L(u)},${L(d)}L${m(t,s).map(L).join(`,`)}`).join(``)}" stroke="${v}" stroke-width="1" stroke-opacity="0.3"/>`),c.forEach((e,t)=>{let[n,r]=m(t,s+o*.7),c=Math.cos(p(t)),l=Math.sin(p(t)),u=Math.abs(c)<.2?`middle`:c>0?`start`:`end`;f.push(i(n,r+l*o*.35,e,u,a.node.text,600))}),e.items.forEach((e,t)=>{let r=xo(e,t,n,!0),i=e.values.map((e,t)=>m(t,h(e)));if(i.length){f.push(`<path d="M${i.map(e=>e.map(L).join(`,`)).join(`L`)}Z" fill="${r}" fill-opacity="0.16" stroke="${r}" stroke-width="2" stroke-linejoin="round"/>`);for(let[e,t]of i)f.push(`<circle cx="${L(e)}" cy="${L(t)}" r="${L(o*.24)}" fill="${r}" stroke="${_}" stroke-width="1"/>`)}});for(let e=1;e<=r.ticks;e++){let t=r.lo+(r.hi-r.lo)*e/r.ticks;f.push(i(u+o*.3,d-s*e/r.ticks,Xa(t,{unit:r.unit}),`start`,a.node.sub,400,o*.75).replace(`<text `,`<text paint-order="stroke" stroke="${a.group.fill}" stroke-width="3" stroke-linejoin="round" `))}if(r.legend!==`none`){let a=r.legend===`right`,s=o*1.75,c=a?t.y+(r.h-e.items.length*s)/2:t.y+r.plotH+o*.6,l=Math.min(e.items.length,r.perRow)*r.itemW;e.items.forEach((e,u)=>{let d=a?0:u%r.perRow,p=a?u:Math.floor(u/r.perRow),m=a?t.x+r.cx*2+o*1.2:t.x+(t.w-l)/2+d*r.itemW,h=c+p*s+s/2;f.push(`<rect x="${L(m)}" y="${L(h-o*.45)}" width="${L(o*.9)}" height="${L(o*.9)}" rx="2.5" fill="${xo(e,u,n,!0)}"/>`),f.push(i(m+o*1.6,h,e.label))})}return f.join(``)}var Oo={isEmpty:e=>!e.items.length,geometry:Co,render:Eo},ko={isEmpty:e=>!e.items.length&&!e.axes.length,geometry:So,render:Do},Ao=e=>e.type===`radar`?ko:Oo,jo=ei((e,t)=>Ao(e).geometry(e,t,t.fs*.88,t.offsets.size??{x:0,y:0}));function Mo(e,t,n){let r=Ao(e);if(r.isEmpty(e))return``;let i=jo(e,n);return r.render(e,t,n,i,To(n.theme,i.fs))}var No={name:`chart`,panels:[{name:`chart`,aliases:{pie:`[type: pie]`,donut:`[type: donut]`,bar:``,line:`[type: line]`,xychart:``},guide:"`label [color]: number` per line; `unit` is appended to values. `type: radar` takes `axes: a, b, c` and one `series [color]: 1, 2, 3` line per series, a value per axis; `min`, `max`, `ticks`, `grid` and `legend` shape it.",layoutParts:"`size DX DY` grows the plot",syntax:`chart id "Title" [type: bar|column|line|pie|donut|radar, unit: %] { label: 42 }`,parse:go,measure(e,t){if(Ao(e).isEmpty(e))return{w:0,h:0};let n=jo(e,t);return{w:n.w,h:n.h}},render:Mo,options:{type:[...ao],unit:`text`,min:`number`,max:`number`,ticks:`number`,grid:[...lo],legend:[...uo]},help:{type:`the kind of chart`,unit:`appended to every value; a currency sign ($, €, £) goes in front`,min:`radar: the value at the centre (default 0)`,max:`radar: the value at the rim (default: the data, rounded up)`,ticks:`radar: how many grid rings (default 5)`,grid:`radar: circle or polygon rings`,legend:`radar: where the series legend goes`},parts:e=>e.items.map((e,t)=>({id:`i${t+1}`,label:e.label,kind:`item`,tone:e.tone})),editPart:ti((e,t,n)=>{let r=Number(t.slice(1))-1,i=e.flatMap((e,t)=>{let n=e.trim(),r=Vr(n,Ur)[0];return!Ua(n)&&!co.test(n)&&(po.test(r)||so.test(r))?[t]:[]})[r];if(!/^i\d+$/.test(t)||i===void 0)return null;let a=[...e];return a[i]=Wr(e[i],mo,`color`,n,Ur),a}),handles(e,t,n){if(Ao(e).isEmpty(e))return[];let r=jo(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize chart`}]}}]},Po=[`normal`,`highlight`,`reverse`],Fo=String.raw`[\p{L}\p{N}_][\p{L}\p{N}_./-]*`,Io=String.raw`(?:\s*\[([^\]]*)\])?`,Lo=new RegExp(String.raw`^commit(?:\s+(.*?))?${Io}$`,`u`),Ro=new RegExp(String.raw`^(?:branch|checkout\s+-b|switch\s+-c)\s+(${Fo})(?:\s+from\s+(\S+))?${Io}$`,`u`),zo=new RegExp(String.raw`^(?:checkout|switch)\s+(${Fo})$`,`u`),Bo=new RegExp(String.raw`^merge\s+(${Fo})(?:\s+(.*?))?${Io}$`,`u`),Vo=new RegExp(String.raw`^cherry-pick\s+(\S+?)(?:\s+(.*?))?${Io}$`,`u`),Ho=/^tag\s+(\S+)$/;function Uo(e){let t=V(e??``);for(let e of Po)t[e]===`true`&&(t.type=e,delete t[e]);return t}function Wo(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&&!Po.includes(o)&&(n(r,`git: unknown commit type "${o}" (use ${Po.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(Ro)){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=Uo(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(zo)){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(Bo)){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:H(u[2]??``)||`Merge ${e.name}`,parents:r,merge:!0},Uo(u[3]),t)}else if(u=l.match(Vo)){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:H(u[2]??``)||i[e].msg,parents:a.head>=0?[a.head]:[],merge:!1,pick:e},Uo(u[3]),t)}else(u=l.match(Ho))?a.head<0?n(t,`git: nothing to tag yet`):i[a.head].tags.push(u[1]):(u=l.match(Lo))?c({msg:H(u[1]??``),parents:a.head>=0?[a.head]:[],merge:!1},Uo(u[2]),t):n(t,`git: cannot read "${l}" (expected commit, branch, checkout, merge, cherry-pick or tag)`)}),{branches:r,commits:i}}function Go(e,t,n){let r=e.branches[t]?.tone;return r?R(r,n.theme,n.theme.accent):m(Fa[t%Fa.length],n.theme.dark?400:500)}function Ko(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 qo=ei(Jo);function Jo(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.86,o=i.direction===`down`,s=t.offsets,c=Ko(e),l=e=>s[e]?.x??0,u=e=>z(F(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 Yo=(e,t,n)=>t>n?(t+n)/2:Math.min(n,Math.max(t,e));function Xo(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${L(h.x)},${L(h.y)}L${L(g.x)},${L(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=Yo((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${L(h.x)},${L(h.y)}V${L(t-e)}C${L(h.x)},${L(t)} ${L(g.x)},${L(t)} ${L(g.x)},${L(t+e)}V${L(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=Yo((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${L(h.x)},${L(h.y)}H${L(S-x)}C${L(S)},${L(h.y)} ${L(S)},${L(g.y)} ${L(S+x)},${L(g.y)}H${L(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${L(i.x)},${L(i.y)}Q${L(e)},${L(n)} ${L(c.x)},${L(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${L(i.x)},${L(i.y)}C${L(p)},${L(i.y+u.y)} ${L(p)},${L(c.y+u.y)} ${L(c.x)},${L(c.y)}`})}),{lanes:u,bends:d,picks:f}}function Zo(e,t,n){if(!e.commits.length)return``;let r=n.theme,i=qo(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=P(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="${L(u)}" y="${L(t-d/2)}" width="${L(l)}" height="${L(d)}" rx="${L(d/2)}" fill="${o?r:s}" stroke="${r}" stroke-width="1.2"/><text x="${L(u+l/2)}" y="${L(t)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.82)}" font-weight="600" fill="${o?s:r}">${I(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="${L(t.x)}" y="${L(o)}" dominant-baseline="central" font-size="${L(a)}" font-weight="600" fill="${Go(e,r.lane,n)}">${I(r.label??r.name)}</text>`)}let f=Math.max(2,r.edgeWidth*1.4),p=Xo(e,i,t),m=(t,r)=>Go(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="${Go(e,e.commits[t.i].lane,n)}" stroke-width="${L(f*.7)}" stroke-dasharray="${L(f*1.6)} ${L(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="${L(f)}" stroke-linecap="round"${e.k?` opacity="0.85"`:``}/>`);return e.commits.forEach((p,m)=>{let{x:h,y:_}=u[m],v=R(p.tone,r,Go(e,p.lane,n));if(p.type===`highlight`){let e=o*1.1;l.push(`<rect x="${L(h-e)}" y="${L(_-e)}" width="${L(e*2)}" height="${L(e*2)}" rx="${L(e*.25)}" fill="${v}" stroke="${v}" stroke-width="${L(f)}"/>`)}else if(p.type===`reverse`){let e=o*.55;l.push(`<circle cx="${L(h)}" cy="${L(_)}" r="${L(o)}" fill="${s}" stroke="${v}" stroke-width="${L(f)}"/><path d="M${L(h-e)},${L(_-e)}L${L(h+e)},${L(_+e)}M${L(h+e)},${L(_-e)}L${L(h-e)},${L(_+e)}" stroke="${v}" stroke-width="${L(f*.8)}" stroke-linecap="round"/>`)}else p.merge?l.push(`<circle cx="${L(h)}" cy="${L(_)}" r="${L(o*1.05)}" fill="${v}"/><circle cx="${L(h)}" cy="${L(_)}" r="${L(o*.4)}" fill="${s}"/>`):p.pick===void 0?l.push(`<circle cx="${L(h)}" cy="${L(_)}" r="${L(o)}" fill="${s}" stroke="${v}" stroke-width="${L(f)}"/>`):l.push(`<circle cx="${L(h)}" cy="${L(_)}" r="${L(o)}" fill="${s}" stroke="${v}" stroke-width="${L(f)}" stroke-dasharray="${L(f*1.2)} ${L(f)}"/>`);if(i.vertical){let o=t.x+i.textX;p.id&&(l.push(`<text x="${L(o)}" y="${L(_)}" dominant-baseline="central" font-size="${L(a)}" font-family="${I(g)}" fill="${r.node.sub}">${I(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,Go(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="${L(o)}" y="${L(_)}" dominant-baseline="central" font-size="${L(a)}" xml:space="preserve">${B(F(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="${L(h)}" y="${L(_+a*1.45)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" stroke="${s}" stroke-width="7" stroke-linejoin="round" paint-order="stroke" xml:space="preserve">${B(F(p.msg),c,r,p.merge)}</text>`)}),l.join(``)}var Qo={name:`git`,panels:[{name:`git`,aliases:{gitGraph:``},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:Wo,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})),...Ko(e).map((t,n)=>({id:t,label:e.commits[n].msg||t,kind:`commit`,tone:e.commits[n].tone}))],editPart:ti((e,t,n,r)=>{let i=r.branches.find(e=>e.name===t)?.at??r.commits[Ko(r).indexOf(t)]?.at;if(i===void 0)return null;let a=[...e];return a[i]=Hr(e[i],`color`,n),a}),measure(e,t){if(!e.commits.length)return{w:0,h:0};let n=qo(e,t);return{w:n.w,h:n.h}},render:Zo,handles(e,t,n){if(!e.commits.length)return[];let r=qo(e,n),i=r.vertical?`y`:`x`,a=r.vertical?`x`:`y`,o=Xo(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`}))]}}]},$o=[`box`,`pill`,`plain`,`circle`],es=e=>ot(e)!==void 0,ts={color:xe,shape:()=>!0,text:xe,"font-size":es,"font-weight":es},ns=e=>{let t=Object.keys(e);return t.length>0&&t.every(t=>ts[t]?.(e[t]))},rs=e=>Vr(e,ns);function is(e,t,n){let r=null,i=0,a=Ka(1);return e.forEach((e,t)=>{let o=e.trim();if(!o)return;let s=Ga(e),[c,l]=rs(o.replace(La,``));l.shape&&!$o.includes(l.shape)&&n(t,`mindmap: unknown shape "${l.shape}" (use one of: ${$o.join(`, `)})`);let u={text:c.trim(),tone:l.color,shape:l.shape,ink:l.text,size:ot(l[`font-size`]),weight:ot(l[`font-weight`]),line:t,children:[]};if(!u.text)return n(t,`mindmap: a node needs some text`);r?(s<=i&&(n(t,`mindmap: "${u.text}" is not indented under the root "${r.text}"; a map has one root`),s=i+1),a.parent(s).children.push(u),a.push(s,u)):(r=u,i=s,a.push(s,u))}),r}var as=e=>e.reduce((e,t)=>Math.min(e,t),1/0),os=e=>e.reduce((e,t)=>Math.max(e,t),-1/0);function ss(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 cs=[`both`,`vertical`,`right`,`left`,`down`,`up`,`radial`],ls=ei(function(e,t){let{theme:n,measure:r,props:i}=t,a=ot(i[`font-size`])??t.fs*.9,o=qa(i.layout,cs),s=o===`radial`,c=o===`down`||o===`up`||o===`vertical`,l=i.colors===`mono`,u=Ra(e),d=ss(u),f=new Map(u.map((e,t)=>[e,d[t]])),p=new Map,m=(e,t,i,o)=>{let s=$o.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=z(F(e.text),c,n.mono,r,l),d=s===`plain`?{x:a*.15,y:a*.3}:{x:c*(t?.8:1.1),y:c*.5},m=u+d.x*2,h=c*1.25+d.y*2;s===`circle`&&(m=h=Math.max(m,h));let g={node:e,part:f.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 p.set(e,g),g};m(e,0,e.tone);for(let e of u){let t=p.get(e);e.children.forEach((e,n)=>m(e,t.depth+1,e.tone??(t.depth===0?l?void 0:Ia[n%Ia.length]:t.color),t))}if(s)return us(u.map(e=>p.get(e)),e=>e.node.children.map(e=>p.get(e)),a);let h=e=>c?a*.8:e<=1?a*.9:a*.35,g=(e,n,r)=>n?Math.max(-h(r)*.75,t.offsets[f.get(e)]?.x??0):0,_=e=>c?e.w:e.h,v=new Map,y=(e,t)=>{let n=p.get(e),r=0;return t.forEach((e,t)=>{r+=v.get(e)+(t?h(n.depth):0)+g(e,t,n.depth)}),Math.max(_(n),r)};for(let e=u.length-1;e>=0;e--)v.set(u[e],y(u[e],u[e].children));let b=e.children,x=b,S=[];if((o===`both`||o===`vertical`)&&b.length>1){let e=b.reduce((e,t)=>e+v.get(t),0),t=0,n=1,r=1/0;for(let i=1;i<b.length;i++){t+=v.get(b[i-1]);let a=Math.abs(e-2*t);a<r&&([r,n]=[a,i])}x=b.slice(0,n),S=b.slice(n)}let C=o===`left`||o===`up`||o===`vertical`?-1:1,w=e=>c?a*1.9:e===0?a*2.6:a*1.7,T=[],E=(e,t,n)=>{let r=y(e.node,t),i=(c?e.x+e.w/2:e.y+e.h/2)-r/2;t.forEach((t,r)=>{i+=(r?h(e.depth):0)+g(t,r,e.depth);let a=p.get(t),o=v.get(t);a.side=n,c?(a.x=i+o/2-a.w/2,a.y=n>0?e.y+e.h+w(e.depth):e.y-w(e.depth)-a.h):(a.y=i+o/2-a.h/2,a.x=n>0?e.x+e.w+w(e.depth):e.x-w(e.depth)-a.w),i+=o,T.push([a,t.children,n])})},D=p.get(e);for(T.push([D,x,C],[D,S,-C]);T.length;)E(...T.pop());let O=u.map(e=>p.get(e)),k=as(O.map(e=>e.x)),A=as(O.map(e=>e.y));for(let e of O)e.x-=k,e.y-=A;return{all:O,vert:c,radial:!1,w:os(O.map(e=>e.x+e.w)),h:os(O.map(e=>e.y+e.h))}});function us(e,t,n){let r=e[0],i=new Map;for(let n=e.length-1;n>=0;n--){let r=t(e[n]);i.set(e[n],r.length?r.reduce((e,t)=>e+i.get(t),0):1)}let a=new Map([[r,Math.PI*2]]);r.angle=-Math.PI/2;for(let n of e){let e=t(n),o=i.get(n),s=n===r?-Math.PI/2-Math.PI*2*i.get(e[0]??n)/o/2:n.angle-a.get(n)/2;for(let t of e){let e=a.get(n)*i.get(t)/o;a.set(t,e),t.angle=s+e/2,s+=e}}let o=e=>(Math.abs(Math.cos(e.angle))*e.w+Math.abs(Math.sin(e.angle))*e.h)/2,s=e=>Math.abs(Math.sin(e.angle))*e.w+Math.abs(Math.cos(e.angle))*e.h,c=os(e.map(e=>e.depth)),l=[0];for(let t=1;t<=c;t++){let i=e.filter(e=>e.depth===t-1),c=e.filter(e=>e.depth===t),u=t===1?Math.hypot(r.w,r.h)/2:os(i.map(o)),d=l[t-1]+u+os(c.map(o))+n*(t===1?2:1.4);for(let e of c){let t=Math.min(a.get(e),Math.PI);d=Math.max(d,(s(e)+n*.6)/(2*Math.sin(t/2)))}l.push(d)}for(let t of e){let e=l[t.depth];t.x=e*Math.cos(t.angle)-t.w/2,t.y=e*Math.sin(t.angle)-t.h/2,t.side=t.depth?Math.cos(t.angle)<0?-1:1:0}let u=as(e.map(e=>e.x)),d=as(e.map(e=>e.y));for(let t of e)t.x-=u,t.y-=d;return{all:e,vert:!1,radial:!0,w:os(e.map(e=>e.x+e.w)),h:os(e.map(e=>e.y+e.h))}}var ds=(e,t)=>R(t,e,e.accent);function fs(e,t,n){if(!e)return``;let r=n.theme,i=ls(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],u=(e,t,n)=>{let r=e.x+e.w/2,i=e.y+e.h/2;if(e.shape===`plain`)return n>i&&Math.abs(t-r)<e.w/2?[r,e.y+e.h]:[t<r?e.x:e.x+e.w,e.y+e.h];let a=t-r,o=n-i,s=Math.min(a?e.w/2/Math.abs(a):1/0,o?e.h/2/Math.abs(o):1/0);return[r+a*s,i+o*s]},d=e=>[e.x+e.w/2,e.y+e.h/2];for(let e of i.all){let t=ds(r,e.color);if(e.parent&&i.radial){let[n,r]=u(e.parent,...d(e)),[i,o]=u(e,...d(e.parent)),l=Math.hypot(i-n,o-r)*.45,f=e.parent.depth?e.parent.angle:e.angle,p=`M${L(s(n))},${L(c(r))}C${L(s(n+Math.cos(f)*l))},${L(c(r+Math.sin(f)*l))} ${L(s(i-Math.cos(e.angle)*l))},${L(c(o-Math.sin(e.angle)*l))} ${L(s(i))},${L(c(o))}`;a.push(`<path d="${p}" fill="none" stroke="${t}" stroke-width="${L(Math.max(1.4,3.6-e.depth*.7))}" stroke-linecap="round" opacity="0.9"/>`)}else 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${L(s(n))},${L(c(r))}C${L(s(n))},${L(c((r+u)/2))} ${L(s(o))},${L(c((r+u)/2))} ${L(s(o))},${L(c(u))}`:`M${L(s(n))},${L(c(r))}C${L(s((n+o)/2))},${L(c(r))} ${L(s((n+o)/2))},${L(c(u))} ${L(s(o))},${L(c(u))}`;a.push(`<path d="${f}" fill="none" stroke="${t}" stroke-width="${L(d)}" stroke-linecap="round" opacity="0.9"/>`)}let f=e.color?r.tone(e.color):void 0,p=e.depth===0&&!f?r.node.fill:f?.fill??r.node.fill,m=e.depth===0&&!f?r.accent:f?.stroke??r.node.stroke,h=N(e.node.ink,r,r.dark?100:800)??(e.shape===`plain`?r.node.text:f?.text??r.node.text),g=s(e.x),_=c(e.y);if(e.shape===`plain`)o.push(`<path d="M${L(g)},${L(_+e.h)}H${L(g+e.w)}" stroke="${t}" stroke-width="${L(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="${L(g)}" y="${L(_)}" width="${L(e.w)}" height="${L(e.h)}" rx="${L(t)}" fill="${p}" stroke="${m}" stroke-width="${e.depth===0?2.5:1.5}"/>`)}let v=e.shape===`plain`?_+e.h/2-n.fs*.05:_+e.h/2;o.push(`<text x="${L(g+e.w/2)}" y="${L(v)}" dominant-baseline="central" text-anchor="middle" font-size="${L(e.font)}"${e.weight===400?``:` font-weight="${e.weight}"`} xml:space="preserve">${B(F(e.node.text),P(r,h,m),r)}</text>`)}return a.join(``)+o.join(``)}var ps={name:`mindmap`,panels:[{name:`mindmap`,aliases:{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:cs,colors:[`branches`,`mono`]},parse:is,measure(e,t){if(!e)return{w:0,h:0};let n=ls(e,t);return{w:n.w,h:n.h}},render:fs,parts(e){if(!e)return[];let t=Ra(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 ss(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:ti((e,t,n,r)=>{if(!r)return null;let i=Ra(r),a=i[ss(i).indexOf(t)];if(!a)return null;let o=[...e],[s,{color:c,...l}]=rs(e[a.line]),u=Gr(n?{color:n,...l}:l);return o[a.line]=s.trimEnd()+(u?` [${u}]`:``),o}),handles(e,t,n){if(!e)return[];let r=ls(e,n),i=[];if(r.radial)return 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}}]},ms=864e5,hs=864e13,gs=1e3,_s=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],vs=/^([\w.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,ys=/^(\s*[\w.-]+(?:\s+"(?:[^"\\]|\\.)*")?)(?:\s*\[([^\]]*)\])?(\s*:.*)$/,bs=/^(?:-{3,}\s*(.*?)\s*-{3,}|section\s+(.+))$/;function xs(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 Ss(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(h|d|w)$/i);return t?+t[1]*{h:36e5,d:ms,w:7*ms}[t[2].toLowerCase()]:NaN}function Cs(e,t,n){let r=[],i=[],a=[],o=[];e.forEach((e,t)=>{let s=e.trim();if(!s||Ua(s))return;let c=s.match(bs);if(c){let e=(c[1]??c[2]).trim(),t=e.match(/^(.*?)\s*\[([^\]]*)\]$/);a.push(t?t[1]:e),o.push(t?V(t[2]).color:void 0);return}let[l,u]=Vr(s),d=l.match(vs);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={...V(m),...u},_=g.milestone===`true`,v={line:t,date:NaN,after:[],len:NaN,endDate:NaN},y=h.split(`,`).map(e=>e.trim()).filter(Boolean),b=0,x=y[0]??``,S=xs(x);/^after\s/i.test(x)?(v.after=x.slice(6).trim().split(/\s+/),b=1):Number.isNaN(S)?x&&Number.isNaN(Ss(x))&&n(t,`gantt: "${x}" is not a date (YYYY-MM-DD), "after id" or a length`):(v.date=S,b=1);let C=y[b];C===void 0?!_&&x&&n(t,`gantt: task "${f}" needs a length, e.g. "${x}, 3d"`):(v.len=Ss(C),Number.isNaN(v.len)&&(v.endDate=xs(C),Number.isNaN(v.endDate)&&n(t,`gantt: "${C}" is not a length (3h, 5d, 2w) or an end date`)));let w=g.progress===void 0?NaN:parseFloat(g.progress)/(g.progress.endsWith(`%`)?100:1);g.progress!==void 0&&!(w>=0&&w<=1)&&n(t,`gantt: progress "${g.progress}" must be 0% to 100%`),r.push({id:f,label:p?.replace(/\\(.)/g,`$1`)??f,tone:g.color,progress:Math.min(1,Math.max(0,w)),owner:g.owner,done:g.done===`true`,active:g.active===`true`,crit:g.crit===`true`,milestone:_,start:NaN,end:NaN,after:v.after,section:a.length-1}),i.push(v)});let s=new Map(r.map((e,t)=>[e.id,t])),c=r.map(()=>0),l=i.map(e=>e.date).filter(e=>!Number.isNaN(e)),u=l.length?l.reduce((e,t)=>Math.min(e,t)):Date.UTC(2025,0,1),d=e=>{let t=i[e];return t.after.length?t.after:Number.isNaN(t.date)&&e>0?[e-1]:[]},f=(e,t)=>{let a=r[e],o=i[e],s=o.date;return o.after.length?s=t.length?t.reduce((e,t)=>Math.max(e,t)):u:Number.isNaN(s)&&(e>0?s=t[0]:(n(o.line,`gantt: the first task needs a start date`),s=u)),a.start=s,a.end=a.milestone?s:Number.isNaN(o.len)?Number.isNaN(o.endDate)?s+ms:Math.max(s,o.endDate):s+o.len,Math.abs(a.end)<=hs||(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 ws(e){let t=[];return e.forEach((e,n)=>{let r=e.trim();r&&!Ua(r)&&!bs.test(r)&&vs.test(Vr(r)[0])&&t.push(n)}),t}var Ts=e=>{let t=new Date(e);return`${_s[t.getUTCMonth()]} ${t.getUTCDate()}`},Es=e=>{let t=e/ms;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 Ds(e,t,n,r){let i=[];for(let a of[1,2,7,14]){if(a*n<r)continue;let o=Math.ceil(e/ms)*ms;if(a>=7)for(let e=0;e<7&&new Date(o).getUTCDay()!==1;e++)o+=ms;for(;o<=t&&i.length<2e3&&Number.isFinite(new Date(o).getTime());o+=a*ms)i.push({t:o,label:Ts(o)});return i}for(let a of[1,2,3,6,12,24,60]){if(a*30.4*n<r)continue;let o=new Date(e),s=o.getUTCFullYear(),c=o.getUTCMonth()+(o.getUTCDate()>1||o.getUTCHours()?1:0);c=Math.ceil(c/a)*a;let l=!0;for(;;){s+=Math.floor(c/12),c%=12;let e=Date.UTC(s,c,1);if(!Number.isFinite(e)||e>t||i.length>=2e3)break;i.push({t:e,label:a>=12?`${s}`:c===0||l?`${_s[c]} ${s}`:_s[c]}),l=!1,c+=a}return i}return i}function Os(e){let t=te(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 ks={compact:1.6,normal:2.1,loose:2.7},As=ei(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=a*(ks[i.density??``]??ks.normal),s=a*1.9,c=a*2.2,l=i.labels===`bar`,u=i.bars===`thin`,d=(e,t=400)=>z(F(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/ms)*ms,_=Math.max(g+ms,Math.ceil(e.max/ms)*ms),v=(_-g)/ms,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*gs/v),x=e=>h+(e-g)/ms*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?`${Ts(e.start)} – ${Ts(e.end)}`:e.milestone?Ts(e.start):Es(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 js(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${L(n[0][0])},${L(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${L(u[0])},${L(u[1])}Q${L(a[0])},${L(a[1])} ${L(d[0])},${L(d[1])}`}let i=n[n.length-1];return`${r}L${L(i[0])},${L(i[1])}`}function Ms(e,t,n){if(!e.tasks.length)return``;let r=n.theme,i=n.props,a=As(e,n),{fs:o,x:s}=a,c=e=>t.x+s(e),l=t.y+a.h,u=r.group.stroke,d=[],f=P(r),p=(e,t,n,i,a,s=!1)=>`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central"${s?` text-anchor="end"`:``} font-size="${L(o)}"${i===400?``:` font-weight="${i}"`} xml:space="preserve">${B(F(n),a?{...f,text:a}:f,r)}</text>`,m=(e,t,n,r,i=!1)=>`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central"${i?` text-anchor="end"`:``} font-size="${L(o*.82)}" font-weight="500" fill="${r}">${I(n)}</text>`;if(i.weekends===`show`&&a.dayW>=o*.3&&(a.max-a.min)/864e5<=3660)for(let e=a.min;e<a.max;e+=ms){let n=new Date(e).getUTCDay();(n===0||n===6)&&d.push(`<rect x="${L(c(e))}" y="${L(t.y+a.axisH*.8)}" width="${L(a.dayW)}" height="${L(a.h-a.axisH*.8)}" fill="${u}" opacity="0.14"/>`)}let h=i.today===`now`?Math.floor(Date.now()/ms)*ms:xs(i.today??``),g=h>=a.min&&h<=a.max,_=g?`today · ${Ts(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 Ds(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${L(s)},${L(t.y+a.axisH*.75)}V${L(l)}" stroke="${u}" stroke-width="1" opacity="0.45"/>`),m||d.push(`<text x="${L(p)}" y="${L(t.y+a.axisH*.35)}" dominant-baseline="central" text-anchor="middle" font-size="${L(o*.82)}" fill="${r.node.sub}">${I(e.label)}</text>`)}d.push(`<path d="M${L(t.x+a.labelW)},${L(t.y+a.axisH*.75)}H${L(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="${L(t.x-o*.4)}" y="${L(t.y+n.y)}" width="${L(T+o*.4)}" height="${L(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=R(e.sectionTones[n.section],r,r.node.sub);d.push(`<path d="M${L(t.x)},${L(t.y+n.y+1)}H${L(t.x+T)}" stroke="${u}" stroke-width="1" opacity="0.6"/>`,p(t.x,s,e.sections[n.section],700,l));let f=e.tasks.filter(e=>e.section===n.section);if(f.length&&i.summary!==`hide`){let e=c(Math.min(...f.map(e=>e.start))),t=Math.max(e+2,c(Math.max(...f.map(e=>e.end)))),n=o*.32;d.push(`<path d="M${L(e)},${L(s+n*1.6)}V${L(s-n/2)}H${L(t)}V${L(s+n*1.6)}" fill="none" stroke="${l}" stroke-width="1.2" opacity="0.7"/>`,`<rect x="${L(e)}" y="${L(s-n/2)}" width="${L(t-e)}" height="${L(n)}" fill="${l}" opacity="0.55"/>`)}}if(g&&d.push(`<path d="M${L(c(h))},${L(t.y+a.axisH*.35)}V${L(l)}" stroke="${R(`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${L(g)},${L(_)}C${L(g+e)},${L(_)} ${L(b-e)},${L(y)} ${L(b)},${L(y)}`}else if(b-g>=n*1.5){let e=Math.min(g+n,b-n*.75);x=js([[g,_],[e,_],[e,y],[b,y]],o*.35)}else{let e=y>_?S(f):S(f)+a.rowH;x=js([[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="${L(l)}" stroke-linejoin="round"/>`,On({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`?Os(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=R(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${L(t)},${L(s-a.ms)}L${L(t+a.ms)},${L(s)}L${L(t)},${L(s+a.ms)}L${L(t-a.ms)},${L(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?R(`red`,r,f):f,D=!Number.isNaN(e.progress),k=(e,t)=>`<rect x="${L(v)}" y="${L(x)}" width="${L(e)}" height="${L(b)}" rx="${L(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 j=D&&e.progress>0?Math.min(y,Math.max(S*2,y*e.progress)):0;j&&d.push(k(j,`fill="${f}"${E===`soft`||E===`outline`?` opacity="0.3"`:``}`)),e.active&&E!==`thin`&&y-j>2&&d.push(`<rect x="${L(v+j)}" y="${L(x)}" width="${L(y-j)}" height="${L(b)}" rx="${L(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+j-o*.2)?Os(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=R(`red`,r,r.accent),n=t.y+a.axisH*.35;d.push(`<rect x="${L(b)}" y="${L(n-o*.55)}" width="${L(v)}" height="${L(o*1.1)}" rx="${L(o*.55)}" fill="${e}"/>`,`<text x="${L(b+v/2)}" y="${L(n)}" dominant-baseline="central" text-anchor="middle" font-size="${L(o*.72)}" font-weight="650" fill="${Os(e)}">${I(_)}</text>`)}return d.join(``)}function Ns(e,t){if(!e.tasks.length)return{w:0,h:0};let n=As(e,t);return{w:n.w,h:n.h}}function Ps(e,t,n){if(!e.tasks.length)return[];let r=As(e,n);return r.rows.flatMap(n=>n.task===void 0?[]:[{part:e.tasks[n.task].id,x:t.x+r.labelW-r.fs*.5,y:t.y+n.y+2,axis:`y`,title:`move ${e.tasks[n.task].id}`}])}var Fs={name:`gantt`,panels:[{name:`gantt`,aliases:{roadmap:``},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:Cs,measure:Ns,render:Ms,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:ti((e,t,n,r)=>{let i=ws(e)[r.tasks.findIndex(e=>e.id===t)];if(i===void 0)return null;let a=[...e];return a[i]=Wr(e[i],ys,`color`,n),a}),handles:Ps}]},Is=/^([xy])-axis\s*:?\s*(.*)$/i,Ls=/^q([1-4])(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/i,Rs=/^(.+?)(?:\s*\[([^\]]*)\])?\s*:\s*(-?\d*\.?\d+)\s*%?\s*,\s*(-?\d*\.?\d+)\s*%?$/,zs=/^(\s*(?:q[1-4]|.+?))(?:\s*\[([^\]]*)\])?(\s*:.*)$/i,Bs=[`teal`,`blue`,`slate`,`amber`];function Vs(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(Is);if(o){let[e,t=``]=o[2].split(/\s*-+>\s*/);r[o[1].toLowerCase()]=[e.trim(),t.trim()];return}let[s,c]=Vr(a,Ur),l=s.match(Ls);if(l){r.q[l[1]-1]={text:l[3].trim(),tone:c.color??V(l[2]).color};return}let u=s.match(Rs);if(!u)return n(t,`quadrant: cannot read "${a}" (expected "Name: x, y", "q1: label" or "x-axis low -> high")`);i.push({name:H(u[1]),tone:c.color??V(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=za(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 Hs(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]=Vr(l,Ur),d=new RegExp(Rs,`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 Us=ei(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=z(F(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=z(F(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 Ws(e,t,n){let r=n.theme,i=Us(e,n),{fs:a,S:o}=i,s=t.x+i.left,c=t.y,l=[],u=P(r),d=o/2,f=[[d,0],[0,0],[0,d],[d,d]];e.q.forEach((e,t)=>{let n=e.tone??Bs[t],i=r.tone(n)?.fill??m(n,r.dark?900:50)??r.node.fill;l.push(`<rect x="${L(s+f[t][0])}" y="${L(c+f[t][1])}" width="${L(d)}" height="${L(d)}" fill="${i}"/>`)}),e.q.forEach((e,t)=>{if(!e.text)return;let n=R(e.tone??Bs[t],r,r.node.sub);l.push(`<text x="${L(s+f[t][0]+d/2)}" y="${L(c+f[t][1]+a*1.1)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" font-weight="700" xml:space="preserve">${B(F(e.text),{...u,text:n},r)}</text>`)}),l.push(`<rect x="${L(s)}" y="${L(c)}" width="${L(o)}" height="${L(o)}" fill="none" stroke="${r.group.stroke}" stroke-width="1.5"/>`,`<path d="M${L(s+d)},${L(c)}V${L(c+o)}M${L(s)},${L(c+d)}H${L(s+o)}" stroke="${r.group.stroke}" stroke-width="1"/>`);let p=(e,t,n,i)=>n?`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.85)}" fill="${r.node.sub}"${i?` transform="rotate(-90 ${L(e)} ${L(t)})"`:``}>${I(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=R(e.tone,r,r.accent),{x:a,y:o}=i.pts[t],d=i.labels[t];l.push(`<circle cx="${L(s+a)}" cy="${L(c+o)}" r="${L(i.r)}" fill="${n}" stroke="${r.background===`none`?r.node.fill:r.background}" stroke-width="1.5"/>`,`<text x="${L(s+d.x)}" y="${L(c+d.y+d.h/2)}" dominant-baseline="central" font-size="${L(i.lfs)}" xml:space="preserve">${B(F(e.name),u,r)}</text>`)}),l.join(``)}var Gs={name:`quadrant`,panels:[{name:`quadrant`,aliases:{quadrantChart:``},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:Vs,measure(e,t){let n=Us(e,t);return{w:n.w,h:n.h}},render:Ws,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:ti((e,t,n,r)=>{let i,a=t.match(/^q([1-4])$/);if(a){if(i=e.findIndex(e=>Ls.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]=Wr(e[i],zs,`color`,n,Ur),o}),handles(e,t,n){let r=Us(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)=>Hs(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`}]}}]},Ks={high:`red`,medium:`amber`,low:`gray`};function qs(e){let[t,n]=Vr(e);return{text:t.trim(),props:n}}var Js=e=>!e.trim(),Ys=/^[-*]\s+/;function Xs(e){if(e===void 0||!e.trim())return;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0}function Zs(e,t,n){let r=[],i=Math.min(...e.filter(e=>!Js(e)).map(Ga)),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(Js(e))return;let d=e.trim(),f=Ga(e),p=c;if(c=t,Ys.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}=qs(d.replace(Ys,``)),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`?(Ks[r]||n(t,`kanban: priority "${r}" (use low, medium or high)`),l.push({text:r,tone:Ks[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}=qs(d),g=Xs(h.limit);h.limit!==void 0&&g===void 0&&n(t,`kanban: limit expects a number of 0 or more, got "${h.limit}"`);let _=za(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 Qs(e,t){let n=e.match(/^\s*(?:[-*]\s+)?/)[0],[r,i]=Vr(e),a=t(r.slice(n.length).trim(),i),{color:o,...s}=i,c=Gr(o?{color:o,...s}:s);return`${n}${a}${c?` [${c}]`:``}`}var $s=[`owner`,`ticket`,`priority`];function ec(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]?Ga(e[t.cards[0].start]):Ga(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=Zs(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=Ga(e[c.start]),l=u(c).map(e=>e.trim()?a+e.slice(Math.min(s,Ga(e))):e);return p(f(c,r.end,l),[t,-1])}if(!(r===`text`||r===`color`||(c?$s:[`limit`]).includes(r))||i&&/[\r\n]/.test(i)||r===`limit`&&i&&Xs(i)===void 0)return null;let a=r===`text`?i?.trim():void 0,s=[...e];s[l.start]=Qs(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=Zs(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]?Ga(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 tc=ei(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=yi(r),p=e=>{let t=e.chips.reduce((e,t)=>e+d(t)+i*.35,0);return{w:Math.max(z(F(e.text),i,n.mono,f,500),t,...e.details.map(e=>z(F(e),i*.88,n.mono,f))),h:a*1.7+i*1.2+(e.chips.length?i*1.5:0)+e.details.length*i*1.25}},m=e.map(e=>e.cards.map(p)),h=e=>e.limit===void 0?`${e.cards.length}`:`${e.cards.length}/${e.limit}`,g=Math.max(i*11,...e.map(e=>f(e.title,i,700,n.mono)+r(h(e),i*.8,600,n.mono)+i*3.2),...m.flat().map(e=>e.w+a*2+o*2)),_=[],v=0;e.forEach((e,n)=>{n&&(v+=s+Math.max(-s*.7,t.offsets[e.id]?.x??0)),_.push(v),v+=g});let y=Math.max(i*7,...m.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:m,badge:h,colW:g,at:_,w:v,h:y}});function nc(e,t,n){if(!e.length)return``;let r=n.theme,i=tc(e,n),{fs:a}=i,o=[],s=P(r),c=Math.min(r.radius,a*.6),l=R(`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="${L(d)}" y="${L(f)}" width="${L(i.colW)}" height="${L(i.h)}" rx="${L(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="${L(d+i.cpad+a*.35)}" cy="${L(h)}" r="${L(a*.32)}" fill="${R(e.tone,r,r.node.sub)}"/>`,`<text x="${L(d+i.cpad+a*1.05)}" y="${L(h)}" dominant-baseline="central" font-size="${L(a)}" font-weight="700" xml:space="preserve">${B(F(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="${L(v)}" y="${L(h-a*.6)}" width="${L(_)}" height="${L(a*1.2)}" rx="${L(a*.6)}" fill="${m?l:r.node.fill}" stroke="${m?l:r.node.stroke}"/>`,`<text x="${L(v+_/2)}" y="${L(h)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.8)}" font-weight="600" fill="${m?r.dark?`#000`:`#fff`:r.node.sub}">${I(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="${L(l)}" y="${L(y)}" width="${L(f)}" height="${L(n.h)}" rx="${L(c)}" fill="${r.node.fill}" stroke="${p?.stroke??r.node.stroke}"/>`),e.tone&&o.push(`<rect x="${L(l)}" y="${L(y+c/2)}" width="3.5" height="${L(n.h-c)}" rx="1.75" fill="${R(e.tone,r,r.accent)}"/>`);let m=y+i.pad+a*.6;o.push(`<text x="${L(l+i.pad)}" y="${L(m)}" dominant-baseline="central" font-size="${L(a)}" font-weight="500" xml:space="preserve">${B(F(e.text),s,r)}</text>`),m+=a*.6;for(let t of e.details)m+=a*1.25,o.push(`<text x="${L(l+i.pad)}" y="${L(m-a*.6)}" dominant-baseline="central" font-size="${L(a*.88)}" xml:space="preserve">${B(F(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="${L(t)}" y="${L(n-i.chipFs*.75)}" width="${L(e)}" height="${L(i.chipFs*1.5)}" rx="${L(i.chipFs*.75)}" fill="${c?.fill??r.group.fill}" stroke="${c?.stroke??r.node.stroke}" stroke-width="0.8"/>`,`<text x="${L(t+e/2)}" y="${L(n)}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.chipFs)}" font-weight="600"${s.mono?` font-family="ui-monospace, SFMono-Regular, Menlo, monospace"`:``} fill="${c?.text??r.node.sub}">${I(s.text)}</text>`),t+=e+a*.35}}y+=n.h+i.cardGap})}),o.join(``)}var rc={name:`kanban`,panels:[{name:`kanban`,aliases:{board:``},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:Zs,measure(e,t){if(!e.length)return{w:0,h:0};let n=tc(e,t);return{w:n.w,h:n.h}},render:nc,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:ec,adds:`column`,handles(e,t,n){if(!e.length)return[];let r=tc(e,n);return e.slice(1).map((e,n)=>({part:e.id,x:t.x+r.at[n+1],y:t.y+r.headH/2,axis:`x`,title:`move ${e.title}`}))}}]};function ic(e){let t=[],n=e=>t.push(e)-1,r=0,i=t=>{let n=[[]];for(;r<e.length;){let a=e[r++],o=n[n.length-1];if(a===`*`)e[r]===`*`?(r++,e[r]===`/`?(r++,o.push({t:`**/`})):o.push({t:`**`})):o.push({t:`*`});else if(a===`?`)o.push({t:`?`});else if(a===`{`)o.push({t:`alt`,alts:i(!0)});else if(a===`}`&&t)return n;else a===`,`&&t?n.push([]):o.push({t:`lit`,c:a.toLowerCase()})}return n},a=(e,r)=>{for(let i=e.length-1;i>=0;i--){let o=e[i];if(o.t===`lit`)r=n({k:`char`,c:o.c,next:r});else if(o.t===`?`)r=n({k:`seg`,next:r});else if(o.t===`*`||o.t===`**`){let e=n({k:`split`,outs:[]}),i=n({k:o.t===`*`?`seg`:`any`,next:e});t[e].outs.push(i,r),r=e}else if(o.t===`**/`){let e=n({k:`split`,outs:[]}),i=n({k:`any`,next:e}),a=n({k:`char`,c:`/`,next:r});t[e].outs.push(i,a),r=n({k:`split`,outs:[e,r]})}else r=n({k:`split`,outs:o.alts.map(e=>a(e,r))})}return r},o=i(!1),s=a(o.length>1?[{t:`alt`,alts:o}]:o[0],n({k:`end`})),c=e=>{let n=new Set,r=[...e];for(;r.length;){let e=r.pop();if(n.has(e))continue;n.add(e);let i=t[e];i.k===`split`&&r.push(...i.outs)}return n},l=c([s]);return{test(e){let n=l,r=e.toLowerCase();for(let e=0;e<r.length;e++){let i=r[e],a=[];for(let e of n){let n=t[e];n.k!==`split`&&n.k!==`end`&&(n.k===`char`?n.c===i:n.k!==`seg`||i!==`/`)&&a.push(n.next)}if(!a.length)return!1;n=c(a)}for(let e of n)if(t[e].k===`end`)return!0;return!1}}}var ac={added:`green`,modified:`amber`,deleted:`red`,renamed:`blue`,ignored:`gray`},oc=Object.keys(ac),sc={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,ignored:``},cc=[`collapsed`,`highlight`,`dim`,`folder`,`file`,...oc],lc=[`color`,`icon`,`badge`,`note`,`size`,`status`],uc=e=>oc.find(t=>e[t]===`true`)??(oc.includes(e.status)?e.status:void 0);function dc(e){for(let t of oc)delete e[t];delete e.status}var fc=[`folder`,`folder-open`,`file`,`code`,`doc`,`image`,`config`,`lock`,`package`,`git`,`database`,`test`,`font`,`media`,`terminal`,`yuhwa`],pc=/^(?:[ \t │┃┆┊╎]|[├└┣┗╰][─━]*|[|`+\\]-+|\|)*/u,mc=/^[-*+]\s+/,hc=/\s\[([^[\]]*)\]\s*$/,gc=/:\s|\s#\s|:$/,_c=/^\d+ director(?:y|ies)(?:, \d+ files?)?$/,vc=/^match\s+(\S+)\s+\[([^\]]*)\]\s*$/,yc=/^(?:\.{3}|…)$/;function bc(e){return e.replace(/\[[^[\]]*\]/g,e=>`x`.repeat(e.length))}var xc=e=>e.replace(/\/$/,``);function Sc(e,t){for(let n of Object.keys(e))!cc.includes(n)&&!lc.includes(n)&&t(`treeview: unknown prop "${n}" (use a colour, ${[...lc.slice(1),...cc].join(`, `)})`);e.status&&!oc.includes(e.status)&&t(`treeview: unknown status "${e.status}" (use one of: ${oc.join(`, `)})`),e.color&&!Ce(e.color)&&delete e.color}var Cc=100;function wc(e,t,n){let r=[],i=Ka(),a=[],o=!1;e.forEach((e,t)=>{if(!e.trim()||/^\s*#/.test(e))return;let s=e.trim().match(vc);if(s){let e=V(s[2]);Sc(e,e=>n(t,e));let r=s[1];a.push({re:ic(xc(r)),path:xc(r).includes(`/`),folders:r.endsWith(`/`),props:e,line:t,glob:r,hits:0});return}let c=e.match(pc)[0],l=e.slice(c.length),u=l.match(mc);u&&(l=l.slice(u[0].length));let d=e.length-l.trimStart().length;if(l=l.trim(),!l||_c.test(l))return;let f=(c+(u?.[0]??``)).replace(/\t/g,` `).length,p={},m,h=l.match(hc);h&&(p=V(h[1]),m=[d+h.index,d+l.length],l=l.slice(0,h.index).trimEnd());let g,_=bc(l).match(gc);if(_&&_.index>0){g=l.slice(_.index+_[0].length).trim()||void 0,l=l.slice(0,_.index).trimEnd();let e=l.match(hc);e&&!h&&(p=V(e[1]),m=[d+e.index,d+l.length],l=l.slice(0,e.index).trimEnd())}Sc(p,e=>n(t,e));let v={text:l,collapsed:!1,highlight:!1,dim:!1,line:t,lead:e.slice(0,d),depth:0,own:{props:p,note:p.note??g},children:[]};m&&(v.propSpan=m);let y=i.parent(f);i.depth>=Cc&&(o||n(t,`treeview: entries nest at most ${Cc} levels deep`),o=!0,y=i.cut(99)),v.depth=i.depth,(y?y.children:r).push(v),i.push(f,v)});let s=(e,t)=>{for(let n of e){let e=t+xc(n.text),{props:r,note:i}=n.own,o=r.folder===`true`||r.file!==`true`&&(n.children.length>0||n.text.endsWith(`/`)),c={};for(let t of a)(!t.folders||o)&&t.re.test(t.path?e:xc(n.text))&&(t.hits++,Object.assign(c,t.props));r.folder===`true`&&delete c.file,r.file===`true`&&delete c.folder,(oc.some(e=>r[e]===`true`)||r.status)&&dc(c),Object.assign(c,r),n.note=i??c.note,n.tone=c.color,n.icon=c.icon,n.badge=c.badge,n.size=c.size,n.status=uc(c),n.collapsed=c.collapsed===`true`,n.highlight=c.highlight===`true`,n.dim=c.dim===`true`,n.type=c.folder===`true`?`folder`:c.file===`true`?`file`:void 0,s(n.children,e+`/`)}};s(r,``);for(let e of a)e.hits||n(e.line,`treeview: "match ${e.glob}" matches no entry`);return r}function Tc(e,t=[]){for(let n of e)t.push(n),Tc(n.children,t);return t}var Ec=e=>e.type===`folder`||e.type!==`file`&&(e.children.length>0||e.text.endsWith(`/`)),Dc={added:`+`,modified:`~`,deleted:`-`,renamed:`>`};function Oc(e,t){let[n,r,i]=t.ascii?[`|-- `,"`-- ",`| `]:[`├── `,`└── `,`│ `],a=[],o=(e,t,s)=>{e.forEach((c,l)=>{let u=l===e.length-1,d=Ec(c),f=c.status?`${Dc[c.status]??`*`} `:``,p=(s?``:t+(u?r:n))+f+c.text;d&&!c.text.endsWith(`/`)&&(p+=`/`),c.collapsed&&c.children.length&&(p+=` …`);let m=[c.size,c.badge&&`[${c.badge}]`,c.note].filter(Boolean).join(` `);a.push({name:p,note:m}),c.collapsed||o(c.children,s?``:t+(u?` `:i),!1)})};e.length===1?o(e,``,!0):e.forEach(e=>o([e],``,!0));let s=Math.max(...a.map(e=>[...e.name].length));return a.map(e=>e.note?e.name.padEnd(s+2+e.name.length-[...e.name].length)+`# `+e.note:e.name)}var kc=e=>{let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``},Ac={},U=(e,t,n)=>{for(let r of n.split(` `))Ac[r]=[t,e]};U(`blue`,`code`,`ts tsx mts cts py c cpp`),U(`amber`,`code`,`js jsx mjs cjs zig`),U(`green`,`code`,`vue`),U(`orange`,`code`,`svelte rs swift html`),U(`purple`,`code`,`astro kt h cs css`),U(`cyan`,`code`,`go`),U(`red`,`code`,`java rb`),U(`indigo`,`code`,`php lua`),U(`pink`,`code`,`scss`),U(`green`,`terminal`,`sh bash zsh fish ps1`),U(`blue`,`doc`,`md`),U(`amber`,`doc`,`mdx`),U(`gray`,`doc`,`txt rst`),U(`red`,`doc`,`pdf`),U(`green`,`doc`,`csv`),U(`purple`,`image`,`png jpg jpeg gif webp avif ico`),U(`amber`,`image`,`svg`),U(`red`,`font`,`woff woff2 ttf otf`),U(`pink`,`media`,`mp3 wav ogg flac mp4 mov webm mkv`),U(`amber`,`config`,`json`),U(`purple`,`config`,`yaml yml`),U(`gray`,`config`,`toml ini`),U(`orange`,`config`,`xml`),U(`slate`,`config`,`env`),U(`cyan`,`database`,`sql db sqlite`),U(`amber`,`package`,`zip tar gz`),U(`pink`,`yuhwa`,`yu yuhwa`);var jc=/^(node_modules|dist|build|out|target|coverage|vendor|\.git|\.next|\.nuxt|\.cache|__pycache__)$/;function Mc(e){let t=xc(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`]:Ac[kc(t)]??[`file`,void 0]}var Nc=`M3.5 1.5h6l3.5 3.5v9.5h-9.5z`,Pc=`M9.5 1.5v3.5h3.5`;function Fc(e,t,n){let r=e=>`<path d="${e}" fill="none" stroke="${n}"/>`,i=`<path d="${Nc}" fill="${t}" stroke="${n}"/>${r(Pc)}`;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 Ic=l({folder:`📁`,"folder-open":`📂`,image:`🖼️`,lock:`🔒`,package:`📦`,database:`🗄️`,config:`⚙️`,git:`🔀`,test:`🧪`,font:`🔤`,media:`🎬`,terminal:`💻`});function Lc(e){let t=new Map;for(let n of e)t.set(xc(n.text),(t.get(xc(n.text))??0)+1);return e.map((e,n)=>/^[\w.-]+$/.test(xc(e.text))&&t.get(xc(e.text))===1&&!/^n\d+$/.test(xc(e.text))?xc(e.text):`n${n+1}`)}var Rc=e=>e!==void 0&&/^\d+(\.\d+)?$/.test(e)?Number(e):void 0,zc=e=>e!==void 0&&e!==`false`,Bc=e=>e&&Ce(e)?e:void 0,Vc=new Intl.Collator(`en`,{numeric:!0,sensitivity:`base`});function Hc(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 Hc(r,t))n.add(e)}return t.set(e,n),n}var Uc=[`color`,`mono`,`emoji`,`none`],Wc=[`solid`,`rounded`,`dashed`,`dotted`,`none`],Gc=[`none`,`name`,`folders`],Kc=[`collapsed`,`all`,`none`],qc=[`letter`,`dot`,`none`],Jc=ei(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.92,o=qa(i.icons,Uc,Uc[0]),s=qa(i.sort,Gc,Gc[0]),c=i.counts===`true`?`all`:qa(i.counts,Kc,Kc[0]),l=qa(i.marks,qc,qc[0]),u=i.rollup!==`false`&&l!==`none`,d=zc(i.compact),f=zc(i.chevrons),p=Rc(i.depth),m=Bc(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=Rc(i.indent)??y+a*.75,x=Tc(e),S=Lc(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(yc.test(e.text));return[...e].sort((e,n)=>t(e)-t(n)||(s===`folders`?Number(Ec(n))-Number(Ec(e)):0)||Vc.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,_=[xc(f.text)];for(;d&&f.children.length===1&&Ec(f)&&Ec(f.children[0])&&A(f)&&!g(f);)f=f.children[0],_.push(xc(f.text));let v=Ec(f),y=!v&&yc.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`,jc.test(xc(f.text))?`gray`:m]:Mc(f.text),k=f.icon??T,j=fc.includes(k)?k:void 0,ne=v?600:400,re=v&&(c===`all`||c===`collapsed`&&!x)&&f.children.length?String(E(f)):void 0,ie=v&&u&&!f.status?Hc(f,w):void 0,ae={node:f,part:C.get(f),depth:t,folder:v,open:x,last:l===s.length-1,parent:o,more:y,label:S,icon:j??`file`,iconTone:f.tone??(f.status?ac[f.status]:void 0)??(f.icon?void 0:D),iconText:j?void 0:f.icon,textW:z(F(S),a,n.mono,r,ne),badgeW:f.badge?r(f.badge,a*.72,600,n.mono)+a*.9:0,count:re,countW:re?O(re):0,rollup:ie?.size?ie.size===1?[...ie][0]:`modified`:void 0,sizeW:f.size?r(f.size,a*.82,400,n.mono):0,y:ee.length*h,x:t*b};ee.push(ae),x&&te(f.children,t+1,ae)})};te(e,0);let j=e=>e.more?e.x+_:e.x+_+g+v,ne=e=>j(e)+e.textW+a*.5,re=e=>(e.badgeW?ne(e)+e.badgeW:j(e)+e.textW)+a*.45,ie=e=>e.countW?re(e)+e.countW:e.badgeW?ne(e)+e.badgeW:j(e)+e.textW,ae=i.notes===`inline`,M=a*.88,oe=0;for(let e of ee)oe=Math.max(oe,ie(e));let se=oe+a*1.6,ce=e=>ae?ie(e)+a*.9:se,le=e=>e.node.note?z(F(e.node.note),M,n.mono,r,400):0,ue=e=>l!==`none`&&(e.node.status&&sc[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):ie(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:M,rowH:h,icons:o,marks:l,iconW:g,chevW:_,anchor:y,textX:j,badgeX:ne,countX:re,noteX:ce,sizeRight:me,markX:he,mark:ue,w:de?he+a*.8:me,h:ee.length*h}}),Yc=e=>{let t=_t(e,1);return t?` stroke-dasharray="${t}"${e===`dotted`?` stroke-linecap="round"`:``}`:``};function Xc(e,t){if(!e.length)return{w:0,h:0};let n=Jc(e,t);return{w:n.w,h:n.h}}function Zc(e,t,n){if(!e.length)return``;let r=n.theme,i=Jc(e,n),{props:a}=n,o=e=>t.x+e,s=e=>t.y+e,c=[],l=[],u=[],d=qa(a.lines,Wc,Wc[0]),f=(e,t)=>R(e,r,t),p=f(Bc(a[`line-color`]),r.edge.stroke),m=Bc(a[`highlight-color`]),h=Bc(a[`badge-color`])??`blue`,g=f(Bc(a[`note-color`]),r.node.sub),_=f(Bc(a[`strike-color`]),r.node.sub),v=Rc(a[`strike-width`])??Math.max(1.25,i.fs*.11),y=`fill="none" stroke="${p}" stroke-width="${L(it(a)??1)}" stroke-opacity="0.55"${Yc(d)}${d===`rounded`?` stroke-linejoin="round"`:``}`,b=Math.min(Rc(a.radius)??r.radius,(i.rowH-2)/2),x=Math.max(0,t.w-i.w),S=i.sizeRight+x,C=i.markX+x,w=L(o(-i.fs*.35)),T=L(i.w+x+i.fs*.7);return i.rows.forEach((e,t)=>{let n=e.node,p=e.y+i.rowH/2,x=[];if(n.highlight){let t=n.tone??m,o=t?r.tone(t):void 0;c.push(`<rect x="${w}" y="${L(s(e.y+1))}" width="${T}" height="${L(i.rowH-2)}" rx="${L(a.radius?b:Math.min(r.radius,i.rowH/3))}" fill="${o?.fill??r.accent}"${o?``:` fill-opacity="0.14"`}/>`)}else a.rows===`striped`&&t%2==1&&c.push(`<rect x="${w}" y="${L(s(e.y))}" width="${T}" height="${L(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${L(o(t))},${L(s(r))}V${L(s(p-a))}Q${L(o(t))},${L(s(p))} ${L(o(t+a))},${L(s(p))}H${L(o(n))}" ${y}/>`:`<path d="M${L(o(t))},${L(s(r))}V${L(s(p))}H${L(o(n))}" ${y}/>`)}else l.push(`<path d="M${L(o(t))},${L(s(p))}H${L(o(n))}" ${y}/>`)}if(i.chevW&&e.folder){let t=o(e.x+i.chevW*.45),n=i.fs*.22,a=e.open?`M${L(t-n)},${L(s(p)-n/2)}L${L(t)},${L(s(p)+n/2)}L${L(t+n)},${L(s(p)-n/2)}`:`M${L(t-n/2)},${L(s(p)-n)}L${L(t+n/2)},${L(s(p))}L${L(t-n/2)},${L(s(p)+n)}`;x.push(`<path d="${a}" fill="none" stroke="${r.node.sub}" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>`)}if(i.iconW&&!e.more){let t=o(e.x+i.chevW),n=s(p-i.iconW/2);if(e.iconText||i.icons===`emoji`)x.push(`<text x="${L(t+i.iconW/2)}" y="${L(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.fs*.95)}">${I(e.iconText??Ic[e.icon]??`📄`)}</text>`);else{let a=i.icons===`mono`,o=!a&&e.iconTone?r.tone(e.iconTone):void 0,s=a||!e.iconTone?r.node.sub:f(e.iconTone,r.node.sub),c=o?.fill??r.node.fill;x.push(`<g transform="translate(${L(t)},${L(n)}) scale(${L(i.iconW/16)})" stroke-width="1.3" stroke-linejoin="round">${Fc(e.icon,c,s)}</g>`)}}if(n.status===`deleted`){let t=o(i.textX(e));x.push(`<line x1="${L(t-i.fs*.15)}" y1="${L(s(p))}" x2="${L(t+e.textW+i.fs*.15)}" y2="${L(s(p))}" stroke="${_}" stroke-width="${L(v)}" stroke-linecap="round"/>`)}let E=n.status?f(ac[n.status],r.node.text):void 0,D=e.more?r.node.sub:n.tone?f(n.tone,r.node.text):E??r.node.text,O=[n.status===`deleted`?` opacity="0.8"`:``,n.status===`ignored`?` opacity="0.55"`:``,e.folder?` font-weight="600"`:``].join(``);if(x.push(`<text x="${L(o(i.textX(e)))}" y="${L(s(p))}" dominant-baseline="central" font-size="${L(i.fs)}"${O} xml:space="preserve">${B(F(e.label),P(r,D,D),r)}</text>`),n.badge){let t=r.tone(n.tone??h),a=o(i.badgeX(e)),c=i.fs*1.15;x.push(`<rect x="${L(a)}" y="${L(s(p)-c/2)}" width="${L(e.badgeW)}" height="${L(c)}" rx="${L(c/2)}" fill="${t?.fill??r.node.fill}" stroke="${t?.stroke??r.node.stroke}"/><text x="${L(a+e.badgeW/2)}" y="${L(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.fs*.72)}" font-weight="600" fill="${t?.text??r.node.text}">${I(n.badge)}</text>`)}if(e.count){let t=o(i.countX(e)),n=i.fs*1.05;x.push(`<rect x="${L(t)}" y="${L(s(p)-n/2)}" width="${L(e.countW)}" height="${L(n)}" rx="${L(n/2)}" fill="${r.node.sub}" fill-opacity="0.12"/><text x="${L(t+e.countW/2)}" y="${L(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.smallFs)}" font-weight="600" fill="${r.node.sub}">${e.count}</text>`)}if(n.note&&x.push(`<text x="${L(o(i.noteX(e)))}" y="${L(s(p))}" dominant-baseline="central" font-size="${L(i.noteFs)}" xml:space="preserve">${B(F(n.note),{text:g,sub:g,stroke:g},r,!0)}</text>`),n.size&&x.push(`<text x="${L(o(S))}" y="${L(s(p))}" dominant-baseline="central" text-anchor="end" font-size="${L(i.fs*.82)}" fill="${r.node.sub}">${I(n.size)}</text>`),i.mark(e)){let t=n.status??e.rollup,a=f(ac[t],r.node.text);i.marks===`dot`||!n.status?x.push(`<circle cx="${L(o(C))}" cy="${L(s(p))}" r="${L(i.fs*.22)}" fill="${a}"/>`):x.push(`<text x="${L(o(C))}" y="${L(s(p))}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.fs*.85)}" font-weight="700" fill="${a}">${sc[t]}</text>`)}u.push(n.dim?`<g opacity="0.45">${x.join(``)}</g>`:x.join(``))}),c.join(``)+l.join(``)+u.join(``)}var Qc={text:[],note:[],status:[``,...oc],icon:[``,...fc],badge:[],size:[],collapsed:[``,`true`],highlight:[``,`true`],dim:[``,`true`]},$c=e=>e.children.length?$c(e.children.at(-1)):e.line+1;function el(e,t,n,r){let i=Gr(r);return e.lead+t+(n?`: ${n}`:``)+(i?` [${i}]`:``)}function tl(e,t){let n=e?e.children[0]:t[0],r=e=>e.replace(/[^\s\-*+]/gu,` `).replace(/[-*+](?!\s)/g,` `);if(n)return r(n.lead);if(!e)return``;let i=e.lead.match(/[-*+]\s+$/)?.[0]??``;return` `.repeat(r(e.lead).length-i.length+2)+i}function nl(e,t,n){let r=Tc(n),i=Lc(r),a=t.id===void 0?-1:i.indexOf(t.id),o=r[a],s=(e,t,n)=>{if(t===void 0)return{body:e};let r=Tc(n??wc(e,{},()=>{}));return{body:e,id:Lc(r)[r.findIndex(e=>e.line===t)]}},c=e=>r.find(t=>t.children.includes(e))?.children??n;switch(t.op){case`set`:{if(!o)return null;let{key:n}=t,r=t.value?.trim()||null;if(r&&/[\r\n]/.test(r)||n!==`color`&&!(n in Qc)||Qc[n]?.length&&r&&!Qc[n].includes(r)&&n!==`icon`||n===`color`&&r&&!Ce(r))return null;let i=[...e],c=o.text,l=o.own.note;if(n===`text`||n===`note`){if(n===`text`){if(!r)return null;c=r}else l=r??void 0;let{note:e,...t}=o.own.props;i[o.line]=el(o,c,l,t)}else{let{color:t,...a}=o.own.props;n===`status`?(dc(a),r&&(a[r]=`true`)):n!==`color`&&(r?a[n]=r:delete a[n]);let s=n===`color`?r:t,c=Gr(s?{color:s,...a}:a),l=e[o.line],[u,d]=o.propSpan??[l.trimEnd().length,l.trimEnd().length];i[o.line]=l.slice(0,u)+(c?` [${c}]`:``)+l.slice(d)}let u=wc(i,{},()=>{}),d=Tc(u)[a];return!d||d.text!==c||d.own.note!==l?null:s(i,o.line,u)}case`up`:case`down`:{if(!o)return null;let n=c(o),r=n.indexOf(o),i=t.op===`up`,a=n[i?r-1:r+1];if(!a)return null;let[l,u]=i?[a,o]:[o,a],d=[...e],f=e.slice(l.line,u.line),p=e.slice(u.line,$c(u));return d.splice(l.line,f.length+p.length,...p,...f),s(d,i?l.line:l.line+p.length)}case`remove`:{if(!o)return null;let t=[...e];return t.splice(o.line,$c(o)-o.line),s(t)}case`add`:{if(t.id!==void 0&&!o)return null;let r=[...e],i=o?$c(o):n.length?$c(n[n.length-1]):e.length;return r.splice(i,0,tl(o,n)+`new-file`),s(r,i)}}}var rl={name:`treeview`,panels:[{name:`treeview`,aliases:{tree:``,filetree:``},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: "+fc.join(`|`)+"|<emoji>`, `badge: text`, `size: text`, `collapsed`, `highlight`, `dim`, `"+oc.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:[...Uc],lines:[...Wc],sort:[...Gc],notes:[`column`,`inline`],chevrons:`flag`,rows:[`plain`,`striped`],spacing:[`compact`,`normal`,`relaxed`],slashes:[`true`,`false`],compact:`flag`,counts:[...Kc],marks:[...qc],rollup:[`true`,`false`],depth:`number`,indent:`number`,"folder-color":`color`,"line-color":`color`,"highlight-color":`color`,"badge-color":`color`,"note-color":`color`,"strike-color":`color`,"strike-width":`number`},help:{icons:`how files and folders are drawn: coloured glyphs, one colour, emoji or no icon`,lines:`the guide lines that join an entry to its folder`,sort:`reorder entries: as written, by name, or folders first`,notes:`notes in their own column, or right after the name`,chevrons:`an open/closed arrow before each folder`,rows:`every other row shaded`,spacing:`the row height`,slashes:"a `/` after folder names",compact:"fold a folder whose only child is a folder into one `a/b/` row",counts:`how many entries a folder holds: on collapsed folders, on all, or none`,marks:`the git status column on the right: letters (M, A, D, R), dots, or none`,rollup:`a dot on folders that hold changed files`,depth:`show this many levels; deeper folders are drawn collapsed`,indent:`how far each level is indented, in pixels`,"folder-color":`the folder icon colour`,"line-color":`the guide line colour`,"highlight-color":`the band behind highlighted entries`,"badge-color":`the badge colour`,"note-color":`the note text colour`,"strike-color":`the line through deleted entries`,"strike-width":`how thick the line through deleted entries is`},parse:wc,measure:Xc,render:Zc,parts(e){let t=Tc(e);return Lc(t).map((e,n)=>{let r=t[n],i=r.own.props,a=Ec(r);return{id:e,label:r.text,kind:`entry`,depth:r.depth,tone:r.tone,fields:Qc,values:{text:r.text,note:r.own.note??``,status:uc(i)??``,icon:i.icon??``,badge:i.badge??``,size:i.size??``,collapsed:i.collapsed===`true`?`true`:``,highlight:i.highlight===`true`?`true`:``,dim:i.dim===`true`?`true`:``},actions:a?[`up`,`down`,`remove`,`add`]:[`up`,`down`,`remove`],...a?{adds:`entry`}:{}}})},editPart:nl,adds:`entry`,text:Oc}]},il=/^(?:(\d+)(?:\s*-\s*(\d+))?|\+\s*(\d+))(?:\s*\[([^\]]*)\])?\s*:\s*(.*)$/,al=/^(\s*(?:\d+(?:\s*-\s*\d+)?|\+\s*\d+))(?:\s*\[([^\]]*)\])?(\s*:.*)$/,ol=65536,sl=[`fields`,`all`,`none`],cl=[`ascending`,`descending`],ll=[`plain`,`cycle`];function ul(e,t,n){let r=Number(t.bits??32);(!Number.isInteger(r)||r<1||r>256)&&(n(-1,`packet: "bits: ${t.bits}" must be a whole number from 1 to 256; using 32`),r=32);let i=[],a=new Set,o=0;return e.forEach((e,t)=>{let r=e.trim();if(!r||Ua(r))return;let[s,c]=Vr(r,Ur),l=s.match(il);if(!l)return n(t,`packet: cannot read "${r}" (expected "0-15: label", "16: label" or "+8: label")`);let u,d;if(l[3]!==void 0){let e=Number(l[3]);if(e<1)return n(t,`packet: "+${l[3]}" needs at least one bit`);u=o,d=o+e-1}else u=Number(l[1]),d=l[2]===void 0?u:Number(l[2]);if(d<u)return n(t,`packet: the range ${u}-${d} runs backwards; write the lower bit first`);if(d>=ol)return n(t,`packet: bit ${d} is past the last bit a packet can show (65535)`);if(u<o)return n(t,`packet: bits ${u}-${d} overlap the field above, which ends at bit ${o-1}`);let f=H(l[5]),p=Ba(f,a,`f${i.length+1}`,/^f\d+$/);i.push({label:f,id:p,start:u,end:d,tone:c.color??V(l[4]).color,line:t}),o=d+1}),{fields:i,bits:r}}function dl(e){let t=[],n=(n,r,i)=>{for(let a=n;a<=r;){let n=Math.floor(a/e.bits),o=Math.min(r,(n+1)*e.bits-1);t.push({row:n,from:a,to:o,field:i}),a=o+1}},r=0;return e.fields.forEach((e,t)=>{e.start>r&&n(r,e.start-1),n(e.start,e.end,t),r=e.end+1}),t}var fl=ei(function(e,t){let n=t.fs*.88,r=Math.max(6,Number(t.props[`bit-width`])||Math.round(n*1.55)),i=qa(t.props.numbers,sl),a=i===`none`?0:n*1.15,o=n*2.7,s=a+o+n*.35,c=dl(e),l=c.length?c[c.length-1].row+1:0;return{fs:n,bw:r,numbers:i,numH:a,rowH:o,pitch:s,cells:c,rows:l,w:r*e.bits,h:l?l*s-n*.35:0}});function pl(e,t,n,r){let{measure:i,theme:a}=r,o=t=>z(F(e),t,a.mono,i),s=o(n);if(s<=t)return{text:e,size:n,cut:!1};let c=Math.max(n*.7,n*t/s);return o(c)<=t?{text:e,size:c,cut:!1}:{text:Va(wi(e),e=>i(e,c,400,a.mono)<=t),size:c,cut:!0}}function ml(e,t,n){let r=n.theme,i=fl(e,n),{fs:a,bw:o}=i,s=n.props.order===`descending`,c=n.props.colors===`cycle`,l=P(r),u=[],d=(e,t,n,i)=>`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central" text-anchor="${i}" font-size="${L(a*.62)}" fill="${r.node.sub}">${n}</text>`,f=n=>{let r=n%e.bits;return t.x+(s?e.bits-1-r:r)*o},p=Math.min(1.5,o*.08),h=Math.min(4,r.radius);for(let g of i.cells){let _=t.y+g.row*i.pitch+i.numH,v=Math.min(f(g.from),f(g.to)),y=v+p,b=(g.to-g.from+1)*o-p*2;if(g.field===void 0)u.push(`<rect x="${L(y)}" y="${L(_)}" width="${L(b)}" height="${L(i.rowH)}" rx="${L(h)}" fill="none" stroke="${r.group.stroke}" stroke-width="1" stroke-dasharray="3 3"/>`);else{let t=e.fields[g.field],o=c?Wa(t.tone,g.field):t.tone,s=o?r.tone(o):void 0,d=o?s?.fill??m(o,r.dark?900:50)??R(o,r,r.node.fill):r.node.fill,f=o?s?.stroke??R(o,r,r.node.stroke):r.node.stroke,p=s?.text??r.node.text;u.push(`<rect x="${L(y)}" y="${L(_)}" width="${L(b)}" height="${L(i.rowH)}" rx="${L(h)}" fill="${d}" stroke="${f}" stroke-width="${L(r.strokeWidth)}"/>`);let v=pl(t.label,b-a*.5,a,n),x=!1;if(v.cut&&b<i.rowH){let e=pl(t.label,i.rowH-a*.5,Math.min(a*.8,b*.75),n);e.text.length>v.text.length&&([v,x]=[e,!0])}if(v.text){let e=v.cut?I(v.text):B(F(v.text),{...l,text:p},r),t=y+b/2,n=_+i.rowH/2,a=x?` transform="rotate(-90 ${L(t)} ${L(n)})"`:``;u.push(`<text x="${L(t)}" y="${L(n)}" dominant-baseline="central" text-anchor="middle" font-size="${L(v.size)}" fill="${p}" xml:space="preserve"${a}>${e}</text>`)}}if(i.numbers===`fields`&&g.field!==void 0){let e=_-i.numH/2;if(g.from===g.to)u.push(d(v+o/2,e,g.from,`middle`));else{let[t,n]=s?[g.to,g.from]:[g.from,g.to];u.push(d(v+p+1,e,t,`start`),d(v+(g.to-g.from+1)*o-p-1,e,n,`end`))}}}if(i.numbers===`all`)for(let n=0;n<i.rows;n++){let r=t.y+n*i.pitch+i.numH/2;for(let t=0;t<e.bits;t++){let i=n*e.bits+t;u.push(d(f(i)+o/2,r,i,`middle`))}}return u.join(``)}var hl={name:`packet`,panels:[{name:`packet`,guide:"one field per line: `start-end: label`, `bit: label` for a single bit, or `+N: label` for N bits after the field above; a trailing `[color]` tints a field. Fields wrap at `bits` per row (32 by default); uncovered bits show as an empty dashed cell.",syntax:`packet id "Title" [bits: 32] { 0-15: Source port; +16: Destination port; 32 [red]: Flag }`,parse:ul,measure(e,t){let n=fl(e,t);return{w:n.w,h:n.h}},render:ml,options:{bits:`number`,"bit-width":`number`,numbers:[...sl],order:[...cl],colors:[...ll]},help:{bits:`bits per row (32 by default)`,"bit-width":`the width of one bit in px`,numbers:`bit numbers above the rows: at the edges of each field, over every bit, or none`,order:`ascending puts bit 0 on the left; descending mirrors each row`,colors:`plain fields, or each field in the next palette colour`},parts:e=>e.fields.map(e=>({id:e.id,label:e.label,kind:`field`,tone:e.tone})),editPart:ti((e,t,n,r)=>{let i=r.fields.find(e=>e.id===t);if(!i)return null;let a=[...e];return a[i.line]=Wr(e[i.line],al,`color`,n,Ur),a})}]},gl=/^(.+?)(?:\s*\[([^\]]*)\])?(?:\s*:\s*(-?\d*\.?\d+(?:e[+-]?\d+)?))?$/i,_l=/^(\s*(?:"[^"]*"|[^[:]+?))(?:\s*\[([^\]]*)\])?(\s*(?::.*)?)$/,vl=[`plain`,`thousands`,`compact`,`percent`],yl=32;function bl(e,t,n){let r=[],i=[],a=Ka(),o=new Map,s=new Set;e.forEach((e,t)=>{let c=e.trim();if(!c||Ua(c))return;let l=Ga(e),[u,d]=Vr(c,Ur),f=u.match(gl);if(!f)return n(t,`treemap: cannot read "${c}" (expected "Name: value" or a branch name)`);let p=a.parent(l);if(a.depth>=yl)return n(t,`treemap: "${c}" nests deeper than ${yl} levels`);let m=H(f[1]),h={name:m,id:Ba(m,s,`n${i.length+1}`,/^(n\d+|size)$/),value:0,tone:d.color??V(f[2]).color,line:t,depth:a.depth,children:[]};if(f[3]!==void 0){let e=Number(f[3]);!(e>=0)||!Number.isFinite(e)||e>1e300?n(t,`treemap: "${m}" needs a value of 0 or more`):o.set(h,e)}(p?p.children:r).push(h),i.push(h),a.push(l,h)});let c=e=>(e.children.length?(o.has(e)&&n(e.line,`treemap: "${e.name}" has lines under it, so its value is their sum, not ${o.get(e)}`),e.value=e.children.reduce((e,t)=>e+c(t),0)):(o.has(e)||n(e.line,`treemap: "${e.name}" has no value and nothing under it (write "${e.name}: 10")`),e.value=o.get(e)??0),e.value);return{roots:r,total:r.reduce((e,t)=>e+c(t),0),all:i}}function xl(e,t){let n=new Map,r=e.filter(e=>e.value>0).sort((e,t)=>t.value-e.value),i=r.reduce((e,t)=>e+t.value,0);if(!r.length||t.w<=0||t.h<=0)return n;let a=t.w*t.h/i,{x:o,y:s,w:c,h:l}=t,u=(e,t)=>{let n=e.reduce((e,t)=>e+t,0),r=0,i=1/0;for(let t of e)r=Math.max(r,t),i=Math.min(i,t);return Math.max(t*t*r/(n*n),n*n/(t*t*i))},d=0;for(;d<r.length;){let e=Math.min(c,l),t=[r[d]],i=[r[d].value*a];for(d++;d<r.length&&!(u([...i,r[d].value*a],e)>u(i,e));)i.push(r[d].value*a),t.push(r[d]),d++;let f=i.reduce((e,t)=>e+t,0);if(c>=l){let e=f/l,r=s;t.forEach((t,a)=>{let s=i[a]/e;n.set(t,{x:o,y:r,w:e,h:s}),r+=s}),o+=e,c-=e}else{let e=f/c,r=o;t.forEach((t,a)=>{let o=i[a]/e;n.set(t,{x:r,y:s,w:o,h:e}),r+=o}),s+=e,l-=e}}return n}var Sl=ei(function(e,t){let n=t.fs*.88,r=t.offsets.size??{x:0,y:0},i=Math.max(n*10,(Number(t.props.width)||n*38)+r.x),a=Math.max(n*6,(Number(t.props.height)||n*24)+r.y),o=Math.max(0,tt(t.props.padding,3)),s=Math.max(0,tt(t.props.gap,2))/2,c=Math.max(1,Math.round(tt(t.props.depth,1/0))),l=t.props.headers!==`hide`,u=n*1.7,d=[],f=(e,t,r)=>{let i=xl(e,t);e.forEach((e,t)=>{let a=i.get(e);if(!a)return;let p={x:a.x+s,y:a.y+s,w:Math.max(0,a.w-s*2),h:Math.max(0,a.h-s*2)},m=e.tone??r(e,t),h=e.children.length>0&&e.depth+1<c,g=l&&h&&p.h>u*2&&p.w>n*3;if(d.push({node:e,rect:p,tone:m,header:g,branch:h}),h){let t=g?u:o;f(e.children,{x:p.x+o,y:p.y+t,w:p.w-o*2,h:p.h-t-o},()=>m)}})};return f(e.roots,{x:0,y:0,w:i,h:a},(e,t)=>Wa(void 0,t)),{fs:n,w:i,h:a,headH:u,placed:d}});function Cl(e,t,n){let r=t.decimals===void 0?void 0:Math.min(10,Math.max(0,Math.round(Number(t.decimals))||0));return Xa(e,{unit:t.unit,format:qa(t.format,vl),decimals:r,total:n})}function wl(e,t,n){let r=n.theme,i=Sl(e,n),{fs:a}=i,o=n.props.values!==`hide`,s=P(r),c=[],l=Math.min(4,r.radius),u=a*.45,d=(e,t,i,a)=>z(F(e),i,r.mono,n.measure,a)<=t?{text:e,cut:!1}:{text:Va(wi(e),e=>n.measure(e,i,a,r.mono)<=t,2),cut:!0},f=(e,t,n,i,a,o)=>n.text?`<text x="${L(e)}" y="${L(t)}" dominant-baseline="central" font-size="${L(i)}"${a===400?``:` font-weight="${a}"`} fill="${o}" xml:space="preserve">${n.cut?I(n.text):B(F(n.text),{...s,text:o},r)}</text>`:``;for(let s of i.placed){let{node:p,rect:m,tone:h}=s,g=t.x+m.x,_=t.y+m.y,v=R(h,r,r.accent),{branch:y}=s,b=o?Cl(p.value,n.props,e.total):``;if(y){if(c.push(`<rect x="${L(g)}" y="${L(_)}" width="${L(m.w)}" height="${L(m.h)}" rx="${L(l)}" fill="${v}" fill-opacity="${r.dark?.14:.08}" stroke="${v}" stroke-opacity="0.55" stroke-width="1"/>`),s.header){let e=_+i.headH/2+1,t=m.w-u*2,s=o?n.measure(b,a*.8,400,r.mono)+a*.6:0,l=d(p.name,t-(s<t*.5?s:0),a*.9,700);c.push(f(g+u,e,l,a*.9,700,R(h,r,r.node.text))),o&&s<t*.5&&l.text&&c.push(`<text x="${L(g+m.w-u)}" y="${L(e)}" dominant-baseline="central" text-anchor="end" font-size="${L(a*.8)}" fill="${r.node.sub}">${I(b)}</text>`)}continue}c.push(`<rect x="${L(g)}" y="${L(_)}" width="${L(m.w)}" height="${L(m.h)}" rx="${L(l)}" fill="${v}" fill-opacity="${r.dark?.42:.26}" stroke="${v}" stroke-opacity="0.7" stroke-width="1"/>`);let x=m.w-u*2;if(x<a*1.2||m.h<a*1.5)continue;let S=d(p.name,x,a,600),C=m.h>=a*2.4?_+u+a*.65:_+m.h/2;if(c.push(f(g+u,C,S,a,600,r.node.text)),o&&S.text&&m.h>=a*3.4){let e=d(b,x,a*.85,400);e.cut||c.push(f(g+u,C+a*1.25,e,a*.85,400,r.node.sub))}}return c.join(``)}var Tl={name:`treemap`,panels:[{name:`treemap`,guide:"indentation is the tree: a leaf is `Name [color]: value`, a branch a name with lines indented under it (its value is their sum). Each top-level branch takes the next palette colour; `[color]` recolours a subtree.",layoutParts:"`size DX DY` grows the map",syntax:`treemap id "Title" [unit: " GB", format: thousands] { Code [blue] / (indented) src: 120 }`,parse:bl,measure(e,t){if(!e.roots.length)return{w:0,h:0};let n=Sl(e,t);return{w:n.w,h:n.h}},render:wl,options:{values:[`show`,`hide`],format:[...vl],decimals:`number`,unit:`text`,width:`number`,height:`number`,padding:`number`,gap:`number`,headers:[`show`,`hide`],depth:`number`},help:{values:`show each value under its name and next to each branch`,format:`plain numbers, thousands separators, 1.2k / 3.4M, or the share of the total`,decimals:`digits after the decimal point`,unit:`appended to each value; a currency sign ($, €, £) goes in front`,width:`the map width in px`,height:`the map height in px`,padding:`space in px between a branch and the tiles inside it (default 3)`,gap:`space in px between neighbouring tiles (default 2)`,headers:`show a branch name and total above its tiles, or hide them`,depth:`levels drawn; a branch at the last level is one tile with its total`},parts:e=>e.all.map(e=>({id:e.id,label:e.name,kind:e.children.length?`branch`:`leaf`,depth:e.depth,tone:e.tone})),editPart:ti((e,t,n,r)=>{let i=r.all.find(e=>e.id===t);if(!i)return null;let a=[...e];return a[i.line]=Wr(e[i.line],_l,`color`,n,Ur),a}),handles(e,t,n){let r=Sl(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize`}]}}]},El=[`justify`,`left`,`right`,`center`],Dl=[`source`,`target`,`gradient`],Ol=String.raw`-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?`,kl=new RegExp(String.raw`^(.+?)\s*-+>\s*(.+?)\s*:\s*(${Ol})\s*$`,`i`),Al=RegExp(`^${Ol}$`,`i`),jl=/^(\s*(?:"(?:[^"\\]|\\.)*"|[^"[\]]+?))(?:\s*\[([^\]]*)\])?(\s*)$/,Ml=1e300;function Nl(e){let t=[],n=``,r=!1;for(let i=0;i<e.length;i++){let a=e[i];r?a===`"`&&e[i+1]===`"`?(n+=`"`,i++):a===`"`?r=!1:n+=a:a===`"`&&!n.trim()?(r=!0,n=``):a===`,`?(t.push(n.trim()),n=``):n+=a}return t.push(n.trim()),t}function Pl(e,t,n){let r=[],i=new Map,a=new Set,o=e=>{let t=i.get(e);return t===void 0&&(t=r.length,i.set(e,t),r.push({name:e,id:Ba(e,a,`n${t+1}`,/^(n\d+|size)$/)})),t},s=[],c=new Map,l=(e,t)=>{let n=[e],r=new Set;for(;n.length;){let e=n.pop();if(e===t)return!0;if(!r.has(e)){r.add(e);for(let t of c.get(e)??[])n.push(t)}}return!1},u=new Map,d=(e,t,r,i,a)=>{let d=Number(i);if(!t||!r)return n(e,`sankey: a flow needs a source and a target`);if(!(d>0)||d>Ml)return n(e,`sankey: "${i.slice(0,24)}" is not a positive number, flow skipped`);let f=o(t),p=o(r);if(f===p||l(p,f))return n(e,`sankey: "${t} -> ${r}" would make a loop, flow skipped`);let m=u.get(`${f}>${p}`);if(m){m.value+=d,m.tone=a??m.tone;return}let h={s:f,t:p,value:d,tone:a};s.push(h),u.set(`${f}>${p}`,h);let g=c.get(f)??new Set;g.add(p),c.set(f,g)};return e.forEach((e,t)=>{let i=e.trim();if(!i||Ua(i))return;let[a,s]=Vr(i,Ur),c=a.match(kl);if(c)return d(t,H(c[1]),H(c[2]),c[3],s.color);if(a.includes(`,`)){let e=Nl(a);return e.length!==3||!Al.test(e[2])?n(t,`sankey: cannot read "${i}" (expected "source,target,value")`):d(t,e[0],e[1],e[2],s.color)}let l=H(a);if(!l||/\[|\]|->/.test(a))return n(t,`sankey: cannot read "${i}" (expected "Source -> Target: value" or "Name [color]")`);let u=r[o(l)];u.tone=s.color??u.tone,u.line??=t}),{nodes:r,links:s}}var Fl=ei(function(e,t){let{theme:n,measure:r,props:i}=t,a=t.fs*.88,o=e.nodes.length,s=qa(i.align,El,`justify`),c=i.values!==`hide`,l=i.unit??``,u=e.nodes.map(()=>[]),d=e.nodes.map(()=>[]);e.links.forEach((e,t)=>{d[e.s].push(t),u[e.t].push(t)});let f=t=>t.reduce((t,n)=>t+e.links[n].value,0),p=e.nodes.map((e,t)=>Math.max(f(u[t]),f(d[t]))),m=Array(o).fill(0),h=Array(o).fill(0);for(let t=!0,n=0;t&&n<=o;n++){t=!1;for(let n of e.links)m[n.t]<m[n.s]+1&&(m[n.t]=m[n.s]+1,t=!0),h[n.s]<h[n.t]+1&&(h[n.s]=h[n.t]+1,t=!0)}let g=Ha(m,0),_=e.nodes.map((t,n)=>{switch(s){case`left`:return m[n];case`right`:return g-h[n];case`center`:return u[n].length||!d[n].length?m[n]:Math.min(...d[n].map(t=>m[e.links[t].t]))-1;default:return d[n].length?m[n]:g}}),v=g+1,y=Array.from({length:v},()=>[]);e.nodes.forEach((e,t)=>y[_[t]].push(t));let b=t.offsets.size??{x:0,y:0},x=Math.max(2,tt(i.gap,a*.9)),S=Math.max(2,tt(i[`node-width`],Math.round(a*.7))),C=Ha(y.map(e=>e.length),1),w=Math.max(a*6,Math.max(a*15,C*a*2.6)+b.y),T=Math.min(...y.map(e=>{let t=e.reduce((e,t)=>e+p[t],0);return t>0?(w-(e.length-1)*x)/t:1/0})),E=Number.isFinite(T)&&T>0?T:1,D=p.map(e=>Math.max(1,e*E)),O=e.nodes.map(e=>F(e.name)),k=O.map(e=>z(e,a,n.mono,r,600)),A=p.map(e=>c?Xa(e,{unit:l}):``),ee=A.map(e=>e?r(e,a,400,n.mono)+a*.4:0),te=e.nodes.map((e,t)=>k[t]+ee[t]),j=a*.5,ne=v>1?Ha(y[0].map(e=>te[e]+j),0):0,re=Ha(y[v-1].map(e=>te[e]+j),0),ie=Ha(y.slice(1,-1).flatMap(e=>e.map(e=>te[e]+j*2)),0),ae=Math.max(a*8,ie+a*2)+(v>1?b.x/(v-1):0),M=_.map(e=>ne+e*(S+ae)),oe=Array(o).fill(0),se=e=>{let t=e.reduce((e,t)=>e+D[t],0)+(e.length-1)*x,n=(w-t)/2;for(let t of e)oe[t]=n,n+=D[t]+x};y.forEach(se);let ce=e=>oe[e]+D[e]/2,le=(t,n,r)=>{let i=f(n);return i>0?n.reduce((t,n)=>t+ce(r(e.links[n]))*e.links[n].value,0)/i:ce(t)},ue=(e,t)=>{let n=new Map(e.map(e=>[e,t(e)]));e.sort((e,t)=>n.get(e)-n.get(t)||e-t),se(e)};for(let e=0;e<6;e++){for(let e=1;e<v;e++)ue(y[e],e=>le(e,u[e],e=>e.s));for(let e=v-2;e>=0;e--)ue(y[e],e=>le(e,d[e],e=>e.t))}let de=Array(e.links.length).fill(0),fe=Array(e.links.length).fill(0),pe=e.links.map(e=>e.value*E);e.nodes.forEach((t,n)=>{let r=oe[n];for(let t of[...d[n]].sort((t,n)=>ce(e.links[t].t)-ce(e.links[n].t)||t-n))de[t]=r,r+=pe[t];r=oe[n];for(let t of[...u[n]].sort((t,n)=>ce(e.links[t].s)-ce(e.links[n].s)||t-n))fe[t]=r,r+=pe[t]});let me=a*.6;return{fs:a,top:me,H:w,x:M,y:oe,h:D,w:pe,sy:de,ty:fe,col:_,ncol:v,nodeW:S,names:O,valText:A,nameW:k,width:ne+v*S+(v-1)*ae+re,height:w+me*2}});function Il(e,t,n){let r=n.theme,i=Fl(e,n),a=t.x,o=t.y+i.top,s=t=>R(Wa(e.nodes[t].tone,t),r,m(`blue`,500)),c=r.dark?.45:.38,l=n.props.links??`source`,u=n.props[`link-color`]?R(n.props[`link-color`],r,r.node.sub):void 0,d=[],f=[],p=`${n.idPrefix??`yw`}-sk-${Math.round(t.x)}-${Math.round(t.y)}`;e.links.forEach((t,m)=>{let h=a+i.x[t.s]+i.nodeW,g=a+i.x[t.t],_=(h+g)/2,v=o+i.sy[m],y=v+i.w[m],b=o+i.ty[m],x=b+i.w[m],S;if(t.tone)S=R(t.tone,r,r.node.sub);else if(u)S=u;else if(l===`gradient`){let e=`${p}-${m}`;d.push(`<linearGradient id="${e}" gradientUnits="userSpaceOnUse" x1="${L(h)}" y1="0" x2="${L(g)}" y2="0"><stop offset="0" stop-color="${s(t.s)}"/><stop offset="1" stop-color="${s(t.t)}"/></linearGradient>`),S=`url(#${e})`}else S=s(l===`target`?t.t:t.s);let C=e.nodes[t.s].name,w=e.nodes[t.t].name;f.push(`<path d="M${L(h)},${L(v)}C${L(_)},${L(v)} ${L(_)},${L(b)} ${L(g)},${L(b)}L${L(g)},${L(x)}C${L(_)},${L(x)} ${L(_)},${L(y)} ${L(h)},${L(y)}Z" fill="${S}" fill-opacity="${c}"><title>${I(`${C} → ${w}: ${Xa(t.value,{unit:n.props.unit})}`)}</title></path>`)});let h=P(r),g=N(n.props.fill,r,50)??r.group.fill;return e.nodes.forEach((e,t)=>{f.push(`<rect x="${L(a+i.x[t])}" y="${L(o+i.y[t])}" width="${L(i.nodeW)}" height="${L(i.h[t])}" rx="1.5" fill="${s(t)}"/>`)}),e.nodes.forEach((e,t)=>{let n=i.col[t]===0&&i.ncol>1,s=i.col[t]>0&&i.col[t]<i.ncol-1,c=n?a+i.x[t]-i.fs*.5:a+i.x[t]+i.nodeW+i.fs*.5,l=o+i.y[t]+i.h[t]/2,u=i.valText[t]?`<tspan font-weight="400" fill="${r.node.sub}"> ${I(i.valText[t])}</tspan>`:``,d=`<tspan font-weight="600">${B(i.names[t],h,r)}</tspan>`,p=s?` stroke="${g}" stroke-width="${L(i.fs*.3)}" stroke-linejoin="round" paint-order="stroke"`:``;f.push(`<text x="${L(c)}" y="${L(l)}" dominant-baseline="central" text-anchor="${n?`end`:`start`}" font-size="${L(i.fs)}" fill="${r.node.text}"${p} xml:space="preserve">${d}${u}</text>`)}),(d.length?`<defs>${d.join(``)}</defs>`:``)+f.join(``)}var Ll=e=>/[,[\]"]|->|^\s|\s$/.test(e)?JSON.stringify(e):e,Rl={name:`sankey`,panels:[{name:`sankey`,guide:"one flow per line, `Source -> Target: value` or the Mermaid CSV row `Source,Target,value` (quote fields with commas); `Name [color]` colours a node; `[color]` after a flow colours that link. Columns follow the flows; loops are dropped.",layoutParts:"`size DX DY` makes the plot wider and taller",syntax:`sankey id "Title" [links: gradient] { Coal -> Power: 40; Power -> Homes: 30 }`,parse:Pl,measure(e,t){if(!e.nodes.length)return{w:0,h:0};let n=Fl(e,t);return{w:n.width,h:n.height}},render:(e,t,n)=>e.nodes.length?Il(e,t,n):``,options:{links:[...Dl],"link-color":`color`,align:[...El],values:[`show`,`hide`],unit:`text`,"node-width":`number`,gap:`number`},help:{links:`link colour: of the source node, the target node, or a gradient between them`,"link-color":"one colour for every link, instead of `links`",align:`which column nodes go to: sinks to the right (justify), as early or as late as possible, or centred`,values:`show each node total after its name`,unit:`appended to every value, e.g. " TWh" or "%"; a currency sign ($, €, £) goes in front`,"node-width":`width of the node bars in px`,gap:`space between nodes in one column in px`},parts:e=>e.nodes.map((t,n)=>({id:t.id,label:t.name,kind:`node`,tone:e.nodes[n].tone})),editPart:ti((e,t,n,r)=>{let i=r.nodes.find(e=>e.id===t);if(!i)return null;if(i.line===void 0)return n?[...e,`${Ll(i.name)} [${n}]`]:e;let a=[...e];return a[i.line]=Wr(e[i.line],jl,`color`,n,Ur),a}),handles(e,t,n){if(!e.nodes.length)return[];let r=Fl(e,n);return[{part:`size`,x:t.x+r.width,y:t.y+r.height,title:`resize sankey`}]}}]},zl=4,Bl=String.raw`(?:"(?:[^"\\]|\\.)*"|[^:"[\]&])+?`,Vl=new RegExp(String.raw`^(${Bl}(?:\s*&\s*${Bl})*)(?:\s*\[([^\]]*)\])?\s*(?::(.*))?$`),Hl=new RegExp(String.raw`^(\s*${Bl}(?:\s*&\s*${Bl})*)(?:\s*\[([^\]]*)\])?(\s*(?::.*)?)$`),Ul=e=>e.join(`&`);function Wl(e,t,n){let r=[],i=[],a=new Map,o=new Set;return e.forEach((e,t)=>{let s=e.trim();if(!s||Ua(s))return;let c=s.match(Vl);if(!c)return n(t,`venn: cannot read "${s}" (expected "Set: text" or "A & B: text")`);let l=c[1].split(/\s*&\s*(?=(?:(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*")*(?:[^"\\]|\\.)*$)/).map(H);if(l.some(e=>!e))return n(t,`venn: a set name is missing in "${s}"`);let u=V(c[2]),d=[];for(let e of l){let i=r.findIndex(t=>t.name===e);if(i<0){if(r.length>=zl)return n(t,`venn: at most ${zl} sets, "${e}" is skipped`);i=r.length,r.push({name:e,id:Ba(e,o,`s${i+1}`,/^size$/)})}d.includes(i)||d.push(i)}d.sort((e,t)=>e-t);let f,p;for(let[e,r]of Object.entries(u))e===`color`&&xe(r)?f=r:e===`size`&&Number(r)>=0?p=Number(r):n(t,`venn: unknown prop "${e}${r===`true`?``:`: ${r}`}" (use color or size)`);let m=Ul(d),h=a.get(m);h||(h={sets:d,texts:[]},a.set(m,h),i.push(h)),h.line??=t;let g=c[3]?.trim();if(g&&h.texts.push(g),d.length===1){let e=r[d[0]];e.tone=f??e.tone,e.size=p??e.size,e.line??=t}else h.tone=f??h.tone,h.size=p??h.size}),{sets:r,regions:i}}function Gl(e,t,n){if(n>=e+t)return 0;if(n<=Math.abs(e-t))return Math.PI*Math.min(e,t)**2;let r=(n*n+e*e-t*t)/(2*n),i=n-r,a=(e,t)=>e*e*Math.acos(Math.min(1,Math.max(-1,t/e)))-t*Math.sqrt(Math.max(0,e*e-t*t));return a(e,r)+a(t,i)}function Kl(e,t,n){let r=Math.abs(e-t),i=e+t;for(let a=0;a<50;a++){let a=(r+i)/2;Gl(e,t,a)>n?r=a:i=a}return(r+i)/2}var ql=[{cx:-.6,cy:.4,rx:1.4,ry:.8,rot:45},{cx:0,cy:0,rx:1.32,ry:.6,rot:45},{cx:0,cy:0,rx:1.32,ry:.6,rot:-45},{cx:.6,cy:.4,rx:1.4,ry:.8,rot:-45}];function Jl(e,t){let n=e.sets.length;if(n===4)return ql.map(e=>({cx:e.cx*t,cy:e.cy*t,rx:e.rx*t,ry:e.ry*t,rot:e.rot}));let r=Ha(e.sets.map(e=>e.size).filter(e=>e!==void 0&&e>0),0),i=r>0?Math.PI*t*t/r:0,a=e.sets.map(e=>r>0&&e.size!==void 0?t*Math.sqrt(Math.max(e.size,r*.02)/r):t),o=(n,r)=>{let o=e.regions.find(e=>e.sets.length===2&&e.sets[0]===n&&e.sets[1]===r)?.size;return o!==void 0&&i>0?o===0?a[n]+a[r]+t*.15:Kl(a[n],a[r],o*i):(a[n]+a[r])*.56},s=(e,t,n)=>({cx:e,cy:t,rx:n,ry:n,rot:0});if(n===1)return[s(0,0,a[0])];let c=o(0,1);if(n===2)return[s(0,0,a[0]),s(c,0,a[1])];let l=o(0,2),u=o(1,2),d=c>0?(l*l-u*u+c*c)/(2*c):0,f=Math.sqrt(Math.max(0,l*l-d*d));return[s(0,0,a[0]),s(c,0,a[1]),s(d,f,a[2])]}function Yl(e){let t=-e.rot*Math.PI/180,n=Math.cos(t),r=Math.sin(t),i=Math.min(e.rx,e.ry);return(t,a)=>{let o=t-e.cx,s=a-e.cy,c=o*n-s*r,l=o*r+s*n,u=Math.sqrt((c/e.rx)**2+(l/e.ry)**2),d=u>0?Math.hypot(o,s)*Math.abs(1-1/u):i;return{inside:u<1,gap:Math.min(d,i*Math.abs(1-u))||d}}}function Xl(e){let t=e.rot*Math.PI/180,n=Math.sqrt((e.rx*Math.cos(t))**2+(e.ry*Math.sin(t))**2),r=Math.sqrt((e.rx*Math.sin(t))**2+(e.ry*Math.cos(t))**2);return{x0:e.cx-n,x1:e.cx+n,y0:e.cy-r,y1:e.cy+r}}var Zl=ei(function(e,t){let{theme:n,measure:r}=t,i=t.fs*.88,a=i*1.3,o=e.sets.length,s=t.offsets.size??{x:0,y:0},c=e.regions.map(e=>e.texts.map(e=>F(e))),l=c.map(e=>Ha(e.map(e=>z(e,i,n.mono,r)),0)),u=Ha(l,0),d=Math.max(i*4,Math.max(i*6.5,u*1.05)+(s.x+s.y)/2),f=t=>{let n=!0,r=Jl(e,t),o=r.map(Yl),s=1/0,u=-1/0,d=1/0,f=-1/0;for(let e of r){let t=Xl(e);s=Math.min(s,t.x0),u=Math.max(u,t.x1),d=Math.min(d,t.y0),f=Math.max(f,t.y1)}let p=t/24,m=Math.max(1,Math.ceil((u-s)/p)),h=Math.max(1,Math.ceil((f-d)/p)),g=new Int8Array(m*h),_=new Float64Array(m*h),v=new Map;for(let e=0;e<h;e++)for(let t=0;t<m;t++){let n=0,r=1/0;o.forEach((i,a)=>{let o=i(s+(t+.5)*p,d+(e+.5)*p);o.inside&&(n|=1<<a),r=Math.min(r,o.gap)});let i=e*m+t;g[i]=n,_[i]=r;let a=v.get(n);a?a.push(i):v.set(n,[i])}let y=(e,t)=>{let n=Math.floor((e-s)/p),r=Math.floor((t-d)/p);return n<0||r<0||n>=m||r>=h?-1:r*m+n};return{shapes:r,probes:o,spots:e.regions.map((e,t)=>{let r=e.sets.reduce((e,t)=>e|1<<t,0),o=l[t]/2+i*.3,u=c[t].length*a/2,f=[-o,0,o],h=[-u,0,u],b,x;for(let e of v.get(r)??[]){let t=s+(e%m+.5)*p,n=d+(Math.floor(e/m)+.5)*p;(!x||_[e]>x.gap)&&(x={x:t,y:n,gap:_[e]});let i=_[e];for(let e of f){for(let a of h){let o=y(t+e,n+a);if(i=o<0||g[o]!==r?-1:Math.min(i,_[o]),i<0)break}if(i<0)break}i>=0&&(!b||i>b.gap)&&(b={x:t,y:n,gap:i})}return b||(n=!1),b??x}),fits:n,x0:s,x1:u,y0:d,y1:f}},p=f(d);for(let e=1;!p.fits&&e<=3;e++)p=f(d*(1+e*.15));let{shapes:m,probes:h,spots:g}=p,{x0:_,x1:v,y0:y,y1:b}=p,x=m.reduce((e,t)=>e+t.cx,0)/Math.max(1,o),S=m.reduce((e,t)=>e+t.cy,0)/Math.max(1,o),C=e.sets.map(e=>F(e.name)),w=m.map((e,t)=>{let a=z(C[t],i,n.mono,r,700),o={x:e.cx,y:Xl(e).y0-i*.9,anchor:`middle`,score:-1/0};for(let t=0;t<72;t++){let n=t/72*Math.PI*2,r=e.rot*Math.PI/180,s=Math.cos(n)*e.rx,c=Math.sin(n)*e.ry,l=e.cx+s*Math.cos(r)-c*Math.sin(r),u=e.cy+s*Math.sin(r)+c*Math.cos(r),d=l-e.cx,f=u-e.cy,p=Math.hypot(d,f)||1,m=l+d/p*i*.6,g=u+f/p*i*.6,_=d/p<-.35?`end`:d/p>.35?`start`:`middle`,v=_===`end`?m-a:_===`middle`?m-a/2:m,y=g+f/p*i*.4,b=([[v,y-i*.6],[v+a,y-i*.6],[v,y+i*.6],[v+a,y+i*.6],[v+a/2,y]].every(([e,t])=>h.every(n=>!n(e,t).inside))?0:-1e6)+Math.hypot(l-x,u-S)-(u-S)*.6;b>o.score&&(o={x:m,y,anchor:_,score:b})}return{...o,w:a}});for(let e of w){let t=e.anchor===`end`?e.x-e.w:e.anchor===`middle`?e.x-e.w/2:e.x;_=Math.min(_,t),v=Math.max(v,t+e.w),y=Math.min(y,e.y-i*.7),b=Math.max(b,e.y+i*.7)}return{fs:i,lh:a,shapes:m,texts:c,spots:g,names:C,labels:w,ox:2-_,oy:2-y,w:v-_+4,h:b-y+4}});function Ql(e,t,n,r){if(e.rx===e.ry)return`<circle cx="${L(t+e.cx)}" cy="${L(n+e.cy)}" r="${L(e.rx)}"${r}/>`;let i=L(t+e.cx),a=L(n+e.cy);return`<ellipse cx="${i}" cy="${a}" rx="${L(e.rx)}" ry="${L(e.ry)}" transform="rotate(${L(e.rot)} ${i} ${a})"${r}/>`}function $l(e,t,n){let r=n.theme,i=Zl(e,n),a=t.x+i.ox,o=t.y+i.oy,s=Math.min(1,Math.max(0,Number(n.props.opacity??(r.dark?.3:.22))||0)),c=t=>R(Wa(e.sets[t].tone,t),r,r.accent),l=`${n.idPrefix??`yw`}-venn-${Math.round(t.x)}-${Math.round(t.y)}`,u=[];i.shapes.forEach((e,t)=>u.push(Ql(e,a,o,` fill="${c(t)}" fill-opacity="${L(s)}"`)));let d=e.regions.filter(e=>e.sets.length>1&&e.tone).sort((e,t)=>e.sets.length-t.sets.length);if(d.length){let e=new Set(d.flatMap(e=>e.sets.slice(0,-1)));u.unshift(`<defs>${[...e].map(e=>`<clipPath id="${l}-${e}">${Ql(i.shapes[e],a,o,``)}</clipPath>`).join(``)}</defs>`);for(let e of d){let t=Ql(i.shapes[e.sets[e.sets.length-1]],a,o,` fill="${R(e.tone,r,r.accent)}" fill-opacity="${L(Math.min(1,s*3))}"`);u.push(e.sets.slice(0,-1).reduceRight((e,t)=>`<g clip-path="url(#${l}-${t})">${e}</g>`,t))}}i.shapes.forEach((e,t)=>u.push(Ql(e,a,o,` fill="none" stroke="${c(t)}" stroke-width="1.5"`)));let f=P(r);return e.regions.forEach((e,t)=>{let n=i.spots[t];if(!n||!i.texts[t].length)return;let s=o+n.y-(i.texts[t].length-1)*i.lh/2;i.texts[t].forEach((e,t)=>{u.push(`<text x="${L(a+n.x)}" y="${L(s+t*i.lh)}" dominant-baseline="central" text-anchor="middle" font-size="${L(i.fs)}" xml:space="preserve">${B(e,f,r)}</text>`)})}),i.labels.forEach((t,n)=>{u.push(`<text x="${L(a+t.x)}" y="${L(o+t.y)}" dominant-baseline="central" text-anchor="${t.anchor}" font-size="${L(i.fs)}" font-weight="700" xml:space="preserve">${B(i.names[n],{...f,text:c(n)},r)}<title>${I(e.sets[n].name)}</title></text>`)}),u.join(``)}var eu=e=>/[:"[\]&]|^\s|\s$/.test(e)?JSON.stringify(e):e,tu=(e,t)=>t.sets.map(t=>e.sets[t].id).join(`+`),nu=()=>!1,ru={name:`venn`,panels:[{name:`venn`,guide:"one region per line: `Set [color, size: n]: text` for a set, `A & B: text` for an overlap (`A & B & C` too); each line adds a line of text, sets come in order of first mention. 1 to 3 sets are circles, sized by `size`; 4 sets are ellipses.",layoutParts:"`size DX DY` makes the circles larger",syntax:`venn id "Title" { Frontend: React; Backend: Postgres; Frontend & Backend: APIs }`,parse:Wl,measure(e,t){if(!e.sets.length)return{w:0,h:0};let n=Zl(e,t);return{w:n.w,h:n.h}},render:(e,t,n)=>e.sets.length?$l(e,t,n):``,options:{opacity:`number`},help:{opacity:`fill opacity of the sets, from 0 to 1`},parts:e=>[...e.sets.map(e=>({id:e.id,label:e.name,kind:`set`,tone:e.tone})),...e.regions.filter(e=>e.sets.length>1).map(t=>({id:tu(e,t),label:t.sets.map(t=>e.sets[t].name).join(` & `),kind:`overlap`,tone:t.tone}))],editPart:ti((e,t,n,r)=>{let i=r.sets.findIndex(e=>e.id===t),a=r.regions.find(e=>i>=0?e.sets.length===1&&e.sets[0]===i:e.sets.length>1&&tu(r,e)===t);if(i<0&&!a)return null;let o=i>=0?r.sets[i].line:a.line;if(o===void 0){let t=i>=0?eu(r.sets[i].name):a.sets.map(e=>eu(r.sets[e].name)).join(` & `);return n?[...e,`${t} [${n}]`]:e}let s=[...e];return s[o]=Wr(e[o],Hl,`color`,n,nu),s}),handles(e,t,n){if(!e.sets.length)return[];let r=Zl(e,n);return[{part:`size`,x:t.x+r.w,y:t.y+r.h,title:`resize venn`}]}}]},iu=.5;function au(e,t,n){let r=null,i=0,a=Ka(1);return e.forEach((e,t)=>{let o=e.trim();if(!o||Ua(o))return;let s=Ga(e),[c,l]=Vr(o.replace(La,``),Ur),u={text:H(c),tone:l.color,line:t,children:[]};if(!u.text)return n(t,`ishikawa: a line needs some text`);r?(s<=i&&(s=i+.5),a.parent(s).children.push(u),a.push(s,u)):(r=u,i=s,a.push(s,u))}),r}function ou(e){let t=e.map(e=>za(e.text)),n=new Map;for(let e of t)n.set(e,(n.get(e)??0)+1);return e.map((e,r)=>{if(r===0)return`effect`;let i=t[r];return i&&n.get(i)===1&&!/^(n\d+|effect)$/.test(i)?i:`n${r}`})}var su=ei(function(e,t){let{theme:n,measure:r}=t,i=t.fs*.9,a=t.props.colors===`mono`,o=i,s=e=>e*1.75,c=o*1.9,l=i*.7,u=i*.35,d=(e,t,i=400)=>z(F(e),t,n.mono,r,i),f=e.children.map((e,t)=>{let n=e.tone??(a?void 0:Ia[t%Ia.length]),r=[],s=(e,t,n)=>{let a=t?i*.8:i*.88,o=e.tone??n;r.push({node:e,depth:t,font:a,color:o,dist:0,left:0,end:0,tx:0,tw:d(e.text,a)});for(let n of e.children)s(n,t+1,o)};for(let t of e.children)s(t,0,n);let c=d(e.text,o,700);return{node:e,side:t%2?1:-1,color:n,x:0,rows:r,lw:c+o*1.6,tw:c}}),p=e=>l+e.rows.reduce((e,t)=>e+s(t.font),0)+i*.9,m={[-1]:i*3,1:i*3};for(let e of f)m[e.side]=Math.max(m[e.side],p(e));for(let e of f){let t=m[e.side],n=e.rows.reduce((e,t)=>e+s(t.font),0),r=e.side<0?t-l:t-l-n,a=[];for(let t of e.rows){let n=s(t.font);e.side<0?(t.dist=r-n+t.font*.35,r-=n):(r+=n,t.dist=r-t.font*.35),a.length=t.depth;let o=a[t.depth-1];o?(o.stem===void 0&&(o.stem=Math.max(o.left+i*.4,o.end-i*1.1)),o.stemTo=t.dist,t.end=o.stem):t.end=-t.dist*iu,t.tx=t.end-u-(!t.depth&&e.side<0?t.font*.9*iu:0),t.left=t.tx-t.tw-i*.15,a[t.depth]=t}}let h=i*1.2,g=e=>-m[e.side]*iu-e.lw/2,_=e=>-m[e.side]*iu+e.lw/2,v=0;f.forEach((e,t)=>{let n=t?f[t-1].x+i*2.2:0;for(let r=t-1;r>=0;r--){let t=f[r];if(t.side===e.side){for(let r of e.rows)n=Math.max(n,t.x-r.dist*iu-r.left+h);n=Math.max(n,t.x+_(t)-g(e)+h);break}}e.x=n,v=n});let y=i*1.05,b=i*11,x=[];for(let t of e.text.split(/\s+/)){let e=x[x.length-1];e!==void 0&&d(`${e} ${t}`,y,700)<=b?x[x.length-1]=`${e} ${t}`:x.push(t)}let S=Math.max(...x.map(e=>d(e,y,700)))+y*2,C=x.length*y*1.3+y*1.3,w=f.length?Math.max(...f.map(e=>e.x+Math.max(0,_(e)))):i*6,T=Math.max(v,w)+i*1.6,E=f.some(e=>e.side<0)?m[-1]+c:0,D=f.some(e=>e.side>0)?m[1]+c:0,O=Math.max(E,C/2,i),k=O+Math.max(D,C/2,i),A=-i*1.6;for(let e of f)A=Math.min(A,e.x+g(e),...e.rows.map(t=>e.x+t.left));let ee=-i*.8;for(let e of f)for(let t of e.rows)t.dist<i*1.6&&(ee=Math.min(ee,e.x+t.left-i*.6));A=Math.min(A,ee-i*.9);let te=-A;for(let e of f)e.x+=te;return{fs:i,cfs:o,hfs:y,labelH:c,reach:m,bones:f,spineY:O,tailX:ee+te,head:{x:T+te,y:O-C/2,w:S,h:C,lines:x},w:T+te+S,h:k}});function cu(e,t,n){if(!e)return``;let r=n.theme,i=su(e,n),a=n.props.direction===`left`,o=e=>L(t.x+(a?i.w-e:e)),s=e=>L(t.y+e),c=e=>a&&e!==`middle`?e===`start`?`end`:`start`:e,l=(e,t=r.edge.ink)=>R(e,r,t),u=(e,t,n,i,a,l=400,u)=>`<text x="${o(e)}" y="${s(t)}" dominant-baseline="central" text-anchor="${c(a)}" font-size="${L(i)}"${l===400?``:` font-weight="${l}"`} xml:space="preserve">${B(F(n),P(r,u??r.node.text),r)}</text>`,d=[],{spineY:f,fs:p}=i,m=i.head;d.push(`<path d="M${o(i.tailX)},${s(f)}H${o(m.x)}" stroke="${r.edge.ink}" stroke-width="3" stroke-linecap="round"/>`,`<path d="M${o(i.tailX-p*.9)},${s(f-p*.9)}L${o(i.tailX)},${s(f)}L${o(i.tailX-p*.9)},${s(f+p*.9)}" fill="none" stroke="${r.edge.ink}" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>`);for(let e of i.bones){let n=i.reach[e.side],c=l(e.color),p=e.x-n*iu,m=f+e.side*n;d.push(`<path d="M${o(p)},${s(m)}L${o(e.x)},${s(f)}" stroke="${c}" stroke-width="2.2" stroke-linecap="round"/>`);let h=e.color?r.tone(e.color):void 0,g=e.side<0?m-i.labelH:m,_=a?i.w-(p+e.lw/2):p-e.lw/2;d.push(`<rect x="${L(t.x+_)}" y="${s(g)}" width="${L(e.lw)}" height="${L(i.labelH)}" rx="${L(Math.min(r.radius+2,i.labelH/2))}" fill="${h?.fill??r.node.fill}" stroke="${h?.stroke??r.node.stroke}" stroke-width="1.5"/>`,u(p,g+i.labelH/2,e.node.text,i.cfs,`middle`,700,h?.text));for(let t of e.rows){let n=f+e.side*t.dist,i=l(t.color);d.push(`<path d="M${o(e.x+t.left)},${s(n)}H${o(e.x+t.end)}" stroke="${i}" stroke-width="${t.depth?1:1.4}" stroke-linecap="round" opacity="0.75"/>`,u(e.x+t.tx,n-t.font*.62,t.node.text,t.font,`end`,400,t.depth?r.node.sub:void 0)),t.stem!==void 0&&t.stemTo!==void 0&&d.push(`<path d="M${o(e.x+t.stem)},${s(n)}V${s(f+e.side*t.stemTo)}" stroke="${i}" stroke-width="1" opacity="0.75"/>`)}}let h=e.tone?r.tone(e.tone):void 0,g=a?i.w-m.x-m.w:m.x;return d.push(`<rect x="${L(t.x+g)}" y="${s(m.y)}" width="${L(m.w)}" height="${L(m.h)}" rx="${L(Math.min(m.h/2,i.hfs*1.4))}" fill="${h?.fill??r.node.fill}" stroke="${h?.stroke??r.accent}" stroke-width="2.5"/>`),m.lines.forEach((e,t)=>{let n=m.y+i.hfs*.65+i.hfs*1.3*(t+.5);d.push(u(m.x+m.w/2,n,e,i.hfs,`middle`,700,h?.text))}),d.join(``)}var lu={name:`ishikawa`,panels:[{name:`ishikawa`,aliases:{fishbone:``},guide:"indentation is the tree: the first line is the effect (the head), lines one level in are categories (bones above and below the spine), deeper lines causes and sub-causes; `-` / `*` bullets are optional. A trailing `[color]` tints a category or cause and everything under it.",syntax:`ishikawa id "Title" { Effect\\n Category [blue]\\n Cause\\n Sub-cause }`,options:{direction:[`right`,`left`],colors:[`categories`,`mono`]},help:{direction:`side of the head: right (default) or left`,colors:`categories: a palette colour per bone (default); mono: none`},parse:au,measure(e,t){if(!e)return{w:0,h:0};let n=su(e,t);return{w:n.w,h:n.h}},render:cu,parts(e){if(!e)return[];let t=Ra(e),n=new Set(e.children);return ou(t).map((e,r)=>({id:e,label:t[r].text,kind:r===0?`effect`:n.has(t[r])?`category`:`cause`,tone:t[r].tone}))},editPart:ti((e,t,n,r)=>{if(!r)return null;let i=Ra(r),a=i[ou(i).indexOf(t)];if(!a)return null;let o=[...e],[s]=Vr(e[a.line],Ur),c=Gr(n?{color:n}:{});return o[a.line]=s.trimEnd()+(c?` [${c}]`:``),o})}]},uu=new Set([`=`,`::=`,`:=`,`<-`,`=/`,`←`]),du=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*/u;function fu(e,t,n){let r=[],i=null,a=()=>{let e=r[r.length-1];return!e||e.kind===`op`&&/^(=|::=|:=|\||,|\(|\[|\{|-|=\/)$/.test(e.v)};return e.forEach((e,o)=>{let s=0,c=(e,t,n)=>r.push({kind:e,v:t,line:o,...n});for(;s<e.length;){if(i){let t=e.indexOf(i,s);if(t<0)return;s=t+i.length,i=null;continue}let r=e.slice(s),l=e[s];if(/\s/.test(l)){s++;continue}if(r.startsWith(`(*`)&&t!==`abnf`){i=`*)`,s+=2;continue}if(r.startsWith(`/*`)){i=`*/`,s+=2;continue}if(l===`#`&&t===`peg`||l===`;`&&t===`abnf`&&r.slice(1).trim())return;let u=r.match(/^(?:%[si])?("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/);if(u){c(`str`,u[1].slice(1,-1).replace(/\\(.)/g,`$1`)),s+=u[0].length;continue}if(l===`"`||l===`'`){n(o,`railroad: unclosed string ${r}`),c(`str`,r.slice(1));return}let d=r.match(/^%[xdb][0-9a-f]+(?:(?:\.[0-9a-f]+)+|-[0-9a-f]+)?/i)??r.match(/^#x[0-9a-f]+/i);if(d&&(d[0][0]===`%`||t!==`peg`)){c(`term`,d[0]),s+=d[0].length;continue}if(l===`[`&&t!==`abnf`){let e=r.match(/^\[(?:[^\]\\]|\\.)+\]/);if(e&&(t===`peg`||/^\[\^|#x|^\[[^\s\]]-[^\s\]]/.test(e[0]))&&!/\s/.test(e[0])){c(`term`,e[0]),s+=e[0].length;continue}}if(l===`?`&&t===`ebnf`&&a()){let t=e.indexOf(`?`,s+1);if(t>0){c(`special`,e.slice(s+1,t).trim()),s=t+1;continue}}if(l===`<`&&!r.startsWith(`<-`)){let e=r.match(/^<([^<>]+)>/);if(e){c(t===`abnf`?`special`:`id`,e[1].trim()),s+=e[0].length;continue}}if(t===`abnf`){let e=r.match(/^(\d*)\*(\d*)/)??r.match(/^(\d+)/);if(e){let t=!e[0].includes(`*`),n=e[1]?Number(e[1]):0,r=t?n:e[2]?Number(e[2]):1/0;c(`rep`,e[0],{min:n,max:r}),s+=e[0].length;continue}}let f=r.match(/^\d+/);if(f){c(`num`,f[0]),s+=f[0].length;continue}let p=r.match(du);if(p){c(`id`,p[0]),s+=p[0].length;continue}let m=r.match(/^(::=|:=|<-|=\/|[=|/,;.()[\]{}?*+\-&!←:])/);m?(c(`op`,m[0]===`:`?`=`:m[0]),s+=m[0].length):(n(o,`railroad: unexpected "${l}"`),s++)}}),r}var pu=e=>e.length===1?e[0]:{k:`seq`,items:e};function mu(e,t){return t===1/0?`${e}+×`:e===t?`${e}×`:`${e}–${t}×`}function hu(e,t,n){if(n===0)return{k:`skip`};if(t===0&&n===1)return{k:`opt`,item:e};if(t===1&&n===1)return e;if(n===1/0&&t<=1)return t?{k:`many`,item:e,min:1}:{k:`opt`,item:{k:`many`,item:e,min:1}};let r={k:`many`,item:e,min:1,label:mu(t,n)};return t===0?{k:`opt`,item:r}:r}function gu(e,t,n){let r=0,i=(t=0)=>e[r+t],a=(e,...t)=>!!e&&e.kind===`op`&&t.includes(e.v),o=(e=0)=>i(e)?.kind===`id`&&a(i(e+1),...uu),s=()=>!i()||a(i(),`;`)||t===`ebnf`&&a(i(),`.`)||o(),c=()=>i()?.line??e[e.length-1]?.line??0;function l(){let e=[u()];for(;a(i(),`|`,`/`);)r++,e.push(u());if(e.length===1)return e[0];let t=e.filter(e=>e.k!==`skip`);return t.length<e.length?t.length?{k:`opt`,item:t.length===1?t[0]:{k:`choice`,items:t}}:{k:`skip`}:{k:`choice`,items:e}}function u(){let e=[];for(;!s()&&!a(i(),`|`,`/`,`)`,`]`,`}`);){if(a(i(),`,`)){r++;continue}let t=r,o=d();o&&e.push(o),r===t&&(n(c(),`railroad: unexpected "${i().v}"`),r++)}return e.length?pu(e):{k:`skip`}}function d(){let e=f();if(e&&t===`ebnf`&&a(i(),`-`)){r++;let t=f();if(t)return{k:`seq`,items:[e,{k:`group`,item:t,label:`except`}]}}return e}function f(){let e=i();if(!e)return null;if(t===`peg`&&a(e,`&`,`!`)){r++;let t=f();return t?{k:`group`,item:t,label:e.v===`&`?`followed by`:`not followed by`}:null}if(e.kind===`rep`){r++;let t=f();return t?hu(t,e.min,e.max):null}if(e.kind===`num`&&a(i(1),`*`)){r+=2;let t=f(),n=Number(e.v);return t?hu(t,n,n):null}let n=p();if(!n)return null;for(;;){let e=i();if(a(e,`?`))n={k:`opt`,item:n};else if(a(e,`*`))n={k:`opt`,item:{k:`many`,item:n,min:1}};else if(a(e,`+`))n={k:`many`,item:n,min:1};else return n;r++}}function p(){let e=i();if(!e)return null;switch(e.kind){case`id`:return r++,{k:`nt`,text:e.v};case`str`:case`term`:return r++,{k:`term`,text:e.v};case`special`:return r++,{k:`special`,text:e.v};case`num`:return r++,{k:`term`,text:e.v}}if(t===`peg`&&a(e,`.`))return r++,{k:`special`,text:`any character`};let o={"(":`)`,"[":`]`,"{":`}`}[e.v];if(e.kind!==`op`||!o)return null;r++;let u=l();return a(i(),o)?r++:n(c(),`railroad: missing "${o}"`),e.v===`[`?{k:`opt`,item:u}:e.v===`{`?a(i(),`-`)&&t===`ebnf`&&(s()||!i(1)||i(1).kind===`op`)?(r++,{k:`many`,item:u,min:1}):{k:`opt`,item:{k:`many`,item:u,min:1}}:u}let m=[],h=new Map;for(;r<e.length;){if(!o()){let t=i();for(a(t,`;`,`.`)||n(t.line,`railroad: expected a rule like \`name = …;\`, found "${t.v}"`),r++;r<e.length&&!o();)r++;continue}let t=i(),u=i(1).v;r+=2;let d=l();i()&&!s()&&n(c(),`railroad: unexpected "${i().v}"`),a(i(),`;`,`.`)&&r++;let f=h.get(t.v);if(u===`=/`&&f){f.expr={k:`choice`,items:[...f.expr.k===`choice`?f.expr.items:[f.expr],d]};continue}let p={name:t.v,expr:d,line:t.line};f&&n(t.line,`railroad: rule "${t.v}" is defined twice`),h.set(t.v,p),m.push(p)}for(let e of m)e.expr=_u(e.expr);return m}function _u(e){switch(e.k){case`seq`:{let t=e.items.map(_u).flatMap(e=>e.k===`seq`?e.items:e.k===`skip`?[]:[e]);return t.length?pu(t):{k:`skip`}}case`choice`:{let t=e.items.map(_u).flatMap(e=>e.k===`choice`?e.items:[e]);if(t.some(e=>e.k===`skip`)){let e=t.filter(e=>e.k!==`skip`);return e.length?_u({k:`opt`,item:e.length===1?e[0]:{k:`choice`,items:e}}):{k:`skip`}}return t.length===1?t[0]:{k:`choice`,items:t}}case`opt`:{let t=_u(e.item);return t.k===`skip`||t.k===`opt`?t:{k:`opt`,item:t}}case`many`:case`group`:return{...e,item:_u(e.item)};default:return e}}function vu(e,t,n){return gu(fu(e,t,n),t,n)}var yu=e=>e.includes(`"`)?`'${e}'`:`"${e}"`;function bu(e){let t=(e,t)=>t.k===`seq`||t.k===`choice`?`( ${e} )`:e;switch(e.k){case`term`:return yu(e.text);case`nt`:return e.text;case`special`:return`? ${e.text} ?`;case`skip`:return`( )`;case`seq`:return e.items.map(e=>e.k===`choice`?`( ${bu(e)} )`:bu(e)).join(` , `);case`choice`:return e.items.map(e=>bu(e)).join(` | `);case`opt`:return e.item.k===`many`&&!e.item.label?`{ ${bu(e.item.item)} }`:`[ ${bu(e.item)} ]`;case`many`:return`${t(bu(e.item),e.item)}+`;case`group`:return bu(e.item)}}var xu=e=>({R:e*.55,H:e*1.9,gap:e*.85,vs:e*.55}),Su=(e,t)=>`<path d="${e}" fill="none" stroke="${t.edge.ink}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>`,Cu=(e,t,n,r)=>t-e>.01?Su(`M${L(e)},${L(n)}H${L(t)}`,r):``;function wu(e,t){let{T:n,fs:r,measure:i}=t,{R:a,H:o,gap:s,vs:c}=xu(r),l=(e,a)=>{let s=a===`term`,c=s?r*.92:r,l=a===`nt`?500:400,u=i(e,c,l,s),d=Math.max(o,u+r*1.5),f=a===`term`?t.terminal:a===`nt`?t.nonterminal:null;return{w:d,up:o/2,down:o/2,draw(r,i,u){let p=a===`term`?o/2:Math.min(n.radius,o/3),m=a===`special`?` stroke-dasharray="4 3"`:``,h=f?.fill??n.background,_=f?.stroke??n.node.stroke,v=f?.text??n.node.sub,y=s?` font-family="${I(g)}"`:``,b=a===`special`?` font-style="italic"`:l===400?``:` font-weight="${l}"`,x=`<rect x="${L(r)}" y="${L(i-o/2)}" width="${L(d)}" height="${L(o)}" rx="${L(p)}" fill="${h}" stroke="${_}" stroke-width="1.4"${m}/><text x="${L(r+d/2)}" y="${L(i)}" dominant-baseline="central" text-anchor="middle" font-size="${L(c)}" fill="${v}"${y}${b} xml:space="preserve">${I(e)}</text>`;a===`nt`&&t.names.has(e)&&(x=`<a href="#${I(t.idPrefix+Eu(e))}">${x}</a>`),u.push(x)}}};switch(e.k){case`term`:return l(e.text,`term`);case`nt`:return l(e.text,`nt`);case`special`:return l(e.text,`special`);case`skip`:return{w:0,up:0,down:0,draw(){}};case`seq`:return Tu(e.items.map(e=>wu(e,t)),s,n);case`choice`:case`opt`:{let r=e.k===`opt`?[wu(e.item,t),{w:0,up:0,down:0,draw(){}}]:e.items.map(e=>wu(e,t)),i=e.k===`opt`?[r[1]]:[],o=r[0],s=e.k===`opt`?[]:r.slice(1),l=Math.max(...r.map(e=>e.w)),u=l+4*a,d=[],f=0,p=o;for(let e of i)f-=Math.max(2*a,p.up+e.down+c),d.push(f),p=e;let m=[...d];f=0,p=o;let h=[];for(let e of s)f+=Math.max(2*a,p.down+e.up+c),h.push(f),p=e;return{w:u,up:Math.max(o.up,...i.map((e,t)=>e.up-m[t])),down:Math.max(o.down,...s.map((e,t)=>e.down+h[t])),draw(e,t,r){let c=(i,o)=>{let s=e+2*a+(l-i.w)/2;if(o){let c=o>0?1:-1,l=o-2*a*c;r.push(Su(`M${L(e)},${L(t)}a${L(a)},${L(a)} 0 0 ${+(c>0)} ${L(a)},${L(a*c)}v${L(l)}a${L(a)},${L(a)} 0 0 ${c>0?0:1} ${L(a)},${L(a*c)}H${L(s)}`,n),Su(`M${L(s+i.w)},${L(t+o)}H${L(e+u-2*a)}a${L(a)},${L(a)} 0 0 ${c>0?0:1} ${L(a)},${L(-a*c)}v${L(-l)}a${L(a)},${L(a)} 0 0 ${+(c>0)} ${L(a)},${L(-a*c)}`,n))}else r.push(Cu(e,s,t,n),Cu(s+i.w,e+u,t,n));i.draw(s,t+o,r)};c(o,0),i.forEach((e,t)=>c(e,m[t])),s.forEach((e,t)=>c(e,h[t]))}}}case`many`:{let i=wu(e.item,t),o=Math.max(2*a,i.down+c),s=e.label?r*1.2:0,l=i.w+2*a;return{w:l,up:i.up,down:o+s,draw(t,c,u){u.push(Cu(t,t+a,c,n),Cu(t+a+i.w,t+l,c,n),Su(`M${L(t+a+i.w)},${L(c)}a${L(a)},${L(a)} 0 0 1 ${L(a)},${L(a)}v${L(o-2*a)}a${L(a)},${L(a)} 0 0 1 ${L(-a)},${L(a)}H${L(t+a)}a${L(a)},${L(a)} 0 0 1 ${L(-a)},${L(-a)}v${L(-(o-2*a))}a${L(a)},${L(a)} 0 0 1 ${L(a)},${L(-a)}`,n));let d=t+l/2,f=r*.28;u.push(On({x:d-f*.6,y:c+o},Math.PI,`open`,n.edge.ink,1.6,f*1.7)),e.label&&u.push(`<text x="${L(d)}" y="${L(c+o+s*.6)}" dominant-baseline="central" text-anchor="middle" font-size="${L(r*.78)}" fill="${n.node.sub}">${I(e.label)}</text>`),i.draw(t+a,c,u)}}}case`group`:{let a=wu(e.item,t),o=r*.5,s=r*1.1,c=i(e.label,r*.75,400,!1),l=Math.max(a.w+2*o,c+2*o);return{w:l,up:a.up+o+s,down:a.down+o,draw(t,i,c){let u=t+(l-a.w)/2,d=i-a.up-o-s;c.push(`<rect x="${L(t)}" y="${L(d)}" width="${L(l)}" height="${L(s+a.up+a.down+2*o)}" rx="${L(Math.min(n.radius,o))}" fill="none" stroke="${n.group.stroke}" stroke-width="1.2" stroke-dasharray="4 3"/>`,`<text x="${L(t+o)}" y="${L(d+s*.6)}" dominant-baseline="central" font-size="${L(r*.75)}" fill="${n.node.sub}" font-style="italic">${I(e.label)}</text>`,Cu(t,u,i,n),Cu(u+a.w,t+l,i,n)),a.draw(u,i,c)}}}}}function Tu(e,t,n){let r=e.filter(e=>e.w>0);return r.length?r.length===1?r[0]:{w:r.reduce((e,t)=>e+t.w,0)+t*(r.length-1),up:Math.max(...r.map(e=>e.up)),down:Math.max(...r.map(e=>e.down)),draw(e,i,a){let o=e;r.forEach((e,r)=>{r&&(a.push(Cu(o,o+t,i,n)),o+=t),e.draw(o,i,a),o+=e.w})}}:{w:0,up:0,down:0,draw(){}}}var Eu=e=>`rule-`+e.replace(/[^\p{L}\p{N}_-]+/gu,`_`);function Du(e,t,n){let{fs:r}=t,{R:i,gap:a,vs:o}=xu(r),s=r*1.2,c=r*1.9,l=e.expr,u=l.k===`seq`?l.items.map(e=>wu(e,t)):[wu(l,t)],d=[[]],f=0;for(let e of u){let t=d[d.length-1],r=(t.length?a:0)+e.w;n>0&&t.length&&f+r>n?(d.push([e]),f=e.w):(t.push(e),f+=r)}let p=d.map(e=>Tu(e,a,t.T)),m=[],h=c+Math.max(p[0].up,r*.6);p.forEach((e,t)=>{if(t){let n=p[t-1];h+=n.down+o+Math.max(2*i,e.up+o)+2*i}m.push(h)});let g=p[p.length-1],_=p.length>1;return{rule:e,rows:p,ys:m,w:s+(_?2*i:0)+Math.max(...p.map(e=>e.w))+(_?2*i:0)+s,h:m[m.length-1]+Math.max(g.down,r*.6)}}function Ou(e,t,n,r,i){let{T:a,fs:o}=r,{R:s,vs:c}=xu(o),l=o*1.2,u=e.rows.length>1,d=t+l+(u?2*s:0);i.push(`<text id="${I(r.idPrefix+Eu(e.rule.name))}" x="${L(t)}" y="${L(n+o*.75)}" dominant-baseline="central" font-size="${L(o*1.05)}" font-weight="700" fill="${a.node.text}" xml:space="preserve">${I(e.rule.name)}</text>`);let f=(e,t)=>`<path d="M${L(e)},${L(t-o*.6)}V${L(t+o*.6)}M${L(e+o*.3)},${L(t-o*.6)}V${L(t+o*.6)}" stroke="${a.edge.ink}" stroke-width="1.8" stroke-linecap="round"/>`;e.rows.forEach((r,l)=>{let u=n+e.ys[l];l===0&&i.push(f(t+o*.1,u),Cu(t+o*.4,d,u,a)),r.draw(d,u,i);let p=d+r.w;if(l===e.rows.length-1){let n=t+e.w-o*.4;i.push(Cu(p,n,u,a),f(n,u));return}let m=n+e.ys[l+1],h=u+r.down+c+s,g=d+Math.max(...e.rows.map(e=>e.w));i.push(Su(`M${L(p)},${L(u)}H${L(g)}a${L(s)},${L(s)} 0 0 1 ${L(s)},${L(s)}V${L(h-s)}a${L(s)},${L(s)} 0 0 1 ${L(-s)},${L(s)}H${L(d-s)}a${L(s)},${L(s)} 0 0 0 ${L(-s)},${L(s)}V${L(m-s)}a${L(s)},${L(s)} 0 0 0 ${L(s)},${L(s)}H${L(d)}`,a))})}var ku=/^(?:::=|:=|=\/|<-|=|←|:)/;function Au(e){let t=[],n=0,r=!1,i=0,a=(a,o)=>{t.push({t:e.slice(n,n+o),kind:a,sp:r,nl:i,start:n,end:n+o}),n+=o,r=!1,i=0};for(;n<e.length;){let o=e[n],s=e.slice(n);if(/\s/.test(o)){r=!0,i+=+(o===`
|
|
7
|
+
`),n++;continue}if(s.startsWith(`(*`)||s.startsWith(`/*`))return null;let c=s.match(/^"(?:[^"\\\n]|\\.)*"|^'(?:[^'\\\n]|\\.)*'/);if(c){a(`str`,c[0].length);continue}if(o===`"`||o===`'`)return null;let l=t[t.length-1];if(o===`?`&&(!l||/^(?:open|sep|def|end)$/.test(l.kind))){let e=s.indexOf(`?`,1);if(e>0&&!s.slice(0,e).includes(`
|
|
8
|
+
`)){a(`str`,e+1);continue}}let u=s.match(/^<[^<>\n]+>(?!-)/)??s.match(/^[\p{L}_][\p{L}\p{N}_-]*|^\d+/u);if(u&&!s.startsWith(`<-`)){a(`word`,u[0].length);continue}let d=s.match(ku);d?a(`def`,d[0].length):a(`([{`.includes(o)?`open`:`)]}`.includes(o)?`close`:o===`,`||o===`|`?`sep`:o===`;`||o===`.`?`end`:`word`,1)}return t}var ju=e=>e.map((e,t)=>(t&&e.sp?` `:``)+e.t).join(``);function Mu(e,t){let n=[[]],r=0;for(let i of e)r+=i.kind===`open`?1:i.kind===`close`?-1:0,r===0&&i.kind===`sep`&&i.t===t?n.push([]):n[n.length-1].push(i);return n}function Nu(e,t,n,r,i){let a=[],o=e+t[0];for(let e of t.slice(1))(o+n+e).length>i?(a.push(o+n.trimEnd()),o=r+e):o+=n+e;return a.push(o),a}function Pu(e,t,n,r,i){let a=r===`;`?` ;`:r,o=`${e} ${t} ${ju(n)}${a}`;if(o.length<=i)return[o];let s=n.some((e,t)=>e.kind===`sep`&&e.t===`,`&&e.sp&&t)?` , `:`, `,c=Mu(n,`|`);if(c.length>1&&c.every(e=>Mu(e,`,`).length===1)){let n=Nu(`${e} ${t} `,c.map(ju),` | `,` | `,i);for(let e=0;e<n.length-1;e++)n[e]=n[e].replace(/ \|$/,``);return n[n.length-1]+=a,n}let l=[];return c.forEach((n,r)=>{let a=Mu(n,`,`).map(ju),o=r===0?`${e} ${t} `:` | `;l.push(...Nu(o,a,s,c.length>1?` `:` `,i))}),l[l.length-1]+=a,l}function Fu(e,t){let n=e.join(`
|
|
9
|
+
`),r=Au(n);if(!r)return null;let i=[],a=[],o=0;for(let e of r)o+=e.kind===`open`?1:e.kind===`close`?-1:0,a.push(e),o===0&&e.kind===`end`&&(i.push(a),a=[]);if(a.length||o)return null;let s=[];for(let e of i){let[r,i]=e,a=e.slice(2,-1);if(r?.kind!==`word`||i?.kind!==`def`||!a.length||a.some(e=>e.kind===`def`))return null;s.length&&r.nl>1&&s.push(``);let o=n.slice(r.start,e[e.length-1].end).split(`
|
|
10
|
+
`),c=o.length>1&&o.every(e=>e.trimEnd().length<=t);s.push(...c?o.map(e=>e.trimEnd()):Pu(r.t,i.t,a,e[e.length-1].t,t))}return s}var Iu=[`ebnf`,`abnf`,`peg`];function Lu(e,t,n){return t&&e.tone(t)||n}function Ru(e,t){let{theme:n}=e,r=e.fs*.95,i=e.props,a=i.wrap===`0`?0:e.width??ot(i.wrap)??r*48;return{T:n,fs:r,measure:e.measure,terminal:Lu(n,i.terminal,n.tone(`green`)??{fill:n.node.fill,stroke:n.accent,text:n.node.text}),nonterminal:Lu(n,i.nonterminal,{fill:n.node.fill,stroke:n.node.stroke,text:n.node.text}),idPrefix:e.idPrefix??``,names:t,wrap:a,gap:r*1.4}}var zu=ei(function(e,t){let n=Ru(t,new Set(e.rules.map(e=>e.name))),r=e.rules.map(e=>Du(e,n,n.wrap)),i=[],a=0;for(let e of r)i.push(a),a+=e.h+n.gap;return{c:n,boxes:r,ys:i,w:Math.max(0,...r.map(e=>e.w)),h:Math.max(0,a-n.gap)}});function Bu(e,t,n){let r=n.rules.findIndex(e=>e.name===(`id`in t?t.id:void 0)),i=n.rules.map(e=>e.line);if(r<0||t.op===`set`||t.op===`add`||i.some((e,t)=>t&&e<=i[t-1]))return null;let a=t=>{let n=i[t+1]??e.length;for(;n>i[t]+1&&!e[n-1].trim();)n--;return[i[t],n]},[o,s]=a(r);if(t.op===`remove`)return{body:[...e.slice(0,o),...e.slice(s)]};let c=t.op===`up`?r-1:r+1;if(c<0||c>=i.length)return null;let[l,u]=c<r?[a(c),[o,s]]:[[o,s],a(c)];return{body:[...e.slice(0,l[0]),...e.slice(u[0],u[1]),...e.slice(l[1],u[0]),...e.slice(l[0],l[1]),...e.slice(u[1])],id:n.rules[r].name}}var Vu={name:`railroad`,panels:[{name:`railroad`,guide:'one grammar rule per statement, `name = definition ;`, drawn as a railroad diagram each. EBNF (default): `"x"` terminals, names for rules, `,` or a space in sequence, `|` alternatives, `[a]` or `a?` optional, `{a}` or `a*` zero or more, `a+` one or more, `( )` groups, `? text ?` a special sequence, `(* comments *)`. `notation: abnf` reads RFC 5234 (`/`, `*a`, `1*a`, `%x41`, `; comment`), `notation: peg` reads `Name <- a / b` with `&a`, `!a` and `.`. Keep a lone `}` off its own line: it ends the panel.',syntax:`railroad id "Title" [notation: ebnf] { rule = "a" , ( b | c ) , { d } , [ e ] ; }`,options:{notation:Iu,terminal:`color`,nonterminal:`color`,wrap:`number`},help:{notation:`grammar notation of the body: ebnf (default), abnf or peg`,terminal:`colour of terminal pills`,nonterminal:`colour of nonterminal boxes`,wrap:`break a rule wider than this many px into rows; 0 never. A panel width sets it`},parse(e,t,n){let r=String(t.notation??`ebnf`).toLowerCase(),i=Iu.includes(r)?r:`ebnf`;return{notation:i,rules:vu(e,i,n)}},parts(e){return e.rules.map(e=>({id:e.name,label:e.name,kind:`rule`,color:!1,actions:[`up`,`down`,`remove`]}))},editPart:Bu,format(e,t){return String(t.notation??`ebnf`).toLowerCase()===`ebnf`?Fu(e,72):null},measure(e,t){let n=zu(e,t);return{w:n.w,h:n.h}},render(e,t,n){let r=zu(e,n),i=[];return r.boxes.forEach((e,n)=>Ou(e,t.x,t.y+r.ys[n],r.c,i)),i.join(``)}}]},Hu=[`build`,`buy`,`outsource`,`market`,`inertia`],Uu=[{label:`Genesis`,end:.174},{label:`Custom built`,end:.4},{label:`Product (+rental)`,end:.7},{label:`Commodity (+utility)`,end:1}],Wu=String.raw`-?\d*\.?\d+`,Gu=String.raw`\[\s*(${Wu})\s*,\s*(${Wu})\s*\]`,Ku=String.raw`("[^"]*"|[^"[\]]+?)`,qu=new RegExp(String.raw`^(anchor|component|market|submap|ecosystem)\s+${Ku}\s*${Gu}\s*(.*)$`,`i`),Ju=new RegExp(String.raw`^component\s+${Ku}\s*\[\s*(${Wu})\s*\]\s*(.*)$`,`i`),Yu=new RegExp(String.raw`^pipeline\s+${Ku}\s*(?:\[\s*(${Wu})\s*,\s*(${Wu})\s*\])?\s*\{?\s*$`,`i`),Xu=new RegExp(String.raw`^evolve\s+${Ku}\s+(${Wu})\s*(?:label\s*${Gu})?\s*$`,`i`),Zu=new RegExp(String.raw`^note\s+("[^"]*"|.+?)\s*${Gu}\s*$`,`i`),Qu=new RegExp(String.raw`^annotations\s*${Gu}\s*$`,`i`),$u=/^annotation\s+(\d+)\s*,?\s*(\[.*\])\s*(.*)$/i,ed=new RegExp(String.raw`^(accelerator|deaccelerator)\s+("[^"]*"|.+?)\s*${Gu}\s*$`,`i`),td=/^evolution\s+(.+)$/i,nd=/^("[^"]*"|.+?)\s*(-\.->|-->|->|\+<>|\+<|\+'([^']*)'>|\+>)\s*("[^"]*"|.+?)\s*(?:;\s*(.*))?$/,rd=new RegExp(String.raw`label\s*${Gu}`,`i`);function id(e,t,n,r){return e>=0&&e<=1?e:(r(n,`wardley: ${t} ${e} is outside 0 to 1`),Math.min(1,Math.max(0,Number.isFinite(e)?e:0)))}function ad(e,t,n){let r=e.split(/\s*->\s*/).map(e=>e.trim());if(r.length<2){n(t,`wardley: evolution needs at least two stages, e.g. "evolution Genesis -> Custom -> Product -> Commodity"`);return}let i=r.map(e=>{let t=e.match(/^(.*?)\s*@\s*(-?\d*\.?\d+)$/);return{label:H(t?t[1]:e),end:t?Number(t[2]):NaN}});i[i.length-1].end=Number.isFinite(i[i.length-1].end)?i[i.length-1].end:1;let a=0;for(let e=0;e<i.length;e++){if(!Number.isFinite(i[e].end)){let t=e;for(;!Number.isFinite(i[t].end);)t++;i[e].end=a+(i[t].end-a)/(t-e+1)}if(i[e].end<=a||i[e].end>1){n(t,`wardley: stage "${i[e].label}" must end after the one before it and at most at 1`);return}a=i[e].end}return i[i.length-1].end=1,i}function od(e,t){let n={nodes:[],links:[],evolves:[],notes:[],annotations:[],forces:[],pipelines:[],stages:Uu},r=new Set([`size`]),i,a=e=>{n.nodes.some(t=>t.name===e.name)?t(e.line,`wardley: "${e.name}" is already on the map`):n.nodes.push({...e,id:Ba(e.name,r,`c${n.nodes.length+1}`,/^c\d+$/)})},o=(e,n)=>{let[r,i]=Vr(e.trim(),Ur),a=r,o=a.match(rd),s=o?{x:Number(o[1]),y:Number(o[2])}:void 0;a=a.replace(rd,``);let c=[];for(let e of a.matchAll(/\(\s*([\w-]+)\s*\)/g)){let r=e[1].toLowerCase();Hu.includes(r)?c.push(r):t(n,`wardley: unknown decorator "(${e[1]})" (use ${Hu.map(e=>`(${e})`).join(`, `)})`)}return a=a.replace(/\(\s*[\w-]+\s*\)/g,``).trim(),a&&t(n,`wardley: cannot read "${a}" after the coordinates`),{label:s,decorators:c,tone:i.color}};e.forEach((e,r)=>{let s=e.trim();if(!s)return;let c=e.length-e.trimStart().length;i&&c<=i.indent&&(i=void 0);let l;if(i&&(l=s.match(Ju))){let e=n.nodes.find(e=>e.name===i.parent);a({name:H(l[1]),kind:`component`,vis:e?.vis??.5,evo:id(Number(l[2]),`evolution`,r,t),line:r,pipeline:i.parent,...o(l[3],r)})}else if(l=s.match(qu)){let e=l[1].toLowerCase(),n=o(l[5],r);e===`market`&&!n.decorators.includes(`market`)&&n.decorators.unshift(`market`),a({name:H(l[2]),kind:e===`anchor`?`anchor`:`component`,vis:id(Number(l[3]),`visibility`,r,t),evo:id(Number(l[4]),`evolution`,r,t),line:r,...n})}else if(l=s.match(Yu)){let e=H(l[1]);n.pipelines.push({parent:e,span:l[2]===void 0?void 0:[id(Number(l[2]),`evolution`,r,t),id(Number(l[3]),`evolution`,r,t)],line:r}),i=l[2]===void 0?{parent:e,indent:c}:void 0}else if(l=s.match(Xu))n.evolves.push({name:H(l[1]),evo:id(Number(l[2]),`evolution`,r,t),line:r});else if(l=s.match(Zu))n.notes.push({text:H(l[1]),vis:id(Number(l[2]),`visibility`,r,t),evo:id(Number(l[3]),`evolution`,r,t),line:r});else if(l=s.match(Qu))n.annotationsAt=[id(Number(l[1]),`visibility`,r,t),id(Number(l[2]),`evolution`,r,t)];else if(l=s.match($u)){let e=[...l[2].matchAll(new RegExp(Gu,`g`))].map(e=>[id(Number(e[1]),`visibility`,r,t),id(Number(e[2]),`evolution`,r,t)]);if(!e.length){t(r,`wardley: annotation ${l[1]} needs a place, e.g. "annotation ${l[1]},[0.5, 0.5] text"`);return}n.annotations.push({n:l[1],at:e,text:H(l[3]),line:r})}else if(l=s.match(ed))n.forces.push({kind:l[1].toLowerCase(),text:H(l[2]),vis:id(Number(l[3]),`visibility`,r,t),evo:id(Number(l[4]),`evolution`,r,t),line:r});else if(l=s.match(td))n.stages=ad(l[1],r,t)??n.stages;else if(/^(title|size|style)\b/i.test(s))t(r,`wardley: "${s.split(/\s/)[0]}" is not part of the body (use the panel title and the size handle)`);else if(l=s.match(nd)){let e=l[2];n.links.push({from:H(l[1]),to:H(l[4]),dashed:e===`-.->`,arrow:e===`+<>`?`both`:e===`+<`?`from`:e.startsWith(`+`)?`to`:`none`,label:l[3]??(l[5]?H(l[5]):void 0),line:r})}else t(r,`wardley: cannot read "${s}" (expected "component Name [visibility, evolution]", "A -> B", "evolve Name 0.8" or "note text [v, e]")`)});let s=new Set(n.nodes.map(e=>e.name));return n.links=n.links.filter(e=>{let n=[e.from,e.to].find(e=>!s.has(e));return n&&t(e.line,`wardley: link to unknown component "${n}"`),!n}),n.evolves=n.evolves.filter(e=>(s.has(e.name)||t(e.line,`wardley: cannot evolve unknown component "${e.name}"`),s.has(e.name))),n.pipelines=n.pipelines.filter(e=>(s.has(e.parent)||t(e.line,`wardley: pipeline for unknown component "${e.parent}"`),s.has(e.parent))),n}var sd=ei(function(e,t){let{measure:n}=t,r=t.fs*.85,i=t.offsets.size??{x:0,y:0},a=Math.max(r*24,r*46+i.x),o=Math.max(r*16,r*28+i.y),s=r*.42,c=r*.85,l=r*2.2,u=s*2+r*.6,d=new Map(e.nodes.map(e=>[e.name,e])),f=e=>t.offsets[e.id]??{x:0,y:0},p=new Map;for(let i of e.nodes){let e=i.pipeline?d.get(i.pipeline):void 0,l=f(i),m=i.evo*a+l.x,h=(1-i.vis)*o+l.y;if(e){let t=f(e);h=(1-e.vis)*o+t.y+s+r*.3+u/2,m=i.evo*a+l.x}let g=z(F(i.name),i.kind===`anchor`?r:c,t.theme.mono,n,i.kind===`anchor`?700:400);if(i.kind===`anchor`)p.set(i.name,{x:m,y:h,lx:m,ly:h,lw:g,anchor:`middle`});else if(i.label)p.set(i.name,{x:m,y:h,lx:m+i.label.x,ly:h+i.label.y,lw:g,anchor:`start`});else if(e)p.set(i.name,{x:m,y:h,lx:m,ly:h+u/2+c*.8,lw:g,anchor:`middle`});else{let e=(i.decorators.some(e=>e===`build`||e===`buy`||e===`outsource`)?s*2.1:s)+r*(i.decorators.includes(`inertia`)?1.1:.3);p.set(i.name,{x:m,y:h,lx:m+e,ly:h-s-c*.35,lw:g,anchor:`start`})}}for(let t of e.pipelines){let n=e.nodes.filter(e=>e.pipeline===t.parent&&!e.label).map(e=>p.get(e.name)).sort((e,t)=>e.x-t.x),i=[];for(let e of n){let t=i.findIndex(t=>e.lx-e.lw/2>t+r*.5);t<0&&(t=i.length,i.push(0)),i[t]=e.lx+e.lw/2,e.ly+=t*c*1.25}}let m=e.evolves.map(e=>{let r=p.get(e.name),i=z(F(e.name),c,t.theme.mono,n);return{...e,x:e.evo*a,y:r.y,lw:i}}),h=0,g=a,_=0,v=(e,t,n)=>{h=Math.min(h,e),g=Math.max(g,t),_=Math.min(_,n)};for(let e of p.values()){let t=e.anchor===`middle`?e.lx-e.lw/2:e.lx;v(t,t+e.lw,e.ly-c)}for(let e of m)v(e.x,e.x+s+r*.3+e.lw,e.y-s-c*1.35);let y=e.notes.map(e=>z(F(e.text),c,t.theme.mono,n,600));e.notes.forEach((e,t)=>v(e.evo*a,e.evo*a+y[t],(1-e.vis)*o-c));let b=r*4;for(let i of e.forces){let e=n(i.text,c,400,t.theme.mono);v(i.evo*a-Math.max(b,e)/2,i.evo*a+Math.max(b,e)/2,(1-i.vis)*o-r)}let x=r*.8,S=x,C=e.annotations.map(e=>F(`${e.n}. ${e.text}`)),w=yi(n),T=Math.max(0,...C.map(e=>z(e,x,t.theme.mono,w)))+S*2,E=e.annotations.length?e.annotations.length*x*1.4+r*.8:0;if(e.annotationsAt){let t=e.annotationsAt[1]*a;v(t,t+T,(1-e.annotationsAt[0])*o)}let D=Math.max(0,-h)+r*.4,O=Math.max(0,-_)+r*.4,k=r*3.2,A=e.annotations.length&&!e.annotationsAt?E+r*.6:0;return{fs:r,lfs:c,r:s,W:a,H:o,pipeH:u,left:l+D,top:O,bottom:k,pos:p,evolved:m,noteW:y,forceW:b,listFs:x,listPad:S,list:C,listW:T,listH:E,w:l+D+g+r*.4,h:O+o+k+A}});function cd(e,t,n,r){return On(t,Math.atan2(t.y-e.y,t.x-e.x),`arrow`,r,1,n)}function ld(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y)||1;return{x:e.x+(t.x-e.x)/r*n,y:e.y+(t.y-e.y)/r*n}}function ud(e,t,n){let r=n.theme,i=sd(e,n),{fs:a,lfs:o,r:s,W:c,H:l}=i,u=t.x+i.left,d=t.y+i.top,f=e=>u+e,p=e=>d+e,h=P(r),g=r.node.sub,_=R(`red`,r,`#d33`),v=r.background===`none`?r.node.fill:r.background,y=[];y.push(`<rect x="${L(f(0))}" y="${L(p(0))}" width="${L(c)}" height="${L(l)}" fill="${r.group.fill}" stroke="none"/>`);let b=0;for(let t of e.stages){let e=b*c,n=t.end*c;t.end<1&&y.push(`<path d="M${L(f(n))},${L(p(0))}V${L(p(l))}" stroke="${r.node.sub}" stroke-opacity="0.45" stroke-width="1" stroke-dasharray="4 4"/>`),y.push(`<text x="${L(f((e+n)/2))}" y="${L(p(l)+a*.85)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.8)}" fill="${r.node.sub}">${I(t.label)}</text>`),b=t.end}let x=r.node.text;y.push(`<path d="M${L(f(0))},${L(p(0))}V${L(p(l))}H${L(f(c))}" fill="none" stroke="${x}" stroke-width="1.5"/>`,cd({x:f(0),y:p(l)},{x:f(c)+a*.4,y:p(l)},a*.55,x),cd({x:f(0),y:p(l)},{x:f(0),y:p(0)-a*.4},a*.55,x),`<text x="${L(f(c))}" y="${L(p(l)+a*2.2)}" dominant-baseline="central" text-anchor="end" font-size="${L(a*.85)}" font-weight="700" fill="${x}">Evolution</text>`);let S=f(0)-a*.9,C=(e,t,n,i=!1)=>`<text x="${L(S)}" y="${L(e)}" dominant-baseline="central" text-anchor="${n}" font-size="${L(a*.8)}"${i?` font-weight="700"`:``} fill="${i?x:r.node.sub}" transform="rotate(-90 ${L(S)} ${L(e)})">${t}</text>`;y.push(C(p(0),`Visible`,`end`),C(p(l/2),`Value chain`,`middle`,!0),C(p(l),`Invisible`,`start`));for(let t of e.pipelines){let n=i.pos.get(t.parent),r=e.nodes.filter(e=>e.pipeline===t.parent).map(e=>i.pos.get(e.name).x),o=t.span?t.span[0]*c:Math.min(n.x,...r)-s*2.5,l=t.span?t.span[1]*c:Math.max(n.x,...r)+s*2.5,u=n.y+s+a*.3;y.push(`<path d="M${L(f(n.x))},${L(p(n.y+s))}V${L(p(u))}" stroke="${g}" stroke-width="1"/>`,`<rect x="${L(f(o))}" y="${L(p(u))}" width="${L(l-o)}" height="${L(i.pipeH)}" fill="${v}" stroke="${x}" stroke-width="1.2"/>`)}let w=e=>e.kind===`anchor`?a*.75:s+1,T=new Map(e.nodes.map(e=>[e.name,e]));for(let t of e.links){let e=i.pos.get(t.from),n=i.pos.get(t.to),o={x:f(e.x),y:p(e.y)},s={x:f(n.x),y:p(n.y)},c=ld(o,s,w(T.get(t.from))),l=ld(s,o,w(T.get(t.to))),u=t.arrow!==`none`,d=u?R(`blue`,r,r.accent):g;y.push(`<path d="M${L(c.x)},${L(c.y)}L${L(l.x)},${L(l.y)}" stroke="${d}" stroke-width="${u?2:1}"${t.dashed?` stroke-dasharray="5 4"`:``}${u?` stroke-opacity="0.8"`:``}/>`),(t.arrow===`to`||t.arrow===`both`)&&y.push(cd(c,l,a*.6,d)),(t.arrow===`from`||t.arrow===`both`)&&y.push(cd(l,c,a*.6,d)),t.label&&y.push(`<text x="${L((c.x+l.x)/2+a*.3)}" y="${L((c.y+l.y)/2-a*.5)}" dominant-baseline="central" font-size="${L(a*.75)}" fill="${r.node.sub}" xml:space="preserve">${B(F(t.label),{...h,text:r.node.sub},r)}</text>`)}for(let e of i.evolved){let t=i.pos.get(e.name),n={x:f(t.x),y:p(t.y)},c={x:f(e.x),y:p(e.y)},l=ld(n,c,s+2),u=ld(c,n,s+2);y.push(`<path d="M${L(l.x)},${L(l.y)}L${L(u.x)},${L(u.y)}" stroke="${_}" stroke-width="1.5" stroke-dasharray="5 4"/>`,cd(l,u,a*.55,_),`<circle cx="${L(c.x)}" cy="${L(c.y)}" r="${L(s)}" fill="${v}" stroke="${_}" stroke-width="1.5"/>`,`<text x="${L(c.x+s+a*.3)}" y="${L(c.y-s-o*.35)}" dominant-baseline="central" font-size="${L(o)}" xml:space="preserve">${B(F(e.name),{...h,text:_},r)}</text>`)}for(let t of e.nodes){let e=i.pos.get(t.name),n=f(e.x),c=p(e.y),l=R(t.tone,r,x);if(t.kind===`anchor`){y.push(`<text x="${L(n)}" y="${L(c)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" font-weight="700" xml:space="preserve">${B(F(t.name),{...h,text:l},r)}</text>`);continue}let u=s*2.1;for(let e of t.decorators){let i=`fill="${t.tone&&r.tone(t.tone)?.fill||m(`slate`,r.dark?800:200)||r.group.stroke}" stroke="${g}" stroke-width="1"`;if(e===`build`)y.push(`<path d="M${L(n)},${L(c-u)}L${L(n+u*.95)},${L(c+u*.6)}H${L(n-u*.95)}Z" ${i}/>`);else if(e===`buy`)y.push(`<path d="M${L(n)},${L(c-u)}L${L(n+u)},${L(c)}L${L(n)},${L(c+u)}L${L(n-u)},${L(c)}Z" ${i}/>`);else if(e===`outsource`){let e=u*.8;y.push(`<rect x="${L(n-e)}" y="${L(c-e)}" width="${L(e*2)}" height="${L(e*2)}" ${i}/>`)}else if(e===`inertia`){let e=n+s+a*.6;y.push(`<path d="M${L(e)},${L(c-s*1.8)}V${L(c+s*1.8)}" stroke="${x}" stroke-width="${L(a*.3)}"/>`)}}if(t.decorators.includes(`market`)){let e=s*1.6;y.push(`<circle cx="${L(n)}" cy="${L(c)}" r="${L(e)}" fill="${v}" stroke="${l}" stroke-width="1.5"/>`);for(let t=0;t<3;t++){let r=-Math.PI/2+t*Math.PI*2/3;y.push(`<circle cx="${L(n+Math.cos(r)*e*.48)}" cy="${L(c+Math.sin(r)*e*.48)}" r="${L(e*.24)}" fill="${l}"/>`)}}else y.push(`<circle cx="${L(n)}" cy="${L(c)}" r="${L(s)}" fill="${v}" stroke="${l}" stroke-width="1.5"/>`);y.push(`<text x="${L(f(e.lx))}" y="${L(p(e.ly))}" dominant-baseline="central" text-anchor="${e.anchor}" font-size="${L(o)}" xml:space="preserve">${B(F(t.name),{...h,text:R(t.tone,r,r.node.text)},r)}</text>`)}for(let t of e.forces){let e=f(t.evo*c),n=p((1-t.vis)*l),s=i.forceW/2,u=a*.45,d=t.kind===`accelerator`?1:-1,m=e+s*d,h=e+s*.35*d;y.push(`<path d="M${L(e-s*d)},${L(n-u)}H${L(h)}V${L(n-u*1.8)}L${L(m)},${L(n)}L${L(h)},${L(n+u*1.8)}V${L(n+u)}H${L(e-s*d)}Z" fill="${r.group.fill}" stroke="${x}" stroke-width="1.2"/>`,`<text x="${L(e)}" y="${L(n+u*1.8+o*.8)}" dominant-baseline="central" text-anchor="middle" font-size="${L(o)}" fill="${r.node.text}">${I(t.text)}</text>`)}e.notes.forEach(e=>{y.push(`<text x="${L(f(e.evo*c))}" y="${L(p((1-e.vis)*l))}" dominant-baseline="central" font-size="${L(o)}" font-weight="600" xml:space="preserve">${B(F(e.text),h,r)}</text>`)});let E=a*.55;for(let t of e.annotations)for(let[e,n]of t.at){let r=f(n*c),i=p((1-e)*l);y.push(`<circle cx="${L(r)}" cy="${L(i)}" r="${L(E)}" fill="${v}" stroke="${x}" stroke-width="1.2"/>`,`<text x="${L(r)}" y="${L(i)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.65)}" font-weight="700" fill="${x}">${I(t.n)}</text>`)}if(e.annotations.length){let t=e.annotationsAt?f(e.annotationsAt[1]*c):f(0),n=e.annotationsAt?p((1-e.annotationsAt[0])*l):p(l)+i.bottom;y.push(`<rect x="${L(t)}" y="${L(n)}" width="${L(i.listW)}" height="${L(i.listH)}" rx="3" fill="${v}" stroke="${r.group.stroke}" stroke-width="1"/>`),i.list.forEach((e,o)=>{y.push(`<text x="${L(t+i.listPad)}" y="${L(n+a*.4+i.listFs*1.4*(o+.5))}" dominant-baseline="central" font-size="${L(i.listFs)}" fill="${r.node.text}" xml:space="preserve">${B(e,h,r)}</text>`)})}return y.join(``)}var dd=/\[\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*\]/d,fd=/\[\s*(-?\d*\.?\d+)\s*\]/d,pd=e=>Number(Math.min(1,Math.max(0,e)).toFixed(3));function md(e,t,n,r){let i=e[t.line];if(i===void 0)return null;let a=[...e];if(t.pipeline){let e=fd.exec(i);if(!e?.indices?.[1])return null;let[n,o]=e.indices[1];return a[t.line]=i.slice(0,n)+pd(r)+i.slice(o),a}let o=dd.exec(i);if(!o?.indices?.[1]||!o.indices[2])return null;let[s,c]=o.indices[1],[l,u]=o.indices[2];return a[t.line]=i.slice(0,s)+pd(n)+i.slice(c,l)+pd(r)+i.slice(u),a}var hd={name:`wardley`,panels:[{name:`wardley`,guide:"A Wardley map in the OWM / Mermaid wardley-beta syntax. Coordinates are `[visibility, evolution]` from 0 to 1 (top is visible, right is commodity). `anchor Name [v, e]` is a user need, `component Name [v, e]` a component, followed by decorators `(build)`, `(buy)`, `(outsource)`, `(market)` or `(inertia)`, `label [dx, dy]` and a `[color]`. `A -> B` links the value chain, `A -.-> B` dashed, `A +> B`, `A +< B`, `A +<> B` and `A +'label'> B` are flows, `; text` labels a link. `evolve Name 0.8` draws where a component is heading, `note text [v, e]` a note, `accelerator text [v, e]` / `deaccelerator text [v, e]` a force, `annotation 1,[v, e] text` numbered markers (listed under the map, or at `annotations [v, e]`). `pipeline Name` followed by indented `component X [e]` lines puts components in a box under Name. `evolution Genesis -> Custom -> Product -> Commodity` renames the stages; `Custom@0.4` sets where one ends.",layoutParts:"a component or anchor by its name (lower case, `-` for spaces), else `c<n>`, moves by `DX DY`; `size DX DY` grows the map",syntax:`wardley id "Title" { anchor User [0.95, 0.6]; component Kettle [0.4, 0.35]; User -> Kettle; evolve Kettle 0.6 }`,parse:(e,t,n)=>od(e,n),measure(e,t){let n=sd(e,t);return{w:n.w,h:n.h}},render:ud,parts:e=>e.nodes.map(e=>({id:e.id,label:e.name,kind:e.kind,tone:e.tone})),editPart:ti((e,t,n,r)=>{let i=r.nodes.find(e=>e.id===t);if(!i||e[i.line]===void 0)return null;let a=[...e];return a[i.line]=Hr(e[i.line],`color`,n||null,Ur),a}),handles(e,t,n){let r=sd(e,n),i=t.x+r.left,a=t.y+r.top;return[...e.nodes.map(e=>{let t=r.pos.get(e.name);return{part:e.id,x:i+t.x,y:a+t.y,axis:e.pipeline?`x`:`xy`,title:`move ${e.name}`,editPosition:(t,n)=>md(t,e,e.vis-n.y/r.H,e.evo+n.x/r.W)}}),{part:`size`,x:i+r.W,y:a+r.H,title:`resize`}]}}]},gd=[`complex`,`complicated`,`chaotic`,`clear`,`confused`],_d={complex:{name:`Complex`,text:`Probe – Sense – Respond`,tone:`teal`},complicated:{name:`Complicated`,text:`Sense – Analyze – Respond`,tone:`blue`},clear:{name:`Clear`,text:`Sense – Categorize – Respond`,tone:`green`},chaotic:{name:`Chaotic`,text:`Act – Sense – Respond`,tone:`orange`},confused:{name:`Confusion`,text:`Disorder`,tone:`slate`}},vd={complex:`complex`,complicated:`complicated`,clear:`clear`,obvious:`clear`,simple:`clear`,chaotic:`chaotic`,chaos:`chaotic`,confused:`confused`,confusion:`confused`,disorder:`confused`},yd=RegExp(`^(${Object.keys(vd).join(`|`)})\\b\\s*(?:\\[([^\\]]*)\\])?\\s*(?::\\s*(.*))?$`,`i`),bd=/^("[^"]*"|.+?)\s*(-\.->|-->|->)\s*("[^"]*"|.+?)\s*(?::\s*(.*))?$/,xd=/^[-*]\s+/;function Sd(e,t,n){let r=Object.fromEntries(gd.map(e=>[e,{key:e,items:[]}])),i=[],a=[],o=new Set([...gd,`size`]),s;e.forEach((e,t)=>{let c=e.trim();if(!c||c.startsWith(`%%`))return;let[l,u]=Vr(c,Ur),d=xd.test(l)||/^"[^"]*"$/.test(l),f=d?null:l.match(yd);if(f){let e=vd[f[1].toLowerCase()],n=r[e];n.line=t;let i=u.color??(f[2]?Cd(f[2]):void 0);i&&(n.tone=i),f[3]?.trim()&&(n.text=H(f[3].trim())),s=e;return}let p=d?null:l.match(bd);if(p){let e=p[4]?.trim();a.push({from:H(p[1].trim()),to:H(p[3].trim()),label:e?H(e):void 0,tone:u.color,dashed:p[2]===`-.->`,line:t});return}if(/^(title|acc(Title|Descr))\b/i.test(l))return n(t,`cynefin: write the title in the panel header`);let m=H(l.replace(xd,``).trim());if(!m)return;if(!s)return n(t,`cynefin: "${m}" comes before any domain line (complex, complicated, clear, chaotic, confusion)`);let h={id:Ba(m,o,`i${i.length+1}`,/^i\d+$/),name:m,domain:s,tone:u.color,line:t};i.push(h),r[s].items.push(h)});let c=e=>{let t=e.toLowerCase(),n=vd[t];if(n)return{kind:`domain`,key:n};let r=i.find(e=>e.id===t)??i.find(e=>e.name.toLowerCase()===t);return r&&{kind:`item`,id:r.id}},l=(e,t)=>e.kind===`domain`?t.kind===`domain`&&e.key===t.key:t.kind===`item`&&e.id===t.id,u=[];for(let e of a){let t=c(e.from),r=c(e.to);!t||!r?n(e.line,`cynefin: no domain or item named "${t?e.to:e.from}"`):l(t,r)?n(e.line,`cynefin: an arrow needs two different ends`):u.push({from:t,to:r,label:e.label,tone:e.tone,dashed:e.dashed,line:e.line})}return{domains:r,items:i,arrows:u,descriptions:!(e=>e!==void 0&&/^(hide|false|off|no|none)$/i.test(e))(t.descriptions),wavy:!/^straight$/i.test(t.boundary??``)}}function Cd(e){let[,t]=Vr(`x [${e}]`,Ur);return t.color}var wd=3,Td=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n});function Ed(e,t){let n=Td(e.p0,e.c1,t),r=Td(e.c1,e.c2,t),i=Td(e.c2,e.p3,t),a=Td(n,r,t),o=Td(r,i,t);return{p0:Td(a,o,t),c1:o,c2:i,p3:e.p3}}var Dd=e=>`${L(e.x)},${L(e.y)}`,Od=e=>`C${Dd(e.c1)} ${Dd(e.c2)} ${Dd(e.p3)}`,kd=e=>`C${Dd(e.c2)} ${Dd(e.c1)} ${Dd(e.p0)}`,Ad=ei(function(e,t){let{measure:n,theme:r}=t,i=r.mono,a=t.fs*.85,o=a*.85,s=a*1.15,c=o*1.8,l=a*.45,u=a*1.2,d=t.offsets.size??{x:0,y:0},f=Math.max(a*30,a*44+d.x),p=f/2,m=e=>z(F(e),o,i,n)+o*1.4,h=s*1.4+(e.descriptions?a*1.2:0),g=e.domains.confused.items,_=g.slice(0,wd).map(e=>({...jd(),w:m(e.name),text:e.name,item:e}));if(g.length>wd){let e=`+${g.length-wd} more`;_.push({...jd(),w:m(e),text:e})}let v=z(F(_d.confused.name),s,i,n,700),y=e.descriptions?z(F(Md(e,`confused`)),a*.8,i,n):0,b=h+_.length*(c+l),x=Math.max(a*3.6,Math.max(v,y,..._.map(e=>e.w))/2+a*1.4,b/2+a*1.4),S=t=>{let n=p-u*2,r=[[]],i=0;for(let a of e.domains[t].items){let e=Math.min(m(a.name),n);r[r.length-1].length&&i+l+e>n&&(r.push([]),i=0),r[r.length-1].push({...jd(),w:e,text:a.name,item:a}),i+=(i?l:0)+e}let a=r[0].length?r.length:0;return{rows:r.slice(0,a||0),h:h+(a?l+a*(c+l):0)}},C=Object.fromEntries(gd.slice(0,4).map(e=>[e,S(e)])),w=a*12+d.y/2,T=e.arrows.length?a*1.4:0,E=Math.max(w,u+T+Math.max(C.complex.h,C.complicated.h)+x*.9+a*.6),D=Math.max(w,u+T+Math.max(C.chaotic.h,C.clear.h)+x*.9+a*.6),O=E+D,k={x:p,y:E},A=+!!e.wavy,ee=a*1.8*A,te={top:{p0:k,c1:{x:k.x-A*f*.06,y:E*.66},c2:{x:k.x+A*f*.07,y:E*.3},p3:{x:k.x+A*f*.02,y:0}},right:{p0:k,c1:{x:k.x+p*.35,y:k.y+ee},c2:{x:k.x+p*.7,y:k.y-ee},p3:{x:f,y:k.y-A*O*.03}},bottom:{p0:k,c1:{x:k.x+A*f*.06,y:k.y+D*.35},c2:{x:k.x-A*f*.07,y:k.y+D*.7},p3:{x:k.x-A*f*.02,y:O}},left:{p0:k,c1:{x:p*.65,y:k.y-ee},c2:{x:p*.3,y:k.y+ee},p3:{x:0,y:k.y+A*O*.03}}},j=new Map,ne=(t,r,o,d=!1)=>{let f=Math.max(z(F(_d[t].name),s,i,n,700),e.descriptions?z(F(Md(e,t)),a*.8,i,n):0),p=[],m=d?o:o+h+l;for(let e of C[t].rows){let t=r-(e.reduce((e,t)=>e+t.w,0)+l*(e.length-1))/2;for(let n of e)p.push({...n,x:t,y:m}),t+=n.w+l;m+=c+l}return{x:r,y:d?O-u-T-s*.7:o+s*.7,titleW:f,chips:p,below:d}},re=E+x*.9+a*.6,ie={complex:ne(`complex`,p/2,u+T),complicated:ne(`complicated`,p*1.5,u+T),chaotic:ne(`chaotic`,p/2,re,!0),clear:ne(`clear`,p*1.5,re,!0)},ae=k.y-b/2,M=ae+h;ie.confused={x:k.x,y:ae+s*.7,titleW:v,chips:_.map(e=>{let t={...e,x:k.x-e.w/2,y:M};return M+=c+l,t})};for(let e of Object.values(ie))for(let t of e.chips)t.h=c,t.item&&j.set(t.item.id,t);let oe=ie.confused.chips.find(e=>!e.item);if(oe)for(let e of g.slice(wd))j.set(e.id,oe);return{fs:a,cfs:o,W:f,H:O,C:k,R:x,curves:te,blocks:ie,chipOf:j,w:f,h:O}});function jd(){return{x:0,y:0,w:0,h:0,text:``}}var Md=(e,t)=>e.domains[t].text??_d[t].text,Nd=(e,t)=>e.domains[t].tone??_d[t].tone;function Pd(e,t){return t.tone(e)?.fill??m(e,t.dark?900:50)??t.node.fill}function Fd(e,t,n){let r=[];for(let i=0;i<72;i++){let a=i/72*Math.PI*2,o=t*(1+(n?.05*Math.sin(a*5+.6)+.03*Math.sin(a*3):0));r.push(Dd({x:e.x+Math.cos(a)*o,y:e.y+Math.sin(a)*o}))}return`M${r.join(`L`)}Z`}function Id(e,t,n){let r=n.theme,i=Ad(e,n),{fs:a,W:o,H:s,C:c,R:l,curves:u}=i,d=`${n.idPrefix??`cy`}-cynefin`,f=[],p=P(r),m=r.group.stroke,h=Math.min(r.radius,a);f.push(`<defs><clipPath id="${d}-clip"><rect width="${L(o)}" height="${L(s)}" rx="${L(h)}"/></clipPath></defs>`,`<g transform="translate(${L(t.x)},${L(t.y)})">`,`<g clip-path="url(#${d}-clip)">`);let{top:g,right:_,bottom:v,left:y}=u,b={complex:`M0,0L${Dd(g.p3)}${kd(g)}${Od(y)}Z`,complicated:`M${Dd(g.p3)}${kd(g)}${Od(_)}L${L(o)},0Z`,chaotic:`M${Dd(y.p3)}${kd(y)}${Od(v)}L0,${L(s)}Z`,clear:`M${Dd(_.p3)}${kd(_)}${Od(v)}L${L(o)},${L(s)}Z`};for(let t of gd.slice(0,4))f.push(`<path d="${b[t]}" fill="${Pd(Nd(e,t),r)}"/>`);f.push(`<path d="M${Dd(c)}${Od(g)}M${Dd(c)}${Od(_)}M${Dd(c)}${Od(v)}M${Dd(c)}${Od(y)}" fill="none" stroke="${m}" stroke-width="1.5"/>`);let x=Ed(v,.62),S=x.p0,C=a*.9;f.push(`<path d="M${Dd(x.p0)}${Od(x)}" fill="none" stroke="${r.node.sub}" stroke-width="3" stroke-linecap="round"/>`,`<path d="M${Dd(S)}c${L(-C*.2)},${L(-C*.9)} ${L(-C*1.5)},${L(-C*1.1)} ${L(-C*1.7)},${L(-C*.2)}c${L(-C*.1)},${L(C*.5)} ${L(C*.4)},${L(C*.7)} ${L(C*.6)},${L(C*.2)}" fill="none" stroke="${r.node.sub}" stroke-width="2" stroke-linecap="round"/>`,`<path d="${Fd(c,l,e.wavy)}" fill="${Pd(Nd(e,`confused`),r)}" stroke="${m}" stroke-width="1.5"/>`,`</g>`,`<rect width="${L(o)}" height="${L(s)}" rx="${L(h)}" fill="none" stroke="${m}" stroke-width="1.5"/>`);for(let t of gd){let n=i.blocks[t],o=Nd(e,t),s=R(o,r,r.node.text);f.push(`<text x="${L(n.x)}" y="${L(n.y)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*1.15)}" font-weight="700" fill="${s}">${I(_d[t].name)}</text>`),e.descriptions&&f.push(`<text x="${L(n.x)}" y="${L(n.y+(n.below?-1:1)*a*1.35)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a*.8)}" font-style="italic" xml:space="preserve">${B(F(Md(e,t)),{...p,text:r.node.sub},r)}</text>`);for(let e of n.chips)f.push(Ld(e,o,r,i))}for(let t of e.arrows)f.push(zd(t,i,r,d,n.measure));return f.push(`</g>`),f.join(``)}function Ld(e,t,n,r){let i=e.item?.tone,a=i?n.tone(i):void 0,o=i?a?.fill??m(i,n.dark?800:100)??n.node.fill:n.node.fill,s=i?a?.stroke??R(i,n,n.node.stroke):m(t,n.dark?600:300)??n.node.stroke,c=P(n,a?.text??n.node.text),l=!e.item;return`<g${e.item?` data-part="${I(e.item.id)}"`:``}><rect x="${L(e.x)}" y="${L(e.y)}" width="${L(e.w)}" height="${L(e.h)}" rx="${L(e.h/2)}" fill="${o}" stroke="${s}" stroke-width="1"${l?` stroke-dasharray="3 2"`:``}/><text x="${L(e.x+e.w/2)}" y="${L(e.y+e.h/2)}" dominant-baseline="central" text-anchor="middle" font-size="${L(r.cfs)}" xml:space="preserve">${B(F(e.text),c,n,l)}</text></g>`}function Rd(e,t){if(e.kind===`item`){let n=t.chipOf.get(e.id);if(n)return{p:{x:n.x+n.w/2,y:n.y+n.h/2},hw:n.w/2,hh:n.h/2}}let n=e.kind===`domain`?e.key:`confused`;if(n===`confused`)return{p:t.C,hw:t.R*.75,hh:t.R*.75};let r=t.blocks[n];return{p:{x:r.x,y:r.y},hw:r.titleW/2+t.fs*.4,hh:t.fs*.9,title:!0}}function zd(e,t,n,r,i){let a=Rd(e.from,t),o=Rd(e.to,t),s=(e,n)=>{if(!e.title)return e.p;let r=n.p.x-e.p.x,i=Math.abs(r)<t.W/4?e.p.x<t.C.x?-1:1:Math.sign(r);return{x:e.p.x+i*(e.hw+2),y:e.p.y}},c=s(a,o),l=s(o,a),u=l.x-c.x,d=l.y-c.y,f=Math.hypot(u,d)||1,p=Math.min(f*.25,t.fs*5),m={x:(c.x+l.x)/2,y:(c.y+l.y)/2},h=d/f,g=-u/f,_=(m.x-t.C.x)*h+(m.y-t.C.y)*g,v=_<0?-1:1,y=e=>Math.hypot(e.x-t.C.x,e.y-t.C.y)<t.R;!y(c)&&!y(l)&&(p=Math.max(p,Math.min(2*(t.R+t.fs-Math.abs(_)),f*.9)));let b={x:m.x+h*p*v,y:m.y+g*p*v},x=(e,t)=>{if(e.title)return t;let n=b.x-e.p.x,r=b.y-e.p.y,i=Math.hypot(n,r)||1,a=Math.min(e.hw/(Math.abs(n/i)||1e-9),e.hh/(Math.abs(r/i)||1e-9))+3;return{x:e.p.x+n/i*a,y:e.p.y+r/i*a}},S=x(a,c),C=x(o,l),w=R(e.tone,n,n.edge.ink),T=Math.atan2(C.y-b.y,C.x-b.x),E={x:C.x-Math.cos(T)*10*.8,y:C.y-Math.sin(T)*10*.8},D=[`<path d="M${Dd(S)}Q${Dd(b)} ${Dd(E)}" fill="none" stroke="${w}" stroke-width="1.6"${e.dashed?` stroke-dasharray="5 4"`:``}/>`,On(C,T,`arrow`,w,1.6,10)];if(e.label){let r={x:.25*S.x+.5*b.x+.25*C.x,y:.25*S.y+.5*b.y+.25*C.y},a=t.fs*.78,o=F(e.label),s=z(o,a,n.mono,i,400);r.x=Math.min(t.W-s/2-6,Math.max(s/2+6,r.x)),r.y=Math.min(t.H-a,Math.max(a,r.y));let c=n.background===`none`?n.node.fill:n.background;D.push(`<rect x="${L(r.x-s/2-4)}" y="${L(r.y-a*.75)}" width="${L(s+8)}" height="${L(a*1.5)}" rx="${L(a*.4)}" fill="${c}" fill-opacity="0.9"/>`,`<text x="${L(r.x)}" y="${L(r.y)}" dominant-baseline="central" text-anchor="middle" font-size="${L(a)}" xml:space="preserve">${B(o,{...P(n),text:w},n)}</text>`)}return D.join(``)}var Bd=/^(\s*[A-Za-z]+)(?:\s*\[([^\]]*)\])?(\s*(?::.*)?)$/;mi(ji,Ni,Pi,Ui,qi,ea,pa,aa,Pa,io,No,Qo,ps,Fs,Gs,rc,rl,hl,Tl,Rl,ru,lu,Vu,hd,{name:`cynefin`,panels:[{name:`cynefin`,guide:'A Cynefin framework in the Mermaid cynefin-beta syntax. A domain line `complex`, `complicated`, `clear`, `chaotic` or `confusion` (aliases `obvious`, `simple`, `disorder`) opens a domain; the lines under it are its items, as `"Quoted text"`, plain text or `- bullets`, each with an optional `[color]`. `complex [amber]` colours a domain, `complex: text` replaces its description. `A --> B : label` draws a transition between two domains or items (by name), `-.->` a dashed one, `[color]` at the end colours it. Complex is top left, complicated top right, chaotic bottom left, clear bottom right, confusion in the centre (it shows three items, then `+N more`).',layoutParts:"`size DX DY` grows the panel",syntax:`cynefin id "Title" { complex; "Run experiments"; clear; "Restart service"; complex --> clear : "Codified" }`,options:{descriptions:[`show`,`hide`],boundary:[`wavy`,`straight`]},help:{descriptions:`show each domain’s approach, such as Probe – Sense – Respond`,boundary:`wavy boundaries between the domains, or straight ones`},parse:Sd,measure(e,t){let n=Ad(e,t);return{w:n.w,h:n.h}},render:Id,parts:e=>[...gd.map(t=>({id:t,label:_d[t].name,kind:`domain`,tone:e.domains[t].tone})),...e.items.map(e=>({id:e.id,label:e.name,kind:`item`,tone:e.tone}))],editPart:ti((e,t,n,r)=>{let i=r.domains[t],a=[...e];if(i)return i.line===void 0||e[i.line]===void 0?n?[...e,`${t===`confused`?`confusion`:t} [${n}]`]:null:(a[i.line]=Wr(e[i.line],Bd,`color`,n,Ur),a);let o=r.items.find(e=>e.id===t);return!o||e[o.line]===void 0?null:(a[o.line]=Hr(e[o.line],`color`,n||null,Ur),a)}),handles(e,t,n){let r=Ad(e,n);return[{part:`size`,x:t.x+r.W,y:t.y+r.H,title:`resize`}]}}]});var W=e=>JSON.stringify(e),Vd=(e,t)=>t.test(e)?Jr(e):e,Hd=e=>/^[\p{L}\p{N}_.#/-]+$/u.test(e)?e:W(e);function G(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,`
|
|
11
|
+
`).replace(/<\/?(b|i|em|strong|span|code)[^>]*>/gi,``).replace(/"|#quot;/g,`"`).replace(/&/g,`&`).replace(/#59;/g,`;`).replace(/\bfa[bsr]?:fa-[\w-]+\s*/g,``).replace(/^`(.*)`$/s,`$1`),t||(n=n.replace(/\*\*(.+?)\*\*/g,`$1`)),n.trim()}var K=(e,t=!1)=>G(e,t).replace(/\s*\n\s*/g,` `);function Ud(e,t=Wd){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 Wd=new Set(gr);function Gd(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 Kd(e,t,n,r,i){let a=[e,t];return n&&a.push(W(n)),r.length&&a.push(`[${r.join(`, `)}]`),a.push(`{`),[a.join(` `),...i.map(e=>e&&` `+e),`}`]}var qd=/^title\b(?!\s*(?:[-=.~<>&|[({]|:::))\s*:?\s*(.*)$/,Jd=new RegExp(qd.source,`i`);function Yd(e,t=!0){let n=e.match(t?Jd:qd);return n?G(n[1]):void 0}var Xd=/^(accTitle|accDescr)\b/;function Zd(e,t){return Xd.test(e.text)?(t.warnOnce(`acc`,e.line,`accessibility titles (accTitle, accDescr) are skipped`),!0):!1}function Qd(e,t,n){for(;e.index<e.lines.length;e.index++){let r=e.lines[e.index];!Zd(r,t)&&!n(r)&&t.warn(r.line,`could not read "${r.text}"`)}}var $d={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},ef=/^direction\s+(TD|TB|BT|LR|RL)$/i,tf=/^style\s+(\S+)\s+(.*)$/;function nf(e,t){let n=e.match(tf);return n?{target:n[1],props:lf(n[2],t)}:void 0}var rf=/^classDef\s+([\w,-]+)\s+(.*)$/;function af(e,t){let n=e.match(rf);if(!n)return;let r=lf(n[2],t);return n[1].split(`,`).map(e=>`.${e.trim()} [${r}]`)}function of(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 sf=e=>/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u.test(e)?e:W(e),cf=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 lf(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=cf[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 uf=[`blue`,`purple`,`teal`,`amber`,`pink`,`lime`,`orange`,`cyan`,`indigo`,`red`,`green`],df=()=>({settings:{},nodes:new Map,edges:[],groups:new Map,classes:l({}),layout:{nodes:{},edges:{}},panels:[],diagnostics:[]}),ff=Object.keys(he),pf=e=>e.match(/^\s*/)[0].length,mf=(e,t,n)=>void e.classUses.push([t,n]);function hf(e){for(let t=e.stack.length-1;t>=0;t--)if(e.stack[t].kind===`group`)return e.stack[t].id}function gf(e,t){let n=e.d.nodes.get(t);return n||(n={id:t,label:t,props:{},classes:[],implicit:!0,group:hf(e)},e.d.nodes.set(t,n)),n}function _f(e,t,n,r,i){let a=n.value;t.labelRef={line:r,at:n.start,range:[n.start,n.end],generated:e.gen||void 0};let o=e.labelled.get(t.id);o!==void 0&&t.label!==a&&e.warn(r,`"${t.id}" already has the label "${t.label}" (line ${o+1}); this renames it to "${a}"`+(i?`. For an edge label write: ... -> ${t.id}: ${a}`:``)),t.label=a,e.labelled.set(t.id,r)}function vf(e,t,n,r,i){if(!(n in he))return e.warn(i,`Unknown theme key "${n}"${or(n,ff)||` (keys: ${ff.join(`, `)})`}`);he[n].kind!==`color`||[`none`,`transparent`].includes(r)||r.includes(`$`)||xe(r)||e.warn(i,`Unknown color "${r}" for ${n}${or(r,f)}`),t[n]=r}function yf(e,t,n,r){e.themeLines.has(t)&&e.warn(r,`Theme "${t}" is defined twice`),(e.d.themes??=l({}))[t]=n,e.themeLines.set(t,r)}function bf(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 xf(e,t,n){let r=e.exports;if(!t&&!r)return e;let i=e=>!r||r.includes(e),a=new Map,o=new Set,s=new Set(e.panels.map(e=>e.id));if(t)for(let[c,l]of t){let t=c.replace(/^\./,``);if(e.sharedSettings?.includes(c)&&!e.nodes.has(c)&&!e.groups.has(c)){l===c?o.add(c):n(`a setting keeps its name: import { ${c} }`);continue}let u=c.startsWith(`.`)?t in e.classes:c.startsWith(`$`)?c.slice(1)in(e.vars??{}):e.nodes.has(t)||e.groups.has(t)||s.has(t)||t in(e.defs??{});!u&&c in(e.themes??{})||(u?i(c)?(o.add(c),l!==c&&a.set(c,l)):n(`"${c}" is not exported (exports: ${r.join(`, `)||`none`})`):n(`no "${c}" to import${r?.length?` (exports: ${r.join(`, `)})`:``}`))}else for(let e of r)o.add(e);let c=t=>{for(let n=t;n;n=e.groups.get(n)?.parent)if(o.has(n))return!0;return!1},l=df(),u=e=>a.get(e)?.replace(/^\./,``)??e,d=e=>a.get(`.${e}`)?.slice(1)??e,f=new Set;for(let t of e.groups.values())(o.has(t.id)||c(t.parent))&&(l.groups.set(u(t.id),{...t,id:u(t.id),parent:t.parent&&l.groups.has(u(t.parent))?u(t.parent):void 0,classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e)));let p=t=>o.has(t)||c(e.nodes.get(t)?.group);for(let t of e.nodes.values())if(p(t.id)){let e=t.group&&l.groups.has(u(t.group))?u(t.group):void 0;l.nodes.set(u(t.id),{...t,id:u(t.id),group:e,classes:t.classes.map(d)}),t.classes.forEach(e=>f.add(e))}for(let t of e.edges)if(p(t.from)&&p(t.to)){let e=u(t.from)+`->`+u(t.to)+(t.key.match(/#\d+$/)?.[0]??``);l.edges.push({...t,key:e,from:u(t.from),to:u(t.to),classes:t.classes?.map(d)}),t.classes?.forEach(e=>f.add(e))}for(let t of e.panels)o.has(t.id)&&l.panels.push({...t,id:u(t.id)});for(let[t,n]of Object.entries(e.defs??{}))if(o.has(t))for(let e of n.body)for(let t of Pr(e).tokens)t.kind===`class`&&f.add(t.value);l.sharedSettings=(e.sharedSettings??[]).filter(e=>!t||o.has(e));for(let t of l.sharedSettings)l.settings[t]=e.settings[t];for(let[t,n]of Object.entries(e.classes))(o.has(`.${t}`)||f.has(t))&&(l.classes[d(t)]=n);l.vars={};for(let[t,n]of Object.entries(e.vars??{}))o.has(`$${t}`)&&(l.vars[(a.get(`$${t}`)??`$${t}`).slice(1)]=n);l.defs={};for(let[t,n]of Object.entries(e.defs??{}))o.has(t)&&(l.defs[a.get(t)??t]=n);return l.themes=e.themes,l}function Sf(e,t,n){let r=`${t}->${n}`,i=(e.get(r)??0)+1;return e.set(r,i),i===1?r:`${r}#${i}`}function Cf(e,t,n){for(let n of t.sharedSettings??[])!(n in e.settings)&&n in t.settings&&(e.settings[n]=t.settings[n]);for(let[n,r]of Object.entries(t.classes))e.classes[n]={...r,...e.classes[n]};for(let n of t.groups.values())e.groups.has(n.id)||e.groups.set(n.id,{...n,props:{...n.props},ref:void 0,labelRef:void 0});for(let n of t.nodes.values()){let t=e.nodes.get(n.id);if(!t)e.nodes.set(n.id,{...n,props:{...n.props},classes:[...n.classes],ref:void 0,labelRef:void 0,bodyLines:void 0});else{t.implicit&&!n.implicit&&(t.label=n.label,t.implicit=!1),t.props={...n.props,...t.props};for(let e of n.classes)t.classes.includes(e)||t.classes.push(e);t.group??=n.group,!t.body&&n.body&&(t.body=n.body)}}for(let r of t.edges)e.edges.push({...r,key:Sf(n,r.from,r.to),ref:void 0,labelRef:void 0});for(let n of t.panels)e.panels.push({...n,lines:void 0,ref:void 0,labelRef:void 0});for(let[n,r]of Object.entries(t.data??{}))n in(e.data??={})||(e.data[n]=r);t.layout.ranks?.length&&(e.layout.ranks??=[]).push(...t.layout.ranks),t.layout.aligns?.length&&(e.layout.aligns??=[]).push(...t.layout.aligns);for(let[n,r]of Object.entries(t.vars??{}))(e.vars??={})[n]??=r;for(let[n,r]of Object.entries(t.defs??{}))(e.defs??={})[n]??=r;for(let[n,r]of Object.entries(t.themes??{}))(e.themes??=l({}))[n]??=r}function wf(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`?(Ir(h,Lr(e[l],f,t,o),t),g&&(h.ref={line:t,props:[e[l].start,e[l].end],insertAt:e[l].start}),l++):l>p&&g&&(h.ref={line:t,insertAt:e[l-1].end}),l>p&&(h.implicit=!1),l>p&&g&&!h.labelRef&&(h.labelRef={line:t,at:e[p-1].end})}return a},f=d();if(!f.length){let n=e[0]?.kind===`string`?e[0].value:``;o(t,`Edge needs a source node${n.trim()?`: a label needs an id, write ${Ud(n.toLowerCase())} ${Jr(n)}`:``}`,`error`);return}let p=[];for(;l<e.length&&e[l].kind===`arrow`;){let n=e[l++].value,r=d(!0);if(!r.length){o(t,`Edge "${n}" needs a target node`,`error`);return}p.push({from:f,to:r,arrow:n}),f=r}let m,h=[],g={},_={line:t,insertAt:e[l-1].end,prefix:`:`},v={line:t,at:e[l-1].end,colon:!1};if(e[l]?.kind===`punct`&&e[l].value===`:`){_.insertAt=v.at=e[l].end,v.colon=void 0,_.prefix=void 0,l++;let r=l;for(;l<e.length&&e[l].kind!==`class`&&e[l].kind!==`props`;)l++;for(l>r&&(m=l-r===1&&e[r].kind===`string`?e[r].value:n.slice(e[r].start,e[l-1].end).trim(),_.insertAt=e[l-1].end,v.range=[e[r].start,e[l-1].end]);e[l]?.kind===`class`;)c(e[l].value,t),h.push(e[l].value),_.insertAt=e[l++].end;e[l]?.kind===`props`&&(g=V(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=qr(e.arrow);for(let n of e.from)for(let i of e.to){let e=n,o=i,s=t.start,c=t.end;s&&!c&&([e,o]=[o,e],[s,c]=[!1,!0]);let l={key:Sf(a,e,o),from:e,to:o,label:m,startHead:s,endHead:c,line:t.line,props:{...g},classes:[...h],ref:_,labelRef:v};r.edges.push(l)}}}var Tf=(e,t)=>(e.layout.panels??={})[t]??={};function Ef(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(!nr(t))return null;n.push(t)}return n},s=1,c=Dt(a,i[1]);if(c&&a===`rank`){let e=i.slice(1).filter(Boolean);if(e.length<2)return r(t,`rank needs two or more node ids: rank a b c`);(n.layout.ranks??=[]).push(e);return}if(c&&a===`align`){let[e,a]=Et(i.slice(1).filter(Boolean));if(a.length<2)return r(t,`align needs two or more ids: align ${Tt} a b c`);(n.layout.aligns??=[]).push({side:e,ids:a});return}if(a.includes(`->`)){let e=a.match(/^(.+?)->(.+?)(?:#(\d+))?$/);if(!e)return r(t,`Bad edge key "${a}"`);let c=`${e[1]}->${e[2]}${e[3]&&e[3]!==`1`?`#`+e[3]:``}`,l=n.layout.edges[c]??={};for(;s<i.length;){let e=i[s++];if(e===`via`){l.via=[];for(let e=o(s,2);e;e=o(s,2))l.via.push({x:e[0],y:e[1]}),s+=2}else if(e===`label`){let e=o(s,2);if(!e)return r(t,`label expects two numbers: dx dy (each within ±${tr})`);l.label={x:e[0],y:e[1]},s+=2}else if(e===`ports`){let e=i[s],n=i[s+1];if(!Un.includes(e)||!Un.includes(n))return r(t,`ports expects two sides: ${Un.join(`|`)}`);l.ports=[e,n],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}return}let l=a.indexOf(`:`);if(l>0){let s=a.slice(0,l),c=a.slice(l+1),u=i[1]===`offset`?2:1,d=i.length-u,f=c&&(d===1||d===2)?o(u,d):null;if(!f)return r(t,`Bad panel part "${e.trim()}" (expected panel:part d, or panel:part dx dy)`);(Tf(n,s).parts??={})[c]={x:f[0],y:f[1]??0};return}if(n.panels.some(e=>e.id===a)){let e=i[1]===`at`&&i.length===4?o(2,2):null;if(!e)return r(t,`panel "${a}" takes only "at x y" in layout (its content sets the size)`);Tf(n,a).at={x:e[0],y:e[1]};return}let u=n.layout.nodes[a]??={};for(;s<i.length;){let e=i[s++];if(e===`at`){let e=o(s,2);if(!e)return r(t,`at expects two numbers: x y (each within ±${tr})`);u.x=e[0],u.y=e[1],s+=2}else if(e===`size`){let e=o(s,2);if(!e)return r(t,`size expects two numbers: width height (each within ±${tr})`);u.w=e[0],u.h=e[1],s+=2}else return r(t,`Unknown layout keyword "${e}"`)}}function Df(e,t,n,r){switch(t?.kind){case`body`:return Of(e,t,n,r),!0;case`panel`:return kf(e,t,n,r),!0;case`theme`:return jf(e,t,n,r),!0;case`layout`:return Mf(e,n,r),!0;default:return!1}}function Of(e,t,n,r){if(n.trim()===`}`){e.stack.pop();let n=e.d.nodes.get(t.id);n.body=qe(t.lines),n.bodyLines=[t.start,r]}else t.lines.push(n)}function kf(e,t,n,r){n.trim()===`}`?(e.stack.pop(),Af(e,t,r)):t.lines.push(n.slice(0,Pr(n).codeEnd).trimEnd())}function Af(e,t,r){let i=t.panel,a=t.lines.findIndex(e=>e.trim());i.body=qe(t.lines),i.lines=[t.start,r];try{i.data=Cr.get(i.kind).parse(i.body,i.props,(n,r)=>e.warn(n<0?t.start:t.start+1+Math.max(0,a)+n,r))}catch(r){let a=c(`panel`,i.kind);e.warn(t.start,`${a?`plugin "${a}": `:``}${i.kind} panel failed to parse: ${n(r)}`,`error`),i.failed=!0}}function jf(e,t,n,r){let i=n.slice(0,Pr(n).codeEnd).trim();if(!i)return;if(i===`}`){e.stack.pop(),yf(e,t.id,t.props,t.start);return}let a=i.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);a?vf(e,t.props,a[1].toLowerCase(),H(a[2].trim()),r):e.warn(r,`Expected "key: value" in theme ${t.id} (keys: ${ff.join(`, `)})`,`error`)}function Mf(e,t,n){let r=t.slice(0,Pr(t).codeEnd).trim();r&&(r.startsWith(`}`)?(e.stack.pop(),e.d.layoutBlock[1]=n):(e.layoutLines.set(r.split(/\s+/)[0],n),Ef(r,n,e.d,e.warn)))}function Nf(e,t){if(!e.stack.length)e.warn(t,`Unmatched "}"`,`error`);else{let n=e.stack.pop(),r=n.kind===`group`?e.d.groups.get(n.id):void 0;r?.ref&&(r.ref.end=t)}e.lastDecl=null}function Pf(e,t,n){e.stack.length&&e.warn(n,`theme must be at the top level`,`error`);let r={},i=2;if(t[i]?.kind===`props`){for(let[a,o]of Object.entries(V(t[i].value)))vf(e,r,a,o,n);i++}if(t[i]?.value===`{`){if(i++,t[i]?.value===`}`)i++;else if(i===t.length){e.stack.push({kind:`theme`,id:t[1].value,start:n,props:r});return}}i<t.length&&e.warn(n,`Unexpected "${t[i].value}" in theme ${t[1].value}`,`error`),yf(e,t[1].value,r,n)}function Ff(e,t,n){let r=t[0].value,i=1,a=t[i]?.kind===`ident`?t[i++].value:`${r}${e.d.panels.length+1}`,o=e.gen?void 0:t[i]?.kind===`string`?{line:n,at:t[i].start,range:[t[i].start,t[i].end]}:{line:n,at:t[i-1].end},s=t[i]?.kind===`string`?t[i++].value:void 0,c={line:n,insertAt:t[i-1].end},l={};t[i]?.kind===`props`&&(l=V(t[i].value),c.props=[t[i].start,t[i].end],i++),l.vertical!==void 0&&l.direction===void 0&&l.vertical!==`false`&&(l.direction=`down`),delete l.vertical,i!==t.length-1&&e.warn(n,`Unexpected "${t[i].value}" in ${r} header`,`error`),e.stack.length&&e.warn(n,`${r} must be at the top level`,`error`);let u={kind:r,id:a,label:s,props:l,body:[],data:void 0,ref:e.gen?void 0:c,labelRef:o};e.d.panels.push(u),e.stack.push({kind:`panel`,id:a,start:n,lines:[],panel:u})}function If(e,t,n){e.stack.length&&e.warn(n,`layout block must be at top level`,`error`),e.d.layoutBlock=[n,n],t[2]?.value!==`}`&&e.stack.push({kind:`layout`})}function Lf(e){let t=e.lines.length-1;for(let n of e.stack)n.kind===`group`?e.warn(t,`Group "${n.id}" is missing "}"`,`error`):n.kind===`body`?e.warn(n.start,`Body of "${n.id}" is missing a closing "}" line`,`error`):n.kind===`panel`?(e.warn(n.start,`${n.panel.kind} "${n.id}" is missing a closing "}" line`,`error`),Af(e,n,t)):n.kind===`def`?e.warn(n.start,`def ${n.id}() is missing "}"`,`error`):n.kind===`theme`?e.warn(n.start,`theme ${n.id} is missing "}"`,`error`):e.warn(t,`layout block is missing "}"`,`error`)}var Rf=1e5,zf=5e4,Bf=16,Vf=/\$\$|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g,Hf=/^\s*\$([A-Za-z_]\w*)\s*[:=]\s*(.*)$/,Uf=/^\s*def\s+([\p{L}_][\p{L}\p{N}_-]*)\s*\(([^)]*)\)\s*\{\s*$/u,Wf=/^\s*([\p{L}_][\p{L}\p{N}_-]*)\s*\((.*)\)\s*$/u,Gf=new WeakMap;function Kf(e){let t=[],n=``,r=null,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(r)o===`\\`?n+=o+(e[++a]??``):(n+=o,o===r&&(r=null));else{if(o===`"`||o===`'`)r=o;else if(`[({`.includes(o))i++;else if(`])}`.includes(o))i--;else if(o===`,`&&!i){t.push(n.trim()),n=``;continue}n+=o}}return(n.trim()||t.length)&&t.push(n.trim()),t}function qf(e,t,n,r,i=!1){let a=t.match(Hf);if(a)return t.slice(0,t.length-a[2].length)+qf(e,a[2],n,r,i);let o=t.length,s=t.replace(Vf,(t,a,s)=>{let c=a??s;if(!c)return`$`;let l=r?.[c]??e.vars[c];return r?.[c]===void 0&&l!==void 0&&e.used.add(`$`+c),l===void 0?(i||e.warn(n,`Unknown variable "$${c}"${or(c,[...Object.keys(r??{}),...Object.keys(e.vars)])}`),t):(o+=l.length)>Rf?t:l});return o>Rf&&e.warn(n,`Variables make this line longer than ${Rf} characters`,`error`),s}function Jf(e,t,n,r){if(e.depth>=Bf){e.tooDeep.has(t.name)||e.warn(r,`${t.name}(): calls nest too deep`,`error`),e.tooDeep.add(t.name);return}if((e.expanded+=t.body.length)>zf){e.expanded-t.body.length<=zf&&e.warn(r,`${t.name}(): components expand to more than ${zf} lines`,`error`);return}let i=Kf(n),a=l({}),o=0;for(let n of i){let s=n.match(/^([A-Za-z_]\w*)\s*[:=]\s*([\s\S]*)$/);if(s&&t.params.some(e=>e.name===s[1]))a[s[1]]=H(s[2]);else if(o<t.params.length)a[t.params[o++].name]=H(n);else{e.warn(r,`${t.name}() takes ${t.params.length} argument(s), got ${i.length}`,`error`);return}}for(let n of t.params)if(!(n.name in a)){if(n.default===void 0){e.warn(r,`${t.name}(): missing argument "${n.name}" (${t.params.map(e=>e.name).join(`, `)})`,`error`);return}a[n.name]=n.default}let s=e.stack.length,c=e.gen;e.gen=!0,e.depth++;let u=t.body.map(t=>qf(e,t,r,a)),d=Gf.get(t)??e.defs;for(let t of u)e.step(t,r,!0,d);e.depth--,e.gen=c,e.stack.length>s&&(e.warn(r,`${t.name}(): a block inside the component is not closed`,`error`),e.stack.length=s)}function Yf(e,t,n,r,i){for(let e of Fr(Pr(n).tokens))t.depth+=e===`{`?1:-1;if(t.depth>0){t.lines.push(n);return}e.stack.pop(),n.trim()!==`}`&&e.warn(r,`Expected "}" alone on the line that closes ${t.id}()`,`error`);let a=t.params,o=l(Object.fromEntries(a.map(e=>[e.name,`\${${e.name}}`]))),s={name:t.id,params:a,body:qe(t.lines).map(t=>qf(e,t,r,o,!0))};Gf.set(s,i),e.defs[s.name]&&e.warn(t.start,`Component "${s.name}" is defined twice`),e.defs[s.name]=s,(e.d.defLines??={})[s.name]=t.start}function Xf(e,t,n,r,i){let a=t.match(Hf);if(a)return e.vars[a[1]]=H(zr(r?a[2]:qf(e,a[2],n)).trimEnd()),(e.d.varLines??={})[a[1]]=n,!0;let o=t.match(Uf);if(o){e.stack.length&&e.warn(n,`def must be at the top level`,`error`);let t=Kf(o[2]).map(t=>{let r=t.match(/^([A-Za-z_]\w*)\s*(?:[:=]\s*([\s\S]*))?$/);return r||e.warn(n,`Bad parameter "${t}": def name(a, b = "default") {`,`error`),{name:r?.[1]??t,default:r?.[2]===void 0?void 0:H(r[2])}});return e.stack.push({kind:`def`,id:o[1],start:n,lines:[],depth:1,params:t}),!0}let s=zr(t).match(Wf);if(s){let a=i[s[1]]??e.defs[s[1]];if(a)return e.used.add(s[1]),Jf(e,a,r?s[2]:qf(e,s[2],n),n),!0;if(!Pr(t).tokens.some(e=>e.kind===`arrow`))return e.warn(n,`Unknown component "${s[1]}"${or(s[1],Object.keys(e.defs))}`,`error`),!0}return!1}var Zf=new Set([...Kn,...qn]),Qf=new Set([`label`,`name`,`title`]);function $f(e,t,n,r){let i=2,a=t[1].value;t[1].kind===`string`&&(a=t[1].value.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-|-$/g,``)||`group`,i=1);let o=e.d.groups.get(a)??{id:a,label:a,props:{},parent:hf(e)};if(t[i]?.kind===`string`){let e=t[i++];o.label=e.value,o.labelRef={line:r,at:e.start,range:[e.start,e.end],id:i===2?a:void 0}}else o.labelRef??={line:r,at:t[1].end};for(e.gen&&(o.labelRef.generated=!0);t[i]?.kind===`class`;)mf(e,t[i].value,r),(o.classes??=[]).push(t[i++].value);let s={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};if(t[i]?.kind===`props`&&(Object.assign(o.props,V(t[i].value)),s.props=[t[i].start,t[i].end],i++),o.ref=s,e.lastDecl={indent:pf(n),targets:[o]},e.d.groups.set(a,o),t[i]?.value!==`{`){e.warn(r,`Expected "{" after group ${a}`,`error`);return}i++;let c=t.findIndex((e,t)=>t>=i&&e.value===`}`);if(c>=0){s.end=r;for(let n=i;n<c;n++)t[n].kind===`ident`&&(gf(e,t[n].value).group=a)}else e.stack.push({kind:`group`,id:a})}function ep(e,t,n,r){let{classes:i}=e.d,a=t[t.length-1],o={};for(let n of t.slice(1))n.kind===`class`&&(i[n.value]?Object.assign(o,i[n.value]):e.warn(r,`Unknown class ".${n.value}"${or(n.value,Object.keys(i))}`));i[t[0].value]={...i[t[0].value],...o,...a.kind===`props`?V(a.value):{}},(e.d.classLines??={})[t[0].value]=r,e.lastDecl={indent:pf(n),targets:[{props:i[t[0].value]}]}}function tp(e,t,n,r,i){let a=n.slice(t[1].end,i).trim();if(t[0].kind!==`ident`||!a)return!1;let o,s=a.match(/^\{(.*)\}$/s);if(s)o=`[${s[1].trim()}]`;else if(/^["']/.test(a))o=a;else{let e=a.match(jr);o=`${Jr(e[1].trim())}${e[2]}${e[3]?` ${e[3]}`:``}`}let c=e.gen;return e.gen=!0,e.statement(`${n.match(/^\s*/)[0]}${t[0].value} ${o}`,r),e.gen=c,!0}function np(e,t,n,r,i,a){let o=Rr(t[0].value),s=n.slice(t[1].end,i).trim();/^(["']).*\1$/.test(s)&&(s=Nr(s.slice(1,-1)));let c=e.lastDecl&&pf(n)>e.lastDecl.indent?e.lastDecl.targets:null,l=a?.kind===`group`?e.d.groups.get(a.id):void 0,u=l?Jn:vr,d=_r.has(o)||u.includes(o),f=d||Qf.has(o)?``:or(o,u);if((!c||c[0]===l)&&!d&&!f&&!Zf.has(o)&&tp(e,t,n,r,i))return;let p=c??(l?[l]:null);if(p){for(let t of p)t.props[o]=s||`true`,t.ref&&!e.gen&&((t.ref.propLines??={})[o]=r);return}if(e.stack.length&&e.warn(r,`Setting "${o}" should be at the top level`),!_r.has(o)){let n=Zf.has(o)?`. "${o}" is a prop: put it in brackets after a node, e.g. a [${o}: ${s||`…`}]`:`. For a node write ${t[0].value} "Label"`;e.warn(r,`Unknown setting "${o}"${(l?or(o,vr):f)||n}`);return}o===`direction`&&(s=xr[s.toLowerCase()]??s),o===`theme`&&(e.themeLine=r);let m=o===`theme`?void 0:yr[o];m&&s&&!s.includes(`$`)&&!m.includes(s)&&e.warn(r,`Unknown ${o} "${s}"${or(s,m)||` (use one of: ${m.join(`, `)})`}`),e.d.settings[o]=s}function rp(e,t,n,r,i){let{d:a}=e,o=a.edges.length;if(wf(t,r,n.slice(0,i),a,t=>gf(e,t),e.edgeCount,e.warn,(t,n,r,i)=>_f(e,t,n,r,i),(t,n)=>mf(e,t,n)),e.lastDecl={indent:pf(n),targets:a.edges.slice(o)},e.gen){for(let e of a.edges.slice(o))e.ref&&(e.ref.generated=!0),e.labelRef&&(e.labelRef.generated=!0);for(let e of t)if(e.kind===`ident`){let t=a.nodes.get(e.value);t?.ref?.line===r&&(t.ref.generated=!0),t?.labelRef?.line===r&&(t.labelRef.generated=!0)}}}function ip(e,t,n,r){let i=0,a=!0;for(;i<t.length;){let o=t[i];if(o.kind===`punct`&&o.value===`,`){i++,a=!0;continue}if(!a&&o.kind===`ident`){let n=[t[i-1].value];for(;t[i]?.kind===`ident`;)n.push(t[i++].value);let a=n.join(` `),o=n[0].toLowerCase();e.warn(r,o===`subgraph`||o===`end`?`"${n[0]}" is Mermaid syntax: write group id "Label" { ... }`:`"${a}" looks like a label: write ${n.join(`_`).toLowerCase()} "${a}" (or separate nodes with commas)`,`error`);break}if(o.kind===`punct`&&o.value===`{`&&i===t.length-1&&i>0&&t[i-1].kind!==`punct`){let n=t.slice(0,i).reverse().find(e=>e.kind===`ident`);e.stack.push({kind:`body`,id:n.value,start:r,lines:[]});break}if(o.kind!==`ident`){e.warn(r,`Unexpected "${o.value}"`,`error`);break}a=!1;let s=gf(e,o.value);s.implicit=!1;let c=hf(e);for(c&&s.group&&s.group!==c&&e.warn(r,`"${o.value}" is already in group "${s.group}": a node lives in one group, so it moves to "${c}"`),c&&(s.group=c),i++,t[i]?.kind===`string`?_f(e,s,t[i++],r,!1):s.labelRef??={line:r,at:o.end,generated:e.gen||void 0};t[i]?.kind===`class`;){let n=t[i++].value;mf(e,n,r),s.classes.includes(n)||s.classes.push(n)}let l={line:r,insertAt:t[i-1].end,generated:e.gen||void 0};t[i]?.kind===`props`&&(Ir(s,Lr(t[i],s.id,r,e.warn),r),l.props=[t[i].start,t[i].end],i++),s.ref=l,e.lastDecl={indent:pf(n),targets:[s]}}}function ap(e){lp(e),up(e),e.hasExport&&dp(e),fp(e),pp(e),hr(e.d,e=>Cr.get(e)?.options),e.opts.chain||t(e.d.diagnostics,()=>Tr.forEach(t=>t(e.d))),mp(e),hp(e),e.opts.chain||cp(e)}var op=2e3,sp=2e3;function cp(e){let{nodes:t,edges:n}=e.d;t.size<=op&&n.length<=sp||(e.warn(0,`Diagram too large to lay out: ${t.size} nodes and ${n.length} edges (at most ${op} nodes and ${sp} edges). The graph is not drawn; split it into files or panels`,`error`),t.clear(),n.length=0,e.d.groups.clear())}function lp(e){let t=ve(e.d.themes);for(let[n,r]of e.themeLines){let i=e.d.themes[n].base;i&&i!==n&&!t.includes(i)&&e.warn(r,`Unknown base theme "${i}"${or(i,t)}`)}let n=e.d.settings.theme;e.themeLine!==void 0&&n&&!n.includes(`$`)&&!t.includes(n)&&e.warn(e.themeLine,`Unknown theme "${n}"${or(n,t)||` (use one of: ${t.join(`, `)})`}`)}function up(e){let t=new Set;for(let[n,r]of e.classUses)e.d.classes[n]||t.has(`${r}.${n}`)||(t.add(`${r}.${n}`),e.warn(r,`Unknown class ".${n}"`))}function dp(e){let{d:t}=e,n=new Set(t.panels.map(e=>e.id));t.exports=[...e.exported.keys()].filter(r=>r.startsWith(`.`)?r.slice(1)in t.classes:r.startsWith(`$`)?r.slice(1)in e.vars:t.nodes.has(r)||t.groups.has(r)||n.has(r)||r in e.defs||r in(t.themes??{}));for(let[n,r]of e.exported)!t.exports.includes(n)&&!Cr.has(n)&&n!==`group`&&n!==`def`&&e.warn(r,`export: "${n}" is not declared in this file`)}function fp(e){let{d:t}=e;for(let e of t.panels){t.nodes.get(e.id)?.implicit&&t.nodes.delete(e.id);let n=t.layout.nodes[e.id];n&&(n.x!==void 0&&n.y!==void 0&&(Tf(t,e.id).at={x:n.x,y:n.y}),delete t.layout.nodes[e.id])}}function pp(e){let{d:t}=e,n=new Map;for(let r of t.panels){let t=n.get(r.id);t?r.lines&&e.warn(r.lines[0],`panel id "${r.id}" is already used${t.lines?` on line ${t.lines[0]+1}`:` by an import`}: layout, edges and edits can't tell them apart, rename one`):n.set(r.id,r)}for(let[n,r]of t.groups)if(t.nodes.has(n)){let i=t.edges.find(e=>e.ref&&(e.from===n||e.to===n))?.ref?.line??r.ref?.line??0;e.warn(i,`"${n}" is both a node and a group. Edges connect nodes, not groups: use a node inside "${n}", or rename one of them`)}}function mp(e){let{d:t}=e;for(let n of Object.keys(t.layout.nodes)){let r=e.layoutLines.get(n);r!==void 0&&!t.nodes.has(n)&&!t.groups.has(n)&&e.warn(r,`layout: there is no node "${n}" (renamed or deleted?); remove this line${or(n,[...t.nodes.keys()])}`)}}function hp(e){let{d:t}=e,n=0;for(let r of t.groups.values())ut(t,r)?n++:r.parent&&M(pt(t,r).lane,!1)&&r.props.lane!==void 0&&r.ref&&e.warn(r.ref.line,`"${r.id}" is inside "${r.parent}": only a top-level group can be a lane`);if(!n)return;let r=[...t.nodes.values()].filter(e=>{let n=e.group;for(;n&&t.groups.get(n)?.parent;)n=t.groups.get(n).parent;return!n||!ut(t,t.groups.get(n))});if(r.length){let t=r.slice(0,3).map(e=>`"${e.id}"`),n=r.length>3?` and ${r.length-3} more`:``;e.warn(r[0].ref?.line??0,`${t.join(`, `)}${n} ${r.length>1?`are`:`is`} in no lane: ${r.length>1?`they sit`:`it sits`} after the last lane`)}}var gp=e=>/\.(yu|yuhwa)$/i.test(e);function _p(e,t){if(/^[a-z][a-z0-9+.-]*:/i.test(t))return t;let n=t.startsWith(`/`)||!e?``:e.replace(/[^/]*$/,``),r=(n+t).startsWith(`/`),i=[];for(let e of(n+t).split(`/`))if(e&&e!==`.`){if(e===`..`&&i.length&&i[i.length-1]!==`..`)i.pop();else if(e===`..`&&r)continue;else i.push(e)}return(r?`/`:``)+i.join(`/`)}function vp(e,t,n,r){let{opts:i,merged:a}=e;if(!i.resolve)return e.warn(n,`Cannot import "${t}": no resolver (pass { resolve } to render, or use the CLI)`,`error`);let o=_p(i.file,t);if(!gp(o))return e.warn(n,`Cannot import "${t}": imports must be .yu files`,`error`);let s=[...i.chain??(i.file?[i.file]:[])];if(s.includes(o))return e.warn(n,`Import cycle: ${[...s,o].join(` -> `)}`,`error`);let c=r?`${o}{${r.map(e=>e.join(` as `)).join(`,`)}}`:o;if(a.has(c))return;let l;try{l=i.resolve(o)}catch{l=void 0}if(l==null)return e.warn(n,`Cannot import "${t}": file not found (${o})`,`error`);if(typeof l!=`string`){let r=l instanceof Promise?`a Promise (resolve must be synchronous)`:typeof l;return e.warn(n,`Cannot import "${t}": the resolver returned ${r}, not the source text`,`error`)}let u=new Set(a),d=e.parse(l,{resolve:i.resolve,file:o,chain:[...s,o],seen:u});for(let r of d.diagnostics)e.warn(n,`${t}:${r.line}: ${r.message}`,r.severity);let f=xf(d,r,r=>e.warn(n,`${t}: ${r}`,`error`));if(f===d)for(let e of u)a.add(e);a.add(c),Cf(e.d,f,e.edgeCount),(e.d.imports??=[]).push(o,...d.imports??[])}function yp(e,t,n,r){if(e.stack.length)e.warn(n,`import must be at the top level`,`error`);else if(!t[1])e.warn(n,`import needs a path: import "./shared.yu"`,`error`);else if(!r)t.length>2&&e.warn(n,`Unexpected "${t[2].value}" after import path`,`error`),vp(e,t[1].value,n);else{let r=bf(t,n,e.warn);r&&vp(e,r.path,n,r.names)}}function bp(e,t,n,r){let i=()=>e.step(n.slice(0,t[0].start)+` `.repeat(6)+n.slice(t[0].end),r);e.stack.length&&e.warn(r,`export must be at the top level`,`error`);let a=t[1].kind===`ident`&&t[2]?.value===`:`&&_r.has(t[1].value.toLowerCase());if(a||t[1].value===`theme`&&t[2]?.kind===`ident`){let n=t[1].value.toLowerCase();return a&&!e.d.sharedSettings?.includes(n)&&(e.d.sharedSettings??=[]).push(n),i()}e.hasExport=!0;let o=t.slice(1).every(e=>e.kind===`ident`||e.kind===`class`||e.value===`,`),s=t=>e.exported.has(t)||e.exported.set(t,r);if(t[1].value===`def`&&t[2])s(t[2].value);else if(t[1].value.startsWith(`$`)&&(t[2]?.value===`:`||t[2]?.value===`=`))s(t[1].value);else for(let e of t.slice(1))(e.kind===`ident`||e.kind===`class`)&&s(e.kind===`class`?`.${e.value}`:e.value);if(!o||t.slice(1).some(e=>e.kind===`ident`&&Cr.has(e.value)))return i()}function xp(e,t={}){let n=df(),r=t.seen??=new Set;t.file&&r.add(t.file);let i={d:n,opts:t,lines:e.split(/\r?\n/),stack:[],merged:r,edgeCount:new Map,exported:new Map,hasExport:!1,classUses:[],themeLines:new Map,labelled:new Map,layoutLines:new Map,vars:n.vars=l({}),defs:n.defs=l({}),used:n.used=new Set,gen:!1,depth:0,expanded:0,tooDeep:new Set,lastDecl:null,warn:(e,t,r=`warning`)=>n.diagnostics.push({line:e+1,message:t,severity:r,code:r===`error`?`syntax`:`parse`}),step:(e,t,n,r)=>Sp(i,e,t,n,r),statement:(e,t)=>Cp(i,e,t),parse:xp};Gf.set(i.defs,i.defs);for(let e=0;e<i.lines.length;e++)Sp(i,i.lines[e],e);return Lf(i),ap(i),n}function Sp(e,t,n,r=!1,i=e.defs){if(/^\s*#(\s|$)/.test(t)){e.warn(n,`Comments start with "//", not "#"`,`error`);return}let a=e.stack[e.stack.length-1];if(a?.kind===`def`)return Yf(e,a,t,n,i);let o=a?.kind===`body`||a?.kind===`panel`;if(!o&&a?.kind!==`layout`&&Xf(e,t,n,r,i))return;let s=r||a?.kind===`layout`||!o&&/^\s*(import|export)\b/.test(t)?t:qf(e,t,n,void 0,o),c=e.gen;e.gen||=s!==t,Cp(e,s,n),e.gen=c}function Cp(e,t,n){let r=e.stack[e.stack.length-1];if(Df(e,r,t,n))return;let{tokens:i,codeEnd:a}=Pr(t);if(!i.length)return;let o=Xr(i,t);if(o){e.warn(n,o,`error`);return}if(i[0].kind===`punct`&&i[0].value===`}`)return Nf(e,n);let s=i[0].kind===`ident`?i[0].value:void 0,c=i[1]?.value===`{`&&i.some(e=>e.kind===`ident`&&e.value===`from`);if(s===`import`&&(i[1]?.kind===`string`||i.length===1||c))return yp(e,i,n,c);if(s===`export`&&i.length>1&&i[1].kind!==`arrow`&&i[1].value!==`:`)return bp(e,i,t,n);let l=s===void 0?void 0:wr.get(s);if(l&&i[1]?.kind!==`arrow`&&i[1]?.value!==`:`&&i[1]?.value!==`,`){l.parse(t.slice(i[0].end,a).trim(),e.d,{line:n,warn:(t,r)=>e.warn(n,t,r)});return}if(s===`theme`&&i[1]?.kind===`ident`&&(i[2]?.kind===`props`||i[2]?.value===`{`))return Pf(e,i,n);let u=i[i.length-1].value===`{`;if(s!==void 0&&i.length>2&&!Cr.has(s)&&i[1].kind===`ident`&&u&&s!==`group`&&s!==`layout`&&e.warn(n,Qr(i)),s!==void 0&&Cr.has(s)&&u&&(i[1]?.kind===`ident`||i[1]?.kind===`string`||i[1]?.kind===`props`||i[1]?.value===`{`))return Ff(e,i,n);if(s===`layout`&&i[1]?.value===`{`)return If(e,i,n);if(s===`group`&&(i[1]?.kind===`ident`||i[1]?.kind===`string`&&i.some(e=>e.value===`{`)))return $f(e,i,t,n);let d=i[i.length-1];if(i[0].kind===`class`&&i.slice(1,-1).every(e=>e.kind===`class`)&&(d.kind===`props`||d.kind===`class`))return ep(e,i,t,n);if(s!==void 0&&i[1]?.kind===`punct`&&i[1].value===`:`)return np(e,i,t,n,a,r);if(i.some(e=>e.kind===`arrow`))return rp(e,i,t,n,a);ip(e,i,t,n)}function wp(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 ni.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:F(e.slice(0,s)),right:F(e.slice(s+4).trim())}):t.push({kind:`text`,left:F(e),right:null})}for(let[e,t]of n)t.finish?.(e);return t}var Tp=e=>ni.rows.find(t=>t.kind===e.kind);function Ep(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,z(e.left,t,n,r,o)+(e.right?t*2+z(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=Tp(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 Dp(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(`
|
|
12
|
+
`):[],o=e.sub?e.sub.split(`
|
|
13
|
+
`):[],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)=>Ie(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=>Ie(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?Ep(wp(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?ni.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 Op(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(Ye(c+e.iconSize/2,t,e.iconSize,a.text,I(e.icon),` text-anchor="middle"`)),n+=e.iconSize+8);let r=e.letterSpacing?` letter-spacing="${L(e.letterSpacing)}"`:``;e.label.forEach((i,l)=>s.push(Ye(l?c:n,t+l*e.labelLh,e.labelSize,e.caps?a.sub:a.text,Ge(i,e.caps?Te(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(Ye(c,i+e.subLh/2,e.subSize,a.sub,Ge(t,Te(a),o),` xml:space="preserve"`)),i+=e.subLh;e.meta&&s.push(Ye(l,t,e.subSize,a.sub,Ge(e.meta,Te(a),o),` text-anchor="end" xml:space="preserve"`))}if(e.divider){let n=u+e.headH+e.sep/2;s.push(`<path d="M${L(t)},${L(n)}H${L(t+r)}" stroke="${a.stroke}" stroke-width="1"/>`)}return e.body&&s.push(kp(e.body,c,l,u+e.headH+e.sep,{...a,text:a.body},o)),s.join(``)}function kp(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(et(r.left,t,c,s,i,a,!1,e.weight)),r.right&&o.push(et(r.right,n-Qe(r.right),c,s,i,a,!1,e.weight))}else l.kind===`rule`?o.push(`<path d="M${L(t)},${L(d+f/2)}H${L(n)}" stroke="${i.stroke}" stroke-width="1"/>`):l.kind!==`gap`&&o.push(Tp(l)?.render(l,{x:t,y:d,w:n-t,h:f},c)??``)}),`<g class="body"${e.mono&&!a.mono?` font-family="${I(g)}"`:``}>${o.join(``)}</g>`}function Ap(e,t){let n={top:0,right:0,bottom:0,left:0};for(let r of e)n.top+=t(r,`top`),n.right+=t(r,`right`),n.bottom+=t(r,`bottom`),n.left+=t(r,`left`);return n}function jp(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Mp(e,t,n){let r=new Map;for(let i of e){let e=t.get(i);if(e){let t=n.get(i);r.get(t)?.push(e)??r.set(t,[e])}}return[...r.values()]}function Np(e,t,n){let r=[];for(let i of e.split(`
|
|
14
|
+
`)){if(!(t>0)||n(i)<=t){r.push(i);continue}let e=``;for(let a of Ne(i)){let i=e?`${e} ${a}`:a;e&&n(i)>t?(r.push(e),e=a):e=i}r.push(e)}return r}function Pp(e,t,n,r,i,a,o,s=!1,c=0,l=a.mono){let u=s?r*.1:0,d=Math.round(r*.82*10)/10,f=e=>{let t=new Map;return n=>t.get(n)??(t.set(n,e(n)),t.get(n))},p=f(e=>Ie(e,r,i,l,o,s,u)),m=f(e=>Ie(e,d,400,l,o)),h=Np(e,c,p),g=t?Np(t,c,m):[],_=ze(h,r),v=ze(g,d,1.35),y=Math.round(r*1.6),b=0;for(let e of h)b=Math.max(b,p(e));for(let e of g)b=Math.max(b,m(e));let x=h.length*_+g.length*v+(g.length?3:0);return n&&(x+=y+4,b=Math.max(b,y)),{lines:h,sub:g,icon:n,lineHeight:_,subSize:d,subLineHeight:v,iconSize:y,letterSpacing:u,caps:s,w:b,h:x}}function Fp(e,t){let{title:n,subtitle:r}=e.settings;if(!n&&!r)return null;let i=t.fontSize*1.3,a=t.fontSize*.95;return{titleSize:i,subSize:a,h:(n?i*1.3:0)+(r?a*1.5:0)+10}}var Ip=e=>e===`right`||e===`left`,Lp=(e,t=0)=>Math.ceil(Math.max(e,t)/2)*2,Rp=(e,t)=>e[0]-t[0]||e[1]-t[1],zp=(e,t,n)=>{let r=n?.get(e);return r===void 0?[1,t]:[0,r]};function Bp(e){let t=new Map;for(let[n,r]of e)r.fixedOrder!==void 0&&t.set(n,r.fixedOrder);return t}function Vp(e,t){let n=new Map,r=new Map;for(let t of e){let e=new Set,i=new Map;t.forEach((r,a)=>{r.path.forEach((o,s)=>{let c=n.get(o)??[0,0];if(c[0]+=(a+.5)/t.length,c[1]++,n.set(o,c),!e.has(o)){e.add(o);let t=s?r.path[s-1]:``;i.set(t,[...i.get(t)??[],o])}})});for(let e of i.values())e.forEach((t,n)=>{let i=r.get(t)??new Map;r.set(t,i);for(let t of e.slice(n+1))i.set(t,(i.get(t)??0)+1)})}let i=new Map([...n].map(([e,[t,n]])=>[e,t/n])),a=new Map,o=new Map([...i.keys()].map(e=>[e,0]));for(let[e,t]of r)for(let[n,i]of t)i>(r.get(n)?.get(e)??0)&&(a.set(e,[...a.get(e)??[],n]),o.set(n,o.get(n)+1));let s=[...i.keys()].sort((e,t)=>i.get(e)-i.get(t)),c=[];for(;s.length;){let e=Math.max(0,s.findIndex(e=>o.get(e)===0)),t=s.splice(e,1)[0];c.push(t);for(let e of a.get(t)??[])o.set(e,o.get(e)-1)}let l=c.map((e,n)=>({g:e,key:zp(e,n,t)}));return l.sort((e,t)=>Rp(e.key,t.key)),new Map(l.map(({g:e},t)=>[e,t]))}function Hp(e,t,n,r,i=new Map){let a=e=>i.get(e)?.spansAllRanks===!0,o=e.flat(),s=new Map;for(let e of o)e.path.forEach((t,n)=>{let r=s.get(t);r||s.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 c=[...s.keys()];if(!c.length)return new Map;for(let[t,n]of s)a(t)&&(n.r0=0,n.r1=e.length-1);let l=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}),u=n*.5+6,d=Bp(i),f=Vp(e,d),p=e=>`\0L${e}`,m=e=>`\0R${e}`,h=new Map(o.map(e=>[e.id,e.pos]));for(let e of c)h.set(p(e),-1/0).set(m(e),-1/0);let g=new Map([...h.keys()].map(e=>[e,[]])),_=new Map([...h.keys()].map(e=>[e,0])),v=(e,t,n)=>{g.get(e).push([t,n]),_.set(t,_.get(t)+1)};for(let t of e)for(let e=1;e<t.length;e++)v(t[e-1].id,t[e].id,r(t[e-1],t[e]));for(let[n,{members:r,gPath:i,r0:o,r1:c}]of s){let s=1/0,g=-1/0;for(let e of r){let r=e.path.slice(e.path.indexOf(n)),i=e.oExt/2+r.reduce((e,n)=>e+t.low(n),0),a=e.oExt/2+r.reduce((e,n)=>e+t.high(n),0);v(p(n),e.id,i),v(e.id,m(n),a),s=Math.min(s,e.pos-i),g=Math.max(g,e.pos+a)}a(n)&&Number.isFinite(s)&&h.set(p(n),s);let _=(s+g)/2,y=e=>{let t=i.findIndex((t,n)=>e.path[n]!==t),n=e.path[t];return n===void 0?t===0&&d.has(i[0])?!1:void 0:f.get(n)<f.get(i[t])};for(let t=o;t<=c;t++){let r=e[t],i=l[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=y(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<_;)n++;a=[n-1,n]}let[o,s]=a;o>=0&&v(r[o].id,p(n),r[o].oExt/2+u),s<r.length&&v(m(n),r[s].id,r[s].oExt/2+u)}}for(let[e,t]of i)t.minThickness!==void 0&&s.has(e)&&v(p(e),m(e),t.minThickness);let y=new Map;for(let[e,t]of s){let n=t.gPath.slice(0,-1).join(`\0`);y.set(n,[...y.get(n)??[],e])}for(let e of y.values())for(let t of e)for(let n of e){let[e,r]=[s.get(t),s.get(n)];f.get(t)>=f.get(n)||e.r1<r.r0||r.r1<e.r0||v(m(t),p(n),u)}let b=[..._].filter(([,e])=>e===0).map(([e])=>e),x=new Set;for(;x.size<h.size;){if(!b.length){let e=``,t=1/0;for(let[n,r]of _)!x.has(n)&&r<t&&([e,t]=[n,r]);b.push(e)}let e=b.pop();if(!x.has(e)){x.add(e);for(let[t,n]of g.get(e))x.has(t)||(h.set(t,Math.max(h.get(t),h.get(e)+n)),_.set(t,_.get(t)-1),_.get(t)===0&&b.push(t))}}for(let e of o)e.pos=h.get(e.id);let S=new Map;for(let e of i.keys())a(e)&&s.has(e)&&S.set(e,[h.get(p(e)),h.get(m(e))]);return S}function Up(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 Wp(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 Gp(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=ur(pt(e,r))?.[0];if(!r.ref||!i)continue;let a=lr(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`,code:`layout`})}}function Kp(e,t,n){let r=[],i=new Map,a=[],o=Ip(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=ur(pt(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 qp(e,t,n){let r=new Map;n.forEach((e,t)=>e.forEach(e=>r.set(e,t)));for(let i=0;i<50;i++){let i=!1;for(let t of n){let n=Math.max(...t.map(t=>e.get(t)));for(let r of t)e.get(r)!==n&&(e.set(r,n),i=!0)}for(let n of t){let[t,a]=n.reversed?[n.to,n.from]:[n.from,n.to];if(r.has(t)&&r.get(t)===r.get(a))continue;let o=e.get(t)+(n.len??1);e.get(a)<o&&(e.set(a,o),i=!0)}if(!i)return}}function Jp(e,t){let n=new Set,r=new Map;if(e.length)for(let e of t.values())for(let t of e.path)r.get(t)?.push(e)??r.set(t,[e]);for(let{side:i,ids:a,within:o}of e){let e=a.map(e=>t.has(e)?[t.get(e)]:r.get(e)??[]).filter(e=>e.some(e=>e.real));if(o&&(e=Yp(e)),e.length<2)continue;let s=e.map(e=>{let t=e.filter(e=>e.real),n=Math.min(...t.map(e=>e.pos-e.oExt/2)),r=Math.max(...t.map(e=>e.pos+e.oExt/2));return i===`left`||i===`top`?n:i===`right`||i===`bottom`?r:(n+r)/2}),c=s.reduce((e,t)=>e+t,0)/s.length;e.forEach((e,t)=>{for(let r of e)r.pos+=c-s[t],n.add(r)})}return n}function Yp(e){let t=[];for(let n of e){let e=new Set(n.filter(e=>e.real).map(e=>e.rank)),r=t.filter(t=>t.some(t=>t.real&&e.has(t.rank)));t.splice(0,t.length,...t.filter(e=>!r.includes(e)),[...r.flat(),...n])}return t}function Xp(e,t,n){for(let{side:r,ids:i}of e){let[e,a]=r===`top`||r===`bottom`?[`y`,`h`]:[`x`,`w`];for(let o of Mp(i,t,n))if(r===`top`||r===`left`){let t=Math.min(...o.map(t=>t[e]));o.forEach(n=>n[e]=t)}else{let t=Math.max(...o.map(t=>t[e]+t[a]));o.forEach(n=>n[e]=t-n[a])}}}function Zp(e,t,n,r=new Map,i){let a=new Map;for(let t of e)for(let e of t)e.u=a.size,a.set(e.id,e.u);let o=a.size,s=Array(o),c=Array(o);for(let[e,r]of a)s[r]=t.get(e).map(([e])=>a.get(e)),c[r]=n.get(e).map(([e])=>a.get(e));let l=new Int32Array(o),u=e=>e.forEach((e,t)=>l[e.u]=t),d=new Float64Array(o),f=new Int32Array(o);e.forEach((e,t)=>e.forEach(e=>f[e.u]=t));let p=[];for(let[e,[t,n]]of r){let r=a.get(e),i=a.get(t);r!==void 0&&i!==void 0&&p.push([r,i,n])}let m=e=>{for(let t=0;t<Math.min(r.size,8);t++)for(let[t,n,r]of p)f[t]===e&&f[n]===e&&(d[t]=d[n]+r*.001)};e.forEach((e,t)=>{e.forEach((e,t)=>d[e.u]=t),m(t),em(e,d,i),u(e)});let h=()=>{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=c[o.u].map(e=>l[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},g=e.map(e=>[...e]),_=h();for(let t=0;t<24&&_>0;t++){let n=t%2==0,r=n?s:c;for(let t=1;t<e.length;t++){let a=n?t:e.length-1-t,o=e[a];for(let e of o){let t=r[e.u],n=0;for(let e of t)n+=l[e];d[e.u]=t.length?n/t.length:l[e.u]}m(a),em(o,d,i),u(o)}let a=h();a<_&&(_=a,g=e.map(e=>[...e]))}g.forEach((t,n)=>e[n]=t),Qp(e,i)}function Qp(e,t){let n=Vp(e,t);if(!n.size)return;let r=e=>n.get(e),i=(e,t)=>{let n=[];for(let r of e){let e=r.path[t],i=n[n.length-1];e!==void 0&&i?.g===e?i.nodes.push(r):n.push({g:e,nodes:[r]})}let a=n.map((e,t)=>e.g===void 0?-1:t).filter(e=>e>=0),o=a.map(e=>n[e]).sort((e,t)=>r(e.g)-r(t.g));return a.forEach((e,t)=>n[e]=o[t]),n.flatMap(e=>e.g===void 0?e.nodes:i(e.nodes,t+1))};for(let t=0;t<e.length;t++)e[t]=i(e[t],0)}var $p=[1,0];function em(e,t,n){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 r=new Map,i=new Map;for(let n of e)for(let e of n.path){let r=i.get(e)??[0,0];r[0]+=t[n.u],r[1]++,i.set(e,r)}for(let[e,[t,a]]of i)r.set(e,zp(e,t/a,n));let a=e.map((e,n)=>({v:e,orig:n,ent:[...e.path,e.id],val:[...e.path.map(e=>r.get(e)),[1,t[e.u]]]}));a.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])return Rp(e.val[r]??$p,t.val[r]??$p)||e.orig-t.orig;return e.orig-t.orig}),a.forEach((t,n)=>e[n]=t.v)}function tm(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 nm(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 rm(e,t,n){let r=e.props,{size:i,weight:a,caps:o,spacing:s,mono:c}=im(e,t),l=e=>Ie(e,i,a,c,n,o,s),u=r.meta?Ie(r.meta,t.fontSize*.82,400,t.mono,n):0;return{text:e.label,width:l,meta:u,lineHeight:Math.round(ze(e.label.split(`
|
|
15
|
+
`),i)*10)/10}}function im(e,t){let n=M(e.props.caps,!1),r=st(e.props,t.fontSize*.82,600,t),i=n?r.size*.92:r.size;return{...r,size:i,caps:n,spacing:i*(n?.1:.02)}}var am=14,om=12;function sm(e,t,n,r,i,a,o){let s=e.groups.get(t);if(!s.label)return;let c=rm(s,a,o),l=Math.max(...c.text.split(`
|
|
16
|
+
`).map(c.width)),u=2*am+l+(c.meta?c.meta+om:0);if(u<=n.w&&!c.text.includes(`
|
|
17
|
+
`))return;if(u>n.w){let a=n=>lt(e,n).includes(t),o=[],s=lt(e,t),c=(t,n,r)=>{let i=jp(n,s),a=[...n.slice(i,n.length-r),...s.slice(i,s.length-1)].reduce((t,n)=>{let r=ht(e,n,18);return t+Math.max(r.top,r.right,r.bottom,r.left)},0);o.push({x:t.x-a,y:t.y-a,w:t.w+2*a,h:t.h+2*a})};for(let n of r.values()){let r=lt(e,n.decl.group);r.includes(t)||c(n,r,0)}for(let[t,n]of i)!a(t)&&!s.includes(t)&&c(n,lt(e,t),1);let l=-1/0,d=1/0;for(let e of o)e.y>=n.y+n.h+9||e.y+e.h<=n.y-9||(e.x+e.w<=n.x+1?l=Math.max(l,e.x+e.w+9):e.x>=n.x+n.w-1&&(d=Math.min(d,e.x-9)));let f=u-n.w,p=Math.max(0,Math.min(f,d-n.x-n.w)),m=Math.max(0,Math.min(f-p,n.x-l));n.x=Math.floor(n.x-m),n.w=Math.ceil(n.w+m+p)}let d=n.w-2*am-(c.meta?c.meta+om:0),f=Np(c.text,Math.max(d,40),c.width);if(f.length===1)return;let p=(f.length-1)*c.lineHeight;return n.y-=p,n.h+=p,{lines:f,header:26+p,lineHeight:c.lineHeight}}function cm(e,t,n,r,i=()=>!1){let a=t=>lt(e,t).length,o=[...e.groups.keys()].filter(e=>!i(e)).sort((e,t)=>a(t)-a(e)),s=new Map,c=[];for(let i of o){let o=[];for(let e of t.values())e.decl.group===i&&o.push(e);for(let[t,n]of s)e.groups.get(t).parent===i&&o.push(n);if(!o.length)continue;let l=ht(e,i,18),u=Math.min(...o.map(e=>e.x))-l.left,d=Math.min(...o.map(e=>e.y))-l.top-26,f=Math.max(...o.map(e=>e.x+e.w))+l.right,p=Math.max(...o.map(e=>e.y+e.h))+l.bottom,m={x:u,y:d,w:f-u,h:p-d},h=sm(e,i,m,t,s,n,r);s.set(i,m);let g=e.groups.get(i);c.push({id:i,decl:g,depth:a(i),...m,...h,style:yt({...g,props:pt(e,g)},n)})}return c.sort((e,t)=>e.depth-t.depth)}function lm(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 um(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=at(t.settings.padding,24);a-=l,o-=l,s+=l,c+=l;let u=Fp(t,n);if(u){o-=u.h;let e=yi(r);t.settings.title&&(s=Math.max(s,a+l+z(F(t.settings.title),u.titleSize,n.mono,e,650)+l)),t.settings.subtitle&&(s=Math.max(s,a+l+z(F(t.settings.subtitle),u.subSize,n.mono,e)+l))}let d=[];for(let e of ni.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 dm=(e,t)=>e?t*1.95:0;function fm(e,t,n,r){let i=ot(e.props[`font-size`])??n.fontSize,a=ot(e.props.width);return{theme:n,measure:r,fs:i,props:e.props,offsets:t,width:a&&Math.max(0,a-32)}}function pm(e,t,n,r){let i=[];for(let r of e.panels){let a=ni.panels.get(r.kind);if(!a)continue;let o=e.layout.panels?.[r.id]?.parts??{},s=fm(r,o,xt(t,r.props,e.themes),n),c=r.failed?{w:0,h:0}:a.measure(r.data,s),l=dm(r.label,s.fs),u=st(r.props,s.fs,650,t),d=r.label?Ie(r.label,s.fs*1.05,u.weight,u.mono,n):0,f=Lp(Math.max(c.w,d)+32,ot(r.props.width)),p=Lp(c.h+l+32,ot(r.props.height)),m={x:0,y:0,w:f-32,h:r.props.height?p-l-32:c.h},h;i.push({decl:r,box:{x:0,y:0,w:f,h:p},inner:m,offsets:o,ctx:s,get handles(){return h??=!r.failed&&a.handles?.(r.data,m,s)||[]}})}if(!i.length)return i;let a=at(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+dm(t.decl.label,t.ctx.fs)}return i}function mm(e,t,n,r,i,a,o){let s=at(e.settings.padding,24),c=Math.max(...[...t.keys()].map(e=>n.get(e))),l=new Map;for(let e of t.values()){let t=o.frames.get(e.id);l.set(e.id,{x:e.x-t.left,y:e.y-t.top,w:e.w+t.left+t.right,h:e.h+t.top+t.bottom})}let u=Array(c+1).fill(!1),d=new Map;for(let r of t.values())for(let t of lt(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 hm(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=>nm(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 gm(e,t,n,r,i,a){let[o,s]=r?[`y`,`h`]:[`x`,`w`],c=e=>Mp(e,t,n).map(e=>e.sort((e,t)=>e[o]-t[o])),l=new Map;for(let e of t.values())e.decl.group&&(l.get(e.decl.group)?.push(e.id)??l.set(e.decl.group,[e.id]));for(let[n,r]of l){if(!r.some(e=>t.get(e).pinned))continue;let i=gt(e,n,NaN);if(!Number.isNaN(i))for(let e of c(r))e.forEach((t,n)=>n&&(t[o]=e[n-1][o]+e[n-1][s]+i))}for(let{side:e,ids:n,within:r}of i){let i=r?c(n):n.flatMap(e=>t.has(e)?[[t.get(e)]]:[]),a=i.map(t=>e===`center`?t[0][o]+t[0][s]/2:e===`top`||e===`left`?t[0][o]:t[0][o]+t[0][s]),l=e===`center`?a.reduce((e,t)=>e+t,0)/a.length:e===`top`||e===`left`?Math.min(...a):Math.max(...a);i.forEach((e,t)=>e.forEach(e=>e[o]+=l-a[t]))}Xp(a,t,n)}var _m=168,vm=40,ym=(e,t,n,r)=>({groups:new Map(e.map((e,t)=>[e,{fixedOrder:t,spansAllRanks:!0,header:n,minThickness:r[t]}])),heads:t,header:n});function bm(e,t,n,r){let i=[...e.groups.values()].filter(t=>ut(e,t)).map(e=>e.id);if(!i.length)return;let a=i.map(t=>rm(e.groups.get(t),n,r)),o=Math.max(0,...a.flatMap(e=>e.text?e.text.split(`
|
|
18
|
+
`).map(e.width):[]));if(t){let e=Math.ceil(Math.max(vm,Math.min(_m,o+28))),t=a.map(t=>{let n=t.text?Np(t.text,e-28,t.width).length:0;return Math.ceil(n*t.lineHeight+28)});return ym(i,a,{side:`left`,size:e},t)}let s=a.map(e=>{let t=e.text?Math.max(...e.text.split(`
|
|
19
|
+
`).map(e.width)):0;return Math.ceil(Math.min(208,t+28))});return ym(i,a,{side:`top`,size:xm(Math.max(1,...a.map(e=>e.text?e.text.split(`
|
|
20
|
+
`).length:1)),a[0]?.lineHeight??16)},s)}var xm=(e,t)=>Math.ceil(e*t+28-4),Sm={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function Cm(e,t,n,r,i,a,o){let{side:s}=t.header,c=s===`left`,l=e=>c?e.y:e.x,u=e=>c?e.y+e.h:e.x+e.w,d=e=>c?e.x:e.y,f=e=>c?e.x+e.w:e.y+e.h,p=c?`top`:`left`,m=new Map([...t.groups.keys()].map(e=>[e,[]]));for(let t of n.values())m.get(lt(e,t.decl.group)[0])?.push(t);for(let t of r)m.get(lt(e,t.id)[0])?.push(t);let h=1/0,g=-1/0,_=0,v=0;for(let e of t.groups.keys()){let t=a.get(e);_=Math.max(_,t[s]),v=Math.max(v,t[Sm[s]]);for(let t of m.get(e))h=Math.min(h,d(t)),g=Math.max(g,f(t))}Number.isFinite(h)||(h=0,g=160);let y=new Map,b=16,x=[...t.groups].map(([e,{minThickness:n}],r)=>{let o=a.get(e),s=m.get(e),c=Math.min(...s.map(l))-o[p],d=Math.max(...s.map(u))+o[Sm[p]],f=i.get(e);return f&&Number.isFinite(f[0])&&(c=Math.min(c,f[0])),f&&Number.isFinite(f[1])&&(d=Math.max(d,f[1])),{id:e,head:t.heads[r],min:n,lo:c,hi:d}});x.forEach((e,t)=>{if(Number.isFinite(e.lo)&&Number.isFinite(e.hi)||(e.lo=t?x[t-1].hi:0,e.hi=e.lo+48),e.hi-e.lo<e.min){let t=(e.min-(e.hi-e.lo))/2;e.lo-=t,e.hi+=t}});for(let e=1;e<x.length;e++){let t=Math.round((x[e-1].hi+x[e].lo)/2);x[e-1].hi=t}for(let e=1;e<x.length;e++)x[e].lo=x[e-1].hi,x[e].hi=Math.max(x[e].hi,x[e].lo+12);for(let e of x)if(e.lo=Math.round(e.lo),e.hi=Math.round(e.hi),!c){let t=e.head;b=t.lineHeight,y.set(e.id,t.text?Np(t.text,e.hi-e.lo-28,t.width):[])}let S=t.header.size;c||(S=xm(Math.max(1,...[...y.values()].map(e=>e.length)),b));let C=Math.round(h-_-S),w=Math.round(g+v);return x.map((t,n)=>{let r=e.groups.get(t.id),i=c?{x:C,y:t.lo,w:w-C,h:t.hi-t.lo}:{x:t.lo,y:C,w:t.hi-t.lo,h:w-C},a=t.head,l=c?a.text?Np(a.text,S-28,a.width):[]:y.get(t.id)??[];return{id:t.id,decl:r,depth:1,...i,lines:l,header:S,lineHeight:a.lineHeight,lane:{index:n,count:x.length,side:s},style:yt({...r,props:pt(e,r)},o)}})}function wm(e){let t=e.header??0;return e.lane?.side===`left`?{x:e.x,y:e.y,w:t,h:e.h}:{x:e.x,y:e.y,w:e.w,h:t}}function Tm(e,t,n,r,i){for(let a=0;a<4;a++)for(let a of e)a.forEach((e,o)=>{let s=t.get(e.path[0]);if(e.real||e.path.length!==1||!s)return;let c=i(e);if(!c.length)return;let l=0,u=0;for(let[e,t]of c)l+=e.pos*t,u+=t;let d=o>0?a[o-1].pos+n(a[o-1],e):-1/0,f=o+1<a.length?a[o+1].pos-n(e,a[o+1]):1/0;d=Math.max(d,s[0]+e.oExt/2+r.low(e.path[0])),f=Math.min(f,s[1]-e.oExt/2-r.high(e.path[0])),d<=f&&(e.pos=Math.max(d,Math.min(f,l/u)))})}function Em(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}=fe(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=M(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),M(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,rt(n,t)}var Dm=2e4;function Om(e,t){let n=e=>e.hidden?0:Math.abs(t.get(e.to)-t.get(e.from))-1,r=0;for(let t of e)r+=Math.max(0,n(t));let i=new Set;if(r<=Dm)return i;let a=e.map(e=>({idx:e.idx,n:n(e)})).filter(e=>e.n>0).sort((e,t)=>t.n-e.n);for(let e of a){if(r<=Dm)break;i.add(e.idx),r-=e.n}return i}function km(e,n={}){return t(e.diagnostics,()=>Am(e,n))}function Am(e,t){let n=Em(ye(t.theme??e.settings.theme,e.themes),e.settings),r=t.measure??t.measureFor?.(n)??_i,i=[`right`,`down`,`left`,`up`].includes(e.settings.direction)?e.settings.direction:`right`,a=Ip(i),o=at(e.settings.gap,36),s=[...e.nodes.values()].some(e=>e.group),c=at(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=pt(e,t),a=vt(e,t,i,n),o=jn(i.shape??u),s=i.caps!==void 0&&i.caps!==`false`,c=at(i[`max-width`],at(e.settings.wrap,0)),l=Pp(t.label,i.sub,i.icon,a.fontSize,a.fontWeight,n,r,s,c,a.mono),p;t.body?.length||i.meta||i.frame?(l.card=Dp({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=Nn(o,l.w,l.h),f.set(t.id,l);let m=e.layout.nodes[t.id],h=m?.w??Lp(at(i.width,p.w)),g=m?.h??Lp(at(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(tt(e.props.length,1))));m.push({from:e.from,to:e.to,idx:t,reversed:!1,len:n})});let h=Kp(e,d,i);m.unshift(...h.edges),Up(p,m);let g=Wp(p,m),_=a?[`center`,`top`,`bottom`]:[`center`,`left`,`right`],v=[],y=[];for(let t of kt(e))(_.includes(t.side)?v:y).push(t);let b=[...e.layout.ranks??[],...h.same,...y.filter(e=>!e.within).map(e=>e.ids)].map(e=>e.filter(e=>d.has(e))).filter(e=>e.length>1);b.length&&qp(g,m,b);let x=new Set(m.flatMap(e=>[e.from,e.to])),S=new Map;for(let t of e.edges)if(t.props.constraint===`false`&&d.has(t.from)&&d.has(t.to))for(let[e,n]of[[t.from,t.to],[t.to,t.from]])!x.has(e)&&x.has(n)&&!S.has(e)&&(S.set(e,[n,1]),g.set(e,g.get(n)));if(h.order.size){qp(g,m,[...b,...[...h.order].map(([e,[t]])=>[e,t])]);for(let[e,t]of h.order)S.set(e,t)}Gp(e,h,g);let C=bm(e,a,n,r),w=C?.groups??new Map,T=e=>e!==void 0&&w.get(e)?.spansAllRanks===!0,E=new Map;for(let t of p){let n=d.get(t);E.set(t,{id:t,real:!0,path:lt(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 D;for(let e of w.keys())if(T(e)&&!(D??=new Set([...E.values()].map(e=>e.path[0]))).has(e)){let t=`\u0000lane:${e}`;E.set(t,{id:t,real:!1,path:[e],oExt:48,rExt:0,rank:0,pos:0,u:0})}let O=[],k=new Map,A=Om(m,g);A.size&&e.diagnostics.push({line:0,message:`${A.size} long edges are drawn straight: routing them around nodes would take more than ${Dm} bends`,severity:`warning`,code:`layout`});let ee=(e,t,n,r,i)=>{if(e.length)return e;let a=r*2<=i?t:n;return T(a[0])?[a[0]]:[]};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){O.push([t,n,2]);continue}if(i-r<=1||A.has(e.idx)){O.push([t,n,1]);continue}let a=E.get(t).path,o=E.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 u=`\u0000${e.idx}:${n}`;E.set(u,{id:u,real:!1,path:ee(s,a,o,n-r,i-r),oExt:6,rExt:0,rank:n,pos:0,u:0}),O.push([c,u,c===t?1:2]),l.push(u),c=u}O.push([c,n,1]),k.set(e.idx,e.reversed?l.reverse():l)}let te=0;for(let e of E.values())te=Math.max(te,e.rank);let j=Array.from({length:te+1},()=>[]);for(let e of E.values())j[e.rank].push(e);let ne=new Map,re=new Map;for(let e of E.keys())ne.set(e,[]),re.set(e,[]);for(let[e,t,n]of O)re.get(e).push([t,n]),ne.get(t).push([e,n]);Zp(j,ne,re,S,Bp(w));let ie=new Map([...e.groups.keys()].map(t=>[t,ht(e,t,18)])),ae=new Map([...e.groups.keys()].map(t=>[t,gt(e,t,o)])),M=(e,t)=>{let n=w.get(e)?.header;return ie.get(e)[t]+((n?.side??`top`)===t?n?.size??26:0)},oe={low:e=>M(e,a?`top`:`left`),high:e=>M(e,a?`bottom`:`right`),start:e=>M(e,$t[_n[i]]),end:e=>M(e,_n[i])},se=(e,t)=>e.reduce((e,n)=>e+t(n),0),ce=(e,t)=>{let n=jp(e.path,t.path),r=e.path.slice(n),i=t.path.slice(n),a=se(r,oe.high)+se(i,oe.low)+(r.length+i.length>0?10:0),s=n?ae.get(e.path[n-1]):o,c=!e.real&&!t.real?14:!e.real||!t.real?s*.6:s;return(e.oExt+t.oExt)/2+c+a};for(let e of j){let t=0;e.forEach((n,r)=>{r>0&&(t+=ce(e[r-1],n)),n.pos=t})}let le=e=>e.length?e[e.length-1].pos-e[0].pos:0,ue=Math.max(...j.map(le));for(let e of j){let t=(ue-le(e))/2;for(let n of e)n.pos+=t}let de=e=>e.map(([e,t])=>[E.get(e),t]),fe=[],pe=[],me=[];for(let e of E.values())fe[e.u]=de(ne.get(e.id)),pe[e.u]=de(re.get(e.id)),me[e.u]=[...fe[e.u],...pe[e.u]];let he=j.map(e=>e.slice(1).map((t,n)=>ce(e[n],t))),ge=j.map((e,t)=>j.length-1-t),_e=j.map((e,t)=>t),ve=(e,t)=>{let n=e===`down`?fe:e===`up`?pe:me;for(let r of e===`up`?ge:_e){let e=j[r];if(!e.length)continue;let i=[],a=[];for(let r of e){if(t?.has(r)){i.push(r.pos),a.push(1e3);continue}let e=0,o=0;for(let[t,i]of n[r.u])o+=t.pos*i,e+=i;i.push(e?o/e:r.pos),a.push(e||.25)}let o=tm(i,a,he[r]);e.forEach((e,t)=>e.pos=o[t])}};for(let e=0;e<12;e++)ve(e%2==0?`down`:`up`);let be=Jp(v,E);for(let e=0;e<4;e++)ve(`both`,be);let xe=Hp(j,oe,o,ce,w);xe.size&&Tm(j,xe,ce,oe,e=>me[e.u]);let Se=j.map(e=>Math.max(0,...e.filter(e=>e.real).map(e=>e.rExt))),N=Array(j.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=ct(pt(e,t),n),s=t.label.split(`
|
|
21
|
+
`),c=a?Math.max(...s.map(e=>Ie(e,o.size,o.weight,o.mono,r)))+16:s.length*ze(s,o.size)+10;N[i]=Math.max(N[i],c)});let Ce=new Map;for(let e of E.values())for(let t of e.path){let n=Ce.get(t);Ce.set(t,n?[Math.min(n[0],e.rank),Math.max(n[1],e.rank)]:[e.rank,e.rank])}let we=Array(j.length).fill(0),P=Array(j.length).fill(0);for(let e of E.values()){let t=se(e.path.filter(t=>!T(t)&&Ce.get(t)[1]===e.rank),oe.end),n=se(e.path.filter(t=>!T(t)&&Ce.get(t)[0]===e.rank),oe.start);we[e.rank]=Math.max(we[e.rank],t),P[e.rank]=Math.max(P[e.rank],n)}let Te=Array(j.length).fill(-1),Ee=Array(j.length).fill(!1),De=new Map([...e.groups.keys()].map(t=>[t,gt(e,t,NaN)]));for(let t of e.edges){let[e,n]=[g.get(t.from),g.get(t.to)];if(e===void 0||n===void 0||e===n)continue;let r=E.get(t.from).path,i=jp(r,E.get(t.to).path),a=i?De.get(r[i-1]):NaN,o=Number.isNaN(a)?c:Math.max(a,20);for(let t=Math.min(e,n);t<Math.max(e,n);t++)Te[t]=Math.max(Te[t],o),Ee[t]||=Number.isNaN(a)}let Oe=[],ke=0;for(let e=0;e<j.length;e++){Oe.push(ke+Se[e]/2);let t=e+1<j.length?we[e]+P[e+1]:0,n=t?t+24:0,r=Te[e]>=0&&!Ee[e],i=Te[e]<0?c:Te[e];ke+=Se[e]+Math.max(i,N[e]+(r?20:44),n)}let Ae=(e,t)=>{switch(i){case`right`:return{x:e,y:t};case`left`:return{x:-e,y:t};case`down`:return{x:t,y:e};case`up`:return{x:t,y:-e}}};for(let e of E.values()){if(!e.real)continue;let t=d.get(e.id),n=Ae(Oe[e.rank],e.pos);t.x=n.x-t.w/2,t.y=n.y-t.h/2}Xp(y,d,g);let je=new Map;for(let[e,t]of k)je.set(e,t.map(e=>{let t=E.get(e);return Ae(Oe[t.rank],t.pos)}));let Me=new Map([...d.values()].map(e=>[e.id,Ap(E.get(e.id).path,M)])),F=0,Ne=1/0,Pe=1/0;for(let e of d.values())Ne=Math.min(Ne,e.x-Me.get(e.id).left),Pe=Math.min(Pe,e.y-Me.get(e.id).top);if(d.size){let e=-Ne,t=-Pe;F=a?t:e;for(let n of d.values())n.x=Math.round(n.x+e),n.y=Math.round(n.y+t);for(let n of je.values())for(let r of n)r.x=Math.round(r.x+e),r.y=Math.round(r.y+t)}let Fe=at(e.settings[`max-width`],0),Le=new Set,Re=[...d.keys()].some(t=>e.layout.nodes[t]?.x!==void 0),Be=[...w.keys()].some(T);if(Fe>0&&a&&d.size&&!Re&&!Be){let t=new Map;for(let[e,n]of k)t.set(e,n.map(e=>E.get(e).rank));mm(e,d,g,je,t,Le,{maxW:Fe,dir:i,rankGap:c,frames:Me})}hm(e,d,a,o);let Ve=[...d.values()].some(e=>e.pinned);Ve&&gm(e,d,g,a,v,y);let He=cm(e,d,n,r,T);if(C){let t=new Map;for(let[e,[n,r]]of Ve?[]:xe)t.set(e,[n+F,r+F]);He=[...Cm(e,C,d,He,t,ie,n),...He]}let Ue=new Map;Ve||e.edges.forEach((e,t)=>je.has(t)&&Ue.set(e.key,je.get(t)));let We=bn(e,d,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:Ue,channels:Ve?void 0:Le,obstacles:[...d.values()],groups:He.map(e=>({box:e,header:e.lane?wm(e):{x:e.x,y:e.y,w:e.w,h:(e.header??26)+9}}))}),Ge=t=>{if(!t.length)return[];let a=e.edges.filter(e=>!d.has(e.from)||!d.has(e.to));if(!a.length)return[];let o=new Map(d);for(let e of t)o.set(e.decl.id,{...e.box,id:e.decl.id,shape:`box`});return bn({...e,edges:a},o,{theme:n,measure:r,direction:i,defaultCurve:l,dummyVia:new Map,obstacles:[...o.values()]})},Ke=pm(e,n,r,lm(d,He,We,[]));We.push(...Ge(Ke));let{bounds:qe,decor:I}=um(lm(d,He,We,Ke),e,n,r),Je={nodes:d,groups:He,edges:We,bounds:qe,direction:i,theme:n,blocks:f,decor:I,panels:Ke};for(let t of En)t(Je,e);return Je}function jm(e,t){if(!t||!we(t))return e;let n=/^https?:/i.test(t.trim());return`<a href="${I(t)}"${n?` target="_blank" rel="noopener"`:``}>${e}</a>`}var Mm=/<(text|foreignObject)\b[\s\S]*?<\/\1>|<(image|use)\b(?:[^>]*\/>|[^>]*>[\s\S]*?<\/\2>)/g,Nm=new RegExp([String.raw`<(rect|path|line|polyline|polygon|circle|ellipse)\b(?:[^>]*\/>|[^>]*>[\s\S]*?<\/\1>)`,String.raw`<(defs|clipPath|mask|marker|pattern|linearGradient|radialGradient|filter|style|title|desc)\b[\s\S]*?<\/\2>`,String.raw`<(g|a|svg)\b[^>]*>`,String.raw`<\/(g|a|svg)>`].join(`|`),`g`);function Pm(e){let t=``,n=0,r=[];for(let i of e.matchAll(Nm))if(t+=e.slice(n,i.index),n=i.index+i[0].length,i[3]){let e=i[0].replace(/ (?:id|data-[\w-]+)="[^"]*"/g,``);e.endsWith(`/>`)||r.push([i[3],t.length,t.length+e.length]),t+=e}else if(i[4]){let e=r.pop();e&&e[0]===i[4]&&e[2]===t.length?t=t.slice(0,e[1]):t+=i[0]}return t+e.slice(n)}function Fm(e,t,n){let r=`<g class="${e}" filter="url(#${n})">${t.replace(Mm,``)}</g>`,i=Pm(t);return i?`${r}<g class="${e}-crisp" pointer-events="none">${i}</g>`:r}var q=e=>(Math.round(e*100)/100).toString(),Im=(e,t)=>t==null||t===``?``:` ${e}="${typeof t==`number`?q(t):I(t)}"`,Lm=0;function Rm(e){let t=t=>Ke(F((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?` (${Ke(F(e.label))})`:``}`);return e.edges.length>40&&n.push(`${e.edges.length-40} more`),[e.settings.subtitle&&Ke(F(e.settings.subtitle)),e.nodes.size?`${e.nodes.size} nodes, ${e.edges.length} edges${n.length?`: ${n.join(`; `)}`:``}.`:``].filter(Boolean).join(`. `)}function zm(e,n,r={}){return t(e.diagnostics,()=>Bm(e,n,r))}function Bm(e,t,n){let r=t.theme,i=n.idPrefix??`yuhwa${(Lm++).toString(36)}`,a=t.bounds,o=[],s=e.settings.title,c=s&&Ke(F(s)),l=Rm(e),u=t.edges.some(e=>e.style.flow),d=e.settings.look===`sketch`,f=!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="${q(a.x)} ${q(a.y)} ${q(a.w)} ${q(a.h)}"`+Im(`width`,n.width??a.w)+(n.width?``:Im(`height`,a.h))+` role="img"${Im(`aria-label`,c||`diagram`)}${l?Im(`aria-describedby`,`${i}-desc`):``} class="yuhwa" font-family="${I(r.font)}">`),c&&o.push(`<title>${I(c)}</title>`),l&&o.push(`<desc id="${i}-desc">${I(l)}</desc>`);let p=[];f&&p.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>`),d&&p.push(`<filter id="${i}-sk" filterUnits="userSpaceOnUse" x="${q(a.x)}" y="${q(a.y)}" width="${q(a.w)}" height="${q(a.h)}"><feTurbulence type="fractalNoise" baseFrequency="0.018" numOctaves="1" seed="7"/><feDisplacementMap in="SourceGraphic" scale="5" xChannelSelector="R" yChannelSelector="G"/></filter>`),r.grid&&p.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 m=n.snapGrid;m&&p.push(`<pattern id="${i}-snap" x="${-m/2}" y="${-m/2}" width="${m}" height="${m}" patternUnits="userSpaceOnUse"><circle cx="${m/2}" cy="${m/2}" r="0.9" fill="${r.node.sub}" opacity="0.35"/></pattern>`),p.length&&o.push(`<defs>${p.join(``)}</defs>`),u&&o.push(`<style>@keyframes ${i}-flow{to{stroke-dashoffset:var(--mf,-40px)}}.${i}-flow{animation:${i}-flow 1.2s linear infinite}@media (prefers-reduced-motion:reduce){.${i}-flow{animation:none}}</style>`);let h=`x="${q(a.x)}" y="${q(a.y)}" width="${q(a.w)}" height="${q(a.h)}"`;n.transparent||(o.push(`<rect ${h} fill="${r.background}"/>`),r.grid&&o.push(`<rect ${h} fill="url(#${i}-grid)"/>`)),m&&o.push(`<rect ${h} fill="url(#${i}-snap)" pointer-events="none"/>`);let g=Fp(e,r);if(g){let t=parseFloat(e.settings.padding)||24,n=a.y+t,i=P(r,r.title);s&&(o.push(`<text x="${q(a.x+t)}" y="${q(n+g.titleSize*.8)}" font-size="${q(g.titleSize)}" font-weight="650" xml:space="preserve">${B(F(s),i,r)}</text>`),n+=g.titleSize*1.3),e.settings.subtitle&&o.push(`<text x="${q(a.x+t)}" y="${q(n+g.subSize*.95)}" font-size="${q(g.subSize)}" xml:space="preserve">${B(F(e.settings.subtitle),i,r,!0)}</text>`)}for(let n of t.decor??[]){let t=ni.decorations.find(e=>e.name===n.name);t&&o.push(t.render(n.value,n.area,r,{pad:at(e.settings.padding,24),bounds:a,d:e}))}let _=(e,t)=>o.push(d?Fm(e,t,`${i}-sk`):`<g class="${e}">${t}</g>`);_(`groups`,[...t.groups].sort((e,t)=>e.depth-t.depth).map(e=>Wm(e,t,!!n.interactive)).join(``)),_(`edges`,t.edges.map(e=>Km(e,i,!!n.interactive)).join(``));let v=f?`${i}-sh`:null;t.panels?.length&&_(`panels`,t.panels.map(e=>Vm(e,t,n.measure,v,i)).join(``)),_(`nodes`,[...t.nodes.values()].map(n=>Ym(e,n,t,v)).join(``)),o.push(`<g class="labels">`);for(let e of t.edges)e.label&&o.push(Jm(e,t));o.push(`</g></svg>`);let y=o.join(``);for(let n of Dn)y=n(y,e,t);return We(y)}function Vm(e,t,n,r,i){let a=t.theme,o=ni.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=st(e.decl.props,e.ctx.fs,650,s),f=[`<g${Im(`data-panel`,e.decl.id)}${Im(`class`,`panel panel-${e.decl.kind}`)}>`];return c.framed&&f.push(`<rect x="${q(l.x)}" y="${q(l.y)}" width="${q(l.w)}" height="${q(l.h)}" rx="${q(c.radius)}" fill="${c.fill}" stroke="${c.stroke}" stroke-width="${q(c.width)}"${Im(`stroke-dasharray`,c.dash)}${c.shadow&&r?` filter="url(#${r})"`:``}/>`),e.decl.label&&f.push(`<text x="${q(l.x+16)}" y="${q(l.y+16+u)}" dominant-baseline="central" font-size="${q(e.ctx.fs*1.05)}" font-weight="${d.weight}"${Je(d.italic,d.family)} fill="${c.text}" xml:space="preserve">${B(F(e.decl.label),P(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 Hm(e,t,n,r,[i,a,o,s]){return`M${q(e+i)} ${q(t)}H${q(e+n-a)}`+(a?`A${q(a)} ${q(a)} 0 0 1 ${q(e+n)} ${q(t+a)}`:``)+`V${q(t+r-o)}`+(o?`A${q(o)} ${q(o)} 0 0 1 ${q(e+n-o)} ${q(t+r)}`:``)+`H${q(e+s)}`+(s?`A${q(s)} ${q(s)} 0 0 1 ${q(e)} ${q(t+r-s)}`:``)+`V${q(t+i)}`+(i?`A${q(i)} ${q(i)} 0 0 1 ${q(e+i)} ${q(t)}`:``)+`Z`}function Um(e,t,n){let r=t.theme,i=e.style,{index:a,count:o,side:s}=e.lane,c=s===`left`,l=Math.min(14,r.radius+4),u=a===0?l:0,d=a===o-1?l:0,f=e.header??0,p=c?{x:e.x,y:e.y,w:f,h:e.h}:{x:e.x,y:e.y,w:e.w,h:f},m=c?[u,0,0,d]:[u,d,0,0],h=c?[u,u,d,d]:[u,d,d,u],g=im(e.decl,r),_=P(r,i.text,i.stroke),v=e.lines??[e.decl.label],y=e.lineHeight??g.size*1.3,b=p.x+p.w/2,x=p.y+p.h/2,S=e=>x+(e-(v.length-1)/2)*y+g.size*.35,C=e.decl.label?`<text x="${q(b)}" y="${q(S(0))}" text-anchor="middle" font-size="${q(g.size)}" font-weight="${g.weight}"${Je(g.italic,g.family)} letter-spacing="${g.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${v.length>1?Be(v,b,S,e=>Ge(e,_,r,g.caps)):Ge(v[0]??``,_,r,g.caps)}</text>`:``,w=a%2?.55:.85,T=c?`M${q(p.x+f)} ${q(e.y)}V${q(e.y+e.h)}`:`M${q(e.x)} ${q(e.y+f)}H${q(e.x+e.w)}`;return`<g${Im(`data-group`,e.id)} data-lane="${a}"${n?` cursor="move"`:``}><path d="${Hm(e.x,e.y,e.w,e.h,h)}" fill="${i.fill}" fill-opacity="${w}"/><path d="${Hm(p.x,p.y,p.w,p.h,m)}" fill="${i.fill}"/><path d="${T}" fill="none" stroke="${i.stroke}" stroke-width="1"/><path d="${Hm(e.x,e.y,e.w,e.h,h)}" fill="none" stroke="${i.stroke}" stroke-width="1"${Im(`stroke-dasharray`,i.dash)}/>`+C+`</g>`}function Wm(e,t,n){if(e.lane)return Um(e,t,n);let r=t.theme,i=e.style,a=r.fontSize*.82,o=e.decl.props,s=im(e.decl,r),c=e.decl.label,l=P(r,i.text,i.stroke),u=e.lines??[c],d=e.y+14+Math.round(s.size*.7),f=u.length>1?Be(u,e.x+14,t=>d+t*e.lineHeight,e=>Ge(e,l,r,s.caps)):Ge(c,l,r,s.caps),p=c?`<text x="${q(e.x+14)}" y="${q(d)}" font-size="${q(s.size)}" font-weight="${s.weight}"${Je(s.italic,s.family)} letter-spacing="${s.caps?`0.1em`:`0.02em`}" fill="${i.text}" xml:space="preserve">${f}</text>`:``,m=o.meta?`<text x="${q(e.x+e.w-14)}" y="${q(d)}" text-anchor="end" font-size="${q(a)}" fill="${r.node.sub}" xml:space="preserve">${Ge(o.meta,Te(l),r)}</text>`:``;return`<g${Im(`data-group`,e.id)}${n?` cursor="move"`:``}><rect x="${q(e.x)}" y="${q(e.y)}" width="${q(e.w)}" height="${q(e.h)}" rx="${q(Math.min(14,r.radius+4))}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="1"${Im(`stroke-dasharray`,i.dash)}/>`+p+m+`</g>`}function Gm(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:${q(-1.2*r/2/i)}s`:``;return` class="${e}-flow" style="--mf:${q(-i)}px${a}"`}function Km(e,t,n){let r=e.style,i=[];i.push(`<g${Im(`data-edge`,e.key)}${r.opacity<1?Im(`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="${q(r.width)}" stroke-linecap="round" stroke-linejoin="round"`;if(r.flow&&e.heads.length===2){let e=r.width,n=`${q(e*3)} ${q(e*9)}`;i.push(a+` opacity="0.35"`+Im(`stroke-dasharray`,r.dash===`${e*4} ${e*3}`?null:r.dash)+`/>`,a+Im(`stroke-dasharray`,n)+Gm(t,n)+`/>`,a+Im(`stroke-dasharray`,n)+Gm(t,n,!0)+`/>`)}else i.push(a+Im(`stroke-dasharray`,r.dash)+(r.flow&&r.dash?Gm(t,r.dash):``)+`/>`);for(let t of e.heads)i.push(On(t.at,t.angle,t.kind,r.stroke,r.width));return i.push(`</g>`),i.join(``)}function qm(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 Jm(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(`
|
|
22
|
+
`):[],u=P(r,i.text,i.stroke);if(l.length){let{w:d,h:f}=n.pill,p=n.lineHeight,m=s-(l.length-1)*p/2,h=Be(l,o,e=>m+e*p,e=>Ge(e,u,r)),g=r.edge.labelStroke,_=`x="${q(o-d/2)}" y="${q(s-f/2)}" width="${q(d)}" height="${q(f)}" rx="${g?q(f/2):4}"`;c.push(`<rect ${_} fill="${e.style.labelBg}"`+(g?` stroke="${g}" stroke-width="1"`:``)+`/>`,...qm(o,s,e,t).map(e=>`<rect ${_} fill="${e}"/>`),`<text text-anchor="middle" dominant-baseline="central" font-size="${q(a)}" font-weight="${i.fontWeight}"${Je(i.italic,i.family)} fill="${i.text}" xml:space="preserve">${h}</text>`)}if(n.caption){let t=a*.88,i=n.caption.split(`
|
|
23
|
+
`),d=n.captionLineHeight,f=s+(l.length?n.pill.h/2:0)+2,p=Math.max(n.pill.w,n.w),m=`<rect x="${q(o-(n.rotate?n.h:p)/2)}" y="${q(f)}" width="${q(n.rotate?n.h:p)}" height="${q(i.length*d+2)}" fill="${r.background===`none`?`none`:e.style.labelBg}" opacity="0.85"/>`,h=Be(i,o,e=>f+d*(e+.5)+1,e=>Ge(e,Te(u),r));c.push(m,`<text text-anchor="middle" dominant-baseline="central" font-size="${q(t)}" fill="${r.node.sub}" xml:space="preserve">${h}</text>`)}let d=n.rotate?` transform="rotate(-90 ${q(o)} ${q(s)})"`:``;return`<g${Im(`data-edge-label`,e.key)}${d}>${c.join(``)}</g>`}function Ym(e,t,n,r){let i=t.style,a=pt(e,t.decl),o=n.blocks.get(t.id),s=[],c=a.tooltip?`<title>${I(a.tooltip)}</title>`:``;if(s.push(`<g${Im(`data-node`,t.id)}${i.opacity<1?Im(`opacity`,i.opacity):``}>${c}`),t.shape!==`text`){s.push(`<path d="${Fn(t.shape,t,i.radius)}" fill="${i.fill}" stroke="${i.stroke}" stroke-width="${q(i.strokeWidth)}"`+Im(`stroke-dasharray`,i.dash)+(i.shadow&&r?` filter="url(#${r})"`:``)+`/>`);let e=In(t.shape,t);e&&s.push(`<path d="${e}" fill="none" stroke="${i.stroke}" stroke-width="${q(i.strokeWidth)}"/>`)}if(o.card){let e=o.card.frame&&ni.frames.get(o.card.frame.name);e&&s.push(e.render(t,{theme:n.theme,col:{text:i.text,sub:i.sub,stroke:i.stroke},arg:o.card.frame.arg,radius:i.radius,fs:i.fontSize}));let r={text:i.text,sub:i.sub,stroke:i.stroke,body:i.body};return s.push(Op(o.card,t.x,t.y,t.w,t.h,r,n.theme)),s.push(`</g>`),jm(s.join(``),a.link)}let l=t.x+t.w/2,u=t.y+t.h/2+Pn(t.shape)-o.h/2;o.icon&&(s.push(`<text x="${q(l)}" y="${q(u+o.iconSize/2)}" text-anchor="middle" dominant-baseline="central" font-size="${q(o.iconSize)}">${I(o.icon)}</text>`),u+=o.iconSize+4);let d=`text-anchor="middle" dominant-baseline="central" font-size="${q(i.fontSize)}" font-weight="${i.fontWeight}" fill="${i.text}"`+Je(i.italic,i.family)+(o.letterSpacing?` letter-spacing="${q(o.letterSpacing)}"`:``),f={text:i.text,sub:i.sub,stroke:i.stroke},p=Be(o.lines,l,e=>u+o.lineHeight*(e+.5),e=>Ge(e,f,n.theme,o.caps));if(s.push(`<text ${d} xml:space="preserve">${p}</text>`),u+=o.lines.length*o.lineHeight,o.sub.length){u+=3;let e=Be(o.sub,l,e=>u+o.subLineHeight*(e+.5),e=>Ge(e,Te(f),n.theme));s.push(`<text text-anchor="middle" dominant-baseline="central" font-size="${q(o.subSize)}" fill="${i.sub}" xml:space="preserve">${e}</text>`)}return s.push(`</g>`),jm(s.join(``),a.link)}var Xm=new Set([`->`,`-->`,`..>`,`=>`,`==>`,`<->`,`--`,`-`]),Zm=/^[\p{L}_][\p{L}\p{N}_]*(?:-[\p{L}\p{N}_]+)*$/u,Qm=/^[\p{L}_][\p{L}\p{N}_-]*$/u,$m=/^[\p{L}_][\p{L}\p{N}_-]*$/u,eh=Jr;function th(e,t,n){let r={};for(let[i,a]of Object.entries(e))t.includes(i)||a==null||($m.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=Gr(r);return i?` [${i}]`:``}var nh=e=>!!e&&typeof e==`object`&&!Array.isArray(e),rh=(e,t)=>(Array.isArray(e)?e:e?[e]:[]).filter(e=>typeof e==`string`&&Qm.test(e)||(t.push(`class name ${JSON.stringify(e)} is not a valid name`),!1)).map(e=>` .${e}`).join(``),ih=e=>Array.isArray(e)?e:[e];function ah(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)=>nh(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||nh(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))$m.test(e)?a.push(`${e}: ${/[\n\r"'{}]|\s\/\/|^\s|\s$/.test(String(n))?eh(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)Qm.test(e)?nh(n)?a.push(`.${e}${th(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`&&Zm.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?``:` `+eh(String(e.label))}${rh(e.class,t)}${th(e,[`id`,`label`,`group`,`class`,`body`],t)}`,i=e.body===void 0?[]:Array.isArray(e.body)?e.body.map(String):String(e.body).split(`
|
|
24
|
+
`);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(`
|
|
25
|
+
`)):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?``:` `+eh(String(i.label))}${rh(i.class,t)}${th(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=ih(e.from).filter(e=>c(e,`edge.from`)),r=ih(e.to).filter(e=>c(e,`edge.to`));if(!n.length||!r.length)continue;let i=e.arrow??`->`;Xm.has(i)||t.push(`edge arrow "${i}" must be one of ${[...Xm].join(` `)}`);let o=`${e.label===void 0?``:` `+eh(String(e.label))}${rh(e.class,t)}${th(e,[`from`,`to`,`label`,`arrow`,`class`],t)}`;a.push(`${n.join(`, `)} ${Xm.has(i)?i:`->`} ${r.join(`, `)}${o?`:`+o:``}`)}return{source:a.join(`
|
|
26
|
+
`).replace(/\n+$/,``)+`
|
|
27
|
+
`,errors:t}}var oh=/^"(.*)"$/;function sh(e){return{id:e,attrs:[],methods:[],rows:[],classes:[]}}function ch(e,t){return{ctx:t,lines:e,index:0,cards:new Map,root:{id:``,label:``,items:[]},rels:[],direction:`down`,title:t.title}}function lh(e,t){Qd(e,e.ctx,({text:n,line:r})=>t.some(t=>t(n,e,r)))}function uh(e,t){for(;++e.index<e.lines.length&&e.lines[e.index].text!==`}`;)t(e.lines[e.index])}var dh=(e,t)=>{let n=Yd(e,!1);return n!==void 0&&(t.title=n),n!==void 0},fh=(e,t)=>{let n=e.match(ef);return n&&(t.direction=$d[n[1].toUpperCase()]),!!n};function ph(e){let t=[e.id];e.label!==void 0&&e.label!==e.id&&t.push(W(e.label));for(let n of e.classes)t.push(`.${n}`);let n=[];return e.note&&n.push(`shape: note`),e.sub&&n.push(`sub: ${W(e.sub)}`),e.style&&n.push(e.style),n.length&&t.push(`[${n.join(`, `)}]`),t}function mh(e){if(e.rows.length)return e.rows;let t=e.attrs.length&&e.methods.length?[`---`]:[];return[...e.attrs,...t,...e.methods]}function hh(e,t){let n=ph(e),r=mh(e);return r.length?(n.length===1&&n.push(W(e.id)),[`${t}${n.join(` `)} {`,...r.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function gh(e){let t=[e.label?sf(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);return`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`}function _h(e,t,n){let r=(t,n)=>t.items.flatMap(t=>hh(e.cards.get(t),n)),i=r(e.root,``);for(let e of n)i.push(`group ${e.id} ${W(e.label)} {`,...r(e,` `),`}`);return e.rels.length&&i.push(``),i.push(...e.rels.map(gh)),[...[e.title?`title: ${e.title}`:``,`direction: ${e.direction}`].filter(Boolean),...t.length?[``,...t]:[],``,...i]}var vh=l({"<|":`open`,"|>":`open`,"*":`diamond`,o:`diamond`,"<":`arrow`,">":`arrow`}),yh=/^(\S+?)\s+(?:"([^"]*)"\s+)?(<\||\*|o|<|)(--|\.\.)(\|>|\*|o|>|)\s+(?:"([^"]*)"\s+)?(\S+?)\s*(?::\s*(.*))?$/,bh=/^([^\s<*.-]+?)\s*(?:"([^"]*)"\s*)?(<\||\*|<|)(--|\.\.)(\|>|\*|>|)\s*(?:"([^"]*)"\s*)?([^\s:]+?)\s*(?::\s*(.*))?$/,xh=/^class\s+([^\s[{:~]+)(~[^~]+~)?(?:\["([^"]*)"\])?(?::::([\w-]+))?\s*(\{)?\s*(\})?$/,Sh=/^namespace\s+(\S+)\s*\{$/,Ch=/^<<(.+)>>$/,wh=/^<<(.+)>>\s+(\S+)$/,Th=/^note\s+for\s+(\S+)\s+"(.*)"$/,Eh=/^note\s+"(.*)"$/,Dh=/^cssClass\s+"([^"]+)"\s+([\w-]+)$/,Oh=/^(click|callback|link)\b/,kh=/^([^\s:]+)\s*:\s*(.*)$/,Ah=e=>e.replace(/~([^~]*)~/g,`<$1>`),jh=e=>e.replace(/~[^~]*~/g,``),Mh=e=>`«${e.trim()}»`;function Nh(e,t){let n=Ud(jh(t)),r=e.cards.get(n);return r||(r=sh(n),(n!==t||/~/.test(t))&&(r.label=Ah(t.replace(oh,`$1`))),e.cards.set(n,r),e.scope.items.push(n)),r}function Ph(e,t){let n=Ah(t.trim());if(!n)return;let r=n.match(Ch);r?e.sub=Mh(r[1]):(n.includes(`(`)?e.methods:e.attrs).push(n)}function Fh(e,t){let n=`note${++e.notes}`;return e.cards.set(n,{...sh(n),label:G(t),note:!0}),e.scope.items.push(n),n}var Ih=[dh,fh,(e,t)=>{let n=e.match(Sh);return n&&(t.scope={id:Ud(n[1]),label:n[1],items:[]},t.scopes.push(t.scope)),!!n},(e,t,n)=>e===`}`&&(t.scope===t.root?t.ctx.warn(n,`"}" without a namespace`):t.scope=t.root,!0),(e,t)=>{let n=e.match(xh);if(!n)return!1;let[,r,i,a,o,s,c]=n,l=Nh(t,r+(i??``));return a!==void 0&&(l.label=K(a)),o&&l.classes.push(o),s&&!c&&uh(t,e=>Ph(l,e.text)),!0},(e,t)=>{let n=e.match(wh);return n&&(Nh(t,n[2]).sub=Mh(n[1])),!!n},(e,t)=>{let n=e.match(Th);if(n){let e=Fh(t,n[2]);t.rels.push({from:e,to:Nh(t,n[1]).id,arrow:`..`,props:[]})}return!!n},(e,t)=>{let n=e.match(Eh);return n&&Fh(t,n[1]),!!n},(e,t,n)=>{let r=af(e,e=>t.ctx.warn(n,e));return t.classDefs.push(...r??[]),!!r},(e,t)=>{let n=e.match(Dh);if(n)for(let e of n[1].split(`,`))Nh(t,e.trim()).classes.push(n[2]);return!!n},(e,t,n)=>{let r=nf(e,e=>t.ctx.warn(n,e));return r&&(Nh(t,r.target).style=r.props),!!r},(e,t,n)=>Oh.test(e)?(t.ctx.warnOnce(`click`,n,`click, link and callback are skipped`),!0):!1,(e,t,n)=>{let r=e.match(yh)??e.match(bh);if(!r)return!1;let[,i,a,o,s,c,l,u,d]=r,f=[];o&&f.push(`tail: ${vh[o]}`),c&&f.push(`head: ${vh[c]}`),(o===`o`||c===`o`)&&t.ctx.warnOnce(`aggr`,n,`aggregation (o--) is drawn with a filled diamond, like composition`);let p=[a,l].filter(e=>e!==void 0);return p.length&&f.push(`caption: ${W(p.join(` to `))}`),t.rels.push({from:Nh(t,i).id,to:Nh(t,u).id,arrow:s,props:f,label:d?K(d):void 0}),!0},(e,t)=>{let n=e.match(kh);return n&&Ph(Nh(t,n[1]),n[2]),!!n}],Lh=(e,t)=>{let n=ch(e,t),r={...n,scopes:[],scope:n.root,classDefs:[],notes:0};return lh(r,Ih),_h(r,r.classDefs,r.scopes)},Rh={"||":`1`,"|o":`0..1`,"}|":`1..n`,"}o":`0..n`},zh={"||":`1`,"o|":`0..1`,"|{":`1..n`,"o{":`0..n`},Bh=/^("[^"]*"|[^\s|}o{]+?)\s*(\|\||\|o|\}\||\}o)(--|\.\.)(\|\||o\||\|\{|o\{)\s*("[^"]*"|\S+?)\s*:\s*(.*)$/,Vh=/^(\S+)\s+(\S+)((?:\s+(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*)?)(?:\s+"([^"]*)")?$/,Hh=/^("[^"]*"|[^\s[{]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{\s*(\})?$/,Uh=/^("[^"]*"|[^\s[]+)\s*\["?([^"\]]*)"?\]$/,Wh=/^(classDef|class|style)\b/,Gh=/^("[^"]*"|[\w-]+)$/;function Kh(e,t){let n=t.replace(oh,`$1`),r=Ud(n),i=e.cards.get(r);return i||(i=sh(r),r!==n&&(i.label=n),e.cards.set(r,i),e.root.items.push(r)),i}function qh(e,t,n){let r=n.text.match(Vh);if(!r){e.ctx.warn(n.line,`could not read attribute "${n.text}"`);return}let[,i,a,o,s]=r,c=[i,a,o.replace(/\s+/g,``).replace(/,/g,`, `),s??``].map(e=>e.replace(/\|/g,`/`));t.rows.push(`| ${c.join(` | `)} |`)}var Jh=[dh,fh,(e,t)=>{let n=e.match(Hh);if(!n)return!1;let[,r,i,a]=n,o=Kh(t,r);return i!==void 0&&(o.label=i),a||uh(t,e=>qh(t,o,e)),!0},(e,t)=>{let n=e.match(Bh);if(!n)return!1;let[,r,i,a,o,s,c]=n;return t.rels.push({from:Kh(t,r).id,to:Kh(t,s).id,arrow:a===`..`?`..`:`--`,props:[`caption: ${W(`${Rh[i]} to ${zh[o]}`)}`],label:K(c)||void 0}),!0},(e,t)=>{let n=e.match(Uh);return n&&(Kh(t,n[1]).label=n[2]),!!n},(e,t,n)=>Wh.test(e)?(t.ctx.warnOnce(`erstyle`,n,`ER styles and classes are skipped`),!0):!1,(e,t)=>Gh.test(e)?(Kh(t,e),!0):!1],Yh=(e,t)=>{let n=ch(e,t);return lh(n,Jh),_h(n,[],[])},Xh=/^section\s+(.*)$/;function Zh(e,t){let n=Yd(e.text);return n!==void 0&&(t.title=n,!0)}function Qh(e,t,n,r){Qd({lines:e,index:0},t,e=>Zh(e,n)||r(e))}function $h(e,t){return t.length?`${e} [${t.join(`, `)}]`:e}function eg(e,t){for(let n of t.filter(Boolean))e.push(` - ${n}`)}var tg=/(\w+)\s*:\s*("[^"]*"|\S+)/g;function ng(e){let t={};for(let n of e.matchAll(tg))t[n[1]]=n[2].replace(/^"(.*)"$/,`$1`);return t}var rg=e=>/[[\]:]|^"/.test(e)?W(e):e,ig=/^(.+?)\s*(<<-->>|<<->>|-->>|->>|--x|-x|--\)|-\)|-->|->)\s*([+-]?)\s*(.+?)\s*:\s*(.*)$/,ag=/^(loop|alt|else|opt|par|and|critical|option|break)\b\s*(.*)$/,og=/^(participant|actor)\s+(.+?)(?:\s+as\s+(.+))?$/,sg=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*:\s*(.*)$/i,cg=/^(activate|deactivate|create|destroy|box|link|links|properties|details)\b/;function lg(e){let t=new Map,n=new Set;return(r,i,a=!1)=>{let o=r.trim(),s=t.get(o),c=!s;if(s||(s=Ud(o),t.set(o,s)),i!==void 0||c&&s!==o){let t=a?`actor`:`participant`,r=i??o;n.has(s)||e.push(r===s?`${t} ${s}`:`${t} ${s} ${W(r)}`),n.add(s)}return s}}function ug(e,t,n,r){return t&&n.warnOnce(`act`,r,`activation markers (+/-) are skipped`),e.endsWith(`x`)&&n.warnOnce(`cross`,r,`cross arrow ends (-x) are drawn as normal arrows`),e.startsWith(`<<`)&&n.warnOnce(`bidi`,r,`two-way arrows (<<->>) are drawn one way`),e.replace(/^<</,``).startsWith(`--`)?`-->`:`->`}var dg=(e,t)=>{let n={title:t.title},r=[],i=lg(r),a=!1,o=e=>{let n=e.text.match(og);if(!n)return!1;let[,r,a,o]=n,s=a;return/@\{/.test(s)&&(t.warnOnce(`ptype`,e.line,`participant types (@{ "type": … }) are skipped`),s=s.replace(/@\{.*$/,``)),i(s,o===void 0?s.trim():K(o),r===`actor`),!0},s=e=>{let t=e.text.match(sg);if(!t)return!1;let n=t[1].split(`,`).map(e=>i(e));return r.push(`note ${n.join(`, `)}: ${K(t[2])}`),!0},c=e=>{let n=e.text.match(ag);return n?(t.warnOnce(`block`,e.line,`loop/alt/opt/par blocks become "--- … ---" dividers`),r.push(`--- ${[n[1],K(n[2])].filter(Boolean).join(` `)} ---`),!0):!1},l=e=>{if(/^rect\b/.test(e.text))return t.warnOnce(`rect`,e.line,`"rect" highlight boxes are skipped`),!0;let n=e.text.match(cg);return n?(t.warnOnce(n[1],e.line,`"${n[1]}" is not supported and was skipped`),!0):!1},u=e=>{let n=e.text.match(ig);if(!n)return!1;let[,a,o,s,c,l]=n,u=ug(o,s,t,e.line);return r.push(`${i(a)} ${u} ${i(c)}: ${K(l)}`),!0};return Qh(e,t,n,e=>e.text===`autonumber`||e.text.startsWith(`autonumber `)?(a=!0,!0):o(e)||s(e)||c(e)||e.text===`end`||l(e)||u(e)),Kd(`sequence`,Gd(n.title,`seq`),n.title,a?[`numbered`]:[],r)},fg=/^commit\b(.*)$/,pg=/^branch\s+("[^"]*"|\S+)(.*)$/,mg=/^(checkout|switch)\s+(.+)$/,hg=/^merge\s+("[^"]*"|\S+)(.*)$/,gg=/^cherry-pick\b(.*)$/,_g=e=>e.trim().replace(/^"(.*)"$/,`$1`).replace(/\s+/g,`-`).replace(/[^\p{L}\p{N}_./-]/gu,`_`).replace(/^[^\p{L}\p{N}_]+/u,``);function vg(e){let t=[];e.id&&t.push(`id: ${Hd(_g(e.id))}`),e.tag&&t.push(`tag: ${Hd(e.tag)}`);let n=e.type?.toUpperCase();return n===`HIGHLIGHT`?t.push(`highlight`):n===`REVERSE`&&t.push(`reverse`),t}function yg(e,t){let n=t.header.match(/^\s*(LR|TB|BT)\s*:?/)?.[1];return n===`BT`&&t.warn(e[0]?.line??1,`bottom-to-top git graphs are drawn top to bottom`),n===`TB`||n===`BT`?[`direction: down`]:[]}var bg=(e,t)=>{let n={title:t.title},r=yg(e,t),i=[],a=(e,n)=>{n.parent&&t.warnOnce(`parent`,e.line,`cherry-pick "parent" is skipped`),n.tag&&t.warnOnce(`cptag`,e.line,`cherry-pick "tag" is skipped`),n.id?i.push(`cherry-pick ${_g(n.id)}`):t.warn(e.line,`cherry-pick needs an id`)};return Qh(e,t,n,e=>{let t=e.text,n;if(n=t.match(fg)){let e=ng(n[1]);i.push($h(e.msg?`commit ${W(e.msg)}`:`commit`,vg(e)))}else if(n=t.match(pg)){let e=ng(n[2]).order;i.push($h(`branch ${_g(n[1])}`,e?[`order: ${e}`]:[]))}else if(n=t.match(mg))i.push(`${n[1]} ${_g(n[2])}`);else if(n=t.match(hg))i.push($h(`merge ${_g(n[1])}`,vg(ng(n[2]))));else if(n=t.match(gg))a(e,ng(n[1]));else return!1;return!0}),Kd(`git`,Gd(n.title,`history`),n.title,r,i)},xg=/^("[^"]*"|'[^']*'|[^:]+?)\s*:\s*(-?\d+(?:\.\d+)?)\s*$/,Sg=(e,t)=>{let n={title:t.title},r=t.header.replace(/\bshowData\b/,``).trim();r&&(n.title=Yd(r)??n.title);let i=[];return Qh(e,t,n,e=>{if(e.text===`showData`)return!0;let t=e.text.match(xg);return t&&i.push(`${rg(K(t[1]))}: ${t[2]}`),!!t}),Kd(`chart`,Gd(n.title,`pie`),n.title,[`type: pie`],i)},Cg=/^x-axis\b\s*(?:"[^"]*"|[^\s[]+)?\s*(.*)$/,wg=/^(bar|line)\b\s*(?:"[^"]*")?\s*(\[.*\])\s*$/;function Tg(e,t,n,r){let i=Gd(r,`xy`);if(!e.length)return Kd(`chart`,i,r,[`type: column`],[]);let a=[];return e.forEach((e,o)=>{let s=e.values.map((e,n)=>`${rg(t[n]??String(n+1))}: ${e}`),c=e.type===`line`?`line`:n?`bar`:`column`;o&&a.push(``),a.push(...Kd(`chart`,o?`${i}${o+1}`:i,r,[`type: ${c}`],s))}),a}var Eg=(e,t)=>{let n={title:t.title},r=[],i=[];return Qh(e,t,n,e=>{let n=e.text.match(Cg);if(n){let i=n[1].trim();return i.startsWith(`[`)?r=of(i).map(e=>K(e)):t.warnOnce(`xrange`,e.line,`a numeric x-axis range becomes 1, 2, 3, …`),!0}if(/^y-axis\b/.test(e.text))return t.warnOnce(`yaxis`,e.line,`the y-axis title and range are skipped; the chart scales to the data`),!0;let a=e.text.match(wg);return a&&i.push({type:a[1],values:of(a[2]),line:e.line}),!!a}),i.length>1&&t.warn(i[1].line,`each xychart series becomes its own chart; yuhwa charts plot one series`),Tg(i,r,/\bhorizontal\b/.test(t.header),n.title)},Dg=/^([xy])-axis\s+(.*)$/,Og=/^quadrant-([1-4])\s+(.*)$/,kg=/^(.+?)(?::::[\w-]+)?\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]\s*(.*)$/,Ag=/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i;function jg(e,t,n){let[,r,i,a,o]=t,s=ng(o.replace(/,/g,` `));/:::/.test(e.text)&&n.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`),(s.radius||s[`stroke-color`]||s[`stroke-width`])&&n.warnOnce(`qstyle`,e.line,`point radius and stroke are skipped`);let c=s.color&&Ag.test(s.color)?` [${s.color}]`:``;return`${K(r)}${c}: ${i}, ${a}`}var Mg=(e,t)=>{let n={title:t.title},r=[];return Qh(e,t,n,e=>{let n=e.text,i;if(i=n.match(Dg)){let[e,t]=i[2].split(/\s*-->\s*/).map(e=>K(e));r.push(`${i[1]}-axis ${e}${t?` -> ${t}`:``}`)}else if(i=n.match(Og))r.push(`q${i[1]}: ${K(i[2])}`);else if(/^classDef\b/.test(n))t.warnOnce(`qclass`,e.line,`quadrant point classes are skipped`);else if(i=n.match(kg))r.push(jg(e,i,t));else return!1;return!0}),Kd(`quadrant`,Gd(n.title,`matrix`),n.title,[],r)},Ng=new Set([`done`,`active`,`crit`,`milestone`]),Pg=/^(axisFormat|tickInterval|excludes|includes|weekday|weekend|todayMarker|inclusiveEndDates|topAxis|displayMode|click)\b/,Fg=/^([^:]+?)\s*:\s*(.*)$/,Ig=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/;function Lg(e){let t=new Set,n=[];for(let r of e){let e=r.text.match(Fg);if(!e||/^(title|dateFormat|section)\b/.test(r.text)||Pg.test(r.text)||Xd.test(r.text))continue;let i=e[2].split(`,`).map(e=>e.trim()).filter(Boolean);n.push({l:r,label:e[1],items:i});let a=i.filter(e=>!Ng.has(e));a.length===3&&t.add(Ud(a[0]))}return{tasks:n,taken:t}}function Rg(e){let t=0;return()=>{let n;do n=`t${++t}`;while(e.has(n));return n}}function zg(e,t,n){let r=e.match(Ig);return!r||[`h`,`d`,`w`].includes(r[2])?e:(t.warnOnce(`mins`,n,`minute and second lengths are rounded up to 1h`),`1h`)}function Bg(e,t){return e.replace(/^after\s+(.*)$/,(e,n)=>`after `+n.split(/\s+/).map(e=>t.get(e)??Ud(e)).join(` `))}var Vg=(e,t)=>{let n={title:t.title},{tasks:r,taken:i}=Lg(e),a=Rg(i),o=new Map,s=[],c=0,l=!0,u=e=>e.length>=3?{id:Ud(e[0]),from:e[1],to:e[2]}:e.length===2?{id:a(),from:e[0],to:e[1]}:{id:a(),to:e[0]},d=(e,n)=>{let r=n.items.filter(e=>Ng.has(e)),i=n.items.filter(e=>!Ng.has(e)),{id:a,from:c,to:d}=u(i);i.length>=3&&o.set(i[0],a),i.length>3&&t.warn(e.line,`extra task fields "${i.slice(3).join(`, `)}" are skipped`),l&&!c&&t.warn(e.line,`the first task has no start date`),l=!1;let f=d;f?.startsWith(`until `)&&(t.warnOnce(`until`,e.line,`"until" ends become a 1d length`),f=`1d`),f&&=zg(f,t,e.line);let p=c?Bg(c,o):``,m=(r.includes(`milestone`)?[p]:[p,f??``]).filter(Boolean).join(`, `),h=[a,W(K(n.label)),r.length?`[${r.join(`, `)}]`:``].filter(Boolean).join(` `);s.push(m?`${h}: ${m}`:h)};return Qh(e,t,n,e=>{let n=e.text,i=n.match(/^dateFormat\s+(.*)$/);if(i)return/^YYYY-MM-DD( HH:mm)?$/.test(i[1].trim())||t.warn(e.line,`dateFormat "${i[1].trim()}" is kept as written; yuhwa reads YYYY-MM-DD dates`),!0;if(Pg.test(n)){let r=n.split(/\s+/)[0];return t.warnOnce(r,e.line,`"${r}" is not supported and was skipped`),!0}let a=n.match(Xh);if(a)return s.push(`--- ${K(a[1])} ---`),!0;let o=r[c];return!o||o.l!==e?!1:(c++,d(e,o),!0)}),Kd(`gantt`,Gd(n.title,`plan`),n.title,[],s)},Hg=(e,t)=>{let n={title:t.title},r=[],i,a=0,o=(e,[n,a,...o])=>{let s=i?` [${i}]`:``;a?(r.push(`${n}${s}: ${a}`),eg(r,o)):(t.warn(e.line,`event "${n}" has no text`),r.push(`${n}${s}: ${n}`))},s=(e,n)=>{!r.length||r[r.length-1].startsWith(`//`)?t.warn(e.line,`event detail "${e.text}" has no event above it`):eg(r,n.slice(1))};return Qh(e,t,n,e=>{let n=e.text.match(Xh);if(n)return i=uf[a++%uf.length],t.warnOnce(`section`,e.line,`timeline sections become a colour per section`),r.push(`// ${K(n[1])}`),!0;let c=e.text.split(/\s*:\s*/).map(e=>K(e));return e.text.startsWith(`:`)?s(e,c):o(e,c),!0}),Kd(`timeline`,Gd(n.title,`events`),n.title,[],r)},Ug=/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/,Wg=e=>e<=2?`red`:e<4?`amber`:`green`,Gg=(e,t)=>{let n={title:t.title},r=[];return Qh(e,t,n,e=>{let n=e.text.match(Xh);if(n)return r.push(`// ${K(n[1])}`),!0;let i=e.text.match(Ug);if(!i)return!1;let[,a,o,s]=i;return s&&t.warnOnce(`actors`,e.line,`journey actors are skipped; scores become a column chart`),r.push(`${rg(K(a))} [${Wg(Number(o))}]: ${o}`),!0}),Kd(`chart`,Gd(n.title,`journey`),n.title,[`type: column`],r)},Kg=[[`((`,`))`,`circle`],[`))`,`((`,``],[`{{`,`}}`,``],[`(`,`)`,`pill`],[`[`,`]`,`box`],[`)`,`(`,``]];function qg(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 Kg){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:G(r.slice(o+e.length,r.length-i.length),!0),shape:a||void 0}}return{text:G(r,!0)}}var Jg=(e,t)=>{let n=[],r=Ka(),i=0;for(let a of e){if(Zd(a,t))continue;if(a.text.startsWith(`::icon(`)){t.warnOnce(`icon`,a.line,`mindmap icons (::icon) are skipped`);continue}let e=r.enter(a.indent);e===0&&i++&&t.warn(a.line,`a mindmap has one root; this node starts a second tree`);let o=qg(a.text,t,a.line),s=o.text.replace(/\s*\n\s*/g,` `);n.push(` `.repeat(e)+s+(o.shape?` [shape: ${o.shape}]`:``))}return Kd(`mindmap`,Gd(t.title,`map`),t.title,[`layout: both`],n)},Yg=l({"very high":`high`,high:`high`,medium:`medium`,low:`low`,"very low":`low`}),Xg=/([\w-]+)\s*:\s*('[^']*'|"[^"]*"|[^,]+)/g,Zg=[`assigned`,`ticket`,`priority`];function Qg(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(Xg))t[e[1]]=e[2].trim().replace(/^(['"])(.*)\1$/,`$2`);let i=r.match(/^[\w-]*\[(.*)\]$/);return i&&(r=i[1]),{text:K(r,!0),meta:t}}function $g(e,t,n){let r=[];if(e.assigned&&r.push(`owner: ${Hd(e.assigned)}`),e.ticket&&r.push(`ticket: ${Hd(e.ticket)}`),e.priority){let i=Yg[e.priority.toLowerCase()];i?(/very/i.test(e.priority)&&t.warnOnce(`very`,n,`"Very High" and "Very Low" priorities become high and low`),r.push(`priority: ${i}`)):t.warn(n,`priority "${e.priority}" is skipped`)}for(let[t,n]of Object.entries(e))!Zg.includes(t)&&/^[\w-]+$/.test(t)&&r.push(`${t}: ${Hd(n)}`);return r}var e_=(e,t)=>{let n=[],r=Math.min(...e.filter(e=>!Xd.test(e.text)).map(e=>e.indent));for(let i of e){if(Zd(i,t))continue;let{text:e,meta:a}=Qg(i.text);i.indent<=r?n.push(e):n.push($h(` - ${e}`,$g(a,t,i.line)))}return Kd(`kanban`,Gd(t.title,`board`),t.title,[],n)},t_={start:`state-start`,end:`state-end`,fork:`state-bar`,choice:`state-choice`},n_=/^(hide empty description|scale\b)/,r_=/^state\s+(?:"([^"]*)"\s+as\s+)?([^\s{]+)\s*\{$/,i_=/^state\s+(\S+)\s+<<(fork|join|choice)>>$/,a_=/^state\s+"([^"]*)"\s+as\s+(\S+)$/,o_=/^state\s+([^\s:]+)\s*(?::\s*(.*))?$/,s_=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,c_=/^note\s+(?:right of|left of|over)\s+([^:]+?)\s*(?::\s*(.*))?$/i,l_=/^(\S+)\s*-->\s*(\S+?)\s*(?::\s*(.*))?$/,u_=/^([^\s:]+)\s*:\s*(.*)$/,d_=/^(click|link|callback)\b/,f_=/^[\p{L}\p{N}_-]+$/u,p_=/^(.+?)(?::::([\w-]+))?$/,m_=class e{nodes=new Map;boxes=new Map;root={id:``,label:``,items:[]};stack=[this.root];edges=[];classDefs=[];direction=`down`;title;noteCount=0;cursor;ctx;constructor(e,t){this.cursor={lines:e,index:0},this.ctx=t,this.title=t.title}convert(){return Qd(this.cursor,this.ctx,t=>e.HANDLERS.some(e=>e.call(this,t.text,t))),this.stack.length>1&&this.ctx.warn(this.cursor.lines[this.cursor.lines.length-1]?.line??1,`composite state is missing "}"`),this.attachCompositeEdges(),this.write()}static HANDLERS=[e.prototype.readSkipped,e.prototype.readTitle,e.prototype.readDirection,e.prototype.readCompositeClose,e.prototype.readConcurrency,e.prototype.readCompositeOpen,e.prototype.readPseudoState,e.prototype.readStateAlias,e.prototype.readStateDeclaration,e.prototype.readClassDef,e.prototype.readClass,e.prototype.readStyle,e.prototype.readNote,e.prototype.readTransition,e.prototype.readDescription,e.prototype.readClick,e.prototype.readBareName];get current(){return this.stack[this.stack.length-1]}node(e,t=`state`){let n=Ud(e),r=this.nodes.get(n);if(r)return t!==`state`&&(r.kind=t),r;let i={id:n,kind:t,descs:[],classes:[]};return n!==e.trim()&&(i.label=G(e)),this.nodes.set(n,i),this.boxes.has(n)||this.current.items.push(n),i}pseudo(e){let t=this.current,n=e?`end`:`start`;if(!t[n]){let e=t.id?`${t.id}_${n}`:n;t[n]=e,this.nodes.set(e,{id:e,label:``,kind:n,descs:[],classes:[]}),t.items.push(e)}return t[n]}endpoint(e,t){if(e===`[*]`)return this.pseudo(t);let[,n,r]=e.match(p_);if(this.boxes.has(Ud(n)))return Ud(n);let i=this.node(n);return r&&!i.classes.includes(r)&&i.classes.push(r),i.id}readSkipped(e){return n_.test(e)}readTitle(e){let t=Yd(e,!1);return t!==void 0&&(this.title=t),t!==void 0}readDirection(e,t){let n=e.match(ef);return n?(this.stack.length>1?this.ctx.warnOnce(`subdir`,t.line,`direction inside a composite state is skipped`):this.direction=$d[n[1].toUpperCase()],!0):!1}readCompositeClose(e,t){return e===`}`&&(this.stack.length>1?this.stack.pop():this.ctx.warn(t.line,`"}" without a composite state`),!0)}readConcurrency(e,t){return e===`--`&&(this.ctx.warnOnce(`conc`,t.line,`concurrent regions (--) are drawn as one region`),!0)}readCompositeOpen(e){let t=e.match(r_);if(!t)return!1;let[,n,r]=t,i=Ud(r);if(this.nodes.delete(i))for(let e of[this.root,...this.boxes.values()])e.items=e.items.filter(e=>e!==i);let a={id:i,label:n===void 0?r:G(n),items:[]};return this.boxes.set(i,a),this.current.items.push(a),this.stack.push(a),!0}readPseudoState(e){let t=e.match(i_);return t&&(this.node(t[1],t[2]===`choice`?`choice`:`fork`).label=``),!!t}readStateAlias(e){let t=e.match(a_);return t&&(this.node(t[2]).label=K(t[1])),!!t}readStateDeclaration(e){let t=e.match(o_);if(!t)return!1;let n=this.node(t[1]);return t[2]&&n.descs.push(K(t[2])),!0}readClassDef(e,t){let n=af(e,e=>this.ctx.warn(t.line,e));return this.classDefs.push(...n??[]),!!n}readClass(e){let t=e.match(s_);if(!t)return!1;for(let e of t[1].split(`,`))this.node(e.trim()).classes.push(t[2]);return!0}readStyle(e,t){let n=nf(e,e=>this.ctx.warn(t.line,e));return n&&(this.node(n.target).style=n.props),!!n}readNote(e){let t=e.match(c_);if(!t)return!1;let n=t[2]??this.readNoteBody(),r=this.endpoint(t[1].trim(),!1),i=`note${++this.noteCount}`;return this.nodes.set(i,{id:i,label:G(n),kind:`note`,descs:[],classes:[]}),this.current.items.push(i),this.edges.push({from:i,to:r,dotted:!0}),!0}readNoteBody(){let e=[];for(;++this.cursor.index<this.cursor.lines.length&&this.cursor.lines[this.cursor.index].text!==`end note`;)e.push(this.cursor.lines[this.cursor.index].text);return e.join(`
|
|
28
|
+
`)}readTransition(e,t){let n=e.match(l_);if(!n)return!1;let r=this.endpoint(n[1],!1),i=this.endpoint(n[2],!0);return this.edges.push({from:r,to:i,label:n[3]?K(n[3]):void 0,line:t.line}),!0}readDescription(e){let t=e.match(u_);return t&&this.node(t[1]).descs.push(K(t[2])),!!t}readClick(e,t){return d_.test(e)?(this.ctx.warnOnce(`click`,t.line,`click handlers are skipped`),!0):!1}readBareName(e){return f_.test(e)?(this.node(e),!0):!1}attachCompositeEdges(){for(let e of this.edges){let t=this.boxes.get(e.from),n=this.boxes.get(e.to);(t||n)&&this.ctx.warnOnce(`composite`,e.line??1,`edges to a composite state attach to its start or end inside`),t&&(e.from=t.end??y_(t)??e.from),n&&(e.to=n.start??v_(n)??e.to)}}write(){let e=[];this.writeBox(this.root,0,e),this.edges.length&&e.push(``);for(let t of this.edges)e.push(__(t));let t=[this.title?`title: ${this.title}`:``,`direction: ${this.direction}`].filter(Boolean),n=[...this.pseudoClassDefs(),...this.classDefs];return[...t,...n.length?[``,...n]:[],``,...e]}writeBox(e,t,n){let r=` `.repeat(t);for(let i of e.items)typeof i==`string`?n.push(r+g_(this.nodes.get(i))):(n.push(`${r}group ${i.id} ${W(i.label)} {`),this.writeBox(i,t+1,n),n.push(`${r}}`))}pseudoClassDefs(){let e=new Set([...this.nodes.values()].map(e=>e.kind)),t=this.direction===`right`||this.direction===`left`,n=[];return e.has(`start`)&&n.push(`.state-start [shape: circle, fill: slate-700, stroke: slate-700, width: 16, height: 16]`),e.has(`end`)&&n.push(`.state-end [shape: circle, fill: slate-700, stroke: slate-300, stroke-width: 3, width: 20, height: 20]`),e.has(`fork`)&&n.push(`.state-bar [shape: box, fill: slate-700, stroke: slate-700, width: ${t?8:70}, height: ${t?70:8}]`),e.has(`choice`)&&n.push(`.state-choice [shape: diamond, width: 28, height: 28]`),n}},h_=(e,t)=>new m_(e,t).convert();function g_(e){let t=[e.id],n=e.label??e.id;(n!==e.id||e.kind===`note`)&&t.push(W(n));let r=t_[e.kind];r&&t.push(`.${r}`);for(let n of e.classes)t.push(`.${n}`);let i=[];return e.kind===`note`&&i.push(`shape: note`),e.descs.length&&i.push(`sub: ${W(e.descs.join(` / `))}`),e.style&&i.push(e.style),i.length&&t.push(`[${i.join(`, `)}]`),t.join(` `)}function __(e){let t=e.dotted?`..`:`->`;return`${e.from} ${t} ${e.to}${e.label?`: `+sf(e.label):``}`}function v_(e){for(let t of e.items){let e=typeof t==`string`?t:t.start??v_(t);if(e)return e}}function y_(e){for(let t=e.items.length-1;t>=0;t--){let n=e.items[t],r=typeof n==`string`?n:n.end??y_(n);if(r)return r}}var b_=/^(\d+(?:\s*-\s*\d+)?|\+\s*\d+)\s*:\s*(.+)$/,x_=/[[\]]|^"|^(\/\/|#)|^$/,S_=(e,t)=>{let n={title:t.title},r=[];return Qh(e,t,n,e=>{let t=e.text.match(b_);return t&&r.push(`${t[1].replace(/\s+/g,``)}: ${Vd(K(t[2]),x_)}`),!!t}),Kd(`packet`,Gd(n.title,`packet`),n.title,[],r)},C_=/^("[^"]*"|'[^']*'|[^:]+?)\s*(?::\s*(-?\d*\.?\d+(?:e[+-]?\d+)?))?\s*(?::::([\w-]+))?\s*;?$/i,w_=/[[\]:]|^"|^(\/\/|#)|^$/,T_=(e,t)=>{let n={title:t.title},r=new Map,i=[];Qh(e,t,n,e=>{let n=e.text.match(rf);if(n){let i=n[2].match(/(?:^|[,;])\s*fill\s*:\s*([^,;]+)/)?.[1].trim();for(let e of n[1].split(`,`))i&&r.set(e.trim(),i);return/(?:^|[,;])\s*(?!fill\b)[\w-]+\s*:/.test(n[2])&&t.warnOnce(`classdef`,e.line,`only the fill of a classDef carries over, as the colour`),!0}let a=e.text.match(C_);return a&&i.push({l:e,name:K(G(a[1])),value:a[2],cls:a[3]}),!!a});let a=Ka(),o=i.map(({l:e,name:n,value:i,cls:o})=>{let s=a.enter(e.indent),c=``;if(o){let n=r.get(o);n?c=` [${/^[\w#]+$/.test(n)?n:W(n)}]`:t.warnOnce(`class:${o}`,e.line,`class "${o}" has no fill to carry over`)}return`${` `.repeat(s)}${Vd(n,w_)}${c}${i===void 0?``:`: ${i}`}`});return Kd(`treemap`,Gd(n.title,`treemap`),n.title,[],o)},E_=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,D_=/[,[\]:"]|->|^$/,O_=e=>Vd(e,D_),k_=(e,t)=>{let n={title:t.title},r=[];return Qh(e,t,n,e=>{let t=Nl(e.text);if(t.length!==3||!E_.test(t[2])||!t[0]||!t[1])return!1;let[n,i,a]=t;return r.push(`${O_(n)} -> ${O_(i)}: ${a}`),!0}),Kd(`sankey`,Gd(n.title,`sankey`),n.title,[`links: gradient`],r)},A_=String.raw`[\p{L}\p{N}_.-]+`,j_=String.raw`(?:\[\s*"([^"]*)"\s*\]|\[([^\]]*)\])`,M_=String.raw`(?:\s*:\s*(\d+(?:\.\d+)?))`,N_=new RegExp(String.raw`^set\s+(${A_})\s*${j_}?${M_}?\s*$`,`u`),P_=new RegExp(String.raw`^union\s+(${A_}(?:\s*,\s*${A_})+)\s*${j_}?${M_}?\s*$`,`u`),F_=new RegExp(String.raw`^text\s+(?:(${A_})\s*${j_}|"([^"]*)"|(.+))$`,`u`),I_=new RegExp(String.raw`^style\s+(${A_}(?:\s*,\s*${A_})*)\s+(.*)$`,`u`),L_=e=>Vd(e,/[:&[\]"]|^\s|\s$/),R_=(e,t)=>{let n={title:t.title},r=new Map,i=[],a,o,s=e=>{let t=r.get(e);return t||(t={ids:[e],texts:[]},r.set(e,t)),t},c=e=>{if(e.length===1)return s(e[0]);let t=[...e].sort().join(`,`);return i.find(e=>[...e.ids].sort().join(`,`)===t)};Qh(e,t,n,e=>{let n=e.text.match(N_);if(n){let e=s(n[1]);return e.label=G(n[2]??n[3]??``)||e.label,e.size=n[4]??e.size,a=e,!0}let r=e.text.match(P_);if(r){let e=r[1].split(/\s*,\s*/);e.forEach(s);let t=c(e);return t||(t={ids:e,texts:[]},i.push(t)),t.label=G(r[2]??r[3]??``)||t.label,t.size=r[4]??t.size,a=t,!0}let l=e.text.match(F_);if(l){let n=G(l[2]??l[3]??l[4]??l[5]??l[1]??``);return a?n&&a.texts.push(n):t.warn(e.line,`text "${n}" is not inside a set or union and was skipped`),!0}let u=e.text.match(I_);if(u){let n=u[1].split(/\s*,\s*/),r=n.length>1?c(n):s(n[0]);for(let n of u[2].replace(/;$/,``).split(`,`)){let[i,...a]=n.split(`:`),s=i.trim(),c=a.join(`:`).trim();s&&(s===`fill`&&r?r.color=c:s===`fill-opacity`?o=c:t.warnOnce(`style-${s}`,e.line,`venn style "${s}" is not supported and was skipped`))}return r||t.warn(e.line,`style for "${u[1]}" has no matching union and was skipped`),!0}return!1}),r.size>4&&t.warnOnce(`venn-sets`,e[0]?.line??1,`a yuhwa venn shows at most 4 sets; the rest are skipped`);let l=e=>L_(r.get(e)?.label??e),u=e=>{let t=[e.color,e.size===void 0?void 0:`size: ${e.size}`].filter(Boolean);return t.length?` [${t.join(`, `)}]`:``},d=[];for(let e of r.values()){let t=l(e.ids[0]),n=u(e);(n||!e.texts.length)&&d.push(`${t}${n}`),d.push(...e.texts.map(e=>`${t}: ${e}`))}for(let e of i){let t=e.ids.map(l).join(` & `),n=u(e);(e.label||n||!e.texts.length)&&d.push(`${t}${n}${e.label?`: ${e.label}`:``}`),d.push(...e.texts.map(e=>`${t}: ${e}`))}return Kd(`venn`,Gd(n.title,`venn`),n.title,o?[`opacity: ${o}`]:[],d)},z_=/^[-*+]\s|^"|(^|\s)\/\/|^[{}]$/,B_=(e,t)=>{let n=[],r,i=0,a=Ka();for(let o of e){if(Zd(o,t))continue;let e=K(o.text);if(!e)continue;let s=Vd(e,z_);if(r===void 0){r=e,i=o.indent,n.push(s);continue}o.indent<=i&&a.cut(0);let c=a.enter(o.indent)+1;n.push(` `.repeat(c)+s)}return r===void 0&&t.warn(e[0]?.line??1,`ishikawa: no event line, so the diagram is empty`),Kd(`ishikawa`,Gd(t.title??r,`fishbone`),t.title,[],n)},V_=/\b(?:terminal|nonterminal|sequence|choice|optional|zeroOrMore|oneOrMore|special)\s*\(/,H_=e=>e.replace(/"[^"]*"|'[^']*'/g,`""`).replace(/\/\*.*?\*\/|\(\*.*?\*\)/g,` `).replace(/(^|\s)#.*$/,`$1`);function U_(e){let t=e.map(H_).join(`
|
|
29
|
+
`);return V_.test(t)?`ir`:/<-|←/.test(t)?`peg`:/%[xdb][0-9a-f]/i.test(t)||/(?:^|[\s(=/[])\d*\*\d*[\p{L}"(%[<]/u.test(t)||/\//.test(t)?`abnf`:`ebnf`}function W_(e){let t=[];for(let n of e.matchAll(/\s+|"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([\p{L}_][\p{L}\p{N}_-]*)|(.)/gu))n[1]!==void 0||n[2]!==void 0?t.push({v:(n[1]??n[2]).replace(/\\(.)/g,`$1`),str:!0}):(n[3]??n[4])&&t.push({v:n[3]??n[4]});return t}var G_={sequence:`seq`,choice:`choice`},K_={optional:e=>({k:`opt`,item:e}),oneOrMore:e=>({k:`many`,item:e,min:1}),zeroOrMore:e=>({k:`opt`,item:{k:`many`,item:e,min:1}})},q_={terminal:`term`,nonterminal:`nt`,special:`special`};function J_(e,t,n){let r=W_(e),i=0,a=e=>{n.warn(t,`railroad: ${e}`)},o=()=>{let e=r[i++];if(!e)return a(`the rule ends early`);if(e.str)return{k:`term`,text:e.v};if(r[i]?.v!==`(`)return/^[\p{L}_]/u.test(e.v)?{k:`nt`,text:e.v}:a(`unexpected "${e.v}"`);i++;let t=[];for(;i<r.length&&r[i].v!==`)`;){if(r[i].v===`,`){i++;continue}if(q_[e.v]&&r[i].str){t.push({k:`term`,text:r[i++].v});continue}let n=o();if(!n)return;t.push(n)}if(i++,q_[e.v]){let n=t[0]?.k===`term`||t[0]?.k===`nt`?t[0].text:``;return{k:q_[e.v],text:n}}if(G_[e.v])return t.length===1?t[0]:{k:G_[e.v],items:t};if(K_[e.v]){let n=t.length===1?t[0]:{k:`seq`,items:t};return K_[e.v](n)}return a(`unknown constructor "${e.v}"`)},s=r[i++];if(!s||s.str||r[i++]?.v!==`=`)return a(`could not read "${e.trim().slice(0,40)}"`);let c=o();return c&&`${s.v} = ${bu(c)} ;`}function Y_(e,t){let n=[],r=``,i=0;for(let a of e){r||(i=a.line);for(let e of a.text.split(/(;)(?=(?:[^"]*"[^"]*")*[^"]*$)/))if(e===`;`){let e=r.trim()&&J_(r,i,t);e&&n.push(e),r=``,i=a.line}else r+=e+` `}if(r.trim()){let e=J_(r,i,t);e&&n.push(e)}return n}var X_=(e,t)=>{let n={},r=[];Qh(e,t,n,e=>/^(?:config|style|classDef)\b/.test(e.text)?(t.warnOnce(`rr-style`,e.line,`railroad: styling statements are skipped`),!0):(r.push(e),!0));let i=n.title??t.title,a=t.type?.match(/^railroad-(ebnf|abnf|peg)(?:-beta)?$/)?.[1]??U_(r.map(e=>e.text)),o;if(a===`ir`)o=Y_(r,t);else{o=[];for(let e of r)e.text===`}`&&o.length?o[o.length-1]+=` `+e.text:o.push(e.text)}o.length||t.warn(e[0]?.line??1,`railroad: no rules, so the diagram is empty`);let s=a===`abnf`||a===`peg`?[`notation: ${a}`]:[];return Kd(`railroad`,Gd(i,`grammar`),i,s,o)},Z_=/^(anchor|component|market|submap|ecosystem|evolve|note|accelerator|deaccelerator|annotations?|evolution)\b/i,Q_=/^("[^"]*"|[^"]+?)\s*(-\.->|-->|->|\+<>|\+<|\+'[^']*'>|\+>)\s*("[^"]*"|[^;]+?)\s*(;.*)?$/,$_=/^pipeline\s+(.+?)\s*\{\s*$/i,e1=/^pipeline\s+.+\[\s*-?[\d.]+\s*,\s*-?[\d.]+\s*\]\s*$/i,t1=/^.+?\s*-\.-\s*\(/,n1=(e,t)=>{let n={title:t.title},r=[],i=!1;return Qh(e,t,n,e=>{let n=e.text.trim(),a;return i?n===`}`?(i=!1,!0):/^component\b/i.test(n)?(r.push(` ${n}`),!0):!1:(a=n.match($_))?(r.push(`pipeline ${a[1]}`),i=!0,!0):e1.test(n)||Z_.test(n)?(r.push(n),!0):/^size\b/i.test(n)?(t.warnOnce(`size`,e.line,`size was dropped: drag the map corner to resize it`),!0):/^style\b/i.test(n)?(t.warnOnce(`style`,e.line,`map styles (wardley, handwritten, …) were dropped`),!0):t1.test(n)?(t.warn(e.line,`trend lines were dropped`),!0):Q_.test(n)?(r.push(n),!0):!1}),Kd(`wardley`,Gd(n.title,`map`),n.title,[],r)},r1=/^(complex|complicated|clear|chaotic|confusion)\s*$/i,i1=/^([A-Za-z]+)\s*-->\s*([A-Za-z]+)\s*(?::\s*(.*))?$/,a1=/^"([^"]*)"\s*$/,o1=(e,t)=>{let n={title:t.title},r=[],i=!1;return Qh(e,t,n,e=>{let n=e.text.trim(),a;if(a=n.match(r1))return r.push(a[1].toLowerCase()),i=!0,!0;if(a=n.match(i1)){let[,n,i,o]=a;return!r1.test(n)||!r1.test(i)?!1:n.toLowerCase()===i.toLowerCase()?(t.warn(e.line,`the self-loop on ${n} was dropped`),!0):(r.push(`${n.toLowerCase()} --> ${i.toLowerCase()}${o?.trim()?` : ${o.trim()}`:``}`),!0)}return(a=n.match(a1))?i?(r.push(` ${n}`),!0):(t.warn(e.line,`"${a[1]}" comes before any domain and was dropped`),!0):!1}),Kd(`cynefin`,Gd(n.title,`cynefin`),n.title,[],r)},s1=/^\s*([\p{L}\p{N}_-]+)\s*(?:\[\s*("[^"]*"|[^\]]*)\s*\])?\s*/u,c1=/^-?\d+(?:\.\d+)?$/;function l1(e){let t=[],n=e;for(;n.trim();){let e=n.match(s1);if(!e)return;t.push({id:e[1],label:e[2]?K(e[2]):e[1]}),n=n.slice(e[0].length).replace(/^,\s*/,``)}return t}function u1(e,t){let n=[],r=e;for(;r.trim();){let e=r.match(/^\s*([\p{L}\p{N}_-]+)\s*(?:\[\s*("[^"]*"|[^\]]*)\s*\])?\s*\{([^}]*)\}\s*,?\s*/u);if(!e)return;n.push({label:e[2]?K(e[2]):e[1],values:of(e[3]),line:t}),r=r.slice(e[0].length)}return n}var d1=/^(showLegend|max|min|graticule|ticks)\s+(\S+)\s*$/,f1=(e,t)=>{let n={title:t.title},r=[],i=[],a=[`type: radar`];Qh(e,t,n,e=>{let n=e.text,o;if(o=n.match(/^axis\s+(.*)$/)){let e=l1(o[1]);return e?.forEach(e=>r.push(e)),!!e}if(o=n.match(/^curve\s+(.*)$/)){let t=u1(o[1],e.line);return t?.forEach(e=>i.push(e)),!!t}if(o=n.match(d1)){let[,n,r]=o;return n===`showLegend`?r===`false`&&a.push(`legend: none`):n===`graticule`?a.push(`grid: ${r===`polygon`?`polygon`:`circle`}`):c1.test(r)?a.push(`${n}: ${r}`):t.warn(e.line,`${n} expects a number, got "${r}"`),!0}return!1});let o=[];r.length&&o.push(`axes: ${r.map(e=>/[,[\]:"]/.test(e.label)?W(e.label):e.label).join(`, `)}`);let s=new Map(r.map((e,t)=>[e.id,t]));for(let e of i){let n;if(e.values.some(e=>e.includes(`:`))){n=r.map(()=>`0`);for(let r of e.values){let[i,a=``]=r.split(`:`).map(e=>e.trim()),o=s.get(i);o===void 0?t.warn(e.line,`curve "${e.label}": unknown axis "${i}" was skipped`):c1.test(a)&&(n[o]=a)}}else n=e.values.filter(e=>c1.test(e)),n.length!==e.values.length&&t.warn(e.line,`curve "${e.label}": values that are not numbers were skipped`);n.length?o.push(`${rg(e.label)}: ${n.join(`, `)}`):t.warn(e.line,`curve "${e.label}" has no values and was skipped`)}return Kd(`chart`,Gd(n.title,`radar`),n.title,a,o)},p1=/^[│┃├└┣┗─━\s]*/,m1=/:::([\w-]+)/g,h1=/\bicon\(([^)]*)\)/g,g1=/\s*##\s*(.*)$/,_1=(e,t)=>{let n=[],r=Ka();for(let i of e){if(Zd(i,t))continue;let e=i.text.match(p1)[0],a=i.indent+e.length,o=i.text.slice(e.length);if(!o)continue;let s=r.enter(a),c=[],l=``,u=o.match(g1);u&&(l=u[1].trim(),o=o.slice(0,u.index)),o=o.replace(m1,(e,n)=>(n===`highlight`?c.push(`highlight`):t.warnOnce(`class:${n}`,i.line,`treeView class :::${n} is skipped`),``)),o=o.replace(h1,(e,n)=>{let r=n.trim();return r===`folder`||r===`file`?c.push(r):r!==`none`&&t.warnOnce(`icon:${r}`,i.line,`treeView icon ${r} is skipped; yuhwa picks icons from the file name`),``});let d=o.trim(),f=d.match(/^"(.*)"$/)??d.match(/^'(.*)'$/);if(f&&(d=f[1]),!d)continue;let p=` `.repeat(s)+d;c.length&&(p+=` [${c.join(`, `)}]`),l&&(p+=` # ${l}`),n.push(p)}return Kd(`treeview`,Gd(t.title,`tree`),t.title,[],n)},v1=/^\s*(graph|flowchart)\b\s*(TD|TB|BT|RL|LR)?\s*(?:;.*)?$/i;function y1(e){let t=e.findIndex(e=>e.trim());if(t<0||e[t].trim()!==`---`)return 0;let n=e.findIndex((e,n)=>n>t&&e.trim()===`---`);return n<0?0:n+1}var b1=/%%.*$/,x1=/^\s*title\s*:\s*(.+)$/;function S1(e){return e.replace(b1,``)}function C1(e){let t;for(let n=0;n<y1(e);n++){let r=e[n].match(x1);r&&(t=G(r[1]))}return t}function w1(e,t){let n=[];for(let r=t;r<e.length;r++){let t=S1(e[r]).replace(/\s+$/,``),i=t.trim();if(!i)continue;let a=t.match(/^\s*/)[0];n.push({text:i,line:r+1,indent:a.replace(/\t/g,` `).length})}return n}var T1=[[`(((`,`)))`,`circle`],[`((`,`))`,`circle`],[`([`,`])`,`pill`],[`[(`,`)]`,`cylinder`],[`[[`,`]]`,`box`],[`{{`,`}}`,`hexagon`],[`[/`,`/]`,`parallelogram`],[`[\\`,`\\]`,`parallelogram`],[`[/`,`\\]`,`parallelogram`],[`[\\`,`/]`,`parallelogram`],[`(`,`)`,``],[`[`,`]`,``],[`{`,`}`,`diamond`],[`>`,`]`,`box`]],E1=/^[A-Za-z0-9_][\w]*(?:[.-](?![-.=>ox]\s|[-.=>])[\w]+)*/,D1=/^[\w-]+/,O1=`:::`,k1=/^([<ox])?(--|==|-\.)([^-=.>|][^>|]*?)(-{2,}>?|={2,}>?|\.+-+>?|-\.+-*>?)(?:([ox])(?=\s|$))?/,A1=/^([<ox])?(-{2,}|={2,}|-\.+-)(>|[ox](?=[\s|]|$))?(?:\s*\|([^|]*)\|)?/,j1=class{pos=0;nodes=[];edges=[];text;toId;warn;constructor(e,t,n){this.text=e,this.toId=t,this.warn=n}read(){let e=this.readNodeGroup();if(!e)return this.warn(`could not read "${this.text}"`),null;let t=e;for(;!this.atEnd();){let e=this.readLink();if(!e){this.warn(`could not read "${this.text.slice(this.pos)}"`);break}let n=this.readNodeGroup();if(!n){this.warn(`link without a target in "${this.text}"`);break}this.addEdges(t,n,e),t=n}return{nodes:this.nodes,edges:this.edges}}atEnd(){return this.skipSpace(),this.pos>=this.text.length}skipSpace(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}rest(){return this.text.slice(this.pos)}readNodeGroup(){let e=[];for(;;){let t=this.readNode();if(!t)return e.length?e:null;if(e.push(t),this.skipSpace(),this.text[this.pos]!==`&`)return e;this.pos++}}readNode(){this.skipSpace();let e=this.rest().match(E1);if(!e)return null;this.pos+=e[0].length;let t={id:this.toId(e[0]),classes:[]};return this.readShape(t),this.readClasses(t),this.nodes.push(t),t}readShape(e){for(let[t,n,r]of T1){if(!this.text.startsWith(t,this.pos))continue;let i=this.pos+t.length,a=I1(this.text,i,n);if(!(a<0)){e.label=G(this.text.slice(i,a)),e.shape=r||void 0,this.pos=a+n.length;return}}}readClasses(e){for(;this.text.startsWith(O1,this.pos);){let t=this.text.slice(this.pos+3).match(D1);if(!t)return;e.classes.push(t[0]),this.pos+=3+t[0].length}}readLink(){let e=this.rest(),t=e.match(k1);if(t&&/[->=]/.test(t[4])){this.pos+=t[0].length;let[,e,n,r,i,a]=t;return{start:e,body:n,end:i.endsWith(`>`)?`>`:a,label:G(r)}}let n=e.match(A1);if(!n)return null;this.pos+=n[0].length;let[,r,i,a,o]=n;return{start:r,body:i,end:a,label:o===void 0?void 0:G(o)}}addEdges(e,t,n){let{arrow:r,props:i}=N1(n);for(let a of e)for(let e of t)this.edges.push({from:a.id,to:e.id,arrow:r,label:n.label||void 0,props:i})}},M1={o:`dot`,x:`bar`};function N1({start:e,body:t,end:n}){let r=t.startsWith(`=`),i=t.includes(`.`),a=e&&n?`<->`:n?r?`=>`:i?`..>`:`->`:`--`,o=[];return(a===`<->`||a===`--`)&&P1(o,r,i),F1(o,e,n),e&&!n&&o.push(`tail: arrow`),{arrow:a,props:o}}function P1(e,t,n){t&&e.push(`width: 3`),n&&e.push(`style: dotted`)}function F1(e,t,n){n&&n in M1&&e.push(`head: ${M1[n]}`),t&&t in M1&&e.push(`tail: ${M1[t]}`)}function I1(e,t,n){let r=!1;for(let i=t;i<e.length;i++)if(e[i]===`"`&&(r=!r),!r&&e.startsWith(n,i))return i;return-1}function L1(e){let t=[],n=0,r=``,i=0;for(let a=0;a<e.length;a++){let o=e[a];r?o===r&&(r=``):o===`"`?r=o:`[({`.includes(o)?n++:`)]}`.includes(o)?n=Math.max(0,n-1):o===`;`&&n===0&&(t.push(e.slice(i,a)),i=a+1)}return t.push(e.slice(i)),t}var R1=/^subgraph\s+(.*)$/,z1=/^([\w-]+)\s*\[(.*)\]$/,B1=/^class\s+([\w,\s-]+?)\s+([\w-]+)$/,V1=/^(linkStyle|click|accTitle|accDescr|callback|interpolate)\b/,H1=/^[\p{L}\p{N}][\p{L}\p{N} ,!?'()+-]*$/u;function U1(e,t={}){let n=e.split(`
|
|
30
|
+
`),r=new W1(C1(n),t.lanes??!1);for(let e=y1(n);e<n.length;e++)for(let t of L1(S1(n[e])))r.statement(t.trim(),e+1);return r.finish(n.length)}var W1=class{warnings=[];settings=[];classDefs=[];body=[];ids=new Map;declared=new Set;groupIds=new Set;depth=0;openEdges=new Map;line=0;lane;homes=new Map;lanes;constructor(e,t){this.lanes=t,e!==void 0&&this.settings.push(`title: ${e}`)}statement(e,t){e&&(this.line=t,this.header(e)||this.title(e)||this.direction(e)||this.subgraph(e)||this.end(e)||this.classDef(e)||this.classAssign(e)||this.style(e)||this.unsupported(e)||this.nodesAndEdges(e))}finish(e){for(;this.depth>0;)this.closeGroup(),this.warnings.push({line:e,message:`subgraph is missing "end"`});for(let e of this.groupIds)this.declared.has(e)&&this.warnings.push({line:1,message:`"${e}" is both a node and a subgraph; edges to subgraphs are not supported`});for(let[e,t]of this.homes)t.lane===void 0&&this.warnings.push({line:t.line,message:`"${e}" is outside every lane: it sits after the last lane`});let t=[...this.settings,...this.classDefs.length?[``,...this.classDefs]:[]],n=this.body.map(e=>typeof e==`string`?e:K1(e));return{source:[...t,...t.length?[``]:[],...n].join(`
|
|
31
|
+
`)+`
|
|
32
|
+
`,warnings:this.warnings}}header(e){let t=e.match(v1);return t?(t[2]&&this.settings.push(`direction: ${$d[t[2].toUpperCase()]}`),!0):!1}title(e){let t=Yd(e);return t===void 0||this.depth>0?!1:(this.settings.push(`title: ${t}`),!0)}direction(e){let t=e.match(ef);return t?(this.depth>0?this.warn(`subgraph direction is not supported; the whole diagram uses one direction`):this.settings.push(`direction: ${$d[t[1].toUpperCase()]}`),!0):!1}subgraph(e){let t=e.match(R1);if(!t)return!1;let{id:n,title:r}=this.subgraphIdAndTitle(t[1].trim());return this.groupIds.add(n),this.depth===0&&(this.lane=r),this.write(`group ${n} ${W(r)} {`),this.depth++,this.openEdges=new Map,!0}subgraphIdAndTitle(e){let t=e.match(z1);if(t)return{id:this.toId(t[1]),title:G(t[2])};if(/^".*"$/.test(e)){let t=G(e);return{id:this.toId(t.toLowerCase()),title:t}}return/^[\w-]+$/.test(e)?{id:this.toId(e),title:e}:{id:this.toId(e.toLowerCase()),title:e}}end(e){return e===`end`&&(this.depth>0?this.closeGroup():this.warn(`"end" without subgraph`),!0)}closeGroup(){this.depth--,this.openEdges=new Map,this.write(`}`)}classDef(e){let t=af(e,e=>this.warn(e));return this.classDefs.push(...t??[]),!!t}classAssign(e){let t=e.match(B1);if(!t)return!1;for(let e of t[1].split(`,`))this.write(`${this.toId(e.trim())} .${t[2]}`);return!0}style(e){let t=nf(e,e=>this.warn(e));return t?.props&&this.write(`${this.toId(t.target)} [${t.props}]`),!!t}unsupported(e){return V1.test(e)?(this.warn(`"${e.split(/\s+/)[0]}" is not supported and was skipped`),!0):!1}nodesAndEdges(e){let t=new j1(e,e=>this.toId(e),e=>this.warn(e)).read();if(!t)return;let n=new Set(t.edges.flatMap(e=>[e.from,e.to]));for(let e of t.nodes)this.writeNode(e,n.has(e.id));for(let e of t.edges)this.writeEdge(e)}writeNode(e,t){if(this.lanes&&!this.laneHome(e.id))return;let n=[e.id];e.label!==void 0&&e.label!==e.id&&n.push(W(e.label));for(let t of e.classes)n.push(`.${t}`);e.shape&&n.push(`[shape: ${e.shape}]`);let r=n.length===1,i=this.depth>0;this.declared.has(e.id)&&r&&!i||(this.declared.add(e.id),r&&!i&&t||this.write(n.join(` `)))}laneHome(e){let t=this.homes.get(e);return this.depth===0?(t||this.homes.set(e,{line:this.line}),!0):t?.lane===void 0?(this.homes.set(e,{lane:this.lane,line:t?.line??this.line}),!0):t.lane===this.lane||(this.warn(`"${e}" is already in lane "${t.lane}": it stays there, as in Mermaid`),!1)}writeEdge(e){let t=G1(e),n=`${this.indent()}${e.from} ${e.arrow} `,r=`${n}\0${t}`,i=this.openEdges.get(r);if(i){i.targets.push(e.to);return}let a={head:n,targets:[e.to],tail:t};this.openEdges.set(r,a),this.body.push(a)}warn(e){this.warnings.push({line:this.line,message:e})}write(e){this.body.push(this.indent()+e)}indent(){return` `.repeat(this.depth)}toId(e){let t=this.ids.get(e);return t===void 0&&(t=Ud(e),this.ids.set(e,t)),t}};function G1(e){return[e.label?H1.test(e.label)?e.label:W(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `)}function K1({head:e,targets:t,tail:n}){return`${e}${t.join(`, `)}${n?`: `+n:``}`}var q1=(e,t)=>{let n=t.header.split(/\s+/)[0]?.toUpperCase()||`TB`;$d[n]||t.warn(e[0]?.line??1,`unknown direction "${t.header}": the lanes run down`);let r=Math.max(1,...e.map(e=>e.line)),i=Array.from({length:r},()=>``);i[0]=`flowchart ${$d[n]?n:`TB`}`;for(let t of e)i[t.line-1]=t.text;let a=U1(i.join(`
|
|
33
|
+
`),{lanes:!0});for(let e of a.warnings)t.warn(e.line,e.message);let o=[`lanes: on`];return t.title!==void 0&&o.unshift(`title: ${t.title}`),[...o,...a.source.replace(/\n+$/,``).split(`
|
|
34
|
+
`)]},J1=/^(tf|timeframe|rf|resetframe)\s+(\S+)\s+(\S+)\s+([^\s{[]+)\s*(.*)$/i,Y1=/^data\s+([\p{L}\p{N}_.-]+)\s*(?:`(\w+)`)?\s*\{(.*)$/u,X1=/^->>\s*(\S+)\s*/,Z1=/^(?:`(\w+)`)?\s*\{(.*)\}\s*/,Q1=/^\[\[([^\]]+)\]\]\s*/,$1={ui:`ui`,pcr:`pcr`,processor:`pcr`,cmd:`cmd`,command:`cmd`,rmo:`rmo`,readmodel:`rmo`,evt:`evt`,event:`evt`},e0={ui:[`ui`,`UI / Automation`],pcr:[`ui`,`UI / Automation`],cmd:[`cmd`,`Commands / Read models`],rmo:[`cmd`,`Commands / Read models`],evt:[`evt`,`Events`]},t0=[[`ui`,`[tone: slate]`],[`pcr`,`[tone: purple, shape: hexagon]`],[`cmd`,`[tone: blue]`],[`rmo`,`[tone: green]`],[`evt`,`[tone: orange]`]],n0=(e,t)=>{let n=[],r=new Map,i=new Map,a=new Map;for(let o=0;o<e.length;o++){let s=e[o],c=s.text.trim();if(/^(accTitle|accDescr)\b/.test(c)){t.warnOnce(`acc`,s.line,`accessibility titles (accTitle, accDescr) are skipped`);continue}let l=c.match(Y1);if(l){let n=[],r=1,i=l[3];for(;;){for(let e of i)r+=e===`{`?1:e===`}`?-1:0;if(n.push(r>0?i:i.replace(/\}\s*$/,``)),r<=0||o+1>=e.length)break;i=e[++o].text.trim()}r>0&&t.warn(s.line,`data block "${l[1]}" is missing its closing "}"`),a0(l[2],s.line,t),a.has(l[1])&&t.warn(s.line,`data block "${l[1]}" is defined twice: the later one is used`),a.set(l[1],{fields:i0(n.join(`
|
|
35
|
+
`)),line:s.line});continue}let u=c.match(J1);if(!u){t.warn(s.line,`could not read "${c}"`);continue}let[,d,f,p,m]=u,h=u[5],g=$1[p.toLowerCase()];if(!g){t.warn(s.line,`unknown entity type "${p}" (use ui, pcr, cmd, rmo or evt): the frame was skipped`);continue}if(r.has(f)){t.warn(s.line,`time frame ${f} is used twice: the later one was skipped`);continue}let _=m.lastIndexOf(`.`),v=_>0?m.slice(0,_):``,[y,b]=e0[g],x=v?Ud(`${v}_${y}`):y,S={num:f,id:Ud(`f${f}`),kind:g,label:_>0?m.slice(_+1):m,lane:x,reset:/^r/i.test(d),line:s.line,links:[],data:[]};for(;h;){let e=h.match(X1),n=h.match(Z1),r=h.match(Q1);if(e)S.links.push(e[1]),h=h.slice(e[0].length);else if(n)a0(n[1],s.line,t),S.data.push(...i0(n[2])),h=h.slice(n[0].length);else if(r)S.ref=r[1].trim(),h=h.slice(r[0].length);else{t.warn(s.line,`could not read "${h}" after frame ${f}: it was skipped`);break}}n.push(S),r.set(f,S),i.has(x)||i.set(x,{title:v?`${v}: ${b}`:b,frames:[]}),i.get(x).frames.push(S)}let o=new Set;for(let e of n){if(!e.ref)continue;let n=a.get(e.ref);n?(o.add(e.ref),e.data.push(...n.fields)):t.warn(e.line,`data block "${e.ref}" is not defined`)}for(let[e,n]of a)o.has(e)||t.warn(n.line,`data block "${e}" is not used by any time frame`);let s=[];t.title!==void 0&&s.push(`title: ${t.title}`),s.push(`direction: right`,`lanes: on`,``);let c=new Set(n.map(e=>e.kind));for(let[e,t]of t0)c.has(e)&&s.push(`.${e} ${t}`);for(let[e,t]of i){s.push(``,`group ${e} ${W(t.title)} {`);for(let e of t.frames){let t=e.data.length?` [sub: ${W(e.data.join(`, `))}]`:``;s.push(` ${e.id} ${W(e.label)} .${e.kind}${t}`)}s.push(`}`)}let l=[...n].sort((e,t)=>r0(e.num,t.num)),u=new Set,d=(e,t,n=``)=>{e!==t&&u.add(`${e.id} -> ${t.id}${n}`)};l.forEach((e,t)=>{let n=l[t+1];n&&d(e,n,n.reset?`: [opacity: 0]`:``)});for(let e of n)for(let n of e.links){let i=r.get(n);i?d(e,i):t.warn(e.line,`frame ${e.num} links to frame ${n}, which does not exist`)}return u.size&&s.push(``,...u),s};function r0(e,t){let[n,r]=[Number(e),Number(t)];return Number.isFinite(n)&&Number.isFinite(r)?n-r:e.localeCompare(t)}function i0(e){let t=e.trim().replace(/^\{|\}$/g,``),n=[],r=``,i=0,a=``;for(let e of t){if(a)a=e===a?``:a;else if(e===`"`||e===`'`)a=e;else if(e===`{`||e===`[`)i++;else if(e===`}`||e===`]`)i--;else if((e===`,`||e===`
|
|
36
|
+
`)&&!i){n.push(r),r=``;continue}r+=e}return n.push(r),n.map(e=>e.trim().replace(/^["']([^"']*)["']\s*:/,`$1:`).replace(/:\s*["']([^"']*)["']$/,`: $1`).replace(/\s+/g,` `)).filter(Boolean)}function a0(e,t,n){e&&n.warnOnce(`data-type`,t,`data types such as \`${e}\` are shown as plain text`)}var o0=class{settings=[];classDefs=[];nodes=new Map;groups=new Map;edges=[];layout=[];ids=new Map;id(e){let t=this.ids.get(e);if(t===void 0){t=Ud(e);let n=new Set(this.ids.values());for(let r=2;n.has(t);r++)t=`${Ud(e)}_${r}`;this.ids.set(e,t)}return t}node(e,t){let n=this.id(e),r=this.nodes.get(n);return r||(r={id:n,classes:[],props:[],body:[],group:t},this.nodes.set(n,r)),r}has(e){let t=this.ids.get(e);return t!==void 0&&(this.nodes.has(t)||this.groups.has(t))}group(e,t){let n=this.id(e),r=this.groups.get(n);return r||(r={id:n,classes:[],props:[],parent:t},this.groups.set(n,r)),r}edge(e,t,n=`->`,r,i=[]){let a={from:e,to:t,arrow:n,label:r,props:i};return this.edges.push(a),a}styling(e,t){let n=n=>t.warn(e.line,n),r=af(e.text.replace(/;$/,``),n);if(r)return this.classDefs.push(...r),!0;let i=e.text.match(/^class\s+([^\s]+)\s+([\w,-]+);?$/);if(i){for(let e of i[1].split(`,`)){let t=this.target(e.trim());t?t.classes.push(...i[2].split(`,`)):n(`class for unknown "${e.trim()}" was skipped`)}return!0}let a=nf(e.text.replace(/;$/,``),n);if(a){for(let e of a.target.split(`,`)){let t=this.target(e);t&&a.props?t.props.push(a.props):t||n(`style for unknown "${e}" was skipped`)}return!0}return!1}target(e){let t=this.ids.get(e)??Ud(e);return this.nodes.get(t)??this.groups.get(t)}emit(e={},t=`after`){let n=[...this.settings],r=new Set([...this.nodes.values(),...this.groups.values()].flatMap(e=>e.classes)),i=Object.entries(e).filter(([e])=>r.has(e)).map(([e,t])=>`.${e} ${t}`),a=t===`before`?[...i,...this.classDefs]:[...this.classDefs,...i];a.length&&n.push(``,...new Set(a)),n.push(``);let o=(e,t)=>{for(let r of this.nodes.values())r.group===e&&n.push(...c0(r,t));for(let r of this.groups.values())r.parent===e&&(n.push(t+[`group`,...s0(r.id,r.label,r.classes,r.props),`{`].join(` `)),o(r.id,t+` `),n.push(t+`}`))};o(void 0,``),this.edges.length&&n.push(``);for(let e of this.edges){let t=[e.label?/[()[\]{}]/.test(e.label)?W(e.label):sf(e.label):``,e.props.length?`[${e.props.join(`, `)}]`:``].filter(Boolean).join(` `);n.push(`${e.from} ${e.arrow} ${e.to}${t?`: `+t:``}`)}return this.layout.length&&n.push(``,`layout {`,...this.layout.map(e=>` `+e),`}`),n}};function s0(e,t,n,r){let i=[e];return t!==void 0&&t!==e&&i.push(W(t)),i.push(...[...new Set(n)].map(e=>`.${e}`)),r.length&&i.push(`[${r.join(`, `)}]`),i}function c0(e,t){let n=s0(e.id,e.label,e.classes,e.props);return e.body.length?((e.label===void 0||e.label===e.id)&&n.splice(1,0,W(e.label??e.id)),[`${t}${n.join(` `)} {`,...e.body.map(e=>`${t} ${e}`),`${t}}`]):[t+n.join(` `)]}function l0(e){let t=[];for(let n of e){let e=t.at(-1);if(e&&u0(e.text)){let t=(e.text.match(/"/g)??[]).length%2==1;e.text+=(t?`
|
|
37
|
+
`:` `)+n.text}else t.push({...n})}return t}function u0(e){if((e.match(/"/g)??[]).length%2==1)return!0;let t=e.indexOf(`@{`);if(t<0)return!1;let n=e.slice(t).replace(/"[^"]*"/g,``);return(n.match(/\{/g)??[]).length>(n.match(/\}/g)??[]).length}function d0(e){let t=new Map,n=``,r=!1,i=0,a=()=>{let e=n.trim().match(/^([\w-]+)\s*:\s*(.*)$/s);e&&t.set(e[1],G(e[2])),n=``};for(let t of e)t===`"`?r=!r:!r&&`[{`.includes(t)?i++:!r&&`]}`.includes(t)&&i--,!r&&i===0&&(t===`,`||t===`
|
|
38
|
+
`)?a():n+=t;return a(),t}var f0={cloud:`☁️`,database:`🗄️`,disk:`💾`,internet:`🌐`,server:`🖥️`},p0={L:{side:`left`,place:`left-of`},R:{side:`right`,place:`right-of`},T:{side:`top`,place:`above`},B:{side:`bottom`,place:`below`}},m0=/^(group|service|junction)\s+([\w-]+)\s*(?:\(([^)]*)\))?\s*(?:\[([^\]]*)\])?\s*(?:in\s+([\w-]+))?$/,h0=/^([\w-]+)(\{group\})?\s*:\s*([LRTB])\s*(<?)--(>?)\s*([LRTB])\s*:\s*([\w-]+)(\{group\})?$/,g0=/^align\s+(row|column)\s+(.+)$/,_0=(e,t)=>{let n=new o0;n.settings.push(`direction: right`),t.title&&n.settings.unshift(`title: ${JSON.stringify(t.title)}`);let r=(e,n)=>{if(!e)return;let r=f0[e.trim()];return r||t.warnOnce(`icon:${e}`,n,`icon "${e}" has no equivalent and was dropped`),r},i=[],a=[],o=[];Qd({lines:e,index:0},t,e=>{let s=Yd(e.text);if(s!==void 0)return n.settings.unshift(`title: ${JSON.stringify(s)}`),!0;let c=e.text.match(m0);if(c){let[,i,a,o,s,l]=c,u=l?n.id(l):void 0;l&&!n.groups.has(u)&&t.warn(e.line,`group "${l}" is not declared before "${a}"`);let d=r(o,e.line),f=s===void 0?void 0:G(s);if(i===`group`){let e=n.group(a,u);e.label=d?`${d} ${f??a}`:f??a}else if(i===`service`){let e=n.node(a,u);e.label=f??a,d&&e.props.push(`icon: ${d}`)}else{let e=n.node(a,u);e.label=``,e.classes.push(`junction`)}return!0}let l=e.text.match(h0);if(l){let[,n,r,o,s,c,u,d,f]=l,p=p0[o].side,m=p0[u].side,h=s&&c?`<->`:s||c?`->`:`--`,g=h===`--`||h===`<->`?o===`L`||o===`T`:!!s,_=g?[`exit: ${m}`,`enter: ${p}`]:[`exit: ${p}`,`enter: ${m}`];return(g?u===`L`||u===`T`:o===`L`||o===`T`)&&_.push(`constraint: false`),i.push({from:g?d:n,to:g?n:d,arrow:h,props:_,line:e.line}),r||f?t.warnOnce(`group-edge`,e.line,`edges from a {group} end on the service instead of its group`):a.push({a:n,s1:o,b:d,s2:u}),!0}let u=e.text.match(g0);if(u){let e=u[2].split(/[\s,]+/).filter(Boolean).map(e=>n.id(e));return o.push(`align ${u[1]===`row`?`top`:`left`} ${e.join(` `)}`),!0}return!1});for(let e of i)n.edge(v0(n,e.from,e.line,t),v0(n,e.to,e.line,t),e.arrow,void 0,e.props);return y0(n,a),o.length&&n.layout.push(...o),[...n.nodes.values()].some(e=>e.classes.includes(`junction`))&&n.classDefs.push(`.junction [shape: circle, width: 10, height: 10, fill: #94a3b8, stroke: #94a3b8]`),n.emit()};function v0(e,t,n,r){return e.has(t)||(r.warn(n,`"${t}" is not declared; it was added as a service`),e.node(t).label=t),e.id(t)}function y0(e,t){let n=new Set,r=t=>e.nodes.get(e.id(t)),i=()=>{for(let{a:e,s1:i,b:a,s2:o}of t){let t=r(e),s=r(a);if(t&&s&&t!==s){if(n.has(t.id)&&!n.has(s.id)&&t.group===s.group)return s.props.push(`${p0[i].place}: ${t.id}`),n.add(s.id),!0;if(n.has(s.id)&&!n.has(t.id)&&t.group===s.group)return t.props.push(`${p0[o].place}: ${s.id}`),n.add(t.id),!0}}return!1};for(let t of e.nodes.values())if(!n.has(t.id))for(n.add(t.id);i(););}var b0=16,x0=12,S0=80,C0=20,w0={right:`➡`,left:`⬅`,up:`⬆`,down:`⬇`,x:`⬌`,y:`⬍`},T0=[[/^[\w-]+\[\[/,`subroutine`],[/^[\w-]+\(\(\(/,`double circle`],[/^[\w-]+>/,`asymmetric`],[/^[\w-]+\[[/\\].*[/\\]\]/,`trapezoid`]],E0=/^block(?::([\w-]+))?(?::(\d+))?$/,D0=/^space(?::(\d+))?$/,O0=/^([\w-]+)<\[(.*)\]>\(\s*(\w+)(?:\s*,\s*(\w+))?\s*\)(?::(\d+))?$/,k0=/^(.*?[\])}>]|[\w-]+):(\d+)$/,A0=/(^|[\s\])}])(--|==|-\.|~~~)/,j0=(e,t)=>{let n=new o0;t.title&&n.settings.push(`title: ${JSON.stringify(t.title)}`);let r={items:[]},i=[r],a=new Map,o=[],s=0,c=!1,l=(e,r)=>{let a=e=>t.warn(r.line,e),o=i.at(-1),s=e.match(O0);if(s){let[,e,t,r,i,l]=s;i&&a(`block arrow "${e}" points one way only`);let d=w0[r.toLowerCase()];d||a(`block arrow direction "${r}" is not known`),c=!0;let f=n.node(e,o.id);f.label=[d,G(t)].filter(Boolean).join(` `),f.classes.push(`arrow`),u(o,e,f.label,Number(l??1));return}let l=e.match(k0),d=l?l[1]:e,f=l?Number(l[2]):1;for(let[e,n]of T0)e.test(d)&&t.warnOnce(`block-shape:${n}`,r.line,`the ${n} shape is drawn as the nearest yuhwa shape`);let p=new j1(d,e=>n.id(e),a).read()?.nodes[0];if(!p)return;let m=d.match(/^[\w-]+/)?.[0]??p.id,h=n.node(m,o.id);h.label=p.label??h.label??m,p.shape&&h.props.push(`shape: ${p.shape}`),h.classes.push(...p.classes),u(o,m,h.label,f)},u=(e,t,r,i)=>{let o=n.id(t);if(a.get(o))return;let s=r.split(`
|
|
39
|
+
`),c=Math.max(...s.map(e=>e.length))*7.5+32,l={kind:`node`,id:o,span:i,lines:s.length,width:c};a.set(o,l),e.items.push(l)};Qd({lines:e,index:0},t,e=>{let r=e.text.replace(/;$/,``);if(n.styling(e,t))return!0;let a=r.match(/^columns\s+(\d+|auto)$/);if(a)return i.at(-1).columns=a[1]===`auto`?void 0:Math.max(1,Number(a[1])),!0;if(ef.test(r))return t.warnOnce(`block-direction`,e.line,`direction has no effect on a block diagram and was skipped`),!0;if(A0.test(r.replace(/"[^"]*"/g,`""`)))return o.push(e),!0;for(let a of N0(r)){if(a===`end`){i.length>1?i.pop():t.warn(e.line,`unmatched "end" was skipped`);continue}let r=a.match(E0);if(r){let e=i.at(-1),t=r[1]??`block${++s}`,a=n.group(t,e.id);a.label=``,a.props.push(`padding: ${x0}`);let o={id:a.id,items:[]};e.items.push({kind:`block`,block:o,span:Number(r[2]??1)}),i.push(o);continue}let o=a.match(D0);o?i.at(-1).items.push({kind:`space`,span:Number(o[1]??1)}):l(a,e)}return!0}),i.length>1&&t.warn(e.at(-1)?.line??1,`a block was not closed with "end"`);for(let e of o){let i=new j1(e.text.replace(/;$/,``),e=>n.id(e),n=>t.warn(e.line,n)).read();if(i){for(let o of i.nodes)if(!a.has(o.id)&&!n.groups.has(o.id)){t.warn(e.line,`"${o.id}" is not in a block; it was added at the end`);let i=n.node(o.id);i.label=o.label??o.id,u(r,o.id,i.label,1)}for(let r of i.edges){let i=M0(n,r.from,e,t),a=M0(n,r.to,e,t);i&&a&&n.edge(i,a,r.arrow,r.label,r.props)}}}c&&(t.warnOnce(`block-arrow`,1,`block arrows are drawn as an arrow sign next to their label`),n.classDefs.push(`.arrow [shape: text, font-size: 18]`));let d=F0(r),f=P0(r);return I0(r,0,0,f*d+(f-1)*b0,n.layout),n.emit()};function M0(e,t,n,r){if(e.nodes.has(t))return t;if(e.groups.has(t)){r.warnOnce(`block-edge`,n.line,`edges to a nested block end on its first node`);let i=t=>[...e.nodes.values()].find(e=>e.group===t)?.id??[...e.groups.values()].filter(e=>e.parent===t).map(e=>i(e.id)).find(Boolean),a=i(t);return a||r.warn(n.line,`block "${t}" is empty, so its edge was skipped`),a}}function N0(e){let t=[],n=``,r=0,i=!1;for(let a of e)a===`"`?i=!i:!i&&`[({<`.includes(a)?r++:!i&&`])}>`.includes(a)&&(r=Math.max(0,r-1)),/\s/.test(a)&&!i&&r===0?(n&&t.push(n),n=``):n+=a;return n&&t.push(n),t}var P0=e=>e.columns??Math.max(1,e.items.reduce((e,t)=>e+t.span,0));function F0(e){let t=P0(e),n=S0;for(let r of e.items){let e=Math.min(r.span,t),i=0;if(r.kind===`node`)i=r.width;else if(r.kind===`block`){let e=P0(r.block);i=e*F0(r.block)+(e-1)*b0+24}n=Math.max(n,(i-(e-1)*b0)/e)}return Math.ceil(n)}function I0(e,t,n,r,i){let a=P0(e),o=(r-(a-1)*b0)/a,s=0,c=n,l=0;for(let n of e.items){let e=Math.min(n.span,a);s+e>a&&(c+=l+b0,s=0,l=0);let r=t+s*(o+b0),u=e*o+(e-1)*b0;if(n.kind===`node`){let e=36+n.lines*C0;i.push(`${n.id} at ${L0(r)} ${L0(c)} size ${L0(u)} ${e}`),l=Math.max(l,e)}else if(n.kind===`block`){let e=I0(n.block,r+x0,c+x0+26,u-24,i);l=Math.max(l,e+24+26)}else l=Math.max(l,56);s+=e}return c+l-n}var L0=e=>Math.round(e),R0={Person:{cls:`c4-person`,type:`Person`,tech:!1},System:{cls:`c4-system`,type:`Software System`,tech:!1},Container:{cls:`c4-container`,type:`Container`,tech:!0},Component:{cls:`c4-component`,type:`Component`,tech:!0},Node:{cls:`c4-node`,type:`Node`,tech:!0},Deployment_Node:{cls:`c4-node`,type:`Node`,tech:!0}},z0={Boundary:``,Enterprise_Boundary:`Enterprise`,System_Boundary:`Software System`,Container_Boundary:`Container`},B0={"c4-person":`[shape: person, fill: #08427b, stroke: #073b6f, text: white, sub-color: #dbe7f3, bold, max-width: 220]`,"c4-system":`[fill: #1168bd, stroke: #0b4884, text: white, sub-color: #dbe7f3, bold, max-width: 220]`,"c4-container":`[fill: #438dd5, stroke: #3c7fc0, text: white, sub-color: #e8f0fa, bold, max-width: 220]`,"c4-component":`[fill: #85bbf0, stroke: #78a8d8, text: #0b2a4a, sub-color: #1e3f61, bold, max-width: 220]`,"c4-node":`[fill: white, stroke: #888888, text: #222222, sub-color: #555555, bold, max-width: 220]`,"c4-ext":`[fill: #8a8a8a, stroke: #6b6b6b, text: white, sub-color: #eeeeee]`,"c4-db":`[shape: cylinder]`,"c4-queue":`[shape: pill]`,"c4-boundary":`[dashed, fill: none]`},V0={U:[`top`,`bottom`],Up:[`top`,`bottom`],D:[`bottom`,`top`],Down:[`bottom`,`top`],L:[`left`,`right`],Left:[`left`,`right`],R:[`right`,`left`],Right:[`right`,`left`]},H0=/^([A-Za-z_]+)\s*\((.*)\)\s*(\{)?\s*$/,U0=/^(Person|System|Container|Component|Node|Deployment_Node)(Db|Queue)?(_Ext)?(?:_[LR])?$/,W0=/^(Rel|BiRel|RelIndex|Rel_Back|Rel_(U|Up|D|Down|L|Left|R|Right))$/;function G0(e){let t=[],n=new Map,r=``,i=!1,a=()=>{let e=r.trim();r=``;let i=e.match(/^\$(\w+)\s*=\s*(.*)$/s);i?n.set(i[1],G(i[2])):t.push(G(e))};for(let t of e)t===`"`?(i=!i,r+=t):t===`,`&&!i?a():r+=t;return(r.trim()||t.length)&&a(),{pos:t,named:n}}var K0=e=>(t,n)=>{let r=new o0;r.settings.push(`direction: down`);let i=e||t.some(e=>/^RelIndex\s*\(/.test(e.text));n.title&&r.settings.unshift(`title: ${W(n.title)}`);let a=[],o=0,s=e=>{if(e.text===`}`)return a.length||n.warn(e.line,`unmatched "}" was skipped`),a.pop(),!0;let t=Yd(e.text);if(t!==void 0)return r.settings.unshift(`title: ${W(t)}`),!0;let s=e.text.match(H0);if(!s)return!1;let[,l,u,d]=s,{pos:f,named:p}=G0(u),m=a.at(-1);X0(p,e,n);let h=l.match(U0);if(h&&(!d||h[1]===`Deployment_Node`||h[1]===`Node`)){if(d)return c(l,f,`Node`,m,e);let[,t,i,a]=h,o=R0[t],[s,u=s]=f;if(!s)return n.warn(e.line,`${l} needs an alias`),!0;let p=o.tech?f[2]:void 0,g=o.tech?f[3]:f[2],_=r.node(s,m);_.label=u,_.classes.push(o.cls);for(let[e,t]of[[a,`c4-ext`],[i===`Db`,`c4-db`],[i===`Queue`,`c4-queue`]])e&&_.classes.push(t);let v=`${a?`External `:``}${o.type}`,y=[p?`[${v}: ${p}]`:`[${v}]`,g].filter(Boolean).join(`
|
|
40
|
+
`);return _.props.push(`sub: ${W(y)}`),!0}if(l in z0||l.endsWith(`_Boundary`))return d||n.warn(e.line,`${l} without "{" was read as an empty boundary`),c(l,f,z0[l]??l.replace(/_Boundary$/,``),m,e),d||a.pop(),!0;let g=l.match(W0);if(g){let t=l===`RelIndex`?f.slice(1):f,[a,s]=t,[,,c,u]=t;if(!a||!s)return n.warn(e.line,`${l} needs two elements`),!0;l===`Rel_Back`&&([a,s]=[s,a]);let d=[];u&&d.push(`caption: ${W(`[${u}]`)}`);let p=g[2]?V0[g[2]]:void 0;p&&d.push(`exit: ${p[0]}`,`enter: ${p[1]}`),t[4]&&n.warnOnce(`rel-descr`,e.line,`relationship descriptions are skipped`);let m=c;if(i){o++;let e=l===`RelIndex`&&f[0]?f[0]:String(o);m=m?`${e}: ${m}`:e}return r.edge(Y0(r,a,e,n),Y0(r,s,e,n),l===`BiRel`?`<->`:`->`,m,d),!0}if(l===`UpdateElementStyle`){let t=r.nodes.get(r.id(f[0]??``));if(!t)return n.warn(e.line,`UpdateElementStyle for unknown "${f[0]}" was skipped`),!0;for(let[e,n]of[[`bgColor`,`fill`],[`borderColor`,`stroke`],[`fontColor`,`text`]]){let r=p.get(e);if(r){let e=/^[\w#]+$/.test(r)?r:W(r);t.props.push(`${n}: ${e}`),n===`text`&&t.props.push(`sub-color: ${e}`)}}return!0}return/^(UpdateRelStyle|UpdateLayoutConfig|UpdateBoundaryStyle|Lay_\w+|AddElementTag|AddRelTag)$/.test(l)?(n.warnOnce(`c4:${l}`,e.line,`${l} has no equivalent and was skipped`),!0):!1},c=(e,t,i,o,s)=>{let[c,l=c]=t;if(!c)return n.warn(s.line,`${e} needs an alias`),!0;let u=r.group(c,o),d=t[2]||i;return u.label=d?`${l} [${d}]`:l,u.classes.push(`c4-boundary`),a.push(u.id),!0};return Qd({lines:t,index:0},n,s),a.length&&n.warn(t.at(-1)?.line??1,`a boundary was not closed with "}"`),r.emit(B0,`after`)},q0=K0(!1),J0=K0(!0);function Y0(e,t,n,r){return e.has(t)||(r.warn(n.line,`"${t}" is not declared; it was added as a plain node`),e.node(t).label=t),e.id(t)}function X0(e,t,n){for(let r of e.keys())[`sprite`,`tags`,`link`,`techn`,`descr`,`legendText`,`legendSprite`].includes(r)&&n.warnOnce(`c4-arg:${r}`,t.line,`C4 $${r} has no equivalent and was skipped`)}var Z0={requirement:`Requirement`,functionalrequirement:`Functional Requirement`,interfacerequirement:`Interface Requirement`,performancerequirement:`Performance Requirement`,physicalrequirement:`Physical Requirement`,designconstraint:`Design Constraint`,element:`Element`},Q0={id:`Id`,text:`Text`,risk:`Risk`,verifymethod:`Verification`,type:`Type`,docref:`Doc ref`},$0=new Set([`contains`,`copies`,`derives`,`satisfies`,`verifies`,`refines`,`traces`]),ev=String.raw`("[^"]*"|[^\s{:]+)`,tv=new RegExp(String.raw`^(\w+)\s+${ev}\s*(?::::([\w-]+(?:,[\w-]+)*))?\s*\{$`),nv=/^(\w+)\s*:\s*(.*)$/,rv=new RegExp(String.raw`^${ev}\s*-\s*(\w+)\s*->\s*${ev}$`),iv=new RegExp(String.raw`^${ev}\s*<-\s*(\w+)\s*-\s*${ev}$`),av=(e,t)=>{let n=new o0;n.settings.push(`direction: down`),t.title&&n.settings.unshift(`title: ${W(t.title)}`);let r,i=[];Qd({lines:e,index:0},t,e=>{let a=e.text.replace(/;$/,``);if(r){if(a===`}`)return r=void 0,!0;let n=a.match(nv);if(!n)return!1;let i=Q0[n[1].toLowerCase()];return i||t.warn(e.line,`field "${n[1]}" is not known; it was kept as a line`),r.body.push(`*${i??n[1]}:* ${G(n[2])}`),!0}let o=Yd(a);if(o!==void 0)return n.settings.unshift(`title: ${W(o)}`),!0;let s=a.match(ef);if(s)return n.settings[n.settings.findIndex(e=>e.startsWith(`direction:`))]=`direction: ${$d[s[1].toUpperCase()]}`,!0;let c=a.match(tv);if(c&&Z0[c[1].toLowerCase()]){let e=Z0[c[1].toLowerCase()],t=G(c[2]);return r=n.node(t),r.label=t,r.props.push(`meta: ${W(`«${e}»`)}`),r.classes.push(e===`Element`?`req-element`:`req`),c[3]&&r.classes.push(...c[3].split(`,`)),!0}let l=a.match(rv),u=a.match(iv);if(l||u){let[,t,n,r]=l??u,[a,o]=l?[t,r]:[r,t];return i.push({from:G(a),to:G(o),rel:n.toLowerCase(),line:e.line}),!0}let d=a.match(new RegExp(String.raw`^${ev}:::([\w-]+(?:,[\w-]+)*)$`));if(d){let r=G(d[1]);return n.has(r)?n.node(r).classes.push(...d[2].split(`,`)):t.warn(e.line,`class for unknown "${r}" was skipped`),!0}return n.styling({...e,text:a.replace(/"([^"]*)"/g,(e,t)=>n.id(t))},t)}),r&&t.warn(e.at(-1)?.line??1,`"${r.label}" was not closed with "}"`);for(let e of i){$0.has(e.rel)||t.warn(e.line,`relationship "${e.rel}" is not a Mermaid relationship; it was kept as a label`);for(let r of[e.from,e.to])n.has(r)||(t.warn(e.line,`"${r}" is not declared; it was added as a plain node`),n.node(r).label=r);let r=e.rel===`contains`?[]:[`dashed`];n.edge(n.id(e.from),n.id(e.to),`->`,`«${e.rel}»`,r)}let a=new Set([...n.nodes.values()].flatMap(e=>e.classes));return a.has(`req`)&&n.classDefs.unshift(`.req [fill: #fdf6e3, stroke: #b58900, caps, max-width: 260]`),a.has(`req-element`)&&n.classDefs.unshift(`.req-element [fill: #eef4fb, stroke: #4a78b0, caps, max-width: 260]`),n.emit()},ov=String.raw`[A-Za-z0-9_]+`,sv=String.raw`\(\s*("[^"]*"|[^)]*)\s*\)|\[\s*("[^"]*"|[^\]]*)\s*\]`,cv=String.raw`(${ov}|"[^"]*")(?:${sv})?(?:@\{([^}]*)\})?\s*(?:<<([^>]+)>>)?\s*(?::::([\w-]+(?:,[\w-]+)*))?`,lv=RegExp(`^${cv}$`),uv=RegExp(`^actor\\s+${cv}$`),dv=RegExp(`^systemBoundary\\s+${cv}$`),fv=RegExp(`^(${ov})@\\{(.*)\\}$`,`s`),pv=RegExp(`^note\\s+for\\s+(${ov})\\s+("[^]*")$`),mv=RegExp(`^json\\s+(${ov})@(\\{.*\\})\\s*(?::::([\\w-]+(?:,[\\w-]+)*))?$`,`s`),hv=RegExp(`^(${cv})\\s+(?:(${ov})@)?(\\S.*?)\\s+(${cv})$`),gv={"uc-actor":`[shape: actor, stroke: #475569]`,"uc-case":`[shape: ellipse]`,"uc-rect":`[shape: box]`,"uc-note":`[shape: note]`,"uc-json":`[caps]`,"uc-boundary":`[fill: none]`};function _v(e){let t=e.match(/^\.\.>\s*:\s*(include|extend)$/);if(t)return{arrow:`-->`,label:`«${t[1]}»`,props:[],uml:!0};if(e===`--|>`)return{arrow:`->`,props:[`head: open`],uml:!0};let n={"--o":[`head: dot`],"o--":[`tail: dot`],"--x":[`head: bar`],"x--":[`tail: bar`]};if(n[e])return{arrow:`--`,props:n[e]};if(t=e.match(/^--\s*("[^"]*")\s*(-{2,})>$/),t)return{arrow:`->`,label:G(t[1]),props:vv(t[2].length)};if(t=e.match(/^(<?)(-{2,})(>?)$/),t&&!(t[1]&&t[3]))return{arrow:t[1]||t[3]?`->`:`--`,props:vv(t[2].length),swap:!!t[1]}}var vv=e=>e>2?[`length: ${e-1}`]:[],yv=(e,t)=>{let n=new o0;n.settings.push(`direction: right`),t.title&&n.settings.unshift(`title: ${W(t.title)}`);let r=new Map,i,a=0,o=(e,t)=>{e.classes.includes(t)||e.classes.unshift(t)},s=(e,n,r)=>{for(let[e,i]of d0(n))e===`type`&&i===`package`?t.warnOnce(`uc-package`,r.line,`package boundaries are drawn without their title tab`):e===`type`&&i===`rect`||(e===`type`?t.warnOnce(`uc-type:${i}`,r.line,`actor type "${i}" is drawn as a plain actor`):e===`business`?t.warnOnce(`uc-business`,r.line,`business actors and use cases are drawn as plain ones`):e===`icon`?t.warnOnce(`uc-icon`,r.line,`actor icons have no equivalent and were dropped`):t.warn(r.line,`metadata "${e}" has no equivalent and was skipped`))},c=(e,t,r=!1,a=1)=>{let[c,l,u,d,f,p]=e.slice(a,a+6),m=c.startsWith(`"`),h=m?G(c).replace(/\W/g,`_`):c,g=n.has(h),_=n.node(h,g?void 0:i?.id);g&&i&&!_.group&&(_.group=i.id),r?(_.classes=_.classes.filter(e=>!e.startsWith(`uc-`)),o(_,`uc-actor`)):u===void 0?_.classes.some(e=>e.startsWith(`uc-`))||o(_,`uc-case`):o(_,`uc-rect`);let v=l??u??(m?c:void 0);return v===void 0?_.label??=h:_.label=G(v),d&&s(_,d,t),f&&_.props.push(`sub: ${W(`«${f.trim()}»`)}`),p&&_.classes.push(...p.split(`,`)),_};return Qd({lines:l0(e),index:0},t,e=>{let l=e.text;if(l===`end`)return i||t.warn(e.line,`unmatched "end" was skipped`),i=void 0,!0;let u=Yd(l);if(u!==void 0)return n.settings.unshift(`title: ${W(u)}`),!0;let d=l.match(ef);if(d)return n.settings[n.settings.findIndex(e=>e.startsWith(`direction:`))]=`direction: ${$d[d[1].toUpperCase()]}`,!0;let f=l.match(uv);if(f)return c(f,e,!0),!0;let p=l.match(dv);if(p){i&&t.warn(e.line,`boundaries do not nest; this one was read at the top level`);let[,r,a,c,l,u,d]=p,f=r.startsWith(`"`),m=n.group(f?G(r).replace(/\W/g,`_`):r),h=a??c??(f?r:void 0);return m.label=h===void 0?m.id:G(h),o(m,`uc-boundary`),l&&s(m,l,e),u&&t.warn(e.line,`boundary stereotypes are skipped`),d&&m.classes.push(...d.split(`,`)),i=m,!0}let m=l.match(pv);if(m){let t=`note${++a}`,r=n.node(t);return r.label=G(m[2]),o(r,`uc-note`),n.has(m[1])||c(m[1].match(lv),e),n.edge(t,n.id(m[1]),`--`,void 0,[`dotted`]),!0}let h=l.match(mv);if(h)return bv(n,h,e,t),!0;let g=l.match(fv);if(g){let[,i,a]=g,o=r.get(i);if(o){let e=d0(a);return(e.get(`animate`)??(e.has(`animation`)?`true`:void 0))===`true`&&o.props.push(`animate`),!0}let c=n.groups.get(n.id(i))??(n.has(i)?n.node(i):void 0);return c?(s(c,a,e),!0):(t.warn(e.line,`metadata for unknown "${i}" was skipped`),!0)}let _=l.match(hv),v=_&&_v(_[9]);if(_&&v){i&&t.warn(e.line,`relationships belong at the top level; this one was read there`);let a=i;i=void 0;let o=c(_,e,!1,2),s=c(_,e,!1,11);i=a,v.swap&&([o,s]=[s,o]);let l=n.edge(o.id,s.id,v.arrow,v.label,[...v.props]);return _[8]&&r.set(_[8],l),!0}if(/^(classDef|class|style)\s/.test(l)){let i=l.match(/^style\s+(\S+)/);return i&&r.has(i[1])?(t.warnOnce(`uc-edge-style`,e.line,`styles on edges are skipped`),!0):n.styling(e,t)}let y=l.match(lv);return y?(c(y,e),!0):!1}),i&&t.warn(e.at(-1)?.line??1,`boundary "${i.label}" was not closed with "end"`),n.emit(gv,`before`)};function bv(e,t,n,r){let[,i,a,o]=t,s;try{s=JSON.parse(a)}catch{r.warn(n.line,`json "${i}" is not valid JSON and was skipped`);return}if(!s||typeof s!=`object`||Array.isArray(s)){r.warn(n.line,`json "${i}" must be an object and was skipped`);return}let c=[],l=(e,t)=>{if(e&&typeof e==`object`){let n=Array.isArray(e)?e.map((e,t)=>[`[${t}]`,e]):Object.entries(e);n.length||c.push(`${t} || ${Array.isArray(e)?`[]`:`{}`}`);for(let[r,i]of n)l(i,Array.isArray(e)?`${t}${r}`:t?`${t}.${r}`:r)}else c.push(`${t} || ${typeof e==`string`?e:JSON.stringify(e)}`)};l(s,``);let u=e.node(i);u.label=i,u.classes.push(`uc-json`,...o?o.split(`,`):[]),u.body.push(...c)}var xv={task:`rounded`,tool:`box`,input:`parallelogram`,decision:`diamond`,refdoc:`document`,action:`hexagon`,rect:`box`,rectangle:`box`,rounded:`rounded`,roundedrect:`rounded`,stadium:`pill`,pill:`pill`,circle:`circle`,circ:`circle`,diamond:`diamond`,diam:`diamond`,hex:`hexagon`,hexagon:`hexagon`,cyl:`cylinder`,cylinder:`cylinder`,database:`cylinder`,db:`cylinder`,doc:`document`,document:`document`,"lin-doc":`document`,"lean-r":`parallelogram`,"lean-right":`parallelogram`,subroutine:`box`,subproc:`box`,"fr-rect":`box`,ellipse:`ellipse`,oval:`ellipse`,text:`text`},Sv=new Set([`tool`,`subroutine`,`subproc`,`fr-rect`,`lin-doc`,`refdoc`]),Cv=[`description`,`instruction`,`model`,`params`,`returns`,`value`,`example`,`connectorRef`],wv=String.raw`[\w-]+`,Tv=String.raw`(${wv})(?:\[\s*("[^"]*"|[^\]]*)\s*\])?(?:@\{([^}]*)\})?(?::::([\w-]+(?:,[\w-]+)*))?`,Ev=RegExp(`^${Tv}$`),Dv=new RegExp(String.raw`^flow\s+${Tv}$`),Ov=new RegExp(String.raw`^connector\s+${Tv}$`),kv=/\s*(--\s+(?:"[^"]*"|[^-][^>]*?)\s+-->|-->|-\.-|--x)\s*/g,Av={"af-collapsed":`[dashed]`,"af-connector":`[shape: pill, dashed]`},jv=l({sequenceDiagram:dg,timeline:Hg,gitGraph:bg,pie:Sg,xychart:Eg,journey:Gg,mindmap:Jg,gantt:Vg,quadrantChart:Mg,kanban:e_,stateDiagram:h_,classDiagram:Lh,erDiagram:Yh,packet:S_,treemap:T_,sankey:k_,venn:R_,ishikawa:B_,railroad:X_,wardley:n1,cynefin:o1,radar:f1,treeView:_1,swimlane:q1,eventmodeling:n0,architecture:_0,block:j0,C4Context:q0,C4Container:q0,C4Component:q0,C4Dynamic:J0,C4Deployment:q0,requirementDiagram:av,usecase:yv,agentflow:(e,t)=>{let n=new o0,r=t.header.trim().toUpperCase();n.settings.push(`direction: ${$d[r]??`down`}`),r&&!$d[r]&&t.warn(e[0]?.line??1,`direction "${t.header.trim()}" is not known; down was used`),t.title&&n.settings.unshift(`title: ${W(t.title)}`);let i=[],a=new Map,o=[],s=()=>i.at(-1)?.id,c=(e,n,r)=>{for(let[i,s]of d0(n))if(i===`shape`&&`body`in e){let n=xv[s.toLowerCase()];n?(Sv.has(s.toLowerCase())&&t.warnOnce(`af-shape:${s}`,r.line,`the ${s} shape is drawn as the nearest yuhwa shape`),e.props=e.props.filter(e=>!e.startsWith(`shape:`)),e.props.push(`shape: ${n}`)):t.warn(r.line,`shape "${s}" has no equivalent; it was drawn rounded`)}else if(i===`label`)e.label=s;else if(i!==`labelType`){if(i===`view`)s===`collapsed`&&(t.warnOnce(`af-collapsed`,r.line,`collapsed flows are drawn open, with a dashed frame`),e.classes.push(`af-collapsed`));else if(i===`algorithm`)t.warnOnce(`af-algorithm`,r.line,`per-flow layout algorithms have no equivalent and were skipped`);else if(i===`protocol`||i===`endpoint`)i!==`endpoint`&&e.props.some(e=>e.startsWith(`sub:`))||(e.props=e.props.filter(e=>!e.startsWith(`sub:`)),e.props.push(`sub: ${W(s)}`));else if(Cv.includes(i)){i===`connectorRef`&&`body`in e&&o.push({node:e.id,ref:s,line:r.line});let t=a.get(e.id)??new Map;t.set(i,s),a.set(e.id,t)}else i===`curve`||i===`animate`||i===`animation`?t.warnOnce(`af-edge-meta`,r.line,`edge metadata (curve, animate) is skipped`):t.warnOnce(`af-key:${i}`,r.line,`metadata "${i}" has no equivalent and was skipped`)}},l=(e,t)=>{let[,r,i,a,o]=e,l=!n.has(r),u=n.node(r,l?s():void 0);return l&&(u.label=r),i!==void 0&&(u.label=G(i)),a&&c(u,a,t),o&&u.classes.push(...o.split(`,`)),u};Qd({lines:l0(e),index:0},t,e=>{let r=e.text.replace(/;$/,``);if(r===`end`)return i.length||t.warn(e.line,`unmatched "end" was skipped`),i.pop(),!0;if(r===`global`)return i.push(void 0),!0;let a=Yd(r);if(a!==void 0)return n.settings.unshift(`title: ${W(a)}`),!0;let o=r.match(Dv);if(o){let[,t,r,a,l]=o,u=n.group(t,s());return u.label=r===void 0?t:G(r),a&&c(u,a,e),l&&u.classes.push(...l.split(`,`)),i.push(u),!0}let u=r.match(Ov);if(u)return l(u,e).classes.unshift(`af-connector`),!0;if(/^(classDef|class|style)\s/.test(r))return n.styling(e,t);let d=r.split(kv);if(d.length>=3){let t=[];for(let n=0;n<d.length;n+=2){let r=d[n].match(Ev);if(!r)return!1;t.push(l(r,e))}for(let e=1;e<d.length;e+=2){let r=d[e],[i,a]=[t[(e-1)/2],t[(e+1)/2]];if(r===`-.-`)n.edge(i.id,a.id,`--`,void 0,[`dotted`]);else if(r===`--x`)n.edge(i.id,a.id,`->`,void 0,[`head: bar`,`color: #dc2626`]);else{let e=r.match(/^--\s+(.*?)\s+-->$/)?.[1];n.edge(i.id,a.id,`->`,e===void 0?void 0:G(e))}}return!0}let f=r.match(new RegExp(String.raw`^(${wv})@\{(.*)\}$`,`s`));if(f&&n.groups.has(n.id(f[1])))return c(n.groups.get(n.id(f[1])),f[2],e),!0;let p=r.match(Ev);return p?(l(p,e),!0):!1}),i.length&&t.warn(e.at(-1)?.line??1,`a flow was not closed with "end"`);for(let[e,t]of a){let r=n.nodes.get(e)??n.groups.get(e);if(r){let e=Cv.filter(e=>t.has(e)).map(e=>`${e}: ${t.get(e)}`);r.props.push(`tooltip: ${W(e.join(`
|
|
41
|
+
`))}`)}}a.size&&t.warnOnce(`af-docs`,1,`documentation keys (description, params, …) are kept as tooltips`);for(let e of o){let t=e.ref.split(`.`)[0];n.has(t)&&!/^\w+:\/\//.test(e.ref)&&n.edge(e.node,n.id(t),`--`,void 0,[`dotted`])}return n.emit(Av,`before`)}}),Mv=l({"stateDiagram-v2":`stateDiagram`,"classDiagram-v2":`classDiagram`,"railroad-ebnf":`railroad`,"railroad-abnf":`railroad`,"railroad-peg":`railroad`});function Nv(e){let t=e.replace(/-beta$/,``);return Mv[t]??t}var Pv=/^(zenuml)$/;function Fv(e){for(let t=y1(e);t<e.length;t++){let n=e[t].trim();if(n&&!n.startsWith(`%%`))return t}return-1}function Iv(e){let t=e.split(`
|
|
42
|
+
`),n=Fv(t);if(n<0)return;let r=t[n].trim().match(/^([A-Za-z][\w-]*)(.*)$/);if(!r)return;let[,i,a]=r,o=Nv(i);if((o in jv||Pv.test(o))&&!/^[\w-]/.test(a)&&!(!(o===`pie`&&/^\s*(showData\b|title\b)/.test(a))&&/"/.test(a)||/[{]|->|=>|\.\.>|^\s*[,:.[]/.test(a)))return{type:o,keyword:i,rest:a,index:n}}function Lv(e){let t=e.split(`
|
|
43
|
+
`),n=Fv(t);if(n>=0&&v1.test(t[n]))return!0;let r=Iv(e);return!!r&&r.type in jv}function Rv(e){let t=Iv(e);return t&&!(t.type in jv)?t.keyword:void 0}function zv(e){let t=Iv(e),n=t&&jv[t.type];if(!t||!n)return U1(e);let r=e.split(`
|
|
44
|
+
`),i=[],a=new Set;return{source:n(w1(r,t.index+1),{header:S1(t.rest).trim(),type:t.keyword,title:C1(r),warn:(e,t)=>i.push({line:e,message:t}),warnOnce(e,t,n){a.has(e)||(a.add(e),i.push({line:t,message:n}))}}).join(`
|
|
45
|
+
`).replace(/^\n+/,``)+`
|
|
46
|
+
`,warnings:i}}var Bv=e=>Math.round(e),Vv=e=>e.split(/\r?\n/),Hv=e=>e.includes(`\r
|
|
47
|
+
`)?`\r
|
|
48
|
+
`:`
|
|
49
|
+
`,Uv=(e,t)=>e.join(Hv(t));function Wv(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 ${Bv(r.x)} ${Bv(r.y)}`),r.w!==void 0&&r.h!==void 0&&e.push(`size ${Bv(r.w)} ${Bv(r.h)}`),e.length>1&&t.push(` `+e.join(` `))}for(let n of e.ranks??[])t.push(` rank ${n.join(` `)}`);for(let n of e.aligns??[])t.push(` align ${n.side===`center`?``:n.side+` `}${n.ids.join(` `)}`);for(let[n,r]of Object.entries(e.edges)){let e=[n];r.via?.length&&e.push(`via `+r.via.map(e=>`${Bv(e.x)} ${Bv(e.y)}`).join(` `)),r.ports&&(r.ports[0]!==`auto`||r.ports[1]!==`auto`)&&e.push(`ports ${r.ports[0]} ${r.ports[1]}`),r.label&&(Bv(r.label.x)||Bv(r.label.y))&&e.push(`label ${Bv(r.label.x)} ${Bv(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 ${Bv(r.at.x)} ${Bv(r.at.y)}`);for(let[e,i]of Object.entries(r.parts??{}))(Bv(i.x)||Bv(i.y))&&t.push(` ${n}:${e} ${Bv(i.x)}${Bv(i.y)?` ${Bv(i.y)}`:``}`)}return t.length?`layout {\n${t.join(`
|
|
50
|
+
`)}\n}`:``}function Gv(e,t,n=xp(e)){let r=Wv(t),i=Vv(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(`
|
|
51
|
+
`):[]),Uv(i,e)}if(!r)return e;let a=e.replace(/\s*$/,``),o=Hv(e);return a+o+o+r.split(`
|
|
52
|
+
`).join(o)+o}function Kv(e,t,n,r,i){let a=e[t.line],o={},s=t.insertAt,c=t.insertAt;t.props&&([s,c]=t.props,o=V(a.slice(s+1,a[c-1]===`]`?c-1:c))),i===null?delete o[r]:o[r]=i;let l=Gr(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 qv=(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 Jv(e,t,n,r){let i=n.layoutBlock?n.layoutBlock[0]:t.length;n.layoutBlock&&i>1&&!t[i-1].trim()&&t[i-2].trim()&&i--;let a=n.layoutBlock&&i>0&&t[i-1].trim()&&t[i].trim()?[...r,``]:r;return!n.layoutBlock&&t[t.length-1]===``?t.splice(t.length-1,0,...a):t.splice(i,0,...a),Uv(t,e)}var Yv=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Xv=e=>e===e.trim()&&!/["'[\]{}\n\t]|(^|\s)\/\/|(^|\s)\.[\p{L}_]|^#/u.test(e);function Zv(e,t,n,r=xp(e)){let i=qv(r,t);if(!i)return e;let a=Vv(e),o=i.labelRef;if(!o)return t.kind===`node`&&n&&!i.ref?Jv(e,a,r,[`${t.id} ${Yv(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+$/,``),Uv(a,e)}let l=!!o.range&&/^["']/.test(s.slice(o.range[0])),u=(o.id?o.id+` `:``)+(c&&!l&&Xv(n)?n:Yv(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),Uv(a,e)}var Qv={style:[`dashed`,`dotted`],"border-style":[`dashed`,`dotted`]};function $v(e,t,n,r,i=xp(e)){n=Rr(n);let a=qv(i,t);if(!a)return e;let o=ey(e,t,n,r,i,a);for(let e of(Qv[n]??[]).filter(e=>e in a.props))o=$v(o,t,e,null);return o}function ey(e,t,n,r,i,a){let o=Vv(e),s=a.ref?.generated?void 0:a.ref;if(!s)return r===null||t.kind===`panel`?e:Jv(e,o,i,[`${t.id} [${Gr({[n]:r})}]`]);let c=s.propLines;if(c){let i=s.props?V(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]]=`${ay(o[c[n]])}${n}: ${Kr(r)}`,n in i&&Kv(o,s,t.kind,n,null),Uv(o,e);if(r!==null&&!(n in i)){let t=Math.max(...Object.values(c));return o.splice(t+1,0,`${ay(o[t])}${n}: ${Kr(r)}`),Uv(o,e)}}return Kv(o,s,t.kind,n,r),Uv(o,e)}function ty(e,t,n){let r=Vv(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 Fr(Pr(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}`,Uv(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}`),Uv(r,e)}function ny(e,t,n,r=xp(e)){let i,a=iy(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 ry(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 Gv(e,t.layout,t);let[o,s]=i.lines,c=Vv(e),l=c.slice(o+1,s),u=l.map(e=>e.slice(0,Pr(e).codeEnd)),d=u.findIndex(e=>e.trim());if(d<0)return Gv(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 Gv(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 Uv(c,e)}function iy(e,t,n,r){let i=n.panels.find(e=>e.id===t),a=i&&Cr.get(i.kind);if(!i?.lines||!a||i.failed||i.ref?.generated)return e;let[o,s]=i.lines;if(s-o-1!==i.body.length)return e;let c=r(a,i);if(!c)return e;let l=Vv(e),u=oy(l,o,s);return l.splice(o+1,s-o-1,...c.map(e=>e.trim()?u+e:``)),Uv(l,e)}var ay=e=>e.match(/^\s*/)[0];function oy(e,t,n){let r=e.slice(t+1,n).filter(e=>e.trim());return r.length?r.map(ay).reduce((e,t)=>t.length<e.length?t:e):ay(e[t])+` `}function sy(e,t,n=xp(e)){let{from:r,to:i}=t;return n.edges.some(e=>e.from===r&&e.to===i)?e:Jv(e,Vv(e),n,[`${r} -> ${i}`])}function cy(e,t,n=xp(e)){let{id:r,label:i,from:a,group:o}=t,s=r+(i?` `+Yv(i):``),c=a?`${a} -> ${r}`:null,l=Vv(e),u=o?n.groups.get(o)?.ref:void 0;if(u&&!u.generated&&u.end!==void 0&&u.end>u.line){let t=oy(l,u.line,u.end),i=c&&n.nodes.get(a)?.group===o;l.splice(u.end,0,t+s,...i?[t+c]:[]);let d=Uv(l,e);return a&&!i?sy(d,{from:a,to:r}):d}return Jv(e,l,n,c?[s,c]:[s])}function ly(e,t,n=new Map){let r=new Set;for(let[e,n]of t)for(let t=e;t<=n;t++)r.add(t);let i=[];return e.forEach((e,t)=>{let a=n.get(t);a?i.push(...a):r.has(t)||(e.trim()||!r.has(t-1)||i.length&&i[i.length-1].trim())&&i.push(e)}),i}function uy(e,t){return e.aligns?.some(e=>e.ids.includes(t))?(e.aligns=e.aligns.map(e=>({...e,ids:e.ids.filter(e=>e!==t)})).filter(e=>e.ids.length>1),!0):!1}function dy(e,t,n=xp(e)){let r=Vv(e),i=[],a=new Map,o=e=>{for(let t of Object.values(e.propLines??{}))i.push([t,t])},s=(e,t)=>n.edges.some(n=>n.ref?.line===e&&!t(n)),c=(e,t)=>[...n.nodes.values(),...n.groups.values(),...n.edges].some(n=>n!==t&&n.ref?.line===e),l=t=>{let n=Uv(ly(r,i,a),e),o=xp(n),s=structuredClone(o.layout);return t(s)&&(n=Gv(n,s,o)),n};switch(t.kind){case`edge`:{let r=n.edges.find(e=>e.key===t.id);return!r?.ref||r.ref.generated||c(r.ref.line,r)?e:(i.push([r.ref.line,r.ref.line]),o(r.ref),l(e=>!!e.edges[r.key]&&delete e.edges[r.key]))}case`node`:{let u=n.nodes.get(t.id);if(!u)return e;let d=e=>e.from===u.id||e.to===u.id,f=new Set;for(let t of n.edges.filter(d)){if(!t.ref||t.ref.generated)return e;f.add(t.ref.line),o(t.ref)}for(let t of f){if(s(t,d))return e;i.push([t,t])}if(u.ref&&!f.has(u.ref.line)){let t=u.ref.line;if(u.ref.generated||c(t,u))return e;i.push(u.bodyLines?[t,Math.max(t,u.bodyLines[1])]:[t,t]),o(u.ref)}let p=xp(Uv(ly(r,i),e));if(p.nodes.has(u.id))return e;for(let e of f){let t=n.edges.filter(t=>t.ref?.line===e).flatMap(e=>[e.from,e.to]).filter((e,t,n)=>e!==u.id&&!p.nodes.has(e)&&n.indexOf(e)===t);t.length&&a.set(e,t.map(t=>ay(r[e])+t))}return l(e=>{let t=u.id in e.nodes;delete e.nodes[u.id];for(let r of n.edges)d(r)&&e.edges[r.key]&&(t=delete e.edges[r.key]);return e.ranks?.some(e=>e.includes(u.id))&&(e.ranks=e.ranks.map(e=>e.filter(e=>e!==u.id)).filter(e=>e.length>1),t=!0),uy(e,u.id)||t})}case`group`:{let s=n.groups.get(t.id),u=s?.ref;if(!u||u.generated||u.end===void 0||u.end<=u.line||c(u.line,s))return e;let d=r.slice(u.line+1,u.end),f=Math.max(0,oy(r,u.line,u.end).length-ay(r[u.line]).length);return d.forEach((e,t)=>{let n=Math.min(f,ay(e).length);n&&a.set(u.line+1+t,[e.slice(n)])}),i.push([u.line,u.line],[u.end,u.end]),o(u),l(e=>uy(e,s.id))}case`panel`:{let r=n.panels.find(e=>e.id===t.id);return!r?.lines||r.ref?.generated?e:(i.push(r.lines),l(e=>!!e.panels?.[r.id]&&delete e.panels[r.id]))}}}function fy(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 py=e=>e.replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t))).replace(/&#x([\da-f]+);/gi,(e,t)=>String.fromCodePoint(parseInt(t,16))).replace(/&/g,`&`);function my(e,t){return[...e.matchAll(RegExp(`${t}(?:="([^"]*)"|\\s*:\\s*([^;"}]+))`,`g`))].map(e=>py(e[1]??e[2]).trim())}function hy(e){let t=new Set;for(let n of my(e,`font-family`))for(let e of n.split(`,`))t.add(H(e).toLowerCase());return t}var gy={normal:400,bold:700};function _y(e,t=hy(e)){let n=new Set,r=e.replace(/<style\b[^>]*>[\s\S]*?<\/style>/g,``).match(/>[^<]+</g)??[];for(let e of r)for(let t of py(e.slice(1,-1)))n.add(t.codePointAt(0));let i=new Set([400]);for(let t of my(e,`font-weight`)){let e=gy[t]??Number(t);e>0&&i.add(e)}return{families:t,chars:n,weights:i,italic:my(e,`font-style`).some(e=>/^(?:italic|oblique)/.test(e))}}function vy(e){let[t,n=t]=(e??`normal`).trim().split(/\s+/).map(e=>gy[e]??(Number(e)||400));return[t,n]}function yy(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 by(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)yy(e,vy(n.weight))<yy(e,vy(t.weight))&&(t=n);i.add(t)}}return e.filter(e=>i.has(e))}function xy(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 Sy(e,t){let n=e.match(/url\(\s*(['"]?)(.*?)\1\s*\)/);if(n)try{return new URL(n[2],t).href}catch{return}}function Cy(e,t){let n=Sy(e(`src`),t),r=H(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 wy(e,t){let n=[];for(let r of e.matchAll(/@font-face\s*\{([^}]*)\}/g)){let e=r[1],i=Cy(t=>e.match(RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`,`i`))?.[1]??``,t);i&&n.push(i)}return n}var Ty=32;function Ey(e,t,n){let r=e.get(t);return r||(e.set(t,r=n()),e.size>Ty&&e.delete(e.keys().next().value),r)}var Dy=new Map,Oy;function ky(){return Oy??=Ay().finally(()=>Oy=void 0)}async function Ay(){if(typeof document>`u`)return[];let e=[],t=[],n=(t,i)=>{for(let a of Array.from(t))if(a instanceof CSSFontFaceRule){let t=Cy(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(Ey(Dy,n,()=>fetch(n).then(e=>e.ok?e.text():``).then(e=>wy(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 jy(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 My=new Map;function Ny(e){return e.startsWith(`data:`)?Promise.resolve(e):Ey(My,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,${jy(new Uint8Array(t))}`).catch(()=>void 0))}var Py=e=>`"${e.replace(/["\\<>]/g,``)}"`,Fy=e=>e.replace(/[;{}<>"\\]/g,``);async function Iy(e,t=`page`){let n=_y(e),r=by((t===`page`?await ky():t).filter(e=>n.families.has(e.family.toLowerCase())&&xy(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]=[vy(t.weight),vy(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 Ny(e.url);return t?`@font-face{font-family:${Py(e.family)};src:url(${t});`+(e.weight?`font-weight:${Fy(e.weight)};`:``)+(e.style?`font-style:${Fy(e.style)};`:``)+(e.unicodeRange?`unicode-range:${Fy(e.unicodeRange)};`:``)+`}`:``}))).join(``);return a?e.replace(/<svg\b[^>]*>/,e=>`${e}<style>${a}</style>`):e}async function Ly(e,t){let n=typeof document>`u`?void 0:document.fonts;if(!n)return!1;let{families:r,chars:i,weights:a,italic:o}=_y(e,t),s=String.fromCodePoint(...i)||`a`,c=[];for(let e of r)for(let t of a)for(let n of o?[`normal`,`italic`]:[`normal`])c.push(`${n} ${t} 16px ${Py(e)}`);let l=c.filter(e=>{try{return!n.check(e,s)}catch{return!1}});return l.length?(await Promise.all(l.map(e=>n.load(e,s).catch(()=>[])))).some(e=>e.length>0):!1}async function Ry(e,t={}){let{width:n,height:r}=fy(e),i=t.scale??(typeof devicePixelRatio==`number`&&devicePixelRatio>0?devicePixelRatio:1),a=t.fonts??`page`,o=a===!1?e:await Iy(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 zy(e){if(typeof e!=`string`||/^\s*\{/.test(e)){let t=ah(e);return{source:t.source,format:`json`,diagnostics:t.errors.map(e=>({line:1,message:e,severity:`error`,code:`convert`}))}}let t=Rv(e);if(t)return{source:``,format:`mermaid`,diagnostics:[{line:1,severity:`error`,code:`unsupported-diagram`,message:`Mermaid "${t}" is not supported; yuhwa has no equivalent for it`}]};if(Lv(e)){let t=zv(e);return{source:t.source,format:`mermaid`,diagnostics:t.warnings.map(e=>({...e,message:`mermaid: ${e.message}`,severity:`warning`,code:`convert`}))}}return{source:e,format:`yuhwa`,diagnostics:[]}}var By=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}},Vy=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}}}},Hy=[{name:`Everything (showcase)`,source:`title: **Shopfront** platform
|
|
53
|
+
subtitle: everything yuhwa can draw, in one file
|
|
54
|
+
direction: right
|
|
55
|
+
theme: paper
|
|
56
|
+
panels: wrap
|
|
57
|
+
panel-gap: 40
|
|
58
|
+
legend: .svc Service | .store Datastore | .ext External | --> async | ..> optional | red Deprecated
|
|
59
|
+
footer: yuhwa showcase | {teal: v1.0} | 2026
|
|
60
|
+
|
|
61
|
+
// variables: replaced in labels, props, settings and panel bodies
|
|
62
|
+
$brand: indigo
|
|
63
|
+
$db: "Postgres 16"
|
|
64
|
+
$warn: rgb(234, 88, 12)
|
|
65
|
+
|
|
66
|
+
// classes, one built on another
|
|
67
|
+
.svc [color: $brand, shape: rounded]
|
|
68
|
+
.store [amber, cylinder]
|
|
69
|
+
.ext [color: hsl(330 70% 50%), dashed]
|
|
70
|
+
.primary .svc [bold, shadow]
|
|
71
|
+
.async [dashed, flow: true]
|
|
72
|
+
|
|
73
|
+
// a component: one service, its database and the edge between them
|
|
74
|
+
def service(id, label, lang = Go) {
|
|
75
|
+
$id "$label" .svc [sub: $lang]
|
|
76
|
+
\${id}_db "$label DB" .store
|
|
77
|
+
$id -> \${id}_db: SQL
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// nodes: every shape, sub lines, icons, links and tooltips
|
|
81
|
+
user "Customer" [shape: circle, purple, icon: 🙂]
|
|
82
|
+
admin "Admin" [ellipse, #0ea5e9]
|
|
83
|
+
web "Storefront" [frame: browser shop.example.com] {
|
|
84
|
+
**Cart** || 3 items
|
|
85
|
+
---
|
|
86
|
+
progress: 72% checkout funnel
|
|
87
|
+
spark: 3 5 4 6 8 7 9
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
group edge "Edge" [color: slate, dashed] {
|
|
91
|
+
cdn "CDN" [hexagon, teal, link: https://example.com, tooltip: cached at 40 PoPs]
|
|
92
|
+
waf "WAF" [parallelogram, color: tomato]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
group core "Core services" [color: #4f46e5] {
|
|
96
|
+
gateway "API Gateway" .svc .primary [sub: "auth, rate limit"]
|
|
97
|
+
service(orders, Orders, Kotlin)
|
|
98
|
+
service(payments, Payments, lang: Rust)
|
|
99
|
+
group search "Search" [teal] {
|
|
100
|
+
indexer "Indexer" .svc
|
|
101
|
+
es "Elasticsearch" .store [color: $warn]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
queue "Event bus" [diamond, lime]
|
|
106
|
+
stripe "Stripe" .ext [document]
|
|
107
|
+
legacy "Legacy ERP" [box, red, opacity: 0.7]
|
|
108
|
+
note "nightly sync,\\nbest effort" [note, yellow-100]
|
|
109
|
+
|
|
110
|
+
metrics "metrics" [meta: live, caps: true] {
|
|
111
|
+
stat: 99.98% uptime | 41ms p50
|
|
112
|
+
bars: 3 5 4 6 8 9 7
|
|
113
|
+
| service | p95 |
|
|
114
|
+
|----------|--------|
|
|
115
|
+
| orders | 120 ms |
|
|
116
|
+
| payments | 88 ms |
|
|
117
|
+
✓ health || [[green: ok]]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// edges: every arrow, labels, captions and edge props
|
|
121
|
+
user -> web: browse
|
|
122
|
+
web -> cdn: assets [label-bg: lightyellow, curve: straight]
|
|
123
|
+
admin => cdn: purge [color: $brand, width: 3]
|
|
124
|
+
cdn -> waf -> gateway
|
|
125
|
+
gateway -> orders, payments
|
|
126
|
+
gateway <-> indexer: query [curve: orthogonal]
|
|
127
|
+
orders --> queue: OrderPlaced .async
|
|
128
|
+
queue ..> indexer: reindex [caption: within 2 s]
|
|
129
|
+
payments -> stripe: charge [head: dot, color: #db2777]
|
|
130
|
+
indexer -- es
|
|
131
|
+
queue -> legacy: export [dotted, red]
|
|
132
|
+
legacy .. note
|
|
133
|
+
stripe == metrics
|
|
134
|
+
|
|
135
|
+
// panels, in reading order: how it works, how it runs, what comes next
|
|
136
|
+
sequence login "Sign in" [numbered, lifeline-style: dotted] {
|
|
137
|
+
actor user "Customer" [purple]
|
|
138
|
+
participant web, db
|
|
139
|
+
participant api "API" [indigo]
|
|
140
|
+
user -> web: open /login
|
|
141
|
+
web -> api: POST /login
|
|
142
|
+
api -> db: find user
|
|
143
|
+
db --> api: row [width: 2]
|
|
144
|
+
api -> db: audit [red, dotted, head: open]
|
|
145
|
+
note api: checks the hash [amber]
|
|
146
|
+
--- session ---
|
|
147
|
+
api --> web: 200 + cookie [green]
|
|
148
|
+
web -> web: render
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
chart p95 "Latency p95" [type: column, unit: ms] {
|
|
152
|
+
checkout: 120
|
|
153
|
+
search [green]: 48
|
|
154
|
+
payments [hsl(330 70% 50%)]: 88
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
chart traffic "Traffic by region" [type: donut, unit: %, theme: midnight, shadow] {
|
|
158
|
+
EU: 46
|
|
159
|
+
US [indigo]: 31
|
|
160
|
+
APAC: 23
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
quadrant prio "Priorities" [background: lightyellow, border: orange, border-style: dashed, radius: 6] {
|
|
164
|
+
x-axis Low effort -> High effort
|
|
165
|
+
y-axis Low value -> High value
|
|
166
|
+
q1 [green]: Quick wins
|
|
167
|
+
q2: Big bets
|
|
168
|
+
q3: Fill-ins
|
|
169
|
+
q4 [red]: Money pit
|
|
170
|
+
Search [teal]: 0.25, 0.8
|
|
171
|
+
Billing: 0.7, 0.65
|
|
172
|
+
Exports [color: tomato]: 0.3, 0.3
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// three looks for a gantt: a label column, names on solid bars, thin lines
|
|
176
|
+
gantt plan "Q1 plan" [today: 2026-01-20, weekends: show] {
|
|
177
|
+
--- Design [violet] ---
|
|
178
|
+
research "User research" [progress: 100%]: 2026-01-05, 5d
|
|
179
|
+
wireframes [done]: after research, 4d
|
|
180
|
+
review [milestone]: after wireframes
|
|
181
|
+
--- Build [teal] ---
|
|
182
|
+
api "Build API" [active, progress: 40%, owner: ana]: 2026-01-14, 2w
|
|
183
|
+
ui [crit, owner: kim]: after wireframes api, 10d
|
|
184
|
+
launch [milestone, red]: after ui
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
gantt release "Release 2.0" [theme: midnight, today: 2026-02-18, bars: solid, labels: bar, notes: dates, density: compact, arrows: curved, summary: hide] {
|
|
188
|
+
--- Beta [sky] ---
|
|
189
|
+
beta "Private beta" [progress: 80%]: 2026-02-02, 2w
|
|
190
|
+
feedback "Feedback round" [active]: after beta, 1w
|
|
191
|
+
--- GA [green] ---
|
|
192
|
+
docs "Docs" [progress: 30%]: 2026-02-16, 10d
|
|
193
|
+
ga "General availability" [milestone]: after feedback docs
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
gantt hiring "Hiring" [bars: thin, labels: bar, rows: plain, grid: none, scale: week, density: loose] {
|
|
197
|
+
sourcing "Sourcing" [blue, progress: 70%]: 2026-01-05, 3w
|
|
198
|
+
interviews "Interviews" [indigo]: after sourcing, 4w
|
|
199
|
+
offers "Offers" [green]: after interviews, 2w
|
|
200
|
+
start "First day" [milestone]: after offers
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
timeline roadmap "Roadmap" [border: 2] {
|
|
204
|
+
2026 Q1: Private beta
|
|
205
|
+
- 40 design partners
|
|
206
|
+
2026 Q2 [green]: **Launch**
|
|
207
|
+
2026 Q3 [#0ea5e9]: Mobile app
|
|
208
|
+
2026 Q4 [color: rgb(234, 88, 12)]: EU region
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
kanban sprint "Sprint 12" {
|
|
212
|
+
Todo [gray]
|
|
213
|
+
- Write docs [owner: ana, priority: high]
|
|
214
|
+
- **Fix** login [red]
|
|
215
|
+
Doing [blue, limit: 2]
|
|
216
|
+
- API v2 [ticket: MER-12]
|
|
217
|
+
needs the new auth flow
|
|
218
|
+
- Search tuning [owner: kim]
|
|
219
|
+
- Billing export
|
|
220
|
+
Done [green]
|
|
221
|
+
- Ship 1.0
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
git release_flow "Release flow" {
|
|
225
|
+
commit "init" [tag: v1.0]
|
|
226
|
+
branch feature/login [pink]
|
|
227
|
+
commit "login form"
|
|
228
|
+
commit "oauth"
|
|
229
|
+
checkout main
|
|
230
|
+
commit "hotfix" [id: fix, highlight, red]
|
|
231
|
+
merge feature/login [tag: v1.1]
|
|
232
|
+
branch release/1.0 from v1.0 [label: "1.0.x", #0ea5e9]
|
|
233
|
+
cherry-pick fix
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// a file tree: rules, compact folders, counts, sizes and git status
|
|
237
|
+
treeview repo "Repo" [sort: folders, chevrons, compact, folder-color: $brand, rows: striped] {
|
|
238
|
+
match *.test.ts [dim]
|
|
239
|
+
match docs/ [collapsed]
|
|
240
|
+
services/
|
|
241
|
+
checkout/
|
|
242
|
+
main.go: entry point
|
|
243
|
+
cart.go [modified, size: 6 KB]
|
|
244
|
+
cart_test.go [added]
|
|
245
|
+
search/
|
|
246
|
+
index/
|
|
247
|
+
query.go [size: 3 KB]
|
|
248
|
+
web/
|
|
249
|
+
app/
|
|
250
|
+
page.tsx [badge: new]
|
|
251
|
+
page.test.ts
|
|
252
|
+
...
|
|
253
|
+
docs/
|
|
254
|
+
intro.md
|
|
255
|
+
api.md
|
|
256
|
+
scripts/
|
|
257
|
+
deploy.sh
|
|
258
|
+
shop.yu [highlight] # this file
|
|
259
|
+
package.json
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
mindmap ideas "Launch plan" [layout: both] {
|
|
263
|
+
**Launch**
|
|
264
|
+
Marketing [pink]
|
|
265
|
+
Blog posts
|
|
266
|
+
Newsletter
|
|
267
|
+
Product
|
|
268
|
+
Beta [#16a34a]
|
|
269
|
+
- Pricing page
|
|
270
|
+
Sales [shape: pill]
|
|
271
|
+
Partners
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// the request header the checkout API speaks: rows of bit fields
|
|
275
|
+
packet frame "Order frame" {
|
|
276
|
+
0-15: Order id
|
|
277
|
+
16-23 [amber]: Status
|
|
278
|
+
24-31: Flags
|
|
279
|
+
+32: Total (cents)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// where the disk goes, squarified
|
|
283
|
+
treemap disk "Storage" [unit: " GB"] {
|
|
284
|
+
Images
|
|
285
|
+
Products: 420
|
|
286
|
+
Banners: 80
|
|
287
|
+
Logs: 160
|
|
288
|
+
Backups: 260
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// where each euro of revenue ends up
|
|
292
|
+
sankey money "Revenue" [unit: " k€"] {
|
|
293
|
+
Orders -> Revenue: 120
|
|
294
|
+
Subscriptions -> Revenue: 40
|
|
295
|
+
Revenue -> Payroll: 70
|
|
296
|
+
Revenue -> Hosting: 25
|
|
297
|
+
Revenue -> Profit: 65
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// who the shop is for
|
|
301
|
+
venn reach "Customers" {
|
|
302
|
+
Mobile: app only
|
|
303
|
+
Web: browser only
|
|
304
|
+
Mobile & Web: **both**
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// why checkouts fail
|
|
308
|
+
ishikawa causes "Abandoned carts" [direction: left] {
|
|
309
|
+
Abandoned carts
|
|
310
|
+
Price
|
|
311
|
+
Shipping cost
|
|
312
|
+
Speed
|
|
313
|
+
Slow payment page
|
|
314
|
+
Trust
|
|
315
|
+
No reviews
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// the coupon code grammar
|
|
319
|
+
railroad coupon "Coupon code" {
|
|
320
|
+
code = letter , letter , { digit } , [ "-" , "VIP" ] ;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// how evolved each part of the stack is
|
|
324
|
+
wardley stack "Value chain" {
|
|
325
|
+
anchor Shopper [0.95, 0.6]
|
|
326
|
+
component Checkout [0.8, 0.45]
|
|
327
|
+
component Payments [0.5, 0.8] (buy)
|
|
328
|
+
component Search [0.55, 0.3] (build)
|
|
329
|
+
Shopper -> Checkout
|
|
330
|
+
Checkout -> Payments
|
|
331
|
+
Checkout -> Search
|
|
332
|
+
evolve Search 0.6
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// which incidents need which kind of response
|
|
336
|
+
cynefin ops "Incidents" {
|
|
337
|
+
complex
|
|
338
|
+
"Conversion drop"
|
|
339
|
+
complicated
|
|
340
|
+
"Slow queries"
|
|
341
|
+
clear
|
|
342
|
+
"Expired certificate"
|
|
343
|
+
chaotic
|
|
344
|
+
"Payments down"
|
|
345
|
+
confusion
|
|
346
|
+
"Unknown alert"
|
|
347
|
+
}
|
|
348
|
+
`},{name:`Multi-file system`,source:`title: Shop platform
|
|
349
|
+
subtitle: three files, one diagram
|
|
350
|
+
legend: .svc Service | .store Datastore | .ext External | --> async
|
|
351
|
+
|
|
352
|
+
// the shared look: only what styles.yu exports
|
|
353
|
+
import { theme, .svc, .store, .ext, .async, $brand } from "./shared/styles.yu"
|
|
354
|
+
accent: $brand
|
|
355
|
+
// the orders group (with its members) and payments, renamed
|
|
356
|
+
import { orders, payments as billing } from "./services.yu"
|
|
357
|
+
// the release history panel
|
|
358
|
+
import "./release.yu"
|
|
359
|
+
|
|
360
|
+
user "Shopper" [circle, purple]
|
|
361
|
+
web "Storefront" .svc
|
|
362
|
+
sub: Next.js
|
|
363
|
+
stripe "Stripe" .ext
|
|
364
|
+
|
|
365
|
+
user -> web: browses [flow]
|
|
366
|
+
web -> orders-api: place order
|
|
367
|
+
orders-api -> billing: charge
|
|
368
|
+
billing -> stripe: API .async
|
|
369
|
+
`,files:{"shared/styles.yu":`// shared classes, imported by every diagram
|
|
370
|
+
// one theme for every file that imports it (a plain theme: line would stay here)
|
|
371
|
+
export theme: pastel
|
|
372
|
+
export $brand: blue
|
|
373
|
+
.svc
|
|
374
|
+
color: $brand
|
|
375
|
+
shape: rounded
|
|
376
|
+
.store [amber, cylinder]
|
|
377
|
+
.ext [slate, dashed]
|
|
378
|
+
.async
|
|
379
|
+
style: dashed
|
|
380
|
+
flow: true
|
|
381
|
+
.internal [red]
|
|
382
|
+
|
|
383
|
+
// .internal stays private to this file
|
|
384
|
+
export .svc, .store, .ext, .async
|
|
385
|
+
`,"services.yu":`import { theme, .svc, .store } from "./shared/styles.yu"
|
|
386
|
+
|
|
387
|
+
// one service: its API, its database and the line between them
|
|
388
|
+
def service(id, label, store, lang = Go) {
|
|
389
|
+
$id "$label" .svc
|
|
390
|
+
sub: $lang
|
|
391
|
+
$store .store
|
|
392
|
+
$id -> $store
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export orders, payments, search
|
|
396
|
+
|
|
397
|
+
group orders "Orders" {
|
|
398
|
+
service(orders-api, "Orders API", orders-db, Kotlin)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
payments "Payments" .svc
|
|
402
|
+
sub: Go
|
|
403
|
+
search "Search" .svc
|
|
404
|
+
`,"release.yu":`git release "Releases" {
|
|
405
|
+
commit "init" [tag: v0.1.0]
|
|
406
|
+
branch feature/cart
|
|
407
|
+
commit "cart model"
|
|
408
|
+
commit "checkout"
|
|
409
|
+
checkout main
|
|
410
|
+
commit "hotfix" [id: hotfix, type: highlight]
|
|
411
|
+
merge feature/cart [tag: v0.2.0]
|
|
412
|
+
branch release/0.2
|
|
413
|
+
cherry-pick hotfix
|
|
414
|
+
}
|
|
415
|
+
`}},{name:`Web app`,source:`title: Web app
|
|
416
|
+
direction: right
|
|
417
|
+
|
|
418
|
+
.svc [blue]
|
|
419
|
+
|
|
420
|
+
user "You" [circle, purple]
|
|
421
|
+
group app "Your app" {
|
|
422
|
+
web "Web app" .svc
|
|
423
|
+
sub: Next.js
|
|
424
|
+
api "API" .svc
|
|
425
|
+
}
|
|
426
|
+
db "Database" [cylinder, amber]
|
|
427
|
+
|
|
428
|
+
user -> web: visits
|
|
429
|
+
flow: true
|
|
430
|
+
web -> api
|
|
431
|
+
api -> db: SQL
|
|
432
|
+
`},{name:`Team ownership`,source:`title: Who owns what
|
|
433
|
+
subtitle: three teams, one request path
|
|
434
|
+
theme: pastel
|
|
435
|
+
|
|
436
|
+
.web [blue]
|
|
437
|
+
.platform [purple]
|
|
438
|
+
.data [green]
|
|
439
|
+
|
|
440
|
+
group web "Web team" .web {
|
|
441
|
+
meta: 5 people
|
|
442
|
+
site "Marketing site" .web
|
|
443
|
+
shop "Shop frontend" .web
|
|
444
|
+
}
|
|
445
|
+
group platform "Platform team" .platform {
|
|
446
|
+
meta: 4 people
|
|
447
|
+
gw "API gateway" .platform
|
|
448
|
+
auth "Auth" .platform
|
|
449
|
+
}
|
|
450
|
+
group data "Data team" .data {
|
|
451
|
+
meta: 3 people
|
|
452
|
+
wh "Warehouse" .data [cylinder]
|
|
453
|
+
bi "Dashboards" .data
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
site, shop -> gw
|
|
457
|
+
gw -> auth
|
|
458
|
+
gw ..> wh: events
|
|
459
|
+
flow: true
|
|
460
|
+
wh -> bi
|
|
461
|
+
`},{name:`Release dashboard`,source:`title: Shop release **v2.4**
|
|
462
|
+
subtitle: what ships on {green: Friday}
|
|
463
|
+
footer: **landfall** v2.4 | \`eu-central-1\` | updated {green: 2 min ago}
|
|
464
|
+
theme: midnight
|
|
465
|
+
|
|
466
|
+
app "Storefront" [frame: browser shop.example.com, blue] {
|
|
467
|
+
stat: 99.9% uptime | 42ms p95 | 1.2k rps
|
|
468
|
+
---
|
|
469
|
+
spark blue: 3 5 4 6 8 7 9 12 10 14
|
|
470
|
+
}
|
|
471
|
+
ci "Pipeline" [frame: terminal ~/shop, meta: 42s] {
|
|
472
|
+
progress green: 72% tests
|
|
473
|
+
progress amber: 9/12 deploys
|
|
474
|
+
bars purple: 3 5 4 8 6 9
|
|
475
|
+
}
|
|
476
|
+
flags "Flags" [frame: window Settings] {
|
|
477
|
+
new-checkout || [[green: on]]
|
|
478
|
+
dark-mode || [[off]]
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
app -> ci: build
|
|
482
|
+
flow: true
|
|
483
|
+
ci -> flags
|
|
484
|
+
`},{name:`Service table`,source:`title: Service status
|
|
485
|
+
theme: terminal
|
|
486
|
+
|
|
487
|
+
api "api" [meta: v3.2, green] {
|
|
488
|
+
| route | p95 | rps |
|
|
489
|
+
|----------|-------|------|
|
|
490
|
+
| /orders | 42ms | 310 |
|
|
491
|
+
| /cart | 18ms | 920 |
|
|
492
|
+
}
|
|
493
|
+
db "postgres" [cylinder, amber]
|
|
494
|
+
|
|
495
|
+
api -> db: pool 20
|
|
496
|
+
`},{name:`Annotated sketch`,source:`theme: mono
|
|
497
|
+
curve: straight
|
|
498
|
+
|
|
499
|
+
a "Input" -> b "Parse" -> c "Layout" -> d "Render" -> e "SVG" [document]
|
|
500
|
+
note "deterministic:\\nsame input, same SVG" [note]
|
|
501
|
+
d -- note
|
|
502
|
+
style: dotted
|
|
503
|
+
constraint: false
|
|
504
|
+
`},{name:`Sign-in story`,source:`title: Sign in
|
|
505
|
+
subtitle: flow, sequence and numbers in one file
|
|
506
|
+
panels: row
|
|
507
|
+
|
|
508
|
+
web "Web" [blue] -> api "API" [blue] -> db "Postgres" [cylinder, amber]
|
|
509
|
+
|
|
510
|
+
sequence login "Sign in" [numbered] {
|
|
511
|
+
actor user "Customer" [purple]
|
|
512
|
+
participant web, api, db
|
|
513
|
+
user -> web: open /login
|
|
514
|
+
web -> api: POST /login
|
|
515
|
+
api -> db: find user
|
|
516
|
+
db --> api: row
|
|
517
|
+
note api: compares the **bcrypt** hash
|
|
518
|
+
api --> web: 200 + cookie
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
chart latency "Latency p95" [unit: ms] {
|
|
522
|
+
checkout: 120
|
|
523
|
+
search [green]: 48
|
|
524
|
+
login: 80
|
|
525
|
+
}
|
|
526
|
+
`},{name:`Git flow`,source:`title: Release flow
|
|
527
|
+
subtitle: trunk-based, short-lived branches
|
|
528
|
+
|
|
529
|
+
git flow "main and feature branches" {
|
|
530
|
+
commit "init" [tag: v0.1.0]
|
|
531
|
+
branch feature/login
|
|
532
|
+
commit "login form"
|
|
533
|
+
commit "oauth provider"
|
|
534
|
+
checkout main
|
|
535
|
+
commit "fix typo"
|
|
536
|
+
branch fix/cache [amber]
|
|
537
|
+
commit "cache headers"
|
|
538
|
+
checkout main
|
|
539
|
+
merge fix/cache [tag: v0.1.1]
|
|
540
|
+
merge feature/login [tag: v0.2.0]
|
|
541
|
+
commit "docs"
|
|
542
|
+
}
|
|
543
|
+
`},{name:`Project structure`,source:`title: Project structure
|
|
544
|
+
subtitle: what lives where, and what this PR touches
|
|
545
|
+
theme: paper
|
|
546
|
+
panels: wrap
|
|
547
|
+
|
|
548
|
+
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] {
|
|
549
|
+
match **/*.test.ts [dim, icon: test]
|
|
550
|
+
match node_modules/ [collapsed]
|
|
551
|
+
match *.{png,svg} [purple]
|
|
552
|
+
apps/
|
|
553
|
+
web/
|
|
554
|
+
src/
|
|
555
|
+
main.ts: boots the app
|
|
556
|
+
router.ts
|
|
557
|
+
pages/
|
|
558
|
+
home.tsx [badge: new]
|
|
559
|
+
checkout.tsx
|
|
560
|
+
...
|
|
561
|
+
public/
|
|
562
|
+
logo.svg
|
|
563
|
+
hero.png
|
|
564
|
+
api/
|
|
565
|
+
src/
|
|
566
|
+
main/
|
|
567
|
+
java/
|
|
568
|
+
com/
|
|
569
|
+
acme/
|
|
570
|
+
App.java: entry point
|
|
571
|
+
OrderController.java
|
|
572
|
+
build.gradle [icon: package]
|
|
573
|
+
packages/
|
|
574
|
+
ui/: shared components
|
|
575
|
+
Button.tsx [size: 2.1 KB]
|
|
576
|
+
Button.test.ts [size: 1.4 KB]
|
|
577
|
+
Card.tsx [size: 3.8 KB]
|
|
578
|
+
config/: lint and tsconfig presets
|
|
579
|
+
eslint.js
|
|
580
|
+
tsconfig.json
|
|
581
|
+
docs/ [collapsed]
|
|
582
|
+
intro.md
|
|
583
|
+
deploy.md
|
|
584
|
+
node_modules/
|
|
585
|
+
react/
|
|
586
|
+
.github/
|
|
587
|
+
workflows/
|
|
588
|
+
ci.yml: lint, test, build
|
|
589
|
+
pnpm-workspace.yaml
|
|
590
|
+
README.md [highlight]
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
treeview pr "feat: dark mode" [sort: folders, marks: letter, highlight-color: amber, line-color: gray, lines: dashed] {
|
|
594
|
+
src/
|
|
595
|
+
theme/
|
|
596
|
+
dark.ts [added, size: +120]
|
|
597
|
+
tokens.ts [modified, size: +8 −3]
|
|
598
|
+
old-colors.ts [deleted, size: −64]
|
|
599
|
+
App.tsx [modified, size: +2 −1]
|
|
600
|
+
tests/
|
|
601
|
+
theme.test.ts [added, size: +40]
|
|
602
|
+
.env [ignored]
|
|
603
|
+
CHANGELOG.md [modified, highlight]
|
|
604
|
+
}
|
|
605
|
+
`},{name:`Product overview`,source:`title: Checkout v2
|
|
606
|
+
subtitle: architecture, plan, branches and numbers in one file
|
|
607
|
+
panels: grid
|
|
608
|
+
|
|
609
|
+
.svc [blue]
|
|
610
|
+
web "Web" .svc -> api "API" .svc -> db "Orders" [cylinder, amber]
|
|
611
|
+
api -> queue "Events" [pill, teal]: publish
|
|
612
|
+
style: dashed
|
|
613
|
+
|
|
614
|
+
timeline plan "Roadmap" {
|
|
615
|
+
Jan: Design
|
|
616
|
+
Feb [blue]: Build
|
|
617
|
+
Mar [green]: **Launch**
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
git branches "Branches" {
|
|
621
|
+
commit "v1" [tag: v1.0]
|
|
622
|
+
branch checkout-v2
|
|
623
|
+
commit "new cart"
|
|
624
|
+
commit "payments"
|
|
625
|
+
checkout main
|
|
626
|
+
merge checkout-v2 [tag: v2.0]
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
chart conv "Conversion" [type: line, unit: %] {
|
|
630
|
+
Jan: 2.1
|
|
631
|
+
Feb: 2.4
|
|
632
|
+
Mar: 3.2
|
|
633
|
+
}
|
|
634
|
+
`}],Uy=[{label:`Sequence diagram`,group:`Panels`,id:`seq`,text:`sequence {id} "Checkout" [numbered] {
|
|
635
|
+
actor user "Customer" [purple]
|
|
636
|
+
participant web, api, db
|
|
637
|
+
user -> web: add to cart
|
|
638
|
+
web -> api: POST /orders
|
|
639
|
+
api -> db: insert order
|
|
640
|
+
db --> api: id
|
|
641
|
+
note api: idempotency key
|
|
642
|
+
api --> web: 201 Created
|
|
643
|
+
}`},{label:`Timeline`,group:`Panels`,id:`plan`,text:`timeline {id} "Roadmap" {
|
|
644
|
+
2026 Q1: Private beta
|
|
645
|
+
- 40 design partners
|
|
646
|
+
2026 Q2 [green]: **Launch**
|
|
647
|
+
2026 Q4 [amber]: EU region
|
|
648
|
+
}`},{label:`Bar chart`,group:`Panels`,id:`chart`,text:`chart {id} "Requests by service" [type: bar] {
|
|
649
|
+
api: 420
|
|
650
|
+
web: 310
|
|
651
|
+
worker [amber]: 95
|
|
652
|
+
}`},{label:`Donut chart`,group:`Panels`,id:`share`,text:`chart {id} "Traffic by region" [type: donut, unit: %] {
|
|
653
|
+
EU: 46
|
|
654
|
+
US: 31
|
|
655
|
+
APAC: 23
|
|
656
|
+
}`},{label:`Line chart`,group:`Panels`,id:`latency`,text:`chart {id} "p95 latency" [type: line, unit: ms] {
|
|
657
|
+
Mon: 120
|
|
658
|
+
Tue: 96
|
|
659
|
+
Wed: 140
|
|
660
|
+
Thu: 88
|
|
661
|
+
Fri: 72
|
|
662
|
+
}`},{label:`Git branches`,group:`Panels`,id:`git`,text:`git {id} "Release flow" {
|
|
663
|
+
commit "init" [tag: v1.0]
|
|
664
|
+
checkout -b feature/login
|
|
665
|
+
commit "login form"
|
|
666
|
+
commit "oauth"
|
|
667
|
+
checkout main
|
|
668
|
+
commit "hotfix" [id: fix, type: highlight, tag: v1.0.1]
|
|
669
|
+
merge feature/login [tag: v1.1]
|
|
670
|
+
branch release/1.0 from v1.0 [label: "1.0.x"]
|
|
671
|
+
cherry-pick fix
|
|
672
|
+
}`},{label:`Mind map`,group:`Panels`,id:`ideas`,text:`mindmap {id} "Launch plan" {
|
|
673
|
+
**Launch**
|
|
674
|
+
Marketing [pink]
|
|
675
|
+
Blog posts
|
|
676
|
+
Newsletter
|
|
677
|
+
Product
|
|
678
|
+
Beta [green]
|
|
679
|
+
Sales
|
|
680
|
+
}`},{label:`File tree`,group:`Panels`,id:`files`,text:`treeview {id} "my-app" [sort: folders, chevrons, compact] {
|
|
681
|
+
match *.test.ts [dim]
|
|
682
|
+
src/
|
|
683
|
+
index.ts: entry point
|
|
684
|
+
components/
|
|
685
|
+
Button.tsx [added]
|
|
686
|
+
Button.test.ts
|
|
687
|
+
util.ts [modified, size: 2 KB]
|
|
688
|
+
docs/ [collapsed]
|
|
689
|
+
intro.md
|
|
690
|
+
package.json
|
|
691
|
+
README.md [highlight]
|
|
692
|
+
}`},{label:`Gantt chart`,group:`Panels`,id:`plan`,text:`gantt {id} "Q1 plan" {
|
|
693
|
+
--- Design ---
|
|
694
|
+
research "User research": 2026-01-05, 5d
|
|
695
|
+
wireframes [blue]: after research, 4d
|
|
696
|
+
--- Build ---
|
|
697
|
+
api "Build API" [green, active]: after wireframes, 2w
|
|
698
|
+
launch [milestone]: after api
|
|
699
|
+
}`},{label:`Quadrant`,group:`Panels`,id:`prio`,text:`quadrant {id} "Priorities" {
|
|
700
|
+
x-axis Low effort -> High effort
|
|
701
|
+
y-axis Low value -> High value
|
|
702
|
+
q1: Quick wins
|
|
703
|
+
q2: Big bets
|
|
704
|
+
q3: Fill-ins
|
|
705
|
+
q4: Money pit
|
|
706
|
+
Search [teal]: 0.25, 0.8
|
|
707
|
+
Billing: 0.7, 0.65
|
|
708
|
+
}`},{label:`Kanban board`,group:`Panels`,id:`board`,text:`kanban {id} "Sprint" {
|
|
709
|
+
Todo [gray]
|
|
710
|
+
- Write docs [owner: ana]
|
|
711
|
+
Doing [blue, limit: 2]
|
|
712
|
+
- API v2 [ticket: MER-12]
|
|
713
|
+
Done [green]
|
|
714
|
+
- Ship 1.0
|
|
715
|
+
}`},{label:`Radar chart`,group:`Panels`,id:`skills`,text:`chart {id} "Team skills" [type: radar, max: 5] {
|
|
716
|
+
axes: Design, Frontend, Backend, Ops, Data
|
|
717
|
+
Alice [blue]: 5, 4, 2, 3, 2
|
|
718
|
+
Bob: 2, 3, 5, 4, 4
|
|
719
|
+
}`},{label:`Packet`,group:`Panels`,id:`udp`,text:`packet {id} "UDP header" {
|
|
720
|
+
0-15: Source port
|
|
721
|
+
16-31: Destination port
|
|
722
|
+
+16: Length
|
|
723
|
+
+16 [amber]: Checksum
|
|
724
|
+
64-95: Data
|
|
725
|
+
}`},{label:`Treemap`,group:`Panels`,id:`disk`,text:`treemap {id} "Disk usage" [unit: " GB"] {
|
|
726
|
+
Code
|
|
727
|
+
src: 120
|
|
728
|
+
tests: 40
|
|
729
|
+
Media
|
|
730
|
+
Photos: 300
|
|
731
|
+
Video: 520
|
|
732
|
+
Other: 30
|
|
733
|
+
}`},{label:`Sankey`,group:`Panels`,id:`flows`,text:`sankey {id} "Flows" {
|
|
734
|
+
Income -> Budget: 100
|
|
735
|
+
Budget -> Rent: 40
|
|
736
|
+
Budget -> Food: 25
|
|
737
|
+
Budget -> Savings: 35
|
|
738
|
+
}`},{label:`Venn`,group:`Panels`,id:`sets`,text:`venn {id} "Overlap" {
|
|
739
|
+
A: only A
|
|
740
|
+
B: only B
|
|
741
|
+
A & B: both
|
|
742
|
+
}`},{label:`Fishbone`,group:`Panels`,id:`why`,text:`ishikawa {id} "Why" {
|
|
743
|
+
Slow checkout
|
|
744
|
+
People
|
|
745
|
+
No on-call owner
|
|
746
|
+
Process
|
|
747
|
+
Manual deploys
|
|
748
|
+
Tools
|
|
749
|
+
Old database driver
|
|
750
|
+
}`},{label:`Railroad`,group:`Panels`,id:`grammar`,text:`railroad {id} "Grammar" {
|
|
751
|
+
number = [ "-" ] , digit , { digit } ;
|
|
752
|
+
digit = "0" | "1" | "2" | "3" ;
|
|
753
|
+
}`},{label:`Wardley map`,group:`Panels`,id:`tea`,text:`wardley {id} "Tea shop" {
|
|
754
|
+
anchor Customer [0.95, 0.63]
|
|
755
|
+
component Cup of Tea [0.79, 0.61]
|
|
756
|
+
component Kettle [0.43, 0.35]
|
|
757
|
+
component Power [0.1, 0.75]
|
|
758
|
+
Customer -> Cup of Tea
|
|
759
|
+
Cup of Tea -> Kettle
|
|
760
|
+
Kettle -> Power
|
|
761
|
+
evolve Kettle 0.62
|
|
762
|
+
}`},{label:`Cynefin`,group:`Panels`,id:`cynefin`,text:`cynefin {id} "Incident response" {
|
|
763
|
+
complex
|
|
764
|
+
"Investigate root cause"
|
|
765
|
+
complicated
|
|
766
|
+
"Analyze performance data"
|
|
767
|
+
clear
|
|
768
|
+
"Restart service"
|
|
769
|
+
chaotic
|
|
770
|
+
"Page on-call"
|
|
771
|
+
confusion
|
|
772
|
+
"Unknown failure mode"
|
|
773
|
+
chaotic --> complex : "Stabilised"
|
|
774
|
+
}`},{label:`Node`,group:`Graph`,id:`node`,text:`{id} "New node" [blue]`},{label:`Group`,group:`Graph`,id:`group`,text:`group {id} "New group" {
|
|
775
|
+
{id}_a "First"
|
|
776
|
+
{id}_b "Second"
|
|
777
|
+
}
|
|
778
|
+
{id}_a -> {id}_b`},{label:`Swimlane`,group:`Graph`,id:`lane`,text:`group {id} "New lane" [lane] {
|
|
779
|
+
{id}_a "First"
|
|
780
|
+
}`},{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) {
|
|
781
|
+
$id "$label" [color: blue, sub: $lang]
|
|
782
|
+
$id-db [shape: cylinder, color: amber]
|
|
783
|
+
$id -> $id-db
|
|
784
|
+
}
|
|
785
|
+
{id}(first, "First")
|
|
786
|
+
{id}(second, "Second", Rust)`},{label:`Card with rows`,group:`Graph`,id:`card`,text:`{id} "orders" [meta: 12k/day, color: amber] {
|
|
787
|
+
| field | type |
|
|
788
|
+
|--------|-------|
|
|
789
|
+
| id | uuid |
|
|
790
|
+
| total | money |
|
|
791
|
+
---
|
|
792
|
+
spark: 3 5 4 8 7 9
|
|
793
|
+
}`}],Wy=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()}},Gy=e=>`file:///`+e.split(`/`).map(encodeURIComponent).join(`/`),Ky=e=>decodeURIComponent(new URL(e).pathname).slice(1);function qy(e,t){let n=0;for(let r=0;r<t.line;r++){let t=e.indexOf(`
|
|
794
|
+
`,n);if(t<0)return e.length;n=t+1}return Math.min(n+t.character,e.length)}function Jy(e,t){let n=e.slice(0,t);return{line:n.split(`
|
|
795
|
+
`).length-1,character:t-(n.lastIndexOf(`
|
|
796
|
+
`)+1)}}function Yy(e,t){let n=t.map(t=>({from:qy(e,t.range.start),to:qy(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 Xy(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 Zy=e=>e.replace(/[&<>]/g,e=>({"&":`&`,"<":`<`,">":`>`})[e]),Qy=e=>Zy(e).replace(/\*\*([^*]+)\*\*/g,`<b>$1</b>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/\n\n/g,`<br>`),$y={3:`ƒ`,6:`n`,7:`c`,9:`p`,10:`k`,12:`v`,14:`⌘`,17:`f`};function e2(e){let{ta:t}=e,n=new Wy(new Worker(new URL(new URL(`lsp.worker-DrpLBfKZ.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=Ky(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(Gy(i),a),r||=i===e.current());for(let e of o.keys())e in t||(o.delete(e),s.delete(e),n.close(Gy(e)));return r}function l(){(c()||j!==e.current())&&(te=new Map,ae(),oe())}async function u(i,a={},o=t.selectionStart){await r,c();let s=Gy(e.current());return n.request(i,{textDocument:{uri:s},position:Jy(t.value,o),...a})}function d(e){let n=qy(t.value,e.start);t.focus(),t.setSelectionRange(n,qy(t.value,e.end));let r=Xy(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=Yy(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(qy(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=$y[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=Xy(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?qy(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=Qy(r);let i=Xy(t,n.range?qy(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[Gy(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=Ky(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,j=``,ne=null,re=0,ie=0;function ae(){k.style.width=t.clientWidth+`px`,k.style.height=t.clientHeight+`px`;let e=``;for(let[n,r]of t.value.split(`
|
|
797
|
+
`).entries()){n&&(e+=`
|
|
798
|
+
`);let t=ne&&n>=ne[0]&&n<=ne[1];t&&(e+=`<span class="src-mark">`);let i=[...ee.get(n)??[],...te.get(n)??[]];if(!i.length)e+=Zy(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=Zy(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 M(e){let t=new Map;for(let n of e){let e=t.get(n.line);e?e.push(n):t.set(n.line,[n])}return t}function oe(){clearTimeout(re),re=window.setTimeout(async()=>{await r,c();let[i,o]=[e.current(),t.value],s=await n.request(`textDocument/semanticTokens/full`,{textDocument:{uri:Gy(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=M(l),j=i,ae()},30)}function se(){clearTimeout(ie),ie=window.setTimeout(async()=>{let e=t.selectionStart,n=t.value,r=e===t.selectionEnd?await u(`textDocument/documentHighlight`):null;if(t.value!==n||t.selectionStart!==e)return;let i=M((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,ae())},120)}t.addEventListener(`input`,()=>{te=new Map,ae(),oe(),se()}),t.addEventListener(`scroll`,()=>k.scrollTop=t.scrollTop),t.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&se()}),new ResizeObserver(()=>ae()).observe(t),ae(),t.addEventListener(`input`,e=>{if(E(),!(e instanceof InputEvent)||e.inputType!==`insertText`)return x();v(!1)}),t.addEventListener(`keydown`,e=>{E();let t=!p.hidden;if(t&&(e.key===`ArrowDown`||e.key===`ArrowUp`))h=(h+(e.key===`ArrowDown`?1:m.length-1))%m.length,b();else if(t&&(e.key===`Enter`||e.key===`Tab`))S(h);else if(t&&e.key===`Escape`)x();else if(e.key===` `&&e.ctrlKey)v(!0);else if(e.key===`F2`)D();else if(e.key===`F12`)O();else{t&&(e.key===`ArrowLeft`||e.key===`ArrowRight`||e.key===`Home`||e.key===`End`)&&x();return}e.preventDefault(),e.stopImmediatePropagation()},!0);let ce=()=>{x(),E()};t.addEventListener(`blur`,ce),t.addEventListener(`scroll`,ce),t.addEventListener(`click`,e=>{x(),E(),se(),e.metaKey||e.ctrlKey?O():w=window.setTimeout(()=>void T(),350)});function le(e,n=!1){if(ne=e,ae(),!e||!n)return;let r=qy(t.value,{line:e[0],character:0}),i=qy(t.value,{line:e[1]+1,character:0}),a=Xy(t,r).top,o=Xy(t,i).top,s=t.getBoundingClientRect();(a<s.top||o>s.bottom)&&(t.scrollTop+=a-s.top-t.clientHeight/3)}return{sync:l,mark:le,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?.[Gy(e.current())];return n?(f(n),!0):!1}}}var t2=` `;function n2(e,t){let n=e.slice(e.lastIndexOf(`
|
|
799
|
+
`,t-1)+1,t),r=n.match(/^[ \t]*/)[0],i=0;for(let e of Fr(Pr(n).tokens))i=Math.max(0,i+(e===`{`?1:-1));return i?r+t2:r}function r2(e,t){let n=1;for(let r=e.lastIndexOf(`
|
|
800
|
+
`,t-1);r>=0;){let t=r>0?e.lastIndexOf(`
|
|
801
|
+
`,r-1)+1:0,i=e.slice(t,e[r-1]===`\r`?r-1:r);for(let e of Fr(Pr(i).tokens).reverse())if(n+=e===`}`?1:-1,!n)return i.match(/^[ \t]*/)[0];r=t-1}return``}function i2(e,t){let n=n2(e,t),r=e.slice(e.lastIndexOf(`
|
|
802
|
+
`,t-1)+1,t);return n+((n===r.match(/^[ \t]*/)[0]?r.match(/^[ \t]*([-*] +)\S/)?.[1]:void 0)??``)}function a2(e,t,n){let r=e.lastIndexOf(`
|
|
803
|
+
`,t-1)+1,i=e.slice(r,t),a=i.match(/^[ \t]*/)[0],o=e.indexOf(`
|
|
804
|
+
`,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=`
|
|
805
|
+
`+i2(e,t);return n2(e,t)!==a&&/^[ \t]*\}/.test(s)?{start:t,end:n,insert:c+`
|
|
806
|
+
`+a,caret:t+c.length}:{start:t,end:n,insert:c}}function o2(e,t,n,r=!1){let i=e.lastIndexOf(`
|
|
807
|
+
`,t-1)+1,a=n>t&&e[n-1]===`
|
|
808
|
+
`?n-1:n,o=e.indexOf(`
|
|
809
|
+
`,a),s=o<0?e.length:o,c=e.slice(i,s).split(`
|
|
810
|
+
`),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?t2+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(`
|
|
811
|
+
`)+e.slice(s),from:f(t,t<n),to:f(n,!1)}}var s2=class{diagram;L;snap;constructor(e,t,n){this.diagram=e,this.L=t,this.snap=n}pinAll(){for(let e of this.L.nodes.values()){let t=this.diagram.layout.nodes[e.id]??={};(t.x===void 0||t.y===void 0)&&(t.x=Math.round(e.x),t.y=Math.round(e.y))}}edgeOverride(e){return this.diagram.layout.edges[e]??={}}nearestSide(e,t){let n=this.L.nodes.get(e),r=(t.x-(n.x+n.w/2))/(n.w/2),i=(t.y-(n.y+n.h/2))/(n.h/2);return Math.abs(r)>Math.abs(i)?r>0?`right`:`left`:i>0?`bottom`:`top`}pinned(e,t){t&&this.pinAll();let n=t?this.L.nodes.get(e):this.L.panels.find(t=>t.decl.id===e).box,r=t?this.diagram.layout.nodes[e]??={}:((this.diagram.layout.panels??={})[e]??={}).at??={x:n.x,y:n.y};return r.x??=n.x,r.y??=n.y,{o:r,w:n.w,h:n.h}}centre(e,t){let{o:n,w:r,h:i}=this.pinned(e,t),a=n.x+r/2,o=n.y+i/2;return(e,t,s)=>{n.x=Math.round(this.snap(a+t.x,s)-r/2),n.y=Math.round(this.snap(o+t.y,s)-i/2)}}part(e,t){let n=((this.diagram.layout.panels??={})[e]??={}).parts??={},r=n[t.part]??{x:0,y:0},i=(e,t,n)=>Math.round(this.snap(e+t,n)-e);return(e,a,o)=>{let s=t.axis??`xy`;n[t.part]=s===`xy`?{x:r.x+i(t.x,a.x,o),y:r.y+i(t.y,a.y,o)}:{x:r.x+i(t[s],a[s],o),y:0}}}panelSize(e,t){let{w:n,h:r}=t;return(t,i,a)=>{e.props.width=String(Math.max(40,this.snap(n+i.x,a))),e.props.height=String(Math.max(24,this.snap(r+i.y,a)))}}resize(e){let t=this.L.nodes.get(e),n=t.w,r=t.h;return this.pinAll(),(t,i,a)=>{let o=this.diagram.layout.nodes[e];o.w=Math.max(24,this.snap(n+i.x,a)),o.h=Math.max(16,this.snap(r+i.y,a))}}via(e,t,n){let r=this.L.edges.find(t=>t.key===e);this.pinAll();let i=this.edgeOverride(e);n&&c2(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),c2(r,n),r.via=n.via.map(e=>({x:Math.round(e.x),y:Math.round(e.y)})),i=p2(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=>lt(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 c2(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 l2(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 u2(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 d2(e){let t=[0];for(let n of e.via)t.push(l2(e.samples,n,t[t.length-1]));return t.push(l2(e.samples,e.end,t[t.length-1])),t}function f2(e){let t=d2(e);return t.slice(1).map((n,r)=>u2(e.samples,(t[r]+n)/2))}function p2(e,t){let n=d2(e),r=l2(e.samples,t),i=0;for(;i<n.length-2&&r>n[i+1];)i++;return i}var J=e=>document.querySelector(e),Y=J(`#source`),X=J(`#stage`),m2=J(`#diagnostics`),h2=J(`#inspector`),g2=J(`#status`),_2=J(`#theme`),v2=J(`#direction`),y2=J(`#curve`),b2=J(`#template`),x2=J(`#save`),S2=J(`#summary`),C2=J(`#zoom-fit`),w2=J(`#tabs`),T2=J(`#insert`),E2=(e,t)=>t?.altKey?Math.round(e):Math.round(e/12)*12,D2=e=>{g2.textContent=e,e&&setTimeout(()=>g2.textContent===e&&(g2.textContent=``),2e3)};function O2(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 k2(e){let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`));return new TextDecoder().decode(Uint8Array.from(t,e=>e.charCodeAt(0)))}function A2(){return X.querySelector(`svg`)}function j2(e){let t=A2(),n=new DOMPoint(e.clientX,e.clientY).matrixTransform(t.getScreenCTM().inverse());return{x:n.x,y:n.y}}var M2=e=>`M${e.x} ${e.y}h${e.w}v${e.h}h${-e.w}Z`;function N2(e,t,n){let r=e.direction===`right`||e.direction===`left`,[i,a,o,s]=r?[`x`,`w`,`y`,`h`]:[`y`,`h`,`x`,`w`],c=(e,t,n,i)=>r?{x:e,y:n,w:t-e,h:i-n}:{x:n,y:e,w:i-n,h:t-e},l=[...e.nodes.values()].filter(e=>!t.group||e.decl.group===t.group),u=t.group?e.groups.find(e=>e.id===t.group):void 0;if(t.kind===`padding`){if(!t.group){let t=e.bounds,r=n;return[M2(t)+M2({x:t.x+r,y:t.y+r,w:t.w-2*r,h:t.h-2*r})]}let r=[...l,...e.groups.filter(e=>e.decl.parent===t.group)];return u&&r.length?[M2(u)+M2(P2(r))]:[]}if(t.kind===`panel-gap`){let t=[...e.nodes.values(),...e.groups];if(!t.length)return[];let n=P2(t);return e.panels.flatMap(({box:e})=>{let t=(e,t,n,r)=>[Math.max(e,n),Math.min(t,r)],[r,i]=t(n.y,n.y+n.h,e.y,e.y+e.h),[a,o]=t(n.x,n.x+n.w,e.x,e.x+e.w);return e.x>=n.x+n.w&&i>r?[M2({x:n.x+n.w,y:r,w:e.x-n.x-n.w,h:i-r})]:e.y>=n.y+n.h&&o>a?[M2({x:a,y:n.y+n.h,w:o-a,h:e.y-n.y-n.h})]:[]})}let d=(e,t)=>e[i]<t[i]+t[a]&&t[i]<e[i]+e[a];if(t.kind===`gap`){let e=[],t=[...l].sort((e,t)=>e[o]-t[o]);for(let[n,r]of t.entries()){let l=t.slice(n+1).find(e=>d(r,e)&&e[o]>=r[o]+r[s]);if(l){let t=Math.max(r[i],l[i]),n=Math.min(r[i]+r[a],l[i]+l[a]);e.push(M2(c(t,n,r[o]+r[s],l[o])))}}return e}if(!l.length)return[];let f=l.map(e=>[e[i],e[i]+e[a]]).sort((e,t)=>e[0]-t[0]),p=[];for(let[e,t]of f){let n=p[p.length-1];n&&e<n[1]?n[1]=Math.max(n[1],t):p.push([e,t])}let m=Math.min(...l.map(e=>e[o])),h=Math.max(...l.map(e=>e[o]+e[s]));return p.slice(1).map((e,t)=>M2(c(p[t][1],e[0],m,h)))}function P2(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y));return{x:t,y:n,w:Math.max(...e.map(e=>e.x+e.w))-t,h:Math.max(...e.map(e=>e.y+e.h))-n}}var F2=`main.yu`,Z={source:``,diagram:void 0,L:void 0,selection:null,spacing:null,zoom:0,frozen:null,files:{[F2]:``},current:F2,drag:null},I2=new Map,L2=new URLSearchParams(location.search).has(`server`),R2=e=>e?`${e.kind}:${e.id}${e.k?`#${e.k}`:``}`:``,z2=(e,t,n)=>{let r=n.k??0;for(let i of e)if(t(i)===n.id&&!r--)return i},B2=e=>z2(Z.diagram.panels,e=>e.id,e),V2=e=>z2(Z.L.panels,e=>e.decl.id,e),H2={rebuild:U2,commit:U2,commitLayout:U2,deleteSelection:U2,addNodeAt:U2};function U2(){throw Error(`editor: app hooks are not installed yet`)}var W2=`http://www.w3.org/2000/svg`;function G2(e,t){let n=document.createElementNS(W2,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,String(r));return n}var K2=``;matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,()=>K2=``);function q2(e){if(!Z.selection&&!Z.spacing)return;let t=G2(`g`,{class:`overlay`}),n=Z.L.bounds.w/(e.width.baseVal.value||Z.L.bounds.w),r=K2||=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||`#2563eb`;if(Z.spacing){let e=Number(Z.diagram.settings.padding??24),i=Z.spacing.kind===`gap`&&Z.spacing.group?[Z.spacing,{...Z.spacing,kind:`rank-gap`}]:[Z.spacing];for(let a of i.flatMap(t=>N2(Z.L,t,e)))t.append(G2(`path`,{d:a,"fill-rule":`evenodd`,fill:r,"fill-opacity":.22,stroke:r,"stroke-width":n,"stroke-dasharray":`${3*n} ${2*n}`,"pointer-events":`none`}))}if(!Z.selection){e.append(t);return}let i=(e,n,i)=>t.append(G2(`rect`,{x:e.x-n,y:e.y-n,width:e.w+2*n,height:e.h+2*n,rx:i,fill:`none`,stroke:r,"stroke-width":1.5,"stroke-dasharray":`4 3`,"pointer-events":`none`})),a=(e,i,a,o,s=`circle`)=>{let c={"data-handle":a,"data-i":o,stroke:r,"stroke-width":1.5*n,style:`cursor:move`};s===`square`?t.append(G2(`rect`,{x:e-5*n,y:i-5*n,width:10*n,height:10*n,rx:2*n,fill:`#fff`,...c})):t.append(G2(`circle`,{cx:e,cy:i,r:(s===`ring`?4:5.5)*n,fill:s===`ring`?`#fff`:r,...c}))};if(Z.selection.kind===`node`){let e=Z.L.nodes.get(Z.selection.id);i(e,4,6),a(e.x+e.w+4,e.y+e.h+4,`resize`,0,`square`)}else if(Z.selection.kind===`panel`){let e=V2(Z.selection);i(e.box,3,12),a(e.box.x+e.box.w+3,e.box.y+e.box.h+3,`resize`,0,`square`);let n=t.lastElementChild;n.setAttribute(`style`,`cursor:nwse-resize`);let r=G2(`title`,{});r.textContent=`drag to set the smallest frame size · double-click to reset`,n.append(r),e.handles.forEach((n,r)=>{let i=!!Z.diagram.layout.panels?.[e.decl.id]?.parts?.[n.part];a(n.x,n.y,`part`,r,i?`circle`:`ring`);let o=t.lastElementChild,s=G2(`title`,{});s.textContent=`${n.title??n.part}${i?` · double-click to reset`:``}`,o.append(s),o.setAttribute(`style`,`cursor:${n.axis===`x`?`ew-resize`:n.axis===`y`?`ns-resize`:`move`}`)})}else if(Z.selection.kind===`group`)i(Z.L.groups.find(e=>e.id===Z.selection.id),3,14);else{let e=Z.L.edges.find(e=>e.key===Z.selection.id);t.append(G2(`path`,{d:e.d,fill:`none`,stroke:r,"stroke-width":e.style.width+4,opacity:.25,"pointer-events":`none`}));let n=e=>{let n=G2(`title`,{});n.textContent=e,t.lastElementChild.append(n)};f2(e).forEach((e,t)=>{a(e.x,e.y,`mid`,t,`ring`),n(`drag to add a bend`)}),e.via.forEach((e,t)=>{a(e.x,e.y,`via`,t),n(`drag to move · right-click or double-click to remove`)}),a(e.start.x,e.start.y,`end`,0,`square`),n(`drag to pick a side · right-click to reset`),a(e.end.x,e.end.y,`end`,1,`square`),n(`drag to pick a side · right-click to reset`)}e.append(t)}var J2=.1,Y2=8,X2=()=>{let e=Z.L.bounds;return Math.min(1.5,Math.max(.2,Math.min((X.clientWidth-48)/e.w,(X.clientHeight-48)/e.h)))};function Z2(e){let t=Z.L.bounds,n=Z.zoom||X2();Z.frozen?(e.setAttribute(`viewBox`,Z.frozen.viewBox),e.setAttribute(`width`,String(Z.frozen.w)),e.setAttribute(`height`,String(Z.frozen.h))):(e.setAttribute(`width`,String(Math.round(t.w*n))),e.setAttribute(`height`,String(Math.round(t.h*n)))),C2.textContent=`${Math.round((Z.frozen?Z.frozen.w/t.w:n)*100)}%`,C2.title=Z.zoom?`Fit to view (⌘0)`:`Fitted to view`}function Q2(e,t){let n=A2();if(!n||Z.frozen)return;let r=e?Math.min(Y2,Math.max(J2,e)):0;if(r===Z.zoom)return;let i=X.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(Z.zoom=r,Z2(n),n.querySelector(`:scope > .overlay`)?.remove(),q2(n),!Z.zoom)return;let u=n.getBoundingClientRect();X.scrollLeft+=u.left+c*u.width-a,X.scrollTop+=u.top+l*u.height-o}function $2(e){return e.kind===`node`?Z.L.nodes.has(e.id):e.kind===`group`?Z.L.groups.some(t=>t.id===e.id):e.kind===`panel`?!!V2(e):Z.L.edges.some(t=>t.key===e.id)}var e4=[`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`],t4,n4=new Map;globalThis.document?.fonts?.addEventListener(`loadingdone`,()=>n4.clear());function r4(e){if(ue(e)||(t4??=document.createElement(`canvas`).getContext(`2d`),!t4))return!0;let t=n4.get(e);if(t!==void 0)return t;let n=t4,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 n4.set(e,a),a}function i4(e,t=r4){let n=de(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:ue(e)?t:e,missing:r}}r.push(e)}return{shown:`the browser default`,missing:r}}function a4(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 Q(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),a4(e,i,!n)}var o4=e=>e.replace(/\n/g,`\\n`),s4=e=>e.replace(/\\n/g,`
|
|
812
|
+
`);function c4(e,t,n=`text`,r=``){let i=document.createElement(`input`);return i.type=n,i.value=n===`text`?o4(e):e,i.placeholder=r,i.spellcheck=!1,n===`number`&&(i.step=`any`),i.onchange=()=>t(n===`text`?s4(i.value.trim()):i.value),i.onkeydown=t=>{t.stopPropagation(),t.key===`Enter`?i.blur():t.key===`Escape`&&(i.value=n===`text`?o4(e):e,i.blur())},i}function l4(e){let t=ft(Z.diagram,e,`gap`);return t?`${t.value} from ${t.group}`:`${Z.diagram.settings.gap??`36`} from diagram`}function u4(e){let t=document.createElement(`p`);return t.className=`scope`,t.textContent=e,t}function d4(e,t){let n=e=>{Z.spacing=e?t:null;let n=A2();n&&(n.querySelector(`:scope > .overlay`)?.remove(),q2(n))};return e.addEventListener(`mouseenter`,()=>n(!0)),e.addEventListener(`mouseleave`,()=>n(e.contains(document.activeElement))),e.addEventListener(`focusin`,()=>n(!0)),e.addEventListener(`focusout`,()=>n(!1)),e}function f4(e,t){return j4(t,br[e]?.replace(/`/g,``))}function p4(e,t,n,r=``){return a4(e,c4(t,n,`text`,r),!t,`text`)}function m4(){let e=`font-list`;if(document.getElementById(e))return e;let t=Object.assign(document.createElement(`datalist`),{id:e}),n=()=>{let e=[...document.fonts].flatMap(e=>de(e.family)),n=new Set([...e4.filter((e,t)=>t<3||r4(e)),...e]);t.replaceChildren(...[...n].map(e=>Object.assign(document.createElement(`option`),{value:e})))};return n(),document.fonts.addEventListener(`loadingdone`,n),document.body.append(t),e}function h4(e,t,n=!1){let r=p4(`font`,e,t,n?`diagram font`:`theme font`);if(r.querySelector(`input`).setAttribute(`list`,m4()),n&&!e)return[r];let{shown:i,missing:a}=i4(e?fe(e).font:ye(Z.diagram.settings.theme,Z.diagram.themes).font),o=document.createElement(`p`);return o.className=`hint`,o.textContent=e&&a.length?`${a.join(`, `)} ${a.length>1?`are`:`is`} not on this computer, so the editor shows ${i}. A viewer without the font sees the next one in the list.`:`Shown as ${i}.`,[r,o]}function $(e,t,n,r=``){return a4(e,c4(t,n,`number`,r),!t,`text`)}function g4(e,t,n){let r=document.createElement(`input`);return r.type=`checkbox`,r.checked=t,r.onchange=()=>n(r.checked),a4(e,r,!t,`toggle`)}var _4=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function v4(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 y4=e=>!e||!_4.test(e)?`#888888`:e.length===4?`#${e.slice(1).split(``).map(e=>e+e).join(``)}`:e.toLowerCase();function b4(e){let t=document.createElement(`i`);return t.className=e?`swatch`:`swatch none`,e&&t.style.setProperty(`--sw`,v4(e)??`transparent`),t}function x4(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`,v4(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`,v4(e)??`transparent`);let o=document.createElement(`input`);return o.type=`color`,o.value=y4(v4(e,500)),o.onchange=()=>t(o.value),i.append(o),n.append(i),n}function S4(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=c4(t,n,`text`,r||`#hex, rgb(), hsl(), tomato`);return c.classList.add(`color-text`),i.append(a,x4(t,n),c),i}function C4(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`,v4(t,500)??`transparent`),o.title=`pick a colour`;let s=document.createElement(`input`);s.type=`color`,s.value=y4(v4(t,500)),s.onchange=()=>n(s.value),o.append(s);let c=c4(t,n,`text`,r||`none`);return i.append(a,o,c),t&&i.append(D4(`×`,()=>n(``),`clear`)),i}function w4(e){let t=e.kind===`node`?Z.diagram.nodes.get(e.id):e.kind===`group`?Z.diagram.groups.get(e.id):e.kind===`panel`?B2(e):Z.diagram.edges.find(t=>t.key===e.id);return t&&(t.labelRef?!t.labelRef.generated:e.kind===`node`&&!t.ref)?t.label??``:null}function T4(e,t){t!==w4(e)&&H2.commit(Zv(Z.source,e,t,Z.diagram))}function E4(e,t){let n=w4(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=o4(n),o.spellcheck=!1;let s=r||e.kind!==`group`&&e.kind!==`panel`,c=s?i.top+i.height/2-15:i.top+6,l=s?i.left+i.width/2-a/2:i.left+6;Object.assign(o.style,{top:`${c}px`,left:`${Math.max(4,l)}px`,width:`${a}px`}),document.body.append(o),o.focus(),o.select();let u=!1,d=t=>{u||(u=!0,o.remove(),t&&T4(e,s4(o.value)))};o.onkeydown=e=>{e.stopPropagation(),e.key===`Enter`?d(!0):e.key===`Escape`&&d(!1)},o.onblur=()=>d(!0)}function D4(e,t,n=``){let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,n&&(r.className=n),r.onclick=t,r}function O4(e,t,n){return t?D4(e,()=>{n(),H2.commitLayout()}):null}var k4=new Set((()=>{try{return JSON.parse(localStorage.getItem(`yuhwa-folded`)??`[]`)}catch{return[]}})());function A4(e,...t){let n=t.filter(e=>!!e);if(!n.length)return;let r=document.createElement(`section`);r.classList.toggle(`folded`,k4.has(e));let i=document.createElement(`h3`),a=document.createElement(`button`);a.type=`button`,a.textContent=e,a.setAttribute(`aria-expanded`,String(!k4.has(e))),a.onclick=()=>{let t=r.classList.toggle(`folded`);a.setAttribute(`aria-expanded`,String(!t)),t?k4.add(e):k4.delete(e);try{localStorage.setItem(`yuhwa-folded`,JSON.stringify([...k4]))}catch{}},i.append(a);let o=document.createElement(`div`);o.className=`rows`,o.append(...n),r.append(i,o),h2.append(r)}function j4(e,t){if(!t)return e;let n=document.createElement(`i`);return n.className=`info`,n.tabIndex=0,n.textContent=`i`,n.setAttribute(`aria-label`,t),n.dataset.tip=t,n.onclick=e=>e.preventDefault(),e.querySelector(`:scope > span`)?.append(n),e}function M4(e){let t=document.createElement(`p`);return t.className=`hint`,t.innerHTML=e,t}var N4=null,P4={up:`↑`,down:`↓`,remove:`✕`};function F4(e,t){let n=n=>r=>t({op:`set`,id:e.id,key:n,value:r||null}),r=e.color===!1?[]:[x4(e.tone??``,n(`color`))],i=e.values??{},a=Object.entries(e.fields??{}).map(([e,t])=>t.length===2&&t[0]===``&&t[1]===`true`?g4(e,i[e]===`true`,t=>n(e)(t?`true`:``)):t.length?Q(e,t,i[e]??``,n(e)):p4(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`}`:P4[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 I4(e,t,n){let r=document.createElement(`div`);r.className=`parts`;let i=(t,n=!0)=>{let r=ny(Z.source,e,t,Z.diagram);if(r.source===Z.source)return D2(`this part cannot be changed here`);N4=n&&r.id?`${e}:${r.id}`:null,H2.commit(r.source)},a=``;for(let n of t){if(n.kind!==a){a=n.kind;let e=document.createElement(`div`);e.className=`parts-kind`,e.textContent=a,r.append(e)}let t=`${e}:${n.id}`,o=document.createElement(`div`);o.className=`part`,n.depth&&(o.style.marginLeft=`${Math.min(n.depth,8)*12}px`);let s=document.createElement(`button`);s.type=`button`,s.title=`edit ${n.id}`;let c=document.createElement(`span`);c.textContent=n.label;let l=document.createElement(`code`);l.textContent=n.tone??``,s.append(...n.color===!1?[]:[b4(n.tone??``)],c,l);let u=e=>{o.classList.toggle(`open`,e),o.replaceChildren(s,...e?F4(n,i):[])};s.onclick=()=>{let e=N4!==t;r.querySelector(`.part.open`)?.dispatchEvent(new Event(`close`)),N4=e?t:null,u(e)},o.addEventListener(`close`,()=>u(!1)),u(N4===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 L4=[``,...Xn.style],R4=[``,...yr.curve],z4=`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 B4(){let e=Z.diagram.settings,t=e=>t=>H2.commit(ty(Z.source,e,t||null)),n=e.direction===`down`||e.direction===`up`,r=document.createElement(`div`);r.className=`title`,r.innerHTML=`<small>diagram</small>settings`,h2.append(r,u4(`Whole diagram. Groups, nodes and edges can override some of these with their own props.`)),A4(`Text`,p4(`title`,e.title??``,t(`title`)),p4(`subtitle`,e.subtitle??``,t(`subtitle`)),...h4(e.font??``,t(`font`)),$(`font size`,e[`font-size`]??``,t(`font-size`),`14`)),A4(`Style`,Q(`theme`,[``,...ve(Z.diagram.themes)],e.theme??``,t(`theme`)),C4(`accent`,e.accent??``,t(`accent`),`theme`),C4(`background`,e.background??``,t(`background`),`theme`),$(`radius`,e.radius??``,t(`radius`),`theme`),$(`stroke`,e[`stroke-width`]??``,t(`stroke-width`),`theme`),C4(`edge color`,e[`edge-color`]??``,t(`edge-color`),`theme`),$(`edge width`,e[`edge-width`]??``,t(`edge-width`),`theme`),g4(`shadow`,!!e.shadow&&e.shadow!==`false`,e=>t(`shadow`)(e?`true`:``)),Q(`shape`,[``,...kn],e.shape??``,t(`shape`)),f4(`look`,Q(`look`,[``,...yr.look],e.look??``,t(`look`)))),A4(`Layout`,Q(`direction`,[``,...yr.direction],e.direction??``,t(`direction`)),Q(`curve`,R4,e.curve??``,t(`curve`)),Q(`merge`,[``,...yr.merge],e.merge??``,t(`merge`)),d4(f4(`gap`,$(`node gap`,e.gap??``,t(`gap`),`36`)),{kind:`gap`}),d4(f4(`rank-gap`,$(n?`row gap`:`column gap`,e[`rank-gap`]??``,t(`rank-gap`),`auto`)),{kind:`rank-gap`}),d4(f4(`padding`,$(`padding`,e.padding??``,t(`padding`),`24`)),{kind:`padding`}),f4(`wrap`,$(`wrap`,e.wrap??``,t(`wrap`),`off`)),f4(`panels`,Q(`panels`,[``,...yr.panels],e.panels??``,t(`panels`))),d4(f4(`panel-gap`,$(`panel gap`,e[`panel-gap`]??``,t(`panel-gap`),`48`)),{kind:`panel-gap`}),g4(`grid`,!!e.grid&&e.grid!==`false`,e=>t(`grid`)(e?`true`:``))),h2.append(M4(z4))}function V4(){if(h2.innerHTML=``,!Z.selection)return B4();let e=Z.selection,t=document.createElement(`div`);t.className=`title`;let n=document.createElement(`small`);n.textContent=e.kind;let r=document.createElement(`span`);r.textContent=e.id;let i=D4(`Delete`,H2.deleteSelection,`delete`);i.title=`delete this ${e.kind} (Delete)`;let a=D4(`×`,()=>{Z.selection=null,H2.rebuild(!1)},`clear`);a.title=`deselect (Esc)`,t.append(n,r,i,a),h2.append(t,u4(`Only this ${e.kind}. Empty fields fall back to its classes, then the diagram settings.`));let o={kind:e.kind,id:e.id},s=e=>t=>H2.commit($v(Z.source,o,e,t||null)),c=(e,t)=>g4(e,!!t[e]&&t[e]!==`false`,t=>s(e)(t?`true`:``)),l=(e,t=`auto`,n={})=>[C4(`text`,e.text??e[`label-color`]??``,s(`text`),n.text),...h4(e.font??``,s(`font`),!0),$(`font size`,e[`font-size`]??``,s(`font-size`),n[`font-size`]??t),$(`font weight`,e[`font-weight`]??``,s(`font-weight`),n[`font-weight`]??`auto`),c(`italic`,e)],u=(e,t,n)=>{let r=(e.align??``).trim().split(/\s+/).filter(Boolean),i=wt.includes(r[0])?r[0]:``,a=r.slice(+!!i).join(` `),o=(e,t)=>s(`align`)([e,t.trim()].filter(Boolean).join(` `));return[Q(`merge`,[``,...Xn.merge],e.merge??``,s(`merge`)),Q(n&&!a?`align members`:`align`,[``,...wt],i,e=>o(e,a)),p4(`align with`,a,e=>o(i,e),t.align??(n?`id, or empty for the members`:`id`))]},d=w4(o),f=d!==null&&p4(e.kind===`panel`?`title`:`label`,d,e=>T4(o,e));if(e.kind===`panel`){let t=B2(e),r=ni.panels.get(t.kind);n.textContent=t.kind;let i=r?.options??{},a=!!t.ref&&!t.ref.generated;A4(`Text`,f,...a?l(t.props,`theme`):[]),a&&(A4(`Options`,...Object.entries(i).map(([e,n])=>{let i=$r(n),a=t.props[e]??``;return j4((()=>{switch(i.kind){case`select`:return Q(e,[``,...i.values],a,s(e));case`flag`:return c(e,t.props);case`color`:return C4(e,a,s(e),`default`);case`number`:return $(e,a,s(e));case`text`:return p4(e,a,s(e));default:return i}})(),r?.help?.[e])})),A4(`Size`,j4($(`width`,t.props.width??``,s(`width`),`auto`),Yn.width),j4($(`height`,t.props.height??``,s(`height`),`auto`),Yn.height),M4(`Or drag the square at the frame’s corner on the canvas.`)),A4(`Style`,S4(`color`,t.props.color??``,s(`color`)),Q(`theme`,[``,...ve(Z.diagram.themes)],t.props.theme??``,s(`theme`)),C4(`background`,t.props.background??t.props.fill??``,s(`background`),`theme`),C4(`border`,t.props.border??t.props.stroke??``,s(`border`),`theme`),Q(`border style`,L4,nt(t.props)??``,s(`border-style`)),$(`border width`,t.props[`border-width`]??``,s(`border-width`),`1`),C4(`edge color`,t.props[`edge-color`]??``,s(`edge-color`),`theme`),$(`edge width`,t.props[`edge-width`]??``,s(`edge-width`),`theme`),$(`radius`,t.props.radius??``,s(`radius`),`10`),c(`shadow`,t.props),g4(`frame`,t.props.frame!==`false`,e=>s(`frame`)(e?``:`false`))));let o=!t.failed&&r?.parts?.(t.data)||[],u=a&&!!r?.editPart&&!!t.lines&&t.lines[1]-t.lines[0]-1===t.body.length;o.length&&A4(`Parts`,u?I4(e.id,o,r?.adds):M4(`Write the panel body on its own lines to colour its parts here.`));let d=Z.diagram.layout.panels?.[e.id];A4(`Layout`,O4(`Unpin`,d?.at,()=>delete d.at),O4(`Reset layout`,d?.parts,()=>delete d.parts))}else if(e.kind===`node`){let n=Z.diagram.nodes.get(e.id),r=Object.assign({},...n.classes.map(e=>Z.diagram.classes[e]??{})),i=e=>n.props[e]??``;A4(`Text`,f,p4(`sub`,i(`sub`),s(`sub`),r.sub),...l(n.props,`auto`,r),c(`bold`,n.props),c(`mono`,n.props),$(`body size`,i(`body-size`),s(`body-size`),r[`body-size`]??`auto`),C4(`body colour`,i(`body-color`),s(`body-color`),r[`body-color`]??`from text`),p4(`icon`,i(`icon`),s(`icon`),r.icon),p4(`link`,i(`link`),s(`link`),r.link),p4(`tooltip`,i(`tooltip`),s(`tooltip`),r.tooltip)),A4(`Colour`,S4(`color`,i(`color`),s(`color`),r.color),C4(`fill`,i(`fill`),s(`fill`),r.fill??`from color`),C4(`stroke`,i(`stroke`),s(`stroke`),r.stroke??`from color`)),A4(`Shape`,Q(`shape`,[``,...kn],i(`shape`),s(`shape`)),Q(`border`,L4,nt(n.props)??``,s(`border-style`)),$(`border width`,i(`stroke-width`),s(`stroke-width`),r[`stroke-width`]??`theme`),$(`radius`,i(`radius`),s(`radius`),r.radius??`theme`),$(`opacity`,i(`opacity`),s(`opacity`),`1`),c(`shadow`,n.props));let a=[...Z.diagram.nodes.keys()].filter(t=>t!==e.id);A4(`Connect`,D4(`+ Connected node`,()=>H2.addNodeAt({from:e.id,group:n.group})),a.length>0&&Q(`connect to`,[``,...a],``,t=>t&&H2.commit(sy(Z.source,{from:e.id,to:t},Z.diagram)))),A4(`Size`,$(`width`,i(`width`),s(`width`),`auto`),$(`height`,i(`height`),s(`height`),`auto`),$(`max width`,i(`max-width`),s(`max-width`),`auto`)),A4(`Layout`,...u(n.props,r,!1),O4(`Unpin`,Z.diagram.layout.nodes[e.id],()=>delete Z.diagram.layout.nodes[e.id])),r.shape&&!n.props.shape&&(t.title=`shape ${r.shape} from class`)}else if(e.kind===`edge`){let t=Z.diagram.edges.find(t=>t.key===e.id),n=e=>t.props[e]??``,r=[``,`arrow`,`open`,`dot`,`diamond`,`bar`,`none`],i=[``,`top`,`right`,`bottom`,`left`,`auto`];A4(`Text`,f,...l(t.props),C4(`label bg`,n(`label-bg`),s(`label-bg`))),A4(`Line`,S4(`color`,n(`color`),s(`color`)),C4(`stroke`,n(`stroke`),s(`stroke`),`from color`),Q(`style`,L4,nt(t.props,`style`)??``,s(`style`)),$(`width`,n(`width`),s(`width`),`theme`),$(`opacity`,n(`opacity`),s(`opacity`),`1`),c(`flow`,t.props),c(`animate`,t.props)),A4(`Ends`,Q(`head`,r,n(`head`),s(`head`)),Q(`tail`,r,n(`tail`),s(`tail`)),Q(`exit`,i,n(`exit`),s(`exit`)),Q(`enter`,i,n(`enter`),s(`enter`))),A4(`Route`,Q(`curve`,R4,n(`curve`),s(`curve`)),c(`constraint`,t.props),Q(`merge`,[``,...Xn.merge],n(`merge`),s(`merge`)),O4(`Reset route`,Z.diagram.layout.edges[e.id],()=>delete Z.diagram.layout.edges[e.id])),t.ref&&Z.diagram.edges.filter(e=>e.ref===t.ref).length>1&&h2.append(M4(`Style applies to every edge on this line.`))}else{let t=Z.diagram.groups.get(e.id),n=e=>t.props[e]??``;A4(`Text`,f,...l(t.props),c(`caps`,t.props)),A4(`Colour`,S4(`color`,n(`color`),s(`color`)),C4(`fill`,n(`fill`),s(`fill`),`from color`),C4(`stroke`,n(`stroke`),s(`stroke`),`from color`),Q(`border`,L4,nt(t.props)??``,s(`border-style`))),A4(`Content`,D4(`+ Node inside`,()=>H2.addNodeAt({group:e.id}))),A4(`Layout`,...u(t.props,{},!0),d4(j4($(`gap`,n(`gap`),s(`gap`),l4(t.parent)),`Space between this group's members and between its ranks, px. Only this group. Empty: the parent group's gap, else the diagram's node gap.`),{kind:`gap`,group:e.id}),d4(j4(p4(`padding`,n(`padding`),s(`padding`),`18, or y x, or top right bottom left`),`Space inside this group's border, px, like CSS: all, y x, top x bottom, or top right bottom left. Only this group.`),{kind:`padding`,group:e.id}))}}Object.assign(H2,{rebuild:G4,commit:a3,commitLayout:o3,deleteSelection:s3,addNodeAt:c3});var H4=`title: Hello yuhwa
|
|
813
|
+
direction: right
|
|
814
|
+
|
|
815
|
+
.svc [blue]
|
|
816
|
+
|
|
817
|
+
user "You" [shape: circle, purple]
|
|
818
|
+
|
|
819
|
+
group app "Your app" {
|
|
820
|
+
web "Web app" .svc [sub: "Next.js"]
|
|
821
|
+
api "API" .svc
|
|
822
|
+
}
|
|
823
|
+
db "Database" [shape: cylinder, amber]
|
|
824
|
+
|
|
825
|
+
user -> web: visits
|
|
826
|
+
web -> api
|
|
827
|
+
api -> db: SQL
|
|
828
|
+
|
|
829
|
+
// Drag boxes, edges and labels in the preview.
|
|
830
|
+
// Positions are written to the layout block below.
|
|
831
|
+
`,U4=[],W4=[];function G4(e=!0){e&&(Z.diagram=xp(Z.source,{file:Z.current,resolve:e=>e===Z.current?Z.source:Z.files[e]})),Z.L=km(Z.diagram,{measureFor:e=>xi(e.font)});let t=zm(Z.diagram,Z.L,{interactive:!0,idPrefix:`ed`,snapGrid:12});X.innerHTML=t;let n=!Z.diagram.nodes.size&&!Z.diagram.panels.length&&!Z.diagram.settings.title;if(X.classList.toggle(`is-empty`,n),n){let e=document.createElement(`p`);e.className=`empty-hint`,e.textContent=Object.keys(Z.diagram.classes).length?`Nothing to draw yet: this file only defines classes. Import it from another file, or add a node.`:`Nothing to draw yet. Type a line like a -> b or pick something from Add. Double-click the canvas for a new node.`,X.append(e)}let r=A2();Z2(r),Z.selection&&!$2(Z.selection)&&(Z.selection=null),q2(r),e&&(Ly(t),z3.sync(),t3(),n3());let i=R2(Z.selection);if(e||i!==K4){let e=Z4(Z.selection);z3.mark(e,i!==K4);let t=J4(e);i===K4&&t&&t===q4||V4(),K4=i,q4=t}}var K4=``,q4=``;function J4(e){return!Z.selection||!e?``:[Z.source.split(`
|
|
832
|
+
`).slice(e[0],e[1]+1).join(`
|
|
833
|
+
`),JSON.stringify(Z.diagram.layout),Object.keys(Z.diagram.classes).join()].join(`
|
|
834
|
+
\0`)}function Y4(e,t){return[...A2()?.querySelectorAll(`[data-panel="${CSS.escape(t)}"]`)??[]].indexOf(e)}function X4(e){let t=Z.source.split(`
|
|
835
|
+
`),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 Z4(e){if(!e)return null;if(e.kind===`node`){let t=Z.diagram.nodes.get(e.id);if(!t)return null;if(!t.ref||t.implicit){let t=Z.diagram.edges.find(t=>(t.from===e.id||t.to===e.id)&&t.ref)?.ref.line;return t===void 0?null:[t,t]}let n=Math.max(t.ref.line,t.bodyLines?.[1]??0,...Object.values(t.ref.propLines??{}));return[t.ref.line,n]}if(e.kind===`edge`){let t=Z.diagram.edges.find(t=>t.key===e.id)?.ref?.line;return t===void 0?null:[t,t]}if(e.kind===`group`){let t=Z.diagram.groups.get(e.id)?.ref?.line;return t===void 0?null:[t,X4(t)]}return B2(e)?.lines??null}function Q4(e){let t=null,n=1/0,r=r=>{let i=Z4(r);i&&e>=i[0]&&e<=i[1]&&i[1]-i[0]<n&&(t=r,n=i[1]-i[0])};for(let e of Z.diagram.nodes.values())e.implicit||r({kind:`node`,id:e.id});for(let e of Z.diagram.edges)r({kind:`edge`,id:e.key});for(let e of Z.diagram.groups.keys())r({kind:`group`,id:e});let i=new Map;for(let e of Z.diagram.panels){let t=i.get(e.id)??0;i.set(e.id,t+1),r({kind:`panel`,id:e.id,k:t})}return t&&$2(t)?t:null}function $4(e){let t={node:`data-node`,edge:`data-edge`,group:`data-group`,panel:`data-panel`}[e.kind],n=A2()?.querySelectorAll(`[${t}="${CSS.escape(e.id)}"]`)[e.k??0];if(!n)return;let r=n.getBoundingClientRect(),i=X.getBoundingClientRect();r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom||X.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 e3(){if(Y.value!==Z.source)return;let e=Q4(Z.source.slice(0,Y.selectionStart).split(`
|
|
836
|
+
`).length-1);R2(e)!==R2(Z.selection)&&(Z.selection=e,G4(!1),e&&$4(e))}function t3(){m2.innerHTML=``;let e=z3.diagnostics(Z.current),t=e.filter(e=>e.severity===1).length,n=e.length-t,r=(e,t)=>`${e} ${t}${e===1?``:`s`}`;if(S2.textContent=`${r(Z.diagram.nodes.size,`node`)} · ${r(Z.diagram.edges.length,`edge`)}`,t||n){let e=document.createElement(`span`);e.className=`bad`,e.textContent=` · ${t?r(t,`error`):r(n,`warning`)}`,S2.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=()=>z3.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(),z3.fix(t)},e.append(n)}m2.append(e)}}function n3(){let e=ve(Z.diagram.themes);[..._2.options].map(e=>e.value).join()!==e.join()&&_2.replaceChildren(...e.map(e=>new Option(e,e))),_2.value=e.includes(Z.diagram.settings.theme)?Z.diagram.settings.theme:`paper`,v2.value=Z.diagram.settings.direction||`right`,y2.value=Z.diagram.settings.curve||`smooth`}function r3(e){U4[U4.length-1]!==e&&U4.push(e),U4.length>200&&U4.shift(),W4.length=0}function i3(e,t=!0){if(e===Z.source)return;N3.end(),t&&r3(Z.source),Z.source=e;let n=Y.scrollTop;Y.value=e,Y.scrollTop=n,u3()}function a3(e){i3(e),G4(!0)}function o3(){a3(Gv(Z.source,Z.diagram.layout,Z.diagram))}function s3(){if(!Z.selection)return;let{kind:e,id:t}=Z.selection,n=dy(Z.source,{kind:e,id:t},Z.diagram);if(n===Z.source)return D2(`this ${e} cannot be deleted here, edit the source`);Z.selection=null,a3(n),D2(`${e} ${t} deleted`)}function c3(e,t){let n=J3(`node`),r=cy(Z.source,{id:n,label:`New node`,...e},Z.diagram);if(r===Z.source)return D2(`cannot add a node here`);if(Z.selection={kind:`node`,id:n},a3(r),t&&Z.L.nodes.has(n)){let{o:e,w:r,h:i}=p3().pinned(n,!0);e.x=Math.round(E2(t.x)-r/2),e.y=Math.round(E2(t.y)-i/2),i3(Gv(Z.source,Z.diagram.layout,Z.diagram),!1),G4(!0)}let i=X.querySelector(`[data-node="${CSS.escape(n)}"]`);i&&E4({kind:`node`,id:n},i)}var l3=0;function u3(){if(Z.files[Z.current]=Z.source,L2)d3.changed(),clearTimeout(l3),l3=window.setTimeout(f3,500);else try{localStorage.setItem(`yuhwa-files`,JSON.stringify({files:Z.files,current:Z.current}))}catch{}}var d3=new Vy(async()=>{let e=await fetch(`/api/source`,{method:`PUT`,body:JSON.stringify({files:Z.files})});if(!e.ok)throw Error(`save failed`);let{written:t=[]}=await e.json();return t.length?`saved ${t.join(`, `)}`:`saved`},D2);function f3(){if(L2)return clearTimeout(l3),d3.save()}var p3=()=>new s2(Z.diagram,Z.L,E2),m3=null,h3=!1,g3=new Map,_3=null;function v3(e,t){m3={x:e.clientX,y:e.clientY,left:X.scrollLeft,top:X.scrollTop,moved:!1,clear:t},X.setPointerCapture(e.pointerId),X.classList.add(`panning`),e.preventDefault()}var y3=()=>{let[e,t]=[...g3.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)}};X.addEventListener(`wheel`,e=>{if(!(e.ctrlKey||e.metaKey)||Z.drag||!A2())return;e.preventDefault();let t=e.deltaMode===1?e.deltaY*16:e.deltaY;Q2(j3()*Math.min(2,Math.max(.5,Math.exp(-t*.01))),e)},{passive:!1}),X.addEventListener(`pointerdown`,e=>{if(e.pointerType!==`touch`||(g3.set(e.pointerId,{x:e.clientX,y:e.clientY}),g3.size!==2))return;C3(),m3=null;let t=y3();_3={d:t.d,z:j3(),mid:t},e.stopImmediatePropagation()},{capture:!0}),X.addEventListener(`pointermove`,e=>{if(!g3.has(e.pointerId)||(g3.set(e.pointerId,{x:e.clientX,y:e.clientY}),!_3||g3.size!==2))return;let t=y3();Q2(_3.z*t.d/Math.max(1,_3.d),{clientX:t.x,clientY:t.y}),X.scrollLeft-=t.x-_3.mid.x,X.scrollTop-=t.y-_3.mid.y,_3.mid=t,e.stopImmediatePropagation()},{capture:!0});var b3=e=>{g3.delete(e.pointerId),g3.size<2&&(_3=null)};X.addEventListener(`pointerup`,b3,{capture:!0}),X.addEventListener(`pointercancel`,b3,{capture:!0}),X.addEventListener(`pointerdown`,e=>{if(!A2()||_3)return;if(e.button===1||e.button===0&&h3)return v3(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 v3(e,!0);let n=j2(e),r=A2();Z.frozen={viewBox:r.getAttribute(`viewBox`),w:r.width.baseVal.value,h:r.height.baseVal.value};let i=o3,a=()=>{},o=p3();if(t.hasAttribute(`data-handle`)){let e=t.getAttribute(`data-handle`),r=Number(t.getAttribute(`data-i`));if(Z.selection?.kind===`panel`&&e===`part`){let e=Z.selection.id,t=V2(Z.selection).handles[r];i=()=>a3(ry(Z.source,Z.diagram,e,t)),a=o.part(e,t)}else if(Z.selection?.kind===`panel`&&e===`resize`){let e={kind:`panel`,id:Z.selection.id},t=B2(Z.selection);a=o.panelSize(t,V2(Z.selection).box),i=()=>{let{width:n,height:r}=t.props;a3($v($v(Z.source,e,`width`,n),e,`height`,r))}}else Z.selection?.kind===`node`&&e===`resize`?a=o.resize(Z.selection.id):Z.selection?.kind===`edge`&&(e===`via`||e===`mid`?a=o.via(Z.selection.id,r,e===`mid`?n:null):e===`end`&&(a=o.port(Z.selection.id,r===0?0:1)))}else if(t.hasAttribute(`data-node`)){let e=t.getAttribute(`data-node`);Z.selection={kind:`node`,id:e},a=o.centre(e,!0)}else if(t.hasAttribute(`data-edge-label`)){let e=t.getAttribute(`data-edge-label`);Z.selection={kind:`edge`,id:e},a=o.label(e)}else if(t.hasAttribute(`data-edge`)){let e=t.getAttribute(`data-edge`);Z.selection={kind:`edge`,id:e},a=o.bend(e,n)}else if(t.hasAttribute(`data-panel`)){let e=t.getAttribute(`data-panel`);Z.selection={kind:`panel`,id:e,k:Y4(t,e)},a=o.centre(e,!1)}else if(t.hasAttribute(`data-group`)){let e=t.getAttribute(`data-group`);Z.selection={kind:`group`,id:e},a=o.group(e)}Z.drag={move:a,finish:i,moved:!1,start:n},X.setPointerCapture(e.pointerId),G4(!1),e.preventDefault()}),X.addEventListener(`pointermove`,e=>{if(m3){let t=e.clientX-m3.x,n=e.clientY-m3.y;if(!m3.moved&&Math.hypot(t,n)<3)return;m3.moved=!0,X.scrollLeft=m3.left-t,X.scrollTop=m3.top-n;return}if(!Z.drag)return;let t=j2(e),n={x:t.x-Z.drag.start.x,y:t.y-Z.drag.start.y};!Z.drag.moved&&Math.hypot(n.x,n.y)<3||(Z.drag.moved=!0,X.classList.add(`dragging`),Z.drag.move(t,n,e),x3||=requestAnimationFrame(()=>{x3=0,G4(!1)}))});var x3=0;function S3(){if(m3){let{moved:e,clear:t}=m3;m3=null,X.classList.remove(`panning`),!e&&t&&Z.selection&&(Z.selection=null,G4(!1))}else C3()}function C3(){if(!Z.drag)return;let{moved:e,finish:t}=Z.drag;Z.drag=null,Z.frozen=null,X.classList.remove(`dragging`),e?t():G4()}X.addEventListener(`pointerup`,S3),X.addEventListener(`pointercancel`,S3);function w3(e,t){let n=Z.diagram.layout.edges[e],r=Number(t.getAttribute(`data-i`));if(!n)return!1;if(t.getAttribute(`data-handle`)===`via`&&n.via)n.via.splice(r,1),n.via.length||delete n.via;else if(t.getAttribute(`data-handle`)===`end`&&n.ports)n.ports[r]=`auto`;else return!1;return o3(),!0}X.addEventListener(`contextmenu`,e=>{let t=e.target,n=t.closest(`[data-handle]`);if(Z.selection?.kind===`edge`&&n){w3(Z.selection.id,n)&&e.preventDefault();return}let r=t.closest(`[data-edge]`)?.getAttribute(`data-edge`),i=r?Z.diagram.layout.edges[r]:void 0;r&&i?.via&&(e.preventDefault(),delete i.via,Z.selection={kind:`edge`,id:r},o3())}),X.addEventListener(`dblclick`,e=>{let t=e.target,n=t.closest(`[data-handle]`),r=t.closest(`[data-edge-label]`);if(Z.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`part`){let e=Z.selection.id,t=V2(Z.selection)?.handles[Number(n.getAttribute(`data-i`))]?.part,r=Z.diagram.layout.panels?.[e];if(!t||!r?.parts?.[t])return;delete r.parts[t],Object.keys(r.parts).length||delete r.parts,o3()}else if(Z.selection?.kind===`panel`&&n?.getAttribute(`data-handle`)===`resize`){let e={kind:`panel`,id:Z.selection.id};a3($v($v(Z.source,e,`width`,null),e,`height`,null))}else if(Z.selection?.kind===`edge`&&n)w3(Z.selection.id,n);else if(!n){let n=r??t.closest(`[data-node],[data-edge],[data-group],[data-panel]`);if(!n)return c3({},j2(e));let[i,a]=r?[`edge`,r.getAttribute(`data-edge-label`)]:[`node`,`edge`,`group`,`panel`].map(e=>[e,n.getAttribute(`data-${e}`)]).find(([,e])=>e!==null),o=i===`edge`&&!r?X.querySelector(`[data-edge-label="${CSS.escape(a)}"]`)??n:n;E4({kind:i,id:a},o)}}),document.addEventListener(`keydown`,e=>{let t=e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLInputElement,n=e.metaKey||e.ctrlKey;if(n&&e.key.toLowerCase()===`s`){e.preventDefault(),f3();return}if(t)return;if(e.key===` `&&!e.repeat){h3=!0,X.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(),Q2(r===-1?1:r&&j3()*r);return}if(n&&e.key.toLowerCase()===`z`){e.preventDefault(),e.shiftKey?E3():T3();return}if(e.key===`Escape`){Z.selection=null,G4(!1);return}if((e.key===`Delete`||e.key===`Backspace`)&&Z.selection){e.preventDefault(),s3();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]&&(Z.selection?.kind===`node`||Z.selection?.kind===`panel`)){e.preventDefault();let t=e.shiftKey?12:1,{o:n}=p3().pinned(Z.selection.id,Z.selection.kind===`node`);n.x+=i[e.key].x*t,n.y+=i[e.key].y*t,o3()}});function T3(){let e=U4.pop();e!==void 0&&(W4.push(Z.source),i3(e,!1),G4(!0))}function E3(){let e=W4.pop();e!==void 0&&(U4.push(Z.source),i3(e,!1),G4(!0))}_2.replaceChildren(...T.map(e=>new Option(e,e)));for(let[e,t]of[[v2,`direction`],[y2,`curve`]])e.replaceChildren(...yr[t].map(e=>new Option(e,e)));for(let e of Hy)b2.append(new Option(e.name,e.name));b2.onchange=()=>{let e=Hy.find(e=>e.name===b2.value);if(b2.value=``,e){if(e.files){if(L2)return D2(`multi-file templates need the browser editor`);if(Z.files[Z.current]=Z.source,Object.values(Z.files).some(e=>e.trim()&&e!==H4)&&!confirm(`Replace all files with "${e.name}"?`))return;s6({files:{[F2]:e.source,...e.files},current:F2}),Y.value=Z.source,u3(),K3(),G4(!0)}else a3(e.source)}},_2.onchange=()=>a3(ty(Z.source,`theme`,_2.value===`paper`&&!/^\s*import\b/m.test(Z.source)?null:_2.value)),v2.onchange=()=>{Z.diagram.layout.nodes={},Z.diagram.layout.edges={};for(let e of Object.values(Z.diagram.layout.panels??{}))delete e.at;a3(ty(Gv(Z.source,Z.diagram.layout,Z.diagram),`direction`,v2.value))},y2.onchange=()=>a3(ty(Z.source,`curve`,y2.value===`smooth`?null:y2.value)),J(`#undo`).onclick=T3,J(`#redo`).onclick=E3,J(`#reset`).onclick=()=>{Z.diagram.layout={nodes:{},edges:{}},o3()};function D3(){return zm(Z.diagram,km(Z.diagram,{measureFor:e=>xi(e.font)}),{idPrefix:`yuhwa`})}async function O3(e,t){try{await navigator.clipboard.writeText(e),D2(`${t} copied`)}catch{D2(`clipboard blocked`)}}J(`#copy-svg`).onclick=()=>O3(D3(),`SVG`),J(`#copy-md`).onclick=()=>O3("```yuhwa\n"+Z.source.replace(/\s*$/,``)+"\n```\n",`Markdown`);function k3(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=(Z.diagram.settings.title||`diagram`).toLowerCase().replace(/[^\w]+/g,`-`)+t,n.click(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}document.fonts?.addEventListener(`loadingdone`,()=>{G4(!1),Z.selection||V4()}),J(`#download`).onclick=()=>k3(new Blob([D3()],{type:`image/svg+xml`}),`.svg`),J(`#download-png`).onclick=async()=>{try{(await Ry(D3(),{scale:2})).toBlob(e=>e?k3(e,`.png`):D2(`PNG export failed`),`image/png`)}catch{D2(`PNG export failed`)}};var A3=J(`#export`);A3.querySelector(`.menu-list`).addEventListener(`click`,e=>{e.target.closest(`button`)&&(A3.open=!1)}),document.addEventListener(`pointerdown`,e=>{A3.open&&!A3.contains(e.target)&&(A3.open=!1)}),A3.addEventListener(`keydown`,e=>{e.key===`Escape`&&(A3.open=!1,A3.querySelector(`summary`).focus())}),J(`#share`).onclick=()=>{let e=Object.keys(Z.files).length>1,t=`${location.origin}${location.pathname}#${e?`files=${O2(JSON.stringify({files:Z.files,current:Z.current}))}`:`src=${O2(Z.source)}`}`;history.replaceState(null,``,t),O3(t,`link`)},J(`#zoom-in`).onclick=()=>Q2(j3()*1.25),J(`#zoom-out`).onclick=()=>Q2(j3()/1.25),J(`#zoom-fit`).onclick=()=>Q2(+!Z.zoom);function j3(){let e=A2();return e?e.width.baseVal.value/Z.L.bounds.w:1}x2.hidden=!L2,x2.onclick=()=>void f3(),window.addEventListener(`beforeunload`,e=>{L2&&d3.dirty&&e.preventDefault()}),window.addEventListener(`resize`,()=>Z.zoom||G4(!1));var M3=()=>{h3=!1,X.classList.remove(`can-pan`)};document.addEventListener(`keyup`,e=>{e.key===` `&&M3()}),window.addEventListener(`blur`,M3);var N3=new By((e,t)=>{t&&r3(Z.source),Z.source=e,u3()},()=>G4(!0));Y.addEventListener(`input`,()=>N3.input(Y.value)),Y.addEventListener(`click`,e3),Y.addEventListener(`keyup`,e=>{/^(Arrow|Page|Home|End)/.test(e.key)&&e3()}),Y.addEventListener(`keydown`,e=>{if(e.isComposing||e.altKey||e.ctrlKey||e.metaKey)return;let{value:t,selectionStart:n,selectionEnd:r}=Y;if(e.key===`Tab`){e.preventDefault();let i=o2(t,n,r,e.shiftKey);if(i.text===t)return;let a=Y.scrollTop;Y.value=i.text,Y.setSelectionRange(i.from,i.to),Y.scrollTop=a,Y.dispatchEvent(new Event(`input`));return}let i=t.lastIndexOf(`
|
|
837
|
+
`,n-1)+1,a;e.key===`Enter`&&!e.shiftKey?a=a2(t,n,r):e.key===`}`&&n===r&&!t.slice(i,n).trim()&&(a={start:i,end:r,insert:r2(t,n)+`}`}),a&&(e.preventDefault(),Y.setRangeText(a.insert,a.start,a.end,`end`),a.caret!==void 0&&Y.setSelectionRange(a.caret,a.caret),Y.dispatchEvent(new Event(`input`)))});function P3(e,t,n){let r=document.createElement(`div`);r.className=`split ${e}`,r.setAttribute(`role`,`separator`),t(r),r.addEventListener(`pointerdown`,e=>{e.preventDefault(),r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let t=()=>{r.classList.remove(`dragging`),r.removeEventListener(`pointermove`,n),r.removeEventListener(`pointerup`,t);try{localStorage.setItem(`yuhwa-panes`,JSON.stringify(L3))}catch{}Z.zoom||G4(!1)};r.addEventListener(`pointermove`,n),r.addEventListener(`pointerup`,t)})}var F3=J(`main`),I3=J(`#left`),L3={};try{L3=JSON.parse(localStorage.getItem(`yuhwa-panes`)??`{}`)}catch{}var R3=()=>{L3.left&&(F3.style.gridTemplateColumns=`${L3.left}px 1fr var(--side)`),L3.diag&&Object.assign(m2.style,{height:`${L3.diag}px`,maxHeight:`none`})};P3(`split-x`,e=>I3.append(e),e=>{L3.left=Math.round(Math.min(Math.max(e.clientX-F3.getBoundingClientRect().left,240),innerWidth-640)),R3()}),P3(`split-y`,e=>m2.before(e),e=>{let t=I3.getBoundingClientRect().bottom;L3.diag=Math.round(Math.min(Math.max(t-e.clientY,40),I3.clientHeight-160)),R3()}),R3();var z3=e2({ta:Y,files:()=>({...Z.files,[Z.current]:Y.value}),current:()=>Z.current,commit:a3,open:B3,status:D2,onDiagnostics:e=>{e===Z.current&&t3()}});function B3(e){if(e===Z.current||!(e in Z.files))return;Z.files[Z.current]=Z.source,N3.end(),I2.set(Z.current,{undo:U4,redo:W4}),Z.current=e,Z.source=Z.files[e];let t=I2.get(e);U4=t?.undo??[],W4=t?.redo??[],Z.selection=null,Y.value=Z.source,Y.scrollTop=0,u3(),K3(),G4(!0)}var V3=e=>{let t=e.trim().replace(/^\.?\//,``).replace(/\s+/g,`-`);return t?/\.\w+$/.test(t)?t:`${t}.yu`:``};function H3(e,t){let n=e;for(let t=2;n in Z.files;t++)n=e.replace(/(\.\w+)?$/,`-${t}$1`);return Z.files[n]=t,B3(n),n}function U3(e){let t=Z.current.split(`/`).slice(0,-1),n=e.split(`/`),r=0;for(;r<t.length&&t[r]===n[r];)r++;let i=t.slice(r).map(()=>`..`);return(i.length?i.join(`/`)+`/`:`./`)+n.slice(r).join(`/`)}function W3(e){let t=V3(prompt(`Rename file`,e)??``);if(!t||t===e)return;if(t in Z.files)return D2(`${t} exists`);Z.files[Z.current]=Z.source,N3.end();let n=Z.files[e];delete Z.files[e],Z.files[t]=n;let r=e=>e.split(`/`).pop();for(let n of Object.keys(Z.files))Z.files[n]=Z.files[n].replace(/^(\s*(?:\/\/\s*)?import\s+(?:\{[^}]*\}\s*from\s+)?")([^"]+)(")/gm,(n,i,a,o)=>r(a)===r(e)?i+a.slice(0,-r(e).length)+r(t)+o:n);Z.current===e&&(Z.current=t),Z.source=Z.files[Z.current],Y.value=Z.source,u3(),K3(),G4(!0)}function G3(e){Object.keys(Z.files).length<2||(!Z.files[e].trim()||confirm(`Delete ${e}?`))&&(e===Z.current&&B3(Object.keys(Z.files).find(t=>t!==e)),delete Z.files[e],I2.delete(e),u3(),K3(),G4(!0))}function K3(){w2.innerHTML=``;for(let e of Object.keys(Z.files)){let t=document.createElement(`button`);t.className=`tab`,t.setAttribute(`role`,`tab`),t.setAttribute(`aria-selected`,String(e===Z.current)),t.textContent=e,t.onclick=()=>B3(e),L2||(t.title=`${e}: double-click to rename`,t.ondblclick=()=>W3(e));let n=document.createElement(`span`);n.className=`x`,n.textContent=`×`,n.title=`Delete ${e}`,n.onclick=t=>{t.stopPropagation(),G3(e)},L2||t.append(n),w2.append(t)}w2.querySelector(`[aria-selected="true"]`)?.scrollIntoView({block:`nearest`,inline:`nearest`}),q3.hidden=L2,Y3()}var q3=J(`#add-file`);q3.onclick=()=>{let e=V3(prompt(`New file name`,`shared.yu`)??``);e&&D2(`${H3(e,`// Shared classes and nodes. Use them from ${Z.current} with:\n// import "${U3(e).replace(/^(\.\.\/)+/,`./`)}"\n\n.svc [blue]\n`)} added`)};function J3(e){let t=new Set([...Z.diagram.nodes.keys(),...Z.diagram.panels.map(e=>e.id),...Z.diagram.groups.keys(),...Object.keys(Z.diagram.classes),...Object.keys(Z.diagram.vars??{}),...Object.keys(Z.diagram.defs??{})]);for(let n=1;;n++){let r=n===1?e:`${e}${n}`;if(!t.has(r)&&!Z.source.includes(`${r} `))return r}}function Y3(){T2.replaceChildren(T2.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),T2.append(i)),i.append(new Option(n,r))};Uy.forEach((e,n)=>t(e.group,e.label,`s${n}`));for(let e of ni.panels.keys())Uy.some(t=>t.text.startsWith(e+` `))||t(`Panels`,e,`k${e}`);for(let e of Object.keys(Z.files))e!==Z.current&&t(`Import a file`,`import "${U3(e)}"`,`f${e}`)}function X3(e,t=!1){let n=Z.source.search(/^layout\s*\{/m),r=t?0:n>=0?n:Z.source.length,i=Z.source.slice(0,r).replace(/\s*$/,``),a=Z.source.slice(r),o=i?t?``:`
|
|
838
|
+
|
|
839
|
+
`:``,s=t?`${e}\n${Z.source}`:`${i}${o}${e}\n${a?`
|
|
840
|
+
`+a:``}`;a3(s);let c=t?0:i.length+o.length;Y.focus(),Y.setSelectionRange(c,c+e.length);let l=s.slice(0,c).split(`
|
|
841
|
+
`).length;Y.scrollTop=Math.max(0,(l-3)*parseFloat(getComputedStyle(Y).lineHeight||`20`))}T2.onchange=()=>{let e=T2.value;if(T2.value=``,e.startsWith(`s`)){let t=Uy[Number(e.slice(1))],n=J3(t.id);X3(t.text.replaceAll(`{id}`,n)),D2(`${t.label.toLowerCase()} added`)}else if(e.startsWith(`k`)){let t=ni.panels.get(e.slice(1));X3(`${t.name} ${J3(t.name)} "${t.name}" {\n // ${t.syntax??``}\n}`)}else if(e.startsWith(`f`)){let t=`import "${U3(e.slice(1))}"`;if(Z.source.includes(t))return D2(`already imported`);X3(t,!0)}};var Z3=J(`#import-dlg`),Q3=J(`#import-text`),$3=J(`#import-msg`),e6=J(`#import-new`),t6=`imported.yu`;function n6(e=``,t=`imported.yu`){Q3.value=e,t6=t,$3.textContent=``,$3.className=``,e6.checked=!L2,e6.disabled=L2,Z3.showModal(),Q3.focus()}J(`#import`).onclick=()=>n6();async function r6(e){n6(await e.text(),V3(e.name.replace(/\.(mmd|mermaid|json|txt|md)$/,``)))}J(`#import-file`).onchange=async e=>{let t=e.target.files?.[0];t&&await r6(t),e.target.value=``};var i6=e=>e.match(/```(?:yuhwa|mermaid|json)[^\n]*\n([\s\S]*?)```/)?.[1]??e;J(`#import-go`).onclick=e=>{e.preventDefault();let t=i6(Q3.value);if(!t.trim())return Z3.close();let n=zy(t),r=n.diagnostics.filter(e=>e.severity===`error`);if(r.length||!n.source.trim()){$3.className=`error`,$3.textContent=r.map(e=>e.message).join(`
|
|
842
|
+
`)||`nothing to import`;return}let i=n.format===`yuhwa`?`yuhwa`:n.format===`json`?`JSON`:`Mermaid`;e6.checked?H3(t6,n.source):a3(n.source),Z3.close();let a=n.diagnostics.length;D2(`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(),r6(t))});async function a6(){if(L2){let e=await(await fetch(`/api/source`)).json();Z.source=e.source,Z.current=String(e.name).split(`/`).pop()||`main.yu`,Z.files={[Z.current]:Z.source,...e.files},document.title=`${e.name} — yuhwa`,D2(e.name)}else{if(!o6()){let e=null;try{e=localStorage.getItem(`yuhwa-files`),s6(e?JSON.parse(e):{files:{[F2]:localStorage.getItem(`yuhwa-source`)??H4}})}catch{s6({files:{[F2]:H4}})}}Z.files[Z.current]=Z.source}Y.value=Z.source,K3(),G4(!0)}function o6(){let e=location.hash.match(/src=([\w-]+)/),t=location.hash.match(/files=([\w-]+)/);try{if(t)s6(JSON.parse(k2(t[1])));else if(e)s6({files:{[F2]:k2(e[1])}});else return!1}catch{return D2(`broken link`),!1}return!0}function s6(e){N3.end(),Z.files=Object.keys(e.files??{}).length?{...e.files}:{[F2]:H4},Z.current=e.current&&e.current in Z.files?e.current:Object.keys(Z.files)[0],Z.source=Z.files[Z.current],I2.clear(),U4=[],W4=[]}a6(),addEventListener(`hashchange`,()=>{!L2&&o6()&&(Y.value=Z.source,K3(),G4(!0))});
|