respec 37.7.2 → 37.8.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.
@@ -0,0 +1 @@
1
+ var pele=function(e){"use strict";var t=[["flowchart","flowchart-elk",/^\s*flowchart-elk/],["mindmap","mindmap",/^\s*mindmap/],["architecture","architecture",/^\s*architecture/],["agentflow","agentflow",/^\s*agentflow-beta\b/],["c4","c4",/^\s*(?:C4Context|C4Container|C4Component|C4Dynamic|C4Deployment)/],["kanban","kanban",/^\s*kanban/],["class","classDiagram",/^\s*classDiagram/],["er","er",/^\s*erDiagram/],["gantt","gantt",/^\s*gantt/],["info","info",/^\s*info/],["pie","pie",/^\s*pie/],["requirement","requirement",/^\s*requirement(Diagram)?/],["sequence","sequence",/^\s*sequenceDiagram/],["swimlane","swimlane",/^\s*swimlane-beta\b/],["flowchart","flowchart-v2",/^\s*(graph|flowchart)/],["timeline","timeline",/^\s*timeline/],["gitGraph","gitGraph",/^\s*gitGraph/],["state","stateDiagram",/^\s*stateDiagram/],["journey","journey",/^\s*journey/],["quadrantChart","quadrantChart",/^\s*quadrantChart/],["sankey","sankey",/^\s*sankey(-beta)?/],["packet","packet",/^\s*packet(-beta)?/],["xychart","xychart",/^\s*xychart(-beta)?/],["block","block",/^\s*block(-beta)?/],["eventmodeling","eventmodeling",/^\s*eventmodeling/],["treeView","treeView",/^\s*treeView-beta/],["radar","radar",/^\s*radar-beta/],["ishikawa","ishikawa",/^\s*ishikawa(-beta)?\b/i],["treemap","treemap",/^\s*treemap/],["railroad","railroad",/^\s*railroad-beta/i],["railroad","railroadEbnf",/^\s*railroad-ebnf-beta/i],["railroad","railroadAbnf",/^\s*railroad-abnf-beta/i],["railroad","railroadPeg",/^\s*railroad-peg-beta/i],["venn","venn",/^\s*venn-beta/],["wardley","wardley",/^\s*wardley-beta/i],["cynefin","cynefin",/^\s*cynefin-beta(?:[\s:]|$)/],["usecase","usecase",/^\s*usecase-beta(?:\s|$)/]];function r(e){for(let[r,a,i]of t)if(i.test(e))return{type:r,mermaidType:a};return null}var a,i=class extends Error{code;type;mermaidType;line;column;snippet;constructor(e,t="syntax",r={}){super(e),this.name="PeleError",this.code=t,this.type=r.type??null,this.mermaidType=r.mermaidType??null,this.line=r.line??0,this.column=r.column??0,this.snippet=r.snippet??""}};function l(e,t,r){return Array.from(e.matchAll(t),e=>[e.index,e.index+e[0].length,r])}function n(e,t){let r=0;for(let[a,i,l]of e){let e=a-r;if(t<e)break;if(t<e+l)return a+Math.min(t-e,i-a-1);r+=i-a-l}return t+r}function s(e,t){for(let r=e.length-1;r>=0;r--)t=n(e[r],t);return t}function o(e,t){return void 0!==a&&e===a.parsed?a.find(t):[e,t]}function h(e,t){let r=e.trimEnd().length;r>0&&t>=r?([e,t]=o(e,r-1),t++):[e,t]=o(e,t);let a=1,i=0;for(let r=e.indexOf("\n");-1!==r&&r<t;r=e.indexOf("\n",r+1))a++,i=r+1;let l=e.indexOf("\n",t);-1===l&&(l=e.length);let n=t-i+1;return{line:a,column:n,snippet:e.slice(i,l)+"\n"+"-".repeat(n-1)+"^"}}function c(e,t,r,a,l=!1){let n=h(t,r),s=l?`Lexical error on line ${n.line}. Unrecognized text.`:`Parse error on line ${n.line}:`,o=l?`${s}\n${n.snippet}`:`${s}\n${n.snippet}\n${a}`;return new i(o,"syntax",{type:e,...n})}var d;function f(e,t){return e>0&&e<=1114111&&(e<55296||e>57343)?String.fromCodePoint(e):t}var u=/&(?:#(\d+)|#[xX]([0-9a-fA-F]+)|(\w+));/g;var p=/fl°°?(\w+)¶ß/g;function g(e){return e.includes("¶ß")?e.replace(p,"#$1;"):e}function m(e){return e.includes("¶ß")&&(e=function(e){let t="",r=0,a=e.indexOf("fl°");for(;-1!==a;){let i=e.indexOf("¶",a+2);if(-1===i)break;if("ß"===e[i+1]){let l="°"===e[a+2];t+=e.slice(r,a)+(l?"&#":"&")+e.slice(a+(l?3:2),i)+";",r=i+2}a=e.indexOf("fl°",i+1)}return 0===r?e:t+e.slice(r)}(e)),e.includes("&")&&(e=e.replace(u,(e,t,r,a)=>t?f(Number(t),e):r?f(parseInt(r,16),e):function(e){if(!d){d=new Map;for(let e of"amp:38,lt:60,gt:62,quot:34,apos:39,nbsp:160,shy:173,iexcl:161,cent:162,pound:163,curren:164,yen:165,sect:167,copy:169,laquo:171,not:172,reg:174,deg:176,plusmn:177,sup2:178,sup3:179,micro:181,para:182,middot:183,sup1:185,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,times:215,divide:247,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,euro:8364,trade:8482,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,radic:8730,infin:8734,and:8743,or:8744,cap:8745,cup:8746,int:8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830,check:10003,cross:10007,AMP:38,LT:60,GT:62,QUOT:34,lsqb:91,rsqb:93,lcub:123,rcub:125,verbar:124,VerticalLine:124,midast:42,DiacriticalGrave:96,Hat:94,UnderBar:95,equals:61,colon:58,semi:59,num:35,percnt:37,lpar:40,rpar:41,lbrack:91,rbrack:93,lbrace:123,rbrace:125,vert:124,sol:47,bsol:92,quest:63,excl:33,ast:42,plus:43,comma:44,period:46,dollar:36,commat:64,grave:96,hat:94,lowbar:95,tilde:126,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969".split(",")){let t=e.indexOf(":");d.set(e.slice(0,t),String.fromCodePoint(Number(e.slice(t+1))))}}return d.get(e)}(a)??e)),e}var y,x=new Map;function w(e){if(void 0===y)return"";let t=x.get(e);return void 0===t&&(t=y(e)??"",x.set(e,t)),t}var $,b=new Map;function M(e){return Number.isFinite(e)&&e>0}function v(e,t){if(void 0===$)return;let r=t+"\n"+e;if(b.has(r))return b.get(r);let a=$(e,t)??void 0,i=a&&M(a.width)&&M(a.height)&&"string"==typeof("svg"in a?a.svg:a.html)?a:void 0;return b.set(r,i),i}var k=class{constructor(e){this.message=e}message};function A(e,t,r){"__proto__"===t?Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0}):e[t]=r}var T=class{lines;i=0;constructor(e){this.lines=(e.includes("\r")?e.replace(/\r\n?/g,"\n"):e).split("\n")}skipBlank(){for(;this.i<this.lines.length;){let e=this.lines[this.i].trim();if(""!==e&&"#"!==e[0]&&"---"!==e)break;this.i++}}indent(){let e=this.lines[this.i],t=0;for(;t<e.length&&" "===e[t];)t++;if("\t"===e[t])throw new Error("YAML: tabs are not allowed for indentation");return t}},C=/^[-+]?(?:0|[1-9][0-9]*)$/,E=/^[-+]?0x[0-9a-fA-F]+$/,_=/^[-+]?0o[0-7]+$/,S=/^[-+]?0b[01]+$/,I=/^[-+]?(?:[0-9][0-9]*(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?$/,N=/[\s#:,[\]{}&*!|>'"%@`]/;function D(e){return" "===e||"\t"===e||"\n"===e||"\r"===e}function R(e){let t,r,a=e[0];if('"'===a||"'"===a){let i=1;for(;;){if(i>=e.length)return null;let t=e[i];if('"'===a&&"\\"===t)i+=2;else if(t===a){if('"'===a||"'"!==e[i+1])break;i+=2}else i++}for(t=i+1,r=t;D(e[r]);)r++;if(":"!==e[r])return null}else{if(void 0===a||N.test(a)||"-"===a&&(e.length<2||D(e[1])||":"===e[1]||"#"===e[1]))return null;for(r=1;r<e.length&&":"!==e[r]&&"#"!==e[r];)r++;if(":"!==e[r])return null;for(t=r;D(e[t-1]);)t--}let i=r+1;if(i<e.length&&!D(e[i]))return null;for(;D(e[i]);)i++;return{key:e.slice(0,t),length:i}}function L(e){let t=e.trim();if(""===t||"~"===t||"null"===t||"Null"===t||"NULL"===t)return null;if("true"===t||"True"===t||"TRUE"===t)return!0;if("false"===t||"False"===t||"FALSE"===t)return!1;let r=t[0];if("-"!==r&&"+"!==r&&"."!==r&&(r<"0"||r>"9"))return t;if(C.test(t)||I.test(t))return Number(t);if(E.test(t)||_.test(t)||S.test(t)){let e="-"===t[0],r=Number(e||"+"===t[0]?t.slice(1):t);return e?-r:r}return/^[-+]?\.(?:inf|Inf|INF)$/.test(t)?"-"===t[0]?-1/0:1/0:/^\.(?:nan|NaN|NAN)$/.test(t)?NaN:t}var O={0:"\0",a:"",b:"\b",t:"\t",n:"\n",v:"\v",f:"\f",r:"\r",e:""," ":" ",'"':'"',"/":"/","\\":"\\",N:"…",_:" ",L:"\u2028",P:"\u2029"};function F(e){if(!e.includes("\n"))return e;let t=e.split("\n"),r=t.length-1;for(let e=0;e<=r;e++){let a=t[e],i=0,l=a.length;if(e>0)for(;i<l&&(32===a.charCodeAt(i)||9===a.charCodeAt(i));)i++;if(e<r)for(;l>i&&(32===a.charCodeAt(l-1)||9===a.charCodeAt(l-1));)l--;t[e]=a.slice(i,l)}return t.join("\n").replace(/\n+/g,e=>1===e.length?" ":"\n".repeat(e.length-1))}function z(e){if(!e.includes("\\"))return F(e);let t="",r=F(e.replace(/\\\n[ \t]*/g,""));for(let e=0;e<r.length;e++){let a=r[e];if("\\"!==a){t+=a;continue}let i=r[++e];if("x"===i||"u"===i||"U"===i){let a="x"===i?2:"u"===i?4:8;t+=String.fromCodePoint(parseInt(r.slice(e+1,e+1+a),16)),e+=a}else{if(!(i in O))throw new Error("YAML: unknown escape sequence");t+=O[i]}}return t}function W(e,t,r){for(;t<e.length;){let a=e[t];if(" "===a||"\n"===a||"\t"===a||"\r"===a||r)t++;else{if("#"!==a||0!==t&&!/\s/.test(e[t-1]))break;{let r=e.indexOf("\n",t);t=-1===r?e.length:r}}}return t}function P(e,t){if(!t)throw new Error("YAML: missed comma between flow collection entries");if(","===e)throw new Error("YAML: expected the node content, but found ','")}function B(e,t,r,a=0){if(a>64)throw new Error("YAML: nesting is too deep");let i=e[t=W(e,t,!1)];if("{"===i){let r={};t++;let i=!0;for(;;){if((t=W(e,t,!1))>=e.length)throw new k("YAML: unexpected end of the stream within a flow collection");if("}"===e[t])return[r,t+1];let l;P(e[t],i),[l,t]=B(e,t,":,}",a+1);let n=null;":"===e[t=W(e,t,!1)]&&([n,t]=B(e,t+1,",}",a+1)),A(r,String(l),n),i=","===e[t=W(e,t,!1)],i&&t++}}if("["===i){let r=[];t++;let i=!0;for(;;){if((t=W(e,t,!1))>=e.length)throw new k("YAML: unexpected end of the stream within a flow collection");if("]"===e[t])return[r,t+1];let l;P(e[t],i),[l,t]=B(e,t,",]",a+1),r.push(l),i=","===e[t=W(e,t,!1)],i&&t++}}if('"'===i){let r=t+1;for(;r<e.length&&'"'!==e[r];)r+="\\"===e[r]?2:1;if(r>=e.length)throw new k("YAML: unexpected end of the stream within a double quoted scalar");return[z(e.slice(t+1,r)),r+1]}if("'"===i){let r=t+1;for(;r<e.length;){if("'"===e[r]){if("'"!==e[r+1])break;r++}r++}if(r>=e.length)throw new k("YAML: unexpected end of the stream within a single quoted scalar");return[F(e.slice(t+1,r)).replace(/''/g,"'"),r+1]}let l=t;for(;l<e.length;){let a=e[l];if(r.includes(a)&&(":"!==a||l+1>=e.length||/[\s,[\]{}]/.test(e[l+1])))break;if("#"===a&&l>t&&/\s/.test(e[l-1])){let r=e.indexOf("\n",l);return[L(F(e.slice(t,l).trim())),-1===r?e.length:r]}l++}return[L(F(e.slice(t,l).trim())),l]}function H(e){let t="";for(let r=0;r<e.length;r++){let a=e[r];if(t)"\\"===a&&'"'===t?r++:a===t&&(t="");else if('"'===a||"'"===a)t=a;else if("#"===a&&(0===r||" "===e[r-1]||"\t"===e[r-1]))return e.slice(0,r)}return e}function Y(e,t,r){let a=t[0];if(("|"===a||">"===a)&&/^[|>][-+0-9]*\s*(?:#.*)?$/.test(t))return function(e,t,r){let a=">"===t[0],i=t.includes("-")?"-":t.includes("+")?"+":"",l=/[1-9]/.exec(t),n=l?r+Number(l[0]):-1,s=[];for(;e.i<e.lines.length;){let t=e.lines[e.i];if(""===t.trim()){s.push(""),e.i++;continue}let a=t.length-t.trimStart().length;if(-1===n){if(a<=r)break;n=a}if(a<n)break;s.push(t.slice(n)),e.i++}let o,h=0;for(;s.length>0&&""===s[s.length-1];)s.pop(),h++;if(a){o="";for(let e=0;e<s.length;e++){let t=s[e];if(e>0){let r=s[e-1];""===t?o+="\n":""!==r&&(o+=/^[ \t]/.test(r)||/^[ \t]/.test(t)?"\n":" ")}o+=t}}else o=s.join("\n");return 0===s.length?"+"===i?"\n".repeat(h):"":"-"===i?o:"+"===i?o+"\n".repeat(h+1):o+"\n"}(e,t,r);if("{"===a||"["===a||'"'===a||"'"===a){let r=e.i,a=t,i=0,l=1;for(;;)try{let[t,i]=B(a,0,""),l=0;for(let e=a.indexOf("\n");-1!==e&&e<i;e=a.indexOf("\n",e+1))l++;let n=a.indexOf("\n",i);if(""!==H(a.slice(i,-1===n?a.length:n)).trim())throw new Error("YAML: unexpected content after a value");return e.i=r+l,t}catch(t){if(!(t instanceof k))throw t;if(r+i>=e.lines.length)throw new Error(t.message);let n=e.lines.slice(r+i,r+i+l);a+="\n"+n.join("\n"),i+=n.length,l*=2}}let i=H(t).trim();for(;e.i<e.lines.length;){let t=e.lines[e.i];if(""===t.trim()){let t=e.i;for(;t<e.lines.length&&""===e.lines[t].trim();)t++;if(t>=e.lines.length||e.lines[t].length-e.lines[t].trimStart().length<=r)break;i+="\n".repeat(t-e.i),e.i=t;continue}if(t.length-t.trimStart().length<=r)break;let a=H(t).trim();i+=(i.endsWith("\n")?"":" ")+a,e.i++}return L(i)}function G(e,t,r=0){if(r>64)throw new Error("YAML: nesting is too deep");if(e.skipBlank(),e.i>=e.lines.length)return null;let a=e.indent();if(a<t)return null;let i=e.lines[e.i].slice(a);if("-"===i||i.startsWith("- ")){let t=[];for(;e.i<e.lines.length&&(e.skipBlank(),!(e.i>=e.lines.length||e.indent()!==a));){let i=e.lines[e.i].slice(a);if("-"!==i&&!i.startsWith("- "))break;let l=i.slice(1),n=l.length-l.trimStart().length+1,s=H(l).trim();""===s?(e.i++,t.push(G(e,a+1,r+1))):null!==R(s)?(e.lines[e.i]=" ".repeat(a+n)+l.trimStart(),t.push(G(e,a+n,r+1))):(e.i++,t.push(Y(e,l.trim(),a)))}return t}if(null===R(i))return e.i++,Y(e,i.trim(),a-1);let l={};for(;e.i<e.lines.length&&(e.skipBlank(),!(e.i>=e.lines.length));){let t=e.indent();if(t<a)break;if(t>a)throw new Error("YAML: bad indentation of a mapping entry");let i=e.lines[e.i].slice(a),n=R(i);if(!n)throw new Error("YAML: can not read a block mapping entry");let s=String(B(n.key,0,"")[0]),o=i.slice(n.length);if(e.i++,""===H(o).trim())if(e.skipBlank(),e.i<e.lines.length){let t=e.indent(),i=e.lines[e.i].slice(t),n="-"===i||i.startsWith("- ");A(l,s,t>a||n&&t===a?G(e,n?a:a+1,r+1):null)}else A(l,s,null);else A(l,s,Y(e,o.trim(),a))}return l}function U(e){let t=e.trim();if("{"===t[0]||"["===t[0])try{let[e,r]=B(t,0,"");if(W(t,r,!1)===t.length)return e}catch(e){throw e instanceof k?new Error(e.message):e}let r=new T(e),a=G(r,0);if(r.skipBlank(),r.i<r.lines.length&&"..."!==r.lines[r.i].trim())throw new Error("YAML: end of the stream or a document separator is expected");return a}function q(e){return e<128?32===e||e>=9&&e<=13:160===e||5760===e||e>=8192&&e<=8202||8232===e||8233===e||8239===e||8287===e||12288===e||65279===e}function j(e){return 32===e||9===e}function V(e){return 10===e||13===e||8232===e||8233===e}function X(e){return e>=48&&e<=57}function K(e){return e>=65&&e<=90||e>=97&&e<=122}function Z(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function Q(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||95===e}var J=/^\s*%%(?!{)[^\n]+\n?/gm,ee=/%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,te=/<(\w+)([^>]*)>/g,re=/="([^"]*)"/g,ae=new Set(["__proto__","constructor","prototype"]);function ie(e,t,r){return r?.push(l(e,t,0)),e.replace(t,"")}function le(e,t){e.includes("%%")&&(e=ie(e,J,t));let r=e.trimStart();return t?.push([[0,e.length-r.length,0]]),r}function ne(e){return e.includes("\r")?e.replace(/\r\n?/g,"\n"):e}function se(e){return"\n"===e||"\r"===e}function oe(e){return void 0!==e&&/\s/.test(e)}function he(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ce(e,t){for(let r of Object.keys(t)){if(ae.has(r))continue;let a=t[r],i=e[r];he(a)&&he(i)?ce(i,a):he(a)?e[r]=ce({},a):e[r]=a}return e}function de(e,t){let r=ne(e),a=r.includes("<")?r.lastIndexOf(">"):-1;a>0&&(r=r.slice(0,a+1).replace(te,(e,t,r)=>"<"+t+r.replace(re,"='$1'")+">")+r.slice(a+1));let l,n={},s=0,o=r.includes("---")?function(e){let t=0;for(;t<e.length&&oe(e[t])&&!se(e[t]);)t++;let r=e.slice(0,t);if(!e.startsWith("---",t))return;let a=[];for(let r=t+3;r<e.length&&oe(e[r]);r++)se(e[r])&&a.push(r);if(0===a.length)return;let i=r+"---",l=t=>{if(!se(e[t])||!e.startsWith(i,t+1))return-1;let r=-1;for(let a=t+1+i.length;a<e.length&&oe(e[a]);a++)se(e[a])&&(r=a);return r},n="\n"+i,s=-1;for(let t=e.lastIndexOf(n);t>a[0];t=e.lastIndexOf(n,t-1))if(-1!==l(t)){s=t;break}if(-1===s)return;let o=a[0];for(let e of a)e<s&&(o=e);let h=o+1,c=h>0?h-1:0;for(let t=e.indexOf(n,c);-1!==t&&t<=s;t=e.indexOf(n,t+1)){if(t<h)continue;let a=l(t);if(-1!==a)return{indent:r,body:e.slice(h,t),length:a+1}}}(r):void 0;if(o){let e,a=o.indent?o.body.split("\n").map(e=>e.startsWith(o.indent)?e.slice(o.indent.length):e).join("\n"):o.body;try{e=U(a)}catch(e){throw new i(`Front matter is not valid YAML. ${e.message}`,"syntax")}if(he(e)&&(e.title&&(l=String(e.title)),he(e.config)&&ce(n,e.config),e.displayMode)){(he(n.gantt)?n.gantt:n.gantt={}).displayMode=String(e.displayMode)}for(let e=r.indexOf("\n");-1!==e&&e<o.length;e=r.indexOf("\n",e+1))s++;r=r.slice(o.length),t?.push([[0,o.length,0]])}return r=function(e,t,r){if(!e.includes("%%{"))return e;let a,i=e.trim().replace(/'/g,'"');for(ee.lastIndex=0;null!==(a=ee.exec(i));){a.index===ee.lastIndex&&ee.lastIndex++;let e=a[1]??a[2];if("wrap"===e)t.wrap=!0;else if(("init"===e||"initialize"===e)&&a[4])try{let e=JSON.parse(a[4].trim());he(e)&&ce(t,e)}catch{}}return ee.lastIndex=0,ie(e,ee,r)}(r,n,t),{text:le(r),title:l,config:n,withComments:r,lineOffset:s}}var fe=/#\w+;/g,ue=/^\+?\d+$/,pe=new RegExp("[\\n\\r\u2028\u2029]","g");function ge(e){if(void 0===e)return;let t=[];return e.push(t),t}function me(e,t,r){let a=ge(r),i=e.indexOf(t);if(-1===i)return e;let l="",n=0;for(;-1!==i;){pe.lastIndex=i;let r=pe.test(e)?pe.lastIndex-1:e.length,s=!1,o=-1;for(let a=i+t.length;a<r;a++){let t=e.charCodeAt(a);if(58===t)s=!0;else if(35===t){if(s){o=a;break}}else q(t)&&(s=!1)}if(-1!==o){let t=e.lastIndexOf(";",r-1);t>o&&(a?.push([t,t+1,0]),l+=e.slice(n,t),n=t+1)}i=r>=e.length?-1:e.indexOf(t,r+1)}return 0===n?e:l+e.slice(n)}function ye(e,t){if(!e.includes("#"))return e;e=me(me(e,"style",t),"classDef",t);let r=ge(t);return e.replace(fe,(e,t)=>{let a=e.substring(1,e.length-1),i=(ue.test(a)?"fl°°":"fl°")+a+"¶ß";return r?.push([t,t+e.length,i.length]),i})}var xe,we;function $e(e){let t=new Uint16Array(95);for(let r=0;r<95;r++)t[r]=parseInt(e.substr(2*r,2),36);return t}function be(e){return e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=55296&&e<=56319}function Me(e){return 173===e||e>=768&&e<=879||e>=8203&&e<=8207||e>=56320&&e<=57343||e>=65024&&e<=65039||65279===e}var ve={width(e,t,r){let a=!!(4&r),i=24&r?t/1.2:t,l=1&r?we??=$e("7q99d6fgfgopk26m9999atg87q997q7qfgfgfgfgfgfgfgfgfgfg9999g8g8g8gzr3k2k2k2k2ijgzlmk27qfgk2gzn5k2lmijlmk2ijgzk2ijq8ijijgz997q99g8fg99fggzfggzfg99gzgz7q7qfg7qopgzgzgzgzatfg99gzfglmfgfgdwat7satg8"):xe??=$e("7q7q9vfgfgopij5b9999atg87q997q7qfgfgfgfgfgfgfgfgfgfg7q7qg8g8g8fgs7ijijk2k2ijgzlmk27qdwijfgn5k2lmijlmk2ijgzk2ijq8ijijgz7q7q7qd1fg99fgfgdwfgfg7qfgfg6666dw66n5fgfgfgfg99dw7qfgdwk2dwdwdw9a789ag8"),n=0;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(!(r<32))if(r<127)n+=a?600:l[r-32];else{if(Me(r))continue;be(r)?n+=a?1200:1e3:n+=a?600:580}}return n*i/1e3}};function ke(){let e=globalThis;return e.document?.fonts??e.fonts}function Ae(e,t="monospace"){let r=function(){let e=globalThis;try{if(e.OffscreenCanvas)return new e.OffscreenCanvas(1,1).getContext("2d");if(e.document)return e.document.createElement("canvas").getContext("2d")}catch{return null}return null}();if(!r)return null;let a=new Map,i="",l=ke()?.size;return{width(n,s,o){let h=ke();h?.size!==l&&(l=h?.size,a.clear());let c=(2&o?"italic ":"")+(1&o?"bold ":"")+(24&o?s/1.2:s)+"px "+(4&o?t:e),d=a.get(c);d||a.set(c,d=new Map);let f=d.get(n);return void 0===f&&(c!==i&&(r.font=i=c),f=r.measureText(n).width,function(e,t,r){try{return e?.check(t,r)??!0}catch{return!0}}(h,c,n)&&(d.size>=2e4&&d.clear(),d.set(n,f))),f}}}var Te=new Map;function Ce(e="sans-serif",t="monospace"){let r=e+"\n"+t,a=Te.get(r);return a||(a=Ae(e,t)??ve,Te.set(r,a)),a}function Ee(){Te.clear()}var _e=/[&<>"\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]/u,Se=/[&<>"]|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]+/gu,Ie={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},Ne=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]/u;function De(e){return _e.test(e)?e.replace(Se,e=>Ie[e]??""):e}function Re(e){return De(m(e))}var Le=[];for(let e=0;e<100;e++)Le.push(0===e?"":e%10==0?"."+e/10:"."+(e<10?"0"+e:e));function Oe(e){let t=Math.round(100*e);if(0===t)return"0";if(t>0){if(t<1e11){let e=Math.floor(t/100);return e+Le[t-100*e]}}else if(t>-1e11){let e=-t,r=Math.floor(e/100);return"-"+r+Le[e-100*r]}return String(t/100)}function Fe(e,t,r,a,i){let l=e.lines;if(0===l.length)return"";let n=e.lineHeight,s=e.heights,o=.35*e.size,h=r-e.height/2,c=1===l.length&&1===l[0].length?l[0][0]:void 0;if(c&&void 0===c.icon&&void 0===c.math&&0===c.style)return`<text${a} x="${Oe(t)}" y="${Oe(h+n/2+o)}" text-anchor="middle">${De(c.text)}</text>`;let d,f=Qe(e),u=a;a=Je(a,f);let p="",g="";for(let r=0;r<l.length;r++){let a=l[r],c=s?s[r]:n,m=h+c/2,y=m+o,x=!1;for(let e of a)(void 0!==e.icon||e.math)&&(x=!0);if(x){let l=t-e.widths[r]/2;for(let t of a){if(t.math){let r=`x="${Oe(l)}" y="${Oe(m-t.math.height/2)}" width="${Oe(t.math.width)}" height="${Oe(t.math.height)}"`;d??=Ye(u),g+=void 0===d.halo?Ge(t.math,r,e.size,d.attrs):`<rect ${r} rx="2" fill="${d.halo}"/>`}else if(void 0!==t.icon){let r=1.1*e.size,a=i?.(t.icon)??"";g+=`<svg class="pele-icon" data-icon="${Re(t.icon)}" x="${Oe(l)}" y="${Oe(m-r/2)}" width="${Oe(r)}" height="${Oe(r)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${a}</svg>`}else""!==t.text&&(p+=`<tspan x="${Oe(l)}" y="${Oe(y)}" text-anchor="start"${Ze(t.style&~f)}>${De(t.text)}</tspan>`);l+=t.width}}else{for(let e=0;e<a.length;e++){let r=a[e];p+=`<tspan${0===e?` x="${Oe(t)}" y="${Oe(y)}"`:""}${Ze(r.style&~f)}>${De(r.text)}</tspan>`}0===a.length&&(p+=`<tspan x="${Oe(t)}" y="${Oe(y)}"> </tspan>`)}h+=c}return`<text${a} text-anchor="middle" xml:space="preserve">${p}</text>${g}`}var ze=/ fill="([^"]*)"/,We=/ stroke="([^"]*)"/,Pe=/ style="([^"]*)"/,Be=/(?:^|;)\s*fill:([^;]*)/,He=/(?:^|;)\s*opacity:([^;]*)/;function Ye(e){let t=Pe.exec(e)?.[1]??"",r=(Be.exec(t)?.[1]??ze.exec(e)?.[1]??"").trim();if("none"===r)return{attrs:"",halo:We.exec(e)?.[1]??"none"};let a=He.exec(t)?.[1].trim();return{attrs:(""===r?"":` color="${r}"`)+(a?` opacity="${a}"`:"")}}function Ge(e,t,r,a){return"svg"in e?`<svg class="pele-math" ${t} overflow="visible"${a}>${e.svg}</svg>`:`<foreignObject class="pele-math" ${t} overflow="visible"${a}><div xmlns="http://www.w3.org/1999/xhtml" style="display:flex;align-items:center;justify-content:center;width:100%;height:100%;font-size:${Oe(r)}px;line-height:normal;white-space:nowrap">${e.html}</div></foreignObject>`}var Ue=' font-weight="var(--_w)"',qe=' font-style="italic"',je=' text-decoration="underline"',Ve=' font-family="var(--_fm)"',Xe=' baseline-shift="sub" font-size="smaller"',Ke=' baseline-shift="super" font-size="smaller"';function Ze(e){return(1&e?Ue:"")+(2&e?qe:"")+(4&e?Ve:"")+(32&e?je:"")+(8&e?Xe:16&e?Ke:"")}function Qe(e){let t=7,r=!1;for(let a of e.lines)for(let e of a)void 0!==e.icon||""===e.text||(t&=e.style,r=!0);return r?t:0}function Je(e,t){return e+(1&t&&!e.includes(' font-weight="')?Ue:"")+(2&t&&!e.includes(' font-style="')?qe:"")+(4&t&&!e.includes(' font-family="')?Ve:"")}var et=new Set("black blue blueviolet brown crimson darkblue darkcyan darkgreen darkmagenta darkolivegreen darkorchid darkred darkslateblue darkslategray darkviolet dimgray firebrick forestgreen green indigo maroon mediumblue mediumslateblue mediumvioletred midnightblue navy olive purple rebeccapurple royalblue saddlebrown seagreen sienna slateblue steelblue teal".split(" ")),tt=new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque blanchedalmond burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk cyan darkgoldenrod darkgray darkkhaki darkorange darksalmon darkseagreen darkturquoise deeppink deepskyblue dodgerblue floralwhite fuchsia gainsboro ghostwhite gold goldenrod gray greenyellow honeydew hotpink indianred ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightpink lightsalmon lightseagreen lightskyblue lightslategray lightsteelblue lightyellow lime limegreen linen magenta mediumaquamarine mediumorchid mediumpurple mediumseagreen mediumspringgreen mediumturquoise mintcream mistyrose moccasin navajowhite oldlace olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue red rosybrown salmon sandybrown seashell silver skyblue slategray snow springgreen tan thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ")),rt="var(--pele-fg-on-light,#1f1f1f)",at="var(--pele-fg-on-dark,#fff)",it=/[";]fill:([^;"]*)/,lt=/[";](?:fill-)?opacity:([^;"]*)/g,nt=/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,st=/^(rgba?|hsla?)\(([^()]*)\)$/i,ot=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(%|deg|grad|rad|turn)?$/i,ht=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,ct=(e,t,r)=>.2126*ht(e)+.7152*ht(t)+.0722*ht(r),dt=Math.sqrt(1.05*(ct(31/255,31/255,31/255)+.05))-.05;function ft(e,t){let r=ot.exec(e);return!r||r[1]&&"%"!==r[1]?NaN:(e=>Math.min(Math.max(e,0),1))(parseFloat(e)/(r[1]?100:t))}function ut(e){let t=e.trim().toLowerCase(),r=t.replace("grey","gray");if(et.has(r))return[0,1];if(tt.has(r))return[1,1];if(nt.test(t)){let e=t.length<6?t.slice(1).replace(/./g,"$&$&"):t.slice(1),r=t=>parseInt(e.slice(2*t,2*t+2),16)/255;return[ct(r(0),r(1),r(2)),8===e.length?r(3):1]}let a=st.exec(t),i=a?.[1].startsWith("hsl")??!1,l=a&&function(e,t){let r=e.includes(","),[a,i,l]=r?[e]:e.split("/");if(void 0!==l)return;let n=a.trim().split(r?/\s*,\s*/:/\s+/);if(r?n.length<3||n.length>4:3!==n.length)return;if(void 0!==i&&n.push(i.trim()),!r)return n.map(e=>"none"===e?"0":e);let s=n.slice(t?1:0,3).filter(e=>e.endsWith("%")).length;return s===(t?2:3)||!t&&0===s?n:void 0}(a[2],i);if(!l)return;let n,s=4===l.length?ft(l[3],1):1;if(i){let e=(function(e){let t=ot.exec(e);if(!t||"%"===t[1])return NaN;let r=t[1]?.toLowerCase(),a=parseFloat(e);return"turn"===r?360*a:"rad"===r?180*a/Math.PI:"grad"===r?.9*a:a}(l[0])%360+360)%360/30,t=ft(l[1],100),r=ft(l[2],100),a=t*Math.min(r,1-r);n=[0,8,4].map(t=>{let i=(t+e)%12;return r-a*Math.max(-1,Math.min(i-3,9-i,1))})}else n=l.slice(0,3).map(e=>ft(e,255));let o=ct(n[0],n[1],n[2]);return Number.isNaN(o+s)?void 0:[o,s]}function pt(e){let t=1;for(let[,r]of e.matchAll(lt))t*=ft(r.trim(),1);return t}var gt=new Map;function mt(e,t=""){let r=`${e}\0${t}`;if(gt.has(r))return gt.get(r);gt.size>1e3&&gt.clear();let a=function(e,t){let r=it.exec(e),a=r&&!it.test(t)?ut(r[1]):void 0;if(a&&a[1]*pt(e)>=.5)return a[0]>dt?rt:at}(e,t);return gt.set(r,a),a}function yt(e){let t=it.exec(e)?.[1].trim().toLowerCase();if(!t||"none"===t||"transparent"===t)return!1;let r=pt(e);return(ut(t)?.[1]??1)*(Number.isNaN(r)?1:r)>0}function xt(e,t){let r=mt(e.shape,e.text)??t;return r?` fill="${r}"`:""}var wt={pie:{prefix:"pie",first:1},gitGraph:{prefix:"git",first:0},timeline:{prefix:"cScale",first:0},radar:{prefix:"cScale",first:0},treemap:{prefix:"cScale",first:0},mindmap:{prefix:"cScale",first:1},venn:{prefix:"venn",first:1,repeat:!0}},$t=/^[\w\s#%.,+\-/()]{1,200}$/,bt=/([\w-]*)\s*\(/g,Mt=/var\(\s*([\w-]*)/gi,vt=new Set(["rgb","rgba","hsl","hsla","hwb","lab","lch","oklab","oklch","color","color-mix","light-dark","var"]),kt=e=>he(e)?e:{};function At(e){if("string"!=typeof e)return;let t=e.trim();if(!$t.test(t))return;if(!t.includes("("))return function(e){let t=e.trim().toLowerCase(),r=t.replace("grey","gray");return nt.test(t)||et.has(r)||tt.has(r)||"transparent"===t||"currentcolor"===t}(t)?t:void 0;let r=0;for(let e of t)if("("===e)r++;else if(")"===e&&--r<0)return;if(0===r){for(let[,e]of t.matchAll(bt))if(!vt.has(e.toLowerCase()))return;for(let[,e]of t.matchAll(Mt))if(!e.startsWith("--pele-"))return;return t}}function Tt(e){let t=[],r=0,a=0;for(let i=0;i<e.length;i++){let l=e[i];"("===l?r++:")"===l?r--:","===l&&0===r&&(t.push(e.slice(a,i)),a=i+1)}return t.push(e.slice(a)),t.map(e=>e.trim())}var Ct={style:"",inks:[]};function Et(e,t){let r=function(e,t){if("xychart"===e){let e=kt(t.xyChart).plotColorPalette;return"string"==typeof e?{list:Tt(e),repeat:!0}:void 0}let r=wt[e];if(void 0===r)return;let a=[];for(let e=0;e<8;e++)a.push(t[r.prefix+(r.first+e)]);return r.repeat&&(a=a.filter(e=>null!=e&&""!==e)),{list:a,repeat:!0===r.repeat}}(e,kt(t.themeVariables));if(void 0===r||0===r.list.length)return Ct;let{list:a,repeat:i}=r,l="",n=[];for(let e=0;e<8&&(i||!(e>=a.length));e++){let t=At(a[e%a.length]);void 0!==t&&(l+=`;--pele-series-${e+1}:${t}`,n[e]=mt(`;fill:${t}`))}return""===l?Ct:{style:De(l),inks:n}}var _t=Ct;function St(e){let t=_t.inks[(e%8+8)%8];return t?` fill="${t}"`:""}function It(e){return e.ownerDocument?.defaultView??globalThis}function Nt(e,t){let r=e.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);return r>0?r:0}var Dt=1.25,Rt={zoomIn:"M5 12h14M12 5v14",zoomOut:"M5 12h14",reset:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"},Lt={zoomIn:"Zoom in",zoomOut:"Zoom out",reset:"Reset zoom"};function Ot(e,t,r){let a,i,l,n=null,s={width:0,height:0},o={width:0,height:0},h={width:0,height:0},c=!1,d="",f={width:"",height:"",maxWidth:"",margin:"",display:""},u=null,p=0,g=0,m=0,y=0,x=()=>It(e),w=()=>s.width>0&&o.width>0?o.width/s.width:1,$=()=>Math.max(w(),t.maxScale??3),b=()=>null!==n&&s.width>0&&(!0===t.always||w()<.999),M=()=>{if(!n||0!==p)return;let t=n.getBoundingClientRect();o={width:t.width,height:t.height},h={width:Math.max(o.width,e.clientWidth),height:Math.max(o.height,e.clientHeight)},c=h.width>o.width+1||h.height>o.height+1,c||(h=o);let r=x().getComputedStyle(e);d=["Top","Right","Bottom","Left"].map(e=>-(parseFloat(r.getPropertyValue(`padding-${e.toLowerCase()}`))||0)+"px").join(" ")},v={},k=!1,A=()=>{if(!1===t.controls)return;let r=b();if(!a){if(!r)return;let i=e.ownerDocument;a=i.createElement("div"),a.className="pele pele-zoom",a.setAttribute("style","--_bg:var(--pele-bg,#fff);--_fg:var(--pele-fg,#1f1f1f);--_b:var(--pele-border,#8a8a8a);position:absolute;top:var(--pele-zoom-top,8px);right:var(--pele-zoom-right,8px);bottom:var(--pele-zoom-bottom,auto);left:var(--pele-zoom-left,auto);display:flex;flex-direction:column;gap:2px;padding:2px;width:auto;max-width:none;border:1px solid var(--_b);border-radius:var(--pele-radius,4px);background:var(--_bg);color:var(--_fg);line-height:0");let l={zoomIn:()=>I((p||w())*Dt*Dt),zoomOut:()=>I((p||w())/(Dt*Dt)),reset:()=>E()};for(let e of["zoomIn","zoomOut","reset"]){let r=i.createElement("button"),n=t.labels?.[e]??Lt[e];r.type="button",r.className="pele-zoom-"+("zoomIn"===e?"in":"zoomOut"===e?"out":"reset"),r.setAttribute("style","appearance:none;display:grid;place-items:center;width:24px;height:24px;margin:0;padding:0;border:0;border-radius:calc(var(--pele-radius,4px) - 1px);background:transparent;color:inherit;font:inherit;cursor:var(--pele-zoom-cursor,pointer)"),r.setAttribute("aria-label",n),r.title=n,r.innerHTML=`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${Rt[e]}"/></svg>`,r.addEventListener("click",l[e]),v[e]=r,a.append(r)}}r&&!k&&"static"===x().getComputedStyle(e).position&&(e.style.position="relative",k=!0),r&&a.parentNode!==e&&e.append(a),a.hidden=!r,a.style.display=r?"flex":"none";let i=(e,t)=>{e&&(e.disabled=t,e.style.opacity=t?"0.35":"",e.style.cursor=t?"default":"var(--pele-zoom-cursor,pointer)")};i(v.zoomIn,(p||w())>=.999*$()),i(v.zoomOut,0===p),v.reset&&(v.reset.style.display=0===p?"none":"grid")},T=e=>void 0!==a&&e.target instanceof x().Node&&a.contains(e.target),C=()=>{n&&(S(),n.style.width=f.width,n.style.height=f.height,n.style.maxWidth=f.maxWidth,n.style.margin=f.margin,n.style.display=f.display)},E=()=>{n&&(C(),p=0,n.setAttribute("viewBox",`0 0 ${s.width} ${s.height}`),n.style.cursor="",n.style.userSelect="",M(),n.style.touchAction=b()?"pan-y":"",b()?n.setAttribute("tabindex","0"):n.removeAttribute("tabindex"),j(b()),A(),_())},_=()=>{if(!n||!a||a.hidden)return;let t=a.getBoundingClientRect(),r=[...n.querySelectorAll("text")].some(e=>{let r=e.getBoundingClientRect();return r.right>t.left&&r.left<t.right&&r.bottom>t.top&&r.top<t.bottom}),i=n.getBoundingClientRect(),l=t.left-4;if(!r||i.right-l>=i.width/2)return;let s=e.getBoundingClientRect(),o=e.offsetWidth>0?s.width/e.offsetWidth:1,h=parseFloat(x().getComputedStyle(e).paddingRight)||0,c=s.left+(e.clientLeft+e.clientWidth-h)*o,d=[n.style.maxWidth,n.style.marginRight];n.style.maxWidth=(l-i.left)/o+"px",n.style.marginRight=Math.max(c-l,0)/o+"px",u={before:d,after:[n.style.maxWidth,n.style.marginRight]},n.getBoundingClientRect().right>l+1&&S(),M()},S=()=>{!n||!u||(n.style.maxWidth===u.after[0]&&(n.style.maxWidth=u.before[0]),n.style.marginRight===u.after[1]&&(n.style.marginRight=u.before[1]),u=null)},I=(e,t,r)=>{if(!n||(0===p&&M(),!b()))return;let a=p||w(),i=Math.min(Math.max(e,w()),$());if(i<=1.001*w())return void E();let l=n.getBoundingClientRect(),s=t??l.left+l.width/2,o=r??l.top+l.height/2,f=(p?g:0)+(s-l.left)/a,u=(p?m:0)+(o-l.top)/a;p=i;let y=l;c&&(n.style.maxWidth="none",n.style.margin=d,n.style.display="block",n.style.width=`${h.width}px`,n.style.height=`${h.height}px`,y=n.getBoundingClientRect()),N(f-(s-y.left)/p,u-(o-y.top)/p),n.style.cursor="grab",n.style.userSelect="none",n.style.touchAction="none",A()},N=(e,t)=>{if(!n)return;let r=function(e,t,r,a,i){let l=t.width/r,n=t.height/r,s=(e,t,r)=>t>=r?Math.min(Math.max(e,r-t),0):Math.min(Math.max(e,0),r-t);return{x:s(a,l,e.width),y:s(i,n,e.height),width:l,height:n}}(s,h,p,e,t);g=r.x,m=r.y,n.setAttribute("viewBox",`${g} ${m} ${r.width} ${r.height}`)},D=(e,t)=>{0!==p&&N(g-e/p,m-t/p)},R=()=>{L();let t=e.clientWidth+e.clientHeight;t!==y&&(y=t,E())},L=()=>{if(!r)return;let t=x();t!==l&&(i?.disconnect(),l=t,i=t.ResizeObserver?new t.ResizeObserver(R):void 0,i?.observe(e))},O=()=>{L(),0!==p?C():S();let t=e.firstElementChild;if(n=t&&"svg"===t.localName?t:null,p=0,!n)return a?.remove(),void j(!1);s={width:Number(n.getAttribute("width"))||0,height:Number(n.getAttribute("height"))||0},f={width:n.style.width,height:n.style.height,maxWidth:n.style.maxWidth,margin:n.style.margin,display:n.style.display},E()},F=new Map,z=!1,W=0,P=0,B=()=>{let[e,t]=[...F.values()];return{distance:Math.hypot(e.x-t.x,e.y-t.y),x:(e.x+t.x)/2,y:(e.y+t.y)/2}},H=e=>{F.delete(e.pointerId)&&(P=0,0===F.size&&n&&0!==p&&(n.style.cursor="grab"))},Y=0,G=[["pointerdown",()=>{z=!1},{capture:!0}],["pointerdown",t=>{!b()||T(t)||"mouse"===t.pointerType&&0!==t.button||(F.set(t.pointerId,{x:t.clientX,y:t.clientY}),W=0,2===F.size&&(P=B().distance),(2===F.size||0!==p)&&(e.setPointerCapture?.(t.pointerId),n&&(n.style.cursor="grabbing")))}],["pointermove",e=>{let t=F.get(e.pointerId);if(t){if(2===F.size){let t=B();F.set(e.pointerId,{x:e.clientX,y:e.clientY});let r=B();return P>0&&r.distance>0&&I((p||w())*(r.distance/t.distance),r.x,r.y),D(r.x-t.x,r.y-t.y),void(z=!0)}F.set(e.pointerId,{x:e.clientX,y:e.clientY}),0!==p&&(W+=Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y),W>4&&(z=!0),D(e.clientX-t.x,e.clientY-t.y))}}],["pointerup",H],["pointercancel",H],["click",e=>{!z||0===e.detail||(z=!1,e.preventDefault(),e.stopPropagation())},{capture:!0}],["dblclick",e=>{!b()||T(e)||(e.preventDefault(),0!==p?E():I(Math.max(1,2*w()),e.clientX,e.clientY))}],["keydown",e=>{if(!b()||T(e)||e.ctrlKey||e.metaKey||e.altKey)return;let t=e.key;if("+"===t||"="===t)I((p||w())*Dt);else if("-"===t)I((p||w())/Dt);else{if(0===p)return;if("0"===t||"Escape"===t)E();else if("ArrowLeft"===t)D(48,0);else if("ArrowRight"===t)D(-48,0);else if("ArrowUp"===t)D(0,48);else{if("ArrowDown"!==t)return;D(0,-48)}}e.preventDefault()}],["focusin",e=>{if(!n||e.target!==n)return;let t=!0;try{t=n.matches(":focus-visible")}catch{}n.style.outline=t?"":"none"}]];for(let[t,r,a]of G)e.addEventListener(t,r,a);let U=[["wheel",e=>{if(!e.ctrlKey&&!e.metaKey||!b())return;e.preventDefault(),0===p&&M();let t=Math.min(Math.max(-e.deltaY,-24),24);I((p||w())*2**(.02*t),e.clientX,e.clientY)},{passive:!1}],["gesturestart",e=>{b()&&(e.preventDefault(),0===p&&M(),Y=p||w())},{passive:!1}],["gesturechange",e=>{if(0===Y)return;e.preventDefault();let{scale:t,clientX:r,clientY:a}=e;I(Y*t,r,a)},{passive:!1}],["gestureend",()=>{Y=0},{passive:!1}]],q=!1;function j(t){if(t!==q){q=t;for(let[r,a,i]of U)t?e.addEventListener(r,a,i):e.removeEventListener(r,a,i);t||(Y=0)}}return y=e.clientWidth+e.clientHeight,O(),{get scale(){return p||w()},get fit(){return w()},zoomBy(e){I((p||w())*e)},zoomTo(e){I(e)},reset:E,refresh:O,resized:R,destroy(){E(),S(),n&&(n.style.touchAction="",n.removeAttribute("tabindex")),a?.remove(),k&&(e.style.position=""),i?.disconnect(),j(!1);for(let[t,r,a]of G)e.removeEventListener(t,r,a)}}}function Ft(e,t){let r=t?It(t).getComputedStyle(t):e;return{family:r.getPropertyValue("--pele-font").trim()||e.fontFamily||void 0,mono:r.getPropertyValue("--pele-font-mono").trim()||void 0}}var zt=new WeakMap;function Wt(e){let t=zt.get(e);return t||(t=e.ready.then(()=>{zt.delete(e),Ee()}),zt.set(e,t)),t}var Pt=new WeakMap;var Bt=new WeakMap,Ht=0,Yt=Math.random().toString(36).slice(2,7);function Gt(e,t,r,a={}){Bt.get(t)?.destroy();let i,l,n,s,o,h,c,d,f,u,p,g=r,m=a,y=!1,x=`pele-${Yt}-${++Ht}`,w={},$=-1,b=!1,M=!1,v=!1,k=(r,a)=>{let{onRender:l,onError:n,sanitize:o,...c}=m,d={...c,idPrefix:c.idPrefix??x,fontFamily:c.fontFamily??w.family,fontFamilyMono:c.fontFamilyMono??w.mono,maxWidth:void 0};a&&(s=e.render(i,d),h=void 0);let f=m.maxWidth??Nt(t,r);return $=f,f>0&&f<s.width&&(h??=e.render(i,{...d,maxWidth:1}).svg!==s.svg,h)?e.render(i,{...d,maxWidth:f}):s},A=e=>{m.sanitize?t.replaceChildren(m.sanitize(e)):t.innerHTML=e},T=()=>{let e=o?t.firstElementChild:null;if(e?.style&&(e.style.opacity=void 0===n?"":"0.4"),void 0===n)return c?.remove(),void(c=void 0);let r=t.ownerDocument;if(!r)return;c??=r.createElement("div"),c.className="pele pele-error";let a=function(e){return e instanceof Error?e.message:String(e)}(n);e?(c.textContent=function(e){let t=e.split("\n").filter(e=>""!==e.trim());return t.length>1?`${t[0]} ${t[t.length-1]}`:t[0]??""}(a),c.title=a,c.setAttribute("style","position:relative;height:1.3em;margin-top:-1.3em;line-height:1.3;font-size:0.8em;color:var(--pele-error,#e45756);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"),c.parentNode!==t&&t.append(c)):(c.textContent=a,c.removeAttribute("title"),c.setAttribute("style","margin:0;font-size:0.8em;font-family:var(--pele-font-mono,monospace);color:var(--pele-error,#e45756);white-space:pre-wrap;"),t.replaceChildren(c))},C=e=>{n=e,T(),m.onError?.(e)},E=()=>{if(M||v)return;let e=function(e){return[...new Set([e.ownerDocument?.fonts,globalThis.document?.fonts])].filter(e=>void 0!==e)}(t).filter(e=>"loading"===e.status);0!==e.length&&(M=!0,function(e,t){Promise.all(e.map(Wt)).then(()=>{let e=t.deref();e&&Pt.get(e)?.()})}(e,new WeakRef(L)))},_=(e,r=!e)=>{let a,c=It(t).getComputedStyle(t),f=t.firstElementChild??null,u={fonts:w,natural:s,adapts:h,drawnFor:$,stale:b};try{if(e&&(w=Ft(c,f),b=!1===t.isConnected),a=k(c,e),r&&a.svg===o?.svg)return e&&(l=i),void(y&&void 0!==n&&(n=void 0,T()));A(a.svg)}catch(e){throw({fonts:w,natural:s,adapts:h,drawnFor:$,stale:b}=u),e}if(e&&(l=i),e&&!f&&t.firstElementChild){let e=Ft(c,t.firstElementChild);if(e.family!==w.family||e.mono!==w.mono){let t={fonts:w,natural:s,adapts:h,drawnFor:$};w=e;try{let e=k(c,!0);A(e.svg),a=e}catch{({fonts:w,natural:s,adapts:h,drawnFor:$}=t)}}}o=a,y&&(n=void 0),T(),d?.refresh(),E(),m.onRender?.(a)},S=!1,I=()=>{let e=m.zoom??"auto";e!==S&&(d?.destroy(),S=e,d=!1===e?void 0:Ot(t,"object"==typeof e?e:{always:!0===e},!1))},N=()=>{if(v||(R(),!(i&&!1!==t.isConnected&&t.clientWidth>0)))return;let e=It(t).getComputedStyle(t),r=Ft(e,t.firstElementChild??null);try{if(b||r.family!==w.family||r.mono!==w.mono)_(!0,!0);else if(!1!==h&&void 0===m.maxWidth){let r=Nt(t,e);r!==$&&r!==o?.width&&_(!1)}}catch(e){b=!1,y&&(n=e),i!==l&&(i=l,y=!1),T(),m.onError?.(e)}d?.resized(),E()},D=()=>{void 0!==p&&f?.cancelAnimationFrame(p),p=void 0},R=()=>{let e=It(t);e!==f&&(u?.disconnect(),D(),f=e,u=e.ResizeObserver?new e.ResizeObserver(()=>{if(void 0===p){if(!e.requestAnimationFrame)return N();p=e.requestAnimationFrame(()=>{p=void 0,N()})}}):void 0,u?.observe(t))},L={get result(){return o},get source(){return g},get error(){return n},get zoom(){return d},update(r,a=m){let n=!y||r!==g||a.limit!==m.limit||a.maxEdges!==m.maxEdges||a.config!==m.config;g=r,m=a;let s=i;if(n)try{s=e.parse(r,a)}catch(e){return y=!1,C(e),void I()}let h=o;if(i=s,y=!0,!1!==t.isConnected&&!(t.clientWidth>0))return b=!0,void I();try{_(!0)}catch(e){if(o!==h)throw I(),e;i=l,y=!1,C(e)}I()},refresh:N,destroy(){v=!0,u?.disconnect(),u=void 0,D(),f=void 0,d?.destroy(),Pt.delete(L),Bt.get(t)===L&&Bt.delete(t)}};Pt.set(L,()=>{M=!1,b=!0,N()});try{i=e.parse(r,a),y=!0,_(!0)}catch(e){if(o)throw e;i=l,y=!1,C(e)}return I(),R(),Bt.set(t,L),L}var Ut=new Map;function qt(...e){for(let t of e)Ut.set(t.type,t)}function jt(e){try{return e()}catch(e){throw e instanceof RangeError?new i("Diagram is nested too deeply.","limit"):e}}function Vt(e,t){try{return t()}catch(t){if(t instanceof RangeError)throw new i("Diagram is nested too deeply.","limit",e);if(t instanceof i){t.type??=e.type,t.mermaidType??=e.mermaidType;let r=g(t.message);r!==t.message&&(t.stack=t.stack?.replace(t.message,()=>r),t.message=r),t.snippet=g(t.snippet)}throw t}}var Xt=new WeakMap;function Kt(e,t=5e4,l=5e3,n){if(e.length>t)throw new i(`Diagram source is longer than the limit of ${t} characters.`,"limit");let s=de(e),o=r(s.text);if(null===o)throw new i("No diagram type detected for the given text.","unsupported-diagram");let h=Ut.get(o.type);if(void 0===h)throw new i(`Diagram type "${o.type}" is not supported yet.`,"unsupported-diagram",o);let c=n?{...n,...s.config}:s.config,d=!0===h.keepComments,f=ye(d?s.withComments:s.text)+"\n",u=Vt(o,()=>function(e,t){let r=a;a=e;try{return t()}finally{a=r}}({parsed:f,find:Zt(e,d)},()=>h.parse(f,c,s.title,s.lineOffset,{maxEdges:l})));return{...o,diagram:h,model:u,config:c}}function Zt(e,t){let r,a="";return i=>{if(void 0===r){r=[];let i=de(e,r);ye(t?i.withComments:le(i.withComments,r),r),a=ne(e)+"\n"}return[a,s(r,i)]}}function Qt(e){return r(de(e).text)?.type??null}function Jt(e,t={}){return jt(()=>{let r=Kt(e,t.limit,t.maxEdges,t.config),a=r.model;return Object.defineProperty(a,"mermaidType",{value:r.mermaidType,enumerable:!0}),Xt.set(a,r),a})}function er(e,t={}){return jt(()=>{let{type:r,mermaidType:a,diagram:l,model:n,config:s}=function(e,t){if("string"==typeof e)return Kt(e,t.limit,t.maxEdges,t.config);let r=Xt.get(e);if(void 0===r)throw new TypeError("render() takes diagram text or a model that parse() returned.");return r}(e,t),o=s[l.section??r],h="object"==typeof o&&null!==o&&!Array.isArray(o)&&!1===o.useMaxWidth,c=t.responsive??!h,d=t.icons,f=d&&(e=>d(m(e))),u=Vt({type:r,mermaidType:a},()=>function(e,t){let r=_t;_t=e;try{return t()}finally{_t=r}}(Et(r,s),()=>function(e,t){let r=$,a=b;$=e,b=new Map;try{return t()}finally{$=r,b=a}}(l.math?t.math:void 0,()=>function(e,t){let r=y,a=x;y=e,x=new Map;try{return t()}finally{y=r,x=a}}(f,()=>l.render(n,s,{...t,responsive:c,icons:f}))))),p=t.outputLimit??4e6;if(u.svg.length>p)throw new i(`Diagram output is longer than the limit of ${p} characters.`,"limit",{type:r,mermaidType:a});for(let e of u.links)e.id=m(e.id);return{type:r,mermaidType:a,...u}})}var tr="about:blank",rr=/^([^\w]*)(javascript|data|vbscript)/im,ar=/&#(\w+)(^\w|;)?/g,ir=/&(newline|tab);/gi,lr=/[\u0000-\u001F\u007F-\u009F -‍\uD800-\uDFFF\uFFFE\uFFFF]/gimu,nr=/^.+(:|&colon;)/gim,sr=/(\\|%5[cC])((%(6[eE]|72|74))|[nrt])/g;function or(e){try{return decodeURIComponent(e)}catch{return e}}function hr(e,t){let r,a=t?or(e.trim()):e.trim(),i=0;do{if(++i>32)return;a=a.replace(lr,"").replace(ar,(e,t)=>String.fromCharCode(t)).replace(ir,"").replace(lr,"").replace(sr,"").trim(),t&&(a=or(a)),r=a.match(lr)||a.match(ar)||a.match(ir)||a.match(sr)}while(r&&r.length>0);return a}function cr(e){if(!e)return tr;let t=hr(e,!0),r=hr(e,!1);if(!t||!r)return tr;if("."===t[0]||"/"===t[0])return r;let a=t.trimStart().match(nr);if(!a)return r;let i=a[0].toLowerCase().trim();if(rr.test(i))return tr;let l=r.trimStart().replace(/\\/g,"/");if("mailto:"===i||i.includes("://"))return l;if("http:"===i||"https:"===i){let e;try{e=new URL(l)}catch{return tr}return e.protocol=e.protocol.toLowerCase(),e.hostname=e.hostname.toLowerCase(),e.toString()}return l}function dr(e){return cr(m(e))}var fr=["http","https","mailto","tel"],ur=["http","https"],pr=/^([a-z][a-z0-9+.-]*):/i,gr=/^[\\/]{2}/;function mr(e,t){if(gr.test(e))return!1;let r=pr.exec(e);return!r||t.includes(r[1].toLowerCase())}function yr(e,t){let r=hr(e,!0);return void 0!==r&&mr(e,t)&&mr(r,t)?e:void 0}function xr(e,t){return!1===t.links?void 0:yr(e,t.linkSchemes??fr)}function wr(e,t){return!1===t.images?void 0:yr(e,t.imageSchemes??ur)}var $r=new RegExp(Ne.source,"gu");function br(e,t){let r=cr(e);return r!==tr&&void 0!==xr(r,t)&&void 0!==xr(e.replace($r,"").replace(/[\t\n\r]/g,"").replace(/^[\x00-\x20]+/,""),t)}function Mr(e,t,r,a,i,l=""){let n=xr(t,i);return void 0===n?e:(a.push({id:r,href:n,internal:!1}),`<a href="${De(n)}"${l}${vr(i)}>${e}</a>`)}function vr(e){let t=e.linkRel??"noopener";return t?` rel="${De(t)}"`:""}var kr=new Map([["square","rect"],["round","rounded"],["ellipse","ellipse"],["hexagon","hex"],["diamond","diam"]]),Ar=new Map;for(let e of[["rect","proc","process","rectangle","squareRect"],["rounded","event","roundedRect"],["stadium","terminal","pill"],["fr-rect","subprocess","subproc","framed-rectangle","subroutine"],["cyl","db","database","cylinder"],["datastore","data-store"],["folder","directory"],["bucket"],["console"],["browser"],["person"],["circle","circ"],["bang"],["cloud"],["diam","decision","diamond","question"],["hex","hexagon","prepare"],["lean-r","lean-right","in-out","lean_right"],["lean-l","lean-left","out-in","lean_left"],["trap-b","priority","trapezoid-bottom","trapezoid"],["trap-t","manual","trapezoid-top","inv-trapezoid","inv_trapezoid"],["dbl-circ","double-circle","doublecircle"],["text"],["notch-rect","card","notched-rectangle"],["lin-rect","lined-rectangle","lined-process","lin-proc","shaded-process"],["sm-circ","start","small-circle","stateStart"],["fr-circ","stop","framed-circle","stateEnd"],["fork","join","forkJoin"],["hourglass","collate"],["brace","comment","brace-l"],["brace-r"],["braces"],["bolt","com-link","lightning-bolt"],["doc","document"],["delay","half-rounded-rectangle"],["h-cyl","das","horizontal-cylinder"],["lin-cyl","disk","lined-cylinder"],["curv-trap","curved-trapezoid","display"],["div-rect","div-proc","divided-rectangle","divided-process"],["tri","extract","triangle"],["win-pane","internal-storage","window-pane"],["f-circ","junction","filled-circle"],["notch-pent","loop-limit","notched-pentagon"],["flip-tri","manual-file","flipped-triangle"],["sl-rect","manual-input","sloped-rectangle"],["docs","documents","st-doc","stacked-document"],["st-rect","procs","processes","stacked-rectangle"],["bow-rect","stored-data","bow-tie-rectangle"],["cross-circ","summary","crossed-circle"],["tag-doc","tagged-document"],["tag-rect","tagged-rectangle","tag-proc","tagged-process"],["flag","paper-tape"],["odd","rect_left_inv_arrow"],["lin-doc","lined-document"]])for(let t of e)Ar.set(t,e[0]);for(let e of["state","choice","note","composite","rectWithTitle","labelRect","block_arrow","collapsedGroup","iconSquare","iconCircle","icon","iconRounded","imageSquare","anchor","kanbanItem","mindmapCircle","defaultMindmapNode","classBox","erBox","requirementBox","usecaseActor","usecaseActorHollow","usecaseActorAwesome","usecaseActorIcon","usecaseBusiness","usecaseEllipse","usecaseJsonTable"])Ar.set(e,e);function Tr(e){return Ar.has(e)}function Cr(e){return void 0===e?"rect":kr.get(e)??Ar.get(e)??"rect"}var Er=new Map([["task","roundedRect"],["tool","subroutine"],["input","lean-right"],["decision","diamond"],["refdoc","lin-doc"],["action","hexagon"],["round","rect"]]),_r=new Set(["doc","stadium","terminal","circle","trapezoid","inv_trapezoid","inv-trapezoid","doublecircle","double-circle","typeDeclaration","procs","lean_left","lean-left","in-out","cylinder","ellipse","odd","tag-rect","tagged-rectangle","delay","half-rounded-rectangle","lin-rect","lined-rectangle","win-pane","window-pane","curv-trap","curved-trapezoid"]),Sr=new Set(["roundedRect","subroutine","subprocess","subproc","framed-rectangle","lean-right","diamond","lin-doc","lined-document","hexagon","hex","connector","collapsedGroup"]),Ir="roundedRect";function Nr(e){return e&&(Er.get(e)??e)}var Dr=new Set(["shape","view","icon","img","form","pos","w","h","class","style","labelType"]),Rr=new Set(["subroutine","subprocess","subproc","framed-rectangle","tool"]);function Lr(e){return"markdown"===e||"string"===e||"text"===e?e:"markdown"}function Or(e){return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}function Fr(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function zr(e,t){return Object.assign(e??{},t)}var Wr=/:\s*[>|][\d+-]*\s*$/,Pr=/,([\t ]*)$/;function Br(e,t){return"arrow_point"===e&&"normal"===t?"sequence":"arrow_cross"===e&&"normal"===t?"failure":"arrow_open"===e&&"dotted"===t?"reference":void 0}function Hr(e){if(!e)return;let t={},r=!1;for(let a of Object.keys(e))Dr.has(a)||(t[a]=e[a],r=!0);return r?t:void 0}var Yr,Gr=class{type="agentflow";direction;nodes=new Map;edges=[];subgraphs=[];connectors=new Map;classes=new Map;tooltips=new Map;defaultEdgeStyle;defaultInterpolate;mappings=[];diagnostics=[];title;accTitle;accDescr;lineOffset;subgraphLookup=new Map;globalNodes=new Set;members=new Set;edgeById=new Map;pairCount=new Map;subCount=0;bareMappings=new Set;firstMapping=new Map;reported=new Map;options;constructor(e={}){this.options=e,this.lineOffset=e.lineOffset??0}metadata(e,t,r){let a,l=t.includes("\n");try{a=U(l?t+"\n":"{\n"+t+"\n}")}catch(n){let s,o=l?function(e){let t,r=!1,a=!1,i=0,l=[];for(let n of e.split("\n")){if(void 0!==t){let e=n.length-n.trimStart().length;if(""===n.trim()||e>t){l.push(n);continue}t=void 0}let e=-1;for(let t=0;t<n.length;t++){let l=n[t];if(a)"\\"===l?t++:'"'===l&&(a=!1);else if(r)"'"===l&&(r=!1);else if('"'===l)a=!0;else if("'"===l)r=!0;else{if("#"===l&&(0===t||" "===n[t-1]||"\t"===n[t-1])){e=t;break}"["===l||"{"===l?i++:("]"===l||"}"===l)&&(i=Math.max(0,i-1))}}if(r||a||i>0){l.push(n);continue}let s=e>=0?n.slice(0,e):n,o=e>=0?n.slice(e):"";Wr.test(s)?(t=n.length-n.trimStart().length,l.push(n)):l.push(s.replace(Pr,"$1")+o)}return l.join("\n")}(t):t;if(o!==t)try{s=U(o+"\n")}catch{s=void 0}if(void 0===s){let{line:t,column:a}=this.errorAt(r),l=r?` (${t}:${a})`:"";throw new i(`Metadata of "${e}" is not valid YAML. ${n.message}${l}`,"syntax",{type:"agentflow",line:t,column:a})}a=s}return function(e){let t=e=>Array.isArray(e)?[]:Fr(e)?{}:e,r=t(e),a=[[e,r]];for(;a.length>0;){let[e,r]=a.pop();if(Array.isArray(e))for(let i of e){let e=t(i);r.push(e),"object"==typeof i&&null!==i&&a.push([i,e])}else if(Fr(e))for(let i of Object.keys(e)){if("__proto__"===i||"constructor"===i||"prototype"===i)continue;let l=e[i],n=t(l);r[i]=n,"object"==typeof l&&null!==l&&a.push([l,n])}}return r}(a??{})}errorAt(e){if(void 0===e)return{line:0,column:0};let t=this.options.source;if(void 0===t)return{line:e.first_line+this.lineOffset,column:e.first_column+1};let r=0;for(let a=1;a<e.first_line;a++)r=t.indexOf("\n",r)+1;let{line:a,column:i}=h(t,r+e.first_column);return{line:a,column:i}}shapeError(e,t){return new i(e,"semantic",{type:"agentflow",...this.errorAt(t)})}addVertex(e,t,r,a,i,l,n={},s,o){if(!e||0===e.trim().length)return;let h,c,d;void 0!==s&&(h=this.metadata(e,s,o),Fr(h)&&(c=h,"string"==typeof h.shape&&(d=h.shape,h.shape=Nr(h.shape))));let f=this.subgraphLookup.get(e);if(f&&h)return void(f.metadata=zr(f.metadata,h));let u=this.connectors.get(e);if(u&&h)return void(u.metadata=zr(u.metadata,h));if("connectors"===e)return;let p=this.edgeById.get(e);if(p)return void 0!==c?.animate&&(p.animate=c.animate),void 0!==c?.animation&&(p.animation=c.animation),void 0!==c?.curve&&(p.interpolate=c.curve),void(h&&(p.metadata=zr(p.metadata,h)));let g=this.nodes.get(e);if(void 0===g&&(g={id:e,labelType:"text",styles:[],classes:[]},this.nodes.set(e,g)),void 0!==t?(g.labelType=t.type,g.text=Or(t.text.trim())):void 0===g.text&&(g.text=e),void 0!==r&&(g.type=r),null!=a)for(let e of a)g.styles.push(e);if(null!=i)for(let e of i)g.classes.push(e);if(void 0!==l&&(g.dir=l),void 0===g.props?g.props=n:void 0!==n&&Object.assign(g.props,n),h&&(g.metadata=zr(g.metadata,h),void 0!==c)){if(c.shape){let e=d??c.shape;if("string"!=typeof e)throw this.shapeError(`No such shape: ${JSON.stringify(e)}.`,o);if(e!==e.toLowerCase()||e.includes("_"))throw this.shapeError(`No such shape: ${e}. Shape names should be lowercase.`,o);let t=c.shape;if(!Tr(m=t)&&"constructor"!==m)throw this.shapeError(`No such shape: ${t}.`,o);g.type=t}c.label&&(g.text=String(c.label),g.labelType=Lr(c.labelType))}var m}addSingleLink(e,t,r,a){let l={start:e,end:t,type:void 0,text:"",labelType:"text",classes:[],isUserDefinedId:!1,interpolate:this.defaultInterpolate},n=r?.text;void 0!==n&&(l.text=Or(n.text.trim()),l.labelType=Lr(n.type)),void 0!==r&&(l.type=r.type,l.stroke=r.stroke,l.length=r.length>10?10:r.length,r.edgeSemantic&&(l.edgeSemantic=r.edgeSemantic));let s=e+"\0"+t,o=this.pairCount.get(s)??0;a&&!this.edgeById.has(a)?(l.id=a,l.isUserDefinedId=!0):l.id=`L_${e}_${t}_${0===o?0:o+1}`;let h=this.options.maxEdges;if(void 0!==h&&this.edges.length>=h)throw new i(`Edge limit exceeded. The limit is ${h}.`,"limit",{type:"agentflow"});this.edges.push(l),this.pairCount.set(s,o+1),this.edgeById.has(l.id)||this.edgeById.set(l.id,l)}addLink(e,t,r){let a="string"==typeof r?.id?r.id.replace("@",""):void 0,i=e[e.length-1],l=t[0];for(let n of e)for(let e of t)this.addSingleLink(n,e,r,n===i&&e===l?a:void 0)}updateLinkInterpolate(e,t){for(let r of e)"default"===r?this.defaultInterpolate=t:this.edgeAt(r).interpolate=t}updateLink(e,t){for(let r of e){if("default"===r){this.defaultEdgeStyle=t;continue}this.edgeAt(r).style=t,t.length>0&&!t.some(e=>e?.startsWith("fill"))&&t.push("fill:none")}}edgeAt(e){let t=this.edges[Number(e)];if(void 0===t)throw new i(`The index ${e} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length-1}. (Help: Ensure that the index is within the range of existing edges.)`,"semantic",{type:"agentflow"});return t}addClass(e,t){let r=t.join().replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",").split(";");for(let t of e.split(",")){let e=this.classes.get(t);void 0===e&&(e={id:t,styles:[],textStyles:[]},this.classes.set(t,e));for(let t of r)t.includes("color")&&e.textStyles.push(t.replace("fill","bgFill")),e.styles.push(t)}}setDirection(e){let t=e.trim();t.includes("<")&&(t="RL"),t.includes("^")&&(t="BT"),t.includes(">")&&(t="LR"),t.includes("v")&&(t="TB"),"TD"===t&&(t="TB"),this.direction=t}setClass(e,t){for(let r of e.split(","))this.nodes.get(r)?.classes.push(t),this.edgeById.get(r)?.classes.push(t),this.subgraphLookup.get(r)?.classes.push(t)}setTooltip(e,t){if(void 0!==t)for(let r of e.split(","))this.tooltips.set(r,t)}setLink(e,t,r){let a=t.trim();for(let t of e.split(",")){let e=this.nodes.get(t);void 0!==e&&(e.link=a?dr(a):void 0,e.linkTarget=r)}this.setClass(e,"clickable")}setClickEvent(e,t,r){this.setClass(e,"clickable")}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addSubGraph(e,t,r,a){let i=e?.text?.trim(),l=r?.text||"";void 0!==e&&e===r&&/\s/.test(l)&&(i=void 0);let n,s=new Set,o=[];for(let e of t)if("string"==typeof e)""!==e.trim()&&!s.has(e)&&(s.add(e),o.push(e));else if(Array.isArray(e))for(let t of e)""!==t.trim()&&!s.has(t)&&(s.add(t),o.push(t));else n=e.value;n??=this.options.inheritDir?this.direction??this.options.direction:void 0,i??="subGraph"+this.subCount,this.subCount++;let h=this.members,c=o.filter(e=>e!==i&&!this.globalNodes.has(e)&&!h.has(e));for(let e of c)h.add(e);let d=this.subgraphLookup.get(i);if(d){for(let e of c)d.nodes.push(e);return l.trim()&&(d.title=l.trim()),n&&(d.dir=n),i}let f={id:i,nodes:c,title:l.trim(),classes:[],dir:n,labelType:Lr(r?.type),type:"flow"};return this.subgraphs.push(f),this.subgraphLookup.set(i,f),i}addGlobal(e){let t=!1,r=e=>{let r=e.trim();""!==r&&(this.globalNodes.add(r),this.members.delete(r)&&(t=!0))};for(let t of e)if("string"==typeof t)r(t);else if(Array.isArray(t))for(let e of t)r(e);if(t)for(let e of this.subgraphs)e.nodes=e.nodes.filter(e=>!this.globalNodes.has(e))}addConnector(e,t){let r=e?.text?.trim();if(!r)return"";let a=t?.text?.trim()??"",i=this.connectors.get(r);if(i)a.length>0&&(i.text=a);else{let e={id:r,labelType:"text",styles:[],classes:[],isConnector:!0,text:a.length>0?a:r};this.connectors.set(r,e),this.nodes.set(r,e)}return r}destructLink(e,t){let r=function(e){let t=e.trim(),r=t.slice(0,-1),a="arrow_open";switch(t.slice(-1)){case"x":a="arrow_cross";break;case">":a="arrow_point";break;case"-":case".":r=t}let i="normal",l=r.length-1,n=0;for(let e=0;e<r.length;e++)"."===r[e]&&n++;return n>0&&(i="dotted",l=n),{type:a,stroke:i,length:l}}(e);return t&&(t.includes(".")?"dotted":"normal")!==r.stroke?{type:"INVALID",stroke:"INVALID"}:{...r,edgeSemantic:Br(r.type,r.stroke)}}subgraph(e){return this.subgraphLookup.get(e)}vertexKind(e){if(t=e,Rr.has(t.type))return"tool";var t;let r=Nr(e.type);return"hexagon"===r||"hex"===r?"action":"lean-right"===r||"lean_right"===r?"input":"lin-doc"===r||"lined-document"===r?"refdoc":"diamond"===r?"decision":"task"}semanticModel(){let e=[],t=[];for(let[r,a]of this.nodes){if(this.subgraphLookup.has(r))continue;let i=Hr(a.metadata);if(a.isConnector){let e={id:r};void 0!==a.text&&a.text!==r&&(e.title=a.text),i&&(e.metadata=i),t.push(e);continue}let l={id:r};void 0!==a.text&&(l.label=a.text);let n=Nr(a.type);void 0!==n&&(l.shape=n),l.vertexKind=this.vertexKind(a),i&&(l.metadata=i),e.push(l)}let r={vertices:e,edges:this.edges.map(e=>{let t={start:e.start,end:e.end};return void 0!==e.id&&(t.id=e.id),e.text.length>0&&(t.label=e.text),void 0!==e.type&&(t.type=e.type),void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.edgeSemantic&&(t.edgeSemantic=e.edgeSemantic),void 0!==e.length&&(t.length=e.length),e.metadata&&Object.keys(e.metadata).length>0&&(t.metadata={...e.metadata}),t}),subGraphs:this.subgraphs.map(e=>{let t={id:e.id,nodes:[...e.nodes],type:e.type,title:e.title};void 0!==e.dir&&(t.direction=e.dir);let r=Hr(e.metadata);return r&&(t.metadata=r),t}),connectors:t,diagnostics:this.diagnostics};return void 0!==this.direction&&(r.direction=this.direction),r}position(e){let t=e?.first_line??0,r=e?.first_column??0;return{startLine:t+this.lineOffset,startColumn:r,endLine:(e?.last_line??t)+this.lineOffset,endColumn:e?.last_column??r,startIndex:0,endIndex:0}}pushMapping(e,t,r){let a={id:e,type:t,position:r};return this.mappings.push(a),this.firstMapping.has(e)||this.firstMapping.set(e,a),a}addVertexMapping(e,t,r,a){if(!e)return;let i=this.pushMapping(e,"vertex",this.position(a));null==r&&this.bareMappings.add(i)}extendVertexMapping(e,t){if(!e||!t)return;let r=this.position(t);for(let t=this.mappings.length-1;t>=0;t--){let a=this.mappings[t];if("vertex"!==a.type||a.id!==e)continue;this.bareMappings.delete(a)&&(a.type="attachment");let i=a.position;return void((r.endLine>i.endLine||r.endLine===i.endLine&&r.endColumn>i.endColumn)&&(i.endLine=r.endLine,i.endColumn=r.endColumn))}this.pushMapping(e,"attachment",r)}addEdgeMapping(e,t,r,a){let i=Array.isArray(t)?t.filter(e=>"string"==typeof e&&""!==e):[];this.pushMapping(i.length>0?i.join(">"):"edge","edge",this.position(a))}blockMapping(e,t,r,a){if(!e)return;let i=this.position(r),l=a?this.position(a):i;this.pushMapping(e,t,{startLine:i.startLine,startColumn:i.startColumn,endLine:l.endLine,endColumn:l.endColumn,startIndex:0,endIndex:0})}addSubgraphMapping(e,t,r,a){let i="string"==typeof e?e:e?.text;this.blockMapping(i??"","subgraph",r,a)}addConnectorMapping(e,t,r,a){this.blockMapping(e?.text?.trim()??"","connector",r,a)}emit(e,t,r,a){let i=a?.nodeId??a?.edgeId,l={id:e,severity:t,message:r};a?.nodeId?l.nodeId=a.nodeId:a?.edgeId&&(l.edgeId=a.edgeId);let n=i?this.firstMapping.get(i):void 0;n&&(l.position=n.position);let s=i??"",o=this.reported.get(s);if(void 0===o)this.reported.set(s,[l]);else{for(let a of o)if(a.id===e&&a.severity===t&&a.message===r&&a.nodeId===l.nodeId&&a.edgeId===l.edgeId)return;o.push(l)}this.diagnostics.push(l),this.options.log?.(t,`agentflow[${e}]: ${r}`)}emitWarning(e,t,r){this.emit(e,"warning",t,r)}emitError(e,t,r){this.emit(e,"error",t,r)}};function Ur(e){if(e<170||e>65500)return!1;let t=Yr??=function(){let e="4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 9 0 2 2 2 0 2 j 2 2a 2 3u 9 4d a 11 3 0 8 12 21 q 6 2 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 20 0 2 a 2g 1h 4 0 j 0 8 9 g 6 2 6 6 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 k 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 10 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 9 2 4 4 0 r 1 7 1 10 7 2 2 2 m 2 9 2 4 4 0 x 0 2 1 g 1 j 7 2 2 2 14 3 0 h 0 i 1 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 3 1 2 0 3 0 7 3 2 6 2 2 2 0 2 0 3 1 2 3 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2c d h7 3 g 2 p 6 22 m c 2 3 f h f h f c 2 2 g 1f 10 0 5 0 1w 2f 9 14 2 0 6 1x b s 1g t 3 4 c 17 m 6 1l m a 1g 2b 0 2m 1a i 6 1k t e 1 b 17 r z 16 2 b z 30 3 2 3 4 1 a 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 4 4 7 0 2 0 2 0 2 3 2 a 3 3 6 4 5 0 1h 1 22k 1a 2 1a 2 3o 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 29 0 d2 1 17 4 6 1 5 2d 7 2 2 2h 2 3 6 14 4 2l i q 1i f e9 52t 23 g5o 1g wc 1w 19 3 7g 4 f b 1 l 1a h o 9 1x 1e 8 3 2u 3 3 2 3 d a 26 9 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 f r b m q s 8 1a t 0 1d 14 o 2 2 7 l m 4 0 6 1b 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 42 y u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2".split(" "),t=new Uint16Array(e.length),r=0;for(let a=0;a<e.length;a+=2){let i=r+parseInt(e[a],36);r=i+parseInt(e[a+1],36),t[a]=i,t[a+1]=r}return t}(),r=0,a=(t.length>>1)-1;for(;r<=a;){let i=r+a>>1;if(e<t[2*i])a=i-1;else{if(!(e>t[2*i+1]))return!0;r=i+1}}return!1}var qr=["$end","INVALID","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","SHAPE_DATA","CALLBACKNAME","CALLBACKARGS","MD_STR","STR","STYLE","DEFAULT","LINKSTYLE","INTERPOLATE","CLASSDEF","CLASS","HREF","CLICK","GRAPH","flow","connector","global","end","LINK_TARGET","NODIR","DIR","direction_tb","direction_bt","direction_rl","direction_lr","direction_td","LINK_ID","NUM","BRKT","STYLE_SEPARATOR","COLON","AMP","SEMI","COMMA","MULT","LINK","START_LINK","EDGE_TEXT","-)","TEXT","(-","STADIUMEND","STADIUMSTART","SUBROUTINEEND","SUBROUTINESTART","VERTEX_WITH_PROPS_START","TAGEND","CYLINDEREND","CYLINDERSTART","DOUBLECIRCLEEND","DOUBLECIRCLESTART","TRAPEND","INVTRAPEND","TRAPSTART","INVTRAPSTART","TAGSTART","UP","SEP","DOWN","COMMENT","NODE_STRING","MINUS","UNICODE_TEXT","PIPE","PE","PS","SQE","SQS","DIAMOND_STOP","DIAMOND_START","NEWLINE","SPACE","EOF"],jr=new Uint8Array(128);for(let e of"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'*+.`?\\_/")jr[e.charCodeAt(0)]=1;var Vr=/accTitle\s*:\s*/y,Xr=/accDescr\s*:\s*/y,Kr=/accDescr\s*\{\s*/y,Zr=/call\s+/y,Qr=/click\s+/y,Jr=/(?:\r?\n)*\s*\n/y,ea=/\s*(?:LR|RL|TB|BT|TD|BR)\b/y,ta=/\s*[<>^]/y,ra=/\s*v\b/y,aa=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y,/.*direction\s+TD[^\n]*/y],ia=/[\n\r\u2028\u2029]/g,la=/\(\s*\)/y,na=/\n\s*/g;function sa(e){let t=e.length,r=[],a=[],i=[],l=[],n=[],s=0,o=0,h=1,c=0,d=!0,f=e.indexOf("direction"),u=e.indexOf("@"),p=-1,g=0,m=0,y=-1,x=-1,w=-1,$=-1,b=-1,M=-1,v=-1,k=t=>{let r=-1;for(let a=o;a<t;a++){let i=e.charCodeAt(a);10===i?(h++,r=a):13===i&&(a+1<t&&10===e.charCodeAt(a+1)&&a++,h++,r=a)}if(r<0)c+=t-o;else{let a=r+1;for(;a<t;){let t=e.charCodeAt(a);if(8232===t||8233===t)break;a++}c=a-r-1}o=t},A=(t,n)=>{r.push(t),a.push(e.slice(o,n)),i.push(o),l.push(h,c),k(n),l.push(h,c)},T=(t,n)=>{r.push(t),a.push(e.slice(o,n)),i.push(o),l.push(h,c),c+=n-o,o=n,l.push(h,c)},C=(t,n)=>{r.push(t),a.push(e.slice(o,n)),i.push(o),l.push(h,c);for(let t=o;t<n;t++){let r=e.charCodeAt(t);10===r||13===r?(h++,c=0):c++}o=n,l.push(h,c)},E=(e,t,n)=>{r.push(e),a.push(t),i.push(o),l.push(h,c),k(n),l.push(h,c)},_=e=>{n.push(s),s=e},S=()=>{n.length>0&&(s=n.pop())},I=(t,r)=>(t.lastIndex=r,t.test(e)?t.lastIndex:-1),N=t=>e.startsWith(t,o)&&!Q(e.charCodeAt(o+t.length)),D=r=>{if(r>=x&&r<=w)return w;let a=r;for(;a<t&&q(e.charCodeAt(a));)a++;return x=r,w=a,a},R=t=>{let r=D(t);if(r===v||45!==e.charCodeAt(r)||45!==e.charCodeAt(r+1))return-1;let a=r+2;for(;45===e.charCodeAt(a);)a++;let i=e.charCodeAt(a);return 120===i||62===i?D(a+1):(v=r,-1)},L=()=>{let t=D(o);if(t===M||45!==e.charCodeAt(t))return!1;let r=e.charCodeAt(t+1),a=t+2;if(45===r){for(;45===e.charCodeAt(a);)a++;let r=e.charCodeAt(a);return 120===r||62===r?A(42,D(a+1)):(_(10),A(43,D(t+2))),!0}if(46===r){for(;46===e.charCodeAt(a);)a++;if(45===e.charCodeAt(a))return A(42,D(a+1)),!0}return M=t,!1},O=r=>{if(37!==e.charCodeAt(r)||37!==e.charCodeAt(r+1)||123===e.charCodeAt(r+2))return-1;let a=e.indexOf("\n",r+2);return-1===a?t:a},F=()=>{96===e.charCodeAt(o+1)?(_(2),k(o+2)):(_(1),k(o+1))},z=t=>{let r=e.charCodeAt(o+1);return 40===t?(45===r?(_(8),T(47,o+2)):91===r?(_(7),T(49,o+2)):40===r&&40===e.charCodeAt(o+2)?(_(7),T(57,o+3)):(_(7),T(72,o+1)),!0):91===t?(91===r?(_(7),T(51,o+2)):40===r?(_(7),T(55,o+2)):47===r?(_(9),T(60,o+2)):92===r?(_(9),T(61,o+2)):(_(7),T(74,o+1)),!0):124===t?(_(7),T(70,o+1),!0):123===t&&(_(7),T(76,o+1),!0)},W=()=>{let r=o;for(;r<t;){let a=e.charCodeAt(r);if(a<128&&1===jr[a])r++;else{if(!(45===a&&r+1<t))break;{let t=e.charCodeAt(r+1);if(62===t||45===t||46===t)break;r++}}}return r!==o&&(T(67,r),!0)},P=r=>{let a=r;for(;a<t;){let t=e.charCodeAt(a);if(32!==t&&9!==t)break;a++}return a},B=r=>{let a;switch(r){case 97:if(e.startsWith("acc",o)){if((a=I(Vr,o))>=0)return _(3),A(2,a),!0;if((a=I(Xr,o))>=0)return _(4),A(4,a),!0;if((a=I(Kr,o))>=0)return _(5),k(a),!0}if(N("agentflow-beta"))return d&&(d=!1,_(6)),T(20,o+14),!0;break;case 64:if(123===e.charCodeAt(o+1))return _(14),E(7,"",o+2),!0;break;case 99:if((a=I(Zr,o))>=0)return _(12),k(a),!0;if(N("classDef"))return T(16,o+8),!0;if(N("class"))return T(17,o+5),!0;if((a=I(Qr,o))>=0)return _(11),k(a),!0;if(N("connector"))return T(22,o+9),!0;break;case 34:return F(),!0;case 115:if(N("style"))return T(12,o+5),!0;break;case 100:if(N("default"))return T(13,o+7),!0;break;case 108:if(N("linkStyle"))return T(14,o+9),!0;break;case 105:if(N("interpolate"))return T(15,o+11),!0;break;case 104:if(e.startsWith("href",o)&&q(e.charCodeAt(o+4)))return A(18,o+5),!0;break;case 102:if(N("flow"))return T(21,o+4),!0;break;case 103:if(N("global"))return T(23,P(o+6)),!0;break;case 101:if(N("end"))return T(24,P(o+3)),!0;break;case 95:if(N("_self"))return T(25,o+5),!0;if(N("_blank"))return T(25,o+6),!0;if(N("_parent"))return T(25,o+7),!0;if(N("_top"))return T(25,o+4),!0}if(-1!==f&&o>=g&&(f<o&&(f=e.indexOf("direction",o)),-1!==f&&(p<o&&(ia.lastIndex=o,p=ia.test(e)?ia.lastIndex-1:t),f<p))){for(let e=0;e<5;e++)if((a=I(aa[e],o))>=0)return A(28+e,a),!0;g=p}if(-1!==u&&34!==r&&!q(r)){if(o>=m){u<o&&(u=e.indexOf("@",o));let r=o;for(;r<t;){let t=e.charCodeAt(r);if(34===t||q(t))break;r++}if(m=r,y=-1,-1!==u&&u<r)for(let a=Math.min(r,t-1)-1;a>=u;a--){if(64!==e.charCodeAt(a))continue;let t=e.charCodeAt(a+1);if(123!==t&&34!==t){y=a;break}}}if(y>o)return T(33,y+1),!0}if(r>=48&&r<=57){let r=o+1;for(;r<t;){let t=e.charCodeAt(r);if(t<48||t>57)break;r++}return T(34,r),!0}switch(r){case 35:return T(35,o+1),!0;case 58:return 58===e.charCodeAt(o+1)&&58===e.charCodeAt(o+2)?T(36,o+3):T(37,o+1),!0;case 38:return T(38,o+1),!0;case 59:return T(39,o+1),!0;case 44:return T(40,o+1),!0;case 42:return T(41,o+1),!0;case 60:return T(62,o+1),!0;case 45:return L()||W()||T(68,o+1),!0;case 40:case 124:case 123:return z(r);case 91:return 124===e.charCodeAt(o+1)?(T(52,o+2),!0):z(r);case 62:return _(7),T(53,o+1),!0;case 94:return T(63,o+1),!0;case 92:return 124===e.charCodeAt(o+1)?(T(64,o+2),!0):W();case 118:return Q(e.charCodeAt(o+1))?W():(T(65,o+1),!0);case 37:return(a=O(o))>=0?(A(66,a),!0):W()}if(q(r)){if(L())return!0;if((32===r||9===r)&&(a=O((r=>{if(r>=$&&r<=b)return b;let a=r;for(;a<t;){let t=e.charCodeAt(a);if(32!==t&&9!==t)break;a++}return $=r,b=a,a})(o)))>=0)return A(66,a),!0;for(a=o;;){let t=e.charCodeAt(a);if(10===t)a++;else{if(13!==t||10!==e.charCodeAt(a+1))break;a+=2}}return a>o?A(77,a):A(78,o+1),!0}return r<128?W():!!Ur(r)&&(T(69,o+1),!0)};for(;;){if(o>=t){let e=-1;switch(s){case 0:e=79;break;case 3:e=3;break;case 4:e=5;break;case 5:e=6;break;case 11:e=19;break;case 12:e=8;break;case 13:e=9}-1!==e&&T(e,t);break}let n=e.charCodeAt(o),d=!0;switch(s){case 0:d=B(n);break;case 1:if(34===n)96===e.charCodeAt(o+1)?(_(2),k(o+2)):(S(),k(o+1));else{let r=e.indexOf('"',o);A(11,-1===r?t:r)}break;case 2:if(96===n)34===e.charCodeAt(o+1)?(S(),k(o+2)):d=!1;else if(34===n)F();else{let r=o+1;for(;r<t;){let t=e.charCodeAt(r);if(96===t||34===t)break;r++}A(10,r)}break;case 3:case 4:{let r=e.indexOf("\n",o);-1===r&&(r=t);let a=3===s?3:5;S(),A(a,r);break}case 5:if(125===n)S(),k(o+1);else{let r=e.indexOf("}",o);-1===r&&(r=t),A(6,r)}break;case 6:{let e;34===n?F():(e=I(Jr,o))>=0?(S(),A(26,e)):(e=I(ea,o))>=0||(e=I(ta,o))>=0||(e=I(ra,o))>=0?(S(),A(27,e)):d=z(n);break}case 7:{let r=e.charCodeAt(o+1);switch(n){case 34:F();break;case 40:case 91:case 123:z(n);break;case 93:S(),41===r?T(48,o+2):93===r?T(50,o+2):T(73,o+1);break;case 41:S(),93===r?T(54,o+2):41===r&&41===e.charCodeAt(o+2)?T(56,o+3):T(71,o+1);break;case 124:S(),T(70,o+1);break;case 125:S(),T(75,o+1);break;case 37:{let e=O(o);e>=0?k(e):d=!1;break}default:{let r=o+1;for(;r<t;){let t=e.charCodeAt(r);if(91===t||93===t||40===t||41===t||123===t||125===t||124===t||34===t||37===t)break;r++}A(46,r)}}break}case 8:{let r,a=e.charCodeAt(o+1);if(34===n)F();else if(37===n&&(r=O(o))>=0)k(r);else if(45!==n&&47!==n&&41!==n||41!==a)if(40===n||91===n||123===n)z(n);else if(41===n||93===n||125===n)d=!1;else{let r=o+1;for(;r<t;){let t=e.charCodeAt(r);if(34===t||40===t||41===t||91===t||93===t||123===t||125===t||(45===t||47===t)&&41===e.charCodeAt(r+1)||37===t&&37===e.charCodeAt(r+1)&&123!==e.charCodeAt(r+2))break;r++}C(46,r)}else S(),T(45,o+2);break}case 9:{let r=e.charCodeAt(o+1);if(34===n){F();break}switch(n){case 40:45===r||91===r||40===r&&40===e.charCodeAt(o+2)?z(n):93===r?(S(),T(58,o+2)):z(n);break;case 91:case 123:z(n);break;case 92:93===r?(S(),T(58,o+2)):T(46,o+1);break;case 47:93===r?(S(),T(59,o+2)):T(46,o+1);break;case 93:case 41:93===r?(S(),T(58,o+2)):d=!1;break;case 125:d=!1;break;case 37:{let e=O(o);e>=0?k(e):d=!1;break}default:{if((63===n||61===n)&&93===r){S(),T(58,o+2);break}let a=o+1;for(;a<t;){let t=e.charCodeAt(a);if(92===t||91===t||93===t||40===t||41===t||123===t||125===t||47===t||37===t)break;a++}A(46,a)}}break}case 10:{if(34===n){F();break}let r=R(o);if(r>=0){S(),A(42,r);break}if(45===n&&45===e.charCodeAt(o+1)){d=!1;break}let a=o+1;for(;a<t;){let t=e.charCodeAt(a);if(34===t)break;if(45===t){if(45===e.charCodeAt(a+1))break}else if(q(t)&&R(a)>=0)break;a++}C(44,a);break}case 11:if(34===n)F();else if(q(n))S(),k(o+1);else{let r=o+1;for(;r<t&&!q(e.charCodeAt(r));)r++;T(19,r)}break;case 12:if(40===n){let e=I(la,o);S(),e>=0?k(e):(_(13),k(o+1))}else{let r=e.indexOf("(",o);-1===r&&(r=t),A(8,r)}break;case 13:if(41===n)S(),k(o+1);else{let r=e.indexOf(")",o);-1===r&&(r=t),A(9,r)}break;case 14:if(34===n)_(15),T(7,o+1);else if(125===n)S(),k(o+1);else if(94===n)d=!1;else{let r=o+1;for(;r<t;){let t=e.charCodeAt(r);if(125===t||94===t||34===t)break;r++}A(7,r)}break;case 15:if(34===n)S(),T(7,o+1);else{let r=e.indexOf('"',o);-1===r&&(r=t),E(7,e.slice(o,r).replace(na,"<br/>"),r)}}if(!d)return r.push(1),a.push(""),i.push(o),l.push(h,c,h,c),{types:r,texts:a,starts:i,locs:l}}return r.push(0),a.push(""),i.push(t),l.push(h,c,h,c),{types:r,texts:a,starts:i,locs:l}}var oa=new Uint8Array(80);for(let e of[34,67,65,68,13,40,37,38,35,41,69])oa[e]=1;var ha=new Uint8Array(80);for(let e of[34,69,67,27,65,68,40,37,38,35,41])ha[e]=1;var ca=new Uint8Array(80);for(let e of[34,67,78,68,38,69,37,41,35,12,14,16,17,19,20,27,21,22,23,24,65,63,43])ca[e]=1;var da=new Uint8Array(80);for(let e of[34,67,37,78,35,12])da[e]=1;var fa=new Uint8Array(80);for(let e of[77,39,79,66])fa[e]=1;var ua="'UNICODE_TEXT', 'TEXT', 'TAGSTART'",pa="'COMMENT', 'SEMI', 'NEWLINE', 'EOF'",ga=new Uint8Array(80);for(let e of[66,77,78,79])ga[e]=1;var ma=[],ya=/}[^\S\n]*\n/g;function xa(e,t,r=!1){let a,i=!r&&e.includes("}")?e.replace(ya,"}\n"):e,{types:n,texts:o,starts:h,locs:d}=sa(i),f=0,u=0,p=0,g=t=>{let r=n[f],a=h[f];if(79===r||0===r){let e=f;for(;e>0&&ga[n[e-1]];)e--;a=i.slice(0,h[e]).trimEnd().length}let o=i===e?a:s([l(e,ya,2)],a);throw 1===r?c("agentflow",e,o,"",!0):c("agentflow",e,o,`Expecting ${t}, got '${qr[r]}'`)},m=(e,t)=>({first_line:d[4*e],first_column:d[4*e+1],last_line:d[4*t+2],last_column:d[4*t+3]}),y=(e,t="")=>(n[f]!==e&&g(`'${qr[e]}'${t?", "+t:""}`),o[f++]),x=()=>{0===fa[n[f]]&&g(pa),f++},w=()=>{0===oa[n[f]]&&g("'NODE_STRING'");let e=o[f++];for(;1===oa[n[f]];)e+=o[f++];return e},$=()=>{0===ha[n[f]]&&g("'NODE_STRING'");let e=o[f++];for(;1===ha[n[f]];)e+=o[f++];return e},b=()=>{let e,t=n[f];if(11===t)e="string";else if(10===t)e="markdown";else{if(46!==t&&62!==t&&53!==t&&69!==t)return g(`${ua}, 'TAGEND', 'STR', 'MD_STR'`);e="text"}let r=o[f++];for(;;){let e=n[f];if(46!==e&&62!==e&&53!==e&&69!==e)break;r+=o[f++]}return{text:r,type:e}},M=e=>{y(e,ua)},v=()=>{u=f;let e=o[f++];for(;7===n[f];)e+=o[f++];return p=f-1,e},k=(e,r,a,i)=>{let l=m(a,i);t.addVertex(e,void 0,void 0,void 0,void 0,void 0,void 0,r,l),t.extendVertexMapping(e,l)},A=(e,r)=>{void 0!==r.data&&t.addVertex(e,void 0,void 0,void 0,void 0,void 0,void 0,r.data,m(r.dataFrom,r.dataTo))},T=()=>{let e=(()=>{let e,r,a,i=f,l=w();switch(n[f]){case 74:f++,e=b(),M(73),r="square";break;case 57:f++,e=b(),M(56),r="doublecircle";break;case 72:f++,72===n[f]?(f++,e=b(),M(71),y(71),r="circle"):(e=b(),M(71),r="round");break;case 47:f++,e=b(),M(45),r="ellipse";break;case 49:f++,e=b(),M(48),r="stadium";break;case 51:f++,e=b(),M(50),r="subroutine";break;case 52:{f++;let t=y(67);y(37);let i=y(67);y(70),e=b(),M(73),r="rect",a={[t]:i};break}case 55:f++,e=b(),M(54),r="cylinder";break;case 76:f++,76===n[f]?(f++,e=b(),M(75),y(75),r="hexagon"):(e=b(),M(75),r="diamond");break;case 53:f++,e=b(),M(73),r="odd";break;case 60:f++,e=b(),59===n[f]?(f++,r="lean_right"):(M(58),r="trapezoid");break;case 61:f++,e=b(),58===n[f]?(f++,r="lean_left"):(M(59),r="inv_trapezoid")}return void 0!==a?t.addVertex(l,e,r,void 0,void 0,void 0,a):void 0!==r?t.addVertex(l,e,r):t.addVertex(l),t.addVertexMapping(l,e,r,m(i,f-1)),l})();return 36===n[f]&&(f++,t.setClass(e,w())),e},C=()=>{let e=[T()];for(a=void 0;;){let t=7===n[f]?v():void 0,r=u,i=p;if(78!==n[f])return a=t,e;do{f++}while(78===n[f]);if(38!==n[f])return void 0!==t&&g("'AMP'"),e;f++,78!==n[f]&&g("'SPACE'");do{f++}while(78===n[f]);let l=T();void 0!==t&&k(e[e.length-1],t,r,i),e.push(l)}},E=()=>{let e;if(33===n[f]&&(e=o[f++]),42===n[f]){let r=t.destructLink(o[f++]);return void 0!==e&&(r.id=e),70===n[f]&&(f++,r.text=b(),M(70),78===n[f]&&f++),r}if(43===n[f]){let r=o[f++],a=(()=>{let e,t=n[f];if(11===t)e="string";else if(10===t)e="markdown";else{if(44!==t&&69!==t)return g("'EDGE_TEXT', 'STR', 'MD_STR'");e="text"}let r=o[f++];for(;44===n[f]||69===n[f];)r+=o[f++];return{text:r,type:e}})(),i=y(42,"'EDGE_TEXT'"),l=t.destructLink(i,r);return l.text=a,void 0!==e&&(l.id=e),l}return g("'LINK', 'START_LINK'")},_=()=>{0===da[n[f]]&&g("'NODE_STRING', 'NUM', 'COLON', 'BRKT'");let e=o[f++];for(;1===da[n[f]];)e+=o[f++];return e},S=()=>{let e=[_()];for(;40===n[f];)f++,e.push(_());return e},I=(e,r)=>{if(78!==n[f])return void t.setLink(e,r);if(f++,25===n[f])return void t.setLink(e,r,o[f++]);let a=y(11,"'LINK_TARGET'");78===n[f]?(f++,t.setLink(e,r,y(25))):t.setLink(e,r),t.setTooltip(e,a)},N=e=>{y(78,pa);let t=(()=>{let e,t=n[f];if(11===t)e="text";else if(10===t)e="markdown";else{if(1!==ca[t])return g("'NODE_STRING', 'STR', 'MD_STR'");e="text"}let r=o[f++];for(;1===ca[n[f]];)r+=o[f++];return{text:r,type:e}})(),r={text:"",type:"text"};74===n[f]&&(f++,r=b(),M(73));let a=7===n[f]?v():void 0;return 0===fa[n[f]]&&g(`${pa}, 'SHAPE_DATA'`),{global:!1,at:e,id:t,title:r,data:a,dataFrom:u,dataTo:p,list:[],collect:!1}},D=()=>{let e=n[f];switch(e){case 12:{f++,y(78);let e=w();return y(78),t.addVertex(e,void 0,void 0,S()),x(),ma}case 14:return(()=>{let e;if(f++,y(78),13===n[f])e=[o[f++]];else for(e=[y(34,"'DEFAULT'")];40===n[f];)f++,e.push(y(34));if(y(78),15!==n[f])return void t.updateLink(e,S());f++,y(78);let r=$();if(78===n[f]){f++;let a=S();t.updateLinkInterpolate(e,r),t.updateLink(e,a)}else t.updateLinkInterpolate(e,r)})(),x(),ma;case 16:{f++,y(78);let e=w();return y(78),t.addClass(e,S()),x(),ma}case 17:{f++,y(78);let e=w();return y(78),t.setClass(e,w()),x(),ma}case 19:return(()=>{let e=o[f++];switch(n[f]){case 8:{let r,a=o[f++],i=9===n[f],l=i?o[f++]:void 0;return 78===n[f]&&(f++,r=y(11)),i?t.setClickEvent(e,a,l):t.setClickEvent(e,a),void(void 0!==r&&t.setTooltip(e,r))}case 18:return f++,void I(e,y(11));case 11:return void I(e,o[f++]);default:{let r=$();if(78===n[f]){f++;let a=y(11);t.setClickEvent(e,r),t.setTooltip(e,a)}else t.setClickEvent(e,r)}}})(),x(),ma;case 22:{let e=N(f++),r=f++,a=t.addConnector(e.id,e.title);return A(a,e),t.addConnectorMapping(e.id,e.title,m(e.at,e.at),m(r,r)),a}case 28:case 29:case 30:case 31:case 32:return f++,{stmt:"dir",value:wa[e-28]};case 2:{f++;let e=y(3).trim();return t.setAccTitle(e),e}case 4:{f++;let e=y(5).trim();return t.setAccDescription(e),e}case 6:{let e=o[f++].trim();return t.setAccDescription(e),e}default:{0===oa[e]&&g($a);let r=(()=>{let e=f,r=C();void 0!==a&&k(r[r.length-1],a,u,p);let i=r;for(;;){let l=n[f];if(42!==l&&43!==l&&33!==l)return i;let s=E(),o=C();void 0!==a&&k(o[o.length-1],a,u,p),t.addLink(r,o,s),t.addEdgeMapping(r,o,s,m(e,f-1)),i=o.concat(i),r=o}})();return x(),r}}};for(;78===n[f]||77===n[f]||66===n[f];)f++;if(y(20,"'SPACE', 'NEWLINE', 'COMMENT'"),26===n[f])f++,t.setDirection("TB");else{let e=y(27,"'NODIR'"),r=n[f];if(78===r){do{f++}while(78===n[f]);r=n[f],77!==r&&g("'NEWLINE', 'SPACE'")}else 39!==r&&77!==r&&66!==r&&g("'COMMENT', 'SEMI', 'NEWLINE', 'SPACE'");f++,t.setDirection(e)}(()=>{let e=[],r=[],a=!1;for(;;){let i=n[f];if(0===i)break;if(24===i){let i=e.pop();if(void 0===i)break;let l=f++;if(i.global){t.addGlobal(r),r=i.list,a=i.collect;continue}let n=t.addSubGraph(i.id,r,i.title,"flow");A(n,i),t.addSubgraphMapping(i.id,i.title,m(i.at,i.at),m(l,l)),r=i.list,a=i.collect,a&&r.push(n)}else if(39===i||77===i||78===i||79===i)a&&r.push(o[f]),f++;else if(66===i)f++;else if(21===i||23===i){let t,l=f++;23===i||1===fa[n[f]]?(t={global:23===i,at:l,id:void 0,title:void 0,data:void 0,dataFrom:0,dataTo:0,list:r,collect:a},x()):(t=N(l),t.list=r,t.collect=a,f++),e.push(t),r=[],a=!0}else{let e=D();a&&(!Array.isArray(e)||e.length>0)&&r.push(e)}}e.length>0&&g("'end'")})(),0!==n[f]&&g($a)}var wa=["TB","BT","RL","LR","TD"],$a="'COMMENT', 'SEMI', 'NEWLINE', 'SPACE', 'EOF', 'flow', 'global', 'connector', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'NODE_STRING'";function ba(e,t,r=0){return{w:e,h:t,kind:r,pin:0,hint:NaN,key:NaN,span:0,x:0,y:0,rank:0}}function Ma(e,t,r=1,a=0,i=0){return{tail:e,head:t,minlen:r,labelW:a,labelH:i,tailDx:0,headDx:0,tailFixed:!1,headFixed:!1,reversed:!1,points:[],labelX:0,labelY:0}}var va=.5,ka=.5,Aa=400,Ta=16,Ca=new Float64Array(34),Ea=new Float64Array(34);function _a(e){return 1===e||2===e}function Sa(e,t,r,a){for(let i=t+1;i<r;i++){let r=e[i],l=a[r],n=i-1;for(;n>=t&&(a[e[n]]>l||a[e[n]]===l&&e[n]>r);)e[n+1]=e[n],n--;e[n+1]=r}}function Ia(e,t,r,a,i,l){let n=(e,t)=>r[e]<r[t]||r[e]===r[t]&&(i?a[e]>a[t]:a[e]<a[t]);for(let r=0;r<t;r+=8)for(let a=r+1,i=Math.min(t,r+8);a<i;a++){let t=e[a],i=a-1;for(;i>=r&&n(t,e[i]);)e[i+1]=e[i],i--;e[i+1]=t}let s=e,o=l;for(let e=8;e<t;e*=2){for(let r=0;r<t;r+=2*e){let a=Math.min(t,r+e),i=Math.min(t,r+2*e),l=r,h=a,c=r;for(;l<a&&h<i;)o[c++]=n(s[h],s[l])?s[h++]:s[l++];for(;l<a;)o[c++]=s[l++];for(;h<i;)o[c++]=s[h++]}let r=s;s=o,o=r}if(s!==e)for(let r=0;r<t;r++)e[r]=s[r]}function Na(e,t,r){let a=e.length;if(0===a)return{width:0,height:0};let i=t.length;if(1===a&&0===i&&0===e[0].kind){let t=e[0];return t.rank=0,t.x=t.w/2,t.y=t.h/2,{width:t.w,height:t.h}}let l=1;if(i>0){let e=new Set;for(let r of t){let t=Math.min(r.tail,r.head),i=Math.max(r.tail,r.head),n=t*a+i;if(r.labelW>0||e.has(n)){l=2;break}e.add(n)}}Da(e,t),Ra(e,t,l);let n=new Int32Array(i),s=0;for(let r=0;r<i;r++){let a=t[r];n[r]=Math.abs(e[a.head].rank-e[a.tail].rank),n[r]>1&&(s+=n[r]-1)}let o=new Uint8Array(i);if(s>2e4){let e=[];for(let t=0;t<i;t++)n[t]>1&&e.push(t);e.sort((e,t)=>n[t]-n[e]||e-t);for(let t of e){if(s<=2e4)break;o[t]=1,s-=n[t]-1}}let h=a+s,c=new Float64Array(h),d=new Float64Array(h),f=new Uint8Array(h),u=new Int32Array(h),p=0;for(let t=0;t<a;t++){let r=e[t];c[t]=r.w,d[t]=r.h,f[t]=r.kind,u[t]=r.rank,r.rank>p&&(p=r.rank)}let g=0;for(let e=0;e<i;e++)o[e]||(g+=n[e]);let m=new Int32Array(g),y=new Int32Array(g),x=new Float64Array(g),w=new Float64Array(g),$=new Int32Array(i).fill(-1),b=new Uint8Array(p+1),M=new Int32Array(i).fill(-1),v=!1;for(let t=0;t<a;t++)e[t].span>0&&0===e[t].kind&&(v=!0);let k=v?new Uint8Array(g):void 0,A=v?new Uint8Array(g):void 0,T=new Int32Array(i).fill(-1),C=new Int32Array(i).fill(-1),E=new Float64Array(h).fill(NaN);for(let t=0;t<a;t++)E[t]=e[t].key;let _,S=!1;{let e=a,r=0;for(let a=0;a<i;a++){if(o[a])continue;let i=t[a],n=i.reversed?i.head:i.tail,s=i.reversed?i.tail:i.head,h=i.reversed?i.headDx:i.tailDx,p=i.reversed?i.tailDx:i.headDx;(0!==h||0!==p)&&(S=!0);let g=u[n],v=u[s],_=-1;i.labelW>0&&(_=g+(v-g>>1),2===l&&v-g>=4?!(1&~_)&&(_+=i.reversed?1:-1):2===l&&!(1&_)&&(_+=i.reversed?1:-1));let I=n;v-g>1&&($[a]=e),T[a]=r,k&&!(i.reversed?i.headFixed:i.tailFixed)&&(k[r]=i.reversed?2:1);for(let t=g+1;t<v;t++){let l=e++;u[l]=t,E[l]=E[n]+(E[s]-E[n])*(t-g)/(v-g),t===_?(c[l]=i.labelW,d[l]=i.labelH,f[l]=2,M[a]=l,b[t]|=i.reversed?2:1):f[l]=1,m[r]=I,y[r]=l,x[r]=I===n?h:0,r++,I=l}m[r]=I,y[r]=s,x[r]=I===n?h:0,w[r]=p,A&&!(i.reversed?i.tailFixed:i.headFixed)&&(A[r]=i.reversed?1:2),C[a]=r,r++}}if(r.groups){let{of:e,parent:l}=r.groups;_=new Int32Array(h);for(let t=0;t<a;t++)_[t]=e[t];let s=e=>{let t=0;for(;e>=0;e=l[e])t++;return t},o=(e,t)=>{let r=s(e),a=s(t);for(;r>a;r--)e=l[e];for(;a>r;a--)t=l[t];for(;e!==t;)e=l[e],t=l[t];return e};for(let r=0;r<i;r++){if($[r]<0)continue;let a=t[r],i=o(e[a.tail],e[a.head]);for(let e=$[r],t=e+n[r]-1;e<t;e++)_[e]=i}}let I=new Int32Array(h+1),N=new Int32Array(h+1);for(let e=0;e<g;e++)I[m[e]+1]++,N[y[e]+1]++;for(let e=0;e<h;e++)I[e+1]+=I[e],N[e+1]+=N[e];let D=new Int32Array(g),R=new Int32Array(g);{let e=I.slice(0,h),t=N.slice(0,h);for(let r=0;r<g;r++)D[e[m[r]]++]=r,R[t[y[r]]++]=r}let L=new Int32Array(p+2);for(let e=0;e<h;e++)L[u[e]+1]++;for(let e=0;e<=p;e++)L[e+1]+=L[e];let O=new Int32Array(h),F=new Int32Array(h);{let e=new Int32Array(h),t=L.slice(0,p+1);for(let r=0;r<h;r++)e[t[u[r]]++]=r;for(let e=0;e<=p;e++)t[e]=L[e];let r=new Uint8Array(h),a=[];for(let i=0;i<h;i++)if(!r[e[i]])for(a.push(e[i]);a.length>0;){let e=a.pop();if(!r[e]){r[e]=1,O[t[u[e]]++]=e;for(let t=I[e+1]-1;t>=I[e];t--){let e=y[D[t]];r[e]||a.push(e)}}}}let z=(e,t)=>{let r=L[e],a=L[e+1];if(a-r<2)return!1;for(let e=r;e<a;e++)if(Number.isNaN(t(O[e])))return!1;let i=Array.from(O.subarray(r,a)),l=new Map;return i.forEach((e,t)=>l.set(e,t)),i.sort((e,r)=>t(e)-t(r)||l.get(e)-l.get(r)),O.set(i,r),!0};for(let e=0;e<=p;e++)z(e,e=>E[e]);let W=!1;for(let t=0;t<a;t++)0!==e[t].pin&&(W=!0);if(W)for(let t=0;t<=p;t++){let r=Array.from(O.subarray(L[t],L[t+1])),i=new Map;r.forEach((e,t)=>i.set(e,t));let l=t=>t<a?e[t].pin:0;r.sort((e,t)=>l(e)-l(t)||i.get(e)-i.get(t)),O.set(r,L[t])}let P=new Uint8Array(p+1),B=t=>t<a&&(3===e[t].kind||4===e[t].kind)?e[t].hint:NaN;for(let e of[0,p])z(e,B)&&(P[e]=1);let H=()=>{for(let e=0;e<=p;e++){let t=L[e];for(let r=t,a=L[e+1];r<a;r++)F[O[r]]=r-t}};H();let Y={n:h,real:a,maxRank:p,W:c,KIND:f,RANK:u,EF:m,ET:y,EFD:x,ETD:w,succStart:I,succE:D,predStart:N,predE:R,layerStart:L,order:O,pos:F,offsets:S,fixed:P,GRP:_,groupParent:r.groups?.parent},G=0,U=0;if(g>0&&p>0&&([G,U]=function(e,t){let{n:r,real:a,maxRank:i,W:l,EF:n,ET:s,EFD:o,ETD:h,succStart:c,succE:d,predStart:f,predE:u,layerStart:p,order:g,pos:m,offsets:y,fixed:x,GRP:w,groupParent:$}=e,b=0;for(let e=0;e<=i;e++)b=Math.max(b,p[e+1]-p[e]);if(b<2)return[0,0];let M=y?new Int32Array(n.length):void 0,v=new Int32Array(M?n.length:0),k=new Int32Array(M?r:0),A=M?d.slice():d,T=new Uint8Array(M?r:0);if(M){let e=u.slice(),t=(e,t,r,a)=>{for(let i=t+1;i<r;i++)if(a[e[i]]!==a[e[t]])return e.subarray(t,r).sort((e,t)=>a[e]-a[t]),!0;return!1};for(let a=0;a<r;a++){if(k[a]=1,t(e,f[a],f[a+1],h))for(let t=f[a]+1;t<f[a+1];t++)h[e[t]]!==h[e[t-1]]&&k[a]++,v[e[t]]=k[a]-1;t(A,c[a],c[a+1],o)&&(T[a]=1)}}let C=1;for(;C<(M?b+n.length:b);)C<<=1;let E=new Int32Array(2*C),_=new Int32Array(n.length),S=()=>{let e=0;for(let t=0;t<i;t++){let r=p[t+2]-p[t+1];if(M){let e=0;for(let r=p[t+1];r<p[t+2];r++){let t=g[r];for(let r=f[t];r<f[t+1];r++)M[u[r]]=e+v[u[r]];e+=k[t]}r=e}if(r<2)continue;let a=0;for(let e=p[t];e<p[t+1];e++){let t=g[e],r=c[t],i=c[t+1],l=a;for(let e=r;e<i;e++)_[a++]=M?M[A[e]]:m[s[d[e]]];let n=a-l;if(!(n<2))if(M&&T[t])for(let e=l+1;e<a;e++){let t=_[e],a=o[A[r+e-l]],i=e-1;for(;i>=l&&o[A[r+i-l]]===a&&_[i]>t;)_[i+1]=_[i],i--;_[i+1]=t}else if(n<=12)for(let e=l+1;e<a;e++){let t=_[e],r=e-1;for(;r>=l&&_[r]>t;)_[r+1]=_[r],r--;_[r+1]=t}else _.subarray(l,a).sort()}if(a<2)continue;let i=1;for(;i<r;)i<<=1;E.fill(0,0,2*i);for(let t=0;t<a;t++){let r=_[t]+i;for(E[r]++;r>1;)!(1&r)&&(e+=E[r+1]),r>>=1,E[r]++}}return e},I=S(),N=new Float64Array(r),D=new Int32Array(b),R=new Int32Array(b),L=$?$.length:0,O=new Int32Array(L);for(let e=0;e<L;e++)for(let t=e;t>=0;t=$[t])O[e]++;let F=new Float64Array(L),z=new Int32Array(L),W=new Int32Array(L),P=(e,t)=>{let a=p[e],i=p[e+1];for(let e=a;e<i;e++)for(let t=w[g[e]];t>=0;t=$[t])F[t]=0,z[t]=0;for(let e=a;e<i;e++){let r=g[e];for(let a=w[r];a>=0;a=$[a])0===z[a]&&(W[a]=e),F[a]+=t[r],z[a]++}let l=e=>e>=r?F[e-r]/z[e-r]:t[e],n=e=>e>=r?W[e-r]:a+m[e],s=(e,t)=>{let a=e,i=t,s=w[e],o=w[t],h=s<0?0:O[s],c=o<0?0:O[o];for(;h>c;h--)a=r+s,s=$[s];for(;c>h;c--)i=r+o,o=$[o];for(;s!==o;)a=r+s,s=$[s],i=r+o,o=$[o];return l(a)-l(i)||n(a)-n(i)},o=Array.from(g.subarray(a,i)).sort(s);g.set(o,a);for(let e=a;e<i;e++)m[g[e]]=e-a};if(w){let e=new Float64Array(r);for(let t=0;t<=i;t++){for(let r=p[t];r<p[t+1];r++)e[g[r]]=r-p[t];P(t,e)}}let B=w?S():I;if(0===B)return[0,I];let H=g.slice(),Y=Math.min(B,I),G=(e,r)=>{let $=e?f:c,b=e?u:d,M=e?n:s,v=e?o:h;for(let n=1;n<=i;n++){let s=e?n:i-n;if(x[s])continue;let o=p[s],h=p[s+1],c=0;for(let r=o;r<h;r++){let i=g[r],n=i<a?t[i].pin:0;if(0!==n){N[i]=1e9*n,D[c++]=i;continue}let d=$[i],f=$[i+1];if(d===f){if(w){let t=e?p[s]-p[s-1]:p[s+2]-p[s+1];N[i]=(r-o)*t/(h-o);continue}N[i]=-1;continue}let u=0;for(let e=d;e<f;e++){let t=M[b[e]];u+=m[t],y&&l[t]>0&&(u+=v[b[e]]/l[t])}N[i]=u/(f-d),D[c++]=i}if(w){P(s,N);continue}if(c<2)continue;Ia(D,c,N,m,r,R);let d=0;for(let e=o;e<h;e++)-1!==N[g[e]]&&(g[e]=D[d++]);for(let e=o;e<h;e++)m[g[e]]=e-o}},U=()=>{let e=0;for(let t=0;t<=i;t++)for(let r=p[t];r<p[t+1];r++)if(!(g[r]>=a))for(let a=r+1;a<p[t+1];a++)g[a]<g[r]&&e++;return e},q=()=>{for(let e=0;e<=i;e++)for(let t=p[e];t<p[e+1];t++)m[g[t]]=t-p[e]},j=e=>e<a?t[e].pin:0,V=(e,t)=>{let r=t?n[e]:s[e];return y&&l[r]>0?m[r]+(t?o[e]:h[e])/l[r]:m[r]},X=(e,t)=>{let r=0;for(let a=f[e];a<f[e+1];a++){let e=V(u[a],!0);for(let a=f[t];a<f[t+1];a++)e>V(u[a],!0)&&r++}for(let a=c[e];a<c[e+1];a++){let e=V(d[a],!1);for(let a=c[t];a<c[t+1];a++)e>V(d[a],!1)&&r++}return r},K=()=>{for(let e=0;e<8;e++){let e=!1;for(let t=0;t<=i;t++){if(x[t])continue;let r=p[t];for(let a=r;a+1<p[t+1];a++){let t=g[a],i=g[a+1];j(t)!==j(i)||w&&w[t]!==w[i]||X(i,t)>=X(t,i)||(g[a]=i,g[a+1]=t,m[i]=a-r,m[t]=a+1-r,e=!0)}}if(!e)break}},Z=g.slice(),Q=r<=600,J=H,ee=1/0;for(let e=0;e<(Q?2:1);e++){e>0&&(g.set(Z),q());let t=Y,r=Z.slice();for(let a=0,i=0;i<4&&a<24;a++,i++){G((a+e)%2==0,a%4>=2);let l=S();if(l<t&&(t=l,r.set(g),i=0,0===l))break}if(g.set(r),Q&&t>0){q(),K();let e=S();e<t&&(t=e,r.set(g))}let a=Q?U():0;(0===e||t<B||t===B&&a<ee)&&(B=t,J=r,ee=a)}if(g.set(J),q(),H.set(J),w&&(B=S()),!Q)return[B,I];for(let e=0;e<a;e++)if(0!==t[e].pin)return[B,I];if(0===ee||x[0]||x[i])return[B,I];for(let e=0;e<=i;e++)g.subarray(p[e],p[e+1]).reverse();return q(),(S()>B||U()>=ee)&&g.set(H),[B,I]}(Y,e),H()),r.orderOnly){let l=Wa(Y,r);for(let t=0;t<a;t++)e[t].x=l[t];for(let e=0;e<i;e++){let r=t[e],a=r.reversed?r.head:r.tail,i=r.reversed?r.tail:r.head,s=[u[a],l[a]];if(!o[e]&&$[e]>=0)for(let t=$[e],r=t+n[e]-1;t<r;t++)s.push(u[t],l[t]);s.push(u[i],l[i]),r.points=s}return{width:0,height:0,crossings:G,declared:U}}k&&A&&function(e,t,r,a){let{real:i,W:l,EFD:n,ETD:s}=e;for(let o=0;o<i;o++){let i=Math.min(t[o].span,l[o]);if(!(i<=0||0!==t[o].kind))for(let t=0;t<2;t++){let l=[],h=[],c=La(e,o,t,i,0===t?a:r,l,h);if(0===c)continue;let d=0===t?s:n,f=-c/2;for(let e=0;e<l.length;e++)f+=h[e],d[l[e]]=f}}}(Y,e,k,A);let q=Wa(Y,r),j=function(e){let{maxRank:t,KIND:r,layerStart:a,order:i}=e,l=new Uint8Array(t+1),n=!1;for(let e=1;e<t;e++){let t=a[e+1]>a[e];for(let l=a[e];t&&l<a[e+1];l++)1!==r[i[l]]&&(t=!1);t&&(l[e]=1,n=!0)}return n?l:void 0}(Y);if(k&&A){let a=function(e,t,r){let a=[new Int32Array(e.n),new Int32Array(e.n)];for(let i=0;i<e.EF.length;i++)0!==r[i]&&a[0][e.ET[i]]++,0!==t[i]&&a[1][e.EF[i]]++;return a}(Y,k,A);(function(e,t,r,a,i,l){let n=i.edgeSep,{n:s,real:o,maxRank:h,KIND:c,RANK:d,W:f,EF:u,ET:p,EFD:g,ETD:m,succStart:y,succE:x,predStart:w,predE:$,layerStart:b,order:M,pos:v}=e,k=e=>2===c[e]||1===c[e]&&!(void 0!==l&&1===l[d[e]]),A=(e,i)=>{let l=0===i?u[e]:p[e];return[0===i?r[l]+g[e]:r[l]+m[e],l<o&&0===t[l].kind?a[1-i][l]:0]},T=e=>{let t=b[d[e]],a=t+v[e],l=t=>f[t]/2+f[e]/2+(0===c[t]?i.nodeSep/2+n/2:c[t]===c[e]?n:n/2);return[a>t?r[M[a-1]]+l(M[a-1]):-1/0,a+1<b[d[e]+1]?r[M[a+1]]-l(M[a+1]):1/0]},C=(e,t,r,a,i)=>{let l=(t[1]!==r[1]?t[1]<r[1]:Math.abs(t[0]-e)<=Math.abs(r[0]-e))?[t[0],r[0]]:[r[0],t[0]];return l.find(e=>e>=a&&e<=i)??Math.max(a,Math.min(i,l[0]))},E=new Uint8Array(s),_=[];for(let t=1;t<h;t++)for(let a=b[t];a<b[t+1];a++){if(!k(M[a])||E[M[a]])continue;let t=M[a];for(;_a(c[u[$[w[t]]]]);)t=u[$[w[t]]];let i=t,n=-1/0,s=1/0;_.length=0;for(let e=t;_a(c[e]);e=p[x[y[e]]]){if(i=e,!k(e))continue;E[e]=1,_.push(e);let[t,r]=T(e);t>n&&(n=t),r<s&&(s=r)}if(n<=s){let e=C(r[_[0]],A($[w[t]],0),A(x[y[i]],1),n,s);for(let t of _)r[t]=e;continue}for(let t of _){let[a,i]=T(t);a>i||(r[t]=C(r[t],A(Oa(e,l,$[w[t]],0),0),A(Oa(e,l,x[y[t]],1),1),a,i))}}})(Y,e,q,a,r,j),function(e,t,r,a,i,l,n){let{real:s,W:o,EF:h,ET:c,EFD:d,ETD:f,succStart:u,succE:p,predStart:g,predE:m,pos:y}=e,x=(u,p,g,m,y)=>{if(l[p][g]<2)return 0;u=Oa(e,n,u,p);let x=0===p?h[u]:c[u],w=0===p?r[x]+d[u]:r[x]+f[u];if(y&&Math.abs(w-r[g])<=m/2+ka)return Math.max(-m/2,Math.min(m/2,w-r[g]));let $=w,b=0;x<s&&0===t[x].kind&&0!==(0===p?a:i)[u]&&l[1-p][x]>=2&&(b=Math.max(0,Math.min(t[x].span,o[x])),b>0&&($=r[x]));let M=Math.max(r[g]-m/2,$-b/2),v=Math.min(r[g]+m/2,$+b/2);if(M>v+ka){let e=Math.max(0,m/2-40);return Math.max(-e,Math.min(e,w-r[g]))}let k=(r[g]*b+$*m)/(b+m);return Math.max(M,Math.min(v,k))-r[g]},w=[];for(let r=0;r<s;r++){let l=Math.min(t[r].span,o[r]);if(!(l<=0||0!==t[r].kind))for(let t=0;t<2;t++){let n=0===t?h:c,s=0===t?g:u,o=0===t?m:p,d=[],f=[];if(La(e,r,t,l,0===t?i:a,d,f),0===d.length)continue;1===d.length&&(f[0]=0);let x=[];for(let e=s[r];e<s[r+1];e++)x.push(o[e]);x.sort((e,t)=>y[n[e]]-y[n[t]]||e-t),w.push({v:r,side:t,span:l,ids:d,room:f,all:x})}}for(let e=0,t=!0;t&&e<6;e++){t=!1;for(let{v:r,side:l,span:n,ids:s,room:o,all:h}of w){let c=0===l?i:a,u=0===l?f:d,p=0,g=-n/2;for(let a=0;a<=h.length;a++){let i=a<h.length&&0===c[h[a]];if(a<h.length&&!i)continue;let d=0;for(let e=a-1;e>=0&&0!==c[h[e]];e--)d++;let f=i?u[h[a]]-16:n/2;if(d>0){let a=[],i=[],h=0;for(let t=0;t<d;t++){t>0&&(h+=o[p+t]),a.push(x(s[p+t],l,r,n,e>0)-h),i.push(1);let c=t>0&&0===o[p+t];for(;a.length>1&&(c||a[a.length-2]/i[i.length-2]>a[a.length-1]/i[i.length-1]);){c=!1;let e=a.pop(),t=i.pop();a[a.length-1]+=e,i[i.length-1]+=t}}let c=h,m=0;h=0;for(let e=0;e<a.length;e++){let r=f-c<g?(g+f-c)/2:Math.max(g,Math.min(f-c,a[e]/i[e]));for(let a=0;a<i[e];a++,m++)m>0&&(h+=o[p+m]),Math.abs(u[s[p+m]]-r-h)>.01&&(t=!0),u[s[p+m]]=r+h}p+=d}i&&(g=u[h[a]]+16)}}}}(Y,e,q,k,A,a,j),function(e,t,r,a){let{n:i,KIND:l,RANK:n,EF:s,ET:o,EFD:h,ETD:c,layerStart:d,order:f,pos:u}=e,p=e=>void 0!==r&&1===l[e]&&1===r[n[e]],g=[],m=[],y=[],x=[];for(let t=0;t<s.length;t++){if(p(s[t]))continue;let a=Oa(e,r,t,1);g.push(s[t]),m.push(o[a]),y.push(h[t]),x.push(c[a])}let w=e=>t[m[e]]+x[e]-t[g[e]]-y[e],$=new Int32Array(i),b=[];for(let e=0;e<i;e++)$[e]=e,b.push([e]);let M=(e,t)=>{let r=$[e],a=$[t];if(r!==a){b[r].length<b[a].length&&([r,a]=[a,r]);for(let e of b[a])$[e]=r,b[r].push(e);b[a]=[]}},v=[];for(let e=0;e<g.length;e++){let t=Math.abs(w(e));t<.01?M(g[e],m[e]):t<=24&&v.push(e)}if(0===v.length)return;v.sort((e,t)=>Math.abs(w(e))-Math.abs(w(t))||e-t);let k=t=>za(e,a,t),A=(e,r)=>{for(let a of b[e]){let i=d[n[a]],l=d[n[a]+1],s=i+u[a];if(s>i&&$[f[s-1]]!==e&&t[a]+r-t[f[s-1]]<k(a)+k(f[s-1])-.01||s+1<l&&$[f[s+1]]!==e&&t[f[s+1]]-t[a]-r<k(a)+k(f[s+1])-.01)return!1}return!0};for(let e of v){let r=w(e);if(Math.abs(r)<.01){M(g[e],m[e]);continue}if(Math.abs(r)>24||$[g[e]]===$[m[e]])continue;let a=$[g[e]],i=$[m[e]],n=b[a].length<=b[i].length?a:i;for(let s of[n,n===a?i:a]){let i=s===a?r:-r;if((!(Math.abs(r)>12)||b[s].every(e=>1===l[e]))&&A(s,i)){for(let e of b[s])t[e]+=i;M(g[e],m[e]);break}}}}(Y,q,j,r);for(let e=0;e<i;e++){if(o[e])continue;let r=t[e],a=x[T[e]],i=w[C[e]];r.tailDx=r.reversed?i:a,r.headDx=r.reversed?a:i}}!function(e,t,r){let{maxRank:a,KIND:i,EF:l,ET:n,EFD:s,ETD:o,succStart:h,succE:c,predStart:d,predE:f,layerStart:u,order:p}=e;for(let[g,m]of[[0,3],[a,4]]){let a=u[g],y=u[g+1],x=[];for(let u=a;u<y;u++){let a=p[u],g=3===m;if(i[a]!==m||1!==(g?h[a+1]-h[a]:d[a+1]-d[a]))break;let y=Oa(e,r,g?c[h[a]]:f[d[a]],g?1:0),w=g?t[n[y]]+o[y]:t[l[y]]+s[y];if(x.length>0&&w<x[x.length-1]+1)break;x.push(w)}if(0!==x.length&&x.length===y-a)for(let e=a;e<y;e++)t[p[e]]=x[e-a]}}(Y,q,j);let V=new Uint8Array(h);j&&!r.tracks&&function(e,t,r,a,i,l,n){let{maxRank:s,EF:o,ET:h,EFD:c,ETD:d,succStart:f,succE:u,predStart:p,predE:g,layerStart:m,order:y}=e,x=new Float64Array(t.length),w=new Float64Array(t.length),$=new Float64Array(t.length);for(let l=0;l<a.length;l++){let n=a[l];if(n<0)continue;let s=n+i[l]-1,m=e.RANK[n];for(let e=n;e<s;e++){if(!r[m+e-n])continue;let a=e;for(;a+1<s&&r[m+a+1-n];)a++;let i=g[p[e]],l=u[f[a]],y=t[o[i]]+c[i],b=t[h[l]]+d[l],M=a-e+2;for(let t=e;t<=a;t++)x[t]=y+(b-y)*(t-e+1)/M,w[t]=y,$[t]=b;e=a}}let b=[];for(let a=1;a<s;a++){if(!r[a])continue;let i=m[a],s=m[a+1],o=Array.from(y.subarray(i,s)).sort((e,t)=>w[e]-w[t]||$[e]-$[t]||e-t);for(let r=0;r<o.length;){b.length=0;let a=r;for(;a<o.length&&Math.abs(w[o[a]]-w[o[r]])<1&&Math.abs($[o[a]]-$[o[r]])<1;a++)b.push(o[a]);b.sort((t,r)=>e.pos[t]-e.pos[r]);for(let e=0;e<b.length;e++){let r=b[e];t[r]=x[r]+(e-(b.length-1)/2)*l,(1===b.length||0===l)&&(n[r]=1)}r=a}}}(Y,q,j,$,n,r.apart?0:r.edgeSep,V),r.tracks||function(e,t,r,a,i,l){let{maxRank:n,W:s,KIND:o,RANK:h,EF:c,ET:d,EFD:f,ETD:u,succStart:p,succE:g,predStart:m,predE:y,layerStart:x,order:w}=e,$=new Uint8Array(n+1),b=!1;for(let e=1;e<n;e++){let t=!1,r=!1;for(let a=x[e];a<x[e+1];a++){let e=o[w[a]];2===e?t=!0:1!==e&&(r=!0)}t&&!r&&($[e]=1,b=!0)}if(b)for(let e=0;e<r.length;e++){let n=r[e];if(!(n<0))for(let r=n,b=n+a[e]-1;r<b;r++){if(1!==o[r]||!$[h[r]])continue;let e=r,a=r;for(;e>n&&l[e-1];)e--;for(;a+1<b&&l[a+1];)a++;let M=y[m[e]],v=g[p[a]],k=t[c[M]]+f[M],A=t[d[v]]+u[v],T=Math.min(k,A)-i,C=Math.max(k,A)+i,E=!0,_=h[r];for(let e=x[_];E&&e<x[_+1];e++){let r=w[e];2===o[r]&&t[r]+s[r]/2>T&&t[r]-s[r]/2<C&&(E=!1)}if(!E)continue;l[r]=1;let S=a-e+2;for(let r=e;r<=a;r++)t[r]=k+(A-k)*(r-e+1)/S}}}(Y,q,$,n,r.edgeSep,V);let X=new Int32Array(i+1),K=r.tracks||k&&!r.straight?{from:[],to:[],rank:[],lower:[],track:[],levels:[],wide:[]}:void 0,Z=new Int32Array(p+1);if(K){for(let e=0;e<i;e++){if(X[e]=K.from.length,o[e])continue;let t=$[e],a=!1;for(let i=t,l=t<0?t:t+n[e]-1;i<l;i++){let e=void 0!==j&&1===j[u[i]];!r.tracks&&e!==(1===V[i])&&(a=!0)}if(a)continue;let i=q[m[T[e]]]+x[T[e]],l=u[m[T[e]]];for(let r=t,a=t<0?t:t+n[e]-1;r<a;r++)j&&j[u[r]]||(K.from.push(i),K.to.push(q[r]),K.rank.push(l),K.lower.push(r),i=q[r],l=u[r]);K.from.push(i),K.to.push(q[y[C[e]]]+w[C[e]]),K.rank.push(l),K.lower.push(-1)}X[i]=K.from.length}let Q=(e,t)=>{let r=!1;for(let a=L[e];a<L[e+1];a++){let e=f[O[a]];if(e===t)r=!0;else if(1!==e)return!1}return r},J=Q(0,3)?l:0,ee=Q(p,4)?l:0,te=new Float64Array(p+1);for(let e=0;e<g;e++){let t=Math.abs(q[m[e]]+x[e]-q[y[e]]-w[e]);t>te[u[m[e]]]&&(te[u[m[e]]]=t)}let re=new Float64Array(p+1),ae=new Float64Array(p+1),ie=e=>(e<J||e>=p-ee?r.portSep:r.rankSep)/l,le=new Float64Array(p+1);for(let e=0;e<p;e++)le[e]=K?ie(e):Math.max(ie(e),Math.min(3*r.rankSep/l,.125*te[e]));let ne=new Uint8Array(p+1).fill(1);for(let e=0;e<a;e++)ne[u[e]]=0;for(let e=1;e<p;e++){if(r.tracks||!ne[e]||1!==b[e]&&2!==b[e])continue;let t=Math.min((r.headRoom??0)/2,le[1===b[e]?e-1:e]/2);le[e-1]+=1===b[e]?-t:t,le[e]+=1===b[e]?t:-t}let se=e=>1===f[e]&&ne[u[e]]&&!r.tracks?(ae[u[e]]-re[u[e]])/4:0,oe=r.tracks?18:28,he=r.tracks?10:12,ce=r.tracks?14:12,de=new Int32Array(p+1);if(K){let e=new Float64Array(p+1);for(let t=0;t<p;t++){if(j&&j[t])continue;let r=t+1;for(e[t]=le[t];r<p&&j&&j[r];)e[t]+=le[r++];de[t]=r}for(let t=0;t<K.from.length;t++)K.wide.push(Math.abs(K.from[t]-K.to[t])>2*e[K.rank[t]]?1:0);let t=new Float64Array(p+1);!function(e,t,r,a,i){let{from:l,to:n,rank:s,track:o,levels:h,wide:c}=e,d=l.length,f=new Map;for(let e=0;e<d;e++){if(o.push(-1),h.push(0),Math.abs(l[e]-n[e])<ka)continue;let t=f.get(s[e]);t?t.push(e):f.set(s[e],[e])}if(0===f.size)return;let u=new Float64Array(d),p=new Float64Array(d);for(let e=0;e<d;e++)u[e]=Math.min(l[e],n[e]),p[e]=Math.max(l[e],n[e]);let g=(e,t)=>e>=u[t]-ka&&e<=p[t]+ka?1:0,m=(e,t)=>Math.abs(l[e]-l[t])<ka||Math.abs(n[e]-n[t])<ka,y=(e,t)=>u[e]<p[t]-ka&&u[t]<p[e]-ka,x=(e,t)=>y(e,t)&&!m(e,t),w=(e,t)=>y(e,t)||g(n[e],t)+g(l[t],e)+g(n[t],e)+g(l[e],t)>0,$=(e,t)=>g(n[e],t)+g(l[t],e),b=e=>{let t=e.map((e,t)=>t).sort((t,r)=>u[e[t]]-u[e[r]]),r=[];for(let a=0;a<t.length;a++){let i=t[a],l=p[e[i]]+2;for(let n=a+1;n<t.length&&u[e[t[n]]]<=l;n++){let e=t[n];r.push(Math.min(i,e),Math.max(i,e))}}return r},M=e=>{e.sort((e,t)=>p[t]-u[t]-(p[e]-u[e])||u[e]-u[t]||e-t);let t=e.length,a=[],i=e.map((e,t)=>t),l=e=>{for(;i[e]!==e;)e=i[e]=i[i[e]];return e},n=t<=Aa,s=n?b(e):[],c=n?e.map(()=>[]):[];for(let t=0;t<s.length;t+=2){let r=s[t],a=s[t+1];x(e[r],e[a])&&(c[r].push(a),c[a].push(r))}let d=e.map((e,t)=>t);if(n){let r=new Int32Array(t),n=[];for(let e=0;e<t;e++)a.push([]),n.push([]);for(let t=0;t<s.length;t+=2){let o=s[t],h=s[t+1],c=e[o],d=e[h];if(!w(c,d))continue;i[l(o)]=l(h);let f=$(c,d),u=$(d,c);if(f===u)continue;let p=f<u?o:h,g=f<u?h:o;a[g].push(p),n[p].push(g),r[g]++}let o=new Uint8Array(t);d=[];for(let e=0;e<t;e++){let e=-1;for(let a=0;a<t&&(o[a]||((e<0||r[a]<r[e])&&(e=a),0!==r[a]));a++);o[e]=1,d.push(e);for(let t of n[e])r[t]--}}let f=new Set,g=[],m=0;for(let t of d){let r=e[t],i=0;for(let r of a[t]??[])o[e[r]]>=i&&(i=o[e[r]]+1);if(n){f.clear();for(let r of c[t])f.add(o[e[r]]);for(;f.has(i);)i++}else{for(;g[i]?.some(e=>x(r,e));)i++;(g[i]??=[]).push(r)}o[r]=i,i>=m&&(m=i+1)}let y=new Int32Array(t).fill(m),M=new Int32Array(t).fill(-1);for(let r=0;r<t;r++){let t=l(r);y[t]=Math.min(y[t],o[e[r]]),M[t]=Math.max(M[t],o[e[r]])}for(let a=0;a<t;a++){let t=l(a);h[e[a]]=M[t]-y[t]+1,r&&(o[e[a]]-=y[t])}return m},v=(e,t,r)=>{let a=Fa(n[e]-l[e],t);for(let i=0;i<=Ta;i++){let s=i/Ta,o=1-s;r[2*i]=l[e]+(n[e]-l[e])*s*s*(3-2*s),r[2*i+1]=t*(3*a*s*o*o+3*(1-a)*s*s*o+s*s*s)}},k=(e,t,r)=>{let a=r*r*1.000000001;for(let i=0;i<=Ta;i++){let l=e[2*i],n=e[2*i+1];for(let e=0;e<Ta;e++){let i=t[2*e+2]-t[2*e],s=t[2*e+3]-t[2*e+1],o=Math.max(0,Math.min(1,((l-t[2*e])*i+(n-t[2*e+1])*s)/(i*i+s*s||1))),h=l-t[2*e]-o*i,c=n-t[2*e+1]-o*s;if(h*h+c*c<a&&Math.hypot(h,c)<r)return!0}}return!1},A=(e,t,r,a)=>{let i=Math.max(r/2,r-24);return v(e,i,Ca),v(t,i,Ea),k(Ca,Ea,a)||k(Ea,Ca,a)};for(let[e,s]of f){if(!r){t[e]=M(s);continue}if(s.length>Aa)continue;let d=s.filter(e=>1===c[e]);M(d);let f=new Set(d.filter(e=>h[e]>1)),g=b(s);for(let t=0;t<g.length;t+=2){let r=s[g[t]],i=s[g[t+1]];f.has(r)&&f.has(i)||!x(r,i)||l[r]<n[r]!=l[i]<n[i]||A(r,i,a[e],1===c[r]||1===c[i]?8:4)&&f.add(r).add(i)}for(let e of d)o[e]=-1,h[e]=0;if(0===f.size)continue;let $=0,v=0,k=new Set;for(let e=0;e<g.length;e+=2){let t=s[g[e]],r=s[g[e+1]];if(f.has(t)&&f.has(r)){if(!y(t,r))continue;l[t]<n[t]!=l[r]<n[r]?$++:m(t,r)||v++}else(f.has(t)||f.has(r))&&w(t,r)&&k.add(t).add(r)}if($>v){for(let t of s)(p[t]-u[t])*va>i[e]&&(i[e]=(p[t]-u[t])*va);continue}let T=s.filter(e=>f.has(e)||1!==c[e]&&k.has(e));M(T);let C=0;for(let e of T)h[e]>C&&(C=h[e]);t[e]=C}}(K,Z,!r.tracks,e,t);for(let a=0;a<p;a++)Z[a]>0?le[a]+=Math.max(0,2*oe+(Z[a]-1)*he-e[a]):t[a]>0&&(le[a]+=Math.max(0,Math.min(3*r.rankSep,t[a])-e[a]))}let fe=0;for(let e=0;e<=p;e++){let t=0;for(let r=L[e];r<L[e+1];r++)d[O[r]]>t&&(t=d[O[r]]);re[e]=fe,ae[e]=fe+t,fe+=t+le[e]}let ue=fe,pe=(e,t=K.track[e])=>{let a=K.rank[e],i=ae[a],l=re[de[a]],n=r.tracks?Z[a]:K.levels[e];return(i+l)/2+(t-(n-1)/2)*(n>1?Math.min(ce,(l-i-2*oe)/(n-1)):0)},ge=1/0,me=-1/0;for(let e=0;e<h;e++){let t=c[e]/2;q[e]-t<ge&&(ge=q[e]-t),q[e]+t>me&&(me=q[e]+t)}let ye=new Uint8Array(p+1),xe=new Uint8Array(p+1);for(let e=0;e<a;e++)0!==f[e]||!k||(N[e+1]>N[e]&&(ye[u[e]]=1),I[e+1]>I[e]&&(xe[u[e]]=1));for(let t=0;t<a;t++){let r=e[t],a=r.rank;r.x=q[t]-ge,0===f[t]&&xe[a]&&!ye[a]?r.y=ae[a]-r.h/2:0===f[t]&&ye[a]&&!xe[a]?r.y=re[a]+r.h/2:r.y=(re[a]+ae[a])/2}for(let a=0;a<i;a++){let i=t[a],l=e[i.reversed?i.head:i.tail],s=e[i.reversed?i.tail:i.head],o=[l.x+(i.reversed?i.headDx:i.tailDx),l.y+l.h/2],h=$[a];if(K&&X[a+1]>X[a])for(let e=X[a];e<X[a+1];e++){if(K.track[e]>=0&&(r.tracks||1===K.wide[e])){let t=pe(e);o.push(K.from[e]-ge,t,K.to[e]-ge,t)}else K.track[e]>0&&o.push(K.from[e]-ge,pe(e,K.track[e]-1));let t=K.lower[e];t<0||(o.push(q[t]-ge,re[u[t]]+se(t)),ae[u[t]]>re[u[t]]&&o.push(q[t]-ge,ae[u[t]]-se(t)))}else if(h>=0)for(let e=h,t=h+n[a]-1;e<t;e++){if(V[e])continue;let t=q[e]-ge,r=re[u[e]],a=ae[u[e]];o.push(t,r+se(e)),a>r&&o.push(t,a-se(e))}if(o.push(s.x+(i.reversed?i.tailDx:i.headDx),s.y-s.h/2),i.reversed)for(let e=0,t=o.length-2;e<t;e+=2,t-=2){let r=o[e],a=o[e+1];o[e]=o[t],o[e+1]=o[t+1],o[t]=r,o[t+1]=a}i.points=o;let c=M[a];c>=0?(i.labelX=q[c]-ge,i.labelY=(re[u[c]]+ae[u[c]])/2):i.labelW>0&&(i.labelX=(o[0]+o[o.length-2])/2,i.labelY=(o[1]+o[o.length-1])/2)}return{width:me-ge,height:ue}}function Da(e,t){let r=e.length,a=t.length,i=new Int32Array(r+1);for(let r=0;r<a;r++){let a=t[r];a.reversed=3===e[a.head].kind||4===e[a.tail].kind,a.reversed||i[a.tail+1]++}for(let e=0;e<r;e++)i[e+1]+=i[e];let l=new Int32Array(i[r]);{let e=i.slice(0,r);for(let r=0;r<a;r++)t[r].reversed||(l[e[t[r].tail]++]=r)}let n=new Uint8Array(r),s=i.slice(0,r),o=[];for(let e=0;e<r;e++)if(0===n[e])for(o.push(e),n[e]=1;o.length>0;){let e=o[o.length-1];if(s[e]<i[e+1]){let r=t[l[s[e]++]],a=r.head;1===n[a]?r.reversed=!0:0===n[a]&&(n[a]=1,o.push(a))}else n[e]=2,o.pop()}}function Ra(e,t,r){let a=e.length,i=t.length,l=new Int32Array(i),n=new Int32Array(i),s=new Int32Array(i),o=new Int32Array(a+1),h=new Int32Array(a+1);for(let e=0;e<i;e++){let a=t[e],i=a.reversed?a.head:a.tail,c=a.reversed?a.tail:a.head;l[e]=i,n[e]=c,s[e]=Math.max(1,a.minlen)*r,o[i+1]++,h[c+1]++}for(let e=0;e<a;e++)o[e+1]+=o[e],h[e+1]+=h[e];let c=new Int32Array(i),d=new Int32Array(i);{let e=o.slice(0,a),t=h.slice(0,a);for(let r=0;r<i;r++)c[e[l[r]]++]=r,d[t[n[r]]++]=r}let f=new Int32Array(a);for(let t=0;t<a;t++)3===e[t].kind&&(f[t]=-r);let u=new Int32Array(a);for(let e=0;e<a;e++)u[e]=h[e+1]-h[e];let p=new Int32Array(a),g=0;for(let e=0;e<a;e++)0===u[e]&&(p[g++]=e);for(let e=0;e<g;e++){let t=p[e];for(let e=o[t];e<o[t+1];e++){let r=c[e],a=n[r];f[t]+s[r]>f[a]&&(f[a]=f[t]+s[r]),0===--u[a]&&(p[g++]=a)}}for(let e=0;e<8;e++){let e=!1;for(let t=g-1;t>=0;t--){let r=p[t],a=h[r+1]-h[r],i=o[r+1]-o[r];if(0===a&&0===i)continue;let u=-1/0,g=1/0;for(let e=h[r];e<h[r+1];e++){let t=d[e];u=Math.max(u,f[l[t]]+s[t])}for(let e=o[r];e<o[r+1];e++){let t=c[e];g=Math.min(g,f[n[t]]-s[t])}let m=f[r];i>a&&g!==1/0?m=g:a>i&&u!==-1/0&&(m=u),m!==f[r]&&(f[r]=m,e=!0)}if(!e)break}let m=1/0,y=-1/0,x=!1;for(let t=0;t<a;t++){let r=e[t].kind;3===r&&(x=!0),3!==r&&4!==r&&(f[t]<m&&(m=f[t]),f[t]>y&&(y=f[t]))}m===1/0&&(m=0,y=0);for(let t=0;t<a;t++)3===e[t].kind?f[t]=m-r:4===e[t].kind&&(f[t]=y+r);x&&(m-=r);for(let t=0;t<a;t++)e[t].rank=f[t]-m}function La(e,t,r,a,i,l,n){let s=0===r?e.predStart:e.succStart,o=0===r?e.predE:e.succE,h=0===r?e.EF:e.ET,c=e.pos;for(let e=s[t];e<s[t+1];e++)0!==i[o[e]]&&l.push(o[e]);if(l.length<2)return 0;l.sort((e,t)=>c[h[e]]-c[h[t]]||e-t);let d=e=>{let t=0;n[0]=0;for(let r=1;r<l.length;r++){let a=i[l[r]]===i[l[r-1]];n[r]=e(a&&1===i[l[r]],a),t+=n[r]}return t},f=d(()=>1);if(a/f<8&&(f=d(e=>e?.5:1)),a/f<8&&(f=d((e,t)=>t?0:1)),0===f)return 0;let u=Math.min(16,a/f);for(let e=1;e<l.length;e++)n[e]*=u;return f*u}function Oa(e,t,r,a){if(!t)return r;let{KIND:i,RANK:l,EF:n,ET:s,succStart:o,succE:h,predStart:c,predE:d}=e;for(let e=0;e<1e5;e++){let e=0===a?n[r]:s[r];if(1!==i[e]||!t[l[e]])break;r=0===a?d[c[e]]:h[o[e]]}return r}function Fa(e,t){return Math.max(.25,Math.min(.5,4*Math.abs(t)/(Math.abs(e)||1)))}function za(e,t,r){return e.W[r]/2+(0===e.KIND[r]?t.nodeSep:t.edgeSep)/2}function Wa(e,t){let{n:r,maxRank:a,W:i,KIND:l,EF:n,ET:s,EFD:o,ETD:h,succStart:c,succE:d,predStart:f,predE:u,layerStart:p,order:g,pos:m}=e,y=n.length,x=new Float64Array(r);for(let a=0;a<r;a++)x[a]=za(e,t,a);let w=new Int32Array(y);for(let e=0;e<y;e++)w[e]=m[s[e]];for(let e=0;e<r;e++)c[e+1]-c[e]>1&&Sa(d,c[e],c[e+1],w);for(let e=0;e<y;e++)w[e]=m[n[e]];for(let e=0;e<r;e++)f[e+1]-f[e]>1&&Sa(u,f[e],f[e+1],w);let $=new Uint8Array(y);for(let e=1;e<=a;e++){let t=p[e]-p[e-1],r=p[e],a=p[e+1],i=0,s=r;for(let e=r;e<a;e++){let r=g[e],o=-1;if(_a(l[r])){let e=n[u[f[r]]];_a(l[e])&&(o=e)}let h=o>=0?m[o]:t;if(o>=0||e===a-1){for(let t=s;t<=e;t++){let e=g[t],r=_a(l[e]);for(let t=f[e];t<f[e+1];t++){let e=u[t],a=m[n[e]];(a<i||h<a)&&(!r||!_a(l[n[e]]))&&($[e]=1)}}s=e+1,i=h}}}let b=[],M=new Int32Array(r),v=new Int32Array(r),k=new Float64Array(r),A=new Int32Array(r),T=new Int32Array(r),C=new Float64Array(r),E=new Int32Array(r),_=new Int32Array(r+1),S=new Int32Array(r),I=new Int32Array(r),N=new Int32Array(r),D=new Float64Array(r);for(let e=0;e<4;e++){let t=e<2,i=!(1&~e),l=t?f:c,y=t?u:d,w=t?n:s,R=t?h:o,L=t?o:h;for(let e=0;e<r;e++)M[e]=e,v[e]=e,k[e]=0,E[e]=0,_[e+1]=0,D[e]=0;for(let e=0;e<=a;e++){let r=t?e:a-e,n=p[r],s=p[r+1],o=t?r-1:r+1,h=o>=0&&o<=a?p[o+1]-p[o]-1:0,c=-1;for(let e=i?s-1:n;i?e>=n:e<s;i?e--:e++){let t=g[e],r=l[t],a=l[t+1]-r;if(0===a)continue;let n=r+(a-1>>1),s=r+(a>>1);for(let e=0;e<2&&(1!==e||n!==s);e++){let r=y[0===e!==i?n:s],a=w[r],l=i?h-m[a]:m[a];v[t]===t&&c<l&&0===$[r]&&(v[a]=t,v[t]=M[t]=M[a],k[t]=k[a]+L[r]-R[r],c=l)}}}let O=0;for(let e=0;e<=a;e++){let t=p[e],r=p[e+1];for(let e=t+1;e<r;e++){let t=i?g[e]:g[e-1],r=i?g[e-1]:g[e],a=x[t]+x[r];A[O]=M[t],T[O]=M[r],C[O]=i?a-k[t]+k[r]:a+k[t]-k[r],E[M[r]]++,_[M[t]+1]++,O++}}for(let e=0;e<r;e++)_[e+1]+=_[e];for(let e=0;e<r;e++)I[e]=_[e];for(let e=0;e<O;e++)S[I[A[e]]++]=e;let F=0;for(let e=0;e<r;e++)M[e]===e&&0===E[e]&&(N[F++]=e);for(let e=0;e<F;e++){let t=N[e];for(let e=_[t];e<_[t+1];e++){let r=S[e],a=T[r];D[t]+C[r]>D[a]&&(D[a]=D[t]+C[r]),0===--E[a]&&(N[F++]=a)}}for(let e=F-1;e>=0;e--){let t=N[e],r=1/0;for(let e=_[t];e<_[t+1];e++){let t=S[e],a=D[T[t]]-C[t];a<r&&(r=a)}r!==1/0&&r>D[t]&&(D[t]=r)}let z=new Float64Array(r);for(let e=0;e<r;e++)z[e]=(i?-D[M[e]]:D[M[e]])+k[e];b.push(z)}let R=0,L=1/0,O=[],F=[];for(let e=0;e<4;e++){let t=1/0,a=-1/0,l=b[e];for(let e=0;e<r;e++){let r=i[e]/2;l[e]-r<t&&(t=l[e]-r),l[e]+r>a&&(a=l[e]+r)}O.push(t),F.push(a),a-t<L&&(L=a-t,R=e)}for(let e=0;e<4;e++){let t=1&e?F[R]-F[e]:O[R]-O[e];if(0!==t){let a=b[e];for(let e=0;e<r;e++)a[e]+=t}}let z=new Float64Array(r);for(let e=0;e<r;e++){let t,r=b[0][e],a=b[1][e],i=b[2][e],l=b[3][e];r>a&&(t=r,r=a,a=t),i>l&&(t=i,i=l,l=t),r>i&&(t=r,r=i,i=t),a>l&&(t=a,a=l,l=t),a>i&&(t=a,a=i,i=t),z[e]=(a+i)/2}return z}function Pa(e){return"BT"===e||"LR"===e||"RL"===e?e:"TB"}function Ba(e,t,r,a){let i=[];for(let t of e)i.push(t.x,t.y,t.w,t.h);let l=[];for(let e of t)l.push(e.labelX,e.labelY);let n=[];for(let e of r){n.push(e.x,e.y);for(let t of e.ports)n.push(t.px,t.py)}return{nodes:i,routes:t.map(e=>e.route),labels:l,levels:n,total:a}}function Ha(e,t,r,a){t.forEach((t,r)=>{t.x=e.nodes[4*r],t.y=e.nodes[4*r+1],t.w=e.nodes[4*r+2],t.h=e.nodes[4*r+3]}),r.forEach((t,r)=>{t.route=e.routes[r],t.labelX=e.labels[2*r],t.labelY=e.labels[2*r+1]});let i=0;for(let t of a){t.x=e.levels[i++],t.y=e.levels[i++];for(let r of t.ports)r.px=e.levels[i++],r.py=e.levels[i++]}return e.total}var Ya=.5,Ga=Math.max(3,3,3);function Ua(e,t,r=0){let a=0;for(let e of t)e.src!==e.dst&&e.route.length>3&&(a+=(e.route.length/3-1)*Ga);let i=new Float64Array(a),l=new Float64Array(a),n=new Float64Array(a),s=new Float64Array(a),o=new Float64Array(a),h=new Float64Array(a),c=new Int32Array(a),d=new Uint8Array(a),f=0,u=1/0,p=-1/0,g=NaN,m=NaN,y=NaN,x=NaN,w=(e,t,r,a,w,$)=>{let b=f-1;r===y&&a===x&&($===a&&m===a||w===r&&g===r)&&c[b]===e&&d[b]===t&&(r-g)*(w-r)+(a-m)*($-a)>0&&(f--,r=g,a=m),g=r,m=a,y=w,x=$,d[f]=t,i[f]=Math.min(r,w),n[f]=Math.max(r,w),l[f]=r<=w?a:$,s[f]=r<=w?$:a,o[f]=Math.min(a,$),h[f]=Math.max(a,$),o[f]<u&&(u=o[f]),h[f]>p&&(p=h[f]),c[f++]=e};for(let e=0;e<t.length;e++){let a=t[e];if(a.src===a.dst)continue;let i=a.route,l=e=>Math.abs(i[e]-i[e-3])<.01||Math.abs(i[e+1]-i[e-2])<.01,n=e=>Math.abs(i[e]-i[e-3])+Math.abs(i[e+1]-i[e-2]),s=e=>0===r&&e>0&&e<i.length-3&&l(e)&&l(e+3)&&n(e)>=.01&&n(e+3)>=.01&&Math.abs(i[e]-i[e-3])<.01!=Math.abs(i[e+3]-i[e])<.01,o=i[0],h=i[1];for(let t=3;t<i.length;t+=3){let a=(3===t?1:0)|(t===i.length-3?2:0),c=o,d=h,f=i[t],u=i[t+1];if(o=f,h=u,l(t)||2===r){if(!s(t)){w(e,a,c,d,f,u);continue}let r=s(t-3)?n(t)/2:n(t),l=s(t+3)?n(t+3)/2:n(t+3),p=(f-i[t-3])/n(t),g=(u-i[t-2])/n(t),m=(i[t+3]-f)/n(t+3),y=(i[t+4]-u)/n(t+3),x=f-p*r,$=u-g*r;w(e,a,c,d,x,$);let b=f-p*r*.38,M=u-g*r*.38,v=f+m*l*.38,k=u+y*l*.38;o=f+m*l,h=u+y*l;let A=a|(t+3===i.length-3?2:0),T=x,C=$;for(let t=1;t<=2;t++){let r=t/2,a=1-r,i=a*a*a*x+3*a*a*r*b+3*a*r*r*v+r*r*r*o,l=a*a*a*$+3*a*a*r*M+3*a*r*r*k+r*r*r*h;w(e,A,T,C,i,l),T=i,C=l}continue}if(1===r){let r=0===i[t+2],l=r?c:(c+f)/2,n=r?(d+u)/2:d;w(e,a,c,d,l,n),w(e,a,l,n,r?f:l,r?n:u),w(e,a,r?f:l,r?n:u,f,u);continue}let p=0===i[t+2],g=p?Fa(f-c,u-d):Fa(u-d,f-c),m=c,y=d;for(let t=1;t<=3;t++){let r=t/3,i=1-r,l=r*r*(3-2*r),n=3*g*r*i*i+3*(1-g)*r*r*i+r*r*r,s=c+(f-c)*(p?l:n),o=d+(u-d)*(p?n:l);w(e,a,m,y,s,o),m=s,y=o}}}let $=p>u?Math.round(Math.sqrt(f)):1,b=p>u?$/(p-u):0,M=e=>Math.min($-1,Math.floor((e-u)*b)),v=new Int32Array(f),k=new Int32Array($+1);for(let e=0;e<f;e++){v[e]=M(o[e]);for(let t=v[e],r=M(h[e]);t<=r;t++)k[t+1]++}for(let e=0;e<$;e++)k[e+1]+=k[e];let A=k.slice(0,$),T=new Int32Array(k[$]);for(let e=0;e<f;e++)for(let t=v[e],r=M(h[e]);t<=r;t++)T[A[t]++]=e;let C=new Float64Array(8*t.length),E=(e,t,r,a)=>Math.abs(e[t]-e[r])<Ya&&Math.abs(e[t]-e[a])<Ya||Math.abs(e[t+1]-e[r+1])<Ya&&Math.abs(e[t+1]-e[a+1])<Ya;for(let e=0;e<t.length;e++){let r=t[e].route;if(r.length<6)continue;let a=3;for(;a+3<r.length&&E(r,0,a,a+3);)a+=3;let i=r.length-3,l=i-3;for(;l>=3&&E(r,i,l,l-3);)l-=3;C.set([r[0],r[1],r[a],r[a+1],r[l],r[l+1],r[i],r[i+1]],8*e)}let _=(e,t,r,a)=>{let i=8*e+(1===t?0:4),l=C[i],n=C[i+1],s=C[i+2]-l,o=C[i+3]-n,h=s*s+o*o,c=h>0?Math.max(0,Math.min(1,((r-l)*s+(a-n)*o)/h)):0;return Math.hypot(r-l-c*s,a-n-c*o)<Ya},S=0;for(let r=0;r<$;r++){let a=k[r+1];if(a-k[r]>128)T.subarray(k[r],a).sort((e,t)=>i[e]-i[t]||e-t);else for(let e=k[r]+1;e<a;e++){let t=T[e],a=e;for(;a>k[r]&&i[T[a-1]]>i[t];a--)T[a]=T[a-1];T[a]=t}for(let f=k[r];f<a;f++){let u=T[f],p=n[u]-i[u],g=s[u]-l[u],m=v[u]===r;for(let y=f+1;y<a;y++){let a=T[y];if(i[a]>n[u])break;if(h[a]<o[u]||o[a]>h[u]||c[u]===c[a]||!m&&v[a]!==r)continue;if(p*(l[a]-l[u])-g*(i[a]-i[u])>0==p*(s[a]-l[u])-g*(n[a]-i[u])>0)continue;let f=n[a]-i[a],x=s[a]-l[a],w=f*(l[u]-l[a])-x*(i[u]-i[a]),$=f*(s[u]-l[a])-x*(n[u]-i[a]);if(w>0==$>0)continue;let b=t[c[u]],M=t[c[a]],k=w/(w-$),A=i[u]+k*p,C=l[u]+k*g,E=(t,r,i)=>0!==(d[u]&r)&&0!==(d[a]&i)||Math.abs(A-e[t].x)<e[t].w/2+24&&Math.abs(C-e[t].y)<e[t].h/2+24||_(c[u],r,A,C)&&_(c[a],i,A,C);b.src===M.src&&E(b.src,1,1)||b.src===M.dst&&E(b.src,1,2)||b.dst===M.src&&E(b.dst,2,1)||b.dst===M.dst&&E(b.dst,2,2)||S++}}}return S}function qa(e,t){let r=t=>{let r=new Set;for(let a=e[t].parent;a>=0&&!r.has(a);a=e[a].parent)r.add(a);return r};for(let[a,i]of t){if(a<0||i<0||a===i)continue;let t=r(a),l=r(i);for(let r of t)l.has(r)||(e[r].dir=void 0);for(let r of l)t.has(r)||(e[r].dir=void 0)}}function ja(e,t,r,a){for(let t of e)t.x+=r,t.y+=a;for(let e of t){for(let t=0;t<e.route.length;t+=3)e.route[t]+=r,e.route[t+1]+=a;e.labelX+=r,e.labelY+=a}}function Va(e,t,r=-1){return{w:e,h:t,parent:r,isGroup:!1,dir:void 0,padX:0,padTop:0,padBottom:0,minW:0,seq:0,span:0,x:0,y:0}}function Xa(e){return"TB"===e?0:"BT"===e?2:"LR"===e?3:1}function Ka(e){return e+2&3}function Za(e,t,r,a){let i=e.length,l=new Map,n=[],s=(e,t)=>{let r={id:e,dir:t,items:[],edges:[],ports:[],portOf:new Map,routes:new Map,x:0,y:0};return l.set(e,r),r},o=s(-1,r),h=[];for(let e=0;e<i;e++)h.push([]);let c=[];for(let t=0;t<i;t++){let r=e[t].parent;r>=0&&r<i&&r!==t&&e[r].isGroup?h[r].push(t):(e[t].parent=-1,c.push(t))}o.items=c,n.push(o);let d=new Int32Array(i),f=new Uint8Array(i),u=t=>{for(let r=t;r<n.length;r++){let t=n[r];for(let r of t.items)if(f[r]=1,d[r]=t.id<0?0:d[t.id]+1,e[r].isGroup){let a=s(r,e[r].dir??t.dir);a.items=h[r],n.push(a)}}};u(0);for(let t=0;t<i;t++){if(f[t])continue;let a=e[t].parent;if(h[a]=h[a].filter(e=>e!==t),e[t].parent=-1,o.items.push(t),f[t]=1,d[t]=0,e[t].isGroup){let a=n.length,i=s(t,e[t].dir??r);i.items=h[t],n.push(i),u(a)}}for(let t=n.length-1;t>0;t--){let r=n[t],a=1/0;for(let t of r.items)e[t].seq<a&&(a=e[t].seq);a!==1/0&&(e[r.id].seq=a)}for(let t of n)t.items.sort((t,r)=>e[t].seq-e[r].seq||t-r);let p=0;for(let r of t){let t=r.src,a=r.dst,i=0;for(;d[t]>d[a];i++)t=e[t].parent;for(;d[a]>d[t];i++)a=e[a].parent;for(;t!==a&&e[t].parent!==e[a].parent;i+=2)t=e[t].parent,a=e[a].parent;t!==a&&(p+i>4e4?(r.src=t,r.dst=a):p+=i)}let g=[],m=[];for(let r=0;r<t.length;r++){let a=t[r];if(a.route=[],a.src===a.dst){g.push(r);continue}let i=a.src,n=a.dst,s=[],o=[];for(;d[i]>d[n];)s.push(i),i=e[i].parent;for(;d[n]>d[i];)o.push(n),n=e[n].parent;if(i!==n){for(;e[i].parent!==e[n].parent;)s.push(i),o.push(n),i=e[i].parent,n=e[n].parent;l.get(e[i].parent).edges.push({e:r,a:i,b:n});for(let[t,a]of[[s,!0],[o,!1]])for(let i of t){let t=l.get(e[i].parent),n={e:r,inner:i,out:a,side:0,hint:NaN,px:0,py:0,route:[]};t.ports.push(n),t.portOf.set(2*r+(a?0:1),n)}}else m.push(r)}let y,x=new Int32Array(i),w=(e,t,r)=>(r?t.src:t.dst)!==e,$=(r,a)=>{let i="TB"===r.dir||"BT"===r.dir,n=Xa(r.dir),s=[],o=[];r.items.forEach((t,r)=>{x[t]=r;let l=e[t],n=a?ba(i?l.w:l.h,i?l.h:l.w):ba(0,0);n.span=l.isGroup?Math.min(l.span,n.w-2*l.padX):l.span,n.key=v?M[t]:NaN,s.push(n)});let h=(r,a,i)=>e[r].isGroup&&w(r,t[a],i),c=(r,n,s)=>{if(!a||!e[r].isGroup||!w(r,t[n],s))return 0;let o=l.get(r).portOf.get(2*n+(s?0:1));return i?o.px-e[r].w/2:o.py-e[r].h/2};for(let e of r.edges){let r=t[e.e],l=Ma(x[e.a],x[e.b],r.minlen);a&&(l.labelW=i?r.labelW:r.labelH,l.labelH=i?r.labelH:r.labelW,l.tailDx=c(e.a,e.e,!0),l.headDx=c(e.b,e.e,!1),l.tailFixed=h(e.a,e.e,!0),l.headFixed=h(e.b,e.e,!1)),o.push(l)}let d=new Int32Array(r.ports.length).fill(-1);return r.ports.forEach((e,a)=>{if(e.side===n||e.side===Ka(n)){let i=s.length,l=ba(0,0,e.side===n?3:4);l.key=v?M[e.out?t[e.e].dst:t[e.e].src]:NaN,l.hint=Number.isNaN(e.hint)&&v&&y?y(r,e):e.hint,s.push(l),d[a]=i;let f=e.out?Ma(x[e.inner],i):Ma(i,x[e.inner]);e.out?(f.tailDx=c(e.inner,e.e,!0),f.tailFixed=h(e.inner,e.e,!0)):(f.headDx=c(e.inner,e.e,!1),f.headFixed=h(e.inner,e.e,!1)),o.push(f)}else s[x[e.inner]].pin=0===e.side||3===e.side?-1:1}),{lnodes:s,ledges:o,dummies:d}},b=p>1&&p<=400&&t.length<=500,M=new Float64Array(i).fill(NaN),v=!1,k=0,A=n.length>1&&b;for(let e of n)e.dir!==r&&(A=!1);if(A){let l="TB"===r||"BT"===r,n=new Int32Array(i).fill(-1),s=new Int32Array(i).fill(-1),o=[],h=[],c=[];for(let t=0;t<i;t++)e[t].isGroup&&(s[t]=c.length,c.push(-1));for(let t=0;t<i;t++){let r=e[t].parent;e[t].isGroup?c[s[t]]=r>=0?s[r]:-1:(n[t]=o.length,o.push(ba(l?e[t].w:e[t].h,l?e[t].h:e[t].w)),h.push(r>=0?s[r]:-1))}let d=[],f=new Int32Array(t.length).fill(-1);t.forEach((e,t)=>{e.src===e.dst||n[e.src]<0||n[e.dst]<0||(f[t]=d.length,d.push(Ma(n[e.src],n[e.dst],e.minlen,l?e.labelW:e.labelH,l?e.labelH:e.labelW)))});let u=Na(o,d,{...a,groups:{of:Int32Array.from(h),parent:Int32Array.from(c)},orderOnly:!0});k=Math.min(u.crossings??0,u.declared??0);let p=new Float64Array(i),g=new Int32Array(i),m=new Int32Array(i).fill(-1);for(let t=0;t<i;t++)if(!(n[t]<0)){M[t]=o[n[t]].x;for(let r=e[t].parent;r>=0;r=e[r].parent)p[r]+=M[t],g[r]++,m[r]=Math.max(m[r],o[n[t]].rank)}for(let e=0;e<i;e++)g[e]>0&&(M[e]=p[e]/g[e]);y=(e,r)=>{let a=f[r.e];if(a<0||e.id<0||!r.out||r.side!==Ka(Xa(e.dir)))return NaN;let i=d[a].points,l=M[t[r.e].src],n=0;for(let t=0;t<i.length;t+=2)i[t]===m[e.id]&&(l=i[t+1]),i[t]===m[e.id]+1&&(n=i[t+1]);return l+1e-6*n}}let T=new Map,C=(e,t,r)=>{if(!b)return{lnodes:t,ledges:r,size:Na(t,r,a)};let i=[];for(let e of t)i.push(e.w,e.h,e.kind,e.pin,e.hint,e.key,e.span);for(let e of r)i.push(e.tail,e.head,e.minlen,e.labelW,e.labelH,e.tailDx,e.headDx,+e.tailFixed,+e.headFixed);let l=T.get(e.id);l||T.set(e.id,l=[]);for(let e of l){let t=e.given.length===i.length;for(let r=0;t&&r<i.length;r++)t=Object.is(e.given[r],i[r]);if(t)return e}let n={given:i,lnodes:t,ledges:r,size:Na(t,r,a)};return l.push(n),n},E={width:0,height:0},_=()=>{for(let r of n){for(let a of r.ports)e[a.inner].isGroup&&w(a.inner,t[a.e],a.out)&&(l.get(a.inner).portOf.get(2*a.e+(a.out?0:1)).side=a.side);if(0===r.edges.length)continue;let a=!1;for(let i of r.edges){let r=t[i.e];(e[i.a].isGroup&&r.src!==i.a||e[i.b].isGroup&&r.dst!==i.b)&&(a=!0)}if(!a)continue;let{lnodes:i,ledges:n}=$(r,!1);Da(i,n),Ra(i,n,1);let s=Xa(r.dir);r.edges.forEach((r,a)=>{let i=t[r.e],o=!n[a].reversed;e[r.a].isGroup&&i.src!==r.a&&(l.get(r.a).portOf.get(2*r.e).side=o?Ka(s):s),e[r.b].isGroup&&i.dst!==r.b&&(l.get(r.b).portOf.get(2*r.e+1).side=o?s:Ka(s))})}for(let r=n.length-1;r>=0;r--){let a=n[r],i=a.id>=0?e[a.id]:void 0,s="TB"===a.dir||"BT"===a.dir,o="BT"===a.dir||"RL"===a.dir,h=$(a,!0),{lnodes:c,ledges:d,size:f}=C(a,h.lnodes,h.ledges),u=h.dummies,p=s?f.width:f.height,g=s?f.height:f.width,m=i?i.padX:0,y=i?i.padTop:0,x=Math.max(p+2*m,i?i.minW:0),b=g+y+(i?i.padBottom:0),M=(x-p)/2,v=y,k=(e,t)=>M+(s?e:o?f.height-t:t),A=(e,t)=>v+(s?o?f.height-t:t:e),T=s?0:1,_=e=>{let t=[];for(let r=0;r<e.length;r+=2)t.push(k(e[r],e[r+1]),A(e[r],e[r+1]),T);return t};a.items.forEach((t,r)=>{e[t].x=k(c[r].x,c[r].y),e[t].y=A(c[r].x,c[r].y)}),a.edges.forEach((e,r)=>{let i=d[r];a.routes.set(e.e,_(i.points));let l=t[e.e];l.labelW>0&&(l.labelX=k(i.labelX,i.labelY),l.labelY=A(i.labelX,i.labelY))});let S=a.edges.length;a.ports.forEach((r,a)=>{let i=e[r.inner];if(u[a]>=0){let e=_(d[S++].points),t=r.out?e.length-3:0,a=e[t],i=e[t+1];return 0===r.side?i=0:2===r.side?i=b:a=3===r.side?0:x,r.out?e.push(a,i,T):e.unshift(a,i,T),r.px=a,r.py=i,void(r.route=e)}let n=i.x,s=i.y;if(i.isGroup&&w(r.inner,t[r.e],r.out)){let e=l.get(r.inner).portOf.get(2*r.e+(r.out?0:1));n+=e.px-i.w/2,s+=e.py-i.h/2}else 0===r.side?s-=i.h/2:2===r.side?s+=i.h/2:3===r.side?n-=i.w/2:n+=i.w/2;let o=n,h=s;0===r.side?h=0:2===r.side?h=b:o=3===r.side?0:x;let c=0===r.side||2===r.side?0:1;r.px=o,r.py=h,r.route=r.out?[n,s,c,o,h,c]:[o,h,c,n,s,c]}),i?(i.w=x,i.h=b):E={width:x,height:b}}for(let t of n){let r=t.x,a=t.y;for(let i of t.items){let t=e[i];if(t.x+=r,t.y+=a,t.isGroup){let e=l.get(i);e.x=t.x-t.w/2,e.y=t.y-t.h/2}}}let r=(e,t,r,a)=>{for(let i=0;i<t.length;i+=3){let l=t[i]+r,n=t[i+1]+a,s=e.length;s>=3&&Math.abs(e[s-3]-l)<.01&&Math.abs(e[s-2]-n)<.01||e.push(l,n,t[i+2])}};for(let a of n)for(let i of a.edges){let n=t[i.e],s=[],o=[];for(let t=n.src;e[t].parent!==a.id;t=e[t].parent)o.push(l.get(e[t].parent));for(let e of o)r(s,e.portOf.get(2*i.e).route,e.x,e.y);r(s,a.routes.get(i.e),a.x,a.y);let h=[];for(let t=n.dst;e[t].parent!==a.id;t=e[t].parent)h.push(l.get(e[t].parent));for(let e=h.length-1;e>=0;e--)r(s,h[e].portOf.get(2*i.e+1).route,h[e].x,h[e].y);n.route=s,n.labelW>0&&(n.labelX+=a.x,n.labelY+=a.y)}},S=function(e){return e.tracks?1:e.straight?2:0}(a);v=A,_();let I=-1;if(A&&(I=Ua(e,t,S),I>1.5*k+4)){let r=Ba(e,t,n,E);v=!1,_();let a=Ua(e,t,S);a>=I?(v=!0,E=Ha(r,e,t,n)):I=a}if(v===A&&b){let r=!1;for(let a of n){if(a.id<0)continue;let i=e[a.id],l="TB"===a.dir||"BT"===a.dir,n=Ka(Xa(a.dir)),s=[];for(let e of a.ports){if(e.side!==n)continue;let r=t[e.e].route,o=a.x+e.px,h=a.y+e.py,c=-1;for(let t=0;t<r.length&&(c<0||e.out);t+=3)Math.abs(r[t]-o)<.01&&Math.abs(r[t+1]-h)<.01&&(c=t);if(c<0)continue;let d=l?0:1,f=e.out?c+3:c-3;for(;f>=0&&f<r.length&&Math.abs(r[f+d]-r[c+d])<Ya;)f+=e.out?3:-3;f<0||f>=r.length||(e.hint=r[f+d]-(l?i.x-i.w/2:i.y-i.h/2),s.push([l?e.px:e.py,e.hint]))}s.sort((e,t)=>e[0]-t[0]);for(let e=1;e<s.length;e++)s[e-1][1]>s[e][1]&&(r=!0)}if(r){let r=I>=0?I:Ua(e,t,S),a=r>0?Ba(e,t,n,E):void 0;a&&(_(),Ua(e,t,S)>=r&&(E=Ha(a,e,t,n)))}}for(let r of m){let a=t[r],i=e[a.src],l=e[a.dst];a.route=[i.x,i.y,0,l.x,l.y,0],a.labelX=(i.x+l.x)/2,a.labelY=(i.y+l.y)/2}for(let r of g){let a=t[r],i=e[a.src];a.labelX=i.x+i.w/2+28+a.labelW/2,a.labelY=i.y}return E}function Qa(e,t){for(let r=0;r<t.length;r+=3){let a=Math.round(t[r+1]),i=e.get(a);i?i.push(t[r]):e.set(a,[t[r]])}}function Ja(e,t,r,a){if(0===t)return e.x;let i=e.y-e.h/2,l=e.x-e.w/2,n=t/2,s=[l+a-6+n,e.x,l+e.w-a+6-n],o=r.get(Math.round(i));if(void 0===o)return s[0];let h=s[0],c=-1;for(let t of s){let r=1/0;for(let a of o)a>l&&a<l+e.w&&(r=Math.min(r,Math.abs(a-t)-n));if(r>=6)return t;r>c+.5&&(c=r,h=t)}return h}function ei(e,t,r,a){let i=t>0?a.get(Math.round(e.y-e.h/2)):void 0;if(void 0===i)return!1;let l=e.x-e.w/2;for(let a of i)if(a>l&&a<l+e.w&&Math.abs(a-r)<t/2+4)return!0;return!1}function ti(e,t,r,a,i,l,n,s){let o=1;for(let e=l[n].parent;e>=0&&o<8;e=l[e].parent)o++;return`<g class="pele-cluster-title" data-id="${i}">`+Fe(e,t,r,` fill="none" stroke="${`color-mix(in srgb,var(--_a) ${Oe(100*(1-.5**o))}%,var(--_bg))`}" stroke-width="5" stroke-linejoin="round"`,s)+Fe(e,t,r,a,s)+"</g>"}function ri(){let e=new Map;return{add(t,r,a){let i=ii(a);r>=0&&i>0&&i+6>(e.get(4*t+r)??0)&&e.set(4*t+r,i+6)},of:(t,r)=>r>=0?e.get(4*t+r)??0:0}}function ai(e,t,r,a,i=(r>0?r+6:0),l=(a>0?a+6:0)){let n="linear"===t,s="step"===t||"stepBefore"===t||"stepAfter"===t,o=[],h=[],c=[],d=(e,t,r,a)=>Math.abs(e-r)<.01&&Math.abs(t-a)<.01;for(let r=0;r<e.length;r+=3){let a=e[r],i=e[r+1],l=e[r+2],n=o.length-1;if(s&&n>=0&&Math.abs(a-o[n])>=.01&&Math.abs(i-h[n])>=.01){let e=o[n],r=h[n],s="stepBefore"===t?r:"stepAfter"===t?i:(r+i)/2,f="stepBefore"===t?e:"stepAfter"===t?a:(e+a)/2,u=0===l?[e,s,a,s]:[f,r,f,i];for(let t=0;t<4;t+=2)d(u[t],u[t+1],e,r)||d(u[t],u[t+1],a,i)||(o.push(u[t]),h.push(u[t+1]),c.push(l))}o.push(a),h.push(i),c.push(l)}let f=o.length-1,u=e=>Math.abs(o[e]-o[e-1])<.01||Math.abs(h[e]-h[e-1])<.01,p=e=>n||u(e),g=(e,t,r)=>{if(!p(Math.max(e,t)))return 0===r?[0,Math.sign(h[t]-h[e])||1]:[Math.sign(o[t]-o[e])||1,0];let a=o[t]-o[e],i=h[t]-h[e],l=Math.hypot(a,i)||1;return[a/l,i/l]},[m,y]=g(0,1,c[1]),[x,w]=g(f-1,f,c[f]),$=o[0],b=h[0],M=o[f],v=h[f];o[0]+=m*r,h[0]+=y*r,o[f]-=x*a,h[f]-=w*a;let k=e=>Math.abs(o[e]-o[e-1])+Math.abs(h[e]-h[e-1]),A=e=>!n&&e>0&&e<f&&u(e)&&u(e+1)&&k(e)>=.01&&k(e+1)>=.01&&Math.abs(o[e]-o[e-1])<.01!=Math.abs(o[e+1]-o[e])<.01,T=(e,t,r)=>Math.abs(o[e]-o[e-1])*Math.abs(t)+Math.abs(h[e]-h[e-1])*Math.abs(r),C=(e,t,r)=>{let a=Math.min(Math.max(0,e-6-t),r/4);return a+Math.min(e-t-a,(r-a)/4)},E=l>a&&(!p(f)||A(f-1))?C(l,a,T(f,x,w)):0,_=i>r&&(!p(1)||A(1))?C(i,r,T(1,m,y)):0;E>=1&&(o.splice(f,0,o[f]-x*E),h.splice(f,0,h[f]-w*E),c.splice(f,0,c[f]),f++),_>=1&&(o.splice(1,0,o[0]+m*_),h.splice(1,0,h[0]+y*_),c.splice(1,0,c[1]),f++);let S=[],I=e=>(S.push(function(e){let t=Math.round(100*e);return 0===t?0:t/100}(e)),Oe(e));S.push(77,2);let N=`M${I(o[0])},${I(h[0])}`,D=o[0],R=h[0],L=(e,t)=>{d(e,t,D,R)||(S.push(76,2),N+=`L${I(e)},${I(t)}`,D=e,R=t)};for(let e=1;e<=f;e++){let t=o[e],r=h[e];if(!p(e)){let a=0===c[e],i=a?r-R:t-D,l=Math.abs(i)*Fa(a?t-D:r-R,i),n=a?0:Math.sign(i)*l,s=a?Math.sign(i)*l:0;S.push(67,6),N+=`C${I(D+n)},${I(R+s)} ${I(t-n)},${I(r-s)} ${I(t)},${I(r)}`,D=t,R=r;continue}if(!A(e)){if(e<f&&u(e)&&u(e+1)&&(t-o[e-1])*(o[e+1]-t)+(r-h[e-1])*(h[e+1]-r)>0)continue;L(t,r);continue}let a=A(e-1)?k(e)/2:k(e),i=A(e+1)?k(e+1)/2:k(e+1);s&&(a=i=Math.min(12,a,i));let[l,n]=g(e-1,e,c[e]),[d,m]=g(e,e+1,c[e+1]);L(t-l*a,r-n*a),D=t+d*i,R=r+m*i,s?(S.push(81,4),N+=`Q${I(t)},${I(r)} ${I(D)},${I(R)}`):(S.push(67,6),N+=`C${I(t-l*a*.38)},${I(r-n*a*.38)} ${I(t+d*i*.38)},${I(r+m*i*.38)} ${I(D)},${I(R)}`)}return{d:N,tokens:S,sx:$,sy:b,sdx:-m,sdy:-y,ex:M,ey:v,edx:x,edy:w}}function ii(e){return"arrow_point"===e?7:"arrow_circle"===e?8:"arrow_cross"===e?4:0}function li(e,t,r,a,i,l,n="none"){let s=-i,o=a;if("arrow_point"===e){let e=t-8*a,h=r-8*i,c=3.36;return`<path class="pele-marker" d="M${Oe(t)},${Oe(r)}L${Oe(e+s*c)},${Oe(h+o*c)}L${Oe(e-s*c)},${Oe(h-o*c)}Z" fill="${l}" stroke="${n}"/>`}if("arrow_circle"===e)return`<circle class="pele-marker" cx="${Oe(t-4*a)}" cy="${Oe(r-4*i)}" r="3.5" fill="${l}" stroke="${n}"/>`;if("arrow_cross"===e){let e=t-4*a,l=r-4*i,n=3.5,h=(a+s)*n,c=(i+o)*n,d=(a-s)*n,f=(i-o)*n;return`<path class="pele-marker" d="M${Oe(e-h)},${Oe(l-c)}L${Oe(e+h)},${Oe(l+c)}M${Oe(e-d)},${Oe(l-f)}L${Oe(e+d)},${Oe(l+f)}"/>`}return""}var ni=Array.from({length:23},(e,t)=>+`1e${t}`);function si(e){return oi(function(e){let t=[],r=-1;for(let a=0;a<e.length;){let i=e.charCodeAt(a);if(i>=65&&i<=90&&69!==i)r=t.length+1,t.push(i,0),a++;else if(45===i||46===i||i>=48&&i<=57){let l,n=45===i?a+1:a,s=0,o=-1;for(let t=e.charCodeAt(n);t>=48&&t<=57||46===t&&o<0;t=e.charCodeAt(++n))46===t?o=0:(s=10*s+t-48,o>=0&&o++);if(101==(32|e.charCodeAt(n))||s>Number.MAX_SAFE_INTEGER||o>22){for(let t=e.charCodeAt(n);46===t||101===t||69===t||t>=48&&t<=57||(45===t||43===t)&&101==(32|e.charCodeAt(n-1));t=e.charCodeAt(++n));l=Number(e.slice(a,n))}else l=o>0?s/ni[o]:s,45===i&&(l=-l);r>=0&&(t.push(l),t[r]++),a=n}else a++}return t}(e))}function oi(e){let t=[],r=0,a=0;for(let i=0;i<e.length;){let l=e[i],n=i+2,s=n+e[i+1];if(i=s,72===l||86===l)for(let i=n;i<s;i++)72===l?r=e[i]:a=e[i],t.push(r,a);else if(67===l||81===l){let i=67===l,o=i?6:4;for(let l=n;l+o<=s;l+=o){let n=e[l],s=e[l+1],o=e[l+2],h=e[l+3],c=i?e[l+4]:o,d=i?e[l+5]:h;for(let e=.125;e<=1;e+=.125){let l=r+(n-r)*e,f=a+(s-a)*e,u=n+(o-n)*e,p=s+(h-s)*e;if(i){l+=(u-l)*e,f+=(p-f)*e,u+=(o+(c-o)*e-u)*e,p+=(h+(d-h)*e-p)*e}t.push(l+(u-l)*e,f+(p-f)*e)}r=c,a=d}}else if(65===l)for(let i=n;i+7<=s;i+=7)hi(t,r,a,e[i],e[i+1],e[i+3],e[i+4],e[i+5],e[i+6]),r=e[i+5],a=e[i+6];else for(let i=n;i+2<=s;i+=2)77===l&&i===n&&t.length>0&&t.push(NaN,NaN),r=e[i],a=e[i+1],t.push(r,a)}return t}function hi(e,t,r,a,i,l,n,s,o){let h=(t-s)/2,c=(r-o)/2;if(0===a||0===i||0===h&&0===c)return void e.push(s,o);let d=Math.max(1,Math.sqrt(h*h/(a*a)+c*c/(i*i)));a*=d,i*=d;let f=(l===n?-1:1)*Math.sqrt(Math.max(0,(a*a*i*i-a*a*c*c-i*i*h*h)/(a*a*c*c+i*i*h*h))),u=f*a*c/i+(t+s)/2,p=-f*i*h/a+(r+o)/2,g=Math.atan2((r-p)/i,(t-u)/a),m=Math.atan2((o-p)/i,(s-u)/a)-g;n&&m<0?m+=2*Math.PI:!n&&m>0&&(m-=2*Math.PI);for(let t=1;t<=8;t++)e.push(u+a*Math.cos(g+m*t/8),p+i*Math.sin(g+m*t/8))}function ci(e,t,r,a,i,l,n,s){let o=0,h=1;for(let c=0;c<4;c++){let d=0===c?-r:1===c?r:2===c?-a:a,f=0===c?e-i:1===c?n-e:2===c?t-l:s-t;0===d?f<0&&(h=-1):d<0?o=Math.max(o,f/d):h=Math.min(h,f/d)}return o<h}function di(e,t,r,a,i){for(let l=0;l+2<e.length;l+=2){let n=e[l],s=e[l+1],o=e[l+2],h=e[l+3];if(!(n<t&&o<t||n>a&&o>a||s<r&&h<r||s>i&&h>i)&&ci(n,s,o-n,h-s,t,r,a,i))return!0}return!1}function fi(e,t,r,a){if(0===r.length)return;let i=a?oi(a):si(e),l=1/0,n=1/0,s=-1/0,o=-1/0;for(let e=0;e<i.length+t.length;e+=2){let r=e<i.length?i[e]:t[e-i.length],a=e<i.length?i[e+1]:t[e+1-i.length];r<l&&(l=r),r>s&&(s=r),a<n&&(n=a),a>o&&(o=a)}let h,c=1/0;for(let e of r){let[r,a,d,f]=e.box;if(s<r+.5||l>d-.5||o<a+.5||n>f-.5)continue;let u=di(i,r+.5,a+.5,d-.5,f-.5);for(let e=0;e<t.length&&!u;e+=2)u=t[e]>r+.5&&t[e]<d-.5&&t[e+1]>a+.5&&t[e+1]<f-.5;if(!u)continue;if(l<r||s>d||n<a||o>f)return"";let p=(d-r)*(f-a);p<c&&(c=p,h=e)}return h}function ui(e,t=""){return(/[";]stroke:/.test(t)?void 0:mt(e.shape))??""}function pi(e,t){let r=/[";]fill:([^;"]*)/.exec(t.shape)?.[1].trim();return r?e.replace(/ fill="var\(--_bg\)"/g,` fill="${r}"`):e}function gi(e,t,r,a="",i){let l=fi(e,t,r,i);return l&&ui(l,a)}function mi(e,t,r="",a=!1){let i=e=>r.includes(e)?new RegExp(`[";]${e}:([^;"]+);`).exec(r)?.[1].trim():void 0,l=i("stroke");if("none"===l||"transparent"===l)return"";let n=a?"2.5":i("stroke-width"),s="",o="";void 0!==n&&/^[\d.]+(?:px)?$/.test(n)?1!==parseFloat(n)&&(s=` stroke-width="${Oe(parseFloat(n)+4)}"`):void 0!==n&&(o+=`stroke-width:calc(${n} + 4px);`);for(let e of["opacity","stroke-opacity"]){let t=i(e);void 0!==t&&(o+=`${e}:${t};`)}let h=`<path d="${e}"/>`+t.replace(/ class="pele-marker"/g,"");return s||o?`<g${s}${o?` style="${o}"`:""}>${h}</g>`:h}function yi(e,t,r,a="",i=!1){return mi(e.d,li(t,e.sx,e.sy,e.sdx,e.sdy,"var(--_bg)","var(--_bg)")+li(r,e.ex,e.ey,e.edx,e.edy,"var(--_bg)","var(--_bg)"),a,i)}function xi(e){return e?`<g class="pele-casings" fill="none" stroke="var(--_bg)" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" pointer-events="none">${e}</g>`:""}function wi(e,t,r,a,i,l){let n=t.width+8,s=t.height;return`<g class="pele-edge-label" data-id="${Re(e)}"><rect x="${Oe(r-n/2)}" y="${Oe(a-s/2)}" width="${Oe(n)}" height="${Oe(s)}" rx="3" fill="var(--_bg)"/>`+Fe(t,r,a,i,l)+"</g>"}function $i(e,t,r,a,i,l,n,s){let o=(i?t:r)/2,h=Math.min(o-4,8+6*a),c=l+8*a,d=Math.hypot(c,h)||1,f=(a,l)=>i?`${Oe(e.x+l)},${Oe(e.y+r/2+a)}`:`${Oe(e.x+t/2+a)},${Oe(e.y+l)}`,u=c/d*n,p=h/d*n;return i?(s.labelX=e.x,s.labelY=e.y+r/2+c+4+s.labelH/2):(s.labelX=e.x+t/2+c+4+s.labelW/2,s.labelY=e.y),{d:`M${f(0,-h)}C${f(c,2*-h)} ${f(c,2*h)} ${f(u,h+p)}`,sx:i?e.x-h:e.x+t/2,sy:i?e.y+r/2:e.y-h,sdx:i?0:-1,sdy:i?-1:0,ex:i?e.x+h:e.x+t/2,ey:i?e.y+r/2:e.y+h,edx:i?-h/d:-c/d,edy:i?-c/d:-h/d}}var bi="var(--_fm)",Mi=' style="rx:var(--_r)"',vi=/[";]fill:/,ki=e=>vi.test(e);function Ai(e){let t=e.indexOf(' style="');return t<0?e+Mi:`${e.slice(0,t+8)}rx:var(--_r);${e.slice(t+8)}`}var Ti="var(--pele-critical,#e45756)",Ci=String.raw`(?:"[^"'\\\n<>{}();:@]*"|'[^"'\\\n<>{}();:@]*'|[\p{L}\p{N}_-][\p{L}\p{N}_ .-]*)`,Ei=new RegExp(String.raw`^\s*${Ci}(?:\s*,\s*${Ci})*\s*$`,"u");function _i(e,t){return e&&Ei.test(e)?e:t}var Si=new Set(["fill","fill-opacity","stroke","stroke-width","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-opacity","opacity","rx","ry"]),Ii=new Set(["color","font-size","font-family","font-weight","font-style","text-decoration","letter-spacing","word-spacing","opacity"]),Ni=/url\s*\(|expression\s*\(|javascript:|[<>{};\\]|@import|image-set|\/\*/i,Di={shape:"",line:"",text:"",stroke:void 0,bold:!1,italic:!1,fontSize:void 0};function Ri(e){if(0===e.length)return Di;let t=new Map,r=new Map;for(let a of e){let e=a.indexOf(":");if(e<=0)continue;let i=a.slice(0,e).trim().toLowerCase(),l=a.slice(e+1).replace(/!important/gi,"").trim();""===l||Ni.test(l)||Ne.test(l)||(Si.has(i)&&t.set(i,l),Ii.has(i)&&r.set("color"===i?"fill":i,l))}if(0===t.size&&0===r.size)return Di;let a="",i="";for(let[e,r]of t)a+=`${e}:${r};`,"fill"!==e&&"fill-opacity"!==e&&(i+=`${e}:${r};`);let l="";for(let[e,t]of r)l+=`${e}:${t};`;let n=r.get("font-weight"),s=r.get("font-size"),o=s&&/^[\d.]+(px)?$/.test(s)?parseFloat(s):void 0;return{shape:a?` style="${De(a)}"`:"",line:i?` style="${De(i)}"`:"",text:l?` style="${De(l)}"`:"",stroke:t.get("stroke"),bold:"bold"===n||"bolder"===n||Number(n)>=600,italic:"italic"===r.get("font-style"),fontSize:void 0!==o&&o>0&&o<=200?o:void 0}}var Li=/[^\w-]+/g;function Oi(e){let t=e.replace(Li," ").trim();return""===t?"":" "+t}var Fi=["#4c78a8","#f58518","#54a24b","#e45756","#72b7b2","#eeca3b","#b279a2","#9d755d"];function zi(e){let t=(e%8+8)%8;return`var(--pele-series-${t+1},${Fi[t]})`}var Wi=[["tw","title"],["hw","heading"],["w","bold"]],Pi=/var\(--_(r|tw|hw|w)\)/g;function Bi(e,t,r,a,i,l,n){let s=De(i.idPrefix??"pele"),o="",h="";l.accTitle&&(o+=`<title id="${s}-title">${Re(l.accTitle)}</title>`,h+=` aria-labelledby="${s}-title"`),l.accDescr&&(o+=`<desc id="${s}-desc">${Re(l.accDescr)}</desc>`,h+=` aria-describedby="${s}-desc"`);let c=!1===i.responsive?"":"max-width:100%;height:auto;",d=new Set;for(let[,e]of n.matchAll(Pi))if(d.add(e),4===d.size)break;let f=d.has("r")?";--_r:var(--pele-radius,4px)":"";for(let[e,t]of Wi)d.has(e)&&(f+=`;--_${e}:var(--pele-${t}-weight,bold)`);return`<svg xmlns="http://www.w3.org/2000/svg" class="pele pele-${e}" viewBox="0 0 ${t} ${r}" width="${t}" height="${r}" style="${c}--_bg:var(--pele-bg,#fff);--_fg:var(--pele-fg,#1f1f1f);--_m:var(--pele-muted,#6e6e6e);--_l:var(--pele-line,#1f1f1f);--_s:var(--pele-surface,#f3f3f3);--_a:var(--pele-surface-alt,#e6e6e6);--_b:var(--pele-border,#8a8a8a);--_c:var(--pele-accent,#5b7bd5);color:var(--_fg)${f}${De(function(e,t,r){return`;--_fm:var(--pele-font-mono,${_i(r,"monospace")});font:${e}px sans-serif;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;font-family:var(--pele-font,${_i(t,"sans-serif")})`}(a,i.fontFamily,i.fontFamilyMono))}${_t.style}" fill="var(--_fg)" role="graphics-document document" aria-roledescription="${e}"${h}>`+o+n+"</svg>"}var Hi=12,Yi=(e,t,r)=>(r?t:e)-24,Gi=e=>(t,r,a)=>a?0:t-2*e(r)-24;function Ui(e,t,r){let a=Math.min(1,Math.abs(e)/t);return r*(1-Math.sqrt(1-a*a))}var qi=(e,t,r,a)=>1&r?Ui(a,t/2,e/2):Ui(a,e/2,t/2),ji=(e,t,r)=>.6*(r?t:e),Vi=(e,t,r,a)=>1&r?0:Ui(a,e/2,Math.min(12,Math.max(6,e/14))),Xi=(e,t)=>()=>({w:e,h:t,dy:0});function Ki(e,t,r){let a=Math.max(1.6*e+40,80),i=(t+10)/(1-(e+8)/a),l=i/2-10-t/2;return{w:a,h:i,dy:r?-l:l}}function Zi(e,t){return`<path d="${e}"${t}/>`}var Qi=(e,t,r)=>1&r?t/8:0,Ji=(e,t)=>({w:Math.max(e+36,48),h:t+24,dy:0});function el(e,t){let r="";for(let t=0;t<e.length;t+=2)r+=(t?" ":"")+Oe(e[t])+","+Oe(e[t+1]);return`<polygon points="${r}"${t}/>`}function tl(e,t,r,a=""){return`<rect x="${Oe(-e/2)}" y="${Oe(-t/2)}" width="${Oe(e)}" height="${Oe(t)}"${a}${r}/>`}var rl={rect:{size:Ji,span:Yi,draw:(e,t,r)=>tl(e,t,Ai(r))},rounded:{size:Ji,span:Yi,draw:(e,t,r)=>tl(e,t,r,` rx="${Oe(Math.min(12,t/2))}"`)},stadium:{inset:(e,t,r,a)=>1&r?Ui(a,t/2,t/2):0,span:(e,t,r)=>r?.6*t:e-t,size:(e,t)=>{let r=t+24;return{w:e+.5*r+36-8,h:r,dy:0}},draw:(e,t,r)=>tl(e,t,r,` rx="${Oe(t/2)}"`)},"fr-rect":{span:Yi,size:(e,t)=>({w:e+36+16,h:t+24,dy:0}),draw:(e,t,r,a)=>{let i=e/2-8;return tl(e,t,Ai(r))+`<path d="M${Oe(-i)},${Oe(-t/2)}V${Oe(t/2)}M${Oe(i)},${Oe(-t/2)}V${Oe(t/2)}" fill="none"${a}/>`}},cyl:{inset:Vi,span:(e,t,r)=>r?t-24-12:.6*e,size:(e,t)=>{let r=Math.max(e+36,56),a=Math.min(12,Math.max(6,r/14));return{w:r,h:t+24+2*a,dy:a/2}},draw:(e,t,r,a)=>{let i=e/2,l=Math.min(12,Math.max(6,e/14)),n=-t/2+l,s=t/2-l;return`<path d="M${Oe(-i)},${Oe(n)}A${Oe(i)},${Oe(l)} 0 0 1 ${Oe(i)},${Oe(n)}V${Oe(s)}A${Oe(i)},${Oe(l)} 0 0 1 ${Oe(-i)},${Oe(s)}Z"${r}/><path d="M${Oe(-i)},${Oe(n)}A${Oe(i)},${Oe(l)} 0 0 0 ${Oe(i)},${Oe(n)}" fill="none"${a}/>`}},circle:{inset:qi,span:ji,size:(e,t)=>{let r=Math.max(Math.sqrt(e*e+t*t)+16,44);return{w:r,h:r,dy:0}},draw:(e,t,r)=>`<circle r="${Oe(e/2)}"${r}/>`},"dbl-circ":{inset:qi,span:ji,size:(e,t)=>{let r=Math.max(Math.sqrt(e*e+t*t)+26,54);return{w:r,h:r,dy:0}},draw:(e,t,r,a)=>`<circle r="${Oe(e/2)}"${r}/><circle r="${Oe(e/2-5)}" fill="none"${a}/>`},ellipse:{inset:qi,span:ji,size:(e,t)=>({w:1.3*e+36,h:1.2*t+24,dy:0}),draw:(e,t,r)=>`<ellipse rx="${Oe(e/2)}" ry="${Oe(t/2)}"${r}/>`},diam:{inset:(e,t,r,a)=>1&r?Math.abs(a)*e/t:Math.abs(a)*t/e,span:(e,t,r)=>.6*(r?t:e),size:(e,t)=>{let r=e+16,a=t+8;return{w:r+1.6*a,h:r/1.6+a,dy:0}},draw:(e,t,r)=>el([0,-t/2,e/2,0,0,t/2,-e/2,0],r)},hex:{inset:(e,t,r,a)=>1&r?Math.abs(a)/2:0,span:(e,t,r)=>r?.5*t:e-t/2-Hi,size:(e,t)=>{let r=t+24;return{w:e+36+r/2,h:r,dy:0}},draw:(e,t,r)=>{let a=t/4;return el([-e/2+a,-t/2,e/2-a,-t/2,e/2,0,e/2-a,t/2,-e/2+a,t/2,-e/2,0],r)}},odd:{inset:(e,t,r)=>3===r?t/4:0,span:Gi(()=>0),size:(e,t)=>{let r=t+24;return{w:e+36+r/4,h:r,dy:0}},draw:(e,t,r)=>el([-e/2,-t/2,e/2,-t/2,e/2,t/2,-e/2,t/2,-e/2+t/4,0],r)},"lean-r":{inset:Qi,span:Gi(e=>e/4),size:(e,t)=>{let r=t+24;return{w:e+36+r/2,h:r,dy:0}},draw:(e,t,r)=>{let a=t/4;return el([-e/2+a,-t/2,e/2,-t/2,e/2-a,t/2,-e/2,t/2],r)}},"lean-l":{inset:Qi,span:Gi(e=>e/4),size:(e,t)=>{let r=t+24;return{w:e+36+r/2,h:r,dy:0}},draw:(e,t,r)=>{let a=t/4;return el([-e/2,-t/2,e/2-a,-t/2,e/2,t/2,-e/2+a,t/2],r)}},"trap-b":{inset:Qi,span:Gi(e=>e/4),size:(e,t)=>{let r=t+24;return{w:e+36+r/2,h:r,dy:0}},draw:(e,t,r)=>{let a=t/4;return el([-e/2+a,-t/2,e/2-a,-t/2,e/2,t/2,-e/2,t/2],r)}},"trap-t":{inset:Qi,span:Gi(e=>e/4),size:(e,t)=>{let r=t+24;return{w:e+36+r/2,h:r,dy:0}},draw:(e,t,r)=>{let a=t/4;return el([-e/2,-t/2,e/2,-t/2,e/2-a,t/2,-e/2+a,t/2],r)}},text:{bare:!0,span:Yi,size:(e,t)=>({w:e+8,h:t+8,dy:0}),draw:(e,t)=>tl(e,t,' fill="none" stroke="none"')},"sm-circ":{noLabel:!0,inset:qi,span:ji,size:Xi(14,14),draw:(e,t,r)=>`<circle r="${Oe(e/2)}"${r}/>`},"f-circ":{noLabel:!0,inset:qi,span:ji,size:Xi(14,14),draw:(e,t,r,a)=>`<circle r="${Oe(e/2)}" fill="var(--_l)"${a}/>`},"fr-circ":{noLabel:!0,inset:qi,span:ji,size:Xi(18,18),draw:(e,t,r,a)=>`<circle r="${Oe(e/2)}"${r}/><circle r="${Oe(e/2-4)}" fill="var(--_l)"${a}/>`},fork:{noLabel:!0,span:(e,t,r)=>(r?t:e)-8,size:Xi(72,8),draw:(e,t,r,a)=>tl(e,t,` fill="var(--_l)"${a}`,' rx="2"')},"notch-rect":{size:Ji,span:Yi,draw:(e,t,r)=>el([-e/2+10,-t/2,e/2,-t/2,e/2,t/2,-e/2,t/2,-e/2,-t/2+10],r)},"lin-rect":{span:Yi,size:(e,t)=>({w:e+36+8,h:t+24,dy:0}),draw:(e,t,r,a)=>tl(e,t,Ai(r))+`<path d="M${Oe(-e/2+8)},${Oe(-t/2)}V${Oe(t/2)}" fill="none"${a}/>`},"div-rect":{span:Yi,size:(e,t)=>({w:e+36,h:t+24+8,dy:4}),draw:(e,t,r,a)=>tl(e,t,Ai(r))+`<path d="M${Oe(-e/2)},${Oe(-t/2+8)}H${Oe(e/2)}" fill="none"${a}/>`},"win-pane":{span:Yi,size:(e,t)=>({w:e+36+8,h:t+24+8,dy:4}),draw:(e,t,r,a)=>tl(e,t,Ai(r))+`<path d="M${Oe(-e/2+8)},${Oe(-t/2)}V${Oe(t/2)}M${Oe(-e/2)},${Oe(-t/2+8)}H${Oe(e/2)}" fill="none"${a}/>`},tri:{inset:(e,t,r)=>1&r?e/4:0,size:(e,t)=>Ki(e,t,!1),draw:(e,t,r)=>el([0,-t/2,e/2,t/2,-e/2,t/2],r)},"flip-tri":{inset:(e,t,r)=>1&r?e/4:0,size:(e,t)=>Ki(e,t,!0),draw:(e,t,r)=>el([-e/2,-t/2,e/2,-t/2,0,t/2],r)},"sl-rect":{inset:(e,t,r)=>0===r?5:0,size:(e,t)=>({w:e+36,h:t+24+10,dy:5}),draw:(e,t,r)=>el([-e/2,-t/2+10,e/2,-t/2,e/2,t/2,-e/2,t/2],r)},"notch-pent":{span:Yi,size:(e,t)=>({w:e+36,h:t+24,dy:0}),draw:(e,t,r)=>el([-e/2+10,-t/2,e/2-10,-t/2,e/2,-t/2+10,e/2,t/2,-e/2,t/2,-e/2,-t/2+10],r)},hourglass:{noLabel:!0,inset:(e,t,r)=>1&r?e/2:0,size:Xi(32,40),draw:(e,t,r)=>el([-e/2,-t/2,e/2,-t/2,-e/2,t/2,e/2,t/2],r)},delay:{size:(e,t)=>{let r=t+24;return{w:e+36+r/4,h:r,dy:0}},draw:(e,t,r)=>{let a=t/2;return`<path d="M${Oe(-e/2)},${Oe(-a)}H${Oe(e/2-a)}A${Oe(a)},${Oe(a)} 0 0 1 ${Oe(e/2-a)},${Oe(a)}H${Oe(-e/2)}Z"${r}/>`}},"h-cyl":{size:(e,t)=>{let r=t+24;return{w:e+36+2*Math.min(12,r/4),h:r,dy:0}},draw:(e,t,r,a)=>{let i=t/2,l=Math.min(12,t/4),n=-e/2+l,s=e/2-l;return`<path d="M${Oe(n)},${Oe(-i)}H${Oe(s)}A${Oe(l)},${Oe(i)} 0 0 1 ${Oe(s)},${Oe(i)}H${Oe(n)}A${Oe(l)},${Oe(i)} 0 0 1 ${Oe(n)},${Oe(-i)}Z"${r}/><path d="M${Oe(s)},${Oe(-i)}A${Oe(l)},${Oe(i)} 0 0 0 ${Oe(s)},${Oe(i)}" fill="none"${a}/>`}},"cross-circ":{noLabel:!0,inset:qi,span:ji,size:Xi(44,44),draw:(e,t,r,a)=>{let i=e/2,l=i*Math.SQRT1_2;return`<circle r="${Oe(i)}"${r}/><path d="M${Oe(-l)},${Oe(-l)}L${Oe(l)},${Oe(l)}M${Oe(l)},${Oe(-l)}L${Oe(-l)},${Oe(l)}" fill="none"${a}/>`}},"st-rect":{span:(e,t,r)=>(r?t:e)-24-8,size:(e,t)=>({w:e+36+8,h:t+24+8,dy:4}),draw:(e,t,r)=>{let a=e-8,i=t-8,l="";for(let n=0;n<3;n++){let s=-t/2+4*n;l+=`<rect x="${Oe(-e/2+4*(2-n))}" y="${Oe(s)}" width="${Oe(a)}" height="${Oe(i)}"${Ai(r)}/>`}return l}},doc:{inset:(e,t,r)=>2===r?10:0,size:(e,t)=>({w:e+36,h:t+24+10,dy:-5}),draw:(e,t,r)=>il(e,t,r)},flag:{inset:(e,t,r)=>1&r?0:8,size:(e,t)=>({w:e+36,h:t+24+16,dy:0}),draw:(e,t,r)=>{let a=t/2-8,i=e/4;return`<path d="M${Oe(-(e/2))},${Oe(-a)}q${Oe(i)},-10 ${Oe(2*i)},0t${Oe(2*i)},0V${Oe(a)}q${Oe(-i)},10 ${Oe(-2*i)},0t${Oe(-2*i)},0Z"${r}/>`}},datastore:{size:Ji,span:Yi,draw:(e,t,r,a)=>tl(e,t,r.replace('stroke="var(--_b)"','stroke="none"'))+`<path d="M${Oe(-e/2)},${Oe(-t/2)}H${Oe(e/2)}M${Oe(-e/2)},${Oe(t/2)}H${Oe(e/2)}" fill="none"${a}/>`},folder:{size:(e,t)=>({w:Math.max(e+36,64),h:t+24+8,dy:4}),draw:(e,t,r)=>{let a=e/2,i=t/2,l=Math.min(.4*e,48);return Zi(`M${Oe(-a)},${Oe(-i)}H${Oe(-a+l)}L${Oe(-a+l+8)},${Oe(8-i)}H${Oe(a)}V${Oe(i)}H${Oe(-a)}Z`,r)}},bucket:{size:(e,t)=>({w:e+36+20,h:t+24+10,dy:3}),inset:(e,t,r)=>1&r?t/12:0,draw:(e,t,r,a)=>{let i=e/2,l=t/2,n=t/6;return Zi(`M${Oe(-i)},${Oe(5-l)}A${Oe(i)},${Oe(5)} 0 0 1 ${Oe(i)},${Oe(5-l)}L${Oe(i-n)},${Oe(l-5)}A${Oe(i-n)},${Oe(5)} 0 0 1 ${Oe(-i+n)},${Oe(l-5)}Z`,r)+`<path d="M${Oe(-i)},${Oe(5-l)}A${Oe(i)},${Oe(5)} 0 0 0 ${Oe(i)},${Oe(5-l)}" fill="none"${a}/>`}},console:{span:Yi,size:(e,t)=>({w:Math.max(e+36,72),h:t+24+12,dy:6}),draw:(e,t,r,a)=>tl(e,t,Ai(r))+`<path d="M${Oe(-e/2)},${Oe(-t/2+12)}H${Oe(e/2)}M${Oe(-e/2+7)},${Oe(-t/2+4)}l3,2.5l-3,2.5M${Oe(-e/2+13)},${Oe(-t/2+9)}h4" fill="none"${a}/>`},browser:{span:Yi,size:(e,t)=>({w:Math.max(e+36,72),h:t+24+12,dy:6}),draw:(e,t,r,a)=>{let i="";for(let r=0;r<3;r++)i+=`<circle cx="${Oe(-e/2+8+7*r)}" cy="${Oe(-t/2+6)}" r="1.5" fill="none"${a}/>`;return tl(e,t,Ai(r))+`<path d="M${Oe(-e/2)},${Oe(-t/2+12)}H${Oe(e/2)}" fill="none"${a}/>`+i}},person:{size:(e,t)=>({w:Math.max(e+36,56),h:t+24+26,dy:13}),draw:(e,t,r)=>{let a=-t/2;return`<rect x="${Oe(-e/2)}" y="${Oe(a+26)}" width="${Oe(e)}" height="${Oe(t-26)}" rx="12"${r}/><circle cy="${Oe(a+14)}" r="13"${r}/>`}},bang:{size:(e,t)=>({w:e+36+28,h:t+24+24,dy:0}),inset:()=>3,draw:(e,t,r)=>{let a=[];for(let r=0;r<28;r++){let i=Math.PI*r/14-Math.PI/2,l=r%2==0?1:.82;a.push(Math.cos(i)*(e/2)*l,Math.sin(i)*(t/2)*l)}return el(a,r)}},cloud:{size:(e,t)=>({w:e+36+32,h:t+24+24,dy:0}),inset:(e,t,r)=>1&r?2:1,draw:(e,t,r)=>{let a=e/2,i=t/2,l=.55*i;return Zi(`M${Oe(-a+l)},${Oe(i)}A${Oe(l)},${Oe(l)} 0 0 1 ${Oe(.6*l-a)},${Oe(.1*-i)}A${Oe(.42*a)},${Oe(.7*i)} 0 0 1 ${Oe(.1*-a)},${Oe(.72*-i)}A${Oe(.4*a)},${Oe(.62*i)} 0 0 1 ${Oe(.62*a)},${Oe(.42*-i)}A${Oe(1.05*l)},${Oe(1.05*l)} 0 0 1 ${Oe(a-l)},${Oe(i)}Z`,r)}},brace:{bare:!0,size:(e,t)=>({w:e+36+12,h:t+24,dy:0}),draw:(e,t,r,a)=>tl(e,t,' fill="none" stroke="none"')+al(-e/2+12,t,-1,a)},"brace-r":{bare:!0,size:(e,t)=>({w:e+36+12,h:t+24,dy:0}),draw:(e,t,r,a)=>tl(e,t,' fill="none" stroke="none"')+al(e/2-12,t,1,a)},braces:{bare:!0,size:(e,t)=>({w:e+36+24,h:t+24,dy:0}),draw:(e,t,r,a)=>tl(e,t,' fill="none" stroke="none"')+al(-e/2+12,t,-1,a)+al(e/2-12,t,1,a)},bolt:{noLabel:!0,size:Xi(36,56),inset:(e,t,r)=>1&r?e/4:0,draw:(e,t,r)=>el([.15*e,-t/2,-e/2,.08*t,.05*-e,.08*t,.15*-e,t/2,e/2,.08*-t,.05*e,.08*-t],r)},"lin-cyl":{inset:Vi,span:(e,t,r)=>r?t-24-20:.6*e,size:(e,t)=>{let r=Math.max(e+36,56),a=Math.min(12,Math.max(6,r/14));return{w:r,h:t+24+2*a+8,dy:a/2+4}},draw:(e,t,r,a)=>{let i=e/2,l=Math.min(12,Math.max(6,e/14)),n=-t/2+l,s=t/2-l,o=e=>`M${Oe(-i)},${Oe(e)}A${Oe(i)},${Oe(l)} 0 0 0 ${Oe(i)},${Oe(e)}`;return Zi(`M${Oe(-i)},${Oe(n)}A${Oe(i)},${Oe(l)} 0 0 1 ${Oe(i)},${Oe(n)}V${Oe(s)}A${Oe(i)},${Oe(l)} 0 0 1 ${Oe(-i)},${Oe(s)}Z`,r)+`<path d="${o(n)}${o(n+8)}" fill="none"${a}/>`}},"curv-trap":{size:(e,t)=>{let r=t+24;return{w:e+36+.6*r,h:r,dy:0}},draw:(e,t,r)=>{let a=e/2,i=t/2,l=.3*t;return Zi(`M${Oe(-a+l)},${Oe(-i)}H${Oe(a-l)}A${Oe(l)},${Oe(i)} 0 0 1 ${Oe(a-l)},${Oe(i)}H${Oe(-a+l)}L${Oe(-a)},0Z`,r)}},docs:{size:(e,t)=>({w:e+36+8,h:t+24+18,dy:-1}),inset:(e,t,r)=>2===r?10:0,draw:(e,t,r)=>{let a="";for(let i=0;i<3;i++)a+=`<g transform="translate(${4*(1-i)},${4*(i-1)})">${il(e-8,t-8,r)}</g>`;return a}},"bow-rect":{size:(e,t)=>{let r=t+24;return{w:e+36+.4*r,h:r,dy:0}},inset:(e,t,r)=>1===r?.2*t:0,draw:(e,t,r)=>{let a=e/2,i=t/2,l=.2*t;return Zi(`M${Oe(-a+l)},${Oe(-i)}H${Oe(a)}A${Oe(l)},${Oe(i)} 0 0 0 ${Oe(a)},${Oe(i)}H${Oe(-a+l)}A${Oe(l)},${Oe(i)} 0 0 1 ${Oe(-a+l)},${Oe(-i)}Z`,r)}},"tag-rect":{size:Ji,span:Yi,draw:(e,t,r,a)=>tl(e,t,Ai(r))+`<path d="M${Oe(e/2-12)},${Oe(t/2)}L${Oe(e/2)},${Oe(t/2-12)}" fill="none"${a}/>`},"tag-doc":{size:(e,t)=>({w:e+36,h:t+24+10,dy:-5}),inset:(e,t,r)=>2===r?10:0,draw:(e,t,r,a)=>il(e,t,r)+`<path d="M${Oe(e/2-12)},${Oe(t/2-14)}L${Oe(e/2)},${Oe(t/2-26)}" fill="none"${a}/>`},"lin-doc":{size:(e,t)=>({w:e+36+8,h:t+24+10,dy:-5}),inset:(e,t,r)=>2===r?10:0,draw:(e,t,r,a)=>il(e,t,r)+`<path d="M${Oe(-e/2+8)},${Oe(-t/2)}V${Oe(t/2-6)}" fill="none"${a}/>`},collapsedGroup:{size:(e,t)=>({w:e+36+8,h:t+24+8,dy:-2}),draw:(e,t,r)=>`<rect x="${Oe(-e/2+6)}" y="${Oe(-t/2+8)}" width="${Oe(e-12)}" height="${Oe(t-8)}"${Ai(r)}/><rect x="${Oe(-e/2)}" y="${Oe(-t/2)}" width="${Oe(e)}" height="${Oe(t-4)}"${Ai(r)}/>`}};function al(e,t,r,a){let i=t/2,l=6*r;return`<path d="M${Oe(e)},${Oe(-i)}q${Oe(l)},0 ${Oe(l)},6V-6q0,6 ${Oe(l)},6q${Oe(-l)},0 ${Oe(-l)},6V${Oe(i-6)}q0,6 ${Oe(-l)},6" fill="none"${a}/>`}function il(e,t,r){let a=e/2,i=-t/2,l=t/2-10,n=e/4;return`<path d="M${Oe(-a)},${Oe(i)}H${Oe(a)}V${Oe(l)}q${Oe(-n)},-12 ${Oe(-2*n)},0t${Oe(-2*n)},0Z"${r}/>`}var ll=rl.rect,nl=new Map(Object.entries(rl));function sl(e,t,r){return(nl.get(e)??ll).size(t,r)}function ol(e,t,r,a,i){return(nl.get(e)??ll).draw(t,r,a,i)}function hl(e,t,r,a,i=0){return nl.get(e)?.inset?.(t,r,a,i)??0}function cl(e){return!0!==nl.get(e)?.noLabel}function dl(e){return!0!==(nl.get(e)??ll).bare}function fl(e,t,r){let a=e[t]-r.x,i=e[t+1]-r.y;return Math.abs(Math.abs(i)-r.h/2)<.5?i<0?0:2:Math.abs(Math.abs(a)-r.w/2)<.5?a<0?3:1:-1}function ul(e,t,r,a){if(a.isGroup)return;let i=fl(e,t,a);if(0===i||2===i){let l=hl(r.shape,r.w,r.h,i,e[t]-a.x)+(a.h-r.h)/2;e[t+1]+=0===i?l:-l}else if(i>=0){let l=hl(r.shape,r.w,r.h,i,e[t+1]-a.y)+(a.w-r.w)/2;e[t]+=3===i?l:-l}}var pl,gl=/<br\s*\/?>|\\n|\n/gi,ml=/<\/?([a-zA-Z][\w-]*)(?:\s[^<>]*)?\/?>/y,yl=/(fa[bklrs]?):fa-([\w-]+)/g,xl=/[<\\\n*_]|fa[bklrs]?:fa-/,wl=new Map([["b",1],["strong",1],["i",2],["em",2],["cite",2],["dfn",2],["var",2],["code",4],["kbd",4],["samp",4],["tt",4],["sub",8],["sup",16],["u",32],["ins",32]]),$l=new Set("a abbr address article aside audio b bdi bdo big blockquote body br button caption center cite code col colgroup data dd del details dfn dialog div dl dt em embed fieldset figcaption figure font footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd label legend li link main map mark meta meter nav noscript object ol optgroup option output p picture pre progress q rp rt ruby s samp script section select small source span strike strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track tt u ul var video wbr".split(" ")),bl="\\u2e80-\\u9fff\\uf900-\\ufaff\\uff00-\\uff60",Ml="、。,.:;!?)]}」』】〕〉》〙〗ー…‥・ゝゞぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮ,.:;!?)\\]}",vl=new RegExp(`[${bl}]`),kl="\\u200b\\u00ad",Al=new RegExp(`[${kl}]`),Tl=new RegExp(`\\s*(?:[([{「『【〔〈《〘〖([{]*[${bl}][${Ml}]*|[^\\s${bl}${kl}]+[${kl}]*[${Ml}]*|[${kl}]+)\\s*|\\s+`,"g"),Cl=/\$\$(.+?)\$\$/g,El=/[\ue000-\uf8ff]/,_l=/([\ue000-\uf8ff])/,Sl={lines:[],widths:[],width:0,height:0,size:0,lineHeight:0};function Il(e){return void 0!==e&&void 0===e.icon&&void 0===e.math}function Nl(e,t,r){if(""!==t){if(void 0!==pl&&El.test(t)){let a=pl,i=t.split(_l);for(let t=0;t<i.length;t++){if(t%2==0){""!==i[t]&&Dl(e,i[t],r);continue}let l=i[t].charCodeAt(0)-57344,n=a.math[l];n?e.push({text:"",style:r,math:n,width:n.width}):Dl(e,`$$${a.tex[l]}$$`,r)}return}Dl(e,t,r)}}function Dl(e,t,r){let a=m(t),i=e[e.length-1];Il(i)&&i.style===r?i.text+=a:e.push({text:a,style:r,width:0})}function Rl(e,t,r,a,i){let l=i.style,n=0,s="",o=0,h=t.length,c=()=>{(function(e,t,r){if(!t.includes(":fa-"))return void Nl(e,t,r);let a,i=0;for(yl.lastIndex=0;null!==(a=yl.exec(t));){let l=`${a[1]}:fa-${a[2]}`;if(Nl(e,t.slice(i,a.index),r),i=a.index+a[0].length,""!==w(l))e.push({text:"",style:r,icon:l,width:0});else if(" "===t[i])i++;else if(i===t.length){let t=e[e.length-1];Il(t)&&(t.text=t.text.trimEnd())}}Nl(e,t.slice(i),r)})(e,s,l|(i.shifts[i.shifts.length-1]??0)),s=""};for(;o<h;){let e=t[o];if("<"===e){ml.lastIndex=o;let e=ml.exec(t);if(e&&e.index===o){let r=e[1].toLowerCase(),n="/"===t[o+1],s=wl.get(r)??0;if(24&s){c();let e=i.shifts.lastIndexOf(s);n?-1!==e&&i.shifts.splice(e,1):i.shifts.push(s)}else s&&(c(),i.style=n?i.style&~s|a&s:i.style|s,l=n?l&~s|a&s:l|s);if(s||$l.has(r)){o+=e[0].length;continue}}}else if(r&&("*"===e||"_"===e)){let r=t[o+1]===e,i=r?1:2,s=r?2:1,d=0===(n&i),f=o>0?t[o-1]:" ",u=o+s<h?t[o+s]:" ",p=d&&""!==u.trim()&&-1!==t.indexOf(r?e+e:e,o+s),g=!d&&""!==f.trim(),m="_"===e&&/\w/.test(f)&&/\w/.test(u);if((p||g)&&!m){c(),n=p?n|i:n&~i,l=p?l|i:l&~i|a&i,o+=s;continue}}s+=e,o++}c()}function Ll(e,t,r){let a=0;for(let i of e)i.width=void 0!==i.icon?1.25*r:i.math?i.math.width:t.width(i.text,r,i.style),a+=i.width;return a}function Ol(e,t,r,a,i,l){let n=[],s=0,o=(e=!1)=>{let a=n[n.length-1];if(Il(a)){let i=a.text.trimEnd();if(e&&a.text.endsWith("­")&&(i=i.slice(0,-1)+"-"),i!==a.text){a.text=i;let e=t.width(i,r,a.style);s+=e-a.width,a.width=e}}i.push(n),l.push(s),n=[],s=0};for(let i of e){if(void 0!==i.icon||i.math){let e=i.math?i.math.width:1.25*r;s>0&&s+e>a&&o(),n.push({...i,width:e}),s+=e;continue}let l=i.text.match(Tl)??[],h=i.text.includes("­"),c=h?l.length:0,d=new Float64Array(c),f=new Float64Array(c+1);for(let a=c-1;a>=0;a--){let n=l[a].endsWith("­"),s=l[a].trimEnd();d[a]=t.width(n?s.slice(0,-1):s,r,i.style),f[a]=n?a===c-1?i===e[e.length-1]?d[a]:1/0:d[a]+f[a+1]:d[a]}for(let e=0;e<l.length;e++){let c=l[e],u=h?d[e]:t.width(c.trimEnd(),r,i.style),p=h&&c.endsWith("­")?s+t.width(c.slice(0,-1)+"-",r,i.style)<=a||s+f[e]<=a:s+u<=a;s>0&&!p&&(o(c.trimStart()===c),c=c.trimStart());let g=n[n.length-1];if(Il(g)&&g.style===i.style){if(g.text+=c,u>0||c.trimEnd()!==c){let e=g.width;g.width=t.width(g.text,r,g.style),s+=g.width-e}}else{let e=t.width(c,r,i.style);n.push({text:c,style:i.style,width:e}),s+=e}}}(n.length>0||0===i.length)&&o()}function Fl(e,t,r,a,i,l=0){if(void 0===e||""===e)return Sl;let n=Math.round(1.5*a);if(void 0!==$&&e.includes("$$")&&!El.test(e)){let s={tex:[],math:[]},o=e.replace(Cl,(e,t)=>6400===s.tex.length?e:(s.tex.push(t),String.fromCharCode(57344+s.tex.length-1)));if(s.tex.length>0){for(let e of s.tex)s.math.push(v(m(e),a));return zl(o,t,r,a,i,l,n,s)}}if(!xl.test(e)&&!e.includes("&")&&!e.includes("fl")){let t=e.trim(),s=r.width(t,a,l);if(s<=i||!(t.includes(" ")||vl.test(t)||Al.test(t)))return{lines:[[{text:t,style:l,width:s}]],widths:[s],width:s,height:n,size:a,lineHeight:n};let o=[],h=[];Ol([{text:t,style:l,width:s}],r,a,i,o,h);let c=0;for(let e of h)e>c&&(c=e);let d=o.length>1?Math.round(1.3*a):n;return{lines:o,widths:h,width:c,height:o.length*d,size:a,lineHeight:d}}return zl(e,t,r,a,i,l,n)}function zl(e,t,r,a,i,l,n,s){let o=pl;pl=s;try{let o=function(e,t,r,a,i,l,n){let s=t?function(e){let t=e.split("\n"),r=1/0;for(let e of t){if(""===e.trim())continue;let t=e.length-e.trimStart().length;t<r&&(r=t)}return r===1/0||0===r?e:t.map(e=>e.slice(Math.min(r,e.length-e.trimStart().length))).join("\n")}(e.replace(/\r\n?/g,"\n")).trim():e.trim(),o=[],h=[],c=0,d={style:l,shifts:[]};for(let e of s.split(gl)){let n=[];Rl(n,e.trim(),t,l,d);let s=Ll(n,r,a);s>i?Ol(n,r,a,i,o,h):(o.push(n),h.push(s))}for(let e of h)e>c&&(c=e);let f=o.length>1?Math.round(1.3*a):n;return{lines:o,widths:h,width:c,height:o.length*f,size:a,lineHeight:f}}(e,t,r,a,i,l,n);return s?Wl(o):o}finally{pl=o}}function Wl(e){let t;for(let r=0;r<e.lines.length;r++){let a=e.lineHeight;for(let t of e.lines[r])t.math&&(a=Math.max(a,Math.ceil(t.math.height+e.size/4)));a!==e.lineHeight&&void 0===t&&(t=e.lines.map(()=>e.lineHeight)),t&&(t[r]=a)}if(void 0===t)return void 0===e.heights?e:{...e,heights:void 0,height:e.lines.length*e.lineHeight};let r=0;for(let e of t)r+=e;return{...e,heights:t,height:r}}function Pl(e){for(let t of e)if(t.math)return!0;return!1}function Bl(e,t){let r=e.heights;if(!r)return(t+.5)*e.lineHeight;let a=0;for(let e=0;e<t;e++)a+=r[e];return a+r[t]/2}function Hl(e,t){let r=e.widths[t],a=e.heights?e.heights[t]:e.lineHeight,i={lines:[e.lines[t]],widths:[r],width:r,height:a,size:e.size,lineHeight:e.lineHeight};return a!==e.lineHeight&&(i.heights=[a]),i}function Yl(e,t,r,a){let i=a(t,!1),l=e.maxWidth;if(void 0===l||!(l>0)||i.width<=l)return i;let n=Math.min(r,t),s=t;i=a(s,!0);for(let e=0;e<3&&i.width>l&&s>n;e++)s=Math.max(n,s-(i.width-l)),i=a(s,!0);return i}function Gl(e){let t=e.maxWidth;return void 0!==t&&t>0?Math.max(80,t-2*(e.padding??8)):4e3}function Ul(e,t,r,a=0){let i=e.maxWidth;return void 0!==i&&i>0?Math.max(Math.min(r,t),Math.min(t,i-a)):t}function ql(e,t){let r=t(!1),a=e.maxWidth;if(!1===e.autoDirection||void 0===a||!(a>0)||r.width<=a)return r;let i=e.directionBreakpoint;if(a>=(void 0!==i&&i>0?i:640))return r;let l=t(!0);return l.width<r.width?l:r}function jl(e){return"LR"===e||"RL"===e}function Vl(e,t){let r=t(!1),a=e.maxWidth;if(void 0===a||!(a>0)||r.width<=a)return r;let i=t(!0);return i.width<r.width?i:r}var Xl=new Map([["tool",0],["task",1],["decision",2],["input",3],["refdoc",4],["connector",5],["action",6]]),Kl=Xl.size,Zl=(e,t)=>{let r=Kl+e%(e=>Math.max(1,e-Kl))(t);return t>0?r%t:r};function Ql(e,t,r){let a=[],i=[],l=e.subgraphs,n=t=>{let r=[];for(let a of t){let t=e.classes.get(a);t?.styles&&(r=[...r,...t.styles].map(e=>e.trim())),t?.textStyles&&(r=[...r,...t.textStyles].map(e=>e.trim()))}return r},s=new Set,o=new Map,h=new Set;for(let t of l){if("collapsed"!==t.metadata?.view||s.has(t.id))continue;let r=[t.id];for(;r.length>0;){let a=e.subgraph(r.pop())?.nodes;if(void 0!==a)for(let e of a)e===t.id||s.has(e)||(s.add(e),o.set(e,t.id),h.has(e)||r.push(e))}h.add(t.id)}let c=new Map;for(let e of s){let t=[e],r=o.get(e);for(;;){let e=c.get(r),a=e??o.get(r);if(void 0===a||(void 0===e&&t.push(r),r=a,void 0!==e))break}for(let e of t)c.set(e,r)}let d=new Map;l.forEach((e,t)=>d.set(e.id,t));let f=new Map,u=(e,t,r)=>{let a=d.get(e);if(void 0===a||a<r)return!1;let i=t;for(let t=0;void 0!==i&&t<=l.length;t++){if(i===e)return!0;i=f.get(i)}return!1};for(let t=l.length-1;t>=0;t--){let r=l[t];if(!s.has(r.id))for(let a of r.nodes)u(a,r.id,t)?e.emitWarning("CONTAINMENT_VIOLATION",`Container "${r.id}" cannot contain "${a}" because "${a}" already contains it. The nesting that would close the loop is dropped.`,{nodeId:a}):f.set(a,r.id)}let p=new Map;for(let e=l.length-1;e>=0;e--){let t=l[e];if(s.has(t.id))continue;let r="collapsed"===t.metadata?.view,i={id:t.id,label:t.title,labelType:t.labelType,parentId:f.get(t.id),cssStyles:[],cssCompiledStyles:n(t.classes),cssClasses:t.classes.join(" "),shape:r?"collapsedGroup":"flowGroup",dir:t.dir,isGroup:!r,metadata:r?{...t.metadata,containerType:t.type}:t.metadata};a.push(i),p.set(t.id,i)}for(let t of e.nodes.values()){if(s.has(t.id))continue;let r=p.get(t.id);if(r){r.cssStyles=t.styles,r.cssCompiledStyles=n(t.classes),r.cssClasses=t.classes.join(" ");continue}let i=Nr(t.type),l={id:t.id,label:t.text,labelType:t.labelType,parentId:f.get(t.id),cssStyles:t.styles,cssCompiledStyles:n(["default","node",...t.classes]),cssClasses:"default "+t.classes.join(" "),dir:t.dir,link:t.link,linkTarget:t.linkTarget,tooltip:e.tooltips.get(t.id),metadata:t.metadata,isGroup:!1,shape:"square"===i||void 0===i?"squareRect":i};a.push(l),p.set(t.id,l)}e.edges.forEach((t,a)=>{let l=c.get(t.start)??t.start,s=c.get(t.end)??t.end;if(l===s&&t.start!==t.end)return;let o=[...e.defaultEdgeStyle??[]];t.style&&o.push(...t.style);let h="arrow_open"===t.type?"none":"arrow_cross"===t.type||"arrow_point"===t.type?t.type:"arrow_point";i.push({id:t.id||`L_${l}_${s}_${a}`,isUserDefinedId:t.isUserDefinedId,start:l,end:s,type:t.type??"normal",label:t.text,labelType:t.labelType,thickness:t.stroke,pattern:t.stroke,minlen:t.length,classes:"edge-thickness-normal edge-pattern-solid flowchart-link",arrowTypeStart:"none",arrowTypeEnd:h,cssCompiledStyles:n(t.classes),style:o,animate:t.animate,animation:t.animation,curve:t.interpolate||e.defaultInterpolate||r,metadata:t.metadata})}),function(e,t){for(let r of e)r.isGroup||((!r.shape||"squareRect"===r.shape||"rect"===r.shape)&&(r.shape=Ir),_r.has(r.shape)?(t.emitError("SHAPE_REMOVED",`shape "${r.shape}" was removed in v0.8.1, using "${Ir}"`,{nodeId:r.id}),r.shape=Ir):Sr.has(r.shape)||(t.emitWarning("SHAPE_UNSUPPORTED",`shape "${r.shape}" is not supported, using "${Ir}"`,{nodeId:r.id}),r.shape=Ir))}(a,e);let g=new Map;for(let e of l){let t=f.get(e.id);if(void 0===t)continue;let r=g.get(t);r?r.push(e.id):g.set(t,[e.id])}let m=new Map;for(let e of l){if(void 0!==f.get(e.id))continue;let t=[e.id];for(;t.length>0;){let e=t.pop();if(m.has(e))continue;m.set(e,m.size);let r=g.get(e);if(r)for(let e=r.length-1;e>=0;e--)t.push(r[e])}}return function(e,t,r,a){let i=r.size;for(let l of e){if(l.isGroup||"collapsedGroup"===l.shape){l.colorIndex=Zl(r.get(l.id)??i++,a);continue}let e=t(l.id);e&&Xl.has(e)&&(l.kind=e)}}(a,t=>{if(e.connectors.has(t))return"connector";let r=e.nodes.get(t);return r?e.vertexKind(r):void 0},m,t),{nodes:a,edges:i}}var Jl="collapsed",en={TB:2,RL:3,BT:0,LR:1},tn=new WeakMap;function rn(e,t){let r=tn.get(e);if(void 0===r){let a=t.flowchart?.curve;r=Ql(e,8,"string"==typeof a?a:void 0),tn.set(e,r)}return r}function an(e,t,r){let a=e.agentflow?.[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}function ln(e,t,r){let a=zi(e);return` fill="${a}"${ki(r.shape)?"":` fill-opacity="${t}"`} stroke="${a}"`}function nn(e,t,r,a){let i=rn(e,t),l=r.fontSize??16,n=Math.round(.875*l),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=an(t,"wrappingWidth",120),h=an(t,"minNodeWidth",120),c=r.padding??8,d=r.icons,f=new Map,u=[],p=[];i.nodes.forEach((e,t)=>f.set(e.id,t));for(let e of i.nodes){let t,r,a=Ri(e.cssStyles.length>0?e.cssCompiledStyles.concat(e.cssStyles):e.cssCompiledStyles),i=(a.bold?1:0)|(a.italic?2:0),n="markdown"===e.labelType,c=a.fontSize??l;if(e.isGroup){let l=Fl(e.label,n,s,c,4e3,i);t={node:e,style:a,label:l,shape:"group",w:0,h:0,dy:0,loops:0},r=Va(0,0),r.isGroup=!0,r.dir=e.dir?Pa(e.dir):void 0,r.padX=20,r.padTop=l.height>0?l.height+16:20,r.padBottom=20,r.minW=l.width+40-12}else if("collapsedGroup"===e.shape){let l=Fl(e.label,n,s,c,o,i),d=Math.max(l.width,h)+36,f=l.height+24+14;t={node:e,style:a,label:l,shape:Jl,w:d,h:f,dy:-7,loops:0},r=Va(d,f)}else{let l=Cr(e.shape),d=Fl(e.label,n,s,c,o,i),f=sl(l,"diam"===l?d.width:Math.max(d.width,h),d.height);t={node:e,style:a,label:d,shape:l,w:f.w,h:f.h,dy:f.dy,loops:0},r=Va(f.w,f.h)}r.seq=u.length,u.push(t),p.push(r)}i.nodes.forEach((e,t)=>{p[t].parent=void 0!==e.parentId?f.get(e.parentId)??-1:-1}),qa(p,i.edges.map(e=>[f.get(e.start)??-1,f.get(e.end)??-1]));let g=a?"TB":Pa(e.direction),y=e=>{let t;for(let r=p[e].parent,a=0;r>=0&&void 0===t&&a<1e4;r=p[r].parent,a++)t=p[r].dir;return t??g},x=e=>{let t=y(e);return"LR"===t||"RL"===t},w=new Int32Array(p.length).fill(-1);for(let e=0;e<p.length;e++){let t=[],r=e;for(;r>=0&&w[r]<0&&t.length<=p.length;)t.push(r),r=p[r].parent;let a=r>=0?w[r]+1:0;for(let e=t.length-1;e>=0;e--)w[t[e]]=a++}let $=(e,t)=>{let r=t;for(let a=w[t];a>w[e];a--)r=p[r].parent;return r===e&&t!==e},b=[],M=[],v=[],k=[];for(let e of i.edges){let t=f.get(e.start),r=f.get(e.end);if(void 0===t||void 0===r)continue;let a=Fl(e.label,"markdown"===e.labelType,s,n,o);$(t,r)||$(r,t)?k.push({edge:e,label:a,src:t,dst:r}):(t===r&&(u[t].loops++,x(t)?p[t].h+=2*(26+(a.height>0?a.height+8:0)):p[t].w+=2*(26+(a.width>0?a.width+12:0))),v.push(e),M.push(a),b.push({src:t,dst:r,minlen:e.minlen??1,labelW:a.width>0?a.width+12:0,labelH:a.height>0?a.height+4:0,route:[],labelX:0,labelY:0}))}let A=Za(p,b,g,{nodeSep:an(t,"nodeSpacing",40),edgeSep:16,rankSep:an(t,"rankSpacing",48),portSep:20}),T=Fl(e.title,!1,s,l,4e3,1),C=T.height>0?T.height+12:0,E=Math.max(A.width,T.width),_=c+(E-A.width)/2;ja(p,b,_,c+C);let S=Math.ceil(E+2*c),I=Math.ceil(A.height+C+2*c),N=[],D=[],R=[],L=[],O=k.length*p.length<2e6;for(let{edge:e,src:t,dst:r}of k){let a=$(r,t),i=a?r:t,l=a?t:r,n=p[i],s=p[l],o=en[n.dir??y(i)],h=a?o:o+2&3,c=e=>{let t=!(1&e),r=0===e||3===e?-1:1,i=t?s.x:s.x+r*s.w/2,l=t?s.y+r*s.h/2:s.y,o=t?s.x:n.x+r*n.w/2,h=t?n.y+r*n.h/2:s.y,c=t?0:1;return a?[i,l,c,o,h,c]:[o,h,c,i,l,c]},d=e=>{for(let t=0;t<p.length;t++){let r=p[t];if(t!==l&&!r.isGroup&&r.x+r.w/2>Math.min(e[0],e[3])-1&&r.x-r.w/2<Math.max(e[0],e[3])+1&&r.y+r.h/2>Math.min(e[1],e[4])-1&&r.y-r.h/2<Math.max(e[1],e[4])+1)return!0}return!1},f=c(h);if(O&&d(f))for(let e of[h+1&3,h+3&3,h+2&3]){let t=c(e);if(!d(t)){f=t;break}}L.push(f),R.push((f[0]+f[3])/2,(f[1]+f[4])/2);let g=f.slice();ul(g,a?0:3,u[l],s),D.push(ai(g,"linear",0,ii(e.arrowTypeEnd)))}let F=new Map,z=!1;for(let e of p)e.isGroup&&(z=!0);if(z){for(let e of b)Qa(F,e.route);for(let e of L)Qa(F,e)}let W="",P="",B=[];for(let e=0;e<u.length;e++){let t=u[e],a=p[e],i=t.node,l=a.x,n=a.y,s=Oi(i.cssClasses.replace(/^default\s?/,"")),o=Re(i.id);if(a.isGroup){yt(t.style.shape)&&B.push({box:[l-a.w/2,n-a.h/2,l+a.w/2,n+a.h/2],shape:t.style.shape});let e=Ja(a,t.label.width,F,20);W+=`<g class="pele-cluster pele-flow${s}" data-id="${o}"><rect x="${Oe(l-a.w/2)}" y="${Oe(n-a.h/2)}" width="${Oe(a.w)}" height="${Oe(a.h)}"${Ai(ln(i.colorIndex??Xl.size,"0.06",t.style)+t.style.shape)}/>`+Fe(t.label,e,n-a.h/2+8+t.label.height/2,` class="pele-cluster-label"${xt(t.style,"var(--_m)")}${t.style.text}`,d)+"</g>";continue}let h,c=t.w,f=t.h,g="";if(t.shape===Jl){let e=zi(i.colorIndex??Xl.size),r=f/2-14-2,a=r+8;h=`<rect x="${Oe(-c/2)}" y="${Oe(-f/2)}" width="${Oe(c)}" height="${Oe(f)}"${Ai(ln(i.colorIndex??Xl.size,"0.06",t.style)+t.style.shape)}/><path d="M${Oe(-c/2+10)},${Oe(r)}H${Oe(c/2-10)}" fill="none" stroke="${e}" stroke-dasharray="3 3"${t.style.line}/><path class="pele-collapsed-mark" d="${sn(-9,a)}${sn(0,a)}${sn(9,a)}" fill="${e}" stroke="none"/>`}else{let e=Xl.get(i.kind??"task")??1;g=` pele-kind-${i.kind??"task"}`,h=ol(t.shape,c,f,ln(e,"0.14",t.style)+t.style.shape,` stroke="${zi(e)}"`+t.style.line)}let y=t.shape===Jl||dl(t.shape)?xt(t.style):"",x=Fe(t.label,0,t.dy,` class="pele-label"${y}${t.style.text}`,d);if(/ internal-link(?: |$)/.test(s+" ")&&i.label&&!1!==r.links){let e=m(i.label),t=br(e,r),a=De(e);x=`<a class="internal-link"${t?` href="${a}"${vr(r)}`:""} data-href="${a}">${x}</a>`,N.push({id:i.id,href:e,internal:!0})}let w=h+x;i.tooltip&&(w=`<title>${Re(i.tooltip)}</title>`+w),i.link&&(w=Mr(w,i.link,i.id,N,r,i.linkTarget?` target="${De(i.linkTarget)}"`:"")),P+=`<g class="pele-node pele-shape-${t.shape}${g}${s}" data-id="${o}" transform="translate(${Oe(l)},${Oe(n)})">${w}</g>`}let H="",Y="",G="",U=(e,t,r,a,i)=>{let l=e.style.length>0||e.cssCompiledStyles.length>0?Ri(e.cssCompiledStyles.concat(e.style)):void 0,n=e.arrowTypeEnd,s=gi(r.d,[r.ex,r.ey],B,l?.line,r.tokens),o=s||(l?.stroke?De(l.stroke):"var(--_l)"),h="dotted"===e.thickness?"reference":"arrow_cross"===n?"failure":"sequence",c=Oi(e.classes.replace(/edge-thickness-normal|edge-pattern-solid|flowchart-link/g,""));""===s&&(H+=yi(r,"none",n,l?.line)),Y+=`<g class="pele-edge pele-edge-${h}${c}" data-id="${Re(e.id)}"${s?` stroke="${s}"`:""}${l?.line??""}><path d="${r.d}"${"dotted"===e.thickness?' stroke-dasharray="3 4"':""}/>`+li(n,r.ex,r.ey,r.edx,r.edy,o)+"</g>",t.width>0&&(G+=wi(e.id,t,a,i,l?.text??"",d))},q=new Map;for(let e=0;e<b.length;e++){let t,r=b[e],a=v[e],i=M[e],l=a.arrowTypeEnd;if(r.src===r.dst){let e=u[r.src],a=q.get(r.src)??0;q.set(r.src,a+1),t=$i(p[r.src],e.w,e.h,a,x(r.src),26,ii(l),r)}else{let e=r.route.slice();ul(e,0,u[r.src],p[r.src]),ul(e,e.length-3,u[r.dst],p[r.dst]),t=ai(e,a.curve,0,ii(l))}U(a,i,t,r.labelX,r.labelY)}return k.forEach((e,t)=>U(e.edge,e.label,D[t],R[2*t],R[2*t+1])),{svg:Bi("agentflow",S,I,l,r,e,Fe(T,S/2,c+T.height/2,' class="pele-title" font-weight="var(--_tw)"')+(W?`<g class="pele-clusters">${W}</g>`:"")+xi(H)+(Y?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${Y}</g>`:"")+(G?`<g class="pele-edge-labels" font-size="${n}">${G}</g>`:"")+`<g class="pele-nodes">${P}</g>`),width:S,height:I,links:N}}function sn(e,t){return`M${Oe(e-1.75)},${Oe(t)}a1.75,1.75 0 1 0 3.5,0a1.75,1.75 0 1 0 -3.5,0Z`}var on={type:"agentflow",keepComments:!0,parse(e,t,r,a,i){let l=t.flowchart??{},n=new Gr({inheritDir:!0===l.inheritDir,direction:"string"==typeof t.direction?t.direction:void 0,lineOffset:a,source:e,maxEdges:i.maxEdges});return r&&(n.title=r),xa(e,n),rn(n,t),n},render:function(e,t,r){return jl(e.direction)?ql(r,a=>nn(e,t,r,a)):nn(e,t,r,!1)}};function hn(e){throw new i(e,"semantic",{type:"architecture"})}var cn=class{type="architecture";title;accTitle;accDescr;nodes=new Map;groups=new Map;edges=[];layoutHints=[];registered=new Map;register(e,t,r){this.registered.has(t)&&hn(`The ${e} id [${t}] is already in use by another ${this.registered.get(t)}`),void 0!==r&&(t===r&&hn(`The ${e} [${t}] cannot be placed within itself`),this.registered.has(r)||hn(`The ${e} [${t}]'s parent does not exist. Please make sure the parent is created before this ${e}`),"node"===this.registered.get(r)&&hn(`The ${e} [${t}]'s parent is not a group`)),this.registered.set(t,"group"===e?"group":"node")}addService({id:e,icon:t,iconText:r,title:a,in:i}){this.register("service",e,i),this.nodes.set(e,{id:e,type:"service",icon:t,iconText:r,title:a,in:i})}addJunction({id:e,in:t}){this.register("junction",e,t),this.nodes.set(e,{id:e,type:"junction",in:t})}addGroup({id:e,icon:t,title:r,in:a}){this.register("group",e,a),this.groups.set(e,{id:e,icon:t,title:r,in:a})}addEdge({lhsId:e,rhsId:t,lhsDir:r,rhsDir:a,lhsInto:i,rhsInto:l,lhsGroup:n,rhsGroup:s,title:o}){let h=[["left",e,n],["right",t,s]];for(let[e,t]of h)this.registered.has(t)||hn(`The ${e}-hand id [${t}] does not yet exist. Please create the service/group before declaring an edge to it.`);for(let[e,t]of h)this.nodes.has(t)||hn(`The ${e}-hand id [${t}] is a group. Add {group} to a service inside it instead.`);let c=this.nodes.get(e).in;if(void 0!==c&&c===this.nodes.get(t).in)for(let[e,t,r]of h)r&&hn(`The ${e}-hand id [${t}] is modified to traverse the group boundary, but the edge does not pass through two groups.`);this.edges.push({lhsId:e,lhsDir:r,lhsInto:i,lhsGroup:n,rhsId:t,rhsDir:a,rhsInto:l,rhsGroup:s,title:o})}addLayoutHint(e){e.members.length<2&&hn(`An align directive requires at least two members; got ${e.members.length}`);let t=new Set;for(let r of e.members)"node"!==this.registered.get(r)&&hn(`align ${e.direction} references [${r}], which is not a service or junction`),t.has(r)&&hn(`align ${e.direction} lists [${r}] more than once`),t.add(r);this.layoutHints.push(e)}};var dn=new WeakMap;function fn(e,t,r){let a=[],i=[],l=[],n=new Uint8Array(t.length),{starting:s,every:o,longer:h}=dn.get(t)??function(e){let t=e.map((e,t)=>t),r=[];for(let a=0;a<128;a++){let i=String.fromCharCode(a);r.push(t.filter(t=>{let{pattern:r,first:a}=e[t];return"string"==typeof r?r[0]===i:void 0===a||a.includes(i)}))}let a={starting:r,every:t,longer:e.map(t=>t.longer?.map(t=>e.indexOf(t)))};return dn.set(e,a),a}(t),d=[],f=e.length,u=(r,i)=>{if(n[r])return-1;let l=t[r];if(void 0!==l.match)return l.match(e,i,a[a.length-1]??-1);if(void 0!==l.scanner)return(d[r]??=l.scanner())(e,i,a[a.length-1]??-1);let s=l.pattern;return"string"==typeof s?e.startsWith(s,i)?i+s.length:-1:(s.lastIndex=i,s.test(e)?s.lastIndex:(void 0!==l.opener&&(l.opener.lastIndex=i,l.opener.test(e)&&(n[r]=1)),-1))},p=0;e:for(;p<f;){let n=e.charCodeAt(p);for(let e of n<128?s[n]:o){let r=u(e,p);if(r<=p)continue;let n=e,s=h[e];if(void 0!==s)for(let e of s){let t=u(e,p);if(t>r){n=e,r=t;break}}t[n].hidden||(a.push(n),i.push(p),l.push(r)),p=r;continue e}throw c(r,e,p,"",!0)}return a.push(-1),i.push(f),l.push(f),{kinds:a,starts:i,ends:l,src:e}}var un={name:"ACC_DESCR",pattern:/[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/y,first:"\t a"},pn={name:"ACC_TITLE",pattern:/[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/y,first:"\t a"},gn={name:"TITLE",pattern:/[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/y,first:"\t t"};function mn(e){return{...gn,pattern:new RegExp(String.raw`[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|(?!${e}))`,"y")}}var yn={name:"STRING",pattern:/"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/y,first:"\"'"},xn={name:"NEWLINE",pattern:/\r?\n/y,first:"\r\n"},wn={name:"WHITESPACE",pattern:/[\t ]+/y,hidden:!0,first:"\t "},$n={name:"YAML",pattern:/---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/y,hidden:!0,opener:/---[\t ]*\r?\n/y,first:"-"},bn={name:"DIRECTIVE",pattern:/[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/y,hidden:!0,opener:/[\t ]*%%{/y,first:"\t %"},Mn={name:"SINGLE_LINE_COMMENT",pattern:/[\t ]*%%[^\n\r]*/y,first:"\t %",hidden:!0};function vn(e){return{name:e,pattern:new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"(?:(?=%%)|(?!\\S))","y"),first:e[0]}}var kn=/accDescr(?:[\t ]*:([^\n\r]*)|\s*{([^}]*)})/,An=/accTitle[\t ]*:([^\n\r]*)/,Tn=/title([\t ][^\n\r]*|)/;function Cn(e){return e.trim().replace(/[\t ]{2,}/gm," ")}function En(e){return Cn(Tn.exec(e)[1])}function _n(e){return Cn(An.exec(e)[1])}function Sn(e){let t=kn.exec(e);return void 0!==t[1]?Cn(t[1]):t[2].replace(/^\s*/gm,"").replace(/\s+$/gm,"").replace(/[\t ]{2,}/gm," ").replace(/[\n\r]{2,}/gm,"\n")}var In=new Map([["b","\b"],["f","\f"],["n","\n"],["r","\r"],["t","\t"],["v","\v"],["0","\0"]]);function Nn(e){if(!e.includes("\\"))return e.slice(1,-1);let t="";for(let r=1;r<e.length-1;r++){let a=e[r];if("\\"===a){let a=e[++r];t+=In.get(a)??a}else t+=a}return t}var Dn=class{constructor(e,t,r){this.tokens=e,this.types=t,this.diagram=r,this.kinds=e.kinds}tokens;types;diagram;i=0;kinds;get kind(){return this.kinds[this.i]}text(e=this.i){return this.tokens.src.slice(this.tokens.starts[e],this.tokens.ends[e])}take(){return this.text(this.i++)}accept(e){return this.kinds[this.i]===e&&(this.i++,!0)}expect(e){return this.kinds[this.i]!==e&&this.fail(`token of type '${this.types[e].name}'`),this.take()}fail(e){let t=-1===this.kind?"end of input":`\`${this.text()}\``,{src:r,starts:a,ends:i}=this.tokens,l=a[this.i];if(-1===this.kind){let e=this.i;for(;e>0&&""===r.slice(a[e-1],i[e-1]).trim();)e--;e>0&&(l=i[e-1])}throw c(this.diagram,r,l,`Expecting ${e} but found ${t}.`)}},Rn={name:"ID",pattern:/[\w]([-\w]*\w)?/y};function Ln(e){return{name:e,pattern:e,longer:[Rn]}}var On=[Ln("architecture-beta"),Ln("junction"),Ln("service"),Ln("column"),Ln("group"),Ln("align"),Ln("row"),{name:"--",pattern:"--",longer:[$n]},Ln("in"),{name:":",pattern:":"},{name:"-",pattern:"-",longer:[$n]},{name:"ARROW_DIRECTION",pattern:/L|R|T|B/y},{name:"ARROW_GROUP",pattern:/\{group\}/y},{name:"ARROW_INTO",pattern:/<|>/y},un,pn,mn(String.raw`[-\w]*\w`),yn,Rn,xn,wn,$n,bn,Mn,{name:"ARCH_ICON",pattern:/\([\w-:]+\)/y},{name:"ARCH_TITLE",pattern:/\[(?:"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|[^\[\]\r\n]+)\]/y}];function Fn(e){let t=e.slice(1,-1).trim();return(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1).replace(/\\"/g,'"').replace(/\\'/g,"'")),t.trim()}var zn=new Map([["database","M4 6a8 3 0 1 0 16 0a8 3 0 1 0-16 0M4 6v12a8 3 0 0 0 16 0V6M4 12a8 3 0 0 0 16 0"],["server","M3 4h18v7H3zM3 13h18v7H3zM7 7.5h.01M7 16.5h.01M11 7.5h6M11 16.5h6"],["disk","M5 3h14v18H5zM12 6.5a4 4 0 1 0 0 8a4 4 0 1 0 0-8M12 10.5h.01M8 18h3"],["internet","M3 12a9 9 0 1 0 18 0a9 9 0 1 0-18 0M3 12h18M12 3a13 13 0 0 0 0 18M12 3a13 13 0 0 1 0 18"],["cloud","M7 18a4 4 0 0 1-.5-7.97A6 6 0 0 1 18 9.5a4.25 4.25 0 0 1-.5 8.5z"]]);var Wn=[-1,1,0,0],Pn=[0,0,-1,1];function Bn(e){return"L"===e?0:"R"===e?1:"T"===e?2:3}var Hn=2**25,Yn=2**26;var Gn=12,Un=[-1,1,0,0],qn=[0,0,-1,1];function jn(e,t,r,a,i){let l=e.architecture,n=null===l||"object"!=typeof l||Array.isArray(l)?void 0:l[t];return"number"==typeof n&&Number.isFinite(n)?Math.min(i,Math.max(a,n)):r}function Vn(e){let t=new Map;for(let r of e.sort((e,t)=>e-t))t.has(r)||t.set(r,t.size);return t}function Xn(e,t,r,a,i){return`<svg class="pele-icon" data-icon="${Re(e)}" x="${Oe(t)}" y="${Oe(r)}" width="${Oe(a)}" height="${Oe(a)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${i?.(e)??function(e){let t=zn.get(e);return void 0===t?"":`<path d="${t}" stroke="var(--_fg)" stroke-width="1.5"/>`}(e)}</svg>`}function Kn(e,t,r,a){let i=e.lines.length>r;if(!i&&e.width<=t)return e;let l=a.width("…",e.size,0),n=[],s=[],o=0;for(let h=0;h<Math.min(r,e.lines.length);h++){let c=e.lines[h].map(e=>({...e})),d=e.widths[h];if(d>t||i&&h===r-1)for(;;){let r=c[c.length-1];if(void 0===r){c.push({text:"…",style:0,width:l}),d=l;break}let i=d-r.width;if(void 0===r.icon&&i+l<t){let n=0,s=r.text.length;for(;n<s;){let o=n+s+1>>1;i+a.width(r.text.slice(0,o),e.size,r.style)+l<=t?n=o:s=o-1}let o=n>0?r.text.charCodeAt(n-1):0;o>=55296&&o<=56319&&n--,r.text=r.text.slice(0,n).trimEnd()+"…",r.width=a.width(r.text,e.size,r.style),d=i+r.width;break}c.pop(),d=i}n.push(c),s.push(d),o=Math.max(o,d)}return{...e,lines:n,widths:s,width:o,height:n.length*e.lineHeight}}function Zn(e,t){let{x:r,y:a,dx:i,dy:l}=e,{x:n,y:s,dx:o,dy:h}=t,c=r+i*Gn,d=a+l*Gn,f=n+o*Gn,u=s+h*Gn;if(i*o+l*h===0){let e=0!==i?n:r,t=0!==i?a:s;return(e-r)*i+(t-a)*l>0&&(e-n)*o+(t-s)*h>0?[r,a,e,t,n,s]:0!==i?[r,a,c,d,c,u,f,u,n,s]:[r,a,c,d,f,d,f,u,n,s]}let p=0!==i,g=p?s-a:n-r;if(i===-o&&l===-h){if((n-r)*i+(s-a)*l>0){if(Math.abs(g)<.5)return[r,a,n,s];if(p){let l=i>0?e.x1:t.x1,o=i>0?t.x0:e.x0,h=l<o?(l+o)/2:(r+n)/2;return[r,a,h,a,h,s,n,s]}let o=l>0?e.y1:t.y1,h=l>0?t.y0:e.y0,c=o<h?(o+h)/2:(a+s)/2;return[r,a,r,c,n,c,n,s]}}else if(Math.abs(g)>=1){if(p){let e=i>0?Math.max(r,n)+Gn:Math.min(r,n)-Gn;return[r,a,e,a,e,s,n,s]}let e=l>0?Math.max(a,s)+Gn:Math.min(a,s)-Gn;return[r,a,r,e,n,e,n,s]}if(p){let i=e.y1+Gn<=t.y0?(e.y1+t.y0)/2:t.y1+Gn<=e.y0?(t.y1+e.y0)/2:Math.max(e.y1,t.y1)+Gn;return[r,a,c,a,c,i,f,i,f,s,n,s]}let m=e.x1+Gn<=t.x0?(e.x1+t.x0)/2:t.x1+Gn<=e.x0?(t.x1+e.x0)/2:Math.max(e.x1,t.x1)+Gn;return[r,a,r,d,m,d,m,u,n,u,n,s]}function Qn(e){let t=[e[0],e[1]];for(let r=2;r<e.length;r+=2){let a=e[r],i=e[r+1],l=t.length,n=Math.abs(a-t[l-2])<.01,s=Math.abs(i-t[l-1])<.01;n&&s||(l>=4&&(n&&Math.abs(t[l-4]-t[l-2])<.01||s&&Math.abs(t[l-3]-t[l-1])<.01)?(t[l-2]=a,t[l-1]=i):t.push(a,i))}return t}function Jn(e,t,r){let a=e.length/2,i=new Array(a),l=new Array(a);for(let t=0;t<a;t++)i[t]=e[2*t],l[t]=e[2*t+1];let n=(e,t,r)=>{let a=Math.hypot(i[t]-i[e],l[t]-l[e]),n=Math.min(r,Math.max(0,a-1));a>0&&n>0&&(i[e]+=(i[t]-i[e])/a*n,l[e]+=(l[t]-l[e])/a*n)};n(0,1,t),n(a-1,a-2,r);let s=`M${Oe(i[0])},${Oe(l[0])}`;for(let e=1;e<a-1;e++){let t=Math.hypot(i[e]-i[e-1],l[e]-l[e-1]),r=Math.hypot(i[e+1]-i[e],l[e+1]-l[e]),a=Math.min(6,t/2,r/2);if(a<.5){s+=`L${Oe(i[e])},${Oe(l[e])}`;continue}let n=i[e]-(i[e]-i[e-1])/t*a,o=l[e]-(l[e]-l[e-1])/t*a,h=i[e]+(i[e+1]-i[e])/r*a,c=l[e]+(l[e+1]-l[e])/r*a;s+=`L${Oe(n)},${Oe(o)}Q${Oe(i[e])},${Oe(l[e])} ${Oe(h)},${Oe(c)}`}return s+`L${Oe(i[a-1])},${Oe(l[a-1])}`}var es={type:"architecture",parse(e,t,r){let a=new cn;return r&&(a.title=r),function(e,t){e.accDescr&&(t.accDescr=e.accDescr.replace(/\n\s+/g,"\n")),e.accTitle&&(t.accTitle=e.accTitle.replace(/^\s+/g,"")),e.title&&(t.title=e.title);for(let r of e.groups)t.addGroup(r);for(let r of e.services)t.addService(r);for(let r of e.junctions)t.addJunction(r);for(let r of e.edges)t.addEdge(r);for(let r of e.alignments)t.addLayoutHint({direction:r.direction,members:[...r.members]})}(function(e){let t=new Dn(fn(e,On,"architecture"),On,"architecture"),r={$type:"Architecture",groups:[],services:[],junctions:[],edges:[],alignments:[]},a=e=>t.kinds[t.i]===e,i=()=>{if(-1!==t.kind)for(19!==t.kind&&t.fail("a line break or the end of input");19===t.kind;)t.i++};for(;19===t.kind;)t.i++;for(t.expect(0);-1!==t.kind;){switch(t.kind){case 19:t.i++;continue;case 14:r.accDescr=Sn(t.take());break;case 15:r.accTitle=_n(t.take());break;case 16:r.title=En(t.take());break;case 4:{t.i++;let e={$type:"Group",id:t.expect(18)};a(24)&&(e.icon=t.take().slice(1,-1)),a(25)&&(e.title=Fn(t.take())),t.accept(8)&&(e.in=t.expect(18)),r.groups.push(e);break}case 2:{t.i++;let e={$type:"Service",id:t.expect(18)};a(17)?e.iconText=Nn(t.take()):a(24)&&(e.icon=t.take().slice(1,-1)),a(25)&&(e.title=Fn(t.take())),t.accept(8)&&(e.in=t.expect(18)),r.services.push(e);break}case 1:{t.i++;let e={$type:"Junction",id:t.expect(18)};t.accept(8)&&(e.in=t.expect(18)),r.junctions.push(e);break}case 18:{let e=t.take(),i=t.accept(12);t.expect(9);let l,n=t.expect(11),s=t.accept(13);t.accept(7)||(a(10)||t.fail("'--' or '-'"),t.i++,l=Fn(t.expect(25)),t.expect(10));let o=t.accept(13),h=t.expect(11);t.expect(9);let c=t.expect(18),d=t.accept(12);r.edges.push({$type:"Edge",lhsId:e,lhsGroup:i,lhsDir:n,lhsInto:s,title:l,rhsInto:o,rhsDir:h,rhsId:c,rhsGroup:d});break}case 5:{t.i++,!a(6)&&!a(3)&&t.fail("'row' or 'column'");let e=t.take(),i=[t.expect(18),t.expect(18)];for(;a(18);)i.push(t.take());r.alignments.push({$type:"Alignment",direction:e,members:i});break}default:t.fail("a group, a service, a junction, an edge, an alignment, a title, or a line break")}i()}return r}(e),a),a},render:function(e,t,r){return Vl(r,a=>function(e,t,r,a){let i=jn(t,"iconSize",48,8,512),l=jn(t,"fontSize",r.fontSize??16,4,128),n=Math.min(jn(t,"padding",20,0,256),a?12:1/0),s=Math.round(.875*l),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=r.icons,d=i/2,f=[...e.nodes.values()],u=[...e.groups.values()],p=f.length,g=u.length,m=function(e,t,r,a){let i=e.length,l=t.length,n=l,s=new Map,o=new Map,h=new Int32Array(i+l).fill(n),c=new Int32Array(l+1),d=[];for(let e=0;e<=l;e++)d.push([]);t.forEach((e,t)=>{o.set(e.id,t);let r=void 0===e.in?void 0:o.get(e.in);void 0!==r&&r!==t?(h[i+t]=r,c[t]=c[r]+1):c[t]=1}),e.forEach((e,t)=>{s.set(e.id,t);let r=void 0===e.in?void 0:o.get(e.in);void 0!==r&&(h[t]=r),d[h[t]].push(t)});for(let e=0;e<l;e++)d[h[i+e]].push(i+e);let f=[],u=[],p=[],g=[],m=[],y=[],x=new Array(i+l),w=new Array(i+l),$=(e,t,r,a,l)=>{if(e===t)return;let n=e,s=t,o=h[e],d=h[t];for(;o!==d;)c[o]>=c[d]?(n=i+o,o=h[n]):(s=i+d,d=h[s]);let x=f.length;f.push(e),u.push(t),p.push(r),g.push(a),m.push(n),y.push(s),(l[n]??=[]).push(x),(l[s]??=[]).push(x)};for(let e of a){let t="row"===e.direction;for(let r=1;r<e.members.length;r++){let a=s.get(e.members[r-1]),i=s.get(e.members[r]);void 0!==a&&void 0!==i&&$(a,i,t?1:3,t?0:2,x)}}for(let e of[!1,!0])for(let t of r){if(t.lhsDir===t.rhsDir!==e)continue;let r=s.get(t.lhsId),a=s.get(t.rhsId);void 0!==r&&void 0!==a&&$(r,a,Bn(t.lhsDir),Bn(t.rhsDir),w)}let b=new Int32Array(i+l),M=new Int32Array(i+l),v=new Int32Array(i+l).fill(1),k=new Int32Array(i+l).fill(1),A=new Uint8Array(i+l),T=[],C=new Map,E=[],_=new Map,S=0,I=0,N=0,D=(e,t)=>{I=0,N=0;for(let r=e;r!==t;r=i+h[r])I+=b[r],N+=M[r]},R=(e,t,r)=>{if(b[e]=t,M[e]=r,A[e]=1,T.push(e),v[e]*k[e]>64)E.push(e);else for(let a=r;a<r+k[e];a++)for(let r=t;r<t+v[e];r++)C.set((r+Hn)*Yn+a+Hn,e)},L=(e,t,r,a,i)=>b[e]<t+a&&t<b[e]+v[e]&&M[e]<r+i&&r<M[e]+k[e],O=(e,t,r,a)=>{if(r*a>64){for(let i=S;i<T.length;i++)if(L(T[i],e,t,r,a))return T[i];return-1}for(let i=t;i<t+a;i++)for(let t=e;t<e+r;t++){let e=C.get((t+Hn)*Yn+i+Hn);if(void 0!==e)return e}for(let i of E)if(L(i,e,t,r,a))return i;return-1},F=(e,t,r,a,i,l)=>{let n=`${e},${t},${r},${a},${i},${l}`,s=_.get(n)??0;for(;;){let n=O(e+s*i,t+s*l,r,a);if(n<0)break;s=i>0?b[n]+v[n]-e:i<0?e+r-b[n]:l>0?M[n]+k[n]-t:t+a-M[n]}return _.set(n,s),s},z=(e,t)=>{let r=m[t]===e,a=r?y[t]:m[t];if(A[a])return;let i=r?p[t]:g[t],l=r?g[t]:p[t];D(r?f[t]:u[t],e);let n=I,s=N;D(r?u[t]:f[t],a);let o,h,c=Wn[i],d=Pn[i],x=0,$=0,T=Wn[i]+Wn[l]===0&&Pn[i]+Pn[l]===0;if(i===l?(c=0===Wn[i]?1:0,d=1-c):T||(x=-Wn[l],$=-Pn[l]),0!==c?(o=c>0?b[e]+v[e]:b[e]-v[a],h=M[e]+s+$-N):(h=d>0?M[e]+k[e]:M[e]-k[a],o=b[e]+n+x-I),T){let e=w[a];if(void 0!==e&&e.length>1){let t=[];for(let r of e){let e=y[r]===a,n=e?m[r]:y[r];if(!A[n]||(e?p[r]:g[r])!==i||(e?g[r]:p[r])!==l)continue;D(e?f[r]:u[r],n);let s=0!==c?M[n]+N:b[n]+I;D(e?u[r]:f[r],a),t.push(s-(0!==c?N:I))}t.length>1&&(t.sort((e,t)=>e-t),0!==c?h=t[t.length-1>>1]:o=t[t.length-1>>1])}let t=0===c?1:0,r=1-t,n=F(o,h,v[a],k[a],t,r),s=0===n?0:F(o,h,v[a],k[a],-t,-r),d=n<=s?n:-s;o+=t*d,h+=r*d}else{let e=F(o,h,v[a],k[a],c,d);o+=c*e,h+=d*e}R(a,o,h)},W=e=>{let t=d[e];if(0===t.length)return;T.length=0;let r=[];for(let e of t){if(A[e])continue;S=T.length,r.push(S),C.clear(),E.length=0,_.clear(),R(e,0,0);let t=S,a=S,i=0;for(;;){if(t<T.length){let e=T[t++],r=x[e];if(void 0!==r)for(let t of r)z(e,t);continue}if(a>=T.length)break;let e=w[T[a]];void 0===e||i>=e.length?(a++,i=0):z(T[a],e[i++])}}r.push(T.length);let a=r.length-1,n=new Array(a),s=new Array(a),o=new Array(a),h=new Array(a),c=0,f=0;for(let e=0;e<a;e++){let t=1/0,a=1/0,i=-1/0,l=-1/0;for(let n=r[e];n<r[e+1];n++){let e=T[n];t=Math.min(t,b[e]),a=Math.min(a,M[e]),i=Math.max(i,b[e]+v[e]),l=Math.max(l,M[e]+k[e])}n[e]=t,s[e]=a,o[e]=i-t,h[e]=l-a,c+=o[e]*h[e],f=Math.max(f,o[e])}let u=Math.max(f,Math.ceil(Math.sqrt(2*c))),p=0,g=0,m=0,y=0;for(let e=0;e<a;e++){p>0&&p+o[e]>u&&(g+=m,p=0,m=0);for(let t=r[e];t<r[e+1];t++)b[T[t]]+=p-n[e],M[T[t]]+=g-s[e];p+=o[e],m=Math.max(m,h[e]),y=Math.max(y,p)}e<l&&(v[i+e]=y,k[i+e]=g+m)};for(let e=l-1;e>=0;e--)W(e);W(n);let P=new Int32Array(l),B=new Int32Array(l),H=new Int32Array(l),Y=new Uint8Array(l);for(let e=0;e<l;e++){let t=h[i+e];H[e]=t===n?-1:t,P[e]=b[i+e]+(t===n?0:P[t]),B[e]=M[i+e]+(t===n?0:B[t]),0===d[e].length&&(Y[e]=1)}let G=new Int32Array(i),U=new Int32Array(i),q=new Int32Array(i);for(let e=0;e<i;e++){let t=h[e];q[e]=t===n?-1:t,G[e]=b[e]+(t===n?0:P[t]),U[e]=M[e]+(t===n?0:B[t])}return{col:G,row:U,groupCol:P,groupRow:B,groupCols:v.slice(i),groupRows:k.slice(i),groupParent:H,groupEmpty:Y,nodeParent:q}}(f,u,e.edges,e.layoutHints),y=new Map;f.forEach((e,t)=>y.set(e.id,t));let x=new Array(p),w=new Float64Array(p),$=new Float64Array(p),b=a?Math.max(i,64):Math.max(2.25*i,96);for(let e=0;e<p;e++){let t=f[e],r=Fl("service"===t.type?t.title:void 0,!0,o,l,b);x[e]=r,w[e]=Math.max(i,2*Math.ceil(r.width/2)),$[e]=i+(r.height>0?4+r.height:0)}let M=[],v=[];for(let e=0;e<p;e++)M.push(m.col[e]),v.push(m.row[e]);for(let e=0;e<g;e++)m.groupEmpty[e]&&(M.push(m.groupCol[e]),v.push(m.groupRow[e]));let k=Vn(M),A=Vn(v),T=k.size,C=A.size,E=new Float64Array(T),_=new Float64Array(C),S=a?Math.max(24,24):Math.max(40,Math.round(.75*i)),I=new Float64Array(T).fill(S),N=new Float64Array(C).fill(S),D=new Int32Array(p),R=new Int32Array(p);for(let e=0;e<p;e++){let t=D[e]=k.get(m.col[e]),r=R[e]=A.get(m.row[e]);E[t]=Math.max(E[t],w[e]),_[r]=Math.max(_[r],$[e])}for(let e=0;e<g;e++){if(!m.groupEmpty[e])continue;let t=k.get(m.groupCol[e]),r=A.get(m.groupRow[e]);E[t]=Math.max(E[t],i),_[r]=Math.max(_[r],d)}let L=e.edges.length,O=new Array(L),F=new Int32Array(2*L);for(let t=0;t<L;t++){let r=e.edges[t],a=F[2*t]=y.get(r.lhsId)??-1,i=F[2*t+1]=y.get(r.rhsId)??-1,l=Fl(r.title,!0,o,s,160);if(O[t]=l,!(0===l.width||a<0||i<0))if(D[a]!==D[i]){let e=Math.min(D[a],D[i]);I[e]=Math.max(I[e],Math.ceil(l.width)+28)}else if(E[D[a]]=Math.max(E[D[a]],2*Math.ceil(l.width/2)+8),R[a]!==R[i]){let e=Math.min(R[a],R[i]);N[e]=Math.max(N[e],Math.ceil(l.height)+24)}}let z=new Array(g),W=new Int32Array(g),P=new Int32Array(g),B=new Int32Array(g),H=new Int32Array(g),Y=new Float64Array(g),G=new Float64Array(g),U=new Float64Array(g),q=new Float64Array(g),j=new Float64Array(g),V=new Float64Array(g),X=new Float64Array(T),K=new Float64Array(T),Z=new Float64Array(C),Q=new Float64Array(C),J=Math.round(1.25*l);for(let e=0;e<g;e++){W[e]=k.get(m.groupCol[e]),P[e]=k.get(m.groupCol[e]+m.groupCols[e]-1),B[e]=A.get(m.groupRow[e]),H[e]=A.get(m.groupRow[e]+m.groupRows[e]-1);let t=Fl(u[e].title,!0,o,l,a?Math.max(80,Gl(r)/2):320);z[e]=t;let i=u[e].icon?J:0;j[e]=t.width+i+(t.width>0&&i>0?6:0),V[e]=Math.max(t.height,i)}for(let e=g-1;e>=0;e--){let t=n+Y[e],r=n+G[e],a=(V[e]>0?Math.max(n,V[e]+12):n)+U[e],i=n+q[e];if(j[e]>0){let a=t+r;for(let t=W[e];t<=P[e];t++)a+=E[t]+(t<P[e]?K[t]+I[t]+X[t+1]:0);j[e]+20>a&&(r+=Math.ceil(j[e]+20-a))}Y[e]=t,G[e]=r,U[e]=a,q[e]=i,X[W[e]]=Math.max(X[W[e]],t),K[P[e]]=Math.max(K[P[e]],r),Z[B[e]]=Math.max(Z[B[e]],a),Q[H[e]]=Math.max(Q[H[e]],i);let l=m.groupParent[e];l<0||(W[l]===W[e]&&(Y[l]=Math.max(Y[l],t)),P[l]===P[e]&&(G[l]=Math.max(G[l],r)),B[l]===B[e]&&(U[l]=Math.max(U[l],a)),H[l]===H[e]&&(q[l]=Math.max(q[l],i)))}let ee=new Float64Array(T),te=new Float64Array(C),re=0;for(let e=0;e<T;e++)ee[e]=re+X[e],re=ee[e]+E[e]+K[e]+(e<T-1?I[e]:0);let ae=0;for(let e=0;e<C;e++)te[e]=ae+Z[e],ae=te[e]+_[e]+Q[e]+(e<C-1?N[e]:0);let ie=0,le=0,ne=re,se=ae,oe=e=>ee[W[e]]-Y[e],he=e=>ee[P[e]]+E[P[e]]+G[e],ce=e=>te[B[e]]-U[e],de=e=>te[H[e]]+_[H[e]]+q[e],fe=e=>ee[D[e]]+E[D[e]]/2,ue=(e,t,r)=>{let a=Un[t],i=qn[t],l=fe(e),n=te[R[e]],s={x:l,y:n+d,dx:a,dy:i,x0:l-w[e]/2,y0:n,x1:l+w[e]/2,y1:n+$[e],gap:0,wire:!1};"junction"===f[e].type?(s.x0=s.x1=l,s.y0=s.y1=s.y,s.gap=3):0!==a?s.x=l+a*d:s.y=i<0?n:n+$[e]+(x[e].height>0?2:0);let o=r?m.nodeParent[e]:-1;return o>=0&&(s.x0=oe(o),s.x1=he(o),s.y0=ce(o),s.y1=de(o),s.gap=0,s.wire="junction"===f[e].type,0!==a?s.x=a<0?s.x0:s.x1:s.y=i<0?s.y0:s.y1),s},pe="",ge="",me=[],ye=ii("arrow_point");for(let t=0;t<L;t++){let r=e.edges[t],a=F[2*t],i=F[2*t+1];if(a<0||i<0)continue;let l=ue(a,Bn(r.lhsDir),r.lhsGroup),n=ue(i,Bn(r.rhsDir),r.rhsGroup);l.x===n.x&&l.y===n.y&&l.dx===n.dx&&(l.x-=8*Math.abs(l.dy),l.y-=8*Math.abs(l.dx),n.x+=8*Math.abs(l.dy),n.y+=8*Math.abs(l.dx));let s=Zn(l,n);l.wire&&s.unshift(fe(a),te[R[a]]+d),n.wire&&s.push(fe(i),te[R[i]]+d);let o=Qn(s);if(o.length<4)continue;pe+=`<g class="pele-edge" data-id="${Re(`${r.lhsId}-${r.rhsId}`)}"><path d="${Jn(o,r.lhsInto&&!l.wire?ye+l.gap:0,r.rhsInto&&!n.wire?ye+n.gap:0)}"/>`+(r.lhsInto?li("arrow_point",l.x+l.dx*l.gap,l.y+l.dy*l.gap,-l.dx,-l.dy,"var(--_l)"):"")+(r.rhsInto?li("arrow_point",n.x+n.dx*n.gap,n.y+n.dy*n.gap,-n.dx,-n.dy,"var(--_l)"):"")+"</g>";let h=-1,f=-1,u=-1,p=-1,g=O[t];for(let e=0;e<o.length;e+=2)ie=Math.min(ie,o[e]-4),ne=Math.max(ne,o[e]+4),le=Math.min(le,o[e+1]-4),se=Math.max(se,o[e+1]+4);for(let e=0;e+3<o.length;e+=2){let t=Math.abs(o[e+1]-o[e+3])<.01,r=Math.abs(o[e]-o[e+2])+Math.abs(o[e+1]-o[e+3]);t||me.push(o[e],Math.min(o[e+1],o[e+3]),Math.max(o[e+1],o[e+3])),r>f&&(h=e,f=r),t&&r>p&&(u=e,p=r)}if(g.width>0){let e=p>=g.width+8?u:h,t=(o[e]+o[e+2])/2,a=(o[e+1]+o[e+3])/2,i=g.width+8,s=Math.abs(o[e]-o[e+2])<.01;for(let e of[l,n])t+i/2<=e.x0||t-i/2>=e.x1||a+g.height/2<=e.y0||a-g.height/2>=e.y1||(s?t=t>=(e.x0+e.x1)/2?e.x1+i/2+4:e.x0-i/2-4:a=a>=(e.y0+e.y1)/2?e.y1+g.height/2+4:e.y0-g.height/2-4);ie=Math.min(ie,t-i/2),ne=Math.max(ne,t+i/2),le=Math.min(le,a-g.height/2),se=Math.max(se,a+g.height/2),ge+=wi(`${r.lhsId}-${r.rhsId}`,g,t,a,"",c)}}let xe="";for(let e=0;e<g;e++){let t=u[e],r=oe(e),a=ce(e),i=he(e)-r,l=z[e],n="";if(j[e]>0){let s=a+V[e]+12,o=[];for(let e=0;e<me.length;e+=3)me[e+1]<s&&me[e+2]>a&&me[e]>r&&me[e]<r+i&&o.push(me[e]);o.sort((e,t)=>e-t),o.push(r+i-4);let h=r+10;for(let t of o){if(t-6-h>=j[e])break;h=Math.max(h,t+6)}h+j[e]>r+i-4&&(h=r+10);let d=a+6+V[e]/2,f=h;t.icon&&(n+=Xn(t.icon,h,d-J/2,J,c),f+=J+6),n+=Fe(l,f+l.width/2,d,' class="pele-cluster-label" fill="var(--_m)"',c)}xe+=`<g class="pele-cluster" data-id="${Re(t.id)}"><rect x="${Oe(r)}" y="${Oe(a)}" width="${Oe(i)}" height="${Oe(de(e)-a)}" fill="var(--_a)" fill-opacity="0.5" stroke="var(--_b)"${Mi}/>`+n+"</g>"}let we="",$e=.5*i,be=Math.max(6,Math.round(.75*l));for(let e=0;e<p;e++){let t=f[e],r=`data-id="${Re(t.id)}" transform="translate(${Oe(fe(e))},${Oe(te[R[e]])})"`;if("junction"===t.type){we+=`<g class="pele-node pele-junction" ${r}><circle cy="${Oe(d)}" r="3" fill="var(--_l)"/></g>`;continue}let a="";if(t.icon)a=Xn(t.icon,-$e/2,(i-$e)/2,$e,c);else if(t.iconText){let e=Fl(t.iconText,!1,o,be,i-8);a=Fe(Kn(e,i-8,Math.max(1,Math.floor((i-4)/(e.lineHeight||1))),o),0,d,` class="pele-icon-text" font-size="${be}"`,c)}we+=`<g class="pele-node pele-service" ${r}><rect x="${Oe(-d)}" width="${Oe(i)}" height="${Oe(i)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`+a+Fe(x[e],0,i+4+x[e].height/2,' class="pele-label"',c)+"</g>"}let Me=Fl(e.title,!1,o,l,a?Gl(r):4e3,1),ve=Me.height>0?Me.height+12:0,ke=Math.ceil(Math.max(ne-ie,Me.width)+2*h),Ae=Math.ceil(se-le+ve+2*h),Te=Math.round((ke-(ne-ie))/2-ie),Ee=Math.round(h+ve-le),_e=(xe?`<g class="pele-clusters">${xe}</g>`:"")+(pe?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round" stroke-linejoin="round">${pe}</g>`:"")+(ge?`<g class="pele-edge-labels" font-size="${s}">${ge}</g>`:"")+(we?`<g class="pele-nodes">${we}</g>`:"");return{svg:Bi("architecture",ke,Ae,l,r,e,Fe(Me,ke/2,h+Me.height/2,' class="pele-title" font-weight="var(--_tw)"')+(_e?`<g transform="translate(${Te},${Ee})">${_e}</g>`:"")),width:ke,height:Ae,links:[]}}(e,t,r,a))}},ts=1e5;function rs(e){switch(e){case"[]":return"square";case"()":return"round";case"(())":return"circle";case">]":return"rect_left_inv_arrow";case"{}":return"diamond";case"{{}}":return"hexagon";case"([])":return"stadium";case"[[]]":return"subroutine";case"[()]":return"cylinder";case"((()))":return"doublecircle";case"[//]":return"lean_right";case"[\\\\]":return"lean_left";case"[/\\]":return"trapezoid";case"[\\/]":return"inv_trapezoid";case"<[]>":return"block_arrow";default:return"na"}}function as(e){switch(e.trim().slice(-1)){case"x":return"arrow_cross";case"o":return"arrow_circle";case">":return"arrow_point";default:return""}}function is(e){switch(e.trim().charAt(0)){case"x":return"arrow_cross";case"o":return"arrow_circle";case"<":return"arrow_point";default:return"arrow_open"}}function ls(e){return e.includes("==")?"thick":"normal"}function ns(e){return e.includes(".-")?"dotted":"solid"}function ss(e,t){let r=e.flat(),a=-1;for(let e of r)if("column-setting"===e.type){a=e.columns??-1;break}return{list:r,at:0,parent:t,children:[],columns:a}}var os=class{type="block";title;root={id:"root",type:"composite",children:[],columns:-1};blocks=[];edges=[];classes=new Map;byId=new Map;typeStr2Type=rs;edgeStrToEdgeData=as;edgeStrToEdgeStartData=is;edgeStrToThickness=ls;edgeStrToPattern=ns;warn;pending=new Set;edgeCount=new Map;ids=0;colors=0;spaces=0;constructor(e={}){this.warn=e.warn}generateId(){return"id-"+ ++this.ids}addStyleClass(e,t=""){let r=this.classes.get(e);r||(r={id:e,styles:[],textStyles:[]},this.classes.set(e,r));for(let e of t.split(",")){let t=e.indexOf(";"),a=(-1===t?e:e.slice(0,t)+e.slice(t+1)).trim();e.includes("color")&&r.textStyles.push(a.replace("fill","bgFill").replace("color","fill")),r.styles.push(a)}}addStyle2Node(e,t=""){this.named(e).styles=t.split(",")}setCssClass(e,t){for(let r of e.split(","))(this.named(r.trim()).classes??=[]).push(t)}named(e){let t=this.byId.get(e);return void 0===t&&(t={id:e,type:"na",children:[]},this.byId.set(e,t),this.pending.add(e)),t}setHierarchy(e){let t=[ss(e,this.root)];for(;t.length>0;){let e=t[t.length-1];if(e.at===e.list.length){e.parent.children=e.children,t.pop();continue}let r=e.list[e.at++];switch(e.columns>0&&"column-setting"!==r.type&&"number"==typeof r.widthInColumns&&r.widthInColumns>e.columns&&this.warn?.(`Block ${r.id} width ${r.widthInColumns} exceeds configured column width ${e.columns}`),r.type){case"classDef":this.addStyleClass(r.id,r.css);continue;case"applyClass":this.setCssClass(r.id,r.styleClass??"");continue;case"applyStyles":r.stylesStr&&this.addStyle2Node(r.id,r.stylesStr);continue;case"column-setting":e.parent.columns=r.columns??-1;continue;case"edge":{let e=(this.edgeCount.get(r.id)??0)+1;this.edgeCount.set(r.id,e),r.id=e+"-"+r.id,this.edges.push(r);continue}}r.id??=this.generateId(),r.label||(r.label="composite"===r.type?"":r.id);let a=this.byId.get(r.id),l=void 0===a||this.pending.delete(r.id);l?(a&&(r.classes=a.classes,r.styles=a.styles),"composite"===r.type&&(r.colorIndex=this.colors++),this.byId.set(r.id,r)):("na"!==r.type&&(a.type=r.type),r.label!==r.id&&(a.label=r.label));let n=r.children;if(r.children=[],"space"===r.type){let t=r.width??1;if(!(t<=ts-this.spaces))throw new i(`A block diagram can hold at most ${ts} space blocks.`,"limit",{type:"block"});this.spaces+=Math.max(t,0);for(let a=0;a<t;a++){let t={...r,id:r.id+"-"+a,children:[]};this.byId.set(t.id,t),e.children.push(t)}}else l&&e.children.push(r);n&&n.length>0&&t.push(ss(n,r))}this.blocks=this.root.children??[]}},hs=["$end","INVALID","BLOCK_DIAGRAM_KEY","id-block","COLUMNS","MD_STR","STR","SPACE_BLOCK","DEFAULT","LINKSTYLE","INTERPOLATE","classDef","DEFAULT_CLASSDEF_ID","CLASSDEF_ID","CLASSDEF_STYLEOPTS","class","CLASSENTITY_IDS","STYLECLASS","style","STYLE_ENTITY_IDS","STYLE_DEFINITION_DATA","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","end","NODE_DSTART","NODE_DEND","BLOCK_ARROW_START","BLOCK_ARROW_END","DIR","NODE_ID","LINK","START_LINK","LINK_LABEL","SIZE","EOF"],cs=["right","left","x","y","up","down"],ds=new Uint8Array(128);for(let e of[9,10,11,12,13,32,40,41,45,58,60,61,62,91,123,125])ds[e]=1;var fs="'NODE_ID', 'COLUMNS', 'SPACE_BLOCK', 'BLOCK_DIAGRAM_KEY', 'id-block', 'classDef', 'class', 'style'";function us(e){let t=e[e.length-1];return Array.isArray(t)?(e.pop(),e.concat(t)):e}function ps(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=(e,t,l)=>(r.push(e),a.push(t),i.push(s),s=l,!0),h=(t,r)=>o(t,e.slice(s,r),r),c=e=>{l.push(n),n=e},d=()=>{l.length>0&&(n=l.pop())},f=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},u=r=>{for(;r<t;){let t=e.charCodeAt(r);if(t<48||t>57)break;r++}return r},p=r=>{for(;r<t&&Q(e.charCodeAt(r));)r++;return r},g=t=>e.startsWith(t,s)&&!Q(e.charCodeAt(s+t.length)),m=()=>(96===e.charCodeAt(s+1)?(c(2),s+=2):(c(1),s++),!0),y=t=>{if(46!==e.charCodeAt(t))return-1;do{t++}while(46===e.charCodeAt(t));if(45!==e.charCodeAt(t))return-1;let r=e.charCodeAt(t+1);return 120===r||111===r||62===r?t+2:t+1},x=t=>{let r=e.charCodeAt(t);(120===r||111===r||60===r)&&t++;let a=e.charCodeAt(t);if(46===a)return y(t);if(45!==a&&61!==a)return-1;let i=t+1;for(;e.charCodeAt(i)===a;)i++;if(i-t===1)return 45===a?y(i):-1;let l=e.charCodeAt(i);return 120===l||111===l||62===l?i+1:i-t>=3?i:-1},w=()=>{let t=x(s);if(t>=0)return h(33,f(t));let r=60===e.charCodeAt(s)?s+1:s,a=e.charCodeAt(r),i=e.charCodeAt(r+1);return(45===a&&(45===i||46===i)||61===a&&61===i)&&(c(6),h(34,f(r+2)))},$=r=>{let a=e.indexOf("\n",s);return-1===a&&(a=t),d(),h(r,a)},b=(t,r)=>{let a=p(s);if(a===s)return!1;for(;44===e.charCodeAt(a);){let e=f(a+1),t=p(e);if(t===e)break;a=t}return n=r,h(t,a)},M=r=>{if(q(r))return s=f(s+1),!0;let a;switch(r){case 98:if(e.startsWith("block",s)){if(g("block-beta"))return h(2,s+10);if(58===e.charCodeAt(s+5))return h(3,s+6);if(!Q(e.charCodeAt(s+5)))return h(2,s+5)}break;case 99:if(e.startsWith("columns",s)){if(a=f(s+7),a>s+7){if(e.startsWith("auto",a)&&!Q(e.charCodeAt(a+4)))return o(4,"-1",a+4);let t=u(a);if(t>a)return o(4,e.slice(a,t),t)}}else if(e.startsWith("class",s)){let t=e.startsWith("Def",s+5),r=t?s+8:s+5;if(a=f(r),a>r)return c(t?7:9),h(t?11:15,a)}break;case 34:return m();case 115:if(e.startsWith("space",s)){if(58===e.charCodeAt(s+5)){let t=u(s+6);if(t>s+6)return o(7,e.slice(s+6,t),t)}if(!Q(e.charCodeAt(s+5)))return o(7,"1",s+5)}else if(e.startsWith("style",s)&&(a=f(s+5),a>s+5))return c(11),h(18,a);break;case 100:if(g("default"))return h(8,s+7);break;case 108:if(g("linkStyle"))return h(9,s+9);break;case 105:if(g("interpolate"))return h(10,s+11);break;case 97:if(e.startsWith("accTitle",s)){if(a=f(s+8),58===e.charCodeAt(a))return c(13),h(21,f(a+1))}else if(e.startsWith("accDescr",s)){a=f(s+8);let t=e.charCodeAt(a);if(58===t)return c(14),h(23,f(a+1));if(123===t)return c(15),s=f(a+1),!0}break;case 101:if(g("end"))return h(26,f(s+3));break;case 45:return 41===e.charCodeAt(s+1)?(c(3),h(27,s+2)):w();case 61:return w();case 60:return 91===e.charCodeAt(s+1)?(c(4),h(29,s+2)):w();case 40:{let t=e.charCodeAt(s+1),r=45===t||91===t?2:40===t?40===e.charCodeAt(s+2)?3:2:1;return c(3),h(27,s+r)}case 41:case 123:return c(3),h(27,e.charCodeAt(s+1)===r?s+2:s+1);case 62:return c(3),h(27,s+1);case 91:{let t=e.charCodeAt(s+1);return c(3),h(27,91===t||124===t||40===t||92===t||47===t?s+2:s+1)}case 58:{let t=u(s+1);return t>s+1&&o(36,e.slice(s+1,t),t)}}for(a=s;a<t;){let t=e.charCodeAt(a);if(t<128?1===ds[t]:q(t))break;a++}return a>s&&h(32,a)},v=t=>{let r=e.charCodeAt(s+1),a=0;switch(t){case 34:return m();case 40:a=45===r?2:40===r?40===e.charCodeAt(s+2)?3:2:1;break;case 41:a=41===r?41===e.charCodeAt(s+2)?3:2:93===r?2:1;break;case 125:a=125===r?2:1;break;case 45:a=41===r?2:0;break;case 93:a=93===r||41===r||62===r?2:1;break;case 92:case 47:a=93===r?2:0}return 0!==a&&(d(),h(28,s+a))},k=t=>{if(41===t)return d(),d(),o(30,"]>",f(s+1));let r=f(44===t?s+1:s);for(let a of cs)if(e.startsWith(a,r)){let i=f(r+a.length);return o(31,e.slice(44===t?r:s,i),i)}return!1};for(;;){if(s>=t){let e=-1;switch(n){case 0:e=37;break;case 1:e=6;break;case 8:e=14;break;case 10:e=17;break;case 12:e=20;break;case 13:e=22;break;case 14:e=24;break;case 15:e=25}s=t,-1!==e&&o(e,"",t);break}let l=e.charCodeAt(s),u=!0;switch(n){case 0:u=M(l);break;case 1:if(34===l)d(),s++;else{let r=e.indexOf('"',s);h(6,-1===r?t:r)}break;case 2:if(96===l)u=34===e.charCodeAt(s+1),u&&(d(),s+=2);else if(34===l)u=!1;else{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(96===t||34===t)break;r++}h(5,r)}break;case 3:u=v(l);break;case 4:if(34===l)m();else if(93===l&&62===e.charCodeAt(s+1)){let t=f(s+2);u=40===e.charCodeAt(t),u&&(c(5),s=t+1)}else u=!1;break;case 5:u=k(l);break;case 6:if(34===l)96===e.charCodeAt(s+1)?m():(h(35,s+1),c(1));else{let e=x(f(s));u=e>=0,u&&(d(),h(33,f(e)))}break;case 7:{let t=12,r=e.startsWith("DEFAULT",s)?s+7:s,a=f(r);(r===s||a===r)&&(t=13,r=p(s),a=f(r)),u=r>s&&a>r,u&&(n=8,h(t,a));break}case 8:$(14);break;case 9:u=b(16,10);break;case 10:$(17);break;case 11:u=b(19,12);break;case 12:$(20);break;case 13:$(22);break;case 14:$(24);break;case 15:if(125===l)d(),s++;else{let r=e.indexOf("}",s);h(25,-1===r?t:r)}}if(!u)return r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}}return r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}(e),l=0,n=t=>{let a=r[l];throw 1===a?c("block",e,i[l],"",!0):c("block",e,i[l],`Expecting ${t}, got '${hs[a]}'`)},s=e=>(r[l]!==e&&n(`'${hs[e]}'`),a[l++]),o=()=>{let e=s(32);if(27===r[l]){let t=a[l++];return{id:e,label:s(6),typeStr:t+s(28)}}if(29===r[l]){let t=a[l++],i=s(6),n=[s(31)];for(;31===r[l];)n.push(a[l++]);return{id:e,label:i,typeStr:t+s(30),directions:n}}return{id:e}},h=()=>{let e,i=o(),n=36===r[l]?parseInt(a[l++],10):1,h={id:i.id,label:i.label,type:t.typeStr2Type(i.typeStr),directions:i.directions,widthInColumns:n};for(;33===r[l]||34===r[l];){let i="";34===r[l++]&&(s(35),i=s(6),s(33));let n=a[l-1],c=o(),d=t.edgeStrToEdgeData(n),f=t.edgeStrToEdgeStartData(n),u=t.edgeStrToThickness(n),p=t.edgeStrToPattern(n);e??=[{id:h.id,label:h.label,type:h.type,directions:h.directions}],h={id:c.id,label:c.label,type:t.typeStr2Type(c.typeStr),directions:c.directions},e.push({id:e[e.length-1].id+"-"+c.id,start:e[e.length-1].id,end:c.id,label:i,type:"edge",thickness:u,pattern:p,directions:c.directions,arrowTypeEnd:d,arrowTypeStart:f},h)}return e??h};s(2);let d=[],f=[];for(;;)switch(r[l]){case 32:f.push(h());break;case 4:f.push({type:"column-setting",columns:parseInt(a[l++],10)});break;case 7:{let e=parseInt(a[l++],10);f.push({id:t.generateId(),type:"space",label:"",width:e,children:[]});break}case 2:l++,d.push({list:f,header:void 0}),f=[];break;case 3:l++,32!==r[l]&&n("'NODE_ID'"),d.push({list:f,header:h()}),f=[];break;case 26:{let e=d.pop();if(void 0===e||0===f.length)return n(fs);l++;let r=t.generateId(),a=us(f);f=e.list,f.push(void 0===e.header?{id:r,type:"composite",label:"",children:a}:{...e.header,type:"composite",children:a});break}case 11:{l++;let e=s(13).trim();f.push({type:"classDef",id:e,css:s(14).trim()});break}case 15:{l++;let e=s(16).trim();f.push({type:"applyClass",id:e,styleClass:s(17).trim()});break}case 18:{l++;let e=s(19).trim();f.push({type:"applyStyles",id:e,stylesStr:s(20).trim()});break}case 37:return d.length>0&&n(fs+", 'end'"),0===f.length&&n(fs),void t.setHierarchy(us(f));default:n(0===f.length?fs:fs+(d.length>0?", 'end'":", 'EOF'"))}}function gs(e,t,r,a){return function(e){if(void 0===$)return e();let t=$;$=void 0;try{return e()}finally{$=t}}(()=>Fl(e,!1,t,r,a,1))}function ms(e,t,r,a,i,l,n){let s=gs(e,t,r,4e3);if(0===s.height)return{width:i,height:l,content:n};let o=s.height+12,h=Math.max(i,Math.ceil(s.width+2*a));return{width:h,height:Math.ceil(l+o),content:Fe(s,h/2,a+s.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe((h-i)/2)},${Oe(o)})">${n}</g>`}}var ys=12;var xs=(e,t)=>e&t?1:0;function ws(e){return 0===e||12&e?0===e||3&e?"":"y":"x"}function $s(e,t,r){let a=ws(e),i=xs(e,2)-xs(e,1),l=xs(e,4)-xs(e,8);if("x"===a){let a=Math.max(r+8,14)+14,l=Math.min(a/2,20);return{w:Math.max(t+12,16)+l*(3===e?2:1),h:a,dx:i*l/2,dy:0}}if("y"===a){let a=Math.max(t+16,14)+14,i=Math.min(a/2,20);return{w:a,h:Math.max(r+8,16)+i*(12===e?2:1),dx:0,dy:l*i/2}}return{w:Math.max(t+16,24)+ys*(xs(e,2)+xs(e,1)),h:Math.max(r+8,24)+ys*(xs(e,4)+xs(e,8)),dx:i*ys/2,dy:l*ys/2}}function bs(e,t,r,a){let i,l=ws(e),n=t/2,s=r/2;if("x"===l){let t=Math.min(s,20),r=s-7,a=2&e?-n+t:-n,l=1&e?n-t:n;i=[a,-r,l,-r],1&e&&i.push(l,-s,n,0,l,s),i.push(l,r,a,r),2&e&&i.push(a,s,-n,0,a,-s)}else if("y"===l){let t=Math.min(n,20),r=n-7,a=4&e?-s+t:-s,l=8&e?s-t:s;i=[r,a,r,l],8&e&&i.push(n,l,0,s,-n,l),i.push(-r,l,-r,a),4&e&&i.push(-n,a,0,-s,n,a)}else{let t=2&e?-n+ys:-n,r=1&e?n-ys:n,a=4&e?-s+ys:-s,l=8&e?s-ys:s,o=(t+r)/2,h=(a+l)/2,c=Math.min(10,(r-t)/2),d=Math.min(10,(l-a)/2);i=[t,a],4&e&&i.push(o-c,a,o,-s,o+c,a),i.push(r,a),1&e&&i.push(r,h-d,n,h,r,h+d),i.push(r,l),8&e&&i.push(o+c,l,o,s,o-c,l),i.push(t,l),2&e&&i.push(t,h+d,-n,h,t,h-d)}let o="";for(let e=0;e<i.length;e+=2)o+=(e?" ":"")+Oe(i[e])+","+Oe(i[e+1]);return`<polygon points="${o}" stroke-linejoin="round"${a}/>`}function Ms(e,t){if(0===e||!Number.isInteger(e))throw new i("Columns must be an integer !== 0.","semantic",{type:"block"});if(t<0||!Number.isInteger(t))throw new i("Position must be a non-negative integer."+t,"semantic",{type:"block"});return e<0?{px:t,py:0}:{px:t%e,py:Math.floor(t/e)}}function vs(e,t,r){let a=e.columns,i=[],l=0,n=0,s=0,o=0;for(let r of e.children){let{px:e,py:h}=Ms(a,l),c=r.span>=1?Math.min(r.span,1e3):1;if(a>0&&c>a-e&&(c=a-e),r.span=c,r.col=e,r.row=h,l+=c,e+c>n&&(n=e+c),h===i.length&&i.push(0),0===r.children.length?i[h]=-1:i[h]>=0&&r.nh>i[h]&&(i[h]=r.nh),r.space)continue;let d=(r.nw-t*(c-1))/c;d>s&&(s=d),r.nh>o&&(o=r.nh)}let h=(i.length-1)*t+As(e.rowGaps);for(let e=0;e<i.length;e++)i[e]<0&&(i[e]=o),h+=i[e];e.cols=n,e.heights=i,e.nw=Math.max(e.nw,n*s+(n-1)*t+As(e.colGaps)+2*r),e.nh=h+2*r+e.head}function ks(e,t,r){let{cols:a,heights:i,rowGaps:l,colGaps:n}=e,s=i.length,o=(e.w-2*r-(a-1)*t-As(n))/a,h=e.h-2*r-e.head-(s-1)*t-As(l),c=[];if(n.length>0){let e=0;for(let t=0;t<a;t++)c.push(e),e+=n[t]??0}let d=0;for(let e of i)d+=e;let f=d>0?h/d:0,u=d>0?0:h/s,p=e.x-e.w/2+r,g=e.y-e.h/2+r+e.head,m=0;for(let r of e.children){for(;m<r.row;m++)g+=i[m]*f+u+t+(l[m]??0);let e=c[r.col]??0;r.w=o*r.span+t*(r.span-1)+(c[r.col+r.span-1]??0)-e,r.h=i[m]*f+u,r.x=p+r.col*(o+t)+e+r.w/2,r.y=g+r.h/2}}function As(e){let t=0;for(let r of e)t+=r??0;return t}var Ts=200,Cs=' fill="var(--_s)" stroke="var(--_b)"',Es=' stroke="var(--_b)"',_s=[],Ss=[],Is=[],Ns=[],Ds=["default"],Rs=2e6,Ls=new Map([["square","rect"],["round","rounded"],["circle","circle"],["doublecircle","dbl-circ"],["diamond","diam"],["hexagon","hex"],["stadium","stadium"],["subroutine","fr-rect"],["cylinder","cyl"],["rect_left_inv_arrow","odd"],["lean_right","lean-r"],["lean_left","lean-l"],["trapezoid","trap-b"],["inv_trapezoid","trap-t"]]),Os=new Set(["circle","dbl-circ","diam"]),Fs=new Set(["stadium","hex","odd","lean-r","lean-l","trap-b","trap-t"]);function zs(e){return 0===e.kind&&("circle"===e.shape||"dbl-circ"===e.shape)}function Ws(e,t,r){let a=e.bw/2,i=e.bh/2,l=Math.abs(t-e.x),n=i;return zs(e)?n=Math.sqrt(Math.max(a*a-l*l,0)):0===e.kind&&"diam"===e.shape?n=i*Math.max(1-l/a,0):0===e.kind?n=i-hl(e.shape,e.bw,e.bh,r>0?2:0):1===e.kind&&"x"===ws(e.mask)&&(n=i-7),e.y+r*n}function Ps(e,t,r){let a=e.bw/2,i=e.bh/2,l=Math.abs(t-e.y),n=a;return zs(e)?n=Math.sqrt(Math.max(i*i-l*l,0)):0===e.kind&&"diam"===e.shape?n=a*Math.max(1-l/i,0):0===e.kind?n=a-hl(e.shape,e.bw,e.bh,r>0?1:3):1===e.kind&&"y"===ws(e.mask)&&(n=a-7),e.x+r*n}function Bs(e,t,r,a){let i,l=t-e.x,n=r-e.y,s=e.bw/2,o=e.bh/2;i=zs(e)?s/(Math.hypot(l,n)||1):0===e.kind&&"diam"===e.shape?1/(Math.abs(l)/s+Math.abs(n)/o||1):Math.min(0===l?1/0:s/Math.abs(l),0===n?1/0:o/Math.abs(n)),i===1/0&&(i=0),a.push(e.x+l*i,e.y+n*i)}function Hs(e,t,r,a,i){let l=i.x-i.bw/2+1,n=i.x+i.bw/2-1,s=i.y-i.bh/2+1,o=i.y+i.bh/2-1;if(e<l&&r<l||e>n&&r>n||t<s&&a<s||t>o&&a>o)return!1;if(e===r||t===a)return!0;let h=r-e,c=a-t,d=(r,a)=>Math.sign(h*(a-t)-c*(r-e)),f=d(l,s);return 0===f||d(n,s)!==f||d(n,o)!==f||d(l,o)!==f}function Ys(e,t,r,a){let i=0;for(let l of a)if(l!==t&&l!==r)for(let t=0;t+3<e.length;t+=2)if(Hs(e[t],e[t+1],e[t+2],e[t+3],l)){i++;break}return i}function Gs(e,t,r,a){let i=e.x-e.bw/2,l=e.x+e.bw/2,n=e.y-e.bh/2,s=e.y+e.bh/2,o=t.x-t.bw/2,h=t.x+t.bw/2,c=t.y-t.bh/2,d=t.y+t.bh/2,f=Math.max(i,o),u=Math.min(l,h),p=Math.max(n,c),g=Math.min(s,d),m=u-f>6,y=g-p>6;if(m&&y){let r,a=e.bw*e.bh<=t.bw*t.bh?e:t,i=a===e?t:e,l=a.y-a.bh/2-(i.y-i.bh/2),n=i.y+i.bh/2-(a.y+a.bh/2),s=a.x-a.bw/2-(i.x-i.bw/2),o=i.x+i.bw/2-(a.x+a.bw/2),h=Math.min(l,n,s,o);return r=h===n?[a.x,Ws(a,a.x,1),a.x,i.y+i.bh/2]:h===l?[a.x,Ws(a,a.x,-1),a.x,i.y-i.bh/2]:h===o?[Ps(a,a.y,1),a.y,i.x+i.bw/2,a.y]:[Ps(a,a.y,-1),a.y,i.x-i.bw/2,a.y],a===e?r:[r[2],r[3],r[0],r[1]]}if(m){let a=Math.min(6,(u-f)/2),i=Math.min(Math.max((f+u)/2+r,f+a),u-a),l=t.y>e.y?1:-1;return[i,Ws(e,i,l),i,Ws(t,i,-l)]}if(y){let a=Math.min(6,(g-p)/2),i=Math.min(Math.max((p+g)/2+r,p+a),g-a),l=t.x>e.x?1:-1;return[Ps(e,i,l),i,Ps(t,i,-l),i]}let x=t.x>e.x?1:-1,w=t.y>e.y?1:-1,$=[Ps(e,e.y,x),e.y,t.x,e.y,t.x,Ws(t,t.x,-w)],b=[e.x,Ws(e,e.x,w),e.x,t.y,Ps(t,t.y,-x),t.y],M=Math.abs(t.x-e.x)>=Math.abs(t.y-e.y),v=M?$:b;if(void 0===a)return v;let k=Ys(v,e,t,a);if(0===k)return v;let A=M?b:$,T=Ys(A,e,t,a);if(T<k&&(v=A,k=T),0===k)return v;let C=[];return Bs(e,t.x,t.y,C),Bs(t,e.x,e.y,C),Ys(C,e,t,a)<k?C:v}function Us(e,t,r){let a=e.length,i=e[0],l=e[1],n=e[a-2],s=e[a-1],o=e[2]-i,h=e[3]-l,c=Math.hypot(o,h);o/=c||1,h/=c||1;let d=n-e[a-4],f=s-e[a-3],u=Math.hypot(d,f);if(d/=u||1,f/=u||1,4===a&&t+r>c){let e=c/(t+r);t*=e,r*=e}t=Math.min(t,c),r=Math.min(r,u);let p=`M${Oe(i+o*t)},${Oe(l+h*t)}`;if(6===a){let a=Math.max(0,Math.min(8,c-t,u-r));p+=`L${Oe(e[2]-o*a)},${Oe(e[3]-h*a)}Q${Oe(e[2])},${Oe(e[3])} ${Oe(e[2]+d*a)},${Oe(e[3]+f*a)}`}return p+=`L${Oe(n-d*r)},${Oe(s-f*r)}`,{d:p,sx:i,sy:l,sdx:-o,sdy:-h,ex:n,ey:s,edx:d,edy:f}}function qs(e,t){let r=e.bw/2,a=e.bh/2,i=Math.max(1,Math.min(10+5*(t-1),r,a));if(zs(e)){let t=e.x+r*Math.SQRT1_2,a=e.y-r*Math.SQRT1_2,l=2*Math.asin(Math.min(1,i/(2*r))),n=i=>Math.atan2(e.y-r*Math.sin(i)-a,e.x+r*Math.cos(i)-t);return[t,a,i,n(Math.PI/4+l),n(Math.PI/4-l)]}if(0===e.kind&&"diam"===e.shape){let t=Math.atan2(a,r);return[e.x+r/2,e.y-a/2,i,t+Math.PI,t]}return[e.x+r,e.y-a,i,Math.PI,Math.PI/2]}function js(e,t,r,a){let[i,l,n,s,o]=qs(e,t),h=s+r/n,c=o-a/n,d=(c-h)%(2*Math.PI);d<=0&&(d+=2*Math.PI);let f=i+n*Math.cos(h),u=l+n*Math.sin(h),p=i+n*Math.cos(c),g=l+n*Math.sin(c),m=i+n*Math.cos(s),y=l+n*Math.sin(s),x=i+n*Math.cos(o),w=l+n*Math.sin(o),$=Math.hypot(m-f,y-u),b=Math.hypot(x-p,w-g);return{d:`M${Oe(f)},${Oe(u)}A${Oe(n)},${Oe(n)} 0 ${d>Math.PI?1:0} 1 ${Oe(p)},${Oe(g)}`,sx:m,sy:y,sdx:$>0?(m-f)/$:Math.sin(s),sdy:$>0?(y-u)/$:-Math.cos(s),ex:x,ey:w,edx:b>0?(x-p)/b:-Math.sin(o),edy:b>0?(w-g)/b:Math.cos(o)}}var Vs=[.5,.3,.7,.15,.85];function Xs(e,t,r,a,i,l,n){if(void 0===n)return!1;for(let s of n)if(s!==i&&s!==l&&Math.abs(e-s.x)<(r+s.bw)/2&&Math.abs(t-s.y)<(a+s.bh)/2)return!0;return!1}function Ks(e,t,r,a,i,l,n){if(void 0===n)return.5;for(let s of Vs){if(!Xs(e[t]+(e[t+2]-e[t])*s,e[t+1]+(e[t+3]-e[t+1])*s,r,a,i,l,n))return s}return.5}function Zs(e,t,r,a,i,l){let n=r[e[0]][0]===r[e[0]][2],s=-1/0,o=1/0,h=-4,c=!1;for(let a=0;a<e.length;a++){let i=r[e[a]];if(n?i[0]!==i[2]:i[1]!==i[3])return 0;s=Math.max(s,n?Math.min(i[1],i[3]):Math.min(i[0],i[2])),o=Math.min(o,n?Math.max(i[1],i[3]):Math.max(i[0],i[2]));let l=t[e[a]];h+=(n?l.label.height:l.label.width+8)+4;for(let r=0;r<a;r++){let a=t[e[r]];Math.abs(l.lx-a.lx)<(l.label.width+a.label.width)/2+8&&Math.abs(l.ly-a.ly)<(l.label.height+a.label.height)/2&&(c=!0)}}if(!c)return 0;if(h>o-s-16)return h-(o-s-16);let d=[],f=(s+o-h)/2;for(let r of e){let{label:e,lx:s,ly:o}=t[r],h=n?e.height:e.width+8,c=f+h/2;if(Xs(n?s:c,n?c:o,e.width+8,e.height,a,i,l))return 0;d.push(c),f+=h+4}return e.forEach((e,r)=>{n?t[e].ly=d[r]:t[e].lx=d[r]}),0}function Qs(e,t,r,a,i,l){let n=new Set;for(let r=t;void 0!==r;r=e[r.index])n.add(r);let s,o=r;for(;void 0!==o&&!n.has(o);)s=o,o=e[o.index];if(void 0===o||void 0===s||o===t)return!1;let h,c=t;for(;e[c.index]!==o;)c=e[c.index];if(a){if(c.row===s.row)return!1;h=Math.max(c.row,s.row)-1,o.rowGaps===Ns&&(o.rowGaps=[])}else{let[e,t]=c.col<s.col?[c,s]:[s,c];if(t.col<e.col+e.span)return!1;h=t.col-1,o.colGaps===Ns&&(o.colGaps=[])}let d=a?o.rowGaps:o.colGaps;return l.has(d)||l.set(d,d.slice()),d[h]=Math.max(d[h]??0,(l.get(d)[h]??0)+i),!0}var Js={type:"block",math:!0,parse(e,t,r){let a=new os;return a.title=r,ps(e,a),a},render:function(e,t,r){return Vl(r,a=>function(e,t,r,a){let i=r.fontSize??16,l=Math.round(.875*i),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8,o=r.icons,h=t.block?.padding,c=Math.min("number"==typeof h&&h>=0?Math.min(h,200):12,a?6:1/0),d=a?80:Ts,f=t=>{let r=[],a=e=>{for(let t of e)for(let e of t.split(";"))r.push(e)};for(let r of t.classes&&t.classes.length>0?t.classes:Ds){let t=e.classes.get(r);t&&a(t.styles)}return t.styles&&a(t.styles),Ri(r)},u=(e,t)=>{let l,s=e.type,o="space"===s?Ri(_s):f(e),h=(o.bold?1:0)|(o.italic?2:0),u=o.fontSize??i,p=0,g="",m=0,y=0,x=0,w=0,$=0,b=0;if("space"===s)p=3,l=Fl(void 0,!1,n,u,d);else if("composite"===s)p=2,l=Fl(e.label,!1,n,u,a?Gl(r):4e3,h),x=l.height>0?l.height+4:0,m=l.width+2*c,y=x+2*c;else if("block_arrow"===s){p=1,l=Fl(e.label,!1,n,u,d,h);let t=!0;for(let e of l.lines)for(let r of e)(void 0!==r.icon||""!==r.text.trim())&&(t=!1);w=function(e){let t=0;if(e)for(let r of e)switch(r.trim()){case"right":t|=1;break;case"left":t|=2;break;case"up":t|=4;break;case"down":t|=8;break;case"x":t|=3;break;case"y":t|=12}return t}(e.directions);let r=t?$s(w,0,0):$s(w,l.width,l.height);m=r.w,y=r.h,$=r.dx,b=r.dy}else{g=Ls.get(s??"")??"rect",l=Fl(e.label,!1,n,u,d,h);let t=sl(g,l.width,l.height);m=t.w,y="cyl"===g?Math.max(t.h,l.height+40):t.h,b=t.dy}return{children:[],columns:2===p?e.columns??-1:-1,span:3===p?1:e.widthInColumns??1,space:3===p,head:x,nw:m,nh:y,col:0,row:0,cols:0,heights:Is,rowGaps:Ns,colGaps:Ns,x:0,y:0,w:0,h:0,block:e,kind:p,index:t,shape:g,label:l,style:o,mask:w,dx:$,dy:b,bw:0,bh:0}},p=u(e.root,0);p.nw=0,p.nh=0;let g=[p],m=[],y=new Map;for(let e=0;e<g.length;e++){let t=g[e];if(2===t.kind)for(let e of t.block.children??Ss){let r=u(e,g.length);t.children.push(r),m[r.index]=t,g.push(r),3!==r.kind&&y.set(e.id,r)}}let x=[],w=[],$=g.map(e=>e.nw),b=()=>{for(let e of g)e.nw=$[e.index];let e=function(e,t){let r=[e];for(let e=0;e<r.length;e++)for(let t of r[e].children)r.push(t);for(let e=r.length-1;e>=0;e--){let a=r[e];a.children.length>0&&vs(a,t,0===e?0:t)}e.w=e.nw,e.h=e.nh,e.x=e.w/2,e.y=e.h/2;for(let e=0;e<r.length;e++){let a=r[e];a.children.length>0&&ks(a,t,0===e?0:t)}return{width:e.w,height:e.h}}(p,c);x.length=0,w.length=0;for(let e of g)0===e.kind&&Os.has(e.shape)?(e.bw=e.nw,e.bh=e.nh):1===e.kind?(e.bw=e.span>1?e.w:e.nw,e.bh=e.nh):(e.bw=e.w,e.bh=0===e.kind&&Fs.has(e.shape)?e.nh:e.h),0===e.kind&&"cyl"===e.shape&&(e.dy=Math.min(12,Math.max(6,e.bw/14))/2),0===e.kind||1===e.kind?x.push(e):e.head>0&&w.push({x:e.x,y:e.y-e.h/2+(e.head+c)/2+2,bw:e.label.width,bh:e.label.height});return e},M=b(),v=new Map,k=new Set,A=[],T=[];for(let t of e.edges){let e=y.get(t.start??""),r=y.get(t.end??"");if(void 0===e||void 0===r)continue;let a=Math.min(e.index,r.index)*g.length+Math.max(e.index,r.index);v.set(a,(v.get(a)??0)+1),t.label&&k.add(a),A.push([e,r]),T.push(t)}let C=T.length*x.length<=Rs?x:void 0,E=[],_=new Map,S=[],I=()=>{let e=new Map;E.length=0,_.clear();for(let t=0;t<T.length;t++){let[r,a]=A[t],i=Math.min(r.index,a.index)*g.length+Math.max(r.index,a.index),s=v.get(i)??1,o=e.get(i)??0;e.set(i,o+1);let h,c,d,f=Fl(T[t].label,!1,n,l,Ts);if(r===a){let[e,t,a]=qs(r,o+1);h=[],c=e+a+6+f.width/2,d=t-a/2}else{h=Gs(r,a,(o-(s-1)/2)*(k.has(i)?Math.round(1.5*l)+2:14),C);let e=h.length,n=Math.abs(h[2]-h[0])+Math.abs(h[3]-h[1]),u=Math.abs(h[e-2]-h[e-4])+Math.abs(h[e-1]-h[e-3]),p=6===e&&u>n?2:0,g=f.width>0?Ks(h,p,f.width+8,f.height,r,a,C):.5;if(c=h[p]+(h[p+2]-h[p])*g,d=h[p+1]+(h[p+3]-h[p+1])*g,f.width>0&&s>1){S[t]=h.slice(p,p+4);let e=_.get(i);e?e.push(t):_.set(i,[t])}}E.push({edge:T[t],points:h,loop:r===a?o+1:0,label:f,lx:c,ly:d})}},N=e=>{I();let t=C&&[...C,...w],r=new Map,i=!1;for(let l of _.values()){if(l.length<2)continue;let[n,s]=A[l[0]],o=Zs(l,E,S,n,s,t),h=S[l[0]][0]===S[l[0]][2];e&&o>0&&(h||!a)&&Qs(m,n,s,h,Math.ceil(o),r)&&(i=!0)}return i},D=()=>{let e=0;for(let t=0;t<E.length;t++){let r=E[t];for(let a=t+1;a<E.length;a++){let t=E[a],i=(r.label.width+8)/2,l=(t.label.width+8)/2,n=Math.min(r.lx+i,t.lx+l)-Math.max(r.lx-i,t.lx-l),s=Math.min(r.ly+r.label.height/2,t.ly+t.label.height/2)-Math.max(r.ly-r.label.height/2,t.ly-t.label.height/2);r.label.width>0&&t.label.width>0&&n>0&&s>0&&(e+=n*s)}}return e},R=0,L=0,O=0,F=0,z=(e,t,r,a)=>{e-r/2<R&&(R=e-r/2),e+r/2>O&&(O=e+r/2),t-a/2<L&&(L=t-a/2),t+a/2>F&&(F=t+a/2)},W=()=>{R=0,L=0,O=M.width,F=M.height;for(let e=0;e<E.length;e++){let t=E[e];if(t.loop>0){let[r,a,i]=qs(A[e][0],t.loop);z(r,a,2*i+2,2*i+2)}t.label.width>0&&z(t.lx,t.ly,t.label.width+8,t.label.height)}return O-R};if(N(T.length*T.length<=Rs)){let e=D(),t=W(),a=!0;for(let e=0;e<3&&a;e++)M=b(),a=N(e<2);let i=W(),l=void 0!==r.maxWidth&&r.maxWidth>0?r.maxWidth:1/0;if(D()>e-1||i>t&&Math.ceil(i+2*s)>l){for(let e of g)e.rowGaps=Ns,e.colGaps=Ns;M=b(),N(!1)}}W();let P=gs(e.title,n,i,a?Gl(r):4e3),B=P.height>0?P.height+12:0,H=Math.max(O-R,P.width),Y=s-R+(H-(O-R))/2,G=s+B-L;for(let e of g)e.x+=Y,e.y+=G;let U=Math.ceil(H+2*s),q=Math.ceil(F-L+B+2*s),j="",V="",X=[];for(let e=1;e<g.length;e++){let t=g[e];if(3===t.kind)continue;let r=Oi((t.block.classes??_s).join(" ")),a=Re(t.block.id);if(2===t.kind){let e=t.y-t.h/2;yt(t.style.shape)&&X.push({box:[t.x-t.w/2,e,t.x+t.w/2,e+t.h],shape:t.style.shape}),j+=`<g class="pele-cluster${r}" data-id="${a}"><rect x="${Oe(t.x-t.w/2)}" y="${Oe(e)}" width="${Oe(t.w)}" height="${Oe(t.h)}" fill="var(--_a)"${ki(t.style.shape)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${Ai(t.style.shape)}/>`+Fe(t.label,t.x,e+(t.head+c)/2+2,` class="pele-cluster-label"${xt(t.style,"var(--_m)")}${t.style.text}`,o)+"</g>";continue}let i=1===t.kind,l=t.label;if(t.span>1&&t.label.width>0&&t.label.lines.length>1&&t.bw>t.nw&&(i||!Os.has(t.shape))){let e=(t.style.bold?1:0)|(t.style.italic?2:0),r=t.label.width+(t.bw-t.nw);l=Fl(t.block.label,!1,n,t.label.size,r,e)}V+=`<g class="pele-node pele-shape-${i?"block-arrow":t.shape}${r}" data-id="${a}" transform="translate(${Oe(t.x)},${Oe(t.y)})">`+(i?bs(t.mask,t.bw,t.bh,Cs+t.style.shape):ol(t.shape,t.bw,t.bh,Cs+t.style.shape,Es+t.style.line))+Fe(l,t.dx,t.dy,` class="pele-label"${i||dl(t.shape)?xt(t.style):""}${t.style.text}`,o)+"</g>"}let K="",Z="",Q="";for(let e=0;e<E.length;e++){let t,{edge:r,points:a,loop:i,label:l}=E[e],n=r.arrowTypeStart??"",s=r.arrowTypeEnd??"";if(i>0)t=js(A[e][0],i,ii(n),ii(s));else{for(let e=0;e<a.length;e+=2)a[e]+=Y,a[e+1]+=G;t=Us(a,ii(n),ii(s))}let h=gi(t.d,[t.sx,t.sy,t.ex,t.ey],X);if(""===h&&(K+=yi(t,n,s,"","thick"===r.thickness)),Z+=`<g class="pele-edge" data-id="${Re(r.id)}"${h?` stroke="${h}"`:""}><path d="${t.d}"${"thick"===r.thickness?' stroke-width="2.5"':""}${"dotted"===r.pattern?' stroke-dasharray="3 4"':""}/>`+li(n,t.sx,t.sy,t.sdx,t.sdy,h||"var(--_l)")+li(s,t.ex,t.ey,t.edx,t.edy,h||"var(--_l)")+"</g>",l.width>0){let t=E[e].lx+Y,a=E[e].ly+G;Q+=wi(r.id,l,t,a,"",o)}}return{svg:Bi("block",U,q,i,r,e,Fe(P,U/2,s+P.height/2,' class="pele-title" font-weight="var(--_tw)"')+(j?`<g class="pele-clusters">${j}</g>`:"")+xi(K)+(Z?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${Z}</g>`:"")+`<g class="pele-nodes">${V}</g>`+(Q?`<g class="pele-edge-labels" font-size="${l}">${Q}</g>`:"")),width:U,height:q,links:[]}}(e,t,r,a))}},eo=new Set(["label","type","descr","techn","sprite","tags","link","bgColor","fontColor","borderColor","shadowing","shape","legendText","legendSprite"]),to=new Set(["label","descr","techn","sprite","tags","link","textColor","lineColor"]);function ro(e,t){let{key:r,value:a}=t;!("from"in e)||"offsetX"!==r&&"offsetY"!==r?("from"in e?to:eo).has(r)?e[r]=a:(e.extra??=new Map).set(r,a):e[r]=parseInt(a)}function ao(e,t,r){void 0!==r&&("string"==typeof r?e[t]=r:ro(e,r))}function io(e,t,r){void 0===r?e[t]??="":ao(e,t,r)}function lo(e,t){e.labelAttr=void 0,"object"==typeof t?(e.label="",e.labelAttr=t,ro(e,t)):e.label=t??""}var no=class{type="c4";c4Type;title;accTitle;accDescr;shapes=[];boundaries=[{alias:"global",label:"global",type:"global",parent:void 0}];rels=[];shapeInRow=4;boundaryInRow=2;shapeIndex=new Map;boundaryIndex=new Map;relIndex=new Map;current=this.boundaries[0];stack=[];setC4Type(e){this.c4Type=e}setTitle(e){this.title=e}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}element(e,t,r,a){let i="string"==typeof r?t.get(r):void 0;return void 0===i&&(i={alias:"",label:"",parent:void 0},e.push(i),"string"==typeof r?(i.alias=r,t.set(r,i)):(i.aliasAttr=r,ro(i,r))),lo(i,a),i}addPersonOrSystem(e,t){let r=this.element(this.shapes,this.shapeIndex,t[0],t[1]);io(r,"descr",t[2]),this.finishShape(r,e,t,3)}addContainer(e,t){let r=this.element(this.shapes,this.shapeIndex,t[0],t[1]);io(r,"techn",t[2]),io(r,"descr",t[3]),this.finishShape(r,e,t,4)}addComponent(e,t){this.addContainer(e,t)}finishShape(e,t,r,a){ao(e,"sprite",r[a]),ao(e,"tags",r[a+1]),ao(e,"link",r[a+2]),e.kind=t,e.parent=this.current}boundary(e,t){let r=this.element(this.boundaries,this.boundaryIndex,e[0],e[1]);return void 0===e[2]?r.type=t:ao(r,"type",e[2]),r}open(e){e.parent=this.current,this.stack.push(this.current),this.current=e}addPersonOrSystemBoundary(e,t="system"){let r=this.boundary(e,t);ao(r,"tags",e[3]),ao(r,"link",e[4]),this.open(r)}addContainerBoundary(e){this.addPersonOrSystemBoundary(e,"container")}addDeploymentNode(e,t){let r=this.boundary(t,"node");io(r,"descr",t[3]),ao(r,"sprite",t[4]),ao(r,"tags",t[5]),ao(r,"link",t[6]),r.nodeType=e,this.open(r)}popBoundaryParseStack(){this.current=this.stack.pop()??this.boundaries[0]}addRel(e,t){let r=t[0],a=t[1];if(void 0===r||void 0===a||void 0===t[2])return;let i="string"==typeof r&&"string"==typeof a,l=i?this.relIndex.get(r)?.get(a):void 0;if(void 0===l){if(l={type:e,from:"",to:"",label:""},this.rels.push(l),i){let e=this.relIndex.get(r);void 0===e&&this.relIndex.set(r,e=new Map),e.set(a,l)}"string"==typeof r?l.from=r:l.fromAttr=r,"string"==typeof a?l.to=a:l.toAttr=a}l.type=e,lo(l,t[2]),io(l,"techn",t[3]),io(l,"descr",t[4]),ao(l,"sprite",t[5]),ao(l,"tags",t[6]),ao(l,"link",t[7])}getC4Shape(e){return this.shapeIndex.get(e)??this.boundaryIndex.get(e)}updateElStyle(e,t){let r="string"==typeof t[0]?this.getC4Shape(t[0]):void 0;void 0!==r&&(ao(r,"bgColor",t[1]),ao(r,"fontColor",t[2]),ao(r,"borderColor",t[3]),ao(r,"shadowing",t[4]),ao(r,"shape",t[5]),ao(r,"sprite",t[6]),ao(r,"techn",t[7]),ao(r,"legendText",t[8]),ao(r,"legendSprite",t[9]))}updateRelStyle(e,t){let r=t[0],a=t[1],i="string"==typeof r&&"string"==typeof a?this.relIndex.get(r)?.get(a):void 0;if(void 0===i)return;ao(i,"textColor",t[2]),ao(i,"lineColor",t[3]);let l=t[4],n=t[5];"string"==typeof l?i.offsetX=parseInt(l):void 0!==l&&ro(i,l),"string"==typeof n?i.offsetY=parseInt(n):void 0!==n&&ro(i,n)}updateLayoutConfig(e,t){let r=e=>void 0===e?NaN:parseInt("string"==typeof e?e:e.value),a=r(t[0]),i=r(t[1]);a>=1&&(this.shapeInRow=a),i>=1&&(this.boundaryInRow=i)}},so=["$end","INVALID","direction_tb","direction_bt","direction_rl","direction_lr","title","accDescription","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","NEWLINE","C4_CONTEXT","C4_CONTAINER","C4_COMPONENT","C4_DYNAMIC","C4_DEPLOYMENT","PERSON","PERSON_EXT","SYSTEM","SYSTEM_DB","SYSTEM_QUEUE","SYSTEM_EXT","SYSTEM_EXT_DB","SYSTEM_EXT_QUEUE","CONTAINER","CONTAINER_DB","CONTAINER_QUEUE","CONTAINER_EXT","CONTAINER_EXT_DB","CONTAINER_EXT_QUEUE","COMPONENT","COMPONENT_DB","COMPONENT_QUEUE","COMPONENT_EXT","COMPONENT_EXT_DB","COMPONENT_EXT_QUEUE","ENTERPRISE_BOUNDARY","SYSTEM_BOUNDARY","BOUNDARY","CONTAINER_BOUNDARY","NODE","NODE_L","NODE_R","REL","BIREL","REL_U","REL_D","REL_L","REL_R","REL_B","REL_INDEX","UPDATE_EL_STYLE","UPDATE_REL_STYLE","UPDATE_LAYOUT_CONFIG","EOF_IN_STRUCT","ATTRIBUTE_EMPTY","STR","STR_KEY","STR_VALUE","LBRACE","RBRACE","EOF"],oo=new Map([["C4Context",14],["C4Container",15],["C4Component",16],["C4Dynamic",17],["C4Deployment",18],["Person",19],["Person_Ext",20],["System",21],["SystemDb",22],["SystemQueue",23],["System_Ext",24],["SystemDb_Ext",25],["SystemQueue_Ext",26],["Container",27],["ContainerDb",28],["ContainerQueue",29],["Container_Ext",30],["ContainerDb_Ext",31],["ContainerQueue_Ext",32],["Component",33],["ComponentDb",34],["ComponentQueue",35],["Component_Ext",36],["ComponentDb_Ext",37],["ComponentQueue_Ext",38],["Enterprise_Boundary",39],["System_Boundary",40],["Boundary",41],["Container_Boundary",42],["Deployment_Node",43],["Node",43],["Node_L",44],["Node_R",45],["Rel",46],["BiRel",47],["Rel_Up",48],["Rel_U",48],["Rel_Down",49],["Rel_D",49],["Rel_Left",50],["Rel_L",50],["Rel_Right",51],["Rel_R",51],["Rel_Back",52],["RelIndex",53],["UpdateElementStyle",54],["UpdateRelStyle",55],["UpdateLayoutConfig",56]]),ho=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y],co=/[\n\r\u2028\u2029]/g,fo=/title[^\S\r\n]*(?=[\r\n]|$)\s*/y;var uo=["person","external_person","system","system_db","system_queue","external_system","external_system_db","external_system_queue","container","container_db","container_queue","external_container","external_container_db","external_container_queue","component","component_db","component_queue","external_component","external_component_db","external_component_queue"],po=["rel","birel","rel_u","rel_d","rel_l","rel_r","rel_b","rel"],go=["node","nodeL","nodeR"];function mo(e){return 6===e||7===e||8===e||10===e||12===e}function yo(e){return e>=19&&e<=56}function xo(e,t){let{types:r,starts:a,ends:i}=function(e){let t=e.length,r=[],a=[],i=[],l=0,n=9,s=0,o=!1,h=-2,c=-1,d=0,f=(e,t,l)=>{r.push(e),a.push(t),i.push(l),s=l},u=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},p=(r,a)=>{let i=e.indexOf(r,a);return-1===i?t:i},g=(r,a)=>{let i=s+r.length;if(!e.startsWith(r,s)||!q(e.charCodeAt(i)))return!1;let l=++i;for(;i<t;){let t=e.charCodeAt(i);if(35===t||10===t||59===t)break;i++}return i!==l&&(f(a,s,i),!0)};for(;;){if(o){f(0,t,t);break}s>=t&&(o=!0);let r=e.charCodeAt(s);if(0===l){if(s>=t){f(64,t,t);continue}if(-1!==h&&s>=d&&(h<s&&(h=e.indexOf("direction",s)),-1!==h&&(c<s&&(co.lastIndex=s,c=co.test(e)?co.lastIndex-1:t),h<c))){let t=!1;for(let r=0;r<4&&!t;r++)ho[r].lastIndex=s,ho[r].test(e)&&(f(2+r,s,ho[r].lastIndex),t=!0);if(t)continue;d=c}if(116===r){if(fo.lastIndex=s,fo.test(e)){s=fo.lastIndex;continue}if(g("title",6))continue}if(97===r){if(g("accDescription",7))continue;let t=e.startsWith("accTitle",s);if(t||e.startsWith("accDescr",s)){let r=u(s+8),a=e.charCodeAt(r);if(58===a){f(t?8:10,s,u(r+1)),n=t?9:11,l=7;continue}if(123===a&&!t){s=u(r+1),l=8;continue}}}if(37===r&&37===e.charCodeAt(s+1)){let r=p("\n",s+2);for(;r<t&&(10===e.charCodeAt(r)||13===e.charCodeAt(r));)r++;s=r;continue}if(q(r)){let r=s,a=-1;for(;r<t;){let t=e.charCodeAt(r);if(!q(t))break;10===t&&(a=r),r++}-1!==a?f(13,s,a+1):s=r;continue}if(123===r){f(62,s,s+1);continue}if(125===r){f(63,s,s+1);continue}if(Q(r)){let r=s+1;for(;r<t&&Q(e.charCodeAt(r));)r++;let a=r-s<=19?oo.get(e.slice(s,r)):void 0;if(void 0!==a){a>18&&(l=1),f(a,s,r);continue}}f(1,s,s);break}if(1!==l)if(2!==l)if(3!==l)if(4!==l){if(5===l){if(s>=t)continue;let a=s+1;if(61===r)for(;32===e.charCodeAt(a);)a++;if(61!==r||34!==e.charCodeAt(a)){f(1,s,s);break}s=a+1,l=6;continue}if(6!==l)7!==l?125===r?(s++,l=0):f(12,s,p("}",s)):(f(n,s,p("\n",s)),l=0);else{if(s>=t)continue;34===r?(s++,l=2):f(61,s,p('"',s))}}else f(60,s,p("=",s)),l=5;else 34===r?(s++,l=2):f(59,s,p('"',s));else{if(s>=t)continue;if(41===r)s++,l=0;else if(44===r)44===e.charCodeAt(s+1)?f(58,s,s+2):s++;else{let t=s;for(;32===e.charCodeAt(t);)t++;let r=e.charCodeAt(t);34===r?34===e.charCodeAt(t+1)?f(58,s,t+2):(s=t+1,l=3):36===r?(s=t+1,l=4):f(59,s,p(",",s))}}else if(s>=t)f(57,t,t);else if(40===r){let t=s+1;for(;32===e.charCodeAt(t);)t++;44===e.charCodeAt(t)?f(58,s,t+1):s++,l=2}else{if(41!==r){f(1,s,s);break}s++,l=0}}return{types:r,starts:a,ends:i}}(e),l=0,n=t=>e.slice(a[t],i[t]),s=t=>{let i=r[l];throw 1===i?c("c4",e,a[l],"",!0):c("c4",e,a[l],`Expecting ${t}, got '${so[i]}'`)},o=e=>{r[l]!==e&&s(`'${so[e]}'`),l++},h=e=>{6===e?t.setTitle(n(l++).substring(6)):7===e?t.setAccDescription(n(l++).substring(15)):12===e?t.setAccDescription(n(l++).trim()):(l++,8===e?(9!==r[l]&&s("'acc_title_value'"),t.setTitle(n(l++).trim())):(11!==r[l]&&s("'acc_descr_value'"),t.setAccDescription(n(l++).trim())))},d=e=>{l++;let a=(()=>{let e=[];for(;;){let t=r[l];if(59===t)e.push(n(l++).trim());else if(58===t)e.push(""),l++;else{if(60!==t)break;l++,61!==r[l]&&s("'STR_VALUE'"),e.push({key:n(l-1).trim(),value:n(l).trim()}),l++}}return 0===e.length&&s("'STR', 'STR_KEY', 'ATTRIBUTE', 'ATTRIBUTE_EMPTY'"),e})();if(e<=26)t.addPersonOrSystem(uo[e-19],a);else if(e<=32)t.addContainer(uo[e-19],a);else if(e<=38)t.addComponent(uo[e-19],a);else{if(e<=45)return 39===e?a.splice(2,0,"ENTERPRISE"):40===e?a.splice(2,0,"SYSTEM"):42===e&&a.splice(2,0,"CONTAINER"),e>=43?t.addDeploymentNode(go[e-43],a):42===e?t.addContainerBoundary(a):t.addPersonOrSystemBoundary(a),62===r[l]?(l++,o(13)):13===r[l]?(l++,o(62),13===r[l]&&l++):s("'NEWLINE', 'LBRACE'"),!0;e<=53?(53===e&&a.splice(0,1),t.addRel(po[e-46],a)):54===e?t.updateElStyle("update_el_style",a):55===e?t.updateRelStyle("update_rel_style",a):t.updateLayoutConfig("update_layout_config",a)}return!1},f=r[l];(f<14||f>18)&&s("'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'C4_CONTEXT', 'C4_CONTAINER', 'C4_COMPONENT', 'C4_DYNAMIC', 'C4_DEPLOYMENT'"),l++,o(13);let u=0,p=0;for(;;){let e=r[l];if(3===p||4===p){if(13===e){l++,p=2;continue}if(3===p&&yo(e)){p=1;continue}}else{if(yo(e)){d(e)?(u++,p=1):p=4;continue}if(mo(e)&&1!==p){h(e),p=3;continue}2!==p&&s("'title', 'accDescription', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'PERSON', 'REL'")}if(!(u>0))return 64!==e&&s("'NEWLINE', 'EOF'"),l++,o(0),void t.setC4Type(n(0));63!==e&&s("'NEWLINE', 'RBRACE'"),l++,t.popBoundaryParseStack(),u--,p=4}}var wo=/\s/;function $o(e,t,r,a,i=0){let l=[];for(let n of e.split("\n")){let e=Array.from(n);0===e.length&&l.push("");let s=0;for(;s<e.length;){let n=l=>t.width(e.slice(s,s+l).join(""),r,i)<=a,o=1;for(;o<e.length-s&&n(o);)o=Math.min(e.length-s,2*o);let h=1;for(;h<o;){let e=Math.ceil((h+o)/2);n(e)?h=e:o=e-1}let c=h,d=s+c<e.length;if(d&&!wo.test(e[s+c]))for(let t=c-1;t>0;t--)if(wo.test(e[s+t])){c=t+1;break}let f=e.slice(s,s+c).join("");for(l.push(d&&f.trimEnd()||f),s+=c;d&&s<e.length&&wo.test(e[s]);)s++}}""===e&&(l.length=0);let n=l.map(e=>t.width(e,r,i)),s=0;for(let e of n)s=Math.max(s,e);let o=Math.round(1.5*r);return{lines:l.map((e,t)=>[{text:e,style:i,width:n[t]}]),widths:n,width:s,height:l.length*o,size:r,lineHeight:o}}function bo(e,t,r){if(e.width<=r)return e;let a=[],i=[];for(let l=0;l<e.lines.length;l++){if(e.widths[l]<=r){a.push(e.lines[l]),i.push(e.widths[l]);continue}let n=[],s=0,o=()=>{a.push(n),i.push(s),n=[],s=0};for(let a of e.lines[l])if(void 0!==a.icon||a.math)n.length&&s+a.width>r&&o(),n.push(a),s+=a.width;else for(let i of Array.from(a.text)){let l=n[n.length-1],h=l&&void 0===l.icon&&void 0===l.math&&l.style===a.style,c=t.width(h?l.text+i:i,e.size,a.style)-(h?l.width:0);n.length&&s+c>r&&(o(),l=void 0,c=t.width(i,e.size,a.style)),l&&void 0===l.icon&&void 0===l.math&&l.style===a.style?(l.text+=i,l.width+=c):n.push({text:i,style:a.style,width:c}),s+=c}(n.length||!e.lines[l].length)&&o()}let l=0;for(let e of i)l=Math.max(l,e);let n={...e,lines:a,widths:i,width:l,height:a.length*e.lineHeight};return e.heights?Wl(n):n}function Mo(e,t,r,a){let i=Qe(e),l="<text"+Je(a,i),n="";for(let s=0;s<e.lines.length;s++){let o=e.lines[s],h=r+(s+.5)*e.lineHeight;if(o.some(e=>void 0!==e.icon)){let r=e.widths[s];n+=Fe({...e,lines:[o],widths:[r],height:e.lineHeight},t+r/2,h,a);continue}let c="";for(let e of o){let t=Ze(e.style&~i);c+=t?`<tspan${t}>${De(e.text)}</tspan>`:De(e.text)}""!==c&&(n+=`${l} x="${Oe(t)}" y="${Oe(h+.35*e.size)}" text-anchor="start" xml:space="preserve">${c}</text>`)}return n}var vo=28,ko=160,Ao=e=>Math.min(12,Math.max(6,e/14)),To=e=>Math.min(12,e/4);function Co(e,t,r,a,i,l,n,s){let o=0,h=1;if(0===n){if(i<e||i>r)return 1/0}else{let t=(e-i)/n,a=(r-i)/n;o=Math.max(o,Math.min(t,a)),h=Math.min(h,Math.max(t,a))}if(0===s){if(l<t||l>a)return 1/0}else{let e=(t-l)/s,r=(a-l)/s;o=Math.max(o,Math.min(e,r)),h=Math.min(h,Math.max(e,r))}return o<=h?o:1/0}function Eo(e,t,r,a,i,l,n,s){let o=n/r,h=s/a,c=(i-e)/r,d=(l-t)/a,f=o*o+h*h,u=2*(o*c+h*d),p=c*c+d*d-1,g=u*u-4*f*p;if(0===f||g<0)return 1/0;let m=(-u-Math.sqrt(g))/(2*f);return m>=0&&m<=1?m:p<=0?0:1/0}function _o(e,t,r,a,i){let{x:l,y:n,w:s,h:o}=e,h=a-t,c=i-r;if("person"===e.form)return Math.min(Co(l,n+26,l+s,n+o,t,r,h,c),Eo(l+s/2,n+14,13,13,t,r,h,c));if("cyl"===e.form){let e=Ao(s);return Math.min(Co(l,n+e,l+s,n+o-e,t,r,h,c),Eo(l+s/2,n+e,s/2,e,t,r,h,c),Eo(l+s/2,n+o-e,s/2,e,t,r,h,c))}if("h-cyl"===e.form){let e=To(o);return Math.min(Co(l+e,n,l+s-e,n+o,t,r,h,c),Eo(l+e,n+o/2,e,o/2,t,r,h,c),Eo(l+s-e,n+o/2,e,o/2,t,r,h,c))}return Co(l,n,l+s,n+o,t,r,h,c)}function So(e,t,r,a,i){for(let l=2;l<e.length;l+=2){let n=e[l-2],s=e[l-1];if(Co(t,r,a,i,n,s,e[l]-n,e[l+1]-s)<=1)return!0}return!1}function Io(e,t){return e.x<=t.x&&e.y<=t.y&&e.x+e.w>=t.x+t.w&&e.y+e.h>=t.y+t.h}var No=class{upright=[];level=[];frames=[[],[]];taken=new Map;squeezed=0;free(e,t,r,a){let i=Math.min(r,a),l=Math.max(r,a),n=(e,r)=>{for(let a=0;a<e.length;a+=3)if(Math.abs(e[a]-t)<r&&e[a+1]<l&&e[a+2]>i)return!0;return!1};return!n(e?this.upright:this.level,6)&&!n(this.frames[e?0:1],3)}crossings(e){let t=0;for(let r=2;r<e.length;r+=2){let a=e[r]===e[r-2],i=a?e[r]:e[r+1],l=Math.min(a?e[r-1]:e[r-2],a?e[r+1]:e[r]),n=Math.max(a?e[r-1]:e[r-2],a?e[r+1]:e[r]),s=a?this.level:this.upright;for(let e=0;e<s.length;e+=3)s[e]>l&&s[e]<n&&s[e+1]<i&&s[e+2]>i&&t++}return t}frame(e){this.frames[0].push(e.x,e.y,e.y+e.h,e.x+e.w,e.y,e.y+e.h),this.frames[1].push(e.y,e.x,e.x+e.w,e.y+e.h,e.x,e.x+e.w)}take(e){for(let t=2;t<e.length;t+=2)e[t]===e[t-2]?this.upright.push(e[t],Math.min(e[t-1],e[t+1]),Math.max(e[t-1],e[t+1])):e[t+1]===e[t-1]&&this.level.push(e[t+1],Math.min(e[t-2],e[t]),Math.max(e[t-2],e[t]))}ports(e,t,r,a,i){let l=this.taken.get(e)??[],n=[];for(let e=0;e<9&&n.length<4;e++){let s=r+(1&e?1:-1)*Math.ceil(e/2)*12;if(s<a||s>i)continue;let o=!0;for(let e=0;e<l.length;e+=2)l[e]===t&&Math.abs(l[e+1]-s)<12&&(o=!1);o&&n.push(s)}return n.length?n:[r]}claim(e,t,r){let a=this.taken.get(e);a?a.push(t,r):this.taken.set(e,[t,r])}};function Do(e,t,r){let a=e.length,i=Math.sign(e[2]-e[0]),l=Math.sign(e[3]-e[1]),n=`M${Oe(e[0]+i*t)},${Oe(e[1]+l*t)}`;for(let t=2;t<a-2;t+=2){let r=e[t],a=e[t+1],i=Math.sign(r-e[t-2]),l=Math.sign(a-e[t-1]),s=Math.sign(e[t+2]-r),o=Math.sign(e[t+3]-a),h=Math.min(8,Math.abs(r-e[t-2]+a-e[t-1])/2,Math.abs(e[t+2]-r+e[t+3]-a)/2);n+=`${i?"H"+Oe(r-i*h):"V"+Oe(a-l*h)}Q${Oe(r)},${Oe(a)} ${Oe(r+s*h)},${Oe(a+o*h)}`}let s=Math.sign(e[a-2]-e[a-4]),o=Math.sign(e[a-1]-e[a-3]);return n+(s?"H"+Oe(e[a-2]-s*r):"V"+Oe(e[a-1]-o*r))}function Ro(e,t,r,a){for(let i of t)if(i!==r&&i!==a&&So(e,i.x,i.y,i.x+i.w,i.y+i.h))return!1;return!0}function Lo(e,t,r,a,i){let l=e.length;return{d:Do(e,r,a),sx:e[0],sy:e[1],sdx:-Math.sign(e[2]-e[0]),sdy:-Math.sign(e[3]-e[1]),ex:e[l-2],ey:e[l-1],edx:Math.sign(e[l-2]-e[l-4]),edy:Math.sign(e[l-1]-e[l-3]),x0:e[t],y0:e[t+1],x1:e[t+2],y1:e[t+3],nx:0,ny:0,lean:0,room:ko,...i,points:e}}function Oo(e,t){let r=[],a=(e+t)/2,i=Math.max(7,(t-e)/4);for(let l=0;l<9;l++){let n=a+(1&l?1:-1)*Math.ceil(l/2)*i;n>=e+6&&n<=t-6&&r.push(n)}return r}function Fo(e,t,r,a,i,l,n){if(e===t){let t=Math.min(e.h/2-4,10),r=Math.hypot(vo,t),a=e.x+e.w,i=e.y+e.h/2,s=vo/r,o=t/r;return{d:`M${Oe(a+s*l)},${Oe(i-t-o*l)}C${Oe(a+vo)},${Oe(i-2*t)} ${Oe(a+vo)},${Oe(i+2*t)} ${Oe(a+s*n)},${Oe(i+t+o*n)}`,sx:a,sy:i-t,sdx:-s,sdy:o,ex:a,ey:i+t,edx:-s,edy:-o,x0:a+vo+4,y0:i,x1:a+vo+4,y1:i,nx:1,ny:0,lean:0,room:64,points:[]}}let[s,o,h,c]=function(e,t,r){let a=e.x+e.w/2,i=e.y+e.h/2,l=t.x+t.w/2,n=t.y+t.h/2,s=Io(e,t);if(s||Io(t,e)){let r=s?e:t,a=s?t:e,i=a.x+a.w/2,l=a.y+a.h/2,n=a.x-r.x,o=r.x+r.w-a.x-a.w,h=a.y-r.y,c=r.y+r.h-a.y-a.h,d=Math.min(n,o,h,c),f=d===n?r.x:d===o?r.x+r.w:i,u=d===n||d===o?l:d===c?r.y+r.h:r.y,p=Math.min(_o(a,f,u,i,l),1),g=f+(i-f)*p,m=u+(l-u)*p;return s?[f,u,g,m]:[g,m,f,u]}let o=a,h=i,c=l,d=n,f=Math.max(e.x,t.x),u=Math.min(e.x+e.w,t.x+t.w),p=Math.max(e.y,t.y),g=Math.min(e.y+e.h,t.y+t.h);f<u?o=c=(f+u)/2:p<g&&(h=d=(p+g)/2);let m=Math.hypot(c-o,d-h)||1,y=-(d-h)/m*r,x=(c-o)/m*r,w=_o(e,c+y,d+x,o+y,h+x),$=_o(t,o+y,h+x,c+y,d+x);return w<=1&&$<=1?(o+=y,h+=x,c+=y,d+=x):(o=a,h=i,c=l,d=n,w=Math.min(_o(e,c,d,o,h),1),$=Math.min(_o(t,o,h,c,d),1)),[c+(o-c)*w,d+(h-d)*w,o+(c-o)*$,h+(d-h)*$]}(e,t,r),d=s===h,f=!1;if(a&&!Io(e,t)&&!Io(t,e))for(let r of a)r!==e&&r!==t&&Co(r.x,r.y,r.x+r.w,r.y+r.h,s,o,h-s,c-o)<=1&&(f=!0);if(a&&f&&!d&&o!==c){let r=function(e,t,r,a,i,l){let n,s=e.x+e.w/2,o=e.y+e.h/2,h=t.x+t.w/2,c=t.y+t.h/2,d=(i,l,s)=>{if(!Ro(i,r,e,t))return;for(let e=2;e<i.length;e+=2){let t=i[e]===i[e-2];if(!a.free(t,t?i[e]:i[e+1],t?i[e-1]:i[e-2],t?i[e+1]:i[e]))return}let o=1e6*a.crossings(i);for(let e=2;e<i.length;e+=2)o+=Math.abs(i[e]-i[e-2])+Math.abs(i[e+1]-i[e-1]);(!n||o<n.cost)&&(n={points:i,cost:o,upright:l,sides:s})};if(e.x+e.w<=t.x||t.x+t.w<=e.x){let r=h>s,i=Math.sign(c-o),l=r?[1,0]:[0,1],f=Oo(r?e.x+e.w:t.x+t.w,r?t.x:e.x);e:for(let r of a.ports(e,l[0],o+i*e.h/4,e.y+8,e.y+e.h-8))for(let o of a.ports(t,l[1],c-i*t.h/4,t.y+8,t.y+t.h-8))for(let a of f){let i=a+(s-a)*Math.min(_o(e,a,r,s,r),1),c=a+(h-a)*Math.min(_o(t,a,o,h,o),1),f=n;if(d([i,r,a,r,a,o,c,o],!0,l),n!==f)break e}}if(e.y+e.h<=t.y||t.y+t.h<=e.y){let r=c>o,i=Math.sign(h-s),l=r?[3,2]:[2,3],f=Oo(r?e.y+e.h:t.y+t.h,r?t.y:e.y);e:for(let r of a.ports(e,l[0],s+i*e.w/4,e.x+8,e.x+e.w-8))for(let s of a.ports(t,l[1],h-i*t.w/4,t.x+8,t.x+t.w-8))for(let a of f){let i=a+(o-a)*Math.min(_o(e,r,a,r,o),1),h=a+(c-a)*Math.min(_o(t,s,a,s,c),1),f=n;if(d([r,i,r,a,s,a,s,h],!1,l),n!==f)break e}}if(!n)return;let{points:f,upright:u,sides:p}=n;return a.take(f),a.claim(e,p[0],u?f[1]:f[0]),a.claim(t,p[1],u?f[7]:f[6]),Lo(f,2,i,l,{room:u?88:ko})}(e,t,a,i,l,n);if(r)return r;i.squeezed++}if(a&&f&&(d||o===c)){let r=r=>{let i=r?-1/0:1/0,l=e=>{let t=d?e.x:e.y;i=r?Math.max(i,t+(d?e.w:e.h)):Math.min(i,t)};l(e),l(t);for(let r of a)r!==e&&r!==t&&Co(r.x,r.y,r.x+r.w,r.y+r.h,s,o,h-s,c-o)<=1&&l(r);return i},f=d?Math.min(e.y,t.y):Math.min(e.x,t.x),u=d?Math.max(e.y+e.h,t.y+t.h):Math.max(e.x+e.w,t.x+t.w),p=(r,i)=>{for(let l of a){if(l===e||l===t)continue;let a=d?l.y<u&&l.y+l.h>f:l.x<u&&l.x+l.w>f,n=d?l.x:l.y,s=n+(d?l.w:l.h);if(a&&(r?s>i:n<i))return!1}return!0},g=e.x+e.w/2,m=e.y+e.h/2,y=t.x+t.w/2,x=t.y+t.h/2,w=Math.sign(d?x-m:y-g),$=l=>{let n=r(l),s=l?1:-1,o=d?l?1:0:l?3:2,h=d?i.ports(e,o,m+w*e.h/4,e.y+8,e.y+e.h-8)[0]:i.ports(e,o,g+w*e.w/4,e.x+8,e.x+e.w-8)[0],c=d?i.ports(t,o,x-w*t.h/4,t.y+8,t.y+t.h-8)[0]:i.ports(t,o,y-w*t.w/4,t.x+8,t.x+t.w-8)[0],f=r=>{if(d){let a=r+(g-r)*Math.min(_o(e,r,h,g,h),1),i=r+(y-r)*Math.min(_o(t,r,c,y,c),1);return[a,h,r,h,r,c,i,c]}let a=r+(m-r)*Math.min(_o(e,h,r,h,m),1),i=r+(x-r)*Math.min(_o(t,c,r,c,x),1);return[h,a,h,r,c,r,c,i]},u=f(n+20*s);for(let r=0;r<=4;r++){let l=n+s*(20+7*r),p=f(l);if(Ro(p,a,e,t)&&(u=p,i.free(d,l,h,c)))return{points:u,side:o,p0:h,p1:c,step:r}}return{points:u,side:o,p0:h,p1:c,step:5}},b=d?c>o:h<s,M=p(b,r(b)),v=p(!b,r(!b)),k=$(b),A=M===v?$(!b):void 0,T=e=>8*i.crossings(e.points)+e.step,C=v&&!M||A&&T(A)<T(k)?!b:b,{points:E,side:_,p0:S,p1:I,step:N}=C===b?k:A??$(!b),D=C?1:-1;return N>4&&i.squeezed++,i.take(E),i.claim(e,_,S),i.claim(t,_,I),Lo(E,2,l,n,d?{nx:D,lean:30,room:88}:{room:ko})}let u=Math.hypot(h-s,c-o)||1,p=(h-s)/u,g=(c-o)/u;return(d||o===c)&&i.take([s,o,h,c]),{d:`M${Oe(s+p*l)},${Oe(o+g*l)}L${Oe(h-p*n)},${Oe(c-g*n)}`,sx:s,sy:o,sdx:-p,sdy:-g,ex:h,ey:c,edx:p,edy:g,x0:s,y0:o,x1:h,y1:c,nx:r?-g:0,ny:r?p:0,lean:0,room:Math.abs(p)>Math.abs(g)?88:ko,points:[s,o,h,c]}}var zo=new Map([["person","person"],["box","rect"],["rounded","rect"],["component","rect"],["cylinder","cyl"],["database","cyl"],["db","cyl"],["queue","h-cyl"],["pipe","h-cyl"]]);function Wo(e,t,r,a,i=216){let l=function(e){let t=zo.get((e.shape??"").toLowerCase())??zo.get((e.sprite??"").toLowerCase());if(t)return t;if(e.tags)for(let t of e.tags.split(",")){let e=zo.get(t.trim().toLowerCase());if(e)return e}let r=e.kind;return r.endsWith("person")?"person":r.endsWith("_db")?"cyl":r.endsWith("_queue")?"h-cyl":"rect"}(e),n="h-cyl"===l?36:0,s="person"===l?26:"cyl"===l?24:0,o=i-28-n,h=[Fl("«"+e.kind.replace(/_/g," ")+"»",!1,t,a-1,o),Fl(e.label,!1,t,r,o,1),Fl(e.techn?`[${e.techn}]`:void 0,!1,t,a,o),Fl(e.descr,!1,t,a,o)],c=0,d=h[3].height>0?4:0;for(let e of h)c=Math.max(c,e.width),d+=e.height;return{shape:e,form:l,labels:h,textH:d,x:0,y:0,w:Math.max(i,c+28+n),h:Math.max(64,d+24+s)}}function Po(e,t,r,a,i){let l=0,n=0;for(let s=0;s<e.length;s+=t){let o=Math.min(e.length,s+t),h=0,c=0;for(let t=s;t<o;t++)c=Math.max(c,e[t].h);for(let t=s;t<o;t++){let a=e[t];a.x=h,a.y=n,i&&(a.h=c),h+=a.w+r}l=Math.max(l,h-r),n+=c+a}return[l,e.length>0?n-a:0]}var Bo=[.5,.4,.6,.3,.7,.2,.8];function Ho(e,t,r){let a=[];return e&&a.push("fill:"+e),t&&a.push("stroke:"+t),r&&a.push("color:"+r),Ri(a)}function Yo(e,t,r,a,i){return t?Mr(e,cr(t.includes("¶ß")?t.replace(/\ufb02\u00b0\u00b0?/g,"#").replace(/\u00b6\u00df/g,";"):t),r,a,i):e}function Go(e,t,r,a,l=36){let n=r.fontSize??16,s=Math.round(.8125*n),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=[],{order:d,boxes:f}=function(e,t,r,a,i,l){let n=void 0===i?28:12,s=new Map;for(let l of e.boundaries){let e=void 0===i?4e3:Math.max(80,i-32-112),o=l.parent?[Fl(l.label,!1,t,r,e,1),Fl(l.type?`[${l.type}]`:void 0,!1,t,a,e),Fl(l.descr,!1,t,a,e)]:[],h=0,c=0;for(let e of o)h+=e.height,c=Math.max(c,e.width);s.set(l,{boundary:l,kids:[],nodes:[],labels:o,head:h>0?h+10+6+20:n,headW:c,headX:16,x:0,y:0,w:0,h:0,form:"rect"})}let o=s.get(e.boundaries[0]);for(let e of s.values()){let t=e.boundary.parent;t&&s.get(t)?.kids.push(e)}let h=[o],c=new Map([[o.boundary,0]]);for(let e=0;e<h.length;e++)for(let t of h[e].kids)c.set(t.boundary,c.get(h[e].boundary)+1),h.push(t);for(let l of e.shapes)if(l.parent){let e=c.get(l.parent)??0,o=void 0===i?216:Math.max(100,Math.min(216,i-2*e*n-32));s.get(l.parent)?.nodes.push(Wo(l,t,r,a,o))}let d=Math.max(1,e.shapeInRow),f=Math.max(1,e.boundaryInRow),u=new Map;for(let e=h.length-1;e>=0;e--){let t=h[e],r=void 0===i?120:l,a=(e,t,r)=>{if(void 0===i)return t;let a=1;for(let t of e)a=Math.max(a,t.w);return Math.max(1,Math.min(t,Math.floor((i+r-2*n)/(a+r))))},[s,c]=Po(t.nodes,a(t.nodes,d,r),r,88,!0),[p,g]=Po(t.kids,a(t.kids,f,48),48,48,!1),m=c>0&&g>0?48:0,y=t===o?0:n;u.set(t,c+m),t.w=Math.max(s,p,t.headW+32-2*y)+2*y,t.h=(y&&t.head)+c+m+g+y}let p=new Map;for(let e of h){let t=e.x+(e===o?0:n),r=e.y+(e===o?0:e.head);for(let a of e.nodes)a.x+=t,a.y+=r,p.set(a.shape,a);for(let a of e.kids)a.x+=t,a.y+=r+u.get(e);e!==o&&p.set(e.boundary,e)}return{order:h,boxes:p}}(e,o,n,s,a?Math.max(80,(r.maxWidth??320)-2*h):void 0,l),u=d[0],p=0,g=0,m=u.w,y=u.h,x=(e,t,r,a)=>{p=Math.min(p,e),g=Math.min(g,t),m=Math.max(m,r),y=Math.max(y,a)},w=[],$=new Map;for(let t of e.rels){let r=t.fromAttr?void 0:e.getC4Shape(t.from),a=t.toAttr?void 0:e.getC4Shape(t.to),l=r&&f.get(r),n=a&&f.get(a);if(!l||!n)throw new i(`C4 rel "${t.from}" -> "${t.to}" references an unknown shape or boundary`,"semantic",{type:"c4"});w.push(l,n);let s=$.get(l);s||$.set(l,s=new Set),s.add(n)}let b=[],M=[];for(let e of d)for(let t of e.nodes)b.push(t),M.push(t.x+8,t.y+8,t.x+t.w-8,t.y+t.h-8);let v=e.rels.length*(b.length+d.length+3*e.rels.length)<=2e6,k=(e,t,r,a)=>{let i=0;for(let l=0;l<M.length;l+=4){let n=Math.min(r,M[l+2])-Math.max(e,M[l]);if(n<=0)continue;let s=Math.min(a,M[l+3])-Math.max(t,M[l+1]);s>0&&(i+=n*s)}return i},A=e=>e?Math.max(-2e3,Math.min(2e3,e)):0,T="",C="",E=ii("arrow_point"),_=[];for(let e of d){if(e===u)continue;let t=Ho(e.boundary.bgColor,void 0,void 0).shape;yt(t)&&_.push({box:[e.x,e.y,e.x+e.w,e.y+e.h],shape:t})}let S=new No;for(let e of d)e!==u&&S.frame(e);let I=e.rels.map((e,t)=>{let r=w[2*t],a=w[2*t+1],i=Ho(void 0,e.lineColor,void 0),l="birel"===e.type||"rel_b"===e.type,n="rel_b"!==e.type,s=Fo(r,a,r!==a&&!0===$.get(a)?.has(r)?7:0,v?b:void 0,S,l?E:0,n?E:0);x(Math.min(s.x0,s.x1),Math.min(s.y0,s.y1),Math.max(s.x0,s.x1),Math.max(s.y0,s.y1)),l&&v&&M.push(s.sx-8,s.sy-8,s.sx+8,s.sy+8),n&&v&&M.push(s.ex-8,s.ey-8,s.ex+8,s.ey+8);let o=gi(s.d,[s.sx,s.sy,s.ex,s.ey],_,i.line),h=o||(i.stroke?De(i.stroke):"var(--_l)");return""===o&&(T+=yi(s,l?"arrow_point":"none",n?"arrow_point":"none",i.line)),C+=`<g class="pele-edge" data-id="${Re(e.from+"-"+e.to)}"${o?` stroke="${o}"`:""}${i.line}><path d="${s.d}"/>`+(l?li("arrow_point",s.sx,s.sy,s.sdx,s.sdy,h):"")+(n?li("arrow_point",s.ex,s.ey,s.edx,s.edy,h):"")+"</g>",s});for(let e of d){if(!v||0===e.headW)continue;let t=e.y+10,r=e.y+e.head-20,a=1/0;for(let i of[16,(e.w-e.headW)/2,e.w-16-e.headW]){let l=0;for(let a of I)So(a.points,e.x+i-4,t,e.x+i+e.headW+4,r)&&l++;if(l<a&&(a=l,e.headX=i),0===l)break}M.push(e.x+e.headX-4,t,e.x+e.headX+e.headW+4,r)}let N="";e.rels.forEach((t,i)=>{let l=I[i],n=t.from+"-"+t.to,h=Ho(void 0,void 0,t.textColor),d=Fl(("C4Dynamic"===e.c4Type?i+1+": ":"")+t.label,!1,o,s,l.room),f=Fl(t.techn?`[${t.techn}]`:void 0,!1,o,s,l.room,2),u=Math.max(d.width,f.width)+8,p=d.height+f.height;if(0===p)return;let g=Math.abs(l.nx)*(u/2)+Math.abs(l.ny)*(p/2)+2,m=l.lean?Math.max(0,Math.min(l.lean,g-14)):g,y=l.nx*m+(a?0:A(t.offsetX)),w=l.ny*m+(a?0:A(t.offsetY)),$=.5;if(v){let e=1/0,t=y!==l.nx*m||w!==l.ny*m;for(let r=0;r<(t?2:1)&&e>0;r++){let t=r?l.nx*m:y,a=r?l.ny*m:w;for(let r of Bo){let i=l.x0+(l.x1-l.x0)*r+t,n=l.y0+(l.y1-l.y0)*r+a,s=k(i-u/2,n-p/2,i+u/2,n+p/2);if(s<e&&(e=s,$=r,y=t,w=a),0===s)break}}}let b=l.x0+(l.x1-l.x0)*$+y,T=l.y0+(l.y1-l.y0)*$+w-p/2;v&&M.push(b-u/2,T,b+u/2,T+p),x(b-u/2,T,b+u/2,T+p),N+=`<g class="pele-edge-label" data-id="${Re(n)}">`+(t.descr?`<title>${Re(t.descr)}</title>`:"")+`<rect x="${Oe(b-u/2)}" y="${Oe(T)}" width="${Oe(u)}" height="${Oe(p)}" rx="3" fill="var(--_bg)"/>`+Yo(Fe(d,b,T+d.height/2,h.text)+Fe(f,b,T+d.height+f.height/2,` class="pele-c4-techn" fill="var(--_m)"${h.text}`),t.link,n,c,r)+"</g>"});let D="",R="";for(let e of d){if(e!==u){let t=e.boundary,a=Ho(t.bgColor,t.borderColor,t.fontColor),i=e.x+e.headX,l=e.y+10,n=xt(a)+a.text,o=xt(a,"var(--_m)")+a.text,h=Mo(e.labels[0],i,l,` class="pele-cluster-label" font-weight="var(--_hw)"${n}`);l+=e.labels[0].height,h+=Mo(e.labels[1],i,l,` class="pele-c4-type" font-size="${s}"${o}`),l+=e.labels[1].height,h+=Mo(e.labels[2],i,l,` class="pele-c4-descr" font-size="${s}"${o}`),D+=`<g class="pele-cluster pele-c4-${t.nodeType?"node":"boundary"}" data-id="${Re(t.alias)}"><rect x="${Oe(e.x)}" y="${Oe(e.y)}" width="${Oe(e.w)}" height="${Oe(e.h)}" fill="none" stroke="var(--_b)"${t.nodeType?"":' stroke-dasharray="6 4"'}${Ai(a.shape)}/>`+Yo(h,t.link,t.alias,c,r)+"</g>"}for(let t of e.nodes){let e=t.shape,a=e.kind.startsWith("external"),i=Ho(e.bgColor,e.borderColor,e.fontColor),l=' stroke="var(--_b)"'+(a?' stroke-dasharray="4 3"':""),{w:n,h:o,form:h,labels:d}=t,f="h-cyl"===h?-To(o)/2:0,u="person"===h?13:"cyl"===h?Ao(n)/2:0,p=xt(i)+i.text,g=xt(i,"var(--_m)")+i.text,m=u-t.textH/2,y=Fe(d[0],f,m+d[0].height/2,` class="pele-c4-type" font-size="${s-1}"${g}`);m+=d[0].height,y+=Fe(d[1],f,m+d[1].height/2,` class="pele-label" font-weight="var(--_hw)"${p}`),m+=d[1].height,y+=Fe(d[2],f,m+d[2].height/2,` class="pele-c4-techn" font-size="${s}"${g}`),m+=d[2].height+4,y+=Fe(d[3],f,m+d[3].height/2,` class="pele-c4-descr" font-size="${s}"${p}`),R+=`<g class="pele-node pele-shape-${h} pele-c4-${e.kind}${a?" pele-c4-external":""}" data-id="${Re(e.alias)}" transform="translate(${Oe(t.x+n/2)},${Oe(t.y+o/2)})">`+Yo(ol(h,n,o,` fill="var(${a?"--_bg":"--_s"})"${l}${i.shape}`,l+i.line)+y,e.link,e.alias,c,r)+"</g>"}}let L=Fl(e.title,!1,o,n,a?Gl(r):4e3,1),O=L.height>0?L.height+12:0,F=Math.max(m-p,L.width),z=Math.ceil(F+2*h),W=Math.ceil(y-g+O+2*h),P=h-p+(F-(m-p))/2,B=h+O-g;return[{svg:Bi("c4",z,W,n,r,e,Fe(L,z/2,h+L.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe(P)},${Oe(B)})">`+(D?`<g class="pele-clusters">${D}</g>`:"")+xi(T)+(C?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${C}</g>`:"")+(R?`<g class="pele-nodes">${R}</g>`:"")+(N?`<g class="pele-edge-labels" font-size="${s}">${N}</g>`:"")+"</g>"),width:z,height:W,links:c},S.squeezed]}var Uo={type:"c4",parse(e,t,r){let a=new no;return r&&(a.title=r),xo(e,a),a},render:function(e,t,r){return Vl(r,a=>{if(!a)return Go(e,t,r,!1)[0];let[i,l]=Go(e,t,r,!0,36);for(let a=60;l>0&&a<=108;a+=24){let[n,s]=Go(e,t,r,!0,a);s<l&&([i,l]=[n,s])}return i})}};function qo(e){let t=0;for(let r=e.indexOf("~");-1!==r;r=e.indexOf("~",r+1))t++;return t}function jo(e){let t=qo(e);if(t<=1)return e;let r=t%2!=0&&e.startsWith("~"),a=e.split(""),i=[];for(let e=r?1:0;e<a.length;e++)"~"===a[e]&&i.push(e);for(let e=0,t=i.length-1;e<t;e++,t--)a[i[e]]="<",a[i[t]]=">";return a.join("")}function Vo(e){if(!e.includes("~"))return e;let t=e.split(/(,)/),r=[];for(let e=0;e<t.length;e++){let a=t[e];","===a&&e>0&&e+1<t.length&&1===qo(t[e-1])&&1===qo(t[e+1])&&(a=t[e-1]+","+t[e+1],e++,r.pop()),r.push(jo(a))}return r.join("")}function Xo(e){return"#"===e||"+"===e||"~"===e||"-"===e}var Ko=class{id="";memberType;visibility="";classifier="";parameters="";returnType="";constructor(e,t){this.memberType=t,("method"!==t||!this.parseMethod(e))&&this.parseAttribute(e),this.id=this.id.startsWith(" ")?" "+this.id.trim():this.id.trim()}parseMethod(e){let t=e.length;for(let r=0;r<t;){let a=r;for(;a<t&&!V(e.charCodeAt(a));)a++;let i=a-1;for(;i>r&&41!==e.charCodeAt(i);)i--;let l=i-1;for(;l>r&&40!==e.charCodeAt(l);)l--;if(l>r){let a=e[r],n=Xo(a)&&l>r+1;n&&(this.visibility=a),this.id=e.slice(n?r+1:r,l),this.parameters=e.slice(l+1,i).trim();let s=i+1,o="";if(s<t){let t=e[s];("$"===t||"*"===t||""===t.trim())&&(o=t.trim(),s++)}let h=s;for(;h<t&&!V(e.charCodeAt(h));)h++;if(this.returnType=e.slice(s,h).trim(),""===o){let e=this.returnType.slice(-1);("$"===e||"*"===e)&&(o=e,this.returnType=this.returnType.slice(0,-1))}return this.classifier=o,!0}r=a+1}return this.memberType="attribute",!1}parseAttribute(e){let t=e.slice(0,1),r=e.slice(-1);Xo(t)&&(this.visibility=t),("$"===r||"*"===r)&&(this.classifier=r),this.id=e.substring(""===this.visibility?0:1,""===this.classifier?e.length:e.length-1)}getDisplayDetails(){let e=this.visibility+Vo(this.id);return"method"===this.memberType&&(e+=`(${Vo(this.parameters.trim())})`,this.returnType&&(e+=" : "+Vo(this.returnType))),{displayText:e.trim(),cssStyle:this.parseClassifier()}}parseClassifier(){return"*"===this.classifier?"font-style:italic;":"$"===this.classifier?"text-decoration:underline;":""}},Zo={LINE:0,DOTTED_LINE:1},Qo={AGGREGATION:0,EXTENSION:1,COMPOSITION:2,DEPENDENCY:3,LOLLIPOP:4};function Jo(e){let t=e.indexOf("~");if(t<=0)return{className:e,type:""};let r=e.indexOf("~",t+1);return{className:e.slice(0,t),type:e.slice(t+1,-1===r?e.length:r)}}function eh(e){let t=e.charCodeAt(0);return Jo(t>=48&&t<=57?"classId-"+e:e).className}var th=class{type="class";lineType=Zo;relationType=Qo;direction="TB";classes=new Map;relations=[];notes=new Map;namespaces=new Map;interfaces=[];styleClasses=new Map;title;accTitle;accDescr;namespaceStack=[];withCssClass=new Map;addClass(e){let{className:t,type:r}=Jo(e);if(this.classes.has(t))return;let a={id:t,type:r,label:t,cssClasses:"default",methods:[],members:[],annotations:[],styles:[]};this.classes.set(t,a),this.tag(a,"default")}tag(e,t){let r=this.withCssClass.get(t);r?r.add(e):this.withCssClass.set(t,new Set([e]))}ensure(e){return this.addClass(e),this.classes.get(Jo(e).className)}setClassLabel(e,t){this.ensure(e).label=t}addRelation(e){let{type1:t,type2:r}=e.relation;t===Qo.LOLLIPOP&&"none"===r?(this.addClass(e.id2),e.id1=this.addInterface(e.id1,e.id2)):r===Qo.LOLLIPOP&&"none"===t?(this.addClass(e.id1),e.id2=this.addInterface(e.id2,e.id1)):(this.addClass(e.id1),this.addClass(e.id2)),e.id1=Jo(e.id1).className,e.id2=Jo(e.id2).className,e.relationTitle1=e.relationTitle1.trim(),e.relationTitle2=e.relationTitle2.trim(),this.relations.push(e)}addInterface(e,t){let r=`interface${this.interfaces.length}`;return this.interfaces.push({id:r,label:e,classId:t}),r}addAnnotation(e,t){this.ensure(e).annotations.push(t)}addMember(e,t){let r=this.ensure(e);if("string"!=typeof t)return;let a=t.trim();if(a.startsWith("<<")&&a.endsWith(">>"))r.annotations.push(a.substring(2,a.length-2));else if(a.indexOf(")")>0){let e=new Ko(a,"method");("method"===e.memberType?r.methods:r.members).push(e)}else a&&r.members.push(new Ko(a,"attribute"))}addMembers(e,t){if(Array.isArray(t)){t.reverse();for(let r of t)this.addMember(e,r)}}addNote(e,t){let r=this.notes.size,a=`note${r}`;return this.notes.set(a,{id:a,class:t,text:e,index:r}),a}cleanupLabel(e){return(e.startsWith(":")?e.substring(1):e).trim()}setCssClass(e,t){for(let r of e.split(",")){let e=this.classes.get(eh(r));if(void 0!==e){e.cssClasses+=" "+t;for(let r of t.split(" "))this.tag(e,r)}}}defineClass(e,t){for(let r of e){let e=this.styleClasses.get(r);if(void 0===e&&(e={id:r,styles:[],textStyles:[]},this.styleClasses.set(r,e)),!t)continue;for(let r of t)r.includes("color")&&e.textStyles.push(r.replace("fill","bgFill")),e.styles.push(r);let a=this.withCssClass.get(r);if(void 0===a)continue;let i=t.flatMap(e=>e.split(","));for(let e of a)for(let t of i)e.styles.push(t)}}setTooltip(e,t){if(void 0!==t)for(let r of e.split(",")){let e=this.classes.get(Jo(r).className);e&&(e.tooltip=t)}}setLink(e,t,r){let a=m(t).trim();for(let t of e.split(",")){let e=this.classes.get(eh(t));e&&(e.link=a?cr(a):void 0,e.linkTarget="string"==typeof r?r:"_blank")}this.setCssClass(e,"clickable")}setClickEvent(e,t,r){for(let t of e.split(",")){let e=this.classes.get(Jo(t).className);e&&(e.haveCallback=!0)}this.setCssClass(e,"clickable")}setDirection(e){this.direction=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addNamespace(e,t){let r=this.namespaceStack[this.namespaceStack.length-1],a=r?`${r}.${e}`:e;this.namespaceStack.push(a);let i=this.namespaces.get(a);if(i)return i.explicit=!0,t&&(i.label=t),a;let l=r||void 0,n=r?r.length+1:0;for(;;){let e=a.indexOf(".",n),r=-1===e,i=r?a:a.slice(0,e),s=this.namespaces.get(i);if(void 0===s){let o=a.slice(n,r?a.length:e);s={id:i,label:r&&t?t:o,classes:new Map,notes:new Map,children:new Map,parent:l,explicit:r},this.namespaces.set(i,s)}else r&&(s.explicit=!0);let o=l?this.namespaces.get(l):void 0;if(o&&(o.children.has(i)||o.children.set(i,s),s.parent??=l),r)return a;l=i,n=e+1}}popNamespace(){this.namespaceStack.pop()}addClassesToNamespace(e,t,r){let a=this.namespaces.get(e);if(void 0!==a){for(let r of t){let{className:t}=Jo(r),i=this.classes.get(t);void 0!==i&&(i.parent=e,a.classes.set(t,i))}for(let t of r){let r=this.notes.get(t);void 0!==r&&(r.parent=e,a.notes.set(t,r))}}}setCssStyle(e,t){let r=this.classes.get(e);if(t&&r)for(let e of t)for(let t of e.split(","))r.styles.push(t)}},rh=["$end","INVALID","CLASS_DIAGRAM","NEWLINE","EOF","SQS","STR","SQE","DOT","GENERICTYPE","LABEL","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","STRUCT_START","STRUCT_STOP","NAMESPACE","STYLE_SEPARATOR","ANNOTATION_START","ANNOTATION_END","CLASS","MEMBER","NOTE_FOR","NOTE","CLASSDEF","ALPHA","COMMA","direction_tb","direction_bt","direction_rl","direction_lr","AGGREGATION","EXTENSION","COMPOSITION","DEPENDENCY","LOLLIPOP","LINE","DOTTED_LINE","CALLBACK","LINK","LINK_TARGET","CLICK","CALLBACK_NAME","CALLBACK_ARGS","HREF","STYLE","CSSCLASS","COLON","BRKT","PCT","MINUS","UNICODE_TEXT","BQUOTE_STR","EDGE_STATE","EOF_IN_STRUCT","OPEN_IN_STRUCT","PLUS","EQUALS","PUNCTUATION"],ah=[4,6,4,9,44,45,12,14,15,4,56,4,56],ih=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y],lh=/[\n\r\u2028\u2029]/g;function nh(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=e.indexOf("direction"),h=-1,c=0,d=(t,l,n)=>(r.push(t),a.push(e.slice(l,n)),i.push(l),s=n,!0),f=e=>{l.push(n),n=e},u=()=>{l.length>0&&(n=l.pop())},p=t=>e.startsWith(t,s)&&!Q(e.charCodeAt(s+t.length)),g=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},m=r=>{let a=e.indexOf(r,s);return-1===a?t:a},y=r=>{let a=s,i=-1;for(let r=e.charCodeAt(a);a<t&&q(r);r=e.charCodeAt(++a))10===r&&(i=a);i<0?s=a:(r&&u(),d(3,s,i+1))},x=t=>{switch(t){case 99:if(p("cssClass"))return d(48,s,s+8);if(p("callback"))return d(40,s,s+8);if(p("click"))return d(43,s,s+5);break;case 108:if(p("link"))return d(41,s,s+4);break;case 110:if(p("note for"))return d(24,s,s+8);if(p("note"))return d(25,s,s+4);break;case 60:if(60===e.charCodeAt(s+1))return d(20,s,s+2);break;case 62:if(62===e.charCodeAt(s+1))return d(21,s,s+2);break;case 104:if(p("href"))return d(46,s,s+4)}return!1},w=r=>{if(x(r))return!0;let a=e.charCodeAt(s+1);switch(r){case 34:return f(1),s++,!0;case 126:return f(3),s++,!0;case 96:return f(2),s++,!0;case 95:if(p("_self"))return d(42,s,s+5);if(p("_blank"))return d(42,s,s+6);if(p("_parent"))return d(42,s,s+7);if(p("_top"))return d(42,s,s+4);break;case 60:return 124===a?d(34,s,s+2):d(36,s,s+1);case 124:return 62===a&&d(34,s,s+2);case 62:return d(36,s,s+1);case 42:return d(35,s,s+1);case 111:if(!Q(a))return d(33,s,s+1);break;case 40:return 41===a&&d(37,s,s+2);case 45:return 45===a?d(38,s,s+2):d(52,s,s+1);case 46:return 46===a?d(39,s,s+2):d(8,s,s+1);case 58:{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(58===t||10===t||59===t)break;r++}return r>s+1?d(10,s,r):58===a&&58===e.charCodeAt(s+2)&&d(19,s,s+3)}case 43:return d(58,s,s+1);case 37:return d(51,s,s+1);case 61:return d(59,s,s+1);case 91:return d(5,s,s+1);case 93:return d(7,s,s+1);case 33:case 35:case 36:case 38:case 39:case 44:case 63:case 92:case 47:return d(60,s,s+1)}if(Q(r)){let t=s+1;for(;Q(e.charCodeAt(t));)t++;return d(27,s,t)}return Ur(r)&&d(53,s,s+1)},$=r=>{if((()=>{if(-1===o||s<c||(o<s&&(o=e.indexOf("direction",s)),-1===o)||(h<s&&(lh.lastIndex=s,h=lh.test(e)?lh.lastIndex-1:t),o>=h))return!1;for(let t=0;t<4;t++){let r=ih[t];if(r.lastIndex=s,r.test(e))return d(29+t,s,r.lastIndex)}return c=h,!1})())return!0;if(q(r))return y(!1),!0;switch(r){case 37:if(37===e.charCodeAt(s+1)){let r=m("\n");for(;r<t&&(10===e.charCodeAt(r)||13===e.charCodeAt(r));)r++;return s=r,!0}break;case 97:{let t=e.startsWith("accTitle",s);if(!t&&!e.startsWith("accDescr",s))break;let r=g(s+8),a=e.charCodeAt(r);if(58===a)return d(t?11:13,s,g(r+1)),f(t?6:7),!0;if(123===a&&!t)return s=g(r+1),f(8),!0;break}case 99:if(p("classDiagram-v2"))return d(2,s,s+15);if(p("classDiagram"))return d(2,s,s+12);if(e.startsWith("call",s)&&q(e.charCodeAt(s+4)))return s=g(s+4),f(4),!0;if(p("classDef"))return d(26,s,s+8);if(p("class"))return f(9),d(22,s,s+5);break;case 91:if(e.startsWith("*]",s+1))return d(55,s,s+3);break;case 115:if(p("style"))return d(47,s,s+5);break;case 110:if(p("namespace"))return f(11),d(18,s,s+9);break;case 44:return d(28,s,s+1);case 35:return d(50,s,s+1)}return w(r)||58===r&&d(49,s,s+1)};for(;;){if(s>=t){r.push(ah[n]),a.push(""),i.push(t);break}let l=e.charCodeAt(s),o=!0;switch(n){case 0:o=$(l);break;case 9:q(l)?y(!0):125===l?(u(),u(),d(17,s,s+1)):123===l?(f(10),d(16,s,s+1)):o=w(l);break;case 10:if(34===l)f(1),s++;else if(125===l)u(),d(17,s,s+1);else if(91===l&&e.startsWith("*]",s+1))d(55,s,s+3);else if(123===l)d(57,s,s+1);else if(10===l)s++;else{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(123===t||125===t||10===t)break;r++}d(23,s,r)}break;case 11:q(l)?y(!0):123===l?(f(12),d(16,s,s+1)):125===l?u():110===l&&p("namespace")?(f(11),d(18,s,s+9)):o=w(l);break;case 12:q(l)?y(!1):125===l?(u(),d(17,s,s+1)):110===l&&p("namespace")?(f(11),d(18,s,s+9)):91===l&&e.startsWith("*]",s+1)?d(55,s,s+3):99===l&&p("class")?(f(9),d(22,s,s+5)):o=w(l);break;case 1:34===l?(u(),s++):d(6,s,m('"'));break;case 3:if(34===l)f(1),s++;else{if(x(l))break;126===l?(u(),s++):d(9,s,m("~"))}break;case 2:if(34===l)f(1),s++;else{if(x(l))break;126===l?(f(3),s++):96===l?(u(),s++):d(54,s,m("`"))}break;case 4:if(40===l){let t=g(s+1);u(),41===e.charCodeAt(t)?s=t+1:(f(5),s++)}else d(44,s,m("("));break;case 5:41===l?(u(),s++):d(45,s,m(")"));break;case 6:case 7:d(6===n?12:14,s,m("\n")),u();break;case 8:125===l?(u(),s++):d(15,s,m("}"))}if(!o)return r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}}return r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}var sh=new Uint8Array(61);for(let e of[53,27,52])sh[e]=1;var oh=new Uint8Array(61);for(let e of[27,49,50,47,51,10])oh[e]=1;var hh=new Uint8Array(61);hh[33]=1,hh[34]=2,hh[35]=3,hh[36]=4,hh[37]=5;function ch(e,t){let{types:r,texts:a,starts:i}=nh(e),l=0,n=t=>{let a=r[l];throw 1===a?c("class",e,i[l],"",!0):c("class",e,i[l],`Expecting ${t}, got '${rh[a]}'`)},s=e=>(r[l]!==e&&n(`'${rh[e]}'`),a[l++]),o=()=>(0===sh[r[l]]&&n("'UNICODE_TEXT', 'NUM', 'ALPHA', 'MINUS'"),a[l++]),h=e=>{let t="";for(;;){if(54===r[l]){t+=a[l++];break}0===sh[r[l]]&&n("'UNICODE_TEXT', 'NUM', 'ALPHA', 'MINUS', 'BQUOTE_STR'"),t+=a[l++];let e=r[l];if(8===e)t+=".",l++;else if(0===sh[e]&&54!==e)break}return e&&9===r[l]&&(t+="~"+a[l++]+"~"),t},d=()=>{l++;let e=s(6);return s(7),e},f=()=>{23!==r[l]&&n("'STRUCT_STOP', 'MEMBER'");let e=[];for(;23===r[l];)e.push(a[l++]);return s(17),e.reverse()},u=()=>{l++;let e=h(!0);switch(t.addClass(e),5===r[l]&&t.setClassLabel(e,d()),r[l]){case 19:{l++;let a=o();t.setCssClass(e,a),16===r[l]&&(l++,t.addMembers(e,f()));break}case 16:l++,17===r[l]?l++:t.addMembers(e,f());break;case 20:{l++;let a=o();s(21),t.addAnnotation(e,a),16===r[l]&&(l++,17===r[l]?l++:t.addMembers(e,f()));break}}return e},p=()=>{if(25===r[l++])return t.addNote(s(6));let e=h(!0);return t.addNote(s(6),e)},g=()=>{let e=hh[r[l]];return 0===e?"none":(l++,e-1)},m=()=>{let e=[];for(;;){0===oh[r[l]]&&n("'ALPHA', 'NUM', 'COLON', 'UNIT', 'SPACE', 'BRKT', 'STYLE', 'PCT', 'LABEL'");let t=a[l++];for(;1===oh[r[l]];)t+=a[l++];if(e.push(t),28!==r[l])return e;l++}},y=e=>{6===r[l]&&t.setTooltip(e,a[l++])},x=e=>{let i=s(6),n=6===r[l]?a[l++]:void 0;42===r[l]?t.setLink(e,i,a[l++]):t.setLink(e,i),void 0!==n&&t.setTooltip(e,n)},w=()=>{let e=r[l];switch(e){case 53:case 27:case 52:case 54:return void(()=>{let e=h(!0),i=r[l];if(10===i)return void t.addMember(e,t.cleanupLabel(a[l++]));let s="none";if(6===i)s=a[l++],i=r[l];else if(0===hh[i]&&38!==i&&39!==i)return;let o=g();i=r[l],38!==i&&39!==i&&n("'AGGREGATION', 'EXTENSION', 'COMPOSITION', 'DEPENDENCY', 'LOLLIPOP', 'LINE', 'DOTTED_LINE'"),l++;let c=g(),d=6===r[l]?a[l++]:"none",f={id1:e,id2:h(!0),relation:{type1:o,type2:c,lineType:38===i?0:1},relationTitle1:s,relationTitle2:d};10===r[l]&&(f.title=t.cleanupLabel(a[l++])),t.addRelation(f)})();case 18:return void(()=>{let e=[];for(;;){l++;let a=h(!1),i=5===r[l]?t.addNamespace(a,d()):t.addNamespace(a);s(16),3===r[l]&&l++,e.push({id:i,classes:[],notes:[]});let o=!0;for(;o;){let a=e[e.length-1],i=r[l];if(18===i)break;for(22===i?a.classes.push(u()):25===i||24===i?a.notes.push(p()):n("'NAMESPACE', 'CLASS', 'NOTE_FOR', 'NOTE'");;){if(3===r[l]){let e=r[l+1];if(18===e||22===e||25===e||24===e){l++;break}l++}s(17);let a=e.pop();if(t.addClassesToNamespace(a.id,a.classes,a.notes),t.popNamespace(),0===e.length){o=!1;break}}}if(0===e.length)return}})();case 22:return void u();case 23:return void l++;case 20:{l++;let e=o();return s(21),void t.addAnnotation(h(!0),e)}case 40:{l++;let e=h(!0);return t.setClickEvent(e,s(6)),void y(e)}case 41:return l++,void x(h(!0));case 43:{l++;let e=h(!0);if(46===r[l])return l++,void x(e);let i=s(44);return 45===r[l]?t.setClickEvent(e,i,a[l++]):t.setClickEvent(e,i),void y(e)}case 47:{l++;let e=s(27);return void t.setCssStyle(e,m())}case 48:{l++;let e=s(6);return void t.setCssClass(e,s(27))}case 25:case 24:return void p();case 26:{l++;let e=[s(27)];for(;28===r[l];)l++,e.push(s(27));return void t.defineClass(e,m())}case 29:case 30:case 31:case 32:return l++,void t.setDirection(29===e?"TB":30===e?"BT":31===e?"RL":"LR");case 11:return l++,void t.setAccTitle(s(12).trim());case 13:return l++,void t.setAccDescription(s(14).trim());case 15:return void t.setAccDescription(a[l++].trim())}n("'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'NAMESPACE', 'ANNOTATION_START', 'CLASS', 'MEMBER', 'NOTE_FOR', 'NOTE', 'CLASSDEF', 'direction_tb', 'CALLBACK', 'LINK', 'CLICK', 'STYLE', 'CSSCLASS', 'ALPHA', 'MINUS', 'BQUOTE_STR'")},$=2===r[l];for($&&(l++,s(3));w(),3===r[l]&&(l++,4!==r[l]&&0!==r[l]););$&&s(4),s(0)}var dh=["aggregation","extension","composition","dependency","lollipop"];function fh(e){return"number"==typeof e&&dh[e]||"none"}function uh(e){switch(e){case"extension":return 12;case"composition":case"aggregation":return 16;case"lollipop":return 10;case"dependency":return ii("arrow_point")}return 0}function ph(e,t,r,a,i,l){let n=-i,s=a;switch(e){case"extension":{let e=t-12*a,l=r-12*i;return`<path class="pele-marker" d="M${Oe(t)},${Oe(r)}L${Oe(e+6*n)},${Oe(l+6*s)}L${Oe(e-6*n)},${Oe(l-6*s)}Z" stroke-linejoin="round"/>`}case"composition":case"aggregation":{let o=t-16*a/2,h=r-16*i/2,c=5;return`<path class="pele-marker" d="M${Oe(t)},${Oe(r)}L${Oe(o+n*c)},${Oe(h+s*c)}L${Oe(t-16*a)},${Oe(r-16*i)}L${Oe(o-n*c)},${Oe(h-s*c)}Z" stroke-linejoin="round"${"composition"===e?` fill="${l}"`:""}/>`}case"lollipop":return`<circle class="pele-marker" cx="${Oe(t-5*a)}" cy="${Oe(r-5*i)}" r="5"/>`;case"dependency":return li("arrow_point",t,r,a,i,l)}return""}var gh=20,mh=26,yh=12,xh="var(--_l)",wh=new Set(["_self","_blank","_parent","_top"]);function $h(e,t,r){let a=e[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}var bh=[],Mh=[];function vh(e,t,r,a){let i=m(e.getDisplayDetails().displayText).trim(),l=("*"===e.classifier?2:0)|(a?4:0);return{text:i,width:t.width(i,r,l),classifier:e.classifier}}var kh={type:"class",math:!0,parse(e,t,r){let a=new th;return r&&(a.title=r),ch(e,a),a},render:function(e,t,r){let a=a=>Vl(r,i=>function(e,t,r,a,i){let l=t.class??{},n=function(e,t=!0){let r=[],a=[],i=new Map,l=new Map,n=new Map,s=new Map,o=r=>{if(t||void 0===r)return r;let a,i=[],l=r;for(;l;){if(s.has(l)){a=s.get(l);break}let t=e.namespaces.get(l);if(void 0===t)break;if(t.explicit){a=l;break}i.push(l),l=t.parent}for(let e of i)s.set(e,a);return a},h=e=>void 0===e?-1:i.get(e)??-1;for(let a of e.namespaces.values())!t&&!a.explicit||(i.set(a.id,r.length),r.push({id:a.id,label:t?a.label:a.id,isGroup:!0,shape:"rect",parentId:t?a.parent:void 0,parent:-1}));for(let e of r)e.parent=h(e.parentId);let c=0;for(let t of e.classes.values()){let e=o(t.parent);l.set(t.id,r.length),r.push({id:t.id,label:t.label,isGroup:!1,shape:"classBox",parentId:e,parent:h(e),classNode:t,colorIndex:c++})}for(let t of e.notes.values()){let e=o(t.parent),i=void 0===t.class?void 0:l.get(t.class);void 0!==i&&a.push({id:`edgeNote${t.index}`,start:t.id,end:r[i].id,source:r.length,target:i,label:void 0,arrowTypeStart:"none",arrowTypeEnd:"none",startLabelRight:"",endLabelLeft:"",pattern:"dotted",classes:"relation"}),r.push({id:t.id,label:t.text,isGroup:!1,shape:"note",parentId:e,parent:h(e)})}for(let t of e.interfaces){let e=l.get(t.classId);n.set(t.id,r.length),r.push({id:t.id,label:t.label,isGroup:!1,shape:"interface",parentId:void 0,parent:void 0===e?-1:r[e].parent})}let d=0;for(let t of e.relations){d++;let{type1:e,type2:r}=t.relation,i=e===Qo.LOLLIPOP&&"none"===r?n:l,s=i===l&&r===Qo.LOLLIPOP&&"none"===e?n:l;a.push({id:`id_${t.id1}_${t.id2}_${d}`,start:t.id1,end:t.id2,source:i.get(t.id1)??-1,target:s.get(t.id2)??-1,label:t.title,arrowTypeStart:fh(e),arrowTypeEnd:fh(r),startLabelRight:"none"===t.relationTitle1?"":t.relationTitle1,endLabelLeft:"none"===t.relationTitle2?"":t.relationTitle2,pattern:1===t.relation.lineType?"dashed":"solid",classes:"relation"})}return{nodes:r,edges:a}}(e,!1!==l.hierarchicalNamespaces),s=!0===l.hideEmptyMembersBox,o=Array.isArray(r.monospace)&&r.monospace.includes("members"),h=e=>o&&!/[";]font-family:/.test(e.text),c=r.fontSize??16,d=Math.round(.875*c),f=Math.round(.8*c),u=Math.round(1.4*f),p=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),g=r.padding??8,y=(e,t)=>{if(!e.includes("$$"))return;let r=Fl(e,!1,p,t,4e3);return r.lines.some(Pl)?r:void 0},x=e=>e?y(e,f)?.width??p.width(m(e),f,0):0,w=a?"TB":Pa(e.direction),$=new Map,b=new Map,M=new Map,v=e=>{let t=$.get(e);if(void 0===t){let r=Ri([e]);t=""===r.shape&&""===r.text?"":e.slice(0,e.indexOf(":")).trim().toLowerCase(),$.set(e,t)}""!==t&&M.set(t,e)},k=t=>{M.clear();let r=b.get(t.cssClasses);if(void 0===r){for(let r of t.cssClasses.split(" ")){let t=e.styleClasses.get(r);if(t)for(let e of t.styles)for(let t of e.split(","))v(t)}r=[...M],b.set(t.cssClasses,r)}else for(let[e,t]of r)M.set(e,t);for(let e of t.styles)v(e);return Ri(0===M.size?Mh:[...M.values()])},A=new Int32Array(n.nodes.length);for(let e of n.nodes)e.parent>=0&&A[e.parent]++;let T=new Uint8Array(n.nodes.length);for(let e of n.edges){if(e.source<0||e.target<0)continue;let t=n.nodes[e.source].parent,r=n.nodes[e.target].parent;if(t!==r){for(let e=t;e>=0&&0===T[e];e=n.nodes[e].parent)T[e]=1;for(let e=r;e>=0&&0===T[e];e=n.nodes[e].parent)T[e]=1}}let C=[],E=[];function _(e,t,r,a,i){return{node:e,style:Ri(Mh),label:t,w:r,h:a,loops:0,annotations:Mh,attributes:bh,methods:bh,titleH:0,attributesH:0,fontSize:i}}function S(e,t){let r=k(t),a=r.fontSize??c,i=Math.round(.875*a),l=Math.round(1.5*i),n=t.type?"&lt;"+Vo(t.type).replace(/</g,"&lt;").replace(/>/g,"&gt;")+"&gt;":"",o=Fl(t.label+n,!1,p,a,4e3,1|(r.italic?2:0)),d=t.annotations.length>0?t.annotations.map(e=>y(`«${e.trim()}»`,f)??`«${m(e).trim()}»`):Mh,g=t.members.length>0?t.members.map(e=>vh(e,p,i,h(r))):bh,x=t.methods.length>0?t.methods.map(e=>vh(e,p,i,h(r))):bh,w=o.width,$=0;for(let e of d)w=Math.max(w,"string"==typeof e?p.width(e,f,0):e.width),$+="string"==typeof e?u:Math.max(u,e.height);for(let e of g)w=Math.max(w,e.width);for(let e of x)w=Math.max(w,e.width);let b=!(s&&0===g.length&&0===x.length),M=e=>b?e>0?12+e*l:10:0,v=16+$+Math.max(o.height,Math.round(1.5*a)),A=M(g.length);return{node:e,style:r,label:o,w:Math.max(w+24,64),h:v+A+M(x.length),loops:0,annotations:d,attributes:g,methods:x,titleH:v,attributesH:A,fontSize:a}}n.nodes.forEach((e,t)=>{let r,a;if(e.isGroup){let l=Fl(e.label,!1,p,c,4e3);r=_(e,l,0,0,c),A[t]>0?(a=Va(0,0),a.isGroup=!0,a.padX=gh,a.padTop=l.height>0?l.height+16:gh,a.padBottom=gh,a.minW=l.width+40-12+(1!==T[t]||i?0:Math.min(l.width+24,240))):(r.w=Math.max(l.width+40,80),r.h=l.height+40,a=Va(r.w,r.h))}else if(e.classNode)r=S(e,e.classNode),a=Va(r.w,r.h);else if("note"===e.shape){let t=Fl(e.label,!0,p,d,260);r=_(e,t,Math.max(t.width+24,40),t.height+16,d),a=Va(r.w,r.h)}else{let t=Fl(e.label,!1,p,d,200);r=_(e,t,Math.max(t.width,12)+4,Math.max(t.height,12),d),a=Va(r.w,r.h)}a.parent=e.parent,a.seq=t,C.push(r),E.push(a)});let I=[],N=[],D=[],R=[],L=[],O=new Float64Array(4*C.length),F=(e,t,r)=>{O[4*e+t]++,r>O[4*e+t+1]&&(O[4*e+t+1]=r)};for(let e of n.edges){if(e.source<0||e.target<0)continue;let t=Fl(e.label,!0,p,d,200),r=x(e.startLabelRight),a=x(e.endLabelLeft);e.source===e.target?(C[e.source].loops++,E[e.source].w+=2*(mh+(t.width>0?t.width+12:0))):(F(e.source,0,r),F(e.target,2,a)),R.push(r),L.push(a),N.push(e),D.push(t),I.push({src:e.source,dst:e.target,minlen:1,labelW:t.width>0?t.width+12:0,labelH:t.height>0?t.height+4:0,route:[],labelX:0,labelY:0})}if("TB"===w||"BT"===w)for(let e=0;e<C.length;e++){if(!C[e].node.classNode)continue;let t=0;for(let r=0;r<4;r+=2){let a=O[4*e+r],i=O[4*e+r+1];a>1&&(t=Math.max(t,(a-1)*(i>0?i+24:14)+24))}t=Math.min(t,480),t>C[e].w&&(E[e].w+=t-C[e].w,C[e].w=t)}let z=!1;for(let e=0;e<N.length&&!z;e++)z=R[e]>0||L[e]>0;let W=0;if("TB"===w||"BT"===w){let e=e=>e?Math.max(u,y(e,f)?.height??0):0;for(let t of N)W=Math.max(W,e(t.startLabelRight)+e(t.endLabelLeft)-2*u)}let P=Za(E,I,w,{nodeSep:$h(l,"nodeSpacing",40),edgeSep:16,rankSep:$h(l,"rankSpacing",z?72:56)+W,portSep:20,apart:!0}),B=new Map,H=[],Y=(e,t,r,a,i)=>{let l=e.route,n=E[r],s=fl(l,t,n);if(s<0)return;let o=(n.w-C[r].w)/2;1===s?l[t]-=o:3===s&&(l[t]+=o);let h=1&s,c=l[(0===t?3:t-3)+h],d=c-l[t+h],f={route:l,at:t,toward:c,order:i,room:a,side:s,after:h?d>0:d>=0},u=4*r+s,p=B.get(u);return p?p.push(f):B.set(u,[f]),f},G=[],U=[];for(let e=0;e<I.length;e++){let t=I[e],r=t.src!==t.dst&&t.route.length>=6;G.push(r?Y(t,0,t.src,R[e],e):void 0),U.push(r?Y(t,t.route.length-3,t.dst,L[e],e):void 0)}let q=(e,t,r)=>{for(let a=E[e].parent,i=0;a>=0&&i<1e4;a=E[a].parent,i++){let e=E[a],i=Math.abs(t-e.x),l=Math.abs(r-e.y);if(Math.abs(l-e.h/2)<.5&&i<=e.w/2+.5||Math.abs(i-e.w/2)<.5&&l<=e.h/2+.5)return!0}return!1},j=[];for(let[e,t]of B){if(t.length<2)continue;let r=e>>2,a=1&e,i=a?C[r].h:C[r].w;t.sort((e,t)=>e.toward-t.toward||e.order-t.order);let l=0;for(let e=0;e+1<t.length;e++){let r=t[e],i=t[e+1],n=a?20:24;r.room>0&&r.after&&(n+=a?u+6:r.room),i.room>0&&!i.after&&(n+=a?u+6:i.room),j[e]=n,l+=n}let n=Math.min(1,(i-24)/l);if(n<=0)continue;let s=(a?E[r].y:E[r].x)-l*n/2;for(let e=0;e<t.length;e++){let{route:i,at:l}=t[e],o=0===l?3:-3,h=l+o,c=-1;for(let e=h;e>=0&&e<i.length&&Math.abs(i[e+a]-i[h+a])<.5;e+=o)if(q(r,i[e],i[e+1])){c=e;break}if(c>=0&&Math.abs(i[h+a]-s)<=24)for(let e=h;e!==c+o;e+=o)i[e+a]=s;i[l+a]=s,s+=j[e]*n}}let V=(e,t,r,a)=>{if(void 0===t||r<=0)return;let i=1&t.side,l=a?0:e.length-3,n=l+1-i,s=Math.abs(e[1+(a?3:l-3)-i]-e[n]),o=Math.min(i?r+10:u+6,.35*s);if(o<4)return;let h=[e[l],e[l+1],e[l+2]];h[1-i]+=(0===t.side||3===t.side?-1:1)*o,e.splice(a?3:l,0,h[0],h[1],h[2])};for(let e=0;e<I.length;e++)V(I[e].route,G[e],R[e],!0),V(I[e].route,U[e],L[e],!1);let X=0,K=0,Z=P.width,Q=P.height,J=(e,t,r,a,i,l,n)=>{if(!t)return;let s=y(t,f),o=s?Math.max(u,s.height):u,h=a,c=i;1&l?(h+=(3===l?-1:1)*(5+r/2),c+=(n?1:-1)*(7+o/2)):(h+=(n?1:-1)*(9+r/2),c+=(0===l?-1:1)*(3+o/2)),H.push({text:m(t),math:s,x:h,y:c,w:r,h:o,parent:e}),X=Math.min(X,h-r/2),Z=Math.max(Z,h+r/2),K=Math.min(K,c-o/2),Q=Math.max(Q,c+o/2)},ee=new Map,te=new Int32Array(I.length);for(let e=0;e<I.length;e++){let t=I[e],r=N[e],a=t.route;if(t.src===t.dst){let a=ee.get(t.src)??0;ee.set(t.src,a+1),te[e]=a;let i=E[t.src],l=C[t.src],n=i.x+l.w/2,s=Math.min(l.h/2-4,8+6*a);J(t.src,r.startLabelRight,R[e],n,i.y-s,1,!1),J(t.dst,r.endLabelLeft,L[e],n,i.y+s,1,!0),t.labelX=i.x+l.w/2+mh+8*a+4+t.labelW/2,t.labelY=i.y}else if(a.length>=6){let i=a.length-3,l=G[e],n=U[e];J(t.src,r.startLabelRight,R[e],a[0],a[1],l?l.side:2,!l||l.after),J(t.dst,r.endLabelLeft,L[e],a[i],a[i+1],n?n.side:0,!n||n.after)}}let re=r.maxWidth;if(void 0!==re&&re>0&&Z-X+2*g>re){let e=H.map(e=>({...Va(e.w,e.h,e.parent),x:e.x,y:e.y})),t=function(e,t,r,a){let i=Int32Array.from(e,(e,t)=>t),l=e=>{for(;i[e]!==e;)i[e]=i[i[e]],e=i[e];return e},n=(e,t)=>{i[l(e)]=l(t)};for(let t=0;t<e.length;t++)e[t].parent>=0&&n(t,e[t].parent);for(let e of t)n(e.src,e.dst);let s=new Map,o=(e,t,r,a=0,i=0)=>{e.left=Math.min(e.left,t-a/2),e.top=Math.min(e.top,r-i/2),e.right=Math.max(e.right,t+a/2),e.bottom=Math.max(e.bottom,r+i/2)};for(let t=0;t<e.length;t++){let r=l(t),a=s.get(r);a||(a={nodes:[],edges:[],left:1/0,top:1/0,right:-1/0,bottom:-1/0},s.set(r,a));let i=e[t];a.nodes.push(i),o(a,i.x,i.y,i.w,i.h)}if(s.size<2)return;for(let e of t){let t=s.get(l(e.src));t.edges.push(e);for(let r=0;r<e.route.length;r+=3)o(t,e.route[r],e.route[r+1]);e.labelW>0&&o(t,e.labelX,e.labelY,e.labelW,e.labelH)}let h=0,c=0,d=0,f=0,u=1/0,p=-1/0,g=[];for(let e of s.values()){let t=e.right-e.left,i=e.bottom-e.top;h>0&&h+t>r&&(c+=d+a,h=0,d=0),g.push(h-e.left,c-e.top),u=Math.min(u,e.left),p=Math.max(p,e.right),f=Math.max(f,h+t),d=Math.max(d,i),h+=t+a}if(f>=p-u)return;let m=0;for(let e of s.values())ja(e.nodes,e.edges,g[m++],g[m++]);return{width:f,height:c+d}}(E.concat(e),I,Math.max(1,re-2*g),$h(l,"nodeSpacing",40));t&&(H.forEach((t,r)=>{t.x=e[r].x,t.y=e[r].y}),X=K=0,Z=t.width,Q=t.height)}let ae=g-X,ie=g-K,le=Math.ceil(Z-X+2*g),ne=Math.ceil(Q-K+2*g),se=[],oe=new Map;if(n.nodes.length>0&&n.nodes[0].isGroup)for(let e of I)Qa(oe,e.route);let he="",ce="",de="";for(let e=0;e<C.length;e++){let t=C[e],a=E[e],i=t.node,l=a.x+ae,s=a.y+ie,o=Re(i.id),h=a.isGroup?a.w:t.w,c=a.isGroup?a.h:t.h;if(i.isGroup){let r=a.isGroup?Ja(a,t.label.width,oe,gh):a.x,i=s-c/2+8+t.label.height/2,d=' class="pele-cluster-label" fill="var(--_m)"',f=a.isGroup&&ei(a,t.label.width,r,oe);f&&(ce+=ti(t.label,r+ae,i,d,o,n.nodes,e)),he+=`<g class="pele-cluster pele-namespace" data-id="${o}"><rect x="${Oe(l-h/2)}" y="${Oe(s-c/2)}" width="${Oe(h)}" height="${Oe(c)}" fill="var(--_a)" fill-opacity="0.5" stroke="var(--_b)"${Mi}/>`+(f?"":Fe(t.label,r+ae,i,d))+"</g>";continue}let f=` transform="translate(${Oe(l)},${Oe(s)})"`;if(i.classNode)de+=fe(t,i.classNode,o,f);else if("note"===i.shape){let e=h/2,a=-c/2;de+=`<g class="pele-node pele-note" data-id="${o}"${f}><path d="M${Oe(-e)},${Oe(a)}H${Oe(e-8)}L${Oe(e)},${Oe(a+8)}V${Oe(-a)}H${Oe(-e)}Z" fill="var(--_a)" stroke="var(--_b)" stroke-linejoin="round"/><path d="M${Oe(e-8)},${Oe(a)}V${Oe(a+8)}H${Oe(e)}" fill="none" stroke="var(--_b)" stroke-linejoin="round"/>`+Fe(t.label,0,0,` class="pele-label" font-size="${d}"`,r.icons)+"</g>"}else de+=`<g class="pele-node pele-interface" data-id="${o}"${f}>`+Fe(t.label,0,0,` class="pele-label" font-size="${d}"`,r.icons)+"</g>"}function fe(e,t,a,i){let{w:l,h:n,style:s}=e,o=-l/2,d=-n/2,p=Math.round(.875*e.fontSize),g=Math.round(1.5*p),m=`<rect x="${Oe(o)}" y="${Oe(d)}" width="${Oe(l)}" height="${Oe(n)}" fill="var(--_s)" stroke="var(--_b)"${Ai(s.shape)}/>`,y=xt(s),x=d+e.titleH,w=x+e.attributesH;if(n>e.titleH){let e=s.stroke?` style="stroke:${De(s.stroke)}"`:"";m+=`<path class="pele-divider" d="M${Oe(o)},${Oe(x)}H${Oe(-o)}M${Oe(o)},${Oe(w)}H${Oe(-o)}" fill="none" stroke="var(--_b)"${e}/>`}let $=d+8;for(let t of e.annotations)if("string"==typeof t)m+=`<text class="pele-annotation" x="0" y="${Oe($+u/2+.35*f)}" text-anchor="middle" font-size="${f}"${y||' fill="var(--_m)"'}>${De(t)}</text>`,$+=u;else{let e=Math.max(u,t.height);m+=Fe(t,0,$+e/2,` class="pele-annotation" font-size="${f}"${y||' fill="var(--_m)"'}`,r.icons),$+=e}let b=e.fontSize===c?"":` font-size="${Oe(e.fontSize)}"`;m+=Fe(e.label,0,($+x-8)/2,` class="pele-label"${b} font-weight="var(--_hw)"${y}${s.text}`,r.icons);let M=(e,t,r)=>{let a="",i=r+6+g/2+.35*p;for(let r of e){a+=`<text class="pele-member pele-${t}${"$"===r.classifier?' pele-static"'+(s.text?s.text.slice(0,-1)+'text-decoration:underline"':' style="text-decoration:underline"'):"*"===r.classifier?` pele-abstract" font-style="italic"${s.text}`:`"${s.text}`} x="${Oe(o+yh)}" y="${Oe(i)}">${De(r.text)}</text>`,i+=g}return a};return(e.attributes.length>0||e.methods.length>0)&&(m+=`<g class="pele-members" font-size="${p}"${y}${h(s)?` font-family="${bi}"`:""}>${M(e.attributes,"attribute",x)}${M(e.methods,"method",w)}</g>`),t.tooltip&&(m=`<title>${Re(t.tooltip)}</title>`+m),t.link&&(m=Mr(m,t.link,t.id,se,r,t.linkTarget&&wh.has(t.linkTarget)?` target="${t.linkTarget}"`:"")),`<g class="pele-node pele-class${Oi(t.cssClasses.replace(/^default\s?/,""))}" data-id="${a}"${i}>${m}</g>`}let ue="",pe="";for(let e=0;e<I.length;e++){let t,a=I[e],i=N[e],l=D[e],n=i.arrowTypeStart,s=i.arrowTypeEnd,o=uh(n),h=uh(s);if(a.src===a.dst){let r=E[a.src],i=C[a.src],l=te[e],n=r.x+ae+i.w/2,s=r.y+ie,c=Math.min(i.h/2-4,8+6*l),d=mh+8*l;t={d:`M${Oe(n+o)},${Oe(s-c)}C${Oe(n+d+o)},${Oe(s-c)} ${Oe(n+d+h)},${Oe(s+c)} ${Oe(n+h)},${Oe(s+c)}`,sx:n,sy:s-c,sdx:-1,sdy:0,ex:n,ey:s+c,edx:-1,edy:0}}else{let e=a.route;for(let t=0;t<e.length;t+=3)e[t]+=ae,e[t+1]+=ie;t=ai(e,void 0,o,h)}let c="dashed"===i.pattern?' stroke-dasharray="6 4"':"dotted"===i.pattern?' stroke-dasharray="2 4"':"";if(ue+=`<g class="pele-edge${"dotted"===i.pattern?" pele-note-edge":" pele-relation"}" data-id="${Re(i.id)}"><path d="${t.d}"${c}/>`+ph(n,t.sx,t.sy,t.sdx,t.sdy,xh)+ph(s,t.ex,t.ey,t.edx,t.edy,xh)+"</g>",l.width>0){let e=a.labelX+ae,t=a.labelY+ie;pe+=wi(i.id,l,e,t,"",r.icons)}}let ge="";for(let e of H)ge+=e.math?Fe(e.math,e.x+ae,e.y+ie,' class="pele-cardinality"',r.icons):`<text class="pele-cardinality" x="${Oe(e.x+ae)}" y="${Oe(e.y+ie+.35*f)}" text-anchor="middle">${De(e.text)}</text>`;let me=ms(e.title,p,c,g,le,ne,(he?`<g class="pele-clusters">${he}</g>`:"")+(ue?`<g class="pele-edges" fill="none" stroke="${xh}" stroke-linecap="round">${ue}</g>`:"")+(ce?`<g class="pele-cluster-titles">${ce}</g>`:"")+(pe?`<g class="pele-edge-labels" font-size="${d}">${pe}</g>`:"")+(ge?`<g class="pele-cardinalities" font-size="${f}" fill="var(--_m)">${ge}</g>`:"")+`<g class="pele-nodes">${de}</g>`);return{svg:Bi("class",me.width,me.height,c,r,e,me.content),width:me.width,height:me.height,links:se}}(e,t,r,a,i));return jl(e.direction)?ql(r,a):a(!1)}},Ah=class{domains=new Map;transitions=[];setDomains(e){if(e)for(let t of e){let e=t.domain;this.domains.set(e,{name:e,items:(t.items??[]).map(e=>({label:e.label}))})}}setTransitions(e){e&&(this.transitions=e.filter(e=>e.from!==e.to).map(e=>({from:e.from,to:e.to,label:e.label||void 0})))}};var Th=[{name:"cynefin-beta:",pattern:"cynefin-beta:"},vn("cynefin-beta"),{name:"--\x3e",pattern:"--\x3e"},{name:":",pattern:":"},{name:"DOMAIN_NAME",pattern:/complex|complicated|clear|chaotic|confusion/y},un,pn,gn,yn,xn,wn,$n,bn,Mn];function Ch(e){let t=e+1831565813|0;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}var Eh={segments:7,vertical:!0,pointStep:17,controlStep:31,controlShift:7},_h={segments:7,vertical:!1,pointStep:23,controlStep:37,controlShift:11};function Sh(e,t,r,a,i,l){let n=(t-e)/l.segments,s=[],o=[];for(let t=0;t<=l.segments;t++){let h=0===t&&l.pinStart||t===l.segments&&l.pinEnd;s.push(e+t*n),o.push(h?r:r+Ch(a+t*l.pointStep)*i*2-i)}let h=l.vertical?[o[0],s[0]]:[s[0],o[0]];for(let e=0;e<l.segments;e++){let t=(s[e]+s[e+1])/2,r=1.5*i*(e%2==0?1:-1)*Ch(a+e*l.controlStep+l.controlShift);l.vertical?h.push(o[e]+r,t,o[e+1]-r,t,o[e+1],s[e+1]):h.push(t,o[e]+r,t,o[e+1]-r,s[e+1],o[e+1])}return h}function Ih(e){let t="";for(let r=2;r<e.length;r+=6)t+=`C${Oe(e[r])},${Oe(e[r+1])} ${Oe(e[r+2])},${Oe(e[r+3])} ${Oe(e[r+4])},${Oe(e[r+5])}`;return t}function Nh(e){let t="";for(let r=e.length-6;r>=2;r-=6)t+=`C${Oe(e[r+2])},${Oe(e[r+3])} ${Oe(e[r])},${Oe(e[r+1])} ${Oe(e[r-2])},${Oe(e[r-1])}`;return t}function Dh(e){return`M${Oe(e[0])},${Oe(e[1])}${Ih(e)}`}var Rh=[["complex",0,0,0],["complicated",1,0,1],["chaotic",0,1,3],["clear",1,1,2]],Lh=new Map([["complex",["Complex","Probe → Sense → Respond","Emergent Practices"]],["complicated",["Complicated","Sense → Analyse → Respond","Good Practices"]],["clear",["Clear","Sense → Categorise → Respond","Best Practices"]],["chaotic",["Chaotic","Act → Sense → Respond","Novel Practices"]],["confusion",["Confusion","","Disorder"]]]);function Oh(e,t,r,a,i){let l=e.cynefin?.[t];return"number"==typeof l&&l>=a&&l<=i?l:r}var Fh={type:"cynefin",parse:(e,t,r)=>function(e,t){let r=new Ah;return r.setDomains(e.domains),r.setTransitions(e.transitions),{type:"cynefin",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,domains:r.domains,transitions:r.transitions}}(function(e){let t=new Dn(fn(e,Th,"cynefin"),Th,"cynefin"),r={$type:"Cynefin",domains:[],transitions:[]},a=()=>{for(;9===t.kinds[t.i];)t.i++},i=()=>{-1!==t.kind&&(9!==t.kind&&t.fail("a line break or the end of input"),a())};for(a(),1!==t.kind&&0!==t.kind&&t.fail("'cynefin-beta'"),t.i++;-1!==t.kind;)switch(t.kind){case 9:t.i++;break;case 5:r.accDescr=Sn(t.take()),i();break;case 6:r.accTitle=_n(t.take()),i();break;case 7:r.title=En(t.take()),i();break;case 4:{let e=t.take();if(t.accept(2)){let a={$type:"Transition",from:e,to:t.expect(4)};t.accept(3)&&(a.label=Nn(t.expect(8))),i(),r.transitions.push(a);break}let l={$type:"DomainBlock",domain:e,items:[]};for(a();8===t.kinds[t.i];)l.items.push({$type:"DomainItem",label:Nn(t.take())}),a();r.domains.push(l);break}default:t.fail("a domain, a transition, a title, or a line break")}return r}(e),r),render:function(e,t,r){let a=r.fontSize??16,i=Math.round(.8125*a),l=Math.round(.875*a),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8,o=r.icons,h=!1!==t.cynefin?.showDomainDescriptions,c=Oh(t,"boundaryAmplitude",8,0,50),d=function(e,t){return"number"==typeof e&&Number.isFinite(e)&&0!==e?e:function(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t}(t)}(Oh(t,"seed",0,-1e15,1e15),r.idPrefix??"pele"),f=Math.round(1.5*l),u=(e,t)=>{let r=Fl(e,!1,n,l,200);return{text:e,label:r,w:r.width+20,h:Math.max(r.height,f)+8,overflow:t}},p=t=>{let r=Lh.get(t),l=Fl(r[0],!1,n,a,4e3,1),s=[];if(h)for(let e of[r[1],r[2]])e&&s.push(Fl(e,!1,n,i,4e3,2));let o=e.domains.get(t)?.items??[],c="confusion"===t&&o.length>3?3:o.length,d=[];for(let e=0;e<c;e++)d.push(u(o[e].label,!1));c<o.length&&d.push(u(`+${o.length-c} more`,!0));let f=l.width,p=l.height;for(let e of s)f=Math.max(f,e.width),p+=e.height;d.length>0&&(p+=4);for(let e of d)f=Math.max(f,e.w),p+=6+e.h;return{name:t,title:l,subtitles:s,badges:d,w:f,h:p,cx:0,cy:0}},g=Rh.map(([e])=>p(e)),m=p("confusion"),y=Math.max(88,.71*m.w+8),x=Math.max(64,.71*m.h+6),w=Oh(t,"width",640,100,1e4)/2,$=Oh(t,"height",440,100,1e4)/2;for(let e of g)w=Math.max(w,e.w+40),$=Math.max($,e.h+40);for(let e of g){let t=(w-e.w)/2,r=($-e.h)/2;if((t/(y+10))**2+(r/(x+10))**2>=1)continue;let a=e.w+2*(y+10),i=e.h+2*(x+10);a*$<=w*i?w=Math.max(w,a):$=Math.max($,i)}let b=Fl(e.title,!1,n,a,4e3,1),M=b.height>0?b.height+12:0,v=2*w,k=2*$,A=s,T=s+M,C=A+w,E=T+$,_=A+v,S=T+k,I=Sh(T,E,C,d,c,{...Eh,segments:4,pinEnd:!0}),N=Sh(A,C,E,d+100,c,{..._h,segments:4,pinEnd:!0}),D=Sh(C,_,E,d+200,c,{..._h,segments:4,pinStart:!0}),R=function(e,t,r,a){let i=r-t;return[e,t,e+a,t+.2*i,e-1.5*a,t+.55*i,e+.5*a,t+.75*i,e-a,t+.85*i,e+.3*a,t+.95*i,e,r]}(C,E,S,.03*v),L=(e,t)=>t?`${Oe(e[e.length-2])},${Oe(e[e.length-1])}`:`${Oe(e[0])},${Oe(e[1])}`,O=new Map([["complex",`M${Oe(A)},${Oe(T)}L${L(I,!1)}${Ih(I)}${Nh(N)}Z`],["complicated",`M${L(I,!1)}L${Oe(_)},${Oe(T)}L${L(D,!0)}${Nh(D)}${Nh(I)}Z`],["chaotic",`M${L(N,!1)}${Ih(N)}${Ih(R)}L${Oe(A)},${Oe(S)}Z`],["clear",`M${L(D,!1)}${Ih(D)}L${Oe(_)},${Oe(S)}L${L(R,!0)}${Nh(R)}Z`]]),F="";for(let[e,,,t]of Rh)F+=`<path class="pele-cynefin-region" data-id="${e}" d="${O.get(e)}" fill="${zi(t)}" fill-opacity="0.14"/>`;let z=`<g class="pele-cynefin-boundaries" fill="none" stroke="var(--_b)" stroke-dasharray="6 3"><path d="${Dh(I)}"/><path d="${Dh(N)}"/><path d="${Dh(D)}"/><path class="pele-cynefin-cliff" d="${Dh(R)}" stroke="var(--_l)" stroke-width="2" stroke-dasharray="none" stroke-linecap="round"/></g>`,W=function(e,t,r,a){let i=`${Oe(r)},${Oe(a)}`;return`M${Oe(e-r)},${Oe(t)}A${i} 0 1,1 ${Oe(e+r)},${Oe(t)}A${i} 0 1,1 ${Oe(e-r)},${Oe(t)}Z`}(C,E,y,x),P=`<path d="${W}" fill="var(--_bg)"/><path class="pele-cynefin-region" data-id="confusion" d="${W}" fill="${zi(4)}" fill-opacity="0.18" stroke="var(--_b)" stroke-dasharray="4 2"/>`,B=e=>{let t=e.cy-e.h/2,r=Fe(e.title,e.cx,t+e.title.height/2,' class="pele-label" font-weight="var(--_hw)"');t+=e.title.height;for(let a of e.subtitles)r+=Fe(a,e.cx,t+a.height/2,` class="pele-cynefin-subtitle" font-size="${i}" font-style="italic" fill="var(--_m)"`),t+=a.height;t+=4;for(let a of e.badges)t+=6,r+=`<g class="pele-node${a.overflow?" pele-cynefin-overflow":""}"${a.overflow?"":` data-id="${Re(a.text)}"`}><rect x="${Oe(e.cx-a.w/2)}" y="${Oe(t)}" width="${Oe(a.w)}" height="${Oe(a.h)}" fill="var(--_bg)" stroke="var(--_b)"${a.overflow?' stroke-dasharray="3 2"':""}${Mi}/>`+Fe(a.label,e.cx,t+a.h/2,` class="pele-label" font-size="${l}"${a.overflow?' fill="var(--_m)"':""}`,o)+"</g>",t+=a.h;return`<g class="pele-cynefin-domain" data-id="${e.name}">${r}</g>`},H=new Map,Y="";Rh.forEach(([e,t,r],a)=>{let i=g[a];i.cx=A+w*(t+.5),i.cy=T+$*(r+.5),H.set(e,i),Y+=B(i)}),m.cx=C,m.cy=E,H.set("confusion",m),Y+=B(m);let G=(e,t,r)=>e===m?((t-C)/(y+4))**2+((r-E)/(x+4))**2<=1:Math.abs(t-e.cx)<=e.w/2+8&&Math.abs(r-e.cy)<=e.h/2+8,U="",q=new Map;for(let t of e.transitions){let e=H.get(t.from),r=H.get(t.to);if(!e||!r||e===r)continue;let a=t.from<t.to?`${t.from} ${t.to}`:`${t.to} ${t.from}`,l=q.get(a)??0;q.set(a,l+1);let s=r.cx-e.cx,h=r.cy-e.cy,c=Math.hypot(s,h)||1,d=(e.cx+r.cx)/2,f=(e.cy+r.cy)/2,u=-h*(d-C)+s*(f-E)>=0?1:-1,p=-h/c*u,g=s/c*u,w=(e!==m&&r!==m&&Math.abs(s)>1&&Math.abs(h)>1?2*(Math.hypot(y*p,x*g)+16):.15*c)+56*l,$=d+p*w,b=f+g*w,M=t=>{let a=1-t;return[a*a*e.cx+2*a*t*$+t*t*r.cx,a*a*e.cy+2*a*t*b+t*t*r.cy]},v=(e,t,r,a)=>{for(let i=0;i<16;i++){let i=(t+r)/2;G(e,...M(i))===a?t=i:r=i}return(t+r)/2},k=48,T=1;for(;T<=k&&G(e,...M(T/k));)T++;if(T>k)continue;let S=v(e,(T-1)/k,T/k,!0);for(;T<=k&&!G(r,...M(T/k));)T++;let I=T>k?1:v(r,(T-1)/k,T/k,!1),[N,D]=M(S),[R,L]=M(I),O=(e,t,r)=>(1-S)*(1-I)*e+((1-S)*I+S*(1-I))*t+S*I*r,F=O(e.cx,$,r.cx),z=O(e.cy,b,r.cy),W=Math.hypot(R-F,L-z)||1,P=(R-F)/W,B=(L-z)/W,Y=li("arrow_point",R,L,P,B,"var(--_l)");R-=P*ii("arrow_point"),L-=B*ii("arrow_point");let j="";if(t.label){let e=Fl(t.label,!1,n,i,200),[r,a]=M((S+I)/2),l=Math.abs(p)*e.width/2+Math.abs(g)*e.height/2+6,s=e.width/2+4;j=Fe(e,Math.min(Math.max(r+p*l,A+s),Math.max(_-s,A+s)),a+g*l,` class="pele-edge-label" font-size="${i}"`,o)}U+=`<g class="pele-edge" data-id="${t.from}-${t.to}"><path d="M${Oe(N)},${Oe(D)}Q${Oe(F)},${Oe(z)} ${Oe(R)},${Oe(L)}" fill="none" stroke="var(--_l)"/>`+Y+j+"</g>"}let j=Math.ceil(Math.max(v,b.width)+2*s),V=Math.ceil(k+M+2*s),X=Fe(b,A+v/2,s+b.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g class="pele-cynefin-regions">${F}</g>`+z+P+Y+(U?`<g class="pele-edges">${U}</g>`:"");return{svg:Bi("cynefin",j,V,a,r,e,X),width:j,height:V,links:[]}}};var zh=class{type="er";direction="TB";entities=new Map;relationships=[];classes=new Map;subgraphs=[];title;accTitle;accDescr;subgraphLookup=new Map;claimed=new Set;addEntity(e,t=""){let r=this.entities.get(e);return void 0===r?(r={id:`entity-${e}-${this.entities.size}`,label:e,alias:t,attributes:[],cssClasses:"default",cssStyles:[]},this.entities.set(e,r)):!r.alias&&t&&(r.alias=t),r}addAttributes(e,t){let r=this.addEntity(e);for(let e=t.length-1;e>=0;e--){let a=t[e];a.keys??=[],a.comment??="",r.attributes.push(a)}}addRelationship(e,t,r,a){let i=this.subgraphLookup.has(e)?e:this.addEntity(e).id,l=this.subgraphLookup.has(r)?r:this.addEntity(r).id;this.relationships.push({entityA:i,roleA:t,entityB:l,relSpec:a})}setDirection(e){this.direction=e}addCssStyles(e,t){if(t)for(let r of e){let e=this.entities.get(r);if(e)for(let r of t)e.cssStyles.push(r);let a=this.subgraphLookup.get(r);if(a)for(let e of t)a.cssStyles.push(e)}}addClass(e,t){for(let r of e){let e=this.classes.get(r);if(void 0===e&&(e={id:r,styles:[],textStyles:[]},this.classes.set(r,e)),t)for(let r of t)r.includes("color")&&e.textStyles.push(r.replace("fill","bgFill")),e.styles.push(r)}}setClass(e,t){for(let r of e){let e=this.entities.get(r);if(e)for(let r of t)e.cssClasses+=" "+r;let a=this.subgraphLookup.get(r);if(a)for(let e of t)a.classes.push(e)}}addSubGraph(e,t,r){let a,i=e.text.trim(),l=new Set,n=[];for(let e of t.flat()){if("string"!=typeof e){"dir"===e?.stmt&&(a=e.value);continue}let t=e.trim();""===t||l.has(t)||(l.add(t),this.claimed.has(e)||n.push(e))}for(let e of n)this.claimed.add(e);let s={id:i,nodes:n,title:(r.text||"").trim(),classes:[],cssStyles:[],dir:a,labelType:(o=r.type,"markdown"===o||"string"===o||"text"===o?o:"markdown")};var o;return this.subgraphs.push(s),this.subgraphLookup.set(i,s),i}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}},Wh=["$end","INVALID","ER_DIAGRAM","EOF","NEWLINE","COLON","STYLE_SEPARATOR","BLOCK_START","BLOCK_STOP","SQS","SQE","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","END","SUBGRAPH","direction_tb","direction_bt","direction_rl","direction_lr","CLASSDEF","UNICODE_TEXT","STYLE_TEXT","COMMA","CLASS","STYLE","SEMI","NUM","BRKT","ENTITY_NAME","DECIMAL_NUM","ENTITY_ONE","ATTRIBUTE_WORD","ATTRIBUTE_KEY","COMMENT","ZERO_OR_ONE","ZERO_OR_MORE","ONE_OR_MORE","ONLY_ONE","MD_PARENT","NON_IDENTIFYING","IDENTIFYING","WORD","CHAR"],Ph=new Uint8Array(128);for(let e=0;e<128;e++){let t=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||95===e,r=t&&(e<48||e>57);t&&(Ph[e]|=11),r&&(Ph[e]|=4)}for(let e of"-*")Ph[e.charCodeAt(0)]|=11;Ph[46]|=9,Ph[42]|=4;for(let e of"[](),")Ph[e.charCodeAt(0)]|=8;var Bh=/accTitle\s*:\s*/iy,Hh=/accDescr\s*:\s*/iy,Yh=/accDescr\s*\{\s*/iy,Gh=[/.*direction\s+TB[^\n]*/iy,/.*direction\s+BT[^\n]*/iy,/.*direction\s+RL[^\n]*/iy,/.*direction\s+LR[^\n]*/iy],Uh=/direction/gi,qh=/[\n\r\u2028\u2029]/g;function jh(e,t){return e<128?0!==(Ph[e]&t):e>=192||181===e}function Vh(e){let t=e.length,r=[],a=[],i=[],l=0,n=0,s=-2,o=0,h=-1,c=-2,d=-1,f=-1,u=-1,p=(t,l,s)=>{r.push(t),a.push(e.slice(l,s)),i.push(l),n=s},g=(t,r)=>(t.lastIndex=r,t.test(e)?t.lastIndex:-1),m=t=>{for(let r=0;r<t.length;r++){let a=t.charCodeAt(r),i=e.charCodeAt(n+r);if(i!==a&&(a<97||a>122||(32|i)!==a))return!1}return!0},y=t=>m(t)&&!Q(e.charCodeAt(n+t.length)),x=t=>{let r=e.charCodeAt(t);return r>=65&&r<=90?r+32:r},w=r=>(qh.lastIndex=r,qh.test(e)?qh.lastIndex-1:t),$=t=>{for(;X(e.charCodeAt(t));)t++;return t},b=t=>{let r;if((97===t||65===t)&&m("acc")){if((r=g(Bh,n))>=0)return l=3,void p(11,n,r);if((r=g(Hh,n))>=0)return l=4,void p(13,n,r);if((r=g(Yh,n))>=0)return l=5,void(n=r)}if(!(()=>{if(-1===s||s<n&&(Uh.lastIndex=n,s=Uh.test(e)?Uh.lastIndex-9:-1,-1===s)||n<o||(h<n&&(h=w(n)),s>=h))return!1;for(let e=0;e<4;e++){let t=g(Gh[e],n);if(t>=0)return p(18+e,n,t),!0}return o=h,!1})()){switch(t){case 32:case 9:case 13:r=n+1;for(let t=e.charCodeAt(r);32===t||9===t||13===t;t=e.charCodeAt(r))r++;return void(n=r);case 10:for(r=n+1;10===e.charCodeAt(r);)r++;return void p(4,n,r);case 34:return void(()=>{let t=e.indexOf('"',n+1);if(-1===t)return void p(45,n,n+1);let r=t>n+1;for(let a=n+1;r&&a<t;a++){let t=e.charCodeAt(a);(37===t||92===t||13===t||10===t||11===t||8===t)&&(r=!1)}p(r?31:44,n,t+1)})();case 123:return l=1,void p(7,n,n+1);case 35:return void p(30,n,n+1);case 44:return void p(25,n,n+1);case 58:return void(58===e.charCodeAt(n+1)&&58===e.charCodeAt(n+2)?p(6,n,n+3):p(5,n,n+1));case 91:return void p(9,n,n+1);case 93:return void p(10,n,n+1)}if(X(t))return void(t=>{let r=e.charCodeAt(n+1);if(43===r&&(49===t||48===t))return void p(49===t?39:38,n,n+2);let a=$(n+1);if(46===e.charCodeAt(a)&&X(e.charCodeAt(a+1)))p(32,n,$(a+2));else{if(49===t){if(q(r)){let t=n+2;for(;q(e.charCodeAt(t));)t++;let r=e.charCodeAt(t);if(Q(r)||34===r||39===r)return void p(40,n,n+1)}else if(45===r||46===r){let t=e.charCodeAt(n+2);if(45===t||46===t)return void p(40,n,n+1)}if(!Q(r))return void p(33,n,n+1)}p(29,n,a)}})(t);if(!(t=>{let r=e.charCodeAt(n+1);switch(t){case 101:if(y("erdiagram"))p(2,n,n+9);else{if(!y("end"))return!1;{let t=n+3;for(;q(e.charCodeAt(t));)t++;p(16,n,t)}}return!0;case 115:if(y("style"))l=6,p(27,n,n+5);else{if(!y("subgraph"))return!1;p(17,n,n+8)}return!0;case 99:if(y("classdef"))l=6,p(22,n,n+8);else{if(!y("class"))return!1;p(26,n,n+5)}return!0;case 111:if(y("one or zero"))p(37,n,n+11);else if(y("one or more")||y("one or many"))p(39,n,n+11);else if(y("one"))p(40,n,n+3);else if(y("only one"))p(40,n,n+8);else if(124===r)p(37,n,n+2);else if(123===r)p(38,n,n+2);else{if(!y("optionally to"))return!1;p(42,n,n+13)}return!0;case 122:if(y("zero or one"))p(37,n,n+11);else{if(!y("zero or more")&&!y("zero or many"))return!1;p(38,n,n+12)}return!0;case 109:if(m("many(0)"))p(38,n,n+7);else if(m("many(1)"))p(39,n,n+7);else{if(!y("many"))return!1;p(38,n,n+4)}return!0;case 116:return!!y("to")&&(p(43,n,n+2),!0);case 117:return(46===r||45===r||124===r)&&(p(41,n,n+1),!0);case 124:if(111!==x(n+1)||Q(e.charCodeAt(n+2)))if(124===r)p(40,n,n+2);else{if(123!==r)return!1;p(39,n,n+2)}else p(37,n,n+2);return!0;case 125:if(111!==x(n+1)||Q(e.charCodeAt(n+2))){if(124!==r)return!1;p(39,n,n+2)}else p(38,n,n+2);return!0;case 46:return(46===r||45===r)&&(p(42,n,n+2),!0);case 45:if(45===r)p(43,n,n+2);else{if(46!==r)return!1;p(42,n,n+2)}return!0}return!1})(t>=65&&t<=90?t+32:t)){if(t>=128||1&Ph[t]){r=n+1;for(let t=e.charCodeAt(r);t>=128||1&Ph[t];t=e.charCodeAt(r))r++;return void p(23,n,r)}p(45,n,n+1)}}},M=r=>{if(q(r)){for(n++;q(e.charCodeAt(n));)n++;return}let a=32|r;if(112!==a&&102!==a&&117!==a||107!=(32|e.charCodeAt(n+1))||Q(e.charCodeAt(n+2))){if(!(()=>{if(-1===c||c<n&&(c=e.indexOf("~",n),-1===c))return!1;if(u<n){let r=n;for(;r<t&&!q(e.charCodeAt(r));)r++;u=r}if(c>=u||(d<n&&(d=w(n),f=e.lastIndexOf("~",d-1)),f<=c))return!1;let r=f+1;for(;r<t&&!q(e.charCodeAt(r));)r++;return p(34,n,r),!0})()){if(jh(r,4)){let r=n+1;for(;r<t&&jh(e.charCodeAt(r),8);)r++;return void p(34,n,r)}if(96===r)return l=2,void n++;if(34===r){let t=e.indexOf('"',n+1);if(-1!==t)return void p(36,n,t+1)}else if(125===r)return l=0,void p(8,n,n+1);p(45,n,n+1)}}else p(35,n,n+2)};for(;n<t;){let s,o=e.charCodeAt(n);switch(l){case 0:b(o);break;case 1:M(o);break;case 2:96===o?(l=1,n++):(s=e.indexOf("`",n),p(34,n,-1===s?t:s));break;case 3:case 4:s=e.indexOf("\n",n),p(3===l?12:14,n,-1===s?t:s),l=0;break;case 5:125===o?(l=0,n++):(s=e.indexOf("}",n),p(15,n,-1===s?t:s));break;case 6:if(10===o){for(s=n+1;10===e.charCodeAt(s);)s++;l=0,p(4,n,s)}else if(q(o))for(n++;q(e.charCodeAt(n));)n++;else if(58===o)p(5,n,n+1);else if(44===o)p(25,n,n+1);else if(35===o)p(30,n,n+1);else if(59===o)p(28,n,n+1);else{if(!(o>=128||2&Ph[o]))return r.push(1),a.push(""),i.push(n),{types:r,texts:a,starts:i};s=n+1;for(let t=e.charCodeAt(s);t>=128||2&Ph[t];t=e.charCodeAt(s))s++;p(24,n,s)}}}let v=0===l?3:3===l?12:4===l?14:5===l?15:-1;return-1!==v&&(r.push(v),a.push(""),i.push(t)),r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}var Xh=new Map([[37,"ZERO_OR_ONE"],[38,"ZERO_OR_MORE"],[39,"ONE_OR_MORE"],[40,"ONLY_ONE"],[41,"MD_PARENT"]]),Kh=["TB","BT","RL","LR"],Zh="'UNICODE_TEXT', 'NUM', 'ENTITY_NAME', 'DECIMAL_NUM', 'ENTITY_ONE'",Qh="'EOF', 'NEWLINE', 'title', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'SUBGRAPH', 'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'CLASSDEF', 'CLASS', 'STYLE', "+Zh;function Jh(e,t){let{types:r,texts:a,starts:i}=Vh(e),l=0,n=t=>{let n=r[l];throw 1===n?c("er",e,i[l],"",!0):c("er",e,i[l],`Expecting ${t}, got '${45===n?a[l]:Wh[n]}'`)},s=e=>(r[l]!==e&&n(`'${Wh[e]}'`),a[l++]),o=()=>{let e=r[l];4!==e&&28!==e&&3!==e&&n("'EOF', 'NEWLINE', 'SEMI'"),l++},h=e=>23===e||31===e||29===e||32===e||33===e,d=()=>{let e=r[l];h(e)||n(Zh);let t=a[l++];return 31===e?t.slice(1,-1):t},f=()=>{let e=[];for(;;){let t=r[l];if(23!==t&&24!==t&&n("'UNICODE_TEXT', 'STYLE_TEXT'"),e.push(a[l++]),25!==r[l])return e;l++}},u=e=>24===e||29===e||5===e||30===e,p=()=>{let e=[];for(;;){u(r[l])||n("'STYLE_TEXT', 'COLON', 'NUM', 'BRKT'");let t=a[l++];for(;u(r[l]);)t+=a[l++];if(e.push(t),25!==r[l])return e;l++}},g=e=>45===r[l]&&a[l]===e,m=()=>{if(7!==r[l])return;if(l++,8===r[l])return void l++;let e=(()=>{let e=[];do{let t=s(34);g("?")&&(t+=a[l++]),34!==r[l]&&n(t.endsWith("?")?"'ATTRIBUTE_WORD'":"'ATTRIBUTE_WORD', '?'");let i={type:t,name:a[l++]};if(35===r[l]){let e=[a[l++]];for(;g(",");)l++,e.push(s(35));i.keys=e}36===r[l]&&(i.comment=a[l++].slice(1,-1)),e.push(i)}while(8!==r[l]);return e.reverse()})();return l++,e},y=()=>{let e,i=d(),o=r[l];if(9===o){l++;let e,a=d();s(10),6===r[l]&&(l++,e=f());let n=m();return t.addEntity(i,a),n&&t.addAttributes(i,n),e&&t.setClass([i],e),[i]}if(6===o&&(l++,e=f(),o=r[l]),Xh.has(o)){let o,h=(()=>{let e=Xh.get(r[l++]),t=r[l];43!==t&&42!==t&&n("'NON_IDENTIFYING', 'IDENTIFYING'");let a=43===t?"IDENTIFYING":"NON_IDENTIFYING";l++;let i=Xh.get(r[l]);return void 0===i?n("'ZERO_OR_ONE', 'ZERO_OR_MORE', 'ONE_OR_MORE', 'ONLY_ONE', 'MD_PARENT'"):(l++,{cardA:i,relType:a,cardB:e})})(),c=d();6===r[l]&&(l++,o=f()),s(5);let u=(()=>{let e=r[l];44!==e&&31!==e&&23!==e&&n("'UNICODE_TEXT', 'ENTITY_NAME', 'WORD'");let t=a[l++];return 23===e?t:t.slice(1,-1)})();return t.addEntity(i),t.addEntity(c),t.addRelationship(i,u,c,h),e&&t.setClass([i],e),o&&t.setClass([c],o),[i,c]}let h=m();return t.addEntity(i),h&&t.addAttributes(i,h),e&&t.setClass([i],e),[i]};s(2);let x=[{id:"",title:"",list:[]}],w=x[0],$=!1;for(;;){let e=r[l];switch(e){case 4:l++;break;case 3:return l++,void($&&n(`'END', ${Qh}`));case 16:{$||n(Qh),l++;let e=t.addSubGraph({text:w.id},w.list,{text:w.title});x.pop(),w=x[x.length-1],$=x.length>1,$&&w.list.push(e);break}case 17:{l++;let e=d(),t=e;if(9===r[l]){for(l++,t=d();h(r[l]);)t+=" "+d();s(10)}o(),w={id:e,title:t,list:[]},x.push(w),$=!0;break}case 11:{l++;let e=s(12).trim();t.setAccTitle(e),$&&w.list.push(e);break}case 13:{l++;let e=s(14).trim();t.setAccDescription(e),$&&w.list.push(e);break}case 15:{let e=a[l++].trim();t.setAccDescription(e),$&&w.list.push(e);break}case 18:case 19:case 20:case 21:{l++;let r=Kh[e-18];$?w.list.push({stmt:"dir",value:r}):t.setDirection(r);break}case 22:{let e=a[l++],r=f(),i=p();o(),t.addClass(r,i),$&&w.list.push(e);break}case 26:{let e=a[l++],r=f();t.setClass(r,f()),$&&w.list.push(e);break}case 27:{let e=a[l++],r=f(),i=p();o(),t.addCssStyles(r,i),$&&w.list.push(e);break}default:{h(e)||n($?`'END', ${Qh}`:Qh);let t=y();if($)for(let e of t)w.list.push(e)}}}}var ec=[];var tc=18;function rc(e,t,r,a,i){let l=(e,l)=>Oe(t-a*e-i*l)+","+Oe(r-i*e+a*l),n=e=>`M${l(e,-5)}L${l(e,5)}`,s=`M${l(0,-6)}L${l(10,0)}L${l(0,6)}`,o=e=>`<circle class="pele-marker" cx="${Oe(t-a*e)}" cy="${Oe(r-i*e)}" r="3.5" fill="var(--_bg)"/>`,h=e=>`<path class="pele-marker" d="${e}"/>`;switch(e){case"only_one":return h(n(6)+n(10));case"zero_or_one":return h(n(6))+o(13.5);case"one_or_more":return h(s+n(13.5));case"zero_or_more":return h(s)+o(14);case"md_parent":return`<path class="pele-marker" d="M${l(0,0)}L${l(6,4)}L${l(12,0)}L${l(6,-4)}Z" fill="var(--_bg)"/>`}return""}var ac=1e6,ic=[],lc=' fill="var(--_s)" stroke="var(--_b)"';function nc(e,t,r){let a=e.er?.[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}function sc(e,t,r,a,i,l=0){let n=e.lines;if(0===n.length)return"";let s=1===n.length&&1===n[0].length?n[0][0]:void 0;if(s&&void 0===s.icon&&void 0===s.math&&s.style===l&&(!l||!s.text.includes(" ")))return`<text${Je(a,l)} x="${Oe(t)}" y="${Oe(r)}">${De(s.text)}</text>`;let o=Qe(e),h=.35*e.size,c=r-h-e.lineHeight/2,d="",f="";for(let l=0;l<n.length;l++){let s=n[l],u=c+Bl(e,l);if(Pl(s)){f+=Fe(Hl(e,l),t+e.widths[l]/2,u,a,i);continue}r=u+h;let p=!1;for(let e of s)void 0!==e.icon&&(p=!0);let g=t,m=!1;for(let t of s){if(void 0!==t.icon){let a=1.1*e.size;f+=`<svg class="pele-icon" data-icon="${Re(t.icon)}" x="${Oe(g)}" y="${Oe(r-.35*e.size-a/2)}" width="${Oe(a)}" height="${Oe(a)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${i?.(t.icon)??""}</svg>`}else if(""!==t.text){d+=`<tspan${p||!m?` x="${Oe(g)}" y="${Oe(r)}"`:""}${Ze(t.style&~o)}>${De(t.text)}</tspan>`,m=!0}g+=t.width}}return`<text${Je(a,o)} xml:space="preserve">${d}</text>${f}`}function oc(e){let t=Vo(e);return t===e?e:t.replace(/</g,"&lt;").replace(/>/g,"&gt;")}function hc(e,t,r,a){let i=function(e){let t=[],r=[],a=e.subgraphs,i=t=>{let r=[];for(let a of t){let t=e.classes.get(a);if(void 0!==t){for(let e of t.styles)r.push(e.trim());for(let e of t.textStyles)r.push(e.trim())}}return r},l=new Map,n=new Set;for(let e=a.length-1;e>=0;e--){let t=a[e];n.add(t.id);for(let e of t.nodes)l.set(e,t.id)}for(let e=a.length-1;e>=0;e--){let r=a[e];t.push({id:r.id,label:r.title,alias:"",attributes:ec,isGroup:!0,parentId:l.get(r.id),cssStyles:r.cssStyles,cssCompiledStyles:i(r.classes),cssClasses:r.classes.join(" "),dir:r.dir,labelType:r.labelType})}let s=new Map;for(let[r,a]of e.entities)n.has(r)?s.set(a.id,r):t.push({id:a.id,label:a.label,alias:a.alias,attributes:a.attributes,isGroup:!1,parentId:l.get(r),cssStyles:a.cssStyles,cssCompiledStyles:i(a.cssClasses.split(" ")),cssClasses:a.cssClasses,dir:void 0,labelType:"markdown"});return e.relationships.forEach((e,t)=>{r.push({id:`id_${e.entityA}_${e.entityB}_${t}`,start:s.get(e.entityA)??e.entityA,end:s.get(e.entityB)??e.entityB,label:e.roleA,arrowTypeStart:e.relSpec.cardB.toLowerCase(),arrowTypeEnd:e.relSpec.cardA.toLowerCase(),pattern:"IDENTIFYING"===e.relSpec.relType?"solid":"dashed"})}),{nodes:t,edges:r}}(e),l=Array.isArray(r.monospace)&&r.monospace.includes("attributes"),n=r.fontSize??16,s=Math.round(.875*n),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=r.icons,d=new Map,f=[],u=[];i.nodes.forEach((e,t)=>d.set(e.id,t));let p=[],g=[],y=[],x=new Map,w=[];for(let e of i.edges){let t=d.get(e.start),r=d.get(e.end);if(void 0===t||void 0===r)continue;let a,i=Fl(e.label,!0,o,s,200);if(t===r){a={label:i,band:0,at:0};let e=x.get(t);e?e.push(a):x.set(t,[a])}w.push(a),y.push(e),g.push(i),p.push({src:t,dst:r,minlen:1,labelW:i.width>0?i.width+12:0,labelH:i.height>0?i.height+4:0,route:[],labelX:0,labelY:0})}let $=t=>{let r=t;for(let e=0;e<i.nodes.length;e++){let e=i.nodes[r].parentId,t=void 0===e?void 0:d.get(e);if(void 0===t)break;let a=i.nodes[t].dir;if(a)return"LR"===a||"RL"===a;r=t}return"LR"===e.direction||"RL"===e.direction};for(let e=0;e<i.nodes.length;e++){let t=i.nodes[e],r=Ri(t.cssStyles.length>0?t.cssCompiledStyles.concat(t.cssStyles):t.cssCompiledStyles),a=(r.bold?1:0)|(r.italic?2:0),h=l&&!/[";]font-family:/.test(r.text)?4:0,c=r.fontSize??n,d=r.fontSize??s,p=r.fontSize??Math.round(.75*n),g=t.isGroup?Fl(t.label,!0,o,c,4e3,a):Fl(t.alias||t.label,!0,o,c,240,a),m=x.get(e)??ic,y=m.length>0&&!t.isGroup&&$(e),w={node:t,style:r,label:g,w:0,h:0,headH:0,rows:[],cols:[],rowSize:d,keySize:p,mono:h,below:y},b=0,M=0;for(let e of m)e.band=Math.max(38,y?e.label.width+12:e.label.height+6),M+=e.band,b=Math.max(b,y?e.label.height:e.label.width);let v,k=Math.max(96,y?M+8:0);if(t.isGroup)v=Va(0,0),v.isGroup=!0,v.dir=t.dir?Pa(t.dir):void 0,v.padX=20,v.padTop=w.label.height>0?w.label.height+16:20,v.padBottom=20,v.minW=Math.max(w.label.width+40-12,96);else{let e=Math.max(g.height,Math.round(1.5*c));if(0===t.attributes.length)w.w=Math.max(g.width+36,k),w.h=Math.max(e+24,y?0:M+8);else{let r=Math.round(1.5*d),i=[0,0,0,0];for(let e of t.attributes){let t=[Fl(oc(e.type),!0,o,d,ac,a|h),Fl(oc(e.name),!0,o,d,ac,a|h),Fl(e.keys.join(", "),!1,o,p,ac,a|h),Fl(oc(e.comment),!0,o,d,260,a)],l=r;for(let e=0;e<4;e++)t[e].width>i[e]&&(i[e]=t[e].width),t[e].height>l&&(l=t[e].height);w.rows.push({cells:t,h:l+9}),w.h+=l+9}let l=0,n=0;for(let e of i)0!==e&&(n+=e+(l>0?16:0),l++);w.w=Math.max(n+24,g.width+36,k);let s=l>0?(w.w-n-24)/l:0,c=12;for(let e of i)w.cols.push(c),e>0&&(c+=e+s+16);w.headH=e+18,w.h+=w.headH}let r=m.length>0?2*(49+b):0;v=y?Va(w.w,w.h+r):Va(w.w+r,w.h)}v.seq=f.length,f.push(w),u.push(v)}i.nodes.forEach((e,t)=>{u[t].parent=void 0!==e.parentId?d.get(e.parentId)??-1:-1});let b=Za(u,p,a?"TB":Pa(e.direction),{nodeSep:nc(t,"nodeSpacing",48),edgeSep:20,rankSep:nc(t,"rankSpacing",64),portSep:24});!function(e,t,r){let a=new Map,i=(e,r,i,l)=>{let n,s=t[e],o=r[i]-s.x,h=r[i+1]-s.y;if(Math.abs(Math.abs(h)-s.h/2)<.5)n=h<0?0:2;else{if(!(Math.abs(Math.abs(o)-s.w/2)<.5))return;n=o<0?3:1}let c=4*e+n,d={route:r,at:i,toward:r[l+(1&n?1:0)]},f=a.get(c);f?f.push(d):a.set(c,[d])};for(let t of e){let e=t.route.length-3;t.src===t.dst||e<3||(i(t.src,t.route,0,3),i(t.dst,t.route,e,e-3))}for(let[e,i]of a){if(i.length<2)continue;let a=e>>2,l=!(1&~e),n=t[a].isGroup?t[a]:r[a],s=l?n.h:n.w,o=Math.max(Math.min(18,(s-28)/(i.length-1)),0),h=l?t[a].y:t[a].x;i.sort((e,t)=>e.toward-t.toward);for(let e=0;e<i.length;e++)i[e].route[i[e].at+(l?1:0)]=h+(e-(i.length-1)/2)*o}}(p,u,f);let M=b.width;for(let[e,t]of x){let r=u[e];if(!r.isGroup)continue;let a=0;for(let e of t)a=Math.max(a,e.label.width);M=Math.max(M,r.x+r.w/2+tc+21+10+a)}let v=gs(e.title,o,n,4e3),k=v.height>0?v.height+12:0,A=Math.max(M,v.width);ja(u,p,h+(A-M)/2,h+k);let T=Math.ceil(A+2*h),C=Math.ceil(b.height+k+2*h),E=[],_=new Map,S=!1;for(let e of u)e.isGroup&&(S=!0);if(S)for(let e of p)Qa(_,e.route);let I="",N=[],D="";for(let e=0;e<f.length;e++){let t=f[e],a=u[e],i=t.node,l=Oi(i.cssClasses.replace(/^default\s?/,""));if(a.isGroup){t.w=a.w,t.h=a.h;let e=a.x-a.w/2,r=a.y-a.h/2,n=Ja(a,t.label.width,_,20);yt(t.style.shape)&&N.push({box:[e,r,e+a.w,r+a.h],shape:t.style.shape}),I+=`<g class="pele-cluster${l}" data-id="${Re(i.id)}"><rect x="${Oe(e)}" y="${Oe(r)}" width="${Oe(a.w)}" height="${Oe(a.h)}" fill="var(--_a)"${ki(t.style.shape)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${Ai(t.style.shape)}/>`+Fe(t.label,n,r+8+t.label.height/2,` class="pele-cluster-label"${xt(t.style,"var(--_m)")}${t.style.text}`,c)+"</g>";continue}let n,s=t.w,o=t.h,h=-s/2,d=-o/2,p=t.style.text,g=xt(t.style),y=g||' fill="var(--_m)"',x=`x="${Oe(h)}" y="${Oe(d)}" width="${Oe(s)}" height="${Oe(o)}"`,w=Fe(t.label,0,t.rows.length>0?d+t.headH/2:0,` class="pele-label"${g}${p}`,c),$=m(i.alias||i.label);if(/ internal-link(?: |$)/.test(l+" ")&&""!==w&&!1!==r.links){let e=br($,r),t=De($);w=`<a class="internal-link"${e?` href="${t}"${vr(r)}`:""} data-href="${t}">${w}</a>`,E.push({id:i.label,href:$,internal:!0})}if(0===t.rows.length)n=`<rect ${x}${Ai(lc+t.style.shape)}/>`+w;else{let e=Math.round(1.5*t.rowSize),r=t.style.stroke?De(t.style.stroke):"var(--_b)",a="",i="",l=d+t.headH;for(let r=0;r<t.rows.length;r++){let n=t.rows[r];if(r%2==0){let e=`x="${Oe(h)}" width="${Oe(s)}"`;r===t.rows.length-1?a+=`<rect ${e} y="${Oe(l)}" height="${Oe(n.h)}"${Mi}/><rect ${e} y="${Oe(l)}" height="${Oe(n.h/2)}"/>`:a+=`<rect ${e} y="${Oe(l)}" height="${Oe(n.h)}"/>`}let o=l+4.5+e/2+.35*t.rowSize,[d,f,u,m]=n.cells;i+=sc(d,h+t.cols[0],o,` class="pele-er-type"${y}${p}`,c,t.mono)+sc(f,h+t.cols[1],o,` class="pele-er-name"${g}${p}`,c,t.mono)+sc(u,h+t.cols[2],o,` class="pele-er-keys" font-size="${t.keySize}"${y}${p}`,c,t.mono)+sc(m,h+t.cols[3],o,` class="pele-er-comment"${y}${p}`,c),l+=n.h}let o=Oe(d+t.headH),f=mt(t.style.shape),u=f===rt?at:f===at?rt:"var(--_bg)";n=`<rect ${x}${Ai(lc+t.style.shape)}/><g class="pele-er-stripes" fill="${u}"${t.style.shape.includes("fill:")?' opacity="0.6"':""}>${a}</g><path class="pele-er-divider" d="M${Oe(h)},${o}H${Oe(h+s)}" stroke="${r}"/><rect ${x} fill="none" stroke="var(--_b)"${Ai(t.style.line)}/>`+w+`<g class="pele-er-attributes" font-size="${t.rowSize}">${i}</g>`}D+=`<g class="pele-node pele-entity${l}" data-id="${Re(i.label)}" transform="translate(${Oe(a.x)},${Oe(a.y)})">${n}</g>`}for(let[e,t]of x){let r=f[e],a=0;for(let e of t)a+=e.band;let i=Math.min(1,Math.max((r.below?r.w:r.h)-8,0)/a),l=-a*i/2;for(let e of t)e.band*=i,e.at=l+e.band/2,l+=e.band}let R="",L="",O="";for(let e=0;e<p.length;e++){let t,r,a,i=p[e],l=y[e],n=g[e],s=w[e];if(s){let e=u[i.src],o=f[i.src],h=Math.max(Math.min(s.band/2-6,13),1),c=45;if(o.below){let d=e.x+s.at,f=e.y+o.h/2,u=Oe(f+tc),p=Oe(f+tc+28);t=`M${Oe(d-h)},${Oe(f)}V${u}C${Oe(d-h)},${p} ${Oe(d+h)},${p} ${Oe(d+h)},${u}V${Oe(f)}`,r=rc(l.arrowTypeStart,d-h,f,0,-1),a=rc(l.arrowTypeEnd,d+h,f,0,-1),i.labelX=d,i.labelY=f+c+n.height/2}else{let d=e.x+o.w/2,f=e.y+s.at,u=Oe(d+tc),p=Oe(d+tc+28);t=`M${Oe(d)},${Oe(f-h)}H${u}C${p},${Oe(f-h)} ${p},${Oe(f+h)} ${u},${Oe(f+h)}H${Oe(d)}`,r=rc(l.arrowTypeStart,d,f-h,-1,0),a=rc(l.arrowTypeEnd,d,f+h,-1,0),i.labelX=d+c+n.width/2,i.labelY=f}}else{let e=cc(i.route);if(e.length<6)continue;dc(e,0,f[i.src],u[i.src]),dc(e,e.length-3,f[i.dst],u[i.dst]);let n=Math.abs(e[e.length-3]-e[0]),s=Math.abs(e[e.length-2]-e[1]),o=6===e.length&&(n<.01||s<.01||Math.hypot(n,s)<=54)?0:tc,h=ai(e,void 0,o,o);t=o>0?`M${Oe(h.sx)},${Oe(h.sy)}L${h.d.slice(1)}L${Oe(h.ex)},${Oe(h.ey)}`:h.d,r=rc(l.arrowTypeStart,h.sx,h.sy,h.sdx,h.sdy),a=rc(l.arrowTypeEnd,h.ex,h.ey,h.edx,h.edy)}let o=fi(t,[],N),h=o&&ui(o);""===h&&(L+=mi(t,r+a)),o&&h&&(r=pi(r,o),a=pi(a,o));let d="dashed"===l.pattern;if(R+=`<g class="pele-edge pele-er-${d?"non-identifying":"identifying"}" data-id="${Re(l.id)}"${h?` stroke="${h}"`:""}><path d="${t}"${d?' stroke-dasharray="4 3"':""}/>`+r+a+"</g>",n.width>0){let e=i.labelX,t=i.labelY;O+=wi(l.id,n,e,t,"",c)}}return{svg:Bi("er",T,C,n,r,e,Fe(v,T/2,h+v.height/2,' class="pele-title" font-weight="var(--_tw)"')+(I?`<g class="pele-clusters">${I}</g>`:"")+xi(L)+(R?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${R}</g>`:"")+(O?`<g class="pele-edge-labels" font-size="${s}">${O}</g>`:"")+`<g class="pele-nodes">${D}</g>`),width:T,height:C,links:E}}function cc(e){let t=e.slice(0,3);for(let r=3;r<e.length;r+=3){let a=t.length-3,i=i=>Math.abs(t[a+i]-e[r+i])<.01&&Math.abs(e[r+i]-e[r+3+i])<.01;r+3<e.length&&(i(0)||i(1))||t.push(e[r],e[r+1],e[r+2])}return t}function dc(e,t,r,a){if(a.isGroup)return;let i=e[t]-a.x,l=e[t+1]-a.y;a.w!==r.w&&Math.abs(Math.abs(i)-a.w/2)<.5&&(e[t]-=Math.sign(i)*(a.w-r.w)/2),a.h!==r.h&&Math.abs(Math.abs(l)-a.h/2)<.5&&(e[t+1]-=Math.sign(l)*(a.h-r.h)/2)}var fc={type:"er",math:!0,parse(e,t,r){let a=new zh;return r&&(a.title=r),Jh(e,a),a},render:function(e,t,r){return jl(e.direction)?ql(r,a=>hc(e,t,r,a)):hc(e,t,r,!1)}},uc=new Map([["ui","ui"],["pcr","processor"],["processor","processor"],["rmo","readmodel"],["readmodel","readmodel"],["cmd","command"],["command","command"],["evt","event"],["event","event"]]),pc=new Map([["trigger",[0,"UI/Automation","UI/A: "]],["state",[100,"Command/Read Model","C/RM: "]],["stream",[200,"Events","Stream: "]]]);function gc(e){let t=e.indexOf("{"),r=e.lastIndexOf("}"),a=(-1!==t&&r>t?e.slice(t+1,r):-1===t&&e.length>=2?e.slice(1,-1):"").replace(/\r/g,"").split("\n");for(;a.length>0&&""===a[0].trim();)a.shift();for(;a.length>0&&""===a[a.length-1].trim();)a.pop();let i=1/0;for(let e of a)""!==e.trim()&&(i=Math.min(i,e.length-e.trimStart().length));return a.map(e=>e.slice(Math.min(i,e.length)).trimEnd()).join("\n")}var mc=/[\t ]*accDescr(?:[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)|\s*({))/y;function yc(){let e=!1;return(t,r)=>{mc.lastIndex=r;let a=mc.exec(t);if(null===a)return-1;let i=mc.lastIndex;if(void 0===a[1])return i;if(e)return-1;let l=t.indexOf("}",i);return e=-1===l,l+1||-1}}function xc(e="ACC_DESCR"){return{...un,name:e,scanner:yc}}var wc={name:"EM_ID",pattern:/[_a-zA-Z][\w_]*/y},$c=e=>({name:e,pattern:e,longer:[wc]}),bc=e=>({name:e,pattern:e}),Mc=[{...vn("eventmodeling"),longer:[wc]},...["resetframe","readmodel","processor","timeframe","command","entity","event","jsobj","figma","given","json","salt","html","text","data","note","when","then","rmo","cmd","evt","pcr","uri"].map($c),bc("->>"),$c("gwt"),$c("ui"),$c("md"),$c("tf"),bc("[["),bc("]]"),$c("rf"),bc("`"),bc("."),wc,{name:"EM_FID",pattern:/\d{1,3}/y},{name:"EM_DATA_INLINE",pattern:/\{(.*)\}|"(.*)"|'(.*)'/y},{name:"EM_DATA_BLOCK",pattern:/\{[\t ]*\r?\n(?:[\S\s]*?\r?\n)?\}(?:\r?\n|(?!\S))/y},xc("EM_ACC_DESCR"),{...pn,name:"EM_ACC_TITLE"},{...mn(String.raw`\w`),name:"EM_TITLE"},{name:"EM_WS",pattern:/\s+/y,hidden:!0},{...$n,name:"EM_YAML"},{...bn,name:"EM_DIRECTIVE"},{...Mn,name:"EM_SINGLE_LINE_COMMENT"},{name:"EM_ML_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0},{name:"EM_SL_COMMENT",pattern:/\/\/[^\n\r]*/y,hidden:!0}],vc=e=>Mc.findIndex(t=>t.name===e),kc=e=>new Set(e.map(vc)),Ac={keyword:0,arrow:vc("->>"),open:vc("[["),close:vc("]]"),tick:vc("`"),dot:vc("."),id:vc("EM_ID"),frameId:vc("EM_FID"),inline:vc("EM_DATA_INLINE"),block:vc("EM_DATA_BLOCK"),accDescr:vc("EM_ACC_DESCR"),accTitle:vc("EM_ACC_TITLE"),title:vc("EM_TITLE"),entity:vc("entity"),data:vc("data"),note:vc("note"),gwt:vc("gwt"),given:vc("given"),when:vc("when"),then:vc("then")},Tc=kc(["tf","timeframe"]),Cc=kc(["rf","resetframe"]),Ec=kc(["rmo","readmodel","ui","cmd","command","evt","event","pcr","processor"]),_c=kc(["json","jsobj","figma","salt","uri","md","html","text"]);var Sc=new Map([["command",0],["event",1],["readmodel",2],["processor",6]]),Ic=12,Nc=10,Dc=12;function Rc(e,t){let r=[];for(let a of m(e).split("\n")){let e=a.length<=t?void 0:Array.from(a);if(void 0===e||e.length<=t)r.push(a);else for(let a=0;a<e.length;a+=t)r.push(e.slice(a,a+t).join(""))}return r}function Lc(e,t,r,a,i){let l="";for(let i=0;i<e.length;i++)""!==e[i]&&(l+=`<tspan x="${Oe(t)}" y="${Oe(r+i*a)}">${De(e[i])}</tspan>`);return""===l?"":`<text${i} xml:space="preserve">${l}</text>`}var Oc=8,Fc=120,zc=20;var Wc={type:"eventmodeling",keepComments:!0,parse:(e,t,r)=>function(e,t){let r=new Set;for(let t of e.frames){if(r.has(t.name)){let r=h(e.$source,t.$offset).line;throw new i(`Duplicate event modeling frame ID "${t.name}" on line ${r}`,"semantic",{type:"eventmodeling",line:r})}r.add(t.name)}let a=new Map;for(let t of e.dataEntities)a.has(t.name)||a.set(t.name,t.dataBlockValue);let l=new Map,n=new Map,s=(e,t)=>{let r=function(e){return"ui"===e||"processor"===e?"trigger":"event"===e?"stream":"state"}(e),a=void 0===t?r:`${r} ${t}`,i=l.get(a);if(!i){let[e,s,o]=pc.get(r),h=e;void 0!==t&&(h=n.get(r)??e+1,n.set(r,h+1)),i={index:h,label:void 0===t?s:o+t,group:r,namespace:t},l.set(a,i)}return i},o=[],c=new Map,d=[];e.frames.forEach((e,t)=>{let r=e.entityIdentifier.split("."),i=2===r.length?r[0]:void 0,l=uc.get(e.modelEntityType)??"event",n=void 0===e.dataInlineValue?void 0:gc(e.dataInlineValue);if(e.dataReference){let t=a.get(e.dataReference.$refText);void 0!==t&&(n=gc(t))}let h={id:e.name,kind:l,entity:e.entityIdentifier,name:2===r.length?r[1]:e.entityIdentifier,namespace:i,reset:"EmResetFrame"===e.$type,lane:s(l,i),data:n,dataType:e.dataType};if(o.push(h),c.set(h.id,h),e.sourceFrames.length>0){let t=new Set(e.sourceFrames.map(e=>e.$refText));for(let e of o)t.has(e.id)&&d.push({source:e,target:h})}else if(t>0&&!h.reset)for(let e=t-1;e>=0;e--)if(o[e].lane!==h.lane){d.push({source:o[e],target:h});break}});let f=e=>e.map(e=>e.entityIdentifier.$refText);return{type:"eventmodeling",title:e.title&&En(e.title)||t,accTitle:e.accTitle?_n(e.accTitle).replace(/^\s+/g,""):void 0,accDescr:e.accDescr?Sn(e.accDescr).replace(/\n\s+/g,"\n"):void 0,boxes:o,lanes:[...l.values()].sort((e,t)=>e.index-t.index),relations:d,notes:e.noteEntities.map(e=>({frame:e.sourceFrame.$refText,text:gc(e.dataBlockValue),dataType:e.dataType})),specifications:e.gwtEntities.map(e=>({frame:e.sourceFrame.$refText,given:f(e.givenStatements),when:f(e.whenStatements),then:f(e.thenStatements)})),entities:e.modelEntities.map(e=>e.name)}}(function(e){let t=new Dn(fn(e,Mc,"eventmodeling"),Mc,"eventmodeling"),r={$type:"EventModel",modelEntities:[],frames:[],dataEntities:[],noteEntities:[],gwtEntities:[],$source:e},a=e=>t.kinds[t.i]===e,i=(e,r)=>e.has(t.kinds[t.i])?t.take():t.fail(r),l=()=>{let e=t.expect(Ac.id);for(;t.accept(Ac.dot);)e+="."+t.expect(Ac.id);return e},n=()=>{if(!t.accept(Ac.tick))return;let e=i(_c,"a data type");return t.expect(Ac.tick),e},s=()=>{let e=[];do{i(Ec,"an entity type"),e.push({$type:"EmGwtStatement",entityIdentifier:{$refText:t.expect(Ac.id)}})}while(Ec.has(t.kinds[t.i]));return e};for(t.expect(Ac.keyword);!a(-1);){let e=t.kinds[t.i];if(e===Ac.accDescr)r.accDescr=t.take();else if(e===Ac.accTitle)r.accTitle=t.take();else if(e===Ac.title)r.title=t.take();else if(e===Ac.entity)t.i++,r.modelEntities.push({$type:"EmModelEntity",name:l()});else if(Tc.has(e)||Cc.has(e)){let s={$type:Tc.has(e)?"EmTimeFrame":"EmResetFrame",name:"",modelEntityType:"",entityIdentifier:"",sourceFrames:[],$offset:t.tokens.starts[t.i]};for(t.i++,s.name=t.expect(Ac.frameId),s.modelEntityType=i(Ec,"an entity type"),s.entityIdentifier=l();t.accept(Ac.arrow);)s.sourceFrames.push({$refText:t.expect(Ac.frameId)});if(t.accept(Ac.open)&&(s.dataReference={$refText:t.expect(Ac.id)},t.expect(Ac.close)),a(Ac.tick)||a(Ac.inline)){let e=n();void 0!==e&&(s.dataType=e),s.dataInlineValue=t.expect(Ac.inline)}r.frames.push(s)}else if(e===Ac.data){t.i++;let e={$type:"EmDataEntity",name:t.expect(Ac.id),dataBlockValue:""},a=n();void 0!==a&&(e.dataType=a),e.dataBlockValue=t.expect(Ac.block),r.dataEntities.push(e)}else if(e===Ac.note){t.i++;let e={$type:"EmNoteEntity",sourceFrame:{$refText:t.expect(Ac.frameId)},dataBlockValue:""},a=n();void 0!==a&&(e.dataType=a),e.dataBlockValue=t.expect(Ac.block),r.noteEntities.push(e)}else if(e===Ac.gwt){t.i++;let e={$type:"EmGwt",sourceFrame:{$refText:t.expect(Ac.frameId)},givenStatements:[],whenStatements:[],thenStatements:[]};t.expect(Ac.given),e.givenStatements=s(),t.accept(Ac.when)&&(e.whenStatements=s()),t.expect(Ac.then),e.thenStatements=s(),r.gwtEntities.push(e)}else t.fail("a frame, an entity, a data block, a note, or a specification")}return r}(e),r),render:function(e,t,r){return ql(r,t=>function(e,t,r,a){if(a)return function(e,t){let r=t.fontSize??16,a=Math.round(.875*r),i=Math.round(.75*r),l=t.padding??8,n=t.measurer??Ce(t.fontFamily,t.fontFamilyMono),s=Math.max(160,(t.maxWidth??320)-2*l),o=new Map(e.boxes.map((e,t)=>[e,t])),h=new Map,c=new Set;for(let t of e.relations){let r=o.get(t.source),a=o.get(t.target);if(void 0===r||void 0===a||r===a)continue;if(Math.abs(r-a)<2){c.add(e.boxes[Math.max(r,a)]);continue}let i=h.get(t.target);i?(i[0]=Math.min(i[0],r),i[1]=Math.max(i[1],r)):h.set(t.target,[Math.min(r,a),Math.max(r,a)])}let d=new Map,f=[];for(let[e,[t,r]]of[...h].sort((e,t)=>e[1][0]-t[1][0])){let a=f.findIndex(e=>e<t);a<0&&(a=f.length),f[a]=r,d.set(e,a)}let u=24+Oc*Math.max(0,f.length-1),p=Math.max(Fc,s-u),g=p-24,y=Fl(e.title,!1,n,r,s,1),x=l+(y.height?y.height+12:0),w=l+y.height,$=Math.max(y.width,p+u),b="",M="",v="",k=new Map,A=(e,t,r=0)=>$o(m(e),n,t,g,r);e.boxes.forEach((e,t)=>{let r=c.has(e)?g-zc:g,s=bo(Fl(e.lane.label,!1,n,a,r,1),n,r),o=Fl(e.name,!1,n,a,g-36,1),h=e.data?A(e.data,i,4):void 0,d=Math.max(p,s.width+24,o.width+24+36,(h?.width??0)+24),f=s.height+12,m=20+o.height+(h?h.height+6:0),y=Sc.get(e.kind),M=x+f,v=`x="${Oe(l)}" y="${Oe(M)}" width="${Oe(d)}" height="${Oe(m)}"`;b+=`<g class="pele-cluster pele-em-lane" data-id="${Re(e.lane.label)}">`+Mo(s,l+Ic,x,` class="pele-cluster-label" font-size="${a}" font-weight="var(--_hw)" fill="var(--_m)"`)+`<g class="pele-node pele-em-${e.kind}${e.reset?" pele-em-reset":""}" data-id="${Re(e.id)}"><rect ${v} fill="var(--_bg)" stroke="var(--_b)"${Mi}/>`+(void 0===y?"":`<rect ${v} fill="${zi(y)}" fill-opacity="0.22" stroke="${zi(y)}"${Mi}/>`)+Fe(o,l+Ic+o.width/2,M+Nc+o.height/2,` class="pele-label" font-size="${a}" font-weight="var(--_hw)"`)+`<text class="pele-em-frame" x="${Oe(l+d-Ic)}" y="${Oe(M+Nc+a)}" text-anchor="end" font-size="${i}" fill="var(--_m)">${De(e.id)}</text>`+(h?Lc(h.lines.map(e=>e.map(e=>e.text).join("")),l+Ic,M+Nc+o.height+6+h.lineHeight/2+.35*i,h.lineHeight,` class="pele-em-data" font-family="${bi}" font-size="${i}"`):"")+"</g></g>",k.set(e,{y:M,h:m,w:d,index:t,lane:s.width}),$=Math.max($,d+u),w=M+m,x=w+28});for(let t of e.relations){let e=k.get(t.source),r=k.get(t.target);if(!e||!r||e===r)continue;let a,i,n=r.y>e.y,s=n?1:-1,o=n?e.y+e.h:e.y,h=n?r.y:r.y+r.h;if(1===Math.abs(e.index-r.index)){let t=l+Math.max(Math.min(e.w,r.w)/2,Ic+(n?r:e).lane+16);a=`M${Oe(t)},${Oe(o)}V${Oe(h-s*ii("arrow_point"))}`,i=li("arrow_point",t,h,0,s,"var(--_l)")}else{let n=l+$-u+12+Oc*(d.get(t.target)??0),s=e.y+e.h/2-5,o=r.y+r.h/2+5;a=`M${Oe(l+e.w)},${Oe(s)}H${Oe(n)}V${Oe(o)}H${Oe(l+r.w+ii("arrow_point"))}`,i=li("arrow_point",l+r.w,o,-1,0,"var(--_l)")}M+=`<g class="pele-edge" data-id="${Re(t.source.id)}-${Re(t.target.id)}"><path d="${a}" fill="none" stroke="var(--_l)"/>${i}</g>`}let T=new Map(e.boxes.map(e=>[e.id,e.name])),C=(e,t,r,i)=>{let s=Fl(`${t} · ${r}${T.has(r)?" "+T.get(r):""}`,!1,n,a,g,1),o=A(i,a),h=Math.max(p,s.width+24,o.width+24),c=20+s.height+o.height;v+=`<g class="pele-em-${e}" data-id="${Re(r)}"><rect x="${Oe(l)}" y="${Oe(x)}" width="${Oe(h)}" height="${Oe(c)}" fill="var(--_bg)" stroke="var(--_b)"${Mi}/>`+Fe(s,l+Ic+s.width/2,x+Nc+s.height/2,` font-size="${a}" font-weight="var(--_hw)"`)+Lc(o.lines.map(e=>e.map(e=>e.text).join("")),l+Ic,x+Nc+s.height+o.lineHeight/2+.35*a,o.lineHeight,` font-size="${a}"`)+"</g>",w=x+c,x=w+8,$=Math.max($,h)};for(let t of e.notes)C("note","Note",t.frame,t.text);for(let t of e.specifications){let e=[`Given ${t.given.join(", ")}`];t.when.length&&e.push(`When ${t.when.join(", ")}`),e.push(`Then ${t.then.join(", ")}`),C("specification","Given / When / Then",t.frame,e.join("\n"))}let E=Math.ceil($+2*l),_=Math.ceil(w+l),S=Fe(y,E/2,l+y.height/2,' class="pele-title" font-weight="var(--_tw)"')+M+b+v;return{svg:Bi("eventmodeling",E,_,r,t,e,S),width:E,height:_,links:[]}}(e,r);let i=r.fontSize??16,l=Math.round(.875*i),n=Math.round(.8125*i),s=Math.round(.75*i),o=Math.round(1.4*s),h=Math.round(1.5*n),c=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),d=r.padding??8,f=(e,t,r)=>{let a=0;for(let i of e)a=Math.max(a,c.width(i,t,r));return a},u=new Map,p=0;for(let t of e.lanes){let e=Fl(t.label,!1,c,n,4e3,1);p=Math.max(p,e.width),u.set(t,{lane:t,label:e,right:-1/0,y:0,h:0})}p+=24;let g,y=[],x=new Map;for(let t of e.boxes){let e=u.get(t.lane),r=Fl(t.name,!1,c,l,4e3,1),a=t.data?Rc(t.data,48):[],i=Math.max(96,Math.max(r.width,f(a,s,4))+24),n=20+r.height+(a.length>0?6+a.length*o:0),h=0;if(g){let r=g.x+Math.max(g.w/2,g.w-80);h=g.box.lane===t.lane?e.right+16:Math.max(r,e.right+16)}let d={box:t,name:r,data:a,x:h,y:0,w:i,h:n};e.right=h+i,e.h=Math.max(e.h,n),y.push(d),x.set(t,d),g=d}let w=0;for(let e of y)w=Math.max(w,e.x+e.w);let $=p+w+Dc,b=Fl(e.title,!1,c,i,4e3,1),M=b.height>0?b.height+12:0,v=d,k=d+M,A=k,T="";for(let e of u.values())e.y=A,e.h+=24,T+=`<g class="pele-cluster pele-em-lane" data-id="${Re(e.lane.label)}"><rect x="${Oe(v)}" y="${Oe(A)}" width="${Oe($)}" height="${Oe(e.h)}" fill="var(--_s)"${Mi}/>`+Fe(e.label,v+Dc+e.label.width/2,A+e.h/2,` class="pele-cluster-label" font-size="${n}" font-weight="var(--_hw)" fill="var(--_m)"`)+"</g>",A+=e.h+8;let C=u.size>0?A-8:k,E="";for(let e of y){let t=u.get(e.box.lane);e.x+=v+p,e.y=t.y+(t.h-e.h)/2;let r=Sc.get(e.box.kind),a=`x="${Oe(e.x)}" y="${Oe(e.y)}" width="${Oe(e.w)}" height="${Oe(e.h)}"`,i=void 0===r?`<rect ${a} fill="var(--_bg)" stroke="var(--_b)"${Mi}/>`:`<rect ${a} fill="var(--_bg)"${Mi}/><rect ${a} fill="${zi(r)}" fill-opacity="0.22" stroke="${zi(r)}"${Mi}/>`,n=e.y+Nc+e.name.height/2,h=Fe(e.name,e.x+e.w/2,n,` class="pele-label" font-size="${l}" font-weight="var(--_hw)"`)+Lc(e.data,e.x+Ic,e.y+Nc+e.name.height+6+o/2+.35*s,o,` class="pele-em-data" font-family="${bi}" font-size="${s}"`);E+=`<g class="pele-node pele-em-${e.box.kind}${e.box.reset?" pele-em-reset":""}" data-id="${Re(e.box.id)}">${i}${h}</g>`}let _="",S=ii("arrow_point");for(let t of e.relations){let e,r,a=x.get(t.source),i=x.get(t.target);if(a&&i&&a!==i){if(a.box.lane===i.box.lane){let t=i.x>=a.x,l=t?a.x+a.w:a.x,n=t?i.x:i.x+i.w,s=a.y+a.h/2,o=i.y+i.h/2,h=n>=l?1:-1;e=`M${Oe(l)},${Oe(s)}L${Oe(n-h*S)},${Oe(o)}`,r=li("arrow_point",n,o,h,0,"var(--_l)")}else{let t=i.y>a.y,l=Math.max(a.x,i.x),n=Math.min(a.x+a.w,i.x+i.w),s=e=>Math.min(24,e/4),o=n-l>=16?(l+n)/2:i.x>a.x?a.x+a.w-s(a.w):a.x+s(a.w),h=n-l>=16?o:i.x>a.x?i.x+s(i.w):i.x+i.w-s(i.w),c=t?a.y+a.h:a.y,d=t?i.y:i.y+i.h,f=t?1:-1,u=d-f*S,p=(c+u)/2;e=o===h?`M${Oe(o)},${Oe(c)}V${Oe(u)}`:`M${Oe(o)},${Oe(c)}C${Oe(o)},${Oe(p)} ${Oe(h)},${Oe(p)} ${Oe(h)},${Oe(u)}`,r=li("arrow_point",h,d,0,f,"var(--_l)")}_+=`<g class="pele-edge" data-id="${Re(t.source.id)}-${Re(t.target.id)}"><path d="${e}" fill="none" stroke="var(--_l)"/>${r}</g>`}}let I=new Map;for(let t of e.boxes)I.set(t.id,t.name);let N="",D=0,R=(e,t,r,a)=>{let i=Fl(`${t} · ${r}${I.has(r)?" "+I.get(r):""}`,!1,c,n,4e3,1),l=Math.max(i.width,f(a,n,0))+24,s=20+i.height+a.length*h,o=C+(""===N&&0===u.size?0:8);N+=`<g class="pele-em-${e}" data-id="${Re(r)}"><rect x="${Oe(v)}" y="${Oe(o)}" width="${Oe(l)}" height="${Oe(s)}" fill="var(--_bg)" stroke="var(--_b)"${Mi}/>`+Fe(i,v+Ic+i.width/2,o+Nc+i.height/2,` font-size="${n}" font-weight="var(--_hw)"`)+Lc(a,v+Ic,o+Nc+i.height+h/2+.35*n,h,` font-size="${n}"`)+"</g>",C=o+s,D=Math.max(D,l)};for(let t of e.notes)R("note","Note",t.frame,Rc(t.text,80));for(let t of e.specifications){let e=[`Given ${t.given.join(", ")}`];t.when.length>0&&e.push(`When ${t.when.join(", ")}`),e.push(`Then ${t.then.join(", ")}`),R("specification","Given / When / Then",t.frame,e.flatMap(e=>Rc(e,80)))}let L=Math.max(u.size>0?$:0,D,b.width),O=Math.ceil(L+2*d),F=Math.ceil(C+d),z=Fe(b,O/2,d+b.height/2,' class="pele-title" font-weight="var(--_tw)"')+T+_+E+N;return{svg:Bi("eventmodeling",O,F,i,r,e,z),width:O,height:F,links:[]}}(e,0,r,t))}};function Pc(e){return"markdown"===e||"string"===e||"text"===e?e:"markdown"}function Bc(e){return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}var Hc=class{type="flowchart";direction;nodes=new Map;edges=[];subgraphs=[];classes=new Map;tooltips=new Map;defaultEdgeStyle;defaultInterpolate;title;accTitle;accDescr;subgraphLookup=new Map;members=new Set;edgeById=new Map;pairCount=new Map;subCount=0;options;constructor(e={}){this.options=e}addVertex(e,t,r,a,l,n,s,o){if(!e||0===e.trim().length)return;let h;if(void 0!==o){let t,r=o.includes("\n")?o+"\n":"{\n"+o+"\n}";try{t=U(r)}catch(t){throw new i(`Metadata of "${e}" is not valid YAML. ${t.message}`,"syntax",{type:"flowchart"})}h=null===t||"object"!=typeof t||Array.isArray(t)?void 0:t}let c=this.subgraphLookup.get(e);if(c&&h)return void(c.metadata={...c.metadata,...h});let d=this.edgeById.get(e);if(d)return void 0!==h?.animate&&(d.animate=h.animate),void 0!==h?.animation&&(d.animation=h.animation),void(void 0!==h?.curve&&(d.interpolate=h.curve));let f=this.nodes.get(e);if(void 0===f&&(void 0===t&&void 0===r&&null!=a&&this.options.warn?.(`Style applied to unknown node "${e}". This may indicate a typo. The node will be created automatically.`),f={id:e,labelType:"text",styles:[],classes:[]},this.nodes.set(e,f)),void 0!==t?(f.labelType=t.type,f.text=Bc(t.text.trim())):void 0===f.text&&(f.text=e),void 0!==r&&(f.type=r),null!=a)for(let e of a)f.styles.push(e);if(null!=l)for(let e of l)f.classes.push(e);if(void 0!==n&&(f.dir=n),void 0===f.props?f.props=s??{}:void 0!==s&&Object.assign(f.props,s),void 0===h)return;if(h.shape){let e=String(h.shape);if(e!==e.toLowerCase()||e.includes("_"))throw new i(`No such shape: ${e}. Shape names should be lowercase.`,"semantic",{type:"flowchart"});if(!Tr(e))throw new i(`No such shape: ${e}.`,"semantic",{type:"flowchart"});f.type=e}let u="string"==typeof h.label?h.label:void 0;h.label&&(f.text=String(h.label),f.labelType=Pc(h.labelType)),h.icon&&(f.icon=String(h.icon),!u?.trim()&&f.text===e&&(f.text="")),h.form&&(f.form=String(h.form)),h.pos&&(f.pos=String(h.pos)),h.img&&(f.img=String(h.img),!u?.trim()&&f.text===e&&(f.text="")),h.constraint&&(f.constraint=String(h.constraint)),h.w&&(f.assetWidth=Number(h.w)),h.h&&(f.assetHeight=Number(h.h))}addSingleLink(e,t,r,a){let l={start:e,end:t,type:void 0,text:"",labelType:"text",classes:[],isUserDefinedId:!1,interpolate:this.defaultInterpolate},n=r?.text;void 0!==n&&(l.text=Bc(n.text.trim()),l.labelType=Pc(n.type)),void 0!==r&&(l.type=r.type,l.stroke=r.stroke,l.length=r.length>10?10:r.length);let s=e+"\0"+t,o=this.pairCount.get(s)??0;a&&!this.edgeById.has(a)?(l.id=a,l.isUserDefinedId=!0):l.id=`L_${e}_${t}_${0===o?0:o+1}`;let h=this.options.maxEdges;if(void 0!==h&&this.edges.length>=h)throw new i(`Edge limit exceeded. The limit is ${h}.`,"limit",{type:"flowchart"});this.edges.push(l),this.pairCount.set(s,o+1),this.edgeById.has(l.id)||this.edgeById.set(l.id,l)}addLink(e,t,r){let a="string"==typeof r?.id?r.id.replace("@",""):void 0,i=e[e.length-1],l=t[0];for(let n of e)for(let e of t)this.addSingleLink(n,e,r,n===i&&e===l?a:void 0)}updateLinkInterpolate(e,t){for(let r of e)"default"===r?this.defaultInterpolate=t:this.edgeAt(r).interpolate=t}updateLink(e,t){for(let r of e){if("default"===r){this.defaultEdgeStyle=t;continue}this.edgeAt(r).style=t,t.length>0&&!t.some(e=>e?.startsWith("fill"))&&t.push("fill:none")}}edgeAt(e){let t=this.edges[Number(e)];if(void 0===t)throw new i(`The index ${e} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length-1}. (Help: Ensure that the index is within the range of existing edges.)`,"semantic",{type:"flowchart"});return t}addClass(e,t){let r=t.join().replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",").split(";");for(let t of e.split(",")){let e=this.classes.get(t);void 0===e&&(e={id:t,styles:[],textStyles:[]},this.classes.set(t,e));for(let t of r)t.includes("color")&&e.textStyles.push(t.replace("fill","bgFill")),e.styles.push(t)}}setDirection(e){let t=e.trim();t.includes("<")&&(t="RL"),t.includes("^")&&(t="BT"),t.includes(">")&&(t="LR"),t.includes("v")&&(t="TB"),"TD"===t&&(t="TB"),this.direction=t}setClass(e,t){for(let r of e.split(","))this.nodes.get(r)?.classes.push(t),this.edgeById.get(r)?.classes.push(t),this.subgraphLookup.get(r)?.classes.push(t)}setTooltip(e,t){if(void 0!==t)for(let r of e.split(","))this.tooltips.set(r,t)}setLink(e,t,r){let a=t.trim();for(let t of e.split(",")){let e=this.nodes.get(t);void 0!==e&&(e.link=a?dr(a):void 0,e.linkTarget=r)}this.setClass(e,"clickable")}setClickEvent(e,t,r){this.setClass(e,"clickable")}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addSubGraph(e,t,r){let a=e?.text.trim(),i=r?.text??"";void 0!==e&&e===r&&/\s/.test(i)&&(a=void 0);let l,n=new Set,s=[];for(let e of t)if("string"==typeof e)""!==e.trim()&&!n.has(e)&&(n.add(e),s.push(e));else if(Array.isArray(e))for(let t of e)""!==t.trim()&&!n.has(t)&&(n.add(t),s.push(t));else l=e.value;l??=this.options.inheritDir?this.direction??this.options.direction:void 0,a??="subGraph"+this.subCount,i=i||"",this.subCount++;let o={id:a,nodes:s,title:i.trim(),classes:[],dir:l,labelType:Pc(r?.type)},h=this.members;o.nodes=s.filter(e=>!h.has(e)&&e!==a);for(let e of o.nodes)h.add(e);let c=this.subgraphLookup.get(a);if(c)for(let e of o.nodes)c.nodes.push(e);else this.subgraphs.push(o);return this.subgraphLookup.set(a,c??o),a}exists(e,t){for(let r of e)if(r.nodes.includes(t))return!0;return!1}makeUniq(e,t){let r=new Set;for(let e of t)for(let t of e.nodes)r.add(t);return{nodes:e.nodes.filter(e=>!r.has(e))}}destructLink(e,t){let r=function(e){let t=e.trim(),r=t.slice(0,-1),a="arrow_open";switch(t.slice(-1)){case"x":a="arrow_cross",t.startsWith("x")&&(a="double_"+a,r=r.slice(1));break;case">":a="arrow_point",t.startsWith("<")&&(a="double_"+a,r=r.slice(1));break;case"o":a="arrow_circle",t.startsWith("o")&&(a="double_"+a,r=r.slice(1))}let i="normal",l=r.length-1;r.startsWith("=")&&(i="thick"),r.startsWith("~")&&(i="invisible");let n=function(e,t){let r=0;for(let a=0;a<t.length;a++)t[a]===e&&r++;return r}(".",r);return n&&(i="dotted",l=n),{type:a,stroke:i,length:l}}(e);if(!t)return r;let a=function(e){let t=e.trim(),r="arrow_open";switch(t[0]){case"<":r="arrow_point",t=t.slice(1);break;case"x":r="arrow_cross",t=t.slice(1);break;case"o":r="arrow_circle",t=t.slice(1)}let a="normal";return t.includes("=")&&(a="thick"),t.includes(".")&&(a="dotted"),{type:r,stroke:a}}(t);if(a.stroke!==r.stroke)return{type:"INVALID",stroke:"INVALID"};if("arrow_open"===a.type)a.type=r.type;else{if(a.type!==r.type)return{type:"INVALID",stroke:"INVALID"};a.type="double_"+a.type}return"double_arrow"===a.type&&(a.type="double_arrow_point"),a.length=r.length,a}subgraph(e){return this.subgraphLookup.get(e)}},Yc=["$end","INVALID","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","SHAPE_DATA","CALLBACKNAME","CALLBACKARGS","MD_STR","STR","STYLE","DEFAULT","LINKSTYLE","INTERPOLATE","CLASSDEF","CLASS","HREF","CLICK","GRAPH","subgraph","end","LINK_TARGET","NODIR","DIR","direction_tb","direction_bt","direction_rl","direction_lr","direction_td","LINK_ID","NUM","BRKT","STYLE_SEPARATOR","COLON","AMP","SEMI","COMMA","MULT","LINK","START_LINK","EDGE_TEXT","-)","TEXT","(-","STADIUMEND","STADIUMSTART","SUBROUTINEEND","SUBROUTINESTART","VERTEX_WITH_PROPS_START","TAGEND","CYLINDEREND","CYLINDERSTART","DOUBLECIRCLEEND","DOUBLECIRCLESTART","TRAPEND","INVTRAPEND","TRAPSTART","INVTRAPSTART","TAGSTART","UP","SEP","DOWN","NODE_STRING","MINUS","UNICODE_TEXT","PIPE","PE","PS","SQE","SQS","DIAMOND_STOP","DIAMOND_START","NEWLINE","SPACE","EOF"],Gc=new Uint8Array(128);for(let e of"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'*+.`?\\_/")Gc[e.charCodeAt(0)]=1;var Uc=/accTitle\s*:\s*/y,qc=/accDescr\s*:\s*/y,jc=/accDescr\s*\{\s*/y,Vc=/call\s+/y,Xc=/click\s+/y,Kc=/(?:\r?\n)*\s*\n/y,Zc=/\s*(?:LR|RL|TB|BT|TD|BR)\b/y,Qc=/\s*[<>^]/y,Jc=/\s*v\b/y,ed=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y,/.*direction\s+TD[^\n]*/y],td=/[\n\r\u2028\u2029]/g,rd=/\s*[xo<]?--+[-xo>]\s*/y,ad=/\s*[xo<]?--\s*/y,id=/\s*[xo<]?==+[=xo>]\s*/y,ld=/\s*[xo<]?==\s*/y,nd=/\s*[xo<]?-?\.+-[xo>]?\s*/y,sd=/\s*[xo<]?-\.\s*/y,od=/\s*~~~+\s*/y,hd=/(?:\r?\n)+/y,cd=/[^\S\n\r]+/y,dd=/\(\s*\)/y,fd=/\n\s*/g;var ud=new Uint8Array(77);for(let e of[32,64,63,65,13,38,35,36,33,39,66])ud[e]=1;var pd=new Uint8Array(77);for(let e of[32,66,64,25,63,65,38,35,36,33,39])pd[e]=1;var gd=new Uint8Array(77);for(let e of[32,64,75,65,36,66,35,39,33,12,14,16,17,19,20,25,21,22,63,61,41])gd[e]=1;var md=new Uint8Array(77);for(let e of[32,64,35,75,33,12])md[e]=1;var yd="'UNICODE_TEXT', 'TEXT', 'TAGSTART'",xd=[],wd=/}\s*\n/g;function $d(e,t){let r,a=e.includes("}")?e.replace(wd,"}\n"):e,{types:i,texts:n,starts:o}=function(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=!0,h=e.indexOf("direction"),c=e.indexOf("@"),d=-1,f=0,u=0,p=-1,g=-1,m=-1,y=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},x=e=>{l.push(n),n=e},w=()=>{l.length>0&&(n=l.pop())},$=(t,r)=>(t.lastIndex=r,t.test(e)?t.lastIndex:-1),b=t=>e.startsWith(t,s)&&!Q(e.charCodeAt(s+t.length)),M=r=>{let a=r;if(r>=g&&r<=m)a=m;else if(q(e.charCodeAt(r))){for(;a<t&&q(e.charCodeAt(a));)a++;g=r,m=a}let i=e.charCodeAt(a);return 120===i||111===i||60===i?e.charCodeAt(a+1):i},v=r=>{let a=r;if(r>=g&&r<=m)a=m;else if(q(e.charCodeAt(r))){for(;a<t&&q(e.charCodeAt(a));)a++;g=r,m=a}return 126===e.charCodeAt(a)},k=()=>{96===e.charCodeAt(s+1)?(x(2),s+=2):(x(1),s++)},A=()=>{if(!v(s))return!1;let e=$(od,s);return!(e<0||(y(40,s,e),0))},T=t=>{let r=e.charCodeAt(s+1);return 40===t?(45===r?(x(8),y(45,s,s+2)):91===r?(x(7),y(47,s,s+2)):40===r&&40===e.charCodeAt(s+2)?(x(7),y(55,s,s+3)):(x(7),y(69,s,s+1)),!0):91===t?(91===r?(x(7),y(49,s,s+2)):40===r?(x(7),y(53,s,s+2)):47===r?(x(9),y(58,s,s+2)):92===r?(x(9),y(59,s,s+2)):(x(7),y(71,s,s+1)),!0):124===t?(x(7),y(67,s,s+1),!0):123===t&&(x(7),y(73,s,s+1),!0)},C=e=>{o&&(o=!1,x(6)),y(20,s,s+e)},E=()=>{let r=s;for(;r<t;){let a=e.charCodeAt(r);if(a<128&&1===Gc[a])r++;else{if(!(45===a&&r+1<t))break;{let t=e.charCodeAt(r+1);if(62===t||45===t||46===t)break;r++}}}return r!==s&&(y(64,s,r),!0)},_=e=>{let t,r=M(s);if(45===r){if((t=$(rd,s))>=0)return y(40,s,t),!0;if((t=$(ad,s))>=0)return x(10),y(41,s,t),!0;if((t=$(nd,s))>=0)return y(40,s,t),!0;if((t=$(sd,s))>=0)return x(12),y(41,s,t),!0}else if(61===r){if((t=$(id,s))>=0)return y(40,s,t),!0;if((t=$(ld,s))>=0)return x(11),y(41,s,t),!0}else if(46===r&&(t=$(nd,s))>=0)return y(40,s,t),!0;return 45!==e&&61!==e&&46!==e&&A()},S=l=>{let n;switch(l){case 97:if(e.startsWith("acc",s)){if((n=$(Uc,s))>=0)return x(3),y(2,s,n),!0;if((n=$(qc,s))>=0)return x(4),y(4,s,n),!0;if((n=$(jc,s))>=0)return x(5),s=n,!0}break;case 64:if(123===e.charCodeAt(s+1))return x(16),r.push(7),a.push(""),i.push(s),s+=2,!0;break;case 99:if((n=$(Vc,s))>=0)return x(14),s=n,!0;if(b("classDef"))return y(16,s,s+8),!0;if(b("class"))return y(17,s,s+5),!0;if((n=$(Xc,s))>=0)return x(13),s=n,!0;break;case 34:return k(),!0;case 115:if(b("style"))return y(12,s,s+5),!0;if(b("swimlane-beta"))return C(13),!0;if(b("subgraph"))return y(21,s,s+8),!0;break;case 100:if(b("default"))return y(13,s,s+7),!0;break;case 108:if(b("linkStyle"))return y(14,s,s+9),!0;break;case 105:if(b("interpolate"))return y(15,s,s+11),!0;break;case 104:if(e.startsWith("href",s)&&q(e.charCodeAt(s+4)))return y(18,s,s+5),!0;break;case 102:if(b("flowchart-elk"))return C(13),!0;if(b("flowchart"))return C(9),!0;break;case 103:if(b("graph"))return C(5),!0;break;case 101:if(b("end")){for(n=s+3;n<t&&q(e.charCodeAt(n));)n++;return y(22,s,n),!0}break;case 95:if(b("_self"))return y(23,s,s+5),!0;if(b("_blank"))return y(23,s,s+6),!0;if(b("_parent"))return y(23,s,s+7),!0;if(b("_top"))return y(23,s,s+4),!0}if(-1!==h&&s>=f&&(h<s&&(h=e.indexOf("direction",s)),-1!==h&&(d<s&&(td.lastIndex=s,d=td.test(e)?td.lastIndex-1:t),h<d))){for(let e=0;e<5;e++)if((n=$(ed[e],s))>=0)return y(26+e,s,n),!0;f=d}if(-1!==c&&34!==l&&!q(l)){if(s>=u){c<s&&(c=e.indexOf("@",s));let r=s;for(;r<t;){let t=e.charCodeAt(r);if(34===t||q(t))break;r++}if(u=r,p=-1,-1!==c&&c<r)for(let a=Math.min(r,t-1)-1;a>=c;a--){if(64!==e.charCodeAt(a))continue;let t=e.charCodeAt(a+1);if(123!==t&&34!==t){p=a;break}}}if(p>s)return y(31,s,p+1),!0}if(l>=48&&l<=57){let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(t<48||t>57)break;r++}return y(32,s,r),!0}switch(l){case 35:return y(33,s,s+1),!0;case 58:return 58===e.charCodeAt(s+1)&&58===e.charCodeAt(s+2)?y(34,s,s+3):y(35,s,s+1),!0;case 38:return y(36,s,s+1),!0;case 59:return y(37,s,s+1),!0;case 44:return y(38,s,s+1),!0;case 42:return y(39,s,s+1),!0;case 120:case 111:case 46:return _(l)||E();case 60:return _(l)||y(60,s,s+1),!0;case 45:return _(l)||E()||y(65,s,s+1),!0;case 61:return _(l);case 126:return A();case 40:case 124:case 123:return T(l);case 91:return 124===e.charCodeAt(s+1)?(y(50,s,s+2),!0):T(l);case 62:return x(7),y(51,s,s+1),!0;case 94:return y(61,s,s+1),!0;case 92:return 124===e.charCodeAt(s+1)?(y(62,s,s+2),!0):E();case 118:return Q(e.charCodeAt(s+1))?E():(y(63,s,s+1),!0)}return q(l)?!!_(l)||((n=$(hd,s))>=0?(y(74,s,n),!0):(n=$(cd,s))>=0&&(y(75,s,n),!0)):l<128?E():!!Ur(l)&&(y(66,s,s+1),!0)},I=(r,a,i,l)=>{if(34===r)return k(),!0;let n=M(s);if(n===i||n===l){let e=$(a,s);if(e>=0)return w(),y(40,s,e),!0}if(r===i&&(45!==i||45===e.charCodeAt(s+1)))return!1;let o=s+1;for(;o<t;){let t=e.charCodeAt(o);if(34===t)break;if(t===i){if(45!==i||45===e.charCodeAt(o+1))break}else if(120===t||111===t||60===t||t===l||q(t)){let e=M(o);if((e===i||e===l)&&$(a,o)>=0)break}o++}return y(42,s,o),!0};for(;;){if(s>=t){let e=-1;switch(n){case 0:e=76;break;case 3:e=3;break;case 4:e=5;break;case 5:e=6;break;case 13:e=19;break;case 14:e=8;break;case 15:e=9}-1!==e&&y(e,t,t);break}let l=e.charCodeAt(s),o=!0;switch(n){case 0:o=S(l);break;case 1:if(34===l)96===e.charCodeAt(s+1)?(x(2),s+=2):(w(),s++);else{let r=e.indexOf('"',s);y(11,s,-1===r?t:r)}break;case 2:if(96===l)34===e.charCodeAt(s+1)?(w(),s+=2):o=!1;else if(34===l)k();else{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(96===t||34===t)break;r++}y(10,s,r)}break;case 3:case 4:{let r=e.indexOf("\n",s);-1===r&&(r=t);let a=3===n?3:5;w(),y(a,s,r);break}case 5:if(125===l)w(),s++;else{let r=e.indexOf("}",s);-1===r&&(r=t),y(6,s,r)}break;case 6:{let e;34===l?k():(e=$(Kc,s))>=0?(w(),y(24,s,e)):(e=$(Zc,s))>=0||(e=$(Qc,s))>=0||(e=$(Jc,s))>=0?(w(),y(25,s,e)):o=A()||T(l);break}case 7:{let r=e.charCodeAt(s+1);switch(l){case 34:k();break;case 40:case 91:case 123:T(l);break;case 93:w(),41===r?y(46,s,s+2):93===r?y(48,s,s+2):y(70,s,s+1);break;case 41:w(),93===r?y(52,s,s+2):41===r&&41===e.charCodeAt(s+2)?y(54,s,s+3):y(68,s,s+1);break;case 124:w(),y(67,s,s+1);break;case 125:w(),y(72,s,s+1);break;default:{if((126===l||q(l))&&A())break;let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(91===t||93===t||40===t||41===t||123===t||125===t||124===t||34===t)break;r++}y(44,s,r)}}break}case 8:{let r=e.charCodeAt(s+1);if(34===l)k();else{if((126===l||q(l))&&A())break;if(45!==l&&47!==l&&41!==l||41!==r)if(40===l||91===l||123===l)T(l);else if(41===l||93===l||125===l)o=!1;else{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(34===t||40===t||41===t||91===t||93===t||123===t||125===t||(45===t||47===t)&&41===e.charCodeAt(r+1)||(126===t||q(t))&&v(r)&&$(od,r)>=0)break;r++}y(44,s,r)}else w(),y(43,s,s+2)}break}case 9:{let r=e.charCodeAt(s+1);if(34===l){k();break}if((126===l||q(l))&&A())break;switch(l){case 40:45===r||91===r||40===r&&40===e.charCodeAt(s+2)?T(l):93===r?(w(),y(56,s,s+2)):T(l);break;case 91:case 123:T(l);break;case 92:93===r?(w(),y(56,s,s+2)):y(44,s,s+1);break;case 47:93===r?(w(),y(57,s,s+2)):y(44,s,s+1);break;case 93:case 41:93===r?(w(),y(56,s,s+2)):o=!1;break;case 125:o=!1;break;default:{if((63===l||61===l)&&93===r){w(),y(56,s,s+2);break}let a=s+1;for(;a<t;){let t=e.charCodeAt(a);if(92===t||91===t||93===t||40===t||41===t||123===t||125===t||47===t)break;a++}y(44,s,a)}}break}case 10:o=I(l,rd,45,-1);break;case 11:o=I(l,id,61,-1);break;case 12:o=I(l,nd,46,45);break;case 13:if(34===l)k();else if(q(l))w(),s++;else{let r=s+1;for(;r<t&&!q(e.charCodeAt(r));)r++;y(19,s,r)}break;case 14:if(40===l){let e=$(dd,s);w(),e>=0?s=e:(x(15),s++)}else{let r=e.indexOf("(",s);-1===r&&(r=t),y(8,s,r)}break;case 15:if(41===l)w(),s++;else{let r=e.indexOf(")",s);-1===r&&(r=t),y(9,s,r)}break;case 16:if(34===l)x(17),y(7,s,s+1);else if(125===l)w(),s++;else if(94===l)o=!1;else{let r=s+1;for(;r<t;){let t=e.charCodeAt(r);if(125===t||94===t||34===t)break;r++}y(7,s,r)}break;case 17:if(34===l)w(),y(7,s,s+1);else{let l=e.indexOf('"',s);-1===l&&(l=t),r.push(7),a.push(e.slice(s,l).replace(fd,"<br/>")),i.push(s),s=l}}if(!o)return r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}}return r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}(a),h=0,d=t=>{let r=i[h],n=a===e?o[h]:s([l(e,wd,2)],o[h]);throw 1===r?c("flowchart",e,n,"",!0):c("flowchart",e,n,`Expecting ${t}, got '${Yc[r]}'`)},f=(e,t="")=>(i[h]!==e&&d(`'${Yc[e]}'${t?", "+t:""}`),n[h++]),u=()=>{let e=i[h];74!==e&&37!==e&&76!==e&&d("'SEMI', 'NEWLINE', 'EOF'"),h++},p=()=>{0===ud[i[h]]&&d("'NODE_STRING'");let e=n[h++];for(;1===ud[i[h]];)e+=n[h++];return e},g=()=>{0===pd[i[h]]&&d("'NODE_STRING'");let e=n[h++];for(;1===pd[i[h]];)e+=n[h++];return e},m=()=>{let e,t=i[h];if(11===t)e="string";else if(10===t)e="markdown";else{if(44!==t&&60!==t&&51!==t&&66!==t)return d(`${yd}, 'TAGEND', 'STR', 'MD_STR'`);e="text"}let r=n[h++];for(;;){let e=i[h];if(44!==e&&60!==e&&51!==e&&66!==e)break;r+=n[h++]}return{text:r,type:e}},y=e=>{f(e,yd)},x=()=>{let e=n[h++];for(;7===i[h];)e+=n[h++];return e},w=()=>{let e=(()=>{let e,r=p();switch(i[h]){case 71:h++,e=m(),y(70),t.addVertex(r,e,"square");break;case 55:h++,e=m(),y(54),t.addVertex(r,e,"doublecircle");break;case 69:h++,69===i[h]?(h++,e=m(),y(68),f(68),t.addVertex(r,e,"circle")):(e=m(),y(68),t.addVertex(r,e,"round"));break;case 45:h++,e=m(),y(43),t.addVertex(r,e,"ellipse");break;case 47:h++,e=m(),y(46),t.addVertex(r,e,"stadium");break;case 49:h++,e=m(),y(48),t.addVertex(r,e,"subroutine");break;case 50:{h++;let a=f(64);f(35);let i=f(64);f(67),e=m(),y(70),t.addVertex(r,e,"rect",void 0,void 0,void 0,{[a]:i});break}case 53:h++,e=m(),y(52),t.addVertex(r,e,"cylinder");break;case 73:h++,73===i[h]?(h++,e=m(),y(72),f(72),t.addVertex(r,e,"hexagon")):(e=m(),y(72),t.addVertex(r,e,"diamond"));break;case 51:h++,e=m(),y(70),t.addVertex(r,e,"odd");break;case 58:h++,e=m(),57===i[h]?(h++,t.addVertex(r,e,"lean_right")):(y(56),t.addVertex(r,e,"trapezoid"));break;case 59:h++,e=m(),56===i[h]?(h++,t.addVertex(r,e,"lean_left")):(y(57),t.addVertex(r,e,"inv_trapezoid"));break;default:t.addVertex(r)}return r})();return 34===i[h]&&(h++,t.setClass(e,p())),e},$=()=>{let e=[w()];for(r=void 0;;){let a=7===i[h]?x():void 0;if(75!==i[h])return r=a,e;do{h++}while(75===i[h]);if(36!==i[h])return void 0!==a&&d("'AMP'"),e;h++,75!==i[h]&&d("'SPACE'");do{h++}while(75===i[h]);let l=w();void 0!==a&&t.addVertex(e[e.length-1],void 0,void 0,void 0,void 0,void 0,void 0,a),e.push(l)}},b=()=>{let e;if(31===i[h]&&(e=n[h++]),40===i[h]){let r=t.destructLink(n[h++]);return void 0!==e&&(r.id=e),67===i[h]&&(h++,r.text=m(),y(67),75===i[h]&&h++),r}if(41===i[h]){let r=n[h++],a=(()=>{let e,t=i[h];if(11===t)e="string";else if(10===t)e="markdown";else{if(42!==t&&66!==t)return d("'EDGE_TEXT', 'STR', 'MD_STR'");e="text"}let r=n[h++];for(;42===i[h]||66===i[h];)r+=n[h++];return{text:r,type:e}})(),l=f(40,"'EDGE_TEXT'"),s=t.destructLink(l,r);return s.text=a,void 0!==e&&(s.id=e),s}return d("'LINK', 'START_LINK'")},M=()=>{0===md[i[h]]&&d("'NODE_STRING', 'NUM', 'COLON', 'BRKT'");let e=n[h++];for(;1===md[i[h]];)e+=n[h++];return e},v=()=>{let e=[M()];for(;38===i[h];)h++,e.push(M());return e},k=(e,r)=>{if(75!==i[h])return void t.setLink(e,r);if(h++,23===i[h])return void t.setLink(e,r,n[h++]);let a=f(11,"'LINK_TARGET'");75===i[h]?(h++,t.setLink(e,r,f(23))):t.setLink(e,r),t.setTooltip(e,a)},A=()=>{h++;let e=i[h];if(74===e||37===e||76===e)return h++,{id:void 0,title:void 0,list:[],collect:!1};f(75,"'SEMI', 'NEWLINE', 'EOF'");let t=(()=>{let e,t=i[h];if(11===t)e="text";else if(10===t)e="markdown";else{if(1!==gd[t])return d("'NODE_STRING', 'STR', 'MD_STR'");e="text"}let r=n[h++];for(;1===gd[i[h]];)r+=n[h++];return{text:r,type:e}})(),r=t;return 71===i[h]&&(h++,r=m(),y(70)),e=i[h],74!==e&&37!==e&&76!==e&&d("'SEMI', 'NEWLINE', 'EOF', 'SQS'"),h++,{id:t,title:r,list:[],collect:!1}},T=e=>{let a=i[h];switch(a){case 12:{h++,f(75);let e=p();return f(75),t.addVertex(e,void 0,void 0,v()),u(),xd}case 14:return(()=>{let e;if(h++,f(75),13===i[h])e=[n[h++]];else for(e=[f(32,"'DEFAULT'")];38===i[h];)h++,e.push(f(32));if(f(75),15!==i[h])return void t.updateLink(e,v());h++,f(75);let r=g();if(75===i[h]){h++;let a=v();t.updateLinkInterpolate(e,r),t.updateLink(e,a)}else t.updateLinkInterpolate(e,r)})(),u(),xd;case 16:{h++,f(75);let e=p();return f(75),t.addClass(e,v()),u(),xd}case 17:{h++,f(75);let e=p();return f(75),t.setClass(e,p()),u(),xd}case 19:return(()=>{let e=n[h++];switch(i[h]){case 8:{let r,a=n[h++],l=9===i[h],s=l?n[h++]:void 0;return 75===i[h]&&(h++,r=f(11)),l?t.setClickEvent(e,a,s):t.setClickEvent(e,a),void(void 0!==r&&t.setTooltip(e,r))}case 18:return h++,void k(e,f(11));case 11:return void k(e,n[h++]);default:{let r=g();if(75===i[h]){h++;let a=f(11);t.setClickEvent(e,r),t.setTooltip(e,a)}else t.setClickEvent(e,r)}}})(),u(),xd;case 26:case 27:case 28:case 29:case 30:return h++,{stmt:"dir",value:bd[a-26]};case 2:{h++;let e=f(3).trim();return t.setAccTitle(e),e}case 4:{h++;let e=f(5).trim();return t.setAccDescription(e),e}case 6:{let e=n[h++].trim();return t.setAccDescription(e),e}default:{0===ud[a]&&d(Md);let l=(e=>{let a=$();void 0!==r&&t.addVertex(a[a.length-1],void 0,void 0,void 0,void 0,void 0,void 0,r);let l=a;for(;;){let n=i[h];if(40!==n&&41!==n&&31!==n)return l;let s=b(),o=$();void 0!==r&&t.addVertex(o[o.length-1],void 0,void 0,void 0,void 0,void 0,void 0,r),t.addLink(a,o,s),e&&(l=o.concat(l)),a=o}})(e);return u(),l}}};for(;75===i[h]||74===i[h];)h++;if(f(20,"'SPACE', 'NEWLINE'"),24===i[h])h++,t.setDirection("TB");else{let e=f(25,"'NODIR'"),r=i[h];if(75===r){do{h++}while(75===i[h]);r=i[h],74!==r&&d("'NEWLINE', 'SPACE'")}else 37!==r&&74!==r&&d("'SEMI', 'NEWLINE', 'SPACE'");h++,t.setDirection(e)}(()=>{let e=[],r=[],a=!1;for(;;){let l=i[h];if(0===l)break;if(22===l){let i=e.pop();if(void 0===i)break;h++;let l=t.addSubGraph(i.id,r,i.title);r=i.list,a=i.collect,a&&r.push(l)}else if(37===l||74===l||75===l||76===l)a&&r.push(n[h]),h++;else if(21===l){let t=A();t.list=r,t.collect=a,e.push(t),r=[],a=!0}else{let e=T(a);a&&(!Array.isArray(e)||e.length>0)&&r.push(e)}}e.length>0&&d("'end'")})(),0!==i[h]&&d(Md)}var bd=["TB","BT","RL","LR","TD"],Md="'SEMI', 'NEWLINE', 'SPACE', 'EOF', 'subgraph', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'NODE_STRING'";function vd(e){if(e.img)return"imageSquare";if(e.icon)return"circle"===e.form?"iconCircle":"square"===e.form?"iconSquare":"rounded"===e.form?"iconRounded":"icon";switch(e.type){case"square":case void 0:return"squareRect";case"round":return"roundedRect";default:return e.type}}var kd=26,Ad=' fill="var(--_s)" stroke="var(--_b)"',Td=' stroke="var(--_b)"';function Cd(e,t,r){let a=e[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}function Ed(e,t){return void 0!==e&&e>0&&e<=4e3?e:t}function _d(e,t,r,a){let i=i=>Vl(r,l=>function(e,t,r,a,i,l){let n=l?12:20,s=a?t[a.type]:void 0,o="object"!=typeof s||null===s||Array.isArray(s)?t.flowchart??{}:s,h=function(e,t){let r=[],a=[],i=e.subgraphs,l=t=>{let r=[];for(let a of t){let t=e.classes.get(a);if(void 0!==t){for(let e of t.styles)r.push(e.trim());for(let e of t.textStyles)r.push(e.trim())}}return r},n=new Map;for(let t of i)for(let r of t.nodes)e.subgraph(r)&&n.set(r,t.id);let s=new Map,o=new Map;for(let e of i){let t=n.get(e.id);if(void 0===t)continue;let r=o.get(t);r?r.push(e.id):o.set(t,[e.id])}let h=0;for(let e of i){if(n.has(e.id))continue;let t=[e.id];for(;t.length>0;){let e=t.pop();if(s.has(e))continue;s.set(e,h++);let r=o.get(e);if(r)for(let e=r.length-1;e>=0;e--)t.push(r[e])}}let c=t=>"collapsed"===e.subgraph(t)?.metadata?.view,d=!1;for(let e of i)"collapsed"===e.metadata?.view&&(d=!0);let f=new Map,u=e=>{let t=[],r=new Set,a=e;for(;void 0!==a&&!f.has(a)&&!r.has(a);)r.add(a),t.push(a),a=n.get(a);let i=void 0!==a?f.get(a):void 0;for(let e=t.length-1;e>=0;e--)void 0===i&&c(t[e])&&(i=t[e]),f.set(t[e],i);return i},p=new Set,g=new Map;for(let e of d?i:[]){let t=u(e.id);if(void 0!==t){e.id!==t&&(p.add(e.id),g.set(e.id,t));for(let r of e.nodes)r!==t&&(p.add(r),g.set(r,t))}}let m=new Map,y=new Set;for(let e=i.length-1;e>=0;e--){let t=i[e];if(!p.has(t.id)){t.nodes.length>0&&y.add(t.id);for(let e of t.nodes)m.set(e,t.id)}}let x=new Map;for(let e=i.length-1;e>=0;e--){let t=i[e];if(p.has(t.id))continue;let a="collapsed"===t.metadata?.view,n={id:t.id,label:t.title,labelType:t.labelType,parentId:m.get(t.id),cssStyles:[],cssCompiledStyles:l(t.classes),cssClasses:t.classes.join(" "),shape:a?"collapsedGroup":"rect",dir:t.dir,isGroup:!a,colorIndex:s.get(t.id)};a||(n.metadata=t.metadata),r.push(n),x.set(t.id,n)}for(let t of e.nodes.values()){if(p.has(t.id))continue;let a=x.get(t.id);if(a){a.cssStyles=t.styles,a.cssCompiledStyles=l(t.classes),a.cssClasses=t.classes.join(" ");continue}let i=y.has(t.id),n={id:t.id,label:t.text,labelType:t.labelType,parentId:m.get(t.id),cssStyles:t.styles,cssCompiledStyles:l(["default","node",...t.classes]),cssClasses:"default "+t.classes.join(" "),dir:t.dir,link:t.link,linkTarget:t.linkTarget,tooltip:e.tooltips.get(t.id),icon:t.icon,pos:t.pos,img:t.img,assetWidth:t.assetWidth,assetHeight:t.assetHeight,constraint:t.constraint,isGroup:i,shape:i?"rect":vd(t)};r.push(n)}return e.edges.forEach((r,i)=>{let n=g.get(r.start)??r.start,s=g.get(r.end)??r.end;if(n===s&&(g.has(r.start)||g.has(r.end)))return;let[o,h]=function(e){switch(e){case"arrow_point":case"arrow_circle":case"arrow_cross":return["none",e];case"double_arrow_point":case"double_arrow_circle":case"double_arrow_cross":{let t=e.replace("double_","");return[t,t]}}return["none","arrow_point"]}(r.type),c=[...e.defaultEdgeStyle??[]];r.style&&c.push(...r.style);let d="invisible"===r.stroke||"arrow_open"===r.type;a.push({id:r.id||`L_${n}_${s}_${i}`,isUserDefinedId:r.isUserDefinedId,start:n,end:s,type:r.type??"normal",label:r.text,labelType:r.labelType,thickness:r.stroke,pattern:r.stroke,minlen:r.length,classes:"invisible"===r.stroke?"":"edge-thickness-normal edge-pattern-solid flowchart-link",arrowTypeStart:d?"none":o,arrowTypeEnd:d?"none":h,cssCompiledStyles:l(r.classes),style:c,animate:r.animate,animation:r.animation,curve:r.interpolate||e.defaultInterpolate||t})}),{nodes:r,edges:a}}(e,"string"==typeof o.curve?o.curve:void 0);a?.prepare(h);let c=r.fontSize??16,d=Math.round(.875*c),f=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),u=Math.min(Cd(o,"wrappingWidth",200),a&&l?100:1/0),p=r.padding??8,g=r.icons,y=new Map,x=[],w=[];h.nodes.forEach((e,t)=>y.set(e.id,t));for(let e of h.nodes){let t,i,s=Ri(e.cssStyles.length>0?e.cssCompiledStyles.concat(e.cssStyles):e.cssCompiledStyles),o=(s.bold?1:0)|(s.italic?2:0),h="markdown"===e.labelType,d=s.fontSize??c;if(e.isGroup){let c=Fl(e.label,h,f,d,a&&l?Math.max(80,Gl(r)/2):4e3,o);t={node:e,style:s,label:c,shape:"group",w:0,h:0,dy:0,loops:0},i=Va(0,0),i.isGroup=!0,i.dir=e.dir?Pa(e.dir):void 0,i.padX=n,i.padTop=c.height>0?c.height+16:20,i.padBottom=n,i.minW=c.width+2*n-12}else{let r,a,l=Cr(e.shape),n=Fl(e.img||e.icon||cl(l)?e.label:void 0,h,f,d,u,o),c=0;if(e.img||e.icon){let t=e.img?80:48,i=Ed(e.assetWidth,t),l=Ed(e.assetHeight,t);r=Math.max(i,n.width+8),a=l+(n.height>0?n.height+6:0),c="t"===e.pos?-l/2:l/2,0===n.height&&(c=0)}else{let e=sl(l,n.width,n.height);r=e.w,a=e.h,c=e.dy}t={node:e,style:s,label:n,shape:l,w:r,h:a,dy:c,loops:0},i=Va(r,a)}i.seq=x.length,x.push(t),w.push(i)}h.nodes.forEach((e,t)=>{w[t].parent=void 0!==e.parentId?y.get(e.parentId)??-1:-1}),qa(w,h.edges.map(e=>[y.get(e.start)??-1,y.get(e.end)??-1]));let $=i?"TB":Pa(e.direction),b=e=>{let t;for(let r=w[e].parent,a=0;r>=0&&void 0===t&&a<1e4;r=w[r].parent,a++)t=w[r].dir;return t??=$,"LR"===t||"RL"===t};x.forEach((e,t)=>{e.node.isGroup?w[t].span=1/0:!e.node.img&&!e.node.icon&&(w[t].span=function(e,t,r,a){return Math.max(0,nl.get(e)?.span?.(t,r,a)??0)}(e.shape,e.w,e.h,b(t)))});let M=[],v=[],k=[];for(let e of h.edges){let t=y.get(e.start),r=y.get(e.end);if(void 0===t||void 0===r)continue;let a=Fl(e.label,"markdown"===e.labelType,f,d,u);t===r&&(x[t].loops++,b(t)?w[t].h+=2*(kd+(a.height>0?a.height+8:0)):w[t].w+=2*(kd+(a.width>0?a.width+12:0))),k.push(e),v.push(a),M.push({src:t,dst:r,minlen:e.minlen??1,labelW:a.width>0?a.width+12:0,labelH:a.height>0?a.height+4:0,route:[],labelX:0,labelY:0})}let A={nodeSep:Cd(o,"nodeSpacing",40)*(l?.5:1),edgeSep:16,rankSep:Cd(o,"rankSpacing",48)*(l?.75:1),portSep:20,tracks:"string"==typeof o.curve&&/^step/.test(o.curve),straight:"linear"===o.curve,headRoom:ii("arrow_point")},T=a?a.layout(w,M,$,A,l):Za(w,M,$,A),C=gs(e.title,f,c,l?Gl(r):4e3),E=C.height>0?C.height+12:0,_=Math.max(T.width,C.width),S=p+(_-T.width)/2;ja(w,M,S,p+E);let I=Math.ceil(_+2*p),N=Math.ceil(T.height+E+2*p),D=[],R=new Map,L=!1;for(let e of w)e.isGroup&&(L=!0);if(L)for(let e of M)Qa(R,e.route);let O="",F="",z="",W=[];for(let e=0;e<x.length;e++){let t=x[e],i=w[e],l=t.node,s=i.x,o=i.y,h=Oi(l.cssClasses.replace(/^default\s?/,"")),c=Re(l.id);if(i.isGroup&&a?.drawGroup&&i.parent<0){yt(t.style.shape)&&a.filledBox&&W.push({box:a.filledBox(i,$),shape:t.style.shape}),O+=a.drawGroup(i,t.label,t.style,h,c,$,g);continue}if(i.isGroup){yt(t.style.shape)&&W.push({box:[s-i.w/2,o-i.h/2,s+i.w/2,o+i.h/2],shape:t.style.shape});let r=Ja(i,t.label.width,R,n),a=o-i.h/2+8+t.label.height/2,l=ei(i,t.label.width,r,R),d=` class="pele-cluster-label"${l?' fill="var(--_m)"':xt(t.style,"var(--_m)")}${t.style.text}`;l&&(F+=ti(t.label,r,a,d,c,w,e,g)),O+=`<g class="pele-cluster${h}" data-id="${c}"><rect x="${Oe(s-i.w/2)}" y="${Oe(o-i.h/2)}" width="${Oe(i.w)}" height="${Oe(i.h)}" fill="var(--_a)"${ki(t.style.shape)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${Ai(t.style.shape)}/>`+(l?"":Fe(t.label,r,a,d,g))+"</g>";continue}let d,f=t.w,u=t.h,p="";if(l.img){let e=Ed(l.assetWidth,80),a=Ed(l.assetHeight,80),i=t.label.height>0?"t"===l.pos?u/2-a:-u/2:-a/2,n=wr(dr(l.img),r);d=void 0===n?"":`<image href="${De(n)}" x="${Oe(-e/2)}" y="${Oe(i)}" width="${Oe(e)}" height="${Oe(a)}" preserveAspectRatio="${"on"===l.constraint?"xMidYMid meet":"none"}"/>`}else if(l.icon){let e=Ed(l.assetHeight,48),r=t.label.height>0?"t"===l.pos?u/2-e:-u/2:-e/2,a=.6*e;d=("icon"===l.shape?"":"iconCircle"===l.shape?`<circle cy="${Oe(r+e/2)}" r="${Oe(e/2)}"${Ad}${t.style.shape}/>`:`<rect x="${Oe(-e/2)}" y="${Oe(r)}" width="${Oe(e)}" height="${Oe(e)}" rx="${"iconRounded"===l.shape?8:0}"${Ad}${t.style.shape}/>`)+`<svg class="pele-icon" data-icon="${Re(l.icon)}" x="${Oe(-a/2)}" y="${Oe(r+(e-a)/2)}" width="${Oe(a)}" height="${Oe(a)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${g?.(l.icon)??""}</svg>`}else d=ol(t.shape,f,u,Ad+t.style.shape,Td+t.style.line),dl(t.shape)&&(p=xt(t.style));let y=Fe(t.label,0,t.dy,` class="pele-label"${p}${t.style.text}`,g);if(/ internal-link(?: |$)/.test(h+" ")&&l.label&&!1!==r.links){let e=m(l.label),t=br(e,r),a=De(e);y=`<a class="internal-link"${t?` href="${a}"${vr(r)}`:""} data-href="${a}">${y}</a>`,D.push({id:l.id,href:e,internal:!0})}let b=d+y;l.tooltip&&(b=`<title>${Re(l.tooltip)}</title>`+b),l.link&&(b=Mr(b,l.link,l.id,D,r,l.linkTarget?` target="${De(l.linkTarget)}"`:"")),z+=`<g class="pele-node pele-shape-${t.shape}${h}" data-id="${c}" transform="translate(${Oe(s)},${Oe(o)})">${b}</g>`}let P=ri();for(let e=0;e<M.length;e++){let t=M[e];t.src===t.dst||"invisible"===k[e].thickness||t.route.length<6||(P.add(t.src,fl(t.route,0,w[t.src]),k[e].arrowTypeStart),P.add(t.dst,fl(t.route,t.route.length-3,w[t.dst]),k[e].arrowTypeEnd))}let B="",H="",Y="",G=new Map;for(let e=0;e<M.length;e++){let t=M[e],r=k[e],a=v[e],i=r.style.length>0||r.cssCompiledStyles.length>0?Ri(r.cssCompiledStyles.concat(r.style)):void 0;if("invisible"!==r.thickness){let e,a=r.arrowTypeStart,l=r.arrowTypeEnd;if(t.src===t.dst){let r=x[t.src],a=G.get(t.src)??0;G.set(t.src,a+1),e=$i(w[t.src],r.w,r.h,a,b(t.src),kd,ii(l),t)}else{let i=t.route.slice(),n=P.of(t.src,fl(i,0,w[t.src])),s=P.of(t.dst,fl(i,i.length-3,w[t.dst]));ul(i,0,x[t.src],w[t.src]),ul(i,i.length-3,x[t.dst],w[t.dst]),e=ai(i,r.curve,ii(a),ii(l),n,s)}let n=gi(e.d,[e.sx,e.sy,e.ex,e.ey],W,i?.line,e.tokens),s=n||(i?.stroke&&"invisible"!==r.thickness?De(i.stroke):"var(--_l)"),o="";"thick"===r.thickness?o+=' stroke-width="2.5"':"dotted"===r.thickness&&(o+=' stroke-dasharray="3 4"');let h=Oi(r.classes.replace(/edge-thickness-normal|edge-pattern-solid|flowchart-link/g,""));""===n&&(B+=yi(e,a,l,i?.line,"thick"===r.thickness)),H+=`<g class="pele-edge${h}" data-id="${Re(r.id)}"${n?` stroke="${n}"`:""}${i?.line??""}><path d="${e.d}"${o}/>`+li(a,e.sx,e.sy,e.sdx,e.sdy,s)+li(l,e.ex,e.ey,e.edx,e.edy,s)+"</g>"}if(a.width>0){let e=t.labelX,l=t.labelY;Y+=wi(r.id,a,e,l,i?.text??"",g)}}return{svg:Bi(a?.type??"flowchart",I,N,c,r,e,Fe(C,I/2,p+C.height/2,' class="pele-title" font-weight="var(--_tw)"')+(O?`<g class="pele-clusters">${O}</g>`:"")+xi(B)+(H?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${H}</g>`:"")+(F?`<g class="pele-cluster-titles">${F}</g>`:"")+(Y?`<g class="pele-edge-labels" font-size="${d}">${Y}</g>`:"")+`<g class="pele-nodes">${z}</g>`),width:I,height:N,links:D}}(e,t,r,a,i,l));return jl(e.direction)?ql(r,i):i(!1)}var Sd={type:"flowchart",math:!0,parse(e,t,r,a,i){let l=t.flowchart??{},n=new Hc({inheritDir:!0===l.inheritDir,maxEdges:i.maxEdges});return r&&(n.title=r),$d(e,n),n},render:_d},Id=["January","February","March","April","May","June","July","August","September","October","November","December"],Nd=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Dd(e){return!Number.isNaN(e.getTime())}function Rd(e,t){let r=String(e);return r.length>=t?r:"0".repeat(t-r.length)+r}function Ld(e){let t=["th","st","nd","rd"],r=e%100;return e+(t[(r-20)%10]||t[r]||t[0])}function Od(e){let t=15*-Math.round(e.getTimezoneOffset()/15);return 0===t?0:t}function Fd(e){let t=Od(e),r=Math.abs(t);return(t>=0?"+":"-")+Rd(Math.floor(r/60),2)+":"+Rd(r%60,2)}function zd(e){return e.getDay()||7}function Wd(e,t){let r=new Date(e);return r.setDate(r.getDate()+t),r}function Pd(e,t){let r=new Date(e);return r.setDate(1),t(r),r.setDate(Math.min(e.getDate(),function(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t.getDate()}(r))),r}function Bd(e,t,r){switch(r){case"M":return Pd(e,r=>r.setMonth(e.getMonth()+t));case"y":return Pd(e,r=>r.setFullYear(e.getFullYear()+t));case"d":return Wd(e,Math.round(t));case"w":return Wd(e,Math.round(7*t));case"h":return new Date(e.getTime()+36e5*t);case"m":return new Date(e.getTime()+6e4*t);case"s":return new Date(e.getTime()+1e3*t);default:return new Date(e.getTime()+t)}}function Hd(e){return Wd(e,4-zd(e))}function Yd(e){let t=Hd(e),r=new Date(t.getFullYear(),0,1),a=zd(r),i=Wd(r,4-a+(a>4?7:0)),l=6e4*(Od(i)-Od(t)),n=(t.getTime()-i.getTime()-l)/6048e5;return(n<0?Math.ceil(n)||0:Math.floor(n))+1}var Gd=/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,Ud=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;function qd(e,t){if(!Dd(e))return"Invalid Date";let r=t||"YYYY-MM-DDTHH:mm:ssZ";if("YYYY-MM-DD"===r)return jd(e);let a=!1,i=r.replace(Gd,t=>{switch(t){case"Q":return String(Math.ceil((e.getMonth()+1)/3));case"Do":return"["+Ld(e.getDate())+"]";case"GGGG":return String(Hd(e).getFullYear());case"W":return String(Yd(e));case"WW":return Rd(Yd(e),2);case"k":return String(e.getHours()||24);case"kk":return Rd(e.getHours()||24,2);case"X":return String(Math.floor(e.getTime()/1e3));case"x":return String(e.getTime());case"gggg":case"wo":case"w":case"ww":case"z":case"zzz":return a=!0,t;default:return t}});if(a)return;let l=e.getHours();return i.replace(Ud,(t,r)=>{if(r)return r;switch(t){case"YY":return String(e.getFullYear()).slice(-2);case"YYYY":return Rd(e.getFullYear(),4);case"M":return String(e.getMonth()+1);case"MM":return Rd(e.getMonth()+1,2);case"MMM":return Id[e.getMonth()].slice(0,3);case"MMMM":return Id[e.getMonth()];case"D":return String(e.getDate());case"DD":return Rd(e.getDate(),2);case"d":return String(e.getDay());case"dd":return Nd[e.getDay()].slice(0,2);case"ddd":return Nd[e.getDay()].slice(0,3);case"dddd":return Nd[e.getDay()];case"H":return String(l);case"HH":return Rd(l,2);case"h":return String(l%12||12);case"hh":return Rd(l%12||12,2);case"a":return l<12?"am":"pm";case"A":return l<12?"AM":"PM";case"m":return String(e.getMinutes());case"mm":return Rd(e.getMinutes(),2);case"s":return String(e.getSeconds());case"ss":return Rd(e.getSeconds(),2);case"SSS":return Rd(e.getMilliseconds(),3);case"Z":return Fd(e);default:return Fd(e).replace(":","")}})}function jd(e){let t=e.getFullYear(),r=e.getMonth()+1,a=e.getDate();return(t>=1e3&&t<=9999?t:Rd(t,4))+(r<10?"-0":"-")+r+(a<10?"-0":"-")+a}var Vd=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,Xd=/\[[^\]]+]/g,Kd=/\d/,Zd=/\d\d/,Qd=/\d\d?/,Jd=/[+-]\d\d:?(\d\d)?|Z/,ef=/\d*[^-_:/,()\s\d]+/;function tf(e){return(t,r)=>(t[e]=+r,!0)}var rf=(e,t)=>{if("Z"===t)return e.offset=0,!0;let r=t.match(/([+-]|\d\d)/g),a=60*+r[1]+(+r[2]||0);return e.offset=0===a?0:"+"===r[0]?-a:a,!0};function af(e){return(t,r)=>{let a=e.indexOf(r)+1;return!(a<1)&&(t.month=a%12||a,!0)}}var lf,nf=new Map([["A",{re:ef,read:(e,t)=>(e.afternoon="PM"===t,!0)}],["a",{re:ef,read:(e,t)=>(e.afternoon="pm"===t,!0)}],["Q",{re:Kd,read:(e,t)=>(e.month=3*(+t-1)+1,!0)}],["S",{re:Kd,read:(e,t)=>(e.milliseconds=100*+t,!0)}],["SS",{re:Zd,read:(e,t)=>(e.milliseconds=10*+t,!0)}],["SSS",{re:/\d{3}/,read:(e,t)=>(e.milliseconds=+t,!0)}],["s",{re:Qd,read:tf("seconds")}],["ss",{re:Qd,read:tf("seconds")}],["m",{re:Qd,read:tf("minutes")}],["mm",{re:Qd,read:tf("minutes")}],["H",{re:Qd,read:tf("hours")}],["h",{re:Qd,read:tf("hours")}],["HH",{re:Qd,read:tf("hours")}],["hh",{re:Qd,read:tf("hours")}],["D",{re:Qd,read:tf("day")}],["DD",{re:Zd,read:tf("day")}],["Do",{re:ef,read:(e,t)=>{let r=t.match(/\d+/);if(!r)return!1;e.day=+r[0],e.dayGiven=!0;for(let r=1;r<=31;r++)Ld(r)===t&&(e.day=r);return!0}}],["w",{re:Qd,read:tf("week")}],["ww",{re:Zd,read:tf("week")}],["M",{re:Qd,read:tf("month")}],["MM",{re:Zd,read:tf("month")}],["MMM",{re:ef,read:af(Id.map(e=>e.slice(0,3)))}],["MMMM",{re:ef,read:af(Id)}],["Y",{re:/[+-]?\d+/,read:tf("year")}],["YY",{re:Zd,read:(e,t)=>(e.year=+t+(+t>68?1900:2e3),!0)}],["YYYY",{re:/\d{4}/,read:tf("year")}],["Z",{re:Jd,read:rf}],["ZZ",{re:Jd,read:rf}]]),sf=null;function of(e,t,r){if("x"===t||"X"===t)return new Date(("X"===t?1e3:1)*Number(e));let a=function(e){if(e===lf)return sf;if(lf=e,sf=null,/[Ll]/.test(e.replace(Xd,"")))return null;let t=e.match(Vd);return t?sf=t.map(e=>nf.get(e)??e.replace(/^\[|\]$/g,"")):null}(t);if(!a)return;let i={},l=e,n=0;for(let e of a){if("string"==typeof e){n+=e.length;continue}let t=e.re.exec(l.slice(n));if(!t||!e.read(i,t[0]))return;l=l.replace(t[0],"")}void 0!==i.afternoon&&void 0!==i.hours&&(i.afternoon?i.hours<12&&(i.hours+=12):12===i.hours&&(i.hours=0));let s=i.dayGiven||i.day?i.day:i.year||i.month?1:r.getDate(),o=i.year||r.getFullYear(),h=0;i.year&&!i.month||(h=i.month>0?i.month-1:r.getMonth());let c=i.hours||0,d=i.minutes||0,f=i.seconds||0,u=i.milliseconds||0;return void 0!==i.offset?new Date(Date.UTC(o,h,s,c,d,f,u+6e4*i.offset)):i.week?void 0:new Date(o,h,s,c,d,f,u)}var hf=/^[YMDHhmsSZXx\-/.:, T]*$/,cf=/^\s*(active|done|crit|milestone|vert)\s*$/,df=/^after\s+([\d\w- ]+)/,ff=/^until\s+([\d\w- ]+)/,uf=/^(\d+(?:\.\d+)?)([Mdhmswy]|ms)$/,pf=/[\s,]+/,gf=/^\d+$/,mf=new Set(Nd.map(e=>e.toLowerCase()));function yf(e){let t=void 0===e?NaN:+e;return Number.isFinite(t)?t:Date.now()}function xf(e,t){let r=new Set(e);for(let e of t.toLowerCase().split(pf))""!==e&&r.add(e);return[...r]}var wf=class{type="gantt";title;accTitle;accDescr;dateFormat="";axisFormat="";tickInterval;todayMarker="";includes=[];excludes=[];inclusiveEndDates=!1;topAxis=!1;displayMode="";weekday;weekend="saturday";sections=[];links=new Map;tasks=[];byId=new Map;currentSection="";taskCount=0;lastOrder=0;lastTaskId;options;now=0;work=0;includeSet=new Set;excludeSet=new Set;excludedDays=[];datedTokens=!1;constructor(e={}){this.options=e}setDateFormat(e){this.dateFormat=e}enableInclusiveEndDates(){this.inclusiveEndDates=!0}TopAxis(){this.topAxis=!0}setAxisFormat(e){this.axisFormat=e}setTickInterval(e){this.tickInterval=e}setTodayMarker(e){this.todayMarker=e}setIncludes(e){this.includes=xf(this.includes,e)}setExcludes(e){this.excludes=xf(this.excludes,e)}setWeekday(e){this.weekday=e}setWeekend(e){this.weekend=e}setDiagramTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addSection(e){this.currentSection=e,this.sections.push(e)}addTask(e,t){let r,a=(t.startsWith(":")?t.slice(1):t).split(","),l={id:"",task:e,section:this.currentSection,startTime:void 0,endTime:void 0,renderEndTime:null,manualEndTime:!1,processed:!1,active:!1,done:!1,crit:!1,milestone:!1,vert:!1,order:-1,classes:[],prevTaskId:this.lastTaskId,raw:{data:t,start:void 0,end:""}};for(;a.length>0&&null!==(r=cf.exec(a[0]));)l[r[1]]=!0,a.shift();if(0===a.length)throw new i(`Task "${e.trim()}" needs a duration or an end date.`,"semantic",{type:"gantt"});if(a.length>3)throw new i(`Task "${e.trim()}" has too many fields. A task takes an id, a start, and an end or duration.`,"semantic",{type:"gantt"});for(let e=0;e<a.length;e++)a[e]=a[e].trim();3===a.length?l.id=a[0]:(this.taskCount++,l.id="task"+this.taskCount),a.length>1&&(l.raw.start=a[a.length-2]),l.raw.end=a[a.length-1],l.vert||(l.order=this.lastOrder++),this.tasks.push(l),this.lastTaskId=l.id,this.byId.set(l.id,l)}setLink(e,t){let r=dr(t);for(let t of e.split(","))this.byId.has(t)&&this.links.set(t,r);this.setClass(e,"clickable")}setClickEvent(e,t,r){this.setClass(e,"clickable")}setClass(e,t){for(let r of e.split(","))this.byId.get(r)?.classes.push(t)}getTasks(e){this.now=yf(e),this.work=0,this.includeSet=new Set(this.includes),this.excludeSet=new Set(this.excludes);let t="friday"===this.weekend?5:"saturday"===this.weekend?6:NaN,r=this.excludeSet.has("weekends");this.excludedDays=Nd.map((e,a)=>{let i=a||7;return r&&(i===t||i===t+1)||this.excludeSet.has(e.toLowerCase())}),this.datedTokens=this.includes.length>0||!hf.test(this.dateFormat.trim());for(let e of this.excludes)"weekends"!==e&&!mf.has(e)&&(this.datedTokens=!0);for(let e of this.tasks)e.startTime=e.endTime=void 0,e.renderEndTime=null,e.processed=e.manualEndTime=!1;let a=this.compileTasks();for(let e=0;!a&&e<10;e++)a=this.compileTasks();return this.tasks}isInvalidDate(e){let t=this.excludedDays[e.getDay()];if(!this.datedTokens)return t;let r=this.dateFormat.trim(),a=jd(e),i=a;this.spend(200),"YYYY-MM-DD"!==r&&(this.spend(400+8*r.length),i=qd(e,r));let l=e=>e.has(a)||void 0!==i&&e.has(i);return!l(this.includeSet)&&(t||l(this.excludeSet))}spend(e){if(this.work+=e,this.work>4e8)throw new i("The gantt chart takes too much work to schedule.","limit",{type:"gantt"})}parse(e,t){return this.spend((t.length+1)*(e.length+1)),function(e,t,r){let a=of(e,t,r);return a&&Dd(a)&&qd(a,t)===e?a:void 0}(e,t,new Date(this.now))}today(){let e=new Date(this.now);return e.setHours(0,0,0,0),e}warn(e){this.options.warn&&this.options.warn(e())}compileTasks(){let e=!0;for(let t of this.tasks)this.compileTask(t),e=e&&t.processed;return e}compileTask(e){let t=e.raw.start;if(void 0===t){let t=void 0===e.prevTaskId?void 0:this.byId.get(e.prevTaskId);e.startTime=t?t.endTime:this.today()}else{let r=this.getStartDate(t);r&&(e.startTime=r)}e.startTime&&(e.endTime=this.getEndDate(e.startTime,e.raw.end),e.endTime&&(e.processed=!0,e.manualEndTime=void 0!==this.parse(e.raw.end,"YYYY-MM-DD"),this.checkTaskDates(e)))}references(e,t){let r,a=[];for(let e of t.split(" ")){if(""===e)continue;let t=this.byId.get(e);t?a.push(t):(r??=[]).push(e)}if(r){let t=r;this.warn(()=>`Gantt: "${e}" refers to task ids that do not exist: ${t.join(", ")}.`)}return a}getStartDate(e){let t=e.trim(),r=this.dateFormat.trim();if(("x"===r||"X"===r)&&gf.test(t))return this.checked(new Date(Number(t)),t);let a=df.exec(t);if(null!==a){let e,t=this.references("after",a[1]);for(let r of t)(!e||r.endTime>e.endTime)&&(e=r);return e?e.endTime:this.today()}let l=this.parse(t,r);if(l)return l;let n=new Date(t);if(!Dd(n)||n.getFullYear()<-1e4||n.getFullYear()>1e4)throw new i("Invalid date:"+t,"semantic",{type:"gantt"});return n}checked(e,t){if(!Dd(e))throw new i("Invalid date:"+t,"semantic",{type:"gantt"});return e}getEndDate(e,t){let r=t.trim(),a=ff.exec(r);if(null!==a){let e,t=this.references("until",a[1]);for(let r of t)(!e||r.startTime<e.startTime)&&(e=r);return e?e.startTime:this.today()}let i=this.dateFormat.trim(),l=this.parse(r,i);if(l)return this.inclusiveEndDates?Wd(l,1):l;let[n,s]=function(e){let t=uf.exec(e.trim());return t?[Number.parseFloat(t[1]),t[2]]:[NaN,"ms"]}(r);if(Number.isNaN(n))return this.warn(()=>`Gantt: "${r}" is neither a date in the "${i}" format nor a duration such as "3d", so the task gets no duration.`),new Date(e);let o=Bd(e,n,s);return Dd(o)?o:new Date(e)}checkTaskDates(e){if(0===this.excludes.length||e.manualEndTime)return;let t=Wd(e.startTime,1),r=new Date(e.endTime),a=+Wd(r,1e4),l=!1,n=null;for(;+t<=+r;){if(this.spend(400),l||(n=+r),l=this.isInvalidDate(t),l&&(r.setDate(r.getDate()+1),+r>a))throw new i("Failed to find a valid date that was not excluded by `excludes` after 10,000 iterations.","semantic",{type:"gantt"});t.setDate(t.getDate()+1)}e.endTime=r,e.renderEndTime=null===n?null:new Date(n)}},$f=["$end","INVALID","open_directive","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","NL","href","callbackname","callbackargs","click","gantt","dateFormat","inclusiveEndDates","topAxis","axisFormat","tickInterval","includes","excludes","todayMarker","weekday_monday","weekday_tuesday","weekday_wednesday","weekday_thursday","weekday_friday","weekday_saturday","weekday_sunday","weekend_friday","weekend_saturday","date","title","accDescription","section","taskTxt","taskData",":","EOF"],bf=/accTitle\s*:\s*/iy,Mf=/accDescr\s*:\s*/iy,vf=/accDescr\s*\{\s*/iy,kf=/href\s+"/iy,Af=/call\s+/iy,Tf=/click\s+/iy,Cf=/\(\s*\)/y,Ef=/weekday\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/iy,_f=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],Sf=/weekend\s+(?:(friday)|saturday)\b/iy,If=/\d\d\d\d-\d\d-\d\d\b/y,Nf=/title[^\S\r\n]*(?=[\r\n]|$)/iy,Df=new Map([[97,[[/axisFormat\s[^#\n;]+/iy,17],[/accDescription\s[^#\n;]+/iy,33]]],[103,[[/gantt\b/iy,13]]],[100,[[/dateFormat\s[^#\n;]+/iy,14]]],[105,[[/inclusiveEndDates\b/iy,15],[/includes\s[^#\n;]+/iy,19]]],[116,[[/topAxis\b/iy,16],[/tickInterval\s[^#\n;]+/iy,18],[/todayMarker\s[^\n;]+/iy,21],[/title[^\S\r\n][^\n]+/iy,32]]],[101,[[/excludes\s[^#\n;]+/iy,20]]],[115,[[/section\s[^\n]+/iy,34]]]]);var Rf=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],Lf="'EOF', 'SPACE', 'NL', 'weekday_monday', 'weekday_tuesday', 'weekday_wednesday', 'weekday_thursday', 'weekday_friday', 'weekday_saturday', 'weekday_sunday', 'weekend_friday', 'weekend_saturday', 'dateFormat', 'inclusiveEndDates', 'topAxis', 'axisFormat', 'tickInterval', 'excludes', 'includes', 'todayMarker', 'title', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'section', 'taskTxt', 'click'",Of=new Uint8Array(39);for(let e=22;e<=30;e++)Of[e]=1;for(let e of[38,8,14,15,16,17,18,20,19,21,32,3,5,7,34,35,12])Of[e]=1;function Ff(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l=0,n=0,s=(t,l,s)=>{r.push(t),a.push(e.slice(l,s)),i.push(l),n=s},o=t=>(t.lastIndex=n,t.test(e)?t.lastIndex:-1),h=(r,a)=>{let i=e.indexOf(r,a);return-1===i?t:i},c=t=>{let r;switch(32|t){case 97:if((r=o(bf))>=0)return l=1,s(3,n,r),!0;if((r=o(Mf))>=0)return l=2,s(5,n,r),!0;if((r=o(vf))>=0)return l=3,n=r,!0;break;case 104:if((r=o(kf))>=0)return l=4,n=r,!0;break;case 99:if((r=o(Af))>=0)return l=5,n=r,!0;if((r=o(Tf))>=0)return l=7,n=r,!0;break;case 116:if((r=o(Nf))>=0)return n=r,!0;break;case 119:{Ef.lastIndex=n;let t=Ef.exec(e);if(t)return s(22+_f.indexOf(t[1].toLowerCase()),n,Ef.lastIndex),!0;if(Sf.lastIndex=n,t=Sf.exec(e),t)return s(void 0!==t[1]?29:30,n,Sf.lastIndex),!0;break}}let a=Df.get(32|t);if(a)for(let[e,t]of a)if((r=o(e))>=0)return s(t,n,r),!0;return!1};for(;;){if(n>=t){let e=38;switch(l){case 1:e=4;break;case 2:e=6;break;case 3:e=7;break;case 4:e=9;break;case 5:e=10;break;case 6:e=11;break;case 7:e=12}s(e,t,t);break}let d=e.charCodeAt(n);switch(l){case 0:{let l=e.charCodeAt(n+1);if(37===d)if(37!==l){let t=h("\n",n+1);for(;10===e.charCodeAt(t);)t++;n=t}else{if(123===e.charCodeAt(n+2))return s(2,n,n+3),s(1,n,n),{types:r,texts:a,starts:i};n=h("\n",n+2)}else if(10===d){let t=n+1;for(;10===e.charCodeAt(t);)t++;s(8,n,t)}else if(q(d))for(n++;n<t&&q(e.charCodeAt(n));)n++;else{if(c(d))break;if(d>=48&&d<=57&&o(If)>=0)s(31,n,n+10);else if(58!==d){let r=n+1;for(;r<t;){let t=e.charCodeAt(r);if(58===t||10===t)break;r++}s(35,n,r)}else{let r=n+1;for(;r<t;){let t=e.charCodeAt(r);if(35===t||10===t||59===t)break;r++}s(r>n+1?36:37,n,r)}}break}case 1:case 2:{let e=1===l?4:6;l=0,s(e,n,h("\n",n));break}case 3:125===d?(l=0,n++):s(7,n,h("}",n));break;case 4:34===d?(l=0,n++):s(9,n,h('"',n));break;case 5:if(40===d){let e=o(Cf);e>=0?(l=0,n=e):(l=6,n++)}else s(10,n,h("(",n));break;case 6:41===d?(l=0,n++):s(11,n,h(")",n));break;case 7:if(q(d))l=0,n++;else{let r=n+1;for(;r<t&&!q(e.charCodeAt(r));)r++;s(12,n,r)}}}return r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}(e),l=0,n=t=>{let a=r[l];throw c("gantt",e,i[l],`Expecting ${t}, got '${0===a?"1":$f[a]}'`)},s=(e="")=>{1!==Of[r[l]]&&n(Lf+e)};for(13!==r[l]&&n("'gantt'"),l++;;){let e=r[l],i=a[l];switch(1!==Of[e]&&n(Lf),l++,e){case 38:if(0===r[l])return;s();break;case 8:break;case 14:s(),t.setDateFormat(i.slice(11));break;case 15:s(),t.enableInclusiveEndDates();break;case 16:s(),t.TopAxis();break;case 17:s(),t.setAxisFormat(i.slice(11));break;case 18:s(),t.setTickInterval(i.slice(13));break;case 20:s(),t.setExcludes(i.slice(9));break;case 19:s(),t.setIncludes(i.slice(9));break;case 21:s(),t.setTodayMarker(i.slice(12));break;case 29:s(),t.setWeekend("friday");break;case 30:s(),t.setWeekend("saturday");break;case 32:s(),t.setDiagramTitle(i.slice(6));break;case 3:{4!==r[l]&&n("'acc_title_value'");let e=a[l++];s(),t.setAccTitle(e.trim());break}case 5:{6!==r[l]&&n("'acc_descr_value'");let e=a[l++];s(),t.setAccDescription(e.trim());break}case 7:s(),t.setAccDescription(i.trim());break;case 34:s(),t.addSection(i.slice(8));break;case 35:{36!==r[l]&&n("'taskData'");let e=a[l++];s(),t.addTask(i,e);break}case 12:{let e,o,h=null;10===r[l]?(e=a[l++],11===r[l]&&(h=a[l++]),9===r[l]?(o=a[l++],s()):s(null===h?", 'callbackargs', 'href'":", 'href'")):9===r[l]?(o=a[l++],10===r[l]?(e=a[l++],11===r[l]?(h=a[l++],s()):s(", 'callbackargs'")):s(", 'callbackname'")):n("'callbackname', 'href'"),void 0!==e&&t.setClickEvent(i,e,h),void 0!==o&&t.setLink(i,o);break}default:s(),t.setWeekday(Rf[e-22])}}}var zf=1e3,Wf=6e4,Pf=60*Wf,Bf=24*Pf,Hf=7*Bf,Yf=30*Bf,Gf=365*Bf;function Uf(e){e.setHours(0,0,0,0)}function qf(e){return{floor(t){t.setDate(t.getDate()-(t.getDay()+7-e)%7),Uf(t)},offset:(e,t)=>e.setDate(e.getDate()+7*t),cycle:1/0,ms:Hf}}var jf={millisecond:{floor:()=>{},offset:(e,t)=>e.setTime(+e+t),cycle:1/0,ms:1},second:{floor:e=>e.setTime(+e-e.getMilliseconds()),offset:(e,t)=>e.setTime(+e+t*zf),field:e=>e.getUTCSeconds(),cycle:60,ms:zf},minute:{floor:e=>e.setTime(+e-e.getMilliseconds()-e.getSeconds()*zf),offset:(e,t)=>e.setTime(+e+t*Wf),field:e=>e.getMinutes(),cycle:60,ms:Wf},hour:{floor:e=>e.setTime(+e-e.getMilliseconds()-e.getSeconds()*zf-e.getMinutes()*Wf),offset:(e,t)=>e.setTime(+e+t*Pf),field:e=>e.getHours(),cycle:24,ms:Pf},day:{floor:Uf,offset:(e,t)=>e.setDate(e.getDate()+t),field:e=>e.getDate()-1,cycle:31,ms:Bf},month:{floor(e){e.setDate(1),Uf(e)},offset:(e,t)=>e.setMonth(e.getMonth()+t),field:e=>e.getMonth(),cycle:12,ms:Yf},year:{floor(e){e.setMonth(0,1),Uf(e)},offset:(e,t)=>e.setFullYear(e.getFullYear()+t),cycle:1/0,ms:Gf}};function Vf(e,t,r){return Math.floor((+t-+e-(t.getTimezoneOffset()-e.getTimezoneOffset())*Wf)/r)}function Xf(e,t,r){let a="week"===e?qf(r):jf[e];if(t<=1)return a;if("millisecond"===e)return{...a,floor:e=>e.setTime(Math.floor(+e/t)*t),offset:(e,r)=>e.setTime(+e+r*t)};if("year"===e)return{...a,floor(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),a.floor(e)},offset:(e,r)=>e.setFullYear(e.getFullYear()+r*t)};if("week"===e){let e=new Date(0);return a.floor(e),{...a,floor(r){a.floor(r),a.offset(r,-function(e,t){return(e%t+t)%t}(Vf(e,r,Hf),t))},offset:(e,r)=>a.offset(e,r*t)}}let i=a.field,l=e=>i(e)%t===0;return{...a,floor(e){for(a.floor(e);Number.isFinite(+e)&&!l(e);a.floor(e))e.setTime(+e-1)},offset(e,t){for(let r=0;r<t&&Number.isFinite(+e);r++)do{a.offset(e,1)}while(Number.isFinite(+e)&&!l(e))}}}function Kf(e,t,r,a){let i=new Date(t-1);e.floor(i),e.offset(i,1),e.floor(i);let l=[],n=-1/0;for(;+i<=r&&+i>n;){if(l.length>=a)return;n=+i,l.push(n),e.offset(i,1),e.floor(i)}return l}function Zf(e,t,r){let a=(t-e)/Math.max(0,r),i=Math.floor(Math.log10(a)),l=a/Math.pow(10,i),n=l>=Math.sqrt(50)?10:l>=Math.sqrt(10)?5:l>=Math.SQRT2?2:1;return Math.pow(10,i)*n}var Qf=[["second",1,zf],["second",5,5e3],["second",15,15e3],["second",30,3e4],["minute",1,Wf],["minute",5,5*Wf],["minute",15,15*Wf],["minute",30,30*Wf],["hour",1,Pf],["hour",3,3*Pf],["hour",6,6*Pf],["hour",12,12*Pf],["day",1,Bf],["day",2,2*Bf],["week",1,Hf],["month",1,Yf],["month",3,3*Yf],["year",1,Gf]];var Jf=/^([1-9]\d*)(millisecond|second|minute|hour|day|week|month)$/,eu=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];function tu(e,t,r){let a=e<0?"-":"",i=String(a?-e:e);return a+(i.length<r?t.repeat(r-i.length)+i:i)}function ru(e,t){let r=new Date(+e);return t.floor(r),r}function au(e,t){let r=qf(t),a=ru(e,jf.year);return Vf(ru(new Date(+a-1),r),ru(e,r),Hf)}function iu(e){let t=qf(4),r=e.getDay(),a=ru(r>=4||0===r?e:new Date(+e-1),t);return r>=4||0===r||(t.offset(a,1),t.floor(a)),a}var lu=new Map([["-",""],["_"," "],["0","0"]]);function nu(e,t){let r="",a=0,i=e.length;for(let l=0;l<i;l++){if(37!==e.charCodeAt(l))continue;r+=e.slice(a,l);let i=e.charAt(++l),n=lu.get(i);void 0!==n?i=e.charAt(++l):n="e"===i?" ":"0",r+=su(i,t,n),a=l+1}return r+e.slice(a)}function su(e,t,r){switch(e){case"a":return Nd[t.getDay()].slice(0,3);case"A":return Nd[t.getDay()];case"b":return Id[t.getMonth()].slice(0,3);case"B":return Id[t.getMonth()];case"c":return nu("%x, %X",t);case"d":case"e":return tu(t.getDate(),r,2);case"f":return tu(t.getMilliseconds(),r,3)+"000";case"g":return tu(iu(t).getFullYear()%100,r,2);case"G":return tu(iu(t).getFullYear()%1e4,r,4);case"H":return tu(t.getHours(),r,2);case"I":return tu(t.getHours()%12||12,r,2);case"j":return tu(1+Vf(ru(t,jf.year),ru(t,jf.day),Bf),r,3);case"L":return tu(t.getMilliseconds(),r,3);case"m":return tu(t.getMonth()+1,r,2);case"M":return tu(t.getMinutes(),r,2);case"p":return t.getHours()>=12?"PM":"AM";case"q":return String(1+Math.floor(t.getMonth()/3));case"Q":return String(+t);case"s":return String(Math.floor(+t/1e3));case"S":return tu(t.getSeconds(),r,2);case"u":return String(t.getDay()||7);case"U":return tu(au(t,0),r,2);case"V":{let e=iu(t),a=ru(e,jf.year);return tu(Vf(ru(a,qf(4)),e,Hf)+(4===a.getDay()?1:0),r,2)}case"w":return String(t.getDay());case"W":return tu(au(t,1),r,2);case"x":return nu("%-m/%-d/%Y",t);case"X":return nu("%-I:%M:%S %p",t);case"y":return tu(t.getFullYear()%100,r,2);case"Y":return tu(t.getFullYear()%1e4,r,4);case"Z":{let e=t.getTimezoneOffset(),r=Math.abs(e);return(e>0?"-":"+")+tu(Math.floor(r/60),"0",2)+tu(r%60,"0",2)}case"%":return"%";default:return e}}var ou=/<br\s*\/?>/gi;function hu(e,t,r,a){let i=e.gantt?.[t];return"number"==typeof i&&Number.isFinite(i)?Math.min(a,Math.max(r,i)):void 0}function cu(e,t){let r=e.gantt?.[t];return"string"==typeof r?r:void 0}function du(e,t,r){let a=Fl(e.replace(ou," "),!1,t,r,4e3);return a.lines.length<=1?a:{...a,lines:[a.lines[0]],widths:[a.widths[0]],width:a.widths[0],height:a.lineHeight}}function fu(e){return Number.isFinite(+e.startTime)&&Number.isFinite(+e.endTime)}function uu(e,t,r){let a=e.filter(fu).sort((e,t)=>+e.startTime-+t.startTime||e.order-t.order),i=[];for(let e of a){let a=+e.startTime,l=0;for(;l<i.length&&a<i[l];)l++;i[l]=+e.endTime,r.set(e,t+l)}let l=i.length;for(let a of e)r.has(a)||r.set(a,t+l++);return Math.max(l,1)}var pu={type:"gantt",parse(e,t,r){let a=new wf;r&&(a.title=r);let i=t.gantt?.displayMode;return"string"==typeof i&&(a.displayMode=i),Ff(e,a),a},render:function(e,t,r){let a=r.fontSize??16,i=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),l=r.padding??8,n=yf(r.now),s=hu(t,"fontSize",4,72)??Math.round(.8125*a),o=hu(t,"sectionFontSize",4,72)??s,h=Math.round(.75*a),c=hu(t,"barHeight",4,400)??Math.round(1.85*s),d=c+(hu(t,"barGap",0,400)??Math.round(c/4)),f=Math.round(hu(t,"numberSectionStyles",1,1e3)??4),u="compact"===e.displayMode,p=e.topAxis||function(e,t){return!0===e.gantt?.[t]}(t,"topAxis"),g=e.getTasks(n),m=g.filter(e=>!e.vert),y=g.filter(e=>e.vert&&fu(e)),x=new Map;for(let e of m)x.has(e.section)||x.set(e.section,x.size);let w=new Map,$=[];if(u){let e=new Map;for(let t of m){let r=e.get(t.section);r?r.push(t):e.set(t.section,[t])}for(let[t,r]of e){let e=uu(r,$.length,w);for(let r=0;r<e;r++)$.push(t)}}else for(let e of m)w.set(e,$.length),$.push(e.section);let b=$.length,M=1/0,v=-1/0;for(let e of g)fu(e)&&(M=Math.min(M,+e.startTime),v=Math.max(v,+e.endTime));let k=M<=v,A=Fl(e.title,!1,i,a,4e3,1),T=A.height>0?A.height+16:0;if(!k){let t=Math.ceil(Math.max(A.width,1)+2*l),i=Math.ceil(Math.max(A.height,1)+2*l);return{svg:Bi("gantt",t,i,a,r,e,Fe(A,t/2,l+A.height/2,' class="pele-title" font-weight="var(--_tw)"')),width:t,height:i,links:[]}}let C=new Map,E=0;for(let e of x.keys()){let t=Fl(e,!1,i,o,180);C.set(e,t),E=Math.max(E,t.width)}let _=e.axisFormat||("D"===e.dateFormat?"%d":cu(t,"axisFormat")??"%Y-%m-%d"),S=e=>nu(_,new Date(e)),I=Math.max(i.width(S(M),h,0),i.width(S(v),h,0)),N=l+(hu(t,"leftPadding",0,2e3)??Math.max(E>0?E+24:0,I/2)),D=hu(t,"rightPadding",0,2e3)??Math.max(16,I/2),R=Ul(r,hu(t,"useWidth",100,2e4)??800,280),L=Math.max(240,R-N-D-l),O=N+L,F=v>M?L/(v-M):0,z=e=>0===F?N+L/2:N+(e-M)*F,W=Math.round(1.75*h),P=hu(t,"topPadding",0,2e3),B=hu(t,"gridLineStartPadding",0,2e3),H=l+T+(p?W:0),Y=Math.max(H,P??0),G=void 0!==P&&void 0!==B?Math.max(0,Math.min(P-B,Y-H)):0,U=Math.max(b,1)*d,q=Y+U,j=[],V=O+D;for(let e of m){let t=du(e.task,i,s),r=w.get(e);if(!fu(e)){let a=N+8+t.width/2;V=Math.max(V,a+t.width/2),j.push({task:e,label:t,row:r,x0:NaN,x1:NaN,labelX:a,inside:!1});continue}let a=z(+e.startTime),l=Math.max(z(+(e.renderEndTime??e.endTime)),a+(e.milestone?0:2));if(e.milestone){let t=a+(z(+e.endTime)-a)/2;a=t-c/2,l=t+c/2}let n=!e.milestone&&t.width+16<=l-a,o=(a+l)/2;if(!n){let e=l+8+t.width<=O+D,r=a-8-t.width>=N;o=e||!r?l+8+t.width/2:a-8-t.width/2,V=Math.max(V,o+t.width/2)}j.push({task:e,label:t,row:r,x0:a,x1:l,labelX:o,inside:n})}let X=e.tickInterval||cu(t,"tickInterval")||"",K=e.weekday??cu(t,"weekday")??"sunday",Z=Math.max(2,Math.min(10,Math.floor(L/(I+24)))),Q=function(e,t,r,a,i){let l=Jf.exec(e);if(!l)return;let n=parseInt(l[1],10),s=Xf(l[2],n,Math.max(0,eu.indexOf(t)));return(a-r)/(Math.min(n,s.cycle)*s.ms)>i?void 0:Kf(s,r,a,i)}(X,K,M,v,Math.ceil(L/3))??function(e,t,r){let a,i=(t-e)/r,l=0;for(;l<Qf.length&&Qf[l][2]<=i;)l++;if(l===Qf.length)a=Xf("year",Math.max(1,Zf(e/Gf,t/Gf,r)),0);else if(0===l)a=Xf("millisecond",Math.max(Zf(e,t,r),1),0);else{let[e,t]=Qf[i/Qf[l-1][2]<Qf[l][2]/i?l-1:l];a=Xf(e,t,0)}return Kf(a,e,t,4*r+8)??[]}(M,v,Z),J="",ee="",te="",re=-1/0,ae="",ie=q+W/2+2,le=Y-G-W/2-2;for(let e of Q){let t=z(e);J+=`M${Oe(t)},${Oe(Y-G)}V${Oe(q)}`;let r=S(e),a=i.width(r,h,0);if(t-a/2<re+8||r===ae)continue;re=t+a/2,ae=r,V=Math.max(V,re);let l=`text-anchor="middle">${De(r)}</text>`;ee+=`<text x="${Oe(t)}" y="${Oe(ie+.35*h)}" ${l}`,p&&(te+=`<text x="${Oe(t)}" y="${Oe(le+.35*h)}" ${l}`)}let ne="",se="",oe=[],he=q+W+4,ce=Math.round(1.5*s);for(let e of[...y].sort((e,t)=>+e.startTime-+t.startTime)){let t=z(+e.startTime),r=du(e.task,i,s),a=Math.max(l+r.width/2,t),n=0;for(;n<oe.length&&a-r.width/2<oe[n]+8;)n++;oe[n]=a+r.width/2,V=Math.max(V,oe[n]),ne+=`<path class="pele-vert" data-id="${Re(e.id)}" d="M${Oe(t)},${Oe(Y-G)}V${Oe(q)}"/>`,se+=Fe(r,a,he+n*ce+ce/2,` class="pele-vert-label" data-id="${Re(e.id)}"`)}let de=Math.ceil(Math.max(V,l+A.width)+l),fe=Math.ceil(q+W+(oe.length>0?4+oe.length*ce:0)+l),ue="",pe="";for(let e=0;e<b;){let t=$[e],a=e+1;for(;a<b&&$[a]===t;)a++;let i=x.get(t)%f,n=Y+e*d,s=(a-e)*d;(x.size>1||""!==t)&&(ue+=`<rect class="pele-section pele-section-${i}" x="0" y="${Oe(n)}" width="${de}" height="${Oe(s)}" fill="${i%2==0?"var(--_s)":"none"}"/>`);let o=C.get(t);pe+=Fe(o,l+8+o.width/2,n+s/2,` class="pele-section-label" data-id="${Re(t)}"`,r.icons),e=a}let ge="";if((e.excludes.length>0||e.includes.length>0)&&+Bd(new Date(M),6,"y")>v){let t,r,a=()=>{if(!t||!r)return;let e=new Date(t);e.setHours(0,0,0,0);let a=new Date(r);a.setHours(23,59,59,999);let i=Math.max(N,z(+e)),l=Math.min(O,z(+a));l>i&&(ge+=`<rect x="${Oe(i)}" y="${Oe(Y)}" width="${Oe(l-i)}" height="${Oe(U)}"/>`),t=r=void 0};for(let i=new Date(M);+i<=v;i=Wd(i,1))e.isInvalidDate(i)?(t??=i,r=i):a();a()}let me=[],ye="";for(let t of j){let a=t.task,i=Y+t.row*d+d/2,l=a.active?"active":a.done?"done":"",n="pele-task";l&&(n+=" pele-"+l),a.crit&&(n+=" pele-crit"),a.milestone&&(n+=" pele-milestone"),a.classes.includes("clickable")&&(n+=" pele-clickable");let s="",o="";if(Number.isNaN(t.x0))n+=" pele-unscheduled",o=' fill="var(--_m)"';else{let e=a.crit?Ti:"var(--_c)",r="done"===l?'fill="var(--_a)"':"active"===l?`fill="${e}" fill-opacity="0.25"`:`fill="${e}"`,n=`stroke="${"done"!==l||a.crit?e:"var(--_b)"}"`;if(a.milestone){let e=(t.x0+t.x1)/2,a=c/2;s=`<path d="M${Oe(e)},${Oe(i-a)}L${Oe(e+a)},${Oe(i)}L${Oe(e)},${Oe(i+a)}L${Oe(e-a)},${Oe(i)}Z" ${r} ${n} stroke-linejoin="round"/>`}else s=`<rect x="${Oe(t.x0)}" y="${Oe(i-c/2)}" width="${Oe(t.x1-t.x0)}" height="${Oe(c)}" ${r} ${n}${Mi}/>`;t.inside?o=""===l?' fill="var(--_bg)"':"":"done"===l&&(o=' fill="var(--_m)"')}let h=s+Fe(t.label,t.labelX,i,` class="pele-label"${o}`),f=e.links.get(a.id);void 0!==f&&(h=Mr(h,f,a.id,me,r)),ye+=`<g class="${n}" data-id="${Re(a.id)}">${h}</g>`}let xe="";if("off"!==e.todayMarker&&n>=M&&n<=v&&v>M){let t=z(n),r=Y-G,a=e.todayMarker?Ri(e.todayMarker.split(",")).line:"";xe=`<g class="pele-today"><path d="M${Oe(t)},${Oe(r)}V${Oe(q)}" fill="none" stroke="var(--_c)" stroke-width="2"${a}/>`+(a?"":`<path d="M${Oe(t-4)},${Oe(r-5)}H${Oe(t+4)}L${Oe(t)},${Oe(r+1)}Z" fill="var(--_c)"/>`)+"</g>"}let we=`M${Oe(N)},${Oe(q)}H${Oe(O)}`+(p?`M${Oe(N)},${Oe(Y-G)}H${Oe(O)}`:"");return{svg:Bi("gantt",de,fe,a,r,e,Fe(A,de/2,l+A.height/2,' class="pele-title" font-weight="var(--_tw)"')+(ue?`<g class="pele-sections">${ue}</g>`:"")+(ge?`<g class="pele-excluded" fill="var(--_a)">${ge}</g>`:"")+`<g class="pele-grid" fill="none"><path d="${J}" stroke="var(--_b)" stroke-dasharray="1 3"/><path d="${we}" stroke="var(--_b)"/></g>`+(ne?`<g class="pele-verts" fill="none" stroke="var(--_l)" stroke-width="1.5" stroke-dasharray="4 3">${ne}</g>`:"")+xe+`<g class="pele-tasks" font-size="${Oe(s)}">${ye}</g><g class="pele-section-labels" font-size="${Oe(o)}">${pe}</g><g class="pele-axis" font-size="${h}" fill="var(--_m)">${ee}${te}</g>`+(se?`<g class="pele-vert-labels" font-size="${Oe(s)}">${se}</g>`:"")),width:de,height:fe,links:me}}},gu=0,mu=1,yu=2,xu=3,wu=4;function $u(e){throw new i(e,"semantic",{type:"gitGraph"})}function bu(e){return"REVERSE"===e?mu:"HIGHLIGHT"===e?yu:gu}function Mu(e,t){switch(e.$type){case"Commit":t.commit({id:e.id,msg:e.message??"",type:void 0!==e.type?bu(e.type):gu,tags:e.tags??void 0});break;case"Branch":t.branch({name:e.name,order:e.order??0});break;case"Merge":t.merge({branch:e.branch,id:e.id??"",type:void 0!==e.type?bu(e.type):void 0,tags:e.tags??void 0});break;case"Checkout":t.checkout(e.branch);break;case"CherryPicking":t.cherryPick({id:e.id,targetId:"",tags:0===e.tags?.length?void 0:e.tags,parent:e.parent})}}function vu(e,t,r){let a=t.gitGraph,i="string"==typeof a?.mainBranchName?a.mainBranchName:"main",l="number"==typeof a?.mainBranchOrder?a.mainBranchOrder:0,n=new Map,s=new Map([[i,null]]),o=new Map([[i,l]]),h=[],c=null,d=i,f="LR",u=0,p=()=>{for(let e=u+1;;e+=2654435761){let t=`${u}-${(Math.imul(e,2654435761)>>>0).toString(16).padStart(8,"0").slice(0,7)}`;if(!n.has(t))return t}},g=e=>{c=e,n.set(e.id,e),s.set(d,e.id)},m=e=>{s.has(e)||$u(`Trying to checkout branch which is not yet created. (Help try using "branch ${e}")`),d=e;let t=s.get(e);c=t?n.get(t)??null:null};!function(e,t){e.dir&&t.setDirection(e.dir);for(let r of e.statements)Mu(r,t)}(e,{setDirection(e){f=e},commit({msg:e,id:t,type:r,tags:a}){let i={id:t||p(),message:e,seq:u++,type:r??gu,tags:a?[...a]:[],parents:null===c?[]:[c.id],branch:d};n.has(i.id)&&h.push(`Commit ID ${i.id} already exists`),g(i)},branch({name:e,order:t}){s.has(e)&&$u(`Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${e}")`),s.set(e,null!==c?c.id:null),o.set(e,t),m(e)},merge({branch:e,id:t,type:r,tags:a}){let i=s.get(d),l=s.get(e),o=i?n.get(i):void 0,h=l?n.get(l):void 0;o&&h&&o.branch===e&&$u(`Cannot merge branch '${e}' into itself.`),d===e&&$u('Incorrect usage of "merge". Cannot merge a branch to itself'),void 0===o&&$u(`Incorrect usage of "merge". Current branch (${d})has no commits`),s.has(e)||$u(`Incorrect usage of "merge". Branch to be merged (${e}) does not exist`),void 0===h&&$u(`Incorrect usage of "merge". Branch to be merged (${e}) has no commits`),o===h&&$u('Incorrect usage of "merge". Both branches have same head'),t&&n.has(t)&&$u(`Incorrect usage of "merge". Commit with id:${t} already exists, use different custom id`),g({id:t||p(),message:`merged branch ${e} into ${d}`,seq:u++,parents:null===c?[]:[c.id,l||""],branch:d,type:xu,customType:r,customId:!!t,tags:a?[...a]:[]})},cherryPick({id:e,targetId:t,tags:r,parent:a}){let i=e?n.get(e):void 0;if(void 0===i&&$u('Incorrect usage of "cherryPick". Source commit id should exist and provided'),a&&!i.parents.includes(a)&&$u("Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."),i.type===xu&&!a&&$u("Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."),t&&n.has(t))return;i.branch===d&&$u('Incorrect usage of "cherryPick". Source commit is already on current branch');let l=s.get(d);(!l||!n.has(l))&&$u(`Incorrect usage of "cherry-pick". Current branch (${d})has no commits`),g({id:p(),message:`cherry-picked ${i.message} into ${d}`,seq:u++,parents:null===c?[]:[c.id,i.id],branch:d,type:wu,tags:r?r.filter(Boolean):[`cherry-pick:${i.id}${i.type===xu?`|parent:${a}`:""}`]})},checkout:m});let y=[...o].map(([e,t],r)=>({name:e,order:t??parseFloat(`0.${r}`)})).sort((e,t)=>e.order-t.order).map(e=>e.name);return{type:"gitGraph",title:e.title||r,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,direction:f,commits:n,branches:s,lanes:y,currentBranch:d,head:c,warnings:h}}var ku={name:"REFERENCE",pattern:/\w([-\./\w]*[-\w])?/y},Au=[ku];function Tu(e){return{name:e,pattern:e,longer:Au}}var Cu=[Tu("cherry-pick"),{name:"gitGraph:",pattern:"gitGraph:"},Tu("HIGHLIGHT"),{...vn("gitGraph"),longer:Au},Tu("checkout"),Tu("REVERSE"),{name:"parent:",pattern:"parent:"},Tu("commit"),Tu("NORMAL"),Tu("branch"),{name:"order:",pattern:"order:"},Tu("switch"),{name:"type:",pattern:"type:"},Tu("merge"),{name:"msg:",pattern:"msg:"},{name:"tag:",pattern:"tag:"},{name:"id:",pattern:"id:"},Tu("LR"),Tu("TB"),Tu("BT"),{name:":",pattern:":"},{...un,opener:/[\t ]*accDescr\s*{/y},pn,mn(String.raw`[-./\w]*[-\w]`),{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y},yn,xn,wn,$n,bn,Mn,ku];var Eu=/<(?!br\s*\/?>)/gi,_u=/:fa-/g,Su=/<br\s*\/?>|fl°°?\w+¶ß|&#?\w+;|[\ud800-\udbff][\udc00-\udfff]|[\s\S]/gi;function Iu(e,t,r,a,i=0){let l=e;return void 0!==l&&(l.includes("<")&&(l=l.replace(Eu,"&lt;")),l.includes(":fa-")&&(l=l.replace(_u,"&colon;fa-"))),Fl(l,!1,t,r,a,i)}function Nu(e,t,r,a,i=0){let l=Iu(e,t,r,a,i);if(void 0===e||l.width<=a)return l;let n="",s=0;for(let l of e.match(Su)??[]){if(""===l.trim()||l.length>2&&"<"===l[0])s=0;else{let e=t.width(l.length>2?"x":l,r,i);s>0&&s+e>a&&(n+="\n",s=0),s+=e}n+=l}return Iu(n,t,r,a,i)}var Du=Math.SQRT1_2,Ru=["normal","reverse","highlight","merge","cherry-pick"];function Lu(e,t,r){let a=e.gitGraph?.[t];return"boolean"==typeof a?a:r}function Ou(e){return 11+e.width+6}function Fu(e,t,r,a){let i=`cx="${Oe(t)}" cy="${Oe(r)}"`;if(e===yu)return`<rect x="${Oe(t-7-1)}" y="${Oe(r-7-1)}" width="16" height="16" rx="2" fill="${a}"/>`;if(e===xu)return`<circle ${i} r="6" fill="var(--_bg)" stroke="${a}" stroke-width="2"/><circle ${i} r="2.5" fill="${a}"/>`;let l=`<circle ${i} r="7" fill="${a}"/>`;return e===mu?l+`<path d="M${Oe(t-3)},${Oe(r-3)}l6,6M${Oe(t-3)},${Oe(r+3)}l6,-6" fill="none" stroke="var(--_bg)" stroke-width="1.5" stroke-linecap="round"/>`:e===wu?l+`<path d="M${Oe(t-2.6)},${Oe(r+1)}L${Oe(t+.8)},${Oe(r-4.2)}L${Oe(t+2.6)},${Oe(r+1)}" fill="none" stroke="var(--_bg)" stroke-linejoin="round"/><circle cx="${Oe(t-2.6)}" cy="${Oe(r+2.2)}" r="1.8" fill="var(--_bg)"/><circle cx="${Oe(t+2.6)}" cy="${Oe(r+2.2)}" r="1.8" fill="var(--_bg)"/>`:l}function zu(e,t,r,a){let i=r.fontSize??16,l=Math.round(.75*i),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8,o=Lu(t,"showBranches",!0),h=Lu(t,"showCommitLabel",!0),c=Lu(t,"rotateCommitLabel",!0),d=Lu(t,"parallelCommits",!1),f="LR"!==a,u="BT"===a,p=new Map;e.lanes.forEach((e,t)=>p.set(e,t));let g=e.lanes.length,m=Math.round(.875*i),y=e.lanes.map(e=>Iu(o?e:"",n,m,4e3)),x=[],w=new Map;for(let t of[...e.commits.values()].sort((e,t)=>e.seq-t.seq)){let e=h&&t.type!==wu&&(t.type!==xu||!0===t.customId),r=[];for(let e of t.tags){let t=Iu(e,n,l,4e3);t.lines.length>0&&r.push(t)}let a={commit:t,index:x.length,lane:p.get(t.branch)??0,m:0,label:e?Iu(t.id,n,l,4e3):void 0,tags:r};x.push(a),w.set(t.id,a)}let $=new Float64Array(x.length),b=new Float64Array(x.length),M=new Float64Array(g).fill(7),v=new Float64Array(g).fill(7);x.forEach((e,t)=>{let{label:r,tags:a}=e,i=0,l=0;for(let e of a){let t=Ou(e);f?(i=Math.max(i,e.height),l+=t+4):(i=Math.max(i,t),l+=e.height+3)}let n=0,s=0;void 0!==r&&r.lines.length>0&&(c?s=3+Du*(r.width+r.height):(n=f?r.height:r.width,s=6+(f?r.width:r.height))),$[t]=Math.max(7,i/2,n/2),b[t]=i/2;let o=7+(a.length>0?6+l:0),h=7+s,d=e.lane;M[d]=Math.max(M[d],f?h:o),v[d]=Math.max(v[d],f?o:h)});let k=new Float64Array(x.length);f||x.forEach((e,t)=>{if(0!==b[t])for(let r of e.commit.parents){let a=w.get(r);void 0!==a&&a.lane<e.lane&&(k[t]=b[t]+4)}});let A=(e,t)=>Math.max(44,$[e]+$[t]+8,k[t]>0?$[e]+36+k[t]:0);x.forEach((e,t)=>{if(!d)return void(e.m=0===t?0:x[t-1].m+A(t-1,t));let r=0;for(let a of e.commit.parents){let e=w.get(a);void 0===e||e.index>=t||(r=Math.max(r,e.m+A(e.index,t)))}e.m=r});let T=0;for(let e of x)T=Math.max(T,e.m);let C=new Float64Array(g);for(let e=0;e<g;e++){let t=y[e],r=0===t.lines.length?0:f?t.width/2+8:t.height/2+2;M[e]=Math.max(M[e],r),v[e]=Math.max(v[e],r),e>0&&(C[e]=C[e-1]+Math.max(44,v[e-1]+M[e]+8))}let E=(e,t)=>f?t:e,_=(e,t)=>f?u?-e:e:t,S=(e,t)=>`${Oe(E(e,t))},${Oe(_(e,t))}`,I=1/0,N=1/0,D=-1/0,R=-1/0,L=(e,t,r,a)=>{e<I&&(I=e),t<N&&(N=t),r>D&&(D=r),a>R&&(R=a)},O="";if(o)for(let t=0;t<g;t++){let r=y[t],a=zi(t),i=C[t],l=r.width+16,n=r.height+4,s=0===r.lines.length?-20:-20-(f?n:l),o=E(s+(f?n:l)/2,i),h=_(s+(f?n:l)/2,i);L(E(-20,i),_(-20,i),E(-20,i),_(-20,i)),L(E(T+20,i),_(T+20,i),E(T+20,i),_(T+20,i)),O+=`<g class="pele-branch" data-id="${Re(e.lanes[t])}"><path class="pele-lane" d="M${S(-20,i)}L${S(T+20,i)}" stroke="${a}" stroke-dasharray="2 4"/>`,r.lines.length>0&&(L(o-l/2,h-n/2,o+l/2,h+n/2),O+=`<rect x="${Oe(o-l/2)}" y="${Oe(h-n/2)}" width="${Oe(l)}" height="${Oe(n)}" fill="${a}"${Mi}/>`+Fe(r,o,h,' class="pele-label"'+(St(t)||' fill="var(--_bg)"'))),O+="</g>"}let F=Array.from({length:g},()=>[]);for(let e of x)F[e.lane].push(e.m);if(d)for(let e of F)e.sort((e,t)=>e-t);let z=(e,t,r)=>{let a=F[e],i=0,l=a.length;for(;i<l;){let e=i+l>>1;a[e]<=t?i=e+1:l=e}return i<a.length&&a[i]<r},W="",P="";for(let e of x){let{commit:t}=e,r=C[e.lane],a=e.m;for(let i=0;i<t.parents.length;i++){let l=w.get(t.parents[i]);if(void 0===l||l===e)continue;let n=C[l.lane],s=l.m;if(l.lane===e.lane){P+=`<path class="pele-edge" d="M${S(s,n)}L${S(a,r)}" stroke="${zi(e.lane)}"/>`;continue}let o=i>0&&t.type===xu,h=i>0&&!o,c=`M${S(s,n)}`;if(a<=s){let e=(s+a)/2;c+=`C${S(e,n)} ${S(e,r)} ${S(a,r)}`}else if(o||z(e.lane,s,a)){let t=l.lane<e.lane&&a-k[e.index]>s?a-k[e.index]:a,i=Math.min(36,t-s),h=n;(!o||z(l.lane,s,a))&&(h=n>r?r+v[e.lane]+4:r-M[e.lane]-4,i=Math.min(36,(t-s)/2),c+=`C${S(s+i/2,n)} ${S(s+i/2,h)} ${S(s+i,h)}`),c+=`L${S(t-i,h)}C${S(t-i/2,h)} ${S(t-i/2,r)} ${S(t,r)}`,t<a&&(c+=`L${S(a,r)}`)}else{let e=Math.min(36,a-s);c+=`C${S(s+e/2,n)} ${S(s+e/2,r)} ${S(s+e,r)}L${S(a,r)}`}W+=`<path class="pele-edge${o?" pele-edge-merge":h?" pele-edge-cherry-pick":""}" d="${c}" stroke="${zi(o?l.lane:e.lane)}"${h?' stroke-dasharray="4 3"':""}/>`}}let B="";for(let e of x){let{commit:t,label:r,tags:a}=e,i=E(e.m,C[e.lane]),l=_(e.m,C[e.lane]),n=t.customType??t.type;L(i-7-1,l-7-1,i+7+1,l+7+1);let s=t.type<xu&&""!==t.message?`<title>${Re(t.message)}</title>`:"";if(s+=Fu(n,i,l,zi(e.lane)),void 0!==r&&r.lines.length>0){let e=r.width,t=r.height,a=(r,a)=>`<rect x="${Oe(r-e/2-2)}" y="${Oe(a-t/2+2)}" width="${Oe(e+4)}" height="${Oe(t-4)}" rx="3" fill="var(--_bg)"/>`;if(c){let n=Du*t/2,o=f?i-7-3-n:i+3,h=f?l:l+7+3+n,c=Du*e+n;L(o-c,u?h-c:h-n,o+n,u?h+n:h+c),s+=`<g class="pele-commit-label" transform="rotate(${u?45:-45} ${Oe(o)} ${Oe(h)})">`+a(o-e/2,h)+Fe(r,o-e/2,h,"")+"</g>"}else{let n=f?i-7-6-e/2:i,o=f?l:l+7+6+t/2;L(n-e/2,o-t/2,n+e/2,o+t/2),s+=`<g class="pele-commit-label">${a(n,o)}${Fe(r,n,o,"")}</g>`}}let o=13;for(let e=f?0:a.length-1;e>=0&&e<a.length;e+=f?1:-1){let t=a[e],r=Ou(t),n=t.height,h=f?i+o:i-r/2,c=f?l:l-o-n/2;o+=f?r+4:n+3,L(h,c-n/2,h+r,c+n/2),s+=`<g class="pele-tag"><path d="M${Oe(h)},${Oe(c)}L${Oe(h+7)},${Oe(c-n/2)}H${Oe(h+r)}V${Oe(c+n/2)}H${Oe(h+7)}Z" fill="var(--_s)" stroke="var(--_b)" stroke-linejoin="round"/><circle cx="${Oe(h+7)}" cy="${Oe(c)}" r="1.5" fill="var(--_b)"/>`+Fe(t,h+7+4+t.width/2,c,' fill="var(--_fg)"')+"</g>"}let h=t.type===xu&&n!==xu?" pele-commit-merge":"";B+=`<g class="pele-commit pele-commit-${Ru[n]??Ru[0]}${h}" data-id="${Re(t.id)}">${s}</g>`}I>D&&L(0,0,0,0);let H=Fl(e.title,!1,n,i,4e3,1),Y=H.height>0?H.height+16:0,G=Math.max(D-I,H.width),U=Math.ceil(G+2*s),q=Math.ceil(R-N+Y+2*s),j=s-I+(G-(D-I))/2,V=s+Y-N;return{svg:Bi("gitGraph",U,q,i,r,e,Fe(H,U/2,s+H.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe(j)},${Oe(V)})">`+(O?`<g class="pele-branches" fill="none" font-size="${m}">${O}</g>`:"")+(W||P?`<g class="pele-edges" fill="none" stroke-width="2" stroke-linecap="round">${W}${P}</g>`:"")+(B?`<g class="pele-commits" font-size="${l}" fill="var(--_m)">${B}</g>`:"")+"</g>"),width:U,height:q,links:[]}}var Wu={type:"gitGraph",parse:(e,t,r)=>vu(function(e){let t=new Dn(fn(e,Cu,"gitGraph"),Cu,"gitGraph"),r={$type:"GitGraph",statements:[]},a=()=>{if(-1!==t.kind)for(26!==t.kind&&t.fail("a line break or the end of input");26===t.kind;)t.i++},i=()=>31===t.kind?t.take():25===t.kind?Nn(t.take()):t.fail("a branch name"),l=()=>Nn(t.expect(25)),n=()=>(8!==t.kind&&5!==t.kind&&2!==t.kind&&t.fail("NORMAL, REVERSE, or HIGHLIGHT"),t.take());for(;26===t.kind;)t.i++;if(!t.accept(1)){t.expect(3);let e=t.kinds[t.i+1];17!==t.kind&&18!==t.kind&&19!==t.kind||20!==e?t.accept(20):(r.$type="Direction",r.dir=t.take(),t.i++)}for(;-1!==t.kind;)switch(t.kind){case 26:t.i++;break;case 21:r.accDescr=Sn(t.take()),a();break;case 22:r.accTitle=_n(t.take()),a();break;case 23:r.title=En(t.take()),a();break;case 7:{t.i++;let e={$type:"Commit",tags:[]};for(;;)if(t.accept(16))e.id=l();else if(t.accept(15))e.tags.push(l());else if(t.accept(12))e.type=n();else{if(!t.accept(14)&&25!==t.kinds[t.i])break;e.message=l()}a(),r.statements.push(e);break}case 9:{t.i++;let e={$type:"Branch",name:i()};t.accept(10)&&(e.order=parseInt(t.expect(24))),a(),r.statements.push(e);break}case 13:{t.i++;let e={$type:"Merge",branch:i(),tags:[]};for(;;)if(t.accept(16))e.id=l();else if(t.accept(15))e.tags.push(l());else{if(!t.accept(12))break;e.type=n()}a(),r.statements.push(e);break}case 4:case 11:{t.i++;let e={$type:"Checkout",branch:i()};a(),r.statements.push(e);break}case 0:{t.i++;let e={$type:"CherryPicking",tags:[]};for(;;)if(t.accept(16))e.id=l();else if(t.accept(15))e.tags.push(l());else{if(!t.accept(6))break;e.parent=l()}a(),r.statements.push(e);break}default:t.fail("a statement, a title, or a line break")}return r}(e),t,r),render:function(e,t,r){return"LR"!==e.direction?zu(e,t,r,e.direction):ql(r,a=>zu(e,t,r,a?"TB":"LR"))}};var Pu=[vn("showInfo"),vn("info"),un,pn,gn,xn,wn,$n,bn,Mn];var Bu={type:"info",parse:(e,t,r)=>function(e,t){return{type:"info",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0}}(function(e){let t=new Dn(fn(e,Pu,"info"),Pu,"info"),r={$type:"Info"};for(;5===t.kind;)t.i++;for(t.expect(1);5===t.kind;)t.i++;if(t.accept(0))for(;5===t.kind;)t.i++;for(;-1!==t.kind;){let e=t.kind;if(2===e?r.accDescr=Sn(t.take()):3===e?r.accTitle=_n(t.take()):4===e?r.title=En(t.take()):t.fail("a title or the end of input"),-1===t.kind)break;for(5!==t.kind&&t.fail("a line break or the end of input");5===t.kind;)t.i++}return r}(e),r),render:function(e,t,r){let a=r.fontSize??16,i=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),l=r.padding??8,n=Fl(e.title,!1,i,a,4e3,1),s=n.height>0?n.height+8:0,o=Fl("Pele v1.13.0",!1,i,a,4e3),h=Math.ceil(Math.max(n.width,o.width)+2*l),c=Math.ceil(s+o.height+2*l);return{svg:Bi("info",h,c,a,r,e,Fe(n,h/2,l+n.height/2,' class="pele-title" font-weight="var(--_tw)"')+Fe(o,h/2,l+s+o.height/2,' class="pele-version" fill="var(--_m)"')),width:h,height:c,links:[]}}},Hu=class{type="ishikawa";title;root;stack=[];baseLevel;addNode(e,t){let r={text:t,children:[]};if(!this.root)return this.root=r,void(this.stack=[{level:0,node:r}]);this.baseLevel??=e;let a=Math.max(e-this.baseLevel+1,1),i=this.stack;for(;i.length>1&&i[i.length-1].level>=a;)i.pop();i[i.length-1].node.children.push(r),i.push({level:a,node:r})}},Yu=["$end","EOF","SPACELINE","NL","ISHIKAWA","SPACELIST","TEXT"];function Gu(e,t){let r=0;for(;r<13;){let a=e.charCodeAt(t+r),i="ishikawa-beta".charCodeAt(r);if(a!==i&&(a+32!==i||a<65||a>90))break;r++}return 13!==r||Q(e.charCodeAt(t+13))?r>=8&&!Q(e.charCodeAt(t+8))?8:0:13}var Uu="'SPACELINE', 'NL', 'EOF'";function qu(e,t){let{types:r,starts:a,ends:i}=function(e){let t=[],r=[],a=[],i=e.length,l=0;for(;l<i;){let n,s,o=l,h=-1;for(;o<i&&q(e.charCodeAt(o));)10===e.charCodeAt(o)&&(h=o),o++;if(37===e.charCodeAt(o)&&37===e.charCodeAt(o+1))for(n=2,s=o+2;s<i;){let t=e.charCodeAt(s);if(10===t||13===t||8232===t||8233===t)break;s++}else if(o===l){let t=Gu(e,l);t>0?(n=4,s=l+t):(n=6,s=e.indexOf("\n",l),-1===s&&(s=i))}else h>l?(n=2,s=h+1):h===l?(n=3,s=l+1):(n=5,s=o);t.push(n),r.push(l),a.push(s),l=s}return t.push(1,0),r.push(i,i),a.push(i,i),{types:t,starts:r,ends:a}}(e),l=0,n=t=>{throw c("ishikawa",e,a[l],`Expecting ${t}, got '${Yu[r[l]]}'`)};if(2===r[l]){for(l++;2===r[l]||3===r[l];)l++;4!==r[l]&&n("'SPACELINE', 'NL', 'ISHIKAWA'")}else 4!==r[l]&&n("'SPACELINE', 'ISHIKAWA'");for(l++,3===r[l]&&l++;;){let s=r[l];if(6===s||5===s&&6===r[l+1]){let o=6===s?l:l+1;l=o+1,2!==r[l]&&3!==r[l]&&1!==r[l]&&n(Uu),t.addNode(6===s?0:i[o-1]-a[o-1],e.slice(a[o],i[o]).trim())}else 2===s||5===s?(l++,2!==r[l]&&3!==r[l]&&1!==r[l]&&n(5===s?`${Uu}, 'TEXT'`:Uu)):n("'SPACELINE', 'SPACELIST', 'TEXT'");for(l++;3===r[l]||1===r[l];)l++;if(0===r[l])return}}var ju=.5,Vu=Math.hypot(ju,1);var Xu={type:"ishikawa",parse(e,t,r){let a=new Hu;return a.title=r,qu(e,a),a},render:function(e,t,r){return ql(r,t=>function(e,t,r,a){let i=r.fontSize??16,l=Math.round(.875*i),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8;if(a)return function(e,t){let r=t.fontSize??16,a=Math.round(.875*r),i=t.measurer??Ce(t.fontFamily,t.fontFamilyMono),l=t.padding??8,n=Math.max(140,(t.maxWidth??320)-2*l),s=Fl(e.title,!1,i,r,Gl(t),1),o=[],h=e.root?[{node:e.root,depth:0,parent:-1}]:[],c=0;for(;h.length;){let e=h.pop(),t=o.length;o.push({...e,x:0,y:0,w:0,h:0}),c=Math.max(c,e.depth);for(let r=e.node.children.length-1;r>=0;r--)h.push({node:e.node.children[r],depth:e.depth+1,parent:t})}let d=Math.min(20,Math.max(2,(n-120)/Math.max(1,c))),f=l+(s.height?s.height+12:0),u=s.width,p="",g="";for(let e of o){e.x=l+e.depth*d;let t=Math.max(60,n-e.depth*d-20);e.label=bo(Fl(e.node.text,!1,i,e.depth<2?r:a,t,e.depth<2?1:0),i,t),e.w=e.label.width+20,e.h=e.label.height+12,e.y=f,f+=e.h+12,u=Math.max(u,e.x-l+e.w);let s=e.depth<2;if(p+=`<g class="pele-node ${0===e.depth?"pele-ishikawa-head":1===e.depth?"pele-ishikawa-category":"pele-ishikawa-cause"}" data-id="${Re(e.node.text)}">`+(s?`<rect x="${Oe(e.x)}" y="${Oe(e.y)}" width="${Oe(e.w)}" height="${Oe(e.h)}" rx="${0===e.depth?12:4}" fill="var(--_s)" stroke="var(--_b)"/>`:"")+Fe(e.label,e.x+e.w/2,e.y+e.h/2,` class="pele-label"${e.depth<2?' font-weight="var(--_hw)"':""}${e.depth>1?` font-size="${a}"`:""}`)+"</g>",e.parent>=0){let t=o[e.parent];g+=`<path class="pele-edge" d="M${Oe(t.x+d/2)},${Oe(t.y+t.h)}V${Oe(e.y+e.h/2)}H${Oe(e.x)}" fill="none" stroke="var(--_b)"/>`}}let m=Math.ceil(u+2*l),y=Math.ceil(Math.max(l+s.height,f-12)+l),x=Fe(s,m/2,l+s.height/2,' class="pele-title" font-weight="var(--_tw)"')+g+p;return{svg:Bi("ishikawa",m,y,r,t,{},x),width:m,height:y,links:[]}}(e,r);let o=e.root,h=Fl(e.title,!1,n,i,4e3,1),c=h.height>0?h.height+12:0,d="",f=0,u=0,p=0,g=0;if(o){let e=Fl(o.text,!1,n,i,200,1),t=Math.max(e.height+24,48),r=e.width+24+t/2,a=o.children.map((e,t)=>function(e,t,r,a,i){let l=Fl(e.text,!1,r,a,180),n=Math.round(1.5*i),s=[],o=[],h=[],c=(e,r,a)=>{let i=e.length;for(let l=i-1;l>=0;l--)h.push({node:e[t?i-1-l:l],depth:r,parent:a,slot:l,bone:-1})};for(c(e.children,2,-1);h.length>0;){let e=h.pop();if(-1!==e.bone){o.push(e.bone);continue}let t=s.length;s.push({label:Fl(e.node.text,!1,r,i,200),depth:e.depth,parent:e.parent,slot:e.slot,kids:e.node.children.length,rise:0,at:0,textEnd:0}),e.depth%2==0?o.push(t):(e.bone=t,h.push(e)),c(e.node.children,e.depth+1,t)}let d=14;for(let e of o){let t=Math.max(s[e].label.height,n)+6;s[e].rise=d+t/2,d+=t}let f=l.width+20,u=f/2;for(let e of s){let t=-1===e.parent?void 0:s[e.parent];e.depth%2==0?(e.at=t?t.at:0,e.textEnd=e.at-(e.kids>0?22*(e.kids+1):18)-5):(e.at=t.at-22*(t.kids-e.slot),e.textEnd=e.at-5),u=Math.max(u,e.label.width-e.textEnd)}return{node:e,label:l,boxW:f,boxH:l.height+10,bones:s,rise:d+8,reach:u}}(e,t%2==0,n,i,l));for(let e of a)e.rise=Math.max(e.rise,t/2+14);let s=[],h=-34;for(let e=0;e<a.length;e+=2){if(e>0){let t=0;for(let r=0;r<2;r++){let i=a[e-2+r],l=a[e+r];i&&(t=Math.max(t,i.reach+(l?l.boxW/2:0)))}h-=t+26}s.push(h,h)}let c=a.length>0?h-28:-34;u=r,f=c,p=-t/2,g=t/2;let m="";a.forEach((e,t)=>{let r=t%2==0?-1:1,a=s[t],i=(e,t)=>a+e-t*ju,n=i(0,e.rise),o=r*e.rise,h=7,c=`M${Oe(a-ju/Vu*h)},${Oe(r*h/Vu)}L${Oe(n)},${Oe(o)}`,d="";for(let t of e.bones){let a=r*t.rise;if(t.depth%2==0)c+=`M${Oe(i(t.at,t.rise))},${Oe(a)}H${Oe(i(t.textEnd+5,t.rise))}`;else{let l=e.bones[t.parent].rise;c+=`M${Oe(i(t.at,l))},${Oe(r*l)}L${Oe(i(t.at,t.rise))},${Oe(a)}`}let l=i(t.textEnd,t.rise);d+=Fe(t.label,l-t.label.width/2,a,t.depth>2?' fill="var(--_m)"':""),f=Math.min(f,l-t.label.width)}let y=o+r*(e.boxH/2);f=Math.min(f,n-e.boxW/2),u=Math.max(u,n+e.boxW/2),p=Math.min(p,y-e.boxH/2),g=Math.max(g,y+e.boxH/2),m+=`<g class="pele-ishikawa-category" data-id="${Re(e.node.text)}"><path class="pele-ishikawa-bones" d="${c}" fill="none" stroke="var(--_l)"/>`+li("arrow_point",a,0,ju/Vu,-r/Vu,"var(--_l)")+`<rect x="${Oe(n-e.boxW/2)}" y="${Oe(y-e.boxH/2)}" width="${Oe(e.boxW)}" height="${Oe(e.boxH)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`+Fe(e.label,n,y,' class="pele-label"')+(d?`<g class="pele-ishikawa-causes" font-size="${l}">${d}</g>`:"")+"</g>"});let y=t/2;d=`<path class="pele-ishikawa-spine" d="M${Oe(c)},0H${Oe(-7)}" fill="none" stroke="var(--_l)"/>`+li("arrow_point",0,0,1,0,"var(--_l)")+m+`<g class="pele-ishikawa-head" data-id="${Re(o.text)}"><path d="M0,${Oe(-y)}H${Oe(r-y)}A${Oe(y)},${Oe(y)} 0 0 1 ${Oe(r-y)},${Oe(y)}H0Z" fill="var(--_s)" stroke="var(--_b)" stroke-linejoin="round"/>`+Fe(e,12+e.width/2,0,' class="pele-label" font-weight="var(--_hw)"')+"</g>"}let m=Math.max(u-f,h.width),y=Math.ceil(m+2*s),x=Math.ceil(g-p+c+2*s),w=s+(m-(u-f))/2-f,$=s+c-p;return{svg:Bi("ishikawa",y,x,i,r,{},Fe(h,y/2,s+h.height/2,' class="pele-title" font-weight="var(--_tw)"')+(d?`<g transform="translate(${Oe(w)},${Oe($)})">${d}</g>`:"")),width:y,height:x,links:[]}}(e,0,r,t))}};function Ku(e){let t=new Set;for(let r of e)for(let e of r.people)t.add(e);return[...t].sort()}var Zu=class{type="journey";title;accTitle;accDescr;sections=[];tasks=[];currentSection="";setDiagramTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addSection(e){this.currentSection=e,this.sections.push(e)}addTask(e,t){let r=t.substring(1).split(":"),a=1===r.length?[]:r[1].split(",").map(e=>e.trim());this.tasks.push({task:e,score:Number(r[0]),people:a,section:this.currentSection})}getActors(){return Ku(this.tasks)}};function Qu(e,t){let r=e.indexOf("\n",t);return-1===r?e.length:r}function Ju(e,t,r){for(let a=0;a<r.length;a++)if((32|e.charCodeAt(t+a))!==r.charCodeAt(a))return!1;return!0}function ep(e,t){let r=e.length,a=t;for(;a<r;){let t=e.charCodeAt(a);if(37===t&&123!==e.charCodeAt(a+1))a=Qu(e,a);else{if(10===t)return a;if(q(t))do{a++}while(a<r&&q(e.charCodeAt(a)));else{if(35!==t)return a;a=Qu(e,a)}}}return a}function tp(e,t){let r=t;for(;q(e.charCodeAt(r));)r++;return r}function rp(e,t,r,a){let i=Ju(e,t,"accdescr");if(!i&&!Ju(e,t,"acctitle"))return t;let l=e.length,n=tp(e,t+8),s=e.charCodeAt(n),o=(t,a,i)=>{r.types.push(t),r.texts.push(e.slice(a,i)),r.starts.push(a)};if(58===s){n=tp(e,n+1);let r=Qu(e,n);return o(i?a+2:a,t,n),o(i?a+3:a+1,n,r),r}if(!i||123!==s)return t;for(n=tp(e,n+1);125!==e.charCodeAt(n);){let t=e.indexOf("}",n);if(-1===t&&(t=l),o(a+4,n,t),n===l)return l;n=t}return n+1}var ap=["$end","EOF","INVALID","NEWLINE","journey","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","section","taskName","taskData",":"];function ip(e,t,r){let a=e.length,i=t;for(;i<a;i++){let t=e.charCodeAt(i);if(35===t||10===t||59===t||r&&58===t)break}return i}function lp(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l={types:r,texts:a,starts:i},n=0,s=(t,l)=>{r.push(t),a.push(e.slice(n,l)),i.push(n),n=l};for(;n=ep(e,n),!(n>=t);){let r=e.charCodeAt(n),a=n+1;if(10!==r)if(!Ju(e,n,"journey")||Q(e.charCodeAt(n+7))){if(Ju(e,n,"title")){for(a=n+5;10!==e.charCodeAt(a)&&q(e.charCodeAt(a));)a++;if(a===t||10===e.charCodeAt(a)){n=a;continue}let r=e.charCodeAt(n+5);if(13!==r&&q(r)&&(a=ip(e,n+6,!1),a>n+6)){s(5,a);continue}}a=rp(e,n,l,6),a===n?Ju(e,n,"section")&&q(e.charCodeAt(n+7))&&(a=ip(e,n+8,!0),a>n+8)?s(11,a):58===r?(a=ip(e,n+1,!1),s(a>n+1?13:14,a>n+1?a:n+1)):59===r?s(2,n+1):s(12,ip(e,n+1,!0)):n=a}else s(4,n+7);else{for(;10===e.charCodeAt(a);)a++;s(3,a)}}return(0===i.length||i[i.length-1]<t)&&s(1,t),s(0,t),l}(e),l=(t,a)=>{let l=0===r[t]?"1":ap[r[t]];throw c("journey",e,i[t],`Expecting ${a}, got '${l}'`)};4!==r[0]&&l(0,"'journey'");for(let e=1;;e++){let i=a[e];switch(r[e]){case 3:break;case 5:t.setDiagramTitle(i.substring(6));break;case 6:t.setAccTitle(a[++e].trim());break;case 8:t.setAccDescription(a[++e].trim());break;case 10:t.setAccDescription(i.trim());break;case 11:t.addSection(i.substring(8));break;case 12:13!==r[++e]&&l(e,"'taskData'"),t.addTask(i,a[e]);break;case 1:return;default:l(e,"'EOF', 'SPACE', 'NEWLINE', 'title', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'section', 'taskName'")}}}var np=10,sp=12,op=24,hp=26,cp=11,dp={happy:"M-5,2A6,6 0 0 0 5,2",neutral:"M-4.5,4.5H4.5",sad:"M-5,6.5A6,6 0 0 1 5,6.5"};function fp(e,t,r){return`<g class="pele-face pele-face-${r}" transform="translate(${Oe(e)},${Oe(t)})"><circle r="11" fill="var(--_bg)" stroke="var(--_l)"/><g fill="var(--_l)"><circle cx="-3.6" cy="-2.8" r="1.3"/><circle cx="3.6" cy="-2.8" r="1.3"/></g><path d="${dp[r]}" fill="none" stroke="var(--_l)" stroke-linecap="round"/></g>`}var up={type:"journey",parse(e,t,r){let a=new Zu;return a.title=r,lp(e,a),a},render:function(e,t,r){return ql(r,t=>function(e,t,r,a){let i=r.fontSize??16,l=Math.round(.875*i),n=Math.round(.75*i),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=r.padding??8;if(a)return function(e,t){let r,a=t.fontSize??16,i=Math.round(.875*a),l=t.measurer??Ce(t.fontFamily,t.fontFamilyMono),n=t.padding??8,s=Math.max(140,(t.maxWidth??320)-2*n),o=Nu(e.title,l,a,s,1),h=Ku(e.tasks).filter(e=>""!==e),c=new Map(h.map((e,t)=>[e,t])),d=n+(o.height?o.height+16:0),f="",u=o.width;e.tasks.forEach((t,o)=>{if(t.section!==r){r=t.section;let e=Nu(r,l,a,s-16,1);e.height&&(f+=Fe(e,n+8+e.width/2,d+e.height/2,' class="pele-cluster-label" font-weight="var(--_hw)"'),u=Math.max(u,e.width+16),d+=e.height+8)}let h=Nu(t.task,l,i,s-72),p=t.people.filter(e=>""!==e).map(e=>({name:e,label:Nu(e,l,i,s-44)})),g=Math.max(h.height,42),m=16+g;for(let e of p)m+=Math.max(16,e.label.height)+4;let y=Math.max(s,h.width+72);f+=`<g class="pele-node pele-journey-step" data-id="${o}"><rect x="${Oe(n)}" y="${Oe(d)}" width="${Oe(y)}" height="${Oe(m)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`,f+=Fe(h,n+np+h.width/2,d+8+h.height/2,' class="pele-label"');let x=n+y-28;f+=fp(x,d+8+cp,t.score>3?"happy":t.score<3?"sad":"neutral"),Number.isNaN(t.score)||(f+=`<text class="pele-journey-score" x="${Oe(x)}" y="${Oe(d+8+22+i)}" font-size="${i}" text-anchor="middle">${Oe(Math.min(5,Math.max(1,t.score)))}</text>`);let w=d+8+g+4;for(let e of p){let t=Math.max(16,e.label.height);f+=`<circle class="pele-actor" cx="${Oe(n+16)}" cy="${Oe(w+t/2)}" r="5" fill="${zi(c.get(e.name))}"/>`+Fe(e.label,n+28+e.label.width/2,w+t/2,` class="pele-journey-actor" font-size="${i}"`),w+=t+4}f+="</g>",d+=m,o+1<e.tasks.length&&(f+=`<path class="pele-edge" d="M${Oe(n+y/2)},${Oe(d)}v16" fill="none" stroke="var(--_l)"/>`),d+=16,u=Math.max(u,y)});let p=Math.ceil(u+2*n),g=Math.ceil(Math.max(n+o.height,d-(e.tasks.length?16:0))+n),m=Fe(o,p/2,n+o.height/2,' class="pele-title" font-weight="var(--_tw)"')+f;return{svg:Bi("journey",p,g,a,t,e,m),width:p,height:g,links:[]}}(e,r);let h=e.tasks,c=h.length,d=Ku(h).filter(e=>""!==e),f=new Map;d.forEach((e,t)=>f.set(e,t));let u=124,p=h.map(e=>Iu(e.task,s,l,u)),g=0;for(let e of p)g=Math.max(g,e.width);g>u&&(u=Math.min(Math.ceil(g),200),p=h.map(e=>Nu(e.task,s,l,u)));let m=u+20,y=m+sp,x=c>0?c*y-sp:0,w=Math.round(1.5*l),$=Math.max(x,240),b=[],M=0,v=0,k=0;for(let e of d){let t=Nu(e,s,l,$-10-6),r=16+t.width;k>0&&k+r>$&&(k=0,v+=4);let a=k>0?b[b.length-1].y:v,i=Math.max(t.height,w);b.push({name:e,label:t,x:k,y:a,h:i}),k+=r,M=Math.max(M,k),v=Math.max(v,a+i),k+=20}let A=c>0?op+x:0,T=Nu(e.title,s,i,Math.max(A,320),1),C=T.height>0?T.height+16:0,E=Math.max(A,T.width,c>0?op+M:0),_=o+(E-A)/2+op,S=o+C,I=[],N=0;for(let e=0;e<c;){let t,r=e+1;for(;r<c&&h[r].section===h[e].section;)r++;""!==h[e].section&&(t=Nu(h[e].section,s,l,(r-e)*y-sp-20,1),N=Math.max(N,Math.max(t.height,w)+12)),I.push({start:e,count:r-e,label:t}),e=r}let D=w;for(let e of p)D=Math.max(D,e.height);let R=d.length>0?16:0,L=D+R+16,O=S+(N>0?N+6:0),F=O+L+cp+16,z=F+104,W=_+x,P="",B=S;if(c>0){let e="",t="";for(let r=5;r>=1;r--){let a=F+(5-r)*hp;e+=`M${Oe(_-6)},${Oe(a)}H${Oe(W)}`,t+=`<text x="${Oe(_-12)}" y="${Oe(a+.35*n)}">${r}</text>`}P+=`<path class="pele-grid" d="${e}" fill="none" stroke="var(--_a)"/><g class="pele-scale" font-size="${n}" text-anchor="end" fill="var(--_m)">${t}</g>`;let r="",a="",i="",s=[];h.forEach((e,t)=>{let n=_+t*y,o=n+m/2,h=e.score,c=Number.isNaN(h)?3:Math.min(5,Math.max(1,h)),d=F+(5-c)*hp;r+=`${0===t?"M":"L"}${Oe(o)},${Oe(d)}`,a+=`M${Oe(o)},${Oe(O+L)}V${Oe(d-cp)}`,i+=fp(o,d,h>3?"happy":h<3?"sad":"neutral");let u="",g=e.people.filter(e=>""!==e),x=Math.min(13,(m-20-10)/Math.max(g.length-1,1));g.forEach((e,t)=>{u+=`<circle class="pele-actor" cx="${Oe(o+(t-(g.length-1)/2)*x)}" cy="${Oe(O+L-8-5)}" r="5" fill="${zi(f.get(e)??0)}" stroke="var(--_s)"><title>${Re(e)}</title></circle>`}),s.push(`<g class="pele-node pele-task" data-id="${Re(e.task.trim())}"><rect x="${Oe(n)}" y="${Oe(O)}" width="${Oe(m)}" height="${Oe(L)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`+Fe(p[t],o,O+8+D/2,` font-size="${l}"`)+u+"</g>")}),P+=`<path class="pele-stems" d="${a}" fill="none" stroke="var(--_b)" stroke-dasharray="2 3"/>`+(c>1?`<path class="pele-edge" d="${r}" fill="none" stroke="var(--_l)" stroke-linejoin="round"/>`:"")+i;for(let e of I){let t=s.slice(e.start,e.start+e.count).join("");if(!e.label){P+=t;continue}let r=_+e.start*y,a=e.count*y-sp;P+=`<g class="pele-cluster pele-section" data-id="${Re(h[e.start].section.trim())}"><rect x="${Oe(r)}" y="${Oe(S)}" width="${Oe(a)}" height="${Oe(N)}" fill="var(--_a)"${Mi}/>`+Fe(e.label,r+a/2,S+N/2,` font-size="${l}" font-weight="var(--_hw)"`)+t+"</g>"}if(B=z+cp,b.length>0){let e=_+(x-M)/2,t=B+16,r="";for(let a of b){let i=t+a.y+a.h/2;r+=`<g class="pele-legend-item" data-id="${Re(a.name)}"><circle cx="${Oe(e+a.x+5)}" cy="${Oe(i)}" r="5" fill="${zi(f.get(a.name)??0)}"/>`+Fe(a.label,e+a.x+10+6+a.label.width/2,i,"")+"</g>"}P+=`<g class="pele-legend" font-size="${l}">${r}</g>`,B=t+v}}let H=Math.ceil(E+2*o),Y=Math.ceil(Math.max(B,o)+o),G=Fe(T,o+E/2,o+T.height/2,' class="pele-title" font-weight="var(--_tw)"')+P;return{svg:Bi("journey",H,Y,i,r,e,G),width:H,height:Y,links:[]}}(e,0,r,t))}},pp=["1","INVALID","SPACELINE","NL","EOF","","SPACELIST","ICON","CLASS","NODE_DSTART","NODE_ID","NODE_DESCR","NODE_DEND","SHAPE_DATA"];function gp(e,t){return 5===e?t?"KANBAN":"MINDMAP":pp[e]}var mp=0,yp=1,xp=2,wp=3,$p=4,bp=5,Mp=6;function vp(e,t){switch(e){case"[":return xp;case"(":return")"===t?yp:$p;case"((":return wp;case")":return $p;case"))":return bp;case"{{":return Mp;default:return mp}}var kp=/\s+/y,Ap=/.+/y,Tp=/[^([\n){}]+/y,Cp=/[^([\n){}@]+/y,Ep=/[^)\](}]+/y,_p=/[^`"]+/y,Sp=/[^}^"]+/y,Ip=/\n\s*/g;function Np(e,t,r){for(let a=0;a<r.length;a++)if((32|e.charCodeAt(t+a))!==r.charCodeAt(a))return!1;return!0}var Dp="'SPACELINE', 'NL', 'EOF'",Rp=new Uint8Array(14);for(let e of[2,6,7,8,9,10])Rp[e]=1;function Lp(e){return 2===e||3===e||4===e}function Op(e,t,r){let a=r?"kanban":"mindmap",{types:i,texts:l,starts:n}=function(e,t){let r=e.length,a=[],i=[],l=[],n=t?"kanban":"mindmap",s=t?Cp:Tp,o=0,h=0,c=-1,d=(e,t,r)=>{a.push(e),i.push(t),l.push(h),h=r},f=(t,r,a)=>{d(t,e.slice(h,r),r),o=a},u=(t,r)=>(t.lastIndex=r,t.test(e)?t.lastIndex:-1),p=t=>{let a=e.indexOf(t,h);return-1===a?r:a};for(;h<r;){let r,a=e.charCodeAt(h),i=e.charCodeAt(h+1);if(0===o){let l=a<=32||a>=160?Math.max(u(kp,h),h):h;if(t&&64===a&&123===i)d(13,"",h+2),o=6;else if(37===e.charCodeAt(l)&&37===e.charCodeAt(l+1))f(2,u(Ap,l),0);else if(l>h)c<h&&(c=p("\n")),c>=l?f(6,l,0):(r=e.lastIndexOf("\n",l-1))>h?f(2,r+1,0):f(3,h+1,0);else if(Np(e,h,n)&&!Q(e.charCodeAt(h+n.length)))f(5,h+n.length,0);else if(58===a&&58===i&&58===e.charCodeAt(h+2))h+=3,o=1;else if(58===a&&58===i&&Np(e,h+2,"icon")&&40===e.charCodeAt(h+6))h+=7,o=2;else if(45===a&&41===i||40===a&&(45===i||40===i)||(41===a||123===a)&&i===a)f(9,h+2,3);else if(41===a||40===a||91===a)f(9,h+1,3);else{if(-1===(r=u(s,h)))break;f(10,r,0)}}else if(3===o)34===a?(o=96===i?5:4,h+=96===i?2:1):41===a||40===a?f(12,i===a||40===a&&45===i?h+2:h+1,0):93===a?f(12,h+1,0):125===a&&125===i||45===a&&41===i?f(12,h+2,0):f(11,u(125===a?Ap:Ep,h),3);else if(4===o)34===a?(h++,o=3):f(11,p('"'),4);else if(5===o)if(96===a&&34===i)h+=2,o=3;else{if(-1===(r=u(_p,h)))break;f(11,r,5)}else if(1===o)if(-1!==(r=u(Ap,h)))f(8,r,0);else{if(10!==a)break;h++,o=0}else if(2===o)41===a?(h++,o=0):f(7,p(")"),2);else if(6===o)if(34===a)f(13,h+1,7);else if(125===a)h++,o=0;else{if(-1===(r=u(Sp,h)))break;f(13,r,6)}else 34===a?f(13,h+1,6):(r=p('"'),d(13,e.slice(h,r).replace(Ip,"<br/>"),r))}return h<r?d(1,"",h):(0===o&&d(4,"",r),d(0,"",r)),{types:a,texts:i,starts:l}}(e,r),s=r?", 'SHAPE_DATA'":"",o=0,h=t=>{let l=i[o];throw 1===l?c(a,e,n[o],"",!0):c(a,e,n[o],`Expecting ${t}, got '${gp(l,r)}'`)},d=`'${gp(5,r)}'`;if(2===i[o]){for(o++;2===i[o]||3===i[o];)o++;5!==i[o]&&h(`'SPACELINE', 'NL', ${d}`)}else 5!==i[o]&&h(`'SPACELINE', ${d}`);o++;let f="'SPACELINE', 'NL', 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'";for(3===i[o]&&(o++,f="'SPACELINE', 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'");;){let e=i[o],r=0,a=6===e;if(a&&(r=l[o++].length,e=i[o]),10===e||9===e){let a,n,c=0;if(10===e&&(a=l[o++]),9===i[o]){let e=l[o++];11!==i[o]&&h("'NODE_DESCR'"),n=l[o++],12!==i[o]&&h("'NODE_DEND'");let r=l[o++];!Lp(i[o])&&13!==i[o]&&h(Dp+s),c=t.getType(e,r)}else!Lp(i[o])&&13!==i[o]&&h(Dp+", 'NODE_DSTART'"+s),n=a;if(13===i[o]){let e=l[o++];for(;13===i[o];)e+=l[o++];Lp(i[o])||h(Dp+s),t.addNode(r,a??n,n,c,e)}else t.addNode(r,a??n,n,c)}else if(7===e||8===e){let r=l[o++];Lp(i[o])||h(Dp),t.decorateNode(7===e?{icon:r}:{class:r})}else a?Lp(e)||h(Dp+", 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'"):2===e?Lp(i[++o])||h(Dp):h(f);for(o++;3===i[o]||4===i[o];)o++;if(0===i[o])return;0===Rp[i[o]]&&h(Dp+", 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'")}}var Fp=class{type="kanban";title;sections=[];getType=vp;last;sectionLevel=0;misplaced;addNode(e,t,r,a,l){let n={id:t,level:e,label:r};if(void 0!==l){let e,t=l.includes("\n")?l+"\n":"{\n"+l+"\n}";try{e=U(t)}catch(e){throw new i(`Metadata of "${n.id}" is not valid YAML. ${e.message}`,"syntax",{type:"kanban"})}if(null!==e&&"object"==typeof e&&!Array.isArray(e)){let t=e.shape?String(e.shape):"";if(t!==t.toLowerCase()||t.includes("_"))throw new i(`No such shape: ${t}. Shape names should be lowercase.`,"semantic",{type:"kanban"});e.label&&(n.label=String(e.label)),e.icon&&(n.icon=String(e.icon)),e.assigned&&(n.assigned=String(e.assigned)),e.ticket&&(n.ticket=String(e.ticket)),e.priority&&(n.priority=String(e.priority))}}if(this.misplaced)throw new i(`Items without section detected, found section ("${this.misplaced.label}")`,"semantic",{type:"kanban"});let s=this.sections;if(0===s.length&&(this.sectionLevel=e),this.last=n,e===this.sectionLevel){let e=n;e.items=[],s.push(e)}else s[s.length-1].items.push(n),e<this.sectionLevel&&(this.misplaced=n)}decorateNode(e){let t=this.last;!e||!t||(e.icon&&(t.icon=e.icon),e.class&&(t.cssClasses=e.class))}};function zp(e,t,r,a,i){return`<svg class="pele-icon" data-icon="${Re(e)}" x="${Oe(t)}" y="${Oe(r)}" width="${Oe(a)}" height="${Oe(a)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${i?.(e)??""}</svg>`}var Wp=12,Pp=10,Bp=new Map([["very high",`stroke="${Ti}"`],["high",`stroke="${Ti}" opacity="0.5"`],["low",'stroke="var(--_m)" opacity="0.5"'],["very low",'stroke="var(--_m)"']]);function Hp(e,t,r,a,i,l=0){let n=Fl(e,t,r,a,i,l);if(n.width<=i)return n;let s=[],o=[],h=0,c=[],d=0,f=()=>{s.push(c),o.push(d),h=Math.max(h,d),c=[],d=0};for(let e=0;e<n.lines.length;e++)if(n.widths[e]<=i)c=n.lines[e],d=n.widths[e],f();else{for(let t of n.lines[e]){if(void 0!==t.icon||t.math){d>0&&d+t.width>i&&f(),c.push(t),d+=t.width;continue}let e="",l=d;for(let n of t.text){let s=r.width(n,a,t.style);d>0&&d+s>i&&(e&&c.push({text:e,style:t.style,width:d-l}),f(),e="",l=0),e+=n,d+=s}e&&c.push({text:e,style:t.style,width:d-l})}f()}let u={...n,lines:s,widths:o,width:h,height:s.length*n.lineHeight};return n.heights?Wl(u):u}function Yp(e,t,r,a,i,l=!1){let n="";for(let s=0;s<e.lines.length;s++){let o=e.lines[s],h=r+Bl(e,s);if(1!==o.length||void 0!==o[0].icon||void 0!==o[0].math||56&o[0].style){let r=e.widths[s];n+=Fe(Hl(e,s),t+(l?-r:r)/2,h,a,i)}else n+=`<text${Je(a,o[0].style)} x="${Oe(t)}" y="${Oe(h+.35*e.size)}"${l?' text-anchor="end"':""}>${De(o[0].text)}</text>`}return n}var Gp=e=>!!e&&""!==w(e);var Up={type:"kanban",math:!0,parse(e,t,r){let a=new Fp;return a.title=r,function(e,t){Op(e,t,!0)}(e,a),a},render:function(e,t,r){let a=r.fontSize??16,i=Math.round(.875*a),l=Math.round(1.5*a),n=Math.round(1.5*i),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=r.padding??8,h=r.icons,c=t.kanban??{},d=c.sectionWidth,f=1.25*i,u=0,p=(e,t,r)=>{if(e&&e.includes("$$"))for(let a of Fl(e,!0,s,t,1/0).lines)for(let e of a)e.math&&(u=Math.max(u,e.math.width+r))};for(let t of e.sections){let e=s.width(String(t.items.length),i,0);p(t.label,a,24+e+12+(Gp(t.icon)?f+6:0));for(let e of t.items){let t=36;p(e.label,i,t+(Gp(e.icon)?f+6:0)),p(e.ticket,i,t),p(e.assigned,i,t)}}let g=Math.max("number"==typeof d&&d>0?Math.min(Math.max(d,80),2e3):200,Math.ceil(u)),m=void 0!==r.maxWidth&&r.maxWidth>0?r.maxWidth-2*o:1/0,y=e.sections.length,x=y*(g+Wp)-Wp<=m,w=x?Math.max(y,1):Math.max(1,Math.floor((m+Wp)/(g+Wp))),$=x?g:Math.max(Math.min(g,m),Math.min(Math.floor((m+Wp)/w)-Wp,2*g),Math.ceil(u)),b="string"==typeof c.ticketBaseUrl?c.ticketBaseUrl:"",M=$-16,v=M-20,k=[],A=e.sections,T=[],C=[],E=[],_=l,S=[];for(let e of A){let t=s.width(String(e.items.length),i,0),r=t+12+(Gp(e.icon)?f+6:0),l=Hp(e.label,!0,s,a,M-8-r,1);_=Math.max(_,l.height),C.push(t),T.push(l);let o=[],h=0;for(let t of e.items){let e=Hp(t.label,!0,s,i,v-(Gp(t.icon)?f+6:0)),r=Hp(t.ticket,!1,s,i,v),a=Hp(t.assigned,!1,s,i,v),l=r.width+a.width+8>v?r.height+a.height:Math.max(r.height,a.height),c=20+Math.max(e.height,n)+(l?4+l:0);o.push({item:t,label:e,ticket:r,assigned:a,meta:l,height:c}),h+=c+8}E.push(o),S.push(h)}_+=16;let I=[],N=[];for(let e=0,t=0;e<A.length;e+=w){let r=8;for(let t=e;t<Math.min(e+w,A.length);t++)r=Math.max(r,S[t]);N.push(t),I.push(_+r),t+=_+r+Wp}let D=I.length>0?N[N.length-1]+I[I.length-1]:0,R=gs(e.title,s,a,Gl(r)),L=R.height>0?R.height+16:0,O=Math.max(Math.min(A.length,w)*($+Wp)-Wp,0),F=Math.max(O,R.width),z=o+(F-O)/2,W=$-8-4,P="";for(let e=0;e<A.length;e++){let t=A[e],a=Math.floor(e/w),s=`<rect width="${$}" height="${Oe(I[a])}" fill="var(--_s)"${Mi}/>`+Yp(T[e],12,8,' class="pele-cluster-label" font-weight="var(--_hw)"',h)+`<text class="pele-count" x="${W}" y="${Oe(8+l/2+.35*i)}" text-anchor="end" font-size="${i}" fill="var(--_m)">${t.items.length}</text>`;Gp(t.icon)&&(s+=zp(t.icon,W-C[e]-6-f,8+(l-f)/2,f,h));let c=_;for(let t of E[e]){let e=t.item,a=(e.priority??"").trim().toLowerCase(),l=Bp.get(a),o=`<rect width="${M}" height="${Oe(t.height)}" fill="var(--_bg)" stroke="var(--_b)"${Mi}/>`;void 0!==l&&(o+=`<path class="pele-priority" d="M2.5,5V${Oe(t.height-5)}" fill="none" ${l} stroke-width="3" stroke-linecap="round"/>`),o+=Yp(t.label,Pp,Pp,' class="pele-label"',h),Gp(e.icon)&&(o+=zp(e.icon,M-Pp-f,Pp+(n-f)/2,f,h));let d=t.height-Pp;if(e.ticket){let a=d-t.meta,i=b?xr(dr(b.replace("#TICKET#",()=>e.ticket)),r):void 0;void 0===i?o+=Yp(t.ticket,Pp,a,' class="pele-ticket" fill="var(--_m)"',h):(o+=`<a href="${De(i)}" target="_blank"${vr(r)}>`+Yp(t.ticket,Pp,a,' class="pele-ticket" fill="var(--_c)"',h)+"</a>",k.push({id:e.id,href:i,internal:!1}))}e.assigned&&(o+=Yp(t.assigned,M-Pp,d-t.assigned.height,' class="pele-assigned" fill="var(--_m)"',h,!0)),s+=`<g class="pele-node pele-card${void 0===l?"":" pele-priority-"+a.replace(" ","-")}${Oi(e.cssClasses??"")}" data-id="${Re(e.id)}" transform="translate(8,${Oe(c)})" font-size="${i}">${o}</g>`,c+=t.height+8}P+=`<g class="pele-cluster pele-column${Oi(t.cssClasses??"")}" data-id="${Re(t.id)}" transform="translate(${Oe(z+e%w*($+Wp))},${Oe(o+L+N[a])})">${s}</g>`}let B=Math.ceil(F+2*o),H=Math.ceil(D+L+2*o);return{svg:Bi("kanban",B,H,a,r,{},Fe(R,B/2,o+R.height/2,' class="pele-title" font-weight="var(--_tw)"')+P),width:B,height:H,links:k}}},qp=class{type="mindmap";title;nodes=[];getType=vp;baseLevel=0;open=[];addNode(e,t,r,a){let l=0===this.nodes.length;l&&(this.baseLevel=e),e-=this.baseLevel;let n=this.open,s=n.length;for(;s>0&&n[s-1].level>=e;)s--;let o=n[s-1];if(!o&&!l)throw new i(`There can be only one root. No parent could be found for ("${r}")`,"semantic",{type:"mindmap"});let h={id:this.nodes.length,nodeId:t,level:e,descr:r,type:a,children:[],isRoot:l};o&&(h.section=o.isRoot?o.children.length%11:o.section,o.children.push(h)),n.length=s,n.push(h),this.nodes.push(h)}decorateNode(e){let t=this.nodes[this.nodes.length-1];!e||!t||(e.icon&&(t.icon=e.icon),e.class&&(t.class=e.class))}};var jp=["","rounded","rect","circle","cloud","bang","hex"],Vp="stadium",Xp=28;function Kp(e,t,r,a){if(e.lines.length<2)return Fe(e,t+e.width/2,r,' class="pele-label"',a);let i="",l=r-e.height/2;for(let r=0;r<e.lines.length;r++)i+=Fe(Hl(e,r),t+e.widths[r]/2,l+Bl(e,r),' class="pele-label"',a);return i}var Zp={type:"mindmap",math:!0,parse(e,t,r){let a=new qp;return a.title=r,function(e,t){Op(e,t,!1)}(e,a),a},render:function(e,t,r){return ql(r,a=>function(e,t,r,a){let i=r.fontSize??16,l=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),n=r.padding??8,s=r.icons,o=t.mindmap?.maxNodeWidth,h="number"==typeof o&&o>0?Math.min(o,2e3):200,c=1.25*i,d=e.nodes,f=d.length,u=new Int32Array(f),p=new Int32Array(f);for(let e=0;e<f;e++)for(let t of d[e].children)u[t.id]=e,p[t.id]=p[e]+1;let g=a&&void 0!==r.maxWidth&&r.maxWidth>0?r.maxWidth-2*n:1/0,m=new Array(f),y=new Array(f),x=new Float64Array(f),$=new Float64Array(f),b=new Float64Array(f),M=new Float64Array(f),v=new Uint8Array(f);for(let e=0;e<f;e++){let t=d[e];v[e]=void 0!==t.icon&&""!==w(t.icon)?1:0;let r=Math.min(h,Math.max(72,g-p[e]*Xp-12-(v[e]?c+6:0))),n=m[e]=Fl(t.descr,!0,l,i,r),s=n.width+(v[e]?c+(n.width>0?6:0):0),o=Math.max(n.height,Math.round(1.5*i)),f=jp[t.type]||(0===e?Vp:"");if(a&&0===e&&"rect"!==f&&"rounded"!==f&&(f=Vp),y[e]=f,""===f){let r=t.children.length>0;x[e]=s+2*(r?12:6),$[e]=o+(r?6:0),M[e]=$[e]/2}else{let t=sl(f,s,o);x[e]=t.w,$[e]=t.h,b[e]=t.dy,M[e]=t.h/2}}let k=new Float64Array(f),A=new Float64Array(f),T=new Float64Array(f),C=new Float64Array(f),E=0,_=(e,t,r,a)=>{let i=0,l=0;for(let n=t;n<r;n++){let t=e[n].id;A[t]=i,l=e[n].children.length>0||n+1<r&&e[n+1].children.length>0?Math.max(a,18):a,i+=k[t]+l}E=i-l;let n=e[t].id,s=e[r-1].id;return(A[n]+T[n]+M[n]+A[s]+T[s]+M[s])/2};for(let e=f-1;e>0;e--){let t=d[e].children;if(0===t.length){k[e]=$[e];continue}let r=_(t,0,t.length,8)-M[e],a=Math.min(0,r);k[e]=Math.max(E,r+$[e])-a,T[e]=r-a,C[e]=-a}let S=new Float64Array(f),I=new Float64Array(f),N=new Float64Array(f),D=new Int8Array(f),R=new Float64Array(f);if(a){let e=0;for(let t=0;t<f;t++)t>0&&0===u[t]&&(e+=10),S[t]=p[t]*Xp+x[t]/2,I[t]=e,e+=$[t]+10}else if(f>0){let e=d[0].children,t=e.length,r=0;for(let t of e)r+=k[t.id];let a=t,i=1/0,l=0;for(let n=1;n<t;n++){l+=k[e[n-1].id];let s=Math.abs(2*l-r+28*(2*n-t));s<i&&(i=s,a=n)}for(let r=0,i=a,l=1;r<t;r=i,i=t,l=-1){let t=_(e,r,i,28);for(let a=r;a<i;a++){let r=e[a].id;N[r]=A[r]-t,D[r]=l}}I[0]=-$[0]/2;for(let e=0;e<f;e++){e>0&&(I[e]=N[e]+T[e]);for(let t of d[e].children){let r=t.id;e>0&&(D[r]=D[e],N[r]=N[e]+C[e]+A[r]),S[r]=S[e]+D[r]*(x[e]/2+(e>0?36:52)+x[r]/2)}}}let L=0,O=0,F=0,z=0,W="",P="",B="",H="",Y=e=>{""!==B&&(W+=`<g class="pele-branch pele-section-${e??0}"><g class="pele-edges" fill="none" stroke="${H}" stroke-width="1.5">${P}</g>${B}</g>`,P=B="")};for(let e=1;e<=f;e++){let t=e%f,r=d[t],i=y[t],l=m[t],n=S[t],o=I[t];if(L=Math.min(L,n-x[t]/2),O=Math.max(O,n+x[t]/2),F=Math.min(F,o),z=Math.max(z,o+$[t]),(0===t||0===u[t])&&Y(d[e-1].section),t>0&&a){0===u[t]&&(H=zi(r.section??0));let e=u[t],a=0===e?Math.min(Math.max(12,$[0]/2),20):12,l=S[e]-x[e]/2+Math.min(a,x[e]/2),s=R[e]||I[e]+$[e],h=n-x[t]/2+(i?hl(i,x[t],$[t],3):0),c=o+M[t],d=Math.max(0,Math.min(8,h-l,c-s));R[e]=c-d,P+=`<path class="pele-edge" d="M${Oe(l)},${Oe(s)}V${Oe(c-d)}Q${Oe(l)},${Oe(c)} ${Oe(l+d)},${Oe(c)}H${Oe(h)}"/>`}else if(t>0){0===u[t]&&(H=zi(r.section??0));let e=u[t],a=D[t],l=a>0?1:3,s=S[e]+a*(x[e]/2-(y[e]?hl(y[e],x[e],$[e],l):0)),h=I[e]+M[e],c=n-a*x[t]/2+(i?a*hl(i,x[t],$[t],4-l):0),d=o+M[t],f=Oe((s+c)/2);P+=`<path class="pele-edge" d="M${Oe(s)},${Oe(h)}C${f},${Oe(h)} ${f},${Oe(d)} ${Oe(c)},${Oe(d)}"/>`}let h=!i&&r.children.length>0,p=` fill="${H}" fill-opacity="0.22" stroke="${H}"`,g="";i?g=t>0?ol(i,x[t],$[t],p,` stroke="${H}"`):ol(i,x[t],$[t],' fill="var(--_s)" stroke="var(--_b)"',' stroke="var(--_b)"'):h&&(g=`<rect x="${Oe(-x[t]/2)}" y="${Oe(-$[t]/2)}" width="${Oe(x[t])}" height="${Oe($[t])}" rx="${Oe($[t]/2)}"${p}/>`);let w=0;r.icon&&v[t]&&(w=(c+(l.width>0?6:0))/2,g+=zp(r.icon,-w-l.width/2,b[t]-c/2,c,s));let k=`<g class="pele-node pele-shape-${i||(h?"branch":"text")}${t>0?"":" pele-root"}${Oi(r.class??"")}" data-id="${Re(r.nodeId)}" transform="translate(${Oe(n)},${Oe(o+$[t]/2)})">`+g+(a&&!i?Kp(l,w-l.width/2,b[t],s):Fe(l,w,b[t],' class="pele-label"',s))+"</g>";t>0?B+=k:W+=k}let G=gs(e.title,l,i,Gl(r)),U=G.height>0?G.height+16:0,q=Math.max(O-L,G.width),j=Math.ceil(q+2*n),V=Math.ceil(z-F+U+2*n),X=Fe(G,j/2,n+G.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe(n-L+(q-O+L)/2)},${Oe(n+U-F)})">${W}</g>`;return{svg:Bi("mindmap",j,V,i,r,{},X),width:j,height:V,links:[]}}(e,t,r,a))}};function Qp(e,t,r,a,i){let l=e.packet?.[t];return"number"==typeof l&&l>=a?Math.min(l,i):r}function Jp(e){return new i(e,"semantic",{type:"packet"})}var eg=[{name:"packet-beta",pattern:"packet-beta"},vn("packet"),{name:"-",pattern:"-",longer:[$n]},{name:"+",pattern:"+"},{name:":",pattern:":"},un,pn,gn,{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y},yn,xn,wn,$n,bn,Mn];function tg(e,t,r,a,i,l=0){if(""===e||t<=0)return;let n=i.width(e,r,l);if(n<=t)return{text:e,size:r,width:n};let s=Math.max(a,Math.floor(r*t/n));for(;s>=a;){if(n=i.width(e,s,l),n<=t)return{text:e,size:s,width:n};s--}let o=Array.from(e),h=0,c=o.length-1;for(;h<c;){let e=h+c+1>>1;i.width(o.slice(0,e).join("").trimEnd()+"…",a,l)<=t?h=e:c=e-1}if(0===h)return;let d=o.slice(0,h).join("").trimEnd()+"…";return n=i.width(d,a,l),n<=t?{text:d,size:a,width:n}:void 0}var rg={type:"packet",parse:(e,t,r)=>function(e,t,r){let a=Math.floor(Qp(t,"bitsPerRow",32,1,4096)),i=[],l=-1,n=[],s=1;for(let t of e.blocks){let{start:e,end:r,bits:o}=t;if(void 0!==e&&void 0!==r&&r<e)throw Jp(`Packet block ${e} - ${r} is invalid. End must be greater than start.`);if(e??=l+1,e!==l+1)throw Jp(`Packet block ${e} - ${r??e} is not contiguous. It should start from ${l+1}.`);if(0===o)throw Jp(`Packet block ${e} is invalid. Cannot have a zero bit field.`);for(r??=e+(o??1)-1,o??=r-e+1,l=r;n.length<=a+1&&i.length<1e4;){let l=s*a-1;if(r<=l){n.push({start:e,end:r,bits:o,label:t.label}),r===l&&(i.push(n),n=[],s++);break}n.push({start:e,end:l,bits:l-e,label:t.label}),i.push(n),n=[],s++,e=l+1,o=r-e}}return n.length>0&&i.push(n),{type:"packet",title:e.title||r,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,bitsPerRow:a,rows:i}}(function(e){let t=new Dn(fn(e,eg,"packet"),eg,"packet"),r={$type:"Packet",blocks:[]},a=()=>{if(-1!==t.kind)for(10!==t.kind&&t.fail("a line break or the end of input");10===t.kind;)t.i++};for(;10===t.kind;)t.i++;for(t.accept(0)||t.expect(1);-1!==t.kind;)switch(t.kind){case 10:t.i++;break;case 5:r.accDescr=Sn(t.take()),a();break;case 6:r.accTitle=_n(t.take()),a();break;case 7:r.title=En(t.take()),a();break;case 8:case 3:{let e={$type:"PacketBlock",label:""};t.accept(3)?e.bits=Number(t.expect(8)):(e.start=Number(t.take()),t.accept(2)&&(e.end=Number(t.expect(8)))),t.expect(4),e.label=Nn(t.expect(9)),r.blocks.push(e),a();break}default:t.fail("a field, a title, or a line break")}return r}(e),t,r),render:function(e,t,r){return ql(r,a=>function(e,t,r,a){let i=r.fontSize??16,l=Math.round(.875*i),n=Math.round(.625*i),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=r.padding??8,h=t.packet??{},c=Qp(t,"rowHeight",32,1,400),d=Qp(t,"bitWidth",32,1,400),f=Qp(t,"paddingX",5,0,400),u=Qp(t,"paddingY",5,0,400),p=!1!==h.showBits,g="descending"===h.bitOrder,y=e.bitsPerRow,x=e.rows;if(a){let t=Math.max(1,Math.floor(((r.maxWidth??320)-2*o)/Math.min(d,18)));y=Math.min(y,Math.max(8,2**Math.floor(Math.log2(t))));let a=e.rows[e.rows.length-1],i=a?.[a.length-1]?.end??0;Math.ceil((i+1)/y)>1e4&&(y=e.bitsPerRow),d=Math.min(d,Math.max(18,((r.maxWidth??320)-2*o)/y));let l=e=>e.bits===e.end-e.start,n=[];for(let t of e.rows)for(let r of t){let t=n[n.length-1];t&&l(t)&&l(r)&&t.label===r.label&&r.start===t.end+1&&r.start%e.bitsPerRow===0?(t.end=r.end,t.bits=t.end-t.start):n.push({...r})}x=[];for(let e of n)for(let t=e.start;t<=e.end;){let r=Math.min(e.end,(Math.floor(t/y)+1)*y-1),a=Math.floor(t/y);(x[a]??(x[a]=[])).push({...e,start:t,end:r}),t=r+1}}let w=new Map;if(a)for(let e of x)for(let t of e){let e=Math.max(1,(t.end-t.start+1)*d-Math.min(f,d-1)-6),r=$o(m(t.label).trim(),s,l,e);w.set(t,r)}let $=p?n+4:0,b=x.map(e=>{let t=c;if(a)for(let r of e)t=Math.max(t,w.get(r).height+10);return t}),M=[],v=0;for(let e of b)M.push(v),v+=$+e+u;x.length&&(v-=u);let k=Math.min(f,d-1),A=x.length>0?y*d-k:0,T=Fl(e.title,!1,s,i,a?Gl(r):4e3,1),C=T.height>0?T.height+(v>0?12:0):0,E=new Map,_=(e,t)=>{let r=E.get(e);return r||E.set(e,r=new Map),r.has(t)||r.set(t,tg(m(e).trim(),t,l,Math.round(.5*i),s)),r.get(t)},S=o+Math.max(0,(T.width-A)/2),I="",N="";x.forEach((e,t)=>{let r=o+M[t]+$,i=b[t];for(let t of e){let e=t.end-t.start+1,n=t.start%y,s=S+(g?y-n-e:n)*d,o=e*d-k,h=a?void 0:_(t.label,o-6);if(I+=`<g class="pele-node" data-id="${t.start}-${t.end}"><rect x="${Oe(s)}" y="${Oe(r)}" width="${Oe(o)}" height="${Oe(i)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`+(a?Fe(w.get(t),s+o/2,r+i/2,""):h&&h.size<=i?`<text x="${Oe(s+o/2)}" y="${Oe(r+i/2+.35*h.size)}"${h.size===l?"":` font-size="${Oe(h.size)}"`}>${De(h.text)}</text>`:"")+"</g>",!p)continue;let c=g?t.end:t.start,f=g?t.start:t.end;N+=1===e?`<text x="${Oe(s+o/2)}" y="${Oe(r-4)}" text-anchor="middle">${c}</text>`:`<text x="${Oe(s)}" y="${Oe(r-4)}">${c}</text><text x="${Oe(s+o)}" y="${Oe(r-4)}" text-anchor="end">${f}</text>`}});let D=Math.ceil(Math.max(A,T.width)+2*o),R=Math.ceil(v+C+2*o),L=(I?`<g class="pele-packet-fields" font-size="${l}" text-anchor="middle">${I}</g>`:"")+(N?`<g class="pele-packet-bits" font-size="${n}" fill="var(--_m)">${N}</g>`:"")+Fe(T,D/2,R-o-T.height/2,' class="pele-title" font-weight="var(--_tw)"');return{svg:Bi("packet",D,R,i,r,e,L),width:D,height:R,links:[]}}(e,t,r,a))}};function ag(e,t){let r=t;for(let t=e.charCodeAt(r);t>=48&&t<=57;t=e.charCodeAt(r))r++;return r}var ig=[vn("showData"),vn("pie"),{name:":",pattern:":"},{name:"NUMBER_PIE",pattern:/(?:-?[0-9]+\.[0-9]+(?!\.))|(?:-?(0|[1-9][0-9]*)(?!\.))/y,scanner:function(){let e=0,t=0,r=-1;return(a,i)=>{let l=45===a.charCodeAt(i)?i+1:i;if((l<e||l>=t)&&(e=l,t=ag(a,l),r=-1,t>l&&46===a.charCodeAt(t))){let e=ag(a,t+1),i=e-t-1;i>0&&46!==a.charCodeAt(e)?r=e:i>1&&(r=e-1)}return t===l?-1:r>=0?r:48===a.charCodeAt(l)?46===a.charCodeAt(l+1)?-1:l+1:46!==a.charCodeAt(t)?t:t-1>l?t-1:-1}},first:"-0123456789"},un,pn,gn,yn,xn,wn,$n,bn,Mn];var lg=12,ng=26,sg=32;function og(e,t){return e.pie?.[t]}function hg(e,t){return`${Oe(Math.sin(e)*t)},${Oe(-Math.cos(e)*t)}`}var cg={type:"pie",parse:(e,t,r)=>function(e,t){let r=new Map;for(let{label:t,value:a}of e.sections){if(a<0)throw new i(`"${t}" has invalid value: ${a}. Negative values are not allowed in pie charts. All slice values must be >= 0.`,"semantic",{type:"pie"});r.has(t)||r.set(t,a)}return{type:"pie",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,showData:e.showData,sections:r}}(function(e){let t=new Dn(fn(e,ig,"pie"),ig,"pie"),r={$type:"Pie",showData:!1,sections:[]},a=()=>{if(-1!==t.kind)for(8!==t.kind&&t.fail("a line break or the end of input");8===t.kind;)t.i++};for(;8===t.kind;)t.i++;for(t.expect(1),r.showData=t.accept(0);-1!==t.kind;)switch(t.kind){case 8:t.i++;break;case 4:r.accDescr=Sn(t.take()),a();break;case 5:r.accTitle=_n(t.take()),a();break;case 6:r.title=En(t.take()),a();break;case 7:{let e=Nn(t.take());t.expect(2);let i=Number(t.expect(3));r.sections.push({$type:"PieSection",label:e,value:i}),a();break}default:t.fail("a section, a title, or a line break")}return r}(e),r),render:function(e,t,r){return Yl(r,240,140,(a,i)=>function(e,t,r,a,i){let l=r.fontSize??16,n=Math.round(.875*l),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=r.padding??8,h=og(t,"textPosition"),c="number"==typeof h&&h>=0&&h<=1?h:.75,d=og(t,"donutHole"),f="number"==typeof d&&d>0&&d<=.9?d*a:0,u=String(og(t,"legendPosition")??"right"),p=!i||"left"!==u&&"right"!==u?u:"bottom",g=[...e.sections],m=0;for(let[,e]of g)m+=e;let y=g.map(([t,r])=>Fl(e.showData?`${t} [${r}]`:t,!1,s,n,4e3)),x=0;for(let e of y)x=Math.max(x,e.width);x+=y.length>0?20:0;let w=y.length*ng,$=Fl(e.title,!1,s,l,Gl(r),1),b=$.height>0?$.height+16:0,M=g.map(([,e])=>{let t=m>0?e/m:0;return 100*t>=1&&"0"!==(100*t).toFixed(0)?t:0}),v=M.map(e=>!(0===e||e>=.5)&&2*a*c*Math.sin(e*Math.PI)<s.width((100*e).toFixed(0)+"%",n,0)+6),k=v.includes(!0)?28:0,A="left"===p||"right"===p||"center"===p?p:"",T="top"===p||"bottom"===p,C=2*(a+k),E=C,_=C;"left"===A||"right"===A?(E+=x>0?sg+x:0,_=Math.max(_,w)):T&&(E=Math.max(E,x),_+=w>0?20+w:0),E=Math.max(E,$.width);let S=o+("left"===A?x+sg+C/2:"right"===A?C/2:E/2),I=o+b,N=I+("top"===p?w+20+C/2:T?C/2:_/2),D="",R="",L="",O=0,F=a+14,z=[],W=(e,t,r)=>z.every(a=>Math.abs(e-a.x)>=(r+a.width)/2+2||Math.abs(t-a.y)>=n+2);g.forEach(([e],t)=>{let r=M[t];if(0===r)return;let i=O+r*Math.PI*2;D+=`<path class="pele-slice" data-id="${Re(e)}" d="${function(e,t,r,a){if(t-e>=2*Math.PI-1e-9){let e=(e,t)=>`M0,${Oe(-e)}A${Oe(e)},${Oe(e)} 0 1 ${t} 0,${Oe(e)}A${Oe(e)},${Oe(e)} 0 1 ${t} 0,${Oe(-e)}Z`;return e(r,1)+(a>0?e(a,0):"")}let i=t-e>Math.PI?1:0;return a<=0?`M0,0L${hg(e,r)}A${Oe(r)},${Oe(r)} 0 ${i} 1 ${hg(t,r)}Z`:`M${hg(e,r)}A${Oe(r)},${Oe(r)} 0 ${i} 1 ${hg(t,r)}L${hg(t,a)}A${Oe(a)},${Oe(a)} 0 ${i} 0 ${hg(e,a)}Z`}(O,i,a,f)}" fill="${zi(t)}"/>`;let l=(O+i)/2,o=(100*r).toFixed(0)+"%";if(v[t]){let e=s.width(o,n,0),t=l;for(let r=0;r<360&&!W(Math.sin(t)*F,-Math.cos(t)*F,e);r++)t+=2/F;let r=Math.sin(t)*F,a=-Math.cos(t)*F;z.push({x:r,y:a,width:e}),L+=`<text x="${Oe(r)}" y="${Oe(a+.35*n)}">${o}</text>`}else{let e=a*c;R+=`<text x="${Oe(Math.sin(l)*e)}" y="${Oe(-Math.cos(l)*e+.35*n)}"${St(t)}>${o}</text>`}O=i}),""===D&&(D=`<circle class="pele-slice" r="${a}" fill="none" stroke="var(--_b)"/>`);let P,B,H="";"right"===A?(P=S+C/2+sg,B=I+(_-w)/2):"left"===A?(P=o,B=I+(_-w)/2):"center"===A?(P=S-x/2,B=N-w/2):(P=o+(E-x)/2,B="top"===p?I:I+C+20),y.forEach((e,t)=>{let r=B+t*ng+13;H+=`<g class="pele-legend-item" data-id="${Re(g[t][0])}"><rect x="${Oe(P)}" y="${Oe(r-6)}" width="12" height="12" rx="2" fill="${zi(t)}"/>`+Fe(e,P+lg+8+e.width/2,r,"")+"</g>"});let Y=Math.ceil(E+2*o),G=Math.ceil(_+b+2*o),U=Fe($,Y/2,o+$.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g class="pele-slices" transform="translate(${Oe(S)},${Oe(N)})" stroke="var(--_bg)" stroke-width="1" stroke-linejoin="round">${D}</g>`+(R?`<g class="pele-slice-labels" transform="translate(${Oe(S)},${Oe(N)})" font-size="${n}" text-anchor="middle" fill="var(--_bg)">${R}</g>`:"")+(L?`<g class="pele-slice-labels" transform="translate(${Oe(S)},${Oe(N)})" font-size="${n}" text-anchor="middle">${L}</g>`:"")+(H?`<g class="pele-legend" font-size="${n}">${H}</g>`:"");return{svg:Bi("pie",Y,G,l,r,e,U),width:Y,height:G,links:[]}}(e,t,r,a/2,i))}},dg=/^\d+$/,fg=/^#?([\dA-Fa-f]{6}|[\dA-Fa-f]{3})$/,ug=/^\d+px$/;function pg(e,t,r){return new i(`value for ${e} ${t} is invalid, please use a valid ${r}`,"semantic",{type:"quadrantChart"})}function gg(e){let t=e.trim(),r=t.indexOf(":");if(-1===r)return[t,"undefined"];let a=t.slice(r+1).trimStart(),i=a.indexOf(":");return[t.slice(0,r).trimEnd(),-1===i?a:a.slice(0,i).trimEnd()]}function mg(e){let t={};for(let r of e){let[e,a]=gg(r);if("radius"===e){if(!dg.test(a))throw pg(e,a,"number");t.radius=parseInt(a)}else if("color"===e){if(!fg.test(a))throw pg(e,a,"hex code");t.color=a}else if("stroke-color"===e){if(!fg.test(a))throw pg(e,a,"hex code");t.strokeColor=a}else{if("stroke-width"!==e)throw new i(`style named ${e} is not supported.`,"semantic",{type:"quadrantChart"});if(!ug.test(a))throw pg(e,a,"number of pixels (eg. 10px)");t.strokeWidth=a}}return t}function yg(e){return{text:e.text.trim(),type:e.type}}var xg=class{type="quadrantChart";title;accTitle;accDescr;quadrants=[void 0,void 0,void 0,void 0];xAxisLeft;xAxisRight;yAxisBottom;yAxisTop;points=[];classes=new Map;setQuadrant1Text(e){this.quadrants[0]=yg(e)}setQuadrant2Text(e){this.quadrants[1]=yg(e)}setQuadrant3Text(e){this.quadrants[2]=yg(e)}setQuadrant4Text(e){this.quadrants[3]=yg(e)}setXAxisLeftText(e){this.xAxisLeft=yg(e)}setXAxisRightText(e){this.xAxisRight=yg(e)}setYAxisBottomText(e){this.yAxisBottom=yg(e)}setYAxisTopText(e){this.yAxisTop=yg(e)}addPoint(e,t,r,a,i){this.points.push({x:Number(r),y:Number(a),text:yg(e),className:t,...mg(i)})}addClass(e,t){this.classes.set(e,mg(t))}setDiagramTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}};function wg(e,t,r){for(let a=0;a<r.length;a++){let i=e.charCodeAt(t+a),l=r.charCodeAt(a);if(i!==l&&!(l>=97&&l<=122&&i===l-32))return!1}return!0}var $g=["$end","INVALID","NEWLINE","title","title_value","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","X-AXIS","Y-AXIS","AXIS-TEXT-DELIMITER","QUADRANT_1","QUADRANT_2","QUADRANT_3","QUADRANT_4","CLASSDEF","MD_STR","STR","class_name","point_start","point_x","point_y","QUADRANT","ALPHA","UNICODE_TEXT","COLON","PLUS","COMMA","EQUALS","MULT","BRKT","UNDERSCORE","DOT","AMP","MINUS","NUM","SPACE","SEMI","PUNCTUATION","EOF"],bg=[41,4,6,8,9,19],Mg=new Uint8Array(128);for(let[e,t]of[[":",27],["+",28],[",",29],["=",30],["*",31],["#",32],["_",33],[".",34],["&",35],["-",36],[" \t\v\f",38],[";",39],["!$%'`?\\/",40]])for(let r=0;r<e.length;r++)Mg[e.charCodeAt(r)]=t;function vg(...e){let t=new Uint8Array(42);for(let r of e)t[r]=1;return t}var kg=vg(40,35,37,25,29,28,30,31,34,32,33,26),Ag=vg(25,37,36,29,27,35,32,31,26),Tg=vg(25,37,27,38,32,36),Cg=vg(2,39,41),Eg=["setQuadrant1Text","setQuadrant2Text","setQuadrant3Text","setQuadrant4Text"];function _g(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=0,h=0,c=0,d=0,f=0,u=0,p=0,g=0,m=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},y=e=>{l.push(n),n=e},x=()=>{l.length>0&&(n=l.pop())},w=r=>{let a=e.indexOf("\n",r);return-1===a?t:a},$=t=>{for(;32===e.charCodeAt(t);)t++;return t},b=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},M=r=>{let a=e.charCodeAt(r);if(49===a)return r+1;if(48!==a)return-1;let i=r+1;if(i<t&&!V(e.charCodeAt(i))&&X(e.charCodeAt(i+1)))for(i+=2;X(e.charCodeAt(i));)i++;return i};e:for(;s<t;){let r=e.charCodeAt(s),a=e.charCodeAt(s+1);switch(n){case 0:break;case 1:case 2:case 3:m(bg[n],s,w(s)),x();continue;case 4:if(125===r)s++,x();else{let r=e.indexOf("}",s);m(9,s,-1===r?t:r)}continue;case 5:if(34===r)s++,x();else{let r=e.indexOf('"',s);m(19,s,-1===r?t:r)}continue;case 6:if(96===r&&34===a){s+=2,x();continue}if(96!==r&&34!==r){let r=s+1;for(let a=e.charCodeAt(r);r<t&&96!==a&&34!==a;a=e.charCodeAt(++r));m(18,s,r);continue}break e;case 7:if(Q(r)){let t=s+1;for(;Q(e.charCodeAt(t));)t++;m(20,s,t),x();continue}break e;case 8:{let t=M(s);if(-1!==t){m(22,s,t),y(9);continue}let r=b(s);if(93===e.charCodeAt(r)){s=$(r+1),x();continue}break e}case 9:{let t=b(s);if(44===e.charCodeAt(t)){s=b(t+1),n=10;continue}break e}case 10:{let e=M(s);if(-1!==e){m(23,s,e),x();continue}break e}}if(37===r&&37===a){s=w(s+2);continue}if(10===r||13===r){let t=s+1;for(let r=e.charCodeAt(t);10===r||13===r;r=e.charCodeAt(++t));m(2,s,t);continue}let i=32|r;if(116===i&&wg(e,s,"title")&&!Q(e.charCodeAt(s+5))){m(3,s,s+5),y(1);continue}if(97===i&&wg(e,s,"acc")){let t=wg(e,s+3,"descr");if(t||wg(e,s+3,"title")){let r=b(s+8),a=e.charCodeAt(r);if(58===a){m(t?7:5,s,b(r+1)),y(t?3:2);continue}if(123===a&&t){s=b(r+1),y(4);continue}}}let l=s;32===r&&((s<o||s>=h)&&(o=s,h=$(s)),l=h);let v=e.charCodeAt(l),k=32|v,A=0,T=0;if(120===k&&wg(e,l,"x-axis"))A=10,T=l+6;else if(121===k&&wg(e,l,"y-axis"))A=11,T=l+6;else if(45===v){if(l<c||l>=d)for(c=l,d=l;45===e.charCodeAt(d);)d++;d-l>=2&&62===e.charCodeAt(d)&&(A=12,T=d+1)}else if(113===k&&wg(e,l,"quadrant")){let t=e.charCodeAt(l+9);45===e.charCodeAt(l+8)&&t>=49&&t<=52?(A=13+t-49,T=l+10):wg(e,l+8,"chart")&&(A=24,T=l+13)}if(0===A)if(99!==i||!wg(e,s,"classdef")||Q(e.charCodeAt(s+8)))if(34!==r)if(58!==r||58!==a||58!==e.charCodeAt(s+2)){if(58===r||q(r)){let t=s;if(58!==r&&((s<f||s>=u)&&(f=s,u=b(s)),t=u),58===e.charCodeAt(t)&&((t+1<p||t+1>=g)&&(p=t+1,g=b(t+1)),91===e.charCodeAt(g))){m(21,s,b(g+1)),y(8);continue}}if(K(r)){let t=s+1;for(;K(e.charCodeAt(t));)t++;m(25,s,t);continue}if(r>=128){let t=s+1;for(;e.charCodeAt(t)>=128;)t++;m(26,s,t);continue}if(X(r)){let t=s+1;for(;X(e.charCodeAt(t));)t++;m(37,s,t);continue}if(0===Mg[r])break;m(Mg[r],s,s+1)}else s+=3,y(7);else 96===a?(s+=2,y(6)):(s++,y(5));else m(17,s,s+8);else m(A,s,$(T))}return s<t?(r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}):(n<bg.length&&(r.push(bg[n]),a.push(""),i.push(t)),r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i})}(e),l=0,n=t=>{let a=r[l];throw 1===a?c("quadrantChart",e,i[l],"",!0):c("quadrantChart",e,i[l],`Expecting ${t}, got '${$g[a]}'`)},s=e=>(r[l]!==e&&n(`'${$g[e]}'`),a[l++]),o=e=>19===e||18===e||1===kg[e],h=()=>{let e=r[l];o(e)||n("'STR', 'MD_STR', 'ALPHA', 'NUM', 'UNICODE_TEXT', 'PUNCTUATION'");let t=a[l++];for(;1===kg[r[l]]||38===r[l]||36===r[l];)t+=a[l++];return{text:t,type:18===e?"markdown":"text"}},d=()=>{let e=[];for(;;){0===Tg[r[l]]&&n("'ALPHA', 'NUM', 'COLON', 'SPACE', 'BRKT', 'MINUS'");let t=a[l++];for(;1===Tg[r[l]];)t+=a[l++];if(e.push(t.trim()),29!==r[l])return e;l++}};for(;1===Cg[r[l]]||38===r[l];)l++;for(s(24);0!==r[l];){for(;38===r[l];)l++;let e=r[l];switch(e){case 17:{l++,s(38),0===Ag[r[l]]&&n("'ALPHA', 'NUM', 'UNICODE_TEXT'");let e=a[l++];for(;1===Ag[r[l]];)e+=a[l++];s(38),t.addClass(e,d());break}case 10:case 11:{l++;let a,i=h();12===r[l]&&(l++,o(r[l])?a=h():i.text+=" ⟶ "),10===e?(t.setXAxisLeftText(i),a&&t.setXAxisRightText(a)):(t.setYAxisBottomText(i),a&&t.setYAxisTopText(a));break}case 13:case 14:case 15:case 16:l++,t[Eg[e-13]](h());break;case 3:l++,t.setDiagramTitle(s(4).trim());break;case 5:l++,t.setAccTitle(s(6).trim());break;case 7:l++,t.setAccDescription(s(8).trim());break;case 9:t.setAccDescription(a[l++].trim());break;default:if(o(e)){let e=h(),i=20===r[l]?a[l++]:"";s(21);let n=s(22),o=s(23);t.addPoint(e,i,n,o,1===Tg[r[l]]?d():[])}}0===Cg[r[l]]&&n("'NEWLINE', 'SEMI', 'EOF'"),l++}}function Sg(e,t){return e.quadrantChart?.[t]}function Ig(e,t,r,a){let i=Sg(e,t);return"number"==typeof i&&i>=0?Math.min(i,a):r}function Ng(e,t,r){let a=Sg(e,t);return"number"==typeof a&&Number.isFinite(a)?Math.min(72,Math.max(4,a)):r}function Dg(e){return e.startsWith("#")?e:"#"+e}var Rg={type:"quadrantChart",parse(e,t,r){let a=new xg;return a.title=r,_g(e,a),a},render:function(e,t,r){let a=r.fontSize??16,i=Ng(t,"titleFontSize",a),l=Ng(t,"quadrantLabelFontSize",a),n=Ng(t,"xAxisLabelFontSize",Math.round(.875*a)),s=Ng(t,"yAxisLabelFontSize",Math.round(.875*a)),o=Ng(t,"pointLabelFontSize",Math.round(.75*a)),h=(e,t)=>e===t?"":` font-size="${e}"`,c=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),d=Math.round(Math.max(100,Ig(t,"chartWidth",500,4e3))),f=Math.round(Ul(r,d,280)),u=Math.round(Math.max(100,Ig(t,"chartHeight",500,4e3))*f/d),p=Ig(t,"quadrantPadding",r.padding??8,200),g=Ig(t,"xAxisLabelPadding",5,200),m=Ig(t,"yAxisLabelPadding",5,200),y=e.points.length>0,x=(e,t,r)=>Fl(e?.text,"markdown"===e?.type,c,t,Math.max(r,40)),w=Fl(e.title,!1,c,i,Math.max(f-2*p,40),1),$=Ig(t,"titlePadding",10,200),b=w.height>0?w.height+$:0,M=!(!e.xAxisLeft?.text&&!e.xAxisRight?.text),v=!(!e.yAxisBottom?.text&&!e.yAxisTop?.text),k=y||"bottom"===Sg(t,"xAxisPosition"),A="right"===Sg(t,"yAxisPosition"),T=f-2*p,C=x(e.xAxisLeft,n,e.xAxisRight?T/2-16:T),E=x(e.xAxisRight,n,T/2-16),_=Math.max(C.height,E.height),S=M?_+g:0,I=u-2*p-b-S,N=x(e.yAxisBottom,s,e.yAxisTop?I/2-16:I),D=x(e.yAxisTop,s,I/2-16),R=Math.max(N.height,D.height),L=v?R+m:0,O=p+(A?0:L),F=p+b+(k?0:S),z=Math.max(0,T-L),W=Math.max(0,I),P=Math.max(0,(z-4)/2),B=Math.max(0,(W-4)/2),H=[O+P,F,O+z-P,F+W,O,F+B,O+z,F+W-B],Y=(e,t,r,a,i)=>{for(let l=e;l<H.length;l+=4)if(!(H[l]>=H[l+2]||H[l+1]>=H[l+3])&&t<H[l+2]&&a>H[l]&&r<H[l+3]&&i>H[l+1])return!1;return!0},G=Ig(t,"quadrantTextTopPadding",5,200),U="";for(let t=0;t<4;t++){let r=0===t||3===t?O+z-P:O,i=t<2?F:F+W-B,n=x(e.quadrants[t],l,P-16),s=r+P/2,o=y?i+G+n.height/2:i+B/2;H.push(s-n.width/2,o-n.height/2,s+n.width/2,o+n.height/2),U+=`<g class="pele-quadrant" data-id="${t+1}"><rect x="${Oe(r)}" y="${Oe(i)}" width="${Oe(P)}" height="${Oe(B)}"${Mi}/>`+Fe(n,s,o,` class="pele-label"${h(l,a)} fill="var(--_fg)" stroke="none"`)+"</g>"}let q="";if(M){let e=k?F+W+g+_/2:F-g-_/2;q+=Fe(C,E.height>0?O+z/4:O+C.width/2,e,"")+Fe(E,O+3*z/4,e,"")}if(v){let e=A?O+z+m+R/2:O-m-R/2,t=(t,r)=>t.height>0?`<g transform="translate(${Oe(e)},${Oe(r)}) rotate(-90)"${h(s,n)}>${Fe(t,0,0,"")}</g>`:"";q+=t(N,D.height>0?F+3*W/4:F+W-N.width/2)+t(D,F+W/4)}let j=Ig(t,"pointRadius",5,200),V=Ig(t,"pointTextPadding",5,200),X=zi(0),K=[],Z=[];for(let t of e.points){if(!(t.x>=0&&t.x<=1&&t.y>=0&&t.y<=1))continue;let r=e.classes.get(t.className),a=Math.min(t.radius??r?.radius??j,2e3),i=t.color??r?.color,l=t.strokeColor??r?.strokeColor,n=t.strokeWidth??r?.strokeWidth,s=[];i&&s.push("fill:"+Dg(i)),n&&(l&&s.push("stroke:"+Dg(l)),s.push("stroke-width:"+n));let h=O+t.x*z,c=F+(1-t.y)*W;K.push({cx:h,cy:c,reach:a+(n?Math.min(parseInt(n),400)/2:0),text:x(t.text,o,z)}),Z.push(`<circle class="pele-point${Oi(t.className)}" data-id="${Re(t.text.text)}" cx="${Oe(h)}" cy="${Oe(c)}" r="${Oe(a)}"${n&&!l?` stroke="${X}"`:""}${Ri(s).shape}/>`)}let Q=K.length<=300;if(Q)for(let{cx:e,cy:t,reach:r}of K)H.push(e-r,t-r,e+r,t+r);let J="";for(let{cx:e,cy:t,reach:r,text:a}of K){let i=a.width/2,l=.6*a.size+(a.height-a.lineHeight)/2,n=r+V,s=Math.min(n,Math.max(0,(P-a.width)/2)),o=8+4*(e<O+z/2?t<F+W/2?1:2:t<F+W/2?0:3),h=[e,t+n+l,e,t-n-l,e+n+i,t,e-n-i,t,e,Math.max(t+n,H[o+3]+V)+l],c=e,d=h[1],f=!1;for(let e=0;e<20;e+=2){let t=e%10,r=8===t?s:0,n=(t<4||8===t)&&a.width<z?Math.min(Math.max(h[t],O+i+r),O+z-i-r):h[t],o=h[t+1];if(n-i<O||n+i>O+z||o-l<F||o+l>F+W)continue;let u=!Q||Y(e<10?0:8,n-i,o-l,n+i,o+l);if((!f||u)&&(c=n,d=o,f=!0),u)break}Q&&H.push(c-i,d-l,c+i,d+l),J+=Fe(a,c,d,' class="pele-label"')}return{svg:Bi("quadrantChart",f,u,a,r,e,Fe(w,f/2,$/2+w.height/2,` class="pele-title"${h(i,a)} font-weight="var(--_tw)"`)+`<g class="pele-quadrants" fill="var(--_s)" stroke="var(--_b)">${U}</g>`+(q?`<g class="pele-axis-labels" font-size="${n}" fill="var(--_m)">${q}</g>`:"")+(K.length>0?`<g class="pele-points" fill="${X}">${Z.reverse().join("")}</g><g class="pele-point-labels" font-size="${o}">${J}</g>`:"")),width:f,height:u,links:[]}}};function Lg(e){return new i(e,"semantic",{type:"radar"})}var Og=0,Fg=0;function zg(e,t){let r=t;for(let t=e.charCodeAt(r);t>=48&&t<=57;t=e.charCodeAt(r))r++;return r}var Wg=un.pattern,Pg=/[\t ]*accDescr\s*{/y,Bg=-2;var Hg={name:"ID",pattern:/[\w]([-\w]*\w)?/y},Yg=/[-\w]*\w/y;function Gg(e,t){return(r,a,i)=>{if(e.lastIndex=a,!e.test(r))return-1;let l=e.lastIndex;return i===t?l:(Yg.lastIndex=l,Yg.test(r)?-1:l)}}var Ug=e=>({name:e,pattern:e,longer:[Hg]}),qg=e=>({name:e,pattern:e}),jg=[qg("radar-beta:"),{...vn("radar-beta"),longer:[Hg]},Ug("showLegend"),Ug("graticule"),Ug("curve"),Ug("ticks"),Ug("axis"),Ug("max"),Ug("min"),qg(":"),qg(","),qg("["),qg("]"),qg("{"),qg("}"),{name:"GRATICULE",pattern:/circle|polygon/y,match:Gg(/circle|polygon/y,3)},{name:"BOOLEAN",pattern:/true|false/y,match:Gg(/true|false/y,2)},{...un,match:function(e,t){return Pg.lastIndex=t,Pg.test(e)&&(-2===Bg&&(Bg=e.lastIndexOf("}")),Pg.lastIndex>Bg)?-1:(Wg.lastIndex=t,Wg.test(e)?Wg.lastIndex:-1)}},pn,mn(String.raw`[-\w]*\w`),{name:"NUMBER",pattern:/(?:[0-9]+\.[0-9]+(?!\.))|(?:0|[1-9][0-9]*(?!\.))/y,match:function(e,t){(t<Og||t>=Fg)&&(Og=t,Fg=zg(e,t));let r=Fg;if(r===t)return-1;let a=46===e.charCodeAt(r);if(a){let t=zg(e,r+1),a=t-r-1;if(a>0&&46!==e.charCodeAt(t))return t;if(a>1)return t-1}return 48===e.charCodeAt(t)?t+1:a?r-1>t?r-1:-1:r}},yn,Hg,xn,wn,$n,bn,Mn];function Vg(e){let t=new Dn(function(e){return Og=Fg=0,Bg=-2,fn(e,jg,"radar")}(e),jg,"radar"),r={$type:"Radar",axes:[],curves:[],options:[]},a=()=>{for(;23===t.kind;)t.i++},i=()=>{-1!==t.kind&&(23!==t.kind&&t.fail("a line break or the end of input"),a())},l=()=>{if(!t.accept(11))return;let e=Nn(t.expect(21));return t.expect(12),e},n=e=>{if(!e)return{$type:"Entry",value:Number(t.expect(20))};let r={$refText:t.expect(22)};return t.accept(9),{$type:"Entry",axis:r,value:Number(t.expect(20))}},s=()=>{let e=t.expect(22),r=l(),i={$type:"Curve",name:e,entries:[]};void 0!==r&&(i.label=r),t.expect(13),a(),20!==t.kind&&22!==t.kind&&t.fail("a number or an axis name");let s=22===t.kind;for(i.entries.push(n(s));t.accept(10);)a(),i.entries.push(n(s));return a(),t.expect(14),i},o=()=>{let e={$type:"Axis",name:t.expect(22)},r=l();return void 0!==r&&(e.label=r),e},h=()=>{let e,r=t.kind,a=t.take();return e=2===r?"true"===t.expect(16):3===r?t.expect(15):Number(t.expect(20)),{$type:"Option",name:a,value:e}},c=()=>2===t.kind||5===t.kind||7===t.kind||8===t.kind||3===t.kind;for(a(),t.accept(0)||(t.expect(1),t.accept(9)),a();-1!==t.kind;)switch(t.kind){case 23:t.i++;break;case 17:r.accDescr=Sn(t.take()),i();break;case 18:r.accTitle=_n(t.take()),i();break;case 19:r.title=En(t.take()),i();break;case 6:t.i++;do{r.axes.push(o())}while(t.accept(10));break;case 4:t.i++;do{r.curves.push(s())}while(t.accept(10));break;default:for(c()||t.fail("an axis, a curve, an option, a title, or a line break"),r.options.push(h());t.accept(10);)c()||t.fail("an option"),r.options.push(h())}return r}var Xg=12,Kg=26;function Zg(e,t,r,a,i){let l=e.radar?.[t];return"number"==typeof l&&l>=a?Math.min(l,i):r}function Qg(e){let t="";for(let r of e)t+=(t?" ":"")+Oe(r.x)+","+Oe(r.y);return t}var Jg={type:"radar",parse:(e,t,r)=>function(e,t){let r=e.axes.map(e=>({name:e.name,label:e.label??e.name})),a=e.curves.map(e=>{let t;if(void 0===e.entries[0].axis)t=e.entries.map(e=>e.value);else{if(0===r.length)throw Lg("Axes must be populated before curves for reference entries");let a=new Map;for(let t of e.entries)void 0!==t.axis&&!a.has(t.axis.$refText)&&a.set(t.axis.$refText,t.value);t=r.map(e=>{let t=a.get(e.name);if(void 0===t)throw Lg("Missing entry for axis "+e.label);return t})}return{name:e.name,label:e.label??e.name,entries:t}}),i={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"};for(let t of e.options)"showLegend"===t.name?i.showLegend=t.value:"graticule"===t.name?i.graticule=t.value:i[t.name]=t.value;return i.ticks>32&&(i.ticks=32),{type:"radar",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,axes:r,curves:a,options:i}}(Vg(e),r),render:function(e,t,r){let a=Zg(t,"width",320,1,4e3);return Yl(r,a,160,(i,l)=>function(e,t,r,a,i,l){let n=r.fontSize??16,s=Math.round(.875*n),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=Zg(t,"axisScaleFactor",1,0,10),d=Zg(t,"axisLabelFactor",1.05,0,10),f=Zg(t,"curveTension",.17,0,1),u=Math.min(a,i)/2,{axes:p,curves:g}=e,{ticks:m,graticule:y,min:x}=e.options,w=p.length,$=p.map((e,t)=>{let r=2*Math.PI*t/w-Math.PI/2;return{x:Math.cos(r),y:Math.sin(r)}}),b=e.options.max;if(null===b){b=-1/0;for(let e of g)for(let t of e.entries)t>b&&(b=t)}let M=-a/2-Zg(t,"marginLeft",16,0,2e3),v=a/2+Zg(t,"marginRight",16,0,2e3),k=-i/2-Zg(t,"marginTop",16,0,2e3),A=i/2+Zg(t,"marginBottom",16,0,2e3),T="";for(let e=0;e<m;e++){let t=Math.min(u,u*(e+1)/m);T+="circle"===y?`<circle r="${Oe(t)}"/>`:`<polygon points="${Qg($.map(e=>({x:e.x*t,y:e.y*t})))}"/>`}let C="",E="";$.forEach((e,t)=>{let r=u*c;C+=`M0,0L${Oe(e.x*r)},${Oe(e.y*r)}`;let a=Fl(p[t].label,!1,o,s,4e3),i=u*d+6,l=e.x*i+(e.x>.01?a.width/2:e.x<-.01?-a.width/2:0),n=e.y*i+(e.y>.01?a.height/2:e.y<-.01?-a.height/2:0);E+=`<g class="pele-axis-label" data-id="${Re(p[t].name)}">${Fe(a,l,n,"")}</g>`,M=Math.min(M,l-a.width/2),v=Math.max(v,l+a.width/2),k=Math.min(k,n-a.height/2),A=Math.max(A,n+a.height/2)});let _="";g.forEach((e,t)=>{if(e.entries.length!==w)return;let r=e.entries.map((e,t)=>{let r=function(e,t,r,a){let i=Math.min(Math.max(e,t),r),l=a*(i-t);return Number.isFinite(l)?l/(r-t):a*((i-t)/(r-t))}(e,x,b,u),a=Number.isFinite(r)?r:0;return{x:$[t].x*a,y:$[t].y*a}}),a=zi(t),i=` class="pele-curve" data-id="${Re(e.name)}" fill="${a}" stroke="${a}"`;_+="circle"===y?`<path${i} d="${function(e,t){let r=e.length,a=`M${Oe(e[0].x)},${Oe(e[0].y)}`;for(let i=0;i<r;i++){let l=e[(i-1+r)%r],n=e[i],s=e[(i+1)%r],o=e[(i+2)%r];a+=` C${Oe(n.x+(s.x-l.x)*t)},${Oe(n.y+(s.y-l.y)*t)} ${Oe(s.x-(o.x-n.x)*t)},${Oe(s.y-(o.y-n.y)*t)} ${Oe(s.x)},${Oe(s.y)}`}return a+" Z"}(r,f)}"/>`:`<polygon${i} points="${Qg(r)}"/>`});let S=e.options.showLegend?g.map(e=>Fl(e.label,!1,o,s,4e3)):[],I=0;for(let e of S)I=Math.max(I,e.width);let N=S.length*Kg,D=l?-(20+I)/2:v+24,R=l?A+12:-N/2;S.length>0&&l?(M=Math.min(M,D),v=Math.max(v,-D),A=R+N):S.length>0&&(v=D+Xg+8+I,k=Math.min(k,-N/2),A=Math.max(A,N/2));let L="";S.forEach((e,t)=>{let r=R+t*Kg+13,a=zi(t);L+=`<g class="pele-legend-item" data-id="${Re(g[t].name)}"><rect x="${Oe(D)}" y="${Oe(r-6)}" width="12" height="12" rx="2" fill="${a}" fill-opacity="0.4" stroke="${a}"/>`+Fe(e,D+Xg+8+e.width/2,r,"")+"</g>"});let O=Fl(e.title,!1,o,n,Gl(r),1),F=O.height>0?O.height+8:0,z=Math.max(v-M,O.width),W=Math.ceil(z+2*h),P=Math.ceil(A-k+F+2*h),B=`translate(${Oe(h+(z-(v-M))/2-M)},${Oe(h+F-k)})`,H=Fe(O,W/2,h+O.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="${B}">`+(T?`<g class="pele-graticule" fill="none" stroke="var(--_a)">${T}</g>`:"")+(C?`<path class="pele-axes" d="${C}" fill="none" stroke="var(--_b)"/>`:"")+(_?`<g class="pele-curves" fill-opacity="0.2" stroke-width="1.5" stroke-linejoin="round">${_}</g>`:"")+(E?`<g class="pele-axis-labels" font-size="${s}">${E}</g>`:"")+(L?`<g class="pele-legend" font-size="${s}">${L}</g>`:"")+"</g>";return{svg:Bi("radar",W,P,n,r,e,H),width:W,height:P,links:[]}}(e,t,r,i,Zg(t,"height",320,1,4e3)*i/a,l))}};function em(e){return 32===e||e>=9&&e<=13||e>127&&/\s/.test(String.fromCharCode(e))}var tm="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function rm(e){return{name:"TITLE",pattern:new RegExp(String.raw`title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|(?!${e}))`,"y"),first:"t"}}var am={name:"ACC_TITLE",pattern:/accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/y,first:"a"},im={name:"ACC_DESCR",pattern:/accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/y,first:"a",scanner:function(){let e=1/0;return(t,r)=>{if(!t.startsWith("accDescr",r))return-1;let a=t.length,i=r+8;for(;i<a&&(32===t.charCodeAt(i)||9===t.charCodeAt(i));)i++;if(58===t.charCodeAt(i)){for(i++;i<a;i++){let e=t.charCodeAt(i);if(10===e||13===e||37===e&&37===t.charCodeAt(i+1))break}return i}for(;i<a&&em(t.charCodeAt(i));)i++;if(123!==t.charCodeAt(i)||i>=e)return-1;let l=t.indexOf("}",i+1);return-1===l&&(e=i),l+1||-1}}};function lm(e,t){return{name:e,pattern:e,longer:t}}function nm(e,t){return{...vn(e),longer:[t]}}function sm(e){return{name:e,pattern:/[A-Z_a-z][\w-]*/y,first:tm+"_"}}function om(e){return{name:e,pattern:/"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/y,first:"\"'"}}function hm(e){return[{name:e+"_WHITESPACE",pattern:/[\t \r\n]+/y,hidden:!0,first:"\t \r\n"},{...$n,name:e+"_YAML",first:"-"},{...bn,name:e+"_DIRECTIVE",first:"\t %"},{...Mn,name:e+"_SINGLE_LINE_COMMENT",first:"\t %"}]}function cm(e){if(!e.includes("\\"))return e.slice(1,-1);let t=e.length-1,r="";for(let a=1;a<t;a++){let i=e[a];"\\"===i&&a+1<t?(i=e[++a],r+="n"===i?"\n":"r"===i?"\r":"t"===i?"\t":i):r+=i}return r}function dm(e,t,r,a,i,l){let n=new Dn(fn(e,t,"railroad"),t,"railroad"),s={$type:r,rules:[]};for(n.expect(0);;){let e=n.kind;if(e===a){let e=En(n.take()),t=e[0];s.title='"'!==t&&"'"!==t||!e.endsWith(t)?e:i(e)}else if(e===a+1)s.accTitle=_n(n.take());else{if(e!==a+2)break;s.accDescr=Sn(n.take())}}for(;-1!==n.kind;)s.rules.push(l(n));return s}var fm=[];function um(e){let t=e,r=t.element??t.primary??t.suffix,a=t.alternatives??t.elements??(r?[r]:fm);if(t.base){a=[t.base];for(let e of t.postfixes)e.except&&a.push(e.except)}return a}var pm=e=>({type:"terminal",value:e}),gm=e=>({type:"nonterminal",name:e}),mm=e=>({type:"special",text:e}),ym=e=>({type:"optional",element:e}),xm=(e,t,r=1/0)=>({type:"repetition",element:e,min:t,max:r});function wm(e){return 1===e.length?e[0]:{type:"sequence",elements:e}}function $m(e){return 1===e.length?e[0]:{type:"choice",alternatives:e}}function bm(e,t){return e.rules.map(e=>({name:e.name,definition:Mm(e.definition,um,t)}))}function Mm(e,t,r){let a=[e],i=[t(e)],l=[[]];for(;;){let e=a.length-1,n=l[e];if(n.length<i[e].length){let r=i[e][n.length];a.push(r),i.push(t(r)),l.push([])}else{let t=r(a[e],n);if(0===e)return t;a.pop(),i.pop(),l.pop(),l[e-1].push(t)}}}var vm="0123456789",km={name:"ABNF_RULENAME",pattern:/[A-Za-z][A-Za-z0-9-]*/y,first:tm},Am={name:"ABNF_COMMENT",pattern:/;[^\n\r]*/y,hidden:!0,first:";"},Tm=[nm("railroad-abnf-beta",km),lm("="),lm(";",[Am]),lm("/"),lm("("),lm(")"),lm("["),lm("]"),rm(String.raw`[A-Za-z0-9-]`),am,im,km,{name:"ABNF_STRING",pattern:/"[^"]*"/y,first:'"'},{name:"ABNF_NUMVAL",pattern:/%[xXdDbB][0-9A-Fa-f]+(?:-[0-9A-Fa-f]+|\.[0-9A-Fa-f]+)*/y,first:"%"},{name:"ABNF_REPEAT",pattern:/[0-9]*\*[0-9]*/y,first:vm+"*"},{name:"ABNF_EXACT_REPEAT",pattern:/[0-9]+/y,first:vm},...hm("ABNF"),Am];function Cm(e,t,r,a){let i={$type:"AbnfConcatenation",elements:[]};return t.alternatives.push(i),{alternation:t,concatenation:i,node:e,close:r,repeat:a}}function Em(e){return dm(e,Tm,"RailroadAbnf",8,e=>e.slice(1,-1),e=>{let t=e.expect(11);e.expect(1);let r=function(e){let t=[],r=Cm(void 0,{$type:"AbnfAlternation",alternatives:[]},-2,void 0);for(;;){let a,i=14===e.kind||15===e.kind?e.take():void 0,l=e.kind;switch(l){case 12:a={$type:"AbnfStringLiteral",value:e.take().slice(1,-1)};break;case 13:a={$type:"AbnfNumVal",value:e.take()};break;case 11:a={$type:"AbnfRuleName",name:e.take()};break;case 4:case 6:{e.i++;let a={$type:"AbnfAlternation",alternatives:[]};t.push(r),r=Cm({$type:4===l?"AbnfGroup":"AbnfOptionalGroup",element:a},a,l+1,i);continue}default:e.fail("a string, a number, a name, or an opening bracket")}for(;;){r.concatenation.elements.push(void 0===i?{$type:"AbnfElement",primary:a}:{$type:"AbnfElement",repeat:i,primary:a});let l=e.kind;if(l!==r.close){if(3===l)e.i++,r.concatenation={$type:"AbnfConcatenation",elements:[]},r.alternation.alternatives.push(r.concatenation);else if(12!==l&&13!==l&&11!==l&&4!==l&&6!==l&&14!==l&&15!==l){if(0===t.length)return r.alternation;e.fail(`token of type '${Tm[r.close].name}'`)}break}e.i++,a=r.node,i=r.repeat,r=t.pop()}}}(e);return e.expect(2),{$type:"AbnfRule",name:t,definition:r}})}function _m(e,t){switch(e.$type){case"AbnfAlternation":return $m(t);case"AbnfConcatenation":return wm(t);case"AbnfElement":{let r=e.repeat;if(!r)return t[0];let a=r.indexOf("*"),i=-1===a,l=a>0||i?parseInt(r,10):0,n=i?l:a<r.length-1?parseInt(r.slice(a+1),10):1/0;return 0===l&&1===n?ym(t[0]):xm(t[0],l,n)}case"AbnfStringLiteral":case"AbnfNumVal":return pm(e.value);case"AbnfRuleName":return gm(e.name);case"AbnfGroup":return t[0];case"AbnfOptionalGroup":return ym(t[0])}}var Sm=e=>bm(e,_m);function Im(e,t){if(63!==e.charCodeAt(t))return-1;let r=!1;for(let a=t+1;a<e.length;a++){let t=e.charCodeAt(a);if(63===t)return r?a+1:-1;if(59===t)return-1;r||=!em(t)}return-1}var Nm=sm("EBNF_ID"),Dm={name:"EBNF_SPECIAL_SEQUENCE",pattern:/\?(?=[^?;]*[^?\s;][^?;]*\?)[^?;]*\?/y,first:"?",scanner:()=>Im},Rm=hm("EBNF"),Lm={name:"EBNF_ISO_COMMENT",pattern:/\(\*[\s\S]*?\*\)/y,hidden:!0,first:"(",opener:/\(\*/y},Om=[nm("railroad-ebnf-beta",Nm),lm("::="),lm("="),lm(";"),lm("|"),lm(","),lm("(",[Lm]),lm(")"),lm("["),lm("]"),lm("{"),lm("}"),lm("?",[Dm]),lm("*"),lm("+"),lm("-",[Rm[1]]),rm(String.raw`[\w-]`),am,im,Nm,om("EBNF_STRING"),Dm,...Rm,{name:"EBNF_BLOCK_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0,first:"/",opener:/\/\*/y},Lm];function Fm(e,t,r,a){let i={$type:"EbnfSequence",elements:[]};return t.alternatives.push(i),{choice:t,sequence:i,term:void 0,node:e,close:r,except:a}}var zm=["EbnfGroup","EbnfOptional","EbnfRepetition"];function Wm(e){let t=[],r=Fm(void 0,{$type:"EbnfChoice",alternatives:[]},-2,!1),a=!1;for(;;){let i,l=e.kind;switch(l){case 20:i={$type:"EbnfTerminal",value:cm(e.take())};break;case 19:i={$type:"EbnfNonTerminal",name:e.take()};break;case 21:i={$type:"EbnfSpecial",text:e.take().slice(1,-1).trim()};break;case 6:case 8:case 10:{e.i++;let i={$type:"EbnfChoice",alternatives:[]};t.push(r),r=Fm({$type:zm[l-6>>1],element:i},i,l+1,a),a=!1;continue}default:e.fail("a terminal, a name, or an opening bracket")}for(;;){a?(r.term.postfixes.push({$type:"EbnfExceptionPostfix",except:i}),a=!1):(r.term={$type:"EbnfTerm",base:i,postfixes:[]},r.sequence.elements.push(r.term));let l=r.term.postfixes;for(;;){let t=e.kind;if(12===t)l.push({$type:"EbnfOptionalPostfix",operator:e.take()});else if(13===t)l.push({$type:"EbnfZeroOrMorePostfix",operator:e.take()});else{if(14!==t)break;l.push({$type:"EbnfOneOrMorePostfix",operator:e.take()})}}let n=e.kind;if(n!==r.close){if(15===n)e.i++,a=!0;else if(5===n)e.i++;else if(4===n)e.i++,r.sequence={$type:"EbnfSequence",elements:[]},r.choice.alternatives.push(r.sequence);else if(20!==n&&19!==n&&21!==n&&6!==n&&8!==n&&10!==n){if(0===t.length)return r.choice;e.fail(`token of type '${Om[r.close].name}'`)}break}e.i++,i=r.node,a=r.except,r=t.pop()}}}function Pm(e,t){switch(e.$type){case"EbnfChoice":return $m(t);case"EbnfSequence":return wm(t);case"EbnfTerm":{let r=t[0],a=1;for(let i of e.postfixes)r="EbnfOptionalPostfix"===i.$type?ym(r):"EbnfExceptionPostfix"===i.$type?{type:"sequence",elements:[r,pm("-"),t[a++]]}:xm(r,"EbnfOneOrMorePostfix"===i.$type?1:0);return r}case"EbnfTerminal":return pm(e.value);case"EbnfNonTerminal":return gm(e.name);case"EbnfSpecial":return mm(e.text);case"EbnfGroup":return t[0];case"EbnfOptional":return ym(t[0]);case"EbnfRepetition":return xm(t[0],0)}}var Bm=e=>bm(e,Pm),Hm=sm("RR_ID"),Ym=e=>lm(e,[Hm]),Gm=[nm("railroad-beta",Hm),Ym("nonterminal"),Ym("zeroOrMore"),Ym("oneOrMore"),Ym("sequence"),Ym("optional"),Ym("terminal"),Ym("special"),Ym("choice"),lm("="),lm(";"),lm("("),lm(","),lm(")"),rm(String.raw`[\w-]`),am,im,Hm,om("RR_STRING"),...hm("RR"),{name:"RR_BLOCK_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0,first:"/",opener:/\/\*/y}];function Um(e){e.i++,e.expect(11);let t=cm(e.expect(18));return e.expect(13),t}function qm(e){return{$type:e,element:void 0}}function jm(e){return dm(e,Gm,"Railroad",14,cm,e=>{let t=e.expect(17);e.expect(9);let r=function(e){let t=[];for(;;){let r;switch(e.kind){case 6:r={$type:"RailroadTerminalExpr",value:Um(e)};break;case 1:r={$type:"RailroadNonTerminalExpr",name:Um(e)};break;case 7:r={$type:"RailroadSpecialExpr",text:Um(e)};break;case 4:r={$type:"RailroadSequenceExpr",elements:[]};break;case 8:r={$type:"RailroadChoiceExpr",alternatives:[]};break;case 5:r=qm("RailroadOptionalExpr");break;case 3:r=qm("RailroadOneOrMoreExpr");break;case 2:r=qm("RailroadZeroOrMoreExpr");break;default:e.fail("an expression")}if("elements"in r||"alternatives"in r||"element"in r)e.i++,e.expect(11),t.push(r);else for(;;){let a=t[t.length-1];if(void 0===a)return r;if("element"in a)a.element=r;else if(("elements"in a?a.elements:a.alternatives).push(r),e.accept(12))break;e.expect(13),t.pop(),r=a}}}(e);return e.expect(10),{$type:"RailroadRule",name:t,definition:r}})}function Vm(e,t){switch(e.$type){case"RailroadTerminalExpr":return pm(e.value);case"RailroadNonTerminalExpr":return gm(e.name);case"RailroadSpecialExpr":return mm(e.text);case"RailroadSequenceExpr":return wm(t);case"RailroadChoiceExpr":return $m(t);case"RailroadOptionalExpr":return ym(t[0]);default:return xm(t[0],"RailroadOneOrMoreExpr"===e.$type?1:0)}}var Xm=e=>bm(e,Vm),Km=sm("PEG_ID"),Zm=[nm("railroad-peg-beta",Km),lm("<-"),lm(";"),lm("/"),lm("&"),lm("!"),lm("?"),lm("*"),lm("+"),lm("("),lm(")"),lm("."),rm(String.raw`[\w-]`),am,im,Km,om("PEG_STRING"),...hm("PEG"),{name:"PEG_LINE_COMMENT",pattern:/#[^\n\r]*/y,hidden:!0,first:"#"}];function Qm(e,t,r){let a={$type:"PegSequence",elements:[]};return t.alternatives.push(a),{choice:t,sequence:a,node:e,operator:r}}function Jm(e){let t=[],r=Qm(void 0,{$type:"PegOrderedChoice",alternatives:[]},void 0);for(;;){let a,i=4===e.kind||5===e.kind?e.take():void 0;switch(e.kind){case 16:a={$type:"PegLiteral",value:cm(e.take())};break;case 15:a={$type:"PegIdentifier",name:e.take()};break;case 11:a={$type:"PegAny",dot:e.take()};break;case 9:{e.i++;let a={$type:"PegOrderedChoice",alternatives:[]};t.push(r),r=Qm({$type:"PegGroup",element:a},a,i);continue}default:e.fail("a literal, a name, a dot, or an opening parenthesis")}for(;;){let l={$type:"PegSuffix",primary:a};(6===e.kind||7===e.kind||8===e.kind)&&(l.operator=e.take()),r.sequence.elements.push(void 0===i?{$type:"PegPrefix",suffix:l}:{$type:"PegPrefix",operator:i,suffix:l});let n=e.kind;if(!(10===n&&t.length>0)){if(3===n)e.i++,r.sequence={$type:"PegSequence",elements:[]},r.choice.alternatives.push(r.sequence);else if(4!==n&&5!==n&&16!==n&&15!==n&&11!==n&&9!==n){if(0===t.length)return r.choice;e.fail("token of type ')'")}break}e.i++,a=r.node,i=r.operator,r=t.pop()}}}function ey(e,t){let r=t[0];switch(e.$type){case"PegOrderedChoice":return $m(t);case"PegSequence":return wm(t);case"PegPrefix":return e.operator?mm(e.operator+function(e){switch(e.type){case"terminal":return`"${e.value}"`;case"nonterminal":return e.name;case"special":return e.text;default:return"(...)"}}(r)):r;case"PegSuffix":return e.operator?"?"===e.operator?ym(r):xm(r,"+"===e.operator?1:0):r;case"PegLiteral":return pm(e.value);case"PegIdentifier":return gm(e.name);case"PegAny":return mm(e.dot);case"PegGroup":return r}}var ty=e=>bm(e,ey),ry=class{type="railroad";notation="railroad";title;accTitle;accDescr;rules=[];byName=new Map;setTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}addRule(e){this.rules.push(e),this.byName.set(e.name,e)}getRule(e){return this.byName.get(e)}},ay=/^\s*railroad-(ebnf-|abnf-|peg-)?beta/i;function iy(e,t){switch(t){case"ebnf":{let t=function(e){return dm(e,Om,"RailroadEbnf",16,cm,e=>{let t=e.expect(19);e.accept(2)||e.expect(1);let r={$type:"EbnfRule",name:t,definition:Wm(e)};return e.expect(3),r})}(e);return[t,Bm(t)]}case"abnf":{let t=Em(e);return[t,Sm(t)]}case"peg":{let t=function(e){return dm(e,Zm,"RailroadPeg",12,cm,e=>{let t=e.expect(15);e.expect(1);let r={$type:"PegRule",name:t,definition:Jm(e)};return e.expect(2),r})}(e);return[t,ty(t)]}default:{let t=jm(e);return[t,Xm(t)]}}}function ly(e,t){let r=function(e){let t=ay.exec(e);if(null===t)return;let r=t[1]?.toLowerCase();return"ebnf-"===r?"ebnf":"abnf-"===r?"abnf":"peg-"===r?"peg":"railroad"}(e);if(void 0===r)throw new i("No railroad diagram keyword found.","syntax",{type:"railroad"});let a=new ry;return t&&(a.title=t),function(e,t,r){let[a,i]=iy(t,r);e.notation=r,a.accDescr&&e.setAccDescription(a.accDescr),a.accTitle&&e.setAccTitle(a.accTitle),a.title&&e.setTitle(a.title);for(let t of i)e.addRule(t)}(a,e,r),a}var ny=12,sy=12;function oy(e,t,r,a){let i=e.railroad?.[t];return"number"==typeof i&&i>=0?Math.min(i,a):r}var hy=/[\n\r\t]/g;function cy(e){return(e.includes("¶ß")?m(e.replace(/&/g,"&amp;")):e).replace(hy,e=>"\n"===e?"\\n":"\r"===e?"\\r":"\\t")}function dy(e,t){for(let r=t,a=e.length-1;r<a;r++,a--){let t=e[r];e[r]=e[a],e[a]=t}}function fy(e){return 2*Math.ceil(e/2)}function uy(e,t,r,a,i){let l=i.height/2;return{kind:e,width:Math.max(fy(i.measurer.width(t,i.size,a)+2*i.padding),i.height),up:l,down:l,kids:fm,text:t,id:r,reach:0}}function py(e,t,r,a){return Math.max(e+t.down+a.sep+r.up,2*a.arc)}function gy(e,t){let r=Math.max(e.up+t.sep,2*t.arc);return{kind:5,width:e.width+4*t.arc,up:r,down:e.down,kids:[e],text:"",id:"",reach:r}}function my(e,t,r=1/0){let a=new Map,i=[[e,r]];for(let e=0;r!==1/0&&e<i.length;e++){let[r,l]=i[e];a.set(r,l);let n="choice"===r.type||"optional"===r.type?4*t.arc:"repetition"===r.type?(0===r.min?6:2)*t.arc:"sequence"===r.type?6*t.arc:0;for(let e of um(r))i.push([e,Math.max(40,l-n)])}return Mm(e,um,(e,r)=>{let i=a.get(e)??1/0;switch(e.type){case"terminal":{let r=cy(e.value);return uy(0,/^ +$/.test(r)?"␣".repeat(r.length):r,"",4,t)}case"nonterminal":return uy(1,cy(e.name),e.name,0,t);case"special":return uy(2,"? "+cy(e.text)+" ?","",2,t);case"sequence":{let e=Math.max(0,r.length-1)*t.gap,a=0,l=0;for(let t of r)e+=t.width,a=Math.max(a,t.up),l=Math.max(l,t.down);let n={kind:3,width:e,up:a,down:l,kids:r,text:"",id:"",reach:0};if(e<=i||r.length<2)return n;let s=[],o=[],h=0,c=()=>{let e=0,t=0;for(let r of o)e=Math.max(e,r.up),t=Math.max(t,r.down);s.push({kind:3,width:h,up:e,down:t,kids:o,text:"",id:"",reach:0}),o=[],h=0};for(let e of r)o.length&&h+t.gap+e.width>Math.max(40,i-6*t.arc)&&c(),h+=(o.length?t.gap:0)+e.width,o.push(e);if(c(),s.length<2)return n;let d=0,f=0;for(let e=0;e<s.length;e++)d=Math.max(d,s[e].width),e&&(f+=s[e-1].down+Math.max(t.sep,2*t.arc)+s[e].up);return{kind:7,width:d+6*t.arc,up:s[0].up,down:f+s[s.length-1].down,kids:s,text:"",id:"",reach:0}}case"choice":{let e=0,a=0;for(let i=0;i<r.length;i++)e=Math.max(e,r[i].width),i>0&&(a=py(a,r[i-1],r[i],t));let i=r[r.length-1];return{kind:4,width:e+4*t.arc,up:r.length>0?r[0].up:0,down:i?a+i.down:0,kids:r,text:"",id:"",reach:0}}case"optional":return gy(r[0],t);case"repetition":{let{min:a,max:i}=e,l=r[0];if(1===a&&1===i)return l;let n=function(e,t){if(t===1/0&&e<=1)return"";let r=e=>Number.isFinite(e)?String(e):"∞";return e===t?r(e)+"×":t===1/0?"≥"+r(e)+"×":0===e?"≤"+r(t)+"×":r(e)+"–"+r(t)+"×"}(a,i),s=Math.max(l.down+t.sep,2*t.arc),o=""===n?0:fy(t.measurer.width(n,12,0)),h={kind:6,width:Math.max(l.width,o)+2*t.arc,up:l.up,down:s+(""===n?4.5:18),kids:[l],text:n,id:"",reach:s};return 0===a?gy(h,t):h}}})}var yy={type:"railroad",parse:(e,t,r)=>ly(e,r),render:function(e,t,r){return Vl(r,a=>function(e,t,r,a){let i=r.fontSize??16,l=oy(t,"fontSize",0,200),n=l||Math.round(.875*i),s=l||i,o=oy(t,"padding",-1,200),h=Math.round(1.5*n),c={measurer:r.measurer??Ce(r.fontFamily,r.fontFamilyMono),size:n,padding:o<0?12:o,height:fy(h+(o<0?9:2*o)),gap:Math.min(oy(t,"horizontalSeparation",16,500),a?12:1/0),sep:oy(t,"verticalSeparation",10,500),arc:Math.min(oy(t,"arcRadius",10,200),a?6:1/0)},d=!1===t.railroad?.showMarkers?0:oy(t,"markerRadius",4,50),f=oy(t,"strokeWidth",0,20),u=f>0?` stroke-width="${Oe(f)}"`:"",p=r.padding??8,{arc:g}=c,m=Oe(g),y=(e,t,r)=>`a${m},${m} 0 0 ${e} ${t}${m},${r}${m}`,x=y(1,"",""),w=y(0,"",""),$=y(0,"","-"),b=y(1,"","-"),M=y(0,"-",""),v=y(0,"-","-"),k=Fl(e.title,!1,c.measurer,i,a?Gl(r):4e3,1),A=k.height>0?k.height+16:0,T=Math.round(1.5*s),C=.35*n,E=c.height/2,_="",S="",I="",N=(e,t,r)=>{r>e&&(_+=`M${Oe(e)},${Oe(t)}H${Oe(r)}`)},D=(e,t,r)=>{let a=[e],i=[t,r];for(;a.length>0;){let e=a.pop(),t=i.pop(),r=i.pop(),l=e.kids,n=r+e.width;switch(e.kind){case 3:{let e=n;for(let r=l.length-1;r>=0;r--)e-=l[r].width,a.push(l[r]),i.push(e,t),r>0&&N(e-c.gap,t,e),e-=c.gap;break}case 7:{let e=r+2*g,s=a.length,o=0;N(r,t,e);for(let s=0;s<l.length;s++){let h=l[s],d=t+o;if(a.push(h),i.push(d,e),s+1<l.length){let a=l[s+1],i=o+h.down+Math.max(c.sep,2*g)+a.up,f=t+o+h.down+Math.max(c.sep,2*g)/2;_+=`M${Oe(e+h.width)},${Oe(d)}H${Oe(n-2*g)}V${Oe(f)}H${Oe(r+g)}V${Oe(t+i)}H${Oe(e)}`,S+=`M${Oe(e-7)},${Oe(t+i-3.5)}l7,3.5l-7,3.5z`,o=i}else _+=`M${Oe(e+h.width)},${Oe(d)}H${Oe(n-g)}V${Oe(t)}H${Oe(n)}`}dy(a,s),dy(i,2*s);break}case 4:{let s=e.width-4*g,o=r+g,h=n-g,d=a.length,f=0;for(let e=0;e<l.length;e++){let d=l[e];e>0&&(f=py(f,l[e-1],d,c));let u=t+f,p=r+2*g+(s-d.width)/2,m=e===l.length-1;0===e?(N(r,t,p),N(p+d.width,t,n)):_+=(m?`M${Oe(r)},${Oe(t)}${x}V${Oe(u-g)}`:`M${Oe(o)},${Oe(u-g)}`)+w+(p>o+g?`H${Oe(p)}`:"")+`M${Oe(p+d.width)},${Oe(u)}`+(p>o+g?`H${Oe(h-g)}`:"")+$+(m?`V${Oe(t+g)}${b}`:""),a.push(d),i.push(u,p)}dy(a,d),dy(i,2*d);break}case 5:{let s=l[0],o=r+2*g;N(r,t,o),N(o+s.width,t,n),_+=`M${Oe(r)},${Oe(t)}${$}V${Oe(t-e.reach+g)}${b}H${Oe(n-2*g)}${x}V${Oe(t-g)}${w}`,a.push(s),i.push(o,t);break}case 6:{let s=l[0],o=r+(e.width-s.width)/2,h=t+e.reach,c=r+e.width/2;N(r,t,o),N(o+s.width,t,n),_+=`M${Oe(r+g)},${Oe(t)}${M}V${Oe(h-g)}${w}H${Oe(n-g)}${$}V${Oe(t+g)}${v}`,S+=`M${Oe(c-3.5)},${Oe(h)}l7,-3.5v7z`,""!==e.text&&(I+=`<text class="pele-edge-label pele-count" x="${Oe(c)}" y="${Oe(h+sy+3)}" font-size="12" fill="var(--_m)">${De(e.text)}</text>`),a.push(s),i.push(o,t);break}default:{let a=e.text,i=a.startsWith(" ")||a.endsWith(" ")||a.includes(" ")?' xml:space="preserve"':"",l=`<rect x="${Oe(r)}" y="${Oe(t-E)}" width="${Oe(e.width)}" height="${Oe(c.height)}"`,n=`<text x="${Oe(r+e.width/2)}" y="${Oe(t+C)}"${i}`;0===e.kind?I+=`<g class="pele-node pele-terminal">${l} rx="${Oe(E)}" fill="var(--_s)" stroke="var(--_b)"${u}/>${n} font-family="${bi}">${De(a)}</text></g>`:1===e.kind?I+=`<g class="pele-node pele-nonterminal" data-id="${Re(e.id)}">${l} fill="var(--_bg)" stroke="var(--_b)"${u}${Mi}/>${n}>${De(a)}</text></g>`:I+=`<g class="pele-node pele-special">${l} fill="var(--_bg)" stroke="var(--_b)" stroke-dasharray="4 3"${u}${Mi}/>${n} font-style="italic"><tspan fill="var(--_m)">? </tspan>${De(a.slice(2,-2))}<tspan fill="var(--_m)"> ?</tspan></text></g>`}}}},R="",L=k.width,O=p+A,F=p+k.height;for(let t of e.rules){let e=my(t.definition,c,a?Math.max(80,(r.maxWidth??320)-2*p-4*d-24-1):1/0),i=cy(t.name),l=O+T+6+e.up,n=p+2*d,o=n+ny,h=o+e.width+ny;_="",S="",I="",N(n,l,o),N(o+e.width,l,h),D(e,o,l);let f=d>0?`<circle class="pele-marker pele-start" cx="${Oe(p+d)}" cy="${Oe(l)}" r="${Oe(d)}" fill="var(--_l)"/><circle class="pele-marker pele-end" cx="${Oe(h+d)}" cy="${Oe(l)}" r="${Oe(d)}" fill="var(--_l)"/>`:"";R+=`<g class="pele-rule" data-id="${Re(t.name)}"><text class="pele-rule-name" x="${Oe(p)}" y="${Oe(O+T/2+.35*s)}" font-size="${Oe(s)}" font-weight="var(--_hw)" text-anchor="start">${De(i)}</text><path class="pele-edge pele-track" d="${_}" fill="none" stroke="var(--_l)"${u}/>`+(S?`<path class="pele-marker" d="${S}" fill="var(--_l)"/>`:"")+f+I+"</g>",L=Math.max(L,h+2*d-p,c.measurer.width(i,s,1)),F=l+e.down,O=F+c.sep+18}let z=Math.ceil(L+2*p),W=Math.ceil(F+p),P=Fe(k,z/2,p+k.height/2,' class="pele-title" font-weight="var(--_tw)"')+(R?`<g class="pele-rules" transform="translate(0.5,0.5)" font-size="${Oe(n)}" text-anchor="middle">${R}</g>`:"");return{svg:Bi("railroad",z,W,i,r,e,P),width:z,height:W,links:[]}}(e,t,r,a))}},xy="Requirement",wy="Functional Requirement",$y="Interface Requirement",by="Performance Requirement",My="Physical Requirement",vy="Design Constraint",ky="Low",Ay="Medium",Ty="High",Cy="Analysis",Ey="Demonstration",_y="Inspection",Sy="Test",Iy="contains",Ny="copies",Dy="derives",Ry="satisfies",Ly="verifies",Oy="refines",Fy="traces",zy=class{type="requirement";direction="TB";requirements=new Map;elements=new Map;relations=[];classes=new Map;title;accTitle;accDescr;newId="";newText="";newRisk="";newVerifyMethod="";newElementType="";newDocRef="";styleCopies=0;copy(e,t){if(this.styleCopies+=t.length,this.styleCopies>1e6)throw new i("Requirement diagram applies too many style declarations.","limit",{type:"requirement"});for(let r of t)e.push(r)}setDirection(e){this.direction=e}addRequirement(e,t){let r=this.requirements.get(e);return void 0===r&&(r={name:e,type:t,requirementId:this.newId,text:this.newText,risk:this.newRisk,verifyMethod:this.newVerifyMethod,cssStyles:[],classes:["default"]},this.requirements.set(e,r)),this.newId=this.newText=this.newRisk=this.newVerifyMethod="",r}setNewReqId(e){this.newId=e}setNewReqText(e){this.newText=e}setNewReqRisk(e){this.newRisk=e}setNewReqVerifyMethod(e){this.newVerifyMethod=e}addElement(e){let t=this.elements.get(e);return void 0===t&&(t={name:e,type:this.newElementType,docRef:this.newDocRef,cssStyles:[],classes:["default"]},this.elements.set(e,t)),this.newElementType=this.newDocRef="",t}setNewElementType(e){this.newElementType=e}setNewElementDocRef(e){this.newDocRef=e}addRelationship(e,t,r){this.relations.push({type:e,src:t,dst:r})}node(e){return this.requirements.get(e)??this.elements.get(e)}setCssStyle(e,t){for(let r of e){let e=this.node(r);if(!t||!e)return;for(let r of t)this.copy(e.cssStyles,r.includes(",")?r.split(","):[r])}}setClass(e,t){for(let r of e){let e=this.node(r);if(e)for(let r of t){e.classes.push(r);let t=this.classes.get(r)?.styles;t&&this.copy(e.cssStyles,t)}}}defineClass(e,t){for(let r of e){let e=this.classes.get(r);void 0===e&&(e={id:r,styles:[],textStyles:[]},this.classes.set(r,e));for(let r of t)r.includes("color")&&e.textStyles.push(r.replace("fill","bgFill")),e.styles.push(r);let a=t.flatMap(e=>e.split(","));for(let e of this.requirements.values())e.classes.includes(r)&&this.copy(e.cssStyles,a);for(let e of this.elements.values())e.classes.includes(r)&&this.copy(e.cssStyles,a)}}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}},Wy=["$end","INVALID","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","direction_tb","direction_bt","direction_rl","direction_lr","NEWLINE","EOF","RD","STRUCT_START","STRUCT_STOP","STYLE_SEPARATOR","COLONSEP","ID","TEXT","RISK","VERIFYMTHD","REQUIREMENT","FUNCTIONAL_REQUIREMENT","INTERFACE_REQUIREMENT","PERFORMANCE_REQUIREMENT","PHYSICAL_REQUIREMENT","DESIGN_CONSTRAINT","LOW_RISK","MED_RISK","HIGH_RISK","VERIFY_ANALYSIS","VERIFY_DEMONSTRATION","VERIFY_INSPECTION","VERIFY_TEST","ELEMENT","CONTAINS","COPIES","DERIVES","SATISFIES","VERIFIES","REFINES","TRACES","TYPE","DOCREF","STYLE","CLASSDEF","CLASS","ALPHA","COLON","SEMICOLON","PERCENT","MINUS","BRKT","END_ARROW_L","END_ARROW_R","LINE","qString","unqString","COMMA"],Py=new Map([["requirementdiagram",14],["id",19],["text",20],["risk",21],["verifymethod",22],["requirement",23],["functionalrequirement",24],["interfacerequirement",25],["performancerequirement",26],["physicalrequirement",27],["designconstraint",28],["low",29],["medium",30],["high",31],["analysis",32],["demonstration",33],["inspection",34],["test",35],["element",36],["contains",37],["copies",38],["derives",39],["satisfies",40],["verifies",41],["refines",42],["traces",43],["type",44],["docref",45],["style",46],["classdef",47],["class",48]]),By=/accTitle\s*:\s*/iy,Hy=/accDescr\s*:\s*/iy,Yy=/accDescr\s*\{\s*/iy,Gy=/direction\s+(?:(TB)|(BT)|(RL)|LR)/gi,Uy=/[\n\r\u2028\u2029]/g,qy=new Uint8Array(128);for(let e of":,\r\n{<>-=")qy[e.charCodeAt(0)]=1;function jy(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=[[],[],[],[]],h=[[],[],[],[]],c=[0,0,0,0],d=!1,f=-1;Gy.lastIndex=0;for(let t=Gy.exec(e);null!==t;t=Gy.exec(e)){let e=void 0!==t[1]?0:void 0!==t[2]?1:void 0!==t[3]?2:3;o[e].push(t.index),h[e].push(Gy.lastIndex),d=!0}let u=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},p=e=>{l.push(n),n=e},g=()=>{l.length>0&&(n=l.pop())},m=(t,r)=>(t.lastIndex=r,t.test(e)?t.lastIndex:-1),y=r=>{let a=e.indexOf("\n",r);return-1===a?t:a},x=l=>{let n=32|l;if(116===n&&"itle"===e.slice(s+1,s+5).toLowerCase()&&q(e.charCodeAt(s+5))){let r=s+6;for(;r<t;){let t=e.charCodeAt(r);if(35===t||10===t||59===t)break;r++}if(r>s+6)return u(2,s,r),!0}if(97===n&&99==(32|e.charCodeAt(s+1))&&99==(32|e.charCodeAt(s+2))){let e;if((e=m(By,s))>=0)return p(3),u(3,s,e),!0;if((e=m(Hy,s))>=0)return p(4),u(5,s,e),!0;if((e=m(Yy,s))>=0)return p(5),s=e,!0}if(d&&!V(l)&&(()=>{if(f<s){Uy.lastIndex=s,f=Uy.test(e)?Uy.lastIndex-1:t;for(let e=0;e<4;e++){let t=o[e],r=c[e];for(;r<t.length&&t[r]<=f;)r++;c[e]=r}}for(let e=0;e<4;e++){let t=c[e]-1;if(t>=0&&o[e][t]>=s)return u(8+e,s,y(h[e][t])),!0}return!1})())return!0;if(10===l||13===l&&10===e.charCodeAt(s+1)){let r=s;for(;r<t;){let t=e.charCodeAt(r);if(10===t)r++;else{if(13!==t||10!==e.charCodeAt(r+1))break;r+=2}}return u(12,s,r),!0}if(q(l)){for(s++;s<t&&q(e.charCodeAt(s));)s++;return!0}if(35===l||37===l)return s=y(s),!0;if(Q(l)){let l=s+1;for(;l<t&&Q(e.charCodeAt(l));)l++;if(l-s<=22){let t=Py.get(e.slice(s,l).toLowerCase());if(void 0!==t)return(46===t||47===t||48===t)&&p(2),u(t,s,l),!0}for(;l<t;){let t=e.charCodeAt(l);if(t<128&&1===qy[t])break;l++}return r.push(59),a.push(e.slice(s,l).trim()),i.push(s),s=l,!0}switch(l){case 123:return u(15,s,s+1),!0;case 125:return u(16,s,s+1),!0;case 58:return 58===e.charCodeAt(s+1)&&58===e.charCodeAt(s+2)?u(17,s,s+3):u(18,s,s+1),!0;case 60:return 45===e.charCodeAt(s+1)&&(u(55,s,s+2),!0);case 45:return 62===e.charCodeAt(s+1)?u(56,s,s+2):u(57,s,s+1),!0;case 34:return p(1),s++,!0;case 44:return u(60,s,s+1),!0}return!1},w=r=>{if(Q(r)){let r=s+1;for(;r<t&&Q(e.charCodeAt(r));)r++;return u(49,s,r),!0}switch(r){case 58:return u(50,s,s+1),!0;case 59:return u(51,s,s+1),!0;case 37:return u(52,s,s+1),!0;case 45:return u(53,s,s+1),!0;case 35:return u(54,s,s+1),!0;case 32:return s++,!0;case 34:return p(1),s++,!0;case 10:return g(),s++,!0;case 44:return u(60,s,s+1),!0}return!1};for(;s<t;){let l=e.charCodeAt(s),o=!0;switch(n){case 0:o=x(l);break;case 2:o=w(l);break;case 1:if(34===l)g(),s++;else{let r=e.indexOf('"',s);u(58,s,-1===r?t:r)}break;case 3:g(),u(4,s,y(s));break;case 4:g(),u(6,s,y(s));break;case 5:if(125===l)g(),s++;else{let r=e.indexOf("}",s);u(7,s,-1===r?t:r)}}if(!o)return r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}}let $=0===n?13:1===n?58:3===n?4:4===n?6:5===n?7:-1;return-1!==$&&u($,t,t),u(0,t,t),{types:r,texts:a,starts:i}}var Vy=[xy,wy,$y,by,My,vy,ky,Ay,Ty,Cy,Ey,_y,Sy,"",Iy,Ny,Dy,Ry,Ly,Oy,Fy];function Xy(e){return 49===e||50===e||54===e||53===e||51===e}var Ky=4.5;function Zy(e,t,r){if(0===t||0===e.lines.length)return e;let a=0,i=[],l=e.lines.map(l=>{let n=0,s=l.map(a=>{let i=a.style|t,l=void 0!==a.icon||a.math?a.width:r.width(a.text,e.size,i);return n+=l,{...a,style:i,width:l}});return i.push(n),n>a&&(a=n),s});return{...e,lines:l,widths:i,width:a}}function Qy(e,t,r,a){let i=Qe(e),l="",n="";for(let s=0;s<e.lines.length;s++){let o=e.lines[s],h=r+Bl(e,s);if(Pl(o)){n+=Fe(Hl(e,s),t+e.widths[s]/2,h,a);continue}let c=h+.35*e.size,d=!0;for(let e of o)void 0!==e.icon||""===e.text||(l+=`<tspan${d?` x="${Oe(t)}" y="${Oe(c)}"`:""}${Ze(e.style&~i)}>${De(e.text)}</tspan>`,d=!1)}return(""===l?"":`<text${Je(a,i)} text-anchor="start" xml:space="preserve">${l}</text>`)+n}function Jy(e,t,r,a){let i=e-6*r,l=t-6*a;return`<circle class="pele-marker" cx="${Oe(i)}" cy="${Oe(l)}" r="6"/><path class="pele-marker" d="M${Oe(i-6*r)},${Oe(l-6*a)}L${Oe(i+6*r)},${Oe(l+6*a)}M${Oe(i+6*a)},${Oe(l-6*r)}L${Oe(i-6*a)},${Oe(l+6*r)}"/>`}function ex(e,t,r,a){let i=e-9*r,l=t-9*a;return`<path class="pele-marker" d="M${Oe(i-a*Ky)},${Oe(l+r*Ky)}L${Oe(e)},${Oe(t)}L${Oe(i+a*Ky)},${Oe(l-r*Ky)}" stroke-linejoin="round"/>`}function tx(e,t,r,a){let i=function(e){let t=[];for(let r of e.requirements.values())t.push({id:r.name,requirement:r,element:void 0,cssStyles:r.cssStyles,cssClasses:r.classes.join(" ")});for(let r of e.elements.values())t.push({id:r.name,requirement:void 0,element:r,cssStyles:r.cssStyles,cssClasses:r.classes.join(" ")});let r=t=>e.requirements.has(t)||e.elements.has(t)?t:void 0;return{nodes:t,edges:e.relations.map((e,t)=>({id:`${e.src}-${e.dst}-${t}`,start:r(e.src),end:r(e.dst),type:e.type,contains:e.type===Iy})),direction:e.direction}}(e),l=r.fontSize??16,n=Math.round(.875*l),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=r.padding??8,h=new Map,c=[],d=[];for(let e of i.nodes){let t=Ri(e.cssStyles),r=(t.bold?1:0)|(t.italic?2:0),a=t.fontSize??l,i=t.fontSize??n,o=e.requirement,f=e.element,u=Zy(Fl(`«${o?o.type:"Element"}»`,!1,s,i,4e3),r,s),p=Zy(Fl(e.id,!0,s,a,280),1|r,s),g=o?[["ID",o.requirementId],["Text",o.text],["Risk",o.risk],["Verification",o.verifyMethod]]:[["Type",f.type],["Doc Ref",f.docRef]],m=[],y=0,x=0,w=0;for(let[e,t]of g){if(!t)continue;let a=Zy(Fl(e,!1,s,i,4e3),r,s),l=Zy(Fl(t,!0,s,i,240),r,s),n=Math.max(a.height,l.height);m.push({key:a,value:l,height:n}),y=Math.max(y,a.width),x=Math.max(x,l.width),w+=n+2}m.length>0&&(w+=18);let $=20+u.height+p.height,b=Math.max(120,Math.max(u.width,p.width)+28,m.length>0?y+12+x+28:0);h.has(e.id)||h.set(e.id,c.length);let M=Va(b,$+w);M.seq=c.length,c.push({node:e,style:t,kind:u,name:p,rows:m,keyWidth:y,headHeight:$,w:b,h:$+w}),d.push(M)}let f=a?"TB":Pa(i.direction),u="LR"===f||"RL"===f,p=[],g=[],m=[];for(let e of i.edges){let t=void 0===e.start?void 0:h.get(e.start),r=void 0===e.end?void 0:h.get(e.end);if(void 0===t||void 0===r)continue;let a=Fl(`«${e.type}»`,!1,s,n,4e3);t===r&&(u?d[t].h+=2*(26+a.height+8):d[t].w+=2*(26+a.width+12)),m.push(e),g.push(a),p.push({src:t,dst:r,minlen:1,labelW:a.width+12,labelH:a.height+4,route:[],labelX:0,labelY:0})}let y=Za(d,p,f,{nodeSep:40,edgeSep:16,rankSep:56,portSep:20});!function(e,t,r){let a=new Map;for(let r of t){let t=r.route;if(!(r.src===r.dst||t.length<6))for(let i of[0,t.length-3]){let l,n=0===i?r.src:r.dst,s=e[n],o=t[i]-s.x,h=t[i+1]-s.y,c=0===i?3:i-3;if(Math.abs(Math.abs(h)-s.h/2)<.5)l=h<0?0:2;else{if(!(Math.abs(Math.abs(o)-s.w/2)<.5))continue;l=o<0?3:1}let d=4*n+l,f={route:t,at:i,toward:t[l%2==0?c:c+1]},u=a.get(d);u?u.push(f):a.set(d,[f])}}for(let[t,i]of a){if(i.length<2)continue;let a=t>>2,l=t%2==1,n=(l?r[a].h:r[a].w)-28,s=Math.max(0,Math.min(28,n/(i.length-1)));i.sort((e,t)=>e.toward-t.toward);for(let t=0;t<i.length;t++){let r=(t-(i.length-1)/2)*s;l?i[t].route[i[t].at+1]=e[a].y+r:i[t].route[i[t].at]=e[a].x+r}}}(d,p,c);let x=gs(e.title,s,l,4e3),w=x.height>0?x.height+12:0,$=Math.max(y.width,x.width),b=o+($-y.width)/2,M=o+w,v=Math.ceil($+2*o),k=Math.ceil(y.height+w+2*o),A="";for(let e=0;e<c.length;e++){let t=c[e],{w:r,h:a,style:i}=t,l=xt(i),n=l||' fill="var(--_m)"',s=-r/2,o=-a/2,h=`<rect x="${Oe(s)}" y="${Oe(o)}" width="${Oe(r)}" height="${Oe(a)}" fill="var(--_s)" stroke="var(--_b)"${Ai(i.shape)}/>`+Fe(t.kind,0,o+10+t.kind.height/2,` class="pele-stereotype" font-size="${t.kind.size}"${n}${i.text}`)+Fe(t.name,0,o+10+t.kind.height+t.name.height/2,` class="pele-label" font-size="${t.name.size}" font-weight="var(--_hw)"${l}${i.text}`);if(t.rows.length>0){let e=o+t.headHeight;h+=`<path class="pele-divider" d="M${Oe(s)},${Oe(e)}H${Oe(-s)}" stroke="var(--_b)"${i.line}/>`;let r=e+10,a="";for(let e of t.rows)a+=Qy(e.key,s+14,r,` class="pele-field"${n}${i.text}`)+Qy(e.value,s+14+t.keyWidth+12,r,` class="pele-value"${l}${i.text}`),r+=e.height+2;h+=`<g class="pele-fields" font-size="${t.rows[0].key.size}">${a}</g>`}A+=`<g class="pele-node ${t.node.requirement?"pele-requirement":"pele-element"}${Oi(t.node.cssClasses.replace(/^default\s?/,""))}" data-id="${Re(t.node.id)}" transform="translate(${Oe(d[e].x+b)},${Oe(d[e].y+M)})">${h}</g>`}let T="",C="",E=new Map;for(let e=0;e<p.length;e++){let t,r=p[e],a=m[e],i=g[e],l=a.contains?12:0,n=r.labelX+b,s=r.labelY+M;if(r.src===r.dst){let e=c[r.src],a=d[r.src].x+b,i=d[r.src].y+M,o=E.get(r.src)??0;E.set(r.src,o+1);let h=(u?e.w:e.h)/2,f=Math.min(h-4,12+6*o),p=26+8*o,g=(t,r)=>u?`${Oe(a+r)},${Oe(i+e.h/2+t)}`:`${Oe(a+e.w/2+t)},${Oe(i+r)}`,m=p/.75;t={d:`M${g(l,-f)}C${g(m,-f)} ${g(m,f)} ${g(0,f)}`,sx:u?a-f:a+e.w/2,sy:u?i+e.h/2:i-f,sdx:u?0:-1,sdy:u?-1:0,ex:u?a+f:a+e.w/2,ey:u?i+e.h/2:i+f,edx:u?0:-1,edy:u?-1:0},u?(n=a,s=i+e.h/2+p+4+r.labelH/2):(n=a+e.w/2+p+4+r.labelW/2,s=i)}else{let e=r.route.slice();for(let t=0;t<e.length;t+=3)e[t]+=b,e[t+1]+=M;t=ai(e,void 0,l,0)}T+=`<g class="pele-edge pele-relationship-${a.contains?"contains":"arrow"}" data-id="${Re(a.id)}"><path d="${t.d}"${a.contains?"":' stroke-dasharray="5 4"'}/>`+(a.contains?Jy(t.sx,t.sy,t.sdx,t.sdy):ex(t.ex,t.ey,t.edx,t.edy))+"</g>",C+=wi(a.id,i,n,s,"")}return{svg:Bi("requirement",v,k,l,r,e,Fe(x,v/2,o+x.height/2,' class="pele-title" font-weight="var(--_tw)"')+(T?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${T}</g>`:"")+(C?`<g class="pele-edge-labels" font-size="${n}" fill="var(--_m)">${C}</g>`:"")+`<g class="pele-nodes">${A}</g>`),width:v,height:k,links:[]}}var rx={type:"requirement",math:!0,parse(e,t,r){let a=new zy;return r&&(a.title=r),function(e,t){let{types:r,texts:a,starts:i}=jy(e),l=0,n=[],s=[],o=(t,a=t,...n)=>{let s=r[l];if(1===s)throw c("requirement",e,i[l],"",!0);for(let e=a;e>=t;e--)n.unshift(e);let o=n.map(e=>`'${Wy[e]}'`).join(", ");throw c("requirement",e,i[l],`Expecting ${o}, got '${Wy[s]}'`)},h=e=>(r[l]!==e&&o(e),a[l++]),d=(e,t)=>{let a=r[l];return(a<e||a>t)&&o(e,t),l++,Vy[a-23]},f=()=>{let e=r[l];return 59!==e&&58!==e&&o(58,59),a[l++]},u=()=>{let e=r[l];if(3===e)l++,t.setAccTitle(h(4).trim());else if(5===e)l++,t.setAccDescription(h(6).trim());else{if(7!==e)return!1;t.setAccDescription(a[l++].trim())}return!0},p=()=>{let e=[];for(;;){let t=r[l];if(49!==t&&59!==t&&58!==t&&o(58,59,49),e.push(a[l++]),60!==r[l])return e;l++}},g=()=>{let e=[];for(;;){Xy(r[l])||o(49,51,53,54);let t=a[l++];for(;Xy(r[l]);)t+=a[l++];if(e.push(t),60!==r[l])return e;l++}},m=()=>{let e;return 17===r[l]?(l++,e=p(),h(15)):15===r[l]?l++:o(15,15,17),h(12),e},y=e=>{for(n.length=0,s.length=0;;){let t=r[l];if(16===t){l++;break}12!==t?((e?t<19||t>22:44!==t&&45!==t)&&(e&&o(19,22,12,16),o(44,45,12,16)),l++,h(18),s.push(21===t?d(29,31):22===t?d(32,35):f()),n.push(t),h(12)):l++}for(let e=n.length-1;e>=0;e--){let r=s[e];switch(n[e]){case 19:t.setNewReqId(r);break;case 20:t.setNewReqText(r);break;case 21:t.setNewReqRisk(r);break;case 22:t.setNewReqVerifyMethod(r);break;case 44:t.setNewElementType(r);break;default:t.setNewElementDocRef(r)}}};for(;u();)12===r[l]&&l++;for(14!==r[l]&&o(14,14,3,5,7),l++,h(12);;){let e=r[l];if(13===e)return;if(12===e)l++;else{if(u())continue;if(e>=8&&e<=11)l++,t.setDirection(8===e?"TB":9===e?"BT":10===e?"RL":"LR");else if(e>=23&&e<=28){let e=d(23,28),r=f(),a=m();y(!0),t.addRequirement(r,e),a&&t.setClass([r],a)}else if(36===e){l++;let e=f(),r=m();y(!1),t.addElement(e),r&&t.setClass([e],r)}else if(46===e){l++;let e=p();t.setCssStyle(e,g())}else if(47===e){l++;let e=p();t.defineClass(e,g())}else if(48===e){l++;let e=p();t.setClass(e,p())}else if(59===e||58===e){let e=a[l++],i=r[l];if(17===i)l++,t.setClass([e],p());else if(55===i||57===i){l++;let r=d(37,43);h(57===i?56:57);let a=f();57===i?t.addRelationship(r,e,a):t.addRelationship(r,a,e)}else o(17,17,55,57)}else o(12,13,3,5,7,8,9,10,11,23,24,25,26,27,28,36,47,48,46,59,58)}}}(e,a),a},render:function(e,t,r){return jl(e.direction)?ql(r,a=>tx(e,t,r,a)):tx(e,t,r,!1)}},ax=class{type="sankey";nodes=[];links=[];title;accTitle;accDescr;lookup=new Map;findOrCreateNode(e){let t=this.lookup.get(e);return void 0===t&&(t={id:e,index:this.nodes.length},this.lookup.set(e,t),this.nodes.push(t)),t}addLink(e,t,r){this.links.push({source:e,target:t,value:r})}},ix=["$end","STUCK","SANKEY","NEWLINE","COMMA","DQUOTE","NON_ESCAPED_TEXT","ESCAPED_TEXT","EOF"];function lx(e){return e>=32&&e<=126&&34!==e&&44!==e||e>=160&&e<=55295||e>=57344&&e<=65533||e>=65536&&e<=1114111}var nx=/[\n\r]+/g,sx=/[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff\ufffe\uffff]/u;function ox(e){return 10!==e&&13!==e&&(e<128?32===e||9===e||11===e||12===e:160===e||5760===e||e>=8192&&e<=8202||8232===e||8233===e||8239===e||8287===e||12288===e||65279===e)}function hx(e,t){let r=[],a=function(e,t){let r=e.length;for(;r>0&&ox(e.charCodeAt(r-1));)r--;let a="",i=0,l=!1;for(let n=0;n<r;){let r=e.charCodeAt(n);if(l)34===r&&(34===e.charCodeAt(n+1)?n++:l=!1),n++;else if(34===r)l=!0,n++;else if(ox(r)){let r=n+1;for(;ox(e.charCodeAt(r));)r++;let l=e.charCodeAt(n-1),s=e.charCodeAt(r);(0===n||10===s||13===s||(10===l||13===l)&&44!==s)&&(a+=e.slice(i,n),t.push([n,r,0]),i=r),n=r}else n++}return r<e.length&&t.push([r,e.length,0]),a+e.slice(i,r)}(e,r),i=a.replace(nx,"\n"),n=i.trim();if(void 0!==t){let e=i.length-i.trimStart().length;t.push(r,l(a,nx,1),[[0,e,0],[e+n.length,i.length,0]])}return n}function cx(e,t,r=e){let{types:a,texts:i,starts:l}=function(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},h=t=>e.slice(s,s+t.length).toLowerCase()===t&&!Q(e.charCodeAt(s+t.length));for(;s<t;){let c=e.charCodeAt(s),d=s,f=s;if(2===n){if(34===c&&34!==e.charCodeAt(s+1)){l.length>0&&(n=l.pop()),o(5,s,s+1);continue}for(;f<t;){let t=e.codePointAt(f);if(lx(t)||44===t||13===t||10===t)f+=t>65535?2:1;else{if(34!==t||34!==e.charCodeAt(f+1))break;f+=2}}o(7,s,f)}else{if(0===n&&115==(32|c)){let e=h("sankey-beta")?11:h("sankey")?6:0;if(e>0){l.push(n),n=1,o(2,s,s+e);continue}}if(10===c||13===c&&10===e.charCodeAt(s+1)){o(3,s,10===c?s+1:s+2);continue}if(44===c){o(4,s,s+1);continue}if(34===c){l.push(n),n=2,o(5,s,s+1);continue}for(;f<t;){let t=e.codePointAt(f);if(!lx(t))break;f+=t>65535?2:1}o(6,s,f)}if(f===d)return o(1,s,s),{types:r,texts:a,starts:i}}return o(2===n?7:8,t,t),o(0,t,t),{types:r,texts:a,starts:i}}(e),n=0,o=(t,a)=>{let i=[];r!==e&&hx(r,i);let l=t>0&&t>=e.length?s(i,e.length-1)+1:s(i,t);return c("sankey",r,l,a)},h=e=>{let t=a[n],r=1===t?ix[a[n-1]]:ix[t];throw o(l[n],`Expecting ${e}, got '${r}'`)},d=(e,t="")=>{a[n]!==e&&h(`'${ix[e]}'${t}`),n++},f=()=>{if(6===a[n])return i[n++];5!==a[n]&&h("'DQUOTE', 'NON_ESCAPED_TEXT'"),n++,7!==a[n]&&h("'ESCAPED_TEXT'");let e=i[n++];return d(5),e},u=()=>{let e=l[n],t=f().trim().replaceAll('""','"');if(sx.test(m(t)))throw o(e,"Invalid XML character in node name");return t};for(d(2),d(3);;){let e=u();d(4,", 'NEWLINE', 'EOF'");let r=u();d(4,", 'NEWLINE', 'EOF'");let i=l[n],s=parseFloat(f());if(!Number.isFinite(s))throw o(i,"Expecting a number");let h=t.findOrCreateNode(e),c=t.findOrCreateNode(r);if(t.addLink(h,c,s),3!==a[n])break;n++}8===a[n]&&n++,0!==a[n]&&h("'NEWLINE', 'EOF'")}function dx(e,t){if(e.length>8)e.sort(t);else for(let r=1;r<e.length;r++){let a=e[r],i=r-1;for(;i>=0&&t(e[i],a)>0;)e[i+1]=e[i],i--;e[i+1]=a}}var fx=300;function ux(e){let t=2166136261,r=5381;for(let a=0;a<e.length;a++){let i=e.charCodeAt(a);t=Math.imul(t^i,16777619),r=Math.imul(r,33)+i|0}return(t>>>0).toString(36)+(r>>>0).toString(36)}function px(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function gx(e,t,r,a,i){let l=e[t];return"number"==typeof l&&l>=a?Math.min(l,i):r}function mx(e,t){let r=e[t];return"string"==typeof r||"number"==typeof r&&Number.isFinite(r)?String(r):""}function yx(e){return Math.abs(e)<1e15?Math.round(100*e)/100:e}function xx(e){return"string"==typeof e?Ri([`fill:${e}`]).shape:""}var wx,$x={type:"sankey",parse(e,t,r){let a=new ax;return r&&(a.title=r),cx(hx(e),a,e),a},render:function(e,t,r){let a=px(t.sankey)?t.sankey:{},l=gx(a,"width",600,1,1e4);return Yl(r,l,160,t=>function(e,t,r,a,l){let n=r.fontSize??16,s=Math.round(.625*n),o=Math.max(s,Math.round(.875*n*Math.min(1,a/l))),h=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),c=r.padding??8,d=gx(t,"height",400,1,1e4),f=Math.min(gx(t,"nodeWidth",10,1,200),a),u=!1!==t.showValues,p=m(mx(t,"prefix")),g=m(mx(t,"suffix")),y="outlined"===t.labelStyle,x="left"===t.nodeAlignment||"right"===t.nodeAlignment||"center"===t.nodeAlignment?t.nodeAlignment:"justify",w="string"==typeof t.linkColor?t.linkColor:"gradient",$=r=>function(e,t){let r=e.nodes.length,a=e.links.map(e=>({source:e.source.index,target:e.target.index,value:Number.isFinite(e.value)&&e.value>0?e.value:0,thickness:0,sourceY:0,targetY:0})),l=[],n=[];for(let e=0;e<r;e++)l.push([]),n.push([]);a.forEach((e,t)=>{l[e.source].push(t),n[e.target].push(t)});let s=new Int32Array(r),o=new Int32Array(r),h=[];for(let e=0;e<r;e++)o[e]=n[e].length,0===o[e]&&h.push(e);for(let e=0;e<h.length;e++){let t=h[e];for(let e of l[t]){let r=a[e].target;s[r]<s[t]+1&&(s[r]=s[t]+1),0===--o[r]&&h.push(r)}}if(h.length<r){let t=0;for(;0===o[t];)t++;let l=new Uint8Array(r);for(;0===l[t];){l[t]=1;for(let e of n[t])if(o[a[e].source]>0){t=a[e].source;break}}throw new i(`Sankey diagrams cannot have circular links, and "${e.nodes[t].id}" is part of one.`,"semantic",{type:"sankey"})}let c=1;for(let e=0;e<r;e++)s[e]+1>c&&(c=s[e]+1);let d=new Int32Array(r);for(let e=r-1;e>=0;e--){let t=h[e];for(let e of l[t])d[t]<d[a[e].target]+1&&(d[t]=d[a[e].target]+1)}let f=0;for(let e of a)e.value>f&&(f=e.value);let u=f>0?1/f:0,p=[],g=new Float64Array(r),m=[];for(let e=0;e<c;e++)m.push([]);let y=c>1?(t.width-t.nodeWidth)/(c-1):0;for(let e=0;e<r;e++){let r;if("left"===t.alignment)r=s[e];else if("right"===t.alignment)r=c-1-d[e];else if("center"===t.alignment){if(r=s[e],0===n[e].length&&l[e].length>0){r=c;for(let t of l[e])s[a[t].target]-1<r&&(r=s[a[t].target]-1)}}else r=l[e].length>0?s[e]:c-1;let i=0,o=0,h=0,f=0;for(let t of n[e])i+=a[t].value*u,h+=a[t].value;for(let t of l[e])o+=a[t].value*u,f+=a[t].value;g[e]=Math.max(i,o),p.push({layer:r,value:Math.max(h,f),x:r*y,y:0,height:0}),m[r].push(e)}let x=1;for(let e of m)e.length>x&&(x=e.length);let w=x>1?Math.min(t.nodePadding,t.height/(x-1)):t.nodePadding,$=1/0;for(let e of m){let r=0;for(let t of e)r+=g[t];r>0&&($=Math.min($,(t.height-(e.length-1)*w)/r))}(!Number.isFinite($)||$<0)&&($=0);let b=Math.max(0,t.labelHeight-w),M=e=>{for(let r of m){let a=(r.length-1)*w;for(let t of r)a+=Math.max(g[t]*e,b);if(a>t.height+1e-6)return!1}return!0};if(b>0&&!M($))if(M(0)){let e=0;for(let t=0;t<40;t++){let t=(e+$)/2;M(t)?e=t:$=t}$=e}else b=0;let v=new Float64Array(r);for(let e of a)e.thickness=e.value*u*$;for(let e of m){let r=0;for(let t of e)p[t].height=g[t]*$,v[t]=Math.max(0,b-p[t].height)/2,p[t].y=r+v[t],r+=p[t].height+2*v[t]+w;let a=(t.height-r+w)/(e.length+1);e.forEach((e,t)=>p[e].y+=a*(t+1))}let k=e=>p[e].y+p[e].height/2,A=new Float64Array(a.length),T=new Float64Array(a.length),C=(e,t)=>k(a[e].target)-k(a[t].target)||e-t,E=(e,t)=>k(a[e].source)-k(a[t].source)||e-t,_=(e,t)=>k(e)-k(t)||e-t,S=e=>{let t=0;dx(l[e],C);for(let r of l[e])A[r]=t+a[r].thickness/2,t+=a[r].thickness},I=e=>{let t=0;dx(n[e],E);for(let r of n[e])T[r]=t+a[r].thickness/2,t+=a[r].thickness},N=()=>{for(let e=0;e<r;e++)S(e),I(e)},D=(e,r,i)=>{for(let t of e){let e=i?n[t]:l[t];if(0===e.length)continue;i?I(t):S(t);let s=0,o=0,h=0;for(let r of e)s+=(i?p[a[r].source].y+A[r]-T[r]:p[a[r].target].y+T[r]-A[r])*a[r].thickness,o+=a[r].thickness,h+=k(i?a[r].source:a[r].target)-p[t].height/2;let c=o>0?s/o:h/e.length;p[t].y+=(c-p[t].y)*r}dx(e,_);let s=0;for(let t of e)p[t].y-v[t]<s&&(p[t].y=s+v[t]),s=p[t].y+p[t].height+v[t]+w;s=t.height;for(let t=e.length-1;t>=0;t--){let r=e[t];p[r].y+p[r].height+v[r]>s&&(p[r].y=s-p[r].height-v[r]),s=p[r].y-v[r]-w}};N();for(let e=0;e<6;e++){let t=Math.pow(.99,e);for(let e=c-2;e>=0;e--)D(m[e],t,!1);N();for(let e=1;e<c;e++)D(m[e],t,!0);N()}for(let e=0;e<a.length;e++)a[e].sourceY=p[a[e].source].y+A[e],a[e].targetY=p[a[e].target].y+T[e];return{nodes:p,links:a}}(e,{width:a,height:d,nodeWidth:f,nodePadding:gx(t,"nodePadding",12,0,200)+(u?15:0),labelHeight:1.15*r,alignment:x}),b=$(o),M=new Map,v=1;for(let e of b.nodes){let t=(M.get(e.layer)??0)+1;M.set(e.layer,t),t>v&&(v=t)}let k=Math.max(s,Math.round(d/v/1.8));k<o&&(o=k,b=$(o));let{nodes:A,links:T}=b,C=1.5*o,E=new Map;if(px(t.nodeColors))for(let[e,r]of Object.entries(t.nodeColors)){let t=xx(r);t&&E.set(e,t)}let _=t=>E.get(e.nodes[t].id)??"",S=e=>/^ style="fill:(.*);"$/.exec(_(e))?.[1]??zi(e),I=0,N=0;A.forEach(e=>{e.value>N&&(N=e.value,I=e.layer)});let D=0,R=a,L=0,O=d,F=A.map((t,r)=>{let i=m(e.nodes[r].id),l=u?`${p}${yx(t.value)}${g}`:"",n=h.width(l?`${i} ${l}`:i,o,0),s=y?t.layer>=I:t.x<a/2,c=s?t.x+f+6:t.x-6,d=t.y+t.height/2;return D=Math.min(D,s?c:c-n),R=Math.max(R,s?c+n:c),L=Math.min(L,d-.75*o),O=Math.max(O,d+.75*o),{value:l,width:n,after:s,left:s?c:c-n,y:d}}),z=new Map;if(A.length<=fx)for(let e of F){let t=Math.floor(e.y/C);for(let r of[t-2,t-1,t,t+1,t+2]){let t=z.get(r);t?t.push(e):z.set(r,[e])}}let W="",P="";A.forEach((t,r)=>{let a=e.nodes[r].id,i=m(a),l=Math.max(t.height,1);P+=`<rect class="pele-sankey-node" data-id="${Re(a)}" x="${Oe(t.x)}" y="${Oe(t.y)}" width="${Oe(f)}" height="${Oe(l)}" rx="${Oe(Math.min(2,l/2))}" fill="${zi(r)}"${_(r)}/>`;let n=F[r],s=(e,t)=>(z.get(Math.floor(t/C))??[]).some(r=>r!==n&&Math.abs(r.y-t)<C&&e<r.left+r.width+6&&e+n.width>r.left-6);if(A.length<=fx&&s(n.left,n.y))e:for(let e of[0,-C,C])for(let a of[n.after,!n.after]){let i=a?t.x+f+6:t.x-6-n.width,l=n.y+e;if(s(i,l)||i<D||i+n.width>R||l-.75*o<L||l+.75*o>O||A.some((e,t)=>t!==r&&i<e.x+f+6&&i+n.width>e.x-6&&l-.75*o<e.y+e.height&&l+.75*o>e.y))continue;let h=Math.max(0,t.y-l,l-t.y-t.height);if(!A.some((e,a)=>a!==r&&e.x===t.x&&Math.max(0,e.y-l,l-e.y-e.height)<=h)){n.left=i,n.y=l,n.after=a;break e}}let{value:h,after:c,y:d}=n,u=` x="${Oe(c?t.x+f+6:t.x-6)}" y="${Oe(d+.35*o)}" text-anchor="${c?"start":"end"}"`,p=De(i)+(h?` <tspan class="pele-sankey-value" fill="var(--_m)">${De(h)}</tspan>`:"");W+=`<g class="pele-label" data-id="${Re(a)}">`+(y?`<text${u} fill="none" stroke="var(--_bg)" stroke-width="3" stroke-linejoin="round">${De(i)}${h?" "+De(h):""}</text>`:"")+`<text${u}>${p}</text></g>`});let B="gradient"===w||"source"===w||"target"===w?"":xx(w),H=r.idPrefix??"",Y="gradient"===w&&/^[\w-]+$/.test(H),G=new Map,U="";for(let t of T){let r="target"===w?t.target:t.source,a=Math.max(t.thickness,1)/2,i=A[t.source].x+f,l=A[t.target].x,n=`fill="${zi(r)}"${B||_(r)}`;if(Y){let e=`x1="${Oe(i)}" x2="${Oe(l)}"><stop offset="0" stop-color="${S(t.source)}"/><stop offset="1" stop-color="${S(t.target)}"/>`,r=`${H}-sankey-${ux(e)}`;G.set(r,`<linearGradient id="${r}" gradientUnits="userSpaceOnUse" ${e}</linearGradient>`),n=`fill="url(#${r}) ${S(t.source)}"`}let s=Oe((i+l)/2),o=Re(e.nodes[t.source].id),h=Re(e.nodes[t.target].id);U+=`<path class="pele-sankey-link" data-id="${o}-&gt;${h}" d="M${Oe(i)},${Oe(t.sourceY-a)}C${s},${Oe(t.sourceY-a)} ${s},${Oe(t.targetY-a)} ${Oe(l)},${Oe(t.targetY-a)}L${Oe(l)},${Oe(t.targetY+a)}C${s},${Oe(t.targetY+a)} ${s},${Oe(t.sourceY+a)} ${Oe(i)},${Oe(t.sourceY+a)}Z" ${n}><title>${o} → ${h}: ${De(p)}${yx(t.value)}${De(g)}</title></path>`}let q=Fl(e.title,!1,h,n,Gl(r),1),j=q.height>0?q.height+12:0,V=Math.max(R-D,q.width),X=c-D+(V-(R-D))/2,K=c+j-L,Z=Math.ceil(V+2*c),Q=Math.ceil(O-L+j+2*c);return{svg:Bi("sankey",Z,Q,n,r,e,Fe(q,Z/2,c+q.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe(X)},${Oe(K)})">`+(G.size>0?`<defs>${[...G.values()].join("")}</defs>`:"")+`<g class="pele-sankey-links" fill-opacity="0.4">${U}</g><g class="pele-sankey-nodes">${P}</g><g class="pele-labels" font-size="${o}">${W}</g></g>`),width:Z,height:Q,links:[]}}(e,a,r,t,l))}},bx=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(%|deg|grad|rad|turn)?$/i;function Mx(e){if("none"===e.toLowerCase())return 4;let t=bx.exec(e);return t?void 0===t[1]?1:"%"===t[1]?2:3:0}function vx(e){let t=e.startsWith("hsl"),r=e.indexOf("("),a=e.slice(0,r);if("rgb"!==a&&"rgba"!==a&&"hsl"!==a&&"hsla"!==a||e.length>120||e.indexOf(")")!==e.length-1)return!1;let i,l,n=e.slice(r+1,-1).trim(),s=n.includes(",");if(s)i=n.split(",").map(e=>e.trim()),4===i.length&&(l=i.pop());else{let e=n.split("/");if(e.length>2)return!1;i=e[0].trim().split(/\s+/),2===e.length&&(l=e[1].trim())}if(3!==i.length||void 0!==l&&!function(e,t){let r=Mx(e);return 1===r||2===r||t&&4===r}(l,!s))return!1;let o=i.map(Mx);if(s)return t?(1===o[0]||3===o[0])&&2===o[1]&&2===o[2]:(1===o[0]||2===o[0])&&o[1]===o[0]&&o[2]===o[0];for(let e=0;e<3;e++){let r=o[e];if(1!==r&&4!==r&&(t&&0===e?3!==r:2!==r))return!1}return!0}var kx=/^:?wrap:/,Ax=/^:?nowrap:/,Tx=/^:?(?:no)?wrap:/,Cx=/^(?:rgba?|hsla?)\s*\(/,Ex=/[\r\u2028\u2029]/,_x=/^\w*/;function Sx(e){throw new i(e,"semantic",{type:"sequence"})}function Ix(e){let t=e.trim(),r=!!kx.test(t)||!Ax.test(t)&&void 0;return{text:(void 0===r?t:t.replace(Tx,"")).trim(),wrap:r}}function Nx(e){return"string"==typeof e?[...e].map((e,t)=>[String(t),e]):null!==e&&"object"==typeof e?Object.entries(e):[]}var Dx=class{type="sequence";actors=new Map;createdActors=new Map;destroyedActors=new Map;boxes=[];messages=[];notes=[];title;accTitle;accDescr;prevActor;currentBox;lastCreated;lastDestroyed;wrapEnabled;sequenceWrap;active=new Map;constructor(e={}){this.wrapEnabled=e.wrap,this.sequenceWrap=e.sequenceWrap??!1}autoWrap(){return this.wrapEnabled??this.sequenceWrap}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}setDiagramTitle(e){this.title=e}parseMessage(e){return Ix(e)}parseBoxData(e){let t=function(e){let t=Cx.exec(e);if(t){let r=e.lastIndexOf(")");if(r>=t[0].length)return Ex.test(e.slice(t[0].length))?void 0:[e.slice(0,r+1),e.slice(r+1)]}if(Ex.test(e))return;let r=_x.exec(e)[0];return[r,e.slice(r.length)]}(e),r=t?.[0]?t[0].trim():"transparent",a=t?.[1]?t[1].trim():void 0;if(((i=r).includes("(")?vx(i):(wx??=new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen transparent currentcolor inherit initial unset revert accentcolor accentcolortext activetext buttonborder buttonface buttontext canvas canvastext field fieldtext graytext highlight highlighttext linktext mark marktext selecteditem selecteditemtext visitedtext activeborder activecaption appworkspace background buttonhighlight buttonshadow captiontext inactiveborder inactivecaption inactivecaptiontext infobackground infotext menu menutext scrollbar threeddarkshadow threedface threedhighlight threedlightshadow threedshadow window windowframe windowtext".split(" ")),wx.has(i.toLowerCase())))||(r="transparent",a=e.trim()),void 0===a)return{text:void 0,color:r,wrap:void 0};var i;let{text:l,wrap:n}=Ix(a);return{text:l||void 0,color:r,wrap:n}}addBox(e){this.currentBox={name:e.text,wrap:e.wrap??this.autoWrap(),fill:e.color,actorKeys:[]},this.boxes.push(this.currentBox)}addActor(e,t,r,a,l){let n,s=this.currentBox;if(void 0!==l){let t;try{t=U(l.includes("\n")?l+"\n":"{\n"+l+"\n}")}catch(t){throw new i(`Config of participant "${e}" is not valid YAML. ${t.message}`,"syntax",{type:"sequence"})}null!==t&&"object"==typeof t&&!Array.isArray(t)&&(n=t)}let o=n&&Object.prototype.hasOwnProperty.call(n,"type")?n.type:void 0,h=n&&Object.prototype.hasOwnProperty.call(n,"alias")?n.alias:void 0;null!=o&&(a=String(o)),h&&(!r||r.text===t)&&(r={text:String(h),wrap:r?.wrap,type:a});let c=this.actors.get(e);if(!c||(this.currentBox&&c.box&&this.currentBox!==c.box&&Sx(`A same participant should only be defined in one Box: ${c.name} can't be in '${c.box.name}' and in '${this.currentBox.name}' at the same time.`),s=c.box?c.box:this.currentBox,c.box=s,t!==c.name||null!=r)){if((null==r?.text||null==a)&&(r={text:t,type:a}),this.actors.set(e,{box:s,name:t,description:r.text,wrap:r.wrap??this.autoWrap(),prevActor:this.prevActor,links:new Map,properties:new Map,type:a??"participant"}),this.prevActor){let t=this.actors.get(this.prevActor);t&&(t.nextActor=e)}this.currentBox&&this.currentBox.actorKeys.push(e),this.prevActor=e}}addMessage(e,t,r,a){this.messages.push({id:String(this.messages.length),from:e,to:t,message:r.text,wrap:r.wrap??this.autoWrap(),answer:a})}addSignal(e,t,r,a,i=!1,l){if(18===a){let t=e?this.active.get(e)??0:0;t<1&&Sx(`Trying to inactivate an inactive participant (${e})`),this.active.set(e,t-1)}else 17===a&&e&&this.active.set(e,(this.active.get(e)??0)+1);return this.messages.push({id:String(this.messages.length),from:e,to:t,message:r?.text??"",wrap:r?.wrap??this.autoWrap(),type:a,activate:i,centralConnection:l??0}),!0}addNote(e,t,r){let a=r.wrap??this.autoWrap(),i={actor:e,placement:t,message:r.text,wrap:a},l="string"==typeof e?[e,e]:e;this.notes.push(i),this.messages.push({id:String(this.messages.length),from:l[0],to:l[1],message:r.text,wrap:a,type:2,placement:t})}addLinks(e,t){let r=this.actors.get(e);if(r)try{let e=JSON.parse(t.text);for(let[t,a]of Nx(e))r.links.set(t,a)}catch{return}}addALink(e,t){let r=this.actors.get(e);if(!r)return;let a=t.text.indexOf("@");r.links.set(t.text.slice(0,a-1).trim(),t.text.slice(a+1).trim())}addProperties(e,t){let r=this.actors.get(e);if(r)try{let e=JSON.parse(t.text);for(let[t,a]of Nx(e))r.properties.set(t,a)}catch{return}}addDetails(e,t){let r=this.actors.get(e);r&&(r.details=t.text)}apply(e){let t=[],r=[],a=e;for(;;){void 0!==a&&(Array.isArray(a)?(t.push(a),r.push(0)):"string"!=typeof a&&this.applyOne(a));let e=t.length-1;if(e<0)return;let i=t[e];r[e]<i.length?a=i[r[e]++]:(t.pop(),r.pop(),a=void 0)}}applyOne(e){let t=e.actor;switch(e.type){case"sequenceIndex":this.messages.push({id:String(this.messages.length),from:void 0,to:void 0,message:{start:e.sequenceIndex,step:e.sequenceIndexStep,visible:!0===e.sequenceVisible},wrap:!1,type:e.signalType});break;case"addParticipant":this.addActor(t,t,e.description,e.draw,e.config);break;case"createParticipant":this.actors.has(t)&&Sx("It is not possible to have actors with the same id, even if one is destroyed before the next is created. Use 'AS' aliases to simulate the behavior"),this.lastCreated=t,this.addActor(t,t,e.description,e.draw,e.config),this.createdActors.set(t,this.messages.length);break;case"destroyParticipant":this.lastDestroyed=t,this.destroyedActors.set(t,this.messages.length);break;case"activeStart":case"activeEnd":case"centralConnection":case"centralConnectionReverse":this.addSignal(t,void 0,void 0,e.signalType);break;case"addNote":this.addNote(e.actor,e.placement,e.text);break;case"addLinks":this.addLinks(t,e.text);break;case"addALink":this.addALink(t,e.text);break;case"addProperties":this.addProperties(t,e.text);break;case"addDetails":this.addDetails(t,e.text);break;case"addMessage":this.lastCreated?(e.to!==this.lastCreated&&Sx(`The created participant ${this.lastCreated} does not have an associated creating message after its declaration. Please check the sequence diagram.`),this.lastCreated=void 0):this.lastDestroyed&&(e.to!==this.lastDestroyed&&e.from!==this.lastDestroyed&&Sx(`The destroyed participant ${this.lastDestroyed} does not have an associated destroying message after its declaration. Please check the sequence diagram.`),this.lastDestroyed=void 0),this.addSignal(e.from,e.to,e.msg,e.signalType,e.activate,e.centralConnection);break;case"boxStart":this.addBox(e.boxData);break;case"boxEnd":this.currentBox=void 0;break;case"loopStart":this.addSignal(void 0,void 0,e.loopText,e.signalType);break;case"rectStart":this.addSignal(void 0,void 0,e.color,e.signalType);break;case"optStart":this.addSignal(void 0,void 0,e.optText,e.signalType);break;case"altStart":case"else":this.addSignal(void 0,void 0,e.altText,e.signalType);break;case"parStart":case"and":this.addSignal(void 0,void 0,e.parText,e.signalType);break;case"criticalStart":this.addSignal(void 0,void 0,e.criticalText,e.signalType);break;case"option":this.addSignal(void 0,void 0,e.optionText,e.signalType);break;case"breakStart":this.addSignal(void 0,void 0,e.breakText,e.signalType);break;case"loopEnd":case"rectEnd":case"optEnd":case"altEnd":case"parEnd":case"criticalEnd":case"breakEnd":this.addSignal(void 0,void 0,void 0,e.signalType)}}},Rx=["$end","INVALID","INVALID","NEWLINE","SD","create","box","restOfLine","end","autonumber","NUM","off","activate","deactivate","title","legacy_title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","loop","rect","opt","alt","par","par_over","critical","break","option","and","else","participant","AS","participant_actor","destroy","note","over","links","link","properties","details",",","left_of","right_of","+","-","()","ACTOR","CONFIG_START","CONFIG_CONTENT","CONFIG_END","TXT","SOLID_OPEN_ARROW","DOTTED_OPEN_ARROW","SOLID_ARROW","BIDIRECTIONAL_SOLID_ARROW","DOTTED_ARROW","BIDIRECTIONAL_DOTTED_ARROW","SOLID_CROSS","DOTTED_CROSS","SOLID_POINT","DOTTED_POINT","SOLID_ARROW_TOP","SOLID_ARROW_BOTTOM","STICK_ARROW_TOP","STICK_ARROW_BOTTOM","SOLID_ARROW_TOP_DOTTED","SOLID_ARROW_BOTTOM_DOTTED","STICK_ARROW_TOP_DOTTED","STICK_ARROW_BOTTOM_DOTTED","SOLID_ARROW_TOP_REVERSE","SOLID_ARROW_BOTTOM_REVERSE","STICK_ARROW_TOP_REVERSE","STICK_ARROW_BOTTOM_REVERSE","SOLID_ARROW_TOP_REVERSE_DOTTED","SOLID_ARROW_BOTTOM_REVERSE_DOTTED","STICK_ARROW_TOP_REVERSE_DOTTED","STICK_ARROW_BOTTOM_REVERSE_DOTTED"],Lx=new Uint8Array(128);for(let e=0;e<128;e++){let t=String.fromCharCode(e),r=32===e||e>=9&&e<=13,a=0;"/\\+()<->:\n,;".includes(t)||(a|=1),"+<->:\n,;".includes(t)||(a|=2),"<>:\n,;@".includes(t)||(a|=8|(r?0:4)),"#\n;".includes(t)||(a|=16),!"/\\+()<>:\n,;-".includes(t)&&!r&&(a|=32),Lx[e]=a}function Ox(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=-1,h=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},c=(e,t,l,n)=>{r.push(e),a.push(n),i.push(t),s=l},d=e=>{l.push(n),n=e},f=()=>{l.length>0&&(n=l.pop())},u=r=>(o<r&&(o=e.indexOf("\n",r),-1===o&&(o=t)),o),p=(t,r)=>{let a=e.charCodeAt(t);return a<128?0!==(Lx[a]&r):4!==r&&32!==r||!q(a)},g=(t,r)=>{for(let a=0;a<r.length;a++){let i=r.charCodeAt(a),l=e.charCodeAt(t+a);if(i>=97&&i<=122?(32|l)!==i:l!==i)return!1}return!0},m=t=>g(s,t)&&!Q(e.charCodeAt(s+t.length)),y=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},x=()=>{let r=s;for(;r<t;){let t=e.charCodeAt(r);if(10===t||!q(t))break;r++}return r!==s&&(s=r,!0)},w=e=>{for(;e<t&&p(e,16);)e++;return e},$=(e,t,r)=>{h(e,s,s+t),d(r)},b=(e,t,r=-1)=>!!m(e)&&(h(t,s,s+e.length),r>=0&&d(r),!0),M=(r,a)=>{if(!g(s,r))return!1;let i=s+r.length,l=e.charCodeAt(i);if(32!==l&&9!==l)return!1;for(;32===l||9===l;)l=e.charCodeAt(++i);return!(i>=t||!p(i,32))&&(h(a,s,s+r.length),!0)},v=t=>{let r=e.charCodeAt(t),a=e.charCodeAt(t+1);if(45===r){if(120===a||88===a||41===a||92===a||47===a||45===a)return!0;let r=e.charCodeAt(t+2);return 124===a&&(92===r||47===r)}return 47===r||92===r?(124===a||a===r)&&45===e.charCodeAt(t+2):40===r&&41===a},k=r=>{switch(32|r){case 97:return b("actor",34,1)||b("alt",24,3)||b("and",30,3)||b("activate",12,1)||(()=>{let t=g(s,"accdescr");if(!t&&!g(s,"acctitle"))return!1;let r=y(s+8),a=e.charCodeAt(r);return 58===a?(h(t?18:16,s,y(r+1)),d(t?6:5),!0):!(!t||123!==a||(s=y(r+1),d(7),0))})()||b("autonumber",9);case 98:return b("box",6,3)||b("break",28,3);case 99:return b("create",5)||b("critical",27,3);case 100:return b("destroy",35,1)||M("details",41)||b("deactivate",13,1);case 101:return b("else",31,3)||b("end",8);case 108:return b("loop",21,3)||b("left of",43)||M("links",38)||M("link",39);case 110:return b("note",36);case 111:return b("opt",23,3)||b("option",29,3)||b("over",37)||b("off",11);case 112:return b("participant",32,1)||b("par",25,3)||b("par_over",26,3)||M("properties",40);case 114:return b("rect",22,3)||b("right of",44);case 115:return b("sequencediagram",4);case 116:return(()=>{if(!g(s,"title"))return!1;let r=s+5,a=58===e.charCodeAt(r);a&&r++;let i=r;for(;i<t&&10!==e.charCodeAt(i)&&q(e.charCodeAt(i));)i++;if(i===t||10===e.charCodeAt(i))return s=i,!0;let l=e.charCodeAt(r);return!(!q(l)||13===l||!p(r+1,16)||(h(a?15:14,s,w(r+1)),0))})();default:return!1}},A=()=>{let r=e.charCodeAt(s);if(10===r){let t=s+1;for(;10===e.charCodeAt(t);)t++;return void h(3,s,t)}if(q(r))s=y(s+1);else if(35===r||37===r&&123!==e.charCodeAt(s+1))s=u(s);else if(!((X(r)||46===r)&&(()=>{let t=s;for(;X(e.charCodeAt(t));)t++;let r=t>s;if(46===e.charCodeAt(t)&&X(e.charCodeAt(t+1))){let r=X(e.charCodeAt(t+2))?t+3:t+2,a=e.charCodeAt(r);if(32===a||10===a)return h(10,s,r),!0}let a=e.charCodeAt(t);return!(!r||32!==a&&10!==a||(h(10,s,t),0))})()||r<128&&(32|r)>=97&&(32|r)<=122&&k(r)))if(44===r)h(42,s,s+1);else if(59===r)h(3,s,s+1);else if(p(s,1))(()=>{let r=s+1;for(;r<t&&p(r,1);)r++;for(;r<t&&!v(r);){let a=r;for(;45===e.charCodeAt(a);)a++;if(a>=t||!p(a,2))break;for(a++;a<t&&p(a,2);)a++;r=a}c(48,s,r,e.slice(s,r).trim())})();else if(45===r)(()=>{let t=e.charCodeAt(s+1),r=e.charCodeAt(s+2);if(62===t)h(62===r?55:53,s,s+(62===r?3:2));else if(120===t||88===t)h(59,s,s+2);else if(41===t)h(61,s,s+2);else if(124===t&&92===r)h(63,s,s+3);else if(124===t&&47===r)h(64,s,s+3);else if(92===t&&92===r)h(65,s,s+3);else if(47===t&&47===r)h(66,s,s+3);else if(45===t){let t=e.charCodeAt(s+3);62===r?h(62===t?57:54,s,s+(62===t?4:3)):120===r||88===r?h(60,s,s+3):41===r?h(62,s,s+3):124===r&&92===t?h(67,s,s+4):124===r&&47===t?h(68,s,s+4):92===r&&92===t?h(69,s,s+4):47===r&&47===t?h(70,s,s+4):h(46,s,s+1)}else h(46,s,s+1)})();else if(60===r&&e.startsWith("<<->>",s))h(56,s,s+5);else if(60===r&&e.startsWith("<<--\x3e>",s))h(58,s,s+6);else{if((47===r||92===r)&&(t=>{let r=e.charCodeAt(s+1);if(124!==r&&r!==t||45!==e.charCodeAt(s+2))return!1;let a,i=45===e.charCodeAt(s+3),l=47===t;return a=124===r?i?l?75:76:l?71:72:i?l?77:78:l?73:74,h(a,s,s+(i?4:3)),!0})(r))return;58===r?h(52,s,w(s+1)):43===r?h(45,s,s+1):40===r&&41===e.charCodeAt(s+1)?h(47,s,s+2):h(2,s,s+1)}},T=()=>{switch(n){case 0:return A(),!0;case 1:return(()=>{if(x())return!0;let r=e.charCodeAt(s);if(35===r)return s=u(s),!0;if(64===r&&123===e.charCodeAt(s+1))return $(49,2,4),!0;let a=s;for(;a<t&&p(a,4);)a++;if(a>s){let t=y(a);if(64===e.charCodeAt(t)&&123===e.charCodeAt(t+1))return h(48,s,a),!0;if(t>a&&g(t,"as")&&q(e.charCodeAt(t+2)))return h(48,s,a),d(2),!0}let i=a;for(;i<t&&p(i,8);)i++;if(i>s){let r=e.charCodeAt(i),a=i;if(i<t&&10!==r&&59!==r)for(a--;a>s&&35!==e.charCodeAt(a);)a--;if(a>s)return c(48,s,a,e.slice(s,a).trim()),f(),!0}if(60===e.charCodeAt(i))return h(2,s,u(s)),f(),!0;if(10!==r){let t=u(s);return c(2,s,t,e.slice(s,t).trim()),f(),!0}return!1})();case 2:return!!x()||(35===e.charCodeAt(s)?(s=u(s),!0):(f(),f(),m("as")?$(33,2,3):h(3,s,s),!0));case 3:return!!x()||(35===e.charCodeAt(s)?(s=u(s),!0):(h(7,s,w(s)),f(),!0));case 4:if(125!==e.charCodeAt(s)){let r=e.indexOf("}",s);return-1===r&&(r=t),h(50,s,r),!0}{let t=y(s+1),r=t>s+1&&g(t,"as")&&q(e.charCodeAt(t+2));return h(51,s,s+1),f(),r?d(2):f(),!0}case 5:case 6:return h(5===n?17:19,s,u(s)),f(),!0;default:if(125===e.charCodeAt(s))s++,f();else{let r=e.indexOf("}",s);-1===r&&(r=t),h(20,s,r)}return!0}};for(;s<t;)if(!T())return r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i};return 0===n||2===n?h(3,t,t):3===n?h(7,t,t):5===n?h(17,t,t):6===n?h(19,t,t):7===n&&h(20,t,t),r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i}}var Fx=new Int8Array(79).fill(-1);Fx[53]=5,Fx[54]=6,Fx[55]=0,Fx[57]=1,Fx[56]=33,Fx[58]=34,Fx[59]=3,Fx[60]=4,Fx[61]=24,Fx[62]=25,Fx[63]=41,Fx[64]=42,Fx[65]=43,Fx[66]=44,Fx[67]=51,Fx[68]=52,Fx[69]=53,Fx[70]=54,Fx[71]=45,Fx[72]=46,Fx[73]=47,Fx[74]=48,Fx[75]=55,Fx[76]=56,Fx[77]=57,Fx[78]=58;var zx=new Int8Array(79).fill(-1);zx[21]=2,zx[22]=3,zx[23]=4,zx[28]=5,zx[24]=6,zx[25]=7,zx[26]=7,zx[27]=8,zx[6]=1;var Wx=' fill="var(--_s)" stroke="var(--_b)"',Px=' fill="none" stroke="var(--_b)"',Bx=new Set(["participant","actor","boundary","control","entity","database","collections","queue"]),Hx=new Set(["actor","boundary","control","entity","database"]);function Yx(e){return Bx.has(e)?e:"participant"}function Gx(e){return Hx.has(e)}function Ux(e,t,r,a,i=16){if(Gx(e))return{w:Math.max(40,t.width+8),h:34+(t.height>0?4+t.height:0)};let l="collections"===e?5:"queue"===e?12:0;return{w:Math.max(r,t.width+2*i)+l,h:Math.max(a,t.height+20)+("collections"===e?5:0)}}function qx(e,t,r,a,i,l,n=""){let{w:s,h:o}=a,h=' class="pele-label"';if(Gx(e))return function(e,t,r){let a=Oe(t),i=e=>Oe(r+e);switch(e){case"actor":return`<circle cx="${a}" cy="${i(7)}" r="6"${Wx}/><path d="M${a},${i(13)}V${i(24)}M${Oe(t-10)},${i(17)}H${Oe(t+10)}M${Oe(t-8)},${i(34)}L${a},${i(24)}L${Oe(t+8)},${i(34)}"${Px}/>`;case"boundary":return`<path d="M${Oe(t-19)},${i(6)}V${i(28)}M${Oe(t-19)},${i(17)}H${Oe(t-8)}"${Px}/><circle cx="${Oe(t+3)}" cy="${i(17)}" r="11"${Wx}/>`;case"control":return`<circle cx="${a}" cy="${i(21)}" r="11"${Wx}/><path d="M${Oe(t+5)},${i(5)}L${Oe(t-1)},${i(10)}L${Oe(t+5)},${i(15)}"${Px}/>`;case"entity":return`<circle cx="${a}" cy="${i(15)}" r="11"${Wx}/><path d="M${Oe(t-11)},${i(30)}H${Oe(t+11)}"${Px}/>`;default:{let e=Oe(t-14),r=Oe(t+14);return`<path d="M${e},${i(7)}V${i(27)}A14,5 0 0 0 ${r},${i(27)}V${i(7)}A14,5 0 0 0 ${e},${i(7)}Z"${Wx}/><path d="M${e},${i(7)}A14,5 0 0 0 ${r},${i(7)}"${Px}/>`}}}(e,t,r)+Fe(i,t,r+34+4+i.height/2,h+n,l);let c=t-s/2;if("collections"===e){let e=s-5,t=o-5;return`<rect x="${Oe(c+5)}" y="${Oe(r)}" width="${Oe(e)}" height="${Oe(t)}"${Wx}${Mi}/>`+`<rect x="${Oe(c)}" y="${Oe(r+5)}" width="${Oe(e)}" height="${Oe(t)}"${Wx}${Mi}/>`+Fe(i,c+e/2,r+5+t/2,h,l)}if("queue"===e){let e=Oe(c+6),a=Oe(c+s-6),n=Oe(r+o),d=Oe(o/2);return`<path d="M${e},${Oe(r)}H${a}A6,${d} 0 0 1 ${a},${n}H${e}A6,${d} 0 0 1 ${e},${Oe(r)}Z"${Wx}/><path d="M${a},${Oe(r)}A6,${d} 0 0 0 ${a},${n}"${Px}/>`+Fe(i,t-3,r+o/2,h,l)}return`<rect x="${Oe(c)}" y="${Oe(r)}" width="${Oe(s)}" height="${Oe(o)}"${Wx}${Mi}/>`+Fe(i,t,r+o/2,h,l)}var jx=[];function Vx(e,t,r,a=1,i=!1){jx[e]={dotted:t,head:r,atStart:1!==a,atEnd:0!==a,bottom:i}}Vx(0,!1,1),Vx(1,!0,1),Vx(3,!1,2),Vx(4,!0,2),Vx(5,!1,0),Vx(6,!0,0),Vx(24,!1,3),Vx(25,!0,3),Vx(33,!1,1,2),Vx(34,!0,1,2);for(let e of[!1,!0]){let t=e?10:0;Vx(41+t,e,4),Vx(42+t,e,4,1,!0),Vx(43+t,e,5),Vx(44+t,e,5,1,!0),Vx(45+t,e,4,0),Vx(46+t,e,4,0,!0),Vx(47+t,e,5,0),Vx(48+t,e,5,0,!0)}var Xx=new Map([[10,"loop"],[12,"alt"],[15,"opt"],[19,"par"],[32,"par"],[27,"critical"],[30,"break"],[22,"rect"]]),Kx=10,Zx=10,Qx=' stroke-dasharray="4 4"';function Jx(e){return void 0!==e&&void 0!==jx[e]}var ew={lines:[],widths:[],width:0,height:0,size:0,lineHeight:0};function tw(e,t,r){let a=e[t];return"number"==typeof a&&a>=0&&a<=2e3?a:r}function rw(e,t,r,a,i,l){let n=Oe(e-8*r);return i?`<path class="pele-marker" d="M${Oe(e)},${Oe(t)}L${n},${Oe(t+5*a)}"/>`:`<path class="pele-marker" d="M${Oe(e)},${Oe(t)}L${n},${Oe(t+4.5*a)}V${Oe(t)}Z" fill="${l}" stroke="none"/>`}function aw(e,t,r,a,i,l){switch(e){case 1:return li("arrow_point",t,r,a,0,l);case 2:return li("arrow_cross",t,r,a,0,l);case 3:return`<path class="pele-marker" d="M${Oe(t-8*a)},${Oe(r-4.5)}L${Oe(t)},${Oe(r)}L${Oe(t-8*a)},${Oe(r+4.5)}" stroke-linejoin="round"/>`;case 4:return rw(t,r,a,i,!1,l);case 5:return rw(t,r,a,i,!0,l);default:return""}}function iw(e){return 1===e?7:2===e?4:0}function lw(e,t,r,a,i=0,l=!0){let n,s=t.sequence??{},o=r.fontSize??16,h=Math.round(.875*o),c=Math.round(.75*o),d=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),f=Array.isArray(r.monospace)&&r.monospace.includes("messages"),u=f?{width:(e,t,r)=>d.width(e,t,4|r)}:d,p=r.icons,g=r.padding??8,m=!1!==s.mirrorActors,y=!0===s.rightAngles,x=Math.min(tw(s,"actorMargin",40),a?8:1/0),w=Math.min(tw(s,"width",64),a?48:1/0),$=tw(s,"height",Math.round(1.5*o)+20),b=Math.min(tw(s,"width",160),a?Math.max(32,((r.maxWidth??320)-2*g)/Math.max(1,e.actors.size)-x-24):1/0),M=Math.max(4,14+tw(s,"messageMargin",35)-35),v=Math.min(tw(s,"noteMargin",10),a?6:1/0),k=Math.min(tw(s,"boxMargin",10),a?6:1/0),A="left"===s.messageAlign?-1:"right"===s.messageAlign?1:0,T=a?6:12,C=a?8:16,E=a?12:20,_=a?6:10,S=e.messages,I=S.length,N=function(e,t){let r=new Array(e.length),a=new Array(e.length),i=1,l=1,n=!1;for(let s=0;s<e.length;s++){let o=e[s];if(r[s]=NaN,a[s]=!1,26===o.type){let e=o.message;i=e.start||i,l=e.step||l,n=e.visible}else Jx(o.type)&&(r[s]=i,a[s]=n||t,i=Math.round(100*(i+l))/100)}return{index:r,shown:a,visible:n}}(S,!0===s.showSequenceNumbers),D=(e,t,r,i=b,l=d)=>{let n=Fl(e,!1,l,t,a||r?i:1/0);return a?bo(n,l,Math.max(120,i)):n},R=(e,t,r=b)=>D(e,h,t,r,u);if(!0===s.hideUnusedParticipants){n=new Set;for(let e of S)n.add(e.from).add(e.to)}let L=new Int32Array(I+1);L[I]=-1;for(let e=I-1;e>=0;e--)L[e]=Jx(S[e].type)?e:L[e+1];let O=[],F=new Map;for(let[t,r]of e.actors){if(n&&!n.has(t))continue;let i=Yx(r.type),l=D(r.description,o,r.wrap),s=e.createdActors.get(t),h=e.destroyedActors.get(t),c=void 0===s?-1:L[Math.min(s,I)];c>=0&&S[c].to!==t&&(c=-1);let d=void 0===h?-1:L[Math.min(h,I)];d>=0&&S[d].to!==t&&S[d].from!==t&&(d=-1),F.set(t,O.length),O.push({id:t,actor:r,kind:i,label:l,size:Ux(i,l,w,$,a?8:void 0),x:0,createAt:c,destroyAt:d,top:0,lifeStart:0,lifeEnd:-1,activations:[]})}let z=O.length-1,W=new Map,P=(e,t,r)=>{if(e<0||t>z)return;let a=e*O.length+t;(W.get(a)??0)<r&&W.set(a,r)},B=e=>N.shown[e]?Math.max(16,d.width(String(N.index[e]),c,0)+8):0,H=new Array(I),Y=new Array(I),G=(e,t)=>{let r=Y[e];if(!r){if(t===b)return H[e].label;Y[e]=r=new Map([[b,H[e].label]])}let a=r.get(t);return a||r.set(t,a=R(S[e].message,!0,t)),a};for(let e=0;e<I;e++){let t=S[e],r=void 0===t.from?void 0:F.get(t.from),i=void 0===t.to?void 0:F.get(t.to);if(void 0!==r&&void 0!==i&&"string"==typeof t.message)if(2===t.type){let a=D(t.message,h,t.wrap),l=a.width+2*v;0===t.placement?P(r-1,r,l+20+Kx):1===t.placement?P(r,r+1,l+20+Kx):r===i?(P(r-1,r,l/2+Zx),P(r,r+1,l/2+Zx)):P(Math.min(r,i),Math.max(r,i),l-2*C),H[e]={kind:2,a:r,b:i,label:a,x:0,w:l}}else if(Jx(t.type)){let l=R(t.message,t.wrap),n=B(e);if(r===i)P(r,r+1,36+l.width+16+Kx+n),H[e]={kind:1,a:r,b:i,label:l,x:0,w:0};else{let s=O[i].createAt===e?O[i].size.w/2:0,o=t.centralConnection?16:0;P(Math.min(r,i),Math.max(r,i),(a?Math.min(l.width,Math.max(16,b-16)):l.width)+2*T+Kx+n+s+o),H[e]={kind:0,a:r,b:i,label:l,x:0,w:0}}}}let U=[];for(let e=0;e<=z;e++){let t=O[e].actor.box,r=U[U.length-1];t&&r&&r.box===t&&r.last===e-1?r.last=e:t&&U.push({box:t,first:e,last:e,title:D(t.name,h,t.wrap),grow:0})}let q=new Array(Math.max(z,0));for(let e=0;e<z;e++){let t=O[e],r=O[e+1],a=t.actor.box!==r.actor.box?(t.actor.box?k:0)+(r.actor.box?k:0):0;q[e]=Math.max(t.size.w/2+r.size.w/2+x+a,W.get(e*O.length+e+1)??0)}let j=[];for(let[e,t]of W){let r=Math.floor(e/O.length),a=e%O.length;a-r>1&&j.push([r,a,t])}j.sort((e,t)=>e[1]-e[0]-(t[1]-t[0])||e[0]-t[0]);for(let[e,t,r]of j){let a=0;for(let r=e;r<t;r++)a+=q[r];if(a>=r)continue;let i=(r-a)/(t-e);for(let r=e;r<t;r++)q[r]+=i}let V=()=>{for(let e=1;e<=z;e++)O[e].x=O[e-1].x+q[e-1]};V();for(let e of U){let t=O[e.last].x+O[e.last].size.w/2-(O[e.first].x-O[e.first].size.w/2);e.grow=Math.max(0,(e.title.width-t)/2),0!==e.grow&&(e.first>0&&(q[e.first-1]+=e.grow),e.last<z&&(q[e.last]+=e.grow))}let X=1/0,K=-1/0,Z=(e,t)=>{e<X&&(X=e),t>K&&(K=t)},Q=e=>[O[e.first].x-O[e.first].size.w/2-k-e.grow,O[e.last].x+O[e.last].size.w/2+k+e.grow],J=new Array(I),ee=()=>{V(),X=1/0,K=-1/0;for(let e of O)Z(e.x-e.size.w/2,e.x+e.size.w/2);for(let e of U)Z(...Q(e));let e=[],t=()=>z<0?[0,120]:[O[0].x-E,O[z].x+E];for(let r=0;r<I;r++){let i=S[r],l=i.type,n=void 0===l?void 0:Xx.get(l),s=H[r];if(void 0!==n){let t={kind:n,x0:1/0,x1:-1/0,top:0,title:ew,tabW:0,fill:"rect"===n&&"string"==typeof i.message?i.message:"",dividers:[r],dividerY:[],dividerLabels:[]};J[r]=t,e.push(t)}else if(13===l||20===l||28===l)e[e.length-1]?.dividers.push(r);else if(11===l||14===l||16===l||21===l||29===l||31===l||23===l){let i=e.pop();if(!i)continue;if(J[r]=i,i.x0>i.x1&&([i.x0,i.x1]=t()),"rect"!==i.kind){i.tabW=d.width(i.kind,c,1)+14;for(let e=0;e<i.dividers.length;e++){let t=S[i.dividers[e]].message,r=0===e?i.tabW+8:0,l=i.x1-i.x0-16-r,n=t?D(`[${t}]`,h,!0,Math.max(l,a?Math.min(240,b):240)):ew;n.width>l&&(i.x1+=n.width-l),0===e?i.title=n:i.dividerLabels.push(n)}}Z(i.x0,i.x1);let l=e[e.length-1];l&&(l.x0=Math.min(l.x0,i.x0-_),l.x1=Math.max(l.x1,i.x1+_))}else if(s){let t,l,n=O[s.a],o=O[s.b];if(2===s.kind){if(0===i.placement)s.x=n.x-Zx-s.w;else if(1===i.placement)s.x=n.x+Zx;else if(s.a===s.b)s.x=n.x-s.w/2;else{let e=Math.min(n.x,o.x)-C,t=Math.max(n.x,o.x)+C;(a||i.wrap)&&(s.label=D(i.message,h,!0,Math.max(b,t-e-2*v))),s.w=Math.max(t-e,s.label.width+2*v),s.x=(e+t-s.w)/2}t=s.x,l=s.x+s.w}else 1===s.kind?(t=n.x,l=n.x+Kx+28+8+s.label.width+B(r)):(t=Math.min(n.x,o.x),l=Math.max(n.x,o.x),(a||i.wrap)&&(s.label=G(r,Math.max(b,l-t-2*T-Kx))),o.createAt===r&&(o.x>n.x?l+=o.size.w/2:t-=o.size.w/2));Z(t,l);let c=e[e.length-1];c&&(c.x0=Math.min(c.x0,t-E),c.x1=Math.max(c.x1,l+E))}}};ee();let te=!1,re=!1;if(a&&void 0!==r.maxWidth){let e=Math.floor(r.maxWidth)-Math.ceil(K-X+2*g)-i,t=new Int32Array(O.length),a=new Array(q.length).fill(0),n=[],s=0;for(let r=0;e>0&&r<H.length;r++){let e=H[r];if(0!==e?.kind)continue;let i=R(S[r].message,!1,1/0);if(e.label.lines.length<=i.lines.length)continue;n.push(r),s+=e.label.lines.length;let l=Math.min(e.a,e.b),o=Math.max(e.a,e.b);t[l]++,t[o]--;let h=(i.width-(O[o].x-O[l].x-2*T-Kx))/(o-l);for(let e=l;e<o;e++)a[e]=Math.max(a[e],h)}let o=0,h=0;for(let e=0;e<q.length;e++)o+=t[e],t[e]=o>0?1:0,h+=t[e];if(h>0){let r=q.slice(),i=e=>{for(let t=0;t<q.length;t++)q[t]=r[t]+e(t);return ee(),n.map(e=>H[e].label.lines.length)},o=e=>e.reduce((e,t)=>e+t,0),c=r=>t[r]*e/h,d=i(c),f=o(a),u=t=>a[t]*(e-.01)/f;if(l&&h>1&&f>0&&q.some((e,t)=>u(t)>c(t))){let e=d;d=i(u),re=o(d)<o(e)&&d.every((t,r)=>t<=e[r]),re||(d=i(c))}te=o(d)<s,te||(q.splice(0,q.length,...r),ee())}}let ae=0;for(let e of U)ae=Math.max(ae,e.title.height);let ie=U.length>0?k+(ae>0?ae+4:0):0,le=0;for(let e of O)e.createAt<0&&(le=Math.max(le,e.size.h));let ne=ie+le;for(let e of O)e.top=ne-e.size.h,e.lifeStart=ne;let se=O.map(e=>e.x),oe=[],he=new Map,ce=e=>{if(e)return he.has(e)||he.set(e,mt(Ri([`fill:${e}`]).shape)),he.get(e)},de=e=>{let t=ce(e);return t?` fill="${t}"`:""},fe=(e,t)=>{for(let e=oe.length-1;e>=0;e--)if("rect"===oe[e].kind)return oe[e].fill;for(let r of U){let[a,i]=Q(r);if(e>=a&&t<=i)return r.box.fill}},ue=(e,t)=>de(fe(e,t)),pe=(e,t,r,a=!1)=>{if(0===e.width)return"";let i=t-e.width/2,l=((e,t)=>{let r=0,a=se.length;for(;r<a;){let t=r+a>>1;se[t]<=e?r=t+1:a=t}return r<se.length&&se[r]<t})(i,i+e.width),n=l?`<rect x="${Oe(i-3)}" y="${Oe(r-e.height/2+2)}" width="${Oe(e.width+6)}" height="${Oe(e.height-4)}" rx="3" fill="var(--_bg)" stroke="none"/>`:"",s=l?"":ue(i,i+e.width);return n+Fe(e,t,r,a?` class="pele-frame-label"${s||' fill="var(--_m)"'} stroke="none"`:s,p)},ge=(e,t=0)=>e.activations.length+t>0?e.x-5:e.x,me=(e,t=0)=>{let r=e.activations.length+t;return r>0?e.x+5+4*(r-1):e.x},ye=[],xe=[],we="",$e="",be="",Me="",ve="",ke="",Ae=(e,t)=>{let r=e.activations.pop(),a=Math.max(t,r+14),i=e.x-5+4*e.activations.length;return Z(i,i+Kx),xe.push(`<rect class="pele-activation" data-id="${Re(e.id)}" x="${Oe(i)}" y="${Oe(r)}" width="10" height="${Oe(a-r)}" rx="2"/>`),a},Te=(e,t)=>{let r=e.x,a=t+16;return e.lifeEnd=a,ke+=`<path class="pele-destroy" data-id="${Re(e.id)}" d="M${Oe(r-6)},${Oe(a-6)}L${Oe(r+6)},${Oe(a+6)}M${Oe(r+6)},${Oe(a-6)}L${Oe(r-6)},${Oe(a+6)}"/>`,a+6},Ee=(e,t,r)=>{let a=e.actor.properties.get("class");return`<g class="pele-node pele-actor pele-actor-${e.kind}${r?" pele-actor-footer":""}${"string"==typeof a?Oi(a):""}" data-id="${Re(e.id)}">`+qx(e.kind,e.x,t,e.size,e.label,p,Gx(e.kind)?de(e.actor.box?.fill):"")+"</g>"},_e=(e,t,r,a)=>`<g class="pele-sequence-number"><rect x="${Oe(t-a/2)}" y="${Oe(r-8)}" width="${Oe(a)}" height="16" rx="8" fill="var(--_l)" stroke="none"/><text x="${Oe(t)}" y="${Oe(r+.35*c)}" text-anchor="middle" font-size="${c}" fill="var(--_bg)" stroke="none">${De(String(N.index[e]))}</text></g>`,Se=ne+6;for(let e=0;e<I;e++){let t=S[e],r=t.type,a=H[e],i=J[e];if(17===r){let e=void 0===t.from?void 0:F.get(t.from);void 0!==e&&O[e].activations.push(Se)}else if(18===r){let e=void 0===t.from?void 0:F.get(t.from);void 0!==e&&O[e].activations.length>0&&(Se=Math.max(Se,Ae(O[e],Se)))}else if(i&&i.dividers[0]===e)oe.push(i),"rect"===i.kind?(i.top=Se+8,Se=i.top):(i.top=Se+12,Se=i.top+Math.max(20,i.title.height+2));else if(i){oe.pop();let e=Se+12,t=Oe(i.x0),r=Oe(i.x1-i.x0);if("rect"===i.kind){let a=i.fill?Ri([`fill:${i.fill}`]).shape:"";ye.push(`<rect class="pele-rect" x="${t}" y="${Oe(i.top)}" width="${r}" height="${Oe(e-i.top)}"${Ai((a?"":' fill-opacity="0.5"')+a)}/>`)}else{let a=`<rect x="${t}" y="${Oe(i.top)}" width="${r}" height="${Oe(e-i.top)}" fill="none"${Mi}/>`;for(let e=0;e<i.dividerY.length;e++){let r=i.dividerY[e],l=i.dividerLabels[e];a+=`<path d="M${t},${Oe(r)}H${Oe(i.x1)}"${Qx}/>`+pe(l,i.x0+8+l.width/2,r+2+l.height/2,!0)}a+=`<rect x="${t}" y="${Oe(i.top)}" width="${Oe(i.tabW)}" height="20" fill="var(--_s)"${Mi}/><text class="pele-frame-kind" x="${Oe(i.x0+i.tabW/2)}" y="${Oe(i.top+10+.35*c)}" text-anchor="middle" font-size="${c}" font-weight="var(--_hw)" fill="var(--_m)" stroke="none">${i.kind}</text>`+pe(i.title,i.x0+i.tabW+8+i.title.width/2,i.top+Math.max(20,i.title.height)/2,!0),we+=`<g class="pele-frame pele-frame-${i.kind}">${a}</g>`}Se=e}else if(13===r||20===r||28===r){let e=oe[oe.length-1];if(e){let t=e.dividerLabels[e.dividerY.length];e.dividerY.push(Se+12),Se+=12+(t.height>0?t.height:0)}}else if(a&&2===a.kind){let e=O[a.a],r=a.label.height+2*Math.max(4,v-4),i=Se+10,l=a.x;1===t.placement?l+=me(e)-e.x:0===t.placement&&(l+=ge(e)-e.x),Z(l,l+a.w),Me+=`<g class="pele-note" data-id="i${Re(t.id)}"><rect x="${Oe(l)}" y="${Oe(i)}" width="${Oe(a.w)}" height="${Oe(r)}"${Mi}/>`+Fe(a.label,l+a.w/2,i+r/2,' class="pele-label" stroke="none" fill="var(--_fg)"',p)+"</g>",Se=i+r}else if(a){let i=jx[r],l=O[a.a],n=O[a.b],s=a.label,o=B(e),h=0;for(let r=e+1;r<I;r++){let e=S[r].type;if(17===e)S[r].from===t.to&&h++;else if(18!==e&&59!==e&&60!==e)break}let c,d,f=i.bottom?1:-1,u=i.dotted?Qx:"",g=t.centralConnection,m=59===g||61===g,x=60===g||61===g,w="var(--_l)",$=(e,t)=>`<circle class="pele-central" cx="${Oe(e)}" cy="${Oe(t)}" r="4" fill="${w}" stroke="none"/>`,b=i.atStart&&!i.atEnd,v=iw(i.head),k="";if(1===a.kind){let r=Se+M+Math.max(0,(s.height-22)/2),a=r+22,n=x?l.x+4:me(l),g=m?l.x+4:me(l,h),A=Math.max(n,g)+28+o/2;c=ce(fe(l.x,A)),w=c??w,x&&(k+=$(l.x,r)),m&&(k+=$(l.x,a)),o>0&&(k+=_e(e,b?g:n,b?a:r,o),b?g+=o/2:n+=o/2);let T=(i.atStart?aw(i.head,n,r,-1,f,w):"")+(i.atEnd?aw(i.head,g,a,-1,-f,w):""),C=Oe(n+(i.atStart?v:0)),E=Oe(g+(i.atEnd?v:0));k=`<path d="${y?`M${C},${Oe(r)}H${Oe(A)}V${Oe(a)}H${E}`:`M${C},${Oe(r)}H${Oe(A-6)}A6,6 0 0 1 ${Oe(A)},${Oe(r+6)}V${Oe(a-6)}A6,6 0 0 1 ${Oe(A-6)},${Oe(a)}H${E}`}"${u}/>`+T+k,Z(l.x,A+8+s.width),s.width>0&&(be+=`<g class="pele-edge-label" data-id="i${Re(t.id)}">${Fe(s,A+8+s.width/2,(r+a)/2,ue(A+8,A+8+s.width),p)}</g>`),d=Math.max(a,(r+a)/2+s.height/2)}else{let r=n.x>l.x?1:-1,a=n.createAt===e;c=ce(fe(Math.min(l.x,n.x),Math.max(l.x,n.x))),w=c??w,d=Se+M+Math.max(s.height>0?s.height+2:6,a?n.size.h/2-M+6:0);let p=r>0?me(l):ge(l),g=r>0?ge(n,h):me(n,h);if(a&&(n.top=d-n.size.h/2,n.lifeStart=n.top+n.size.h,g=n.x-r*(Gx(n.kind)?18:n.size.w/2+1)),x&&(k+=$(l.x,d),p=l.x+4*r),m&&(k+=$(n.x,d),g=n.x-4*r),o>0)if(b){let t=m?g-r*(o/2+2):g;k+=_e(e,t,d,o),g=t-r*o/2}else{let t=x?p+r*(o/2+2):p;k+=_e(e,t,d,o),p=t+r*o/2}let y=(i.atStart?aw(i.head,p,d,-r,f*r,w):"")+(i.atEnd?aw(i.head,g,d,r,f*r,w):""),C=p+(i.atStart?r*v:0),E=g-(i.atEnd?r*v:0);if(k=`<path d="M${Oe(C)},${Oe(d)}H${Oe(E)}"${u}/>`+y+k,s.width>0){let e=Math.min(p,g),r=Math.max(p,g),a=A<0?e+T+s.width/2:A>0?r-T-s.width/2:(e+r)/2;Z(a-s.width/2,a+s.width/2),be+=`<g class="pele-edge-label" data-id="i${Re(t.id)}">${pe(s,a,d-4-s.height/2)}</g>`}a&&(Se=d+n.size.h/2-6)}$e+=`<g class="pele-edge pele-message" data-id="i${Re(t.id)}"${c?` stroke="${c}"`:""}>${k}</g>`,Se=Math.max(Se,d),l.destroyAt===e&&(Se=Math.max(Se,Te(l,d))),n.destroyAt===e&&n!==l&&(Se=Math.max(Se,Te(n,d)))}}Se+=20;for(let e of O)for(;e.activations.length>0;)Ae(e,Se);let Ie=Se;if(m){let e=0;for(let t of O)t.lifeEnd>=0||(e=Math.max(e,t.size.h),ve+=Ee(t,Se,!0));Ie=Se+e}let Ne="";for(let e of O){ve+=Ee(e,e.top,!1);let t=e.lifeEnd>=0?e.lifeEnd:Se;t>e.lifeStart&&(Ne+=`<path class="pele-lifeline" data-id="${Re(e.id)}" d="M${Oe(e.x)},${Oe(e.lifeStart)}V${Oe(t)}"/>`)}let Le="";for(let e of U){let[t,r]=Q(e),a="transparent"===e.box.fill?"":Ri([`fill:${e.box.fill}`]).shape;Le+=`<g class="pele-cluster pele-box"${e.box.name?` data-id="${Re(e.box.name)}"`:""}><rect x="${Oe(t)}" y="0" width="${Oe(r-t)}" height="${Oe(Ie+k)}" fill="var(--_a)" stroke="var(--_b)"${Ai((a?"":' fill-opacity="0.5"')+a)}/>`+Fe(e.title,(t+r)/2,k/2+2+e.title.height/2,` class="pele-cluster-label"${de(e.box.fill)||' fill="var(--_m)"'}`,p)+"</g>"}U.length>0&&(Ie+=k);let ze=0,We="",Pe=Gl(r),Be=gs(e.title,d,o,a?Pe:1/0),He=a?bo(Be,d,Math.max(120,Pe)):Be;if(X>K&&Z(0,Math.max(He.width,40)),He.width>0){let e=(X+K)/2;Z(e-He.width/2,e+He.width/2),ze=-He.height-12,We=Fe(He,e,ze+He.height/2,' class="pele-title" font-weight="var(--_tw)"',p)}let Ye=Math.ceil(K-X+2*g);if(te&&Ye>r.maxWidth)return lw(e,t,r,a,re?i:i>0?1/0:Ye-Math.floor(r.maxWidth),!1);let Ge=Math.ceil(Ie-ze+2*g);return{svg:Bi("sequence",Ye,Ge,o,r,e,`<g transform="translate(${Oe(g-X)},${Oe(g-ze)})">`+We+(Le?`<g class="pele-boxes" font-size="${h}">${Le}</g>`:"")+(ye.length>0?`<g class="pele-rects" fill="var(--_a)">${ye.reverse().join("")}</g>`:"")+(Ne?`<g class="pele-lifelines" fill="none" stroke="var(--_b)">${Ne}</g>`:"")+(xe.length>0?`<g class="pele-activations" fill="var(--_s)" stroke="var(--_b)">${xe.reverse().join("")}</g>`:"")+(we?`<g class="pele-frames" font-size="${h}" stroke="var(--_b)">${we}</g>`:"")+($e?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${$e}</g>`:"")+(ke?`<g class="pele-destroys" fill="none" stroke="var(--_l)" stroke-width="1.5" stroke-linecap="round">${ke}</g>`:"")+(be?`<g class="pele-edge-labels" font-size="${h}"${f?` font-family="${bi}"`:""}>${be}</g>`:"")+(Me?`<g class="pele-notes" font-size="${h}" fill="var(--_a)" stroke="var(--_b)">${Me}</g>`:"")+(ve?`<g class="pele-nodes">${ve}</g>`:"")+"</g>"),width:Ye,height:Ge,links:[]}}var nw={type:"sequence",math:!0,parse(e,t,r){let a=t.sequence??{},i=new Dx({wrap:"boolean"==typeof t.wrap?t.wrap:void 0,sequenceWrap:!0===a.wrap});return r&&i.setDiagramTitle(r),function(e,t){let{types:r,texts:a,starts:i}=Ox(e),l=0,n=t=>{let a=r[l];throw 1===a?c("sequence",e,i[l],"",!0):c("sequence",e,i[l],`Expecting ${t}, got '${Rx[a]}'`)},s=e=>(r[l]!==e&&n(`'${Rx[e]}'`),a[l++]),o=()=>{let e=r[l];return 48!==e&&39!==e&&n("'ACTOR'"),{type:"addParticipant",actor:a[l++]}},h=()=>t.parseMessage(s(52).trim().substring(1)),d=()=>{let e=r[l++];if(35===e){let e=o();return s(3),e.type="destroyParticipant",e}let a=o();if(49===r[l]&&48===r[l-1]){l++;let e=s(50);s(51),a.config=e.trim()}if(a.draw=32===e?"participant":"actor",33===r[l]){l++;let e=s(7);s(3),a.description=t.parseMessage(e)}else 3===r[l]?l++:n("'AS', 'NEWLINE'");return a},f=e=>{let t=!1;47===r[l]&&(t=!0,l++);let a=Fx[r[l]];a<0&&n("'SOLID_OPEN_ARROW', 'DOTTED_OPEN_ARROW', 'SOLID_ARROW', 'DOTTED_ARROW', 'SOLID_CROSS', 'DOTTED_CROSS', 'SOLID_POINT', 'DOTTED_POINT'"),l++;let i=r[l];(47===i||!t&&(45===i||46===i))&&l++;let s=o(),c=h(),d={type:"addMessage",from:e.actor,to:s.actor,signalType:a,msg:c},f=[e,s,d];if(t){let t=47===i;d.activate=t,d.centralConnection=t?61:60,t&&f.push({type:"centralConnection",signalType:59,actor:s.actor}),f.push({type:"centralConnectionReverse",signalType:60,actor:e.actor})}else 45===i?(d.activate=!0,f.push({type:"activeStart",signalType:17,actor:s.actor})):46===i?f.push({type:"activeEnd",signalType:18,actor:e.actor}):47===i&&(d.activate=!0,d.centralConnection=59,f.push({type:"centralConnection",signalType:59,actor:s.actor}));return f},u=e=>{l++;let t=o();return[t,{type:e,actor:t.actor,text:h()}]},p=()=>{l++;let e=r[l];if(37===e){l++;let e=o(),t=e,a=[e.actor,e.actor];if(42===r[l]){l++;let r=o();t=[e,r],a=[e.actor,r.actor]}return[t,{type:"addNote",placement:2,actor:a,text:h()}]}43!==e&&44!==e&&n("'over', 'left_of', 'right_of'"),l++;let t=o();return[t,{type:"addNote",placement:43===e?0:1,actor:t.actor,text:h()}]},g=()=>{l++;let e={type:"sequenceIndex",sequenceVisible:!0,signalType:26};return 10===r[l]?(e.sequenceIndex=Number(a[l++]),e.sequenceIndexStep=10===r[l]?Number(a[l++]):1):11===r[l]&&(l++,e.sequenceVisible=!1),3!==r[l]&&n("'NEWLINE', 'NUM', 'off'"),l++,e},m=(e,r,a,i)=>{let l=e.list,n=e.sections;if(n)for(let e=n.length-2;e>=0;e-=2){let s={type:r,signalType:i};s[a]=t.parseMessage(n[e+1]),l=n[e].concat([s,l])}return l},y=e=>{let r=e.text,a=e.list;switch(e.kind){case 1:a[0]={type:"boxStart",boxData:t.parseBoxData(r)},a.push({type:"boxEnd",boxText:r});break;case 2:a[0]={type:"loopStart",loopText:t.parseMessage(r),signalType:10},a.push({type:"loopEnd",loopText:r,signalType:11});break;case 3:a[0]={type:"rectStart",color:t.parseMessage(r),signalType:22},a.push({type:"rectEnd",color:t.parseMessage(r),signalType:23});break;case 4:a[0]={type:"optStart",optText:t.parseMessage(r),signalType:15},a.push({type:"optEnd",optText:t.parseMessage(r),signalType:16});break;case 5:a[0]={type:"breakStart",breakText:t.parseMessage(r),signalType:30},a.push({type:"breakEnd",optText:t.parseMessage(r),signalType:31});break;case 6:a=m(e,"else","altText",13),a[0]={type:"altStart",altText:t.parseMessage(r),signalType:12},a.push({type:"altEnd",signalType:14});break;case 7:a=m(e,"and","parText",20),a[0]={type:"parStart",parText:t.parseMessage(r),signalType:e.startType},a.push({type:"parEnd",signalType:21});break;default:a=m(e,"option","optionText",28),a[0]={type:"criticalStart",criticalText:t.parseMessage(r),signalType:27},a.push({type:"criticalEnd",signalType:29})}return a};for(;3===r[l];)l++;s(4);let x=[],w={kind:0,text:"",startType:0,list:[],sections:void 0};for(;;){let e=r[l],i=w.list;if(1!==w.kind)switch(e){case 3:case 2:i.push([]),l++;break;case 32:case 34:case 35:i.push(d());break;case 5:{l++;let e=r[l];32!==e&&34!==e&&35!==e&&n("'participant', 'participant_actor', 'destroy'");let t=d();t.type="createParticipant",i.push(t);break}case 48:i.push(f(o())),s(3);break;case 39:{let e=r[l+1];i.push(48===e||39===e?u("addALink"):f(o())),s(3);break}case 38:i.push(u("addLinks")),s(3);break;case 40:i.push(u("addProperties")),s(3);break;case 41:i.push(u("addDetails")),s(3);break;case 36:i.push(p()),s(3);break;case 9:i.push(g());break;case 12:case 13:{l++;let t=o();s(3),i.push(12===e?{type:"activeStart",signalType:17,actor:t.actor}:{type:"activeEnd",signalType:18,actor:t.actor});break}case 14:case 15:{let r=a[l++].substring(14===e?6:7);t.setDiagramTitle(r),i.push(r);break}case 16:{l++;let e=s(17).trim();t.setAccTitle(e),i.push(e);break}case 18:{l++;let e=s(19).trim();t.setAccDescription(e),i.push(e);break}case 20:{let e=a[l++].trim();t.setAccDescription(e),i.push(e);break}case 21:case 22:case 23:case 28:case 24:case 25:case 26:case 27:case 6:{l++;let t=s(7);x.push(w),w={kind:zx[e],text:t,startType:26===e?32:19,list:[[]],sections:void 0};break}case 31:case 30:case 29:{w.kind!==(31===e?6:30===e?7:8)&&n("'end'"),l++;let t=s(7);(w.sections??=[]).push(i,t),w.list=[];break}case 8:{0===w.kind&&n("'NEWLINE', 'EOF'"),l++;let e=y(w);w=x.pop(),w.list.push(e);break}case 0:return 0!==w.kind&&n("'end'"),void t.apply(i);default:n("'NEWLINE', 'ACTOR', 'participant', 'note', 'end'")}else if(32===e||34===e||35===e)i.push(d());else if(3===e)i.push([]),l++;else if(8===e){l++;let e=y(w);w=x.pop(),w.list.push(e)}else n("'end', 'NEWLINE', 'participant', 'participant_actor', 'destroy'")}}(e,i),i},render:function(e,t,r){return Vl(r,a=>lw(e,t,r,a))}};var sw=class{type="state";rootDoc=[];states=new Map;relations=[];classes=new Map;links=new Map;graph={nodes:[],edges:[]};title;accTitle;accDescr;dividerCount=0;get direction(){let e="TB";for(let t of this.rootDoc)"string"!=typeof t&&"dir"===t.stmt&&(e=t.value);return e}setRootDoc(e){this.rootDoc=e,this.translate(),this.extract(e)}extract(e){this.states=new Map,this.relations=[],this.classes=new Map;let t=Array.isArray(e)?e:e.doc;for(let e of t)if("string"!=typeof e)switch(e.stmt){case"state":this.addState(e.id.trim(),e.type,e.doc,e.description,e.note);break;case"relation":this.addRelation(e.state1,e.state2,e.description);break;case"classDef":this.addStyleClass(e.id.trim(),e.classes);break;case"style":{let t=e.styleClass.split(",").map(e=>e.replace(/;/g,"").trim());for(let r of this.named(e.id.trim()))r.styles=t.slice();break}case"applyClass":this.setCssClass(e.id.trim(),e.styleClass);break;case"click":this.addLink("string"==typeof e.id?e.id:e.id.id,e.url,e.tooltip)}this.graph=function(e,t,r){let a=[],l=[],n=new Map,s=new Map,o=new Map,h=0,c=0,d=e=>{if(!e.id||"</join></fork>"===e.id||"</choice>"===e.id)return;if(e.cssClasses){let t;for(let a of e.cssClasses.split(" ")){let i=r.get(a);if(i){t??=e.cssCompiledStyles.slice();for(let e of i.styles)t.push(e)}}t&&(e.cssCompiledStyles=t)}let t=n.get(e.id);if(t){let r=e.parentId??t.parentId;Object.assign(t,e),void 0!==r&&(t.parentId=r)}else n.set(e.id,e),a.push(e)},f=(e,r,a)=>{let i=r.id;if("root"===i)return;let n=t.get(i),f=n?.classes?.join(" ")??"",u=n?.styles??[],p=s.get(i);if(!p){let e="rect";!0===r.start?e="stateStart":!1===r.start&&(e="stateEnd"),"default"!==r.type&&(e=r.type),p={shape:e,description:i,cssClasses:`${f} statediagram-state`,cssStyles:u,type:void 0,dir:void 0,colorIndex:void 0},s.set(i,p)}if(r.description&&(Array.isArray(p.description)?(p.shape="rectWithTitle",p.description=p.description.concat(r.description)):p.description.length>0?(p.shape="rectWithTitle",p.description=p.description===i?[r.description].flat():[p.description,r.description].flat()):(p.shape="rect",p.description=Array.isArray(r.description)?r.description.slice():r.description)),1===p.description.length&&"rectWithTitle"===p.shape&&(p.shape="group"===p.type?"roundedWithTitle":"rect"),!p.type&&r.doc){if(p.type="group",p.dir=function(e){let t="TB";for(let r of e)"string"!=typeof r&&"dir"===r.stmt&&(t=r.value);return t}(r.doc),p.shape="divider"===r.type?"divider":"roundedWithTitle","divider"===p.shape&&void 0!==e?.id&&o.has(e.id))p.colorIndex=o.get(e.id);else{let e=c++;p.colorIndex=""!==f.trim()||u.length>0?void 0:e}o.set(i,p.colorIndex),p.cssClasses=`${p.cssClasses} statediagram-cluster ${a?"statediagram-cluster-alt":""}`}let g=p.description,m={id:i,shape:p.shape,label:Array.isArray(g)?g[0]:g,description:Array.isArray(g)?g.slice(1):[],cssClasses:p.cssClasses,cssCompiledStyles:[],cssStyles:p.cssStyles,type:p.type,isGroup:"group"===p.type,dir:p.dir,colorIndex:p.colorIndex};"divider"===m.shape&&(m.label=""),e&&"root"!==e.id&&(m.parentId=e.id);let y=r.note;if(!y)return void d(m);let x=(e,t,r,a)=>({id:e,shape:t,label:y.text,description:[],cssClasses:r,cssCompiledStyles:[],cssStyles:[],type:a?"group":"node",isGroup:a,dir:void 0,position:y.position}),w=x(`${i}----note-${h++}`,"note","statediagram-note",!1);w.parentId=`${i}----parent`,w.noteFor=i,d(x(w.parentId,"noteGroup",p.cssClasses,!0)),d(w),d(m);let $="left of"===y.position,b=$?w.id:i,M=$?i:w.id;l.push({id:`${b}-${M}`,start:b,end:M,label:"",classes:"transition note-edge",pattern:"dashed"})},u=[{item:void 0,doc:e,at:0,alt:!0}];for(;u.length>0;){let e=u[u.length-1];if(e.at>=e.doc.length){u.pop();continue}let t=e.doc[e.at++];"string"!=typeof t&&("state"===t.stmt?(f(e.item,t,e.alt),t.doc&&u.push({item:t,doc:t.doc,at:0,alt:!e.alt})):"relation"===t.stmt&&(f(e.item,t.state1,e.alt),f(e.item,t.state2,e.alt),l.push({id:"edge"+h++,start:t.state1.id,end:t.state2.id,label:t.description??"",classes:"transition"})))}for(let e of a)if(e.isGroup&&e.description.length>0)throw new i(`Group nodes can only have label. Remove the additional description for node [${e.id}]`,"semantic",{type:"state"});return{nodes:a,edges:l}}(t,this.states,this.classes)}translate(){let e=[["root",{stmt:"root",id:"root",doc:this.rootDoc},!0]];for(;e.length>0;){let[t,r,a]=e.pop();if("string"==typeof r)continue;if("relation"===r.stmt){e.push([t,r.state2,!1],[t,r.state1,!0]);continue}if("state"===r.stmt)"[*]"===r.id?(r.id=t+(a?"_start":"_end"),r.start=a):r.id=r.id.trim();else if("root"!==r.stmt)continue;if(!r.doc)continue;let i=[],l=[];for(let e of r.doc)"string"==typeof e||"state"!==e.stmt||"divider"!==e.type||e.doc?l.push(e):(i.push({...e,doc:l}),l=[]);i.length>0&&(l.length>0&&i.push({stmt:"state",id:this.getDividerId(),type:"divider",doc:l}),r.doc=i);for(let t=r.doc.length-1;t>=0;t--)e.push([r.id,r.doc[t],!0])}}addState(e,t="default",r,a,i,l){let n=e.trim(),s=this.states.get(n);if(s?(s.doc||(s.doc=r),s.type||(s.type=t)):(s={stmt:"state",id:n,descriptions:[],type:t,doc:r,note:i,classes:[],styles:[],textStyles:[]},this.states.set(n,s)),a)for(let e of Array.isArray(a)?a:[a])this.addDescription(n,e.trim());if(i&&(s.note=i),l)for(let e of l)this.setCssClass(n,e.trim())}getState(e){return this.states.get(e)}addLink(e,t,r){this.links.set(e,{url:t,tooltip:r})}addRelation(e,t,r=""){for(let r of[e,t])this.addState(r.id,r.type,r.doc,r.description,r.note,r.classes);this.relations.push({id1:e.id.trim(),id2:t.id.trim(),relationTitle:r})}addDescription(e,t){this.states.get(e)?.descriptions?.push(t.startsWith(":")?t.replace(":","").trim():t)}getDividerId(){return"divider-id-"+ ++this.dividerCount}addStyleClass(e,t=""){let r=this.classes.get(e);if(r||(r={id:e,styles:[],textStyles:[]},this.classes.set(e,r)),t)for(let e of t.split(",")){let t=e.replace(";","").trim();e.includes("color")&&r.textStyles.push(t.replace("fill","bgFill").replace("color","fill")),r.styles.push(t)}}setCssClass(e,t){for(let r of this.named(e))r.classes?.push(t)}getDirection(){for(let e of this.rootDoc)if("string"!=typeof e&&"dir"===e.stmt)return e.value;return"TB"}setDirection(e){for(let t of this.rootDoc)if("string"!=typeof t&&"dir"===t.stmt)return void(t.value=e);this.rootDoc.unshift({stmt:"dir",value:e})}trimColon(e){return e.startsWith(":")?e.slice(1).trim():e.trim()}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}named(e){let t=[];for(let r of e.split(",")){let e=this.states.get(r);e||(this.addState(r),e=this.states.get(r.trim())),e&&t.push(e)}return t}},ow=["$end","INVALID","NL","SD","DESCR","--\x3e","HIDE_EMPTY","scale","WIDTH","COMPOSIT_STATE","STRUCT_START","STRUCT_STOP","STATE_DESCR","AS","ID","FORK","JOIN","CHOICE","CONCURRENT","note","NOTE_TEXT","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","CLICK","STRING","HREF","classDef","CLASSDEF_ID","DEFAULT_CLASSDEF_ID","CLASSDEF_STYLEOPTS","DEFAULT","style","STYLE_IDS","STYLEDEF_STYLEOPTS","class","CLASSENTITY_IDS","STYLECLASS","direction_tb","direction_bt","direction_rl","direction_lr","EDGE_STATE","STYLE_SEPARATOR","left_of","right_of","INVALID"],hw=/direction/gi,cw=/<<(?:fork|join|choice)>>|\[\[(?:fork|join|choice)\]\]/gi,dw=/[\n\r\u2028\u2029]/g,fw=/%%/g,uw=/\{/g;function pw(e,t){let r=0,a=-2;return i=>{if(-2===a||i<r||-1!==a&&i>a){e.lastIndex=i;let l=e.exec(t);a=l?l.index:-1,r=i}return a}}var gw=["TB","BT","RL","LR"],mw="'NL', 'ID', 'HIDE_EMPTY', 'scale', 'COMPOSIT_STATE', 'STATE_DESCR', 'FORK', 'JOIN', 'CHOICE', 'CONCURRENT', 'note', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'CLICK', 'classDef', 'style', 'class', 'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'EDGE_STATE'";function yw(e,t){let{types:r,texts:a,starts:l,error:n}=function(e){let t,r=e.length,a=[],i=[],l=[],n=[],s=0,o=0,h=pw(hw,e),c=pw(cw,e),d=pw(dw,e),f=pw(fw,e),u=pw(uw,e),p=-1,g=-1,m=[-1,-1,-1,-1],y=[0,0,0,0],x=-1,w=-1,$=[-1,-1,-1,-1,-1,-1],b=(t,r,n)=>{a.push(t),i.push(e.slice(r,n)),l.push(r),o=n},M=(e,t,r,n)=>{a.push(e),i.push(t),l.push(r),o=n},v=e=>{n.push(s),s=e},k=()=>{n.length>0&&(s=n.pop())},A=(t,r)=>{for(let a=0;a<t.length;a++){let i=t.charCodeAt(a),l=e.charCodeAt(r+a);if(l!==i&&!(i>=97&&i<=122&&l===i-32))return!1}return!0},T=t=>{let a=t;for(;a<r&&q(e.charCodeAt(a));)a++;return a},C=t=>{let a=t;for(;a<r&&Q(e.charCodeAt(a));)a++;return a},E=t=>{let a=e.indexOf("\n",t);return-1===a?r:a},_=e=>{let t=d(e);return-1===t?r:t},S=e=>{if(e<p||e>g){let t=h(e),a=-1===t?r:_(e);p=e,g=a,m[0]=m[1]=m[2]=m[3]=-1;for(let e=t;-1!==e&&e<a;e=h(e+1)){let t=T(e+9);if(t===e+9)continue;let r=A("tb",t)?0:A("bt",t)?1:A("rl",t)?2:A("lr",t)?3:-1;-1!==r&&(m[r]=e,y[r]=t+2)}}for(let t=0;t<4;t++)if(m[t]>=e)return t;return-1},I=t=>{if(t<x||t>w){let a=c(t),i=-1===a?r:_(t);x=t,w=i,$.fill(-1);for(let t=a;-1!==t&&t<i;t=c(t+1)){let r=32|e.charCodeAt(t+2);$[(60===e.charCodeAt(t)?0:3)+(102===r?0:106===r?1:2)]=t}}for(let e=0;e<6;e++)if($[e]>=t)return e;return-1},N=(e,t)=>{let r=f(e);return-1===r||r+2>t?(b(14,e,t),!0):r===e?(o=t,!1):(b(14,e,r),!0)},D=e=>(a.push(e),i.push(""),l.push(o),{types:a,texts:i,starts:l,error:t});for(;;){if(o>=r){switch(s){case 0:b(2,r,r);break;case 6:b(22,r,r);break;case 7:b(24,r,r);break;case 8:b(25,r,r);break;case 10:b(32,r,r);break;case 12:b(39,r,r);break;case 14:b(36,r,r);break;case 3:b(12,r,r);break;case 18:b(20,r,r);break;case 4:case 19:b(14,r,r)}return D(0)}let a=e.charCodeAt(o);switch(s){case 0:case 1:{let t=0===s,i=32|a;if(t){if(99===i&&A("click",o)&&!Q(e.charCodeAt(o+5))){b(26,o,o+5);continue}if(104===i&&A("href",o)&&!Q(e.charCodeAt(o+4))){b(28,o,o+4);continue}if(34===a){let t=e.indexOf('"',o+1);if(-1!==t){b(27,o,t+1);continue}}if(100===i&&A("default",o)&&!Q(e.charCodeAt(o+7))){b(33,o,o+7);continue}let t=S(o);if(-1!==t){b(40+t,o,E(y[t]));continue}if(10===a){let t=o+1;for(;10===e.charCodeAt(t);)t++;b(2,o,t);continue}if(q(a)){o=T(o);continue}}else if(10!==a&&q(a)){let t=o+1;for(;t<r&&10!==e.charCodeAt(t)&&q(e.charCodeAt(t));)t++;o=t;continue}if(35===a||37===a&&37===e.charCodeAt(o+1)&&123!==e.charCodeAt(o+2)){o=E(o);continue}if(115===i){if(t&&A("scale",o)){let e=T(o+5);if(e>o+5){b(7,o,e),v(5);continue}}if(A("style",o)){let e=T(o+5);if(e>o+5){b(34,o,e),v(13);continue}}if(A("state",o)){let e=T(o+5);if(e>o+5){o=e,v(2);continue}if(t&&A("diagram",o+5)){let t=A("-v2",o+12)?o+15:o+12;if(e=T(t),e>t){b(3,o,e);continue}}}}else if(99===i){if(A("class",o)){let e=A("def",o+5),t=e?o+8:o+5,r=T(t);if(r>t){b(e?29:37,o,r),v(e?9:11);continue}}}else if(97===i&&t&&(A("acctitle",o)||A("accdescr",o))){let t=116==(32|e.charCodeAt(o+3)),r=T(o+8),a=e.charCodeAt(r);if(58===a){b(t?21:23,o,T(r+1)),v(t?6:7);continue}if(123===a&&!t){o=T(r+1),v(8);continue}}if(t){if(123===a){b(10,o,o+1),v(1);continue}}else{let e=S(o);if(-1!==e){b(40+e,o,E(y[e]));continue}if(125===a){b(11,o,o+1),k();continue}if(10===a){o++;continue}}if(110===i&&A("note",o)){let e=T(o+4);if(e>o+4){b(19,o,e),v(15);continue}}if(t&&104===i&&A("hide empty description",o)&&!Q(e.charCodeAt(o+22))){b(6,o,o+22);continue}if(91===a&&42===e.charCodeAt(o+1)&&93===e.charCodeAt(o+2)){b(44,o,o+3);continue}let l=o;for(;l<r;){let t=e.charCodeAt(l);if(58===t||45===t||123===t||q(t))break;l++}if(l>o){N(o,l);continue}if(58===a){for(l=o+1;l<r;){let t=e.charCodeAt(l);if(10===t||59===t)break;if(58===t){let t=e.charCodeAt(l+1);if(l+1>=r||58===t||10===t||59===t)break;l++}l++}if(l>o+1){M(4,e.slice(o,l).trim(),o,l);continue}if(58===e.charCodeAt(o+1)&&58===e.charCodeAt(o+2)){b(45,o,o+3);continue}}else if(45===a&&45===e.charCodeAt(o+1)){if(62===e.charCodeAt(o+2)){b(5,o,o+3);continue}if(!t){b(18,o,o+2);continue}}if(!t)return D(1);b(48,o,o+1);continue}case 2:{if(10!==a&&q(a)){let t=o+1;for(;t<r&&10!==e.charCodeAt(t)&&q(e.charCodeAt(t));)t++;o=t;continue}if(35===a||37===a&&37===e.charCodeAt(o+1)&&123!==e.charCodeAt(o+2)){o=E(o);continue}let i=I(o);if(-1!==i){let t=$[i],r=2===i||5===i;M(r?17:i%3==0?15:16,e.slice(o,t).trim(),o,t+(r?10:8)),k();continue}if(34===a){o++,v(3);continue}let l=10===a?T(o):o;if(A("as",l)){let e=T(l+2);if(e>l+2){b(13,o,e),v(4);continue}}if(10===a){o++,k();continue}if(123===a){b(10,o,o+1),k(),v(1);continue}if(Q(a)){let r=C(o),a=T(r);if(a>r&&Q(e.charCodeAt(a))){let r=u(a+1);if(-1!==r&&r<_(a))return t=`Error: State name must be a single word. Found: "${e.slice(o,r+1).trim()}"`,D(1)}}let n=o+1;for(;n<r;){let t=e.charCodeAt(n);if(123===t||q(t))break;n++}b(9,o,n);continue}case 3:{if(34===a){o++,k();continue}let t=e.indexOf('"',o);b(12,o,-1===t?r:t);continue}case 4:{let t=o;for(;t<r;){let r=e.charCodeAt(t);if(10===r||123===r)break;t++}N(o,t)&&k();continue}case 5:{if(a>=48&&a<=57){let t=o+1;for(;t<r&&e.charCodeAt(t)>=48&&e.charCodeAt(t)<=57;)t++;b(8,o,t);continue}let t=T(o);if(t>o&&A("width",t)&&!Q(e.charCodeAt(t+5))){o=t+5,k();continue}return D(1)}case 6:b(22,o,E(o)),k();continue;case 7:b(24,o,E(o)),k();continue;case 8:{if(125===a){o++,k();continue}let t=e.indexOf("}",o);b(25,o,-1===t?r:t);continue}case 9:{let e=A("default",o)&&T(o+7)>o+7,t=e?o+7:C(o),r=T(t);if(t===o||r===t)return D(1);b(e?31:30,o,r),k(),v(10);continue}case 10:b(32,o,E(o)),k();continue;case 11:{let t=C(o);if(t===o)return D(1);for(;44===e.charCodeAt(t);){let e=T(t+1),r=C(e);if(r===e)break;t=r}b(38,o,t),k(),v(12);continue}case 12:b(39,o,E(o)),k();continue;case 13:{let t=o;for(;t<r&&(Q(e.charCodeAt(t))||44===e.charCodeAt(t));)t++;let a=T(t);if(t===o||a===t)return D(1);b(35,o,a),k(),v(14);continue}case 14:b(36,o,E(o)),k();continue;case 15:if(A("left of",o)&&!Q(e.charCodeAt(o+7))){b(46,o,o+7),k(),v(16);continue}if(A("right of",o)&&!Q(e.charCodeAt(o+8))){b(47,o,o+8),k(),v(16);continue}if(34===a){o++,k(),v(18);continue}return D(1);case 16:{let t=T(o),a=t;for(;a<r;){let t=e.charCodeAt(a);if(58===t||45===t||q(t))break;a++}if(a===t)return D(1);N(o,a)&&(k(),v(17));continue}case 17:{let t=T(o);if(58===e.charCodeAt(t)){let a=t+1;for(;a<r;){let t=e.charCodeAt(a);if(58===t||10===t||59===t)break;a++}if(a>t+1){M(20,e.slice(o+2,a).trim(),o,a),k();continue}}let a=e.indexOf("\n",o),i=-1;for(;-1!==a&&(i=T(a),!A("end note",i)||Q(e.charCodeAt(i+8)));)a=e.indexOf("\n",i);if(-1===a)return D(1);M(20,e.slice(o,i).trim(),o,i+8),k();continue}case 18:{let t=T(o);if(A("as",t)){b(13,o,T(t+2)),k(),v(19);continue}if(34===a){o++;continue}let i=e.indexOf('"',o);b(20,o,-1===i?r:i);continue}case 19:N(o,E(o))&&k();continue}}}(e),s=0,o=t=>{let a=r[s];throw 1===a?void 0!==n?new i(n,"syntax",{type:"state",...h(e,l[s])}):c("state",e,l[s],"",!0):c("state",e,l[s],`Expecting ${t}, got '${ow[a]}'`)},d=e=>(r[s]!==e&&o(`'${ow[e]}'`),a[s++]),f=()=>{let e=r[s];14!==e&&44!==e&&o("'ID', 'EDGE_STATE'");let t=a[s++].trim();return 45!==r[s]?{stmt:"state",id:t,type:"default",description:""}:(s++,{stmt:"state",id:t,classes:[d(14).trim()],type:"default",description:""})};for(;2===r[s];)s++;3!==r[s]&&o("'NL', 'SD'"),s++;let u=[],p=[],g=e=>{"nl"!==e&&u.push(e)},m=(e,t)=>{s++;let r=[];u.push({stmt:"state",id:e,type:"default",description:t,doc:r}),p.push(u),u=r};for(;;){let e=r[s];switch(e){case 2:s++;break;case 14:case 44:{let e=f();if(4===r[s])e.description=t.trimColon(a[s++]),g(e);else if(5===r[s]){s++;let i=f();4===r[s]?g({stmt:"relation",state1:e,state2:i,description:t.trimColon(a[s++])}):g({stmt:"relation",state1:e,state2:i})}else g(e);break}case 6:g(a[s++]);break;case 7:s++,d(8),g(a[s-2]);break;case 9:10===r[s+1]?m(a[s++],""):g(a[s++]);break;case 12:{let e=a[s++];d(13);let t=d(14);if(10===r[s])m(t,e);else if(t.includes(":")){let r=t.split(":");g({stmt:"state",id:r[0],type:"default",description:[e.trim(),r[1]]})}else g({stmt:"state",id:t,type:"default",description:e.trim()});break}case 15:g({stmt:"state",id:a[s++],type:"fork"});break;case 16:g({stmt:"state",id:a[s++],type:"join"});break;case 17:g({stmt:"state",id:a[s++],type:"choice"});break;case 18:s++,g({stmt:"state",id:t.getDividerId(),type:"divider"});break;case 19:{let e=a[s++];if(46===r[s]||47===r[s]){let e=a[s++].trim();g({stmt:"state",id:d(14).trim(),note:{position:e,text:d(20).trim()}})}else 20!==r[s]&&o("'NOTE_TEXT', 'left_of', 'right_of'"),s++,d(13),d(14),g(e);break}case 40:case 41:case 42:case 43:{let r=gw[e-40];s++,t.setDirection(r),g({stmt:"dir",value:r});break}case 21:{s++;let e=d(22).trim();t.setAccTitle(e),g(e);break}case 23:{s++;let e=d(24).trim();t.setAccDescription(e),g(e);break}case 25:{let e=a[s++].trim();t.setAccDescription(e),g(e);break}case 26:{s++;let e,t=f(),i="";28===r[s]?(s++,e=d(27)):(27!==r[s]&&o("'STRING', 'HREF'"),e=a[s++],i=d(27)),d(2),g({stmt:"click",id:t,url:e,tooltip:i});break}case 29:s++,g({stmt:"classDef",id:d(30).trim(),classes:d(32).trim()});break;case 34:s++,g({stmt:"style",id:d(35).trim(),styleClass:d(36).trim()});break;case 37:s++,g({stmt:"applyClass",id:d(38).trim(),styleClass:d(39).trim()});break;case 11:0===p.length&&o(`'$end', ${mw}`),s++,u=p.pop();break;case 0:return p.length>0&&o(`'STRUCT_STOP', ${mw}`),t.setRootDoc(u),u;default:o(p.length>0?`'STRUCT_STOP', ${mw}`:`'$end', ${mw}`)}}}var xw=16,ww=' fill="var(--_s)" stroke="var(--_b)"',$w=' fill="none" stroke="var(--_b)"',bw=/(?:^| )statediagram-(?:state|cluster-alt|cluster|note)(?= |$)/g,Mw=new Map([["rectWithTitle",1],["stateStart",2],["stateEnd",3],["choice",4],["fork",5],["join",6],["note",7],["divider",10]]),vw=["pele-node pele-state","pele-node pele-state","pele-node pele-state-start","pele-node pele-state-end","pele-node pele-state-choice","pele-node pele-state-fork","pele-node pele-state-join","pele-note","pele-cluster pele-state-composite"];function kw(e){return"TB"===e||"BT"===e}function Aw(e,t,r){let a=e.state?.[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}function Tw(e){let t=0,r=e.length;for(;t<r&&34===e.charCodeAt(t);)t++;for(;r>t&&34===e.charCodeAt(r-1);)r--;return e.slice(t,r)}function Cw(e,t,r){return e<t?t:e>r?r:e}function Ew(e,t,r,a,i){return`<rect x="${Oe(e)}" y="${Oe(t)}" width="${Oe(r)}" height="${Oe(a)}"${i}/>`}function _w(e,t,r,a){let i=Va(0,0);return i.isGroup=!0,i.dir=e,i.padX=t,i.padTop=r,i.padBottom=a,i}function Sw(e,t,r,a){let i=e.graph,l=t.flowchart?.curve,n=r.fontSize??16,s=Math.round(.875*n),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=Aw(t,"wrappingWidth",200),c=r.padding??8,d=r.icons,f=a?"TB":Pa(e.direction),u=Fl(void 0,!1,o,n,0),p=(e,t,r,a=0)=>Fl(e,!0,o,t,r,a),g=new Map,y=[],x=[],w=(e,t,r)=>(y.push({node:e,kind:t,style:void 0,label:u,lines:[],w:0,h:0,titleH:0}),r&&x.push(r),y.length-1);for(let e of i.nodes){if("noteGroup"===e.shape)continue;let t=e.isGroup?"divider"===e.shape?9:8:Mw.get(e.shape)??0;g.set(e.id,w(e,t,void 0))}let $=y.length,b=[];for(let e=0;e<$;e++){let t=y[e].node.parentId,r=void 0===t?void 0:g.get(t);b.push(void 0!==r&&r!==e&&y[r].node.isGroup?r:-1)}{let e=[];for(let t=0;t<$;t++)e.push([]);let t=[],r=new Uint8Array($);for(let a=0;a<$;a++)-1===b[a]?(r[a]=1,t.push(a)):e[b[a]].push(a);let a=0,i=()=>{for(;a<t.length;a++)for(let i of e[t[a]])r[i]||(r[i]=1,t.push(i))};i();let l=new Int32Array($).fill(-1);for(let e=0;e<$;e++){if(r[e])continue;let a=e;for(;l[a]!==e;)l[a]=e,a=b[a];b[a]=-1,r[a]=1,t.push(a),i()}}let M=new Int32Array($).fill(-1);for(let e=0;e<$;e++){let t=y[e].node.noteFor,r=void 0===t?void 0:g.get(t);void 0!==r&&(M[e]=r,b[e]=b[r])}let v=e=>Pa(y[e].node.dir),k=e=>kw(-1===b[e]?f:v(b[e])),A=new Int32Array($),T=new Uint8Array($),C=new Array($).fill(1/0),E=0,_=new Int32Array(2*$);for(let e of i.edges){let t=g.get(e.start),r=g.get(e.end);if(void 0!==t&&void 0!==r){if("dashed"===e.pattern){T[7===y[t].kind?r:t]=1;continue}A[t]=Math.max(A[t],++_[2*t]),A[r]=Math.max(A[r],++_[2*r+1]),C[t]===1/0&&(C[t]=E++),C[r]===1/0&&(C[r]=E++)}}for(let e=0;e<$;e++){let t,r=y[e],a=r.node,i=Ri(a.cssStyles.length>0?a.cssCompiledStyles.concat(a.cssStyles):a.cssCompiledStyles),l=(i.bold?1:0)|(i.italic?2:0),o=i.fontSize??n;switch(r.style=i,r.kind){case 8:r.label=p(a.label,o,4e3,l),r.titleH=r.label.height>0?r.label.height+12:0,t=_w(v(e),xw,r.titleH+xw,xw),t.minW=r.label.width+32;break;case 9:t=_w(v(e),10,10,10);break;case 2:r.w=r.h=14;break;case 3:r.w=r.h=18;break;case 4:r.w=r.h=30;break;case 5:case 6:{let t=Cw(40*A[e]+16,72,320);r.w=k(e)?t:8,r.h=k(e)?8:t;break}case 10:break;case 7:r.label=p(a.label,s,Math.max(h,320)),r.w=r.label.width+24,r.h=r.label.height+16;break;default:{r.label=p(a.label,o,h,l);let e=r.label.width,t=r.label.height+20;if(1===r.kind){t+=14;for(let i of a.description){let a=p(""===i?" ":i,s,h,l);r.lines.push(a),a.width>e&&(e=a.width),t+=a.height}}r.w=Math.max(e+32,56),r.h=t}}t??=Va(r.w,r.h),(0===r.kind||1===r.kind)&&(t.span=(k(e)?r.w:r.h)-24),x.push(t)}let S=[],I=[],N=[],D=new Int32Array($),R=new Float64Array($),L=new Float64Array($),O=new Map,F=(e,t)=>{if(!x[e].isGroup)return!1;for(let r=b[t];-1!==r;r=b[r])if(r===e)return!0;return!1},z=(e,t)=>(O.set(S.length,e),C.push(t?-1:1/0),w(void 0,10,Va(0,0,e)));for(let e of i.edges){let t=g.get(e.start),r=g.get(e.end);if(void 0===t||void 0===r)continue;let a=p(e.label,s,h),i=a.width>0?a.width+12:0;t===r?(D[t]++,R[t]=Math.max(R[t],i),L[t]+=a.height):F(t,r)?t=z(t,!0):F(r,t)&&(r=z(r,!1)),N.push(e),I.push(a),S.push({src:t,dst:r,minlen:1,labelW:i,labelH:a.height>0?a.height+4:0,route:[],labelX:0,labelY:0})}for(let e=0;e<$;e++){if(-1!==M[e])continue;let t=x[e],r=0;if(D[e]>0){let a=26+8*(D[e]-1);r=k(e)?a+R[e]:.75*a+4+L[e],t.isGroup||(k(e)?(t.w+=2*r,t.h=Math.max(t.h,L[e])):(t.h+=2*r,t.w=Math.max(t.w,R[e])),r=0)}if(!T[e]&&0===r){t.parent=b[e];continue}let a=k(e)?_w("LR",r,0,0):_w("TB",0,r,r);a.parent=b[e],C.push(C[e]),x[e].parent=w(void 0,10,a)}for(let e=0;e<$;e++)-1!==M[e]&&(x[e].parent=x[M[e]].parent);{let e=[];for(let t=0;t<x.length;t++)e.push([]);let t=[];for(let r=0;r<x.length;r++){let a=x[r].parent;a>=0?e[a].push(r):t.push(r)}let r=e=>2===y[e].kind?0:1,a=(e,t)=>r(e)-r(t)||(C[e]===C[t]?0:C[e]<C[t]?-1:1)||e-t,i=0,l=t.sort(a).reverse();for(;l.length>0;){let t=l.pop();x[t].seq=i++;let r=e[t].sort(a);for(let e=r.length-1;e>=0;e--)l.push(r[e])}}let W=Za(x,S,f,{nodeSep:Aw(t,"nodeSpacing",40),edgeSep:16,rankSep:Aw(t,"rankSpacing",44),portSep:20,tracks:"step"===l||"stepBefore"===l||"stepAfter"===l,straight:"linear"===l,headRoom:ii("arrow_point")}),P=Math.ceil(W.width+2*c),B=Math.ceil(W.height+2*c),H=[],Y=new Map;for(let e of S){let t=e.route;for(let e=3;e<t.length-3;e+=3){let r=Math.round(t[e+1]),a=Y.get(r);a?a.push(t[e]):Y.set(r,[t[e]])}}let G=[];for(let e=0;e<x.length;e++)G.push([]);let U=[];for(let e=0;e<x.length;e++){let t=x[e].parent;t>=0?G[t].push(e):U.push(e)}let q=U.slice();for(let e=0;e<U.length;e++)for(let t of G[U[e]])U.push(t);let j="",V=[],X="",K="",Z="",Q=(e,t,r,a,i)=>{let l=e.filter(e=>9===y[e].kind);if(l.length<2)return;let n=(e,t)=>t?x[e].x-x[e].w/2:x[e].y-x[e].h/2,s=(e,t)=>t?x[e].x+x[e].w/2:x[e].y+x[e].h/2;for(let e of[!0,!1]){let o=l.slice().sort((t,r)=>n(t,e)-n(r,e)||t-r),h=!0;for(let t=1;t<o.length;t++)s(o[t-1],e)>n(o[t],e)+.5&&(h=!1);if(h){for(let l=1;l<o.length;l++){let h=Oe((s(o[l-1],e)+n(o[l],e))/2+c);X+=`<path class="pele-divider" d="M${e?`${h},${Oe(r)}V${Oe(i)}`:`${Oe(t)},${h}H${Oe(a)}`}"/>`}return}}for(let e of l){let t=x[e];X+=Ew(t.x-t.w/2+c,t.y-t.h/2+c,t.w,t.h,' class="pele-divider" rx="10"')}};Q(q,c/2,c/2,P-c/2,B-c/2);for(let t of U){let a=y[t],i=a.node,l=a.style;if(void 0===i||void 0===l||a.kind>=9)continue;let n,o=x[t],h=o.x+c,f=o.y+c,u=a.w,p=a.h,g=xt(l),w=` class="pele-label"${g}${l.text}`;switch(a.kind){case 8:{let e=h-o.w/2,r=f-o.h/2;yt(l.shape)&&V.push({box:[e,r,e+o.w,r+o.h],shape:l.shape}),n=Ew(e,r,o.w,o.h,` rx="10" fill="var(--_a)"${ki(l.shape)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${l.shape}`),a.titleH>0&&(n+=`<path d="M${Oe(e)},${Oe(r+a.titleH)}H${Oe(e+o.w)}"${$w}${l.line}/>`+Fe(a.label,Iw(o,a.label.width,Y)+c,r+a.titleH/2,` class="pele-cluster-label"${g}${l.text}`,d)),Q(G[t],e,r+a.titleH,e+o.w,r+o.h);break}case 2:n=`<circle r="7" fill="var(--_l)"${l.shape}/>`;break;case 3:n=`<circle r="8.5" fill="var(--_bg)" stroke="var(--_l)"${l.line}/><circle r="5" fill="var(--_l)"${l.shape}/>`;break;case 4:n=`<polygon points="0,${Oe(-p/2)} ${Oe(u/2)},0 0,${Oe(p/2)} ${Oe(-u/2)},0"${ww}${l.shape}/>`;break;case 5:case 6:n=Ew(-u/2,-p/2,u,p,` rx="2" fill="var(--_l)"${l.shape}`);break;case 7:{let e=Oe(u/2),t=Oe(p/2),r=Oe(u/2-8),i=Oe(8-p/2);n=`<path d="M-${e},-${t}H${r}L${e},${i}V${t}H-${e}Z" fill="var(--_bg)" stroke="var(--_b)"/><path d="M${r},-${t}V${i}H${e}"${$w}/>`+Fe(a.label,0,0,` class="pele-label" font-size="${s}" fill="var(--_m)"`,d);break}default:{if(n=Ew(-u/2,-p/2,u,p,` rx="${Oe(Math.min(10,p/2))}"${ww}${l.shape}`),0===a.kind){n+=Fe(a.label,0,0,w,d);break}let e=10-p/2+a.label.height;n+=`<path d="M${Oe(-u/2)},${Oe(e+6)}H${Oe(u/2)}"${$w}${l.line}/>`+Fe(a.label,0,e-a.label.height/2,w,d),e+=14;for(let t of a.lines)n+=Fe(t,0,e+t.height/2,` class="pele-state-description" font-size="${s}"${g}${l.text}`,d),e+=t.height}}let $=e.links.get(i.id);if($){let e=m(Tw($.tooltip));e&&(n=`<title>${De(e)}</title>`+n),n=Mr(n,dr(Tw($.url)),i.id,H,r,' target="_blank"')}let b=`<g class="${vw[a.kind]}${Oi(i.cssClasses.replace(bw,""))}" data-id="${Re(i.id)}"`;8===a.kind?j+=`${b}>${n}</g>`:7===a.kind?Z+=`${b} transform="translate(${Oe(h)},${Oe(f)})">${n}</g>`:K+=`${b} transform="translate(${Oe(h)},${Oe(f)})">${n}</g>`}let J=(e,t,r)=>{let a=x[r];if(a.isGroup)return;let i=y[r],l=5===i.kind||6===i.kind,n=0===t?3:t-3;for(let r of[1,0]){let s=r?a.h:a.w,o=r?i.h:i.w,h=r?i.w:i.h,d=(r?a.y:a.x)+c,f=(r?a.x:a.y)+c,u=e[t+r]-d;if(!(Math.abs(Math.abs(u)-s/2)>=.5))return e[t+r]-=Math.sign(u)*(s-o)/2,void(l&&h>o&&(e[t+1-r]=Cw(e[n+1-r],f-h/2+6,f+h/2-6)))}},ee=ri();for(let e=0;e<S.length;e++){let t=S[e];t.src===t.dst||t.route.length<6||"dashed"===N[e].pattern||ee.add(t.dst,fl(t.route,t.route.length-3,x[t.dst]),"arrow_point")}let te="",re="",ae="",ie=new Int32Array($),le=new Float64Array($);for(let e=0;e<S.length;e++){let t,r=S[e],a=N[e],i=I[e],n="dashed"===a.pattern,s=n?"none":"arrow_point";if(r.src===r.dst){let e=x[r.src],a=y[r.src],l=ie[r.src]++,n=k(r.src),o=e.isGroup?e.w:a.w,h=e.isGroup?e.h:a.h,d=(n?o:h)/2,f=Math.max(Math.min((n?h:o)/2-4,8+6*l),2),u=26+8*l,p=ii(s)/(Math.hypot(u,f)||1),g=(t,r)=>e.x+c+(n?d+t:-r),m=(t,r)=>e.y+c+(n?r:d+t),w=(e,t)=>`${Oe(g(e,t))},${Oe(m(e,t))}`;t={d:`M${w(0,-f)}C${w(u,-2*f)} ${w(u,2*f)} ${w(u*p,f+f*p)}`,sx:0,sy:0,sdx:0,sdy:0,ex:g(0,f),ey:m(0,f),edx:g(-u,-f)-g(0,0),edy:m(-u,-f)-m(0,0)};let $=Math.hypot(t.edx,t.edy)||1;t.edx/=$,t.edy/=$;let b=26+8*(D[r.src]-1),M=le[r.src]+i.height/2;le[r.src]+=i.height,r.labelX=n?e.x+d+b+4+r.labelW/2:e.x,r.labelY=n?e.y-L[r.src]/2+M:e.y+d+.75*b+4+M}else{let a=r.route.slice(),i=ee.of(r.src,fl(a,0,x[r.src])),n=ee.of(r.dst,fl(a,a.length-3,x[r.dst]));for(let e=0;e<a.length;e+=3)a[e]+=c,a[e+1]+=c;J(a,0,r.src),J(a,a.length-3,r.dst);let o=O.get(e);if(void 0!==o&&a.length>=6){let e=x[o],t=10===y[r.src].kind,i=t?0:a.length-3,l=("TB"===e.dir||"LR"===e.dir)===t,n=kw(e.dir)?[a[i],e.y+c+(l?y[o].titleH-e.h/2:e.h/2),0]:[e.x+c+(l?-e.w/2:e.w/2),a[i+1],1];a=t?n.concat(a):a.concat(n)}t=ai(a,"string"==typeof l?l:void 0,0,ii(s),i,n)}let o=gi(t.d,[t.ex,t.ey],V,"",t.tokens);if(""===o&&(te+=yi(t,"none",s)),re+=`<g class="pele-edge ${n?`pele-note-edge" stroke="${o||"var(--_b)"}" stroke-dasharray="3 4`:o?`pele-transition" stroke="${o}`:"pele-transition"}" data-id="${Re(a.id)}"><path d="${t.d}"/>`+li(s,t.ex,t.ey,t.edx,t.edy,o||"var(--_l)")+"</g>",i.width>0){let e=r.labelX+c,t=r.labelY+c;ae+=wi(a.id,i,e,t,"",d)}}let ne=ms(e.title,o,n,c,P,B,(j?`<g class="pele-clusters">${j}</g>`:"")+(X?`<g class="pele-dividers" stroke-dasharray="4 4"${$w}>${X}</g>`:"")+xi(te)+(re?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${re}</g>`:"")+(ae?`<g class="pele-edge-labels" font-size="${s}">${ae}</g>`:"")+`<g class="pele-nodes">${K}${Z}</g>`);return{svg:Bi("state",ne.width,ne.height,n,r,e,ne.content),width:ne.width,height:ne.height,links:H}}function Iw(e,t,r){let a=r.get(Math.round(e.y-e.h/2));if(void 0===a||0===t)return e.x;let i=e.x-e.w/2,l=t/2,n=e.x,s=-1;for(let t of[e.x,i+xw+l,i+e.w-xw-l]){let r=1/0;for(let n of a)n>i&&n<i+e.w&&(r=Math.min(r,Math.abs(n-t)-l));if(r>=6)return t;r>s+.5&&(s=r,n=t)}return n}var Nw={type:"state",math:!0,parse(e,t,r){let a=new sw;return r&&(a.title=r),yw(e,a),a},render:function(e,t,r){return jl(e.direction)?ql(r,a=>Sw(e,t,r,a)):Sw(e,t,r,!1)}},Dw=2e6;function Rw(e,t,r,a,i=24){let l=e.length;if(0===l)return{width:0,height:0};let n="LR"===r||"RL"===r,s="BT"===r||"RL"===r,o=[];for(let t=l-1;t>=0;t--)e[t].parent<0&&e[t].isGroup&&o.push(t);let h=Math.max(1,o.length),c=new Int32Array(l).fill(-1);o.forEach((e,t)=>c[e]=t);let d=new Uint8Array(l);for(let t=0;t<l;t++)e[t].parent>=0&&(d[e[t].parent]=1);let f=new Float64Array(h).fill(i),u=i,p=new Int32Array(l).fill(-1),g=[];for(let t=0;t<l;t++)c[t]>=0||(!e[t].isGroup||!d[t])&&(p[t]=g.length,g.push(t));let m=g.map(t=>ba((e=>n?e.h:e.w)(e[t]),(e=>n?e.w:e.h)(e[t]))),y=[],x=[],w=1;{let e=new Set;for(let r=0;r<t.length;r++){let a=t[r],i=p[a.src],l=p[a.dst];if(i<0||l<0||i===l)continue;let s=Math.min(i,l)*g.length+Math.max(i,l);(a.labelW>0||e.has(s))&&(w=2),e.add(s),y.push(Ma(i,l,a.minlen,n?a.labelH:a.labelW,n?a.labelW:a.labelH)),x.push(r)}}Da(m,y),Ra(m,y,w);let $=y.length,b=Int32Array.from(g,t=>{let r=t,a=i;for(let t=0;e[r].parent>=0&&t<1e4;t++)r=e[r].parent,c[r]<0&&(a+=Math.max(e[r].padX,e[r].padTop,e[r].padBottom));let l=Math.max(0,c[r]);return a>f[l]&&(f[l]=a),a>u&&(u=a),l}),M=(r,i)=>{let d=f.map((e,t)=>i[t]?Math.max(e,20):e),M=new Uint8Array(h),v=0,k=new Int32Array($);for(let e=0;e<$;e++)k[e]=Math.abs(m[y[e].head].rank-m[y[e].tail].rank),r[e]||(v+=k[e]-1);let A=v>2e4,T=g.length+(A?0:v),C=new Int32Array(T),E=new Int32Array(T),_=new Float64Array(T),S=new Float64Array(T),I=new Uint8Array(T),N=0;for(let e=0;e<g.length;e++)C[e]=m[e].rank,E[e]=b[e],_[e]=m[e].w,S[e]=m[e].h,C[e]>N&&(N=C[e]);let D=new Int32Array($).fill(-1),R=new Int32Array($).fill(-1),L=[];{let e=g.length;for(let t=0;t<$;t++){let a=y[t],i=a.reversed?a.head:a.tail,l=a.reversed?a.tail:a.head;if(A||k[t]<2||r[t]){L.push(i,l);continue}let n=C[i],s=C[l],o=-1;a.labelW>0&&(o=n+(s-n>>1),2===w&&!(1&o)&&o--),D[t]=e;let h=i;for(let r=n+1;r<s;r++){let c=e++;C[c]=r,E[c]=E[i]+Math.round((E[l]-E[i])*(r-n)/(s-n)),I[c]=1,r===o&&(_[c]=a.labelW,S[c]=a.labelH,R[t]=c),L.push(h,c),h=c}L.push(h,l)}}let O=new Int32Array(T+1),F=new Int32Array(T+1);for(let e=0;e<L.length;e+=2)F[L[e]+1]++,O[L[e+1]+1]++;for(let e=0;e<T;e++)O[e+1]+=O[e],F[e+1]+=F[e];let z=new Int32Array(L.length/2),W=new Int32Array(L.length/2);{let e=O.slice(0,T),t=F.slice(0,T);for(let r=0;r<L.length;r+=2)W[t[L[r]]++]=L[r+1],z[e[L[r+1]]++]=L[r]}let P=[];for(let e=0;e<=N;e++)P.push([]);for(let e=0;e<T;e++)P[C[e]].push(e);let B=new Float64Array(T),H=new Float64Array(T),Y=e=>{e.sort((e,t)=>E[e]-E[t]||H[e]-H[t]||e-t);for(let t=0;t<e.length;t++)B[e[t]]=t};for(let e of P){for(let t=0;t<e.length;t++)H[e[t]]=t;Y(e)}for(let e=0;e<8&&N>0;e++){let t=!(1&e);for(let e=1;e<=N;e++){let r=P[t?e:N-e],a=t?O:F,i=t?z:W;for(let e of r){let t=0,r=a[e+1]-a[e];for(let r=a[e];r<a[e+1];r++)t+=B[i[r]];H[e]=r>0?t/r:B[e]}Y(r)}}let G=(e,t)=>I[e]||I[t]?a.edgeSep:a.nodeSep,U=(e,t)=>{let r=0;for(;r<e.length;){let a=r;for(;a+1<e.length&&E[e[a+1]]===E[e[r]];)a++;t(e,r,a),r=a+1}},q=(e,t,r)=>{let a=_[e[t]];for(let i=t;i<r;i++)a+=G(e[i],e[i+1])+_[e[i+1]];return a},j=new Float64Array(h),V=o.length>0?34:0;for(let t=0;t<o.length;t++){let r=e[o[t]];j[t]=Math.max(0,r.minW-2*d[t]),r.padTop>V&&(V=r.padTop)}for(let e of P)U(e,(t,r,a)=>{let i=q(e,r,a);i>j[E[e[r]]]&&(j[E[e[r]]]=i)});let X=new Float64Array(h+1);for(let e=0;e<h;e++)X[e+1]=X[e]+j[e]+2*d[e];let K=new Float64Array(T),Z=new Float64Array(T),Q=(e,t,r)=>{let a=E[e[t]],i=(X[a]+d[a]+(X[a+1]-d[a])-q(e,t,r))/2;for(let a=t;a<=r;a++)K[e[a]]=i+_[e[a]]/2,a<r&&(i+=_[e[a]]+G(e[a],e[a+1]))},J=(e,t,r)=>{let a=E[e[t]],i=X[a]+d[a];for(let a=t;a<=r;a++){let t=e[a];K[t]=Math.max(Z[t],i+_[t]/2),a<r&&(i=K[t]+_[t]/2+G(t,e[a+1]))}let l=X[a+1]-d[a];for(let a=r;a>=t;a--){let r=e[a];K[r]=Math.min(K[r],l-_[r]/2),a>t&&(l=K[r]-_[r]/2-G(e[a-1],r))}};for(let e of P)U(e,Q);for(let e=0;e<4&&N>0;e++){let t=!(1&e);for(let e=1;e<=N;e++){let r=P[t?e:N-e],a=t?O:F,i=t?z:W;for(let e of r){let t=0,r=0;for(let l=a[e];l<a[e+1];l++)E[i[l]]===E[e]&&(t+=K[i[l]],r++);Z[e]=r>0?t/r:K[e]}U(r,J)}}let ee=new Float64Array(N+1),te=new Float64Array(N+1),re=new Float64Array(N+1).fill(a.rankSep/w);if(r.some(e=>1===e)){let e=a.rankSep/w;re.fill(e/3);for(let t=0;t<$;t++){let a=y[t],i=a.reversed?a.head:a.tail,l=a.reversed?a.tail:a.head;if(r[t]){if(a.labelH<=0||k[t]>w)continue;let r=Math.min(e,(a.labelH+40-Math.min(S[i],S[l])/2)/k[t]);for(let e=C[i];e<C[l];e++)r>re[e]&&(re[e]=r);continue}let n=D[t];if(n<0||k[t]<=w*a.minlen)for(let t=C[i];t<C[l];t++)re[t]=e;else for(let r=n-1;r<n+k[t]-1;r++){let a=r<n?i:r,s=r+1<n+k[t]-1?r+1:l;(E[a]!==E[s]||Math.abs(K[a]-K[s])>=.5)&&(re[C[a]]=e)}}}let ae=V+u;for(let e=0;e<=N;e++){let t=0;for(let r of P[e])S[r]>t&&(t=S[r]);ee[e]=ae,te[e]=ae+t,ae+=t+(e===N?0:re[e])}let ie=ae+u,le=X[h],ne=e=>s?V+ie-e:e,se=(e,t)=>n?ne(t):e,oe=(e,t)=>n?e:ne(t),he=n?1:0;for(let t=0;t<g.length;t++){let r=e[g[t]],a=(ee[C[t]]+te[C[t]])/2;r.x=se(K[t],a),r.y=oe(K[t],a)}for(let t=0;t<o.length;t++){let r=e[o[t]],a=(X[t]+X[t+1])/2,i=X[t+1]-X[t];r.x=n?ie/2:a,r.y=n?a:ie/2,r.w=n?ie:i,r.h=n?i:ie,r.padTop=V}let ce=new Int32Array(l),de=[];for(let t=0;t<l;t++){if(!e[t].isGroup||c[t]>=0||p[t]>=0)continue;let r=0;for(let a=e[t].parent;a>=0&&r<1e4;a=e[a].parent)r++;ce[t]=r,de.push(t)}de.sort((e,t)=>ce[t]-ce[e]||e-t);let fe=new Float64Array(4*l);for(let e=0;e<l;e++)fe[4*e]=1/0,fe[4*e+1]=1/0,fe[4*e+2]=-1/0,fe[4*e+3]=-1/0;let ue=(e,t)=>{t.x-t.w/2<fe[4*e]&&(fe[4*e]=t.x-t.w/2),t.y-t.h/2<fe[4*e+1]&&(fe[4*e+1]=t.y-t.h/2),t.x+t.w/2>fe[4*e+2]&&(fe[4*e+2]=t.x+t.w/2),t.y+t.h/2>fe[4*e+3]&&(fe[4*e+3]=t.y+t.h/2)};for(let t of g)e[t].parent>=0&&c[e[t].parent]<0&&ue(e[t].parent,e[t]);for(let t of de){let r=e[t];if(fe[4*t]===1/0)continue;let a=Math.max(fe[4*t+2]-fe[4*t]+2*r.padX,r.minW);r.x=(fe[4*t]+fe[4*t+2])/2,r.w=a,r.y=(fe[4*t+1]-r.padTop+fe[4*t+3]+r.padBottom)/2,r.h=fe[4*t+3]-fe[4*t+1]+r.padTop+r.padBottom,r.parent>=0&&c[r.parent]<0&&ue(r.parent,r)}for(let e of t)e.route=[];for(let e=0;e<$;e++){let r=y[e],a=t[x[e]],i=r.reversed?r.head:r.tail,l=r.reversed?r.tail:r.head,n=[K[i],te[C[i]]-(te[C[i]]-ee[C[i]]-S[i])/2],s=D[e];if(s>=0)for(let t=s;t<s+k[e]-1;t++)n.push(K[t],ee[C[t]]),te[C[t]]>ee[C[t]]&&n.push(K[t],te[C[t]]);n.push(K[l],ee[C[l]]+(te[C[l]]-ee[C[l]]-S[l])/2);let o=[];for(let e=0;e<n.length;e+=2)o.push(se(n[e],n[e+1]),oe(n[e],n[e+1]),he);if(r.reversed)for(let e=0,t=o.length-3;e<t;e+=3,t-=3)for(let r=0;r<2;r++){let a=o[e+r];o[e+r]=o[t+r],o[t+r]=a}a.route=o;let h=R[e];if(h>=0){let e=(ee[C[h]]+te[C[h]])/2;a.labelX=se(K[h],e),a.labelY=oe(K[h],e)}else a.labelX=(o[0]+o[o.length-3])/2,a.labelY=(o[1]+o[o.length-2])/2}for(let r of t){if(r.route.length>0||r.src===r.dst)continue;let t=e[r.src],a=e[r.dst],[i,l]=Lw(t,a),[n,s]=Lw(a,t),o=Math.abs(n-i)>Math.abs(s-l)?1:0;r.route=[i,l,o,n,s,o],r.labelX=(i+n)/2,r.labelY=(l+s)/2}let pe=new Uint8Array($),ge=t.reduce((e,t)=>e+t.route.length/3,0),me=$*(g.length+t.length+ge);if(me<=Dw){let e=e=>(ee[C[e]]+te[C[e]])/2,r=t.map(e=>[n?e.labelY:e.labelX,ne(n?e.labelX:e.labelY)]),a=(e,t,r,a,i,l,n,s)=>r>i-n/2&&e<i+n/2&&a>l-s/2&&t<l+s/2,i=(i,l,s,o,h,c,d)=>{for(let t=0;t<g.length;t++)if(t!==h&&t!==c&&a(i,l,s,o,K[t],e(t),_[t]+8,S[t]+8))return!1;for(let e=0;e<t.length;e++){let h=t[e];if(e!==d&&h.labelW>0&&h.src!==h.dst&&a(i,l,s,o,r[e][0],r[e][1],n?h.labelH:h.labelW,n?h.labelW:h.labelH))return!1}return!0},l=(e,r,a,i,l)=>{let n=0;for(let s=0;s<t.length;s++){if(s===l)continue;let o=t[s].route;for(let t=3;t<o.length;t+=3)if(Math.max(o[t-3],o[t])>e&&Math.min(o[t-3],o[t])<a&&Math.max(o[t-2],o[t+1])>r&&Math.min(o[t-2],o[t+1])<i){n++;break}}return n},s=(e,r,a)=>{let i=0;for(let l=0;l<t.length;l++){let n=t[l].route;if(l===a||0===n.length)continue;let s=n.length-3;(Math.abs(n[0]-e)<1&&Math.abs(n[1]-r)<1||Math.abs(n[s]-e)<1&&Math.abs(n[s+1]-r)<1)&&i++}return i},o=(e,r,a,i,l)=>{let n=Math.abs(a-e)<.5,s=n?Math.min(r,i):Math.min(e,a),o=n?Math.max(r,i):Math.max(e,a),h=n?e:r;for(let e=0;e<t.length;e++){let r=t[e];if(e===l||r.src===t[l].src||r.dst===t[l].dst)continue;let a=r.route;for(let e=3;e<a.length;e+=3){let t=a[e-3+(n?0:1)],r=a[e+(n?0:1)];if(Math.abs(t-h)>=4||Math.abs(r-h)>=4)continue;let i=a[e-3+(n?1:0)],l=a[e+(n?1:0)];if(Math.min(o,Math.max(i,l))-Math.max(s,Math.min(i,l))>1)return!0}}return!1};for(let a=0;a<$;a++){let n=y[a],h=x[a],c=t[h],f=n.tail,u=n.head;if(E[f]===E[u]||Math.abs(K[u]-K[f])<1)continue;let p=K[f],g=K[u],m=e(f),w=e(u),$=Math.sign(g-p),b=Math.sign(w-m),v=(e,t)=>{for(let r=2;r<e.length;r+=2)if(!i(Math.min(e[r-2],e[r])-t,Math.min(e[r-1],e[r+1])-t,Math.max(e[r-2],e[r])+t,Math.max(e[r-1],e[r+1])+t,f,u,h)||o(se(e[r-2],e[r-1]),oe(e[r-2],e[r-1]),se(e[r],e[r+1]),oe(e[r],e[r+1]),h))return!1;let s=0,d=0,p=-1;if(c.labelW>0){let t=n.labelW,r=n.labelH;for(let a=2;a<e.length;a+=2){let n=(e[a-2]+e[a])/2,o=(e[a-1]+e[a+1])/2,f=Math.abs(e[a]-e[a-2]),u=Math.abs(e[a+1]-e[a-1]),g=f+u;if(g<=p||(f>0?f<t+8:u<r+8)||n-t/2<0||n+t/2>le||o-r/2<0||o+r/2>ie||!i(n-t/2,o-r/2,n+t/2,o+r/2,-1,-1,h))continue;let m=se(n,o),y=oe(n,o);l(m-c.labelW/2,y-c.labelH/2,m+c.labelW/2,y+c.labelH/2,h)>0||(s=n,d=o,p=g)}if(p<0)return!1}let g=[e[0],e[1]];for(let t=2;t<e.length;t+=2){let r=e[t]-e[t-2],a=e[t+1]-e[t-1],i=Math.abs(r)+Math.abs(a),l=t>2?20:0,n=t+2<e.length?20:0;i>l+n+1&&(l&&g.push(e[t-2]+r/i*l,e[t-1]+a/i*l),n&&g.push(e[t]-r/i*n,e[t+1]-a/i*n)),g.push(e[t],e[t+1])}c.route=[];for(let e=0;e<g.length;e+=2){let t=0===e?g[0]!==g[2]:g[e]!==g[e-2];c.route.push(se(g[e],g[e+1]),oe(g[e],g[e+1]),t?1-he:he)}return c.labelW>0&&(c.labelX=se(s,d),c.labelY=oe(s,d),r[h]=[s,d]),pe[a]=1,!0};if(v([p+$*_[f]/2,m,g,m,g,w-b*S[u]/2],2)||v([p,m+b*S[f]/2,p,w,g-$*_[u]/2,w],2)||me>Dw/8)continue;let k=[];for(let e of E[f]<E[u]?[E[u],E[f]]:[E[f],E[u]]){let t=Math.max(d[e]-14,Math.min(d[e]/2,6));for(let r of[X[e]+t,X[e+1]-t]){if(Math.abs(r-p)<_[f]/2+4||Math.abs(r-g)<_[u]/2+4)continue;let t=[p+Math.sign(r-p)*_[f]/2,m,r,m,r,w,g+Math.sign(r-g)*_[u]/2,w],a=1e6*(s(se(t[0],t[1]),oe(t[0],t[1]),h)+s(se(t[6],t[7]),oe(t[6],t[7]),h));for(let e=2;e<t.length;e+=2){let r=se(t[e-2],t[e-1]),i=oe(t[e-2],t[e-1]),n=se(t[e],t[e+1]),s=oe(t[e],t[e+1]);a+=1e6*l(Math.min(r,n),Math.min(i,s),Math.max(r,n),Math.max(i,s),h)+Math.abs(n-r)+Math.abs(s-i)}k.push({pts:t,cost:a,lane:e})}}k.sort((e,t)=>e.cost-t.cost);for(let e of k)if(v(e.pts,1)){M[e.lane]=1;break}}}return{width:n?ie:le,height:n?le:ie,routed:pe,margins:M,work:me}},v=new Uint8Array($),k=new Uint8Array(h),A=M(v,k);for(let e=0;e<3&&A.work<=Dw/8;e++){let t=0===e?A.routed:v.map((e,t)=>e&A.routed[t]);if(t.every((e,t)=>e===v[t])&&A.margins.every((e,t)=>e===k[t]))break;v=t,k=A.margins,A=M(v,k)}return v.some((e,t)=>e&&!A.routed[t])&&(A=M(new Uint8Array($),new Uint8Array(h))),{width:A.width,height:A.height}}function Lw(e,t){let r=t.x-e.x,a=t.y-e.y,i=Math.max(e.w/2,.5),l=Math.max(e.h/2,.5);if(Math.abs(r)<i&&Math.abs(a)<l){return i-Math.abs(r)<l-Math.abs(a)?[e.x+(r<0?-i:i),t.y]:[t.x,e.y+(a<0?-l:l)]}let n=Math.min(0!==r?i/Math.abs(r):1/0,0!==a?l/Math.abs(a):1/0);return[e.x+r*n,e.y+a*n]}var Ow="__swimlane_default__";var Fw={type:"swimlane",prepare:function(e){let t=!1;for(let r of e.nodes)r.isGroup?r.dir=void 0:void 0===r.parentId&&(t=!0);if(t){for(let t of e.nodes)!t.isGroup&&void 0===t.parentId&&(t.parentId=Ow);e.nodes.push({id:Ow,label:void 0,labelType:"text",shape:"rect",isGroup:!0,parentId:void 0,cssStyles:[],cssCompiledStyles:[],cssClasses:"",dir:void 0})}},layout:(e,t,r,a,i)=>Rw(e,t,r,a,i?12:void 0),drawGroup:function(e,t,r,a,i,l,n){let s=e.x-e.w/2,o=e.y-e.h/2,h="LR"===l||"RL"===l,c=h?s+e.padTop/2:e.x,d=h?e.y:o+e.padTop/2,f=Fe(t,c,d,` class="pele-cluster-label"${xt(r,"var(--_m)")}${r.text}`,n);return`<g class="pele-cluster pele-lane${a}" data-id="${i}"><rect x="${Oe(s)}" y="${Oe(o)}" width="${Oe(e.w)}" height="${Oe(e.h)}" fill="none" stroke="var(--_b)"/><rect x="${Oe(s)}" y="${Oe(o)}" width="${Oe(h?e.padTop:e.w)}" height="${Oe(h?e.h:e.padTop)}" fill="var(--_a)" stroke="var(--_b)"${r.shape}/>`+(h&&f?`<g transform="rotate(-90 ${Oe(c)} ${Oe(d)})">${f}</g>`:f)+"</g>"},filledBox:function(e,t){let r=e.x-e.w/2,a=e.y-e.h/2;return"LR"===t||"RL"===t?[r,a,r+e.padTop,a+e.h]:[r,a,r+e.w,a+e.padTop]}},zw={type:"swimlane",math:!0,parse:Sd.parse,render:(e,t,r)=>_d(e,t,r,Fw)},Ww=class{type="timeline";title;accTitle;accDescr;direction="LR";sections=[];periods=[];currentSection="";getCommonDb(){return this}setDiagramTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}setDirection(e){this.direction=e}addSection(e){this.currentSection=e,this.sections.push(e)}addTask(e,t,r){this.periods.push({text:e,events:r?[r]:[],section:this.currentSection,sectionIndex:this.sections.length-1})}addEvent(e){let t=this.periods[this.periods.length-1];if(!t)throw new i("An event needs a time period before it.","semantic",{type:"timeline"});t.events.push(e)}},Pw=["$end","EOF","INVALID","NEWLINE","timeline","timeline_lr","timeline_td","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","section","period","event"];function Bw(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l={types:r,texts:a,starts:i},n=0,s=(t,l)=>{r.push(t),a.push(e.slice(n,l)),i.push(n),n=l};for(;n=ep(e,n),!(n>=t);){let r=e.charCodeAt(n),a=n+1;if(10!==r){if(Ju(e,n,"timeline")){for(a=n+8;32===e.charCodeAt(a)||9===e.charCodeAt(a);)a++;let t=Ju(e,a,"lr");if(a>n+8&&(t||Ju(e,a,"td"))&&!Q(e.charCodeAt(a+2))){s(t?5:6,a+2);continue}if(!Q(e.charCodeAt(n+8))){s(4,n+8);continue}}if(Ju(e,n,"title")){for(a=n+5;10!==e.charCodeAt(a)&&q(e.charCodeAt(a));)a++;if(a===t||10===e.charCodeAt(a)){n=a;continue}let r=e.charCodeAt(n+5);if(13!==r&&q(r)){s(7,Qu(e,n+6));continue}}if(a=rp(e,n,l,8),a===n){if(Ju(e,n,"section")&&q(e.charCodeAt(n+7))){for(a=n+8;a<t&&58!==e.charCodeAt(a)&&10!==e.charCodeAt(a);)a++;if(a>n+8){s(13,a);continue}}if(58===r){if(q(e.charCodeAt(n+1))){for(a=n+2;a<t;a++){let t=e.charCodeAt(a);if(10===t||58===t&&q(e.charCodeAt(a+1)))break}if(a>n+2){s(15,a);continue}}s(2,n+1)}else{a=n+1;for(let r=e.charCodeAt(a);a<t&&35!==r&&58!==r&&10!==r;r=e.charCodeAt(++a));s(14,a)}}else n=a}else{for(;10===e.charCodeAt(a);)a++;s(3,a)}}return(0===i.length||i[i.length-1]<t)&&s(1,t),s(0,t),l}(e),l=(t,a)=>{let l=0===r[t]?"1":Pw[r[t]];throw c("timeline",e,i[t],`Expecting ${a}, got '${l}'`)},n=r[0];4!==n&&5!==n&&6!==n&&l(0,"'timeline', 'timeline_lr', 'timeline_td'"),4!==n&&t.setDirection(5===n?"LR":"TD");for(let e=1;;e++){let i=a[e];switch(r[e]){case 3:break;case 7:t.getCommonDb().setDiagramTitle(i.substring(6));break;case 8:t.getCommonDb().setAccTitle(a[++e].trim());break;case 10:t.getCommonDb().setAccDescription(a[++e].trim());break;case 12:t.getCommonDb().setAccDescription(i.trim());break;case 13:t.addSection(i.substring(8));break;case 14:t.addTask(i,0,"");break;case 15:t.addEvent(i.substring(2));break;case 1:return;default:l(e,"'EOF', 'SPACE', 'NEWLINE', 'title', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'section', 'period', 'event'")}}}var Hw=20,Yw=20,Gw=' fill="none" stroke="var(--_b)"';function Uw(e,t,r,a,i){return`<rect x="${Oe(e)}" y="${Oe(t)}" width="${Oe(r)}" height="${Oe(a)}"${Ai(i)}/>`}function qw(e,t,r,a){let i=r.fontSize??16,l=Math.round(.875*i),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8,o=!0!==t.timeline?.disableMulticolor,h=e.periods,c=e.sections.length>0,d=e.sections.map((e,t)=>({section:t,periods:[]})),f={section:-1,periods:[]};h.forEach((e,t)=>(d[e.sectionIndex]??f).periods.push(t)),f.periods.length>0&&d.unshift(f);let u=a&&void 0!==r.maxWidth&&r.maxWidth>0?r.maxWidth-2*s:1/0,p=Math.min(152,Math.max(80,Math.round(.38*(u-96)))),g=Math.min(264,Math.max(110,u-96-p)),m=p,y=()=>a?g:m,x=h.map(e=>Iu(e.text,n,i,m)),w=h.map(e=>e.events.map(e=>Iu(e,n,l,y()))),$=0;for(let e of x)$=Math.max($,e.width);if(!a)for(let e of w)for(let t of e)$=Math.max($,t.width);let b=$>m;if(a)for(let e of w)for(let t of e)b||=t.width>g;b&&(m=Math.min(Math.max(Math.ceil($),p),u===1/0?216:p),x=h.map(e=>Nu(e.text,n,i,m)),w=h.map(e=>e.events.map(e=>Nu(e,n,l,y()))));let M=Math.round(1.5*i),v=m+24,k=y()+24,A=e=>Math.max(e.height,M)+16,T=e=>Math.max(e.height,Math.round(1.5*l))+16,C=(e,t)=>e.section>=0?e.section:c?void 0:o?t:0,E=(e,t)=>{let r=C(e,t);return void 0===r?"var(--_m)":zi(r)},_=e=>(void 0===e?"":St(e))||' fill="var(--_bg)"',S=!1;for(let e of w)e.length>0&&(S=!0);let I=0;for(let e of d)I+=Math.max(e.periods.length,1);let N,D=v+Hw,R=h.length>0,L=a?v+(S?48+k:R?32:0):I>0?I*D-Hw+(R?20:0):0,O=Nu(e.title,n,i,Math.max(L,320),1),F=O.height>0?O.height+16:0,z=Math.max(L,O.width),W=s+(z-L)/2,P=s+F,B=(t,r)=>Nu(e.sections[t.section],n,i,r-24,1),H=(e,t,r,a,i,l)=>Uw(r,a,i,l,` fill="${zi(e.section)}"`)+Fe(t,r+i/2,a+l/2,' font-weight="var(--_hw)"'+_(e.section)),Y=(e,t,r,a,i,l)=>Uw(a,i,v,l,` fill="${r}"`)+Fe(x[e],a+v/2,i+l/2,_(C(t,e))),G=(e,t,r,a,i)=>'<g class="pele-node pele-event">'+Uw(r,a,k,i,` fill="${t}" fill-opacity="0.16"`)+Fe(e,r+k/2,a+i/2,` font-size="${l}"`)+"</g>",U=(e,t,r)=>`<circle class="pele-dot" cx="${Oe(e)}" cy="${Oe(t)}" r="4" fill="${r}" stroke="var(--_bg)" stroke-width="2"/>`,q=t=>t.section>=0?`<g class="pele-cluster pele-section" data-id="${Re(e.sections[t.section].trim())}">`:"",j=e=>`<g class="pele-node pele-period" data-id="${Re(h[e].text.trim())}">`,V="";if(a){let e=W+v+Yw,t=e+14,r=t+14,a=P;for(let i of d){if(V+=q(i),i.section>=0){let e=B(i,L),t=A(e);V+=H(i,e,W,a,L,t),a+=t+8+4}for(let l of i.periods){let n=E(i,l),s=A(x[l]),o=w[l].length>0?T(w[l][0]):s,h=a+Math.max(s,o)/2,c=`M${Oe(W+v)},${Oe(h)}H${Oe(e)}`,d="",f=h-o/2,u=h;for(let e of w[l]){let a=T(e);u=f+a/2,c+=`M${Oe(t)},${Oe(u)}H${Oe(r)}`,d+=G(e,n,r,f,a),f+=a+8}d&&(c+=`M${Oe(e)},${Oe(h)}H${Oe(t)}V${Oe(u)}`),V+=j(l)+Y(l,i,n,W,h-s/2,s)+`<path class="pele-edge" d="${c}"${Gw}/>`+U(e,h,n)+d+"</g>",a=Math.max(h+s/2,f-8)+Hw}0===i.periods.length&&(a+=8),i.section>=0&&(V+="</g>")}if(d.length>0&&(a-=Hw),R){let t=a+12+8;V=`<path class="pele-axis" d="M${Oe(e)},${Oe(P)}V${Oe(t-8+1)}" fill="none" stroke="var(--_l)"/>`+li("arrow_point",e,t,0,1,"var(--_l)")+V,a=t}N=a+s}else{let e=0,t=d.map(t=>{if(t.section<0)return;let r=B(t,Math.max(t.periods.length,1)*D-Hw);return e=Math.max(e,A(r)),r}),r=0;for(let e of x)r=Math.max(r,A(e));let a=P+(c?e+8:0),i=a+r+(r>0?Yw:0),l=i+Yw,n=R?i+12:P+e,o=0;if(d.forEach((s,h)=>{let c=Math.max(s.periods.length,1),d=W+o*D;V+=q(s);let f=t[h];f&&(V+=H(s,f,d,P,c*D-Hw,e)),s.periods.forEach((e,t)=>{let o=E(s,e),h=d+t*D,c=h+v/2,f=`M${Oe(c)},${Oe(a+r)}V${Oe(w[e].length>0?l:i)}`,u="",p=l;for(let t of w[e]){let e=T(t);p>l&&(f+=`M${Oe(c)},${Oe(p-8)}V${Oe(p)}`),u+=G(t,o,h,p,e),p+=e+8}n=Math.max(n,p-8),V+=j(e)+Y(e,s,o,h,a,r)+`<path class="pele-edge" d="${f}"${Gw}/>`+U(c,i,o)+u+"</g>"}),s.section>=0&&(V+="</g>"),o+=c}),R){let e=W+L;V=`<path class="pele-axis" d="M${Oe(W)},${Oe(i)}H${Oe(e-8+1)}" fill="none" stroke="var(--_l)"/>`+li("arrow_point",e,i,1,0,"var(--_l)")+V}N=n+s}let X=Math.ceil(z+2*s),K=Math.ceil(Math.max(N,2*s)),Z=Fe(O,X/2,s+O.height/2,' class="pele-title" font-weight="var(--_tw)"')+V;return{svg:Bi("timeline",X,K,i,r,e,Z),width:X,height:K,links:[]}}var jw={type:"timeline",parse(e,t,r){let a=new Ww;return a.title=r,Bw(e,a),a},render:function(e,t,r){return"TD"===e.direction?qw(e,t,r,!0):ql(r,a=>qw(e,t,r,a))}},Vw=/[─━│┃└┗├┣]/,Xw=/[└┗├┣]/,Kw=/[─━]/,Zw=/^[\s│┃]+$/,Qw=/^[\s─━│┃└┗├┣]+$/,Jw=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,e$=/^\s*%%/;function t$(e,t){let r=0;for(let a=1;a<t;a++)r=e.indexOf("\n",r)+1;return r}function r$(e,t,r){let{line:a}=h(e,t$(e,t+1));throw new i(`Line ${a}: ${r}`,"syntax",{type:"treeView",line:a})}function a$(e,t){let r=0;for(let a=0;r<e.length&&a<t;r++)a+="\t"===e[r]?4:1;return r}function i$(e){let t=new Map,r=new Map;if(!Vw.test(e))return{text:e,lineMap:t,columns:r};let a=e.split("\n"),i=-1;for(let e=0;e<a.length;e++)if("treeView-beta"===a[e].trim()){i=e;break}if(-1===i)return{text:e,lineMap:t,columns:r};let l=e=>""===e.trim()||e$.test(e)||Jw.test(e),n=[];for(let e=i+1;e<a.length;e++){let t=a[e];l(t)||Zw.test(t)||n.push(t.replace(/\t/g," "))}if(!function(e){return e.some(e=>Vw.test(e))}(n))return{text:e,lineMap:t,columns:r};let s=function(e){for(let t of e){let e=Xw.exec(t);if(e?.index&&e.index>0)return e.index}return 4}(n),o=[],h=(e,a,i)=>{o.push(e),t.set(o.length,a+1),i&&r.set(o.length,i)};for(let e=0;e<=i;e++)h(a[e],e);for(let t=i+1;t<a.length;t++){let r=a[t];if(l(r)){h(r,t);continue}if(Zw.test(r))continue;let i=r.replace(/\t/g," "),n=Xw.exec(i);if(n){let a=Math.round(n.index/s)+1,l=n.index+1;for(;l<i.length&&Kw.test(i[l]);)l++;for(;l<i.length&&" "===i[l];)l++;let o=i.slice(l).trimEnd();o||r$(e,t,"Empty node — expected a filename or directory name after the box-drawing prefix");let c=" ".repeat(a);h(c+o,t,e=>a$(r,l+Math.max(e-c.length,0)))}else{if(Qw.test(i))continue;Vw.test(i)?h(r,t):/^\s+/.test(i)?r$(e,t,"Unexpected indentation without box-drawing characters. In box-drawing format, use ├── or └── prefixes for indented nodes."):h(r,t)}}return{text:o.join("\n"),lineMap:t,columns:r}}function l$(e,t){if(e.startsWith("##",t)||e.startsWith("icon(",t))return!0;if(!e.startsWith(":::",t))return!1;let r=t+3;for(;j(e.charCodeAt(r));)r++;let a=e.charCodeAt(r);return a>=65&&a<=90||a>=97&&a<=122||95===a}var n$={name:"BARE_NAME",pattern:/(?!:::|icon\(|##)[^ \t\n\r"'](?:(?![ \t]+:::[ \t]*[A-Za-z_]|[ \t]+icon\(|[ \t]+##)[^\n\r])*/y,match:function(e,t){let r=e.charCodeAt(t);if(j(r)||10===r||13===r||34===r||39===r||e.startsWith(":::",t)||e.startsWith("icon(",t)||e.startsWith("##",t))return-1;let a=e.length,i=t+1;for(;i<a;){let t=e.charCodeAt(i);if(10===t||13===t)break;if(j(t)){let t=i+1;for(;j(e.charCodeAt(t));)t++;if(l$(e,t))break;i=t}else i++}return i}},s$=[{...vn("treeView-beta"),longer:[n$]},xc(),pn,mn(String.raw`(?!%%)[^\n\r]`),{name:"CLASS_ANNOTATION",pattern:/[ \t]+:::[ \t]*[A-Za-z_][\w-]*/y},{name:"ICON_ANNOTATION",pattern:/[ \t]+icon\([\w-]*(?::[\w-]+)?\)/y},{name:"DESC_ANNOTATION",pattern:/[ \t]+##[^\n\r]*/y},{name:"INDENTATION",pattern:/[ \t]{1,}/y},{name:"QUOTED_NAME",pattern:/"[^"]*"|'[^']*'/y},{name:"WS",pattern:/[ \t]+/y,hidden:!0},{name:"ML_COMMENT",pattern:/\%\%[^\n]*/y,hidden:!0},{name:"NL",pattern:/\r?\n/y,hidden:!0},n$];function o$(e){let t=e.length;for(;t>0&&j(e.charCodeAt(t-1));)t--;return t===e.length?e:e.slice(0,t)}function h$(e,t){switch(e){case"INDENTATION":return t?.length||0;case"QUOTED_NAME":return t.substring(1,t.length-1);case"BARE_NAME":return o$(t);case"CLASS_ANNOTATION":return t.trim().substring(3).trim();case"ICON_ANNOTATION":{let e=t.trim();return e.substring(5,e.length-1)}case"DESC_ANNOTATION":return t.trim().substring(2).trim();default:return}}var c$=class{count=1;root={id:0,level:-1,name:"/",nodeType:"directory",children:[]};stack=[this.root];addNode(e,t,r,a,i,l){let n=this.stack;for(;e<=n[n.length-1].level;)n.pop();let s={id:this.count++,level:e,name:t,nodeType:r,icon:i,cssClass:a,description:l,children:[]};n[n.length-1].children.push(s),n.push(s)}};function d$(e){let{text:t,lineMap:r,columns:a}=i$(e);try{return function(e){let t=new Dn(fn(e,s$,"treeView"),s$,"treeView"),r={$type:"TreeView",nodes:[]};for(t.expect(0);;)if(1===t.kind)r.accDescr=Sn(t.take());else if(2===t.kind)r.accTitle=_n(t.take());else{if(3!==t.kind)break;r.title=En(t.take())}for(;-1!==t.kind;){let e={$type:"TreeNode",name:""};if(7===t.kind&&(e.indent=t.take().length),8===t.kind){let r=t.take();e.name=r.substring(1,r.length-1)}else 12===t.kind?e.name=o$(t.take()):t.fail("a name");for(;;)if(4===t.kind)e.classAnnotation=h$("CLASS_ANNOTATION",t.take());else if(5===t.kind)e.iconAnnotation=h$("ICON_ANNOTATION",t.take());else{if(6!==t.kind)break;e.descAnnotation=h$("DESC_ANNOTATION",t.take())}r.nodes.push(e)}return r}(t)}catch(l){if(!(l instanceof i)||t===e)throw l;let n=r.get(l.line);if(void 0===n)throw l;let s=l.column>0?a.get(l.line)?.(l.column-1)??l.column-1:0,o=h(e,t$(e,n)+s),c=l.message.includes("\n")?l.message.indexOf("\n"):l.message.length,d=l.message.slice(c),f=function(e,t){return e.replace(/\bline\s+(\d+)\b/gi,(e,r)=>{let a=t.get(parseInt(r,10));return a?`line ${a}`:e})}(l.message.slice(0,c),new Map([[l.line,o.line]]))+(l.snippet?d.replace(l.snippet,()=>o.snippet):d);throw new i(f,l.code,{type:l.type,line:o.line,column:l.column>0?o.column:0,snippet:l.snippet?o.snippet:""})}}var f$="mermaid-treeview",u$=new Map([["folder","M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2.4 2.5h8A1.5 1.5 0 0 1 21 9v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18z"],["file","M6.5 3h7L19 8.5v11a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 5 19.5v-15A1.5 1.5 0 0 1 6.5 3zM13.5 3v5.5H19"]]);function p$(e,t){if(void 0===e||!Object.prototype.hasOwnProperty.call(e,t))return;let r=e[t];return"string"==typeof r?r:void 0}function g$(e,t){return e.includes(":")?e:u$.has(e)||!t?`${f$}:${e}`:`${t}:${e}`}function m$(e,t){if("none"!==e.icon){if(e.icon)return g$(e.icon,t.defaultIconPack);if(t.showIcons){if("file"===e.nodeType){let r=function(e,t){let r=p$(t?.filenameIcons,e);if(r)return r;let a=e.lastIndexOf(".");if(a>0){let r=e.substring(a).toLowerCase();return p$(t?.extensionIcons,r)??p$(t?.extensionIcons,r.slice(1))}}(e.name,t);if("none"===r)return;if(r)return g$(r,t.defaultIconPack)}return`${f$}:${"directory"===e.nodeType?"folder":"file"}`}}}function y$(e,t,r,a,i){let l=e.treeView?.[t];return"number"==typeof l&&l>=a&&l<=i?l:r}var x$={type:"treeView",parse:(e,t,r)=>function(e,t){let r=new c$;return function(e,t){for(let r of e.nodes){let e="number"==typeof r.indent?r.indent:0,a=r.name,i=a.endsWith("/");i&&(a=a.slice(0,-1));let l=r.iconAnnotation;t.addNode(e,a,i?"directory":"file",r.classAnnotation||void 0,void 0!==l?l||"none":void 0,r.descAnnotation||void 0)}}(e,r),{type:"treeView",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,root:r.root,count:r.count}}(d$(e),r),render:function(e,t,r){return Vl(r,a=>function(e,t,r,a){let i=r.fontSize??16,l=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),n=r.padding??8,s=function(e){let t=e=>"object"!=typeof e||null===e||Array.isArray(e)?void 0:e,r=t(e.treeView)??{};return{showIcons:!!r.showIcons,defaultIconPack:"string"==typeof r.defaultIconPack?r.defaultIconPack:"",filenameIcons:t(r.filenameIcons),extensionIcons:t(r.extensionIcons)}}(t),o=Array.isArray(r.monospace)&&r.monospace.includes("files"),h=o?` font-family="${bi}"`:"",{paddingX:c,paddingY:d,rowIndent:f,lineThickness:u}=function(e){return{paddingX:y$(e,"paddingX",5,0,100),paddingY:y$(e,"paddingY",2,0,100),rowIndent:y$(e,"rowIndent",15,0,400),lineThickness:y$(e,"lineThickness",1,.25,12)}}(t),p=0,g=e.root.children.map(e=>[e,0]);for(let e=0;a&&e<g.length;e++){let[t,r]=g[e];p=Math.max(p,r);for(let e of t.children)g.push([e,r+1])}let y=a?Math.min(f+c,Math.max(2,((r.maxWidth??320)-120)/Math.max(1,p))):f+c,x=Math.round(1.5*i)+2*d,w=i,$=Fl(e.title,!1,l,i,a?Gl(r):4e3,1),b=$.height>0?$.height+12:0,M=e=>e.some(e=>void 0!==m$(e,s)),v=[],k=new Map,A=[],T=(e,t)=>{let r=M(e);for(let a=e.length-1;a>=0;a--)A.push([e[a],t,r])};T(e.root.children,0);let C=0,E=!1,_=0;for(;A.length>0;){let[e,t,h]=A.pop(),c=t*y,f=m(e.name),u=c+(h?w+6:0),p=Math.max(40,(r.maxWidth??320)-2*n-8-u),g=("directory"===e.nodeType?1:0)|(o?4:0),$=a?$o(f,l,i,p,g):void 0,b=a&&e.description?$o(m(e.description),l,i,p,2):void 0,M=$?$.width:l.width(f,i,g);u+M>C&&(C=u+M);let S=void 0!==e.cssClass&&e.cssClass.split(/\s+/).includes("highlight");S&&(E=!0);let I=a?Math.max(x,($?.height??0)+(b?.height??0)+2*d):x,N={node:e,x:c,cy:_+(a?d+Math.max(w,$?.height??0)/2:I/2),icon:m$(e,s),text:f,labelX:u,highlighted:S,label:$,description:b,top:_,height:I};_+=I,v.push(N),k.set(e,N),T(e.children,t+1)}let S=C+16,I=C;for(let e of v){let t=e.node.description;if(!t)continue;let r=e.description?e.description.width:l.width(m(t),i,2);I=Math.max(I,(a?e.labelX:S)+r)}I=Math.max(I,$.width);let N=n+(E?4:0),D=n+b,R=Math.ceil(I+2*N),L=Math.ceil(D+_+n),O="";for(let e of v){let t=e.node.children;if(0===t.length)continue;let r=N+e.x+7,a=Math.max(r,N+e.x+y-c),i=D+k.get(t[t.length-1]).cy,l=Math.min(4,a-r),n=`M${Oe(r)},${Oe(D+e.top+e.height-2)}V${Oe(i-l)}`;l>0&&(n+=`Q${Oe(r)},${Oe(i)} ${Oe(r+l)},${Oe(i)}H${Oe(a)}`);for(let e=0;e<t.length-1&&a>r;e++)n+=`M${Oe(r)},${Oe(D+k.get(t[e]).cy)}H${Oe(a)}`;O+=`<path d="${n}"/>`}let F=.35*i,z="";for(let e of v){let t=e.node,a=D+e.cy,i="directory"===t.nodeType,l="";if(e.highlighted){let t=N+e.x-4;l+=`<rect class="pele-tree-highlight" x="${Oe(t)}" y="${Oe(D+e.top+1)}" width="${Oe(R-N+4-t)}" height="${Oe(e.height-2)}" fill="var(--_c)" fill-opacity="0.14"${Mi}/>`}if(void 0!==e.icon){let t=e.icon.startsWith(f$+":")?e.icon.slice(17):"",n=u$.get(t)??u$.get(i?"folder":"file"),s=r.icons?.(e.icon)??`<path d="${n}" stroke="var(--_m)" stroke-width="1.5"/>`;l+=`<svg class="pele-icon" data-icon="${Re(e.icon)}" x="${Oe(N+e.x)}" y="${Oe(a-w/2)}" width="${Oe(w)}" height="${Oe(w)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${s}</svg>`}e.label?l+=Mo(e.label,N+e.labelX,D+e.top+d,` class="pele-label"${i?' font-weight="var(--_hw)"':""}${h}`):""!==e.text&&(l+=`<text class="pele-label" x="${Oe(N+e.labelX)}" y="${Oe(a+F)}"${i?' font-weight="var(--_hw)"':""}${h} xml:space="preserve">${De(e.text)}</text>`),e.description?l+=Mo(e.description,N+e.labelX,D+e.top+d+(e.label?.height??0),' class="pele-tree-description" font-style="italic" fill="var(--_m)"'):t.description&&(l+=`<text class="pele-tree-description" x="${Oe(N+S)}" y="${Oe(a+F)}" font-style="italic" fill="var(--_m)" xml:space="preserve">${De(m(t.description))}</text>`),z+=`<g class="pele-node pele-tree-${i?"dir":"file"}${Oi(t.cssClass??"")}" data-id="${Re(t.name)}">${l}</g>`}let W=Fe($,R/2,n+$.height/2,' class="pele-title" font-weight="var(--_tw)"')+(O?`<g class="pele-tree-guides" fill="none" stroke="var(--_b)" stroke-width="${Oe(u)}">${O}</g>`:"")+z;return{svg:Bi("treeView",R,L,i,r,e,W),width:R,height:L,links:[]}}(e,t,r,a))}};function w$(e){let t=[],r=[];for(let a of e){let e="Leaf"===a.type,i={name:a.name,children:e?void 0:[]};for(i.classSelector=a.classSelector,a.cssCompiledStyles&&(i.cssCompiledStyles=a.cssCompiledStyles),e&&void 0!==a.value&&(i.value=a.value);r.length>0&&r[r.length-1].level>=a.level;)r.pop();0===r.length?t.push(i):r[r.length-1].node.children.push(i),e||r.push({node:i,level:a.level})}return t}var $$=[un,pn,mn(String.raw`\w`),{name:"TREEMAP_KEYWORD",pattern:/treemap-beta|treemap/y},{name:"CLASS_DEF",pattern:/classDef\s+([a-zA-Z_][a-zA-Z0-9_]+)(?:\s+([^;\r\n]*))?(?:;)?/y},{name:"STYLE_SEPARATOR",pattern:/:::/y},{name:"SEPARATOR",pattern:/:/y},{name:"COMMA",pattern:/,/y},{name:"INDENTATION",pattern:/[ \t]{1,}/y},{name:"WS",pattern:/[ \t]+/y,hidden:!0},{name:"ML_COMMENT",pattern:/\%\%[^\n]*/y,hidden:!0},{name:"NL",pattern:/\r?\n/y,hidden:!0},{name:"ID2",pattern:/[a-zA-Z_][a-zA-Z0-9_]*/y},{name:"NUMBER2",pattern:/[0-9_\.\,]+/y},{name:"STRING2",pattern:/"[^"]*"|'[^']*'/y}],b$=/classDef\s+([A-Z_a-z]\w+)(?:\s+([^\n\r;]*))?;?/;var M$=/^(?:.?[<>=^])?([-+( ])?(\$)?0?\d*(,)?(?:\.(\d+))?(~)?([a-zA-Z%])?$/;function v$(e){let t="";for(let r=e.length;r>0;r-=3)t=e.slice(Math.max(0,r-3),r)+(t?","+t:"");return t}function k$(e,t,r){return{node:e,parent:t,series:r,value:void 0===e.children&&Number.isFinite(e.value)&&e.value>0?e.value:0,children:[],headed:!1,header:0,x:0,y:0,w:0,h:0}}var A$=(e,t,r)=>e>=t?Math.min(e,r):t;function T$(e,t,r,a){let i=e.map((e,t)=>k$(e,void 0,t)),l=i.slice();for(let e=0;e<l.length;e++){let t=l[e];for(let e of t.node.children??[]){let r=k$(e,t,t.series);t.children.push(r),l.push(r)}}for(let e=l.length-1;e>=0;e--){let t=l[e];t.parent&&(t.parent.value+=t.value)}let{gap:n,header:s,short:o,side:h}=a,c=[],d=(e,t,r,a,i)=>{let l=e.filter(e=>e.value>0).sort((e,t)=>t.value-e.value),s=0;for(let e of l)s+=e.value;if(0!==l.length&&Number.isFinite(s)){a=Math.max(0,a),i=Math.max(0,i),a>0&&i>0&&function(e,t,r,a,i,l,n){let s=t,o=0;for(;o<e.length;){let t=i*l/s,h=Math.min(i,l),c=e[o].value*t,d=c,f=Math.max(h*h*d/(c*c),c*c/(h*h*d)),u=o+1;for(;u<e.length;){let r=e[u].value*t,a=c+r,i=Math.max(h*h*d/(a*a),a*a/(h*h*r));if(i>f)break;f=i,c=a,u++}let p=c/h,g=0;for(let c=o;c<u;c++){let o=e[c],d=c===u-1?h-g:o.value*t/p,f=i>=l?r:r+g,m=i>=l?a+g:a,y=i>=l?p:d,x=i>=l?d:p,w=Math.round(f+y-n/2)>Math.round(f+n/2)?n/2:0,$=Math.round(m+x-n/2)>Math.round(m+n/2)?n/2:0;o.x=Math.round(f+w),o.y=Math.round(m+$),o.w=Math.round(f+y-w)-o.x,o.h=Math.round(m+x-$)-o.y,g+=d,s-=o.value}i>=l?(r+=p,i-=p):(a+=p,l-=p),o=u}}(l,s,t-n/2,r-n/2,a+n,i+n,n);for(let e of l){let l=A$(e.x,t,t+a),n=A$(e.y,r,r+i);e.w=A$(e.x+e.w,l,t+a)-l,e.h=A$(e.y+e.h,n,r+i)-n,e.x=l,e.y=n,c.push(e)}}};d(i,0,0,t,r);for(let e=0;e<c.length;e++){let t=c[e];if(0===t.children.length)continue;let r=t.h-s-h>=12?s:o;t.headed=t.w>Math.max(24,2*h)&&t.h-r-h>=8,t.header=t.headed?r:0,t.headed?d(t.children,t.x+h,t.y+r,t.w-2*h,t.h-r-h):d(t.children,t.x,t.y,t.w,t.h)}return c}var C$=1.25,E$=e=>De(m(e).trim()).trim();function _$(e,t){let r=Math.min(t.w,t.h)/4;return r<4?Ai(e).replace("rx:var(--_r)",`rx:min(var(--_r),${Oe(r)}px)`):Ai(e)}function S$(e,t,r,a,i){let l=e.treemap?.[t];return"number"==typeof l&&l>=a?Math.min(l,i):r}var I$={type:"treemap",parse:(e,t,r)=>function(e,t){let r=new Map;for(let t of e.TreemapRows){if("ClassDefStatement"!==t.$type)continue;let e=r.get(t.className);e||r.set(t.className,e=[]);let a=(t.styleText??"").replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",");for(let t of a.split(";"))e.push(t)}let a=[];for(let t of e.TreemapRows){if("TreemapRow"!==t.$type)continue;let e=t.item,i=e.classSelector?r.get(e.classSelector):void 0;a.push({level:t.indent??0,name:e.name,type:e.$type,value:"Leaf"===e.$type?e.value:void 0,classSelector:e.classSelector,cssCompiledStyles:i&&i.length>0?i:void 0})}return{type:"treemap",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,roots:w$(a),classes:r}}(function(e){let t=new Dn(fn(e,$$,"treemap"),$$,"treemap"),r=t.kinds,a={$type:"Treemap",TreemapRows:[]},i=()=>t.accept(5)?t.expect(12):void 0;for(t.expect(3);-1!==t.kind;){let e=t.kind;if(0===e){a.accDescr=Sn(t.take());continue}if(1===e){a.accTitle=_n(t.take());continue}if(2===e){a.title=En(t.take());continue}8!==e&&14!==e&&4!==e&&t.fail("a node, a class definition, or a title");let l=8===e?t.take().length:void 0;if(4===t.kind){let e=b$.exec(t.take()),r={$type:"ClassDefStatement",className:e[1]};e[2]&&(r.styleText=e[2]),void 0!==l&&(r.indent=l),a.TreemapRows.push(r);continue}let n,s=t.expect(14).slice(1,-1),o=8===r[t.i]?t.i+1:t.i;6===r[o]||7===r[o]?(t.i=o+1,t.accept(8),n={$type:"Leaf",name:s,value:parseFloat(t.expect(13).replace(/,/g,""))}):n={$type:"Section",name:s};let h=i();void 0!==h&&(n.classSelector=h);let c={$type:"TreemapRow",item:n};void 0!==l&&(c.indent=l),a.TreemapRows.push(c)}return a}(e),r),render:function(e,t,r){let a=r.fontSize??16,i=Math.round(.875*a),l=Math.round(.75*a),n=Math.round(.5625*a),s=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),o=t.treemap??{},h=r.padding??S$(t,"diagramPadding",8,0,2e3),c=Math.round(Ul(r,10*S$(t,"nodeWidth",64,1,400),200,2*h)),d=Math.round(10*S$(t,"nodeHeight",40,1,400)),f=!1!==o.showValues,u=function(e){let t=M$.exec("$0,0"===e?"$,":e)??M$.exec(","),r="+"===t[1],a=void 0!==t[3],i=void 0===t[4]?void 0:Math.min(Number(t[4]),20),l=t[6]??"";return e=>{let n,s=Math.abs(e),o="";if("f"===l?n=s.toFixed(i??6):"%"===l?(n=(100*s).toFixed(i??6),o="%"):n="d"===l?Math.round(s).toFixed(0):"e"===l?s.toExponential(i??6):String(Number(s.toPrecision(Math.max(1,i??12)))),t[5]&&n.includes(".")&&!n.includes("e")&&(n=n.replace(/\.?0+$/,"")),a&&!n.includes("e")){let e=n.indexOf(".");n=-1===e?v$(n):v$(n.slice(0,e))+n.slice(e)}return(e<0?"-":r?"+":"")+(t[2]??"")+n+o}}("string"==typeof o.valueFormat?o.valueFormat:","),p=Math.min(1,Math.max(0,Math.log10(c*d/Math.max(1,function(e){let t=0,r=e.slice();for(;r.length>0;){let e=r.pop();void 0!==e.children?r.push(...e.children):Number.isFinite(e.value)&&e.value>0&&t++}return t}(e.roots))/800))),g=T$(e.roots,c,d,{gap:S$(t,"padding",Math.round(2+2*p),0,200),header:28,short:18,side:Math.round(3+3*p)}),y=Fl(e.title,!1,s,a,Gl(r),1),x=y.height>0?y.height+8:0,w=h+Math.max(0,(y.width-c)/2),$=h+x,b="",M="";for(let e of g){let t=e.node,r=Ri(t.cssCompiledStyles??[]),o=zi(e.series),h=w+e.x,c=$+e.y,d=m(t.name).trim(),p=f?u(e.value):"",g=`data-id="${Re(t.name)}">`,y=E$(t.name),x=""===y?[]:[y];for(let t=e.parent;void 0!==t&&!t.headed;t=t.parent){let e=E$(t.node.name);""!==e&&x.unshift(e)}let v=x.join(" › "),k=e=>""===v||e===d&&v===y?"":`<title>${v}</title>`,A=`<rect x="${Oe(h)}" y="${Oe(c)}" width="${Oe(e.w)}" height="${Oe(e.h)}" fill="${o}"`,T=r.fontSize,C=(r.bold?1:0)|(r.italic?2:0),E=ki(r.shape)?xt(r):St(e.series);if(void 0!==t.children){let a,n="";if(e.headed){let t=e.header<28,o=T??(t?l:i),f=T??l,u=e.w-12-4,g=p?s.width(p,f,C):0,m=!t&&g>0&&u-g-12>=3*o,y=o*C$<e.header?tg(d,m?u-g-12:u,o,o,s,1|C):void 0,x=c+e.header/2+1;a=y?.text,y&&(n+=`<text x="${Oe(h+6+2)}" y="${Oe(x+.35*o)}" font-weight="var(--_hw)"${t?` font-size="${o}"`:""}${E}${r.text}>${De(y.text)}</text>`),m&&f*C$<=28&&(n+=`<text class="pele-value" x="${Oe(h+e.w-6-2)}" y="${Oe(x+.35*f)}" font-size="${l}" text-anchor="end"${E||' fill="var(--_m)"'}${r.text}>${De(p)}</text>`)}let f=/[";]fill:/.test(r.shape)?"":' fill-opacity="0.12"',u=e.headed?`${A}${_$(`${f} stroke="${o}"${r.shape}`,e)}/>`:`<rect x="${Oe(h)}" y="${Oe(c)}" width="${Oe(e.w)}" height="${Oe(e.h)}" fill="none"/>`;b+=`<g class="pele-node pele-section${Oi(t.classSelector??"")}" ${g}${k(a)}${u}${n}</g>`;continue}let _="",S=e.w-8,I=T??n,N=void 0===T?Math.min(a,Math.floor((e.h-4)/C$)):T*C$<=e.h-4?T:0,D=N>=I?tg(d,S,N,I,s,C):void 0;if(D){let t=Oe(h+e.w/2),a=c+e.h/2,i=T??Math.max(n,Math.round(.8*D.size)),l=(D.size+i)*C$;if(p&&l<=e.h-4&&s.width(p,i,C)<=S){let e=a-l/2+D.size*C$/2,n=a+l/2-i*C$/2;_=`<text x="${t}" y="${Oe(e+.35*D.size)}" font-size="${Oe(D.size)}"${E}${r.text}>${De(D.text)}</text><text class="pele-value" x="${t}" y="${Oe(n+.35*i)}" font-size="${Oe(i)}"${E}${r.text}>${De(p)}</text>`}else _=`<text x="${t}" y="${Oe(a+.35*D.size)}" font-size="${Oe(D.size)}"${E}${r.text}>${De(D.text)}</text>`}M+=`<g class="pele-node pele-leaf${Oi(t.classSelector??"")}" ${g}${k(D?.text)}${A}${_$(r.shape,e)}/>${_}</g>`}let v=Math.ceil(Math.max(c,y.width)+2*h),k=Math.ceil(d+x+2*h);return{svg:Bi("treemap",v,k,a,r,e,Fe(y,v/2,h+y.height/2,' class="pele-title" font-weight="var(--_tw)"')+(b?`<g class="pele-sections" font-size="${i}">${b}</g>`:"")+(M?`<g class="pele-leaves" text-anchor="middle" fill="var(--_bg)">${M}</g>`:"")),width:v,height:k,links:[]}}},N$="EOF USECASE ACTOR SYSTEM_BOUNDARY END DIRECTION TD TB BT LR RL NOTE FOR JSON CLASS_DEF CLASS STYLE INCLUDE EXTEND TRUE FALSE IDENTIFIER NUMBER AT COMMA COLON HASH_COLOR CSS_IDENTIFIER CSS_ESCAPED_COMMA DASH DOT PERCENT CSS_PUNCTUATION LABEL_PUNCTUATION LABEL_SYMBOL PLAIN_STRING MARKDOWN_STRING UNCLOSED_MARKDOWN_STRING COMMENT NEWLINE ACC_DESCR_BLOCK ACC_TITLE_LINE ACC_DESCR_LINE JSON_DECLARATION_START JSON_OBJECT_LITERAL UNCLOSED_JSON_OBJECT_LITERAL GENERALIZATION DEPENDENCY_ARROW STEREOTYPE_START STEREOTYPE_END STEREOTYPE_TEXT UNCLOSED_STEREOTYPE_TEXT CLASS_SEPARATOR FORWARD_SOLID BACKWARD_SOLID FORWARD_CIRCLE BACKWARD_CIRCLE FORWARD_CROSS BACKWARD_CROSS MARKERLESS_SOLID METADATA_START LBRACE RBRACE LBRACKET RBRACKET LPAREN RPAREN".split(" "),D$=new Uint8Array(128);for(let e=48;e<=57;e++)D$[e]=1;for(let e=65;e<=90;e++)D$[e]=D$[e+32]=1;D$[95]=1;for(let e of"!#$&*+/=?^|~")D$[e.charCodeAt(0)]=2;var R$=[0,12,5,14,3,9,2,2,2,2,2,4,3,4,8,5,5,7,6,4,5];function L$(e){return e<128&&!!(1&D$[e])}function O$(e,t,r){for(let a=0;a<r.length;a++)if((32|e.charCodeAt(t+a))!==r.charCodeAt(a))return!1;return!0}function F$(e,t,r){switch(r){case 97:return e.startsWith("actor",t)?2:0;case 115:return e.startsWith("systemBoundary",t)?3:e.startsWith("style",t)?16:0;case 101:return e.startsWith("end",t)?4:O$(e,t,"extend")?18:0;case 69:return O$(e,t,"extend")?18:0;case 100:return e.startsWith("direction",t)?5:0;case 84:return e.startsWith("TD",t)?6:e.startsWith("TB",t)?7:0;case 66:return e.startsWith("BT",t)?8:0;case 76:return e.startsWith("LR",t)?9:0;case 82:return e.startsWith("RL",t)?10:0;case 110:return e.startsWith("note",t)?11:0;case 102:return e.startsWith("for",t)?12:e.startsWith("false",t)?20:0;case 106:return e.startsWith("json",t)?13:0;case 99:return e.startsWith("classDef",t)?14:e.startsWith("class",t)?15:0;case 105:case 73:return O$(e,t,"include")?17:0;case 116:return e.startsWith("true",t)?19:0;case 117:return e.startsWith("usecase-beta",t)?1:0;default:return 0}}function z$(e,t){[e,t]=o(e,t);let r=1,a=0;for(let i=0;i<t;i++){let l=e.charCodeAt(i);10!==l&&13!==l||(13===l&&i+1<t&&10===e.charCodeAt(i+1)&&i++,r++,a=i+1)}return[r,t-a+1]}function W$(e,t,r){let[a,i]=z$(e,t);return`line ${a}, column ${i} [${o(e,t)[1]},${o(e,r)[1]})`}function P$(e,t,r){for(let a=t+1;a<e.length;a++){let t=e.charCodeAt(a);if(t===r)return a+1;if(10===t||13===t)return-1}return-1}function B$(e,t){let r=e.charCodeAt(t);return 34!==r&&39!==r||(34===r&&96===e.charCodeAt(t+1)||-1!==P$(e,t,r))}function H$(e,t,r){let[a,l]=z$(e,t),[n,s]=[o(e,t)[1],o(e,t+r)[1]];return new i(`Error lexing usecase diagram: unexpected character: ->${e.charAt(t)}<- at offset: ${n}, skipped ${s-n} characters. at line ${a}, column ${l} [${n},${s})`,"syntax",{type:"usecase",line:a,column:l})}function Y$(e,t){if(0===t.length)return;let r=new Set(e);for(let a of t)r.has(a)||(r.add(a),e.push(a))}function G$(e){let t=new Set(["actor","usecase","boundary","edge"]);for(let{key:r,value:a}of e)if("icon"===r)t.clear(),t.add("actor");else if("animate"===r||"animation"===r)t.clear(),t.add("edge");else if("type"===r)t.clear(),"rect"===a||"package"===a?t.add("boundary"):("normal"===a||"hollow"===a||"awesome"===a)&&t.add("actor");else{if("business"!==r)return;t.delete("boundary"),t.delete("edge")}return 1===t.size?[...t][0]:void 0}function U$(e,t,r,a,l){let n={type:"usecase",actors:new Map,useCases:new Map,systemBoundaries:new Map,relationships:[],notes:new Map,jsonNodes:new Map,classDefs:new Map,direction:"LR",title:void 0,accTitle:"",accDescr:"",accDescription:"",source:"",headerSpan:[0,0],statements:[]},{actors:s,useCases:o,systemBoundaries:h}=n,c=new Map,d=new Map,f=new Map,u=new Map,p=new Map,g=t=>W$(e,t[0],t[1]),m=(t,r)=>{let[a,l]=z$(e,r[0]);return new i(t,"semantic",{type:"usecase",line:a,column:l})},y=(e,t)=>{throw m(`${e} at ${g(t)}`,t)},x=(e,t,r,a,i)=>{let l=e=>void 0===e?"":` (label "${e}")`;throw m(`${e} at ${g(t)}${l(a)}; previous declaration at ${g(r)}${l(i)}`,t)},w=(e,t,r)=>y(`Metadata property '${r.key}' is invalid for ${t} '${e}'`,r.keySpan),$=(e,t)=>{let r=p.get(e);(void 0===r||t<r)&&p.set(e,t)},b=e=>[...e].sort((e,t)=>(p.get(e.id)??0)-(p.get(t.id)??0)),M=(e,t)=>{c.set(e.id,{kind:t,span:e.span,generated:e.generated,label:e.label.text})},v=(e,t)=>{let r=c.get(e.id);if(!r)return;let a=e.generated?e.label.text:void 0,i=r.generated?r.label:void 0;r.kind!==t&&x(`ID '${e.id}' is declared as both ${r.kind} and ${t}`,e.span,r.span,a,i),(r.generated||e.generated)&&x(`Generated ID '${e.id}' collides with another declaration`,e.span,r.span,a,i)},k=(e,t,r)=>{let a=c.get(e);a&&x(`ID '${e}' is declared more than once (${a.kind} and ${t})`,r,a.span,void 0,a.generated?a.label:void 0),c.set(e,{kind:t,span:r,generated:!1})},A=(e,t,r)=>{let{key:a,value:i}=t,l=l=>{!r&&void 0!==l&&l!==i&&x(`Actor '${e.id}' has conflicting ${a} metadata`,t.keySpan,e.span)};"type"!==a||"normal"!==i&&"hollow"!==i&&"awesome"!==i?"icon"===a&&"string"==typeof i?(l(e.icon),e.icon=i):"business"===a&&"boolean"==typeof i?(l(e.business),e.business=i):w(e.id,"actor",t):(l(e.actorType),e.actorType=i)},T=(e,t,r)=>{for(let a of t??[])"actor"===e.kind?A(e,a,r):"business"===a.key&&"boolean"==typeof a.value?(!r&&void 0!==e.business&&e.business!==a.value&&x(`Use case '${e.id}' has conflicting business metadata`,a.keySpan,e.span),e.business=a.value):w(e.id,"usecase",a)},C=e=>{let t;if("actor"===e.kind){o.delete(e.id);let r={id:e.id,label:e.label.text,labelType:e.label.type,business:e.business??!1,classes:[...e.classes],type:e.icon?"icon":e.actorType??"normal",styles:s.get(e.id)?.styles??[]};e.icon&&(r.icon=e.icon),s.set(e.id,r),t=r}else s.delete(e.id),t={id:e.id,label:e.label.text,labelType:e.label.type,business:e.business??!1,classes:[...e.classes],shape:e.shape??"ellipse",styles:o.get(e.id)?.styles??[]},o.set(e.id,t);e.stereotype&&(t.stereotype=e.stereotype),e.parent?.id&&(t.parentId=e.parent.id)},E=e=>{v(e,e.kind);let t=e.parent?.id?e.parent:void 0,r=d.get(e.id);if(!r){let r={kind:e.kind,id:e.id,label:e.label,span:e.span,generated:e.generated,classes:[...e.classes],parent:t,shape:e.shape,stereotype:e.stereotype,stereotypeSpan:e.stereotype?e.span:void 0};return T(r,e.metadata,!1),d.set(e.id,r),void M(e,e.kind)}(r.label.text!==e.label.text||r.label.type!==e.label.type)&&x(`ID '${e.id}' has conflicting labels`,e.span,r.span),e.shape&&r.shape&&e.shape!==r.shape&&x(`Use case '${e.id}' has conflicting shapes`,e.span,r.span),t&&r.parent?.id&&t.id!==r.parent.id&&x(`Element '${e.id}' belongs to more than one system boundary`,t.span,r.parent.span),e.stereotype&&r.stereotype&&e.stereotype!==r.stereotype&&x(`Element '${e.id}' has conflicting stereotypes`,e.span,r.stereotypeSpan??r.span),r.shape??=e.shape,r.parent??=e.parent,r.stereotype??=e.stereotype,r.stereotypeSpan??=e.stereotype?e.span:void 0,Y$(r.classes,e.classes),T(r,e.metadata,!1)},_=e=>{v(e,"boundary");let t=f.get(e.id);if(t)return(t.label.text!==e.label.text||t.label.type!==e.label.type)&&x(`Boundary '${e.id}' has conflicting titles`,e.span,t.span),void Y$(t.classes,e.classes);f.set(e.id,{...e,classes:[...e.classes],members:[]}),M(e,"boundary")},S=e=>{e.classed&&!e.declares&&y(`Relationship endpoint '${e.id}' uses ::: without declaring the node`,e.span);let t=c.get(e.id);return t?t.kind:(d.set(e.id,{...e,kind:"usecase",shape:"ellipse",classes:[]}),M(e,"usecase"),$(e.id,e.span[0]),"usecase")},I=(e,t)=>{let r=c.get(e)?.kind;return("actor"===r?s.get(e):"usecase"===r?o.get(e):"boundary"===r?h.get(e):"json"===r?n.jsonNodes.get(e):u.get(e))??y(`Class/style target '${e}' is unresolved or anonymous`,t)},N=[];for(let{source:e,target:r}of t.relationships)$(e.id,e.span[0]),$(r.id,r.span[0]);for(let e of t.elements)$(e.id,e.span[0]),N.push({offset:e.span[0],run:()=>E(e)});for(let e of t.boundaries)$(e.id,e.span[0]),N.push({offset:e.span[0],run:()=>_(e)});for(let e of t.jsons)$(e.id,e.span[0]),N.push({offset:e.span[0],run:()=>k(e.id,"json",e.span)});for(let{id:e,idSpan:r}of t.relationships)e&&r&&N.push({offset:r[0],run:()=>k(e,"edge",r)});N.sort((e,t)=>e.offset-t.offset);for(let e of N)e.run();for(let e of b(d.values()))C(e);for(let e of b(f.values()))h.set(e.id,{id:e.id,label:e.label.text,labelType:e.label.type,type:"rect",members:[],classes:[],styles:[]});for(let e of b(t.jsons))n.jsonNodes.set(e.id,{id:e.id,value:e.value,propertyOrder:e.propertyOrder,classes:[...e.classes],styles:[]});let D=0;for(let e of t.relationships){let{source:t,target:r,type:a}=e,i=S(t),l=S(r),s=e=>"actor"===e||"usecase"===e||"json"===e;s(i)||x(`Relationship source '${t.id}' cannot be ${i}`,t.span,c.get(t.id).span),s(l)||x(`Relationship target '${r.id}' cannot be ${l}`,r.span,c.get(r.id).span),("include"===a||"extend"===a)&&("usecase"!==i||"usecase"!==l)&&y(`${a} relationship requires use-case endpoints`,e.span),"generalization"===a&&("json"===i||i!==l)&&y("Generalization requires actor-to-actor or use-case-to-use-case endpoints",e.span),"association"===a&&("json"===i||"json"===l)&&e.arrowType>2&&y(`JSON relationship '${t.id}' to '${r.id}' permits only point, reversed-point, or markerless solid association`,e.span);let o=e.id??"edge-"+D++,h={id:o,explicitId:!!e.id,source:t.id,target:r.id,type:a,arrowType:e.arrowType,minlen:e.minlen,classes:[],styles:[],animate:!1};e.label&&(h.label=e.label.text,h.labelType=e.label.type),n.relationships.push(h),u.set(o,h)}let R=new Map(s),L=new Map(o);s.clear(),o.clear();for(let e of b(d.values())){let t=R.get(e.id),r=L.get(e.id);t?s.set(e.id,t):r?o.set(e.id,r):C(e)}for(let{target:e,span:r,properties:a,statement:i}of t.metadata){let t=c.get(e);if(!t){let t=G$(a);return y(`Metadata target '${e}' is unresolved${t?` (metadata implies ${t})`:""}`,r)}let l=t.kind;"actor"===l||"usecase"===l?T(d.get(e),a,!0):"edge"===l&&(i.kind="edgeMetadata",i.edges=[{id:e,span:i.span,idSpan:r,metadata:i.metadata}],delete i.nodes);let n=f.get(e),s=u.get(e);for(let t of"actor"===l||"usecase"===l?[]:a){let{key:r,value:a}=t;"boundary"!==l||!n||"type"!==r||"rect"!==a&&"package"!==a?"edge"===l&&s&&"animate"===r&&"boolean"==typeof a?s.animate=a:"edge"!==l||!s||"animation"!==r||"fast"!==a&&"slow"!==a?w(e,l,t):(s.animation=a,s.animate=!0):n.type=a}}for(let e of n.relationships)e.animation&&(e.animate=!0);for(let e of d.values())"actor"===e.kind?(e.icon&&e.actorType&&"normal"!==e.actorType&&y(`Actor '${e.id}' cannot combine icon with type '${e.actorType}'`,e.span),e.business&&(e.icon||"awesome"===e.actorType)&&y(`Business actor '${e.id}' must use normal or hollow geometry`,e.span)):"rect"===e.shape&&e.business&&y(`Rectangular use case '${e.id}' cannot be a business use case`,e.span),C(e);for(let e of[...t.elements].sort((e,t)=>e.span[0]-t.span[0])){if(!e.parent?.id)continue;let t=f.get(e.parent.id).members;t.includes(e.id)||t.push(e.id)}for(let e of f.values()){let t=h.get(e.id);t.type=e.type??"rect",t.members=e.members,t.classes=[...e.classes]}let O=0;for(let e of t.notes){let t=c.get(e.target);if(!t)return y(`Note target '${e.target}' is unresolved`,e.span);"actor"!==t.kind&&"usecase"!==t.kind&&x(`Note target '${e.target}' must be an actor or use case, not ${t.kind}`,e.span,t.span);let r="note-"+O++;n.notes.set(r,{id:r,target:e.target,label:e.label.text,labelType:e.label.type})}for(let e of t.classDefs)for(let t of e.ids)n.classDefs.set(t,{id:t,styles:[...e.styles]});for(let e of t.classes)for(let t of e.targets)Y$(I(t.id,t.span).classes,e.classes);for(let e of t.styles)I(e.target,e.span).styles.push(...e.styles);return n.direction=t.direction??n.direction,n.title=l,n.accTitle=t.accTitle,n.accDescription=t.accDescription,n.accDescr=t.accDescription.replace(/\n\s+/g,"\n"),n.source=e,n.headerSpan=r,n.statements=a,n}var q$=class extends Error{constructor(e){super("Invalid JSON token"),this.offset=e}offset};function j$(e){let t=new Map,r=[],a=[],i=e.length,l=0,n="",s=0,o=()=>{for(;l<i;){let t=e.charCodeAt(l);if(32!==t&&9!==t&&10!==t&&13!==t)return;l++}},h=t=>{l++;let r="";for(;l<i;){let a=l,i=e[l++];if('"'===i)return r;if(i.charCodeAt(0)<32)throw new q$(a);if("\\"!==i){t&&(r+=i);continue}let n,s=l,o=e[l++];if('"'===o||"\\"===o||"/"===o)n=o;else if("b"===o)n="\b";else if("f"===o)n="\f";else if("n"===o)n="\n";else if("r"===o)n="\r";else if("t"===o)n="\t";else{if("u"!==o)throw new q$(s);{let t=e.slice(l,l+4);if(!/^[\dA-Fa-f]{4}$/.test(t))throw new q$(l);n=String.fromCharCode(parseInt(t,16)),l+=4}}t&&(r+=n)}throw new q$(l)},c=t=>{for(let r=0;r<t.length;r++)if(e[l+r]!==t[r])throw new q$(l+r);l+=t.length},d=()=>{if(45===e.charCodeAt(l)&&l++,48===e.charCodeAt(l))l++;else{if(!X(e.charCodeAt(l)))throw new q$(l);for(;X(e.charCodeAt(l));)l++}if(46===e.charCodeAt(l)){if(l++,!X(e.charCodeAt(l)))throw new q$(l);for(;X(e.charCodeAt(l));)l++}if(101==(32|e.charCodeAt(l))){if(l++,(43===e.charCodeAt(l)||45===e.charCodeAt(l))&&l++,!X(e.charCodeAt(l)))throw new q$(l);for(;X(e.charCodeAt(l));)l++}};for(o();;)if(0===s){o();let i=e.charCodeAt(l);if(s=2,123===i){l++;let i=[];t.set(n,i),r.push(n),o(),125===e.charCodeAt(l)?l++:(a.push({object:!0,pointer:n,keys:i,ranges:new Map,key:"",from:0,index:0}),s=1)}else if(91===i)l++,o(),93===e.charCodeAt(l)?l++:(a.push({object:!1,pointer:n,keys:[],ranges:new Map,key:"",from:0,index:0}),n+="/0",s=0);else if(34===i)h(!1);else if(116===i)c("true");else if(102===i)c("false");else if(110===i)c("null");else{if(45!==i&&!X(i))throw new q$(l);d()}}else if(1===s){let i=a[a.length-1];if(34!==e.charCodeAt(l))throw new q$(l);let c=h(!0),d=i.ranges.get(c);if(void 0===d)i.keys.push(c);else for(let e=d[0];e<d[1];e++)t.delete(r[e]);if(i.key=c,i.from=r.length,o(),58!==e.charCodeAt(l))throw new q$(l);l++,n=`${i.pointer}/${c.replaceAll("~","~0").replaceAll("/","~1")}`,s=0}else{let t=a[a.length-1];if(void 0===t)break;t.object?t.ranges.set(t.key,[t.from,r.length]):t.index++,o();let i=e.charCodeAt(l);if(i===(t.object?125:93))l++,a.pop();else{if(44!==i)throw new q$(l);l++,o(),n=`${t.pointer}/${t.index}`,s=t.object?1:0}}if(o(),l!==i)throw new q$(l);return t}function V$(e,t,r,a){let i=Math.min(Math.max(t,0),e.length);for(let t=0;t<i;t++){let i=e.charCodeAt(t);13===i?(r++,a=1):10===i?(0===t||13!==e.charCodeAt(t-1))&&(r++,a=1):a++}return[r,a]}function X$(e,t,r){return new i(`${e} (line ${t}, column ${r})`,"syntax",{type:"usecase",line:t,column:r})}function K$(e,t){let r;try{r=JSON.parse(e)}catch(r){let a=r instanceof Error?r.message:String(r),i=g(e);if(i!==e)try{JSON.parse(i)}catch(e){e instanceof Error&&(a=e.message)}let[l,n]=t(),s=function(e,t,r,a){let i=/\bposition (\d+)\b/.exec(e);if(i)return V$(t,parseInt(i[1],10),r,a);let l=/\bline (\d+) column (\d+)\b/.exec(e);if(l){let e=parseInt(l[1],10),t=parseInt(l[2],10);return[r+e-1,1===e?a+t-1:t]}return/unexpected end|end of json input/i.test(e)?V$(t,t.length,r,a):void 0}(a,i,l,n);if(!s){let e=0;try{j$(i)}catch(t){t instanceof q$&&(e=t.offset)}s=V$(i,e,l,n)}throw X$(`Invalid JSON: ${a}`,s[0],s[1])}if("object"!=typeof r||null===r||Array.isArray(r)){let[e,r]=t();throw X$("JSON value must have an object root",e,r)}return{value:r,propertyOrder:j$(e)}}var Z$="DEPENDENCY_ARROW|GENERALIZATION|FORWARD_SOLID|BACKWARD_SOLID|MARKERLESS_SOLID|FORWARD_CIRCLE|BACKWARD_CIRCLE|FORWARD_CROSS|BACKWARD_CROSS",Q$="IDENTIFIER|PLAIN_STRING|MARKDOWN_STRING",J$="ACC_TITLE_LINE|ACC_DESCR_LINE|ACC_DESCR_BLOCK|DIRECTION|ACTOR|SYSTEM_BOUNDARY|NOTE|JSON_DECLARATION_START|CLASS_DEF|CLASS|STYLE",eb="WORD|PLAIN_STRING|NUMBER|HASH_COLOR|CSS_IDENTIFIER|CSS_ESCAPED_COMMA|DASH|DOT|PERCENT|CSS_PUNCTUATION|COLON|LPAREN|RPAREN|LBRACKET|RBRACKET|LBRACE|RBRACE|AT|MARKERLESS_SOLID",tb=new Uint8Array(67);function rb(e,t){for(let r of e.split("|"))if("WORD"===r)for(let e=1;e<=21;e++)tb[e]|=t;else tb[N$.indexOf(r)]|=t}rb(`NEWLINE|COMMENT|${J$}|${Q$}`,1),rb(`IDENTIFIER|${Z$}`,2),rb(eb,4),rb(`STEREOTYPE_START|CLASS_SEPARATOR|IDENTIFIER|${Z$}|NEWLINE|EOF`,8),rb(`NEWLINE|COMMENT|ACTOR|${Q$}`,16),rb("FORWARD_SOLID|MARKERLESS_SOLID|FORWARD_CIRCLE|FORWARD_CROSS",32),rb("NEWLINE|IDENTIFIER|PLAIN_STRING|RBRACE",64);var ab,ib,lb=new Set(["allowmixing","newpage","package","rectangle","skinparam"]),nb="",sb=[],ob=[],hb=[],cb=0,db=0,fb=[],ub=0,pb=0;function gb(e){return nb.slice(ob[e],hb[e])}function mb(e){return[ob[e],hb[e]]}function yb(e){let[t,r]=z$(nb,ob[cb]);throw new i(`Error parsing usecase diagram: ${e} at ${W$(nb,ob[cb],hb[cb])}`,"syntax",{type:"usecase",line:t,column:r})}function xb(e){yb(`Expecting token of type --\x3e ${e} <-- but found --\x3e '${gb(cb)}' <--`)}function wb(e){return sb[cb]!==e&&xb(N$[e]),cb++}function $b(e){yb(`Expecting: one of these possible Token sequences:\n${e.split("|").map((e,t)=>` ${t+1}. [${e}]`).join("\n")}\nbut found: '${gb(cb)}'`)}function bb(){let e=Q$.split("|"),t=e.flatMap(e=>["NEWLINE","IDENTIFIER","PLAIN_STRING","RBRACE"].map(t=>`${e}, METADATA_START, ${t}`)),r=`STEREOTYPE_START|CLASS_SEPARATOR|IDENTIFIER|${Z$}|NEWLINE|EOF`.split("|"),a=e.flatMap((e,t)=>(0===t?["LPAREN","LBRACKET",...r]:r).map(t=>`${e}, ${t}`));return[J$,...t,...a,...t].join("|")}function Mb(e){return e>=1&&e<=21}function vb(e){return e>=1&&e<=34}function kb(){db=hb[cb-1],39===sb[cb]?cb++:0!==sb[cb]&&$b("NEWLINE|EOF")}function Ab(e){let t=36===sb[e]?2:35===sb[e]?1:0;return[ob[e]+t,hb[e]-t]}function Tb(e){let t=Ab(e);return{text:nb.slice(t[0],t[1]),type:36===sb[e]?"markdown":"text",span:t}}function Cb(e){return e.replace(/\W/g,"_")}function Eb(){let e=sb[cb];if(35===e||36===e)return Tb(cb++);vb(e)||$b("PLAIN_STRING|MARKDOWN_STRING|LABEL_TEXT");let t=cb;for(;vb(sb[cb]);)cb++;let r=[ob[t],hb[cb-1]];return{text:nb.slice(r[0],r[1]),type:"text",span:r}}function _b(e){return 21===e||35===e}function Sb(){let e=cb;_b(sb[cb])||$b("IDENTIFIER|PLAIN_STRING"),cb++,wb(25);let t=cb,r=sb[cb];!_b(r)&&19!==r&&20!==r&&$b("IDENTIFIER|PLAIN_STRING|TRUE|FALSE"),cb++;let a=Ab(e),i=Ab(t);return{key:nb.slice(a[0],a[1]),value:19===r||20!==r&&nb.slice(i[0],i[1]),span:[ob[e],hb[t]],keySpan:a,valueSpan:i}}function Ib(){let e=sb[cb],t=sb[cb+1],r=sb[cb+2];return 24===e?_b(t)||39===t&&(39===r||_b(r)):39===e&&(24===t||_b(t)||39===t&&(39===r||24===r||_b(r)))}function Nb(){wb(60);let e=[];for(;39===sb[cb];)cb++;if(_b(sb[cb])){for(e.push(Sb());Ib();){if(24===sb[cb])cb++;else{for(;39===sb[cb];)cb++;24===sb[cb]&&cb++}for(;39===sb[cb];)cb++;e.push(Sb())}for(24===sb[cb]&&cb++;39===sb[cb];)cb++}return wb(62),e}function Db(e){return e.map(({key:e,span:t,keySpan:r,valueSpan:a})=>({key:e,span:t,keySpan:r,valueSpan:a}))}function Rb(e,t){do{cb++;let r=wb(21);e.push(gb(r)),t.push(mb(r))}while(24===sb[cb])}function Lb(e){let t=cb,r=sb[cb],a={id:"",label:void 0,span:Ab(t),generated:21!==r,classes:[],classSpans:[],explicit:!1,nodeSpan:[0,0]};if(21===r){cb++,a.id=gb(t);let r=sb[cb];65===r||e&&63===r?(cb++,a.label=Eb(),wb(65===r?66:64),a.shape=65===r?"ellipse":"rect"):a.label=Tb(t)}else 35===r||36===r?(cb++,a.label=Tb(t),a.id=Cb(a.label.text)):$b(Q$);return a}function Ob(e){let t=cb,r=Lb(!e);if(e&&(r.shape=void 0),60===sb[cb]&&(r.metadata=Nb()),48===sb[cb]){cb++;let e=wb(50);wb(49),r.stereotype=gb(e).trim(),r.stereotypeSpan=mb(e)}return 52===sb[cb]&&Rb(r.classes,r.classSpans),r.explicit=!!(r.shape||r.metadata||r.stereotype),r.nodeSpan=[ob[t],hb[cb-1]],r}function Fb(e,t){return{id:e.id,kind:t,label:e.label,span:e.span,generated:e.generated,parent:ib,shape:e.shape,metadata:e.metadata,stereotype:e.stereotype,classes:e.classes}}function zb(e,t){return{id:e.id,label:e.label,span:e.span,generated:e.generated,declares:t,classed:e.classes.length>0}}function Wb(e,t){let r={id:e.id,span:e.nodeSpan,idSpan:e.span,labelSpan:e.label.span};return t&&(r.defines=!0),e.stereotypeSpan&&(r.stereotypeSpan=e.stereotypeSpan),e.metadata&&(r.metadata=Db(e.metadata)),e.classSpans.length>0&&(r.classSpans=e.classSpans),r}function Pb(e){if(sb[cb]<1||sb[cb]>36)return!1;for(let t=cb+1;;t++){let r=sb[t];if(59===r||0!==(tb[r]&e))return!0;if(r<1||r>36)return!1}}function Bb(e){let t=hb[e]-ob[e]-(59===sb[e]?0:1);return Math.max(1,t-1)}function Hb(){let e=cb,t={type:"association",arrowType:0,minlen:1,target:void 0,span:[0,0]};21===sb[cb]&&23===sb[cb+1]&&(t.explicitId=gb(cb),t.explicitIdSpan=mb(cb),cb+=2);let r=cb,a=sb[cb++];if(47===a)wb(25),17!==sb[cb]&&18!==sb[cb]&&$b("INCLUDE|EXTEND"),t.type=17===sb[cb]?"include":"extend",t.label={text:t.type,type:"text",span:mb(cb)},cb++;else if(46===a)t.type="generalization";else if(53===a)t.minlen=Bb(r);else if(54===a)t.arrowType=1,hb[r]-ob[r]===3&&Pb(0)?(t.label=Eb(),t.minlen=Bb(wb(59))):t.minlen=Bb(r);else if(59===a)if(t.arrowType=2,hb[r]-ob[r]===2&&Pb(32)){t.label=Eb();let e=sb[cb];53===e?t.arrowType=0:55===e?t.arrowType=3:57===e?t.arrowType=4:59!==e&&$b("FORWARD_SOLID|MARKERLESS_SOLID|FORWARD_CIRCLE|FORWARD_CROSS"),(0===t.arrowType||2===t.arrowType)&&(t.minlen=Bb(cb)),cb++}else t.minlen=Bb(r);else 55===a?t.arrowType=3:57===a?t.arrowType=4:56===a||58===a?(t.arrowType=56===a?5:6,Pb(0)&&(t.label=Eb(),wb(59))):(cb--,$b(Z$));return t.target=Ob(!1),t.span=[ob[e],hb[cb-1]],t}function Yb(e){return{kind:e,span:[0,0]}}function Gb(e,t,r,a){let i=r.target;i.explicit&&ab.elements.push(Fb(i,"usecase")),ab.relationships.push({source:zb(e,t),target:zb(i,i.explicit),span:r.span,id:r.explicitId,idSpan:r.explicitIdSpan,type:r.type,arrowType:r.arrowType,label:r.label,minlen:r.minlen}),a.push(Wb(i,i.explicit));let l=Yb("edge");return l.nodes=a,l.edges=[{id:r.explicitId??"edge-"+ub++,span:l.span}],r.explicitIdSpan&&(l.edges[0].idSpan=r.explicitIdSpan),r.label&&(l.edges[0].labelSpan=r.label.span),l}function Ub(e){let t=Yb("node");return t.nodes=e,t}function qb(e){cb++;let t,r=[Ob(!0)];if(24===sb[cb])do{cb++,r.push(Ob(!0))}while(24===sb[cb]);else e&&2&tb[sb[cb]]&&(t=Hb());kb();for(let e of r)ab.elements.push(Fb(e,"actor"));let a=r.map(e=>Wb(e,!0));return t?Gb(r[0],!0,t,a):Ub(a)}function jb(e){let t=Ob(!1),r=e&&2&tb[sb[cb]]?Hb():void 0;kb(),r||(t.explicit=!0,t.shape??="ellipse"),t.explicit&&ab.elements.push(Fb(t,"usecase"));let a=[Wb(t,t.explicit)];return r?Gb(t,t.explicit,r,a):Ub(a)}function Vb(){let e=cb,t=sb[cb];for(Mb(t)||27===t?cb++:59===t?(cb++,Mb(sb[cb])||xb("WORD"),cb++):$b("WORD|CSS_IDENTIFIER|MARKERLESS_SOLID"),wb(25),!(4&tb[sb[cb]])&&yb(`Expecting: expecting at least one iteration which starts with one of these possible Token sequences::\n <[${eb.replaceAll("|","] ,[")}]>\nbut found: '${gb(cb)}'`);4&tb[sb[cb]];)cb++;return nb.slice(ob[e],hb[cb-1]).replaceAll("\\,",",")}function Xb(){let e=[Vb()];for(;24===sb[cb];)cb++,e.push(Vb());return e}function Kb(){let e=[wb(21)];for(;24===sb[cb];)cb++,e.push(wb(21));return e}function Zb(e){let t=Ab(e);return{id:gb(e),span:t,idSpan:t}}function Qb(){let e,t=cb,r=sb[cb];if(41===r||42===r||40===r){cb++;let a=gb(t);40===r?ab.accDescription=a.slice(a.indexOf("{")+1,a.lastIndexOf("}")).trim():42===r?ab.accDescription=a.slice(a.indexOf(":")+1).trim():ab.accTitle=a.slice(a.indexOf(":")+1).trim(),e=Yb(41===r?"accTitle":"accDescr")}else if(5===r){cb++;let t=sb[cb];(t<6||t>10)&&$b("TD|TB|BT|LR|RL"),ab.direction=6===t?"TB":gb(cb),cb++,e=Yb("direction")}else{if(2===r)return qb(!0);if(3===r)return function(){cb++;let e=Lb(!0),t={id:e.id,label:e.label,span:e.span,generated:e.generated,classes:e.classes},r=60===sb[cb]?Nb():void 0;52===sb[cb]&&Rb(e.classes,e.classSpans),kb(),ab.boundaries.push(t),ib=t;let a=[];for(;16&tb[sb[cb]];)a.push(Jb(!1));ib=void 0;let i=wb(4);kb();let l=Yb("group");return l.group=t.id,l.idSpan=t.span,l.titleSpan=t.label.span,l.endSpan=mb(i),l.classSpans=e.classSpans,a.length>0&&(l.children=a),r&&(l.metadata=Db(r),ab.metadata.push({target:t.id,span:t.span,properties:r,statement:l})),l}();if(11===r){cb++,wb(12);let t=wb(21),r=Eb();ab.notes.push({target:gb(t),span:mb(t),label:r}),e=Yb("note"),e.ref="note-"+pb++,e.refSpan=r.span,e.nodes=[Zb(t)]}else if(43===r){cb++;let r=wb(44),a=[],i=[];52===sb[cb]&&Rb(a,i);let l=ob[t]+4;for(;32===nb.charCodeAt(l)||9===nb.charCodeAt(l);)l++;let n=l;for(;/\w/.test(nb.charAt(n));)n++;let s={id:nb.slice(l,n),value:{},propertyOrder:new Map,span:[l,n],classes:a};ab.jsons.push(s),fb.push([s,r]),e=Yb("json"),e.nodes=[{id:s.id,span:s.span,idSpan:s.span,defines:!0,classSpans:i}],e.classSpans=i}else if(14===r){cb++;let t=Kb();ab.classDefs.push({ids:t.map(gb),styles:Xb()}),e=Yb("classDef"),e.ref=gb(t[0]),e.refSpan=mb(t[0])}else if(15===r){cb++;let t=Kb(),r=Kb();ab.classes.push({targets:t.map(e=>({id:gb(e),span:mb(e)})),classes:r.map(gb)}),e=Yb("classAssign"),e.ref=gb(r[0]),e.refSpan=mb(r[0]),e.nodes=t.map(Zb)}else if(16===r){cb++;let t=wb(21);ab.styles.push({target:gb(t),span:mb(t),styles:Xb()}),e=Yb("style"),e.nodes=[Zb(t)]}else{let a=sb[cb+1];if(60!==a)return(!(8&tb[a]||21===r&&(65===a||63===a))||21===r&&lb.has(gb(t).toLowerCase()))&&$b(bb()),jb(!0);{!(64&tb[sb[cb+2]])&&$b(bb()),cb++;let a=Zb(t);21!==r&&(a.id=Cb(nb.slice(a.span[0],a.span[1])));let i=Nb();e=Yb("metadata"),e.nodes=[a],e.metadata=Db(i),ab.metadata.push({target:a.id,span:a.span,properties:i,statement:e})}}}return kb(),e}function Jb(e){let t=cb,r=sb[cb];if(39===r)return cb++,{kind:"blank",span:mb(t)};if(38===r)return cb++,kb(),{kind:"comment",span:mb(t)};let a=e?Qb():2===r?qb(!1):jb(!1);if(a.span=[ob[t],db],a.edges)for(let e of a.edges)e.span=a.span;return a}function eM(e,t){nb=e,({types:sb,starts:ob,ends:hb}=function(e){let t=[],r=[],a=[],i=e.length,l=0,n=!0,s=!1;for(;l<i;){let o=e.charCodeAt(l);if(32===o||9===o){l++;continue}let h,c=l+1,d=!1;if(o<128&&1&D$[o]){if(h=0,97===o&&n&&e.startsWith("acc",l)){let t=e.startsWith("Descr",l+3);if(t||e.startsWith("Title",l+3)){let r=l+8;for(;j(e.charCodeAt(r));)r++;let a=e.charCodeAt(r);if(58===a)for(h=t?42:41,c=r+1;c<i&&10!==e.charCodeAt(c)&&13!==e.charCodeAt(c);)c++;else if(123===a&&t&&!s){let t=e.indexOf("}",r+1);-1===t?s=!0:(h=40,c=t+1)}}}else if(106===o&&e.startsWith("json",l)&&j(e.charCodeAt(l+4))){let s=l+5;for(;j(e.charCodeAt(s));)s++;let o=s;for(;L$(e.charCodeAt(s));)s++;if(s>o){for(;j(e.charCodeAt(s));)s++;if(64===e.charCodeAt(s)){for(s++;j(e.charCodeAt(s));)s++;if(123===e.charCodeAt(s)){t.push(43),r.push(l),a.push(s),l=s;let o=0,h=!1,c=!1,d=s;for(;d<i;d++){let t=e.charCodeAt(d);if(h)c?c=!1:92===t?c=!0:34===t&&(h=!1);else if(34===t)h=!0;else if(123===t)o++;else if(125===t&&0===--o)break}t.push(d<i?44:45),r.push(s),l=d<i?d+1:i,a.push(l),n=!1;continue}}}}if(0===h){for(;c<i&&L$(e.charCodeAt(c));)c++;let t=F$(e,l,o);if(0!==t)1===t||c-l===R$[t]?(h=t,c=l+R$[t]):h=21;else if(111!==o&&120!==o||45!==e.charCodeAt(l+1)||45!==e.charCodeAt(l+2))if(X(o)){let t=l+1;for(;X(e.charCodeAt(t));)t++;if(46===e.charCodeAt(t)&&X(e.charCodeAt(t+1))){for(h=22,c=t+2;X(e.charCodeAt(c));)c++;for(;K(e.charCodeAt(c));)c++}else h=21}else for(h=21;45===e.charCodeAt(c)&&L$(e.charCodeAt(c+1));)for(h=27,c+=2;L$(e.charCodeAt(c));)c++;else h=111===o?56:58,c=l+3}}else if(10===o)h=39,d=!0;else if(13===o)h=39,d=!0,10===e.charCodeAt(c)&&c++;else if(34===o||39===o){if(34===o&&96===e.charCodeAt(l+1)){let t=e.indexOf('`"',l+2);h=-1===t?37:36,c=-1===t?i:t+2}else if(h=35,c=P$(e,l,o),-1===c){let t=l+1;for(;t<i&&!B$(e,t);)t++;throw H$(e,l,t-l)}}else if(37===o)if(n&&37===e.charCodeAt(c))for(h=38;c<i&&10!==e.charCodeAt(c)&&13!==e.charCodeAt(c);)c++;else h=31;else if(45===o)if(45!==e.charCodeAt(c))h=29;else{for(;45===e.charCodeAt(c);)c++;let t=e.charCodeAt(c),r=c-l===2;r&&124===t&&62===e.charCodeAt(c+1)?(h=46,c+=2):62===t?(h=53,c++):!r||111!==t&&120!==t?h=59:(h=111===t?55:57,c++)}else if(46===o){let t=e.charCodeAt(c);if(46===t&&62===e.charCodeAt(c+1))h=47,c+=2;else if(X(t)){for(h=22;X(e.charCodeAt(c));)c++;for(;K(e.charCodeAt(c));)c++}else h=30}else if(60===o)if(60===e.charCodeAt(c)){if(t.push(48),r.push(l),a.push(l+2),n=!1,l+=2,l>=i)break;if(62===e.charCodeAt(l)&&62===e.charCodeAt(l+1))h=49,c=l+2;else{let n=l,s=!1;for(;n<i;n++){let t=e.charCodeAt(n);if(10===t||13===t)break;if(62===t&&62===e.charCodeAt(n+1)){s=!0;break}}if(s&&""!==e.slice(l,n).trim())t.push(50),r.push(l),a.push(n),h=49,l=n,c=n+2;else{for(;n<i&&10!==e.charCodeAt(n)&&13!==e.charCodeAt(n);)n++;if(n===l){for(;n<i&&(10===e.charCodeAt(n)||13===e.charCodeAt(n));)n++;throw H$(e,l,n-l)}h=51,c=n}}}else if(45===e.charCodeAt(c)&&45===e.charCodeAt(c+1))for(h=54,c+=2;45===e.charCodeAt(c);)c++;else h=33;else if(58===o)58===e.charCodeAt(c)&&58===e.charCodeAt(c+1)?(h=52,c+=2):h=25;else if(64===o)123===e.charCodeAt(c)?(h=60,c++):h=23;else if(123===o)h=61;else if(125===o)h=62;else if(91===o)h=63;else if(93===o)h=64;else if(40===o)h=65;else if(41===o)h=66;else if(44===o)h=24;else if(35===o){for(;Z(e.charCodeAt(c));)c++;h=c>l+1?26:32}else if(92===o)44===e.charCodeAt(c)?(h=28,c++):h=33;else if(o<127&&o>32)h=2&D$[o]?32:33;else for(h=34;c<i;){let t=e.charCodeAt(c);if(t>=32&&t<127||9===t||10===t||13===t)break;c++}t.push(h),r.push(l),a.push(c),l=c,n=d}for(let e=0;e<3;e++)t.push(0),r.push(i),a.push(i);return{types:t,starts:r,ends:a}}(e)),cb=0,ab={elements:[],boundaries:[],jsons:[],relationships:[],notes:[],metadata:[],classes:[],styles:[],classDefs:[],direction:void 0,accTitle:"",accDescription:""},ib=void 0,fb=[],ub=0,pb=0;try{let r=wb(1);kb();let a=[];for(;1&tb[sb[cb]];)a.push(Jb(!0));0!==sb[cb]&&yb(`Redundant input, expecting EOF but found: ${gb(cb)}`);for(let[t,r]of fb){let a=K$(gb(r),()=>z$(e,ob[r]));t.value=a.value,t.propertyOrder=a.propertyOrder}return U$(e,ab,mb(r),a,t)}finally{nb="",sb=ob=hb=fb=[]}}var tM={normal:"usecaseActor",hollow:"usecaseActorHollow",awesome:"usecaseActorAwesome",icon:"usecaseActorIcon"},rM=[["none","arrow_point"],["arrow_point","none"],["none","none"],["none","arrow_circle"],["none","arrow_cross"],["arrow_circle","none"],["arrow_cross","none"]];function aM(e){return"string"==typeof e?e:null===e?"null":String(e)}function iM(e){let t=[],r=[[e.value,"",""]],a=[];for(;r.length>0;){let[i,l,n]=r.pop();if(a.length=0,Array.isArray(i))0===i.length?t.push({key:l,accessibleKey:l,value:"[]"}):i.every(e=>null===e||"object"!=typeof e)?i.forEach((e,r)=>t.push({key:0===r?l:"",accessibleKey:l,value:aM(e)})):i.forEach((e,t)=>a.push([e,`${l}[${t}]`,`${n}/${t}`]));else if(null!==i&&"object"==typeof i){let r=i,s=e.propertyOrder.get(n)??Object.keys(r);0===s.length&&t.push({key:l,accessibleKey:l,value:"{}"});for(let e of s)a.push([Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0,l?`${l}.${e}`:e,`${n}/${e.replaceAll("~","~0").replaceAll("/","~1")}`])}else t.push({key:l,accessibleKey:l,value:aM(i)});for(let e=a.length-1;e>=0;e--)r.push(a[e])}return t}function lM(...e){return e.filter(Boolean).join(" ")}function nM(e){return"generalization"===e.type?["none","extension"]:"association"!==e.type?rM[0]:rM[e.arrowType]??rM[2]}var sM=' fill="var(--_s)" stroke="var(--_b)"';function oM(e,t,r){let a=e.usecase?.[t];return"number"==typeof a&&a>0?Math.min(a,2e3):r}function hM(e,t,r,a,i,l=0){return Fl(e&&!t?function(e){return e.replace(/[&<>\\]/g,e=>`&#${e.charCodeAt(0)};`)}(e):e,t,r,a,i,l)}function cM(e,t,r,a){let i=1===r||2===r?1:-1,l=1===r||3===r,n=(l?e.w:e.h)/2,s=0;if(0===e.kind)l?(n=23,s=(60-e.h)/2):n+=2;else if(1===e.kind){let t=(l?e.h:e.w)/2;n*=Math.sqrt(Math.max(1-(a/t)**2,0))}return l?[t.x+i*n,t.y+s+a]:[t.x+a,t.y+i*n]}function dM(e,t){let r=1===t||3===t;if(0===e.kind)return r?30:24;let a=r?e.h:e.w;return 1===e.kind?.6*a:a-16}function fM(e){return"extension"===e?12:ii(e)}function uM(e,t,r,a,i,l,n){return"extension"===e?function(e,t,r,a,i){let l=e-12*r,n=t-12*a;return`<path class="pele-marker" d="M${Oe(e)},${Oe(t)}L${Oe(l-6*a)},${Oe(n+6*r)}L${Oe(l+6*a)},${Oe(n-6*r)}Z" fill="var(--_bg)" stroke="${i}" stroke-linejoin="round"/>`}(t,r,a,i,l):li(e,t,r,a,i,l,n)}function pM(e,t){let r,a=e.node,i=e.style.shape,l=` fill="none" stroke="var(--_b)"${e.style.line}`,n=-21,s=9;return"hollow"===a.actorType?(s=8,r=`<circle cy="-21" r="8" fill="var(--_bg)" stroke="var(--_b)"${i}/><path d="M-20,-9H20V0H5.5L20,15.5L12,25.5L0,12L-12,25.5L-20,15.5L-5.5,0H-20Z" fill="var(--_bg)" stroke="var(--_b)" stroke-linejoin="round"${i}/>`):"awesome"===a.actorType?r=`<path d="M0,-30A11,11 0 1 1 0,-8A11,11 0 1 1 0,-30ZM-20,25C-20,9 -12,-3 0,-3C12,-3 20,9 20,25C20,28 18,30 15,30H-15C-18,30 -20,28 -20,25Z" fill="var(--_b)"${i}/>`:"icon"===a.actorType?(n=-14,s=12,r=`<rect x="-22" y="-26" width="44" height="44"${Ai(sM+i)}/><svg class="pele-icon" data-icon="${Re(a.icon??"")}" x="-14" y="-18" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${t?.(a.icon??"")??""}</svg>`):r=`<circle cy="-21" r="9"${sM}${i}/><path d="M0,-12V10M-14,-3H14M0,10L-12,30M0,10L12,30"${l}/>`,a.business&&(r+=`<path class="pele-business" d="M${Oe(.12*s)},${Oe(n+.99*s)}L${Oe(.92*s)},${Oe(n-.39*s)}"${l}/>`),r}function gM(e,t,r,a){let i=function(e){let t=[],r=[],a=t=>{let r=new Map;for(let a of["default",...t]){let t=e.classDefs.get(a);if(t)for(let e of t.styles){let t=e.trim(),a=t.indexOf(":"),i=(-1===a?t:t.slice(0,a)).trim();i&&r.set(i,t)}}return[...r.values()]};for(let r of e.actors.values())t.push({id:r.id,label:r.label,labelType:r.labelType,shape:tM[r.type],isGroup:!1,padding:10,cssClasses:lM("default","usecase-actor",`usecase-actor-${r.type}`,r.business&&"usecase-business",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:a(r.classes),actorType:r.type,business:r.business,icon:r.icon||void 0,stereotype:r.stereotype||void 0,parentId:r.parentId||void 0});for(let r of e.useCases.values()){let e="ellipse"===r.shape;t.push({id:r.id,label:r.label,labelType:r.labelType,shape:e?r.business?"usecaseBusiness":"usecaseEllipse":"rect",isGroup:!1,padding:e?20:10,cssClasses:lM("default","usecase-element",`usecase-${r.shape}`,r.business&&"usecase-business",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:a(r.classes),business:r.business,stereotype:r.stereotype||void 0,parentId:r.parentId||void 0})}for(let r of e.notes.values())t.push({id:r.id,label:r.label,labelType:r.labelType,shape:"note",isGroup:!1,padding:10,cssClasses:"default usecase-note",cssStyles:[],cssCompiledStyles:a([]),noteTarget:r.target});for(let r of e.jsonNodes.values())t.push({id:r.id,label:r.id,labelType:"text",shape:"usecaseJsonTable",isGroup:!1,padding:10,cssClasses:lM("default","usecase-json-table",...r.classes),cssStyles:[...r.styles],cssCompiledStyles:a(r.classes),jsonRows:iM(r)});for(let r of e.systemBoundaries.values())t.push({id:r.id,label:r.label,labelType:r.labelType,shape:"usecaseSystemBoundary",isGroup:!0,padding:20,cssClasses:lM("default","system-boundary",`system-boundary-${r.type}`,...r.classes),cssStyles:[...r.styles],cssCompiledStyles:a(r.classes),boundaryType:r.type});for(let t of e.relationships){let e="include"===t.type||"extend"===t.type,[i,l]=nM(t),n=t.animate||void 0!==t.animation,s={id:t.id,start:t.source,end:t.target,relationshipType:t.type,pattern:e?"dotted":"solid",arrowTypeStart:i,arrowTypeEnd:l,classes:lM("default","relationship",`relationship-${t.type}`,...t.classes,n&&`edge-animation-${t.animation??"fast"}`),style:[...t.styles],cssCompiledStyles:a(t.classes),animate:t.animate,animation:t.animation,minlen:t.minlen,explicitId:t.explicitId,internal:!1};e?(s.label=t.type,s.labelType="text"):"association"===t.type&&(t.label&&(s.label=t.label),t.labelType&&(s.labelType=t.labelType)),r.push(s)}for(let t of e.notes.values())r.push({id:`${t.id}-edge`,start:t.id,end:t.target,relationshipType:"note",pattern:"dotted",arrowTypeStart:"none",arrowTypeEnd:"none",classes:"default relationship relationship-note",style:[],cssCompiledStyles:a([]),animate:!1,minlen:1,explicitId:!1,internal:!0});return{nodes:t,edges:r}}(e),l=r.fontSize??16,n=Math.round(.875*l),s=Math.round(.8125*l),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=r.icons,d=a?"TB":Pa(e.direction),f="LR"===d||"RL"===d,u=new Map,p=[],g=[];i.nodes.forEach((e,t)=>u.set(e.id,t));for(let e of i.nodes){let t,r=Ri(e.cssStyles.length>0?e.cssCompiledStyles.concat(e.cssStyles):e.cssCompiledStyles),a=(r.bold?1:0)|(r.italic?2:0),i=r.fontSize??l,h="markdown"===e.labelType,c=hM(e.stereotype&&`«${e.stereotype}»`,!1,o,s,200,a),d={node:e,kind:2,style:r,label:c,stereotype:c,w:0,h:0,rows:[],keyW:0,headH:0,loops:0};if(e.isGroup){d.kind=4,d.label=hM(e.label,h,o,i,4e3,a);let r=d.label.height;t=Va(0,0),t.isGroup=!0,t.padX=20,t.padBottom=20,t.padTop="package"===e.boundaryType?r+12+16:r>0?r+16:20,t.minW=d.label.width+40}else{if(e.jsonRows){d.kind=3,d.label=hM(e.label,!1,o,i,4e3,1|a);let t=0;for(let r of e.jsonRows){let e=hM(r.key,!1,o,n,4e3,a),i=hM(r.value,!1,o,n,260,a);d.rows.push([e,i]),d.keyW=Math.max(d.keyW,e.width),t=Math.max(t,i.width),d.h+=Math.max(e.height,i.height,Math.round(1.5*n))+8}d.keyW>0&&(d.keyW+=20),d.headH=Math.max(d.label.height,Math.round(1.5*i))+8,d.w=Math.max(d.label.width+20,d.rows.length>0?d.keyW+t+20:0,72),d.h+=d.headH}else if(e.actorType)d.kind=0,d.label=hM(e.label,h,o,i,140,a),d.w=Math.max(40,d.label.width,c.width),d.h=66+c.height+d.label.height;else{d.label=hM(e.label,h,o,"note"===e.shape?n:i,180,a);let t=Math.max(d.label.width,c.width),r=d.label.height+c.height;"usecaseEllipse"===e.shape||"usecaseBusiness"===e.shape?(d.kind=1,d.w=Math.max(t+2*e.padding+(e.business?16:4),88),d.h=Math.max(r+28,48)):"note"===e.shape?(d.w=t+2*e.padding+6,d.h=r+18):(d.w=Math.max(t+2*e.padding+12,80),d.h=Math.max(r+24,44))}t=Va(d.w,d.h)}t.seq=p.length,p.push(d),g.push(t)}i.nodes.forEach((e,t)=>{g[t].parent=void 0!==e.parentId?u.get(e.parentId)??-1:-1});let m=[],y=[],x=[];for(let e of i.edges){let t=u.get(e.start),r=u.get(e.end);if(void 0===t||void 0===r)continue;let a=hM("include"===e.relationshipType||"extend"===e.relationshipType?`«${e.label}»`:e.label,"markdown"===e.labelType,o,n,200);t===r&&(p[t].loops++,f?g[t].h+=2*(26+(a.height>0?a.height+8:0)):g[t].w+=2*(26+(a.width>0?a.width+12:0))),x.push(e),y.push(a),m.push({src:t,dst:r,minlen:e.minlen,labelW:a.width>0?a.width+12:0,labelH:a.height>0?a.height+4:0,route:[],labelX:0,labelY:0})}let w=Za(g,m,d,{nodeSep:oM(t,"nodeSpacing",32),edgeSep:16,rankSep:oM(t,"rankSpacing",72),portSep:20}),$=gs(e.title,o,l,4e3),b=$.height>0?$.height+12:0,M=Math.max(w.width,$.width),v=h+(M-w.width)/2;ja(g,m,v,h+b);let k=Math.ceil(M+2*h),A=Math.ceil(w.height+b+2*h),T=new Map;for(let e of m)Qa(T,e.route);!function(e,t,r){let a=new Map,i=(e,r,i,l)=>{let n=t[e];if(n.isGroup)return;let s,o=r[i]-n.x,h=r[i+1]-n.y;if(Math.abs(Math.abs(h)-n.h/2)<.5)s=h<0?0:2;else{if(!(Math.abs(Math.abs(o)-n.w/2)<.5))return;s=o<0?3:1}let c=4*e+s,d={route:r,at:i,toward:r[l+(1&s?1:0)]},f=a.get(c);f?f.push(d):a.set(c,[d])};for(let t of e){let e=t.route.length-3;t.src===t.dst||e<3||(i(t.src,t.route,0,3),i(t.dst,t.route,e,e-3))}for(let[e,i]of a){let a=e>>2,l=3&e,n=r[a],s=i.length>1?Math.min(14,dM(n,l)/(i.length-1)):0;i.sort((e,t)=>e.toward-t.toward);for(let e=0;e<i.length;e++){let[r,o]=cM(n,t[a],l,(e-(i.length-1)/2)*s);i[e].route[i[e].at]=r,i[e].route[i[e].at+1]=o}}}(m,g,p);let C="",E=[],_="";for(let e=0;e<p.length;e++){let t,r,a=p[e],i=g[e],l=a.node,o=Oi(l.cssClasses.replace(/^default\s?/,"")),h=Re(l.id),d=a.style.text,f=a.style.shape,u=xt(a.style),m=u||' fill="var(--_m)"',y=a.w,x=a.h;if(4===a.kind){let e=i.x-i.w/2,t=i.y-i.h/2;yt(f)&&E.push({box:[e,t,e+i.w,t+i.h],shape:f});let r,n=` fill="var(--_a)"${ki(f)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${f}`,s=` class="pele-cluster-label"${m}${d}`;if("package"===l.boundaryType){let l=Math.min(a.label.width+12+8,i.w),o=a.label.height+12;r=`<rect class="pele-boundary-tab" x="${Oe(e)}" y="${Oe(t)}" width="${Oe(l)}" height="${Oe(o)}"${n}/><rect x="${Oe(e)}" y="${Oe(t+o)}" width="${Oe(i.w)}" height="${Oe(i.h-o)}"${n}/>`+Fe(a.label,e+l/2,t+o/2,s,c)}else r=`<rect x="${Oe(e)}" y="${Oe(t)}" width="${Oe(i.w)}" height="${Oe(i.h)}"${Ai(n)}/>`+Fe(a.label,mM(i,a.label.width,T),t+8+a.label.height/2,s,c);C+=`<g class="pele-cluster pele-boundary${o}" data-id="${h}">${r}</g>`;continue}if(0===a.kind){r="pele-actor";let e=-x/2,i=e+60+6+a.stereotype.height/2;t=`<g class="pele-actor-figure" transform="translate(0,${Oe(e+30)})">${pM(a,c)}</g>`+Fe(a.stereotype,0,i,` class="pele-stereotype" font-size="${s}" fill="var(--_m)"`,c)+Fe(a.label,0,x/2-a.label.height/2,` class="pele-label"${d}`,c)}else if(3===a.kind){r="pele-json";let e=-y/2,i=-x/2+a.headH,l="",s=`M${Oe(e)},${Oe(i)}H${Oe(e+y)}`;a.keyW>0&&(s+=`M${Oe(e+a.keyW)},${Oe(i)}V${Oe(x/2)}`);for(let[t,r]of a.rows){let s=Math.max(t.height,r.height,Math.round(1.5*n))+8;l+=Fe(t,e+10+t.width/2,i+s/2,` class="pele-json-key"${m}`,c)+yM(r,e+a.keyW+10,i+s/2,` class="pele-json-value"${u}${d}`,c),i+=s}t=`<rect x="${Oe(e)}" y="${Oe(-x/2)}" width="${Oe(y)}" height="${Oe(x)}"${Ai(sM+f)}/><path class="pele-json-lines" d="${s}" fill="none" stroke="var(--_b)"${a.style.line}/>`+Fe(a.label,0,-x/2+a.headH/2,` class="pele-label" font-weight="var(--_hw)"${u}${d}`,c)+`<g font-size="${n}">${l}</g>`}else{let e,i=a.stereotype.height/2;if(1===a.kind){if(r="pele-usecase",e=`<ellipse rx="${Oe(y/2)}" ry="${Oe(x/2)}"${sM}${f}/>`,l.business){let t=y/2-15,r=y/2-5,i=e=>x/2*Math.sqrt(1-(e/(y/2))**2);e+=`<path class="pele-business" d="M${Oe(t)},${Oe(i(t))}L${Oe(r)},${Oe(-i(r))}" fill="none" stroke="var(--_b)"${a.style.line}/>`}}else if("note"===l.shape){r="pele-note";let t=y/2,i=x/2;e=`<path d="M${Oe(-t)},${Oe(-i)}H${Oe(t-9)}L${Oe(t)},${Oe(9-i)}V${Oe(i)}H${Oe(-t)}Z" fill="var(--_a)" stroke="var(--_b)" stroke-linejoin="round"${f}/><path d="M${Oe(t-9)},${Oe(-i)}V${Oe(9-i)}H${Oe(t)}" fill="none" stroke="var(--_b)" stroke-linejoin="round"${a.style.line}/>`}else r="pele-usecase",e=`<rect x="${Oe(-y/2)}" y="${Oe(-x/2)}" width="${Oe(y)}" height="${Oe(x)}"${Ai(sM+f)}/>`;t=e+Fe(a.stereotype,0,-a.label.height/2,` class="pele-stereotype" font-size="${s}"${m}`,c)+Fe(a.label,0,i,` class="pele-label"${"note"===l.shape?` font-size="${n}"`:""}${u}${d}`,c)}_+=`<g class="pele-node ${r}${o}" data-id="${h}" transform="translate(${Oe(i.x)},${Oe(i.y)})">${t}</g>`}let S="",I="",N="",D=new Map;for(let e=0;e<m.length;e++){let t,r=m[e],a=x[e],i=y[e],l=a.style.length>0||a.cssCompiledStyles.length>0?Ri(a.cssCompiledStyles.concat(a.style)):void 0,n=a.arrowTypeStart,s=a.arrowTypeEnd;if(r.src===r.dst){let e=g[r.src],a=p[r.src],l=D.get(r.src)??0;D.set(r.src,l+1);let o=f?2:1,h=Math.min(dM(a,o)/2,8+6*l),c=26+8*l,[d,u]=cM(a,e,o,-h),[m,y]=cM(a,e,o,h),x=Math.hypot(c,h)||1,w=f?h/x:c/x,$=f?c/x:h/x,b=fM(n),M=fM(s),v=(e,t,r,a)=>f?`${Oe(e+r*h*(a?1:0))},${Oe(t+a)}`:`${Oe(e+a)},${Oe(t+r*h*(a?1:0))}`,k=f?u+$*b:u-$*b,A=m+w*M,T=y+$*M;t={d:`M${Oe(f?d-w*b:d+w*b)},${Oe(k)}C${v(d,u,-1,c)} ${v(m,y,1,c)} ${Oe(A)},${Oe(T)}`,sx:d,sy:u,sdx:f?w:-w,sdy:f?-$:$,ex:m,ey:y,edx:-w,edy:-$},f?(r.labelX=e.x,r.labelY=Math.max(u,y)+.75*c+6+i.height/2):(r.labelX=Math.max(d,m)+.75*c+8+i.width/2,r.labelY=e.y)}else{if(r.route.length<6)continue;t=ai(r.route,void 0,fM(n),fM(s))}let o=fi(t.d,[t.sx,t.sy,t.ex,t.ey],E,t.tokens),h=o&&ui(o,l?.line),d=h||(l?.stroke?De(l.stroke):"var(--_l)");if(""===h){let e="var(--_bg)";S+=mi(t.d,uM(n,t.sx,t.sy,t.sdx,t.sdy,e,e)+uM(s,t.ex,t.ey,t.edx,t.edy,e,e),l?.line)}let u=a.internal?"2 3":"dotted"===a.pattern?"5 4":a.animate?"9 5":"",w=uM(n,t.sx,t.sy,t.sdx,t.sdy,d)+uM(s,t.ex,t.ey,t.edx,t.edy,d);if(I+=`<g class="pele-edge pele-${a.relationshipType}${Oi(a.classes.replace(/^default relationship relationship-\S+\s?/,""))}" data-id="${Re(a.id)}"${h?` stroke="${h}"`:""}${l?.line??""}><path d="${t.d}"${u?` stroke-dasharray="${u}"`:""}/>`+(o&&h?pi(w,o):w)+"</g>",i.width>0){let e=r.labelX,t=r.labelY,n="include"===a.relationshipType||"extend"===a.relationshipType;N+=wi(a.id,i,e,t,(n?' fill="var(--_m)"':"")+(l?.text??""),c)}}return{svg:Bi("usecase",k,A,l,r,e,Fe($,k/2,h+$.height/2,' class="pele-title" font-weight="var(--_tw)"')+(C?`<g class="pele-clusters">${C}</g>`:"")+xi(S)+(I?`<g class="pele-edges" fill="none" stroke="var(--_l)" stroke-linecap="round">${I}</g>`:"")+(N?`<g class="pele-edge-labels" font-size="${n}">${N}</g>`:"")+`<g class="pele-nodes">${_}</g>`),width:k,height:A,links:[]}}function mM(e,t,r){let a=r.get(Math.round(e.y-e.h/2));if(0===t||void 0===a)return e.x;let i=e.x-e.w/2+6,l=e.x+e.w/2-6,n=a.filter(e=>e>i&&e<l).sort((e,t)=>e-t);n.push(l);let s=t/2+6,o=e.x,h=1/0,c=0,d=i;for(let t of n){if(t-d>=2*s){let r=Math.min(Math.max(e.x,d+s),t-s);Math.abs(r-e.x)<h&&(h=Math.abs(r-e.x),o=r)}else h===1/0&&t-d>c&&(c=t-d,o=(d+t)/2);d=t}return o}function yM(e,t,r,a,i){if(e.lines.length<2)return Fe(e,t+e.width/2,r,a,i);let l="";for(let n=0;n<e.lines.length;n++)l+=Fe(Hl(e,n),t+e.widths[n]/2,r-e.height/2+Bl(e,n),a,i);return l}var xM={type:"usecase",math:!0,parse:(e,t,r)=>eM(e,r),render:function(e,t,r){return jl(e.direction)?ql(r,a=>gM(e,t,r,a)):gM(e,t,r,!1)}};function wM(e){let t=e.trim();return t.length>=2&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function $M(e){return e.map(wM).sort()}var bM=class{type="venn";title;subsets=[];textNodes=[];styles=[];known=new Set;current;indent=!1;setDiagramTitle(e){this.title=e}addSubsetData(e,t,r){let a=$M(e);this.current=a,1===a.length&&this.known.add(a[0]),this.subsets.push({sets:a,size:r??10/e.length**2,label:t?wM(t):void 0})}addTextData(e,t,r){this.textNodes.push({sets:$M(e),id:wM(t),label:r?wM(r):void 0})}addStyleData(e,t){let r=new Map;for(let[e,a]of t)r.set(e,a&&wM(a));this.styles.push({targets:$M(e),styles:r})}validateUnionIdentifiers(e){let t=e.map(wM).filter(e=>!this.known.has(e));if(t.length>0)throw new i(`unknown set identifier: ${t.join(", ")}`,"semantic",{type:"venn"})}getCurrentSets(){return this.current}getIndentMode(){return this.indent}setIndentMode(e){this.indent=e}},MM=["$end","INVALID","EOF","NEWLINE","VENN","TITLE","SET","UNION","TEXT","INDENT_TEXT","STYLE","BRACKET_LABEL","NUMERIC","HEXCOLOR","RGBCOLOR","RGBACOLOR","IDENTIFIER","STRING","COMMA","COLON"],vM=[["venn-beta",4],["set",6],["union",7],["text",8],["style",10]],kM=class{constructor(e,t){this.src=e,this.host=t}src;host;text="";start=0;at=0;lineStart=!1;ended=!1;word(e,t){let r=this.src;for(let a=0;a<t.length;a++){let i=r.charCodeAt(e+a),l=t.charCodeAt(a);if(i!==l&&(i+32!==l||i<65||i>90))return!1}return!0}keyword(e,t){return this.word(e,t)&&!Q(this.src.charCodeAt(e+t.length))}color(e,t){let r=this.src,a=e+1;for(let e=0;e<t;e++){for(;q(r.charCodeAt(a));)a++;let i=a;for(;X(r.charCodeAt(a))||46===r.charCodeAt(a);)a++;if(a===i)return-1;for(;q(r.charCodeAt(a));)a++;if(r.charCodeAt(a)!==(e===t-1?41:44))return-1;a++}return a}afterLineFeed(e){let t=e-1;for(;32===this.src.charCodeAt(t)||9===this.src.charCodeAt(t);)t--;return 10===this.src.charCodeAt(t)}lineEnd(e){let t=this.src.indexOf("\n",e);return-1===t?this.src.length:t}next(){let e=this.src,t=e.length;for(;;){let r=this.at;if(this.start=r,this.text="",r>=t)return this.ended?0:(this.ended=!0,2);let a=e.charCodeAt(r);if(37!==a||37!==e.charCodeAt(r+1)||123===e.charCodeAt(r+2)){if(this.lineStart&&this.word(r,"title")&&this.afterLineFeed(r)&&""===e.slice(r+5,this.lineEnd(r+5)).trim()){let t=this.lineEnd(r+5);for(;10===e.charCodeAt(t)||13===e.charCodeAt(t);)t++;this.at=t;continue}if(this.lineStart){if(32===a||9===a){let t=r+1;for(;32===e.charCodeAt(t)||9===e.charCodeAt(t);)t++;if(this.at=t,this.keyword(t,"text")&&this.host.getIndentMode())return this.at=t+4,this.lineStart=!1,this.text=e.slice(r,t),9;continue}10!==a&&13!==a&&(this.host.setIndentMode(!1),this.lineStart=!1)}if(10===a||13===a){for(r++;10===e.charCodeAt(r)||13===e.charCodeAt(r);)r++;return this.lineStart=!0,this.token(3,r)}if(37!==a||37!==e.charCodeAt(r+1)){if(32!==a&&9!==a){if((32|a)>=97&&(32|a)<=122||95===a){let a=e.charCodeAt(r+5);if(this.word(r,"title")&&q(a)&&10!==a&&13!==a){let a=r+6;for(;a<t;){let t=e.charCodeAt(a);if(35===t||10===t||59===t)break;a++}if(a>r+6)return this.token(5,a)}for(let[t,a]of vM)if(this.keyword(r,t)&&45!==e.charCodeAt(r+t.length))return this.token(a,r+t.length);if(this.word(r,"rgb")){let t=97==(32|e.charCodeAt(r+3)),a=r+(t?4:3),i=40===e.charCodeAt(a)?this.color(a,t?4:3):-1;if(-1!==i)return this.token(t?15:14,i)}for(r++;Q(e.charCodeAt(r))||45===e.charCodeAt(r);)r++;return this.token(16,r)}if(91===a){if(34===e.charCodeAt(r+1)){let t=e.indexOf('"',r+2);return-1===t||93!==e.charCodeAt(t+1)?1:(this.at=t+2,this.text=e.slice(r+2,t),11)}let a=r+1;for(;a<t&&93!==e.charCodeAt(a)&&34!==e.charCodeAt(a);)a++;return a===r+1||93!==e.charCodeAt(a)?1:(this.at=a+1,this.text=e.slice(r+1,a).trim(),11)}if(X(a)||46===a||43===a||45===a){(43===a||45===a)&&r++;let t=r;for(;X(e.charCodeAt(r));)r++;if(r>t){if(46===e.charCodeAt(r)&&X(e.charCodeAt(r+1)))for(r+=2;X(e.charCodeAt(r));)r++}else{if(46!==e.charCodeAt(r)||!X(e.charCodeAt(r+1)))return 1;for(r+=2;X(e.charCodeAt(r));)r++}return this.token(12,r)}if(35===a){let t=r+1;for(;t<r+9&&Z(e.charCodeAt(t));)t++;return t>=r+4?this.token(13,t):1}if(34===a){let t=e.indexOf('"',r+1);return-1===t?1:this.token(17,t+1)}return 44===a?this.token(18,r+1):58===a?this.token(19,r+1):1}for(r++;32===e.charCodeAt(r)||9===e.charCodeAt(r);)r++;this.at=r}else this.at=this.lineEnd(r)}else this.at=this.lineEnd(r+2)}}token(e,t){return this.text=this.src.slice(this.at,t),this.at=t,e}};var AM=2*Math.PI;function TM(e,t,r){if(r>=e+t)return 0;let a=Math.min(e,t);return r<=Math.abs(e-t)?Math.PI*a*a:e*e*Math.acos((r*r+e*e-t*t)/(2*r*e))+t*t*Math.acos((r*r+t*t-e*e)/(2*r*t))-.5*Math.sqrt(Math.max((-r+e+t)*(r+e-t)*(r-e+t)*(r+e+t),0))}function CM(e,t,r){let a=Math.abs(e-t),i=e+t;if(!(r>0))return i;if(r>=Math.PI*Math.min(e,t)**2)return a;for(let l=0;l<48;l++){let l=(a+i)/2;TM(e,t,l)>r?a=l:i=l}return(a+i)/2}function EM(e,t,r,a,i,l){let n=1/0;for(let r of t){let t=e[r],s=a-t.x,o=i-t.y,h=t.r-Math.sqrt(s*s+o*o);if(h<n){if(h<l)return h;n=h}}for(let t of r){let r=e[t],s=a-r.x,o=i-r.y,h=Math.sqrt(s*s+o*o)-r.r;if(h<n){if(h<l)return h;n=h}}return n}function _M(e,t,r){let a=0,i=0,l=e[t[0]];for(let r of t){let n=e[r];a+=n.x/t.length,i+=n.y/t.length,n.r<l.r&&(l=n)}let n=l.r,s=a,o=i,h=EM(e,t,r,s,o,-1/0),c=0,d=(l,d)=>{let f=EM(e,t,r,l,d,h-1e-9*n);if(!(f>h-1e-9*n))return!1;let u=Math.hypot(l-a,d-i);return(f>h+1e-9*n||u<c-1e-9*n)&&(h=f,c=u,s=l,o=d,!0)},f=10;for(let e=-f;e<=f;e++)for(let t=-f;t<=f;t++)t*t+e*e<=100&&d(l.x+t*n/f,l.y+e*n/f);let u=n/f;for(let e=0;e<40&&u>1e-6*n;e++){let e=!1;for(let t=0;t<8;t++){let r=t*AM/8;d(s+Math.cos(r)*u,o+Math.sin(r)*u)&&(e=!0)}e||(u/=2)}return{x:s,y:o,margin:h}}function SM(e){let t=new Map;for(let r of e)for(let e of r.sets)t.has(e)||t.set(e,10);for(let r of e)1===r.sets.length&&t.set(r.sets[0],r.size);let r=new Map,a=[],i=0;for(let e of t.values())Number.isFinite(e)&&e>i&&(i=e);0===i&&(i=10);let l=Math.sqrt(i/Math.PI);for(let[e,i]of t){r.set(e,a.length);let t=Number.isFinite(i)&&i>0?Math.sqrt(i/Math.PI):0;a.push({id:e,x:0,y:0,r:Math.max(t,.3*l)})}let n=a.length;if(n<2)return a;let s=new Map;for(let t of function(e){let t=new Set,r=new Map;for(let a of e)t.add(JSON.stringify([...a.sets].sort())),1===a.sets.length&&r.set(a.sets[0],a.size);let a=[];for(let i of e){if(i.sets.length<3)continue;let e=[...i.sets].sort();for(let i=0;i<e.length-1;i++)for(let l=i+1;l<e.length;l++){let n=[e[i],e[l]],s=JSON.stringify(n);if(t.has(s))continue;t.add(s);let o=r.get(n[0]),h=r.get(n[1]);a.push({sets:n,size:void 0!==o&&void 0!==h?Math.min(o,h)/4:2.5,label:""})}}return a.length>0?[...e,...a]:e}(e)){if(2!==t.sets.length)continue;let e=r.get(t.sets[0]),a=r.get(t.sets[1]);e!==a&&s.set(Math.min(e,a)*n+Math.max(e,a),t.size)}let o=new Map;for(let[e,t]of s)o.set(e,CM(a[Math.floor(e/n)].r,a[e%n].r,t));let h=.15*l,c=(e,t)=>o.get(e*n+t)??a[e].r+a[t].r+h;if(2===n)return a[1].x=c(0,1),a;if(3===n){let t=c(0,1),r=c(0,2),i=c(1,2),n=e.some(e=>3===new Set(e.sets).size);for(let e=0;e<40;e++){let e=t>0?(t*t+r*r-i*i)/(2*t):0;if(a[1].x=t,a[2].x=Math.max(-r,Math.min(r,e)),a[2].y=Math.sqrt(Math.max(r*r-e*e,0)),!n||_M(a,[0,1,2],[]).margin>.12*l)break;t*=.94,r*=.94,i*=.94}return a}let d=0;for(let e of a)d+=2*e.r+h;let f=Math.min(300,Math.floor(3e6/(n*n)));if(n<=64){let e=d/AM;a.forEach((t,r)=>{let a=r*AM/n-Math.PI/2;t.x=Math.cos(a)*e,t.y=Math.sin(a)*e})}else{let e=Math.ceil(Math.sqrt(n)),t=2*l+h;a.forEach((r,a)=>{r.x=a%e*t,r.y=Math.floor(a/e)*t})}let u=new Float64Array(n),p=new Float64Array(n),g=new Int32Array(n);for(let e=0;e<f;e++){u.fill(0),p.fill(0),g.fill(0);for(let e=0;e<n;e++)for(let t=e+1;t<n;t++){let r=o.get(e*n+t),i=a[e].r+a[t].r+h,l=a[t].x-a[e].x,s=a[t].y-a[e].y,c=Math.hypot(l,s);if(void 0===r&&c>=i)continue;c<1e-9&&(l=Math.cos(e+t),s=Math.sin(e+t),c=1);let d=(c-(r??i))/2/c;u[e]+=l*d,p[e]+=s*d,u[t]-=l*d,p[t]-=s*d,g[e]++,g[t]++}for(let e=0;e<n;e++)0!==g[e]&&(a[e].x+=u[e]/g[e],a[e].y+=p[e]/g[e])}return a}function IM(e,t){let r=e=>`M${t(e.x-e.r)},${t(e.y)}A${t(e.r)},${t(e.r)} 0 1 1 ${t(e.x+e.r)},${t(e.y)}A${t(e.r)},${t(e.r)} 0 1 1 ${t(e.x-e.r)},${t(e.y)}Z`;if(1===e.length)return r(e[0]);let a=(t,r,a,i)=>{for(let l of e)if(l!==a&&l!==i&&Math.hypot(t-l.x,r-l.y)>l.r*(1+1e-9))return!1;return!0},i=[];for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let l=e[t],n=e[r],s=Math.hypot(n.x-l.x,n.y-l.y);if(s>=l.r+n.r||s<=Math.abs(l.r-n.r)||0===s)continue;let o=(l.r*l.r-n.r*n.r+s*s)/(2*s),h=Math.sqrt(Math.max(l.r*l.r-o*o,0)),c=l.x+(n.x-l.x)*o/s,d=l.y+(n.y-l.y)*o/s;for(let e of[1,-1]){let t=c+e*h*(n.y-l.y)/s,r=d-e*h*(n.x-l.x)/s;a(t,r,l,n)&&i.push({x:t,y:r,a:l,b:n})}}if(i.length<2){let t=e[0];for(let r of e)r.r<t.r&&(t=r);for(let r of e)if(r!==t&&Math.hypot(r.x-t.x,r.y-t.y)+t.r>r.r*(1+1e-9))return"";return r(t)}let l=0,n=0;for(let e of i)l+=e.x/i.length,n+=e.y/i.length;i.sort((e,t)=>Math.atan2(e.y-n,e.x-l)-Math.atan2(t.y-n,t.x-l));let s="";for(let e=0;e<i.length;e++){let r=i[e],a=i[(e+1)%i.length];0===e&&(s=`M${t(r.x)},${t(r.y)}`);let l,n=0,o=1/0;for(let e of[r.a,r.b]){if(e!==a.a&&e!==a.b)continue;let t=Math.atan2(r.y-e.y,r.x-e.x),i=Math.atan2(a.y-e.y,a.x-e.x)-t;i<=0&&(i+=AM);let s=e.x+e.r*Math.cos(t+i/2),h=e.y+e.r*Math.sin(t+i/2),c=Math.hypot(s-(r.x+a.x)/2,h-(r.y+a.y)/2);c<o&&(o=c,l=e,n=i>Math.PI?1:0)}s+=void 0===l?`L${t(a.x)},${t(a.y)}`:`A${t(l.r)},${t(l.r)} 0 ${n} 1 ${t(a.x)},${t(a.y)}`}return s+"Z"}var NM=Ri([]);function DM(e){return 1===e.length?e[0]:JSON.stringify(e)}var RM={type:"venn",parse(e,t,r){let a=new bM;return r&&(a.title=r),function(e,t){let r=new kM(e,t),a=-1,l=()=>-1===a?a=r.next():a,n=t=>{throw 1===l()?c("venn",e,r.start,"",!0):c("venn",e,r.start,`Expecting ${t}, got '${MM[a]}'`)},s=()=>(a=-1,r.text),o=e=>(l()!==e&&n(`'${MM[e]}'`),s()),h=()=>(16!==l()&&17!==a&&n("'IDENTIFIER', 'STRING'"),s()),d=()=>{let e=[h()];for(;18===l();)s(),e.push(h());return e},f=(e,r)=>{let a,n=11===l()?s():void 0;if(19===l()&&(s(),a=parseFloat(o(12))),r){if(e.length<2)throw new i("union requires multiple identifiers","semantic",{type:"venn"});t.validateUnionIdentifiers(e)}t.addSubsetData(e,n,a),t.setIndentMode(!0)},u=e=>{let r=l();16!==r&&17!==r&&12!==r&&n("'NUMERIC', 'IDENTIFIER', 'STRING'");let a=s(),i=12!==r&&11===l()?s():void 0;t.addTextData(e(),a,i)},p=()=>{let e=d(),r=[];for(;;){let e,t=o(16);if(o(19),17===l())e=s();else{let t=[];for(;16===l()||a>=12&&a<=15;)t.push(s());0===t.length&&n("'NUMERIC', 'IDENTIFIER', 'STRING', 'HEXCOLOR', 'RGBCOLOR', 'RGBACOLOR'"),e=t.join(" ")}if(r.push([t,e]),18!==l())break;s()}t.addStyleData(e,r)};for(;3===l();)s();for(o(4);;){let e=l();if(2===e)return;if((e<3||e>10||4===e)&&n("'EOF', 'NEWLINE', 'TITLE', 'SET', 'UNION', 'TEXT', 'INDENT_TEXT', 'STYLE'"),s(),5===e)t.setDiagramTitle(r.text.slice(6));else if(6===e)f([h()],!1);else if(7===e)f(d(),!0);else if(8===e){let e=d();u(()=>e)}else 9===e?u(()=>{let e=t.getCurrentSets();if(!e)throw new i("text requires set","semantic",{type:"venn"});return e}):10===e&&p()}}(e,a),a},render:function(e,t,r){let a=r.fontSize??16,i=Math.round(.875*a),l=Math.round(.8125*a),n=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),s=r.padding??8,o=SM(e.subsets),h=new Map;o.forEach((e,t)=>h.set(e.id,t));let c=new Map;for(let{targets:t,styles:r}of e.styles){let e=DM(t),a=c.get(e);a||c.set(e,a=new Map);for(let[e,t]of r)a.set(e,t)}let d=e=>{let t=c.get(e);if(!t)return NM;let r=[];for(let[e,a]of t)r.push(`${e}:${a}`);return Ri(r)},f=o.map(()=>[]);for(let e=0;e<o.length;e++)for(let t=e+1;t<o.length;t++)Math.hypot(o[e].x-o[t].x,o[e].y-o[t].y)<o[e].r+o[t].r&&(f[e].push(t),f[t].push(e));let u=new Map;for(let t of e.subsets)u.set(DM(t.sets),t);let p=new Map;for(let[e,t]of u){let r=[...new Set(t.sets)],l=r.map(e=>h.get(e)),s=new Set(l),c=l[0];for(let e of l)o[e].r<o[c].r&&(c=e);let u=d(e),g=t.label??(1===t.sets.length?t.sets[0]:void 0),m=(u.bold?1:0)|(u.italic?2:0),y=f[c].filter(e=>!s.has(e)),x=_M(o,l,y),w=y.length>0&&x.margin<.2*o[c].r;w&&(x=_M(o,l,[]));let $={sets:r,inside:l,spot:x,lines:[],style:u,across:w};if(g){let e=1===r.length?a:i;$.lines.push({id:void 0,raw:g,size:e,base:m,label:Fl(g,!1,n,e,4e3,m)})}p.set(e,$)}for(let t of e.textNodes){let e=t.label??t.id;p.get(DM(t.sets))?.lines.push({id:t.id,raw:e,size:l,base:0,label:Fl(e,!1,n,l,4e3)})}let g=0;for(let e of o)e.r>g&&(g=e.r);let m=g>0?100/g:1,y=1;for(let e of p.values()){if(e.spot.margin<=0)continue;let t=0,r=0;for(let a of e.lines)t=Math.max(t,a.label.width),r+=a.label.height;let a=Math.hypot(t,r)/2+4;y=Math.max(y,Math.min(a/(e.spot.margin*m),1.6))}m*=y;for(let e of p.values()){let t=Math.max(e.spot.margin*m*1.8,72);for(let r of e.lines)r.label.width>t&&(r.label=Fl(r.raw,!1,n,r.size,t,r.base))}let x=1/0,w=1/0,$=-1/0,b=-1/0;for(let e of o)x=Math.min(x,(e.x-e.r)*m),w=Math.min(w,(e.y-e.r)*m),$=Math.max($,(e.x+e.r)*m),b=Math.max(b,(e.y+e.r)*m);for(let e of p.values()){let t=0,r=0;for(let a of e.lines)t=Math.max(t,a.label.width),r+=a.label.height;x=Math.min(x,e.spot.x*m-t/2),$=Math.max($,e.spot.x*m+t/2),w=Math.min(w,e.spot.y*m-r/2),b=Math.max(b,e.spot.y*m+r/2)}0===o.length&&(x=w=$=b=0);let M=Fl(e.title&&wM(e.title),!1,n,a,4e3,1),v=M.height>0?M.height+12:0,k=Math.max($-x,M.width),A=s+(k-($-x))/2-x,T=s+v-w,C=Math.ceil(k+2*s),E=Math.ceil(b-w+v+2*s),_=o.map(e=>({id:e.id,x:e.x*m+A,y:e.y*m+T,r:e.r*m})),S="";_.forEach((e,t)=>{let r=zi(t),a=p.get(e.id)?.style??NM;S+=`<circle class="pele-venn-set" data-id="${Re(e.id)}" cx="${Oe(e.x)}" cy="${Oe(e.y)}" r="${Oe(e.r)}" fill="${r}" fill-opacity="0.2" stroke="${r}"${a.shape}/>`});let I=[...p.values()].filter(e=>e.sets.length>1&&""!==e.style.shape),N=e=>{if(e.across)return"";let t=1===e.sets.length&&/[";]fill-opacity:/.test(e.style.shape)?e.style.shape:"";for(let r of I)r.sets.every(t=>e.sets.includes(t))&&(t=r.style.shape);return t},D="",R="";for(let e of p.values()){let t=Re(e.sets.join("|"));if(e.sets.length>1&&""!==e.style.shape){let r=IM(e.inside.map(e=>_[e]),Oe);""!==r&&(D+=`<path class="pele-venn-overlap" data-id="${t}" d="${r}" fill="none"${e.style.shape}/>`)}let r=0;for(let t of e.lines)r+=t.label.height;if(0===r)continue;let i=e.spot.x*m+A,n=e.spot.y*m+T-r/2,s=N(e),o="";for(let t of e.lines){let r=void 0===t.id?e.style.text:d(t.id).text,h=mt(s,r),c=void 0===t.id?` class="pele-label"${t.size===a?"":` font-size="${t.size}"`}${h?` fill="${h}"`:""}${r}`:` class="pele-venn-text" data-id="${Re(t.id)}" font-size="${l}" fill="${h??"var(--_m)"}"${r}`;o+=Fe(t.label,i,n+t.label.height/2,c),n+=t.label.height}R+=`<g class="pele-venn-region" data-id="${t}">${o}</g>`}return{svg:Bi("venn",C,E,a,r,{},Fe(M,C/2,s+M.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g class="pele-venn-sets">${S}</g>`+(D?`<g class="pele-venn-overlaps">${D}</g>`:"")+(R?`<g class="pele-venn-labels">${R}</g>`:"")),width:C,height:E,links:[]}}},LM=class{nodes=new Map;labels;links=[];trends=new Map;pipelines=new Map;annotations=[];notes=[];accelerators=[];deaccelerators=[];annotationsBox;axes={};size;addNode(e){let t=this.nodes.get(e.id)??{id:e.id,label:e.label};this.nodes.set(e.id,{...t,...e,className:e.className??t.className,labelOffsetX:e.labelOffsetX??t.labelOffsetX,labelOffsetY:e.labelOffsetY??t.labelOffsetY}),this.labels=void 0}addLink(e){this.links.push(e)}addTrend(e){this.trends.set(e.nodeId,e)}startPipeline(e){this.pipelines.set(e,{nodeId:e,componentIds:[]});let t=this.nodes.get(e);t&&(t.isPipelineParent=!0)}addPipelineComponent(e,t){this.pipelines.get(e)?.componentIds.push(t);let r=this.nodes.get(t);r&&(r.inPipeline=!0)}addAnnotation(e){this.annotations.push(e)}addNote(e){this.notes.push(e)}addAccelerator(e){this.accelerators.push(e)}addDeaccelerator(e){this.deaccelerators.push(e)}setAnnotationsBox(e,t){this.annotationsBox={x:e,y:t}}setAxes(e){this.axes={...this.axes,...e}}setSize(e,t){this.size={width:e,height:t}}getNode(e){return this.nodes.get(e)}resolveNodeId(e){if(this.nodes.has(e))return e;if(!this.labels){this.labels=new Map;for(let[e,t]of this.nodes)this.labels.has(t.label)||this.labels.set(t.label,e)}return this.labels.get(e)??e}build(){let e=[];for(let t of this.nodes.values()){if("number"!=typeof t.x||"number"!=typeof t.y)throw new i(`Node "${t.label}" is missing coordinates`,"semantic",{type:"wardley"});e.push(t)}return{nodes:e,links:[...this.links],trends:[...this.trends.values()],pipelines:[...this.pipelines.values()],annotations:[...this.annotations],notes:[...this.notes],accelerators:[...this.accelerators],deaccelerators:[...this.deaccelerators],annotationsBox:this.annotationsBox,axes:{...this.axes},size:this.size}}};function OM(e,t){let r=e<=1?100*e:e;if(r<0||r>100)throw new i(`${t} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${e}`,"semantic",{type:"wardley"});return r}function FM(e,t,r){return{x:OM(t,`${r} evolution`),y:OM(e,`${r} visibility`)}}function zM(e){return"+<>"===e?"bidirectional":"+<"===e?"backward":"+>"===e?"forward":void 0}function WM(e){if(!e?.startsWith("+"))return{};let t=e.indexOf("'",2),r="'"===e[1]&&-1!==t?e.slice(2,t):void 0;return e.includes("<>")?{flow:"bidirectional",label:r}:e.includes("<")?{flow:"backward",label:r}:e.includes(">")?{flow:"forward",label:r}:{label:r}}function PM(e){return e?[(e.negX?-1:1)*e.offsetX,(e.negY?-1:1)*e.offsetY]:[void 0,void 0]}function BM(e,t){let r=new LM;return function(e,t){e.size&&t.setSize(e.size.width,e.size.height),e.evolution&&t.setAxes({stages:e.evolution.stages.map(e=>e.secondName?`${e.name.trim()} / ${e.secondName.trim()}`:e.name.trim()),stageBoundaries:e.evolution.stages.filter(e=>void 0!==e.boundary).map(e=>e.boundary)});for(let r of e.anchors){let e=FM(r.visibility,r.evolution,`Anchor "${r.name}"`);t.addNode({id:r.name,label:r.name,x:e.x,y:e.y,className:"anchor"})}for(let r of e.components){let e=FM(r.visibility,r.evolution,`Component "${r.name}"`),[a,i]=PM(r.label);t.addNode({id:r.name,label:r.name,x:e.x,y:e.y,className:"component",labelOffsetX:a,labelOffsetY:i,inertia:r.inertia,sourceStrategy:r.decorator?.strategy})}for(let r of e.notes){let e=FM(r.visibility,r.evolution,`Note "${r.text}"`);t.addNote({text:r.text,x:e.x,y:e.y})}for(let r of e.pipelines){let e=t.getNode(r.parent);if(!e||"number"!=typeof e.y)throw new i(`Pipeline "${r.parent}" must reference an existing component with coordinates.`,"semantic",{type:"wardley"});let a=e.y;t.startPipeline(r.parent);for(let e of r.components){let i=`${r.parent}_${e.name}`,[l,n]=PM(e.label),s=OM(e.evolution,`Pipeline component "${e.name}" evolution`);t.addNode({id:i,label:e.name,x:s,y:a,className:"pipeline-component",labelOffsetX:l,labelOffsetY:n,inertia:void 0,sourceStrategy:void 0}),t.addPipelineComponent(r.parent,i)}}for(let r of e.links){let e=!!r.arrow&&(r.arrow.includes("-.->")||r.arrow.includes(".-.")),a=WM(r.arrow),i=zM(r.fromPort)??zM(r.toPort)??a.flow;t.addLink({source:t.resolveNodeId(r.from),target:t.resolveNodeId(r.to),dashed:e,label:a.label??r.linkLabel,flow:i})}for(let r of e.evolves){let e=t.getNode(r.component);void 0!==e?.y&&t.addTrend({nodeId:r.component,targetX:OM(r.target,`Evolve target for "${r.component}"`),targetY:e.y})}if(e.annotations.length>0){let r=FM(e.annotations[0].x,e.annotations[0].y,"Annotations box");t.setAnnotationsBox(r.x,r.y)}for(let r of e.annotation){let e=FM(r.x,r.y,`Annotation ${r.number}`);t.addAnnotation({number:r.number,coordinates:[{x:e.x,y:e.y}],text:r.text})}for(let r of e.accelerators){let e=FM(r.x,r.y,`Accelerator "${r.name}"`);t.addAccelerator({name:r.name,x:e.x,y:e.y})}for(let r of e.deaccelerators){let e=FM(r.x,r.y,`Deaccelerator "${r.name}"`);t.addDeaccelerator({name:r.name,x:e.x,y:e.y})}}(e,r),{type:"wardley",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,"\n"):void 0,...r.build()}}function HM(e,t){let r=t;for(let t=e.charCodeAt(r);t>=48&&t<=57;t=e.charCodeAt(r))r++;return r}var YM={name:"ARROW",pattern:/->/y,first:"-"},GM={name:"LINK_ARROW",pattern:/-->|-\.->|>|\+'[^']*'<>|\+'[^']*'<|\+'[^']*'>/y,first:"->+"},UM=(e,t)=>({name:e,pattern:new RegExp(t,"y"),first:t[0]}),qM=[{name:"[",pattern:"["},{name:",",pattern:","},{name:"]",pattern:"]"},{name:"@",pattern:"@"},{name:"/",pattern:"/"},{name:"(",pattern:"("},{name:")",pattern:")"},{name:"-",pattern:"-",longer:[YM,GM,$n]},{name:"{",pattern:"{"},{name:"}",pattern:"}"},{name:"WARDLEY_NUMBER",pattern:/[0-9]+\.[0-9]+/y,first:"0123456789",scanner:function(){let e=0,t=0;return(r,a)=>{if((a<e||a>=t)&&(e=a,t=HM(r,a)),t===a||46!==r.charCodeAt(t))return-1;let i=HM(r,t+1);return i>t+1?i:-1}}},YM,{name:"LINK_PORT",pattern:/\+<>|\+>|\+</y,first:"+"},GM,{name:"LINK_LABEL",pattern:/;[^\n\r]+/y,first:";"},{name:"STRATEGY",pattern:/build|buy|outsource|market/y,first:"bom"},UM("KW_WARDLEY","wardley-beta"),UM("KW_SIZE","size"),UM("KW_EVOLUTION","evolution"),UM("KW_ANCHOR","anchor"),UM("KW_COMPONENT","component"),UM("KW_LABEL","label"),UM("KW_INERTIA","inertia"),UM("KW_EVOLVE","evolve"),UM("KW_PIPELINE","pipeline"),UM("KW_NOTE","note"),UM("KW_ANNOTATIONS","annotations"),UM("KW_ANNOTATION","annotation"),UM("KW_ACCELERATOR","accelerator"),UM("KW_DEACCELERATOR","deaccelerator"),{name:"NAME_WITH_SPACES",pattern:/(?!title\s|accTitle|accDescr)[A-Za-z](?:[A-Za-z0-9_()&]|-(?!>))*(?:[ \t]+[A-Za-z(](?:[A-Za-z0-9_()&]|-(?!>))*)*/y,first:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},{name:"WS",pattern:/[ \t]+/y,hidden:!0,first:"\t "},xc(),pn,gn,{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y,first:"0123456789"},yn,{name:"ID",pattern:/[\w]([-\w]*\w)?/y,first:"_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},xn,wn,$n,bn,Mn];var jM=["Genesis","Custom Built","Product","Commodity"],VM=10,XM=15,KM=60,ZM="var(--_c)",QM="var(--_l)";function JM(e,t,r){return e<t?t:e>r?r:e}function ev(e,t,r,a){let i=Qe(e),l="",n=r;for(let r of e.lines){let a=!0;for(let e of r){if(void 0!==e.icon)continue;let r=Ze(e.style&~i);l+=`<tspan${a?` x="${Oe(t)}" y="${Oe(n)}"`:""}${r}>${De(e.text)}</tspan>`,a=!1}n+=e.lineHeight}return""===l?"":`<text${Je(a,i)} xml:space="preserve">${l}</text>`}function tv(e,t,r,a){let i="number"==typeof t&&Number.isFinite(t)?t:function(e,t,r,a,i){let l=e["wardley-beta"]?.[t];return"number"==typeof l&&l>=a&&l<=i?l:r}(e,r,a,1,1e6);return JM(i,200,1e4)-96}var rv={type:"wardley",section:"wardley-beta",parse:(e,t,r)=>BM(function(e){let t=new Dn(fn(e,qM,"wardley"),qM,"wardley"),r={$type:"Wardley",anchors:[],components:[],links:[],evolves:[],pipelines:[],notes:[],annotations:[],annotation:[],accelerators:[],deaccelerators:[]},a=e=>t.kinds[t.i]===e,i=()=>a(36)||a(37)||a(30),l=()=>a(36)?Nn(t.take()):a(37)||a(30)?t.take():t.fail("a name"),n=()=>Number(t.expect(10)),s=()=>parseInt(t.expect(35)),o=()=>a(10)?Number(t.take()):parseInt(t.expect(35)),h=()=>{if(!a(-1))for(a(38)||t.fail("a line break or the end of input");a(38);)t.i++},c=e=>{t.expect(0);let r=e();t.expect(1);let a=e();return t.expect(2),[r,a]},d=()=>{t.expect(21),t.expect(0);let e=t.accept(7),r=s();t.expect(1);let a=t.accept(7),i=s();return t.expect(2),{$type:"Label",negX:e,offsetX:r,negY:a,offsetY:i}},f=()=>{let e={$type:"EvolutionStage",name:l()};return t.accept(3)&&(e.boundary=n()),t.accept(4)&&(e.secondName=l()),e};for(;a(38);)t.i++;for(t.expect(16);!a(-1);)switch(t.kind){case 38:t.i++;break;case 32:r.accDescr=Sn(t.take()),h();break;case 33:r.accTitle=_n(t.take()),h();break;case 34:r.title=En(t.take()),h();break;case 17:{t.i++;let[e,a]=c(s);h(),r.size={$type:"Size",width:e,height:a};break}case 18:{t.i++;let e=[f()];for(t.expect(11),e.push(f());t.accept(11);)e.push(f());h(),r.evolution={$type:"Evolution",stages:e};break}case 19:{t.i++;let e=l(),[a,i]=c(n);h(),r.anchors.push({$type:"Anchor",name:e,visibility:a,evolution:i});break}case 20:{t.i++;let e={$type:"Component",name:l(),visibility:0,evolution:0,inertia:!1};[e.visibility,e.evolution]=c(n),a(21)&&(e.label=d()),a(5)&&15===t.kinds[t.i+1]&&(t.i++,e.decorator={$type:"Decorator",strategy:t.take()},t.expect(6)),t.accept(22)?e.inertia=!0:t.accept(5)&&(t.expect(22),t.expect(6),e.inertia=!0),h(),r.components.push(e);break}case 23:{t.i++;let e=l(),a=n();h(),r.evolves.push({$type:"Evolve",component:e,target:a});break}case 24:{t.i++;let e=l();for(t.expect(8),t.expect(38);a(38);)t.i++;let i=[];do{t.expect(20);let e={$type:"PipelineComponent",name:l(),evolution:0};t.expect(0),e.evolution=n(),t.expect(2),a(21)&&(e.label=d()),h(),i.push(e)}while(a(20));t.expect(9),h(),r.pipelines.push({$type:"Pipeline",parent:e,components:i});break}case 25:{t.i++;let e=Nn(t.expect(36)),[a,i]=c(n);h(),r.notes.push({$type:"Note",text:e,visibility:a,evolution:i});break}case 26:{t.i++;let[e,a]=c(o);h(),r.annotations.push({$type:"Annotations",x:e,y:a});break}case 27:{t.i++;let e=s();t.expect(1);let[a,i]=c(o),l=Nn(t.expect(36));h(),r.annotation.push({$type:"Annotation",number:e,x:a,y:i,text:l});break}case 28:case 29:{let e=29===t.kind;t.i++;let a=l(),[i,s]=c(n);h(),e?r.deaccelerators.push({$type:"Deaccelerator",name:a,x:i,y:s}):r.accelerators.push({$type:"Accelerator",name:a,x:i,y:s});break}default:{i()||t.fail("a statement");let e={$type:"Link",from:l(),to:""};a(12)&&(e.fromPort=t.take()),(a(13)||a(11))&&(e.arrow=t.take()),e.to=l(),a(12)&&(e.toPort=t.take()),a(14)&&(e.linkLabel=t.take().substring(1).trim()),h(),r.links.push(e)}}return r}(e),r),render:function(e,t,r){let a=tv(t,e.size?.width,"width",900);return Yl(r,a,160,(i,l)=>function(e,t,r,a,i,l){let n=r.fontSize??16,s=Math.round(.8125*n),o=Math.round(.6875*n),h=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),c=r.padding??8,d=tv(t,e.size?.height,"height",600)*Math.max(.75,a/i),f=!0===t["wardley-beta"]?.showGrid,u=0,p=0,g=a,m=d,y=(e,t,r,a)=>{e<u&&(u=e),t<p&&(p=t),r>g&&(g=r),a>m&&(m=a)},x=(e,t,a,i)=>(y(t-e.width/2,a-e.height/2,t+e.width/2,a+e.height/2),Fe(e,t,a,i,r.icons)),w=(e,t,r,a)=>(y(t,r-e.size,t+e.width,r-e.size+e.height+4),ev(e,t,r,a)),$=(e,t,r=(l?Math.max(64,Math.min(120,a/2)):4e3),i=0)=>Fl(e,!1,h,t,r,i),b=e=>e/100*a,M=e=>d-e/100*d,v=e.axes.stages&&e.axes.stages.length>0?e.axes.stages:jM,k=e.axes.stageBoundaries,A=void 0!==k&&k.length===v.length,T="",C="",E=d,_=0;if(v.forEach((e,t)=>{let r=A?_:t/v.length,i=A?JM(k[t],0,1):(t+1)/v.length;_=i,t>0&&(T+=`<path class="pele-wardley-stage" d="M${Oe(r*a)},0V${Oe(d)}" stroke="var(--_b)" stroke-dasharray="4 4"/>`);let l=$(e,s,Math.max(48,Math.abs(i-r)*a-12));C+=x(l,(r+i)/2*a,d+8+l.height/2,` class="pele-wardley-stage-label" font-size="${s}" fill="var(--_m)"`),E=Math.max(E,d+8+l.height)}),f)for(let e=1;e<4;e++)T+=`<path class="pele-wardley-grid" d="M${Oe(a*e/4)},0V${Oe(d)}M0,${Oe(d*e/4)}H${Oe(a)}" stroke="var(--_b)" stroke-dasharray="2 6"/>`;T+=`<path class="pele-wardley-axis" d="M0,0V${Oe(d)}H${Oe(a)}" stroke="${QM}"/>`;let S=$(e.axes.xLabel??"Evolution",s),I=$(e.axes.yLabel??"Visibility",s),N=` class="pele-wardley-axis-label" font-size="${s}" font-weight="var(--_hw)"`,D=x(S,a/2,E+6+S.height/2,N)+Fe(I,-16,d/2,`${N} transform="rotate(-90 -16 ${Oe(d/2)})"`);y(-16-I.height/2,0,0,0);let R=E+6+S.height+10,L=new Map;for(let t of e.nodes)L.set(t.id,{x:b(t.x),y:M(t.y),node:t});let O="",F=new Map;for(let t of e.pipelines){F.set(t.nodeId,new Set(t.componentIds));let e=[];for(let r of t.componentIds){let t=L.get(r);t&&e.push(t)}if(0===e.length)continue;e.sort((e,t)=>e.x-t.x);let r=e[0].x,a=e[e.length-1].x,i=e[0].y,l=i-12,n=L.get(t.nodeId);n&&(n.x=(r+a)/2,n.y=l-VM/6),y(r-XM,l,a+XM,l+24),O+=`<g class="pele-wardley-pipeline" data-id="${Re(t.nodeId)}"><rect x="${Oe(r-XM)}" y="${Oe(l)}" width="${Oe(a-r+30)}" height="${Oe(24)}" fill="var(--_s)" stroke="var(--_b)"${Mi}/>`+(e.length>1?`<path d="M${Oe(r)},${Oe(i)}H${Oe(a)}" stroke="${QM}" stroke-dasharray="4 4"/>`:"")+"</g>"}let z=new Map,W=(e,t,r)=>{let i=e.node;if("anchor"===i.className){let e=z.get(i);return e||z.set(i,e=$(i.label,s,l?Math.max(64,a/2):4e3,1)),1/Math.hypot(t/(e.width/2+5),r/(.8*s))}return i.isPipelineParent?VM/Math.SQRT2:i.sourceStrategy?12:6},P=new Map,B=(e,t,r)=>{Math.abs(t)<.25||Math.abs(r)<.25||P.set(e,(P.get(e)??0)|(t>0?r<0?1:2:r<0?4:8))},H="";for(let t of e.links){let e=L.get(t.source),r=L.get(t.target);if(!e||!r||e===r||F.get(t.target)?.has(t.source))continue;let a=r.x-e.x,i=r.y-e.y,l=Math.hypot(a,i);if(l<.01)continue;let n=a/l,s=i/l,h=W(e,n,s),c=W(r,n,s);if(h+c>=l)continue;B(e,n,s),B(r,-n,-s);let d=e.x+n*h,f=e.y+s*h,u=r.x-n*c,p=r.y-s*c,g="";("forward"===t.flow||"bidirectional"===t.flow)&&(g+=li("arrow_point",u,p,n,s,QM),u-=n*ii("arrow_point"),p-=s*ii("arrow_point")),("backward"===t.flow||"bidirectional"===t.flow)&&(g+=li("arrow_point",d,f,-n,-s,QM),d+=n*ii("arrow_point"),f+=s*ii("arrow_point"));let m="";if(t.label){let a=$(t.label,o+1,200),i=n>=0?1:-1,l=s*i,h=-n*i,c=5+Math.abs(l)*a.width/2+Math.abs(h)*a.height/2;m=x(a,(e.x+r.x)/2+l*c,(e.y+r.y)/2+h*c,` class="pele-edge-label" font-size="${o+1}" fill="var(--_m)"`)}H+=`<g class="pele-edge${t.dashed?" pele-wardley-dashed":""}" data-id="${Re(t.source)}-${Re(t.target)}"><path d="M${Oe(d)},${Oe(f)}L${Oe(u)},${Oe(p)}" stroke="${QM}"${t.dashed?' stroke-dasharray="6 6"':""}/>`+g+m+"</g>"}let Y="";for(let t of e.trends){let e=L.get(t.nodeId);if(!e)continue;let r=b(t.targetX),a=M(t.targetY),i=r-e.x,l=a-e.y,n=Math.hypot(i,l),s="",o=n>0?W(e,i/n,l/n):0;if(n>o+6+4){let t=i/n,h=l/n,c=r-8*t,d=a-8*h;s=`<path d="M${Oe(e.x+t*o)},${Oe(e.y+h*o)}L${Oe(c-t*ii("arrow_point"))},${Oe(d-h*ii("arrow_point"))}" stroke="${ZM}" stroke-dasharray="4 4"/>`+li("arrow_point",c,d,t,h,ZM)}y(r-6,a-6,r+6,a+6),Y+=`<g class="pele-wardley-trend" data-id="${Re(t.nodeId)}">${s}<circle cx="${Oe(r)}" cy="${Oe(a)}" r="6" fill="var(--_bg)" stroke="${ZM}"/></g>`}let G="",U=1.2*6,q=.7*6;for(let e of L.values()){let t=e.node,{x:r,y:i}=e,n="anchor"===t.className,o=t.sourceStrategy,h="";if(o){let e="outsource"===o?"var(--_m)":"buy"===o?"var(--_a)":"build"===o?"var(--_s)":"var(--_bg)";h+=`<circle class="pele-wardley-${o}" cx="${Oe(r)}" cy="${Oe(i)}" r="12" fill="${e}" stroke="${QM}"/>`}if("market"===o){let e=U*Math.cos(Math.PI/6),t=i+U*Math.sin(Math.PI/6);h+=`<path d="M${Oe(r)},${Oe(i-U)}L${Oe(r-e)},${Oe(t)}H${Oe(r+e)}Z" fill="none" stroke="${QM}"/>`;for(let[a,l]of[[r,i-U],[r-e,t],[r+e,t]])h+=`<circle cx="${Oe(a)}" cy="${Oe(l)}" r="${Oe(q)}" fill="var(--_bg)" stroke="${QM}"/>`}else t.isPipelineParent?h+=`<rect x="${Oe(r-5)}" y="${Oe(i-5)}" width="10" height="10" fill="var(--_bg)" stroke="${QM}"/>`:n||(h+=`<circle cx="${Oe(r)}" cy="${Oe(i)}" r="6" fill="var(--_bg)" stroke="${QM}"/>`);if(!0===t.inertia){h+=`<rect class="pele-wardley-inertia" x="${Oe(r+(10+(t.isPipelineParent?5:6)+(o?10:0)))}" y="${Oe(i-6)}" width="4" height="12" fill="${QM}"/>`}let c,d=void 0===t.labelOffsetX?void 0:JM(t.labelOffsetX,-5e3,5e3),f=void 0===t.labelOffsetY?void 0:JM(t.labelOffsetY,-5e3,5e3);if(n){let e=z.get(t)??$(t.label,s,l?Math.max(64,a/2):4e3,1);c=x(e,r+(d??0),i+(f??-3),` class="pele-label" font-size="${s}" font-weight="var(--_hw)"`)}else{let a=$(t.label,s),l=` class="pele-label" font-size="${s}"`,n=8+(o?10:0);if(void 0!==d||void 0!==f)c=w(a,r+(d??n),i+(f??-n),l);else if(t.inPipeline)c=x(a,r,i+12+4+a.height/2,l);else{let t=P.get(e)??0,o=1&t?2&t?4&t?8&t?1:8:4:2:1,h=1===o||4===o;c=w(a,1===o||2===o?r+n:r-n-a.width,h?i-n:i+n+.75*s,l)}}y(r-12,i-12,r+12+20,i+12),G+=`<g class="pele-node pele-wardley-${n?"anchor":t.isPipelineParent?"pipeline-parent":t.inPipeline?"pipeline-component":"component"}" data-id="${Re(t.id)}">${h}${c}</g>`}let j="";for(let t of e.annotations){let e=$(String(t.number),o,4e3,1),r="";for(let a of t.coordinates){let t=b(a.x),i=M(a.y),l=Math.max(10,e.width/2+4);y(t-l,i-l,t+l,i+l),r+=`<circle cx="${Oe(t)}" cy="${Oe(i)}" r="${Oe(l)}" fill="var(--_bg)" stroke="${QM}"/>`+Fe(e,t,i,` font-size="${o}" font-weight="var(--_hw)"`)}j+=`<g class="pele-wardley-annotation" data-id="${Re(String(t.number))}">${r}</g>`}let V=e.annotations.filter(e=>e.text).sort((e,t)=>e.number-t.number);if(V.length>0){let t=V.map(e=>$(`${e.number}. ${e.text}`,s,l?Math.max(80,a-20):320)),r=0,i=0;for(let e of t)r=Math.max(r,e.width),i+=e.height;r+=20,i+=14;let n=e.annotationsBox,o=n?JM(b(n.x),0,Math.max(0,a-r)):0,h=n?JM(M(n.y),0,Math.max(0,d-i)):R;y(o,h,o+r,h+i);let c="",f=h+7;for(let e of t)c+=ev(e,o+10,f+e.lineHeight/2+.35*s,` font-size="${s}"`),f+=e.height;j+=`<g class="pele-wardley-annotations"><rect x="${Oe(o)}" y="${Oe(h)}" width="${Oe(r)}" height="${Oe(i)}" fill="var(--_bg)" stroke="var(--_b)"${Mi}/>${c}</g>`}let X="";for(let t of e.notes)X+=w($(t.text,s,Math.min(360,.6*a),1),b(t.x),M(t.y),` class="pele-wardley-note" font-size="${s}" font-weight="var(--_hw)"`);let K="",Z=(e,t,r,a)=>{let i=b(t),l=M(r),n=15,s=a?i+KM:i,h=a?i:i+KM,c=a?i+KM-20:i+20,d=`M${Oe(h)},${Oe(l-n)}H${Oe(c)}V${Oe(l-n-8)}L${Oe(s)},${Oe(l)}L${Oe(c)},${Oe(l+n+8)}V${Oe(l+n)}H${Oe(h)}Z`;y(i,l-n-8,i+KM,l+n+8),K+=`<g class="pele-wardley-${a?"accelerator":"deaccelerator"}" data-id="${Re(e)}"><path d="${d}" fill="var(--_s)" stroke="${QM}"/>`+x($(e,o+1,160,1),i+30,l+n+8+12,` font-size="${o+1}" font-weight="var(--_hw)"`)+"</g>"};for(let t of e.accelerators)Z(t.name,t.x,t.y,!0);for(let t of e.deaccelerators)Z(t.name,t.x,t.y,!1);let Q=Fl(e.title,!1,h,n,l?Math.max(80,a):4e3,1),J=Q.height>0?Q.height+12:0,ee=Math.min(u,a/2-Q.width/2),te=Math.max(g,a/2+Q.width/2),re=c-ee,ae=c+J-p,ie=Math.ceil(te-ee+2*c),le=Math.ceil(m-p+J+2*c),ne=Fe(Q,re+a/2,c+Q.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${Oe(re)},${Oe(ae)})"><g class="pele-wardley-frame" fill="none">${T}</g>`+C+D+O+(H?`<g class="pele-edges" fill="none">${H}</g>`:"")+(Y?`<g class="pele-wardley-trends" fill="none">${Y}</g>`:"")+G+j+X+K+"</g>";return{svg:Bi("wardley",ie,le,n,r,e,ne),width:ie,height:le,links:[]}}(e,t,r,i,a,l))}},av=class{type="xychart";title;accTitle;accDescr;orientation;xAxis={type:"band",title:"",categories:[]};yAxis={type:"linear",title:"",min:1/0,max:-1/0};hasSetXAxis=!1;hasSetYAxis=!1;plots=[];setOrientation(e){this.orientation="horizontal"===e?"horizontal":"vertical"}setXAxisTitle(e){this.xAxis.title=e.text.trim()}setXAxisRangeData(e,t){this.xAxis={type:"linear",title:this.xAxis.title,min:e,max:t},this.hasSetXAxis=!0}setXAxisBand(e){this.xAxis={type:"band",title:this.xAxis.title,categories:e.map(e=>e.text.trim())},this.hasSetXAxis=!0}setYAxisTitle(e){this.yAxis.title=e.text.trim()}setYAxisRangeData(e,t){this.yAxis={type:"linear",title:this.yAxis.title,min:e,max:t},this.hasSetYAxis=!0}plotData(e){if(0===e.length)return[];this.hasSetXAxis||this.setXAxisRangeData(1,e.length);let t=this.xAxis;if("band"===t.type&&e.length>t.categories.length&&(e=e.slice(0,t.categories.length)),!this.hasSetYAxis){let{min:t,max:r}=this.yAxis;for(let a of e)a<t&&(t=a),a>r&&(r=a);this.yAxis={type:"linear",title:this.yAxis.title,min:t,max:r}}if("band"===t.type)return t.categories.map((t,r)=>[t,e[r]]);if(1===e.length)return[[`${t.min}`,e[0]]];let r=(t.max-t.min)/(e.length-1);return e.map((e,a)=>[`${t.min+a*r}`,e])}addPlot(e,t,r){let a={type:e,title:t.text.trim(),data:this.plotData(r.map(e=>e.value))};"line"===e&&r.some(e=>""!==e.label.trim())&&(a.pointLabels=r.map(e=>e.label.trim())),this.plots.push(a)}setLineData(e,t){this.addPlot("line",e,t)}setBarData(e,t){this.addPlot("bar",e,t)}setDiagramTitle(e){this.title=e}setAccTitle(e){this.accTitle=e.replace(/^\s+/g,"")}setAccDescription(e){this.accDescr=e.replace(/\n\s+/g,"\n")}},iv=["$end","INVALID","NEWLINE","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","XYCHART","CHART_ORIENTATION","X_AXIS","Y_AXIS","ARROW_DELIMITER","LINE","BAR","NUMBER_WITH_DECIMAL","SQUARE_BRACES_START","SQUARE_BRACES_END","STR","ALPHA","COLON","PLUS","COMMA","EQUALS","MULT","BRKT","UNDERSCORE","DOT","AMP","MINUS","NUM","SEMI","EOF"],lv=[33,33,33,33,33,19,5,7,8],nv="`)"+" ".repeat(36)+'{ this.pushstate(md_string); }\n<md_string>(?:(?!`").)+'+" ".repeat(18)+"{ return md_str; }\n<md_string>(?:`",sv=new Uint8Array(128);for(let[e,t]of[[":",21],["+",22],[",",23],["=",24],["*",25],["#",26],["_",27],[".",28],["&",29],["-",30],[";",32]])sv[e.charCodeAt(0)]=t;function ov(...e){let t=new Uint8Array(34);for(let r of e)t[r]=1;return t}var hv=ov(29,31,20,22,24,25,28,26,30,27),cv=ov(2,32,33);function dv(e,t){let{types:r,texts:a,starts:i}=function(e){let t=e.length,r=[],a=[],i=[],l=[],n=0,s=0,o=(t,l,n)=>{r.push(t),a.push(e.slice(l,n)),i.push(l),s=n},h=e=>{l.push(n),n=e},c=()=>{l.length>0&&(n=l.pop())},d=r=>{let a=e.indexOf("\n",r);return-1===a?t:a},f=r=>{for(;r<t&&q(e.charCodeAt(r));)r++;return r},u=t=>{for(;X(e.charCodeAt(t));)t++;return t},p=t=>wg(e,s,t)&&!Q(e.charCodeAt(s+t.length));for(;s<t;){let r=e.charCodeAt(s);if(5===n){if(34===r)s++,c();else{let r=e.indexOf('"',s);o(19,s,-1===r?t:r)}continue}if(6===n||7===n){o(lv[n],s,d(s)),c();continue}if(8===n){if(125===r)s++,c();else{let r=e.indexOf("}",s);o(8,s,-1===r?t:r)}continue}let a=e.charCodeAt(s+1);if(37!==r||37!==a){if(10===r||13===r){if(!(1!==n&&3!==n||10!==r&&10!==a)){o(2,s,10===r?s+1:s+2),c();continue}let t=s+1;for(let r=e.charCodeAt(t);10===r||13===r;r=e.charCodeAt(++t));o(2,s,t);continue}switch(32|r){case 116:if(p("title")){o(3,s,s+5);continue}break;case 97:if(wg(e,s,"acc")){let t=wg(e,s+3,"descr");if(t||wg(e,s+3,"title")){let r=f(s+8),a=e.charCodeAt(r);if(58===a){o(t?6:4,s,f(r+1)),h(t?7:6);continue}if(123===a&&t){s=f(r+1),h(8);continue}}}break;case 120:if(p("xychart-beta")){o(9,s,s+12);continue}if(p("xychart")){o(9,s,s+7);continue}if(p("x-axis")){o(11,s,s+6),h(1);continue}break;case 121:if(p("y-axis")){o(12,s,s+6),h(1);continue}break;case 118:if(wg(e,s,"vertical")){o(10,s,s+8);continue}break;case 104:if(wg(e,s,"horizontal")){o(10,s,s+10);continue}break;case 108:if(p("line")){o(14,s,s+4),h(3);continue}break;case 98:if(p("bar")){o(15,s,s+3),h(3);continue}}if(91!==r)if(93!==r)if(1!==n||45!==r||45!==a||62!==e.charCodeAt(s+2)){if(1===n||4===n){let t=43===r||45===r?s+1:s,a=e.charCodeAt(t),i=-1;if(X(a)?(i=u(t+1),46===e.charCodeAt(i)&&X(e.charCodeAt(i+1))&&(i=u(i+2))):46===a&&X(e.charCodeAt(t+1))&&(i=u(t+2)),-1!==i){o(16,s,i);continue}}if(96===r&&wg(e,s,nv))s+=nv.length,c();else if(34!==r){if(K(r)){let t=s+1;for(;K(e.charCodeAt(t));)t++;o(20,s,t);continue}if(X(r))o(31,s,u(s+1));else if(q(r))s=f(s+1);else{if(!(r<128&&0!==sv[r]))break;o(sv[r],s,s+1)}}else s++,h(5)}else o(13,s,s+3);else(4===n||2===n)&&c(),o(18,s,s+1);else 1===n?h(2):3===n&&h(4),o(17,s,s+1)}else s=d(s+2)}return s<t?(r.push(1),a.push(""),i.push(s),{types:r,texts:a,starts:i}):(r.push(lv[n]),a.push(""),i.push(t),r.push(0),a.push(""),i.push(t),{types:r,texts:a,starts:i})}(e),l=0,n=t=>{let a=r[l];throw 1===a?c("xychart",e,i[l],"",!0):c("xychart",e,i[l],`Expecting ${t}, got '${iv[a]}'`)},s=e=>(r[l]!==e&&n(`'${iv[e]}'`),a[l++]),o=e=>19===e||1===hv[e],h=()=>{o(r[l])||n("'STR', 'ALPHA', 'NUM'");let e=a[l++];if(19!==r[l-1])for(;1===hv[r[l]];)e+=a[l++];return{text:e,type:"text"}},d=()=>{let e=Number(s(16));return s(13),[e,Number(s(16))]},f=()=>{let e=[];for(s(17);;){let t=Number(s(16));if(e.push({value:t,label:19===r[l]?a[l++]:""}),23!==r[l])break;l++}return s(18),e};for(;;)if(1===cv[r[l]])l++;else{if(9!==r[l])break;10===r[++l]&&t.setOrientation(a[l++])}for(;0!==r[l];){let e=r[l++];switch(e){case 3:t.setDiagramTitle(h().text.trim());break;case 11:case 12:{let a=o(r[l])?h():void 0;if(11===e&&17===r[l]){let e=[];do{l++,e.push(h())}while(23===r[l]);s(18),t.setXAxisBand(e)}else if(16===r[l]||void 0===a){let[r,a]=d();11===e?t.setXAxisRangeData(r,a):t.setYAxisRangeData(r,a)}11===e?t.setXAxisTitle(a??{type:"text",text:""}):t.setYAxisTitle(a??{type:"text",text:""});break}case 14:case 15:{let a=17===r[l]?{text:"",type:"text"}:h(),i=f();14===e?t.setLineData(a,i):t.setBarData(a,i);break}case 4:t.setAccTitle(s(5).trim());break;case 6:t.setAccDescription(s(7).trim());break;case 8:t.setAccDescription(a[l-1].trim());break;default:l--,n("'title', 'X_AXIS', 'Y_AXIS', 'LINE', 'BAR', 'acc_title', 'acc_descr', 'acc_descr_multiline_value'")}for(;1===cv[r[l]];)l++}}function fv(e,t){let r=e/Math.max(t,1),a=Math.floor(Math.log10(r)),i=r/10**a,l=i>=7.07?10:i>=3.16?5:i>=1.41?2:1;return a<0?-(10**-a)/l:l*10**a}function uv(e,t){return e>0?t/e:t*-e}function pv(e,t){return e>0?t*e:t/-e}function gv(e,t,r){let a=Math.round(uv(r,e));pv(r,a)<e&&a++;let i=Math.round(uv(r,t));pv(r,i)>t&&i--;let l=[];for(let e=a;e<=i&&l.length<100;e++)l.push(pv(r,e));return l}var mv=12,yv=1e300;function xv(e){return"object"!=typeof e||null===e||Array.isArray(e)?{}:e}function wv(e,t,r=!0){let a=e[t];return"boolean"==typeof a?a:r}function $v(e,t){return"number"==typeof e&&e>0?Math.round(Math.min(Math.max(e,100),4e3)):t}function bv(e){return"number"==typeof e&&isFinite(e)?Math.min(Math.max(e,-yv),yv):void 0}function Mv(e,t,r,a){let i=1===e.lines.length?e.lines[0]:void 0;return i&&1===i.length&&void 0===i[0].icon&&0===i[0].style?`<text x="${Oe(t)}" y="${Oe(r+.35*e.size)}" text-anchor="${a}">${De(i[0].text)}</text>`:Fe(e,t+("start"===a?e.width/2:"end"===a?-e.width/2:0),r,"")}return qt(...[Sd,cg,fc,Zp,Up,jw,up,kh,Rg,{type:"xychart",section:"xyChart",parse(e,t,r){let a=new av;return a.title=r,dv(e,a),a},render:function(e,t,r){if(0===e.plots.length)throw new i("No Plot to render, please provide a plot with some data","semantic",{type:"xychart"});let a=xv(t.xyChart),l=r.fontSize??16,n=Math.round(.875*l),s=Math.round(.75*l),o=r.measurer??Ce(r.fontFamily,r.fontFamilyMono),h=r.padding??8,c=$v(a.width,700),d=Ul(r,c,240),f=Math.round($v(a.height,500)*Math.max(.6,d/c)),u="horizontal"===(e.orientation??a.chartOrientation),p=wv(a,"showDataLabel",!1),g=e.xAxis,m=e.plots,y=(e,t,r)=>Fl(e,!1,o,t,r),x=y("0",n,4e3).height,w=y("0",s,4e3).height,$=Fl(wv(a,"showTitle")?e.title:void 0,!1,o,l,d-2*h,1),b=$.height>0?$.height+12:0,M=[],v=0;wv(a,"showLegend")&&m.forEach((e,t)=>{if(""===e.title)return;let r=y(e.title,n,.3*d);M.push({index:t,label:r}),v=Math.max(v,r.width+mv+8)});let k=M.length>0?v+24:0,A=m.filter(e=>"bar"===e.type).length,T=bv(e.yAxis.min)??1/0,C=bv(e.yAxis.max)??-1/0,E=e.hasSetYAxis&&isFinite(T)&&isFinite(C)&&T!==C;if(!E){T=1/0,C=-1/0;for(let e of m)for(let[,t]of e.data){let e=bv(t);void 0!==e&&(e<T&&(T=e),e>C&&(C=e))}T>C&&(T=C=0),A>0&&(T=Math.min(T,0),C=Math.max(C,0)),T===C&&(0===T?C=1:(T-=Math.abs(T)/2,C+=Math.abs(C)/2))}let _=(e,t)=>{let r=fv(Math.abs(C-T),Math.max(2,Math.min(10,Math.floor(e/t))));return E||(T=pv(r,Math.floor(uv(r,T)+1e-9)),C=pv(r,Math.ceil(uv(r,C)-1e-9))),gv(Math.min(T,C),Math.max(T,C),r).map(e=>({at:(e-T)/(C-T),label:y(String(e),n,4e3)}))},S=1;if("band"===g.type)S=Math.max(g.categories.length,1);else for(let e of m)S=Math.max(S,e.data.length);let I=1/S,N="band"===g.type||A>0?I/2:0,D=bv("linear"===g.type?g.min:void 0),R=bv("linear"===g.type?g.max:void 0),L=void 0!==D&&void 0!==R&&D!==R,O=(e,t)=>"band"===g.type?(e+.5)*I:N+(t>1?e/(t-1):L?0:.5)*(1-2*N),F=xv(a.xAxis),z=xv(a.yAxis),W=u?F:z,P=u?z:F,B=y(wv(W,"showTitle")?u?g.title:e.yAxis.title:void 0,n,.8*f),H=y(wv(P,"showTitle")?u?e.yAxis.title:g.title:void 0,n,.8*d),Y=wv(W,"showTick")?4:0,G=wv(P,"showTick")?4:0,U=wv(W,"showLabel"),q=wv(P,"showLabel"),j=u?.3*d:Math.max(48,(d-2*h-64-k)*I-8),V="band"===g.type&&wv(F,"showLabel")?g.categories.map(e=>y(e,n,j)):[],X=0,K=0;for(let e of V)X=Math.max(X,e.width),K=Math.max(K,e.height);let Z=e=>{let t=[];if("band"===g.type){let r=0===V.length?8:u?K:X+12,a=Math.max(1,Math.ceil(r/(e*I)));for(let e=0;e<g.categories.length;e+=a)t.push({at:(e+.5)*I,label:V[e]??y(void 0,n,0)})}else if(L){let r=fv(Math.abs(R-D),Math.max(2,Math.min(10,Math.floor(e/(u?32:80)))));for(let e of gv(Math.min(D,R),Math.max(D,R),r))t.push({at:N+(e-D)/(R-D)*(1-2*N),label:y(String(e),n,4e3)})}else void 0!==D&&t.push({at:.5,label:y(String(D),n,4e3)});return t},Q=0,J=0;for(let e of m){for(let t of e.pointLabels??[])Q=Math.max(Q,o.width(t,s,0));if(p&&u&&"bar"===e.type)for(let[,t]of e.data)J=Math.max(J,o.width(String(bv(t)??""),s,0))}let ee=q?u||"band"!==g.type?x:K:0,te=G+(ee>0?ee+4:0)+(H.height>0?H.height+4:0),re=h+b+(u?0:Q>0||p?w+4:U?x/2:0),ae=Math.max(1,f-h-te-re),ie=re+ae,le=u?Z(ae):_(ae,56),ne=U?function(e){let t=0;for(let r of e)t=Math.max(t,r.label.width);return t}(le):0,se=h+(B.height>0?B.height+6:0)+(ne>0?ne+6:0)+Y,oe=Math.max(Q>0?Q+12:0,J>0?J+8:0),he=u?Math.min(.25*d,oe):0,ce=Math.max(1,d-h-se-k-he),de=u?_(ce,80):Z(ce);if(q&&k+he===0){let e=0;for(let t of de)e=Math.max(e,t.at*ce+t.label.width/2-ce);ce=Math.max(1,ce-e)}let fe=se+ce,ue=(e,t)=>u?se+t*ce:se+e*ce,pe=(e,t)=>u?re+e*ae:ie-t*ae,ge=e=>(e-T)/(C-T),me=e=>Math.min(Math.max(e,0),1),ye=e=>u?`M${Oe(ue(0,e))},${Oe(re)}V${Oe(ie)}`:`M${Oe(se)},${Oe(pe(0,e))}H${Oe(fe)}`,xe="";for(let e of u?de:le)xe+=ye(e.at);let we="",$e="";wv(W,"showAxisLine")&&(we+=`M${Oe(se)},${Oe(re)}V${Oe(ie)}`),wv(P,"showAxisLine")&&(we+=`M${Oe(se)},${Oe(ie)}H${Oe(fe)}`);for(let e of le){let t=u?re+e.at*ae:ie-e.at*ae;Y&&(we+=`M${Oe(se)},${Oe(t)}h${-Y}`),U&&($e+=Mv(e.label,se-Y-6,t,"end"))}for(let e of de){let t=se+e.at*ce;G&&(we+=`M${Oe(t)},${Oe(ie)}v${G}`),q&&($e+=Mv(e.label,t,ie+G+4+e.label.height/2,"middle"))}let be=(u?ae:ce)*I,Me=.7*be/Math.max(A,1),ve=A>1?Math.min(2,.2*Me):0,ke=me(ge(0));A>0&&ke>0&&ke<1&&(we+=ye(ke));let Ae="",Te="",Ee="",_e="",Se=0;m.forEach((e,t)=>{let r=zi(t),a=e.title?` data-id="${Re(e.title)}"`:"",i="band"===g.type?Math.min(e.data.length,S):e.data.length;if("bar"===e.type){let t=(Se++-(A-1)/2)*Me-(Me-ve)/2,l="";for(let r=0;r<i;r++){let a=bv(e.data[r][1]);if(void 0===a)continue;let n=O(r,i),h=me(ge(a)),c=Math.min(ke,h),d=Math.max(ke,h),f=u?ue(n,c):ue(n,0)+t,g=u?pe(n,0)+t:pe(n,d),m=u?(d-c)*ce:Me-ve,y=u?Me-ve:(d-c)*ae;if(l+=`<rect x="${Oe(f)}" y="${Oe(g)}" width="${Oe(m)}" height="${Oe(y)}"/>`,!p)continue;let x=String(a),$=o.width(x,s,0),b=h>=ke?1:-1,M=f+m/2,v=g+y/2,k="middle";if(u){if(y<s)continue;M=(b>0?f+m:f)+6*b,k=b>0?"start":"end"}else{if($+2>be/A)continue;v=(b>0?g:g+y)-b*(w/2+2)}Ee+=`<text x="${Oe(M)}" y="${Oe(v+.35*s)}" text-anchor="${k}">${x}</text>`}return void(Ae+=`<g class="pele-series pele-bars"${a} fill="${r}">${l}</g>`)}let l="",n="",h=!1,c=0,d=NaN;for(let t=0;t<i;t++){let r=bv(e.data[t][1]);if(void 0===r){d=NaN;continue}let a=O(t,i),o=ge(r),f=o>=0&&o<=1;if(d!=d)f&&(l+=`M${Oe(ue(a,o))},${Oe(pe(a,o))}`),h=f;else{let e=o-d,t=0,r=1;if(0!==e){let a=-d/e,i=(1-d)/e;t=Math.max(t,Math.min(a,i)),r=Math.min(r,Math.max(a,i))}else f||(t=2);if(t<=r){let i=c+(a-c)*t,n=d+e*t,s=c+(a-c)*r,o=d+e*r;(!h||t>0)&&(l+=`M${Oe(ue(i,n))},${Oe(pe(i,n))}`),l+=`L${Oe(ue(s,o))},${Oe(pe(s,o))}`}h=f}if(c=a,d=o,!f)continue;let p=ue(a,o),g=pe(a,o);be>=12&&(n+=`<circle cx="${Oe(p)}" cy="${Oe(g)}" r="3"/>`);let m=y(e.pointLabels?.[t],s,4e3);if(m.height>0){let e=m.width/2;_e+=u?Mv(m,p+10,g,"start"):Mv(m,Math.max(Math.min(p,fe-e),se+e),g-6-m.height/2,"middle")}}Te+=`<g class="pele-series pele-line"${a} fill="${r}">`+(l?`<path d="${l}" fill="none" stroke="${r}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`:"")+n+"</g>"});let Ie="";B.height>0&&(Ie+=`<g transform="translate(${Oe(h+B.height/2)},${Oe(re+ae/2)}) rotate(-90)">${Fe(B,0,0,"")}</g>`),Ie+=Fe(H,se+ce/2,f-h-H.height/2,"");let Ne="",De=0;for(let e of M)De+=Math.max(26,e.label.height+6);let Le=re+Math.max(0,(ae-De)/2),ze=fe+he+24;for(let{index:e,label:t}of M){let r=Math.max(26,t.height+6);if(Le+r>f)break;let a=Le+r/2,i=zi(e);Ne+=`<g class="pele-legend-item" data-id="${Re(m[e].title)}">`+("bar"===m[e].type?`<rect x="${Oe(ze)}" y="${Oe(a-6)}" width="12" height="12" rx="2" fill="${i}"/>`:`<path d="M${Oe(ze)},${Oe(a)}h12" stroke="${i}" stroke-width="2" stroke-linecap="round"/>`)+Fe(t,ze+mv+8+t.width/2,a,"")+"</g>",Le+=r}let We=Fe($,d/2,h+$.height/2,' class="pele-title" font-weight="var(--_tw)"')+(xe?`<path class="pele-grid" d="${xe}" stroke="var(--_a)"/>`:"")+`<g class="pele-plot">${Ae}${Te}</g>`+(we?`<path class="pele-axis" d="${we}" fill="none" stroke="var(--_b)"/>`:"")+($e?`<g class="pele-axis-labels" font-size="${n}" fill="var(--_m)">${$e}</g>`:"")+(Ie?`<g class="pele-axis-titles" font-size="${n}">${Ie}</g>`:"")+(Ee?`<g class="pele-data-labels" font-size="${s}">${Ee}</g>`:"")+(_e?`<g class="pele-point-labels" font-size="${s}">${_e}</g>`:"")+(Ne?`<g class="pele-legend" font-size="${n}">${Ne}</g>`:"");return{svg:Bi("xychart",d,f,l,r,e,We),width:d,height:f,links:[]}}},Nw,pu,es,rx,$x,rg,Jg,I$,Bu,nw,Wu,Uo,Js,yy,on,x$,Fh,rv,Wc,xM,RM,Xu,zw]),e.PeleError=i,e.detectType=Qt,e.enableZoom=function(e,t={}){return Ot(e,t,!0)},e.forgetTextWidths=Ee,e.mount=function(e,t,r={}){return Gt({parse:Jt,render:er},e,t,r)},e.parse=Jt,e.register=qt,e.registered=function(e){return Ut.has(e)},e.render=er,e.supports=function(e){try{let t=Qt(e);return null!==t&&Ut.has(t)}catch{return!1}},e}({});