archimaid 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/FOUNDATION.md +108 -0
  3. package/LICENSE +21 -0
  4. package/README.md +271 -2
  5. package/dist/archimate/catalogue.d.ts +106 -0
  6. package/dist/archimate/catalogue.js +219 -0
  7. package/dist/archimate/catalogue.js.map +1 -0
  8. package/dist/archimate/diagnostics.d.ts +48 -0
  9. package/dist/archimate/diagnostics.js +64 -0
  10. package/dist/archimate/diagnostics.js.map +1 -0
  11. package/dist/archimate/frontmatter.d.ts +13 -0
  12. package/dist/archimate/frontmatter.js +62 -0
  13. package/dist/archimate/frontmatter.js.map +1 -0
  14. package/dist/archimate/grammar.d.ts +60 -0
  15. package/dist/archimate/grammar.js +273 -0
  16. package/dist/archimate/grammar.js.map +1 -0
  17. package/dist/archimate/lexer.d.ts +91 -0
  18. package/dist/archimate/lexer.js +215 -0
  19. package/dist/archimate/lexer.js.map +1 -0
  20. package/dist/archimate/model.d.ts +46 -0
  21. package/dist/archimate/model.js +2 -0
  22. package/dist/archimate/model.js.map +1 -0
  23. package/dist/archimate/nesting.d.ts +14 -0
  24. package/dist/archimate/nesting.js +84 -0
  25. package/dist/archimate/nesting.js.map +1 -0
  26. package/dist/archimate/parser.d.ts +14 -0
  27. package/dist/archimate/parser.js +53 -0
  28. package/dist/archimate/parser.js.map +1 -0
  29. package/dist/archimate/suggestions.d.ts +1 -0
  30. package/dist/archimate/suggestions.js +44 -0
  31. package/dist/archimate/suggestions.js.map +1 -0
  32. package/dist/archimate/validate.d.ts +4 -0
  33. package/dist/archimate/validate.js +402 -0
  34. package/dist/archimate/validate.js.map +1 -0
  35. package/dist/bundle/archimaid.esm.min.mjs +1 -0
  36. package/dist/bundle/chunks/archimateDiagram-WUCF6KHR.mjs +132 -0
  37. package/dist/bundle/chunks/chunk-QBMRZFD3.mjs +1 -0
  38. package/dist/bundle/chunks/elk.bundled-2VSLVJGB.mjs +26 -0
  39. package/dist/cli/render.d.ts +10 -0
  40. package/dist/cli/render.js +102 -0
  41. package/dist/cli/render.js.map +1 -0
  42. package/dist/cli/report.d.ts +20 -0
  43. package/dist/cli/report.js +39 -0
  44. package/dist/cli/report.js.map +1 -0
  45. package/dist/cli/sources.d.ts +19 -0
  46. package/dist/cli/sources.js +86 -0
  47. package/dist/cli/sources.js.map +1 -0
  48. package/dist/cli.d.ts +2 -0
  49. package/dist/cli.js +137 -0
  50. package/dist/cli.js.map +1 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +2 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/language.d.ts +5 -0
  55. package/dist/language.js +3 -0
  56. package/dist/language.js.map +1 -0
  57. package/dist/mermaid/archimateDetector.d.ts +12 -0
  58. package/dist/mermaid/archimateDetector.js +29 -0
  59. package/dist/mermaid/archimateDetector.js.map +1 -0
  60. package/dist/mermaid/archimateDiagram.d.ts +9 -0
  61. package/dist/mermaid/archimateDiagram.js +75 -0
  62. package/dist/mermaid/archimateDiagram.js.map +1 -0
  63. package/dist/mermaid/archimateRenderer.d.ts +6 -0
  64. package/dist/mermaid/archimateRenderer.js +40 -0
  65. package/dist/mermaid/archimateRenderer.js.map +1 -0
  66. package/dist/mermaid/architectureLayout.d.ts +50 -0
  67. package/dist/mermaid/architectureLayout.js +144 -0
  68. package/dist/mermaid/architectureLayout.js.map +1 -0
  69. package/dist/mermaid/geometry.d.ts +3 -0
  70. package/dist/mermaid/geometry.js +20 -0
  71. package/dist/mermaid/geometry.js.map +1 -0
  72. package/dist/mermaid/hierarchy.d.ts +1 -0
  73. package/dist/mermaid/hierarchy.js +8 -0
  74. package/dist/mermaid/hierarchy.js.map +1 -0
  75. package/dist/mermaid/invariant.d.ts +1 -0
  76. package/dist/mermaid/invariant.js +7 -0
  77. package/dist/mermaid/invariant.js.map +1 -0
  78. package/dist/mermaid/orthogonalRouter.d.ts +4 -0
  79. package/dist/mermaid/orthogonalRouter.js +249 -0
  80. package/dist/mermaid/orthogonalRouter.js.map +1 -0
  81. package/dist/mermaid/relationshipPlacement.d.ts +3 -0
  82. package/dist/mermaid/relationshipPlacement.js +350 -0
  83. package/dist/mermaid/relationshipPlacement.js.map +1 -0
  84. package/dist/mermaid/render/draw.d.ts +17 -0
  85. package/dist/mermaid/render/draw.js +275 -0
  86. package/dist/mermaid/render/draw.js.map +1 -0
  87. package/dist/mermaid/render/elkRoutes.d.ts +6 -0
  88. package/dist/mermaid/render/elkRoutes.js +216 -0
  89. package/dist/mermaid/render/elkRoutes.js.map +1 -0
  90. package/dist/mermaid/render/graph.d.ts +17 -0
  91. package/dist/mermaid/render/graph.js +200 -0
  92. package/dist/mermaid/render/graph.js.map +1 -0
  93. package/dist/mermaid/render/labels.d.ts +12 -0
  94. package/dist/mermaid/render/labels.js +148 -0
  95. package/dist/mermaid/render/labels.js.map +1 -0
  96. package/dist/mermaid/render/layout.d.ts +12 -0
  97. package/dist/mermaid/render/layout.js +60 -0
  98. package/dist/mermaid/render/layout.js.map +1 -0
  99. package/dist/mermaid/render/measure.d.ts +16 -0
  100. package/dist/mermaid/render/measure.js +96 -0
  101. package/dist/mermaid/render/measure.js.map +1 -0
  102. package/dist/mermaid/render/place.d.ts +20 -0
  103. package/dist/mermaid/render/place.js +63 -0
  104. package/dist/mermaid/render/place.js.map +1 -0
  105. package/dist/mermaid/render/route.d.ts +29 -0
  106. package/dist/mermaid/render/route.js +113 -0
  107. package/dist/mermaid/render/route.js.map +1 -0
  108. package/dist/mermaid/render/shared.d.ts +83 -0
  109. package/dist/mermaid/render/shared.js +52 -0
  110. package/dist/mermaid/render/shared.js.map +1 -0
  111. package/dist/mermaid/render/svg.d.ts +6 -0
  112. package/dist/mermaid/render/svg.js +33 -0
  113. package/dist/mermaid/render/svg.js.map +1 -0
  114. package/dist/mermaid/render/viewport.d.ts +14 -0
  115. package/dist/mermaid/render/viewport.js +58 -0
  116. package/dist/mermaid/render/viewport.js.map +1 -0
  117. package/dist/mermaid/routing/anchors.d.ts +14 -0
  118. package/dist/mermaid/routing/anchors.js +134 -0
  119. package/dist/mermaid/routing/anchors.js.map +1 -0
  120. package/dist/mermaid/routing/bundles.d.ts +14 -0
  121. package/dist/mermaid/routing/bundles.js +94 -0
  122. package/dist/mermaid/routing/bundles.js.map +1 -0
  123. package/dist/mermaid/routing/congestion.d.ts +8 -0
  124. package/dist/mermaid/routing/congestion.js +70 -0
  125. package/dist/mermaid/routing/congestion.js.map +1 -0
  126. package/dist/mermaid/routing/constants.d.ts +13 -0
  127. package/dist/mermaid/routing/constants.js +17 -0
  128. package/dist/mermaid/routing/constants.js.map +1 -0
  129. package/dist/mermaid/routing/primitives.d.ts +33 -0
  130. package/dist/mermaid/routing/primitives.js +110 -0
  131. package/dist/mermaid/routing/primitives.js.map +1 -0
  132. package/dist/mermaid/routing/search.d.ts +4 -0
  133. package/dist/mermaid/routing/search.js +171 -0
  134. package/dist/mermaid/routing/search.js.map +1 -0
  135. package/dist/mermaid/routing/shapes.d.ts +8 -0
  136. package/dist/mermaid/routing/shapes.js +82 -0
  137. package/dist/mermaid/routing/shapes.js.map +1 -0
  138. package/dist/mermaid/routing/types.d.ts +37 -0
  139. package/dist/mermaid/routing/types.js +14 -0
  140. package/dist/mermaid/routing/types.js.map +1 -0
  141. package/dist/mermaid/styles.d.ts +89 -0
  142. package/dist/mermaid/styles.js +166 -0
  143. package/dist/mermaid/styles.js.map +1 -0
  144. package/docs/reference.md +86 -0
  145. package/examples/cross-layer-relationships.mmd +79 -0
  146. package/examples/cross-layer-relationships.svg +33 -0
  147. package/examples/element-preview.svg +1 -0
  148. package/examples/nested-components.mmd +21 -0
  149. package/examples/nested-components.svg +4 -0
  150. package/examples/order-fulfilment.mmd +10 -0
  151. package/examples/order-management.mmd +15 -0
  152. package/examples/order-management.svg +2 -0
  153. package/package.json +91 -4
  154. package/skills/archimaid/SKILL.md +123 -0
@@ -0,0 +1,132 @@
1
+ import"./chunk-QBMRZFD3.mjs";var St=class extends Error{code;line;column;detail;constructor(e,n,r,i){super(`Line ${n}, column ${r}: ${i}`),this.code=e,this.line=n,this.column=r,this.detail=i,this.name="ArchiMateError"}},tn=class{text;lineOffset;diagnostics=[];constructor(e,n){this.text=e,this.lineOffset=n}get hasErrors(){return this.diagnostics.some(({severity:e})=>e==="error")}error(e,n,r){this.errorAt(e,this.range(n,n),r)}errorAt(e,n,r){this.diagnostics.push({severity:"error",code:e,message:r,...n})}warning(e,n,r,i){this.diagnostics.push({severity:"warning",code:e,message:i,...this.range(n,r)})}line(e){return this.range(e,e).line}sourceRange(e,n,r,i){return{line:e+this.lineOffset,column:n,endLine:r+this.lineOffset,endColumn:i}}range(e,n){let{startLine:r,startColumn:i}=e;if(r===void 0||!(r>0)||i===void 0||!(i>0))return this.endOfSource();let{endLine:o,endColumn:a}=n;return o!==void 0&&o>0&&a!==void 0&&a>0?this.sourceRange(r,i,o,a+1):this.sourceRange(r,i,r,i)}endOfSource(){let e=this.text.split(/\r\n|\n|\r/),n=(e.at(-1)?.length??0)+1;return this.sourceRange(e.length,n,e.length,n)}};var ua=/\s/;function nn(t){return t===`
2
+ `||t==="\r"}function lr(t){return t!==void 0&&ua.test(t)}function da(t,e){let n=-1;for(let r=e;lr(t[r]);r++)nn(t[r])&&(n=r);return n}function fa(t){let e=0;for(;lr(t[e])&&!nn(t[e]);)e++;if(!t.startsWith("---",e))return{kind:"none"};let n=[];for(let c=e+3;lr(t[c]);c++)nn(t[c])&&n.push(c);let[r]=n;if(r===void 0)return{kind:"none"};let i=t.slice(0,e)+"---",o=c=>nn(t[c])&&t.startsWith(i,c+1)?da(t,c+1+i.length):-1,a=-1;for(let c=r+1;c<t.length;c++)o(c)!==-1&&(a=c);let s=n.filter(c=>c<a).at(-1)??r;for(let c=s+1;c<=a;c++){let l=o(c);if(l!==-1)return{kind:"closed",length:l+1}}return{kind:"unclosed",column:e+1}}function xi(t){let e=t.replace(/\r\n?/g,`
3
+ `),n=fa(e);if(n.kind!=="closed")return{...n,text:t};let r=e.slice(0,n.length).split(`
4
+ `).length-1,i=t.split(/(?<=\r\n|\r(?!\n)|\n)/).slice(0,r).join("").length;return{...n,text:t.slice(0,i).replace(/[^\r\n]/g,"")+t.slice(i)}}function ot(t){console&&console.error&&console.error(`Error: ${t}`)}function Rt(t){console&&console.warn&&console.warn(`Warning: ${t}`)}function It(t){let e=new Date().getTime(),n=t();return{time:new Date().getTime()-e,value:n}}function Ot(t){function e(){}e.prototype=t;let n=new e;function r(){return typeof n.bar}return r(),r(),t;(0,eval)(t)}function pa(t){return ma(t)?t.LABEL:t.name}function ma(t){return typeof t.LABEL=="string"&&t.LABEL!==""}var xe=class{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){this._definition=e}accept(e){e.visit(this),this.definition.forEach(n=>{n.accept(e)})}},$=class extends xe{constructor(e){super([]),this.idx=1,Object.assign(this,ke(e))}set definition(e){}get definition(){return this.referencedRule!==void 0?this.referencedRule.definition:[]}accept(e){e.visit(this)}},le=class extends xe{constructor(e){super(e.definition),this.orgText="",Object.assign(this,ke(e))}},H=class extends xe{constructor(e){super(e.definition),this.ignoreAmbiguities=!1,Object.assign(this,ke(e))}},G=class extends xe{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ke(e))}},Q=class extends xe{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ke(e))}},J=class extends xe{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ke(e))}},F=class extends xe{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ke(e))}},Y=class extends xe{constructor(e){super(e.definition),this.idx=1,Object.assign(this,ke(e))}},Z=class extends xe{get definition(){return this._definition}set definition(e){this._definition=e}constructor(e){super(e.definition),this.idx=1,this.ignoreAmbiguities=!1,this.hasPredicates=!1,Object.assign(this,ke(e))}},U=class{constructor(e){this.idx=1,Object.assign(this,ke(e))}accept(e){e.visit(this)}};function rn(t){return t.map(st)}function st(t){function e(n){return n.map(st)}if(t instanceof $){let n={type:"NonTerminal",name:t.nonTerminalName,idx:t.idx};return typeof t.label=="string"&&(n.label=t.label),n}else{if(t instanceof H)return{type:"Alternative",definition:e(t.definition)};if(t instanceof G)return{type:"Option",idx:t.idx,definition:e(t.definition)};if(t instanceof Q)return{type:"RepetitionMandatory",idx:t.idx,definition:e(t.definition)};if(t instanceof J)return{type:"RepetitionMandatoryWithSeparator",idx:t.idx,separator:st(new U({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof Y)return{type:"RepetitionWithSeparator",idx:t.idx,separator:st(new U({terminalType:t.separator})),definition:e(t.definition)};if(t instanceof F)return{type:"Repetition",idx:t.idx,definition:e(t.definition)};if(t instanceof Z)return{type:"Alternation",idx:t.idx,definition:e(t.definition)};if(t instanceof U){let n={type:"Terminal",name:t.terminalType.name,label:pa(t.terminalType),idx:t.idx};typeof t.label=="string"&&(n.terminalLabel=t.label);let r=t.terminalType.PATTERN;return t.terminalType.PATTERN&&(n.pattern=r instanceof RegExp?r.source:r),n}else{if(t instanceof le)return{type:"Rule",name:t.name,orgText:t.orgText,definition:e(t.definition)};throw Error("non exhaustive match")}}}function ke(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}var he=class{visit(e){let n=e;switch(n.constructor){case $:return this.visitNonTerminal(n);case H:return this.visitAlternative(n);case G:return this.visitOption(n);case Q:return this.visitRepetitionMandatory(n);case J:return this.visitRepetitionMandatoryWithSeparator(n);case Y:return this.visitRepetitionWithSeparator(n);case F:return this.visitRepetition(n);case Z:return this.visitAlternation(n);case U:return this.visitTerminal(n);case le:return this.visitRule(n);default:throw Error("non exhaustive match")}}visitNonTerminal(e){}visitAlternative(e){}visitOption(e){}visitRepetition(e){}visitRepetitionMandatory(e){}visitRepetitionMandatoryWithSeparator(e){}visitRepetitionWithSeparator(e){}visitAlternation(e){}visitTerminal(e){}visitRule(e){}};function hr(t){return t instanceof H||t instanceof G||t instanceof F||t instanceof Q||t instanceof J||t instanceof Y||t instanceof U||t instanceof le}function Ke(t,e=[]){return t instanceof G||t instanceof F||t instanceof Y?!0:t instanceof Z?t.definition.some(r=>Ke(r,e)):t instanceof $&&e.includes(t)?!1:t instanceof xe?(t instanceof $&&e.push(t),t.definition.every(r=>Ke(r,e))):!1}function ur(t){return t instanceof Z}function me(t){if(t instanceof $)return"SUBRULE";if(t instanceof G)return"OPTION";if(t instanceof Z)return"OR";if(t instanceof Q)return"AT_LEAST_ONE";if(t instanceof J)return"AT_LEAST_ONE_SEP";if(t instanceof Y)return"MANY_SEP";if(t instanceof F)return"MANY";if(t instanceof U)return"CONSUME";throw Error("non exhaustive match")}var we=class{walk(e,n=[]){e.definition.forEach((r,i)=>{let o=e.definition.slice(i+1);if(r instanceof $)this.walkProdRef(r,o,n);else if(r instanceof U)this.walkTerminal(r,o,n);else if(r instanceof H)this.walkFlat(r,o,n);else if(r instanceof G)this.walkOption(r,o,n);else if(r instanceof Q)this.walkAtLeastOne(r,o,n);else if(r instanceof J)this.walkAtLeastOneSep(r,o,n);else if(r instanceof Y)this.walkManySep(r,o,n);else if(r instanceof F)this.walkMany(r,o,n);else if(r instanceof Z)this.walkOr(r,o,n);else throw Error("non exhaustive match")})}walkTerminal(e,n,r){}walkProdRef(e,n,r){}walkFlat(e,n,r){let i=n.concat(r);this.walk(e,i)}walkOption(e,n,r){let i=n.concat(r);this.walk(e,i)}walkAtLeastOne(e,n,r){let i=[new G({definition:e.definition})].concat(n,r);this.walk(e,i)}walkAtLeastOneSep(e,n,r){let i=Ai(e,n,r);this.walk(e,i)}walkMany(e,n,r){let i=[new G({definition:e.definition})].concat(n,r);this.walk(e,i)}walkManySep(e,n,r){let i=Ai(e,n,r);this.walk(e,i)}walkOr(e,n,r){let i=n.concat(r);e.definition.forEach(o=>{let a=new H({definition:[o]});this.walk(a,i)})}};function Ai(t,e,n){return[new G({definition:[new U({terminalType:t.separator})].concat(t.definition)})].concat(e,n)}function ze(t){if(t instanceof $)return ze(t.referencedRule);if(t instanceof U)return ya(t);if(hr(t))return ga(t);if(ur(t))return Ea(t);throw Error("non exhaustive match")}function ga(t){let e=[],n=t.definition,r=0,i=n.length>r,o,a=!0;for(;i&&a;)o=n[r],a=Ke(o),e=e.concat(ze(o)),r=r+1,i=n.length>r;return[...new Set(e)]}function Ea(t){let e=t.definition.map(n=>ze(n));return[...new Set(e.flat())]}function ya(t){return[t.terminalType]}var on="_~IN~_";var dr=class extends we{constructor(e){super(),this.topProd=e,this.follows={}}startWalking(){return this.walk(this.topProd),this.follows}walkTerminal(e,n,r){}walkProdRef(e,n,r){let i=xa(e.referencedRule,e.idx)+this.topProd.name,o=n.concat(r),a=new H({definition:o}),s=ze(a);this.follows[i]=s}};function Ti(t){let e={};return t.forEach(n=>{let r=new dr(n).startWalking();Object.assign(e,r)}),e}function xa(t,e){return t.name+e+on}function b(t){return t.charCodeAt(0)}function sn(t,e){Array.isArray(t)?t.forEach(function(n){e.push(n)}):e.push(t)}function at(t,e){if(t[e]===!0)throw"duplicate flag "+e;let n=t[e];t[e]=!0}function Xe(t){if(t===void 0)throw Error("Internal Error - Should never get here!");return!0}function kt(){throw Error("Internal Error - Should never get here!")}function fr(t){return t.type==="Character"}var Nt=[];for(let t=b("0");t<=b("9");t++)Nt.push(t);var Mt=[b("_")].concat(Nt);for(let t=b("a");t<=b("z");t++)Mt.push(t);for(let t=b("A");t<=b("Z");t++)Mt.push(t);var pr=[b(" "),b("\f"),b(`
5
+ `),b("\r"),b(" "),b("\v"),b(" "),b("\xA0"),b("\u1680"),b("\u2000"),b("\u2001"),b("\u2002"),b("\u2003"),b("\u2004"),b("\u2005"),b("\u2006"),b("\u2007"),b("\u2008"),b("\u2009"),b("\u200A"),b("\u2028"),b("\u2029"),b("\u202F"),b("\u205F"),b("\u3000"),b("\uFEFF")];var Aa=/[0-9a-fA-F]/,an=/[0-9]/,Ta=/[1-9]/,Lt=class{constructor(){this.idx=0,this.input="",this.groupIdx=0}saveState(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}}restoreState(e){this.idx=e.idx,this.input=e.input,this.groupIdx=e.groupIdx}pattern(e){this.idx=0,this.input=e,this.groupIdx=0,this.consumeChar("/");let n=this.disjunction();this.consumeChar("/");let r={type:"Flags",loc:{begin:this.idx,end:e.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};for(;this.isRegExpFlag();)switch(this.popChar()){case"g":at(r,"global");break;case"i":at(r,"ignoreCase");break;case"m":at(r,"multiLine");break;case"u":at(r,"unicode");break;case"y":at(r,"sticky");break}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:r,value:n,loc:this.loc(0)}}disjunction(){let e=[],n=this.idx;for(e.push(this.alternative());this.peekChar()==="|";)this.consumeChar("|"),e.push(this.alternative());return{type:"Disjunction",value:e,loc:this.loc(n)}}alternative(){let e=[],n=this.idx;for(;this.isTerm();)e.push(this.term());return{type:"Alternative",value:e,loc:this.loc(n)}}term(){return this.isAssertion()?this.assertion():this.atom()}assertion(){let e=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(e)};case"$":return{type:"EndAnchor",loc:this.loc(e)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(e)};case"B":return{type:"NonWordBoundary",loc:this.loc(e)}}throw Error("Invalid Assertion Escape");case"(":this.consumeChar("?");let n;switch(this.popChar()){case"=":n="Lookahead";break;case"!":n="NegativeLookahead";break;case"<":{switch(this.popChar()){case"=":n="Lookbehind";break;case"!":n="NegativeLookbehind"}break}}Xe(n);let r=this.disjunction();return this.consumeChar(")"),{type:n,value:r,loc:this.loc(e)}}return kt()}quantifier(e=!1){let n,r=this.idx;switch(this.popChar()){case"*":n={atLeast:0,atMost:1/0};break;case"+":n={atLeast:1,atMost:1/0};break;case"?":n={atLeast:0,atMost:1};break;case"{":let i=this.integerIncludingZero();switch(this.popChar()){case"}":n={atLeast:i,atMost:i};break;case",":let o;this.isDigit()?(o=this.integerIncludingZero(),n={atLeast:i,atMost:o}):n={atLeast:i,atMost:1/0},this.consumeChar("}");break}if(e===!0&&n===void 0)return;Xe(n);break}if(!(e===!0&&n===void 0)&&Xe(n))return this.peekChar(0)==="?"?(this.consumeChar("?"),n.greedy=!1):n.greedy=!0,n.type="Quantifier",n.loc=this.loc(r),n}atom(){let e,n=this.idx;switch(this.peekChar()){case".":e=this.dotAll();break;case"\\":e=this.atomEscape();break;case"[":e=this.characterClass();break;case"(":e=this.group();break}return e===void 0&&this.isPatternCharacter()&&(e=this.patternCharacter()),Xe(e)?(e.loc=this.loc(n),this.isQuantifier()&&(e.quantifier=this.quantifier()),e):kt()}dotAll(){return this.consumeChar("."),{type:"Set",complement:!0,value:[b(`
6
+ `),b("\r"),b("\u2028"),b("\u2029")]}}atomEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}decimalEscapeAtom(){return{type:"GroupBackReference",value:this.positiveInteger()}}characterClassEscape(){let e,n=!1;switch(this.popChar()){case"d":e=Nt;break;case"D":e=Nt,n=!0;break;case"s":e=pr;break;case"S":e=pr,n=!0;break;case"w":e=Mt;break;case"W":e=Mt,n=!0;break}return Xe(e)?{type:"Set",value:e,complement:n}:kt()}controlEscapeAtom(){let e;switch(this.popChar()){case"f":e=b("\f");break;case"n":e=b(`
7
+ `);break;case"r":e=b("\r");break;case"t":e=b(" ");break;case"v":e=b("\v");break}return Xe(e)?{type:"Character",value:e}:kt()}controlLetterEscapeAtom(){this.consumeChar("c");let e=this.popChar();if(/[a-zA-Z]/.test(e)===!1)throw Error("Invalid ");return{type:"Character",value:e.toUpperCase().charCodeAt(0)-64}}nulCharacterAtom(){return this.consumeChar("0"),{type:"Character",value:b("\0")}}hexEscapeSequenceAtom(){return this.consumeChar("x"),this.parseHexDigits(2)}regExpUnicodeEscapeSequenceAtom(){return this.consumeChar("u"),this.parseHexDigits(4)}identityEscapeAtom(){let e=this.popChar();return{type:"Character",value:b(e)}}classPatternCharacterAtom(){switch(this.peekChar()){case`
8
+ `:case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:let e=this.popChar();return{type:"Character",value:b(e)}}}characterClass(){let e=[],n=!1;for(this.consumeChar("["),this.peekChar(0)==="^"&&(this.consumeChar("^"),n=!0);this.isClassAtom();){let r=this.classAtom(),i=r.type==="Character";if(fr(r)&&this.isRangeDash()){this.consumeChar("-");let o=this.classAtom(),a=o.type==="Character";if(fr(o)){if(o.value<r.value)throw Error("Range out of order in character class");e.push({from:r.value,to:o.value})}else sn(r.value,e),e.push(b("-")),sn(o.value,e)}else sn(r.value,e)}return this.consumeChar("]"),{type:"Set",complement:n,value:e}}classAtom(){switch(this.peekChar()){case"]":case`
9
+ `:case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}}classEscape(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:b("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}}group(){let e=!0;this.consumeChar("("),this.peekChar(0)==="?"?(this.consumeChar("?"),this.consumeChar(":"),e=!1):this.groupIdx++;let n=this.disjunction();this.consumeChar(")");let r={type:"Group",capturing:e,value:n};return e&&(r.idx=this.groupIdx),r}positiveInteger(){let e=this.popChar();if(Ta.test(e)===!1)throw Error("Expecting a positive integer");for(;an.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}integerIncludingZero(){let e=this.popChar();if(an.test(e)===!1)throw Error("Expecting an integer");for(;an.test(this.peekChar(0));)e+=this.popChar();return parseInt(e,10)}patternCharacter(){let e=this.popChar();switch(e){case`
10
+ `:case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:b(e)}}}isRegExpFlag(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}}isRangeDash(){return this.peekChar()==="-"&&this.isClassAtom(1)}isDigit(){return an.test(this.peekChar(0))}isClassAtom(e=0){switch(this.peekChar(e)){case"]":case`
11
+ `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}isTerm(){return this.isAtom()||this.isAssertion()}isAtom(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}}isAssertion(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return this.peekChar(1)==="?"&&(this.peekChar(2)==="="||this.peekChar(2)==="!"||this.peekChar(2)==="<"&&(this.peekChar(3)==="="||this.peekChar(3)==="!"));default:return!1}}isQuantifier(){let e=this.saveState();try{return this.quantifier(!0)!==void 0}catch{return!1}finally{this.restoreState(e)}}isPatternCharacter(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case`
12
+ `:case"\r":case"\u2028":case"\u2029":return!1;default:return!0}}parseHexDigits(e){let n="";for(let i=0;i<e;i++){let o=this.popChar();if(Aa.test(o)===!1)throw Error("Expecting a HexDecimal digits");n+=o}return{type:"Character",value:parseInt(n,16)}}peekChar(e=0){return this.input[this.idx+e]}popChar(){let e=this.peekChar(0);return this.consumeChar(void 0),e}consumeChar(e){if(e!==void 0&&this.input[this.idx]!==e)throw Error("Expected: '"+e+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++}loc(e){return{begin:e,end:this.idx}}};var Be=class{visitChildren(e){for(let n in e){let r=e[n];e.hasOwnProperty(n)&&(r.type!==void 0?this.visit(r):Array.isArray(r)&&r.forEach(i=>{this.visit(i)},this))}}visit(e){switch(e.type){case"Pattern":this.visitPattern(e);break;case"Flags":this.visitFlags(e);break;case"Disjunction":this.visitDisjunction(e);break;case"Alternative":this.visitAlternative(e);break;case"StartAnchor":this.visitStartAnchor(e);break;case"EndAnchor":this.visitEndAnchor(e);break;case"WordBoundary":this.visitWordBoundary(e);break;case"NonWordBoundary":this.visitNonWordBoundary(e);break;case"Lookahead":this.visitLookahead(e);break;case"NegativeLookahead":this.visitNegativeLookahead(e);break;case"Lookbehind":this.visitLookbehind(e);break;case"NegativeLookbehind":this.visitNegativeLookbehind(e);break;case"Character":this.visitCharacter(e);break;case"Set":this.visitSet(e);break;case"Group":this.visitGroup(e);break;case"GroupBackReference":this.visitGroupBackReference(e);break;case"Quantifier":this.visitQuantifier(e);break}this.visitChildren(e)}visitPattern(e){}visitFlags(e){}visitDisjunction(e){}visitAlternative(e){}visitStartAnchor(e){}visitEndAnchor(e){}visitWordBoundary(e){}visitNonWordBoundary(e){}visitLookahead(e){}visitNegativeLookahead(e){}visitLookbehind(e){}visitNegativeLookbehind(e){}visitCharacter(e){}visitSet(e){}visitGroup(e){}visitGroupBackReference(e){}visitQuantifier(e){}};var cn={},Sa=new Lt;function Ye(t){let e=t.toString();if(cn.hasOwnProperty(e))return cn[e];{let n=Sa.pattern(e);return cn[e]=n,n}}function Si(){cn={}}var Ii="Complement Sets are not supported for first char optimization",vt=`Unable to use "first char" lexer optimizations:
13
+ `;function Oi(t,e=!1){try{let n=Ye(t);return mr(n.value,{},n.flags.ignoreCase)}catch(n){if(n.message===Ii)e&&Rt(`${vt} Unable to optimize: < ${t.toString()} >
14
+ Complement Sets cannot be automatically optimized.
15
+ This will disable the lexer's first char optimizations.
16
+ See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#COMPLEMENT for details.`);else{let r="";e&&(r=`
17
+ This will disable the lexer's first char optimizations.
18
+ See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#REGEXP_PARSING for details.`),ot(`${vt}
19
+ Failed parsing: < ${t.toString()} >
20
+ Using the @chevrotain/regexp-to-ast library
21
+ Please open an issue at: https://github.com/chevrotain/chevrotain/issues`+r)}}return[]}function mr(t,e,n){switch(t.type){case"Disjunction":for(let i=0;i<t.value.length;i++)mr(t.value[i],e,n);break;case"Alternative":let r=t.value;for(let i=0;i<r.length;i++){let o=r[i];switch(o.type){case"EndAnchor":case"GroupBackReference":case"Lookahead":case"NegativeLookahead":case"Lookbehind":case"NegativeLookbehind":case"StartAnchor":case"WordBoundary":case"NonWordBoundary":continue}let a=o;switch(a.type){case"Character":ln(a.value,e,n);break;case"Set":if(a.complement===!0)throw Error(Ii);a.value.forEach(c=>{if(typeof c=="number")ln(c,e,n);else{let l=c;if(n===!0)for(let u=l.from;u<=l.to;u++)ln(u,e,n);else{for(let u=l.from;u<=l.to&&u<ct;u++)ln(u,e,n);if(l.to>=ct){let u=l.from>=ct?l.from:ct,h=l.to,f=Ne(u),d=Ne(h);for(let p=f;p<=d;p++)e[p]=p}}}});break;case"Group":mr(a.value,e,n);break;default:throw Error("Non Exhaustive Match")}let s=a.quantifier!==void 0&&a.quantifier.atLeast===0;if(a.type==="Group"&&gr(a)===!1||a.type!=="Group"&&s===!1)break}break;default:throw Error("non exhaustive match!")}return Object.values(e)}function ln(t,e,n){let r=Ne(t);e[r]=r,n===!0&&Ra(t,e)}function Ra(t,e){let n=String.fromCharCode(t),r=n.toUpperCase();if(r!==n){let i=Ne(r.charCodeAt(0));e[i]=i}else{let i=n.toLowerCase();if(i!==n){let o=Ne(i.charCodeAt(0));e[o]=o}}}function Ri(t,e){return t.value.find(n=>{if(typeof n=="number")return e.includes(n);{let r=n;return e.find(i=>r.from<=i&&i<=r.to)!==void 0}})}function gr(t){let e=t.quantifier;return e&&e.atLeast===0?!0:t.value?Array.isArray(t.value)?t.value.every(gr):gr(t.value):!1}var Er=class extends Be{constructor(e){super(),this.targetCharCodes=e,this.found=!1}visitChildren(e){if(this.found!==!0){switch(e.type){case"Lookahead":this.visitLookahead(e);return;case"NegativeLookahead":this.visitNegativeLookahead(e);return;case"Lookbehind":this.visitLookbehind(e);return;case"NegativeLookbehind":this.visitNegativeLookbehind(e);return}super.visitChildren(e)}}visitCharacter(e){this.targetCharCodes.includes(e.value)&&(this.found=!0)}visitSet(e){e.complement?Ri(e,this.targetCharCodes)===void 0&&(this.found=!0):Ri(e,this.targetCharCodes)!==void 0&&(this.found=!0)}};function hn(t,e){if(e instanceof RegExp){let n=Ye(e),r=new Er(t);return r.visit(n),r.found}else{for(let n of e){let r=n.charCodeAt(0);if(t.includes(r))return!0}return!1}}var Ze="PATTERN",lt="defaultMode",un="modes",fn=0,wt=1,pn=2,mn=3;function Ni(t,e){e=Object.assign({safeMode:!1,positionTracking:"full",lineTerminatorCharacters:["\r",`
22
+ `],tracer:(A,E)=>E()},e);let n=e.tracer;n("initCharCodeToOptimizedIndexMap",()=>{Va()});let r;n("Reject Lexer.NA",()=>{r=t.filter(A=>A[Ze]!==K.NA)});let i=!1,o;n("Transform Patterns",()=>{i=!1,o=r.map(A=>{let E=A[Ze];if(E instanceof RegExp){let x=E.source;return x.length===1&&x!=="^"&&x!=="$"&&x!=="."&&!E.ignoreCase?x:x.length===2&&x[0]==="\\"&&!["d","D","s","S","t","r","n","t","0","c","b","B","f","v","w","W"].includes(x[1])?x[1]:ki(E)}else{if(typeof E=="function")return i=!0,{exec:E};if(typeof E=="object")return i=!0,E;if(typeof E=="string"){if(E.length===1)return E;{let x=E.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&"),S=new RegExp(x);return ki(S)}}else throw Error("non exhaustive match")}})});let a,s,c,l,u;n("misc mapping",()=>{a=r.map(A=>A.tokenTypeIdx),s=r.map(A=>{let E=A.GROUP;if(E!==K.SKIPPED){if(typeof E=="string")return E;if(E===void 0)return!1;throw Error("non exhaustive match")}}),c=r.map(A=>{let E=A.LONGER_ALT;if(E)return Array.isArray(E)?E.map(S=>r.indexOf(S)):[r.indexOf(E)]}),l=r.map(A=>A.PUSH_MODE),u=r.map(A=>Object.hasOwn(A,"POP_MODE"))});let h;n("Line Terminator Handling",()=>{let A=_i(e.lineTerminatorCharacters);h=r.map(E=>!1),e.positionTracking!=="onlyOffset"&&(h=r.map(E=>Object.hasOwn(E,"LINE_BREAKS")?!!E.LINE_BREAKS:Ci(E,A)===!1&&hn(A,E.PATTERN)))});let f,d,p,m;n("Misc Mapping #2",()=>{f=r.map(wi),d=o.map(Ha),p=r.reduce((A,E)=>{let x=E.GROUP;return typeof x=="string"&&x!==K.SKIPPED&&(A[x]=[]),A},{}),m=o.map((A,E)=>{let x=s[E]===void 0&&c[E]===void 0?Ia(r[E].PATTERN):void 0;return{pattern:o[E],asciiClass:x,longerAlt:c[E],canLineTerminator:h[E],matchType:x!==void 0?mn:d[E]!==!1?fn:f[E]?wt:pn,short:d[E],group:s[E],push:l[E],pop:u[E],tokenTypeIdx:a[E],tokenType:r[E]}})});let y=!0,g=[];return e.safeMode||n("First Char Optimization",()=>{g=r.reduce((A,E,x)=>{if(typeof E.PATTERN=="string"){let S=E.PATTERN.charCodeAt(0),I=Ne(S);yr(A,I,m[x])}else if(Array.isArray(E.START_CHARS_HINT)){let S;E.START_CHARS_HINT.forEach(I=>{let M=typeof I=="string"?I.charCodeAt(0):I,L=Ne(M);S!==L&&(S=L,yr(A,L,m[x]))})}else if(E.PATTERN instanceof RegExp)if(E.PATTERN.unicode)y=!1,e.ensureOptimizations&&ot(`${vt} Unable to analyze < ${E.PATTERN.toString()} > pattern.
23
+ The regexp unicode flag is not currently supported by the regexp-to-ast library.
24
+ This will disable the lexer's first char optimizations.
25
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNICODE_OPTIMIZE`);else{let S=Oi(E.PATTERN,e.ensureOptimizations);S.length===0&&(y=!1),S.forEach(I=>{yr(A,I,m[x])})}else e.ensureOptimizations&&ot(`${vt} TokenType: <${E.name}> is using a custom token pattern without providing <start_chars_hint> parameter.
26
+ This will disable the lexer's first char optimizations.
27
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_OPTIMIZE`),y=!1;return A},[])}),{emptyGroups:p,patternIdxToConfig:m,charCodeToPatternIdxToConfig:g,hasCustom:i,canBeOptimized:y}}function Ia(t){var e,n;if(!(t instanceof RegExp)||t.flags!=="")return;let r;try{r=Ye(t)}catch{return}if(r.value.value.length!==1||r.value.value[0].value.length!==1)return;let i=r.value.value[0].value[0],o;for(;i.type==="Group";){if(i.capturing||i.quantifier!==void 0&&o!==void 0||i.value.value.length!==1||i.value.value[0].value.length!==1)return;o=(e=i.quantifier)!==null&&e!==void 0?e:o,i=i.value.value[0].value[0]}if(i.type!=="Set"||i.complement||i.quantifier!==void 0&&o!==void 0||(o=(n=i.quantifier)!==null&&n!==void 0?n:o,o?.atLeast!==1||o.atMost!==1/0||!o.greedy))return;let a=new Uint8Array(128);for(let s of i.value){let c=typeof s=="number"?s:s.from,l=typeof s=="number"?s:s.to;if(c<0||l>=a.length)return;a.fill(1,c,l+1)}return a}function Mi(t,e){let n=[],r=ka(t);n=n.concat(r.errors);let i=Na(r.valid),o=i.valid;return n=n.concat(i.errors),n=n.concat(Oa(o)),n=n.concat(Pa(o)),n=n.concat(Ua(o,e)),n=n.concat(Fa(o)),n}function Oa(t){let e=[],n=t.filter(r=>r[Ze]instanceof RegExp);return e=e.concat(La(n)),e=e.concat(ba(n)),e=e.concat(Ca(n)),e=e.concat(_a(n)),e=e.concat(va(n)),e}function ka(t){let e=t.filter(i=>!Object.hasOwn(i,Ze)),n=e.map(i=>({message:"Token Type: ->"+i.name+"<- missing static 'PATTERN' property",type:j.MISSING_PATTERN,tokenTypes:[i]})),r=t.filter(i=>!e.includes(i));return{errors:n,valid:r}}function Na(t){let e=t.filter(i=>{let o=i[Ze];return!(o instanceof RegExp)&&typeof o!="function"&&!Object.hasOwn(o,"exec")&&typeof o!="string"}),n=e.map(i=>({message:"Token Type: ->"+i.name+"<- static 'PATTERN' can only be a RegExp, a Function matching the {CustomPatternMatcherFunc} type or an Object matching the {ICustomPattern} interface.",type:j.INVALID_PATTERN,tokenTypes:[i]})),r=t.filter(i=>!e.includes(i));return{errors:n,valid:r}}var Ma=/[^\\][$]/;function La(t){class e extends Be{constructor(){super(...arguments),this.found=!1}visitEndAnchor(o){this.found=!0}}return t.filter(i=>{let o=i.PATTERN;try{let a=Ye(o),s=new e;return s.visit(a),s.found}catch{return Ma.test(o.source)}}).map(i=>({message:`Unexpected RegExp Anchor Error:
28
+ Token Type: ->`+i.name+`<- static 'PATTERN' cannot contain end of input anchor '$'
29
+ See chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:j.EOI_ANCHOR_FOUND,tokenTypes:[i]}))}function va(t){return t.filter(r=>r.PATTERN.test("")).map(r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' must not match an empty string",type:j.EMPTY_MATCH_PATTERN,tokenTypes:[r]}))}var wa=/[^\\[][\^]|^\^/;function ba(t){class e extends Be{constructor(){super(...arguments),this.found=!1}visitStartAnchor(o){this.found=!0}}return t.filter(i=>{let o=i.PATTERN;try{let a=Ye(o),s=new e;return s.visit(a),s.found}catch{return wa.test(o.source)}}).map(i=>({message:`Unexpected RegExp Anchor Error:
30
+ Token Type: ->`+i.name+`<- static 'PATTERN' cannot contain start of input anchor '^'
31
+ See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#ANCHORS for details.`,type:j.SOI_ANCHOR_FOUND,tokenTypes:[i]}))}function Ca(t){return t.filter(r=>{let i=r[Ze];return i instanceof RegExp&&(i.multiline||i.global)}).map(r=>({message:"Token Type: ->"+r.name+"<- static 'PATTERN' may NOT contain global('g') or multiline('m')",type:j.UNSUPPORTED_FLAGS_FOUND,tokenTypes:[r]}))}function _a(t){let e=[],n=t.map(o=>t.reduce((a,s)=>(o.PATTERN.source===s.PATTERN.source&&!e.includes(s)&&s.PATTERN!==K.NA&&(e.push(s),a.push(s)),a),[]));return n=n.filter(Boolean),n.filter(o=>o.length>1).map(o=>{let a=o.map(c=>c.name);return{message:`The same RegExp pattern ->${o[0].PATTERN}<-has been used in all of the following Token Types: ${a.join(", ")} <-`,type:j.DUPLICATE_PATTERNS_FOUND,tokenTypes:o}})}function Pa(t){return t.filter(r=>{if(!Object.hasOwn(r,"GROUP"))return!1;let i=r.GROUP;return i!==K.SKIPPED&&i!==K.NA&&typeof i!="string"}).map(r=>({message:"Token Type: ->"+r.name+"<- static 'GROUP' can only be Lexer.SKIPPED/Lexer.NA/A String",type:j.INVALID_GROUP_TYPE_FOUND,tokenTypes:[r]}))}function Ua(t,e){return t.filter(i=>i.PUSH_MODE!==void 0&&!e.includes(i.PUSH_MODE)).map(i=>({message:`Token Type: ->${i.name}<- static 'PUSH_MODE' value cannot refer to a Lexer Mode ->${i.PUSH_MODE}<-which does not exist`,type:j.PUSH_MODE_DOES_NOT_EXIST,tokenTypes:[i]}))}function Fa(t){let e=[],n=t.reduce((r,i,o)=>{let a=i.PATTERN;return a===K.NA||(typeof a=="string"?r.push({str:a,idx:o,tokenType:i}):a instanceof RegExp&&Ba(a)&&r.push({str:a.source,idx:o,tokenType:i})),r},[]);return t.forEach((r,i)=>{n.forEach(({str:o,idx:a,tokenType:s})=>{if(i<a&&Da(o,r.PATTERN)){let c=`Token: ->${s.name}<- can never be matched.
32
+ Because it appears AFTER the Token Type ->${r.name}<-in the lexer's definition.
33
+ See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#UNREACHABLE`;e.push({message:c,type:j.UNREACHABLE_PATTERN,tokenTypes:[r,s]})}})}),e}function Da(t,e){if(e instanceof RegExp){if($a(e))return!1;let n=e.exec(t);return n!==null&&n.index===0}else{if(typeof e=="function")return e(t,0,[],{});if(Object.hasOwn(e,"exec"))return e.exec(t,0,[],{});if(typeof e=="string")return e===t;throw Error("non exhaustive match")}}function Ba(t){return[".","\\","[","]","|","^","$","(",")","?","*","+","{"].find(n=>t.source.indexOf(n)!==-1)===void 0}function $a(t){return/(\(\?=)|(\(\?!)|(\(\?<=)|(\(\?<!)/.test(t.source)}function ki(t){let e=t.ignoreCase?"iy":"y";return new RegExp(`${t.source}`,e)}function Li(t,e,n){let r=[];return Object.hasOwn(t,lt)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+lt+`> property in its definition
34
+ `,type:j.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE}),Object.hasOwn(t,un)||r.push({message:"A MultiMode Lexer cannot be initialized without a <"+un+`> property in its definition
35
+ `,type:j.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY}),Object.hasOwn(t,un)&&Object.hasOwn(t,lt)&&!Object.hasOwn(t.modes,t.defaultMode)&&r.push({message:`A MultiMode Lexer cannot be initialized with a ${lt}: <${t.defaultMode}>which does not exist
36
+ `,type:j.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST}),Object.hasOwn(t,un)&&Object.keys(t.modes).forEach(i=>{let o=t.modes[i];o.forEach((a,s)=>{a===void 0?r.push({message:`A Lexer cannot be initialized using an undefined Token Type. Mode:<${i}> at index: <${s}>
37
+ `,type:j.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED}):Object.hasOwn(a,"LONGER_ALT")&&(Array.isArray(a.LONGER_ALT)?a.LONGER_ALT:[a.LONGER_ALT]).forEach(l=>{l!==void 0&&!o.includes(l)&&r.push({message:`A MultiMode Lexer cannot be initialized with a longer_alt <${l.name}> on token <${a.name}> outside of mode <${i}>
38
+ `,type:j.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE})})})}),r}function vi(t,e,n){let r=[],i=!1,a=Object.values(t.modes||{}).flat().filter(Boolean).filter(c=>c[Ze]!==K.NA),s=_i(n);return e&&a.forEach(c=>{let l=Ci(c,s);if(l!==!1){let h={message:Ga(c,l),type:l.issue,tokenType:c};r.push(h)}else Object.hasOwn(c,"LINE_BREAKS")?c.LINE_BREAKS===!0&&(i=!0):hn(s,c.PATTERN)&&(i=!0)}),e&&!i&&r.push({message:`Warning: No LINE_BREAKS Found.
39
+ This Lexer has been defined to track line and column information,
40
+ But none of the Token Types can be identified as matching a line terminator.
41
+ See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS
42
+ for details.`,type:j.NO_LINE_BREAKS_FLAGS}),r}function wi(t){let e=t.PATTERN;if(e instanceof RegExp)return!1;if(typeof e=="function")return!0;if(Object.hasOwn(e,"exec"))return!0;if(typeof e=="string")return!1;throw Error("non exhaustive match")}function Ha(t){return typeof t=="string"&&t.length===1?t.charCodeAt(0):!1}var bi={test:function(t){let e=t.length;for(let n=this.lastIndex;n<e;n++){let r=t.charCodeAt(n);if(r===10)return this.lastIndex=n+1,!0;if(r===13)return t.charCodeAt(n+1)===10?this.lastIndex=n+2:this.lastIndex=n+1,!0}return!1},lastIndex:0};function Ci(t,e){if(Object.hasOwn(t,"LINE_BREAKS"))return!1;if(t.PATTERN instanceof RegExp){try{hn(e,t.PATTERN)}catch(n){return{issue:j.IDENTIFY_TERMINATOR,errMsg:n.message}}return!1}else{if(typeof t.PATTERN=="string")return!1;if(wi(t))return{issue:j.CUSTOM_LINE_BREAK};throw Error("non exhaustive match")}}function Ga(t,e){if(e.issue===j.IDENTIFY_TERMINATOR)return`Warning: unable to identify line terminator usage in pattern.
43
+ The problem is in the <${t.name}> Token Type
44
+ Root cause: ${e.errMsg}.
45
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#IDENTIFY_TERMINATOR`;if(e.issue===j.CUSTOM_LINE_BREAK)return`Warning: A Custom Token Pattern should specify the <line_breaks> option.
46
+ The problem is in the <${t.name}> Token Type
47
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#CUSTOM_LINE_BREAK`;throw Error("non exhaustive match")}function _i(t){return t.map(n=>typeof n=="string"?n.charCodeAt(0):n)}function yr(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}var ct=256,dn=[];function Ne(t){return t<ct?t:dn[t]}function Va(){if(dn.length===0){dn=new Array(65536);for(let t=0;t<65536;t++)dn[t]=t>255?255+~~(t/255):t}}function be(t,e){let n=t.tokenTypeIdx;return n===e.tokenTypeIdx?!0:e.isParent===!0&&e.categoryMatchesMap[n]===!0}function ht(t,e){return t.tokenTypeIdx===e.tokenTypeIdx}var Pi=1,Fi={};function Ce(t){let e=ja(t);Wa(e),za(e),Ka(e),e.forEach(n=>{n.isParent=n.categoryMatches.length>0})}function ja(t){let e=[...t],n=t,r=!0;for(;r;){n=n.map(o=>o.CATEGORIES).flat().filter(Boolean);let i=n.filter(o=>!e.includes(o));e=e.concat(i),i.length===0?r=!1:n=i}return e}function Wa(t){t.forEach(e=>{xr(e)||(Fi[Pi]=e,e.tokenTypeIdx=Pi++),Ui(e)&&!Array.isArray(e.CATEGORIES)&&(e.CATEGORIES=[e.CATEGORIES]),Ui(e)||(e.CATEGORIES=[]),Xa(e)||(e.categoryMatches=[]),Ya(e)||(e.categoryMatchesMap={})})}function Ka(t){t.forEach(e=>{e.categoryMatches=[],Object.keys(e.categoryMatchesMap).forEach(n=>{e.categoryMatches.push(Fi[n].tokenTypeIdx)})})}function za(t){t.forEach(e=>{Di([],e)})}function Di(t,e){t.forEach(n=>{e.categoryMatchesMap[n.tokenTypeIdx]=!0}),e.CATEGORIES.forEach(n=>{let r=t.concat(e);r.includes(n)||Di(r,n)})}function xr(t){return Object.hasOwn(t??{},"tokenTypeIdx")}function Ui(t){return Object.hasOwn(t??{},"CATEGORIES")}function Xa(t){return Object.hasOwn(t??{},"categoryMatches")}function Ya(t){return Object.hasOwn(t??{},"categoryMatchesMap")}function Bi(t){return Object.hasOwn(t??{},"tokenTypeIdx")}var Ar={buildUnableToPopLexerModeMessage(t){return`Unable to pop Lexer Mode after encountering Token ->${t.image}<- The Mode Stack is empty`},buildUnexpectedCharactersMessage(t,e,n,r,i,o){return`unexpected character: ->${t.charAt(e)}<- at offset: ${e}, skipped ${n} characters.`}};var j;(function(t){t[t.MISSING_PATTERN=0]="MISSING_PATTERN",t[t.INVALID_PATTERN=1]="INVALID_PATTERN",t[t.EOI_ANCHOR_FOUND=2]="EOI_ANCHOR_FOUND",t[t.UNSUPPORTED_FLAGS_FOUND=3]="UNSUPPORTED_FLAGS_FOUND",t[t.DUPLICATE_PATTERNS_FOUND=4]="DUPLICATE_PATTERNS_FOUND",t[t.INVALID_GROUP_TYPE_FOUND=5]="INVALID_GROUP_TYPE_FOUND",t[t.PUSH_MODE_DOES_NOT_EXIST=6]="PUSH_MODE_DOES_NOT_EXIST",t[t.MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE=7]="MULTI_MODE_LEXER_WITHOUT_DEFAULT_MODE",t[t.MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY=8]="MULTI_MODE_LEXER_WITHOUT_MODES_PROPERTY",t[t.MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST=9]="MULTI_MODE_LEXER_DEFAULT_MODE_VALUE_DOES_NOT_EXIST",t[t.LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED=10]="LEXER_DEFINITION_CANNOT_CONTAIN_UNDEFINED",t[t.SOI_ANCHOR_FOUND=11]="SOI_ANCHOR_FOUND",t[t.EMPTY_MATCH_PATTERN=12]="EMPTY_MATCH_PATTERN",t[t.NO_LINE_BREAKS_FLAGS=13]="NO_LINE_BREAKS_FLAGS",t[t.UNREACHABLE_PATTERN=14]="UNREACHABLE_PATTERN",t[t.IDENTIFY_TERMINATOR=15]="IDENTIFY_TERMINATOR",t[t.CUSTOM_LINE_BREAK=16]="CUSTOM_LINE_BREAK",t[t.MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE=17]="MULTI_MODE_LEXER_LONGER_ALT_NOT_IN_CURRENT_MODE"})(j||(j={}));var bt={deferDefinitionErrorsHandling:!1,positionTracking:"full",lineTerminatorsPattern:/\n|\r\n?/g,lineTerminatorCharacters:[`
48
+ `,"\r"],ensureOptimizations:!1,safeMode:!1,errorMessageProvider:Ar,traceInitPerf:!1,skipValidations:!1,recoveryEnabled:!0};Object.freeze(bt);var K=class{constructor(e,n=bt){if(this.lexerDefinition=e,this.lexerDefinitionErrors=[],this.lexerDefinitionWarning=[],this.patternIdxToConfig={},this.charCodeToPatternIdxToConfig={},this.modes=[],this.emptyGroups={},this.cachedGroupKeys=[],this.trackStartLines=!0,this.trackEndLines=!0,this.hasCustom=!1,this.canModeBeOptimized={},this.TRACE_INIT=(i,o)=>{if(this.traceInitPerf===!0){this.traceInitIndent++;let a=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${a}--> <${i}>`);let{time:s,value:c}=It(o),l=s>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&l(`${a}<-- <${i}> time: ${s}ms`),this.traceInitIndent--,c}else return o()},typeof n=="boolean")throw Error(`The second argument to the Lexer constructor is now an ILexerConfig Object.
49
+ a boolean 2nd argument is no longer supported`);this.config=Object.assign({},bt,n);let r=this.config.traceInitPerf;r===!0?(this.traceInitMaxIdent=1/0,this.traceInitPerf=!0):typeof r=="number"&&(this.traceInitMaxIdent=r,this.traceInitPerf=!0),this.traceInitIndent=-1,this.TRACE_INIT("Lexer Constructor",()=>{let i,o=!0;this.TRACE_INIT("Lexer Config handling",()=>{if(this.config.lineTerminatorsPattern===bt.lineTerminatorsPattern)this.config.lineTerminatorsPattern=bi;else if(this.config.lineTerminatorCharacters===bt.lineTerminatorCharacters)throw Error(`Error: Missing <lineTerminatorCharacters> property on the Lexer config.
50
+ For details See: https://chevrotain.io/docs/guide/resolving_lexer_errors.html#MISSING_LINE_TERM_CHARS`);if(n.safeMode&&n.ensureOptimizations)throw Error('"safeMode" and "ensureOptimizations" flags are mutually exclusive.');this.trackStartLines=/full|onlyStart/i.test(this.config.positionTracking),this.trackEndLines=/full/i.test(this.config.positionTracking),Array.isArray(e)?i={modes:{defaultMode:[...e]},defaultMode:lt}:(o=!1,i=Object.assign({},e))}),this.config.skipValidations===!1&&(this.TRACE_INIT("performRuntimeChecks",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Li(i,this.trackStartLines,this.config.lineTerminatorCharacters))}),this.TRACE_INIT("performWarningRuntimeChecks",()=>{this.lexerDefinitionWarning=this.lexerDefinitionWarning.concat(vi(i,this.trackStartLines,this.config.lineTerminatorCharacters))})),i.modes=i.modes?i.modes:{},Object.entries(i.modes).forEach(([s,c])=>{i.modes[s]=c.filter(l=>l!==void 0)});let a=Object.keys(i.modes);if(Object.entries(i.modes).forEach(([s,c])=>{this.TRACE_INIT(`Mode: <${s}> processing`,()=>{if(this.modes.push(s),this.config.skipValidations===!1&&this.TRACE_INIT("validatePatterns",()=>{this.lexerDefinitionErrors=this.lexerDefinitionErrors.concat(Mi(c,a))}),this.lexerDefinitionErrors.length===0){Ce(c);let l;this.TRACE_INIT("analyzeTokenTypes",()=>{l=Ni(c,{lineTerminatorCharacters:this.config.lineTerminatorCharacters,positionTracking:n.positionTracking,ensureOptimizations:n.ensureOptimizations,safeMode:n.safeMode,tracer:this.TRACE_INIT})}),this.patternIdxToConfig[s]=l.patternIdxToConfig,this.charCodeToPatternIdxToConfig[s]=l.charCodeToPatternIdxToConfig,this.emptyGroups=Object.assign({},this.emptyGroups,l.emptyGroups),this.hasCustom=l.hasCustom||this.hasCustom,this.canModeBeOptimized[s]=l.canBeOptimized}})}),this.defaultMode=i.defaultMode,this.cachedGroupKeys=Object.keys(this.emptyGroups),this.lexerDefinitionErrors.length>0&&!this.config.deferDefinitionErrorsHandling){let c=this.lexerDefinitionErrors.map(l=>l.message).join(`-----------------------
51
+ `);throw new Error(`Errors detected in definition of Lexer:
52
+ `+c)}this.lexerDefinitionWarning.forEach(s=>{Rt(s.message)}),this.TRACE_INIT("Choosing sub-methods implementations",()=>{if(o&&(this.handleModes=()=>{}),this.trackStartLines===!1&&(this.computeNewColumn=s=>s),this.trackEndLines===!1&&(this.updateTokenEndLineColumnLocation=()=>{}),/full/i.test(this.config.positionTracking))this.createTokenInstance=this.createFullToken;else if(/onlyStart/i.test(this.config.positionTracking))this.createTokenInstance=this.createStartOnlyToken;else if(/onlyOffset/i.test(this.config.positionTracking))this.createTokenInstance=this.createOffsetOnlyToken;else throw Error(`Invalid <positionTracking> config option: "${this.config.positionTracking}"`);this.hasCustom?(this.addToken=this.addTokenUsingPush,this.handlePayload=this.handlePayloadWithCustom):(this.addToken=this.addTokenUsingMemberAccess,this.handlePayload=this.handlePayloadNoCustom)}),this.TRACE_INIT("Failed Optimization Warnings",()=>{let s=Object.entries(this.canModeBeOptimized).reduce((c,[l,u])=>(u===!1&&c.push(l),c),[]);if(n.ensureOptimizations&&s.length>0)throw Error(`Lexer Modes: < ${s.join(", ")} > cannot be optimized.
53
+ Disable the "ensureOptimizations" lexer config flag to silently ignore this and run the lexer in an un-optimized mode.
54
+ Or inspect the console log for details on how to resolve these issues.`)}),this.TRACE_INIT("clearRegExpParserCache",()=>{Si()}),this.TRACE_INIT("toFastProperties",()=>{Ot(this)})})}tokenize(e,n=this.defaultMode){if(this.lexerDefinitionErrors.length>0){let i=this.lexerDefinitionErrors.map(o=>o.message).join(`-----------------------
55
+ `);throw new Error(`Unable to Tokenize because Errors detected in definition of Lexer:
56
+ `+i)}return this.tokenizeInternal(e,n)}tokenizeInternal(e,n){let r,i,o,a,s,c,l,u,h,f,d,p,m,y,g,A=e,E=A.length,x=0,S=0,I=this.hasCustom?0:Math.floor(e.length/10),M=new Array(I),L=[],O=this.trackStartLines?1:void 0,T=this.trackStartLines?1:void 0,R={};for(let _=0;_<this.cachedGroupKeys.length;_++)R[this.cachedGroupKeys[_]]=[];let k=this.trackStartLines,N=this.config.lineTerminatorsPattern,w=0,C=[],V=[],P=[],q=[];Object.freeze(q);let ie=!1,ye=_=>{if(P.length===1&&_.tokenType.PUSH_MODE===void 0){let ne=this.config.errorMessageProvider.buildUnableToPopLexerModeMessage(_);L.push({offset:_.startOffset,line:_.startLine,column:_.startColumn,length:_.image.length,message:ne})}else{P.pop();let ne=P.at(-1);C=this.patternIdxToConfig[ne],V=this.charCodeToPatternIdxToConfig[ne],w=C.length;let We=this.canModeBeOptimized[ne]&&this.config.safeMode===!1;V&&We?ie=!0:ie=!1}};function Ie(_){P.push(_),V=this.charCodeToPatternIdxToConfig[_],C=this.patternIdxToConfig[_],w=C.length;let ne=this.canModeBeOptimized[_]&&this.config.safeMode===!1;V&&ne?ie=!0:ie=!1}Ie.call(this,n);let te,je=this.config.recoveryEnabled;for(;x<E;){c=null,h=-1;let _=A.charCodeAt(x),ne;if(ie){let oe=Ne(_),pe=V[oe];ne=pe!==void 0?pe:q}else ne=C;let We=ne.length;for(r=0;r<We;r++){te=ne[r];let oe=te.pattern;switch(l=null,te.matchType){case fn:_===te.short&&(h=1,c=oe);break;case wt:g=oe.exec(A,x,M,R),g!==null?(c=g[0],h=c.length,g.payload!==void 0&&(l=g.payload)):c=null;break;case mn:{let pe=te.asciiClass;if(pe[_]!==1){oe.lastIndex=0;break}let ce=x+1;for(;pe[A.charCodeAt(ce)]===1;)ce++;h=ce-x,oe.lastIndex=ce;break}case pn:oe.lastIndex=x,h=this.matchLength(oe,e,x);break}if(h!==-1){if(s=te.longerAlt,s!==void 0){c=e.substring(x,x+h);let pe=s.length;for(o=0;o<pe;o++){let ce=C[s[o]],ve=ce.pattern;if(u=null,ce.matchType===wt?(g=ve.exec(A,x,M,R),g!==null?(a=g[0],g.payload!==void 0&&(u=g.payload)):a=null):(ve.lastIndex=x,a=this.match(ve,e,x)),a&&a.length>c.length){c=a,h=a.length,l=u,te=ce;break}}}break}}if(h!==-1){if(f=te.group,f!==void 0&&(c=c!==null?c:e.substring(x,x+h),d=te.tokenTypeIdx,p=this.createTokenInstance(c,x,d,te.tokenType,O,T,h),this.handlePayload(p,l),f===!1?S=this.addToken(M,S,p):R[f].push(p)),k===!0&&te.canLineTerminator===!0){let oe=0,pe,ce;N.lastIndex=0;do c=c!==null?c:e.substring(x,x+h),pe=N.test(c),pe===!0&&(ce=N.lastIndex-1,oe++);while(pe===!0);oe!==0?(O=O+oe,T=h-ce,this.updateTokenEndLineColumnLocation(p,f,ce,oe,O,T,h)):T=this.computeNewColumn(T,h)}else T=this.computeNewColumn(T,h);x=x+h,this.handleModes(te,ye,Ie,p)}else{let oe=x,pe=O,ce=T,ve=je===!1;for(;ve===!1&&x<E;)for(x++,i=0;i<w;i++){let ar=C[i],cr=ar.pattern;switch(ar.matchType){case fn:A.charCodeAt(x)===ar.short&&(ve=!0);break;case wt:ve=cr.exec(A,x,M,R)!==null;break;case mn:case pn:cr.lastIndex=x,ve=cr.exec(e)!==null;break}if(ve===!0)break}if(m=x-oe,T=this.computeNewColumn(T,m),y=this.config.errorMessageProvider.buildUnexpectedCharactersMessage(A,oe,m,pe,ce,P.at(-1)),L.push({offset:oe,line:pe,column:ce,length:m,message:y}),je===!1)break}}return this.hasCustom||(M.length=S),{tokens:M,groups:R,errors:L}}handleModes(e,n,r,i){if(e.pop===!0){let o=e.push;n(i),o!==void 0&&r.call(this,o)}else e.push!==void 0&&r.call(this,e.push)}updateTokenEndLineColumnLocation(e,n,r,i,o,a,s){let c,l;n!==void 0&&(c=r===s-1,l=c?-1:0,i===1&&c===!0||(e.endLine=o+l,e.endColumn=a-1+-l))}computeNewColumn(e,n){return e+n}createOffsetOnlyToken(e,n,r,i){return{image:e,startOffset:n,tokenTypeIdx:r,tokenType:i}}createStartOnlyToken(e,n,r,i,o,a){return{image:e,startOffset:n,startLine:o,startColumn:a,tokenTypeIdx:r,tokenType:i}}createFullToken(e,n,r,i,o,a,s){return{image:e,startOffset:n,endOffset:n+s-1,startLine:o,endLine:o,startColumn:a,endColumn:a+s-1,tokenTypeIdx:r,tokenType:i}}addTokenUsingPush(e,n,r){return e.push(r),n}addTokenUsingMemberAccess(e,n,r){return e[n]=r,n++,n}handlePayloadNoCustom(e,n){}handlePayloadWithCustom(e,n){n!==null&&(e.payload=n)}match(e,n,r){return e.test(n)===!0?n.substring(r,e.lastIndex):null}matchLength(e,n,r){return e.test(n)===!0?e.lastIndex-r:-1}};K.SKIPPED="This marks a skipped Token pattern, this means each token identified by it will be consumed and then thrown into oblivion, this can be used to for example to completely ignore whitespace.";K.NA=/NOT_APPLICABLE/;function qe(t){return Tr(t)?t.LABEL:t.name}function Tr(t){return typeof t.LABEL=="string"&&t.LABEL!==""}var Za="parent",$i="categories",Hi="label",Gi="group",Vi="push_mode",ji="pop_mode",Wi="longer_alt",Ki="line_breaks",zi="start_chars_hint";function ee(t){return qa(t)}function qa(t){let e=t.pattern,n={};if(n.name=t.name,e!==void 0&&(n.PATTERN=e),Object.hasOwn(t,Za))throw`The parent property is no longer supported.
57
+ See: https://github.com/chevrotain/chevrotain/issues/564#issuecomment-349062346 for details.`;return Object.hasOwn(t,$i)&&(n.CATEGORIES=t[$i]),Ce([n]),Object.hasOwn(t,Hi)&&(n.LABEL=t[Hi]),Object.hasOwn(t,Gi)&&(n.GROUP=t[Gi]),Object.hasOwn(t,ji)&&(n.POP_MODE=t[ji]),Object.hasOwn(t,Vi)&&(n.PUSH_MODE=t[Vi]),Object.hasOwn(t,Wi)&&(n.LONGER_ALT=t[Wi]),Object.hasOwn(t,Ki)&&(n.LINE_BREAKS=t[Ki]),Object.hasOwn(t,zi)&&(n.START_CHARS_HINT=t[zi]),n}var Ae=ee({name:"EOF",pattern:K.NA});Ce([Ae]);function Qe(t,e,n,r,i,o,a,s){return{image:e,startOffset:n,endOffset:r,startLine:i,endLine:o,startColumn:a,endColumn:s,tokenTypeIdx:t.tokenTypeIdx,tokenType:t}}function Sr(t,e){return be(t,e)}var Je={buildMismatchTokenMessage({expected:t,actual:e,previous:n,ruleName:r}){return`Expecting ${Tr(t)?`--> ${qe(t)} <--`:`token of type --> ${t.name} <--`} but found --> '${e.image}' <--`},buildNotAllInputParsedMessage({firstRedundant:t,ruleName:e}){return"Redundant input, expecting EOF but found: "+t.image},buildNoViableAltMessage({expectedPathsPerAlt:t,actual:e,previous:n,customUserDescription:r,ruleName:i}){let o="Expecting: ",s=`
58
+ but found: '`+e[0].image+"'";if(r)return o+r+s;{let h=`one of these possible Token sequences:
59
+ ${t.reduce((f,d)=>f.concat(d),[]).map(f=>`[${f.map(d=>qe(d)).join(", ")}]`).map((f,d)=>` ${d+1}. ${f}`).join(`
60
+ `)}`;return o+h+s}},buildEarlyExitMessage({expectedIterationPaths:t,actual:e,customUserDescription:n,ruleName:r}){let i="Expecting: ",a=`
61
+ but found: '`+e[0].image+"'";if(n)return i+n+a;{let c=`expecting at least one iteration which starts with one of these possible Token sequences::
62
+ <${t.map(l=>`[${l.map(u=>qe(u)).join(",")}]`).join(" ,")}>`;return i+c+a}}};Object.freeze(Je);var Xi={buildRuleNotFoundError(t,e){return"Invalid grammar, reference to a rule which is not defined: ->"+e.nonTerminalName+`<-
63
+ inside top level rule: ->`+t.name+"<-"}},Oe={buildDuplicateFoundError(t,e){function n(u){return u instanceof U?u.terminalType.name:u instanceof $?u.nonTerminalName:""}let r=t.name,i=e[0],o=i.idx,a=me(i),s=n(i),c=o>0,l=`->${a}${c?o:""}<- ${s?`with argument: ->${s}<-`:""}
64
+ appears more than once (${e.length} times) in the top level rule: ->${r}<-.
65
+ For further details see: https://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES
66
+ `;return l=l.replace(/[ \t]+/g," "),l=l.replace(/\s\s+/g,`
67
+ `),l},buildNamespaceConflictError(t){return`Namespace conflict found in grammar.
68
+ The grammar has both a Terminal(Token) and a Non-Terminal(Rule) named: <${t.name}>.
69
+ To resolve this make sure each Terminal and Non-Terminal names are unique
70
+ This is easy to accomplish by using the convention that Terminal names start with an uppercase letter
71
+ and Non-Terminal names start with a lower case letter.`},buildAlternationPrefixAmbiguityError(t){let e=t.prefixPath.map(i=>qe(i)).join(", "),n=t.alternation.idx===0?"":t.alternation.idx;return`Ambiguous alternatives: <${t.ambiguityIndices.join(" ,")}> due to common lookahead prefix
72
+ in <OR${n}> inside <${t.topLevelRule.name}> Rule,
73
+ <${e}> may appears as a prefix path in all these alternatives.
74
+ See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#COMMON_PREFIX
75
+ For Further details.`},buildAlternationAmbiguityError(t){let e=t.alternation.idx===0?"":t.alternation.idx,n=t.prefixPath.length===0,r=`Ambiguous Alternatives Detected: <${t.ambiguityIndices.join(" ,")}> in <OR${e}> inside <${t.topLevelRule.name}> Rule,
76
+ `;if(n)r+=`These alternatives are all empty (match no tokens), making them indistinguishable.
77
+ Only the last alternative may be empty.
78
+ `;else{let i=t.prefixPath.map(o=>qe(o)).join(", ");r+=`<${i}> may appears as a prefix path in all these alternatives.
79
+ `}return r+=`See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES
80
+ For Further details.`,r},buildEmptyRepetitionError(t){let e=me(t.repetition);return t.repetition.idx!==0&&(e+=t.repetition.idx),`The repetition <${e}> within Rule <${t.topLevelRule.name}> can never consume any tokens.
81
+ This could lead to an infinite loop.`},buildTokenNameError(t){return"deprecated"},buildEmptyAlternationError(t){return`Ambiguous empty alternative: <${t.emptyChoiceIdx+1}> in <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
82
+ Only the last alternative may be an empty alternative.`},buildTooManyAlternativesError(t){return`An Alternation cannot have more than 256 alternatives:
83
+ <OR${t.alternation.idx}> inside <${t.topLevelRule.name}> Rule.
84
+ has ${t.alternation.definition.length+1} alternatives.`},buildLeftRecursionError(t){let e=t.topLevelRule.name,n=t.leftRecursionPath.map(o=>o.name),r=`${e} --> ${n.concat([e]).join(" --> ")}`;return`Left Recursion found in grammar.
85
+ rule: <${e}> can be invoked from itself (directly or indirectly)
86
+ without consuming any Tokens. The grammar path that causes this is:
87
+ ${r}
88
+ To fix this refactor your grammar to remove the left recursion.
89
+ see: https://en.wikipedia.org/wiki/LL_parser#Left_factoring.`},buildInvalidRuleNameError(t){return"deprecated"},buildDuplicateRuleNameError(t){let e;return t.topLevelRule instanceof le?e=t.topLevelRule.name:e=t.topLevelRule,`Duplicate definition, rule: ->${e}<- is already defined in the grammar: ->${t.grammarName}<-`}};function Yi(t,e){let n=new Rr(t,e);return n.resolveRefs(),n.errors}var Rr=class extends he{constructor(e,n){super(),this.nameToTopRule=e,this.errMsgProvider=n,this.errors=[]}resolveRefs(){Object.values(this.nameToTopRule).forEach(e=>{this.currTopLevel=e,e.accept(this)})}visitNonTerminal(e){let n=this.nameToTopRule[e.nonTerminalName];if(n)e.referencedRule=n;else{let r=this.errMsgProvider.buildRuleNotFoundError(this.currTopLevel,e);this.errors.push({message:r,type:re.UNRESOLVED_SUBRULE_REF,ruleName:this.currTopLevel.name,unresolvedRefName:e.nonTerminalName})}}};var Ir=class extends we{constructor(e,n){super(),this.topProd=e,this.path=n,this.possibleTokTypes=[],this.nextProductionName="",this.nextProductionOccurrence=0,this.found=!1,this.isAtEndOfPath=!1}startWalking(){if(this.found=!1,this.path.ruleStack[0]!==this.topProd.name)throw Error("The path does not start with the walker's top Rule!");return this.ruleStack=[...this.path.ruleStack].reverse(),this.occurrenceStack=[...this.path.occurrenceStack].reverse(),this.ruleStack.pop(),this.occurrenceStack.pop(),this.updateExpectedNext(),this.walk(this.topProd),this.possibleTokTypes}walk(e,n=[]){this.found||super.walk(e,n)}walkProdRef(e,n,r){if(e.referencedRule.name===this.nextProductionName&&e.idx===this.nextProductionOccurrence){let i=n.concat(r);this.updateExpectedNext(),this.walk(e.referencedRule,i)}}updateExpectedNext(){this.ruleStack.length===0?(this.nextProductionName="",this.nextProductionOccurrence=0,this.isAtEndOfPath=!0):(this.nextProductionName=this.ruleStack.pop(),this.nextProductionOccurrence=this.occurrenceStack.pop())}},gn=class extends Ir{constructor(e,n){super(e,n),this.path=n,this.nextTerminalName="",this.nextTerminalOccurrence=0,this.nextTerminalName=this.path.lastTok.name,this.nextTerminalOccurrence=this.path.lastTokOccurrence}walkTerminal(e,n,r){if(this.isAtEndOfPath&&e.terminalType.name===this.nextTerminalName&&e.idx===this.nextTerminalOccurrence&&!this.found){let i=n.concat(r),o=new H({definition:i});this.possibleTokTypes=ze(o),this.found=!0}}},ut=class extends we{constructor(e,n){super(),this.topRule=e,this.occurrence=n,this.result={token:void 0,occurrence:void 0,isEndOfRule:void 0}}startWalking(){return this.walk(this.topRule),this.result}},En=class extends ut{walkMany(e,n,r){if(e.idx===this.occurrence){let i=n.concat(r)[0];this.result.isEndOfRule=i===void 0,i instanceof U&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkMany(e,n,r)}},Ct=class extends ut{walkManySep(e,n,r){if(e.idx===this.occurrence){let i=n.concat(r)[0];this.result.isEndOfRule=i===void 0,i instanceof U&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkManySep(e,n,r)}},yn=class extends ut{walkAtLeastOne(e,n,r){if(e.idx===this.occurrence){let i=n.concat(r)[0];this.result.isEndOfRule=i===void 0,i instanceof U&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOne(e,n,r)}},_t=class extends ut{walkAtLeastOneSep(e,n,r){if(e.idx===this.occurrence){let i=n.concat(r)[0];this.result.isEndOfRule=i===void 0,i instanceof U&&(this.result.token=i.terminalType,this.result.occurrence=i.idx)}else super.walkAtLeastOneSep(e,n,r)}};function xn(t,e,n=[]){n=[...n];let r=[],i=0;function o(s){return s.concat(t.slice(i+1))}function a(s){let c=xn(o(s),e,n);return r.concat(c)}for(;n.length<e&&i<t.length;){let s=t[i];if(s instanceof H)return a(s.definition);if(s instanceof $)return a(s.definition);if(s instanceof G)r=a(s.definition);else if(s instanceof Q){let c=s.definition.concat([new F({definition:s.definition})]);return a(c)}else if(s instanceof J){let c=[new H({definition:s.definition}),new F({definition:[new U({terminalType:s.separator})].concat(s.definition)})];return a(c)}else if(s instanceof Y){let c=s.definition.concat([new F({definition:[new U({terminalType:s.separator})].concat(s.definition)})]);r=a(c)}else if(s instanceof F){let c=s.definition.concat([new F({definition:s.definition})]);r=a(c)}else{if(s instanceof Z)return s.definition.forEach(c=>{c.definition.length!==0&&(r=a(c.definition))}),r;if(s instanceof U)n.push(s.terminalType);else throw Error("non exhaustive match")}i++}return r.push({partialPath:n,suffixDef:t.slice(i)}),r}function Zi(t,e,n,r){let i="EXIT_NONE_TERMINAL",o=[i],a="EXIT_ALTERNATIVE",s=!1,c=e.length,l=c-r-1,u=[],h=[];for(h.push({idx:-1,def:t,ruleStack:[],occurrenceStack:[]});h.length!==0;){let f=h.pop();if(f===a){s&&h.at(-1).idx<=l&&h.pop();continue}let d=f.def,p=f.idx,m=f.ruleStack,y=f.occurrenceStack;if(d.length===0)continue;let g=d[0];if(g===i){let A={idx:p,def:d.slice(1),ruleStack:m.slice(0,-1),occurrenceStack:y.slice(0,-1)};h.push(A)}else if(g instanceof U)if(p<c-1){let A=p+1,E=e[A];if(n(E,g.terminalType)){let x={idx:A,def:d.slice(1),ruleStack:m,occurrenceStack:y};h.push(x)}}else if(p===c-1)u.push({nextTokenType:g.terminalType,nextTokenOccurrence:g.idx,ruleStack:m,occurrenceStack:y}),s=!0;else throw Error("non exhaustive match");else if(g instanceof $){let A=[...m];A.push(g.nonTerminalName);let E=[...y];E.push(g.idx);let x={idx:p,def:g.definition.concat(o,d.slice(1)),ruleStack:A,occurrenceStack:E};h.push(x)}else if(g instanceof G){let A={idx:p,def:d.slice(1),ruleStack:m,occurrenceStack:y};h.push(A),h.push(a);let E={idx:p,def:g.definition.concat(d.slice(1)),ruleStack:m,occurrenceStack:y};h.push(E)}else if(g instanceof Q){let A=new F({definition:g.definition,idx:g.idx}),E=g.definition.concat([A],d.slice(1)),x={idx:p,def:E,ruleStack:m,occurrenceStack:y};h.push(x)}else if(g instanceof J){let A=new U({terminalType:g.separator}),E=new F({definition:[A].concat(g.definition),idx:g.idx}),x=g.definition.concat([E],d.slice(1)),S={idx:p,def:x,ruleStack:m,occurrenceStack:y};h.push(S)}else if(g instanceof Y){let A={idx:p,def:d.slice(1),ruleStack:m,occurrenceStack:y};h.push(A),h.push(a);let E=new U({terminalType:g.separator}),x=new F({definition:[E].concat(g.definition),idx:g.idx}),S=g.definition.concat([x],d.slice(1)),I={idx:p,def:S,ruleStack:m,occurrenceStack:y};h.push(I)}else if(g instanceof F){let A={idx:p,def:d.slice(1),ruleStack:m,occurrenceStack:y};h.push(A),h.push(a);let E=new F({definition:g.definition,idx:g.idx}),x=g.definition.concat([E],d.slice(1)),S={idx:p,def:x,ruleStack:m,occurrenceStack:y};h.push(S)}else if(g instanceof Z)for(let A=g.definition.length-1;A>=0;A--){let E=g.definition[A],x={idx:p,def:E.definition.concat(d.slice(1)),ruleStack:m,occurrenceStack:y};h.push(x),h.push(a)}else if(g instanceof H)h.push({idx:p,def:g.definition.concat(d.slice(1)),ruleStack:m,occurrenceStack:y});else if(g instanceof le)h.push(Qa(g,p,m,y));else throw Error("non exhaustive match")}return u}function Qa(t,e,n,r){let i=[...n];i.push(t.name);let o=[...r];return o.push(1),{idx:e,def:t.definition,ruleStack:i,occurrenceStack:o}}var z;(function(t){t[t.OPTION=0]="OPTION",t[t.REPETITION=1]="REPETITION",t[t.REPETITION_MANDATORY=2]="REPETITION_MANDATORY",t[t.REPETITION_MANDATORY_WITH_SEPARATOR=3]="REPETITION_MANDATORY_WITH_SEPARATOR",t[t.REPETITION_WITH_SEPARATOR=4]="REPETITION_WITH_SEPARATOR",t[t.ALTERNATION=5]="ALTERNATION"})(z||(z={}));function Tn(t){if(t instanceof G||t==="Option")return z.OPTION;if(t instanceof F||t==="Repetition")return z.REPETITION;if(t instanceof Q||t==="RepetitionMandatory")return z.REPETITION_MANDATORY;if(t instanceof J||t==="RepetitionMandatoryWithSeparator")return z.REPETITION_MANDATORY_WITH_SEPARATOR;if(t instanceof Y||t==="RepetitionWithSeparator")return z.REPETITION_WITH_SEPARATOR;if(t instanceof Z||t==="Alternation")return z.ALTERNATION;throw Error("non exhaustive match")}function Qi(t,e,n,r,i,o){let a=Pt(t,e,n),s=io(a)?ht:be;return o(a,r,s,i)}function Ji(t,e,n,r,i,o){let a=Ut(t,e,i,n),s=io(a)?ht:be;return o(a[0],s,r)}function eo(t,e,n,r){let i=t.length,o=t.every(a=>a.every(s=>s.length===1));if(e)return function(a){let s=a.map(c=>c.GATE);for(let c=0;c<i;c++){let l=t[c],u=l.length,h=s[c];if(!(h!==void 0&&h.call(this)===!1))e:for(let f=0;f<u;f++){let d=l[f],p=d.length;for(let m=0;m<p;m++){let y=this.LA_FAST(m+1);if(n(y,d[m])===!1)continue e}return c}}};if(o&&!r){let s=t.map(c=>c.flat()).reduce((c,l,u)=>(l.forEach(h=>{h.tokenTypeIdx in c||(c[h.tokenTypeIdx]=u),h.categoryMatches.forEach(f=>{Object.hasOwn(c,f)||(c[f]=u)})}),c),{});return function(){let c=this.LA_FAST(1);return s[c.tokenTypeIdx]}}else return function(){for(let a=0;a<i;a++){let s=t[a],c=s.length;e:for(let l=0;l<c;l++){let u=s[l],h=u.length;for(let f=0;f<h;f++){let d=this.LA_FAST(f+1);if(n(d,u[f])===!1)continue e}return a}}}}function to(t,e,n){let r=t.every(o=>o.length===1),i=t.length;if(r&&!n){let o=t.flat();if(o.length===1&&o[0].categoryMatches.length===0){let s=o[0].tokenTypeIdx;return function(){return this.LA_FAST(1).tokenTypeIdx===s}}else{let a=o.reduce((s,c,l)=>(s[c.tokenTypeIdx]=!0,c.categoryMatches.forEach(u=>{s[u]=!0}),s),[]);return function(){let s=this.LA_FAST(1);return a[s.tokenTypeIdx]===!0}}}else return function(){e:for(let o=0;o<i;o++){let a=t[o],s=a.length;for(let c=0;c<s;c++){let l=this.LA_FAST(c+1);if(e(l,a[c])===!1)continue e}return!0}return!1}}var kr=class extends we{constructor(e,n,r){super(),this.topProd=e,this.targetOccurrence=n,this.targetProdType=r}startWalking(){return this.walk(this.topProd),this.restDef}checkIsTarget(e,n,r,i){return e.idx===this.targetOccurrence&&this.targetProdType===n?(this.restDef=r.concat(i),!0):!1}walkOption(e,n,r){this.checkIsTarget(e,z.OPTION,n,r)||super.walkOption(e,n,r)}walkAtLeastOne(e,n,r){this.checkIsTarget(e,z.REPETITION_MANDATORY,n,r)||super.walkOption(e,n,r)}walkAtLeastOneSep(e,n,r){this.checkIsTarget(e,z.REPETITION_MANDATORY_WITH_SEPARATOR,n,r)||super.walkOption(e,n,r)}walkMany(e,n,r){this.checkIsTarget(e,z.REPETITION,n,r)||super.walkOption(e,n,r)}walkManySep(e,n,r){this.checkIsTarget(e,z.REPETITION_WITH_SEPARATOR,n,r)||super.walkOption(e,n,r)}},An=class extends he{constructor(e,n,r){super(),this.targetOccurrence=e,this.targetProdType=n,this.targetRef=r,this.result=[]}checkIsTarget(e,n){e.idx===this.targetOccurrence&&this.targetProdType===n&&(this.targetRef===void 0||e===this.targetRef)&&(this.result=e.definition)}visitOption(e){this.checkIsTarget(e,z.OPTION)}visitRepetition(e){this.checkIsTarget(e,z.REPETITION)}visitRepetitionMandatory(e){this.checkIsTarget(e,z.REPETITION_MANDATORY)}visitRepetitionMandatoryWithSeparator(e){this.checkIsTarget(e,z.REPETITION_MANDATORY_WITH_SEPARATOR)}visitRepetitionWithSeparator(e){this.checkIsTarget(e,z.REPETITION_WITH_SEPARATOR)}visitAlternation(e){this.checkIsTarget(e,z.ALTERNATION)}};function qi(t){let e=new Array(t);for(let n=0;n<t;n++)e[n]=[];return e}function Or(t){let e=[""];for(let n=0;n<t.length;n++){let r=t[n],i=[];for(let o=0;o<e.length;o++){let a=e[o];i.push(a+"_"+r.tokenTypeIdx);for(let s=0;s<r.categoryMatches.length;s++){let c="_"+r.categoryMatches[s];i.push(a+c)}}e=i}return e}function Ja(t,e,n){for(let r=0;r<t.length;r++){if(r===n)continue;let i=t[r];for(let o=0;o<e.length;o++){let a=e[o];if(i[a]===!0)return!1}}return!0}function no(t,e){let n=t.map(a=>xn([a],1)),r=qi(n.length),i=n.map(a=>{let s={};return a.forEach(c=>{Or(c.partialPath).forEach(u=>{s[u]=!0})}),s}),o=n;for(let a=1;a<=e;a++){let s=o;o=qi(s.length);for(let c=0;c<s.length;c++){let l=s[c];for(let u=0;u<l.length;u++){let h=l[u].partialPath,f=l[u].suffixDef,d=Or(h);if(Ja(i,d,c)||f.length===0||h.length===e){let m=r[c];if(Sn(m,h)===!1){m.push(h);for(let y=0;y<d.length;y++){let g=d[y];i[c][g]=!0}}}else{let m=xn(f,a+1,h);o[c]=o[c].concat(m),m.forEach(y=>{Or(y.partialPath).forEach(A=>{i[c][A]=!0})})}}}}return r}function Pt(t,e,n,r){let i=new An(t,z.ALTERNATION,r);return e.accept(i),no(i.result,n)}function Ut(t,e,n,r){let i=new An(t,n);e.accept(i);let o=i.result,s=new kr(e,t,n).startWalking(),c=new H({definition:o}),l=new H({definition:s});return no([c,l],r)}function Sn(t,e){e:for(let n=0;n<t.length;n++){let r=t[n];if(r.length===e.length){for(let i=0;i<r.length;i++){let o=e[i],a=r[i];if((o===a||a.categoryMatchesMap[o.tokenTypeIdx]!==void 0)===!1)continue e}return!0}}return!1}function ro(t,e){return t.length<e.length&&t.every((n,r)=>{let i=e[r];return n===i||i.categoryMatchesMap[n.tokenTypeIdx]})}function io(t){return t.every(e=>e.every(n=>n.every(r=>r.categoryMatches.length===0)))}function oo(t){return t.lookaheadStrategy.validate({rules:t.rules,tokenTypes:t.tokenTypes,grammarName:t.grammarName}).map(n=>Object.assign({type:re.CUSTOM_LOOKAHEAD_VALIDATION},n))}function so(t,e,n,r){let i=t.flatMap(c=>ec(c,n)),o=sc(t,e,n),a=t.flatMap(c=>rc(c,n)),s=t.flatMap(c=>nc(c,t,r,n));return i.concat(o,a,s)}function ec(t,e){let n=new Nr;t.accept(n);let r=n.allProductions,i=Object.groupBy(r,tc),o=Object.fromEntries(Object.entries(i).filter(([s,c])=>c.length>1));return Object.values(o).map(s=>{let c=s[0],l=e.buildDuplicateFoundError(t,s),u=me(c),h={message:l,type:re.DUPLICATE_PRODUCTIONS,ruleName:t.name,dslName:u,occurrence:c.idx},f=ao(c);return f&&(h.parameter=f),h})}function tc(t){return`${me(t)}_#_${t.idx}_#_${ao(t)}`}function ao(t){return t instanceof U?t.terminalType.name:t instanceof $?t.nonTerminalName:""}var Nr=class extends he{constructor(){super(...arguments),this.allProductions=[]}visitNonTerminal(e){this.allProductions.push(e)}visitOption(e){this.allProductions.push(e)}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}visitAlternation(e){this.allProductions.push(e)}visitTerminal(e){this.allProductions.push(e)}};function nc(t,e,n,r){let i=[];if(e.reduce((a,s)=>s.name===t.name?a+1:a,0)>1){let a=r.buildDuplicateRuleNameError({topLevelRule:t,grammarName:n});i.push({message:a,type:re.DUPLICATE_RULE_NAME,ruleName:t.name})}return i}function co(t,e,n){let r=[],i;return e.includes(t)||(i=`Invalid rule override, rule: ->${t}<- cannot be overridden in the grammar: ->${n}<-as it is not defined in any of the super grammars `,r.push({message:i,type:re.INVALID_RULE_OVERRIDE,ruleName:t})),r}function Lr(t,e,n,r=[]){let i=[],o=Rn(e.definition);if(o.length===0)return[];{let a=t.name;o.includes(t)&&i.push({message:n.buildLeftRecursionError({topLevelRule:t,leftRecursionPath:r}),type:re.LEFT_RECURSION,ruleName:a});let c=r.concat([t]),u=o.filter(h=>!c.includes(h)).flatMap(h=>{let f=[...r];return f.push(h),Lr(t,h,n,f)});return i.concat(u)}}function Rn(t){let e=[];if(t.length===0)return e;let n=t[0];if(n instanceof $)e.push(n.referencedRule);else if(n instanceof H||n instanceof G||n instanceof Q||n instanceof J||n instanceof Y||n instanceof F)e=e.concat(Rn(n.definition));else if(n instanceof Z)e=n.definition.map(o=>Rn(o.definition)).flat();else if(!(n instanceof U))throw Error("non exhaustive match");let r=Ke(n),i=t.length>1;if(r&&i){let o=t.slice(1);return e.concat(Rn(o))}else return e}var Ft=class extends he{constructor(){super(...arguments),this.alternations=[]}visitAlternation(e){this.alternations.push(e)}};function lo(t,e){let n=new Ft;return t.accept(n),n.alternations.flatMap(o=>o.definition.slice(0,-1).flatMap((s,c)=>Zi([s],[],be,1).length===0?[{message:e.buildEmptyAlternationError({topLevelRule:t,alternation:o,emptyChoiceIdx:c}),type:re.NONE_LAST_EMPTY_ALT,ruleName:t.name,occurrence:o.idx,alternative:c+1}]:[]))}function ho(t,e,n){let r=new Ft;t.accept(r);let i=r.alternations;return i=i.filter(a=>a.ignoreAmbiguities!==!0),i.flatMap(a=>{let s=a.idx,c=a.maxLookahead||e,l=Pt(s,t,c,a),u=ic(l,a,t,n),h=oc(l,a,t,n);return u.concat(h)})}var Mr=class extends he{constructor(){super(...arguments),this.allProductions=[]}visitRepetitionWithSeparator(e){this.allProductions.push(e)}visitRepetitionMandatory(e){this.allProductions.push(e)}visitRepetitionMandatoryWithSeparator(e){this.allProductions.push(e)}visitRepetition(e){this.allProductions.push(e)}};function rc(t,e){let n=new Ft;return t.accept(n),n.alternations.flatMap(o=>o.definition.length>255?[{message:e.buildTooManyAlternativesError({topLevelRule:t,alternation:o}),type:re.TOO_MANY_ALTS,ruleName:t.name,occurrence:o.idx}]:[])}function uo(t,e,n){let r=[];return t.forEach(i=>{let o=new Mr;i.accept(o),o.allProductions.forEach(s=>{let c=Tn(s),l=s.maxLookahead||e,u=s.idx;if(Ut(u,i,c,l)[0].flat().length===0){let d=n.buildEmptyRepetitionError({topLevelRule:i,repetition:s});r.push({message:d,type:re.NO_NON_EMPTY_LOOKAHEAD,ruleName:i.name})}})}),r}function ic(t,e,n,r){let i=[];return t.reduce((s,c,l)=>(e.definition[l].ignoreAmbiguities===!0||c.forEach(u=>{let h=[l];t.forEach((f,d)=>{l!==d&&Sn(f,u)&&e.definition[d].ignoreAmbiguities!==!0&&h.push(d)}),h.length>1&&!Sn(i,u)&&(i.push(u),s.push({alts:h,path:u}))}),s),[]).map(s=>{let c=s.alts.map(u=>u+1);return{message:r.buildAlternationAmbiguityError({topLevelRule:n,alternation:e,ambiguityIndices:c,prefixPath:s.path}),type:re.AMBIGUOUS_ALTS,ruleName:n.name,occurrence:e.idx,alternatives:s.alts}})}function oc(t,e,n,r){let i=t.reduce((a,s,c)=>{let l=s.map(u=>({idx:c,path:u}));return a.concat(l)},[]);return i.flatMap(a=>{if(e.definition[a.idx].ignoreAmbiguities===!0)return[];let c=a.idx,l=a.path;return i.filter(f=>e.definition[f.idx].ignoreAmbiguities!==!0&&f.idx<c&&ro(f.path,l)).map(f=>{let d=[f.idx+1,c+1],p=e.idx===0?"":e.idx;return{message:r.buildAlternationPrefixAmbiguityError({topLevelRule:n,alternation:e,ambiguityIndices:d,prefixPath:f.path}),type:re.AMBIGUOUS_PREFIX_ALTS,ruleName:n.name,occurrence:p,alternatives:d}})})}function sc(t,e,n){let r=[],i=e.map(o=>o.name);return t.forEach(o=>{let a=o.name;if(i.includes(a)){let s=n.buildNamespaceConflictError(o);r.push({message:s,type:re.CONFLICT_TOKENS_RULES_NAMESPACE,ruleName:a})}}),r}function fo(t){let e=Object.assign({errMsgProvider:Xi},t),n={};return t.rules.forEach(r=>{n[r.name]=r}),Yi(n,e.errMsgProvider)}function po(t){var e;let n=(e=t.errMsgProvider)!==null&&e!==void 0?e:Oe;return so(t.rules,t.tokenTypes,n,t.grammarName)}var mo="MismatchedTokenException",go="NoViableAltException",Eo="EarlyExitException",yo="NotAllInputParsedException",xo=[mo,go,Eo,yo];Object.freeze(xo);function $e(t){return xo.includes(t.name)}var dt=class extends Error{constructor(e,n){super(e),this.token=n,this.resyncedTokens=[],Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},et=class extends dt{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=mo}},Dt=class extends dt{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=go}},Bt=class extends dt{constructor(e,n){super(e,n),this.name=yo}},$t=class extends dt{constructor(e,n,r){super(e,n),this.previousToken=r,this.name=Eo}};var vr={},br="InRuleRecoveryException",wr=class extends Error{constructor(e){super(e),this.name=br}},In=class{initRecoverable(e){this.firstAfterRepMap=[],this.resyncFollows={},this.recoveryEnabled=Object.hasOwn(e,"recoveryEnabled")?e.recoveryEnabled:ue.recoveryEnabled,this.recoveryEnabled&&(this.attemptInRepetitionRecovery=ac)}getTokenToInsert(e){let n=Qe(e,"",-1,-1,-1,-1,-1,-1);return n.isInsertedInRecovery=!0,n}canTokenTypeBeInsertedInRecovery(e){return!0}canTokenTypeBeDeletedInRecovery(e){return!0}tryInRepetitionRecovery(e,n,r,i){let o=this.findReSyncTokenType(),a=this.exportLexerState(),s=[],c=!1,l=this.LA_FAST(1),u=this.LA_FAST(1),h=()=>{let f=this.LA(0),d=this.errorMessageProvider.buildMismatchTokenMessage({expected:i,actual:l,previous:f,ruleName:this.getCurrRuleFullName()}),p=new et(d,l,this.LA(0));p.resyncedTokens=s.slice(0,-1),this.SAVE_ERROR(p)};for(;!c;)if(this.tokenMatcher(u,i)){h();return}else if(r.call(this)){h(),e.apply(this,n);return}else this.tokenMatcher(u,o)?c=!0:(u=this.SKIP_TOKEN(),this.addToResyncTokens(u,s));this.importLexerState(a)}shouldInRepetitionRecoveryBeTried(e,n,r){return!(r===!1||this.tokenMatcher(this.LA_FAST(1),e)||this.isBackTracking()||this.canPerformInRuleRecovery(e,this.getFollowsForInRuleRecovery(e,n)))}getNextPossibleTokenTypes(e){let n=e.ruleStack[0],i=this.getGAstProductions()[n];return new gn(i,e).startWalking()}getFollowsForInRuleRecovery(e,n){let r=this.getCurrentGrammarPath(e,n);return this.getNextPossibleTokenTypes(r)}tryInRuleRecovery(e,n){if(this.canRecoverWithSingleTokenInsertion(e,n))return this.getTokenToInsert(e);if(this.canRecoverWithSingleTokenDeletion(e)){let r=this.SKIP_TOKEN();return this.consumeToken(),r}throw new wr("sad sad panda")}canPerformInRuleRecovery(e,n){return this.canRecoverWithSingleTokenInsertion(e,n)||this.canRecoverWithSingleTokenDeletion(e)}canRecoverWithSingleTokenInsertion(e,n){if(!this.canTokenTypeBeInsertedInRecovery(e)||n.length===0)return!1;let r=this.LA_FAST(1);return n.find(o=>this.tokenMatcher(r,o))!==void 0}canRecoverWithSingleTokenDeletion(e){return this.canTokenTypeBeDeletedInRecovery(e)?this.tokenMatcher(this.LA(2),e):!1}isInCurrentRuleReSyncSet(e){let n=this.getCurrFollowKey();return this.getFollowSetFromFollowKey(n).includes(e)}findReSyncTokenType(){let e=this.flattenFollowSet(),n=this.LA_FAST(1),r=2;for(;;){let i=e.find(o=>Sr(n,o));if(i!==void 0)return i;n=this.LA(r),r++}}getCurrFollowKey(){if(this.RULE_STACK_IDX===0)return vr;let e=this.currRuleShortName,n=this.getLastExplicitRuleOccurrenceIndex(),r=this.getPreviousExplicitRuleShortName();return{ruleName:this.shortRuleNameToFullName(e),idxInCallingRule:n,inRule:this.shortRuleNameToFullName(r)}}buildFullFollowKeyStack(){let e=this.RULE_STACK,n=this.RULE_OCCURRENCE_STACK,r=this.RULE_STACK_IDX+1,i=new Array(r);for(let o=0;o<r;o++)o===0?i[o]=vr:i[o]={ruleName:this.shortRuleNameToFullName(e[o]),idxInCallingRule:n[o],inRule:this.shortRuleNameToFullName(e[o-1])};return i}flattenFollowSet(){return this.buildFullFollowKeyStack().map(n=>this.getFollowSetFromFollowKey(n)).flat()}getFollowSetFromFollowKey(e){if(e===vr)return[Ae];let n=e.ruleName+e.idxInCallingRule+on+e.inRule;return this.resyncFollows[n]}addToResyncTokens(e,n){return this.tokenMatcher(e,Ae)||n.push(e),n}reSyncTo(e){let n=[],r=this.LA_FAST(1);for(;this.tokenMatcher(r,e)===!1;)r=this.SKIP_TOKEN(),this.addToResyncTokens(r,n);return n.slice(0,-1)}attemptInRepetitionRecovery(e,n,r,i,o,a,s){}getCurrentGrammarPath(e,n){let r=this.getHumanReadableRuleStack(),i=this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1);return{ruleStack:r,occurrenceStack:i,lastTok:e,lastTokOccurrence:n}}getHumanReadableRuleStack(){let e=this.RULE_STACK_IDX+1,n=new Array(e);for(let r=0;r<e;r++)n[r]=this.shortRuleNameToFullName(this.RULE_STACK[r]);return n}};function ac(t,e,n,r,i,o,a){var s,c,l;let u=r|i,h=(s=(c=this.firstAfterRepMap)[l=this.currRuleShortName])!==null&&s!==void 0?s:c[l]=[],f=h[u];if(f===void 0){let y=this.getCurrRuleFullName(),g=this.getGAstProductions()[y];f=new o(g,i).startWalking(),h[u]=f}let d=f.token,p=f.occurrence,m=f.isEndOfRule;this.RULE_STACK_IDX===0&&m&&d===void 0&&(d=Ae,p=1),!(d===void 0||p===void 0)&&this.shouldInRepetitionRecoveryBeTried(d,p,a)&&this.tryInRepetitionRecovery(t,e,n,d)}var Ht=class{constructor(e){var n;this.maxLookahead=(n=e?.maxLookahead)!==null&&n!==void 0?n:ue.maxLookahead}validate(e){let n=this.validateNoLeftRecursion(e.rules);if(n.length===0){let r=this.validateEmptyOrAlternatives(e.rules),i=this.validateAmbiguousAlternationAlternatives(e.rules,this.maxLookahead),o=this.validateSomeNonEmptyLookaheadPath(e.rules,this.maxLookahead);return[...n,...r,...i,...o]}return n}validateNoLeftRecursion(e){return e.flatMap(n=>Lr(n,n,Oe))}validateEmptyOrAlternatives(e){return e.flatMap(n=>lo(n,Oe))}validateAmbiguousAlternationAlternatives(e,n){return e.flatMap(r=>ho(r,n,Oe))}validateSomeNonEmptyLookaheadPath(e,n){return uo(e,n,Oe)}buildLookaheadForAlternation(e){return Qi(e.prodOccurrence,e.rule,e.maxLookahead,e.hasPredicates,e.dynamicTokensEnabled,eo)}buildLookaheadForOptional(e){return Ji(e.prodOccurrence,e.rule,e.maxLookahead,e.dynamicTokensEnabled,Tn(e.prodType),to)}};var kn=class{initLooksAhead(e){this.dynamicTokensEnabled=Object.hasOwn(e,"dynamicTokensEnabled")?e.dynamicTokensEnabled:ue.dynamicTokensEnabled,this.maxLookahead=Object.hasOwn(e,"maxLookahead")?e.maxLookahead:ue.maxLookahead,this.lookaheadStrategy=Object.hasOwn(e,"lookaheadStrategy")?e.lookaheadStrategy:new Ht({maxLookahead:this.maxLookahead}),this.lookAheadFuncsCache=[],this.currRuleLookaheadFuncs=[]}preComputeLookaheadFunctions(e){e.forEach(n=>{this.TRACE_INIT(`${n.name} Rule Lookahead`,()=>{let{alternation:r,repetition:i,option:o,repetitionMandatory:a,repetitionMandatoryWithSeparator:s,repetitionWithSeparator:c}=cc(n);r.forEach(l=>{let u=l.idx===0?"":l.idx;this.TRACE_INIT(`${me(l)}${u}`,()=>{let h=this.lookaheadStrategy.buildLookaheadForAlternation({prodOccurrence:l.idx,rule:n,maxLookahead:l.maxLookahead||this.maxLookahead,hasPredicates:l.hasPredicates,dynamicTokensEnabled:this.dynamicTokensEnabled});this.setLaFuncCache(this.fullRuleNameToShort[n.name],256|l.idx,h)})}),i.forEach(l=>{this.computeLookaheadFunc(n,l.idx,768,"Repetition",l.maxLookahead,me(l))}),o.forEach(l=>{this.computeLookaheadFunc(n,l.idx,512,"Option",l.maxLookahead,me(l))}),a.forEach(l=>{this.computeLookaheadFunc(n,l.idx,1024,"RepetitionMandatory",l.maxLookahead,me(l))}),s.forEach(l=>{this.computeLookaheadFunc(n,l.idx,1536,"RepetitionMandatoryWithSeparator",l.maxLookahead,me(l))}),c.forEach(l=>{this.computeLookaheadFunc(n,l.idx,1280,"RepetitionWithSeparator",l.maxLookahead,me(l))})})})}computeLookaheadFunc(e,n,r,i,o,a){this.TRACE_INIT(`${a}${n===0?"":n}`,()=>{let s=this.lookaheadStrategy.buildLookaheadForOptional({prodOccurrence:n,rule:e,maxLookahead:o||this.maxLookahead,dynamicTokensEnabled:this.dynamicTokensEnabled,prodType:i});this.setLaFuncCache(this.fullRuleNameToShort[e.name],r|n,s)})}setLaFuncCache(e,n,r){let i=this.lookAheadFuncsCache[e];i===void 0&&(i=[],this.lookAheadFuncsCache[e]=i),i[n]=r}},Cr=class extends he{constructor(){super(...arguments),this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}reset(){this.dslMethods={option:[],alternation:[],repetition:[],repetitionWithSeparator:[],repetitionMandatory:[],repetitionMandatoryWithSeparator:[]}}visitOption(e){this.dslMethods.option.push(e)}visitRepetitionWithSeparator(e){this.dslMethods.repetitionWithSeparator.push(e)}visitRepetitionMandatory(e){this.dslMethods.repetitionMandatory.push(e)}visitRepetitionMandatoryWithSeparator(e){this.dslMethods.repetitionMandatoryWithSeparator.push(e)}visitRepetition(e){this.dslMethods.repetition.push(e)}visitAlternation(e){this.dslMethods.alternation.push(e)}},On=new Cr;function cc(t){On.reset(),t.accept(On);let e=On.dslMethods;return On.reset(),e}function Ur(t,e){t.startOffset===-1?(t.startOffset=e.startOffset,t.endOffset=e.endOffset):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset)}function Fr(t,e){t.startOffset===-1?(t.startOffset=e.startOffset,t.startColumn=e.startColumn,t.startLine=e.startLine,t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine):t.endOffset<e.endOffset&&(t.endOffset=e.endOffset,t.endColumn=e.endColumn,t.endLine=e.endLine)}function Ao(t,e,n){t.children[n]===void 0?t.children[n]=[e]:t.children[n].push(e)}function To(t,e,n){t.children[e]===void 0?t.children[e]=[n]:t.children[e].push(n)}var lc="name";function Dr(t,e){Object.defineProperty(t,lc,{enumerable:!1,configurable:!0,writable:!1,value:e})}function hc(t,e){let n=Object.keys(t),r=n.length;for(let i=0;i<r;i++){let o=n[i],a=t[o],s=a.length;for(let c=0;c<s;c++){let l=a[c];l.tokenTypeIdx===void 0&&this[l.name](l.children,e)}}}function So(t,e){let n=function(){};Dr(n,t+"BaseSemantics");let r={visit:function(i,o){if(Array.isArray(i)&&(i=i[0]),i!==void 0)return this[i.name](i.children,o)},validateVisitor:function(){let i=uc(this,e);if(i.length!==0){let o=i.map(a=>a.msg);throw Error(`Errors Detected in CST Visitor <${this.constructor.name}>:
90
+ ${o.join(`
91
+
92
+ `).replace(/\n/g,`
93
+ `)}`)}}};return n.prototype=r,n.prototype.constructor=n,n._RULE_NAMES=e,n}function Ro(t,e,n){let r=function(){};Dr(r,t+"BaseSemanticsWithDefaults");let i=Object.create(n.prototype);return e.forEach(o=>{i[o]=hc}),r.prototype=i,r.prototype.constructor=r,r}var Br;(function(t){t[t.REDUNDANT_METHOD=0]="REDUNDANT_METHOD",t[t.MISSING_METHOD=1]="MISSING_METHOD"})(Br||(Br={}));function uc(t,e){return dc(t,e)}function dc(t,e){return e.filter(i=>typeof t[i]!="function").map(i=>({msg:`Missing visitor method: <${i}> on ${t.constructor.name} CST Visitor.`,type:Br.MISSING_METHOD,methodName:i})).filter(Boolean)}var vn=class{initTreeBuilder(e){if(this.CST_STACK=[],this.outputCst=e.outputCst,this.nodeLocationTracking=Object.hasOwn(e,"nodeLocationTracking")?e.nodeLocationTracking:ue.nodeLocationTracking,!this.outputCst)this.cstInvocationStateUpdate=()=>{},this.cstFinallyStateUpdate=()=>{},this.cstPostTerminal=()=>{},this.cstPostNonTerminal=()=>{},this.cstPostRule=()=>{};else if(/full/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=Fr,this.setNodeLocationFromNode=Fr,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationFullRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleFull,this.setInitialNodeLocation=this.setInitialNodeLocationFullRegular);else if(/onlyOffset/i.test(this.nodeLocationTracking))this.recoveryEnabled?(this.setNodeLocationFromToken=Ur,this.setNodeLocationFromNode=Ur,this.cstPostRule=()=>{},this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRecovery):(this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=this.cstPostRuleOnlyOffset,this.setInitialNodeLocation=this.setInitialNodeLocationOnlyOffsetRegular);else if(/none/i.test(this.nodeLocationTracking))this.setNodeLocationFromToken=()=>{},this.setNodeLocationFromNode=()=>{},this.cstPostRule=()=>{},this.setInitialNodeLocation=()=>{};else throw Error(`Invalid <nodeLocationTracking> config option: "${e.nodeLocationTracking}"`)}setInitialNodeLocationOnlyOffsetRecovery(e){e.location={startOffset:-1,endOffset:-1}}setInitialNodeLocationOnlyOffsetRegular(e){e.location={startOffset:this.LA_FAST(1).startOffset,endOffset:-1}}setInitialNodeLocationFullRecovery(e){e.location={startOffset:-1,startLine:-1,startColumn:-1,endOffset:-1,endLine:-1,endColumn:-1}}setInitialNodeLocationFullRegular(e){let n=this.LA_FAST(1);e.location={startOffset:n.startOffset,startLine:n.startLine,startColumn:n.startColumn,endOffset:-1,endLine:-1,endColumn:-1}}cstInvocationStateUpdate(e){let n={name:e,children:Object.create(null)};this.setInitialNodeLocation(n),this.CST_STACK.push(n)}cstFinallyStateUpdate(){this.CST_STACK.pop()}cstPostRuleFull(e){let n=this.LA(0),r=e.location;r.startOffset!==-1&&r.startOffset<=n.startOffset?(r.endOffset=n.endOffset,r.endLine=n.endLine,r.endColumn=n.endColumn):(r.startOffset=-1,r.startLine=-1,r.startColumn=-1)}cstPostRuleOnlyOffset(e){let n=this.LA(0),r=e.location;r.startOffset!==-1&&r.startOffset<=n.startOffset?r.endOffset=n.endOffset:r.startOffset=-1}cstPostTerminal(e,n){let r=this.CST_STACK[this.CST_STACK.length-1];Ao(r,n,e),this.setNodeLocationFromToken(r.location,n)}cstPostNonTerminal(e,n){let r=this.CST_STACK[this.CST_STACK.length-1];To(r,n,e),this.setNodeLocationFromNode(r.location,e.location)}get currCSTNode(){let e=this;return e.CST_STACK[e.CST_STACK.length-1]}getBaseCstVisitorConstructor(){if(this.baseCstVisitorConstructor===void 0){let e=So(this.className,Object.keys(this.gastProductionsCache));return this.baseCstVisitorConstructor=e,e}return this.baseCstVisitorConstructor}getBaseCstVisitorConstructorWithDefaults(){if(this.baseCstVisitorWithDefaultsConstructor===void 0){let e=Ro(this.className,Object.keys(this.gastProductionsCache),this.getBaseCstVisitorConstructor());return this.baseCstVisitorWithDefaultsConstructor=e,e}return this.baseCstVisitorWithDefaultsConstructor}getPreviousExplicitRuleShortName(){return this.RULE_STACK[this.RULE_STACK_IDX-1]}getLastExplicitRuleOccurrenceIndex(){return this.RULE_OCCURRENCE_STACK[this.RULE_OCCURRENCE_STACK_IDX]}};var wn=class{initLexerAdapter(){this.tokVector=[],this.tokVectorLength=0,this.currIdx=-1}set input(e){if(this.selfAnalysisDone!==!0)throw Error("Missing <performSelfAnalysis> invocation at the end of the Parser's constructor.");this.reset(),this.tokVector=e,this.tokVectorLength=e.length}get input(){return this.tokVector}SKIP_TOKEN(){return this.currIdx<=this.tokVectorLength-2?(this.consumeToken(),this.LA_FAST(1)):_e}LA_FAST(e){let n=this.currIdx+e;return this.tokVector[n]}LA(e){let n=this.currIdx+e;return n<0||this.tokVectorLength<=n?_e:this.tokVector[n]}consumeToken(){this.currIdx++}exportLexerState(){return this.currIdx}importLexerState(e){this.currIdx=e}resetLexerState(){this.currIdx=-1}moveToTerminatedState(){this.currIdx=this.tokVectorLength-1}getLexerPosition(){return this.exportLexerState()}};var bn=class{ACTION(e){return e.call(this)}consume(e,n,r){return this.consumeInternal(n,e,r)}subrule(e,n,r){return this.subruleInternal(n,e,r)}option(e,n){return this.optionInternal(n,e)}or(e,n){return this.orInternal(n,e)}many(e,n){return this.manyInternal(e,n)}atLeastOne(e,n){return this.atLeastOneInternal(e,n)}CONSUME(e,n){return this.consumeInternal(e,0,n)}CONSUME1(e,n){return this.consumeInternal(e,1,n)}CONSUME2(e,n){return this.consumeInternal(e,2,n)}CONSUME3(e,n){return this.consumeInternal(e,3,n)}CONSUME4(e,n){return this.consumeInternal(e,4,n)}CONSUME5(e,n){return this.consumeInternal(e,5,n)}CONSUME6(e,n){return this.consumeInternal(e,6,n)}CONSUME7(e,n){return this.consumeInternal(e,7,n)}CONSUME8(e,n){return this.consumeInternal(e,8,n)}CONSUME9(e,n){return this.consumeInternal(e,9,n)}SUBRULE(e,n){return this.subruleInternal(e,0,n)}SUBRULE1(e,n){return this.subruleInternal(e,1,n)}SUBRULE2(e,n){return this.subruleInternal(e,2,n)}SUBRULE3(e,n){return this.subruleInternal(e,3,n)}SUBRULE4(e,n){return this.subruleInternal(e,4,n)}SUBRULE5(e,n){return this.subruleInternal(e,5,n)}SUBRULE6(e,n){return this.subruleInternal(e,6,n)}SUBRULE7(e,n){return this.subruleInternal(e,7,n)}SUBRULE8(e,n){return this.subruleInternal(e,8,n)}SUBRULE9(e,n){return this.subruleInternal(e,9,n)}OPTION(e){return this.optionInternal(e,0)}OPTION1(e){return this.optionInternal(e,1)}OPTION2(e){return this.optionInternal(e,2)}OPTION3(e){return this.optionInternal(e,3)}OPTION4(e){return this.optionInternal(e,4)}OPTION5(e){return this.optionInternal(e,5)}OPTION6(e){return this.optionInternal(e,6)}OPTION7(e){return this.optionInternal(e,7)}OPTION8(e){return this.optionInternal(e,8)}OPTION9(e){return this.optionInternal(e,9)}OR(e){return this.orInternal(e,0)}OR1(e){return this.orInternal(e,1)}OR2(e){return this.orInternal(e,2)}OR3(e){return this.orInternal(e,3)}OR4(e){return this.orInternal(e,4)}OR5(e){return this.orInternal(e,5)}OR6(e){return this.orInternal(e,6)}OR7(e){return this.orInternal(e,7)}OR8(e){return this.orInternal(e,8)}OR9(e){return this.orInternal(e,9)}MANY(e){this.manyInternal(0,e)}MANY1(e){this.manyInternal(1,e)}MANY2(e){this.manyInternal(2,e)}MANY3(e){this.manyInternal(3,e)}MANY4(e){this.manyInternal(4,e)}MANY5(e){this.manyInternal(5,e)}MANY6(e){this.manyInternal(6,e)}MANY7(e){this.manyInternal(7,e)}MANY8(e){this.manyInternal(8,e)}MANY9(e){this.manyInternal(9,e)}MANY_SEP(e){this.manySepFirstInternal(0,e)}MANY_SEP1(e){this.manySepFirstInternal(1,e)}MANY_SEP2(e){this.manySepFirstInternal(2,e)}MANY_SEP3(e){this.manySepFirstInternal(3,e)}MANY_SEP4(e){this.manySepFirstInternal(4,e)}MANY_SEP5(e){this.manySepFirstInternal(5,e)}MANY_SEP6(e){this.manySepFirstInternal(6,e)}MANY_SEP7(e){this.manySepFirstInternal(7,e)}MANY_SEP8(e){this.manySepFirstInternal(8,e)}MANY_SEP9(e){this.manySepFirstInternal(9,e)}AT_LEAST_ONE(e){this.atLeastOneInternal(0,e)}AT_LEAST_ONE1(e){return this.atLeastOneInternal(1,e)}AT_LEAST_ONE2(e){this.atLeastOneInternal(2,e)}AT_LEAST_ONE3(e){this.atLeastOneInternal(3,e)}AT_LEAST_ONE4(e){this.atLeastOneInternal(4,e)}AT_LEAST_ONE5(e){this.atLeastOneInternal(5,e)}AT_LEAST_ONE6(e){this.atLeastOneInternal(6,e)}AT_LEAST_ONE7(e){this.atLeastOneInternal(7,e)}AT_LEAST_ONE8(e){this.atLeastOneInternal(8,e)}AT_LEAST_ONE9(e){this.atLeastOneInternal(9,e)}AT_LEAST_ONE_SEP(e){this.atLeastOneSepFirstInternal(0,e)}AT_LEAST_ONE_SEP1(e){this.atLeastOneSepFirstInternal(1,e)}AT_LEAST_ONE_SEP2(e){this.atLeastOneSepFirstInternal(2,e)}AT_LEAST_ONE_SEP3(e){this.atLeastOneSepFirstInternal(3,e)}AT_LEAST_ONE_SEP4(e){this.atLeastOneSepFirstInternal(4,e)}AT_LEAST_ONE_SEP5(e){this.atLeastOneSepFirstInternal(5,e)}AT_LEAST_ONE_SEP6(e){this.atLeastOneSepFirstInternal(6,e)}AT_LEAST_ONE_SEP7(e){this.atLeastOneSepFirstInternal(7,e)}AT_LEAST_ONE_SEP8(e){this.atLeastOneSepFirstInternal(8,e)}AT_LEAST_ONE_SEP9(e){this.atLeastOneSepFirstInternal(9,e)}RULE(e,n,r=ft){if(this.definedRulesNames.includes(e)){let a={message:Oe.buildDuplicateRuleNameError({topLevelRule:e,grammarName:this.className}),type:re.DUPLICATE_RULE_NAME,ruleName:e};this.definitionErrors.push(a)}this.definedRulesNames.push(e);let i=this.defineRule(e,n,r);return this[e]=i,i}OVERRIDE_RULE(e,n,r=ft){let i=co(e,this.definedRulesNames,this.className);this.definitionErrors=this.definitionErrors.concat(i);let o=this.defineRule(e,n,r);return this[e]=o,o}BACKTRACK(e,n){var r;let i=(r=e.coreRule)!==null&&r!==void 0?r:e;return function(){this.isBackTrackingStack.push(1);let o=this.saveRecogState();try{return i.apply(this,n),!0}catch(a){if($e(a))return!1;throw a}finally{this.reloadRecogState(o),this.isBackTrackingStack.pop()}}}getGAstProductions(){return this.gastProductionsCache}getSerializedGastProductions(){return rn(Object.values(this.gastProductionsCache))}};var Cn=class{initRecognizerEngine(e,n){if(this.className=this.constructor.name,this.shortRuleNameToFull=[],this.fullRuleNameToShort={},this.ruleShortNameIdx=0,this.tokenMatcher=ht,this.subruleIdx=0,this.currRuleShortName=-1,this.definedRulesNames=[],this.tokensMap={},this.isBackTrackingStack=[],this.RULE_STACK=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK=[],this.RULE_OCCURRENCE_STACK_IDX=-1,this.gastProductionsCache={},Object.hasOwn(n,"serializedGrammar"))throw Error(`The Parser's configuration can no longer contain a <serializedGrammar> property.
94
+ See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_6-0-0
95
+ For Further details.`);if(Array.isArray(e)){if(e.length===0)throw Error(`A Token Vocabulary cannot be empty.
96
+ Note that the first argument for the parser constructor
97
+ is no longer a Token vector (since v4.0).`);if(typeof e[0].startOffset=="number")throw Error(`The Parser constructor no longer accepts a token vector as the first argument.
98
+ See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_4-0-0
99
+ For Further details.`)}if(Array.isArray(e))this.tokensMap=e.reduce((o,a)=>(o[a.name]=a,o),{});else if(Object.hasOwn(e,"modes")&&Object.values(e.modes).flat().every(Bi)){let o=Object.values(e.modes).flat(),a=[...new Set(o)];this.tokensMap=a.reduce((s,c)=>(s[c.name]=c,s),{})}else if(typeof e=="object"&&e!==null)this.tokensMap=Object.assign({},e);else throw new Error("<tokensDictionary> argument must be An Array of Token constructors, A dictionary of Token constructors or an IMultiModeLexerDefinition");this.tokensMap.EOF=Ae;let i=(Object.hasOwn(e,"modes")?Object.values(e.modes).flat():Object.values(e)).every(o=>{var a;return((a=o.categoryMatches)===null||a===void 0?void 0:a.length)==0});this.tokenMatcher=i?ht:be,Ce(Object.values(this.tokensMap))}defineRule(e,n,r){if(this.selfAnalysisDone)throw Error(`Grammar rule <${e}> may not be defined after the 'performSelfAnalysis' method has been called'
100
+ Make sure that all grammar rule definitions are done before 'performSelfAnalysis' is called.`);let i=Object.hasOwn(r,"resyncEnabled")?r.resyncEnabled:ft.resyncEnabled,o=Object.hasOwn(r,"recoveryValueFunc")?r.recoveryValueFunc:ft.recoveryValueFunc,a=this.ruleShortNameIdx++;this.shortRuleNameToFull[a]=e,this.fullRuleNameToShort[e]=a;let s;return this.outputCst===!0?s=function(...h){try{this.ruleInvocationStateUpdate(a,e,this.subruleIdx),n.apply(this,h);let f=this.CST_STACK[this.CST_STACK.length-1];return this.cstPostRule(f),f}catch(f){return this.invokeRuleCatch(f,i,o)}finally{this.ruleFinallyStateUpdate()}}:s=function(...h){try{return this.ruleInvocationStateUpdate(a,e,this.subruleIdx),n.apply(this,h)}catch(f){return this.invokeRuleCatch(f,i,o)}finally{this.ruleFinallyStateUpdate()}},Object.assign(function(...h){this.onBeforeParse(e);try{return s.apply(this,h)}finally{this.onAfterParse(e)}},{ruleName:e,originalGrammarAction:n,coreRule:s})}invokeRuleCatch(e,n,r){let i=this.RULE_STACK_IDX===0,o=n&&!this.isBackTracking()&&this.recoveryEnabled;if($e(e)){let a=e;if(o){let s=this.findReSyncTokenType();if(this.isInCurrentRuleReSyncSet(s))if(a.resyncedTokens=this.reSyncTo(s),this.outputCst){let c=this.CST_STACK[this.CST_STACK.length-1];return c.recoveredNode=!0,c}else return r(e);else{if(this.outputCst){let c=this.CST_STACK[this.CST_STACK.length-1];c.recoveredNode=!0,a.partialCstResult=c}throw a}}else{if(i)return this.moveToTerminatedState(),r(e);throw a}}else throw e}optionInternal(e,n){let r=512|n;return this.optionInternalLogic(e,n,r)}optionInternalLogic(e,n,r){let i=this.currRuleLookaheadFuncs[r],o;if(typeof e!="function"){o=e.DEF;let a=e.GATE;if(a!==void 0){let s=i;i=()=>a.call(this)&&s.call(this)}}else o=e;if(i.call(this)===!0)return o.call(this)}atLeastOneInternal(e,n){let r=1024|e;return this.atLeastOneInternalLogic(e,n,r)}atLeastOneInternalLogic(e,n,r){let i=this.currRuleLookaheadFuncs[r],o;if(typeof n!="function"){o=n.DEF;let a=n.GATE;if(a!==void 0){let s=i;i=()=>a.call(this)&&s.call(this)}}else o=n;if(i.call(this)===!0){let a=this.doSingleRepetition(o);for(;i.call(this)===!0&&a===!0;)a=this.doSingleRepetition(o)}else throw this.raiseEarlyExitException(e,z.REPETITION_MANDATORY,n.ERR_MSG);this.attemptInRepetitionRecovery(this.atLeastOneInternal,[e,n],i,1024,e,yn)}atLeastOneSepFirstInternal(e,n){let r=1536|e;this.atLeastOneSepFirstInternalLogic(e,n,r)}atLeastOneSepFirstInternalLogic(e,n,r){let i=n.DEF,o=n.SEP;if(this.currRuleLookaheadFuncs[r].call(this)===!0){i.call(this);let s=()=>this.tokenMatcher(this.LA_FAST(1),o);for(;this.tokenMatcher(this.LA_FAST(1),o)===!0;)this.CONSUME(o),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,o,s,i,_t],s,1536,e,_t)}else throw this.raiseEarlyExitException(e,z.REPETITION_MANDATORY_WITH_SEPARATOR,n.ERR_MSG)}manyInternal(e,n){let r=768|e;return this.manyInternalLogic(e,n,r)}manyInternalLogic(e,n,r){let i=this.currRuleLookaheadFuncs[r],o;if(typeof n!="function"){o=n.DEF;let s=n.GATE;if(s!==void 0){let c=i;i=()=>s.call(this)&&c.call(this)}}else o=n;let a=!0;for(;i.call(this)===!0&&a===!0;)a=this.doSingleRepetition(o);this.attemptInRepetitionRecovery(this.manyInternal,[e,n],i,768,e,En,a)}manySepFirstInternal(e,n){let r=1280|e;this.manySepFirstInternalLogic(e,n,r)}manySepFirstInternalLogic(e,n,r){let i=n.DEF,o=n.SEP;if(this.currRuleLookaheadFuncs[r].call(this)===!0){i.call(this);let s=()=>this.tokenMatcher(this.LA_FAST(1),o);for(;this.tokenMatcher(this.LA_FAST(1),o)===!0;)this.CONSUME(o),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,o,s,i,Ct],s,1280,e,Ct)}}repetitionSepSecondInternal(e,n,r,i,o){for(;r();)this.CONSUME(n),i.call(this);this.attemptInRepetitionRecovery(this.repetitionSepSecondInternal,[e,n,r,i,o],r,1536,e,o)}doSingleRepetition(e){let n=this.getLexerPosition();return e.call(this),this.getLexerPosition()>n}orInternal(e,n){let r=256|n,i=Array.isArray(e)?e:e.DEF,a=this.currRuleLookaheadFuncs[r].call(this,i);if(a!==void 0)return i[a].ALT.call(this);this.raiseNoAltException(n,e.ERR_MSG)}ruleFinallyStateUpdate(){this.RULE_STACK_IDX--,this.RULE_OCCURRENCE_STACK_IDX--,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName]),this.cstFinallyStateUpdate()}subruleInternal(e,n,r){let i;try{let o=r!==void 0?r.ARGS:void 0;return this.subruleIdx=n,i=e.coreRule.apply(this,o),this.cstPostNonTerminal(i,r!==void 0&&r.LABEL!==void 0?r.LABEL:e.ruleName),i}catch(o){throw this.subruleInternalError(o,r,e.ruleName)}}subruleInternalError(e,n,r){throw $e(e)&&e.partialCstResult!==void 0&&(this.cstPostNonTerminal(e.partialCstResult,n!==void 0&&n.LABEL!==void 0?n.LABEL:r),delete e.partialCstResult),e}consumeInternal(e,n,r){let i;try{let o=this.LA_FAST(1);this.tokenMatcher(o,e)===!0?(this.consumeToken(),i=o):this.consumeInternalError(e,o,r)}catch(o){i=this.consumeInternalRecovery(e,n,o)}return this.cstPostTerminal(r!==void 0&&r.LABEL!==void 0?r.LABEL:e.name,i),i}consumeInternalError(e,n,r){let i,o=this.LA(0);throw r!==void 0&&r.ERR_MSG?i=r.ERR_MSG:i=this.errorMessageProvider.buildMismatchTokenMessage({expected:e,actual:n,previous:o,ruleName:this.getCurrRuleFullName()}),this.SAVE_ERROR(new et(i,n,o))}consumeInternalRecovery(e,n,r){if(this.recoveryEnabled&&r.name==="MismatchedTokenException"&&!this.isBackTracking()){let i=this.getFollowsForInRuleRecovery(e,n);try{return this.tryInRuleRecovery(e,i)}catch(o){throw o.name===br?r:o}}else throw r}saveRecogState(){let e=this.errors,n=this.RULE_STACK.slice(0,this.RULE_STACK_IDX+1);return{errors:e,lexerState:this.exportLexerState(),RULE_STACK:n,CST_STACK:this.CST_STACK}}reloadRecogState(e){this.errors=e.errors,this.importLexerState(e.lexerState);let n=e.RULE_STACK;for(let r=0;r<n.length;r++)this.RULE_STACK[r]=n[r];this.RULE_STACK_IDX=n.length-1,this.RULE_STACK_IDX>=0&&(this.currRuleShortName=this.RULE_STACK[this.RULE_STACK_IDX],this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[this.currRuleShortName])}ruleInvocationStateUpdate(e,n,r){this.RULE_OCCURRENCE_STACK[++this.RULE_OCCURRENCE_STACK_IDX]=r,this.RULE_STACK[++this.RULE_STACK_IDX]=e,this.currRuleShortName=e,this.currRuleLookaheadFuncs=this.lookAheadFuncsCache[e],this.cstInvocationStateUpdate(n)}isBackTracking(){return this.isBackTrackingStack.length!==0}getCurrRuleFullName(){let e=this.currRuleShortName;return this.shortRuleNameToFull[e]}shortRuleNameToFullName(e){return this.shortRuleNameToFull[e]}isAtEndOfInput(){return this.tokenMatcher(this.LA(1),Ae)}reset(){this.resetLexerState(),this.subruleIdx=0,this.currRuleShortName=-1,this.currRuleLookaheadFuncs=[],this.isBackTrackingStack=[],this.errors=[],this.RULE_STACK_IDX=-1,this.RULE_OCCURRENCE_STACK_IDX=-1,this.CST_STACK=[]}onBeforeParse(e){for(let n=0;n<this.maxLookahead+1;n++)this.tokVector.push(_e)}onAfterParse(e){if(this.isAtEndOfInput()===!1){let n=this.LA(1),r=this.errorMessageProvider.buildNotAllInputParsedMessage({firstRedundant:n,ruleName:this.getCurrRuleFullName()});this.SAVE_ERROR(new Bt(r,n))}for(;this.tokVector.at(-1)===_e;)this.tokVector.pop()}};var _n=class{initErrorHandler(e){this._errors=[],this.errorMessageProvider=Object.hasOwn(e,"errorMessageProvider")?e.errorMessageProvider:ue.errorMessageProvider}SAVE_ERROR(e){if($e(e))return e.context={ruleStack:this.getHumanReadableRuleStack(),ruleOccurrenceStack:this.RULE_OCCURRENCE_STACK.slice(0,this.RULE_OCCURRENCE_STACK_IDX+1)},this._errors.push(e),e;throw Error("Trying to save an Error which is not a RecognitionException")}get errors(){return[...this._errors]}set errors(e){this._errors=e}raiseEarlyExitException(e,n,r){let i=this.getCurrRuleFullName(),o=this.getGAstProductions()[i],s=Ut(e,o,n,this.maxLookahead)[0],c=[];for(let u=1;u<=this.maxLookahead;u++)c.push(this.LA(u));let l=this.errorMessageProvider.buildEarlyExitMessage({expectedIterationPaths:s,actual:c,previous:this.LA(0),customUserDescription:r,ruleName:i});throw this.SAVE_ERROR(new $t(l,this.LA(1),this.LA(0)))}raiseNoAltException(e,n){let r=this.getCurrRuleFullName(),i=this.getGAstProductions()[r],o=Pt(e,i,this.maxLookahead),a=[];for(let l=1;l<=this.maxLookahead;l++)a.push(this.LA(l));let s=this.LA(0),c=this.errorMessageProvider.buildNoViableAltMessage({expectedPathsPerAlt:o,actual:a,previous:s,customUserDescription:n,ruleName:this.getCurrRuleFullName()});throw this.SAVE_ERROR(new Dt(c,this.LA(1),s))}};var Fn={description:"This Object indicates the Parser is during Recording Phase"};Object.freeze(Fn);var Io=!0,Oo=255,No=ee({name:"RECORDING_PHASE_TOKEN",pattern:K.NA});Ce([No]);var Mo=Qe(No,`This IToken indicates the Parser is in Recording Phase
101
+ See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,-1,-1,-1,-1,-1,-1);Object.freeze(Mo);var fc={name:`This CSTNode indicates the Parser is in Recording Phase
102
+ See: https://chevrotain.io/docs/guide/internals.html#grammar-recording for details`,children:{}},Pn=class{initGastRecorder(e){this.recordingProdStack=[],this.RECORDING_PHASE=!1}enableRecording(){this.RECORDING_PHASE=!0,this.TRACE_INIT("Enable Recording",()=>{for(let e=0;e<10;e++){let n=e>0?e:"";this[`CONSUME${n}`]=function(r,i){return this.consumeInternalRecord(r,e,i)},this[`SUBRULE${n}`]=function(r,i){return this.subruleInternalRecord(r,e,i)},this[`OPTION${n}`]=function(r){return this.optionInternalRecord(r,e)},this[`OR${n}`]=function(r){return this.orInternalRecord(r,e)},this[`MANY${n}`]=function(r){this.manyInternalRecord(e,r)},this[`MANY_SEP${n}`]=function(r){this.manySepFirstInternalRecord(e,r)},this[`AT_LEAST_ONE${n}`]=function(r){this.atLeastOneInternalRecord(e,r)},this[`AT_LEAST_ONE_SEP${n}`]=function(r){this.atLeastOneSepFirstInternalRecord(e,r)}}this.consume=function(e,n,r){return this.consumeInternalRecord(n,e,r)},this.subrule=function(e,n,r){return this.subruleInternalRecord(n,e,r)},this.option=function(e,n){return this.optionInternalRecord(n,e)},this.or=function(e,n){return this.orInternalRecord(n,e)},this.many=function(e,n){this.manyInternalRecord(e,n)},this.atLeastOne=function(e,n){this.atLeastOneInternalRecord(e,n)},this.ACTION=this.ACTION_RECORD,this.BACKTRACK=this.BACKTRACK_RECORD,this.LA=this.LA_RECORD})}disableRecording(){this.RECORDING_PHASE=!1,this.TRACE_INIT("Deleting Recording methods",()=>{let e=this;for(let n=0;n<10;n++){let r=n>0?n:"";delete e[`CONSUME${r}`],delete e[`SUBRULE${r}`],delete e[`OPTION${r}`],delete e[`OR${r}`],delete e[`MANY${r}`],delete e[`MANY_SEP${r}`],delete e[`AT_LEAST_ONE${r}`],delete e[`AT_LEAST_ONE_SEP${r}`]}delete e.consume,delete e.subrule,delete e.option,delete e.or,delete e.many,delete e.atLeastOne,delete e.ACTION,delete e.BACKTRACK,delete e.LA})}ACTION_RECORD(e){}BACKTRACK_RECORD(e,n){return()=>!0}LA_RECORD(e){return _e}topLevelRuleRecord(e,n){try{let r=new le({definition:[],name:e});return r.name=e,this.recordingProdStack.push(r),n.call(this),this.recordingProdStack.pop(),r}catch(r){if(r.KNOWN_RECORDER_ERROR!==!0)try{r.message=r.message+`
103
+ This error was thrown during the "grammar recording phase" For more info see:
104
+ https://chevrotain.io/docs/guide/internals.html#grammar-recording`}catch{throw r}throw r}}optionInternalRecord(e,n){return Vt.call(this,G,e,n)}atLeastOneInternalRecord(e,n){Vt.call(this,Q,n,e)}atLeastOneSepFirstInternalRecord(e,n){Vt.call(this,J,n,e,Io)}manyInternalRecord(e,n){Vt.call(this,F,n,e)}manySepFirstInternalRecord(e,n){Vt.call(this,Y,n,e,Io)}orInternalRecord(e,n){return pc.call(this,e,n)}subruleInternalRecord(e,n,r){if(Un(n),!e||!Object.hasOwn(e,"ruleName")){let s=new Error(`<SUBRULE${ko(n)}> argument is invalid expecting a Parser method reference but got: <${JSON.stringify(e)}>
105
+ inside top level rule: <${this.recordingProdStack[0].name}>`);throw s.KNOWN_RECORDER_ERROR=!0,s}let i=this.recordingProdStack.at(-1),o=e.ruleName,a=new $({idx:n,nonTerminalName:o,label:r?.LABEL,referencedRule:void 0});return i.definition.push(a),this.outputCst?fc:Fn}consumeInternalRecord(e,n,r){if(Un(n),!xr(e)){let a=new Error(`<CONSUME${ko(n)}> argument is invalid expecting a TokenType reference but got: <${JSON.stringify(e)}>
106
+ inside top level rule: <${this.recordingProdStack[0].name}>`);throw a.KNOWN_RECORDER_ERROR=!0,a}let i=this.recordingProdStack.at(-1),o=new U({idx:n,terminalType:e,label:r?.LABEL});return i.definition.push(o),Mo}};function Vt(t,e,n,r=!1){Un(n);let i=this.recordingProdStack.at(-1),o=typeof e=="function"?e:e.DEF,a=new t({definition:[],idx:n});return r&&(a.separator=e.SEP),Object.hasOwn(e,"MAX_LOOKAHEAD")&&(a.maxLookahead=e.MAX_LOOKAHEAD),this.recordingProdStack.push(a),o.call(this),i.definition.push(a),this.recordingProdStack.pop(),Fn}function pc(t,e){Un(e);let n=this.recordingProdStack.at(-1),r=Array.isArray(t)===!1,i=r===!1?t:t.DEF,o=new Z({definition:[],idx:e,ignoreAmbiguities:r&&t.IGNORE_AMBIGUITIES===!0});Object.hasOwn(t,"MAX_LOOKAHEAD")&&(o.maxLookahead=t.MAX_LOOKAHEAD);let a=i.some(s=>typeof s.GATE=="function");return o.hasPredicates=a,n.definition.push(o),i.forEach(s=>{let c=new H({definition:[]});o.definition.push(c),Object.hasOwn(s,"IGNORE_AMBIGUITIES")?c.ignoreAmbiguities=s.IGNORE_AMBIGUITIES:Object.hasOwn(s,"GATE")&&(c.ignoreAmbiguities=!0),this.recordingProdStack.push(c),s.ALT.call(this),this.recordingProdStack.pop()}),Fn}function ko(t){return t===0?"":`${t}`}function Un(t){if(t<0||t>Oo){let e=new Error(`Invalid DSL Method idx value: <${t}>
107
+ Idx value must be a none negative value smaller than ${Oo+1}`);throw e.KNOWN_RECORDER_ERROR=!0,e}}var Dn=class{initPerformanceTracer(e){if(Object.hasOwn(e,"traceInitPerf")){let n=e.traceInitPerf,r=typeof n=="number";this.traceInitMaxIdent=r?n:1/0,this.traceInitPerf=r?n>0:n}else this.traceInitMaxIdent=0,this.traceInitPerf=ue.traceInitPerf;this.traceInitIndent=-1}TRACE_INIT(e,n){if(this.traceInitPerf===!0){this.traceInitIndent++;let r=new Array(this.traceInitIndent+1).join(" ");this.traceInitIndent<this.traceInitMaxIdent&&console.log(`${r}--> <${e}>`);let{time:i,value:o}=It(n),a=i>10?console.warn:console.log;return this.traceInitIndent<this.traceInitMaxIdent&&a(`${r}<-- <${e}> time: ${i}ms`),this.traceInitIndent--,o}else return n()}};function Lo(t,e){e.forEach(n=>{let r=n.prototype;Object.getOwnPropertyNames(r).forEach(i=>{if(i==="constructor")return;let o=Object.getOwnPropertyDescriptor(r,i);o&&(o.get||o.set)?Object.defineProperty(t.prototype,i,o):t.prototype[i]=n.prototype[i]})})}var _e=Qe(Ae,"",-1,-1,-1,-1,-1,-1);Object.freeze(_e);var ue=Object.freeze({recoveryEnabled:!1,maxLookahead:3,dynamicTokensEnabled:!1,outputCst:!0,errorMessageProvider:Je,nodeLocationTracking:"none",traceInitPerf:!1,skipValidations:!1}),ft=Object.freeze({recoveryValueFunc:()=>{},resyncEnabled:!0}),re;(function(t){t[t.INVALID_RULE_NAME=0]="INVALID_RULE_NAME",t[t.DUPLICATE_RULE_NAME=1]="DUPLICATE_RULE_NAME",t[t.INVALID_RULE_OVERRIDE=2]="INVALID_RULE_OVERRIDE",t[t.DUPLICATE_PRODUCTIONS=3]="DUPLICATE_PRODUCTIONS",t[t.UNRESOLVED_SUBRULE_REF=4]="UNRESOLVED_SUBRULE_REF",t[t.LEFT_RECURSION=5]="LEFT_RECURSION",t[t.NONE_LAST_EMPTY_ALT=6]="NONE_LAST_EMPTY_ALT",t[t.AMBIGUOUS_ALTS=7]="AMBIGUOUS_ALTS",t[t.CONFLICT_TOKENS_RULES_NAMESPACE=8]="CONFLICT_TOKENS_RULES_NAMESPACE",t[t.INVALID_TOKEN_NAME=9]="INVALID_TOKEN_NAME",t[t.NO_NON_EMPTY_LOOKAHEAD=10]="NO_NON_EMPTY_LOOKAHEAD",t[t.AMBIGUOUS_PREFIX_ALTS=11]="AMBIGUOUS_PREFIX_ALTS",t[t.TOO_MANY_ALTS=12]="TOO_MANY_ALTS",t[t.CUSTOM_LOOKAHEAD_VALIDATION=13]="CUSTOM_LOOKAHEAD_VALIDATION"})(re||(re={}));var jt=class t{static performSelfAnalysis(e){throw Error("The **static** `performSelfAnalysis` method has been deprecated. \nUse the **instance** method with the same name instead.")}performSelfAnalysis(){this.TRACE_INIT("performSelfAnalysis",()=>{let e;this.selfAnalysisDone=!0;let n=this.className;this.TRACE_INIT("toFastProps",()=>{Ot(this)}),this.TRACE_INIT("Grammar Recording",()=>{try{this.enableRecording(),this.definedRulesNames.forEach(i=>{let a=this[i].originalGrammarAction,s;this.TRACE_INIT(`${i} Rule`,()=>{s=this.topLevelRuleRecord(i,a)}),this.gastProductionsCache[i]=s})}finally{this.disableRecording()}});let r=[];if(this.TRACE_INIT("Grammar Resolving",()=>{r=fo({rules:Object.values(this.gastProductionsCache)}),this.definitionErrors=this.definitionErrors.concat(r)}),this.TRACE_INIT("Grammar Validations",()=>{if(r.length===0&&this.skipValidations===!1){let i=po({rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),errMsgProvider:Oe,grammarName:n}),o=oo({lookaheadStrategy:this.lookaheadStrategy,rules:Object.values(this.gastProductionsCache),tokenTypes:Object.values(this.tokensMap),grammarName:n});this.definitionErrors=this.definitionErrors.concat(i,o)}}),this.definitionErrors.length===0&&(this.recoveryEnabled&&this.TRACE_INIT("computeAllProdsFollows",()=>{let i=Ti(Object.values(this.gastProductionsCache));this.resyncFollows=i}),this.TRACE_INIT("ComputeLookaheadFunctions",()=>{var i,o;(o=(i=this.lookaheadStrategy).initialize)===null||o===void 0||o.call(i,{rules:Object.values(this.gastProductionsCache)}),this.preComputeLookaheadFunctions(Object.values(this.gastProductionsCache))})),!t.DEFER_DEFINITION_ERRORS_HANDLING&&this.definitionErrors.length!==0)throw e=this.definitionErrors.map(i=>i.message),new Error(`Parser Definition Errors detected:
108
+ ${e.join(`
109
+ -------------------------------
110
+ `)}`)})}constructor(e,n){this.definitionErrors=[],this.selfAnalysisDone=!1;let r=this;if(r.initErrorHandler(n),r.initLexerAdapter(),r.initLooksAhead(n),r.initRecognizerEngine(e,n),r.initRecoverable(n),r.initTreeBuilder(n),r.initGastRecorder(n),r.initPerformanceTracer(n),Object.hasOwn(n,"ignoredIssues"))throw new Error(`The <ignoredIssues> IParserConfig property has been deprecated.
111
+ Please use the <IGNORE_AMBIGUITIES> flag on the relevant DSL method instead.
112
+ See: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#IGNORING_AMBIGUITIES
113
+ For further details.`);this.skipValidations=Object.hasOwn(n,"skipValidations")?n.skipValidations:ue.skipValidations}};jt.DEFER_DEFINITION_ERRORS_HANDLING=!1;Lo(jt,[In,kn,vn,wn,Cn,bn,_n,Pn,Dn]);var Wt=class extends jt{constructor(e,n=ue){let r=Object.assign({},n);r.outputCst=!0,super(e,r)}};var gc=ee({name:"Space",pattern:/[ \t]+/,group:K.SKIPPED}),Ec=ee({name:"Comment",pattern:/%%[^\r\n]*/,group:K.SKIPPED}),pt=ee({name:"Newline",pattern:/\r\n|\r|\n/,line_breaks:!0}),vo=/(?:title|accTitle|accDescr)[ \t]*:[^\r\n]*/y,wo=/accDescr[ \t]*\{[^}]*\}/y,bo=/o--(?![->|/])/y;function Hr(t,e){for(let n=e-1;n>=0&&t[n]!==`
114
+ `&&t[n]!=="\r";n--)if(t[n]!==" "&&t[n]!==" ")return!1;return!0}function yc(t){let e=!1;for(let n=t.indexOf(":")+1;n<t.length;n++){let r=t[n];if(e&&r==="\\")n++;else if(r==='"')e=!e;else if(!e&&r==="%"&&t[n+1]==="%"&&/[ \t]/.test(t[n-1]??""))return n}return t.length}function xc(t,e){if(!Hr(t,e))return null;vo.lastIndex=e;let n=vo.exec(t);return n?[n[0].slice(0,yc(n[0]))]:null}function Ac(t,e){return Hr(t,e)?(wo.lastIndex=e,wo.exec(t)):null}function Tc(t,e){return Hr(t,e)||!/[ \t]/.test(t[e-1]??"")?null:(bo.lastIndex=e,bo.exec(t))}var Co=/\{/y;function Sc(t,e){let n=Math.max(t.lastIndexOf(`
115
+ `,e-1),t.lastIndexOf("\r",e-1))+1;return/^[ \t]*accDescr[ \t]*$/.test(t.slice(n,e))?null:(Co.lastIndex=e,Co.exec(t))}var Gr=ee({name:"OpenBrace",pattern:{exec:Sc},line_breaks:!1,start_chars_hint:["{"],label:'"{"'}),Vr=ee({name:"CloseBrace",pattern:/\}/,label:'"}"'}),zt=ee({name:"AccDescrBlock",pattern:{exec:Ac},line_breaks:!0,start_chars_hint:["a"]}),Xt=ee({name:"Metadata",pattern:{exec:xc},line_breaks:!1,start_chars_hint:["t","a"]}),jr=/"(?:[^"\\\u0000-\u001F]|\\(?:["\\/bfnrt]|u[\da-fA-F]{4}))*"/,Pe=ee({name:"QuotedText",pattern:jr,line_breaks:!1,label:"quoted text"}),Wr=ee({name:"Arrow",pattern:/->/,label:'"->"'}),Kr=ee({name:"Colon",pattern:/:/,label:'":"'}),W=ee({name:"Identifier",pattern:/[a-zA-Z_]\w*(?:-\w+)*/,label:"identifier"}),zr=ee({name:"Header",pattern:/archimate-beta(?![\w-])/,categories:W});function de(t,e){return ee({name:t,pattern:new RegExp(e),longer_alt:W,categories:W})}var Xr=de("Direction","direction"),Yr=de("Layout","layout"),Zr=de("Element","element"),qr=de("Description","description"),Bn=de("Relationship","relationship"),$n=de("Access","access"),Hn=de("Directed","directed"),Gn=de("Label","label"),Qr=de("Note","note"),Jr=de("On","on"),ei=de("Nest","nest"),ti=de("In","in"),ni=de("Via","via"),ri=de("Click","click"),ii=de("Href","href"),_o={"*--":{type:"composition"},"o--":{type:"aggregation"},"@==>":{type:"assignment"},"..|>":{type:"realization"},"-->":{type:"serving"},"..":{type:"access",access:"unspecified"},"<..":{type:"access",access:"read"},"..>":{type:"access",access:"write"},"<..>":{type:"access",access:"readWrite"},"-.->":{type:"influence"},"---":{type:"association"},"--/":{type:"association",directed:!0},"==>":{type:"triggering"},"-.=>":{type:"flow"},"--|>":{type:"specialization"}},Kt=ee({name:"Connector",pattern:K.NA,label:"relationship connector"}),oi=new Map,Rc=Object.entries(_o).sort(([t],[e])=>e.length-t.length).map(([t,e],n)=>{let r='"'+t+'"',i=t==="o--"?ee({name:`Connector${n}`,pattern:{exec:Tc},line_breaks:!1,start_chars_hint:["o"],label:r,categories:Kt}):ee({name:`Connector${n}`,pattern:new RegExp(t.replace(/[.*+?^${}()|[\]\\/]/g,"\\$&")),label:r,categories:Kt});return oi.set(i,e),i}),si=[gc,Ec,pt,zr,zt,Xt,Pe,Kt,...Rc,Wr,Kr,Gr,Vr,Xr,Yr,Zr,qr,Bn,$n,Hn,Gn,Qr,Jr,ei,ti,ni,ri,ii,W],Po=new K(si),$r=/(?:[^"\\\u0000-\u001F]|\\(?:["\\/bfnrt]|u[\da-fA-F]{4}))*/y;function Ic(t,e){$r.lastIndex=e+1,$r.exec(t);let n=$r.lastIndex,r=t[n];return r===void 0||r===`
116
+ `||r==="\r"?"Text is missing its closing double quote.":r==="\\"?'Text contains the invalid escape sequence "'+t.slice(n,n+2)+'". Use "\\\\" for a backslash.':'Text contains a control character. Use an escape sequence such as "\\t" instead.'}function Uo(t,e,n){let r=t.slice(e,e+n),i=String.fromCodePoint(t.codePointAt(e)??65533);return i==="'"?`Unexpected character "'". Use double quotes for text.`:i==='"'?Ic(t,e):i==="{"&&/(?:^|[\r\n])[ \t]*accDescr[ \t]*$/.test(t.slice(0,e))?'The accDescr block is missing its closing "}".':/^[-.=<>@*|/]+$/.test(r)?'"'+r+'" is not a relationship connector.':'Unexpected character "'+i+'".'}var Oc={...Je,buildNoViableAltMessage:t=>t.customUserDescription??Je.buildNoViableAltMessage(t)},ai=class extends Wt{document=this.RULE("document",()=>{this.MANY(()=>this.CONSUME(pt)),this.CONSUME(zr,{ERR_MSG:'Expected the "archimate-beta" diagram header.'}),this.MANY2(()=>{this.CONSUME2(pt),this.OPTION(()=>this.SUBRULE(this.statement))}),this.CONSUME(Ae,{ERR_MSG:"Expected a new line or an ArchiMate declaration (layout, direction, element, description, relationship, connector, note, nest, click, or metadata)."})});statement=this.RULE("statement",()=>{this.OR([{ALT:()=>this.SUBRULE(this.directionStatement)},{ALT:()=>this.SUBRULE(this.layoutStatement)},{ALT:()=>this.SUBRULE(this.elementStatement)},{ALT:()=>this.SUBRULE(this.descriptionStatement)},{ALT:()=>this.SUBRULE(this.relationshipStatement)},{ALT:()=>this.SUBRULE(this.noteStatement)},{ALT:()=>this.SUBRULE(this.nestingStatement)},{ALT:()=>this.SUBRULE(this.clickStatement)},{ALT:()=>this.SUBRULE(this.metadataStatement)},{ALT:()=>this.SUBRULE(this.connectorStatement)}])});blockStatement=this.RULE("blockStatement",()=>{this.OR({DEF:[{ALT:()=>this.SUBRULE(this.elementStatement)},{ALT:()=>this.SUBRULE(this.descriptionStatement)},{ALT:()=>this.SUBRULE(this.relationshipStatement)},{ALT:()=>this.SUBRULE(this.noteStatement)},{ALT:()=>this.SUBRULE(this.nestingStatement)},{ALT:()=>this.SUBRULE(this.clickStatement)},{ALT:()=>this.SUBRULE(this.connectorStatement)}],ERR_MSG:'Expected "}" or a declaration inside the element block (element, description, relationship, connector, note, nest, or click).'})});connectorStatement=this.RULE("connectorStatement",()=>{this.CONSUME(W,{LABEL:"source"}),this.CONSUME(Kt,{LABEL:"connector"}),this.CONSUME2(W,{LABEL:"target"}),this.OPTION(()=>{this.CONSUME(Kr),this.CONSUME(Pe,{LABEL:"labelText"})})});directionStatement=this.RULE("directionStatement",()=>{this.CONSUME(Xr),this.CONSUME(W,{LABEL:"value"})});layoutStatement=this.RULE("layoutStatement",()=>{this.CONSUME(Yr),this.CONSUME(W,{LABEL:"value"})});elementStatement=this.RULE("elementStatement",()=>{this.CONSUME(Zr),this.CONSUME(W,{LABEL:"type"}),this.CONSUME2(W,{LABEL:"id"}),this.CONSUME(Pe,{LABEL:"name"}),this.OPTION(()=>{this.CONSUME(Gr),this.MANY(()=>{this.CONSUME(pt),this.OPTION2(()=>this.SUBRULE(this.blockStatement))}),this.CONSUME(Vr,{ERR_MSG:'Expected "}" on its own line to close the element block.'})})});clickStatement=this.RULE("clickStatement",()=>{this.CONSUME(ri),this.CONSUME(W,{LABEL:"id"}),this.CONSUME(ii),this.CONSUME(Pe,{LABEL:"url"}),this.OPTION(()=>this.CONSUME2(Pe,{LABEL:"tooltip"})),this.OPTION2(()=>this.CONSUME2(W,{LABEL:"target"}))});descriptionStatement=this.RULE("descriptionStatement",()=>{this.CONSUME(qr),this.CONSUME(W,{LABEL:"id"}),this.CONSUME(Pe,{LABEL:"value"})});relationshipStatement=this.RULE("relationshipStatement",()=>{this.CONSUME(Bn),this.CONSUME(W,{LABEL:"type"}),this.CONSUME2(W,{LABEL:"id"}),this.CONSUME3(W,{LABEL:"source"}),this.CONSUME(Wr),this.CONSUME4(W,{LABEL:"target"}),this.OPTION(()=>{this.CONSUME($n),this.CONSUME5(W,{LABEL:"mode"})}),this.OPTION2(()=>this.CONSUME(Hn)),this.OPTION3(()=>{this.CONSUME(Gn),this.CONSUME(Pe,{LABEL:"labelText"})})});metadataStatement=this.RULE("metadataStatement",()=>{this.OR([{ALT:()=>this.CONSUME(Xt,{LABEL:"value"})},{ALT:()=>this.CONSUME(zt,{LABEL:"value"})}])});noteStatement=this.RULE("noteStatement",()=>{this.CONSUME(Qr),this.CONSUME(W,{LABEL:"id"}),this.CONSUME(Pe,{LABEL:"text"}),this.OPTION(()=>{this.CONSUME(Jr),this.CONSUME2(W,{LABEL:"anchor"})})});nestingStatement=this.RULE("nestingStatement",()=>{this.CONSUME(ei),this.CONSUME(W,{LABEL:"child"}),this.CONSUME(ti),this.CONSUME2(W,{LABEL:"parent"}),this.OPTION(()=>{this.CONSUME(ni),this.CONSUME3(W,{LABEL:"relationshipId"})})});constructor(){super(si,{errorMessageProvider:Oc}),this.performSelfAnalysis()}};function D(t,e){let n=t[e]?.[0];if(!n||!("tokenType"in n))throw new Error("Incomplete ArchiMate parse tree.");return n}var Vn=new ai,kc=Vn.getBaseCstVisitorConstructor(),ci=class extends kc{constructor(){super(),this.validateVisitor()}document(e){return(e.statement??[]).flatMap(n=>{if(!("children"in n))throw new Error("Invalid ArchiMate parse tree.");return this.visit(n)})}statement(e){let n=Object.values(e)[0]?.[0];if(!n||!("children"in n))throw new Error("Incomplete ArchiMate statement.");return this.visit(n)}directionStatement(e){return{kind:"direction",value:D(e,"value")}}layoutStatement(e){return{kind:"layout",value:D(e,"value")}}elementStatement(e){let n=D(e,"id"),r={kind:"element",type:D(e,"type"),id:n,name:D(e,"name")},i=(e.blockStatement??[]).map(a=>{if(!("children"in a))throw new Error("Invalid ArchiMate parse tree.");return[this.visit(a)].flat()}),o=i.flatMap(([a])=>a?.kind==="element"?[{kind:"nesting",child:a.id,parent:n}]:[]);return[r,...o,...i.flat()]}blockStatement(e){return this.statement(e)}clickStatement(e){return{kind:"click",id:D(e,"id"),url:D(e,"url"),...e.tooltip&&{tooltip:D(e,"tooltip")},...e.target&&{target:D(e,"target")}}}descriptionStatement(e){return{kind:"description",id:D(e,"id"),value:D(e,"value")}}relationshipStatement(e){return{kind:"relationship",type:D(e,"type"),id:D(e,"id"),source:D(e,"source"),target:D(e,"target"),...e.mode&&{mode:D(e,"mode")},...e.Directed&&{directed:D(e,"Directed")},...e.labelText&&{label:D(e,"labelText")}}}connectorStatement(e){return{kind:"connector",source:D(e,"source"),connector:D(e,"connector"),target:D(e,"target"),...e.labelText&&{label:D(e,"labelText")}}}metadataStatement(e){return{kind:"metadata",value:D(e,"value")}}noteStatement(e){return{kind:"note",id:D(e,"id"),text:D(e,"text"),...e.anchor&&{anchor:D(e,"anchor")}}}nestingStatement(e){return{kind:"nesting",child:D(e,"child"),parent:D(e,"parent"),...e.relationshipId&&{relationshipId:D(e,"relationshipId")}}}},Nc=new ci;function Do(t){Vn.input=t;let e=Vn.document(),n=Vn.errors[0];if(n)return{syntaxError:n};let r=Nc.visit(e);if(!Array.isArray(r))throw new Error("Invalid ArchiMate document parse tree.");return{declarations:r}}var Fo=[$n,Hn,Gn];function Bo(t,e){let n=Fo.indexOf(t.token.tokenType),r=e.indexOf(t.token);if(n<0||r<0)return t.message;let i=r;for(;i>0&&e[i-1]?.tokenType!==pt;)i--;let o=e.slice(i,r);if(o[0]?.tokenType!==Bn)return t.message;let a=o.find(s=>Fo.indexOf(s.tokenType)>n);return a?'"'+t.token.image+'" must come before "'+a.image+'".':t.message}var Ho="#000000",Mc={role:[{d:"M4 3H12A3 5 0 0 1 12 13H4A3 5 0 0 1 4 3Z M12 3A3 5 0 0 0 12 13"}],driver:[{d:"M8 2A6 6 0 1 1 8 14A6 6 0 1 1 8 2Z M8 0.5V15.5 M0.5 8H15.5 M2.5 2.5L13.5 13.5 M13.5 2.5L2.5 13.5"},{d:"M8 6.5A1.5 1.5 0 1 1 8 9.5A1.5 1.5 0 1 1 8 6.5Z",fill:"ink"}],assessment:[{d:"M9.8 1.5A4.8 4.8 0 1 1 9.8 11.1A4.8 4.8 0 1 1 9.8 1.5Z M6.3 9.7L1.5 14.5"}],goal:[{d:"M8 1A7 7 0 1 1 8 15A7 7 0 1 1 8 1Z M8 3.7A4.3 4.3 0 1 1 8 12.3A4.3 4.3 0 1 1 8 3.7Z"},{d:"M8 6.2A1.8 1.8 0 1 1 8 9.8A1.8 1.8 0 1 1 8 6.2Z",fill:"ink"}],outcome:[{d:"M6 5A5 5 0 1 1 6 15A5 5 0 1 1 6 5Z M6 7A3 3 0 1 1 6 13A3 3 0 1 1 6 7Z"},{d:"M14 2L6 10 M6 7V10H9"}],principle:[{d:"M3 1.5H13Q14.5 1.5 14.5 3V13Q14.5 14.5 13 14.5H3Q1.5 14.5 1.5 13V3Q1.5 1.5 3 1.5Z"},{d:"M7.4 4.1H8.6L8.2 9.3H7.8Z M8 11.3A0.7 0.7 0 1 1 8 12.7A0.7 0.7 0 1 1 8 11.3Z",fill:"ink"}],requirement:[{d:"M4 3.5H15L12 12.5H1Z"}],constraint:[{d:"M4 3.5H15L12 12.5H1Z M6.1 3.5L3.1 12.5"}],meaning:[{d:"M4.5 10.5C2.5 10.2 2.2 8 3.7 7.2C2.5 5.3 4.5 3.4 6.3 4.2C7.4 2.8 9.4 2.9 10.4 4.1C12 3.2 14.5 4.2 14 6.3C16 7.6 14.6 10.2 12.9 10.4C12.5 12 10.2 12.3 9.1 11.3C7.8 12.2 5.5 12.2 4.5 10.5Z M3 12A1 1 0 1 1 3 14A1 1 0 1 1 3 12Z M1 14.5H1.1"}],value:[{d:"M8 3.2A7 4.8 0 1 1 8 12.8A7 4.8 0 1 1 8 3.2Z"}],resource:[{d:"M2.5 4H12Q13 4 13 5V11Q13 12 12 12H2.5Q1 12 1 10.5V5.5Q1 4 2.5 4Z M13 6H15V10H13 M4.3 6V10 M7 6V10 M9.7 6V10"}],capability:[{d:"M1 10H5V6H9V2H14V14H1Z M5 10V14 M9 6V14 M5 10H14 M9 6H14"}],valueStream:[{d:"M1 3H9.5L15 8L9.5 13H1L6.5 8Z"}],courseOfAction:[{d:"M10.5 1A4.5 4.5 0 1 1 10.5 10A4.5 4.5 0 1 1 10.5 1Z M10.5 3A2.5 2.5 0 1 1 10.5 8A2.5 2.5 0 1 1 10.5 3Z"},{d:"M1.5 14.5L7.3 8.7 M4.3 8.7H7.3V11.7"}],actor:[{d:"M8 1A2.6 2.6 0 1 1 8 6.2A2.6 2.6 0 1 1 8 1Z M8 6.2V10.7 M4.2 7.7H11.8 M8 10.7L4.4 15 M8 10.7L11.6 15"}],collaboration:[{d:"M6 3A5 5 0 1 1 6 13A5 5 0 1 1 6 3Z M10 3A5 5 0 1 1 10 13A5 5 0 1 1 10 3Z"}],interface:[{d:"M1 8H6 M10.5 3.5A4.5 4.5 0 1 1 10.5 12.5A4.5 4.5 0 1 1 10.5 3.5Z"}],process:[{d:"M1 6H9V2L15 8L9 14V10H1Z"}],function:[{d:"M1.5 7L8 2L14.5 7V13L8 8L1.5 13Z"}],interaction:[{d:"M6.5 2V14A6 6 0 0 1 6.5 2Z M9.5 2V14A6 6 0 0 0 9.5 2Z"}],event:[{d:"M1.5 3H10A5 5 0 0 1 10 13H1.5L4.5 8Z"}],service:[{d:"M5 3.5H11A4.5 4.5 0 0 1 11 12.5H5A4.5 4.5 0 0 1 5 3.5Z"}],object:[{d:"M1.5 3H14.5V13H1.5Z M1.5 6H14.5"}],contract:[{d:"M1.5 3H14.5V13H1.5Z M1.5 5.7H14.5 M1.5 10.3H14.5"}],representation:[{d:"M1.5 3H14.5V12Q11.3 8.7 8 12Q4.7 15.3 1.5 12Z M1.5 6H14.5"}],product:[{d:"M1.5 3H14.5V13H1.5Z M8 3V7H1.5"}],component:[{d:"M4.5 4.8V2H14V14H4.5V11.2 M4.5 9V7 M1 4.8H7V7H1Z M1 9H7V11.2H1Z"}],node:[{d:"M1.5 4.5L4.5 1.5H14.5V11.5L11.5 14.5H1.5Z M1.5 4.5H11.5L14.5 1.5 M11.5 4.5V14.5"}],device:[{d:"M3 2.5H13Q14.5 2.5 14.5 4V10Q14.5 11.5 13 11.5H3Q1.5 11.5 1.5 10V4Q1.5 2.5 3 2.5Z M3 11.5L1.5 14H14.5L13 11.5"}],systemSoftware:[{d:"M4.3 6A5.2 5.2 0 1 1 12 12 M7 5A5.2 5.2 0 1 1 7 15.4A5.2 5.2 0 1 1 7 5Z"}],path:[{d:"M5.4 3.7L1 8L5.4 12.3 M10.6 3.7L15 8L10.6 12.3 M4.8 8H6.6 M9.4 8H11.2"}],communicationNetwork:[{d:"M4.5 3H13L11.5 13H3Z"},{d:"M4.5 1.4A1.6 1.6 0 1 1 4.5 4.6A1.6 1.6 0 1 1 4.5 1.4Z M13 1.4A1.6 1.6 0 1 1 13 4.6A1.6 1.6 0 1 1 13 1.4Z M11.5 11.4A1.6 1.6 0 1 1 11.5 14.6A1.6 1.6 0 1 1 11.5 11.4Z M3 11.4A1.6 1.6 0 1 1 3 14.6A1.6 1.6 0 1 1 3 11.4Z",fill:"ink"}],artifact:[{d:"M2.5 1.5H9.5L13.5 5.5V14.5H2.5Z M9.5 1.5V5.5H13.5"}],equipment:[{d:"M6 5L7 4L9 4.5L9.5 6.3L11.2 7L12.7 6.5L14 8L13.5 9.8L14.5 11.2L13.5 13L11.7 12.8L10.2 14L10 15L7.8 15L7.2 13.8L5.5 13L4.1 13.6L2.6 12.1L3.4 10.6L2.5 9L2.8 7.4L4.7 7.4Z M8.5 7A2.7 2.7 0 1 1 8.5 12.4A2.7 2.7 0 1 1 8.5 7Z"},{d:"M9.5 3L10 1.8L11.4 2L12.2 0.9L13.5 1.5L13.5 2.8L14.8 3.5L14.4 4.8L13.2 4.9L12.7 6 M12.2 2.8A1.4 1.4 0 1 1 12.2 5.6A1.4 1.4 0 1 1 12.2 2.8Z"}],facility:[{d:"M1.5 2H4V9L7.5 7V9L11 7V9L14.5 7V14H1.5Z"}],distributionNetwork:[{d:"M4.5 4L1 8L4.5 12 M11.5 4L15 8L11.5 12 M2.5 6.5H13.5 M2.5 9.5H13.5"}],material:[{d:"M4.5 2H11.5L15 8L11.5 14H4.5L1 8Z M3.5 8L6 4 M10 4L12.5 8 M6 12H10"}],workPackage:[{d:"M8.7 11.1C12.4 8.6 11.1 2.5 6.5 2.5C0.4 2.5 0.1 12.9 6.8 12.9H14.5 M14.5 12.9L11.6 10.7 M14.5 12.9L11.6 15.1"}],deliverable:[{d:"M1.5 3H14.5V12Q11.3 8.7 8 12Q4.7 15.3 1.5 12Z"}],plateau:[{d:"M5 3H15V4.3H5Z M3 7.3H13V8.6H3Z M1 11.6H11V12.9H1Z",fill:"ink"}],gap:[{d:"M8 2.5A5.5 5.5 0 1 1 8 13.5A5.5 5.5 0 1 1 8 2.5Z M0.5 6.2H15.5 M0.5 9.8H15.5"}],grouping:[{d:"M1.5 13V10 M1.5 8.5V5.5 M1.5 4V2H4.5 M6 2H9 M10.5 2H12V5.5 M12 6H15V9 M15 10.5V13H12 M10.5 13H7.5 M6 13H3 M2 6H5 M6.5 6H9.5"}],location:[{d:"M8 1.5A4.5 4.5 0 0 1 12.5 6C12.5 9 9.7 10.5 8 14.7C6.3 10.5 3.5 9 3.5 6A4.5 4.5 0 0 1 8 1.5Z"}]};function v(t,e,n,r,i,o){return{name:t,description:e,category:n,aspect:r,notation:{outline:i,icon:Mc[o]}}}var jn={stakeholder:v("Stakeholder","A party with interests in the architecture and its effects.","motivation","motivation","chamfered","role"),driver:v("Driver","A condition that prompts change and shapes goals.","motivation","motivation","chamfered","driver"),assessment:v("Assessment","A finding about the current situation in light of a driver.","motivation","motivation","chamfered","assessment"),goal:v("Goal","A desired state or direction for the organisation.","motivation","motivation","chamfered","goal"),outcome:v("Outcome","A result produced by a state of affairs or by a change.","motivation","motivation","chamfered","outcome"),principle:v("Principle","A general rule or intent that guides architecture choices.","motivation","motivation","chamfered","principle"),requirement:v("Requirement","A need that the architecture describes for a particular system.","motivation","motivation","chamfered","requirement"),constraint:v("Constraint","A limit on the architecture, its implementation or its realisation.","motivation","motivation","chamfered","constraint"),meaning:v("Meaning","An interpretation of a concept in its particular context.","motivation","motivation","chamfered","meaning"),value:v("Value","The benefit, worth or significance attributed to a concept.","motivation","motivation","chamfered","value"),resource:v("Resource","An asset under a person's or organisation's control.","strategy",null,"rectangle","resource"),capability:v("Capability","Something a person, organisation or system can do.","strategy","behavior","rounded","capability"),valueStream:v("Value Stream","A sequence of activities that produces value for a recipient.","strategy","behavior","rounded","valueStream"),courseOfAction:v("Course of Action","A plan for using capabilities and resources to reach a goal.","strategy","behavior","rounded","courseOfAction"),businessActor:v("Business Actor","A person, organisation or other business entity that can act.","business","activeStructure","rectangle","actor"),businessRole:v("Business Role","A set of responsibilities a business actor can take on.","business","activeStructure","rectangle","role"),businessCollaboration:v("Business Collaboration","Business actors or roles working together to perform shared behaviour.","business","activeStructure","rectangle","collaboration"),businessInterface:v("Business Interface","An access point for a business service.","business","activeStructure","rectangle","interface"),businessProcess:v("Business Process","Ordered business activities that produce a result.","business","behavior","rounded","process"),businessFunction:v("Business Function","Business activities grouped by criteria such as skills or resources.","business","behavior","rounded","function"),businessInteraction:v("Business Interaction","Behaviour that business participants perform jointly.","business","behavior","rounded","interaction"),businessEvent:v("Business Event","A change of state that matters to the business.","business","behavior","rounded","event"),businessService:v("Business Service","Business behaviour exposed to its consumers.","business","behavior","rounded","service"),businessObject:v("Business Object","A concept that carries information in a business domain.","business","passiveStructure","rectangle","object"),contract:v("Contract","An agreement defining obligations and terms for a product or service.","business","passiveStructure","rectangle","contract"),representation:v("Representation","A perceptible form in which a business object's information is expressed.","business","passiveStructure","rectangle","representation"),product:v("Product","Services or passive structure bundled as an offering under an agreement.","business",null,"rectangle","product"),applicationComponent:v("Application Component","A replaceable software module that encapsulates application functionality.","application","activeStructure","rectangle","component"),applicationCollaboration:v("Application Collaboration","Application components working together to perform shared behaviour.","application","activeStructure","rectangle","collaboration"),applicationInterface:v("Application Interface","An access point for an application service.","application","activeStructure","rectangle","interface"),applicationFunction:v("Application Function","Automated behaviour performed by an application component.","application","behavior","rounded","function"),applicationInteraction:v("Application Interaction","Behaviour that application components perform jointly.","application","behavior","rounded","interaction"),applicationProcess:v("Application Process","Ordered application activities that produce a result.","application","behavior","rounded","process"),applicationEvent:v("Application Event","A change of state in an application.","application","behavior","rounded","event"),applicationService:v("Application Service","Application behaviour exposed to its consumers.","application","behavior","rounded","service"),dataObject:v("Data Object","Information organised for automated processing.","application","passiveStructure","rectangle","object"),node:v("Node","A computational or physical resource that hosts or interacts with other resources.","technology","activeStructure","rectangle","node"),device:v("Device","Physical IT equipment that can host software or artifacts.","technology","activeStructure","rectangle","device"),systemSoftware:v("System Software","Software that supplies an environment for running software or using data.","technology","activeStructure","rectangle","systemSoftware"),technologyCollaboration:v("Technology Collaboration","Technology resources working together to perform shared behaviour.","technology","activeStructure","rectangle","collaboration"),technologyInterface:v("Technology Interface","An access point for a technology service.","technology","activeStructure","rectangle","interface"),path:v("Path","A link through which technology resources can exchange information, energy or material.","technology","activeStructure","rectangle","path"),communicationNetwork:v("Communication Network","Infrastructure that connects devices or system software to transmit and route data.","technology","activeStructure","rectangle","communicationNetwork"),technologyFunction:v("Technology Function","A group of activities performed by a technology resource.","technology","behavior","rounded","function"),technologyProcess:v("Technology Process","Ordered technology activities that produce a result.","technology","behavior","rounded","process"),technologyInteraction:v("Technology Interaction","Behaviour that technology resources perform jointly.","technology","behavior","rounded","interaction"),technologyEvent:v("Technology Event","A change of state in the technology layer.","technology","behavior","rounded","event"),technologyService:v("Technology Service","Technology behaviour exposed to its consumers.","technology","behavior","rounded","service"),artifact:v("Artifact","A piece of data used or produced when developing, deploying or running a system.","technology","passiveStructure","rectangle","artifact"),equipment:v("Equipment","Machinery, tools or instruments that act on physical material.","physical","activeStructure","rectangle","equipment"),facility:v("Facility","A physical structure or environment used in operations.","physical","activeStructure","rectangle","facility"),distributionNetwork:v("Distribution Network","Infrastructure that carries material or energy between physical points.","physical","activeStructure","rectangle","distributionNetwork"),material:v("Material","Physical matter or energy involved in the architecture.","physical","passiveStructure","rectangle","material"),workPackage:v("Work Package","A bounded set of actions planned to produce a result.","implementationAndMigration","behavior","rounded","workPackage"),deliverable:v("Deliverable","An identified result produced by a work package.","implementationAndMigration","passiveStructure","rectangle","deliverable"),implementationEvent:v("Implementation Event","A change of state during implementation or migration.","implementationAndMigration","behavior","rounded","event"),plateau:v("Plateau","A relatively stable architecture state within a period of time.","implementationAndMigration",null,"rectangle","plateau"),gap:v("Gap","A difference between two architecture plateaus.","implementationAndMigration",null,"rectangle","gap"),grouping:v("Grouping","A collection of concepts that share a common characteristic.","composite",null,"grouping","grouping"),location:v("Location","A physical or conceptual place where concepts are situated or behaviour occurs.","composite",null,"rectangle","location")};function Wn(t){return Object.hasOwn(jn,t)?jn[t]:void 0}var Kn=["composition","aggregation","assignment","realization","serving","access","influence","association","triggering","flow","specialization"],Go={composition:"Composition",aggregation:"Aggregation",assignment:"Assignment",realization:"Realization",serving:"Serving",access:"Access",influence:"Influence",association:"Association",triggering:"Triggering",flow:"Flow",specialization:"Specialization"},$o={composition:{line:"solid",start:"filledDiamond",end:"none"},aggregation:{line:"solid",start:"openDiamond",end:"none"},assignment:{line:"solid",start:"filledDot",end:"filledArrow"},realization:{line:"dotted",start:"none",end:"openTriangle"},serving:{line:"solid",start:"none",end:"openArrow"},access:{line:"dotted",start:"none",end:"none"},influence:{line:"dashed",start:"none",end:"openArrow"},association:{line:"solid",start:"none",end:"none"},triggering:{line:"solid",start:"none",end:"filledArrow"},flow:{line:"dashed",start:"none",end:"filledArrow"},specialization:{line:"solid",start:"none",end:"openTriangle"}};function zn(t,e="unspecified",n=!1){return t==="access"?{line:"dotted",start:e==="read"||e==="readWrite"?"openArrow":"none",end:e==="write"||e==="readWrite"?"openArrow":"none"}:t==="association"&&n?{line:"solid",start:"none",end:"singleBarb"}:Object.hasOwn($o,t)?$o[t]:void 0}var Lc=new Set(["composition","aggregation","assignment","realization","access"]);function Vo(t,e,n){return t.type==="specialization"?t.source===e&&t.target===n:Lc.has(t.type)&&t.source===n&&t.target===e}function vc(t,e,n){let r=t.child.image,i=t.parent.image,o=n.relationshipsById.get(e.image);if(!o){n.report("INVALID_NESTING",e,'Unknown relationship "'+e.image+'".');return}if(!n.invalidRelationshipIds.has(o.id)){if(!Vo(o,r,i)){n.report("INVALID_NESTING",e,'Relationship "'+e.image+'" does not support nesting "'+r+'" in "'+i+'".');return}return{relationship:o}}}function wc(t,e){let n=t.child.image,r=t.parent.image,i=e.relationships.filter(a=>Vo(a,n,r)),[o]=i;if(i.length<=1)return o?{relationship:o}:{};e.report("INVALID_NESTING",t.parent,`Several relationships can nest "${n}" in "${r}". Declare the intended one with an ID and add "via <relationship-id>".`)}function jo(t,e,n){let{report:r}=n,i=new Map,o=[];for(let s of t){let c=s.child.image,l=s.parent.image,u=[s.child,s.parent].filter(d=>e.get(d.image)?.kind!=="element"),h=u.filter(d=>!n.unknownEndpointIds.has(d.image));for(let d of h)r("INVALID_NESTING",d,'Nesting requires an ArchiMate element. Found "'+d.image+'".');if(u.length>0)continue;if(c===l){r("INVALID_NESTING",s.child,"An element cannot be nested inside itself.");continue}if(i.has(c)){r("INVALID_NESTING",s.child,'Element "'+c+'" already has a nesting parent.');continue}i.set(c,s);let f=s.relationshipId?vc(s,s.relationshipId,n):wc(s,n);f&&o.push({child:c,parent:l,...f.relationship&&{relationship:f.relationship.id}})}let a=new Set;for(let s of i.keys()){let c=new Set,l=s;for(;!a.has(l);){let u=i.get(l);if(!u)break;if(c.has(l)){r("INVALID_NESTING",u.child,'Nesting creates a cycle at "'+l+'".');break}c.add(l),l=u.parent.image}for(let u of c)a.add(u)}return o}function bc(t,e){let n=[],r=Array.from({length:e.length+1},(i,o)=>o);for(let i=1;i<=t.length;i++){let o=[i];for(let a=1;a<=e.length;a++){let s=t[i-1]===e[a-1]?0:1,c=Math.min((r[a]??0)+1,(o[a-1]??0)+1,(r[a-1]??0)+s);i>1&&a>1&&t[i-1]===e[a-2]&&t[i-2]===e[a-1]&&(c=Math.min(c,(n[a-2]??0)+1)),o.push(c)}n=r,r=o}return r[e.length]??0}function Cc(t,e){let n=t.toLowerCase(),r,i=1/0,o=!1;for(let a of e){let s=bc(n,a.toLowerCase());s<i?(r=a,i=s,o=!1):s===i&&(o=!0)}if(!(r===void 0||o))return i<=Math.max(1,Math.floor(r.length/4))?r:void 0}function tt(t,e,n){let r=Cc(e,n);return r===void 0?t:t+' Did you mean "'+r+'"?'}var _c=["TB","TD","BT","LR","RL"],Wo=["architecture","framework","graph"],Ko=["read","write","readWrite","unspecified"],zo=["_blank","_self","_parent","_top"],Pc=new Set(["http","https","mailto"]);function Uc(t,e){switch(t.image){case"TD":case"TB":return"TB";case"BT":case"LR":case"RL":return t.image;default:e("INVALID_DIRECTION",t,tt("Expected direction TB, TD, BT, LR, or RL.",t.image,_c));return}}function Fc(t,e){let n=Wo.find(r=>r===t.image);return n||e("INVALID_LAYOUT",t,tt("Expected layout architecture, framework, or graph.",t.image,Wo)),n}function Dc(t,e){let n=Ko.find(r=>r===t.image);return n||e("INVALID_RELATIONSHIP_PROPERTY",t,tt("Expected access mode read, write, readWrite, or unspecified.",t.image,Ko)),n}function Yo(t,e,n){if(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(t)){n("INVALID_TEXT",e,"Text contains a character that cannot be written to SVG.");return}return t}function nt(t,e,n={}){let{emptyMessage:r,image:i=t.image}=n,o=JSON.parse(i);if(typeof o!="string")throw new Error("Invalid ArchiMate quoted token.");if(r!==void 0&&o.trim()===""){e("INVALID_TEXT",t,r);return}return Yo(o,t,e)}function Bc(t){if(t.tokenType===zt)return{name:"accDescr",key:"accDescription",value:t.image.slice(t.image.indexOf("{")+1,-1).trim().replace(/[ \t]*(?:\r\n|\r|\n)[ \t]*/g,`
117
+ `)};let e=t.image.indexOf(":"),n=t.image.slice(0,e).trim();return{name:n,key:n==="title"?"title":n==="accTitle"?"accTitle":"accDescription",value:t.image.slice(e+1).trim()}}var $c=new RegExp("^"+jr.source+"$");function Hc(t,e,n){switch(t.kind){case"direction":if(e.directionDeclared){n("DUPLICATE_DECLARATION",t.value,"Direction is already set.");return}e.directionDeclared=!0,e.direction=Uc(t.value,n);return;case"layout":if(e.layoutDeclared){n("DUPLICATE_DECLARATION",t.value,"Layout is already set.");return}e.layoutDeclared=!0,e.layout=Fc(t.value,n);return;case"metadata":{let{name:r,key:i,value:o}=Bc(t.value);if(e.declaredMetadata.has(i)){n("DUPLICATE_DECLARATION",t.value,r+" is already set.");return}e.declaredMetadata.add(i);let a=t.value.tokenType===Xt&&$c.test(o)?nt(t.value,n,{emptyMessage:r+" must not be empty.",image:o}):Yo(o,t.value,n);a!==void 0&&(e.metadata[i]=a);return}}}function Gc(t,e,n){if(e.entities.has(t.id.image)){n("DUPLICATE_ID",t.id,'ID "'+t.id.image+'" is already declared.');return}e.entities.set(t.id.image,t),t.kind==="element"?(Wn(t.type.image)||n("UNKNOWN_ELEMENT_TYPE",t.type,tt('Unknown element type "'+t.type.image+'".',t.type.image,Object.keys(jn))),e.elements.push(t)):t.kind==="relationship"?e.relationships.push(t):e.notes.push(t)}function Vc(t,e){let n={settings:{directionDeclared:!1,layoutDeclared:!1,direction:void 0,layout:void 0,declaredMetadata:new Set,metadata:{}},entities:new Map,descriptions:new Map,clicks:new Map,elements:[],relationships:[],notes:[],nesting:[]};for(let r of t)switch(r.kind){case"direction":case"layout":case"metadata":Hc(r,n.settings,e);break;case"description":if(n.descriptions.has(r.id.image)){e("DUPLICATE_DECLARATION",r.id,'Description is already set for "'+r.id.image+'".');break}n.descriptions.set(r.id.image,r);break;case"element":case"relationship":case"note":Gc(r,n,e);break;case"connector":n.relationships.push(r);break;case"nesting":n.nesting.push(r);break;case"click":if(n.clicks.has(r.id.image)){e("DUPLICATE_DECLARATION",r.id,`A link is already set for "${r.id.image}".`);break}n.clicks.set(r.id.image,r);break}return n}function jc(t,e){for(let[n,r]of t.descriptions)t.entities.get(n)?.kind!=="element"&&e("UNKNOWN_ELEMENT",r.id,'Description refers to an undeclared element "'+n+'".');for(let[n,r]of t.clicks)t.entities.get(n)?.kind!=="element"&&e("UNKNOWN_ELEMENT",r.id,`Link refers to an undeclared element "${n}".`)}function Wc(t,e){let n=nt(t.url,e,{emptyMessage:"Link URL must not be empty."}),r=t.tooltip&&nt(t.tooltip,e),i=n?.replace(/[\s\u0000-\u001F]/g,""),o=i&&/^([a-z][a-z\d+.-]*):/i.exec(i)?.[1]?.toLowerCase();if(o!==void 0&&!Pc.has(o)){e("INVALID_LINK",t.url,`Link URL scheme "${o}:" is not allowed. Use http, https or mailto.`);return}let a=t.target?.image,s=zo.find(c=>c===a);if(t.target&&s===void 0){e("INVALID_LINK",t.target,tt(`Unknown link target "${t.target.image}".`,t.target.image,zo));return}if(n!==void 0)return{href:n,...r!==void 0&&{tooltip:r},...s&&{target:s}}}function Kc(t,e){let n=[];for(let r of t.notes){r.anchor&&t.entities.get(r.anchor.image)?.kind!=="element"&&e("INVALID_NOTE_TARGET",r.anchor,"A note must be placed on a declared ArchiMate element.");let i=nt(r.text,e,{emptyMessage:"Note text must not be empty."});i!==void 0&&n.push({id:r.id.image,text:i,...r.anchor&&{on:r.anchor.image}})}return n}function zc(t,e){let n=[];for(let r of t.elements){let i=nt(r.name,e,{emptyMessage:"Element name must not be empty."}),o=t.descriptions.get(r.id.image),a=o&&nt(o.value,e),s=t.clicks.get(r.id.image),c=s&&Wc(s,e);i!==void 0&&n.push({id:r.id.image,type:r.type.image,name:i,...a!==void 0&&{description:a},...c&&{link:c}})}return n}function Xo(t,e){let n=t.entities.get(e.image);if(!n){t.unknownEndpointIds.add(e.image),t.report("UNKNOWN_ELEMENT",e,'Unknown element or note "'+e.image+'".');return}if(n.kind==="relationship"){t.report("UNSUPPORTED_ENDPOINT",e,"Relationship endpoints must be elements or notes.");return}return n}function Xc(t,e){return e&&nt(e,t.report,{emptyMessage:"Relationship label must not be empty. Omit the label instead."})}function Yc(t,e,n,r){let i=e+"__"+n+"__"+r,o=i;for(let a=2;t.usedIds.has(o);a++)o=`${i}_${a}`;return t.usedIds.add(o),o}function Zc(t,e,n){let r=JSON.stringify([e.source.image,e.connector.tokenType.name,e.target.image,n??null]),i=t.shorthandStatements.get(r);if(!i){t.shorthandStatements.set(r,e);return}t.diagnostics.warning("DUPLICATE_RELATIONSHIP",e.source,e.label??e.target,`This relationship repeats the one on line ${t.diagnostics.line(i.source)}. Remove the copy, or use the long form with distinct IDs if both are intended.`)}function qc(t){let e=oi.get(t.connector.tokenType);if(!e)throw new Error('Unknown ArchiMate connector token "'+t.connector.image+'".');return{notation:"shorthand",type:e.type,source:t.source,target:t.target,access:e.access,directed:e.directed===!0,label:t.label,declaredId:void 0,knownType:!0,shorthand:t}}function Qc(t,e){let{report:n}=t,r=e.type.image,i=zn(r)!==void 0;return i||n("UNKNOWN_RELATIONSHIP_TYPE",e.type,tt('Unknown relationship type "'+r+'".',r,Kn)),e.mode&&r!=="access"&&n("INVALID_RELATIONSHIP_PROPERTY",e.mode,"Access mode is only valid on access relationships."),e.directed&&r!=="association"&&n("INVALID_RELATIONSHIP_PROPERTY",e.directed,'"directed" is only valid on association relationships.'),{notation:"longForm",type:r,source:e.source,target:e.target,access:e.mode&&Dc(e.mode,n),directed:e.directed!==void 0,label:e.label,declaredId:e.id,knownType:i,shorthand:void 0}}function Jc(t,e){let n=[Xo(t,e.source),Xo(t,e.target)].every(Boolean),r=Xc(t,e.label),i=e.source.image,o=e.target.image,a=e.declaredId?.image??Yc(t,i,e.type,o),s=e.label!==void 0&&r===void 0;!n||!e.knownType?t.invalidRelationshipIds.add(a):e.shorthand&&!s&&Zc(t,e.shorthand,r);let c=e.access==="unspecified"?void 0:e.access;return{id:a,type:e.type,source:i,target:o,...c&&{access:c},...e.directed&&{directed:!0},...r!==void 0&&{label:r}}}function el(t,e){let n=t.layout??(t.direction===void 0?"architecture":void 0);return{direction:t.direction??"TB",...n&&{layout:n},...t.metadata,elements:e.elements,relationships:e.relationships,...e.notes.length>0&&{notes:e.notes},...e.nesting.length>0&&{nesting:e.nesting}}}function Zo(t,e){let n=(l,u,h)=>{e.error(l,u,h)},r=Vc(t,n);jc(r,n);let i=Kc(r,n),o={diagnostics:e,report:n,entities:r.entities,usedIds:new Set(r.entities.keys()),invalidRelationshipIds:new Set,unknownEndpointIds:new Set,shorthandStatements:new Map},a=r.relationships.map(l=>Jc(o,l.kind==="connector"?qc(l):Qc(o,l))),s=jo(r.nesting,r.entities,{relationships:a,relationshipsById:new Map(a.map(l=>[l.id,l])),invalidRelationshipIds:o.invalidRelationshipIds,unknownEndpointIds:o.unknownEndpointIds,report:n}),c=zc(r,n);if(!e.hasErrors)return el(r.settings,{elements:c,relationships:a,notes:i,nesting:s})}function tl(t,e){let n=t.startsWith("\uFEFF")?t.slice(1):t,r=xi(n),{text:i}=r,o=new tn(i,e.lineOffset??0);if(r.kind==="unclosed")return o.errorAt("SYNTAX_ERROR",o.sourceRange(1,r.column,1,r.column+3),'The frontmatter block is missing its closing "---" line.'),{diagnostics:o.diagnostics};let a=Po.tokenize(i),s=a.errors[0];if(s){let u=s.line??1,h=s.column??1;return o.errorAt("LEXICAL_ERROR",o.sourceRange(u,h,u,h+s.length),Uo(i,s.offset,s.length)),{diagnostics:o.diagnostics}}let c=Do(a.tokens);if("syntaxError"in c){let{syntaxError:u}=c;return o.error("SYNTAX_ERROR",u.token,Bo(u,a.tokens)),{diagnostics:o.diagnostics}}let l=Zo(c.declarations,o);return{...l&&{model:l},diagnostics:o.diagnostics}}function qo(t,e={}){let{model:n,diagnostics:r}=tl(t,e),i=r.find(o=>o.severity==="error");if(i)throw new St(i.code,i.line,i.column,i.message);if(!n)throw new Error("ArchiMate validation produced neither a model nor an error.");return n}function Se(t){let e=[];for(let n of t){let r=e.at(-1);if(r?.x===n.x&&r.y===n.y)continue;let i=e.at(-2);r&&i&&(i.x===r.x&&r.x===n.x||i.y===r.y&&r.y===n.y)&&e.pop(),e.push(n)}return e}var fe=24,Qo=2,Yt=14,ge=9,Ue=14,mt=3,Jo=Ue/16,es=4,gt=8,Te=12,se=12,Xn=1,hi=124,ts=54,ns=20,rs=14,is=48,Me=8,os=12,ss=1.3,as=38,cs=76,ls=200,hs=180,us=240,He="archimate-label",Yn=`${He} archimate-title`,Zn=`${He} archimate-edge-label`;function Et(t){return t==="chamfered"?ge-mt+1:mt}function ds(t){let{x:e,y:n,width:r,height:i}=t;if(e===void 0||n===void 0||r===void 0||i===void 0)throw new Error("ELK did not return a position and size for an ArchiMate element.");return{x:e,y:n,width:r,height:i}}function Fe(t){return t.layout==="architecture"||t.layout==="framework"}function qn(t){return!Fe(t)&&t.direction==="BT"}var fs="http://www.w3.org/2000/svg";function B(t,e,n={}){let r=t.ownerDocument.createElementNS(fs,e);for(let[i,o]of Object.entries(n))r.setAttribute(i,String(o));return t.append(r),r}function ps(t,e){let n=t.ownerDocument.defaultView;if(!n)return;let r=B(t,"g",{visibility:"hidden"});try{return r.style.color=e,r.style.color?n.getComputedStyle(r).color:void 0}finally{r.remove()}}function ms(t,e){let n=e?.securityLevel==="sandbox"?document.getElementById(`i${t}`):null,i=(n instanceof HTMLIFrameElement?n.contentDocument:document)?.querySelector(`svg#${CSS.escape(t)}`);if(i?.namespaceURI!==fs)throw new Error("Mermaid did not create the ArchiMate SVG container.");return i}function Qn(t,e,n,r,i,o,a=!1){let s=B(t,"text",{class:n,fill:o,"text-anchor":"middle","dominant-baseline":"central",...a?{"aria-hidden":"true"}:{}});for(let[c,l]of e.lines.entries())B(s,"tspan",{x:r,y:i+(c-(e.lines.length-1)/2)*e.lineHeight}).textContent=l}function gs(t,{element:e,type:n,notation:r,label:i},o,a,s){let{x:c,y:l,width:u,height:h}=o,{link:f}=e,d=f?B(t,"a",{class:"archimate-link",href:f.href,...f.target&&{target:f.target},...f.target==="_blank"&&{rel:"noopener noreferrer"}}):t,p=B(d,"g",{transform:`translate(${c} ${l})`,"data-archimate-element":e.id,"data-archimate-type":e.type,role:"graphics-symbol","aria-roledescription":n.name,"aria-label":e.name}),m=f?.tooltip??e.description;B(p,"title").textContent=`${n.name}: ${e.name}${m?`
118
+ ${m}`:""}`,e.description&&(B(p,"desc").textContent=e.description);let y=e.type==="location"?s.location:s.elements[n.category],g={class:"archimate-outline",fill:y.fill,stroke:y.stroke,"stroke-width":1.25};if(r.outline==="chamfered"){let E=ge;B(p,"path",{...g,d:`M ${E} 0 H ${u-E} L ${u} ${E} V ${h-E} L ${u-E} ${h} H ${E} L 0 ${h-E} V ${E} Z`})}else r.outline==="grouping"&&(g["stroke-dasharray"]="5 3"),B(p,"rect",{...g,width:u,height:h,rx:r.outline==="rounded"?ge:0});if(r.icon?.length){let E=B(p,"g",{class:"archimate-icon",transform:`translate(${u-Et(r.outline)-Ue} ${mt}) scale(${Jo})`,"aria-hidden":"true",stroke:y.text,"stroke-width":1.15,"stroke-linecap":"round","stroke-linejoin":"round"});for(let x of r.icon)B(E,"path",{d:x.d,fill:x.fill==="ink"?y.text:"none"})}let A=a?gt+i.height/2:h/2;Qn(p,i,He,u/2,A,y.text,!0)}function nl(t,{note:e,label:n},r,i){let{x:o,y:a,width:s,height:c}=r,l=B(t,"g",{transform:`translate(${o} ${a})`,"data-archimate-note":e.id,role:"graphics-symbol","aria-roledescription":"note","aria-label":e.text});B(l,"title").textContent=e.text,B(l,"path",{class:"archimate-note-outline",d:`M 0 0 H ${s-Te} L ${s} ${Te} V ${c} H 0 Z`,fill:i.fill,stroke:i.stroke,"stroke-width":1.25,"stroke-dasharray":"5 3","stroke-linejoin":"round"}),B(l,"path",{d:`M ${s-Te} 0 V ${Te} H ${s} Z`,fill:i.fold}),B(l,"path",{d:`M ${s-Te} 0 V ${Te} H ${s}`,fill:"none",stroke:i.stroke,"stroke-width":1}),Qn(l,n,He,s/2,c/2,i.text,!0)}var rl={filledDiamond:{d:"M 0 0 -6 -4 -12 0 -6 4 Z",fill:"relationship"},openDiamond:{d:"M 0 0 -6 -4 -12 0 -6 4 Z",fill:"canvas"},filledDot:{d:"M 0 0 a 3.5 3.5 0 1 0 -7 0 a 3.5 3.5 0 1 0 7 0 Z",fill:"relationship"},openArrow:{d:"M -8 -4 0 0 -8 4",fill:"none"},filledArrow:{d:"M 0 0 -9 -4 -9 4 Z",fill:"relationship"},openTriangle:{d:"M 0 0 -10 -5 -10 5 Z",fill:"canvas"},singleBarb:{d:"M -8 -4 0 0",fill:"none"}};function Es(t,e,n,r){let i=`${e}-${n}`;if(!t.querySelector(`#${i}`)){let o=B(t,"marker",{id:i,viewBox:"-14 -7 16 14",markerWidth:16,markerHeight:14,markerUnits:"userSpaceOnUse",orient:"auto-start-reverse",refX:0,refY:0}),{d:a,fill:s}=rl[n];r.relationshipOutline&&B(o,"path",{d:a,fill:"none",stroke:r.relationshipOutline,"stroke-width":3,"stroke-linejoin":"round"}),B(o,"path",{d:a,fill:s==="none"?"none":r[s],stroke:r.relationship,"stroke-width":1,"stroke-linejoin":"round"})}return`url(#${i})`}function ys(t,e,n,{relationship:r,notation:i,accessibleName:o},a,s,c,l){let h={d:`M ${a.map(({x:d,y:p})=>`${d} ${p}`).join(" L ")}`,fill:"none",stroke:s.relationship,"stroke-width":1.3};if(i.line==="dashed"?h["stroke-dasharray"]="6 4":i.line==="dotted"&&(h["stroke-dasharray"]="1 3",h["stroke-linecap"]="round"),l?.sharedEnd==="end"&&i.line!=="solid"&&(h["stroke-dashoffset"]=-il(a)),s.relationshipOutline&&c!=="line"&&B(t,"path",{...h,stroke:s.relationshipOutline,"stroke-width":3.3,"aria-hidden":"true"}),c==="outline")return;i.start!=="none"&&(h["marker-start"]=Es(e,n,i.start,s)),i.end!=="none"&&(h["marker-end"]=Es(e,n,i.end,s));let f=B(t,"path",{...h,"data-archimate-relationship":r.id,"data-archimate-type":r.type,role:"graphics-symbol","aria-roledescription":"relationship","aria-label":o});B(f,"title").textContent=o}function il(t){return t.slice(1).reduce((e,n,r)=>{let i=t[r]??n;return e+Math.hypot(n.x-i.x,n.y-i.y)},0)}function ol(t,e,n,r){let{x:i,y:o}=n;B(t,"rect",{x:i,y:o,width:e.width+Me,height:e.height,fill:r.canvas,"aria-hidden":"true"}),Qn(t,e,Zn,i+(e.width+Me)/2,o+e.height/2,r.text,!0)}function xs(t,{id:e,viewport:n,placement:r,edges:i,title:o,palette:a,colours:s,background:c}){let{width:l,height:u,graphWidth:h,left:f,top:d,titleOffset:p,padding:m}=n,y=`archimate-${Array.from(e,x=>x.codePointAt(0)?.toString(16)).join("-")}`,g=B(t,"defs");c==="theme"&&B(t,"rect",{width:l,height:u,fill:s.canvas,"aria-hidden":"true"});let A=B(t,"g",{transform:`translate(${(l-h)/2-f} ${p-d})`});for(let{appearance:x,box:S,compound:I}of r.elements)(I||x.notesHeight>0)&&gs(A,x,S,I,a);let E=new Set;for(let{appearance:x,points:S,bundle:I}of i){if(!I){ys(A,g,y,x,S,s,"both",void 0);continue}if(E.has(I.id))continue;E.add(I.id);let M=i.filter(L=>L.bundle?.id===I.id);for(let L of["outline","line"])for(let O of M)ys(A,g,y,O.appearance,O.points,s,L,I)}for(let{appearance:x,box:S,compound:I}of r.elements)!I&&x.notesHeight===0&&gs(A,x,S,!1,a);for(let{appearance:x,box:S}of r.notes)nl(A,x,S,a.note);for(let{appearance:x,labelPosition:S}of i)x.label&&S&&ol(A,x.label,S,s);o&&Qn(t,o,Yn,l/2,m+o.height/2,s.text)}function yt(t,e){let n=[];for(let r=e.get(t);r!==void 0;r=e.get(r))n.push(r);return n}var sl={TB:"DOWN",BT:"UP",LR:"RIGHT",RL:"LEFT"};function al(t){return Kn.includes(t)}var cl={read:"read",write:"write",readWrite:"read and write"};function ll(t,e){let n=al(t.type)?Go[t.type]:t.type,r=t.type==="access"?t.access&&cl[t.access]:void 0,i=r?` (${r})`:t.type==="association"&&t.directed?" (directed)":"",o=e.get(t.source)??t.source,a=e.get(t.target)??t.target,s=`${o} \u2014 ${n}${i} \u2192 ${a}`;return t.label?`${s}: ${t.label}`:s}function hl(t,e){let n=new Map,r=new Map,i=new Map,o=new Map,a=[];for(let[c,l]of(e.notes??[]).entries()){let u=t.notes[c];if(!u)throw new Error(`The note "${l.id}" was not measured.`);let h={note:l,label:u,width:Math.max(hi,u.width+2*(se+Te)),height:Math.max(is,u.height+2*se)};if(l.on!==void 0){let f=i.get(l.on);f?f.push(h):i.set(l.on,[h])}else{let f=`note${c}`;o.set(l.id,f),r.set(f,h),a.push({id:f,width:h.width,height:h.height})}}let s=new Map;for(let[c,{element:l,type:u,notation:h,label:f}]of t.elements.entries()){let d=`n${c}`,p=h.icon?.length?Et(h.outline)+Ue+es:rs,m=i.get(l.id)??[],y=m.length?m.reduce((E,x)=>E+x.height,0)+(m.length-1)*se-Xn:0,g=Math.max(ts,f.height+ns),A=Math.max(hi,f.width+2*p,...m.map(({width:E})=>E+2*se));n.set(d,{element:l,type:u,notation:h,label:f,headerHeight:g,notesHeight:y}),o.set(l.id,d),s.set(l.id,{id:d,width:A,height:g+y});for(let{note:E}of m)o.set(E.id,d)}return{nodes:n,notes:r,overlays:i,nodeIds:o,elkNodes:s,children:a}}function ul(t,{nodes:e,elkNodes:n,children:r}){let i=new Set,o=qn(t);for(let{parent:a,child:s}of t.nesting??[]){let c=n.get(a),l=n.get(s),u=c&&e.get(c.id);if(!c||!l||!u)throw new Error(`Layout nodes for nesting "${s}" in "${a}" are unavailable.`);if(i.add(l.id),!c.children){c.children=[];let h=u.headerHeight+(o?0:u.notesHeight),f=fe+(o?u.notesHeight:0),p=t.direction==="TB"||t.direction==="BT"?`(${c.height},${c.width})`:`(${c.width},${c.height})`;c.layoutOptions={"elk.padding":`[top=${h},left=${fe},bottom=${f},right=${fe}]`,"elk.nodeSize.constraints":"MINIMUM_SIZE","elk.nodeSize.minimum":p}}c.children.push(l)}for(let a of n.values())i.has(a.id)||r.push(a);return i}function dl(t,e,n,r){let i=new Map,o=new Map,a=new Set(t.nesting?.flatMap(({relationship:d})=>d??[])),s=Fe(t),c=new Map((t.notes??[]).map(d=>[d.id,d.on])),l=[],u=(d,p)=>yt(p??"",r).includes(d),h=(d,p)=>{let m=c.get(d);return m!==void 0&&(u(p,m)||u(m,p))},f=new Map([...t.elements.map(({id:d,name:p})=>[d,p]),...(t.notes??[]).map(({id:d,text:p})=>[d,p])]);for(let[d,p]of t.relationships.entries()){if(a.has(p.id)&&!p.label&&p.access===void 0)continue;let m=n.get(p.source),y=n.get(p.target),g=zn(p.type,p.access,p.directed);if(!m||!y||!g)throw new Error(`SVG notation or endpoints for relationship "${p.id}" are unavailable.`);let A=`e${d}`,E=e.relationshipLabels.get(p.id),x={relationship:p,notation:g,label:E,accessibleName:ll(p,f)},S=!s&&(h(p.source,p.target)||h(p.target,p.source));if(m===y&&p.source!==p.target||S){let I=S?n.get(c.get(p.source)??c.get(p.target)??""):m;if(I===void 0)throw new Error(`The host of the attached note in relationship "${p.id}" is unavailable.`);let M=o.get(I)??0;x.overlayLane=M,x.overlayKey=I,o.set(I,M+1)}i.set(A,x),l.push({id:A,sources:[m],targets:[y],...E?{labels:[{id:`l${d}`,width:E.width+Me,height:E.height}]}:{}})}return{edges:i,overlayLaneCounts:o,relationships:l}}function As(t,e,n){let r=hl(e,t),{nodes:i,notes:o,overlays:a,nodeIds:s,children:c}=r,l=ul(t,r),{edges:u,overlayLaneCounts:h,relationships:f}=dl(t,e,s,n);return{input:{id:"archimate",layoutOptions:{"elk.algorithm":"layered","elk.direction":sl[t.direction],"elk.edgeRouting":"ORTHOGONAL","elk.padding":`[top=${fe},left=${fe},bottom=${fe},right=${fe}]`,"elk.spacing.nodeNode":String(as),"elk.layered.spacing.nodeNodeBetweenLayers":String(cs),"elk.json.shapeCoords":"ROOT","elk.json.edgeCoords":"ROOT",...l.size>0?{"elk.hierarchyHandling":"INCLUDE_CHILDREN"}:{}},children:c,edges:f},nodes:i,notes:o,overlays:a,edges:u,overlayLaneCounts:h,nested:l}}function Ee(t,e){if(t===void 0)throw new Error(`ArchiMate internal error: ${e} is missing.`);return t}function fl(t,e,n){let r=Math.hypot(e.x-t.x,e.y-t.y),i=t.x===e.x,o=Math.sign(i?e.y-t.y:e.x-t.x),a=0;for(let s of n)for(let c=1;c<s.length;c++){let l=s[c-1],u=s[c];if(!l||!u||!(i?l.x===t.x&&u.x===t.x:l.y===t.y&&u.y===t.y))continue;let f=i?t.y:t.x,d=Math.min(i?l.y:l.x,i?u.y:u.x),p=Math.max(i?l.y:l.x,i?u.y:u.x);f<d||f>p||(a=Math.max(a,Math.min(r,o>0?p-f:f-d)))}return a}function pl(t,e,n){let r=n==="start"?[...t]:t.toReversed(),i=n==="start"?e:e.map(o=>o.toReversed());for(let o=1;o<r.length;o++){let a=r[o-1],s=r[o];if(!a||!s)continue;let c=Math.hypot(s.x-a.x,s.y-a.y),l=fl(a,s,i);if(l>=c)continue;let u=l/c,f=[{x:a.x+(s.x-a.x)*u,y:a.y+(s.y-a.y)*u},...r.slice(o)];return n==="start"?f:f.toReversed()}return[...t]}function ml(t,e){let n=t.x+t.width/2,r=t.y+t.height/2;return e.some((i,o)=>{let a=e[o+1];if(!a)return!1;let s=Math.abs(i.x-a.x)>=Math.abs(i.y-a.y),c=s?n:r,l=s?i.x:i.y,u=s?a.x:a.y,h=s?Math.abs(r-(i.y+a.y)/2)-t.height/2:Math.abs(n-(i.x+a.x)/2)-t.width/2;return c>=Math.min(l,u)&&c<=Math.max(l,u)&&h>=0&&h<=8})}function gl(t,e,n,{hint:r,hintNearRoute:i,searchAllSegments:o}){let a=e.width+Me,{height:s}=e,c=({x:h,y:f})=>!n.some(d=>h<d.x+d.width&&h+a>d.x&&f<d.y+d.height&&f+s>d.y);if(r&&c(r)&&(!i||ml({...r,width:a,height:s},t)))return r;let l=[];for(let h=1;h<t.length;h++){let f=t[h-1],d=t[h];f&&d&&l.push({start:f,end:d,length:Math.hypot(d.x-f.x,d.y-f.y)})}l.sort((h,f)=>f.length-h.length);let u;for(let{start:h,end:f}of l){let d=Math.abs(h.x-f.x)>=Math.abs(h.y-f.y),p=d?"x":"y",m=d?"y":"x",y=d?a:s,g=d?s:a,A=(h[p]+f[p]-y)/2,E=Math.min(h[p],f[p])-y/2,x=Math.max(h[p],f[p])-y/2,S=(h[m]+f[m])/2,I=d?[S-s-4,S+4]:[S+4,S-a-4],M=(T,R)=>d?{x:T,y:R}:{x:R,y:T},L=[0,-.5,.5].flatMap(T=>I.map(R=>M(A+T*y,R)));u??=L[0];let O=L.find(c);if(O)return O;if(!o)break;for(let T of I){let k=n.flatMap(N=>{let w=N[m]+(d?N.height:N.width);return T>=w||T+g<=N[m]?[]:[N[p]-y-.5,N[p]+(d?N.width:N.height)+.5]}).filter(N=>N>=E&&N<=x).sort((N,w)=>Math.abs(N-A)-Math.abs(w-A)).map(N=>M(N,T)).find(c);if(k)return k}}return Ee(u,"a label position beside the route")}function Ts(t,e,n){let r=[...e.notes.map(({box:i})=>i),...e.elements.map(({appearance:i,box:o,compound:a})=>a?{...o,height:gt+i.label.height}:o)];return t.map(({id:i,appearance:o,points:a,label:s,bundle:c})=>{let l=n&&o.relationship.source===o.relationship.target,u=c?t.filter(d=>d.bundle?.id===c.id&&d.id!==i).map(d=>d.points):[],h=l?a.slice(1,3):c?pl(a,u,c.sharedEnd):a,f=o.label?gl(h,o.label,r,s):void 0;return n&&f&&o.label&&r.push({...f,width:o.label.width+Me,height:o.label.height}),{appearance:o,points:a,labelPosition:f,bundle:c}})}function El(t,e){let n=new Map;for(let i of t){let o=function(a,s){n.set(a.id,{owner:i,offset:s+a.width/2-i.node.width/2,nested:a!==i.node});for(let c of a.children??[])o(c,s+c.x)};var r=o;o(i.node,0)}return e.flatMap(({source:i,target:o,type:a})=>{let s=n.get(i),c=n.get(o);return s&&c&&s!==c?[{source:s,target:c,type:a}]:[]})}function yl(t,e){let n=new Map;function r(d){let p=d;for(let m=n.get(p);m;m=n.get(p))p=m;return d!==p&&n.set(d,p),p}for(let{source:d,target:p,type:m}of e){if(m!=="triggering")continue;let y=r(d.owner),g=r(p.owner);y!==g&&n.set(g,y)}let i=[...new Set(t.map(r))],o=new Map(i.map(d=>[d,0])),a=new Map,s=new Map,c=new Map;function l(d,p){let m=c.get(d);m?m.push(p):c.set(d,[p])}for(let{source:d,target:p,type:m}of e){let y=r(d.owner),g=r(p.owner);if(y===g)continue;l(y,g),l(g,y);let A=m==="assignment"&&y.row==="technology"&&p.owner.column==="passiveStructure",E=m==="realization"||m==="serving"||A?[g,y]:m==="assignment"&&y.row!=="technology"?[y,g]:void 0;if(!E)continue;let[x,S]=E,I=a.get(x);I||(I=new Set,a.set(x,I)),I.has(S)||(I.add(S),o.set(S,(o.get(S)??0)+1))}let u=new Set(i);function h(d){for(let p of d)if(u.delete(p))for(let m of a.get(p)??[]){if(!u.has(m))continue;s.set(m,Math.max(s.get(m)??0,(s.get(p)??0)+1));let y=(o.get(m)??0)-1;o.set(m,y),y===0&&d.push(m)}}h(i.filter(d=>o.get(d)===0));for(let d of i)u.has(d)&&h([d]);let f=new Map;for(let d of t){let p=r(d),m=c.get(p)??[],y=s.get(p)??(a.has(p)?0:m.reduce((A,E)=>Math.max(A,s.get(E)??0),0)),g=f.get(y);g?g.push(d):f.set(y,[d])}return[...f].sort(([d],[p])=>d-p).map(([,d])=>d)}function xl(t){t.sort((r,i)=>r.center-i.center);let e=t.reduce((r,i)=>r+i.weight,0),n=0;for(let[r,i]of t.entries()){if(n+=i.weight,n<e/2)continue;let o=t[r+1];return{center:n===e/2&&o?(i.center+o.center)/2:i.center,weight:e}}return{center:0,weight:1}}function Al(t,e,n){let r=0,i=t.map(a=>{let s=r+a.width/2;return r+=a.width+n,s}),o=[];for(let[a,s]of t.entries()){let c=i[a]??0,{center:l,weight:u}=e.get(s)??{center:c,weight:1},h={first:a,last:a,mean:l-c,weight:u};for(;;){let f=o.at(-1);if(!f||f.mean<=h.mean)break;o.pop(),h.first=f.first,h.mean=(f.mean*f.weight+h.mean*h.weight)/(f.weight+h.weight),h.weight+=f.weight}o.push(h)}for(let{first:a,last:s,mean:c}of o)for(let l=a;l<=s;l++){let u=t[l];u&&(u.x=(i[l]??0)+c-u.width/2)}}function Rs(t,e){return t.reduce((n,{node:r})=>n+r.width+e,-e)}function Ss(t,e){return Jn([...t].sort((n,r)=>+(r.column==="passiveStructure")-+(n.column==="passiveStructure")),e)}function Tl(t,e,n,r){let i=Rs(t.nodes,n);if(i<=r)return[t];let o=new Map(t.nodes.map(h=>[h.node,h])),a=Math.ceil((i+n)/(r+n)),s=(i+n)/a,c=[],l=[],u=0;for(let h of e){let f=Ee(o.get(h),"the ranked node of a wrapped row"),d=h.width+n;l.length&&(u+d>s+d/2||u+h.width>r)&&(c.push(l),l=[],u=0),l.push(f),u+=d}return c.push(l),c.map(h=>({layer:t.layer,nodes:h}))}function Is(t,e,n,r,i,o){let a=El(t,n),s=a.filter(({source:O,target:T})=>O.owner!==T.owner),c=new Map,l=new Map;for(let O of s){let{source:T,target:R,type:k}=O;for(let{owner:N}of[T,R]){let w=c.get(N);w?w.push(O):c.set(N,[O])}if(k==="triggering"){let N=l.get(T.owner.node.id);N?N.push(R.owner.node.id):l.set(T.owner.node.id,[R.owner.node.id])}}let u=e.flatMap(O=>yl(t.filter(({row:T})=>T===O),s.filter(({source:T,target:R})=>T.owner.row===O&&R.owner.row===O)).flatMap(T=>Tl({layer:O,nodes:T},Ss(T,l),r,o))),h=new Map(u.flatMap(O=>O.nodes.map(T=>[T,O]))),f=new Set;for(let{source:O,target:T,type:R}of a){let k=h.get(O.owner);R==="triggering"&&k&&k===h.get(T.owner)&&f.add(k)}let d=0,p=0,m=!1,y=new Map;for(let[O,T]of u.entries()){let R=Ss(T.nodes,l),k=Rs(T.nodes,r),N=f.has(T);(N&&!m||N===m&&k>p)&&(d=O,p=k,m=N);let w=-k/2;for(let C of R)C.x=w,y.set(C,w+C.width/2),w+=C.width+r}let g=new Set,A=u[d];A&&g.add(A);function E(O){let T=new Map;for(let k of O.nodes){let N=k.node,w=[{center:y.get(N)??0,weight:.25}];for(let{source:C,target:V,type:P}of c.get(k)??[]){let q=C.owner===k?C:V,ie=C.owner===k?V:C,ye=h.get(ie.owner);if(!ye||!g.has(ye))continue;let Ie=ie.owner.node,te=P==="realization"||P==="serving",je=P==="assignment"&&O.layer==="technology"&&q===C;if(ye===O&&P!=="access"&&!je)continue;let _=P==="access"?(Ie.width+N.width)/2+r:0,ne=te?q.nested||ie.nested?10:5:P==="access"?2:1;w.push({center:Ie.x+Ie.width/2+ie.offset-q.offset+(q===C?_:-_),weight:ne})}T.set(N,xl(w))}let R=Jn([...O.nodes].sort((k,N)=>(T.get(k.node)?.center??0)-(T.get(N.node)?.center??0)),l);Al(R,T,r),g.add(O)}for(let O=1;O<u.length;O++){let T=u[d-O],R=u[d+O];T&&E(T),R&&E(R)}for(let O of[u,u.toReversed()])for(let T of O)T!==A&&E(T);let x=0,S=0,I=0,M;for(let O of u){M!==void 0&&(I+=M===O.layer?r:i);let T=O.nodes.reduce((R,{node:k})=>Math.max(R,k.height),0);for(let{node:R}of O.nodes)R.y=I+(T-R.height)/2,x=Math.min(x,R.x),S=Math.max(S,R.x+R.width);I+=T,M=O.layer}let L=t.map(({node:O})=>O);for(let O of L)O.x-=x;return{width:S-x,height:I,children:L}}function Jn(t,e){let n=new Map(t.map(({node:s})=>[s.id,0]));for(let{node:s}of t)for(let c of e.get(s.id)??[]){let l=n.get(c);l!==void 0&&n.set(c,l+1)}let r=new Map(t.map(({node:s})=>[s.id,s])),i=t.filter(({node:s})=>n.get(s.id)===0).map(({node:s})=>s),o=[];function a(){for(let s of i)if(n.delete(s.id)){o.push(s);for(let c of e.get(s.id)??[]){let l=n.get(c),u=r.get(c);l===void 0||!u||(n.set(c,l-1),l===1&&i.push(u))}}i.length=0}a();for(let{node:s}of t)n.has(s.id)&&(i.push(s),a());return o}var Os=["passiveStructure","behavior","activeStructure"],Sl=46,xt=72;function Rl(t,e){return t.reduce((n,r)=>Math.max(n,r[e]),0)}function ks(t,e,n){let r=Rl(t,e?"height":"width"),i=0;for(let a of t)a.x=e?i:(r-a.width)/2,a.y=e?(r-a.height)/2:i,i+=(e?a.width:a.height)+n;let o=Math.max(0,i-n);return{width:e?o:r,height:e?r:o,children:[...t]}}function Il(t,e,n){let r=new Map,i=new Map;for(let l of[...e,"motivation"]){let u=new Map;for(let h of[...Os,null]){let f=t.filter(p=>p.row===l&&p.column===h);if(f.length===0)continue;let d=ks(f.map(({node:p})=>p),!1,n);u.set(h,d),l!=="motivation"&&r.set(h,Math.max(r.get(h)??0,d.width))}i.set(l,u)}let o=new Map,a=0;for(let l of Os){let u=r.get(l);u!==void 0&&(o.set(l,a),a+=u+xt)}a=Math.max(0,a-xt,r.get(null)??0);let s=0;for(let l of e){let u=i.get(l);if(!u?.size)continue;let h=0;for(let[d,p]of o){let m=u.get(d);if(!m)continue;let y=p+((r.get(d)??0)-m.width)/2;for(let g of m.children)g.x+=y,g.y+=s;h=Math.max(h,m.height)}let f=u.get(null);if(f){h&&(h+=n);for(let d of f.children)d.y+=s+h;h+=f.height}s+=h+xt}s=Math.max(0,s-xt);let c=i.get("motivation")?.get(null);if(c){let l=a>0?a+xt:0;for(let u of c.children)u.x+=l;a=l+c.width,s=Math.max(s,c.height)}return{width:a,height:s,children:t.map(({node:l})=>l)}}function Ol(t,e){if(t?.row)return{row:t.row,column:t.column};let n=e[0];return!n||e.some(({row:r})=>r!==n.row)?{row:"neutral",column:null}:{row:n.row,column:e.every(({column:r})=>r===n.column)?n.column:null}}function Ns(t,e,n,{rowOrder:r,padding:i,labelHeight:o,framework:a=!1,maxRowWidth:s}){let c=new Map;for(let{source:m,target:y,type:g}of n){if(g!=="triggering"&&g!=="flow")continue;let A=c.get(m);A?A.push(y):c.set(m,[y])}let l=[...r,"neutral"],u=Math.max(Sl,o+16),h=m=>a?Il(m,l,u):Is(m,["motivation",...l],n,u,xt,s);function f(m){let y=e.get(m.id),g=(m.children??[]).map(f),A=Ol(y,g),E={id:m.id,width:m.width,height:m.height,x:0,y:0};if(!g.length)return{...A,node:E};let x=y?.column==="behavior"?ks(Jn(g,c),!0,u):h(g),S=y?.headerHeight??m.height,I=Math.max(m.width,x.width+2*i),M=Math.max(m.height,S+x.height+2*i);for(let L of x.children)L.x+=(I-x.width)/2,L.y+=S+i;return{...A,node:{...E,width:I,height:M,children:g.map(({node:L})=>L)}}}let d=h(t.map(f));function p(m,y,g){for(let A of m)A.x+=y,A.y+=g,A.children&&p(A.children,A.x,A.y)}return p(d.children,i,i),{...d,width:d.width+2*i,height:d.height+2*i}}var kl=["strategy","business","application","technology","implementationAndMigration"];function Nl(t){return typeof t=="function"}function ui(t,e){return(typeof t=="object"||typeof t=="function")&&t!==null?Reflect.get(t,e):void 0}function Ms(t){let e=[t,ui(t,"default"),ui(ui(t,"default"),"default")].find(Nl);if(!e)throw new Error("The elkjs module did not provide its layout constructor.");return e}var di;function Ml(){return di??=import("./elk.bundled-2VSLVJGB.mjs").then(t=>new(Ms(t))).catch(t=>{throw di=void 0,t}),di}async function Ls(t,{input:e,nodes:n,edges:r},i){let o=Fe(t)?{...e,...Ns(e.children,new Map(Array.from(n,([a,{type:s,headerHeight:c,notesHeight:l}])=>[a,{row:s.category==="composite"?null:s.category==="physical"?"technology":s.category,column:s.aspect==="motivation"?null:s.aspect,headerHeight:c+l}])),e.edges.flatMap(({id:a,sources:[s],targets:[c]})=>{let l=r.get(a)?.relationship.type;return s&&c&&l?[{source:s,target:c,type:l}]:[]}),{rowOrder:kl,padding:fe,labelHeight:Array.from(r.values()).reduce((a,s)=>Math.max(a,s.label?.height??0),0),framework:t.layout==="framework",maxRowWidth:i})}:await(await Ml()).layout(e);if(o.width===void 0||o.height===void 0)throw new Error("ELK did not return the ArchiMate diagram size.");return{root:o,width:o.width,height:o.height}}function Ll(t,e,n){let r=[],i="";for(let o of t.split(/(?<=[-_])/u)){if(n(i+o)<=e){i+=o;continue}if(i&&r.push(i),i="",n(o)<=e){i=o;continue}for(let a of Array.from(o))i&&n(i+a)>e?(r.push(i),i=a):i+=a}return r.push(i),r}function er(t,e,n,r,i){let o=Math.ceil(r*ss);t.setAttribute("class",n);let a=l=>(t.textContent=l,t.getComputedTextLength()||Array.from(l).length*r),s=e.split(/\r\n?|\n/u).flatMap(l=>{if(i===void 0||a(l)<=i)return[l];let u=[],h="";for(let f of l.trim().split(/[^\S\u00a0\u2007\u202f]+/u)){let d=h?`${h} ${f}`:f;if(!h||a(d)<=i?h=d:(u.push(h),h=f),a(h)>i){let p=Ll(h,i,a);h=p.pop()??"",u.push(...p)}}return u.push(h),u}),c=Math.max(...s.map(a));return{lines:s,width:Math.ceil(c),height:s.length*o,lineHeight:o}}function vs(t,e,n,r){let i=B(t,"text",{visibility:"hidden"});try{let o=n?er(i,n,Yn,r.titleSize):void 0,a=(e.notes??[]).map(l=>er(i,l.text,He,r.labelSize,us)),s=e.elements.map(l=>{let u=Wn(l.type);if(!u?.notation)throw new Error(`SVG notation for element type "${l.type}" is not implemented.`);let h=er(i,l.name,He,r.labelSize,ls);return{element:l,type:u,notation:u.notation,label:h}}),c=new Map(e.relationships.flatMap(l=>l.label?[[l.id,er(i,l.label,Zn,r.edgeLabelSize,hs)]]:[]));return{title:o,notes:a,elements:s,relationshipLabels:c}}finally{i.remove()}}function ws(t,e,n){let r=qn(t),i=[],o=[],a=new Map;function s(l){for(let u of l){let h=ds(u),f=n.notes.get(u.id);if(f){o.push({appearance:f,box:h}),a.set(f.note.id,{box:h,outline:"note"});continue}let d=n.nodes.get(u.id);if(!d)throw new Error("ELK returned an unknown ArchiMate element.");let p={...h,y:h.y+(r?0:d.notesHeight),height:h.height-d.notesHeight};i.push({appearance:d,box:p,compound:!!u.children?.length}),a.set(d.element.id,{box:p,outline:d.notation.outline});let m=r?p.y+p.height-Xn:h.y;for(let y of n.overlays.get(d.element.id)??[]){let g={x:p.x+p.width-y.width-se,y:m,width:y.width,height:y.height};o.push({appearance:y,box:g}),a.set(y.note.id,{box:g,outline:"note",overlayHost:p}),m+=y.height+se}u.children&&s(u.children)}}s(e.children??[]);let c=new Map(i.filter(({compound:l})=>l).map(({appearance:{element:l,label:u,notation:h},box:f})=>{let d={x:f.x+(f.width-u.width)/2,y:f.y+gt,width:u.width,height:u.height},p={x:f.x+f.width-Et(h.outline)-Ue,y:f.y+mt,width:Ue,height:Ue};return[l.id,h.icon?.length?[d,p]:[d]]}));return{elements:i,notes:o,endpoints:a,decorations:c}}var X=14,rt=20,Re=8,Zt=14,bs=32,fi=24,Cs=1.3,De={comfortable:8,tight:2},pi=160,_s=3;function Ge(t){return t==="x"?"y":"x"}function At(t,e=0){return{left:t.x-e,right:t.x+t.width+e,top:t.y-e,bottom:t.y+t.height+e}}function qt(t,e,n){if(t.y===e.y){let o=Math.min(t.x,e.x),a=Math.max(t.x,e.x);return n.some(s=>s.top<t.y&&t.y<s.bottom&&o<s.right&&a>s.left)}let r=Math.min(t.y,e.y),i=Math.max(t.y,e.y);return n.some(o=>o.left<t.x&&t.x<o.right&&r<o.bottom&&i>o.top)}function tr(t,e,n){let r=Math.min(X,t.width/4),i=Math.min(X,t.height/4),o=t.x+r+e*(t.width-2*r),a=t.y+i+e*(t.height-2*i),s=t.x+t.width,c=t.y+t.height,l=n?-X:X,u=[{anchor:{x:o,y:c},lead:{x:o,y:c+l},axis:"y",cost:0},{anchor:{x:t.x,y:a},lead:{x:t.x-l,y:a},axis:"x",cost:0},{anchor:{x:s,y:a},lead:{x:s+l,y:a},axis:"x",cost:0}];return n||u.push({anchor:{x:o,y:t.y},lead:{x:o,y:t.y-l},axis:"y",cost:0}),u}function it(t,e,n=!1){let r=0,i=t.length;for(;r<i;){let o=r+i>>>1,a=t[o]??1/0;a<e||n&&a===e?r=o+1:i=o}return r}function Qt(t,e){return e==="x"?t.width:t.height}function Ve(t,e){return Math.hypot(t.x-e.x,t.y-e.y)}var Jt={top:"bottom",bottom:"top",left:"right",right:"left"};function vl(t,e){return{top:e.y+e.height<=t.y,bottom:e.y>=t.y+t.height,left:e.x+e.width<=t.x,right:e.x>=t.x+t.width}}function nr(t,e,n){let r=vl(e,n),i=r.top||r.bottom;return t.map(o=>{let a=rr(e,o.anchor),s=r[a]?o.axis==="x"&&i?rt:0:r[Jt[a]]?3*rt:rt;return{...o,cost:s}})}function rr(t,e){return e.x===t.x?"left":e.x===t.x+t.width?"right":e.y===t.y?"top":"bottom"}function ae(t){return{x:t.x+t.width/2,y:t.y+t.height/2}}function ir(t,e,n){let r=t.x+t.width,i=t.y+t.height;switch(e){case"top":return{anchor:{x:n,y:t.y},lead:{x:n,y:t.y-X},axis:"y",cost:0};case"bottom":return{anchor:{x:n,y:i},lead:{x:n,y:i+X},axis:"y",cost:0};case"left":return{anchor:{x:t.x,y:n},lead:{x:t.x-X,y:n},axis:"x",cost:0};case"right":return{anchor:{x:r,y:n},lead:{x:r+X,y:n},axis:"x",cost:0}}}function mi({type:t,access:e,directed:n}){return{type:t,access:e??"unspecified",directed:n??!1}}function Tt(t,e){return yt(t,{get:n=>e.get(n)?.parent})}function Le(t,e){let n=t.get(e);if(!n)throw new Error(`Missing endpoint "${e}" for an ArchiMate relationship.`);return n.box}function Ps(){let t=new Map;function e(r,i,o,a){return!(t.get(r)?.get(rr(i,o))??[]).some(s=>Math.abs(s.point.x-o.x)+Math.abs(s.point.y-o.y)<(a||s.marker?Zt:Re))}function n(r,i,o,a){let s=t.get(r);s||(s=new Map,t.set(r,s));let c=rr(i,o),l=s.get(c);l?.some(u=>u.point.x===o.x&&u.point.y===o.y)||(l?l.push({point:o,marker:a}):s.set(c,[{point:o,marker:a}]))}return{clear:e,reserve:n}}function gi(t,e,n){let r=Math.max(0,Math.min(X,(e-(n+1)*Re)/2));return Array.from({length:n},(i,o)=>t+r+(o+1)*(e-2*r)/(n+1))}function Us(t,e,n){let r=new Map,i=[],o=(s,c)=>s.x<=c.x&&s.y<=c.y&&s.x+s.width>=c.x+c.width&&s.y+s.height>=c.y+c.height,a=new Map;for(let s of e.values()){let c=JSON.stringify([s.element,s.side]);a.set(c,[...a.get(c)??[],s])}for(let s of a.values()){let[c]=s;if(!c)continue;let l=Le(t,c.element),u=ae(l),h=T=>T.members.map(R=>Le(t,T.sharedEnd==="start"?R.target:R.source)),f=c.side==="left"?l.x:l.x+l.width,d=T=>{let R=[...t.values()].map(k=>k.box).filter(k=>k!==T&&k!==l&&!o(k,T)&&!o(k,l)&&k.x<T.x+T.width&&k.x+k.width>T.x&&(T.y<u.y?k.y>=T.y+T.height&&k.y+k.height<=u.y:k.y+k.height<=T.y&&k.y>=u.y));return R.length?c.side==="left"?Math.max(...R.map(k=>k.x+k.width)):Math.min(...R.map(k=>k.x)):ae(T).x},p=T=>Math.max(...h(T).map(R=>Math.abs(d(R)-f))),m=c.side==="top"||c.side==="bottom",y=m?"x":"y",g=m?l.width:l.height,A=Math.min(X,g/4),E=T=>{let[R]=h(T).toSorted((w,C)=>Ve(ae(w),u)-Ve(ae(C),u));if(!R)return;let k=Math.max(l[y]+A,R[y]+A),N=Math.min(l[y]+g-A,R[y]+(m?R.width:R.height)-A);return k<=N?(k+N)/2:void 0},x,S;if(m){x=s.toSorted((R,k)=>Math.min(...h(R).map(N=>ae(N).x))-Math.min(...h(k).map(N=>ae(N).x)));let T=gi(l[y],g,x.length);S=x.map((R,k)=>E(R)??Ee(T[k],"an evenly spread anchor"))}else{let T=s.filter(P=>E(P)!==void 0).toSorted((P,q)=>Ee(E(P),"a straight anchor")-Ee(E(q),"a straight anchor")),R=s.filter(P=>!T.includes(P)),k=R.filter(P=>h(P).filter(q=>ae(q).y<u.y).length*2>=P.members.length).toSorted((P,q)=>p(P)-p(q)),N=R.filter(P=>!k.includes(P)).toSorted((P,q)=>p(q)-p(P));x=[...k,...T,...N];let w=g/2,C=gi(l.y,w,k.length),V=gi(u.y,w,N.length);S=[...C,...T.map(P=>Ee(E(P),"a straight anchor")),...V]}let I=l[y]+A,M=l[y]+g-A,L=Math.min(Zt,(M-I)/Math.max(1,x.length-1));for(let T=0;T<S.length;T++)S[T]=Math.max(Ee(S[T],"an anchor position"),I,(S[T-1]??-1/0)+L);for(let T=S.length-1;T>=0;T--)S[T]=Math.min(Ee(S[T],"an anchor position"),M,(S[T+1]??1/0)-L);for(let[T,R]of x.entries()){let k=ir(l,R.side,Ee(S[T],"an anchor position"));r.set(R.id,k),n.reserve(R.element,l,k.anchor,R.marker)}let O=c.side==="left"||c.side==="right"?x.toSorted((T,R)=>p(T)-p(R)):x;i.push(...O)}return{ports:r,order:i}}function wl(t,e){return e.x<t.x+t.width&&e.x+e.width>t.x?e.y<t.y?"top":"bottom":ae(e).x<ae(t).x?"left":"right"}function Fs(t,e,n){return t==="top"?"bottom":t==="bottom"?"top":n.y+n.height<=e.y?"bottom":n.y>=e.y?"top":Jt[t]}function Ds(t,e){let n=e.filter(c=>c.bundling===void 0||c.source===c.target?!1:!Tt(c.source,t).includes(c.target)&&!Tt(c.target,t).includes(c.source)),r=new Map,i=({bundling:c})=>[c?.type,c?.access,c?.directed],o=c=>[{key:JSON.stringify([c.source,...i(c),"start"]),element:c.source,sharedEnd:"start"},{key:JSON.stringify([c.target,...i(c),"end"]),element:c.target,sharedEnd:"end"}];for(let c of n)for(let{key:l}of o(c))r.set(l,[...r.get(l)??[],c]);let a=new Map;for(let{source:c,target:l}of n)for(let u of[c,l])a.set(u,(a.get(u)??0)+1);let s=new Map;for(let c of n){let[l,u]=o(c);if(!l||!u)continue;let h=r.get(l.key)?.length??0,f=r.get(u.key)?.length??0,d=a.get(c.source)??0,p=a.get(c.target)??0,m=Math.max(h,f)>=2?h>=f?l:u:Math.max(d,p)>=_s?d>=p?l:u:void 0;if(!m)continue;let y=m.sharedEnd==="start"?c.target:c.source,g=wl(Le(t,m.element),Le(t,y)),A=JSON.stringify([m.key,g]),E=s.get(A),x=S=>m.sharedEnd==="start"?S.target:S.source;E?.members.some(S=>x(S)===y)||(E?E.members.push(c):s.set(A,{id:A,element:m.element,side:g,sharedEnd:m.sharedEnd,members:[c],marker:(m.sharedEnd==="start"?c.sourceMarker:c.targetMarker)??!1}))}return s}function Bs(){let t={x:new Map,y:new Map},e={x:new Map,y:new Map};function n(r,i){let o=e[r].get(i);if(o)return o;let a=[],s=[];for(let[l,u]of t[r]){let h=Math.abs(i-l);if(!(h>=Re))for(let[f,d,p]of u)a.push({from:f,to:d,weight:1-h/Re,owner:p,shared:h===0})}for(let[l,u]of t[Ge(r)])for(let[h,f]of u)h<i&&i<f&&s.push(l);s.sort((l,u)=>l-u);let c={parallel:a,crossings:s};return e[r].set(i,c),c}return{cost(r,i,o,a){let{parallel:s,crossings:c}=n(r,i[Ge(r)]),l=Math.min(i[r],o[r]),u=Math.max(i[r],o[r]),h=0,f=0;for(let d of s){let p=Math.max(0,Math.min(u,d.to)-Math.max(l,d.from));a===void 0||d.owner!==a?h+=2*d.weight*p:d.shared&&(f=Math.max(f,p))}return h-f/2+bs*(it(c,u)-it(c,l))},add(r,i,o,a,s){let c=t[r].get(i);c?c.push([o,a,s]):t[r].set(i,[[o,a,s]]);for(let[l,{parallel:u}]of e[r]){let h=Math.abs(l-i);h<Re&&u.push({from:o,to:a,weight:1-h/Re,owner:s,shared:h===0})}for(let[l,{crossings:u}]of e[Ge(r)])o<l&&l<a&&u.splice(it(u,i),0,i)}}}function bl(t,e){let n=t.length;for(t.push(e);n>0;){let r=Math.floor((n-1)/2),i=t[r];if(!i||i.priority<=e.priority)break;t[n]=i,n=r}t[n]=e}function Cl(t){let e=t[0],n=t.pop();if(!n||t.length===0)return e;let r=0;for(;;){let i=r*2+1,o=i+1,a=t[i],s=t[o];if(!a)break;let c=s&&s.priority<a.priority?o:i,l=t[c];if(!l||n.priority<=l.priority)break;t[r]=l,r=c}return t[r]=n,e}function _l(t,e,n){function r(s,c,l){let u=t.map(y=>y[s]);for(let y of e)u.push(y[c],y[l]);let h=[...new Set(u)].sort((y,g)=>y-g),f=h[0]??0,d=h.at(-1)??0,p=n?.[c]??f-X,m=n?.[l]??d+X;return[...new Set([p,...h,m])].filter(y=>y>=p&&y<=m).sort((y,g)=>y-g)}let i=r("x","left","right"),o=r("y","top","bottom"),a={x:new Map,y:new Map};return{xs:i,ys:o,columns:new Map(i.map((s,c)=>[s,c])),rows:new Map(o.map((s,c)=>[s,c])),blockedSteps(s,c){let l=a[s].get(c);if(l)return l;let u=s==="x"?i:o,h=new Uint8Array(Math.max(0,u.length-1));for(let f of e){let[d,p,m,y]=s==="x"?[f.left,f.right,f.top,f.bottom]:[f.top,f.bottom,f.left,f.right];m<c&&c<y&&h.fill(1,Math.max(0,it(u,d,!0)-1),it(u,p))}return a[s].set(c,h),h}}}function Ei(t,e,n,r,i){if(!t.length||!e.length)return;let{xs:o,ys:a,columns:s,rows:c,blockedSteps:l}=_l([...t,...e].map(({lead:g})=>g),n,i),u=[],h=new Map,f=(g,A,E)=>(A*o.length+g)*2+ +(E==="y");function d(g,A,E,x,S,I){let M=o[g],L=a[A];if(M===void 0||L===void 0)return;let O=f(g,A,E);if((h.get(O)??1/0)<=x)return;h.set(O,x);let T=1/0;for(let{lead:R}of e)T=Math.min(T,Math.abs(M-R.x)+Math.abs(L-R.y));bl(u,{column:g,row:A,axis:E,distance:x,priority:x+Cs*T,...S&&{previous:S},...I&&{port:I}})}for(let g of t){let A=s.get(g.lead.x),E=c.get(g.lead.y);A!==void 0&&E!==void 0&&d(A,E,g.axis,g.cost,void 0,g)}let p,m;for(;(m=Cl(u))&&!(p&&m.priority>=p.cost);){if(m.distance!==h.get(f(m.column,m.row,m.axis)))continue;let g=o[m.column],A=a[m.row];if(g===void 0||A===void 0)continue;let E={x:g,y:A};for(let S of e){if(S.lead.x!==g||S.lead.y!==A)continue;let I=m.distance+S.cost+(S.axis===m.axis?0:rt);(!p||I<p.cost)&&(p={state:m,port:S,cost:I})}let x=[[m.column-1,m.row,"x"],[m.column+1,m.row,"x"],[m.column,m.row-1,"y"],[m.column,m.row+1,"y"]];for(let[S,I,M]of x){let L=o[S],O=a[I];if(L===void 0||O===void 0)continue;let T={x:L,y:O},R=M==="x"?Math.min(S,m.column):Math.min(I,m.row);if(l(M,M==="x"?A:g)[R])continue;let k=m.distance+Math.abs(E[M]-T[M])+(M===m.axis?0:rt)+r(M,E,T);d(S,I,M,k,m)}}if(!p)return;let y=[p.port.anchor];for(let g=p.state;g;g=g.previous){let A=o[g.column],E=a[g.row];if(A===void 0||E===void 0)throw new Error("Invalid orthogonal routing point.");y.push({x:A,y:E}),g.port&&y.push(g.port.anchor)}return Se(y.reverse())}function $s(t,e,n,r,i,{gap:o,parallel:a}){for(let s of["x","y"]){let c=Ge(s),l=Qt(t,c),u=Qt(e,c),h=Math.min(X,l/4),f=Math.min(X,u/4),d=Math.max(t[c]+h,e[c]+f),p=Math.min(t[c]+l-h,e[c]+u-f);if(p<d)continue;let m=t[s]<e[s],y=m?t[s]+Qt(t,s):t[s],g=m?e[s]:e[s]+Qt(e,s);if((m?g-y:y-g)<X)continue;let A=(d+p)/2,E=Math.max(o,(p-d)/(a+1)),x=a>1?Array.from({length:a},(I,M)=>M+1).flatMap(I=>[A-I*E,A+I*E]):[],S=[A,t[c]+l/2,e[c]+u/2,...x,A-o,A+o,d,p];for(let I of S){if(I<d||I>p)continue;let M=s==="x"?{x:y,y:I}:{x:I,y},L=s==="x"?{x:g,y:I}:{x:I,y:g};if(i(M,L)&&!qt(M,L,n)&&r(s,M,L)===0)return[M,L]}}}function Hs(t,e){let n=fi+e*Re,r=Math.min(X,t.height/4),i=Math.min(fi,t.width/2),o=t.x,a=t.x+t.width,s=t.y,c=t.y+t.height;return[[a,1],[o,-1]].flatMap(([l,u])=>{let h=l+u*n,f=l-u*i;return[[{x:l,y:s+r},{x:h,y:s+r},{x:h,y:s-n},{x:f,y:s-n},{x:f,y:s}],[{x:l,y:c-r},{x:h,y:c-r},{x:h,y:c+n},{x:f,y:c+n},{x:f,y:c}]]})}function Pl(t,e,n){let r=new Map;for(let{source:s,target:c}of e)for(let l of[s,c])r.set(l,(r.get(l)??0)+1);let i=new Map,o=({source:s,target:c})=>JSON.stringify([s,c].sort()),a=new Map;for(let s of e)a.set(o(s),(a.get(o(s))??0)+1);return{nodes:t,warn:n,congestion:Bs(),anchors:Ps(),routes:new Map,bundles:new Map,portFraction(s){let c=(i.get(s)??0)+1;return i.set(s,c),c/((r.get(s)??0)+1)},parallelCount:s=>a.get(o(s))??1}}function Gs(t,e){let{nodes:n,congestion:r,anchors:i,routes:o,warn:a}=t,s=n.get(e.source),c=n.get(e.target);if(!s||!c)throw new Error(`Missing endpoints for relationship "${e.id}".`);let l=s.box,u=c.box,h=e.sourceMarker??!1,f=e.targetMarker??!1,d=Tt(e.source,n),p=Tt(e.target,n),m=new Set([...d,...p]),y=d.includes(e.target),g=p.includes(e.source),A=y?e.target:g?e.source:d.find(L=>p.includes(L)),E=A===void 0?void 0:n.get(A)?.box,x=L=>[...n].flatMap(([O,T])=>(m.has(O)?T.decorations??[]:[T.box]).map(R=>({id:O,...At(R,L)})));function S(L,O,T,R,k){let N=x(T),w=(_,ne)=>!qt(_.anchor,_.lead,N.filter(We=>We.id!==ne||m.has(ne))),C=L.filter(_=>w(_,e.source)&&(!R.start||i.clear(e.source,l,_.anchor,h))),V=O.filter(_=>w(_,e.target)&&(!R.end||i.clear(e.target,u,_.anchor,f))),P=(_,ne,We)=>r.cost(_,ne,We,k),q=E&&At(E,-T),ie=At(l,pi),ye=At(u,pi),Ie=q??{left:-1/0,right:1/0,top:-1/0,bottom:1/0},te={left:Math.max(Math.min(ie.left,ye.left),Ie.left),right:Math.min(Math.max(ie.right,ye.right),Ie.right),top:Math.max(Math.min(ie.top,ye.top),Ie.top),bottom:Math.min(Math.max(ie.bottom,ye.bottom),Ie.bottom)},je=N.filter(_=>_.left<te.right&&_.right>te.left&&_.top<te.bottom&&_.bottom>te.top);return(je.length<N.length?Ei(C,V,je,P,te):void 0)??Ei(C,V,N,P,q)}function I(L,O){let[T]=L.flatMap(R=>O.map(k=>[R.anchor,k.anchor])).sort(([R,k],[N,w])=>Ve(R,k)-Ve(N,w));if(!T)throw new Error(`Relationship "${e.id}" has no ports to connect.`);return a?.(`ArchiMate could not find an orthogonal route for relationship "${e.id}" and drew a direct line.`),[...T]}function M(L,O){let T=L[0],R=L.at(-1);if(!T||!R||L.length<2)throw new Error(`Route for relationship "${e.id}" has fewer than two points.`);i.reserve(e.source,l,T,h),i.reserve(e.target,u,R,f),o.set(e.id,[...L]);for(let k=1;k<L.length;k++){let N=L[k-1],w=L[k];if(!N||!w)continue;let C=N.y===w.y?"x":"y",V=N[Ge(C)];r.add(C,V,Math.min(N[C],w[C]),Math.max(N[C],w[C]),O)}}return{sourceBox:l,targetBox:u,sourceMarker:h,targetMarker:f,sourceInsideTarget:y,targetInsideSource:g,frame:E,obstaclesFor:x,search:S,fallback:I,record:M}}function Ul(t,e){let{anchors:n,congestion:r,portFraction:i}=t,o=[],a=new Map;for(let s of e){let{sourceBox:c,targetBox:l,sourceMarker:u,targetMarker:h,sourceInsideTarget:f,targetInsideSource:d,frame:p,obstaclesFor:m,search:y,fallback:g,record:A}=Gs(t,s),E=f||d,x=tr(c,i(s.source),d),S=tr(l,i(s.target),f),I=E?x:nr(x,c,l),M=E?S:nr(S,l,c);if(s.source===s.target){let O=a.get(s.source)??0;a.set(s.source,O+1);let T=m(De.comfortable).filter(({id:C})=>C!==s.source),R=p&&At(p),k=({x:C,y:V})=>!R||C>=R.left&&C<=R.right&&V>=R.top&&V<=R.bottom,N=Hs(c,O),w=N.find(C=>{let V=C[0],P=C.at(-1);return V!==void 0&&P!==void 0&&n.clear(s.source,c,V,u)&&n.clear(s.source,c,P,h)&&C.every((q,ie)=>{let ye=C[ie-1];return k(q)&&(!ye||!qt(ye,q,T))})});w||t.warn?.(`ArchiMate could not keep the self-relationship "${s.id}" clear of other shapes and anchors.`),A(w??Ee(N[O%N.length],"a self-relationship loop"));continue}let L=!f&&!d?$s(c,l,m(De.comfortable).filter(({id:O})=>O!==s.source&&O!==s.target),r.cost,(O,T)=>n.clear(s.source,c,O,u)&&n.clear(s.target,l,T,h),{gap:u||h?Zt:Re,parallel:t.parallelCount(s)}):void 0;if(L)A(L);else{let O={start:!0,end:!0},T={start:!1,end:!1},{comfortable:R,tight:k}=De;o.push(()=>{A(y(I,M,R,O)??y(I,M,R,T)??y(I,M,k,T)??g(I,M))})}}return o}function Fl(t,{ports:e,order:n}){let{nodes:r,bundles:i,portFraction:o}=t;for(let a of n){let s=e.get(a.id);if(!s)continue;let c=Le(r,a.element),l=a.members.toSorted((u,h)=>{let f=d=>Le(r,a.sharedEnd==="start"?d.target:d.source);return Ve(ae(f(h)),ae(c))-Ve(ae(f(u)),ae(c))});for(let u of l){let h=Gs(t,u),f=a.sharedEnd==="start"?u.target:u.source,d=Le(r,f),p=o(f),m=Fs(a.side,s.anchor,d),y=Math.min(X,d.width/4),g=Math.min(X,d.height/4),A=m==="top"||m==="bottom"?"x":"y",E=A==="x"?d.x+y:d.y+g,x=A==="x"?d.x+d.width-y:d.y+d.height-g,I=m===Jt[a.side]&&s.anchor[A]>=E&&s.anchor[A]<=x?s.anchor[A]:E+p*(x-E),M=[...r.values()].flatMap(({box:w})=>A==="x"?[w.x-De.comfortable,w.x+w.width+De.comfortable]:[w.y-De.comfortable,w.y+w.height+De.comfortable]).filter(w=>w>=E&&w<=x),L=[I,...M,...Array.from({length:5},(w,C)=>E+(C+.5)*(x-E)/5)].map(w=>ir(d,m,w)),O=nr(tr(d,p,!1),d,c),T=(w,C,V)=>a.sharedEnd==="start"?h.search([s],w,C,{start:!1,end:V},a.id):h.search(w,[s],C,{start:V,end:!1},a.id),{comfortable:R,tight:k}=De,N=T(L,R,!0)??T(O,R,!0)??T(O,R,!1)??T(O,k,!1)??(a.sharedEnd==="start"?h.fallback([s],O):h.fallback(O,[s]));h.record(N,a.members.length>1?a.id:void 0),a.members.length>1&&i.set(u.id,{id:a.id,sharedEnd:a.sharedEnd})}}}function Vs(t,e,{warn:n}={}){let r=Pl(t,e,n),i=Ds(t,e),o=Us(t,i,r.anchors),a=new Set([...i.values()].flatMap(({members:c})=>c.map(({id:l})=>l))),s=Ul(r,e.filter(({id:c})=>!a.has(c)));Fl(r,o);for(let c of s)c();return{routes:r.routes,bundles:r.bundles}}function en(t,e,{box:n,outline:r}){let i=Math.abs(t.x-e.x)>Math.abs(t.y-e.y);if(r==="note"){let c=n.x+n.width-t.x+t.y-n.y,l=Math.max(0,Te-c);return i?{x:t.x-l,y:t.y}:{x:t.x,y:t.y+l}}if(r!=="rounded"&&r!=="chamfered")return t;let o=i?Math.min(t.y-n.y,n.y+n.height-t.y):Math.min(t.x-n.x,n.x+n.width-t.x),a=Math.max(0,ge-Math.max(0,o)),s=r==="rounded"?ge-Math.sqrt(ge**2-a**2):a;return i?{x:t.x+Math.sign(t.x-e.x)*s,y:t.y}:{x:t.x,y:t.y+Math.sign(t.y-e.y)*s}}function js(t,e,n){let[r,i,...o]=t;if(!r||!i)return[...t];let a=o.length===0,s=e.x+e.width,c=e.y<n.y,l=Math.min(e.y,n.y),u=Math.max(e.y+e.height,n.y+n.height),h=(x,S)=>{let I=e.y+(S?Te:0)+4,M=e.y+e.height-4;return I+Math.min(Math.max(x,0),1)*(M-I)},f=n.x+n.width,d=n.y+n.height;if(r.x===i.x&&i.y<r.y===c){let x=Math.min(Math.max(r.x,e.x+2),s-(c?Te:0)-2),S={x,y:c?e.y:e.y+e.height};if(x===i.x)return Se([S,i,...o]);let I=(S.y+i.y)/2;return Se([S,{x,y:I},{x:i.x,y:I},i,...o])}if(r.y===i.y){let x=i.x>r.x,S={x:x?s:e.x,y:h((r.y-l)/(u-l),x)};if(!a)return Se([S,{x:i.x,y:S.y},i,...o]);let I=x?f+se/2:n.x-se/2,M=x?Math.max((S.x+i.x)/2,I):Math.min((S.x+i.x)/2,I);return Se([S,{x:M,y:S.y},{x:M,y:i.y},i])}let p=i.x>=n.x+n.width/2,m=(r.x-n.x)/n.width,y={x:p?s:e.x,y:h(p?m:1-m,p)},g=p?f+se:n.x-se;if(!a)return Se([y,{x:g,y:y.y},{x:g,y:i.y},i,...o]);let E=((c?d:n.y)+i.y)/2;return Se([y,{x:g,y:y.y},{x:g,y:E},{x:i.x,y:E},i])}function Ws(t,e,n){return Math.min(t.x,e.x)<n.x+n.width-.5&&Math.max(t.x,e.x)>n.x+.5&&Math.min(t.y,e.y)<n.y+n.height-.5&&Math.max(t.y,e.y)>n.y+.5}function Ks(t,e,n,r){let i=n==="x"?"y":"x",o=t[i],a=t[i]+(n==="x"?t.height:t.width),s=Math.abs(e[i]-o)<=Math.abs(e[i]-a)?o:a,c=t[n]+ge,l=t[n]+(n==="x"?t.width:t.height)-ge;if(!(r<c||r>l))return n==="x"?{x:r,y:s}:{x:s,y:r}}function Ys(t,e,n,r,i){let o=t.map(s=>({...s})),a=6;for(let s=0;s+1<o.length;s++){let c=o[s],l=o[s+1];if(!c||!l||c.x!==l.x&&c.y!==l.y)continue;let u=e.find(p=>Ws(c,l,p));if(!u)continue;let h=c.x===l.x?"x":"y",f=h==="x"?u.width:u.height,d=[u[h]-a,u[h]+f+a].sort((p,m)=>Math.abs(p-c[h])-Math.abs(m-c[h]));for(let p of d){let m=o.map(I=>({...I})),y=s===0,g=s+2===o.length;if(y&&r.overlayHost||g&&i.overlayHost)break;let A=y?Ks(r.box,c,h,p):{...c,[h]:p},E=g?Ks(i.box,l,h,p):{...l,[h]:p};if(!A||!E)continue;m[s]=A,m[s+1]=E;let x=m.slice(Math.max(0,s-1),s+3);if(x.slice(1).every((I,M)=>{let L=x[M];return!L||[...e,...n].every(O=>!Ws(L,I,O))})){o=m;break}}}return o}function zs(t,e,n){let r=n.box.y+n.box.height;if(t.y>=n.box.y&&t.y<=r)return en(t,e,n);let i=t.y===e.y,o=i?Math.min(ge,n.box.height/2):0,a=t.y<n.box.y?n.box.y+o:r-o;return en({x:t.x,y:a},i?{x:e.x,y:a}:e,n)}function Zs(t,e,n){let r=t.sections??[],i=new Map(r.map(y=>[y.id,y])),o=r.find(y=>!y.incomingSections?.length);if(!o)throw new Error(`ELK did not return a route for relationship "${t.id}".`);let a=[],s=new Set,c=o;for(;;){if(s.has(c.id)||(c.outgoingSections?.length??0)>1)throw new Error(`ELK returned a branched route for relationship "${t.id}".`);s.add(c.id),a.push(c.startPoint,...c.bendPoints??[],c.endPoint);let y=c.outgoingSections?.[0];if(!y)break;let g=i.get(y);if(!g)throw new Error(`ELK returned an incomplete route for relationship "${t.id}".`);c=g}let l=a.filter((y,g)=>g===0||y.x!==a[g-1]?.x||y.y!==a[g-1]?.y),u=l[0],h=l[1],f=l.at(-1),d=l.at(-2);if(!u||!h||!f||!d||s.size!==r.length)throw new Error(`ELK returned an incomplete route for relationship "${t.id}".`);let p=l;if(e.overlayHost?p=js(p,e.box,e.overlayHost):p=Xs([zs(u,h,e),...p.slice(1)]),n.overlayHost)return js(p.toReversed(),n.box,n.overlayHost).toReversed();let m=[...p.slice(0,-1),zs(f,p.at(-2)??d,n)];return Xs(m.toReversed()).toReversed()}function Xs(t){let[e,n,r,...i]=t;if(!e||!n||e.x===n.x||e.y===n.y)return[...t];if(r&&n.x===r.x)return Se([e,{x:n.x,y:e.y},r,...i]);if(r&&n.y===r.y)return Se([e,{x:e.x,y:n.y},r,...i]);let o=(e.x+n.x)/2;return Se([e,{x:o,y:e.y},{x:o,y:n.y},n,...r?[r]:[],...i])}function qs(t,e,n,r){let o=n.x+n.width+se+(fe-se)*r/2,a=({box:l,overlayHost:u})=>({x:l.x+l.width,y:u?l.y+l.height*(.4+.2*r):Math.min(Math.max(n.y+ge+se*r,l.y+ge),l.y+l.height-ge)}),s=a(t),c=a(e);return[s,{x:o,y:s.y},{x:o,y:c.y},c]}function Dl({model:t,graph:e,placement:n,parents:r,logger:i}){let o=new Map((t.notes??[]).map(s=>[s.id,s.on])),a=new Map;for(let[s,c]of n.endpoints){let l=r.get(o.get(s)??s),u=n.decorations.get(s);a.set(s,{box:c.box,...l&&{parent:l},...u&&{decorations:u}})}return Vs(a,Array.from(e.edges).flatMap(([s,c])=>c.overlayLane===void 0?[{id:s,source:c.relationship.source,target:c.relationship.target,sourceMarker:c.notation.start!=="none",targetMarker:c.notation.end!=="none",...o.has(c.relationship.source)||o.has(c.relationship.target)?{}:{bundling:mi(c.relationship)}}]:[]),i)}function Qs(t,e){let n=t.endpoints.get(e.relationship.source),r=t.endpoints.get(e.relationship.target);if(!n||!r)throw new Error(`ELK did not position the endpoints of relationship "${e.relationship.id}".`);return[n,r]}function Js(t,e,n,r){let i=n.overlayHost??r.overlayHost,o=e.overlayKey===void 0?void 0:t.overlayLaneCounts.get(e.overlayKey);return i&&o&&e.overlayLane!==void 0?qs(n,r,i,(e.overlayLane+1)/(o+1)):void 0}function Bl(t){let{graph:e,placement:n}=t,r=Dl(t);return Array.from(e.edges,([i,o])=>{let[a,s]=Qs(n,o),c=Js(e,o,a,s);if(!c){let l=r.routes.get(i),u=l?.[0],h=l?.[1],f=l?.at(-1),d=l?.at(-2);if(!l||!u||!h||!f||!d)throw new Error(`Missing architecture route for relationship "${o.relationship.id}".`);c=l.slice(),c[0]=en(u,h,a),c[c.length-1]=en(f,d,s)}return{id:i,appearance:o,points:c,label:{hintNearRoute:!1,searchAllSegments:!0},bundle:r.bundles.get(i)}})}function $l({model:t,graph:e,layout:n,placement:r,parents:i}){let o=new Map((t.notes??[]).map(a=>[a.id,a.on]));return(n.root.edges??[]).map(a=>{let s=e.edges.get(a.id);if(!s)throw new Error("ELK returned an unknown ArchiMate relationship.");let[c,l]=Qs(r,s),u=Js(e,s,c,l);if(!u){let{source:g,target:A}=s.relationship,E=new Set;for(let x of[o.get(g)??g,o.get(A)??A])for(let S of yt(x,i))E.add(S);u=Ys(Zs(a,c,l),[...r.notes.filter(({appearance:{note:x}})=>x.id!==g&&x.id!==A).map(({box:x})=>x),...Array.from(r.decorations.values()).flat()],r.elements.filter(({appearance:{element:x}})=>!E.has(x.id)).map(({box:x})=>x),c,l)}let h=s.overlayLane===void 0?a.labels?.[0]:void 0,f=h?.x!==void 0&&h.y!==void 0&&(h.x!==0||h.y!==0)?{x:h.x,y:h.y}:void 0,[d]=a.sources,[p]=a.targets,m=e.nested.has(d??"")||e.nested.has(p??""),y={...f&&{hint:f},hintNearRoute:m,searchAllSegments:!1};return{id:a.id,appearance:s,points:u,label:y,bundle:void 0}})}function ea(t){return Fe(t.model)?Bl(t):$l(t)}function ta(t,e,n,r){let i=Math.min(fe,t.width/2),o=Math.min(fe,t.height/2),a=t.width-i,s=t.height-o,c=[];for(let{appearance:p,points:m,labelPosition:y}of e){for(let{x:E,y:x}of m)i=Math.min(i,E),o=Math.min(o,x),a=Math.max(a,E),s=Math.max(s,x);p.label&&y&&(i=Math.min(i,y.x),o=Math.min(o,y.y),a=Math.max(a,y.x+p.label.width+Me),s=Math.max(s,y.y+p.label.height));let g=m[0],A=m.at(-1);g&&p.notation.start!=="none"&&c.push(g),A&&p.notation.end!=="none"&&c.push(A)}let l=Math.max(Qo,r);i-=l,o-=l,a+=l,s+=l;for(let{x:p,y:m}of c)i=Math.min(i,p-Yt),o=Math.min(o,m-Yt),a=Math.max(a,p+Yt),s=Math.max(s,m+Yt);let u=a-i,h=Math.max(u,(n?.width??0)+2*l),f=n?n.height+os:0,d=Math.max(2*l,s-o+f);return{width:h,height:d,graphWidth:u,left:i,top:o,titleOffset:f,padding:l}}function na(t,{width:e,height:n},r){t.setAttribute("viewBox",`0 0 ${e} ${n}`),r?(t.setAttribute("width","100%"),t.style.maxWidth=`${e}px`,t.style.height="auto"):(t.setAttribute("width",String(e)),t.setAttribute("height",String(n)))}var ra={fill:"#d6f8b8",stroke:"#8bd34c",text:"#2f5909"},Hl={motivation:{fill:"#d9cfff",stroke:"#7b62db",text:"#4026a5"},strategy:{fill:"#f5deaa",stroke:"#bc904c",text:"#654617"},business:{fill:"#faf087",stroke:"#d7c828",text:"#574f04"},application:{fill:"#b8e7fc",stroke:"#52b0d9",text:"#054c6c"},technology:ra,physical:ra,implementationAndMigration:{fill:"#ffe0e0",stroke:"#ce8992",text:"#783d46"},composite:{fill:"#ffffff",stroke:"#9ba5b0",text:"#475666"}},sr={modern:{elements:Hl,location:{fill:"#edcfe2",stroke:"#bd84a9",text:"#704663"},note:{fill:"#fff8cb",fold:"#f5e9a5",stroke:"#9b8736",text:"#000000"}}},Gl={canvas:"#ffffff",text:"#1b1b1b",relationship:Ho},Vl={canvas:"#333",text:"#ffffff",relationship:"#ffffff",relationshipOutline:"#333"},jl=new Set(["dark","neo-dark","redux-dark","redux-dark-color"]),Wl=14,Kl="var(--mermaid-font-family, Arial, sans-serif)";function or(t,e){if(typeof t!="object"||t===null||!(e in t))return;let n=Reflect.get(t,e);return typeof n=="number"&&Number.isFinite(n)?String(n):typeof n=="string"&&n.trim()?n.trim():void 0}var zl=8,Xl=32;function Yl(t){let e="[\\p{L}\\d ,_-]";return t!==void 0&&new RegExp(`^(?:${e}|"${e}*"|'${e}*')+$`,"u").test(t)?t:void 0}function ia(t){return t===void 0?1:t.endsWith("%")?Number.parseFloat(t)/100:Number(t)}function oa(t){let e=/^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/iu.exec(t)?.[1];if(e){let s=e.length<=4?Array.from(e,f=>f+f):e.match(/../gu)??[],[c=0,l=0,u=0,h=255]=s.map(f=>Number.parseInt(f,16));return[c,l,u,h/255]}let n="\\s*[\\s,]\\s*",r="(?:\\s*[,/]\\s*([\\d.]+%?))?",i=new RegExp(`^rgba?\\(\\s*([\\d.]+)${n}([\\d.]+)${n}([\\d.]+)${r}\\s*\\)$`,"iu").exec(t);if(i)return[Number(i[1]),Number(i[2]),Number(i[3]),ia(i[4])];let o=new RegExp(`^hsla?\\(\\s*([\\d.]+)(?:deg)?${n}([\\d.]+)%${n}([\\d.]+)%${r}\\s*\\)$`,"iu").exec(t);if(o){let s=Number(o[1])%360,c=Number(o[2])/100,l=Number(o[3])/100,u=(1-Math.abs(2*l-1))*c,h=f=>{let d=(f+s/30)%12;return 255*(l-u/2*Math.max(-1,Math.min(d-3,9-d,1)))};return[h(0),h(8),h(4),ia(o[4])]}return{white:[255,255,255,1],black:[0,0,0,1],transparent:[0,0,0,0]}[t.toLowerCase()]}function sa(t,e){let n=oa(t);if(n)return n;let r=e?.(t);return r===void 0?void 0:oa(r)}function aa([t,e,n]){let[r,i,o]=[t,e,n].map(a=>{let s=a/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4});return .2126*(r??0)+.7152*(i??0)+.0722*(o??0)<.179}function Zl(t){let e=typeof t=="object"&&t!==null&&"darkMode"in t?t.darkMode:void 0;return typeof e=="boolean"?e:void 0}function ca(t,e,n){let r=t?.themeVariables,i=Zl(r),o=or(r,"background"),a=o===void 0?void 0:sa(o,e),s=a!==void 0&&a[3]>=1?a:void 0,c=i??(s?aa(s):jl.has(t?.theme)),l=c?Vl:Gl;if(t?.theme!=="base"||o===void 0||!s)return l;let u=(h,f)=>{let d=or(r,h);if(d===void 0)return f;let p=sa(d,e);return p&&p[3]>0&&aa(p)!==c?d:(n?.(`ArchiMate replaced the theme ${h} ${d}, which is not readable on ${o}, with ${f}.`),f)};return{canvas:o,text:u("textColor",l.text),relationship:u("lineColor",l.relationship),...c?{relationshipOutline:o}:{}}}function yi(t,e){let n=t==="base"?Number.parseFloat(or(e,"fontSize")??""):Number.NaN,r=Number.isFinite(n)&&n>0?Math.min(Math.max(n,zl),Xl):Wl;return{fontFamily:(t==="base"?Yl(or(e,"fontFamily")):void 0)??Kl,labelSize:r,titleSize:Math.round(r*17/14),edgeLabelSize:Math.round(r*12/14)}}var la=t=>{let e=typeof t=="object"&&t!==null&&"theme"in t?t.theme:void 0,{fontFamily:n,labelSize:r,titleSize:i,edgeLabelSize:o}=yi(e,t);return`
119
+ .archimate-label {
120
+ font-family: ${n};
121
+ font-size: ${r}px;
122
+ }
123
+
124
+ .archimate-title {
125
+ font-size: ${i}px;
126
+ font-weight: 600;
127
+ }
128
+
129
+ .archimate-edge-label {
130
+ font-size: ${o}px;
131
+ }
132
+ `};async function ha(t,e,n,r,i,o){let a=ms(e,i),s=ca(i,g=>ps(a,g),o&&(g=>{o.warn(g)})),c=yi(i?.theme,i?.themeVariables),l=new Map(t.nesting?.map(({child:g,parent:A})=>[g,A])),u=vs(a,t,n,c),h=As(t,u,l),f=await Ls(t,h,r.maxRowWidth),d=ws(t,f.root,h),p=ea({model:t,graph:h,layout:f,placement:d,parents:l,logger:o}),m=Ts(p,d,Fe(t)),y=ta(f,m,u.title,r.diagramPadding);xs(a,{id:e,viewport:y,placement:d,edges:m,title:u.title,palette:sr[r.palette],colours:s,background:r.background}),na(a,y,r.useMaxWidth)}var ql=/fl°°?(\w+)¶ß/gu;function Ql(t){if(typeof t!="object"||t===null||!("warn"in t))return;let{warn:e}=t;return typeof e=="function"?{warn:n=>{e.call(t,n)}}:void 0}function Um(t){if(!Object.hasOwn(sr,t.palette))throw new RangeError(`Unknown ArchiMate palette "${t.palette}".`);let e,n,r=0,i,o;return{db:{preserveCommentsWhenParsing:!0,setFrontmatterLineOffset(a){r=a},clear(){e=void 0,n=void 0,r=0},setDiagramTitle(a){n=a},getDiagramTitle(){return e?.title??n??""},getAccTitle(){return e?.accTitle??e?.title??n??""},getAccDescription(){return e?.accDescription??""}},parser:{parse(a){e=void 0;let s=a.replace(ql,"#$1;");e=qo(s,{lineOffset:r})}},renderer:{async draw(a,s,c,l){if(!e)throw new Error("Parse an ArchiMate diagram before rendering it.");await ha(e,s,l.db.getDiagramTitle?.()??"",t,i?.(),o)}},styles:la,injectUtils(a,s,c){o=Ql(a),i=c}}}export{Um as createArchimateDiagram,Ql as toLogger};