@zombie-mermaid/mermaid-parser 2.2.1 → 3.0.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,3 +1,3 @@
1
1
  Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@zombie-mermaid/core");var t=`<\\|--|<\\|\\.\\.|\\*--|o--|-->|--\\*|--o|--\\|>|\\.\\.>|\\.\\.\\|>|<--|<\\.\\.?|--`,n=new RegExp(t);function r(t){let r={classes:[],relationships:[],namespaces:[],interactions:new Map,classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,notes:[]},o=new Map,s=null,c=null,l=0,d;for(let p=1;p<t.length;p++){let m=t[p],h=m.text;if(c&&l>0){if(h===`}`){l--,l===0&&(c=null,d=void 0);continue}let e=h.match(/^<<(\w+)>>$/);if(e){c.annotation=e[1];continue}if(h.startsWith(`<<`))throw Error(`Line ${m.line}: Malformed class annotation "${h}" — expected "<<name>>" (e.g. "<<interface>>").`);i(c,h,m.line);continue}if(/^click\s+/i.test(h)){(0,e.applyClickStatement)(h,r.interactions);continue}let g=h.match(/^note\s+(?:for\s+(\S+)\s+)?"([^"]*)"\s*$/);if(g){let t=g[1];r.notes.push({text:(0,e.normalizeBrTags)(g[2]),...t?{forClass:t}:{}});continue}if((0,e.tryApplyClassDef)(h,r)||(0,e.tryApplyStyleStatement)(h,r)||(0,e.tryApplyCssClass)(h,r)||(0,e.tryApplyClassAssignment)(h,r))continue;let _=h.match(/^namespace\s+(\S+)\s*\{$/);if(_){s={name:_[1],classIds:[]};continue}if(h===`}`&&s){r.namespaces.push(s),s=null;continue}let v=h.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(v){let e=f(v[1],v[2]);c=o.get(e)??null,l=1,d=m.line;continue}let y=h.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(y){f(y[1],y[2]);continue}let b=h.match(/^class\s+(\S+?)\s*\{\s*(.*?)\s*\}$/);if(b){let e=f(b[1],void 0),t=o.get(e),n=b[2],r=n.match(/^<<(\w+)>>$/);if(t&&r)t.annotation=r[1];else if(t&&n.startsWith(`<<`))throw Error(`Line ${m.line}: Malformed class annotation "${n}" — expected "<<name>>" (e.g. "<<interface>>").`);else t&&n&&i(t,n,m.line);continue}let x=h.match(/^(\S+?)\s*:\s*(.+)$/);if(x){let e=x[2];if(!e.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){i(a(o,x[1]),e,m.line);continue}}let S=u(h);if(S){S.from=f(S.from,void 0,!1),S.to=f(S.to,void 0,!1),r.relationships.push(S);continue}if(n.test(h))throw Error(`Line ${m.line}: Malformed class-diagram relationship "${h}". 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(c!==null)throw Error(`Line ${d}: Unclosed class body for "${c.id}" — expected a closing "}" before the diagram ends.`);return r.classes=[...o.values()],r;function f(t,n,i=!0){let{id:c,className:l}=(0,e.splitClassShorthand)(t),u=c,d=n;if(!d){let e=c.match(/^(.+?)~(\w+)~$/);e&&(u=e[1],d=e[2])}let f=a(o,u);return d&&(f.label=`${u}<${d}>`),l&&r.classAssignments.set(u,l),i&&s&&s.classIds.push(u),u}}function i(e,t,n){let r=l(t,n);r&&(r.isMethod?e.methods.push(r.member):e.attributes.push(r.member))}function a(e,t){let n=e.get(t);return n||(n={id:t,label:t,attributes:[],methods:[]},e.set(t,n)),n}function o(e,t){return Math.max(0,e.split(t).length-1)}function s(e){let t=o(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(`~`),s=i.lastIndexOf(`~`);for(;a!==-1&&s!==-1&&a!==s;)i[a]=`<`,i[s]=`>`,a=i.indexOf(`~`),s=i.lastIndexOf(`~`);return r&&i.unshift(`~`),i.join(``)}function c(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];o(i,`~`)===1&&o(a,`~`)===1&&(r=`${i},${a}`,e++,n.pop())}n.push(s(r))}return n.join(``)}function l(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=c(o[1].trim()),t=o[2]?.trim(),n=t?c(t):void 0,a=o[3]?.trim(),s=a?c(a):void 0,l=e.endsWith(`$`)||i.includes(`$`),u=e.endsWith(`*`)||i.includes(`*`);return{member:{visibility:r,name:e.replace(/[$*]$/,``),type:s||void 0,isStatic:l,isAbstract:u,isMethod:!0,params:n},isMethod:!0}}let s=c(i).split(/\s+/),l,u;s.length>=2?(u=s[0],l=s.slice(1).join(` `)):l=s[0]??i;let d=l.endsWith(`$`),f=l.endsWith(`*`);return{member:{visibility:r,name:l.replace(/[$*]$/,``),type:u||void 0,isStatic:d,isAbstract:f,isMethod:!1},isMethod:!1}}function u(n){let r=n.match(RegExp(`^(\\S+?)\\s+(?:"([^"]*?)"\\s+)?(${t})\\s+(?:"([^"]*?)"\\s+)?(\\S+?)(?::::([\\w][\\w-]*))?(?:\\s*:\\s*(.+))?$`));if(!r)return null;let i=r[1],a=r[2],o=a?(0,e.normalizeBrTags)(a):void 0,s=r[3].trim(),c=r[4],l=c?(0,e.normalizeBrTags)(c):void 0,u=r[6]?`${r[5]}:::${r[6]}`:r[5],f=r[7]?.trim(),p=f?(0,e.normalizeBrTags)(f):void 0,m=d(s);return m?{from:i,to:u,type:m.type,markerAt:m.markerAt,label:p,fromCardinality:o,toCardinality:l}:null}function d(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 f(e){return`${e.visibility?`${e.visibility} `:``}${e.isMethod?`${e.name}(${e.params||``})`:e.name}${e.type?`: ${e.type}`:``}`}function p(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=h(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=m(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=h(e);t&&a.attributes.push(t)}s||(i=a);continue}let u=g(s,o.line);if(u){m(r,u.entity1),m(r,u.entity2),n.relationships.push(u);continue}}return n.entities=[...r.values()],n}function m(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 h(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 g(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?_(l[1]):null,d=l?v(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 _(e){return e===`||`?`one`:e===`|o`?`zero-one`:e===`}|`?`many`:e===`}o`?`zero-many`:null}function v(e){return e===`||`?`one`:e===`o|`?`zero-one`:e===`|{`?`many`:e===`o{`?`zero-many`:null}var y=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(` `)),b=/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,x=/^(?:rgba?|hsla?)\(\s*[\d.%]+(?:[\s,/]+[\d.%]+){2,3}\s*\)$/i;function S(e){return y.has(e.toLowerCase())||b.test(e)||x.test(e)}function C(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!==``&&S(r)?{color:r,label:i}:{label:t}}function w(e){return e===`loop`||e===`alt`||e===`opt`||e===`par`||e===`critical`||e===`break`||e===`rect`}function T(e){if(!w(e))throw Error(`Invalid block type: "${e}"`);return e}var E=/^(.+?)\s*(<<->>|<<-->>|--?>?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/,D=/^(.+?)\s*(<<->>|<<-->>|--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(.+?)\s*:\s*(.+)$/;function O(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}=C(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}),j(n,r,i,f.line),l=i;continue}let g=p.match(/^destroy\s+(.+)$/);if(g){let e=g[1].trim();A(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})),j(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)A(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=T(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();A(n,o,r,e,f.line),n.activations.push({actorId:e,kind:S[1]===`activate`?`start`:`end`,afterIndex:n.messages.length-1});continue}let w=p.match(E)??p.match(D);if(w){let e=w[2],t=w[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, -), --), <<->>, <<-->>.`);M(n,o,r,c,w[1],w[2],w[3],w[4],w[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.`);k(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.`);k(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 k(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 A(e,t,n,r,i){t.has(r)||(t.add(r),e.actors.push({id:r,label:r,type:`participant`})),j(e,n,r,i)}function j(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 M(t,n,r,i,a,o,s,c,l,u){A(t,n,r,a,u),A(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 N(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 P(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}" ${N(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 ${N(e,r)} is never closed with a matching "deactivate ${t}".`});return{ok:a.length===0,issues:a}}function F(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=P(O((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(`
2
- `),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 I(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=L(c[2]).map(e=>R(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:z(f[1],`bar`,e,o.line)});continue}let p=e.match(/^line\s+\[([^\]]+)\]/);if(p){r.push({type:`line`,data:z(p[1],`line`,e,o.line)});continue}let m=e.match(/^(x-axis|y-axis|bar|line|title)\b/i);if(m)throw V(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 L(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 R(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}function z(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 B={"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 V(e,t,n){let r=B[e]??e;return Error(`Line ${n}: Malformed xychart-beta "${e}" directive: "${t}". Expected: ${r}.`)}var H=`#3b82f6`;function U(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 W(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 G(e){let t=e.replace(`#`,``);return[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]}function K(e,t,n){let r=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}function q(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function J(e){return U(e)[2]<50}function Y(e,t,n){let[r,i,a]=G(e),[o,s,c]=G(t),l=1-n;return K(r*l+o*n,i*l+s*n,a*l+c*n)}function X(e,t,n){if(e===0)return t;let r=q(t)?t:H,i=n&&q(n)?n:void 0,[a,o]=U(r),s=Math.max(55,Math.min(85,o)),c=Math.ceil(e/2),l=e%2==1,u=i&&J(i)?!l:l,d=u?Math.max(25,48-c*13):Math.min(78,55+c*11);return W(((a+(u?-8:12)*c)%360+360)%360,s,d)}var Z={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 Q(e){return Z[e.trim().toLowerCase()]}function ee(){return Object.keys(Z).sort()}function te(e){let t={};for(let n of ne(e,`,`)){let e=n.trim();if(e.length===0)continue;let r=re(e,`:`);if(r===-1){t.shape??=$(e);continue}let i=e.slice(0,r).trim().toLowerCase(),a=$(e.slice(r+1).trim());i.length>0&&(t[i]=a)}return t}function ne(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 re(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 $(e){return e.length>=2&&(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))?e.slice(1,-1):e}function ie(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}}}exports.CHART_ACCENT_FALLBACK=H,exports.checkActivationBalance=P,exports.fixActivationBalance=F,exports.formatClassMember=f,exports.getSeriesColor=X,exports.isBlockType=w,exports.isCssColor=S,exports.isDarkBackground=J,exports.isValidHex=q,exports.knownShapeNames=ee,exports.matchExpandedBlock=ie,exports.mixHexColors=Y,exports.parseBoxHeader=C,exports.parseClassDiagram=r,exports.parseErDiagram=p,exports.parseExpandedMeta=te,exports.parseGenericTypes=c,exports.parseSequenceDiagram=O,exports.parseXYChart=I,exports.resolveShapeName=Q,exports.toBlockType=T;
2
+ `),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 I(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=L(c[2]).map(e=>R(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:z(f[1],`bar`,e,o.line)});continue}let p=e.match(/^line\s+\[([^\]]+)\]/);if(p){r.push({type:`line`,data:z(p[1],`line`,e,o.line)});continue}let m=e.match(/^(x-axis|y-axis|bar|line|title)\b/i);if(m)throw V(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 L(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 R(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}function z(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 B={"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 V(e,t,n){let r=B[e]??e;return Error(`Line ${n}: Malformed xychart-beta "${e}" directive: "${t}". Expected: ${r}.`)}var H=`#3b82f6`;function U(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 W(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 G(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function K(e){return U(e)[2]<50}function q(e,t,n){if(e===0)return t;let r=G(t)?t:H,i=n&&G(n)?n:void 0,[a,o]=U(r),s=Math.max(55,Math.min(85,o)),c=Math.ceil(e/2),l=e%2==1,u=i&&K(i)?!l:l,d=u?Math.max(25,48-c*13):Math.min(78,55+c*11);return W(((a+(u?-8:12)*c)%360+360)%360,s,d)}var J={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 Y(e){return J[e.trim().toLowerCase()]}function X(){return Object.keys(J).sort()}function Z(e){let t={};for(let n of Q(e,`,`)){let e=n.trim();if(e.length===0)continue;let r=ee(e,`:`);if(r===-1){t.shape??=$(e);continue}let i=e.slice(0,r).trim().toLowerCase(),a=$(e.slice(r+1).trim());i.length>0&&(t[i]=a)}return t}function Q(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 ee(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 $(e){return e.length>=2&&(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))?e.slice(1,-1):e}function te(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}}}exports.CHART_ACCENT_FALLBACK=H,exports.checkActivationBalance=P,exports.fixActivationBalance=F,exports.formatClassMember=f,exports.getSeriesColor=q,exports.isBlockType=w,exports.isCssColor=S,exports.isDarkBackground=K,exports.isValidHex=G,exports.knownShapeNames=X,exports.matchExpandedBlock=te,exports.parseBoxHeader=C,exports.parseClassDiagram=r,exports.parseErDiagram=p,exports.parseExpandedMeta=Z,exports.parseGenericTypes=c,exports.parseSequenceDiagram=O,exports.parseXYChart=I,exports.resolveShapeName=Y,exports.toBlockType=T;
3
3
  //# sourceMappingURL=index.cjs.map