UNPKG

vue-mermaid-string

Version:

A Vue.js component that turns a Mermaid string into a diagram.

2,093 lines 508 kB
import { m as ot, f as pp, d as mp } from "./min-x5JjnDaq.js"; import { b as gp, l as yp, d as Tp, m as vp, r as Il, n as ta } from "./_baseUniq-DbLykLaa.js"; import { b8 as $p } from "./entry-B2VX-kxa.js"; function Rp(t, e) { return gp(ot(t, e)); } function Ap(t, e) { return t && t.length ? yp(t, Tp(e)) : []; } function ue(t) { return typeof t == "object" && t !== null && typeof t.$type == "string"; } function ze(t) { return typeof t == "object" && t !== null && typeof t.$refText == "string"; } function Ep(t) { return typeof t == "object" && t !== null && typeof t.name == "string" && typeof t.type == "string" && typeof t.path == "string"; } function wi(t) { return typeof t == "object" && t !== null && ue(t.container) && ze(t.reference) && typeof t.message == "string"; } class Lf { constructor() { this.subtypes = {}, this.allSubtypes = {}; } isInstance(e, n) { return ue(e) && this.isSubtype(e.$type, n); } isSubtype(e, n) { if (e === n) return !0; let r = this.subtypes[e]; r || (r = this.subtypes[e] = {}); const i = r[n]; if (i !== void 0) return i; { const s = this.computeIsSubtype(e, n); return r[n] = s, s; } } getAllSubTypes(e) { const n = this.allSubtypes[e]; if (n) return n; { const r = this.getAllTypes(), i = []; for (const s of r) this.isSubtype(s, e) && i.push(s); return this.allSubtypes[e] = i, i; } } } function Lr(t) { return typeof t == "object" && t !== null && Array.isArray(t.content); } function Pf(t) { return typeof t == "object" && t !== null && typeof t.tokenType == "object"; } function Mf(t) { return Lr(t) && typeof t.fullText == "string"; } class re { constructor(e, n) { this.startFn = e, this.nextFn = n; } iterator() { const e = { state: this.startFn(), next: () => this.nextFn(e.state), [Symbol.iterator]: () => e }; return e; } [Symbol.iterator]() { return this.iterator(); } isEmpty() { return !!this.iterator().next().done; } count() { const e = this.iterator(); let n = 0, r = e.next(); for (; !r.done; ) n++, r = e.next(); return n; } toArray() { const e = [], n = this.iterator(); let r; do r = n.next(), r.value !== void 0 && e.push(r.value); while (!r.done); return e; } toSet() { return new Set(this); } toMap(e, n) { const r = this.map((i) => [ e ? e(i) : i, n ? n(i) : i ]); return new Map(r); } toString() { return this.join(); } concat(e) { return new re(() => ({ first: this.startFn(), firstDone: !1, iterator: e[Symbol.iterator]() }), (n) => { let r; if (!n.firstDone) { do if (r = this.nextFn(n.first), !r.done) return r; while (!r.done); n.firstDone = !0; } do if (r = n.iterator.next(), !r.done) return r; while (!r.done); return Ae; }); } join(e = ",") { const n = this.iterator(); let r = "", i, s = !1; do i = n.next(), i.done || (s && (r += e), r += xp(i.value)), s = !0; while (!i.done); return r; } indexOf(e, n = 0) { const r = this.iterator(); let i = 0, s = r.next(); for (; !s.done; ) { if (i >= n && s.value === e) return i; s = r.next(), i++; } return -1; } every(e) { const n = this.iterator(); let r = n.next(); for (; !r.done; ) { if (!e(r.value)) return !1; r = n.next(); } return !0; } some(e) { const n = this.iterator(); let r = n.next(); for (; !r.done; ) { if (e(r.value)) return !0; r = n.next(); } return !1; } forEach(e) { const n = this.iterator(); let r = 0, i = n.next(); for (; !i.done; ) e(i.value, r), i = n.next(), r++; } map(e) { return new re(this.startFn, (n) => { const { done: r, value: i } = this.nextFn(n); return r ? Ae : { done: !1, value: e(i) }; }); } filter(e) { return new re(this.startFn, (n) => { let r; do if (r = this.nextFn(n), !r.done && e(r.value)) return r; while (!r.done); return Ae; }); } nonNullable() { return this.filter((e) => e != null); } reduce(e, n) { const r = this.iterator(); let i = n, s = r.next(); for (; !s.done; ) i === void 0 ? i = s.value : i = e(i, s.value), s = r.next(); return i; } reduceRight(e, n) { return this.recursiveReduce(this.iterator(), e, n); } recursiveReduce(e, n, r) { const i = e.next(); if (i.done) return r; const s = this.recursiveReduce(e, n, r); return s === void 0 ? i.value : n(s, i.value); } find(e) { const n = this.iterator(); let r = n.next(); for (; !r.done; ) { if (e(r.value)) return r.value; r = n.next(); } } findIndex(e) { const n = this.iterator(); let r = 0, i = n.next(); for (; !i.done; ) { if (e(i.value)) return r; i = n.next(), r++; } return -1; } includes(e) { const n = this.iterator(); let r = n.next(); for (; !r.done; ) { if (r.value === e) return !0; r = n.next(); } return !1; } flatMap(e) { return new re(() => ({ this: this.startFn() }), (n) => { do { if (n.iterator) { const s = n.iterator.next(); if (s.done) n.iterator = void 0; else return s; } const { done: r, value: i } = this.nextFn(n.this); if (!r) { const s = e(i); if (Ki(s)) n.iterator = s[Symbol.iterator](); else return { done: !1, value: s }; } } while (n.iterator); return Ae; }); } flat(e) { if (e === void 0 && (e = 1), e <= 0) return this; const n = e > 1 ? this.flat(e - 1) : this; return new re(() => ({ this: n.startFn() }), (r) => { do { if (r.iterator) { const a = r.iterator.next(); if (a.done) r.iterator = void 0; else return a; } const { done: i, value: s } = n.nextFn(r.this); if (!i) if (Ki(s)) r.iterator = s[Symbol.iterator](); else return { done: !1, value: s }; } while (r.iterator); return Ae; }); } head() { const n = this.iterator().next(); if (!n.done) return n.value; } tail(e = 1) { return new re(() => { const n = this.startFn(); for (let r = 0; r < e; r++) if (this.nextFn(n).done) return n; return n; }, this.nextFn); } limit(e) { return new re(() => ({ size: 0, state: this.startFn() }), (n) => (n.size++, n.size > e ? Ae : this.nextFn(n.state))); } distinct(e) { return new re(() => ({ set: /* @__PURE__ */ new Set(), internalState: this.startFn() }), (n) => { let r; do if (r = this.nextFn(n.internalState), !r.done) { const i = e ? e(r.value) : r.value; if (!n.set.has(i)) return n.set.add(i), r; } while (!r.done); return Ae; }); } exclude(e, n) { const r = /* @__PURE__ */ new Set(); for (const i of e) { const s = n ? n(i) : i; r.add(s); } return this.filter((i) => { const s = n ? n(i) : i; return !r.has(s); }); } } function xp(t) { return typeof t == "string" ? t : typeof t > "u" ? "undefined" : typeof t.toString == "function" ? t.toString() : Object.prototype.toString.call(t); } function Ki(t) { return !!t && typeof t[Symbol.iterator] == "function"; } const Sp = new re(() => { }, () => Ae), Ae = Object.freeze({ done: !0, value: void 0 }); function ie(...t) { if (t.length === 1) { const e = t[0]; if (e instanceof re) return e; if (Ki(e)) return new re(() => e[Symbol.iterator](), (n) => n.next()); if (typeof e.length == "number") return new re(() => ({ index: 0 }), (n) => n.index < e.length ? { done: !1, value: e[n.index++] } : Ae); } return t.length > 1 ? new re(() => ({ collIndex: 0, arrIndex: 0 }), (e) => { do { if (e.iterator) { const n = e.iterator.next(); if (!n.done) return n; e.iterator = void 0; } if (e.array) { if (e.arrIndex < e.array.length) return { done: !1, value: e.array[e.arrIndex++] }; e.array = void 0, e.arrIndex = 0; } if (e.collIndex < t.length) { const n = t[e.collIndex++]; Ki(n) ? e.iterator = n[Symbol.iterator]() : n && typeof n.length == "number" && (e.array = n); } } while (e.iterator || e.array || e.collIndex < t.length); return Ae; }) : Sp; } class _o extends re { constructor(e, n, r) { super(() => ({ iterators: r?.includeRoot ? [[e][Symbol.iterator]()] : [n(e)[Symbol.iterator]()], pruned: !1 }), (i) => { for (i.pruned && (i.iterators.pop(), i.pruned = !1); i.iterators.length > 0; ) { const a = i.iterators[i.iterators.length - 1].next(); if (a.done) i.iterators.pop(); else return i.iterators.push(n(a.value)[Symbol.iterator]()), a; } return Ae; }); } iterator() { const e = { state: this.startFn(), next: () => this.nextFn(e.state), prune: () => { e.state.pruned = !0; }, [Symbol.iterator]: () => e }; return e; } } var Ma; (function(t) { function e(s) { return s.reduce((a, o) => a + o, 0); } t.sum = e; function n(s) { return s.reduce((a, o) => a * o, 0); } t.product = n; function r(s) { return s.reduce((a, o) => Math.min(a, o)); } t.min = r; function i(s) { return s.reduce((a, o) => Math.max(a, o)); } t.max = i; })(Ma || (Ma = {})); function Da(t) { return new _o(t, (e) => Lr(e) ? e.content : [], { includeRoot: !0 }); } function Ip(t, e) { for (; t.container; ) if (t = t.container, t === e) return !0; return !1; } function Fa(t) { return { start: { character: t.startColumn - 1, line: t.startLine - 1 }, end: { character: t.endColumn, // endColumn uses the correct index line: t.endLine - 1 } }; } function Hi(t) { if (!t) return; const { offset: e, end: n, range: r } = t; return { range: r, offset: e, end: n, length: n - e }; } var st; (function(t) { t[t.Before = 0] = "Before", t[t.After = 1] = "After", t[t.OverlapFront = 2] = "OverlapFront", t[t.OverlapBack = 3] = "OverlapBack", t[t.Inside = 4] = "Inside", t[t.Outside = 5] = "Outside"; })(st || (st = {})); function wp(t, e) { if (t.end.line < e.start.line || t.end.line === e.start.line && t.end.character <= e.start.character) return st.Before; if (t.start.line > e.end.line || t.start.line === e.end.line && t.start.character >= e.end.character) return st.After; const n = t.start.line > e.start.line || t.start.line === e.start.line && t.start.character >= e.start.character, r = t.end.line < e.end.line || t.end.line === e.end.line && t.end.character <= e.end.character; return n && r ? st.Inside : n ? st.OverlapBack : r ? st.OverlapFront : st.Outside; } function Cp(t, e) { return wp(t, e) > st.After; } const _p = /^[\w\p{L}]$/u; function kp(t, e) { if (t) { const n = Np(t, !0); if (n && wl(n, e)) return n; if (Mf(t)) { const r = t.content.findIndex((i) => !i.hidden); for (let i = r - 1; i >= 0; i--) { const s = t.content[i]; if (wl(s, e)) return s; } } } } function wl(t, e) { return Pf(t) && e.includes(t.tokenType.name); } function Np(t, e = !0) { for (; t.container; ) { const n = t.container; let r = n.content.indexOf(t); for (; r > 0; ) { r--; const i = n.content[r]; if (e || !i.hidden) return i; } t = n; } } class Df extends Error { constructor(e, n) { super(e ? `${n} at ${e.range.start.line}:${e.range.start.character}` : n); } } function Kr(t) { throw new Error("Error! The input value was not handled."); } const ri = "AbstractRule", ii = "AbstractType", na = "Condition", Cl = "TypeDefinition", ra = "ValueLiteral", Yn = "AbstractElement"; function bp(t) { return F.isInstance(t, Yn); } const si = "ArrayLiteral", ai = "ArrayType", Xn = "BooleanLiteral"; function Op(t) { return F.isInstance(t, Xn); } const Jn = "Conjunction"; function Lp(t) { return F.isInstance(t, Jn); } const Zn = "Disjunction"; function Pp(t) { return F.isInstance(t, Zn); } const oi = "Grammar", ia = "GrammarImport", Qn = "InferredType"; function Ff(t) { return F.isInstance(t, Qn); } const er = "Interface"; function Gf(t) { return F.isInstance(t, er); } const sa = "NamedArgument", tr = "Negation"; function Mp(t) { return F.isInstance(t, tr); } const li = "NumberLiteral", ui = "Parameter", nr = "ParameterReference"; function Dp(t) { return F.isInstance(t, nr); } const rr = "ParserRule"; function Ne(t) { return F.isInstance(t, rr); } const ci = "ReferenceType", Ci = "ReturnType"; function Fp(t) { return F.isInstance(t, Ci); } const ir = "SimpleType"; function Gp(t) { return F.isInstance(t, ir); } const fi = "StringLiteral", cn = "TerminalRule"; function Jt(t) { return F.isInstance(t, cn); } const sr = "Type"; function Uf(t) { return F.isInstance(t, sr); } const aa = "TypeAttribute", di = "UnionType", ar = "Action"; function Ts(t) { return F.isInstance(t, ar); } const or = "Alternatives"; function Bf(t) { return F.isInstance(t, or); } const lr = "Assignment"; function Kt(t) { return F.isInstance(t, lr); } const ur = "CharacterRange"; function Up(t) { return F.isInstance(t, ur); } const cr = "CrossReference"; function ko(t) { return F.isInstance(t, cr); } const fr = "EndOfFile"; function Bp(t) { return F.isInstance(t, fr); } const dr = "Group"; function No(t) { return F.isInstance(t, dr); } const hr = "Keyword"; function Ht(t) { return F.isInstance(t, hr); } const pr = "NegatedToken"; function jp(t) { return F.isInstance(t, pr); } const mr = "RegexToken"; function Kp(t) { return F.isInstance(t, mr); } const gr = "RuleCall"; function Wt(t) { return F.isInstance(t, gr); } const yr = "TerminalAlternatives"; function Hp(t) { return F.isInstance(t, yr); } const Tr = "TerminalGroup"; function Wp(t) { return F.isInstance(t, Tr); } const vr = "TerminalRuleCall"; function zp(t) { return F.isInstance(t, vr); } const $r = "UnorderedGroup"; function jf(t) { return F.isInstance(t, $r); } const Rr = "UntilToken"; function Vp(t) { return F.isInstance(t, Rr); } const Ar = "Wildcard"; function qp(t) { return F.isInstance(t, Ar); } class Kf extends Lf { getAllTypes() { return [Yn, ri, ii, ar, or, si, ai, lr, Xn, ur, na, Jn, cr, Zn, fr, oi, ia, dr, Qn, er, hr, sa, pr, tr, li, ui, nr, rr, ci, mr, Ci, gr, ir, fi, yr, Tr, cn, vr, sr, aa, Cl, di, $r, Rr, ra, Ar]; } computeIsSubtype(e, n) { switch (e) { case ar: case or: case lr: case ur: case cr: case fr: case dr: case hr: case pr: case mr: case gr: case yr: case Tr: case vr: case $r: case Rr: case Ar: return this.isSubtype(Yn, n); case si: case li: case fi: return this.isSubtype(ra, n); case ai: case ci: case ir: case di: return this.isSubtype(Cl, n); case Xn: return this.isSubtype(na, n) || this.isSubtype(ra, n); case Jn: case Zn: case tr: case nr: return this.isSubtype(na, n); case Qn: case er: case sr: return this.isSubtype(ii, n); case rr: return this.isSubtype(ri, n) || this.isSubtype(ii, n); case cn: return this.isSubtype(ri, n); default: return !1; } } getReferenceType(e) { const n = `${e.container.$type}:${e.property}`; switch (n) { case "Action:type": case "CrossReference:type": case "Interface:superTypes": case "ParserRule:returnType": case "SimpleType:typeRef": return ii; case "Grammar:hiddenTokens": case "ParserRule:hiddenTokens": case "RuleCall:rule": return ri; case "Grammar:usedGrammars": return oi; case "NamedArgument:parameter": case "ParameterReference:parameter": return ui; case "TerminalRuleCall:rule": return cn; default: throw new Error(`${n} is not a valid reference id.`); } } getTypeMetaData(e) { switch (e) { case Yn: return { name: Yn, properties: [ { name: "cardinality" }, { name: "lookahead" } ] }; case si: return { name: si, properties: [ { name: "elements", defaultValue: [] } ] }; case ai: return { name: ai, properties: [ { name: "elementType" } ] }; case Xn: return { name: Xn, properties: [ { name: "true", defaultValue: !1 } ] }; case Jn: return { name: Jn, properties: [ { name: "left" }, { name: "right" } ] }; case Zn: return { name: Zn, properties: [ { name: "left" }, { name: "right" } ] }; case oi: return { name: oi, properties: [ { name: "definesHiddenTokens", defaultValue: !1 }, { name: "hiddenTokens", defaultValue: [] }, { name: "imports", defaultValue: [] }, { name: "interfaces", defaultValue: [] }, { name: "isDeclared", defaultValue: !1 }, { name: "name" }, { name: "rules", defaultValue: [] }, { name: "types", defaultValue: [] }, { name: "usedGrammars", defaultValue: [] } ] }; case ia: return { name: ia, properties: [ { name: "path" } ] }; case Qn: return { name: Qn, properties: [ { name: "name" } ] }; case er: return { name: er, properties: [ { name: "attributes", defaultValue: [] }, { name: "name" }, { name: "superTypes", defaultValue: [] } ] }; case sa: return { name: sa, properties: [ { name: "calledByName", defaultValue: !1 }, { name: "parameter" }, { name: "value" } ] }; case tr: return { name: tr, properties: [ { name: "value" } ] }; case li: return { name: li, properties: [ { name: "value" } ] }; case ui: return { name: ui, properties: [ { name: "name" } ] }; case nr: return { name: nr, properties: [ { name: "parameter" } ] }; case rr: return { name: rr, properties: [ { name: "dataType" }, { name: "definesHiddenTokens", defaultValue: !1 }, { name: "definition" }, { name: "entry", defaultValue: !1 }, { name: "fragment", defaultValue: !1 }, { name: "hiddenTokens", defaultValue: [] }, { name: "inferredType" }, { name: "name" }, { name: "parameters", defaultValue: [] }, { name: "returnType" }, { name: "wildcard", defaultValue: !1 } ] }; case ci: return { name: ci, properties: [ { name: "referenceType" } ] }; case Ci: return { name: Ci, properties: [ { name: "name" } ] }; case ir: return { name: ir, properties: [ { name: "primitiveType" }, { name: "stringType" }, { name: "typeRef" } ] }; case fi: return { name: fi, properties: [ { name: "value" } ] }; case cn: return { name: cn, properties: [ { name: "definition" }, { name: "fragment", defaultValue: !1 }, { name: "hidden", defaultValue: !1 }, { name: "name" }, { name: "type" } ] }; case sr: return { name: sr, properties: [ { name: "name" }, { name: "type" } ] }; case aa: return { name: aa, properties: [ { name: "defaultValue" }, { name: "isOptional", defaultValue: !1 }, { name: "name" }, { name: "type" } ] }; case di: return { name: di, properties: [ { name: "types", defaultValue: [] } ] }; case ar: return { name: ar, properties: [ { name: "cardinality" }, { name: "feature" }, { name: "inferredType" }, { name: "lookahead" }, { name: "operator" }, { name: "type" } ] }; case or: return { name: or, properties: [ { name: "cardinality" }, { name: "elements", defaultValue: [] }, { name: "lookahead" } ] }; case lr: return { name: lr, properties: [ { name: "cardinality" }, { name: "feature" }, { name: "lookahead" }, { name: "operator" }, { name: "terminal" } ] }; case ur: return { name: ur, properties: [ { name: "cardinality" }, { name: "left" }, { name: "lookahead" }, { name: "right" } ] }; case cr: return { name: cr, properties: [ { name: "cardinality" }, { name: "deprecatedSyntax", defaultValue: !1 }, { name: "lookahead" }, { name: "terminal" }, { name: "type" } ] }; case fr: return { name: fr, properties: [ { name: "cardinality" }, { name: "lookahead" } ] }; case dr: return { name: dr, properties: [ { name: "cardinality" }, { name: "elements", defaultValue: [] }, { name: "guardCondition" }, { name: "lookahead" } ] }; case hr: return { name: hr, properties: [ { name: "cardinality" }, { name: "lookahead" }, { name: "value" } ] }; case pr: return { name: pr, properties: [ { name: "cardinality" }, { name: "lookahead" }, { name: "terminal" } ] }; case mr: return { name: mr, properties: [ { name: "cardinality" }, { name: "lookahead" }, { name: "regex" } ] }; case gr: return { name: gr, properties: [ { name: "arguments", defaultValue: [] }, { name: "cardinality" }, { name: "lookahead" }, { name: "rule" } ] }; case yr: return { name: yr, properties: [ { name: "cardinality" }, { name: "elements", defaultValue: [] }, { name: "lookahead" } ] }; case Tr: return { name: Tr, properties: [ { name: "cardinality" }, { name: "elements", defaultValue: [] }, { name: "lookahead" } ] }; case vr: return { name: vr, properties: [ { name: "cardinality" }, { name: "lookahead" }, { name: "rule" } ] }; case $r: return { name: $r, properties: [ { name: "cardinality" }, { name: "elements", defaultValue: [] }, { name: "lookahead" } ] }; case Rr: return { name: Rr, properties: [ { name: "cardinality" }, { name: "lookahead" }, { name: "terminal" } ] }; case Ar: return { name: Ar, properties: [ { name: "cardinality" }, { name: "lookahead" } ] }; default: return { name: e, properties: [] }; } } } const F = new Kf(); function Yp(t) { for (const [e, n] of Object.entries(t)) e.startsWith("$") || (Array.isArray(n) ? n.forEach((r, i) => { ue(r) && (r.$container = t, r.$containerProperty = e, r.$containerIndex = i); }) : ue(n) && (n.$container = t, n.$containerProperty = e)); } function vs(t, e) { let n = t; for (; n; ) { if (e(n)) return n; n = n.$container; } } function Rt(t) { const n = Ga(t).$document; if (!n) throw new Error("AST node has no document."); return n; } function Ga(t) { for (; t.$container; ) t = t.$container; return t; } function bo(t, e) { if (!t) throw new Error("Node must be an AstNode."); const n = e?.range; return new re(() => ({ keys: Object.keys(t), keyIndex: 0, arrayIndex: 0 }), (r) => { for (; r.keyIndex < r.keys.length; ) { const i = r.keys[r.keyIndex]; if (!i.startsWith("$")) { const s = t[i]; if (ue(s)) { if (r.keyIndex++, _l(s, n)) return { done: !1, value: s }; } else if (Array.isArray(s)) { for (; r.arrayIndex < s.length; ) { const a = r.arrayIndex++, o = s[a]; if (ue(o) && _l(o, n)) return { done: !1, value: o }; } r.arrayIndex = 0; } } r.keyIndex++; } return Ae; }); } function Hr(t, e) { if (!t) throw new Error("Root node must be an AstNode."); return new _o(t, (n) => bo(n, e)); } function dn(t, e) { if (!t) throw new Error("Root node must be an AstNode."); return new _o(t, (n) => bo(n, e), { includeRoot: !0 }); } function _l(t, e) { var n; if (!e) return !0; const r = (n = t.$cstNode) === null || n === void 0 ? void 0 : n.range; return r ? Cp(r, e) : !1; } function Hf(t) { return new re(() => ({ keys: Object.keys(t), keyIndex: 0, arrayIndex: 0 }), (e) => { for (; e.keyIndex < e.keys.length; ) { const n = e.keys[e.keyIndex]; if (!n.startsWith("$")) { const r = t[n]; if (ze(r)) return e.keyIndex++, { done: !1, value: { reference: r, container: t, property: n } }; if (Array.isArray(r)) { for (; e.arrayIndex < r.length; ) { const i = e.arrayIndex++, s = r[i]; if (ze(s)) return { done: !1, value: { reference: s, container: t, property: n, index: i } }; } e.arrayIndex = 0; } } e.keyIndex++; } return Ae; }); } function Xp(t, e) { const n = t.getTypeMetaData(e.$type), r = e; for (const i of n.properties) i.defaultValue !== void 0 && r[i.name] === void 0 && (r[i.name] = Wf(i.defaultValue)); } function Wf(t) { return Array.isArray(t) ? [...t.map(Wf)] : t; } function _(t) { return t.charCodeAt(0); } function oa(t, e) { Array.isArray(t) ? t.forEach(function(n) { e.push(n); }) : e.push(t); } function Hn(t, e) { if (t[e] === !0) throw "duplicate flag " + e; t[e], t[e] = !0; } function un(t) { if (t === void 0) throw Error("Internal Error - Should never get here!"); return !0; } function Jp() { throw Error("Internal Error - Should never get here!"); } function kl(t) { return t.type === "Character"; } const Wi = []; for (let t = _("0"); t <= _("9"); t++) Wi.push(t); const zi = [_("_")].concat(Wi); for (let t = _("a"); t <= _("z"); t++) zi.push(t); for (let t = _("A"); t <= _("Z"); t++) zi.push(t); const Nl = [ _(" "), _("\f"), _(` `), _("\r"), _(" "), _("\v"), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _(" "), _("\u2028"), _("\u2029"), _(" "), _(" "), _(" "), _("\uFEFF") ], Zp = /[0-9a-fA-F]/, hi = /[0-9]/, Qp = /[1-9]/; class zf { 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("/"); const n = this.disjunction(); this.consumeChar("/"); const 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": Hn(r, "global"); break; case "i": Hn(r, "ignoreCase"); break; case "m": Hn(r, "multiLine"); break; case "u": Hn(r, "unicode"); break; case "y": Hn(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() { const 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() { const 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() { const e = this.idx; switch (this.popChar()) { case "^": return { type: "StartAnchor", loc: this.loc(e) }; case "$": return { type: "EndAnchor", loc: this.loc(e) }; // '\b' or '\B' 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"); // '(?=' or '(?!' case "(": this.consumeChar("?"); let n; switch (this.popChar()) { case "=": n = "Lookahead"; break; case "!": n = "NegativeLookahead"; break; } un(n); const r = this.disjunction(); return this.consumeChar(")"), { type: n, value: r, loc: this.loc(e) }; } return Jp(); } quantifier(e = !1) { let n; const 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 "{": const i = this.integerIncludingZero(); switch (this.popChar()) { case "}": n = { atLeast: i, atMost: i }; break; case ",": let s; this.isDigit() ? (s = this.integerIncludingZero(), n = { atLeast: i, atMost: s }) : n = { atLeast: i, atMost: 1 / 0 }, this.consumeChar("}"); break; } if (e === !0 && n === void 0) return; un(n); break; } if (!(e === !0 && n === void 0) && un(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; const 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; } if (e === void 0 && this.isPatternCharacter() && (e = this.patternCharacter()), un(e)) return e.loc = this.loc(n), this.isQuantifier() && (e.quantifier = this.quantifier()), e; } dotAll() { return this.consumeChar("."), { type: "Set", complement: !0, value: [_(` `), _("\r"), _("\u2028"), _("\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 = Wi; break; case "D": e = Wi, n = !0; break; case "s": e = Nl; break; case "S": e = Nl, n = !0; break; case "w": e = zi; break; case "W": e = zi, n = !0; break; } if (un(e)) return { type: "Set", value: e, complement: n }; } controlEscapeAtom() { let e; switch (this.popChar()) { case "f": e = _("\f"); break; case "n": e = _(` `); break; case "r": e = _("\r"); break; case "t": e = _(" "); break; case "v": e = _("\v"); break; } if (un(e)) return { type: "Character", value: e }; } controlLetterEscapeAtom() { this.consumeChar("c"); const 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: _("\0") }; } hexEscapeSequenceAtom() { return this.consumeChar("x"), this.parseHexDigits(2); } regExpUnicodeEscapeSequenceAtom() { return this.consumeChar("u"), this.parseHexDigits(4); } identityEscapeAtom() { const e = this.popChar(); return { type: "Character", value: _(e) }; } classPatternCharacterAtom() { switch (this.peekChar()) { // istanbul ignore next case ` `: // istanbul ignore next case "\r": // istanbul ignore next case "\u2028": // istanbul ignore next case "\u2029": // istanbul ignore next case "\\": // istanbul ignore next case "]": throw Error("TBD"); default: const e = this.popChar(); return { type: "Character", value: _(e) }; } } characterClass() { const e = []; let n = !1; for (this.consumeChar("["), this.peekChar(0) === "^" && (this.consumeChar("^"), n = !0); this.isClassAtom(); ) { const r = this.classAtom(); if (r.type, kl(r) && this.isRangeDash()) { this.consumeChar("-"); const i = this.classAtom(); if (i.type, kl(i)) { if (i.value < r.value) throw Error("Range out of order in character class"); e.push({ from: r.value, to: i.value }); } else oa(r.value, e), e.push(_("-")), oa(i.value, e); } else oa(r.value, e); } return this.consumeChar("]"), { type: "Set", complement: n, value: e }; } classAtom() { switch (this.peekChar()) { // istanbul ignore next case "]": // istanbul ignore next case ` `: // istanbul ignore next case "\r": // istanbul ignore next case "\u2028": // istanbul ignore next case "\u2029": throw Error("TBD"); case "\\": return this.classEscape(); default: return this.classPatternCharacterAtom(); } } classEscape() { switch (this.consumeChar("\\"), this.peekChar()) { // Matches a backspace. // (Not to be confused with \b word boundary outside characterClass) case "b": return this.consumeChar("b"), { type: "Character", value: _("\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++; const n = this.disjunction(); this.consumeChar(")"); const r = { type: "Group", capturing: e, value: n }; return e && (r.idx = this.groupIdx), r; } positiveInteger() { let e = this.popChar(); if (Qp.test(e) === !1) throw Error("Expecting a positive integer"); for (; hi.test(this.peekChar(0)); ) e += this.popChar(); return parseInt(e, 10); } integerIncludingZero() { let e = this.popChar(); if (hi.test(e) === !1) throw Error("Expecting an integer"); for (; hi.test(this.peekChar(0)); ) e += this.popChar(); return parseInt(e, 10); } patternCharacter() { const e = this.popChar(); switch (e) { // istanbul ignore next case ` `: // istanbul ignore next case "\r": // istanbul ignore next case "\u2028": // istanbul ignore next case "\u2029": // istanbul ignore next case "^": // istanbul ignore next case "$": // istanbul ignore next case "\\": // istanbul ignore next case ".": // istanbul ignore next case "*": // istanbul ignore next case "+": // istanbul ignore next case "?": // istanbul ignore next case "(": // istanbul ignore next case ")": // istanbul ignore next case "[": // istanbul ignore next case "|": throw Error("TBD"); default: return { type: "Character", value: _(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 hi.test(this.peekChar(0)); } isClassAtom(e = 0) { switch (this.peekChar(e)) { case "]": case ` `: 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 "\\": // atomEscape case "[": // characterClass // TODO: isAtom must be called before isAssertion - disambiguate case "(": return !0; default: return !1; } } isAssertion() { switch (this.peekChar(0)) { case "^": case "$": return !0; // '\b' or '\B' case "\\": switch (this.peekChar(1)) { case "b": case "B": return !0; default: return !1; } // '(?=' or '(?!' case "(": return this.peekChar(1) === "?" && (this.peekChar(2) === "=" || this.peekChar(2) === "!"); default: return !1; } } isQuantifier() { const 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 ` `: case "\r": case "\u2028": case "\u2029": return !1; default: return !0; } } parseHexDigits(e) { let n = ""; for (let i = 0; i < e; i++) { const s = this.popChar(); if (Zp.test(s) === !1) throw Error("Expecting a HexDecimal digits"); n += s; } return { type: "Character", value: parseInt(n, 16) }; } peekChar(e = 0) { return this.input[this.idx + e]; } popChar() { const 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 }; } } class $s { visitChildren(e) { for (const n in e) { const 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 "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) { } // Assertion visitStartAnchor(e) { } visitEndAnchor(e) { } visitWordBoundary(e) { } visitNonWordBoundary(e) { } visitLookahead(e) { } visitNegativeLookahead(e) { } // atoms visitCharacter(e) { } visitSet(e) { } visitGroup(e) { } visitGroupBackReference(e) { } visitQuantifier(e) { } } const em = /\r?\n/gm, tm = new zf(); class nm extends $s { constructor() { super(...arguments), this.isStarting = !0, this.endRegexpStack = [], this.multiline = !1; } get endRegex() { return this.endRegexpStack.join(""); } reset(e) { this.multiline = !1, this.regex = e, this.startRegexp = "", this.isStarting = !0, this.endRegexpStack = []; } visitGroup(e) { e.quantifier && (this.isStarting = !1, this.endRegexpStack = []); } visitCharacter(e) { const n = String.fromCharCode(e.value); if (!this.multiline && n === ` ` && (this.multiline = !0), e.quantifier) this.isStarting = !1, this.endRegexpStack = []; else { const r = Rs(n); this.endRegexpStack.push(r), this.isStarting && (this.startRegexp += r); } } visitSet(e) { if (!this.multiline) { const n = this.regex.substring(e.loc.begin, e.loc.end), r = new RegExp(n); this.multiline = !!` `.match(r); } if (e.quantifier) this.isStarting = !1, this.endRegexpStack = []; else { const n = this.regex.substring(e.loc.begin, e.loc.end); this.endRegexpStack.push(n), this.isStarting && (this.startRegexp += n); } } visitChildren(e) { e.type === "Group" && e.quantifier || super.visitChildren(e); } } const la = new nm(); function rm(t) { try { return typeof t == "string" && (t = new RegExp(t)), t = t.toString(), la.reset(t), la.visit(tm.pattern(t)), la.multiline; } catch { return !1; } } const im = `\f \r \v              \u2028\u2029   \uFEFF`.split(""); function Ua(t) { const e = typeof t == "string" ? new RegExp(t) : t; return im.some((n) => e.test(n)); } function Rs(t) { return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } function sm(t) { return Array.prototype.map.call(t, (e) => /\w/.test(e) ? `[${e.toLowerCase()}${e.toUpperCase()}]` : Rs(e)).join(""); } function am(t, e) { const n = om(t), r = e.match(n); return !!r && r[0].length > 0; } function om(t) { typeof t == "string" && (t = new RegExp(t)); const e = t, n = t.source; let r = 0; function i() { let s = "", a; function o(u) { s += n.substr(r, u), r += u; } function l(u) { s += "(?:" + n.substr(r, u) + "|$)", r += u; } for (; r < n.length; ) switch (n[r]) { case "\\": switch (n[r + 1]) { case "c": l(3); break; case "x": l(4); break; case "u": e.unicode ? n[r + 2] === "{" ? l(n.indexOf("}", r) - r + 1) : l(6) : l(2); break; case "p": case "P": e.unicode ? l(n.indexOf("}", r) - r + 1) : l(2); break; case "k": l(n.indexOf(">", r) - r + 1); break; default: l(2); break; } break; case "[": a = /\[(?:\\.|.)*?\]/g, a.lastIndex = r, a = a.exec(n) || [], l(a[0].length); break; case "|": case "^": case "$": case "*": case "+": case "?": o(1); break; case "{": a = /\{\d+,?\d*\}/g, a.lastIndex = r, a = a.exec(n), a ? o(a[0].length) : l(1); break; case "(": if (n[r + 1] === "?") switch (n[r + 2]) { case ":": s += "(?:", r += 3, s += i() + "|$)"; break; case "=": s += "(?=", r += 3, s += i() + ")"; break; case "!": a = r, r += 3, i(), s += n.substr(a, r - a); break; case "<": switch (n[r + 3]) { case "=": case "!": a = r, r += 4, i(), s += n.substr(a, r - a); break; default: o(n.indexOf(">", r) - r + 1), s += i() + "|$)"; break; } break; } else o(1), s += i() + "|$)"; break; case ")": return ++r, s; default: l(1); break; } return s; } return new RegExp(i(), t.flags); } function lm(t) { return t.rules.find((e) => Ne(e) && e.entry); } function um(t) { return t.rules.filter((e) => Jt(e) && e.hidden); } function Vf(t, e) { const n = /* @__PURE__ */ new Set(), r = lm(t); if (!r) return new Set(t.rules); const i = [r].concat(um(t)); for (const a of i) qf(a, n, e); const s = /* @__PURE__ */ new Set(); for (const a of t.rules) (n.has(a.name) || Jt(a) && a.hidden) && s.add(a); return s; } function qf(t, e, n) { e.add(t.name), Hr(t).forEach((r) => { if (Wt(r) || n) { const i