@zombie-mermaid/mermaid-parser 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,5 +1,11 @@
1
1
  Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@zombie-mermaid/core");var t=String.raw`[\w-]+`,n=new RegExp(String.raw`^(group|service)\s+(${t})\s*(?:\(([^)]*)\))?\s*(?:\[([^\]]*)\])?(?:\s+in\s+(${t}))?$`),r=new RegExp(String.raw`^junction\s+(${t})(?:\s+in\s+(${t}))?$`),i=new RegExp(String.raw`^(${t})(\{group\})?:([LRTB])\s+(<)?--(>)?\s+([LRTB]):(${t})(\{group\})?$`),a=new RegExp(String.raw`^align\s+(?:row|column)\s+${t}(?:\s+${t})+$`);function o(e,t){throw Error(`Architecture diagram, line ${e.line}: ${t} — "${e.text}"`)}function s(e){return e?.trim().replace(/^"(.*)"$/,`$1`)||void 0}function c(t){let c={groups:[],services:[],junctions:[],edges:[]},l=new Map,u=[],d=[],f=(e,t,n,r)=>{l.has(t)&&o(e,`duplicate id "${t}"`),r===t&&o(e,`"${t}" cannot be inside itself`),l.set(t,n),r&&u.push({stmt:e,parent:r})};for(let l=1;l<t.length;l++){let u=t[l],p=u.text,m=p.match(n);if(m){let t=m[1],n=m[2],r=m[4],i=m[5];f(u,n,t,i);let a={id:n,icon:s(m[3]),title:r===void 0?n:(0,e.normalizeBrTags)(r.trim()),parent:i};t===`group`?c.groups.push(a):c.services.push(a);continue}let h=p.match(r);if(h){let e=h[1],t=h[2];f(u,e,`junction`,t),c.junctions.push({id:e,parent:t});continue}let g=p.match(i);if(g){d.push({stmt:u,edge:{source:g[1],sourceGroup:g[2]!==void 0,sourcePort:g[3],arrowStart:g[4]!==void 0,arrowEnd:g[5]!==void 0,targetPort:g[6],target:g[7],targetGroup:g[8]!==void 0}});continue}a.test(p)||o(u,`unrecognized statement`)}for(let{stmt:e,parent:t}of u)l.get(t)!==`group`&&o(e,`"in ${t}" must name a declared group`);let p=new Map;for(let e of c.groups)e.parent&&p.set(e.id,e.parent);for(let e of c.groups){let t=new Set([e.id]);for(let n=p.get(e.id);n;n=p.get(n)){if(t.has(n))throw Error(`Architecture diagram: group "${e.id}" is nested inside itself`);t.add(n)}}for(let{stmt:e,edge:t}of d){let n=[[t.source,t.sourceGroup],[t.target,t.targetGroup]];for(let[t,r]of n){let n=l.get(t);n||o(e,`unknown id "${t}"`),n===`group`&&o(e,`edges connect services or junctions, not the group "${t}"`);let i=[...c.services,...c.junctions].find(e=>e.id===t)?.parent;r&&!i&&o(e,`"{group}" needs "${t}" to be declared inside a group`)}c.edges.push(t)}return c}var l={database:`cylinder`,disk:`cylinder`,cloud:`stadium`,internet:`circle`},u=new Set([`L`,`R`]);function d(e){let t=0,n=0;for(let r of e)for(let e of[r.sourcePort,r.targetPort])u.has(e)?t++:n++;return n>t?`TB`:`LR`}function f(e,t){let[n,r]=t===`LR`||t===`RL`?[`L`,`R`]:[`T`,`B`];return e.sourcePort===r||e.targetPort===n?!1:e.sourcePort===n||e.targetPort===r}function p(e){let t=new Map,n=new Map;for(let r of e.services)t.set(r.id,{id:r.id,label:r.title,shape:r.icon&&l[r.icon]||`rectangle`}),n.set(r.id,r.parent);for(let r of e.junctions)t.set(r.id,{id:r.id,label:``,shape:`filled-circle`}),n.set(r.id,r.parent);let r=new Map;for(let t of e.groups)r.set(t.id,{id:t.id,label:t.title,nodeIds:[],children:[]});let i=[];for(let t of e.groups){let e=r.get(t.id),n=t.parent?r.get(t.parent):void 0;n?n.children.push(e):i.push(e)}for(let[e,t]of n)r.get(t??``)?.nodeIds.push(e);let a=d(e.edges);return{direction:a,nodes:t,edges:e.edges.map(e=>{let t=(e,t)=>(t?n.get(e):void 0)??e,r=!f(e,a),[i,o]=r?[t(e.source,e.sourceGroup),t(e.target,e.targetGroup)]:[t(e.target,e.targetGroup),t(e.source,e.sourceGroup)];return{source:i,target:o,style:`solid`,hasArrowStart:r?e.arrowStart:e.arrowEnd,hasArrowEnd:r?e.arrowEnd:e.arrowStart}}),subgraphs:i,classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map}}var m={c4context:`context`,c4container:`container`,c4component:`component`,c4dynamic:`dynamic`,c4deployment:`deployment`},h=/^(?:UpdateElementStyle|UpdateRelStyle|UpdateLayoutConfig|LAYOUT_[A-Z_]+|SHOW_LEGEND|SHOW_FLOATING_LEGEND|AddElementTag|AddRelTag|AddBoundaryTag|RoleTag)\b/,g=/^(Person|System|Container|Component)(Db|Queue)?(_Ext)?$/,_=/^(?:Boundary|Enterprise_Boundary|System_Boundary|Container_Boundary)$/,v=/^(?:Deployment_Node|Node|Node_L|Node_R)$/,y=/^(Rel|BiRel|Rel_U|Rel_Up|Rel_D|Rel_Down|Rel_L|Rel_Left|Rel_R|Rel_Right|Rel_Back|RelIndex)$/,b={Enterprise_Boundary:`ENTERPRISE`,System_Boundary:`SYSTEM`,Container_Boundary:`CONTAINER`},x={Rel_U:`up`,Rel_Up:`up`,Rel_D:`down`,Rel_Down:`down`,Rel_L:`left`,Rel_Left:`left`,Rel_R:`right`,Rel_Right:`right`};function S(t){let n=t.trim(),r=n.length>=2&&n.startsWith(`"`)&&n.endsWith(`"`)?n.slice(1,-1):n;return(0,e.normalizeBrTags)(r)}function C(e){let t=[],n=``,r=!1;for(let i of e)i===`"`&&(r=!r),i===`,`&&!r?(t.push(n),n=``):n+=i;return r?null:(t.push(n),t.map(e=>e.trim()).filter(e=>!e.startsWith(`$`)).map(S))}var ee=/^([A-Za-z_][A-Za-z0-9_]*)\s*\((.*)\)\s*(\{)?\s*$/;function w(e,t){throw Error(`C4 diagram, line ${e.line}: ${t} — "${e.text}"`)}function te(t){let n=m[t[0]?.text.trim().toLowerCase()??``];if(!n)throw Error(`C4 diagram: expected a header of C4Context, C4Container, C4Component, C4Dynamic or C4Deployment, got "${t[0]?.text??``}"`);let r={variant:n,elements:[],boundaries:[],relationships:[]},i=new Set,a=[],o,s=(e,t)=>(t||w(e,`missing alias (first argument)`),i.has(t)&&w(e,`duplicate alias "${t}"`),i.add(t),t);for(let n=1;n<t.length;n++){let i=t[n],c=i.text;if(c===`}`){a.length===0&&w(i,`unmatched "}"`),a.pop();continue}if(c===`{`){o||w(i,`unexpected "{"`),a.push(o),o=void 0;continue}o=void 0;let l=c.match(/^title(?:\s+(.*))?$/i);if(l){r.title=(0,e.normalizeBrTags)((l[1]??``).trim());continue}if(h.test(c))continue;let u=c.match(ee);u||w(i,`unrecognized statement`);let d=u[1],f=u[3]===`{`,p=C(u[2]);p||w(i,`unbalanced quotes`);let m=d.match(g);if(m){f&&w(i,`"${d}" cannot contain a block`);let e=m[1].toLowerCase(),t=m[2]===`Db`?`db`:m[2]===`Queue`?`queue`:`default`,n=e===`container`||e===`component`,o=s(i,p[0]),c={alias:o,kind:e,shape:t,external:m[3]!==void 0,label:p[1]||o},l=n?p[2]:void 0,u=n?p[3]:p[2];l&&(c.technology=l),u&&(c.description=u),r.elements.push(c),a.at(-1)?.elementAliases.push(o);continue}if(_.test(d)||v.test(d)){let e=v.test(d),t=s(i,p[0]),n={alias:t,label:p[1]||t,elementAliases:[],children:[]};n.type=b[d]||(p[2]&&(e||d===`Boundary`)?p[2]:e?`node`:`system`),e&&p[3]&&(n.description=p[3]);let c=a.at(-1);c?c.children.push(n):r.boundaries.push(n),f?a.push(n):o=n;continue}if(d.match(y)){let e=d===`RelIndex`?p.slice(1):p;(!e[0]||!e[1])&&w(i,`a relationship needs "from" and "to" aliases`);let t={from:e[0],to:e[1],label:e[2]??``,bidirectional:d===`BiRel`};e[3]&&(t.technology=e[3]),d===`Rel_Back`&&(t.reversed=!0);let n=x[d];n&&(t.layout=n),r.relationships.push(t);continue}w(i,`unknown C4 macro "${d}"`)}if(a.length>0)throw Error(`C4 diagram: boundary "${a.at(-1).alias}" is missing its closing "}"`);r.variant===`dynamic`&&r.relationships.forEach((e,t)=>{e.index=String(t+1)});for(let e of r.relationships)for(let t of[e.from,e.to])if(!i.has(t))throw Error(`C4 diagram: relationship refers to undeclared alias "${t}"`);return r}function ne(e,t){let n=[];for(let r of e.split(`
2
- `)){let e=``;for(let i of r.split(/\s+/).filter(Boolean))e&&e.length+1+i.length>t?(n.push(e),e=i):e=e?`${e} ${i}`:i;n.push(e)}return n}var re={person:`Person`,system:`Software System`,container:`Container`,component:`Component`};function ie(e){let t=(e.kind===`container`||e.kind===`component`)&&e.technology?`: ${e.technology}`:``;return`[${re[e.kind]}${t}]`}function ae(e){return e.type?`[${e.type}]`:void 0}function oe(e){let t=[],n=[e.index?`${e.index}:`:``,e.label].filter(Boolean).join(` `);return n&&t.push(n),e.technology&&t.push(`[${e.technology}]`),t}function se(e){switch(e.layout){case`up`:return{source:e.to,target:e.from,axis:`vertical`,explicit:!0};case`left`:return{source:e.to,target:e.from,axis:`horizontal`,explicit:!0};case`right`:return{source:e.from,target:e.to,axis:`horizontal`,explicit:!0};case`down`:return{source:e.from,target:e.to,axis:`vertical`,explicit:!0};default:return{source:e.from,target:e.to,axis:`vertical`,explicit:!1}}}var ce=`<\\|--|<\\|\\.\\.|\\*--|o--|-->|--\\*|--o|--\\|>|\\.\\.>|\\.\\.\\|>|<--|<\\.\\.?|--`,le=new RegExp(ce);function ue(t){let n={classes:[],relationships:[],namespaces:[],interactions:new Map,classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,notes:[]},r=new Map,i=null,a=null,o=0,s;for(let l=1;l<t.length;l++){let u=t[l],d=u.text;if(a&&o>0){if(d===`}`){o--,o===0&&(a=null,s=void 0);continue}let e=d.match(/^<<(\w+)>>$/);if(e){a.annotation=e[1];continue}if(d.startsWith(`<<`))throw Error(`Line ${u.line}: Malformed class annotation "${d}" — expected "<<name>>" (e.g. "<<interface>>").`);T(a,d,u.line);continue}if(/^click\s+/i.test(d)){(0,e.applyClickStatement)(d,n.interactions);continue}let f=d.match(/^note\s+(?:for\s+(\S+)\s+)?"([^"]*)"\s*$/);if(f){let t=f[1];n.notes.push({text:(0,e.normalizeBrTags)(f[2]),...t?{forClass:t}:{}});continue}if((0,e.tryApplyClassDef)(d,n)||(0,e.tryApplyStyleStatement)(d,n)||(0,e.tryApplyCssClass)(d,n)||(0,e.tryApplyClassAssignment)(d,n))continue;let p=d.match(/^namespace\s+(\S+)\s*\{$/);if(p){i={name:p[1],classIds:[]};continue}if(d===`}`&&i){n.namespaces.push(i),i=null;continue}let m=d.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(m){let e=c(m[1],m[2]);a=r.get(e)??null,o=1,s=u.line;continue}let h=d.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(h){c(h[1],h[2]);continue}let g=d.match(/^class\s+(\S+?)\s*\{\s*(.*?)\s*\}$/);if(g){let e=c(g[1],void 0),t=r.get(e),n=g[2],i=n.match(/^<<(\w+)>>$/);if(t&&i)t.annotation=i[1];else if(t&&n.startsWith(`<<`))throw Error(`Line ${u.line}: Malformed class annotation "${n}" — expected "<<name>>" (e.g. "<<interface>>").`);else t&&n&&T(t,n,u.line);continue}let _=d.match(/^(\S+?)\s*:\s*(.+)$/);if(_){let e=_[2];if(!e.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){T(de(r,_[1]),e,u.line);continue}}let v=me(d);if(v){v.from=c(v.from,void 0,!1),v.to=c(v.to,void 0,!1),n.relationships.push(v);continue}if(le.test(d))throw Error(`Line ${u.line}: Malformed class-diagram relationship "${d}". Expected "FROM ARROW TO" (optionally with cardinalities and a ": label"), e.g. "Animal <|-- Dog" or 'A "1" --> "*" B : label'. ARROW must be one of <|--, <|.., *--, o--, -->, --*, --o, --|>, ..>, ..|>, <--, <.., or --.`)}if(a!==null)throw Error(`Line ${s}: Unclosed class body for "${a.id}" — expected a closing "}" before the diagram ends.`);return n.classes=[...r.values()],n;function c(t,a,o=!0){let{id:s,className:c}=(0,e.splitClassShorthand)(t),l=s,u=a;if(!u){let e=s.match(/^(.+?)~(\w+)~$/);e&&(l=e[1],u=e[2])}let d=de(r,l);return u&&(d.label=`${l}<${u}>`),c&&n.classAssignments.set(l,c),o&&i&&i.classIds.push(l),l}}function T(e,t,n){let r=pe(t,n);r&&(r.isMethod?e.methods.push(r.member):e.attributes.push(r.member))}function de(e,t){let n=e.get(t);return n||(n={id:t,label:t,attributes:[],methods:[]},e.set(t,n)),n}function E(e,t){return Math.max(0,e.split(t).length-1)}function fe(e){let t=E(e,`~`);if(t<=1)return e;let n=e,r=!1;t%2!=0&&n.startsWith(`~`)&&(n=n.slice(1),r=!0);let i=[...n],a=i.indexOf(`~`),o=i.lastIndexOf(`~`);for(;a!==-1&&o!==-1&&a!==o;)i[a]=`<`,i[o]=`>`,a=i.indexOf(`~`),o=i.lastIndexOf(`~`);return r&&i.unshift(`~`),i.join(``)}function D(e){let t=e.split(/(,)/),n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r===`,`&&e>0&&e+1<t.length){let i=t[e-1],a=t[e+1];E(i,`~`)===1&&E(a,`~`)===1&&(r=`${i},${a}`,e++,n.pop())}n.push(fe(r))}return n.join(``)}function pe(e,t){let n=e.trim().replace(/;$/,``);if(!n)return null;let r=``,i=n,a=i[0];if((a===`+`||a===`-`||a===`#`||a===`~`)&&(r=a,i=i.slice(1).trim()),i.includes(`(`)&&!i.includes(`)`))throw Error(`Line ${t}: Malformed class member "${n}" — unclosed "(" in a method signature. Expected e.g. "+eat() void" or "+eat(Food f) void".`);let o=i.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(o){let e=D(o[1].trim()),t=o[2]?.trim(),n=t?D(t):void 0,a=o[3]?.trim(),s=a?D(a):void 0,c=e.endsWith(`$`)||i.includes(`$`),l=e.endsWith(`*`)||i.includes(`*`);return{member:{visibility:r,name:e.replace(/[$*]$/,``),type:s||void 0,isStatic:c,isAbstract:l,isMethod:!0,params:n},isMethod:!0}}let s=D(i),c=s.endsWith(`$`),l=s.endsWith(`*`);return{member:{visibility:r,name:s.replace(/[$*]$/,``),type:void 0,isStatic:c,isAbstract:l,isMethod:!1},isMethod:!1}}function me(t){let n=t.match(RegExp(`^(\\S+?)\\s+(?:"([^"]*?)"\\s+)?(${ce})\\s+(?:"([^"]*?)"\\s+)?(\\S+?)(?::::([\\w][\\w-]*))?(?:\\s*:\\s*(.+))?$`));if(!n)return null;let r=n[1],i=n[2],a=i?(0,e.normalizeBrTags)(i):void 0,o=n[3].trim(),s=n[4],c=s?(0,e.normalizeBrTags)(s):void 0,l=n[6]?`${n[5]}:::${n[6]}`:n[5],u=n[7]?.trim(),d=u?(0,e.normalizeBrTags)(u):void 0,f=he(o);return f?{from:r,to:l,type:f.type,markerAt:f.markerAt,label:d,fromCardinality:a,toCardinality:c}:null}function he(e){switch(e.trim()){case`<|--`:return{type:`inheritance`,markerAt:`from`};case`--|>`:return{type:`inheritance`,markerAt:`to`};case`<|..`:return{type:`realization`,markerAt:`from`};case`..|>`:return{type:`realization`,markerAt:`to`};case`*--`:return{type:`composition`,markerAt:`from`};case`--*`:return{type:`composition`,markerAt:`to`};case`o--`:return{type:`aggregation`,markerAt:`from`};case`--o`:return{type:`aggregation`,markerAt:`to`};case`-->`:return{type:`association`,markerAt:`to`};case`<--`:return{type:`association`,markerAt:`from`};case`..>`:return{type:`dependency`,markerAt:`to`};case`<..`:return{type:`dependency`,markerAt:`from`};case`--`:return{type:`association`,markerAt:`to`};default:return null}}function ge(e){return`${e.visibility?`${e.visibility} `:``}${e.isMethod?`${e.name}(${e.params||``})`:e.name}${e.type?`: ${e.type}`:``}`}function _e(t){let n={entities:[],relationships:[]},r=new Map,i=null;for(let a=1;a<t.length;a++){let o=t[a],s=o.text;if(i){if(s===`}`){i=null;continue}let e=k(s);e&&i.attributes.push(e);continue}let c=s.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(c){n.direction=(0,e.toDirection)(c[1]);continue}let l=s.match(/^(\S+?)(?:\[(.+)\])?\s*\{(.*)$/);if(l){let t=l[1],n=l[2],a=O(r,t,n===void 0?void 0:(0,e.normalizeBrTags)(n.trim().replace(/^["']|["']$/g,``))),o=l[3].trim(),s=o.endsWith(`}`),c=s?o.slice(0,-1).trim():o;for(let e of c.split(`;`).map(e=>e.trim()).filter(Boolean)){let t=k(e);t&&a.attributes.push(t)}s||(i=a);continue}let u=ve(s,o.line);if(u){O(r,u.entity1),O(r,u.entity2),n.relationships.push(u);continue}}return n.entities=[...r.values()],n}function O(e,t,n){let r=e.get(t);return r?n!==void 0&&(r.label=n):(r={id:t,label:n??t,attributes:[]},e.set(t,r)),r}function k(t){let n=t.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!n)return null;let r=n[1],i=n[2],a=n[3]?.trim()??``,o=[],s,c=a.match(/"([^"]*)"/);c&&(s=(0,e.normalizeBrTags)(c[1]));let l=a.replace(/"[^"]*"/,``).trim();for(let e of l.split(/\s+/)){let t=e.toUpperCase();(t===`PK`||t===`FK`||t===`UK`)&&o.push(t)}return{type:r,name:i,keys:o,comment:s}}function ve(t,n){let r=t.match(/^(\S+)\s+(\S*(?:--|\.\.)\S*)\s+(\S+)\s*(?::\s*(.*))?$/);if(!r)return null;let i=r[1],a=r[2],o=r[3],s=r[4]!==void 0,c=r[4]?.trim()??``,l=a.match(/^([|o}{]*)(--|\.\.?)([|o}{]*)$/),u=l?ye(l[1]):null,d=l?be(l[3]):null;if(!u||!d)throw Error(`Line ${n}: Invalid ER relationship cardinality "${a}" in "${t}". Left side must be one of ||, |o, }|, }o; right side must be one of ||, o|, |{, o{ (e.g. "||--o{").`);if(!s||c.length===0)throw Error(`Line ${n}: ER relationship "${i} ${a} ${o}" is missing a ": label" — expected e.g. "${i} ${a} ${o} : label".`);return{entity1:i,entity2:o,cardinality1:u,cardinality2:d,label:(0,e.normalizeBrTags)(c.replace(/^["']|["']$/g,``)),identifying:l[2]===`--`}}function ye(e){return e===`||`?`one`:e===`|o`?`zero-one`:e===`}|`?`many`:e===`}o`?`zero-many`:null}function be(e){return e===`||`?`one`:e===`o|`?`zero-one`:e===`|{`?`many`:e===`o{`?`zero-many`:null}var xe=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`.split(` `)),Se=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Ce=/^(?:rgba?|hsla?)\(\s*[\d.%]+(?:[\s,/]+[\d.%]+){2,3}\s*\)$/i;function A(e){return xe.has(e.toLowerCase())||Se.test(e)||Ce.test(e)}function j(e){let t=e.trim(),n=t.match(/^((?:rgba?|hsla?)\s*\([^)]*\)|#[0-9a-fA-F]+|\S+)?(.*)$/),r=n?.[1]??``,i=n?.[2]?.trim()??``;return r.toLowerCase()===`transparent`?{label:i}:r!==``&&A(r)?{color:r,label:i}:{label:t}}function M(e){return e===`loop`||e===`alt`||e===`opt`||e===`par`||e===`critical`||e===`break`||e===`rect`}function we(e){if(!M(e))throw Error(`Invalid block type: "${e}"`);return e}var Te=/^(.+?)\s*(<<->>|<<-->>|--?>?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/,Ee=/^(.+?)\s*(<<->>|<<-->>|--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/;function De(t){let n={actors:[],messages:[],blocks:[],notes:[],activations:[],boxes:[]},r={open:void 0,membership:new Map},i=0,a,o=new Set,s=[],c={enabled:!1,next:1,step:1},l,u;for(let d=1;d<t.length;d++){let f=t[d],p=f.text,m=p.match(/^box(?:\s+(.*))?$/);if(m){if(r.open!==void 0)throw Error(`Line ${f.line}: Sequence diagram: a box cannot be nested inside another box — close the open box with "end" first`);let{color:t,label:o}=j(m[1]??``),c={label:(0,e.normalizeBrTags)(o),actorIds:[]};t!==void 0&&(c.color=t),n.boxes.push(c),r.open=n.boxes.length-1,i=s.length,a=f.line;continue}let h=p.match(/^create\s+(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(h){let t=h[1]===`actor`?`actor`:`participant`,i=h[2];if(o.has(i))throw Error(`Line ${f.line}: 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`);o.add(i),n.actors.push({id:i,label:(0,e.normalizeBrTags)(h[3]?.trim()??i),type:t}),P(n,r,i,f.line),l=i;continue}let g=p.match(/^destroy\s+(.+)$/);if(g){let e=g[1].trim();N(n,o,r,e,f.line),u=e;continue}let _=p.match(/^autonumber(?:\s+(off|\d+(?:\.\d{1,2})?)(?:\s+(\d+(?:\.\d{1,2})?))?)?$/);if(_){let e=_[1],t=_[2];e===`off`?c.enabled=!1:(c.enabled=!0,c.next=e===void 0?1:Number(e),c.step=t===void 0?1:Number(t));continue}let v=p.match(/^(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(v){let t=v[1]===`actor`?`actor`:`participant`,i=v[2],a=v[3]?.trim()??i,s=(0,e.normalizeBrTags)(a);o.has(i)||(o.add(i),n.actors.push({id:i,label:s,type:t})),P(n,r,i,f.line);continue}let y=p.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.+)$/i);if(y){let t=y[1].toLowerCase(),i=y[2].trim(),a=(0,e.normalizeBrTags)(y[3].trim()),s=i.split(`,`).map(e=>e.trim());for(let e of s)N(n,o,r,e,f.line);let c=`over`;t===`left of`?c=`left`:t===`right of`&&(c=`right`),n.notes.push({actorIds:s,text:a,position:c,afterIndex:n.messages.length-1});continue}let b=p.match(/^(loop|alt|opt|par|critical|break|rect)\s*(.*)$/);if(b){let t=we(b[1]),r=b[2]?.trim()??``,i=(0,e.normalizeBrTags)(r);s.push({type:t,label:i,startIndex:n.messages.length,dividers:[],line:f.line});continue}let x=p.match(/^(else|and)\s*(.*)$/);if(x&&s.length>0){let t=x[2]?.trim()??``,r=(0,e.normalizeBrTags)(t);s[s.length-1].dividers.push({index:n.messages.length,label:r});continue}if(p===`end`&&r.open!==void 0&&s.length===i){r.open=void 0,a=void 0;continue}if(p===`end`&&s.length>0){let e=s.pop();n.blocks.push({type:e.type,label:e.label,startIndex:e.startIndex,endIndex:Math.max(n.messages.length-1,e.startIndex),dividers:e.dividers});continue}if(p===`end`)throw Error(`Line ${f.line}: Sequence diagram: "end" does not match any open block ("loop"/"alt"/"opt"/"par"/"critical"/"break"/"rect") or "box" — nothing is currently open to close.`);let S=p.match(/^(activate|deactivate)\s+(.+)$/);if(S){let e=S[2].trim();N(n,o,r,e,f.line),n.activations.push({actorId:e,kind:S[1]===`activate`?`start`:`end`,afterIndex:n.messages.length-1});continue}let C=p.match(Te)??p.match(Ee);if(C){let e=C[2],t=C[4][0];if(t===`>`||t===`)`)throw Error(`Line ${f.line}: Malformed sequence-diagram arrow in "${p}" — "${e}${t}" is not a recognized arrow. Expected one of: ->, -->, ->>, -->>, -x, --x, -), --), <<->>, <<-->>.`);ke(n,o,r,c,C[1],C[2],C[3],C[4],C[5],f.line);let i=n.messages.length-1,a=n.messages[i];if(l!==void 0){if(a.to!==l)throw Error(`Line ${f.line}: The created participant ${l} does not have an associated creating message after its declaration. Please check the sequence diagram.`);Oe(n,l).createdAt=i,l=void 0}if(u!==void 0){if(a.from!==u&&a.to!==u)throw Error(`Line ${f.line}: The destroyed participant ${u} does not have an associated destroying message after its declaration. Please check the sequence diagram.`);Oe(n,u).destroyedAt=i,u=void 0}continue}}if(s.length>0){let e=s[s.length-1];throw Error(`Line ${e.line}: Sequence diagram: unclosed "${e.type}" block — expected a matching "end" before the diagram ends.`)}if(r.open!==void 0){let e=n.boxes[r.open];throw Error(`Line ${a}: Sequence diagram: unclosed "box${e.label?` ${e.label}`:``}" — expected a matching "end" before the diagram ends.`)}return n}function Oe(e,t){let n=e.actors.find(e=>e.id===t);if(n===void 0)throw Error(`Sequence diagram: unknown actor "${t}"`);return n}function N(e,t,n,r,i){t.has(r)||(t.add(r),e.actors.push({id:r,label:r,type:`participant`})),P(e,n,r,i)}function P(e,t,n,r){let i=t.open;if(i===void 0)return;let a=t.membership.get(n);if(a!==i){if(a!==void 0){let t=e.boxes[a].label,o=e.boxes[i].label;throw Error(`Line ${r}: A same participant should only be defined in one Box: ${n} can't be in '${t}' and in '${o}' at the same time.`)}t.membership.set(n,i),e.boxes[i].actorIds.push(n)}}function ke(t,n,r,i,a,o,s,c,l,u){N(t,n,r,a,u),N(t,n,r,c,u);let d=o===`<<->>`||o===`<<-->>`,f=d?o===`<<-->>`?`dashed`:`solid`:o.startsWith(`--`)?`dashed`:`solid`,p=o.includes(`>>`)||o.includes(`x`)?`filled`:`open`,m=o.includes(`x`),h={from:a,to:c,label:(0,e.normalizeBrTags)(l.trim()),lineStyle:f,arrowHead:p};m&&(h.isLost=!0),d&&(h.bidirectional=!0),s===`+`&&(h.activate=!0),s===`-`&&(h.deactivate=!0),i.enabled&&(h.seqNumber=i.next,i.next=Math.round((i.next+i.step)*100)/100),t.messages.push(h)}function F(e,t){if(t<0)return`before the first message`;let n=e.messages[t];if(!n)return`at an unresolved position`;let r=n.label?`: ${n.label}`:``;return`after message ${t+1} ("${n.from} -> ${n.to}${r}")`}function I(e){let t=new Map;for(let n of e.activations){let e=t.get(n.afterIndex)??[];e.push(n),t.set(n.afterIndex,e)}let n=[];function r(e){for(let r of t.get(e)??[])n.push({actorId:r.actorId,kind:r.kind,afterIndex:e})}r(-1);for(let t=0;t<e.messages.length;t++){let i=e.messages[t];i.activate&&n.push({actorId:i.to,kind:`start`,afterIndex:t}),i.deactivate&&n.push({actorId:i.from,kind:`end`,afterIndex:t}),r(t)}let i=new Map,a=[];for(let t of n){let n=i.get(t.actorId)??[];if(i.set(t.actorId,n),t.kind===`start`){n.push(t.afterIndex);continue}n.pop()===void 0&&a.push({code:`UNMATCHED_DEACTIVATION`,actorId:t.actorId,message:`"deactivate ${t.actorId}" ${F(e,t.afterIndex)} has no matching "activate ${t.actorId}" open at that point.`})}for(let[t,n]of i)for(let r of n)a.push({code:`DANGLING_ACTIVATION`,actorId:t,message:`"activate ${t}" opened ${F(e,r)} is never closed with a matching "deactivate ${t}".`});return{ok:a.length===0,issues:a}}function Ae(t){let n=(0,e.detectDiagramType)(t);if(n!==`sequence`)throw Error(`fixActivationBalance only supports sequence diagrams (source must start with "sequenceDiagram"); detected diagram type: "${n}".`);let r=I(De((0,e.splitStatements)(t)));if(r.ok)return{ok:!0,originalDiagram:t,fixedDiagram:t,fixesApplied:[],remainingIssues:[]};let i=r.issues.filter(e=>e.code===`DANGLING_ACTIVATION`),a=r.issues.filter(e=>e.code!==`DANGLING_ACTIVATION`),o=i.map(e=>` deactivate ${e.actorId}`).join(`
3
- `),s=i.length===0?t:`${t.replace(/\s+$/,``)}\n${o}`,c=i.map(e=>`Appended "deactivate ${e.actorId}" to close: ${e.message}`);return{ok:a.length===0,originalDiagram:t,fixedDiagram:s,fixesApplied:c,remainingIssues:a}}function je(e){let t={},n={},r=[],i,a=!1;for(let o of e){let e=o.text;if(/^xychart(-beta)?\b/i.test(e)){/\bhorizontal\b/i.test(e)&&(a=!0);continue}let s=e.match(/^title\s+"([^"]+)"/);if(s){i=s[1];continue}let c=e.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/);if(c){c[1]&&(t.title=c[1]),t.categories=Me(c[2]).map(e=>Ne(e.trim()));continue}let l=e.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(l){l[1]&&(t.title=l[1]),t.range={min:parseFloat(l[2]),max:parseFloat(l[3])};continue}let u=e.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(u){u[1]&&(n.title=u[1]),n.range={min:parseFloat(u[2]),max:parseFloat(u[3])};continue}let d=e.match(/^y-axis\s+"([^"]+)"\s*$/);if(d){n.title=d[1];continue}let f=e.match(/^bar\s+\[([^\]]+)\]/);if(f){r.push({type:`bar`,data:L(f[1],`bar`,e,o.line)});continue}let p=e.match(/^line\s+\[([^\]]+)\]/);if(p){r.push({type:`line`,data:L(p[1],`line`,e,o.line)});continue}let m=e.match(/^(x-axis|y-axis|bar|line|title)\b/i);if(m)throw Fe(m[1].toLowerCase(),e,o.line)}if(!n.range&&r.length>0){let e=r.flatMap(e=>e.data),t=Math.min(...e),i=Math.max(...e),a=i-t||1;t-=a*.1,i+=a*.1,t>0&&t<a*.5&&(t=0),n.range={min:t,max:i}}return n.range||={min:0,max:100},{title:i,horizontal:a,xAxis:t,yAxis:n,series:r}}function Me(e){let t=[],n=``,r=!1;for(let i of e)i===`"`?(r=!r,n+=i):i===`,`&&!r?(t.push(n),n=``):n+=i;return t.push(n),t}function Ne(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}function L(e,t,n,r){return e.split(`,`).map((e,i)=>{let a=e.trim(),o=parseFloat(a);if(a.length===0||Number.isNaN(o))throw Error(`Line ${r}: Invalid numeric value ${JSON.stringify(a)} at position ${i+1} in "${n}". Every value in a ${t} [...] list must be a number.`);return o})}var Pe={"x-axis":`x-axis [A, B, C] (categories) or x-axis 0 --> 100 (numeric range), either optionally preceded by a quoted title`,"y-axis":`y-axis 0 --> 100 (numeric range) or y-axis "Title" (title only), optionally preceded by a quoted title before a range`,bar:`bar [10, 20, 30] — a comma-separated numeric array in square brackets`,line:`line [10, 20, 30] — a comma-separated numeric array in square brackets`,title:`title "Chart Title" — a double-quoted string`};function Fe(e,t,n){let r=Pe[e]??e;return Error(`Line ${n}: Malformed xychart-beta "${e}" directive: "${t}". Expected: ${r}.`)}var R=`#3b82f6`;function z(e){let t=e.replace(`#`,``),n=parseInt(t.substring(0,2),16)/255,r=parseInt(t.substring(2,4),16)/255,i=parseInt(t.substring(4,6),16)/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)return[0,0,s*100];let c=a-o,l=s>.5?c/(2-a-o):c/(a+o),u;return u=a===n?((r-i)/c+(r<i?6:0))/6:a===r?((i-n)/c+2)/6:((n-r)/c+4)/6,[u*360,l*100,s*100]}function Ie(e,t,n){let r=t/100,i=n/100,a=(1-Math.abs(2*i-1))*r,o=a*(1-Math.abs(e/60%2-1)),s=i-a/2,c,l,u;e<60?(c=a,l=o,u=0):e<120?(c=o,l=a,u=0):e<180?(c=0,l=a,u=o):e<240?(c=0,l=o,u=a):e<300?(c=o,l=0,u=a):(c=a,l=0,u=o);let d=e=>Math.round((e+s)*255).toString(16).padStart(2,`0`);return`#${d(c)}${d(l)}${d(u)}`}function B(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function V(e){return z(e)[2]<50}function Le(e,t,n){if(e===0)return t;let r=B(t)?t:R,i=n&&B(n)?n:void 0,[a,o]=z(r),s=Math.max(55,Math.min(85,o)),c=Math.ceil(e/2),l=e%2==1,u=i&&V(i)?!l:l,d=u?Math.max(25,48-c*13):Math.min(78,55+c*11);return Ie(((a+(u?-8:-12)*c)%360+360)%360,s,d)}var H={rect:`rectangle`,rectangle:`rectangle`,proc:`rectangle`,process:`rectangle`,"normal-rect":`rectangle`,rounded:`rounded`,event:`rounded`,"rounded-rect":`rounded`,stadium:`stadium`,pill:`stadium`,terminal:`stadium`,subproc:`subroutine`,subprocess:`subroutine`,subroutine:`subroutine`,"framed-rectangle":`subroutine`,"fr-rect":`subroutine`,cyl:`cylinder`,cylinder:`cylinder`,db:`cylinder`,database:`cylinder`,"h-cyl":`cylinder`,das:`cylinder`,"horizontal-cylinder":`cylinder`,"lin-cyl":`cylinder`,"lined-cylinder":`cylinder`,disk:`cylinder`,circ:`circle`,circle:`circle`,start:`circle`,"dbl-circ":`doublecircle`,"double-circle":`doublecircle`,stop:`doublecircle`,"f-circ":`filled-circle`,"filled-circle":`filled-circle`,junction:`filled-circle`,"cross-circ":`crossed-circle`,"crossed-circle":`crossed-circle`,summary:`crossed-circle`,diam:`diamond`,diamond:`diamond`,decision:`diamond`,question:`diamond`,hex:`hexagon`,hexagon:`hexagon`,prepare:`hexagon`,odd:`asymmetric`,"rect-left-inv-arrow":`asymmetric`,"lean-r":`parallelogram`,"lean-right":`parallelogram`,"in-out":`parallelogram`,"lean-l":`parallelogram-alt`,"lean-left":`parallelogram-alt`,"out-in":`parallelogram-alt`,"trap-b":`trapezoid`,"trapezoid-bottom":`trapezoid`,priority:`trapezoid`,"trap-t":`trapezoid-alt`,"trapezoid-top":`trapezoid-alt`,manual:`trapezoid-alt`,"curv-trap":`trapezoid-alt`,"curved-trapezoid":`trapezoid-alt`,display:`trapezoid-alt`,doc:`document`,document:`document`,"lin-doc":`document`,"lined-document":`document`,"tag-doc":`document`,"tagged-document":`document`,docs:`stacked-document`,documents:`stacked-document`,"st-doc":`stacked-document`,"stacked-document":`stacked-document`,"notch-rect":`card`,card:`card`,"notched-rectangle":`card`,"lin-rect":`lined-process`,"lined-rectangle":`lined-process`,"lin-proc":`lined-process`,"shaded-process":`lined-process`,"div-rect":`divided-process`,"divided-rectangle":`divided-process`,"div-proc":`divided-process`,"tag-rect":`rectangle`,"tagged-rectangle":`rectangle`,"tag-proc":`rectangle`,procs:`stacked-process`,processes:`stacked-process`,"st-rect":`stacked-process`,"stacked-rectangle":`stacked-process`,tri:`triangle`,triangle:`triangle`,extract:`triangle`,"flip-tri":`flipped-triangle`,"flipped-triangle":`flipped-triangle`,"manual-file":`flipped-triangle`,"win-pane":`window-pane`,"window-pane":`window-pane`,"internal-storage":`window-pane`,fork:`fork-join`,join:`fork-join`,"long-rect":`fork-join`,"notch-pent":`notched-pentagon`,"loop-limit":`notched-pentagon`,"notched-pentagon":`notched-pentagon`,"sl-rect":`sloped-rectangle`,"sloped-rectangle":`sloped-rectangle`,"manual-input":`sloped-rectangle`,flag:`flag`,"paper-tape":`flag`,"bow-rect":`bow-tie-rectangle`,"bow-tie-rectangle":`bow-tie-rectangle`,"stored-data":`bow-tie-rectangle`,delay:`half-rounded-rectangle`,"half-rounded-rectangle":`half-rounded-rectangle`,brace:`brace`,"brace-l":`brace`,comment:`brace`,"brace-r":`brace-right`,braces:`braces`,bolt:`bolt`,"com-link":`bolt`,"lightning-bolt":`bolt`,text:`text`,anchor:`anchor`};function U(e){return H[e.trim().toLowerCase()]}function Re(){return Object.keys(H).sort()}function W(e){let t={};for(let n of ze(e,`,`)){let e=n.trim();if(e.length===0)continue;let r=Be(e,`:`);if(r===-1){t.shape??=G(e);continue}let i=e.slice(0,r).trim().toLowerCase(),a=G(e.slice(r+1).trim());i.length>0&&(t[i]=a)}return t}function ze(e,t){let n=[],r=``,i=null;for(let a of e){if(i!==null){r+=a,a===i&&(i=null);continue}if(a===`"`||a===`'`){i=a,r+=a;continue}if(a===t){n.push(r),r=``;continue}r+=a}return n.push(r),n}function Be(e,t){let n=null;for(let r=0;r<e.length;r++){let i=e[r];if(n!==null){i===n&&(n=null);continue}if(i===`"`||i===`'`){n=i;continue}if(i===t)return r}return-1}function G(e){return e.length>=2&&(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))?e.slice(1,-1):e}function K(e){if(!e.startsWith(`@{`))return;let t=0,n=null;for(let r=1;r<e.length;r++){let i=e[r];if(n!==null){i===n&&(n=null);continue}if(i===`"`||i===`'`){n=i;continue}if(i===`{`){t++;continue}if(i===`}`&&(t--,t===0))return{body:e.slice(2,r),length:r+1}}}function q(e){let t=e.trim();return t.length>=2&&(t[0]===`"`&&t[t.length-1]===`"`||t[0]===`'`&&t[t.length-1]===`'`)?t.slice(1,-1):t}var Ve=`"graph <dir>"/"flowchart <dir>" (dir: TD, TB, LR, BT, RL), "stateDiagram-v2", "sequenceDiagram", "classDiagram", "erDiagram", "xychart-beta", "C4Context"/"C4Container"/"C4Component"/"C4Dynamic"/"C4Deployment", "architecture-beta"`;function He(e){let t=e.trim().toLowerCase();if(/^sequence/.test(t))return`sequenceDiagram`;if(/^class/.test(t))return`classDiagram`;if(/^er/.test(t))return`erDiagram`;if(/^xychart/.test(t))return`xychart-beta`;if(/^state/.test(t))return`stateDiagram-v2`}var Ue=/^(?:[\w-]+@)?<?(?:-{2,}|={2,}|-\.+-?|~{3,})/;function We(e){let t=[];for(let n of e)n.forEach((e,n)=>{if(n===0&&t.length>0&&Ue.test(e.text)){let n=t[t.length-1];t[t.length-1]={text:`${n.text} ${e.text}`,line:n.line}}else t.push(e)});return t}function Ge(t){let n=(0,e.extractInitConfig)(t.split(`
4
- `).map(e=>e.trim())),r=We((0,e.splitStatementsByLine)(t));if(r.length===0)throw Error(`Empty mermaid diagram`);let i=r[0],a=/^stateDiagram(-v2)?\s*$/i.test(i.text)?qe(r):Ke(r);return a.initConfig=n,a}function Ke(t){let n=t[0];if(n===void 0)throw Error(`parseFlowchart called with no lines`);let r=n.text,i=r.match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!i){let e=r.match(/^(?:graph|flowchart)\b\s*(.*)$/i);if(e){let t=e[1].trim();throw Error(t.length>0?`Line ${n.line}: Invalid direction "${t}" in header "${r}". Expected one of: TD, TB, LR, BT, RL.`:`Line ${n.line}: Missing direction in header "${r}". Expected e.g. "graph TD" or "flowchart LR" — one of: TD, TB, LR, BT, RL.`)}let t=He(r),i=t&&t.toLowerCase()!==r.trim().toLowerCase()?` Did you mean "${t}"?`:``;throw Error(`Line ${n.line}: Invalid mermaid header: "${r}".${i} Supported headers: ${Ve}.`)}let a={direction:(0,e.toDirection)(i[1]),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},o=[];for(let n=1;n<t.length;n++){let r=t[n].text;if((0,e.tryApplyClassDef)(r,a)||(0,e.tryApplyClassAssignment)(r,a)||(0,e.tryApplyStyleStatement)(r,a))continue;if(/^click\s+/i.test(r)){nt(r,a);continue}if(Q(r,a))continue;let i=r.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(i){let t=i[1].trim(),n=(0,e.parseStyleProps)(i[2]);if(t==="default")a.linkStyles.set(`default`,{...a.linkStyles.get(`default`),...n});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||a.linkStyles.set(t,{...a.linkStyles.get(t),...n})}continue}let s=r.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(s&&o.length>0){o[o.length-1].direction=(0,e.toDirection)(s[1]);continue}let c=r.match(/^subgraph\s+(.+)$/);if(c){let t=c[1].trim(),n=t.match(/^([^\s[]+)\s*\[(.+)\]$/),r,i;n?(r=n[1],i=(0,e.normalizeBrTags)(q(n[2]))):(i=(0,e.normalizeBrTags)(q(t)),r=i.replace(/\s+/g,`_`).replace(/[^\p{L}\p{N}_-]/gu,``));let a={id:r,label:i,nodeIds:[],children:[]};o.push(a);continue}if(r===`end`){let e=o.pop();e&&(o.length>0?o[o.length-1].children.push(e):a.subgraphs.push(e));continue}st(r,a,o)}return a}function qe(t){let n={direction:`TD`,nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},r=[],i=new Set,a=0,o=0;for(let s=1;s<t.length;s++){let c=t[s].text;if((0,e.tryApplyClassDef)(c,n)||(0,e.tryApplyClassAssignment)(c,n)||(0,e.tryApplyStyleStatement)(c,n))continue;let l=c.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(l){r.length>0?r[r.length-1].direction=(0,e.toDirection)(l[1]):n.direction=(0,e.toDirection)(l[1]);continue}let u=c.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(u){let t=u[1].trim(),r=(0,e.parseStyleProps)(u[2]);if(t==="default")n.linkStyles.set(`default`,{...n.linkStyles.get(`default`),...r});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||n.linkStyles.set(t,{...n.linkStyles.get(t),...r})}continue}if(Q(c,n))continue;let d=c.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(d){let e=d[1]??d[2],t=d[2],a={id:t,label:e,nodeIds:[],children:[]};r.push(a),i.add(t),n.nodes.delete(t);continue}if(c===`}`){let e=r.pop();e&&(r.length>0?r[r.length-1].children.push(e):n.subgraphs.push(e));continue}let f=c.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(f){let t=(0,e.normalizeBrTags)(f[1]),i=f[2];J(n,r,i,t);continue}let p=c.match(/^(\[\*\]|[\w\p{L}-]+)(?::::([\w][\w-]*))?\s*(?:([\w-]+)@)?-->\s*(\[\*\]|[\w\p{L}-]+)(?::::([\w][\w-]*))?(?:\s*:\s*(.+))?$/u);if(p){let t=p[1],s=p[2],c=p[3],l=p[4],u=p[5],d=p[6]?.trim(),f=d?(0,e.normalizeBrTags)(d):void 0;t===`[*]`?(a++,t=`_start${a>1?a:``}`,Y(n,r,{id:t,label:``,shape:`state-start`})):i.has(t)||X(n,r,t),l===`[*]`?(o++,l=`_end${o>1?o:``}`,Y(n,r,{id:l,label:``,shape:`state-end`})):i.has(l)||X(n,r,l),s!==void 0&&n.classAssignments.set(t,s),u!==void 0&&n.classAssignments.set(l,u),n.edges.push({source:t,target:l,label:f,style:`solid`,hasArrowStart:!1,hasArrowEnd:!0,...c===void 0?{}:{id:c}});continue}let m=c.match(/^([\w\p{L}-]+):::([\w][\w-]*)\s*$/u);if(m){let e=m[1];i.has(e)||X(n,r,e),n.classAssignments.set(e,m[2]);continue}let h=c.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(h){let t=h[1];J(n,r,t,(0,e.normalizeBrTags)(h[2].trim()));continue}}for(let e of n.classAssignments.keys())!n.nodes.has(e)&&!i.has(e)&&X(n,[],e);return n}function J(e,t,n,r){let i=e.nodes.get(n);i&&(i.label=r),Y(e,t,{id:n,label:r,shape:`rounded`})}function Y(e,t,n){if(e.nodes.has(n.id)||e.nodes.set(n.id,n),t.length>0){let e=t[t.length-1];e.nodeIds.includes(n.id)||e.nodeIds.push(n.id)}}function X(e,t,n){if(!e.nodes.has(n))Y(e,t,{id:n,label:n,shape:`rounded`});else if(t.length>0){let e=t[t.length-1];e.nodeIds.includes(n)||e.nodeIds.push(n)}}var Je=/^(<|o|x)?(-{2,}|={2,}|-\.+-|~{3,})(>|o|x)?(?:\|([^|]*)\|)?/,Ye=new Set([`--`,`==`]);function Z(e){if(e===`o`)return`circle`;if(e===`x`)return`cross`}var Xe=/^(<|o|x)?(--|-\.|==)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.+-[>ox]|-{3,}|={3,}|-\.+-)/,Ze=[{regex:/^([\w\p{L}-]+)\(\(\(((?:"[^"]*"|(?!\)\)\)).)+)\)\)\)/u,shape:`doublecircle`},{regex:/^([\w\p{L}-]+)\(\[((?:"[^"]*"|(?!\]\)).)+)\]\)/u,shape:`stadium`},{regex:/^([\w\p{L}-]+)\(\(((?:"[^"]*"|(?!\)\)).)+)\)\)/u,shape:`circle`},{regex:/^([\w\p{L}-]+)\[\[((?:"[^"]*"|(?!\]\]).)+)\]\]/u,shape:`subroutine`},{regex:/^([\w\p{L}-]+)\[\(((?:"[^"]*"|(?!\)\]).)+)\)\]/u,shape:`cylinder`},{regex:/^([\w\p{L}-]+)\[\/((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`\\`?`trapezoid`:`parallelogram`},{regex:/^([\w\p{L}-]+)\[\\((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`/`?`trapezoid-alt`:`parallelogram-alt`},{regex:/^([\w\p{L}-]+)>((?:"[^"]*"|(?!\]).)+)\]/u,shape:`asymmetric`},{regex:/^([\w\p{L}-]+)\{\{((?:"[^"]*"|(?!\}\}).)+)\}\}/u,shape:`hexagon`},{regex:/^([\w\p{L}-]+)\[((?:"[^"]*"|(?!\]).)+)\]/u,shape:`rectangle`},{regex:/^([\w\p{L}-]+)\(((?:"[^"]*"|(?!\)).)+)\)/u,shape:`rounded`},{regex:/^([\w\p{L}-]+)\{((?:"[^"]*"|(?!\}).)+)\}/u,shape:`diamond`}],Qe=/^([\w\p{L}]+(?:-[\w\p{L}]+)*)/u,$e=/^([\w\p{L}-]+)(?=@\{)/u;function et(e){if(e.shape)return U(e.shape)??`rectangle`;if(e.icon!==void 0||e.img!==void 0)switch(e.form?.toLowerCase()){case`circle`:return`circle`;case`rounded`:return`rounded`;default:return`rectangle`}return`rectangle`}function tt(e,t){return t.label!==void 0&&t.label.length>0?t.label:t.icon?t.icon:t.img?t.img:e}function nt(t,n){(0,e.applyClickStatement)(t,n.interactions)}var rt=/^([\w-]+)(?=@\{)/;function Q(e,t){let n=e.match(rt);if(!n||!t.edges.some(e=>e.id===n[1]))return!1;let r=K(e.slice(n[1].length));return r?(it(t,n[1],W(r.body)),!0):!1}function it(e,t,n){for(let r of e.edges)r.id===t&&(n.animate!==void 0&&(r.animate=n.animate.toLowerCase()!==`false`),n.animation!==void 0&&(r.animate=!0))}var at=/^:::([\w][\w-]*)/,ot=/^([\w\p{L}-]+):::([\w][\w-]*)/u;function st(t,n,r){let i=t.trim(),a=ct(i,n,r);if(!a||a.ids.length===0)return;i=a.remaining.trim();let o=a.ids;for(;i.length>0;){let t,a,s,c,l,u,d,f=i.match(/^([\w-]+)@(?=[-=<~ox])/);f&&(d=f[1],i=i.slice(f[0].length));let p=i.match(Je),m=p?.[2],h=p?.[1],g=p?.[3];if(p&&m!==void 0&&!(h===void 0&&g===void 0&&Ye.has(m))){t=h!==void 0,l=Z(h);let n=p[4]?.trim();c=n?(0,e.normalizeBrTags)(n):void 0,i=i.slice(p[0].length).trim(),a=ft(m),s=g!==void 0,u=Z(g)}else{let n=i.match(Xe);if(!n)break;t=!!n[1],l=Z(n[1]);let r=n[3].trim();c=r?(0,e.normalizeBrTags)(r):void 0;let o=n[2],d=n[4];i=i.slice(n[0].length).trim(),a=pt(o,d),u=Z(d.slice(-1)),s=d.endsWith(`>`)||u!==void 0}let _=ct(i,n,r);if(!_||_.ids.length===0)break;i=_.remaining.trim();for(let e of o)for(let r of _.ids)n.edges.push({source:e,target:r,label:c,style:a,hasArrowStart:t,hasArrowEnd:s,...l===void 0?{}:{startMarker:l},...u===void 0?{}:{endMarker:u},...d===void 0?{}:{id:d}});o=_.ids}}function ct(e,t,n){let r=lt(e,t,n);if(!r)return null;let i=[r.id],a=r.remaining.trim();for(;a.startsWith(`&`);){a=a.slice(1).trim();let e=lt(a,t,n);if(!e)break;i.push(e.id),a=e.remaining.trim()}return{ids:i,remaining:a}}function lt(t,n,r){let i=null,a=t,o,s=a.match(ot);s&&(o=s[2],a=s[1]+a.slice(s[0].length));let c=a.match($e);if(c){let t=c[1],o=K(a.slice(t.length));if(o){let s=W(o.body);$(n,r,{id:t,label:(0,e.normalizeBrTags)(tt(t,s)),shape:et(s)}),i=t,a=a.slice(t.length+o.length)}}if(i===null)for(let{regex:t,shape:o}of Ze){let s=a.match(t);if(s){i=s[1];let t=(0,e.normalizeBrTags)(s[2]),c=typeof o==`function`?o(s[3]??``):o;$(n,r,{id:i,label:t,shape:c}),a=a.slice(s[0].length);break}}if(i===null){let e=a.match(Qe);e&&(i=e[1],n.nodes.has(i)?ut(n,r,i)||dt(r,i):$(n,r,{id:i,label:i,shape:`rectangle`}),a=a.slice(e[0].length))}if(i===null)return null;o&&n.classAssignments.set(i,o);let l=a.match(at);return l&&(n.classAssignments.set(i,l[1]),a=a.slice(l[0].length)),{id:i,remaining:a}}function $(e,t,n){e.nodes.has(n.id)||e.nodes.set(n.id,n),dt(t,n.id)}function ut(e,t,n){let r=e=>e.nodeIds.includes(n)||e.children.some(r);return e.subgraphs.some(r)||t.some(r)}function dt(e,t){if(e.length>0){let n=e[e.length-1];n.nodeIds.includes(t)||n.nodeIds.push(t)}}function ft(e){return e.startsWith(`~`)?`invisible`:e.includes(`.`)?`dotted`:e.startsWith(`=`)?`thick`:`solid`}function pt(e,t){return e.includes(`.`)||t.includes(`.`)?`dotted`:e.startsWith(`=`)||t.startsWith(`=`)?`thick`:`solid`}exports.CHART_ACCENT_FALLBACK=R,exports.architectureToGraph=p,exports.c4BoundaryTypeLine=ae,exports.c4Placement=se,exports.c4RelLabelLines=oe,exports.c4TypeLine=ie,exports.checkActivationBalance=I,exports.fixActivationBalance=Ae,exports.formatClassMember=ge,exports.getSeriesColor=Le,exports.isBlockType=M,exports.isCssColor=A,exports.isDarkBackground=V,exports.isValidHex=B,exports.knownShapeNames=Re,exports.matchExpandedBlock=K,exports.parseArchitecture=c,exports.parseBoxHeader=j,exports.parseC4Diagram=te,exports.parseClassDiagram=ue,exports.parseErDiagram=_e,exports.parseExpandedMeta=W,exports.parseGenericTypes=D,exports.parseMermaid=Ge,exports.parseSequenceDiagram=De,exports.parseXYChart=je,exports.resolveShapeName=U,exports.toBlockType=we,Object.defineProperty(exports,"toDirection",{enumerable:!0,get:function(){return e.toDirection}}),exports.wrapC4Text=ne;
2
+ `)){let e=``;for(let i of r.split(/\s+/).filter(Boolean))e&&e.length+1+i.length>t?(n.push(e),e=i):e=e?`${e} ${i}`:i;n.push(e)}return n}var re={person:`Person`,system:`Software System`,container:`Container`,component:`Component`};function ie(e){let t=(e.kind===`container`||e.kind===`component`)&&e.technology?`: ${e.technology}`:``;return`[${re[e.kind]}${t}]`}function ae(e){return e.type?`[${e.type}]`:void 0}function oe(e){let t=[],n=[e.index?`${e.index}:`:``,e.label].filter(Boolean).join(` `);return n&&t.push(n),e.technology&&t.push(`[${e.technology}]`),t}function se(e){switch(e.layout){case`up`:return{source:e.to,target:e.from,axis:`vertical`,explicit:!0};case`left`:return{source:e.to,target:e.from,axis:`horizontal`,explicit:!0};case`right`:return{source:e.from,target:e.to,axis:`horizontal`,explicit:!0};case`down`:return{source:e.from,target:e.to,axis:`vertical`,explicit:!0};default:return{source:e.from,target:e.to,axis:`vertical`,explicit:!1}}}var ce=`<\\|--|<\\|\\.\\.|\\*--|o--|-->|--\\*|--o|--\\|>|\\.\\.>|\\.\\.\\|>|<--|<\\.\\.?|--`,le=new RegExp(ce);function ue(t){let n={classes:[],relationships:[],namespaces:[],interactions:new Map,classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,notes:[]},r=new Map,i=null,a=null,o=0,s;for(let l=1;l<t.length;l++){let u=t[l],d=u.text;if(a&&o>0){if(d===`}`){o--,o===0&&(a=null,s=void 0);continue}let e=d.match(/^<<(\w+)>>$/);if(e){a.annotation=e[1];continue}if(d.startsWith(`<<`))throw Error(`Line ${u.line}: Malformed class annotation "${d}" — expected "<<name>>" (e.g. "<<interface>>").`);T(a,d,u.line);continue}if(/^click\s+/i.test(d)){(0,e.applyClickStatement)(d,n.interactions);continue}let f=d.match(/^note\s+(?:for\s+(\S+)\s+)?"([^"]*)"\s*$/);if(f){let t=f[1];n.notes.push({text:(0,e.normalizeBrTags)(f[2]),...t?{forClass:t}:{}});continue}if((0,e.tryApplyClassDef)(d,n)||(0,e.tryApplyStyleStatement)(d,n)||(0,e.tryApplyCssClass)(d,n)||(0,e.tryApplyClassAssignment)(d,n))continue;let p=d.match(/^namespace\s+(\S+)\s*\{$/);if(p){i={name:p[1],classIds:[]};continue}if(d===`}`&&i){n.namespaces.push(i),i=null;continue}let m=d.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(m){let e=c(m[1],m[2]);a=r.get(e)??null,o=1,s=u.line;continue}let h=d.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(h){c(h[1],h[2]);continue}let g=d.match(/^class\s+(\S+?)\s*\{\s*(.*?)\s*\}$/);if(g){let e=c(g[1],void 0),t=r.get(e),n=g[2],i=n.match(/^<<(\w+)>>$/);if(t&&i)t.annotation=i[1];else if(t&&n.startsWith(`<<`))throw Error(`Line ${u.line}: Malformed class annotation "${n}" — expected "<<name>>" (e.g. "<<interface>>").`);else t&&n&&T(t,n,u.line);continue}let _=d.match(/^(\S+?)\s*:\s*(.+)$/);if(_){let e=_[2];if(!e.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){T(de(r,_[1]),e,u.line);continue}}let v=me(d);if(v){v.from=c(v.from,void 0,!1),v.to=c(v.to,void 0,!1),n.relationships.push(v);continue}if(le.test(d))throw Error(`Line ${u.line}: Malformed class-diagram relationship "${d}". Expected "FROM ARROW TO" (optionally with cardinalities and a ": label"), e.g. "Animal <|-- Dog" or 'A "1" --> "*" B : label'. ARROW must be one of <|--, <|.., *--, o--, -->, --*, --o, --|>, ..>, ..|>, <--, <.., or --.`)}if(a!==null)throw Error(`Line ${s}: Unclosed class body for "${a.id}" — expected a closing "}" before the diagram ends.`);return n.classes=[...r.values()],n;function c(t,a,o=!0){let{id:s,className:c}=(0,e.splitClassShorthand)(t),l=s,u=a;if(!u){let e=s.match(/^(.+?)~(\w+)~$/);e&&(l=e[1],u=e[2])}let d=de(r,l);return u&&(d.label=`${l}<${u}>`),c&&n.classAssignments.set(l,c),o&&i&&i.classIds.push(l),l}}function T(e,t,n){let r=pe(t,n);r&&(r.isMethod?e.methods.push(r.member):e.attributes.push(r.member))}function de(e,t){let n=e.get(t);return n||(n={id:t,label:t,attributes:[],methods:[]},e.set(t,n)),n}function E(e,t){return Math.max(0,e.split(t).length-1)}function fe(e){let t=E(e,`~`);if(t<=1)return e;let n=e,r=!1;t%2!=0&&n.startsWith(`~`)&&(n=n.slice(1),r=!0);let i=[...n],a=i.indexOf(`~`),o=i.lastIndexOf(`~`);for(;a!==-1&&o!==-1&&a!==o;)i[a]=`<`,i[o]=`>`,a=i.indexOf(`~`),o=i.lastIndexOf(`~`);return r&&i.unshift(`~`),i.join(``)}function D(e){let t=e.split(/(,)/),n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r===`,`&&e>0&&e+1<t.length){let i=t[e-1],a=t[e+1];E(i,`~`)===1&&E(a,`~`)===1&&(r=`${i},${a}`,e++,n.pop())}n.push(fe(r))}return n.join(``)}function pe(e,t){let n=e.trim().replace(/;$/,``);if(!n)return null;let r=``,i=n,a=i[0];if((a===`+`||a===`-`||a===`#`||a===`~`)&&(r=a,i=i.slice(1).trim()),i.includes(`(`)&&!i.includes(`)`))throw Error(`Line ${t}: Malformed class member "${n}" — unclosed "(" in a method signature. Expected e.g. "+eat() void" or "+eat(Food f) void".`);let o=i.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(o){let e=D(o[1].trim()),t=o[2]?.trim(),n=t?D(t):void 0,a=o[3]?.trim(),s=a?D(a):void 0,c=e.endsWith(`$`)||i.includes(`$`),l=e.endsWith(`*`)||i.includes(`*`);return{member:{visibility:r,name:e.replace(/[$*]$/,``),type:s||void 0,isStatic:c,isAbstract:l,isMethod:!0,params:n},isMethod:!0}}let s=D(i),c=s.endsWith(`$`),l=s.endsWith(`*`);return{member:{visibility:r,name:s.replace(/[$*]$/,``),type:void 0,isStatic:c,isAbstract:l,isMethod:!1},isMethod:!1}}function me(t){let n=t.match(RegExp(`^(\\S+?)\\s+(?:"([^"]*?)"\\s+)?(${ce})\\s+(?:"([^"]*?)"\\s+)?(\\S+?)(?::::([\\w][\\w-]*))?(?:\\s*:\\s*(.+))?$`));if(!n)return null;let r=n[1],i=n[2],a=i?(0,e.normalizeBrTags)(i):void 0,o=n[3].trim(),s=n[4],c=s?(0,e.normalizeBrTags)(s):void 0,l=n[6]?`${n[5]}:::${n[6]}`:n[5],u=n[7]?.trim(),d=u?(0,e.normalizeBrTags)(u):void 0,f=he(o);return f?{from:r,to:l,type:f.type,markerAt:f.markerAt,label:d,fromCardinality:a,toCardinality:c}:null}function he(e){switch(e.trim()){case`<|--`:return{type:`inheritance`,markerAt:`from`};case`--|>`:return{type:`inheritance`,markerAt:`to`};case`<|..`:return{type:`realization`,markerAt:`from`};case`..|>`:return{type:`realization`,markerAt:`to`};case`*--`:return{type:`composition`,markerAt:`from`};case`--*`:return{type:`composition`,markerAt:`to`};case`o--`:return{type:`aggregation`,markerAt:`from`};case`--o`:return{type:`aggregation`,markerAt:`to`};case`-->`:return{type:`association`,markerAt:`to`};case`<--`:return{type:`association`,markerAt:`from`};case`..>`:return{type:`dependency`,markerAt:`to`};case`<..`:return{type:`dependency`,markerAt:`from`};case`--`:return{type:`association`,markerAt:`to`};default:return null}}function ge(e){return`${e.visibility?`${e.visibility} `:``}${e.isMethod?`${e.name}(${e.params||``})`:e.name}${e.type?`: ${e.type}`:``}`}function _e(t){let n={entities:[],relationships:[]},r=new Map,i=null;for(let a=1;a<t.length;a++){let o=t[a],s=o.text;if(i){if(s===`}`){i=null;continue}let e=k(s);e&&i.attributes.push(e);continue}let c=s.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(c){n.direction=(0,e.toDirection)(c[1]);continue}let l=s.match(/^(\S+?)(?:\[(.+)\])?\s*\{(.*)$/);if(l){let t=l[1],n=l[2],a=O(r,t,n===void 0?void 0:(0,e.normalizeBrTags)(n.trim().replace(/^["']|["']$/g,``))),o=l[3].trim(),s=o.endsWith(`}`),c=s?o.slice(0,-1).trim():o;for(let e of c.split(`;`).map(e=>e.trim()).filter(Boolean)){let t=k(e);t&&a.attributes.push(t)}s||(i=a);continue}let u=ve(s,o.line);if(u){O(r,u.entity1),O(r,u.entity2),n.relationships.push(u);continue}}return n.entities=[...r.values()],n}function O(e,t,n){let r=e.get(t);return r?n!==void 0&&(r.label=n):(r={id:t,label:n??t,attributes:[]},e.set(t,r)),r}function k(t){let n=t.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!n)return null;let r=n[1],i=n[2],a=n[3]?.trim()??``,o=[],s,c=a.match(/"([^"]*)"/);c&&(s=(0,e.normalizeBrTags)(c[1]));let l=a.replace(/"[^"]*"/,``).trim();for(let e of l.split(/\s+/)){let t=e.toUpperCase();(t===`PK`||t===`FK`||t===`UK`)&&o.push(t)}return{type:r,name:i,keys:o,comment:s}}function ve(t,n){let r=t.match(/^(\S+)\s+(\S*(?:--|\.\.)\S*)\s+(\S+)\s*(?::\s*(.*))?$/);if(!r)return null;let i=r[1],a=r[2],o=r[3],s=r[4]!==void 0,c=r[4]?.trim()??``,l=a.match(/^([|o}{]*)(--|\.\.?)([|o}{]*)$/),u=l?ye(l[1]):null,d=l?be(l[3]):null;if(!u||!d)throw Error(`Line ${n}: Invalid ER relationship cardinality "${a}" in "${t}". Left side must be one of ||, |o, }|, }o; right side must be one of ||, o|, |{, o{ (e.g. "||--o{").`);if(!s||c.length===0)throw Error(`Line ${n}: ER relationship "${i} ${a} ${o}" is missing a ": label" — expected e.g. "${i} ${a} ${o} : label".`);return{entity1:i,entity2:o,cardinality1:u,cardinality2:d,label:(0,e.normalizeBrTags)(c.replace(/^["']|["']$/g,``)),identifying:l[2]===`--`}}function ye(e){return e===`||`?`one`:e===`|o`?`zero-one`:e===`}|`?`many`:e===`}o`?`zero-many`:null}function be(e){return e===`||`?`one`:e===`o|`?`zero-one`:e===`|{`?`many`:e===`o{`?`zero-many`:null}var xe=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`.split(` `)),Se=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Ce=/^(?:rgba?|hsla?)\(\s*[\d.%]+(?:[\s,/]+[\d.%]+){2,3}\s*\)$/i;function A(e){return xe.has(e.toLowerCase())||Se.test(e)||Ce.test(e)}function j(e){let t=e.trim(),n=t.match(/^((?:rgba?|hsla?)\s*\([^)]*\)|#[0-9a-fA-F]+|\S+)?(.*)$/),r=n?.[1]??``,i=n?.[2]?.trim()??``;return r.toLowerCase()===`transparent`?{label:i}:r!==``&&A(r)?{color:r,label:i}:{label:t}}function M(e){return e===`loop`||e===`alt`||e===`opt`||e===`par`||e===`critical`||e===`break`||e===`rect`}function we(e){if(!M(e))throw Error(`Invalid block type: "${e}"`);return e}var Te=/^(.+?)\s*(<<->>|<<-->>|--?>?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/,Ee=/^(.+?)\s*(<<->>|<<-->>|--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/;function De(t){let n={actors:[],messages:[],blocks:[],notes:[],activations:[],boxes:[]},r={open:void 0,membership:new Map},i=0,a,o=new Set,s=[],c={enabled:!1,next:1,step:1},l,u;for(let d=1;d<t.length;d++){let f=t[d],p=f.text,m=p.match(/^box(?:\s+(.*))?$/);if(m){if(r.open!==void 0)throw Error(`Line ${f.line}: Sequence diagram: a box cannot be nested inside another box — close the open box with "end" first`);let{color:t,label:o}=j(m[1]??``),c={label:(0,e.normalizeBrTags)(o),actorIds:[]};t!==void 0&&(c.color=t),n.boxes.push(c),r.open=n.boxes.length-1,i=s.length,a=f.line;continue}let h=p.match(/^create\s+(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(h){let t=h[1]===`actor`?`actor`:`participant`,i=h[2];if(o.has(i))throw Error(`Line ${f.line}: 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`);o.add(i),n.actors.push({id:i,label:(0,e.normalizeBrTags)(h[3]?.trim()??i),type:t}),P(n,r,i,f.line),l=i;continue}let g=p.match(/^destroy\s+(.+)$/);if(g){let e=g[1].trim();N(n,o,r,e,f.line),u=e;continue}let _=p.match(/^autonumber(?:\s+(off|\d+(?:\.\d{1,2})?)(?:\s+(\d+(?:\.\d{1,2})?))?)?$/);if(_){let e=_[1],t=_[2];e===`off`?c.enabled=!1:(c.enabled=!0,c.next=e===void 0?1:Number(e),c.step=t===void 0?1:Number(t));continue}let v=p.match(/^(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(v){let t=v[1]===`actor`?`actor`:`participant`,i=v[2],a=v[3]?.trim()??i,s=(0,e.normalizeBrTags)(a);o.has(i)||(o.add(i),n.actors.push({id:i,label:s,type:t})),P(n,r,i,f.line);continue}let y=p.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.+)$/i);if(y){let t=y[1].toLowerCase(),i=y[2].trim(),a=(0,e.normalizeBrTags)(y[3].trim()),s=i.split(`,`).map(e=>e.trim());for(let e of s)N(n,o,r,e,f.line);let c=`over`;t===`left of`?c=`left`:t===`right of`&&(c=`right`),n.notes.push({actorIds:s,text:a,position:c,afterIndex:n.messages.length-1});continue}let b=p.match(/^(loop|alt|opt|par|critical|break|rect)\s*(.*)$/);if(b){let t=we(b[1]),r=b[2]?.trim()??``,i=(0,e.normalizeBrTags)(r);s.push({type:t,label:i,startIndex:n.messages.length,dividers:[],line:f.line});continue}let x=p.match(/^(else|and)\s*(.*)$/);if(x&&s.length>0){let t=x[2]?.trim()??``,r=(0,e.normalizeBrTags)(t);s[s.length-1].dividers.push({index:n.messages.length,label:r});continue}if(p===`end`&&r.open!==void 0&&s.length===i){r.open=void 0,a=void 0;continue}if(p===`end`&&s.length>0){let e=s.pop();n.blocks.push({type:e.type,label:e.label,startIndex:e.startIndex,endIndex:Math.max(n.messages.length-1,e.startIndex),dividers:e.dividers});continue}if(p===`end`)throw Error(`Line ${f.line}: Sequence diagram: "end" does not match any open block ("loop"/"alt"/"opt"/"par"/"critical"/"break"/"rect") or "box" — nothing is currently open to close.`);let S=p.match(/^(activate|deactivate)\s+(.+)$/);if(S){let e=S[2].trim();N(n,o,r,e,f.line),n.activations.push({actorId:e,kind:S[1]===`activate`?`start`:`end`,afterIndex:n.messages.length-1});continue}let C=p.match(Te)??p.match(Ee);if(C){let e=C[2],t=C[4][0];if(t===`>`||t===`)`)throw Error(`Line ${f.line}: Malformed sequence-diagram arrow in "${p}" — "${e}${t}" is not a recognized arrow. Expected one of: ->, -->, ->>, -->>, -x, --x, -), --), <<->>, <<-->>.`);ke(n,o,r,c,C[1],C[2],C[3],C[4],C[5],f.line);let i=n.messages.length-1,a=n.messages[i];if(l!==void 0){if(a.to!==l)throw Error(`Line ${f.line}: The created participant ${l} does not have an associated creating message after its declaration. Please check the sequence diagram.`);Oe(n,l).createdAt=i,l=void 0}if(u!==void 0){if(a.from!==u&&a.to!==u)throw Error(`Line ${f.line}: The destroyed participant ${u} does not have an associated destroying message after its declaration. Please check the sequence diagram.`);Oe(n,u).destroyedAt=i,u=void 0}continue}}if(s.length>0){let e=s[s.length-1];throw Error(`Line ${e.line}: Sequence diagram: unclosed "${e.type}" block — expected a matching "end" before the diagram ends.`)}if(r.open!==void 0){let e=n.boxes[r.open];throw Error(`Line ${a}: Sequence diagram: unclosed "box${e.label?` ${e.label}`:``}" — expected a matching "end" before the diagram ends.`)}return n}function Oe(e,t){let n=e.actors.find(e=>e.id===t);if(n===void 0)throw Error(`Sequence diagram: unknown actor "${t}"`);return n}function N(e,t,n,r,i){t.has(r)||(t.add(r),e.actors.push({id:r,label:r,type:`participant`})),P(e,n,r,i)}function P(e,t,n,r){let i=t.open;if(i===void 0)return;let a=t.membership.get(n);if(a!==i){if(a!==void 0){let t=e.boxes[a].label,o=e.boxes[i].label;throw Error(`Line ${r}: A same participant should only be defined in one Box: ${n} can't be in '${t}' and in '${o}' at the same time.`)}t.membership.set(n,i),e.boxes[i].actorIds.push(n)}}function ke(t,n,r,i,a,o,s,c,l,u){N(t,n,r,a,u),N(t,n,r,c,u);let d=o===`<<->>`||o===`<<-->>`,f=d?o===`<<-->>`?`dashed`:`solid`:o.startsWith(`--`)?`dashed`:`solid`,p=o.includes(`>>`)||o.includes(`x`)?`filled`:`open`,m=o.includes(`x`),h={from:a,to:c,label:(0,e.normalizeBrTags)(l.trim()),lineStyle:f,arrowHead:p};m&&(h.isLost=!0),d&&(h.bidirectional=!0),s===`+`&&(h.activate=!0),s===`-`&&(h.deactivate=!0),i.enabled&&(h.seqNumber=i.next,i.next=Math.round((i.next+i.step)*100)/100),t.messages.push(h)}function Ae(e,t){if(t<0)return`before the first message`;let n=e.messages[t];if(!n)return`at an unresolved position`;let r=n.label?`: ${n.label}`:``;return`after message ${t+1} ("${n.from} -> ${n.to}${r}")`}function F(e){let t=new Map;for(let n of e.activations){let e=t.get(n.afterIndex)??[];e.push(n),t.set(n.afterIndex,e)}let n=[];function r(e){for(let r of t.get(e)??[])n.push({actorId:r.actorId,kind:r.kind,afterIndex:e})}r(-1);for(let t=0;t<e.messages.length;t++){let i=e.messages[t];i.activate&&n.push({actorId:i.to,kind:`start`,afterIndex:t}),i.deactivate&&n.push({actorId:i.from,kind:`end`,afterIndex:t}),r(t)}let i=new Map,a=[];for(let t of n){let n=i.get(t.actorId)??[];if(i.set(t.actorId,n),t.kind===`start`){n.push(t.afterIndex);continue}n.pop()===void 0&&a.push({code:`UNMATCHED_DEACTIVATION`,actorId:t.actorId,message:`"deactivate ${t.actorId}" ${Ae(e,t.afterIndex)} has no matching "activate ${t.actorId}" open at that point.`})}for(let[t,n]of i)for(let r of n)a.push({code:`DANGLING_ACTIVATION`,actorId:t,message:`"activate ${t}" opened ${Ae(e,r)} is never closed with a matching "deactivate ${t}".`});return{ok:a.length===0,issues:a}}function je(t){let n=(0,e.detectDiagramType)(t);if(n!==`sequence`)throw Error(`fixActivationBalance only supports sequence diagrams (source must start with "sequenceDiagram"); detected diagram type: "${n}".`);let r=F(De((0,e.splitStatements)(t)));if(r.ok)return{ok:!0,originalDiagram:t,fixedDiagram:t,fixesApplied:[],remainingIssues:[]};let i=r.issues.filter(e=>e.code===`DANGLING_ACTIVATION`),a=r.issues.filter(e=>e.code!==`DANGLING_ACTIVATION`),o=i.map(e=>` deactivate ${e.actorId}`).join(`
3
+ `),s=i.length===0?t:`${t.replace(/\s+$/,``)}\n${o}`,c=i.map(e=>`Appended "deactivate ${e.actorId}" to close: ${e.message}`);return{ok:a.length===0,originalDiagram:t,fixedDiagram:s,fixesApplied:c,remainingIssues:a}}function Me(e){let t={},n={},r=[],i,a=!1;for(let o of e){let e=o.text;if(/^xychart(-beta)?\b/i.test(e)){/\bhorizontal\b/i.test(e)&&(a=!0);continue}let s=e.match(/^title\s+"([^"]+)"/);if(s){i=s[1];continue}let c=e.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/);if(c){c[1]&&(t.title=c[1]),t.categories=Ne(c[2]).map(e=>Pe(e.trim()));continue}let l=e.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(l){l[1]&&(t.title=l[1]),t.range={min:parseFloat(l[2]),max:parseFloat(l[3])};continue}let u=e.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(u){u[1]&&(n.title=u[1]),n.range={min:parseFloat(u[2]),max:parseFloat(u[3])};continue}let d=e.match(/^y-axis\s+"([^"]+)"\s*$/);if(d){n.title=d[1];continue}let f=e.match(/^bar\s+\[([^\]]+)\]/);if(f){r.push({type:`bar`,data:I(f[1],`bar`,e,o.line)});continue}let p=e.match(/^line\s+\[([^\]]+)\]/);if(p){r.push({type:`line`,data:I(p[1],`line`,e,o.line)});continue}let m=e.match(/^(x-axis|y-axis|bar|line|title)\b/i);if(m)throw Ie(m[1].toLowerCase(),e,o.line)}if(!n.range&&r.length>0){let e=r.flatMap(e=>e.data),t=Math.min(...e),i=Math.max(...e),a=i-t||1;t-=a*.1,i+=a*.1,t>0&&t<a*.5&&(t=0),n.range={min:t,max:i}}return n.range||={min:0,max:100},{title:i,horizontal:a,xAxis:t,yAxis:n,series:r}}function Ne(e){let t=[],n=``,r=!1;for(let i of e)i===`"`?(r=!r,n+=i):i===`,`&&!r?(t.push(n),n=``):n+=i;return t.push(n),t}function Pe(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}function I(e,t,n,r){return e.split(`,`).map((e,i)=>{let a=e.trim(),o=parseFloat(a);if(a.length===0||Number.isNaN(o))throw Error(`Line ${r}: Invalid numeric value ${JSON.stringify(a)} at position ${i+1} in "${n}". Every value in a ${t} [...] list must be a number.`);return o})}var Fe={"x-axis":`x-axis [A, B, C] (categories) or x-axis 0 --> 100 (numeric range), either optionally preceded by a quoted title`,"y-axis":`y-axis 0 --> 100 (numeric range) or y-axis "Title" (title only), optionally preceded by a quoted title before a range`,bar:`bar [10, 20, 30] — a comma-separated numeric array in square brackets`,line:`line [10, 20, 30] — a comma-separated numeric array in square brackets`,title:`title "Chart Title" — a double-quoted string`};function Ie(e,t,n){let r=Fe[e]??e;return Error(`Line ${n}: Malformed xychart-beta "${e}" directive: "${t}". Expected: ${r}.`)}var L=`#3b82f6`;function R(e){let t=e.replace(`#`,``),n=parseInt(t.substring(0,2),16)/255,r=parseInt(t.substring(2,4),16)/255,i=parseInt(t.substring(4,6),16)/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)return[0,0,s*100];let c=a-o,l=s>.5?c/(2-a-o):c/(a+o),u;return u=a===n?((r-i)/c+(r<i?6:0))/6:a===r?((i-n)/c+2)/6:((n-r)/c+4)/6,[u*360,l*100,s*100]}function Le(e,t,n){let r=t/100,i=n/100,a=(1-Math.abs(2*i-1))*r,o=a*(1-Math.abs(e/60%2-1)),s=i-a/2,c,l,u;e<60?(c=a,l=o,u=0):e<120?(c=o,l=a,u=0):e<180?(c=0,l=a,u=o):e<240?(c=0,l=o,u=a):e<300?(c=o,l=0,u=a):(c=a,l=0,u=o);let d=e=>Math.round((e+s)*255).toString(16).padStart(2,`0`);return`#${d(c)}${d(l)}${d(u)}`}function z(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function B(e){return R(e)[2]<50}function Re(e,t,n){if(e===0)return t;let r=z(t)?t:L,i=n&&z(n)?n:void 0,[a,o]=R(r),s=Math.max(55,Math.min(85,o)),c=Math.ceil(e/2),l=e%2==1,u=i&&B(i)?!l:l,d=u?Math.max(25,48-c*13):Math.min(78,55+c*11);return Le(((a+(u?-8:-12)*c)%360+360)%360,s,d)}var ze=[[null,/[\t ]+/y],[`SHOW_DATA`,/showData(?:(?=%%)|(?!\S))/y],[`PIE`,/pie(?:(?=%%)|(?!\S))/y],[`COLON`,/:/y],[`NUMBER`,/-?[0-9]+\.[0-9]+(?!\.)|-?(?:0|[1-9][0-9]*)(?!\.)/y],[`ACC_DESCR`,/[\t ]*accDescr(?:[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)|\s*\{[^}]*\})/y],[`ACC_TITLE`,/[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/y],[`TITLE`,/[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/y],[`STRING`,/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/y],[`NEWLINE`,/\n/y],[null,/[\t ]*%%[^\n\r]*/y]],Be=/%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,Ve=/accDescr(?:[\t ]*:([^\n\r]*)|\s*\{([^}]*)\})/,He=/accTitle[\t ]*:([^\n\r]*)/,Ue=/title([\t ][^\n\r]*|)/,We='A pie chart is `pie [showData] [title <text>]` followed by lines of `"Label" : value` (label quoted with " or \'), `title <text>`, `accTitle: <text>`, or `accDescr: <text>`.';function Ge(e){return e.replace(/\r\n?/g,`
4
+ `).replace(/<(\w+)([^>]*)>/g,(e,t,n)=>`<`+t+n.replace(/="([^"]*)"/g,`='$1'`)+`>`).replace(Be,e=>e.replace(/[^\n]/g,``))}function Ke(e){let t=0;for(let n of e)n===`
5
+ `&&t++;return t}function V(e,t,n){let r=(e[t-1]??``).trim();return Error(`Line ${t}: ${n} in "${r}". ${We}`)}function qe(e,t,n){let r=e[t];return r===`"`||r===`'`?`Unterminated quoted label (missing closing ${r})`:n?.kind===`COLON`?`Invalid slice value — expected a number like 42 or 42.5 after ":"`:n===void 0||n.kind===`NEWLINE`||n.kind===`PIE`||n.kind===`SHOW_DATA`?`Unrecognized statement — slice labels must be quoted, e.g. "Dogs" : 42`:`Unexpected text ${JSON.stringify(e.slice(t).split(`
6
+ `)[0])}`}function Je(e,t){let n=[],r=0,i=1;for(;r<e.length;){let a=!1;for(let[t,o]of ze){o.lastIndex=r;let s=o.exec(e);if(s===null||s[0].length===0)continue;let c=s[0];t!==null&&n.push({kind:t,text:c,line:i}),i+=Ke(c),r+=c.length,a=!0;break}if(!a)throw V(t,i,qe(e,r,n.at(-1)))}return n}function Ye(e){let t=``;for(let n=1;n<e.length-1;n++){let r=e.charAt(n);if(r!==`\\`){t+=r;continue}let i=e.charAt(++n);switch(i){case`b`:t+=`\b`;break;case`f`:t+=`\f`;break;case`n`:t+=`
7
+ `;break;case`r`:t+=`\r`;break;case`t`:t+=` `;break;case`v`:t+=`\v`;break;case`0`:t+=`\0`;break;default:t+=i}}return t}function Xe(e,t){let n=(e===`ACC_DESCR`?Ve:e===`ACC_TITLE`?He:Ue).exec(t);return n?.[1]===void 0?(n?.[2]??``).replace(/^\s*/gm,``).replace(/\s+$/gm,``).replace(/[\t ]{2,}/gm,` `).replace(/[\n\r]{2,}/gm,`
8
+ `):n[1].trim().replace(/[\t ]{2,}/gm,` `)}var H={NEWLINE:`end of line`,PIE:`"pie"`,SHOW_DATA:`"showData"`,COLON:`":"`,NUMBER:`number`,STRING:`quoted label`,TITLE:`title`,ACC_TITLE:`accTitle`,ACC_DESCR:`accDescr`};function Ze(e){let t=Ge(e),n=t.split(`
9
+ `),r=Je(t,n),i=0,a=(e,t)=>{if(e===void 0)return V(n,n.length,`Unexpected end of input — expected ${t}`);let r=`Unexpected ${H[e.kind]} — expected ${t}`;return e.kind===`SHOW_DATA`?r+=`; showData is only allowed directly after "pie" on the header line`:e.kind===`PIE`&&(r+=`; the "pie" header may only appear once`),V(n,e.line,r)},o=e=>{let t=r[i];if(t!==void 0&&t.kind!==`NEWLINE`)throw a(t,`end of line after ${e}`)};for(;r[i]?.kind===`NEWLINE`;)i++;if(r[i]?.kind!==`PIE`)throw a(r[i],`the "pie" header`);i++;let s=!1;r[i]?.kind===`SHOW_DATA`&&(s=!0,i++);let c=``,l=``,u=``,d=[];for(;i<r.length;){let e=r[i];switch(e.kind){case`NEWLINE`:i++;break;case`TITLE`:case`ACC_TITLE`:case`ACC_DESCR`:{let t=Xe(e.kind,e.text);e.kind===`TITLE`?c=t:e.kind===`ACC_TITLE`?l=t:u=t,i++,o(H[e.kind]);break}case`STRING`:{if(i++,r[i]?.kind!==`COLON`)throw a(r[i],`":" after the slice label`);i++;let t=r[i];if(t?.kind!==`NUMBER`)throw a(t,`a number after ":"`);i++,o(`the slice value`),d.push({label:Ye(e.text),value:Number(t.text),line:e.line});break}default:throw a(e,`a quoted slice label, title, accTitle, or accDescr`)}}let f=[],p=new Set;for(let{label:e,value:t,line:n}of d){if(t<0)throw Error(`Line ${n}: "${e}" has invalid value: ${t}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);p.has(e)||(p.add(e),f.push({label:e,value:t===0?0:t}))}let m={showData:s,slices:f};return c&&(m.title=c),l&&(m.accTitle=l),u&&(m.accDescr=u),m}var U={rect:`rectangle`,rectangle:`rectangle`,proc:`rectangle`,process:`rectangle`,"normal-rect":`rectangle`,rounded:`rounded`,event:`rounded`,"rounded-rect":`rounded`,stadium:`stadium`,pill:`stadium`,terminal:`stadium`,subproc:`subroutine`,subprocess:`subroutine`,subroutine:`subroutine`,"framed-rectangle":`subroutine`,"fr-rect":`subroutine`,cyl:`cylinder`,cylinder:`cylinder`,db:`cylinder`,database:`cylinder`,"h-cyl":`cylinder`,das:`cylinder`,"horizontal-cylinder":`cylinder`,"lin-cyl":`cylinder`,"lined-cylinder":`cylinder`,disk:`cylinder`,circ:`circle`,circle:`circle`,start:`circle`,"dbl-circ":`doublecircle`,"double-circle":`doublecircle`,stop:`doublecircle`,"f-circ":`filled-circle`,"filled-circle":`filled-circle`,junction:`filled-circle`,"cross-circ":`crossed-circle`,"crossed-circle":`crossed-circle`,summary:`crossed-circle`,diam:`diamond`,diamond:`diamond`,decision:`diamond`,question:`diamond`,hex:`hexagon`,hexagon:`hexagon`,prepare:`hexagon`,odd:`asymmetric`,"rect-left-inv-arrow":`asymmetric`,"lean-r":`parallelogram`,"lean-right":`parallelogram`,"in-out":`parallelogram`,"lean-l":`parallelogram-alt`,"lean-left":`parallelogram-alt`,"out-in":`parallelogram-alt`,"trap-b":`trapezoid`,"trapezoid-bottom":`trapezoid`,priority:`trapezoid`,"trap-t":`trapezoid-alt`,"trapezoid-top":`trapezoid-alt`,manual:`trapezoid-alt`,"curv-trap":`trapezoid-alt`,"curved-trapezoid":`trapezoid-alt`,display:`trapezoid-alt`,doc:`document`,document:`document`,"lin-doc":`document`,"lined-document":`document`,"tag-doc":`document`,"tagged-document":`document`,docs:`stacked-document`,documents:`stacked-document`,"st-doc":`stacked-document`,"stacked-document":`stacked-document`,"notch-rect":`card`,card:`card`,"notched-rectangle":`card`,"lin-rect":`lined-process`,"lined-rectangle":`lined-process`,"lin-proc":`lined-process`,"shaded-process":`lined-process`,"div-rect":`divided-process`,"divided-rectangle":`divided-process`,"div-proc":`divided-process`,"tag-rect":`rectangle`,"tagged-rectangle":`rectangle`,"tag-proc":`rectangle`,procs:`stacked-process`,processes:`stacked-process`,"st-rect":`stacked-process`,"stacked-rectangle":`stacked-process`,tri:`triangle`,triangle:`triangle`,extract:`triangle`,"flip-tri":`flipped-triangle`,"flipped-triangle":`flipped-triangle`,"manual-file":`flipped-triangle`,"win-pane":`window-pane`,"window-pane":`window-pane`,"internal-storage":`window-pane`,fork:`fork-join`,join:`fork-join`,"long-rect":`fork-join`,"notch-pent":`notched-pentagon`,"loop-limit":`notched-pentagon`,"notched-pentagon":`notched-pentagon`,"sl-rect":`sloped-rectangle`,"sloped-rectangle":`sloped-rectangle`,"manual-input":`sloped-rectangle`,flag:`flag`,"paper-tape":`flag`,"bow-rect":`bow-tie-rectangle`,"bow-tie-rectangle":`bow-tie-rectangle`,"stored-data":`bow-tie-rectangle`,delay:`half-rounded-rectangle`,"half-rounded-rectangle":`half-rounded-rectangle`,brace:`brace`,"brace-l":`brace`,comment:`brace`,"brace-r":`brace-right`,braces:`braces`,bolt:`bolt`,"com-link":`bolt`,"lightning-bolt":`bolt`,text:`text`,anchor:`anchor`};function W(e){return U[e.trim().toLowerCase()]}function Qe(){return Object.keys(U).sort()}function G(e){let t={};for(let n of $e(e,`,`)){let e=n.trim();if(e.length===0)continue;let r=et(e,`:`);if(r===-1){t.shape??=K(e);continue}let i=e.slice(0,r).trim().toLowerCase(),a=K(e.slice(r+1).trim());i.length>0&&(t[i]=a)}return t}function $e(e,t){let n=[],r=``,i=null;for(let a of e){if(i!==null){r+=a,a===i&&(i=null);continue}if(a===`"`||a===`'`){i=a,r+=a;continue}if(a===t){n.push(r),r=``;continue}r+=a}return n.push(r),n}function et(e,t){let n=null;for(let r=0;r<e.length;r++){let i=e[r];if(n!==null){i===n&&(n=null);continue}if(i===`"`||i===`'`){n=i;continue}if(i===t)return r}return-1}function K(e){return e.length>=2&&(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))?e.slice(1,-1):e}function q(e){if(!e.startsWith(`@{`))return;let t=0,n=null;for(let r=1;r<e.length;r++){let i=e[r];if(n!==null){i===n&&(n=null);continue}if(i===`"`||i===`'`){n=i;continue}if(i===`{`){t++;continue}if(i===`}`&&(t--,t===0))return{body:e.slice(2,r),length:r+1}}}function J(e){let t=e.trim();return t.length>=2&&(t[0]===`"`&&t[t.length-1]===`"`||t[0]===`'`&&t[t.length-1]===`'`)?t.slice(1,-1):t}var tt=`"graph <dir>"/"flowchart <dir>" (dir: TD, TB, LR, BT, RL), "stateDiagram-v2", "sequenceDiagram", "classDiagram", "erDiagram", "xychart-beta", "C4Context"/"C4Container"/"C4Component"/"C4Dynamic"/"C4Deployment", "architecture-beta", "pie"`;function nt(e){let t=e.trim().toLowerCase();if(/^sequence/.test(t))return`sequenceDiagram`;if(/^class/.test(t))return`classDiagram`;if(/^er/.test(t))return`erDiagram`;if(/^xychart/.test(t))return`xychart-beta`;if(/^state/.test(t))return`stateDiagram-v2`;if(/^pie/.test(t))return`pie`}var rt=/^(?:[\w-]+@)?<?(?:-{2,}|={2,}|-\.+-?|~{3,})/;function it(e){let t=[];for(let n of e)n.forEach((e,n)=>{if(n===0&&t.length>0&&rt.test(e.text)){let n=t[t.length-1];t[t.length-1]={text:`${n.text} ${e.text}`,line:n.line}}else t.push(e)});return t}function at(t){let n=(0,e.extractInitConfig)(t.split(`
10
+ `).map(e=>e.trim())),r=it((0,e.splitStatementsByLine)(t));if(r.length===0)throw Error(`Empty mermaid diagram`);let i=r[0],a=/^stateDiagram(-v2)?\s*$/i.test(i.text)?st(r):ot(r);return a.initConfig=n,a}function ot(t){let n=t[0];if(n===void 0)throw Error(`parseFlowchart called with no lines`);let r=n.text,i=r.match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!i){let e=r.match(/^(?:graph|flowchart)\b\s*(.*)$/i);if(e){let t=e[1].trim();throw Error(t.length>0?`Line ${n.line}: Invalid direction "${t}" in header "${r}". Expected one of: TD, TB, LR, BT, RL.`:`Line ${n.line}: Missing direction in header "${r}". Expected e.g. "graph TD" or "flowchart LR" — one of: TD, TB, LR, BT, RL.`)}let t=nt(r),i=t&&t.toLowerCase()!==r.trim().toLowerCase()?` Did you mean "${t}"?`:``;throw Error(`Line ${n.line}: Invalid mermaid header: "${r}".${i} Supported headers: ${tt}.`)}let a={direction:(0,e.toDirection)(i[1]),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},o=[];for(let n=1;n<t.length;n++){let r=t[n].text;if((0,e.tryApplyClassDef)(r,a)||(0,e.tryApplyClassAssignment)(r,a)||(0,e.tryApplyStyleStatement)(r,a))continue;if(/^click\s+/i.test(r)){_t(r,a);continue}if(yt(r,a))continue;let i=r.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(i){let t=i[1].trim(),n=(0,e.parseStyleProps)(i[2]);if(t==="default")a.linkStyles.set(`default`,{...a.linkStyles.get(`default`),...n});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||a.linkStyles.set(t,{...a.linkStyles.get(t),...n})}continue}let s=r.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(s&&o.length>0){o[o.length-1].direction=(0,e.toDirection)(s[1]);continue}let c=r.match(/^subgraph\s+(.+)$/);if(c){let t=c[1].trim(),n=t.match(/^([^\s[]+)\s*\[(.+)\]$/),r,i;n?(r=n[1],i=(0,e.normalizeBrTags)(J(n[2]))):(i=(0,e.normalizeBrTags)(J(t)),r=i.replace(/\s+/g,`_`).replace(/[^\p{L}\p{N}_-]/gu,``));let a={id:r,label:i,nodeIds:[],children:[]};o.push(a);continue}if(r===`end`){let e=o.pop();e&&(o.length>0?o[o.length-1].children.push(e):a.subgraphs.push(e));continue}Ct(r,a,o)}return a}function st(t){let n={direction:`TD`,nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map,interactions:new Map},r=[],i=new Set,a=0,o=0;for(let s=1;s<t.length;s++){let c=t[s].text;if((0,e.tryApplyClassDef)(c,n)||(0,e.tryApplyClassAssignment)(c,n)||(0,e.tryApplyStyleStatement)(c,n))continue;let l=c.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(l){r.length>0?r[r.length-1].direction=(0,e.toDirection)(l[1]):n.direction=(0,e.toDirection)(l[1]);continue}let u=c.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(u){let t=u[1].trim(),r=(0,e.parseStyleProps)(u[2]);if(t==="default")n.linkStyles.set(`default`,{...n.linkStyles.get(`default`),...r});else{let e=t.split(`,`).map(e=>parseInt(e.trim(),10));for(let t of e)isNaN(t)||n.linkStyles.set(t,{...n.linkStyles.get(t),...r})}continue}if(yt(c,n))continue;let d=c.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(d){let e=d[1]??d[2],t=d[2],a={id:t,label:e,nodeIds:[],children:[]};r.push(a),i.add(t),n.nodes.delete(t);continue}if(c===`}`){let e=r.pop();e&&(r.length>0?r[r.length-1].children.push(e):n.subgraphs.push(e));continue}let f=c.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(f){let t=(0,e.normalizeBrTags)(f[1]),i=f[2];ct(n,r,i,t);continue}let p=c.match(/^(\[\*\]|[\w\p{L}-]+)(?::::([\w][\w-]*))?\s*(?:([\w-]+)@)?-->\s*(\[\*\]|[\w\p{L}-]+)(?::::([\w][\w-]*))?(?:\s*:\s*(.+))?$/u);if(p){let t=p[1],s=p[2],c=p[3],l=p[4],u=p[5],d=p[6]?.trim(),f=d?(0,e.normalizeBrTags)(d):void 0;t===`[*]`?(a++,t=`_start${a>1?a:``}`,Y(n,r,{id:t,label:``,shape:`state-start`})):i.has(t)||X(n,r,t),l===`[*]`?(o++,l=`_end${o>1?o:``}`,Y(n,r,{id:l,label:``,shape:`state-end`})):i.has(l)||X(n,r,l),s!==void 0&&n.classAssignments.set(t,s),u!==void 0&&n.classAssignments.set(l,u),n.edges.push({source:t,target:l,label:f,style:`solid`,hasArrowStart:!1,hasArrowEnd:!0,...c===void 0?{}:{id:c}});continue}let m=c.match(/^([\w\p{L}-]+):::([\w][\w-]*)\s*$/u);if(m){let e=m[1];i.has(e)||X(n,r,e),n.classAssignments.set(e,m[2]);continue}let h=c.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(h){let t=h[1];ct(n,r,t,(0,e.normalizeBrTags)(h[2].trim()));continue}}for(let e of n.classAssignments.keys())!n.nodes.has(e)&&!i.has(e)&&X(n,[],e);return n}function ct(e,t,n,r){let i=e.nodes.get(n);i&&(i.label=r),Y(e,t,{id:n,label:r,shape:`rounded`})}function Y(e,t,n){if(e.nodes.has(n.id)||e.nodes.set(n.id,n),t.length>0){let e=t[t.length-1];e.nodeIds.includes(n.id)||e.nodeIds.push(n.id)}}function X(e,t,n){if(!e.nodes.has(n))Y(e,t,{id:n,label:n,shape:`rounded`});else if(t.length>0){let e=t[t.length-1];e.nodeIds.includes(n)||e.nodeIds.push(n)}}var lt=/^(<|o|x)?(-{2,}|={2,}|-\.+-|~{3,})(>|o|x)?(?:\s*\|([^|]*)\|)?/,ut=new Set([`--`,`==`]);function Z(e){if(e===`o`)return`circle`;if(e===`x`)return`cross`}var dt=/^(<|o|x)?(--|-\.|==)\s+(.+?)\s+(-{2,}[>ox]|={2,}[>ox]|\.+-[>ox]|-{3,}|={3,}|-\.+-)/,ft=[{regex:/^([\w\p{L}-]+)\(\(\(((?:"[^"]*"|(?!\)\)\)).)+)\)\)\)/u,shape:`doublecircle`},{regex:/^([\w\p{L}-]+)\(\[((?:"[^"]*"|(?!\]\)).)+)\]\)/u,shape:`stadium`},{regex:/^([\w\p{L}-]+)\(\(((?:"[^"]*"|(?!\)\)).)+)\)\)/u,shape:`circle`},{regex:/^([\w\p{L}-]+)\[\[((?:"[^"]*"|(?!\]\]).)+)\]\]/u,shape:`subroutine`},{regex:/^([\w\p{L}-]+)\[\(((?:"[^"]*"|(?!\)\]).)+)\)\]/u,shape:`cylinder`},{regex:/^([\w\p{L}-]+)\[\/((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`\\`?`trapezoid`:`parallelogram`},{regex:/^([\w\p{L}-]+)\[\\((?:"[^"]*"|(?![\\/]\]).)+)([\\/])\]/u,shape:e=>e===`/`?`trapezoid-alt`:`parallelogram-alt`},{regex:/^([\w\p{L}-]+)>((?:"[^"]*"|(?!\]).)+)\]/u,shape:`asymmetric`},{regex:/^([\w\p{L}-]+)\{\{((?:"[^"]*"|(?!\}\}).)+)\}\}/u,shape:`hexagon`},{regex:/^([\w\p{L}-]+)\[((?:"[^"]*"|(?!\]).)+)\]/u,shape:`rectangle`},{regex:/^([\w\p{L}-]+)\(((?:"[^"]*"|(?!\)).)+)\)/u,shape:`rounded`},{regex:/^([\w\p{L}-]+)\{((?:"[^"]*"|(?!\}).)+)\}/u,shape:`diamond`}],pt=/^([\w\p{L}]+(?:-[\w\p{L}]+)*)/u,mt=/^([\w\p{L}-]+)(?=@\{)/u;function ht(e){if(e.shape)return W(e.shape)??`rectangle`;if(e.icon!==void 0||e.img!==void 0)switch(e.form?.toLowerCase()){case`circle`:return`circle`;case`rounded`:return`rounded`;default:return`rectangle`}return`rectangle`}function gt(e,t){return t.label!==void 0&&t.label.length>0?t.label:t.icon?t.icon:t.img?t.img:e}function _t(t,n){(0,e.applyClickStatement)(t,n.interactions)}var vt=/^([\w-]+)(?=@\{)/;function yt(e,t){let n=e.match(vt);if(!n||!t.edges.some(e=>e.id===n[1]))return!1;let r=q(e.slice(n[1].length));return r?(bt(t,n[1],G(r.body)),!0):!1}function bt(e,t,n){for(let r of e.edges)r.id===t&&(n.animate!==void 0&&(r.animate=n.animate.toLowerCase()!==`false`),n.animation!==void 0&&(r.animate=!0))}var xt=/^:::([\w][\w-]*)/,St=/^([\w\p{L}-]+):::([\w][\w-]*)/u;function Ct(t,n,r){let i=t.trim(),a=wt(i,n,r);if(!a||a.ids.length===0)return;i=a.remaining.trim();let o=a.ids;for(;i.length>0;){let t,a,s,c,l,u,d,f=i.match(/^([\w-]+)@(?=[-=<~ox])/);f&&(d=f[1],i=i.slice(f[0].length));let p=i.match(lt),m=p?.[2],h=p?.[1],g=p?.[3];if(p&&m!==void 0&&!(h===void 0&&g===void 0&&ut.has(m))){t=h!==void 0,l=Z(h);let n=p[4]?.trim();c=n?(0,e.normalizeBrTags)(n):void 0,i=i.slice(p[0].length).trim(),a=Dt(m),s=g!==void 0,u=Z(g)}else{let n=i.match(dt);if(!n)break;t=!!n[1],l=Z(n[1]);let r=n[3].trim();c=r?(0,e.normalizeBrTags)(r):void 0;let o=n[2],d=n[4];i=i.slice(n[0].length).trim(),a=Ot(o,d),u=Z(d.slice(-1)),s=d.endsWith(`>`)||u!==void 0}let _=wt(i,n,r);if(!_||_.ids.length===0)break;i=_.remaining.trim();for(let e of o)for(let r of _.ids)n.edges.push({source:e,target:r,label:c,style:a,hasArrowStart:t,hasArrowEnd:s,...l===void 0?{}:{startMarker:l},...u===void 0?{}:{endMarker:u},...d===void 0?{}:{id:d}});o=_.ids}}function wt(e,t,n){let r=Tt(e,t,n);if(!r)return null;let i=[r.id],a=r.remaining.trim();for(;a.startsWith(`&`);){a=a.slice(1).trim();let e=Tt(a,t,n);if(!e)break;i.push(e.id),a=e.remaining.trim()}return{ids:i,remaining:a}}function Tt(t,n,r){let i=null,a=t,o,s=a.match(St);s&&(o=s[2],a=s[1]+a.slice(s[0].length));let c=a.match(mt);if(c){let t=c[1],o=q(a.slice(t.length));if(o){let s=G(o.body);Q(n,r,{id:t,label:(0,e.normalizeBrTags)(gt(t,s)),shape:ht(s)}),i=t,a=a.slice(t.length+o.length)}}if(i===null)for(let{regex:t,shape:o}of ft){let s=a.match(t);if(s){i=s[1];let t=(0,e.normalizeBrTags)(s[2]),c=typeof o==`function`?o(s[3]??``):o;Q(n,r,{id:i,label:t,shape:c}),a=a.slice(s[0].length);break}}if(i===null){let e=a.match(pt);e&&(i=e[1],n.nodes.has(i)?Et(n,r,i)||$(r,i):Q(n,r,{id:i,label:i,shape:`rectangle`}),a=a.slice(e[0].length))}if(i===null)return null;o&&n.classAssignments.set(i,o);let l=a.match(xt);return l&&(n.classAssignments.set(i,l[1]),a=a.slice(l[0].length)),{id:i,remaining:a}}function Q(e,t,n){e.nodes.has(n.id)||e.nodes.set(n.id,n),$(t,n.id)}function Et(e,t,n){let r=e=>e.nodeIds.includes(n)||e.children.some(r);return e.subgraphs.some(r)||t.some(r)}function $(e,t){if(e.length>0){let n=e[e.length-1];n.nodeIds.includes(t)||n.nodeIds.push(t)}}function Dt(e){return e.startsWith(`~`)?`invisible`:e.includes(`.`)?`dotted`:e.startsWith(`=`)?`thick`:`solid`}function Ot(e,t){return e.includes(`.`)||t.includes(`.`)?`dotted`:e.startsWith(`=`)||t.startsWith(`=`)?`thick`:`solid`}exports.CHART_ACCENT_FALLBACK=L,exports.architectureToGraph=p,exports.c4BoundaryTypeLine=ae,exports.c4Placement=se,exports.c4RelLabelLines=oe,exports.c4TypeLine=ie,exports.checkActivationBalance=F,exports.fixActivationBalance=je,exports.formatClassMember=ge,exports.getSeriesColor=Re,exports.isBlockType=M,exports.isCssColor=A,exports.isDarkBackground=B,exports.isValidHex=z,exports.knownShapeNames=Qe,exports.matchExpandedBlock=q,exports.parseArchitecture=c,exports.parseBoxHeader=j,exports.parseC4Diagram=te,exports.parseClassDiagram=ue,exports.parseErDiagram=_e,exports.parseExpandedMeta=G,exports.parseGenericTypes=D,exports.parseMermaid=at,exports.parsePieChart=Ze,exports.parseSequenceDiagram=De,exports.parseXYChart=Me,exports.resolveShapeName=W,exports.toBlockType=we,Object.defineProperty(exports,"toDirection",{enumerable:!0,get:function(){return e.toDirection}}),exports.wrapC4Text=ne;
5
11
  //# sourceMappingURL=index.cjs.map