@kitn.ai/ui
Version:
Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.
1,675 lines • 164 kB
JavaScript
var yn = Object.defineProperty;
var _n = (n, e, t) => e in n ? yn(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var f = (n, e, t) => _n(n, typeof e != "symbol" ? e + "" : e, t);
var x = class extends Error {
constructor(n) {
super(n), this.name = "ShikiError";
}
};
function bn(n) {
return Ke(n);
}
function Ke(n) {
return Array.isArray(n) ? Sn(n) : n instanceof RegExp ? n : typeof n == "object" ? Cn(n) : n;
}
function Sn(n) {
let e = [];
for (let t = 0, r = n.length; t < r; t++)
e[t] = Ke(n[t]);
return e;
}
function Cn(n) {
let e = {};
for (let t in n)
e[t] = Ke(n[t]);
return e;
}
function Tt(n, ...e) {
return e.forEach((t) => {
for (let r in t)
n[r] = t[r];
}), n;
}
function xt(n) {
const e = ~n.lastIndexOf("/") || ~n.lastIndexOf("\\");
return e === 0 ? n : ~e === n.length - 1 ? xt(n.substring(0, n.length - 1)) : n.substr(~e + 1);
}
var Ee = /\$(\d+)|\${(\d+):\/(downcase|upcase)}/g, ue = class {
static hasCaptures(n) {
return n === null ? !1 : (Ee.lastIndex = 0, Ee.test(n));
}
static replaceCaptures(n, e, t) {
return n.replace(Ee, (r, s, o, a) => {
let i = t[parseInt(s || o, 10)];
if (i) {
let l = e.substring(i.start, i.end);
for (; l[0] === "."; )
l = l.substring(1);
switch (a) {
case "downcase":
return l.toLowerCase();
case "upcase":
return l.toUpperCase();
default:
return l;
}
} else
return r;
});
}
};
function At(n, e) {
return n < e ? -1 : n > e ? 1 : 0;
}
function Nt(n, e) {
if (n === null && e === null)
return 0;
if (!n)
return -1;
if (!e)
return 1;
let t = n.length, r = e.length;
if (t === r) {
for (let s = 0; s < t; s++) {
let o = At(n[s], e[s]);
if (o !== 0)
return o;
}
return 0;
}
return t - r;
}
function rt(n) {
return !!(/^#[0-9a-f]{6}$/i.test(n) || /^#[0-9a-f]{8}$/i.test(n) || /^#[0-9a-f]{3}$/i.test(n) || /^#[0-9a-f]{4}$/i.test(n));
}
function Et(n) {
return n.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, "\\$&");
}
var Pt = class {
constructor(n) {
f(this, "cache", /* @__PURE__ */ new Map());
this.fn = n;
}
get(n) {
if (this.cache.has(n))
return this.cache.get(n);
const e = this.fn(n);
return this.cache.set(n, e), e;
}
}, pe = class {
constructor(n, e, t) {
f(this, "_cachedMatchRoot", new Pt(
(n) => this._root.match(n)
));
this._colorMap = n, this._defaults = e, this._root = t;
}
static createFromRawTheme(n, e) {
return this.createFromParsedTheme(vn(n), e);
}
static createFromParsedTheme(n, e) {
return Tn(n, e);
}
getColorMap() {
return this._colorMap.getColorMap();
}
getDefaults() {
return this._defaults;
}
match(n) {
if (n === null)
return this._defaults;
const e = n.scopeName, r = this._cachedMatchRoot.get(e).find(
(s) => wn(n.parent, s.parentScopes)
);
return r ? new It(
r.fontStyle,
r.foreground,
r.background
) : null;
}
}, Pe = class fe {
constructor(e, t) {
this.parent = e, this.scopeName = t;
}
static push(e, t) {
for (const r of t)
e = new fe(e, r);
return e;
}
static from(...e) {
let t = null;
for (let r = 0; r < e.length; r++)
t = new fe(t, e[r]);
return t;
}
push(e) {
return new fe(this, e);
}
getSegments() {
let e = this;
const t = [];
for (; e; )
t.push(e.scopeName), e = e.parent;
return t.reverse(), t;
}
toString() {
return this.getSegments().join(" ");
}
extends(e) {
return this === e ? !0 : this.parent === null ? !1 : this.parent.extends(e);
}
getExtensionIfDefined(e) {
const t = [];
let r = this;
for (; r && r !== e; )
t.push(r.scopeName), r = r.parent;
return r === e ? t.reverse() : void 0;
}
};
function wn(n, e) {
if (e.length === 0)
return !0;
for (let t = 0; t < e.length; t++) {
let r = e[t], s = !1;
if (r === ">") {
if (t === e.length - 1)
return !1;
r = e[++t], s = !0;
}
for (; n && !kn(n.scopeName, r); ) {
if (s)
return !1;
n = n.parent;
}
if (!n)
return !1;
n = n.parent;
}
return !0;
}
function kn(n, e) {
return e === n || n.startsWith(e) && n[e.length] === ".";
}
var It = class {
constructor(n, e, t) {
this.fontStyle = n, this.foregroundId = e, this.backgroundId = t;
}
};
function vn(n) {
if (!n)
return [];
if (!n.settings || !Array.isArray(n.settings))
return [];
let e = n.settings, t = [], r = 0;
for (let s = 0, o = e.length; s < o; s++) {
let a = e[s];
if (!a.settings)
continue;
let i;
if (typeof a.scope == "string") {
let u = a.scope;
u = u.replace(/^[,]+/, ""), u = u.replace(/[,]+$/, ""), i = u.split(",");
} else Array.isArray(a.scope) ? i = a.scope : i = [""];
let l = -1;
if (typeof a.settings.fontStyle == "string") {
l = 0;
let u = a.settings.fontStyle.split(" ");
for (let d = 0, g = u.length; d < g; d++)
switch (u[d]) {
case "italic":
l = l | 1;
break;
case "bold":
l = l | 2;
break;
case "underline":
l = l | 4;
break;
case "strikethrough":
l = l | 8;
break;
}
}
let c = null;
typeof a.settings.foreground == "string" && rt(a.settings.foreground) && (c = a.settings.foreground);
let h = null;
typeof a.settings.background == "string" && rt(a.settings.background) && (h = a.settings.background);
for (let u = 0, d = i.length; u < d; u++) {
let m = i[u].trim().split(" "), w = m[m.length - 1], S = null;
m.length > 1 && (S = m.slice(0, m.length - 1), S.reverse()), t[r++] = new Rn(
w,
S,
s,
l,
c,
h
);
}
}
return t;
}
var Rn = class {
constructor(n, e, t, r, s, o) {
this.scope = n, this.parentScopes = e, this.index = t, this.fontStyle = r, this.foreground = s, this.background = o;
}
}, P = /* @__PURE__ */ ((n) => (n[n.NotSet = -1] = "NotSet", n[n.None = 0] = "None", n[n.Italic = 1] = "Italic", n[n.Bold = 2] = "Bold", n[n.Underline = 4] = "Underline", n[n.Strikethrough = 8] = "Strikethrough", n))(P || {});
function Tn(n, e) {
n.sort((l, c) => {
let h = At(l.scope, c.scope);
return h !== 0 || (h = Nt(l.parentScopes, c.parentScopes), h !== 0) ? h : l.index - c.index;
});
let t = 0, r = "#000000", s = "#ffffff";
for (; n.length >= 1 && n[0].scope === ""; ) {
let l = n.shift();
l.fontStyle !== -1 && (t = l.fontStyle), l.foreground !== null && (r = l.foreground), l.background !== null && (s = l.background);
}
let o = new xn(e), a = new It(t, o.getId(r), o.getId(s)), i = new Nn(new Ge(0, null, -1, 0, 0), []);
for (let l = 0, c = n.length; l < c; l++) {
let h = n[l];
i.insert(0, h.scope, h.parentScopes, h.fontStyle, o.getId(h.foreground), o.getId(h.background));
}
return new pe(o, a, i);
}
var xn = class {
constructor(n) {
f(this, "_isFrozen");
f(this, "_lastColorId");
f(this, "_id2color");
f(this, "_color2id");
if (this._lastColorId = 0, this._id2color = [], this._color2id = /* @__PURE__ */ Object.create(null), Array.isArray(n)) {
this._isFrozen = !0;
for (let e = 0, t = n.length; e < t; e++)
this._color2id[n[e]] = e, this._id2color[e] = n[e];
} else
this._isFrozen = !1;
}
getId(n) {
if (n === null)
return 0;
n = n.toUpperCase();
let e = this._color2id[n];
if (e)
return e;
if (this._isFrozen)
throw new Error(`Missing color in color map - ${n}`);
return e = ++this._lastColorId, this._color2id[n] = e, this._id2color[e] = n, e;
}
getColorMap() {
return this._id2color.slice(0);
}
}, An = Object.freeze([]), Ge = class Lt {
constructor(e, t, r, s, o) {
f(this, "scopeDepth");
f(this, "parentScopes");
f(this, "fontStyle");
f(this, "foreground");
f(this, "background");
this.scopeDepth = e, this.parentScopes = t || An, this.fontStyle = r, this.foreground = s, this.background = o;
}
clone() {
return new Lt(this.scopeDepth, this.parentScopes, this.fontStyle, this.foreground, this.background);
}
static cloneArr(e) {
let t = [];
for (let r = 0, s = e.length; r < s; r++)
t[r] = e[r].clone();
return t;
}
acceptOverwrite(e, t, r, s) {
this.scopeDepth > e ? console.log("how did this happen?") : this.scopeDepth = e, t !== -1 && (this.fontStyle = t), r !== 0 && (this.foreground = r), s !== 0 && (this.background = s);
}
}, Nn = class De {
constructor(e, t = [], r = {}) {
f(this, "_rulesWithParentScopes");
this._mainRule = e, this._children = r, this._rulesWithParentScopes = t;
}
static _cmpBySpecificity(e, t) {
if (e.scopeDepth !== t.scopeDepth)
return t.scopeDepth - e.scopeDepth;
let r = 0, s = 0;
for (; e.parentScopes[r] === ">" && r++, t.parentScopes[s] === ">" && s++, !(r >= e.parentScopes.length || s >= t.parentScopes.length); ) {
const o = t.parentScopes[s].length - e.parentScopes[r].length;
if (o !== 0)
return o;
r++, s++;
}
return t.parentScopes.length - e.parentScopes.length;
}
match(e) {
if (e !== "") {
let r = e.indexOf("."), s, o;
if (r === -1 ? (s = e, o = "") : (s = e.substring(0, r), o = e.substring(r + 1)), this._children.hasOwnProperty(s))
return this._children[s].match(o);
}
const t = this._rulesWithParentScopes.concat(this._mainRule);
return t.sort(De._cmpBySpecificity), t;
}
insert(e, t, r, s, o, a) {
if (t === "") {
this._doInsertHere(e, r, s, o, a);
return;
}
let i = t.indexOf("."), l, c;
i === -1 ? (l = t, c = "") : (l = t.substring(0, i), c = t.substring(i + 1));
let h;
this._children.hasOwnProperty(l) ? h = this._children[l] : (h = new De(this._mainRule.clone(), Ge.cloneArr(this._rulesWithParentScopes)), this._children[l] = h), h.insert(e + 1, c, r, s, o, a);
}
_doInsertHere(e, t, r, s, o) {
if (t === null) {
this._mainRule.acceptOverwrite(e, r, s, o);
return;
}
for (let a = 0, i = this._rulesWithParentScopes.length; a < i; a++) {
let l = this._rulesWithParentScopes[a];
if (Nt(l.parentScopes, t) === 0) {
l.acceptOverwrite(e, r, s, o);
return;
}
}
r === -1 && (r = this._mainRule.fontStyle), s === 0 && (s = this._mainRule.foreground), o === 0 && (o = this._mainRule.background), this._rulesWithParentScopes.push(new Ge(e, t, r, s, o));
}
}, X = class B {
static toBinaryStr(e) {
return e.toString(2).padStart(32, "0");
}
static print(e) {
const t = B.getLanguageId(e), r = B.getTokenType(e), s = B.getFontStyle(e), o = B.getForeground(e), a = B.getBackground(e);
console.log({
languageId: t,
tokenType: r,
fontStyle: s,
foreground: o,
background: a
});
}
static getLanguageId(e) {
return (e & 255) >>> 0;
}
static getTokenType(e) {
return (e & 768) >>> 8;
}
static containsBalancedBrackets(e) {
return (e & 1024) !== 0;
}
static getFontStyle(e) {
return (e & 30720) >>> 11;
}
static getForeground(e) {
return (e & 16744448) >>> 15;
}
static getBackground(e) {
return (e & 4278190080) >>> 24;
}
/**
* Updates the fields in `metadata`.
* A value of `0`, `NotSet` or `null` indicates that the corresponding field should be left as is.
*/
static set(e, t, r, s, o, a, i) {
let l = B.getLanguageId(e), c = B.getTokenType(e), h = B.containsBalancedBrackets(e) ? 1 : 0, u = B.getFontStyle(e), d = B.getForeground(e), g = B.getBackground(e);
return t !== 0 && (l = t), r !== 8 && (c = r), s !== null && (h = s ? 1 : 0), o !== -1 && (u = o), a !== 0 && (d = a), i !== 0 && (g = i), (l << 0 | c << 8 | h << 10 | u << 11 | d << 15 | g << 24) >>> 0;
}
};
function me(n, e) {
const t = [], r = En(n);
let s = r.next();
for (; s !== null; ) {
let l = 0;
if (s.length === 2 && s.charAt(1) === ":") {
switch (s.charAt(0)) {
case "R":
l = 1;
break;
case "L":
l = -1;
break;
default:
console.log(`Unknown priority ${s} in scope selector`);
}
s = r.next();
}
let c = a();
if (t.push({ matcher: c, priority: l }), s !== ",")
break;
s = r.next();
}
return t;
function o() {
if (s === "-") {
s = r.next();
const l = o();
return (c) => !!l && !l(c);
}
if (s === "(") {
s = r.next();
const l = i();
return s === ")" && (s = r.next()), l;
}
if (st(s)) {
const l = [];
do
l.push(s), s = r.next();
while (st(s));
return (c) => e(l, c);
}
return null;
}
function a() {
const l = [];
let c = o();
for (; c; )
l.push(c), c = o();
return (h) => l.every((u) => u(h));
}
function i() {
const l = [];
let c = a();
for (; c && (l.push(c), s === "|" || s === ","); ) {
do
s = r.next();
while (s === "|" || s === ",");
c = a();
}
return (h) => l.some((u) => u(h));
}
}
function st(n) {
return !!n && !!n.match(/[\w\.:]+/);
}
function En(n) {
let e = /([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g, t = e.exec(n);
return {
next: () => {
if (!t)
return null;
const r = t[0];
return t = e.exec(n), r;
}
};
}
function Ot(n) {
typeof n.dispose == "function" && n.dispose();
}
var ne = class {
constructor(n) {
this.scopeName = n;
}
toKey() {
return this.scopeName;
}
}, Pn = class {
constructor(n, e) {
this.scopeName = n, this.ruleName = e;
}
toKey() {
return `${this.scopeName}#${this.ruleName}`;
}
}, In = class {
constructor() {
f(this, "_references", []);
f(this, "_seenReferenceKeys", /* @__PURE__ */ new Set());
f(this, "visitedRule", /* @__PURE__ */ new Set());
}
get references() {
return this._references;
}
add(n) {
const e = n.toKey();
this._seenReferenceKeys.has(e) || (this._seenReferenceKeys.add(e), this._references.push(n));
}
}, Ln = class {
constructor(n, e) {
f(this, "seenFullScopeRequests", /* @__PURE__ */ new Set());
f(this, "seenPartialScopeRequests", /* @__PURE__ */ new Set());
f(this, "Q");
this.repo = n, this.initialScopeName = e, this.seenFullScopeRequests.add(this.initialScopeName), this.Q = [new ne(this.initialScopeName)];
}
processQueue() {
const n = this.Q;
this.Q = [];
const e = new In();
for (const t of n)
On(t, this.initialScopeName, this.repo, e);
for (const t of e.references)
if (t instanceof ne) {
if (this.seenFullScopeRequests.has(t.scopeName))
continue;
this.seenFullScopeRequests.add(t.scopeName), this.Q.push(t);
} else {
if (this.seenFullScopeRequests.has(t.scopeName) || this.seenPartialScopeRequests.has(t.toKey()))
continue;
this.seenPartialScopeRequests.add(t.toKey()), this.Q.push(t);
}
}
};
function On(n, e, t, r) {
const s = t.lookup(n.scopeName);
if (!s) {
if (n.scopeName === e)
throw new Error(`No grammar provided for <${e}>`);
return;
}
const o = t.lookup(e);
n instanceof ne ? ge({ baseGrammar: o, selfGrammar: s }, r) : $e(
n.ruleName,
{ baseGrammar: o, selfGrammar: s, repository: s.repository },
r
);
const a = t.injections(n.scopeName);
if (a)
for (const i of a)
r.add(new ne(i));
}
function $e(n, e, t) {
if (e.repository && e.repository[n]) {
const r = e.repository[n];
ye([r], e, t);
}
}
function ge(n, e) {
n.selfGrammar.patterns && Array.isArray(n.selfGrammar.patterns) && ye(
n.selfGrammar.patterns,
{ ...n, repository: n.selfGrammar.repository },
e
), n.selfGrammar.injections && ye(
Object.values(n.selfGrammar.injections),
{ ...n, repository: n.selfGrammar.repository },
e
);
}
function ye(n, e, t) {
for (const r of n) {
if (t.visitedRule.has(r))
continue;
t.visitedRule.add(r);
const s = r.repository ? Tt({}, e.repository, r.repository) : e.repository;
Array.isArray(r.patterns) && ye(r.patterns, { ...e, repository: s }, t);
const o = r.include;
if (!o)
continue;
const a = Mt(o);
switch (a.kind) {
case 0:
ge({ ...e, selfGrammar: e.baseGrammar }, t);
break;
case 1:
ge(e, t);
break;
case 2:
$e(a.ruleName, { ...e, repository: s }, t);
break;
case 3:
case 4:
const i = a.scopeName === e.selfGrammar.scopeName ? e.selfGrammar : a.scopeName === e.baseGrammar.scopeName ? e.baseGrammar : void 0;
if (i) {
const l = { baseGrammar: e.baseGrammar, selfGrammar: i, repository: s };
a.kind === 4 ? $e(a.ruleName, l, t) : ge(l, t);
} else
a.kind === 4 ? t.add(new Pn(a.scopeName, a.ruleName)) : t.add(new ne(a.scopeName));
break;
}
}
}
var Mn = class {
constructor() {
f(this, "kind", 0);
}
}, Bn = class {
constructor() {
f(this, "kind", 1);
}
}, Gn = class {
constructor(n) {
f(this, "kind", 2);
this.ruleName = n;
}
}, Dn = class {
constructor(n) {
f(this, "kind", 3);
this.scopeName = n;
}
}, $n = class {
constructor(n, e) {
f(this, "kind", 4);
this.scopeName = n, this.ruleName = e;
}
};
function Mt(n) {
if (n === "$base")
return new Mn();
if (n === "$self")
return new Bn();
const e = n.indexOf("#");
if (e === -1)
return new Dn(n);
if (e === 0)
return new Gn(n.substring(1));
{
const t = n.substring(0, e), r = n.substring(e + 1);
return new $n(t, r);
}
}
var jn = /\\(\d+)/, ot = /\\(\d+)/g, Fn = -1, Bt = -2;
var le = class {
constructor(n, e, t, r) {
f(this, "$location");
f(this, "id");
f(this, "_nameIsCapturing");
f(this, "_name");
f(this, "_contentNameIsCapturing");
f(this, "_contentName");
this.$location = n, this.id = e, this._name = t || null, this._nameIsCapturing = ue.hasCaptures(this._name), this._contentName = r || null, this._contentNameIsCapturing = ue.hasCaptures(this._contentName);
}
get debugName() {
const n = this.$location ? `${xt(this.$location.filename)}:${this.$location.line}` : "unknown";
return `${this.constructor.name}#${this.id} @ ${n}`;
}
getName(n, e) {
return !this._nameIsCapturing || this._name === null || n === null || e === null ? this._name : ue.replaceCaptures(this._name, n, e);
}
getContentName(n, e) {
return !this._contentNameIsCapturing || this._contentName === null ? this._contentName : ue.replaceCaptures(this._contentName, n, e);
}
}, Wn = class extends le {
constructor(e, t, r, s, o) {
super(e, t, r, s);
f(this, "retokenizeCapturedWithRuleId");
this.retokenizeCapturedWithRuleId = o;
}
dispose() {
}
collectPatterns(e, t) {
throw new Error("Not supported!");
}
compile(e, t) {
throw new Error("Not supported!");
}
compileAG(e, t, r, s) {
throw new Error("Not supported!");
}
}, zn = class extends le {
constructor(e, t, r, s, o) {
super(e, t, r, null);
f(this, "_match");
f(this, "captures");
f(this, "_cachedCompiledPatterns");
this._match = new re(s, this.id), this.captures = o, this._cachedCompiledPatterns = null;
}
dispose() {
this._cachedCompiledPatterns && (this._cachedCompiledPatterns.dispose(), this._cachedCompiledPatterns = null);
}
get debugMatchRegExp() {
return `${this._match.source}`;
}
collectPatterns(e, t) {
t.push(this._match);
}
compile(e, t) {
return this._getCachedCompiledPatterns(e).compile(e);
}
compileAG(e, t, r, s) {
return this._getCachedCompiledPatterns(e).compileAG(e, r, s);
}
_getCachedCompiledPatterns(e) {
return this._cachedCompiledPatterns || (this._cachedCompiledPatterns = new se(), this.collectPatterns(e, this._cachedCompiledPatterns)), this._cachedCompiledPatterns;
}
}, at = class extends le {
constructor(e, t, r, s, o) {
super(e, t, r, s);
f(this, "hasMissingPatterns");
f(this, "patterns");
f(this, "_cachedCompiledPatterns");
this.patterns = o.patterns, this.hasMissingPatterns = o.hasMissingPatterns, this._cachedCompiledPatterns = null;
}
dispose() {
this._cachedCompiledPatterns && (this._cachedCompiledPatterns.dispose(), this._cachedCompiledPatterns = null);
}
collectPatterns(e, t) {
for (const r of this.patterns)
e.getRule(r).collectPatterns(e, t);
}
compile(e, t) {
return this._getCachedCompiledPatterns(e).compile(e);
}
compileAG(e, t, r, s) {
return this._getCachedCompiledPatterns(e).compileAG(e, r, s);
}
_getCachedCompiledPatterns(e) {
return this._cachedCompiledPatterns || (this._cachedCompiledPatterns = new se(), this.collectPatterns(e, this._cachedCompiledPatterns)), this._cachedCompiledPatterns;
}
}, je = class extends le {
constructor(e, t, r, s, o, a, i, l, c, h) {
super(e, t, r, s);
f(this, "_begin");
f(this, "beginCaptures");
f(this, "_end");
f(this, "endHasBackReferences");
f(this, "endCaptures");
f(this, "applyEndPatternLast");
f(this, "hasMissingPatterns");
f(this, "patterns");
f(this, "_cachedCompiledPatterns");
this._begin = new re(o, this.id), this.beginCaptures = a, this._end = new re(i || "", -1), this.endHasBackReferences = this._end.hasBackReferences, this.endCaptures = l, this.applyEndPatternLast = c || !1, this.patterns = h.patterns, this.hasMissingPatterns = h.hasMissingPatterns, this._cachedCompiledPatterns = null;
}
dispose() {
this._cachedCompiledPatterns && (this._cachedCompiledPatterns.dispose(), this._cachedCompiledPatterns = null);
}
get debugBeginRegExp() {
return `${this._begin.source}`;
}
get debugEndRegExp() {
return `${this._end.source}`;
}
getEndWithResolvedBackReferences(e, t) {
return this._end.resolveBackReferences(e, t);
}
collectPatterns(e, t) {
t.push(this._begin);
}
compile(e, t) {
return this._getCachedCompiledPatterns(e, t).compile(e);
}
compileAG(e, t, r, s) {
return this._getCachedCompiledPatterns(e, t).compileAG(e, r, s);
}
_getCachedCompiledPatterns(e, t) {
if (!this._cachedCompiledPatterns) {
this._cachedCompiledPatterns = new se();
for (const r of this.patterns)
e.getRule(r).collectPatterns(e, this._cachedCompiledPatterns);
this.applyEndPatternLast ? this._cachedCompiledPatterns.push(this._end.hasBackReferences ? this._end.clone() : this._end) : this._cachedCompiledPatterns.unshift(this._end.hasBackReferences ? this._end.clone() : this._end);
}
return this._end.hasBackReferences && (this.applyEndPatternLast ? this._cachedCompiledPatterns.setSource(this._cachedCompiledPatterns.length() - 1, t) : this._cachedCompiledPatterns.setSource(0, t)), this._cachedCompiledPatterns;
}
}, _e = class extends le {
constructor(e, t, r, s, o, a, i, l, c) {
super(e, t, r, s);
f(this, "_begin");
f(this, "beginCaptures");
f(this, "whileCaptures");
f(this, "_while");
f(this, "whileHasBackReferences");
f(this, "hasMissingPatterns");
f(this, "patterns");
f(this, "_cachedCompiledPatterns");
f(this, "_cachedCompiledWhilePatterns");
this._begin = new re(o, this.id), this.beginCaptures = a, this.whileCaptures = l, this._while = new re(i, Bt), this.whileHasBackReferences = this._while.hasBackReferences, this.patterns = c.patterns, this.hasMissingPatterns = c.hasMissingPatterns, this._cachedCompiledPatterns = null, this._cachedCompiledWhilePatterns = null;
}
dispose() {
this._cachedCompiledPatterns && (this._cachedCompiledPatterns.dispose(), this._cachedCompiledPatterns = null), this._cachedCompiledWhilePatterns && (this._cachedCompiledWhilePatterns.dispose(), this._cachedCompiledWhilePatterns = null);
}
get debugBeginRegExp() {
return `${this._begin.source}`;
}
get debugWhileRegExp() {
return `${this._while.source}`;
}
getWhileWithResolvedBackReferences(e, t) {
return this._while.resolveBackReferences(e, t);
}
collectPatterns(e, t) {
t.push(this._begin);
}
compile(e, t) {
return this._getCachedCompiledPatterns(e).compile(e);
}
compileAG(e, t, r, s) {
return this._getCachedCompiledPatterns(e).compileAG(e, r, s);
}
_getCachedCompiledPatterns(e) {
if (!this._cachedCompiledPatterns) {
this._cachedCompiledPatterns = new se();
for (const t of this.patterns)
e.getRule(t).collectPatterns(e, this._cachedCompiledPatterns);
}
return this._cachedCompiledPatterns;
}
compileWhile(e, t) {
return this._getCachedCompiledWhilePatterns(e, t).compile(e);
}
compileWhileAG(e, t, r, s) {
return this._getCachedCompiledWhilePatterns(e, t).compileAG(e, r, s);
}
_getCachedCompiledWhilePatterns(e, t) {
return this._cachedCompiledWhilePatterns || (this._cachedCompiledWhilePatterns = new se(), this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences ? this._while.clone() : this._while)), this._while.hasBackReferences && this._cachedCompiledWhilePatterns.setSource(0, t || ""), this._cachedCompiledWhilePatterns;
}
}, Gt = class E {
static createCaptureRule(e, t, r, s, o) {
return e.registerRule((a) => new Wn(t, a, r, s, o));
}
static getCompiledRuleId(e, t, r) {
return e.id || t.registerRule((s) => {
if (e.id = s, e.match)
return new zn(
e.$vscodeTextmateLocation,
e.id,
e.name,
e.match,
E._compileCaptures(e.captures, t, r)
);
if (typeof e.begin > "u") {
e.repository && (r = Tt({}, r, e.repository));
let o = e.patterns;
return typeof o > "u" && e.include && (o = [{ include: e.include }]), new at(
e.$vscodeTextmateLocation,
e.id,
e.name,
e.contentName,
E._compilePatterns(o, t, r)
);
}
return e.while ? new _e(
e.$vscodeTextmateLocation,
e.id,
e.name,
e.contentName,
e.begin,
E._compileCaptures(e.beginCaptures || e.captures, t, r),
e.while,
E._compileCaptures(e.whileCaptures || e.captures, t, r),
E._compilePatterns(e.patterns, t, r)
) : new je(
e.$vscodeTextmateLocation,
e.id,
e.name,
e.contentName,
e.begin,
E._compileCaptures(e.beginCaptures || e.captures, t, r),
e.end,
E._compileCaptures(e.endCaptures || e.captures, t, r),
e.applyEndPatternLast,
E._compilePatterns(e.patterns, t, r)
);
}), e.id;
}
static _compileCaptures(e, t, r) {
let s = [];
if (e) {
let o = 0;
for (const a in e) {
if (a === "$vscodeTextmateLocation")
continue;
const i = parseInt(a, 10);
i > o && (o = i);
}
for (let a = 0; a <= o; a++)
s[a] = null;
for (const a in e) {
if (a === "$vscodeTextmateLocation")
continue;
const i = parseInt(a, 10);
let l = 0;
e[a].patterns && (l = E.getCompiledRuleId(e[a], t, r)), s[i] = E.createCaptureRule(t, e[a].$vscodeTextmateLocation, e[a].name, e[a].contentName, l);
}
}
return s;
}
static _compilePatterns(e, t, r) {
let s = [];
if (e)
for (let o = 0, a = e.length; o < a; o++) {
const i = e[o];
let l = -1;
if (i.include) {
const c = Mt(i.include);
switch (c.kind) {
case 0:
case 1:
l = E.getCompiledRuleId(r[i.include], t, r);
break;
case 2:
let h = r[c.ruleName];
h && (l = E.getCompiledRuleId(h, t, r));
break;
case 3:
case 4:
const u = c.scopeName, d = c.kind === 4 ? c.ruleName : null, g = t.getExternalGrammar(u, r);
if (g)
if (d) {
let m = g.repository[d];
m && (l = E.getCompiledRuleId(m, t, g.repository));
} else
l = E.getCompiledRuleId(g.repository.$self, t, g.repository);
break;
}
} else
l = E.getCompiledRuleId(i, t, r);
if (l !== -1) {
const c = t.getRule(l);
let h = !1;
if ((c instanceof at || c instanceof je || c instanceof _e) && c.hasMissingPatterns && c.patterns.length === 0 && (h = !0), h)
continue;
s.push(l);
}
}
return {
patterns: s,
hasMissingPatterns: (e ? e.length : 0) !== s.length
};
}
}, re = class Dt {
constructor(e, t) {
f(this, "source");
f(this, "ruleId");
f(this, "hasAnchor");
f(this, "hasBackReferences");
f(this, "_anchorCache");
if (e && typeof e == "string") {
const r = e.length;
let s = 0, o = [], a = !1;
for (let i = 0; i < r; i++)
if (e.charAt(i) === "\\" && i + 1 < r) {
const c = e.charAt(i + 1);
c === "z" ? (o.push(e.substring(s, i)), o.push("$(?!\\n)(?<!\\n)"), s = i + 2) : (c === "A" || c === "G") && (a = !0), i++;
}
this.hasAnchor = a, s === 0 ? this.source = e : (o.push(e.substring(s, r)), this.source = o.join(""));
} else
this.hasAnchor = !1, this.source = e;
this.hasAnchor ? this._anchorCache = this._buildAnchorCache() : this._anchorCache = null, this.ruleId = t, typeof this.source == "string" ? this.hasBackReferences = jn.test(this.source) : this.hasBackReferences = !1;
}
clone() {
return new Dt(this.source, this.ruleId);
}
setSource(e) {
this.source !== e && (this.source = e, this.hasAnchor && (this._anchorCache = this._buildAnchorCache()));
}
resolveBackReferences(e, t) {
if (typeof this.source != "string")
throw new Error("This method should only be called if the source is a string");
let r = t.map((s) => e.substring(s.start, s.end));
return ot.lastIndex = 0, this.source.replace(ot, (s, o) => Et(r[parseInt(o, 10)] || ""));
}
_buildAnchorCache() {
if (typeof this.source != "string")
throw new Error("This method should only be called if the source is a string");
let e = [], t = [], r = [], s = [], o, a, i, l;
for (o = 0, a = this.source.length; o < a; o++)
i = this.source.charAt(o), e[o] = i, t[o] = i, r[o] = i, s[o] = i, i === "\\" && o + 1 < a && (l = this.source.charAt(o + 1), l === "A" ? (e[o + 1] = "", t[o + 1] = "", r[o + 1] = "A", s[o + 1] = "A") : l === "G" ? (e[o + 1] = "", t[o + 1] = "G", r[o + 1] = "", s[o + 1] = "G") : (e[o + 1] = l, t[o + 1] = l, r[o + 1] = l, s[o + 1] = l), o++);
return {
A0_G0: e.join(""),
A0_G1: t.join(""),
A1_G0: r.join(""),
A1_G1: s.join("")
};
}
resolveAnchors(e, t) {
return !this.hasAnchor || !this._anchorCache || typeof this.source != "string" ? this.source : e ? t ? this._anchorCache.A1_G1 : this._anchorCache.A1_G0 : t ? this._anchorCache.A0_G1 : this._anchorCache.A0_G0;
}
}, se = class {
constructor() {
f(this, "_items");
f(this, "_hasAnchors");
f(this, "_cached");
f(this, "_anchorCache");
this._items = [], this._hasAnchors = !1, this._cached = null, this._anchorCache = {
A0_G0: null,
A0_G1: null,
A1_G0: null,
A1_G1: null
};
}
dispose() {
this._disposeCaches();
}
_disposeCaches() {
this._cached && (this._cached.dispose(), this._cached = null), this._anchorCache.A0_G0 && (this._anchorCache.A0_G0.dispose(), this._anchorCache.A0_G0 = null), this._anchorCache.A0_G1 && (this._anchorCache.A0_G1.dispose(), this._anchorCache.A0_G1 = null), this._anchorCache.A1_G0 && (this._anchorCache.A1_G0.dispose(), this._anchorCache.A1_G0 = null), this._anchorCache.A1_G1 && (this._anchorCache.A1_G1.dispose(), this._anchorCache.A1_G1 = null);
}
push(n) {
this._items.push(n), this._hasAnchors = this._hasAnchors || n.hasAnchor;
}
unshift(n) {
this._items.unshift(n), this._hasAnchors = this._hasAnchors || n.hasAnchor;
}
length() {
return this._items.length;
}
setSource(n, e) {
this._items[n].source !== e && (this._disposeCaches(), this._items[n].setSource(e));
}
compile(n) {
if (!this._cached) {
let e = this._items.map((t) => t.source);
this._cached = new it(n, e, this._items.map((t) => t.ruleId));
}
return this._cached;
}
compileAG(n, e, t) {
return this._hasAnchors ? e ? t ? (this._anchorCache.A1_G1 || (this._anchorCache.A1_G1 = this._resolveAnchors(n, e, t)), this._anchorCache.A1_G1) : (this._anchorCache.A1_G0 || (this._anchorCache.A1_G0 = this._resolveAnchors(n, e, t)), this._anchorCache.A1_G0) : t ? (this._anchorCache.A0_G1 || (this._anchorCache.A0_G1 = this._resolveAnchors(n, e, t)), this._anchorCache.A0_G1) : (this._anchorCache.A0_G0 || (this._anchorCache.A0_G0 = this._resolveAnchors(n, e, t)), this._anchorCache.A0_G0) : this.compile(n);
}
_resolveAnchors(n, e, t) {
let r = this._items.map((s) => s.resolveAnchors(e, t));
return new it(n, r, this._items.map((s) => s.ruleId));
}
}, it = class {
constructor(n, e, t) {
f(this, "scanner");
this.regExps = e, this.rules = t, this.scanner = n.createOnigScanner(e);
}
dispose() {
typeof this.scanner.dispose == "function" && this.scanner.dispose();
}
toString() {
const n = [];
for (let e = 0, t = this.rules.length; e < t; e++)
n.push(" - " + this.rules[e] + ": " + this.regExps[e]);
return n.join(`
`);
}
findNextMatchSync(n, e, t) {
const r = this.scanner.findNextMatchSync(n, e, t);
return r ? {
ruleId: this.rules[r.index],
captureIndices: r.captureIndices
} : null;
}
}, Ie = class {
constructor(n, e) {
this.languageId = n, this.tokenType = e;
}
}, j, Hn = (j = class {
constructor(e, t) {
f(this, "_defaultAttributes");
f(this, "_embeddedLanguagesMatcher");
f(this, "_getBasicScopeAttributes", new Pt((e) => {
const t = this._scopeToLanguage(e), r = this._toStandardTokenType(e);
return new Ie(t, r);
}));
this._defaultAttributes = new Ie(
e,
8
/* NotSet */
), this._embeddedLanguagesMatcher = new Un(Object.entries(t || {}));
}
getDefaultAttributes() {
return this._defaultAttributes;
}
getBasicScopeAttributes(e) {
return e === null ? j._NULL_SCOPE_METADATA : this._getBasicScopeAttributes.get(e);
}
/**
* Given a produced TM scope, return the language that token describes or null if unknown.
* e.g. source.html => html, source.css.embedded.html => css, punctuation.definition.tag.html => null
*/
_scopeToLanguage(e) {
return this._embeddedLanguagesMatcher.match(e) || 0;
}
_toStandardTokenType(e) {
const t = e.match(j.STANDARD_TOKEN_TYPE_REGEXP);
if (!t)
return 8;
switch (t[1]) {
case "comment":
return 1;
case "string":
return 2;
case "regex":
return 3;
case "meta.embedded":
return 0;
}
throw new Error("Unexpected match for standard token type!");
}
}, f(j, "_NULL_SCOPE_METADATA", new Ie(0, 0)), f(j, "STANDARD_TOKEN_TYPE_REGEXP", /\b(comment|string|regex|meta\.embedded)\b/), j), Un = class {
constructor(n) {
f(this, "values");
f(this, "scopesRegExp");
if (n.length === 0)
this.values = null, this.scopesRegExp = null;
else {
this.values = new Map(n);
const e = n.map(
([t, r]) => Et(t)
);
e.sort(), e.reverse(), this.scopesRegExp = new RegExp(
`^((${e.join(")|(")}))($|\\.)`,
""
);
}
}
match(n) {
if (!this.scopesRegExp)
return;
const e = n.match(this.scopesRegExp);
if (e)
return this.values.get(e[1]);
}
};
typeof process < "u" && process.env.VSCODE_TEXTMATE_DEBUG;
var lt = class {
constructor(n, e) {
this.stack = n, this.stoppedEarly = e;
}
};
function $t(n, e, t, r, s, o, a, i) {
const l = e.content.length;
let c = !1, h = -1;
if (a) {
const g = qn(
n,
e,
t,
r,
s,
o
);
s = g.stack, r = g.linePos, t = g.isFirstLine, h = g.anchorPosition;
}
const u = Date.now();
for (; !c; ) {
if (i !== 0 && Date.now() - u > i)
return new lt(s, !0);
d();
}
return new lt(s, !1);
function d() {
const g = Vn(
n,
e,
t,
r,
s,
h
);
if (!g) {
o.produce(s, l), c = !0;
return;
}
const m = g.captureIndices, w = g.matchedRuleId, S = m && m.length > 0 ? m[0].end > r : !1;
if (w === Fn) {
const _ = s.getRule(n);
o.produce(s, m[0].start), s = s.withContentNameScopesList(s.nameScopesList), ee(
n,
e,
t,
s,
o,
_.endCaptures,
m
), o.produce(s, m[0].end);
const y = s;
if (s = s.parent, h = y.getAnchorPos(), !S && y.getEnterPos() === r) {
s = y, o.produce(s, l), c = !0;
return;
}
} else {
const _ = n.getRule(w);
o.produce(s, m[0].start);
const y = s, b = _.getName(e.content, m), v = s.contentNameScopesList.pushAttributed(
b,
n
);
if (s = s.push(
w,
r,
h,
m[0].end === l,
null,
v,
v
), _ instanceof je) {
const k = _;
ee(
n,
e,
t,
s,
o,
k.beginCaptures,
m
), o.produce(s, m[0].end), h = m[0].end;
const T = k.getContentName(
e.content,
m
), L = v.pushAttributed(
T,
n
);
if (s = s.withContentNameScopesList(L), k.endHasBackReferences && (s = s.withEndRule(
k.getEndWithResolvedBackReferences(
e.content,
m
)
)), !S && y.hasSameRuleAs(s)) {
s = s.pop(), o.produce(s, l), c = !0;
return;
}
} else if (_ instanceof _e) {
const k = _;
ee(
n,
e,
t,
s,
o,
k.beginCaptures,
m
), o.produce(s, m[0].end), h = m[0].end;
const T = k.getContentName(
e.content,
m
), L = v.pushAttributed(
T,
n
);
if (s = s.withContentNameScopesList(L), k.whileHasBackReferences && (s = s.withEndRule(
k.getWhileWithResolvedBackReferences(
e.content,
m
)
)), !S && y.hasSameRuleAs(s)) {
s = s.pop(), o.produce(s, l), c = !0;
return;
}
} else if (ee(
n,
e,
t,
s,
o,
_.captures,
m
), o.produce(s, m[0].end), s = s.pop(), !S) {
s = s.safePop(), o.produce(s, l), c = !0;
return;
}
}
m[0].end > r && (r = m[0].end, t = !1);
}
}
function qn(n, e, t, r, s, o) {
let a = s.beginRuleCapturedEOL ? 0 : -1;
const i = [];
for (let l = s; l; l = l.pop()) {
const c = l.getRule(n);
c instanceof _e && i.push({
rule: c,
stack: l
});
}
for (let l = i.pop(); l; l = i.pop()) {
const { ruleScanner: c, findOptions: h } = Xn(l.rule, n, l.stack.endRule, t, r === a), u = c.findNextMatchSync(e, r, h);
if (u) {
if (u.ruleId !== Bt) {
s = l.stack.pop();
break;
}
u.captureIndices && u.captureIndices.length && (o.produce(l.stack, u.captureIndices[0].start), ee(n, e, t, l.stack, o, l.rule.whileCaptures, u.captureIndices), o.produce(l.stack, u.captureIndices[0].end), a = u.captureIndices[0].end, u.captureIndices[0].end > r && (r = u.captureIndices[0].end, t = !1));
} else {
s = l.stack.pop();
break;
}
}
return { stack: s, linePos: r, anchorPosition: a, isFirstLine: t };
}
function Vn(n, e, t, r, s, o) {
const a = Kn(n, e, t, r, s, o), i = n.getInjections();
if (i.length === 0)
return a;
const l = Yn(i, n, e, t, r, s, o);
if (!l)
return a;
if (!a)
return l;
const c = a.captureIndices[0].start, h = l.captureIndices[0].start;
return h < c || l.priorityMatch && h === c ? l : a;
}
function Kn(n, e, t, r, s, o) {
const a = s.getRule(n), { ruleScanner: i, findOptions: l } = jt(a, n, s.endRule, t, r === o), c = i.findNextMatchSync(e, r, l);
return c ? {
captureIndices: c.captureIndices,
matchedRuleId: c.ruleId
} : null;
}
function Yn(n, e, t, r, s, o, a) {
let i = Number.MAX_VALUE, l = null, c, h = 0;
const u = o.contentNameScopesList.getScopeNames();
for (let d = 0, g = n.length; d < g; d++) {
const m = n[d];
if (!m.matcher(u))
continue;
const w = e.getRule(m.ruleId), { ruleScanner: S, findOptions: _ } = jt(w, e, null, r, s === a), y = S.findNextMatchSync(t, s, _);
if (!y)
continue;
const b = y.captureIndices[0].start;
if (!(b >= i) && (i = b, l = y.captureIndices, c = y.ruleId, h = m.priority, i === s))
break;
}
return l ? {
priorityMatch: h === -1,
captureIndices: l,
matchedRuleId: c
} : null;
}
function jt(n, e, t, r, s) {
return {
ruleScanner: n.compileAG(e, t, r, s),
findOptions: 0
/* None */
};
}
function Xn(n, e, t, r, s) {
return {
ruleScanner: n.compileWhileAG(e, t, r, s),
findOptions: 0
/* None */
};
}
function ee(n, e, t, r, s, o, a) {
if (o.length === 0)
return;
const i = e.content, l = Math.min(o.length, a.length), c = [], h = a[0].end;
for (let u = 0; u < l; u++) {
const d = o[u];
if (d === null)
continue;
const g = a[u];
if (g.length === 0)
continue;
if (g.start > h)
break;
for (; c.length > 0 && c[c.length - 1].endPos <= g.start; )
s.produceFromScopes(c[c.length - 1].scopes, c[c.length - 1].endPos), c.pop();
if (c.length > 0 ? s.produceFromScopes(c[c.length - 1].scopes, g.start) : s.produce(r, g.start), d.retokenizeCapturedWithRuleId) {
const w = d.getName(i, a), S = r.contentNameScopesList.pushAttributed(w, n), _ = d.getContentName(i, a), y = S.pushAttributed(_, n), b = r.push(d.retokenizeCapturedWithRuleId, g.start, -1, !1, null, S, y), v = n.createOnigString(i.substring(0, g.end));
$t(
n,
v,
t && g.start === 0,
g.start,
b,
s,
!1,
/* no time limit */
0
), Ot(v);
continue;
}
const m = d.getName(i, a);
if (m !== null) {
const S = (c.length > 0 ? c[c.length - 1].scopes : r.contentNameScopesList).pushAttributed(m, n);
c.push(new Jn(S, g.end));
}
}
for (; c.length > 0; )
s.produceFromScopes(c[c.length - 1].scopes, c[c.length - 1].endPos), c.pop();
}
var Jn = class {
constructor(n, e) {
f(this, "scopes");
f(this, "endPos");
this.scopes = n, this.endPos = e;
}
};
function Qn(n, e, t, r, s, o, a, i) {
return new er(
n,
e,
t,
r,
s,
o,
a,
i
);
}
function ct(n, e, t, r, s) {
const o = me(e, be), a = Gt.getCompiledRuleId(t, r, s.repository);
for (const i of o)
n.push({
debugSelector: e,
matcher: i.matcher,
ruleId: a,
grammar: s,
priority: i.priority
});
}
function be(n, e) {
if (e.length < n.length)
return !1;
let t = 0;
return n.every((r) => {
for (let s = t; s < e.length; s++)
if (Zn(e[s], r))
return t = s + 1, !0;
return !1;
});
}
function Zn(n, e) {
if (!n)
return !1;
if (n === e)
return !0;
const t = e.length;
return n.length > t && n.substr(0, t) === e && n[t] === ".";
}
var er = class {
constructor(n, e, t, r, s, o, a, i) {
f(this, "_rootId");
f(this, "_lastRuleId");
f(this, "_ruleId2desc");
f(this, "_includedGrammars");
f(this, "_grammarRepository");
f(this, "_grammar");
f(this, "_injections");
f(this, "_basicScopeAttributesProvider");
f(this, "_tokenTypeMatchers");
if (this._rootScopeName = n, this.balancedBracketSelectors = o, this._onigLib = i, this._basicScopeAttributesProvider = new Hn(
t,
r
), this._rootId = -1, this._lastRuleId = 0, this._ruleId2desc = [null], this._includedGrammars = {}, this._grammarRepository = a, this._grammar = ut(e, null), this._injections = null, this._tokenTypeMatchers = [], s)
for (const l of Object.keys(s)) {
const c = me(l, be);
for (const h of c)
this._tokenTypeMatchers.push({
matcher: h.matcher,
type: s[l]
});
}
}
get themeProvider() {
return this._grammarRepository;
}
dispose() {
for (const n of this._ruleId2desc)
n && n.dispose();
}
createOnigScanner(n) {
return this._onigLib.createOnigScanner(n);
}
createOnigString(n) {
return this._onigLib.createOnigString(n);
}
getMetadataForScope(n) {
return this._basicScopeAttributesProvider.getBasicScopeAttributes(n);
}
_collectInjections() {
const n = {
lookup: (s) => s === this._rootScopeName ? this._grammar : this.getExternalGrammar(s),
injections: (s) => this._grammarRepository.injections(s)
}, e = [], t = this._rootScopeName, r = n.lookup(t);
if (r) {
const s = r.injections;
if (s)
for (let a in s)
ct(
e,
a,
s[a],
this,
r
);
const o = this._grammarRepository.injections(t);
o && o.forEach((a) => {
const i = this.getExternalGrammar(a);
if (i) {
const l = i.injectionSelector;
l && ct(
e,
l,
i,
this,
i
);
}
});
}
return e.sort((s, o) => s.priority - o.priority), e;
}
getInjections() {
return this._injections === null && (this._injections = this._collectInjections()), this._injections;
}
registerRule(n) {
const e = ++this._lastRuleId, t = n(e);
return this._ruleId2desc[e] = t, t;
}
getRule(n) {
return this._ruleId2desc[n];
}
getExternalGrammar(n, e) {
if (this._includedGrammars[n])
return this._includedGrammars[n];
if (this._grammarRepository) {
const t = this._grammarRepository.lookup(n);
if (t)
return this._includedGrammars[n] = ut(
t,
e && e.$base
), this._includedGrammars[n];
}
}
tokenizeLine(n, e, t = 0) {
const r = this._tokenize(n, e, !1, t);
return {
tokens: r.lineTokens.getResult(r.ruleStack, r.lineLength),
ruleStack: r.ruleStack,
stoppedEarly: r.stoppedEarly
};
}
tokenizeLine2(n, e, t = 0) {
const r = this._tokenize(n, e, !0, t);
return {
tokens: r.lineTokens.getBinaryResult(r.ruleStack, r.lineLength),
ruleStack: r.ruleStack,
stoppedEarly: r.stoppedEarly
};
}
_tokenize(n, e, t, r) {
this._rootId === -1 && (this._rootId = Gt.getCompiledRuleId(
this._grammar.repository.$self,
this,
this._grammar.repository
), this.getInjections());
let s;
if (!e || e === Fe.NULL) {
s = !0;
const c = this._basicScopeAttributesProvider.getDefaultAttributes(), h = this.themeProvider.getDefaults(), u = X.set(
0,
c.languageId,
c.tokenType,
null,
h.fontStyle,
h.foregroundId,
h.backgroundId
), d = this.getRule(this._rootId).getName(
null,
null
);
let g;
d ? g = te.createRootAndLookUpScopeName(
d,
u,
this
) : g = te.createRoot(
"unknown",
u
), e = new Fe(
null,
this._rootId,
-1,
-1,
!1,
null,
g,
g
);
} else
s = !1, e.reset();
n = n + `
`;
const o = this.createOnigString(n), a = o.content.length, i = new nr(
t,
n,
this._tokenTypeMatchers,
this.balancedBracketSelectors
), l = $t(
this,
o,
s,
0,
e,
i,
!0,
r
);
return Ot(o), {
lineLength: a,
lineTokens: i,
ruleStack: l.stack,
stoppedEarly: l.stoppedEarly
};
}
};
function ut(n, e) {
return n = bn(n), n.repository = n.repository || {}, n.repository.$self = {
$vscodeTextmateLocation: n.$vscodeTextmateLocation,
patterns: n.patterns,
name: n.scopeName
}, n.repository.$base = e || n.repository.$self, n;
}
var te = class D {
/**
* Invariant:
* ```
* if (parent && !scopePath.extends(parent.scopePath)) {
* throw new Error();
* }
* ```
*/
constructor(e, t, r) {
this.parent = e, this.scopePath = t, this.tokenAttributes = r;
}
static fromExtension(e, t) {
let r = e, s = (e == null ? void 0 : e.scopePath) ?? null;
for (const o of t)
s = Pe.push(s, o.scopeNames), r = new D(r, s, o.encodedTokenAttributes);
return r;
}
static createRoot(e, t) {
return new D(null, new Pe(null, e), t);
}
static createRootAndLookUpScopeName(e, t, r) {
const s = r.getMetadataForScope(e), o = new Pe(null, e), a = r.themeProvider.themeMatch(o), i = D.mergeAttributes(
t,
s,
a
);
return new D(null, o, i);
}
get scopeName() {
return this.scopePath.scopeName;
}
toString() {
return this.getScopeNames().join(" ");
}
equals(e) {
return D.equals(this, e);
}
static equals(e, t) {
do {
if (e === t || !e && !t)
return !0;
if (!e || !t || e.scopeName !== t.scopeName || e.tokenAttributes !== t.tokenAttributes)
return !1;
e = e.parent, t = t.parent;
} while (!0);
}
static mergeAttribute