UNPKG

@wolf-scope/wolf-ui

Version:

UI library for web applications using Lit

1,145 lines (1,144 loc) 34.9 kB
import { property as Oe, state as tt } from "lit/decorators.js"; import { unsafeCSS as nt, LitElement as st, html as it } from "lit"; import { unsafeHTML as rt } from "lit/directives/unsafe-html.js"; const ot = `pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#23241f;color:#f8f8f2}.hljs-subst,.hljs-tag{color:#f8f8f2}.hljs-emphasis,.hljs-strong{color:#a8a8a2}.hljs-bullet,.hljs-link,.hljs-literal,.hljs-number,.hljs-quote,.hljs-regexp{color:#ae81ff}.hljs-code,.hljs-section,.hljs-selector-class,.hljs-title{color:#a6e22e}.hljs-strong{font-weight:700}.hljs-emphasis{font-style:italic}.hljs-attr,.hljs-keyword,.hljs-name,.hljs-selector-tag{color:#f92672}.hljs-attribute,.hljs-symbol{color:#66d9ef}.hljs-class .hljs-title,.hljs-params,.hljs-title.class_{color:#f8f8f2}.hljs-addition,.hljs-built_in,.hljs-selector-attr,.hljs-selector-id,.hljs-selector-pseudo,.hljs-string,.hljs-template-variable,.hljs-type,.hljs-variable{color:#e6db74}.hljs-comment,.hljs-deletion,.hljs-meta{color:#75715e}:host{display:block;font-family:monospace;background-color:#2d2d2d;color:#fff;padding:8px 16px;border-radius:4px;overflow-x:auto}:host pre{display:flex;flex-wrap:wrap}:host code{display:contents} `; function ct(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; } function Re(e) { return e instanceof Map ? e.clear = e.delete = e.set = function() { throw new Error("map is read-only"); } : e instanceof Set && (e.add = e.clear = e.delete = function() { throw new Error("set is read-only"); }), Object.freeze(e), Object.getOwnPropertyNames(e).forEach((t) => { const s = e[t], a = typeof s; (a === "object" || a === "function") && !Object.isFrozen(s) && Re(s); }), e; } class de { /** * @param {CompiledMode} mode */ constructor(t) { t.data === void 0 && (t.data = {}), this.data = t.data, this.isMatchIgnored = !1; } ignoreMatch() { this.isMatchIgnored = !0; } } function Se(e) { return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;"); } function v(e, ...t) { const s = /* @__PURE__ */ Object.create(null); for (const a in e) s[a] = e[a]; return t.forEach(function(a) { for (const p in a) s[p] = a[p]; }), /** @type {T} */ s; } const lt = "</span>", be = (e) => !!e.scope, at = (e, { prefix: t }) => { if (e.startsWith("language:")) return e.replace("language:", "language-"); if (e.includes(".")) { const s = e.split("."); return [ `${t}${s.shift()}`, ...s.map((a, p) => `${a}${"_".repeat(p + 1)}`) ].join(" "); } return `${t}${e}`; }; class ut { /** * Creates a new HTMLRenderer * * @param {Tree} parseTree - the parse tree (must support `walk` API) * @param {{classPrefix: string}} options */ constructor(t, s) { this.buffer = "", this.classPrefix = s.classPrefix, t.walk(this); } /** * Adds texts to the output stream * * @param {string} text */ addText(t) { this.buffer += Se(t); } /** * Adds a node open to the output stream (if needed) * * @param {Node} node */ openNode(t) { if (!be(t)) return; const s = at( t.scope, { prefix: this.classPrefix } ); this.span(s); } /** * Adds a node close to the output stream (if needed) * * @param {Node} node */ closeNode(t) { be(t) && (this.buffer += lt); } /** * returns the accumulated buffer */ value() { return this.buffer; } // helpers /** * Builds a span element * * @param {string} className */ span(t) { this.buffer += `<span class="${t}">`; } } const Ee = (e = {}) => { const t = { children: [] }; return Object.assign(t, e), t; }; class ne { constructor() { this.rootNode = Ee(), this.stack = [this.rootNode]; } get top() { return this.stack[this.stack.length - 1]; } get root() { return this.rootNode; } /** @param {Node} node */ add(t) { this.top.children.push(t); } /** @param {string} scope */ openNode(t) { const s = Ee({ scope: t }); this.add(s), this.stack.push(s); } closeNode() { if (this.stack.length > 1) return this.stack.pop(); } closeAllNodes() { for (; this.closeNode(); ) ; } toJSON() { return JSON.stringify(this.rootNode, null, 4); } /** * @typedef { import("./html_renderer").Renderer } Renderer * @param {Renderer} builder */ walk(t) { return this.constructor._walk(t, this.rootNode); } /** * @param {Renderer} builder * @param {Node} node */ static _walk(t, s) { return typeof s == "string" ? t.addText(s) : s.children && (t.openNode(s), s.children.forEach((a) => this._walk(t, a)), t.closeNode(s)), t; } /** * @param {Node} node */ static _collapse(t) { typeof t != "string" && t.children && (t.children.every((s) => typeof s == "string") ? t.children = [t.children.join("")] : t.children.forEach((s) => { ne._collapse(s); })); } } class ft extends ne { /** * @param {*} options */ constructor(t) { super(), this.options = t; } /** * @param {string} text */ addText(t) { t !== "" && this.add(t); } /** @param {string} scope */ startScope(t) { this.openNode(t); } endScope() { this.closeNode(); } /** * @param {Emitter & {root: DataNode}} emitter * @param {string} name */ __addSublanguage(t, s) { const a = t.root; s && (a.scope = `language:${s}`), this.add(a); } toHTML() { return new ut(this, this.options).value(); } finalize() { return this.closeAllNodes(), !0; } } function H(e) { return e ? typeof e == "string" ? e : e.source : null; } function Ne(e) { return L("(?=", e, ")"); } function ht(e) { return L("(?:", e, ")*"); } function gt(e) { return L("(?:", e, ")?"); } function L(...e) { return e.map((s) => H(s)).join(""); } function pt(e) { const t = e[e.length - 1]; return typeof t == "object" && t.constructor === Object ? (e.splice(e.length - 1, 1), t) : {}; } function se(...e) { return "(" + (pt(e).capture ? "" : "?:") + e.map((a) => H(a)).join("|") + ")"; } function je(e) { return new RegExp(e.toString() + "|").exec("").length - 1; } function dt(e, t) { const s = e && e.exec(t); return s && s.index === 0; } const bt = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./; function ie(e, { joinWith: t }) { let s = 0; return e.map((a) => { s += 1; const p = s; let E = H(a), o = ""; for (; E.length > 0; ) { const r = bt.exec(E); if (!r) { o += E; break; } o += E.substring(0, r.index), E = E.substring(r.index + r[0].length), r[0][0] === "\\" && r[1] ? o += "\\" + String(Number(r[1]) + p) : (o += r[0], r[0] === "(" && s++); } return o; }).map((a) => `(${a})`).join(t); } const Et = /\b\B/, Ae = "[a-zA-Z]\\w*", re = "[a-zA-Z_]\\w*", ke = "\\b\\d+(\\.\\d+)?", Te = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)", ve = "\\b(0b[01]+)", _t = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~", wt = (e = {}) => { const t = /^#![ ]*\//; return e.binary && (e.begin = L( t, /.*\b/, e.binary, /\b.*/ )), v({ scope: "meta", begin: t, end: /$/, relevance: 0, /** @type {ModeCallback} */ "on:begin": (s, a) => { s.index !== 0 && a.ignoreMatch(); } }, e); }, U = { begin: "\\\\[\\s\\S]", relevance: 0 }, xt = { scope: "string", begin: "'", end: "'", illegal: "\\n", contains: [U] }, Mt = { scope: "string", begin: '"', end: '"', illegal: "\\n", contains: [U] }, yt = { begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/ }, X = function(e, t, s = {}) { const a = v( { scope: "comment", begin: e, end: t, contains: [] }, s ); a.contains.push({ scope: "doctag", // hack to avoid the space from being included. the space is necessary to // match here to prevent the plain text rule below from gobbling up doctags begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)", end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/, excludeBegin: !0, relevance: 0 }); const p = se( // list of common 1 and 2 letter words in English "I", "a", "is", "so", "us", "to", "at", "if", "in", "it", "on", // note: this is not an exhaustive list of contractions, just popular ones /[A-Za-z]+['](d|ve|re|ll|t|s|n)/, // contractions - can't we'd they're let's, etc /[A-Za-z]+[-][a-z]+/, // `no-way`, etc. /[A-Za-z][a-z]{2,}/ // allow capitalized words at beginning of sentences ); return a.contains.push( { // TODO: how to include ", (, ) without breaking grammars that use these for // comment delimiters? // begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/ // --- // this tries to find sequences of 3 english words in a row (without any // "programming" type syntax) this gives us a strong signal that we've // TRULY found a comment - vs perhaps scanning with the wrong language. // It's possible to find something that LOOKS like the start of the // comment - but then if there is no readable text - good chance it is a // false match and not a comment. // // for a visual example please see: // https://github.com/highlightjs/highlight.js/issues/2827 begin: L( /[ ]+/, // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */ "(", p, /[.]?[:]?([.][ ]|[ ])/, "){3}" ) // look for 3 words in a row } ), a; }, Ot = X("//", "$"), Rt = X("/\\*", "\\*/"), St = X("#", "$"), Nt = { scope: "number", begin: ke, relevance: 0 }, jt = { scope: "number", begin: Te, relevance: 0 }, At = { scope: "number", begin: ve, relevance: 0 }, kt = { // this outer rule makes sure we actually have a WHOLE regex and not simply // an expression such as: // // 3 / something // // (which will then blow up when regex's `illegal` sees the newline) begin: /(?=\/[^/\n]*\/)/, contains: [{ scope: "regexp", begin: /\//, end: /\/[gimuy]*/, illegal: /\n/, contains: [ U, { begin: /\[/, end: /\]/, relevance: 0, contains: [U] } ] }] }, Tt = { scope: "title", begin: Ae, relevance: 0 }, vt = { scope: "title", begin: re, relevance: 0 }, Ct = { // excludes method names from keyword processing begin: "\\.\\s*" + re, relevance: 0 }, It = function(e) { return Object.assign( e, { /** @type {ModeCallback} */ "on:begin": (t, s) => { s.data._beginMatch = t[1]; }, /** @type {ModeCallback} */ "on:end": (t, s) => { s.data._beginMatch !== t[1] && s.ignoreMatch(); } } ); }; var F = /* @__PURE__ */ Object.freeze({ __proto__: null, MATCH_NOTHING_RE: Et, IDENT_RE: Ae, UNDERSCORE_IDENT_RE: re, NUMBER_RE: ke, C_NUMBER_RE: Te, BINARY_NUMBER_RE: ve, RE_STARTERS_RE: _t, SHEBANG: wt, BACKSLASH_ESCAPE: U, APOS_STRING_MODE: xt, QUOTE_STRING_MODE: Mt, PHRASAL_WORDS_MODE: yt, COMMENT: X, C_LINE_COMMENT_MODE: Ot, C_BLOCK_COMMENT_MODE: Rt, HASH_COMMENT_MODE: St, NUMBER_MODE: Nt, C_NUMBER_MODE: jt, BINARY_NUMBER_MODE: At, REGEXP_MODE: kt, TITLE_MODE: Tt, UNDERSCORE_TITLE_MODE: vt, METHOD_GUARD: Ct, END_SAME_AS_BEGIN: It }); function Lt(e, t) { e.input[e.index - 1] === "." && t.ignoreMatch(); } function Dt(e, t) { e.className !== void 0 && (e.scope = e.className, delete e.className); } function Bt(e, t) { t && e.beginKeywords && (e.begin = "\\b(" + e.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)", e.__beforeBegin = Lt, e.keywords = e.keywords || e.beginKeywords, delete e.beginKeywords, e.relevance === void 0 && (e.relevance = 0)); } function Pt(e, t) { Array.isArray(e.illegal) && (e.illegal = se(...e.illegal)); } function Ht(e, t) { if (e.match) { if (e.begin || e.end) throw new Error("begin & end are not supported with match"); e.begin = e.match, delete e.match; } } function Ut(e, t) { e.relevance === void 0 && (e.relevance = 1); } const mt = (e, t) => { if (!e.beforeMatch) return; if (e.starts) throw new Error("beforeMatch cannot be used with starts"); const s = Object.assign({}, e); Object.keys(e).forEach((a) => { delete e[a]; }), e.keywords = s.keywords, e.begin = L(s.beforeMatch, Ne(s.begin)), e.starts = { relevance: 0, contains: [ Object.assign(s, { endsParent: !0 }) ] }, e.relevance = 0, delete s.beforeMatch; }, $t = [ "of", "and", "for", "in", "not", "or", "if", "then", "parent", // common variable name "list", // common variable name "value" // common variable name ], Gt = "keyword"; function Ce(e, t, s = Gt) { const a = /* @__PURE__ */ Object.create(null); return typeof e == "string" ? p(s, e.split(" ")) : Array.isArray(e) ? p(s, e) : Object.keys(e).forEach(function(E) { Object.assign( a, Ce(e[E], t, E) ); }), a; function p(E, o) { t && (o = o.map((r) => r.toLowerCase())), o.forEach(function(r) { const u = r.split("|"); a[u[0]] = [E, Wt(u[0], u[1])]; }); } } function Wt(e, t) { return t ? Number(t) : Kt(e) ? 0 : 1; } function Kt(e) { return $t.includes(e.toLowerCase()); } const _e = {}, I = (e) => { console.error(e); }, we = (e, ...t) => { console.log(`WARN: ${e}`, ...t); }, D = (e, t) => { _e[`${e}/${t}`] || (console.log(`Deprecated as of ${e}. ${t}`), _e[`${e}/${t}`] = !0); }, z = new Error(); function Ie(e, t, { key: s }) { let a = 0; const p = e[s], E = {}, o = {}; for (let r = 1; r <= t.length; r++) o[r + a] = p[r], E[r + a] = !0, a += je(t[r - 1]); e[s] = o, e[s]._emit = E, e[s]._multi = !0; } function Ft(e) { if (Array.isArray(e.begin)) { if (e.skip || e.excludeBegin || e.returnBegin) throw I("skip, excludeBegin, returnBegin not compatible with beginScope: {}"), z; if (typeof e.beginScope != "object" || e.beginScope === null) throw I("beginScope must be object"), z; Ie(e, e.begin, { key: "beginScope" }), e.begin = ie(e.begin, { joinWith: "" }); } } function zt(e) { if (Array.isArray(e.end)) { if (e.skip || e.excludeEnd || e.returnEnd) throw I("skip, excludeEnd, returnEnd not compatible with endScope: {}"), z; if (typeof e.endScope != "object" || e.endScope === null) throw I("endScope must be object"), z; Ie(e, e.end, { key: "endScope" }), e.end = ie(e.end, { joinWith: "" }); } } function Xt(e) { e.scope && typeof e.scope == "object" && e.scope !== null && (e.beginScope = e.scope, delete e.scope); } function Yt(e) { Xt(e), typeof e.beginScope == "string" && (e.beginScope = { _wrap: e.beginScope }), typeof e.endScope == "string" && (e.endScope = { _wrap: e.endScope }), Ft(e), zt(e); } function Zt(e) { function t(o, r) { return new RegExp( H(o), "m" + (e.case_insensitive ? "i" : "") + (e.unicodeRegex ? "u" : "") + (r ? "g" : "") ); } class s { constructor() { this.matchIndexes = {}, this.regexes = [], this.matchAt = 1, this.position = 0; } // @ts-ignore addRule(r, u) { u.position = this.position++, this.matchIndexes[this.matchAt] = u, this.regexes.push([u, r]), this.matchAt += je(r) + 1; } compile() { this.regexes.length === 0 && (this.exec = () => null); const r = this.regexes.map((u) => u[1]); this.matcherRe = t(ie(r, { joinWith: "|" }), !0), this.lastIndex = 0; } /** @param {string} s */ exec(r) { this.matcherRe.lastIndex = this.lastIndex; const u = this.matcherRe.exec(r); if (!u) return null; const M = u.findIndex((P, Z) => Z > 0 && P !== void 0), w = this.matchIndexes[M]; return u.splice(0, M), Object.assign(u, w); } } class a { constructor() { this.rules = [], this.multiRegexes = [], this.count = 0, this.lastIndex = 0, this.regexIndex = 0; } // @ts-ignore getMatcher(r) { if (this.multiRegexes[r]) return this.multiRegexes[r]; const u = new s(); return this.rules.slice(r).forEach(([M, w]) => u.addRule(M, w)), u.compile(), this.multiRegexes[r] = u, u; } resumingScanAtSamePosition() { return this.regexIndex !== 0; } considerAll() { this.regexIndex = 0; } // @ts-ignore addRule(r, u) { this.rules.push([r, u]), u.type === "begin" && this.count++; } /** @param {string} s */ exec(r) { const u = this.getMatcher(this.regexIndex); u.lastIndex = this.lastIndex; let M = u.exec(r); if (this.resumingScanAtSamePosition() && !(M && M.index === this.lastIndex)) { const w = this.getMatcher(0); w.lastIndex = this.lastIndex + 1, M = w.exec(r); } return M && (this.regexIndex += M.position + 1, this.regexIndex === this.count && this.considerAll()), M; } } function p(o) { const r = new a(); return o.contains.forEach((u) => r.addRule(u.begin, { rule: u, type: "begin" })), o.terminatorEnd && r.addRule(o.terminatorEnd, { type: "end" }), o.illegal && r.addRule(o.illegal, { type: "illegal" }), r; } function E(o, r) { const u = ( /** @type CompiledMode */ o ); if (o.isCompiled) return u; [ Dt, // do this early so compiler extensions generally don't have to worry about // the distinction between match/begin Ht, Yt, mt ].forEach((w) => w(o, r)), e.compilerExtensions.forEach((w) => w(o, r)), o.__beforeBegin = null, [ Bt, // do this later so compiler extensions that come earlier have access to the // raw array if they wanted to perhaps manipulate it, etc. Pt, // default to 1 relevance if not specified Ut ].forEach((w) => w(o, r)), o.isCompiled = !0; let M = null; return typeof o.keywords == "object" && o.keywords.$pattern && (o.keywords = Object.assign({}, o.keywords), M = o.keywords.$pattern, delete o.keywords.$pattern), M = M || /\w+/, o.keywords && (o.keywords = Ce(o.keywords, e.case_insensitive)), u.keywordPatternRe = t(M, !0), r && (o.begin || (o.begin = /\B|\b/), u.beginRe = t(u.begin), !o.end && !o.endsWithParent && (o.end = /\B|\b/), o.end && (u.endRe = t(u.end)), u.terminatorEnd = H(u.end) || "", o.endsWithParent && r.terminatorEnd && (u.terminatorEnd += (o.end ? "|" : "") + r.terminatorEnd)), o.illegal && (u.illegalRe = t( /** @type {RegExp | string} */ o.illegal )), o.contains || (o.contains = []), o.contains = [].concat(...o.contains.map(function(w) { return Jt(w === "self" ? o : w); })), o.contains.forEach(function(w) { E( /** @type Mode */ w, u ); }), o.starts && E(o.starts, r), u.matcher = p(u), u; } if (e.compilerExtensions || (e.compilerExtensions = []), e.contains && e.contains.includes("self")) throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation."); return e.classNameAliases = v(e.classNameAliases || {}), E( /** @type Mode */ e ); } function Le(e) { return e ? e.endsWithParent || Le(e.starts) : !1; } function Jt(e) { return e.variants && !e.cachedVariants && (e.cachedVariants = e.variants.map(function(t) { return v(e, { variants: null }, t); })), e.cachedVariants ? e.cachedVariants : Le(e) ? v(e, { starts: e.starts ? v(e.starts) : null }) : Object.isFrozen(e) ? v(e) : e; } var qt = "11.8.0"; class Vt extends Error { constructor(t, s) { super(t), this.name = "HTMLInjectionError", this.html = s; } } const te = Se, xe = v, Me = Symbol("nomatch"), Qt = 7, De = function(e) { const t = /* @__PURE__ */ Object.create(null), s = /* @__PURE__ */ Object.create(null), a = []; let p = !0; const E = "Could not find the language '{}', did you forget to load/include a language module?", o = { disableAutodetect: !0, name: "Plain text", contains: [] }; let r = { ignoreUnescapedHTML: !1, throwUnescapedHTML: !1, noHighlightRe: /^(no-?highlight)$/i, languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i, classPrefix: "hljs-", cssSelector: "pre code", languages: null, // beta configuration options, subject to change, welcome to discuss // https://github.com/highlightjs/highlight.js/issues/1086 __emitter: ft }; function u(n) { return r.noHighlightRe.test(n); } function M(n) { let l = n.className + " "; l += n.parentNode ? n.parentNode.className : ""; const g = r.languageDetectRe.exec(l); if (g) { const b = k(g[1]); return b || (we(E.replace("{}", g[1])), we("Falling back to no-highlight mode for this block.", n)), b ? g[1] : "no-highlight"; } return l.split(/\s+/).find((b) => u(b) || k(b)); } function w(n, l, g) { let b = "", x = ""; typeof l == "object" ? (b = n, g = l.ignoreIllegals, x = l.language) : (D("10.7.0", "highlight(lang, code, ...args) has been deprecated."), D("10.7.0", `Please use highlight(code, options) instead. https://github.com/highlightjs/highlight.js/issues/2277`), x = n, b = l), g === void 0 && (g = !0); const S = { code: b, language: x }; $("before:highlight", S); const T = S.result ? S.result : P(S.language, S.code, g); return T.code = S.code, $("after:highlight", T), T; } function P(n, l, g, b) { const x = /* @__PURE__ */ Object.create(null); function S(i, c) { return i.keywords[c]; } function T() { if (!f.keywords) { y.addText(_); return; } let i = 0; f.keywordPatternRe.lastIndex = 0; let c = f.keywordPatternRe.exec(_), h = ""; for (; c; ) { h += _.substring(i, c.index); const d = j.case_insensitive ? c[0].toLowerCase() : c[0], O = S(f, d); if (O) { const [A, Qe] = O; if (y.addText(h), h = "", x[d] = (x[d] || 0) + 1, x[d] <= Qt && (K += Qe), A.startsWith("_")) h += c[0]; else { const et = j.classNameAliases[A] || A; N(c[0], et); } } else h += c[0]; i = f.keywordPatternRe.lastIndex, c = f.keywordPatternRe.exec(_); } h += _.substring(i), y.addText(h); } function G() { if (_ === "") return; let i = null; if (typeof f.subLanguage == "string") { if (!t[f.subLanguage]) { y.addText(_); return; } i = P(f.subLanguage, _, !0, pe[f.subLanguage]), pe[f.subLanguage] = /** @type {CompiledMode} */ i._top; } else i = J(_, f.subLanguage.length ? f.subLanguage : null); f.relevance > 0 && (K += i.relevance), y.__addSublanguage(i._emitter, i.language); } function R() { f.subLanguage != null ? G() : T(), _ = ""; } function N(i, c) { i !== "" && (y.startScope(c), y.addText(i), y.endScope()); } function ue(i, c) { let h = 1; const d = c.length - 1; for (; h <= d; ) { if (!i._emit[h]) { h++; continue; } const O = j.classNameAliases[i[h]] || i[h], A = c[h]; O ? N(A, O) : (_ = A, T(), _ = ""), h++; } } function fe(i, c) { return i.scope && typeof i.scope == "string" && y.openNode(j.classNameAliases[i.scope] || i.scope), i.beginScope && (i.beginScope._wrap ? (N(_, j.classNameAliases[i.beginScope._wrap] || i.beginScope._wrap), _ = "") : i.beginScope._multi && (ue(i.beginScope, c), _ = "")), f = Object.create(i, { parent: { value: f } }), f; } function he(i, c, h) { let d = dt(i.endRe, h); if (d) { if (i["on:end"]) { const O = new de(i); i["on:end"](c, O), O.isMatchIgnored && (d = !1); } if (d) { for (; i.endsParent && i.parent; ) i = i.parent; return i; } } if (i.endsWithParent) return he(i.parent, c, h); } function Ye(i) { return f.matcher.regexIndex === 0 ? (_ += i[0], 1) : (ee = !0, 0); } function Ze(i) { const c = i[0], h = i.rule, d = new de(h), O = [h.__beforeBegin, h["on:begin"]]; for (const A of O) if (A && (A(i, d), d.isMatchIgnored)) return Ye(c); return h.skip ? _ += c : (h.excludeBegin && (_ += c), R(), !h.returnBegin && !h.excludeBegin && (_ = c)), fe(h, i), h.returnBegin ? 0 : c.length; } function Je(i) { const c = i[0], h = l.substring(i.index), d = he(f, i, h); if (!d) return Me; const O = f; f.endScope && f.endScope._wrap ? (R(), N(c, f.endScope._wrap)) : f.endScope && f.endScope._multi ? (R(), ue(f.endScope, i)) : O.skip ? _ += c : (O.returnEnd || O.excludeEnd || (_ += c), R(), O.excludeEnd && (_ = c)); do f.scope && y.closeNode(), !f.skip && !f.subLanguage && (K += f.relevance), f = f.parent; while (f !== d.parent); return d.starts && fe(d.starts, i), O.returnEnd ? 0 : c.length; } function qe() { const i = []; for (let c = f; c !== j; c = c.parent) c.scope && i.unshift(c.scope); i.forEach((c) => y.openNode(c)); } let W = {}; function ge(i, c) { const h = c && c[0]; if (_ += i, h == null) return R(), 0; if (W.type === "begin" && c.type === "end" && W.index === c.index && h === "") { if (_ += l.slice(c.index, c.index + 1), !p) { const d = new Error(`0 width match regex (${n})`); throw d.languageName = n, d.badRule = W.rule, d; } return 1; } if (W = c, c.type === "begin") return Ze(c); if (c.type === "illegal" && !g) { const d = new Error('Illegal lexeme "' + h + '" for mode "' + (f.scope || "<unnamed>") + '"'); throw d.mode = f, d; } else if (c.type === "end") { const d = Je(c); if (d !== Me) return d; } if (c.type === "illegal" && h === "") return 1; if (Q > 1e5 && Q > c.index * 3) throw new Error("potential infinite loop, way more iterations than matches"); return _ += h, h.length; } const j = k(n); if (!j) throw I(E.replace("{}", n)), new Error('Unknown language: "' + n + '"'); const Ve = Zt(j); let V = "", f = b || Ve; const pe = {}, y = new r.__emitter(r); qe(); let _ = "", K = 0, C = 0, Q = 0, ee = !1; try { if (j.__emitTokens) j.__emitTokens(l, y); else { for (f.matcher.considerAll(); ; ) { Q++, ee ? ee = !1 : f.matcher.considerAll(), f.matcher.lastIndex = C; const i = f.matcher.exec(l); if (!i) break; const c = l.substring(C, i.index), h = ge(c, i); C = i.index + h; } ge(l.substring(C)); } return y.finalize(), V = y.toHTML(), { language: n, value: V, relevance: K, illegal: !1, _emitter: y, _top: f }; } catch (i) { if (i.message && i.message.includes("Illegal")) return { language: n, value: te(l), illegal: !0, relevance: 0, _illegalBy: { message: i.message, index: C, context: l.slice(C - 100, C + 100), mode: i.mode, resultSoFar: V }, _emitter: y }; if (p) return { language: n, value: te(l), illegal: !1, relevance: 0, errorRaised: i, _emitter: y, _top: f }; throw i; } } function Z(n) { const l = { value: te(n), illegal: !1, relevance: 0, _top: o, _emitter: new r.__emitter(r) }; return l._emitter.addText(n), l; } function J(n, l) { l = l || r.languages || Object.keys(t); const g = Z(n), b = l.filter(k).filter(ae).map( (R) => P(R, n, !1) ); b.unshift(g); const x = b.sort((R, N) => { if (R.relevance !== N.relevance) return N.relevance - R.relevance; if (R.language && N.language) { if (k(R.language).supersetOf === N.language) return 1; if (k(N.language).supersetOf === R.language) return -1; } return 0; }), [S, T] = x, G = S; return G.secondBest = T, G; } function Be(n, l, g) { const b = l && s[l] || g; n.classList.add("hljs"), n.classList.add(`language-${b}`); } function q(n) { let l = null; const g = M(n); if (u(g)) return; if ($( "before:highlightElement", { el: n, language: g } ), n.children.length > 0 && (r.ignoreUnescapedHTML || (console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."), console.warn("https://github.com/highlightjs/highlight.js/wiki/security"), console.warn("The element with unescaped HTML:"), console.warn(n)), r.throwUnescapedHTML)) throw new Vt( "One of your code blocks includes unescaped HTML.", n.innerHTML ); l = n; const b = l.textContent, x = g ? w(b, { language: g, ignoreIllegals: !0 }) : J(b); n.innerHTML = x.value, Be(n, g, x.language), n.result = { language: x.language, // TODO: remove with version 11.0 re: x.relevance, relevance: x.relevance }, x.secondBest && (n.secondBest = { language: x.secondBest.language, relevance: x.secondBest.relevance }), $("after:highlightElement", { el: n, result: x, text: b }); } function Pe(n) { r = xe(r, n); } const He = () => { m(), D("10.6.0", "initHighlighting() deprecated. Use highlightAll() now."); }; function Ue() { m(), D("10.6.0", "initHighlightingOnLoad() deprecated. Use highlightAll() now."); } let ce = !1; function m() { if (document.readyState === "loading") { ce = !0; return; } document.querySelectorAll(r.cssSelector).forEach(q); } function me() { ce && m(); } typeof window < "u" && window.addEventListener && window.addEventListener("DOMContentLoaded", me, !1); function $e(n, l) { let g = null; try { g = l(e); } catch (b) { if (I("Language definition for '{}' could not be registered.".replace("{}", n)), p) I(b); else throw b; g = o; } g.name || (g.name = n), t[n] = g, g.rawDefinition = l.bind(null, e), g.aliases && le(g.aliases, { languageName: n }); } function Ge(n) { delete t[n]; for (const l of Object.keys(s)) s[l] === n && delete s[l]; } function We() { return Object.keys(t); } function k(n) { return n = (n || "").toLowerCase(), t[n] || t[s[n]]; } function le(n, { languageName: l }) { typeof n == "string" && (n = [n]), n.forEach((g) => { s[g.toLowerCase()] = l; }); } function ae(n) { const l = k(n); return l && !l.disableAutodetect; } function Ke(n) { n["before:highlightBlock"] && !n["before:highlightElement"] && (n["before:highlightElement"] = (l) => { n["before:highlightBlock"]( Object.assign({ block: l.el }, l) ); }), n["after:highlightBlock"] && !n["after:highlightElement"] && (n["after:highlightElement"] = (l) => { n["after:highlightBlock"]( Object.assign({ block: l.el }, l) ); }); } function Fe(n) { Ke(n), a.push(n); } function ze(n) { const l = a.indexOf(n); l !== -1 && a.splice(l, 1); } function $(n, l) { const g = n; a.forEach(function(b) { b[g] && b[g](l); }); } function Xe(n) { return D("10.7.0", "highlightBlock will be removed entirely in v12.0"), D("10.7.0", "Please use highlightElement now."), q(n); } Object.assign(e, { highlight: w, highlightAuto: J, highlightAll: m, highlightElement: q, // TODO: Remove with v12 API highlightBlock: Xe, configure: Pe, initHighlighting: He, initHighlightingOnLoad: Ue, registerLanguage: $e, unregisterLanguage: Ge, listLanguages: We, getLanguage: k, registerAliases: le, autoDetection: ae, inherit: xe, addPlugin: Fe, removePlugin: ze }), e.debugMode = function() { p = !1; }, e.safeMode = function() { p = !0; }, e.versionString = qt, e.regex = { concat: L, lookahead: Ne, either: se, optional: gt, anyNumberOfTimes: ht }; for (const n in F) typeof F[n] == "object" && Re(F[n]); return Object.assign(e, F), e; }, B = De({}); B.newInstance = () => De({}); var en = B; B.HighlightJS = B; B.default = B; const ye = /* @__PURE__ */ ct(en); var tn = Object.defineProperty, nn = Object.getOwnPropertyDescriptor, oe = (e, t, s, a) => { for (var p = a > 1 ? void 0 : a ? nn(t, s) : t, E = e.length - 1, o; E >= 0; E--) (o = e[E]) && (p = (a ? o(t, s, p) : o(p)) || p); return a && p && tn(t, s, p), p; }; const cn = "wolf-code"; class Y extends st { constructor() { super(...arguments), this.language = "typescript", this.theme = "light"; } connectedCallback() { super.connectedCallback(), this.renderCode(); } onSlotChange() { this.renderCode(); } getLanguage() { switch (this.language) { case "js": return import("../../javascript-b2e359e9.js"); case "html": case "xml": return import("../../xml-05a7ea97.js"); case "css": case "scss": return import("../../scss-b784f6bc.js"); case "json": return import("../../json-7fe99535.js"); case "typescript": return import("../../typescript-02e58456.js"); default: return import("../../typescript-02e58456.js"); } } renderCode() { this.getLanguage().then(({ default: t }) => { ye.registerLanguage(this.language, t); const a = this.shadowRoot?.querySelector("slot")?.assignedNodes() ?? []; this.code = a.map((p) => p.textContent).join(` `) ?? "", this.code = rt(`${ye.highlight(this.code, { language: this.language, ignoreIllegals: !0 }).value}`); }); } render() { return it`<pre><code>${this.code}</code><slot hidden @slotchange=${this.onSlotChange}></slot></pre> `; } } Y.styles = nt(ot); oe([ Oe() ], Y.prototype, "language", 2); oe([ Oe() ], Y.prototype, "theme", 2); oe([ tt() ], Y.prototype, "code", 2); export { Y as WolfCode, cn as tagName };