UNPKG

@kitn.ai/chat

Version:

Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.

3 lines 117 kB
var xn=Object.defineProperty,Ln=(e,t,n)=>t in e?xn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t,n)=>Ln(e,typeof t!="symbol"?t+"":t,n),C=class extends Error{constructor(e){super(e),this.name="ShikiError"}};function Rn(e){return Oe(e)}function Oe(e){return Array.isArray(e)?En(e):e instanceof RegExp?e:typeof e=="object"?In(e):e}function En(e){let t=[];for(let n=0,r=e.length;n<r;n++)t[n]=Oe(e[n]);return t}function In(e){let t={};for(let n in e)t[n]=Oe(e[n]);return t}function ht(e,...t){return t.forEach(n=>{for(let r in n)e[r]=n[r]}),e}function dt(e){const t=~e.lastIndexOf("/")||~e.lastIndexOf("\\");return t===0?e:~t===e.length-1?dt(e.substring(0,e.length-1)):e.substr(~t+1)}var Me=/\$(\d+)|\${(\d+):\/(downcase|upcase)}/g,fe=class{static hasCaptures(e){return e===null?!1:(Me.lastIndex=0,Me.test(e))}static replaceCaptures(e,t,n){return e.replace(Me,(r,o,s,a)=>{let l=n[parseInt(o||s,10)];if(l){let i=t.substring(l.start,l.end);for(;i[0]===".";)i=i.substring(1);switch(a){case"downcase":return i.toLowerCase();case"upcase":return i.toUpperCase();default:return i}}else return r})}};function pt(e,t){return e<t?-1:e>t?1:0}function gt(e,t){if(e===null&&t===null)return 0;if(!e)return-1;if(!t)return 1;let n=e.length,r=t.length;if(n===r){for(let o=0;o<n;o++){let s=pt(e[o],t[o]);if(s!==0)return s}return 0}return n-r}function mt(e){return!!(/^#[0-9a-f]{6}$/i.test(e)||/^#[0-9a-f]{8}$/i.test(e)||/^#[0-9a-f]{3}$/i.test(e)||/^#[0-9a-f]{4}$/i.test(e))}function ft(e){return e.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g,"\\$&")}var yt=class{constructor(e){p(this,"cache",new Map),this.fn=e}get(e){if(this.cache.has(e))return this.cache.get(e);const t=this.fn(e);return this.cache.set(e,t),t}},ye=class{constructor(e,t,n){p(this,"_cachedMatchRoot",new yt(r=>this._root.match(r))),this._colorMap=e,this._defaults=t,this._root=n}static createFromRawTheme(e,t){return this.createFromParsedTheme(Bn(e),t)}static createFromParsedTheme(e,t){return $n(e,t)}getColorMap(){return this._colorMap.getColorMap()}getDefaults(){return this._defaults}match(e){if(e===null)return this._defaults;const t=e.scopeName,n=this._cachedMatchRoot.get(t).find(r=>On(e.parent,r.parentScopes));return n?new bt(n.fontStyle,n.foreground,n.background):null}},Be=class Ee{constructor(t,n){this.parent=t,this.scopeName=n}static push(t,n){for(const r of n)t=new Ee(t,r);return t}static from(...t){let n=null;for(let r=0;r<t.length;r++)n=new Ee(n,t[r]);return n}push(t){return new Ee(this,t)}getSegments(){let t=this;const n=[];for(;t;)n.push(t.scopeName),t=t.parent;return n.reverse(),n}toString(){return this.getSegments().join(" ")}extends(t){return this===t?!0:this.parent===null?!1:this.parent.extends(t)}getExtensionIfDefined(t){const n=[];let r=this;for(;r&&r!==t;)n.push(r.scopeName),r=r.parent;return r===t?n.reverse():void 0}};function On(e,t){if(t.length===0)return!0;for(let n=0;n<t.length;n++){let r=t[n],o=!1;if(r===">"){if(n===t.length-1)return!1;r=t[++n],o=!0}for(;e&&!Mn(e.scopeName,r);){if(o)return!1;e=e.parent}if(!e)return!1;e=e.parent}return!0}function Mn(e,t){return t===e||e.startsWith(t)&&e[t.length]==="."}var bt=class{constructor(e,t,n){this.fontStyle=e,this.foregroundId=t,this.backgroundId=n}};function Bn(e){if(!e)return[];if(!e.settings||!Array.isArray(e.settings))return[];let t=e.settings,n=[],r=0;for(let o=0,s=t.length;o<s;o++){let a=t[o];if(!a.settings)continue;let l;if(typeof a.scope=="string"){let u=a.scope;u=u.replace(/^[,]+/,""),u=u.replace(/[,]+$/,""),l=u.split(",")}else Array.isArray(a.scope)?l=a.scope:l=[""];let i=-1;if(typeof a.settings.fontStyle=="string"){i=0;let u=a.settings.fontStyle.split(" ");for(let d=0,g=u.length;d<g;d++)switch(u[d]){case"italic":i=i|1;break;case"bold":i=i|2;break;case"underline":i=i|4;break;case"strikethrough":i=i|8;break}}let c=null;typeof a.settings.foreground=="string"&&mt(a.settings.foreground)&&(c=a.settings.foreground);let h=null;typeof a.settings.background=="string"&&mt(a.settings.background)&&(h=a.settings.background);for(let u=0,d=l.length;u<d;u++){let g=l[u].trim().split(" "),f=g[g.length-1],_=null;g.length>1&&(_=g.slice(0,g.length-1),_.reverse()),n[r++]=new Gn(f,_,o,i,c,h)}}return n}var Gn=class{constructor(e,t,n,r,o,s){this.scope=e,this.parentScopes=t,this.index=n,this.fontStyle=r,this.foreground=o,this.background=s}},R=(e=>(e[e.NotSet=-1]="NotSet",e[e.None=0]="None",e[e.Italic=1]="Italic",e[e.Bold=2]="Bold",e[e.Underline=4]="Underline",e[e.Strikethrough=8]="Strikethrough",e))(R||{});function $n(e,t){e.sort((i,c)=>{let h=pt(i.scope,c.scope);return h!==0||(h=gt(i.parentScopes,c.parentScopes),h!==0)?h:i.index-c.index});let n=0,r="#000000",o="#ffffff";for(;e.length>=1&&e[0].scope==="";){let i=e.shift();i.fontStyle!==-1&&(n=i.fontStyle),i.foreground!==null&&(r=i.foreground),i.background!==null&&(o=i.background)}let s=new Dn(t),a=new bt(n,s.getId(r),s.getId(o)),l=new Fn(new Ge(0,null,-1,0,0),[]);for(let i=0,c=e.length;i<c;i++){let h=e[i];l.insert(0,h.scope,h.parentScopes,h.fontStyle,s.getId(h.foreground),s.getId(h.background))}return new ye(s,a,l)}var Dn=class{constructor(e){if(p(this,"_isFrozen"),p(this,"_lastColorId"),p(this,"_id2color"),p(this,"_color2id"),this._lastColorId=0,this._id2color=[],this._color2id=Object.create(null),Array.isArray(e)){this._isFrozen=!0;for(let t=0,n=e.length;t<n;t++)this._color2id[e[t]]=t,this._id2color[t]=e[t]}else this._isFrozen=!1}getId(e){if(e===null)return 0;e=e.toUpperCase();let t=this._color2id[e];if(t)return t;if(this._isFrozen)throw new Error(`Missing color in color map - ${e}`);return t=++this._lastColorId,this._color2id[e]=t,this._id2color[t]=e,t}getColorMap(){return this._id2color.slice(0)}},jn=Object.freeze([]),Ge=class Nn{constructor(t,n,r,o,s){p(this,"scopeDepth"),p(this,"parentScopes"),p(this,"fontStyle"),p(this,"foreground"),p(this,"background"),this.scopeDepth=t,this.parentScopes=n||jn,this.fontStyle=r,this.foreground=o,this.background=s}clone(){return new Nn(this.scopeDepth,this.parentScopes,this.fontStyle,this.foreground,this.background)}static cloneArr(t){let n=[];for(let r=0,o=t.length;r<o;r++)n[r]=t[r].clone();return n}acceptOverwrite(t,n,r,o){this.scopeDepth>t?console.log("how did this happen?"):this.scopeDepth=t,n!==-1&&(this.fontStyle=n),r!==0&&(this.foreground=r),o!==0&&(this.background=o)}},Fn=class ct{constructor(t,n=[],r={}){p(this,"_rulesWithParentScopes"),this._mainRule=t,this._children=r,this._rulesWithParentScopes=n}static _cmpBySpecificity(t,n){if(t.scopeDepth!==n.scopeDepth)return n.scopeDepth-t.scopeDepth;let r=0,o=0;for(;t.parentScopes[r]===">"&&r++,n.parentScopes[o]===">"&&o++,!(r>=t.parentScopes.length||o>=n.parentScopes.length);){const s=n.parentScopes[o].length-t.parentScopes[r].length;if(s!==0)return s;r++,o++}return n.parentScopes.length-t.parentScopes.length}match(t){if(t!==""){let r=t.indexOf("."),o,s;if(r===-1?(o=t,s=""):(o=t.substring(0,r),s=t.substring(r+1)),this._children.hasOwnProperty(o))return this._children[o].match(s)}const n=this._rulesWithParentScopes.concat(this._mainRule);return n.sort(ct._cmpBySpecificity),n}insert(t,n,r,o,s,a){if(n===""){this._doInsertHere(t,r,o,s,a);return}let l=n.indexOf("."),i,c;l===-1?(i=n,c=""):(i=n.substring(0,l),c=n.substring(l+1));let h;this._children.hasOwnProperty(i)?h=this._children[i]:(h=new ct(this._mainRule.clone(),Ge.cloneArr(this._rulesWithParentScopes)),this._children[i]=h),h.insert(t+1,c,r,o,s,a)}_doInsertHere(t,n,r,o,s){if(n===null){this._mainRule.acceptOverwrite(t,r,o,s);return}for(let a=0,l=this._rulesWithParentScopes.length;a<l;a++){let i=this._rulesWithParentScopes[a];if(gt(i.parentScopes,n)===0){i.acceptOverwrite(t,r,o,s);return}}r===-1&&(r=this._mainRule.fontStyle),o===0&&(o=this._mainRule.foreground),s===0&&(s=this._mainRule.background),this._rulesWithParentScopes.push(new Ge(t,n,r,o,s))}},Y=class M{static toBinaryStr(t){return t.toString(2).padStart(32,"0")}static print(t){const n=M.getLanguageId(t),r=M.getTokenType(t),o=M.getFontStyle(t),s=M.getForeground(t),a=M.getBackground(t);console.log({languageId:n,tokenType:r,fontStyle:o,foreground:s,background:a})}static getLanguageId(t){return(t&255)>>>0}static getTokenType(t){return(t&768)>>>8}static containsBalancedBrackets(t){return(t&1024)!==0}static getFontStyle(t){return(t&30720)>>>11}static getForeground(t){return(t&16744448)>>>15}static getBackground(t){return(t&4278190080)>>>24}static set(t,n,r,o,s,a,l){let i=M.getLanguageId(t),c=M.getTokenType(t),h=M.containsBalancedBrackets(t)?1:0,u=M.getFontStyle(t),d=M.getForeground(t),g=M.getBackground(t);return n!==0&&(i=n),r!==8&&(c=r),o!==null&&(h=o?1:0),s!==-1&&(u=s),a!==0&&(d=a),l!==0&&(g=l),(i<<0|c<<8|h<<10|u<<11|d<<15|g<<24)>>>0}};function be(e,t){const n=[],r=Wn(e);let o=r.next();for(;o!==null;){let i=0;if(o.length===2&&o.charAt(1)===":"){switch(o.charAt(0)){case"R":i=1;break;case"L":i=-1;break;default:console.log(`Unknown priority ${o} in scope selector`)}o=r.next()}let c=a();if(n.push({matcher:c,priority:i}),o!==",")break;o=r.next()}return n;function s(){if(o==="-"){o=r.next();const i=s();return c=>!!i&&!i(c)}if(o==="("){o=r.next();const i=l();return o===")"&&(o=r.next()),i}if(kt(o)){const i=[];do i.push(o),o=r.next();while(kt(o));return c=>t(i,c)}return null}function a(){const i=[];let c=s();for(;c;)i.push(c),c=s();return h=>i.every(u=>u(h))}function l(){const i=[];let c=a();for(;c&&(i.push(c),o==="|"||o===",");){do o=r.next();while(o==="|"||o===",");c=a()}return h=>i.some(u=>u(h))}}function kt(e){return!!e&&!!e.match(/[\w\.:]+/)}function Wn(e){let t=/([LR]:|[\w\.:][\w\.:\-]*|[\,\|\-\(\)])/g,n=t.exec(e);return{next:()=>{if(!n)return null;const r=n[0];return n=t.exec(e),r}}}function _t(e){typeof e.dispose=="function"&&e.dispose()}var te=class{constructor(e){this.scopeName=e}toKey(){return this.scopeName}},Un=class{constructor(e,t){this.scopeName=e,this.ruleName=t}toKey(){return`${this.scopeName}#${this.ruleName}`}},qn=class{constructor(){p(this,"_references",[]),p(this,"_seenReferenceKeys",new Set),p(this,"visitedRule",new Set)}get references(){return this._references}add(e){const t=e.toKey();this._seenReferenceKeys.has(t)||(this._seenReferenceKeys.add(t),this._references.push(e))}},zn=class{constructor(e,t){p(this,"seenFullScopeRequests",new Set),p(this,"seenPartialScopeRequests",new Set),p(this,"Q"),this.repo=e,this.initialScopeName=t,this.seenFullScopeRequests.add(this.initialScopeName),this.Q=[new te(this.initialScopeName)]}processQueue(){const e=this.Q;this.Q=[];const t=new qn;for(const n of e)Hn(n,this.initialScopeName,this.repo,t);for(const n of t.references)if(n instanceof te){if(this.seenFullScopeRequests.has(n.scopeName))continue;this.seenFullScopeRequests.add(n.scopeName),this.Q.push(n)}else{if(this.seenFullScopeRequests.has(n.scopeName)||this.seenPartialScopeRequests.has(n.toKey()))continue;this.seenPartialScopeRequests.add(n.toKey()),this.Q.push(n)}}};function Hn(e,t,n,r){const o=n.lookup(e.scopeName);if(!o){if(e.scopeName===t)throw new Error(`No grammar provided for <${t}>`);return}const s=n.lookup(t);e instanceof te?ke({baseGrammar:s,selfGrammar:o},r):$e(e.ruleName,{baseGrammar:s,selfGrammar:o,repository:o.repository},r);const a=n.injections(e.scopeName);if(a)for(const l of a)r.add(new te(l))}function $e(e,t,n){if(t.repository&&t.repository[e]){const r=t.repository[e];_e([r],t,n)}}function ke(e,t){e.selfGrammar.patterns&&Array.isArray(e.selfGrammar.patterns)&&_e(e.selfGrammar.patterns,{...e,repository:e.selfGrammar.repository},t),e.selfGrammar.injections&&_e(Object.values(e.selfGrammar.injections),{...e,repository:e.selfGrammar.repository},t)}function _e(e,t,n){for(const r of e){if(n.visitedRule.has(r))continue;n.visitedRule.add(r);const o=r.repository?ht({},t.repository,r.repository):t.repository;Array.isArray(r.patterns)&&_e(r.patterns,{...t,repository:o},n);const s=r.include;if(!s)continue;const a=St(s);switch(a.kind){case 0:ke({...t,selfGrammar:t.baseGrammar},n);break;case 1:ke(t,n);break;case 2:$e(a.ruleName,{...t,repository:o},n);break;case 3:case 4:const l=a.scopeName===t.selfGrammar.scopeName?t.selfGrammar:a.scopeName===t.baseGrammar.scopeName?t.baseGrammar:void 0;if(l){const i={baseGrammar:t.baseGrammar,selfGrammar:l,repository:o};a.kind===4?$e(a.ruleName,i,n):ke(i,n)}else a.kind===4?n.add(new Un(a.scopeName,a.ruleName)):n.add(new te(a.scopeName));break}}}var Yn=class{constructor(){p(this,"kind",0)}},Kn=class{constructor(){p(this,"kind",1)}},Vn=class{constructor(e){p(this,"kind",2),this.ruleName=e}},Xn=class{constructor(e){p(this,"kind",3),this.scopeName=e}},Jn=class{constructor(e,t){p(this,"kind",4),this.scopeName=e,this.ruleName=t}};function St(e){if(e==="$base")return new Yn;if(e==="$self")return new Kn;const t=e.indexOf("#");if(t===-1)return new Xn(e);if(t===0)return new Vn(e.substring(1));{const n=e.substring(0,t),r=e.substring(t+1);return new Jn(n,r)}}var Qn=/\\(\d+)/,vt=/\\(\d+)/g,Zn=-1,wt=-2,ne=class{constructor(e,t,n,r){p(this,"$location"),p(this,"id"),p(this,"_nameIsCapturing"),p(this,"_name"),p(this,"_contentNameIsCapturing"),p(this,"_contentName"),this.$location=e,this.id=t,this._name=n||null,this._nameIsCapturing=fe.hasCaptures(this._name),this._contentName=r||null,this._contentNameIsCapturing=fe.hasCaptures(this._contentName)}get debugName(){const e=this.$location?`${dt(this.$location.filename)}:${this.$location.line}`:"unknown";return`${this.constructor.name}#${this.id} @ ${e}`}getName(e,t){return!this._nameIsCapturing||this._name===null||e===null||t===null?this._name:fe.replaceCaptures(this._name,e,t)}getContentName(e,t){return!this._contentNameIsCapturing||this._contentName===null?this._contentName:fe.replaceCaptures(this._contentName,e,t)}},er=class extends ne{constructor(e,t,n,r,o){super(e,t,n,r),p(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,n,r){throw new Error("Not supported!")}},tr=class extends ne{constructor(e,t,n,r,o){super(e,t,n,null),p(this,"_match"),p(this,"captures"),p(this,"_cachedCompiledPatterns"),this._match=new re(r,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,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new oe,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},Ct=class extends ne{constructor(e,t,n,r,o){super(e,t,n,r),p(this,"hasMissingPatterns"),p(this,"patterns"),p(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 n of this.patterns)e.getRule(n).collectPatterns(e,t)}compile(e,t){return this._getCachedCompiledPatterns(e).compile(e)}compileAG(e,t,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){return this._cachedCompiledPatterns||(this._cachedCompiledPatterns=new oe,this.collectPatterns(e,this._cachedCompiledPatterns)),this._cachedCompiledPatterns}},De=class extends ne{constructor(e,t,n,r,o,s,a,l,i,c){super(e,t,n,r),p(this,"_begin"),p(this,"beginCaptures"),p(this,"_end"),p(this,"endHasBackReferences"),p(this,"endCaptures"),p(this,"applyEndPatternLast"),p(this,"hasMissingPatterns"),p(this,"patterns"),p(this,"_cachedCompiledPatterns"),this._begin=new re(o,this.id),this.beginCaptures=s,this._end=new re(a||"\uFFFF",-1),this.endHasBackReferences=this._end.hasBackReferences,this.endCaptures=l,this.applyEndPatternLast=i||!1,this.patterns=c.patterns,this.hasMissingPatterns=c.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,n,r){return this._getCachedCompiledPatterns(e,t).compileAG(e,n,r)}_getCachedCompiledPatterns(e,t){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new oe;for(const n of this.patterns)e.getRule(n).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}},Se=class extends ne{constructor(e,t,n,r,o,s,a,l,i){super(e,t,n,r),p(this,"_begin"),p(this,"beginCaptures"),p(this,"whileCaptures"),p(this,"_while"),p(this,"whileHasBackReferences"),p(this,"hasMissingPatterns"),p(this,"patterns"),p(this,"_cachedCompiledPatterns"),p(this,"_cachedCompiledWhilePatterns"),this._begin=new re(o,this.id),this.beginCaptures=s,this.whileCaptures=l,this._while=new re(a,wt),this.whileHasBackReferences=this._while.hasBackReferences,this.patterns=i.patterns,this.hasMissingPatterns=i.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,n,r){return this._getCachedCompiledPatterns(e).compileAG(e,n,r)}_getCachedCompiledPatterns(e){if(!this._cachedCompiledPatterns){this._cachedCompiledPatterns=new oe;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,n,r){return this._getCachedCompiledWhilePatterns(e,t).compileAG(e,n,r)}_getCachedCompiledWhilePatterns(e,t){return this._cachedCompiledWhilePatterns||(this._cachedCompiledWhilePatterns=new oe,this._cachedCompiledWhilePatterns.push(this._while.hasBackReferences?this._while.clone():this._while)),this._while.hasBackReferences&&this._cachedCompiledWhilePatterns.setSource(0,t||"\uFFFF"),this._cachedCompiledWhilePatterns}},Tt=class E{static createCaptureRule(t,n,r,o,s){return t.registerRule(a=>new er(n,a,r,o,s))}static getCompiledRuleId(t,n,r){return t.id||n.registerRule(o=>{if(t.id=o,t.match)return new tr(t.$vscodeTextmateLocation,t.id,t.name,t.match,E._compileCaptures(t.captures,n,r));if(typeof t.begin>"u"){t.repository&&(r=ht({},r,t.repository));let s=t.patterns;return typeof s>"u"&&t.include&&(s=[{include:t.include}]),new Ct(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,E._compilePatterns(s,n,r))}return t.while?new Se(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,E._compileCaptures(t.beginCaptures||t.captures,n,r),t.while,E._compileCaptures(t.whileCaptures||t.captures,n,r),E._compilePatterns(t.patterns,n,r)):new De(t.$vscodeTextmateLocation,t.id,t.name,t.contentName,t.begin,E._compileCaptures(t.beginCaptures||t.captures,n,r),t.end,E._compileCaptures(t.endCaptures||t.captures,n,r),t.applyEndPatternLast,E._compilePatterns(t.patterns,n,r))}),t.id}static _compileCaptures(t,n,r){let o=[];if(t){let s=0;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const l=parseInt(a,10);l>s&&(s=l)}for(let a=0;a<=s;a++)o[a]=null;for(const a in t){if(a==="$vscodeTextmateLocation")continue;const l=parseInt(a,10);let i=0;t[a].patterns&&(i=E.getCompiledRuleId(t[a],n,r)),o[l]=E.createCaptureRule(n,t[a].$vscodeTextmateLocation,t[a].name,t[a].contentName,i)}}return o}static _compilePatterns(t,n,r){let o=[];if(t)for(let s=0,a=t.length;s<a;s++){const l=t[s];let i=-1;if(l.include){const c=St(l.include);switch(c.kind){case 0:case 1:i=E.getCompiledRuleId(r[l.include],n,r);break;case 2:let h=r[c.ruleName];h&&(i=E.getCompiledRuleId(h,n,r));break;case 3:case 4:const u=c.scopeName,d=c.kind===4?c.ruleName:null,g=n.getExternalGrammar(u,r);if(g)if(d){let f=g.repository[d];f&&(i=E.getCompiledRuleId(f,n,g.repository))}else i=E.getCompiledRuleId(g.repository.$self,n,g.repository);break}}else i=E.getCompiledRuleId(l,n,r);if(i!==-1){const c=n.getRule(i);let h=!1;if((c instanceof Ct||c instanceof De||c instanceof Se)&&c.hasMissingPatterns&&c.patterns.length===0&&(h=!0),h)continue;o.push(i)}}return{patterns:o,hasMissingPatterns:(t?t.length:0)!==o.length}}},re=class Pn{constructor(t,n){if(p(this,"source"),p(this,"ruleId"),p(this,"hasAnchor"),p(this,"hasBackReferences"),p(this,"_anchorCache"),t&&typeof t=="string"){const r=t.length;let o=0,s=[],a=!1;for(let l=0;l<r;l++)if(t.charAt(l)==="\\"&&l+1<r){const i=t.charAt(l+1);i==="z"?(s.push(t.substring(o,l)),s.push("$(?!\\n)(?<!\\n)"),o=l+2):(i==="A"||i==="G")&&(a=!0),l++}this.hasAnchor=a,o===0?this.source=t:(s.push(t.substring(o,r)),this.source=s.join(""))}else this.hasAnchor=!1,this.source=t;this.hasAnchor?this._anchorCache=this._buildAnchorCache():this._anchorCache=null,this.ruleId=n,typeof this.source=="string"?this.hasBackReferences=Qn.test(this.source):this.hasBackReferences=!1}clone(){return new Pn(this.source,this.ruleId)}setSource(t){this.source!==t&&(this.source=t,this.hasAnchor&&(this._anchorCache=this._buildAnchorCache()))}resolveBackReferences(t,n){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let r=n.map(o=>t.substring(o.start,o.end));return vt.lastIndex=0,this.source.replace(vt,(o,s)=>ft(r[parseInt(s,10)]||""))}_buildAnchorCache(){if(typeof this.source!="string")throw new Error("This method should only be called if the source is a string");let t=[],n=[],r=[],o=[],s,a,l,i;for(s=0,a=this.source.length;s<a;s++)l=this.source.charAt(s),t[s]=l,n[s]=l,r[s]=l,o[s]=l,l==="\\"&&s+1<a&&(i=this.source.charAt(s+1),i==="A"?(t[s+1]="\uFFFF",n[s+1]="\uFFFF",r[s+1]="A",o[s+1]="A"):i==="G"?(t[s+1]="\uFFFF",n[s+1]="G",r[s+1]="\uFFFF",o[s+1]="G"):(t[s+1]=i,n[s+1]=i,r[s+1]=i,o[s+1]=i),s++);return{A0_G0:t.join(""),A0_G1:n.join(""),A1_G0:r.join(""),A1_G1:o.join("")}}resolveAnchors(t,n){return!this.hasAnchor||!this._anchorCache||typeof this.source!="string"?this.source:t?n?this._anchorCache.A1_G1:this._anchorCache.A1_G0:n?this._anchorCache.A0_G1:this._anchorCache.A0_G0}},oe=class{constructor(){p(this,"_items"),p(this,"_hasAnchors"),p(this,"_cached"),p(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(e){this._items.push(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}unshift(e){this._items.unshift(e),this._hasAnchors=this._hasAnchors||e.hasAnchor}length(){return this._items.length}setSource(e,t){this._items[e].source!==t&&(this._disposeCaches(),this._items[e].setSource(t))}compile(e){if(!this._cached){let t=this._items.map(n=>n.source);this._cached=new Nt(e,t,this._items.map(n=>n.ruleId))}return this._cached}compileAG(e,t,n){return this._hasAnchors?t?n?(this._anchorCache.A1_G1||(this._anchorCache.A1_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G1):(this._anchorCache.A1_G0||(this._anchorCache.A1_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A1_G0):n?(this._anchorCache.A0_G1||(this._anchorCache.A0_G1=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G1):(this._anchorCache.A0_G0||(this._anchorCache.A0_G0=this._resolveAnchors(e,t,n)),this._anchorCache.A0_G0):this.compile(e)}_resolveAnchors(e,t,n){let r=this._items.map(o=>o.resolveAnchors(t,n));return new Nt(e,r,this._items.map(o=>o.ruleId))}},Nt=class{constructor(e,t,n){p(this,"scanner"),this.regExps=t,this.rules=n,this.scanner=e.createOnigScanner(t)}dispose(){typeof this.scanner.dispose=="function"&&this.scanner.dispose()}toString(){const e=[];for(let t=0,n=this.rules.length;t<n;t++)e.push(" - "+this.rules[t]+": "+this.regExps[t]);return e.join(` `)}findNextMatchSync(e,t,n){const r=this.scanner.findNextMatchSync(e,t,n);return r?{ruleId:this.rules[r.index],captureIndices:r.captureIndices}:null}},je=class{constructor(e,t){this.languageId=e,this.tokenType=t}},K,nr=(K=class{constructor(e,t){p(this,"_defaultAttributes"),p(this,"_embeddedLanguagesMatcher"),p(this,"_getBasicScopeAttributes",new yt(n=>{const r=this._scopeToLanguage(n),o=this._toStandardTokenType(n);return new je(r,o)})),this._defaultAttributes=new je(e,8),this._embeddedLanguagesMatcher=new rr(Object.entries(t||{}))}getDefaultAttributes(){return this._defaultAttributes}getBasicScopeAttributes(e){return e===null?K._NULL_SCOPE_METADATA:this._getBasicScopeAttributes.get(e)}_scopeToLanguage(e){return this._embeddedLanguagesMatcher.match(e)||0}_toStandardTokenType(e){const t=e.match(K.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!")}},p(K,"_NULL_SCOPE_METADATA",new je(0,0)),p(K,"STANDARD_TOKEN_TYPE_REGEXP",/\b(comment|string|regex|meta\.embedded)\b/),K),rr=class{constructor(e){if(p(this,"values"),p(this,"scopesRegExp"),e.length===0)this.values=null,this.scopesRegExp=null;else{this.values=new Map(e);const t=e.map(([n,r])=>ft(n));t.sort(),t.reverse(),this.scopesRegExp=new RegExp(`^((${t.join(")|(")}))($|\\.)`,"")}}match(e){if(!this.scopesRegExp)return;const t=e.match(this.scopesRegExp);if(t)return this.values.get(t[1])}};typeof process<"u"&&process.env.VSCODE_TEXTMATE_DEBUG;var Pt=class{constructor(e,t){this.stack=e,this.stoppedEarly=t}};function At(e,t,n,r,o,s,a,l){const i=t.content.length;let c=!1,h=-1;if(a){const g=or(e,t,n,r,o,s);o=g.stack,r=g.linePos,n=g.isFirstLine,h=g.anchorPosition}const u=Date.now();for(;!c;){if(l!==0&&Date.now()-u>l)return new Pt(o,!0);d()}return new Pt(o,!1);function d(){const g=sr(e,t,n,r,o,h);if(!g){s.produce(o,i),c=!0;return}const f=g.captureIndices,_=g.matchedRuleId,S=f&&f.length>0?f[0].end>r:!1;if(_===Zn){const b=o.getRule(e);s.produce(o,f[0].start),o=o.withContentNameScopesList(o.nameScopesList),se(e,t,n,o,s,b.endCaptures,f),s.produce(o,f[0].end);const y=o;if(o=o.parent,h=y.getAnchorPos(),!S&&y.getEnterPos()===r){o=y,s.produce(o,i),c=!0;return}}else{const b=e.getRule(_);s.produce(o,f[0].start);const y=o,k=b.getName(t.content,f),w=o.contentNameScopesList.pushAttributed(k,e);if(o=o.push(_,r,h,f[0].end===i,null,w,w),b instanceof De){const N=b;se(e,t,n,o,s,N.beginCaptures,f),s.produce(o,f[0].end),h=f[0].end;const P=N.getContentName(t.content,f),x=w.pushAttributed(P,e);if(o=o.withContentNameScopesList(x),N.endHasBackReferences&&(o=o.withEndRule(N.getEndWithResolvedBackReferences(t.content,f))),!S&&y.hasSameRuleAs(o)){o=o.pop(),s.produce(o,i),c=!0;return}}else if(b instanceof Se){const N=b;se(e,t,n,o,s,N.beginCaptures,f),s.produce(o,f[0].end),h=f[0].end;const P=N.getContentName(t.content,f),x=w.pushAttributed(P,e);if(o=o.withContentNameScopesList(x),N.whileHasBackReferences&&(o=o.withEndRule(N.getWhileWithResolvedBackReferences(t.content,f))),!S&&y.hasSameRuleAs(o)){o=o.pop(),s.produce(o,i),c=!0;return}}else if(se(e,t,n,o,s,b.captures,f),s.produce(o,f[0].end),o=o.pop(),!S){o=o.safePop(),s.produce(o,i),c=!0;return}}f[0].end>r&&(r=f[0].end,n=!1)}}function or(e,t,n,r,o,s){let a=o.beginRuleCapturedEOL?0:-1;const l=[];for(let i=o;i;i=i.pop()){const c=i.getRule(e);c instanceof Se&&l.push({rule:c,stack:i})}for(let i=l.pop();i;i=l.pop()){const{ruleScanner:c,findOptions:h}=lr(i.rule,e,i.stack.endRule,n,r===a),u=c.findNextMatchSync(t,r,h);if(u){if(u.ruleId!==wt){o=i.stack.pop();break}u.captureIndices&&u.captureIndices.length&&(s.produce(i.stack,u.captureIndices[0].start),se(e,t,n,i.stack,s,i.rule.whileCaptures,u.captureIndices),s.produce(i.stack,u.captureIndices[0].end),a=u.captureIndices[0].end,u.captureIndices[0].end>r&&(r=u.captureIndices[0].end,n=!1))}else{o=i.stack.pop();break}}return{stack:o,linePos:r,anchorPosition:a,isFirstLine:n}}function sr(e,t,n,r,o,s){const a=ar(e,t,n,r,o,s),l=e.getInjections();if(l.length===0)return a;const i=ir(l,e,t,n,r,o,s);if(!i)return a;if(!a)return i;const c=a.captureIndices[0].start,h=i.captureIndices[0].start;return h<c||i.priorityMatch&&h===c?i:a}function ar(e,t,n,r,o,s){const a=o.getRule(e),{ruleScanner:l,findOptions:i}=xt(a,e,o.endRule,n,r===s),c=l.findNextMatchSync(t,r,i);return c?{captureIndices:c.captureIndices,matchedRuleId:c.ruleId}:null}function ir(e,t,n,r,o,s,a){let l=Number.MAX_VALUE,i=null,c,h=0;const u=s.contentNameScopesList.getScopeNames();for(let d=0,g=e.length;d<g;d++){const f=e[d];if(!f.matcher(u))continue;const _=t.getRule(f.ruleId),{ruleScanner:S,findOptions:b}=xt(_,t,null,r,o===a),y=S.findNextMatchSync(n,o,b);if(!y)continue;const k=y.captureIndices[0].start;if(!(k>=l)&&(l=k,i=y.captureIndices,c=y.ruleId,h=f.priority,l===o))break}return i?{priorityMatch:h===-1,captureIndices:i,matchedRuleId:c}:null}function xt(e,t,n,r,o){return{ruleScanner:e.compileAG(t,n,r,o),findOptions:0}}function lr(e,t,n,r,o){return{ruleScanner:e.compileWhileAG(t,n,r,o),findOptions:0}}function se(e,t,n,r,o,s,a){if(s.length===0)return;const l=t.content,i=Math.min(s.length,a.length),c=[],h=a[0].end;for(let u=0;u<i;u++){const d=s[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;)o.produceFromScopes(c[c.length-1].scopes,c[c.length-1].endPos),c.pop();if(c.length>0?o.produceFromScopes(c[c.length-1].scopes,g.start):o.produce(r,g.start),d.retokenizeCapturedWithRuleId){const _=d.getName(l,a),S=r.contentNameScopesList.pushAttributed(_,e),b=d.getContentName(l,a),y=S.pushAttributed(b,e),k=r.push(d.retokenizeCapturedWithRuleId,g.start,-1,!1,null,S,y),w=e.createOnigString(l.substring(0,g.end));At(e,w,n&&g.start===0,g.start,k,o,!1,0),_t(w);continue}const f=d.getName(l,a);if(f!==null){const _=(c.length>0?c[c.length-1].scopes:r.contentNameScopesList).pushAttributed(f,e);c.push(new cr(_,g.end))}}for(;c.length>0;)o.produceFromScopes(c[c.length-1].scopes,c[c.length-1].endPos),c.pop()}var cr=class{constructor(e,t){p(this,"scopes"),p(this,"endPos"),this.scopes=e,this.endPos=t}};function ur(e,t,n,r,o,s,a,l){return new dr(e,t,n,r,o,s,a,l)}function Lt(e,t,n,r,o){const s=be(t,ve),a=Tt.getCompiledRuleId(n,r,o.repository);for(const l of s)e.push({debugSelector:t,matcher:l.matcher,ruleId:a,grammar:o,priority:l.priority})}function ve(e,t){if(t.length<e.length)return!1;let n=0;return e.every(r=>{for(let o=n;o<t.length;o++)if(hr(t[o],r))return n=o+1,!0;return!1})}function hr(e,t){if(!e)return!1;if(e===t)return!0;const n=t.length;return e.length>n&&e.substr(0,n)===t&&e[n]==="."}var dr=class{constructor(e,t,n,r,o,s,a,l){if(p(this,"_rootId"),p(this,"_lastRuleId"),p(this,"_ruleId2desc"),p(this,"_includedGrammars"),p(this,"_grammarRepository"),p(this,"_grammar"),p(this,"_injections"),p(this,"_basicScopeAttributesProvider"),p(this,"_tokenTypeMatchers"),this._rootScopeName=e,this.balancedBracketSelectors=s,this._onigLib=l,this._basicScopeAttributesProvider=new nr(n,r),this._rootId=-1,this._lastRuleId=0,this._ruleId2desc=[null],this._includedGrammars={},this._grammarRepository=a,this._grammar=Rt(t,null),this._injections=null,this._tokenTypeMatchers=[],o)for(const i of Object.keys(o)){const c=be(i,ve);for(const h of c)this._tokenTypeMatchers.push({matcher:h.matcher,type:o[i]})}}get themeProvider(){return this._grammarRepository}dispose(){for(const e of this._ruleId2desc)e&&e.dispose()}createOnigScanner(e){return this._onigLib.createOnigScanner(e)}createOnigString(e){return this._onigLib.createOnigString(e)}getMetadataForScope(e){return this._basicScopeAttributesProvider.getBasicScopeAttributes(e)}_collectInjections(){const e={lookup:o=>o===this._rootScopeName?this._grammar:this.getExternalGrammar(o),injections:o=>this._grammarRepository.injections(o)},t=[],n=this._rootScopeName,r=e.lookup(n);if(r){const o=r.injections;if(o)for(let a in o)Lt(t,a,o[a],this,r);const s=this._grammarRepository.injections(n);s&&s.forEach(a=>{const l=this.getExternalGrammar(a);if(l){const i=l.injectionSelector;i&&Lt(t,i,l,this,l)}})}return t.sort((o,s)=>o.priority-s.priority),t}getInjections(){return this._injections===null&&(this._injections=this._collectInjections()),this._injections}registerRule(e){const t=++this._lastRuleId,n=e(t);return this._ruleId2desc[t]=n,n}getRule(e){return this._ruleId2desc[e]}getExternalGrammar(e,t){if(this._includedGrammars[e])return this._includedGrammars[e];if(this._grammarRepository){const n=this._grammarRepository.lookup(e);if(n)return this._includedGrammars[e]=Rt(n,t&&t.$base),this._includedGrammars[e]}}tokenizeLine(e,t,n=0){const r=this._tokenize(e,t,!1,n);return{tokens:r.lineTokens.getResult(r.ruleStack,r.lineLength),ruleStack:r.ruleStack,stoppedEarly:r.stoppedEarly}}tokenizeLine2(e,t,n=0){const r=this._tokenize(e,t,!0,n);return{tokens:r.lineTokens.getBinaryResult(r.ruleStack,r.lineLength),ruleStack:r.ruleStack,stoppedEarly:r.stoppedEarly}}_tokenize(e,t,n,r){this._rootId===-1&&(this._rootId=Tt.getCompiledRuleId(this._grammar.repository.$self,this,this._grammar.repository),this.getInjections());let o;if(!t||t===Fe.NULL){o=!0;const c=this._basicScopeAttributesProvider.getDefaultAttributes(),h=this.themeProvider.getDefaults(),u=Y.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=ae.createRootAndLookUpScopeName(d,u,this):g=ae.createRoot("unknown",u),t=new Fe(null,this._rootId,-1,-1,!1,null,g,g)}else o=!1,t.reset();e=e+` `;const s=this.createOnigString(e),a=s.content.length,l=new gr(n,e,this._tokenTypeMatchers,this.balancedBracketSelectors),i=At(this,s,o,0,t,l,!0,r);return _t(s),{lineLength:a,lineTokens:l,ruleStack:i.stack,stoppedEarly:i.stoppedEarly}}};function Rt(e,t){return e=Rn(e),e.repository=e.repository||{},e.repository.$self={$vscodeTextmateLocation:e.$vscodeTextmateLocation,patterns:e.patterns,name:e.scopeName},e.repository.$base=t||e.repository.$self,e}var ae=class G{constructor(t,n,r){this.parent=t,this.scopePath=n,this.tokenAttributes=r}static fromExtension(t,n){let r=t,o=t?.scopePath??null;for(const s of n)o=Be.push(o,s.scopeNames),r=new G(r,o,s.encodedTokenAttributes);return r}static createRoot(t,n){return new G(null,new Be(null,t),n)}static createRootAndLookUpScopeName(t,n,r){const o=r.getMetadataForScope(t),s=new Be(null,t),a=r.themeProvider.themeMatch(s),l=G.mergeAttributes(n,o,a);return new G(null,s,l)}get scopeName(){return this.scopePath.scopeName}toString(){return this.getScopeNames().join(" ")}equals(t){return G.equals(this,t)}static equals(t,n){do{if(t===n||!t&&!n)return!0;if(!t||!n||t.scopeName!==n.scopeName||t.tokenAttributes!==n.tokenAttributes)return!1;t=t.parent,n=n.parent}while(!0)}static mergeAttributes(t,n,r){let o=-1,s=0,a=0;return r!==null&&(o=r.fontStyle,s=r.foregroundId,a=r.backgroundId),Y.set(t,n.languageId,n.tokenType,null,o,s,a)}pushAttributed(t,n){if(t===null)return this;if(t.indexOf(" ")===-1)return G._pushAttributed(this,t,n);const r=t.split(/ /g);let o=this;for(const s of r)o=G._pushAttributed(o,s,n);return o}static _pushAttributed(t,n,r){const o=r.getMetadataForScope(n),s=t.scopePath.push(n),a=r.themeProvider.themeMatch(s),l=G.mergeAttributes(t.tokenAttributes,o,a);return new G(t,s,l)}getScopeNames(){return this.scopePath.getSegments()}getExtensionIfDefined(t){var n;const r=[];let o=this;for(;o&&o!==t;)r.push({encodedTokenAttributes:o.tokenAttributes,scopeNames:o.scopePath.getExtensionIfDefined(((n=o.parent)==null?void 0:n.scopePath)??null)}),o=o.parent;return o===t?r.reverse():void 0}},D,Fe=(D=class{constructor(e,t,n,r,o,s,a,l){p(this,"_stackElementBrand"),p(this,"_enterPos"),p(this,"_anchorPos"),p(this,"depth"),this.parent=e,this.ruleId=t,this.beginRuleCapturedEOL=o,this.endRule=s,this.nameScopesList=a,this.contentNameScopesList=l,this.depth=this.parent?this.parent.depth+1:1,this._enterPos=n,this._anchorPos=r}equals(e){return e===null?!1:D._equals(this,e)}static _equals(e,t){return e===t?!0:this._structuralEquals(e,t)?ae.equals(e.contentNameScopesList,t.contentNameScopesList):!1}static _structuralEquals(e,t){do{if(e===t||!e&&!t)return!0;if(!e||!t||e.depth!==t.depth||e.ruleId!==t.ruleId||e.endRule!==t.endRule)return!1;e=e.parent,t=t.parent}while(!0)}clone(){return this}static _reset(e){for(;e;)e._enterPos=-1,e._anchorPos=-1,e=e.parent}reset(){D._reset(this)}pop(){return this.parent}safePop(){return this.parent?this.parent:this}push(e,t,n,r,o,s,a){return new D(this,e,t,n,r,o,s,a)}getEnterPos(){return this._enterPos}getAnchorPos(){return this._anchorPos}getRule(e){return e.getRule(this.ruleId)}toString(){const e=[];return this._writeString(e,0),"["+e.join(",")+"]"}_writeString(e,t){var n,r;return this.parent&&(t=this.parent._writeString(e,t)),e[t++]=`(${this.ruleId}, ${(n=this.nameScopesList)==null?void 0:n.toString()}, ${(r=this.contentNameScopesList)==null?void 0:r.toString()})`,t}withContentNameScopesList(e){return this.contentNameScopesList===e?this:this.parent.push(this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,this.endRule,this.nameScopesList,e)}withEndRule(e){return this.endRule===e?this:new D(this.parent,this.ruleId,this._enterPos,this._anchorPos,this.beginRuleCapturedEOL,e,this.nameScopesList,this.contentNameScopesList)}hasSameRuleAs(e){let t=this;for(;t&&t._enterPos===e._enterPos;){if(t.ruleId===e.ruleId)return!0;t=t.parent}return!1}toStateStackFrame(){var e,t,n;return{ruleId:this.ruleId,beginRuleCapturedEOL:this.beginRuleCapturedEOL,endRule:this.endRule,nameScopesList:((t=this.nameScopesList)==null?void 0:t.getExtensionIfDefined(((e=this.parent)==null?void 0:e.nameScopesList)??null))??[],contentNameScopesList:((n=this.contentNameScopesList)==null?void 0:n.getExtensionIfDefined(this.nameScopesList))??[]}}static pushFrame(e,t){const n=ae.fromExtension(e?.nameScopesList??null,t.nameScopesList);return new D(e,t.ruleId,t.enterPos??-1,t.anchorPos??-1,t.beginRuleCapturedEOL,t.endRule,n,ae.fromExtension(n,t.contentNameScopesList))}},p(D,"NULL",new D(null,0,0,0,!1,null,null,null)),D),pr=class{constructor(e,t){p(this,"balancedBracketScopes"),p(this,"unbalancedBracketScopes"),p(this,"allowAny",!1),this.balancedBracketScopes=e.flatMap(n=>n==="*"?(this.allowAny=!0,[]):be(n,ve).map(r=>r.matcher)),this.unbalancedBracketScopes=t.flatMap(n=>be(n,ve).map(r=>r.matcher))}get matchesAlways(){return this.allowAny&&this.unbalancedBracketScopes.length===0}get matchesNever(){return this.balancedBracketScopes.length===0&&!this.allowAny}match(e){for(const t of this.unbalancedBracketScopes)if(t(e))return!1;for(const t of this.balancedBracketScopes)if(t(e))return!0;return this.allowAny}},gr=class{constructor(e,t,n,r){p(this,"_emitBinaryTokens"),p(this,"_lineText"),p(this,"_tokens"),p(this,"_binaryTokens"),p(this,"_lastTokenEndIndex"),p(this,"_tokenTypeOverrides"),this.balancedBracketSelectors=r,this._emitBinaryTokens=e,this._tokenTypeOverrides=n,this._lineText=null,this._tokens=[],this._binaryTokens=[],this._lastTokenEndIndex=0}produce(e,t){this.produceFromScopes(e.contentNameScopesList,t)}produceFromScopes(e,t){var n;if(this._lastTokenEndIndex>=t)return;if(this._emitBinaryTokens){let o=e?.tokenAttributes??0,s=!1;if((n=this.balancedBracketSelectors)!=null&&n.matchesAlways&&(s=!0),this._tokenTypeOverrides.length>0||this.balancedBracketSelectors&&!this.balancedBracketSelectors.matchesAlways&&!this.balancedBracketSelectors.matchesNever){const a=e?.getScopeNames()??[];for(const l of this._tokenTypeOverrides)l.matcher(a)&&(o=Y.set(o,0,l.type,null,-1,0,0));this.balancedBracketSelectors&&(s=this.balancedBracketSelectors.match(a))}if(s&&(o=Y.set(o,0,8,s,-1,0,0)),this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-1]===o){this._lastTokenEndIndex=t;return}this._binaryTokens.push(this._lastTokenEndIndex),this._binaryTokens.push(o),this._lastTokenEndIndex=t;return}const r=e?.getScopeNames()??[];this._tokens.push({startIndex:this._lastTokenEndIndex,endIndex:t,scopes:r}),this._lastTokenEndIndex=t}getResult(e,t){return this._tokens.length>0&&this._tokens[this._tokens.length-1].startIndex===t-1&&this._tokens.pop(),this._tokens.length===0&&(this._lastTokenEndIndex=-1,this.produce(e,t),this._tokens[this._tokens.length-1].startIndex=0),this._tokens}getBinaryResult(e,t){this._binaryTokens.length>0&&this._binaryTokens[this._binaryTokens.length-2]===t-1&&(this._binaryTokens.pop(),this._binaryTokens.pop()),this._binaryTokens.length===0&&(this._lastTokenEndIndex=-1,this.produce(e,t),this._binaryTokens[this._binaryTokens.length-2]=0);const n=new Uint32Array(this._binaryTokens.length);for(let r=0,o=this._binaryTokens.length;r<o;r++)n[r]=this._binaryTokens[r];return n}},mr=class{constructor(e,t){p(this,"_grammars",new Map),p(this,"_rawGrammars",new Map),p(this,"_injectionGrammars",new Map),p(this,"_theme"),this._onigLib=t,this._theme=e}dispose(){for(const e of this._grammars.values())e.dispose()}setTheme(e){this._theme=e}getColorMap(){return this._theme.getColorMap()}addGrammar(e,t){this._rawGrammars.set(e.scopeName,e),t&&this._injectionGrammars.set(e.scopeName,t)}lookup(e){return this._rawGrammars.get(e)}injections(e){return this._injectionGrammars.get(e)}getDefaults(){return this._theme.getDefaults()}themeMatch(e){return this._theme.match(e)}grammarForScopeName(e,t,n,r,o){if(!this._grammars.has(e)){let s=this._rawGrammars.get(e);if(!s)return null;this._grammars.set(e,ur(e,s,t,n,r,o,this,this._onigLib))}return this._grammars.get(e)}},fr=class{constructor(e){p(this,"_options"),p(this,"_syncRegistry"),p(this,"_ensureGrammarCache"),this._options=e,this._syncRegistry=new mr(ye.createFromRawTheme(e.theme,e.colorMap),e.onigLib),this._ensureGrammarCache=new Map}dispose(){this._syncRegistry.dispose()}setTheme(e,t){this._syncRegistry.setTheme(ye.createFromRawTheme(e,t))}getColorMap(){return this._syncRegistry.getColorMap()}loadGrammarWithEmbeddedLanguages(e,t,n){return this.loadGrammarWithConfiguration(e,t,{embeddedLanguages:n})}loadGrammarWithConfiguration(e,t,n){return this._loadGrammar(e,t,n.embeddedLanguages,n.tokenTypes,new pr(n.balancedBracketSelectors||[],n.unbalancedBracketSelectors||[]))}loadGrammar(e){return this._loadGrammar(e,0,null,null,null)}_loadGrammar(e,t,n,r,o){const s=new zn(this._syncRegistry,e);for(;s.Q.length>0;)s.Q.map(a=>this._loadSingleGrammar(a.scopeName)),s.processQueue();return this._grammarForScopeName(e,t,n,r,o)}_loadSingleGrammar(e){this._ensureGrammarCache.has(e)||(this._doLoadSingleGrammar(e),this._ensureGrammarCache.set(e,!0))}_doLoadSingleGrammar(e){const t=this._options.loadGrammar(e);if(t){const n=typeof this._options.getInjections=="function"?this._options.getInjections(e):void 0;this._syncRegistry.addGrammar(t,n)}}addGrammar(e,t=[],n=0,r=null){return this._syncRegistry.addGrammar(e,t),this._grammarForScopeName(e.scopeName,n,r)}_grammarForScopeName(e,t=0,n=null,r=null,o=null){return this._syncRegistry.grammarForScopeName(e,t,n,r,o)}},We=Fe.NULL;function ie(e,t){const n=typeof e=="string"?{}:{...e.colorReplacements},r=typeof e=="string"?e:e.name;for(const[o,s]of Object.entries(t?.colorReplacements||{}))typeof s=="string"?n[o]=s:o===r&&Object.assign(n,s);return n}function j(e,t){return e&&(t?.[e?.toLowerCase()]||e)}function Et(e){return Array.isArray(e)?e:[e]}async function Ue(e){return Promise.resolve(typeof e=="function"?e():e).then(t=>t.default||t)}function le(e){return!e||["plaintext","txt","text","plain"].includes(e)}function qe(e){return e==="ansi"||le(e)}function ce(e){return e==="none"}function ze(e){return ce(e)}const yr=/(\r?\n)/g;function ue(e,t=!1){var n;if(e.length===0)return[["",0]];const r=e.split(yr);let o=0;const s=[];for(let a=0;a<r.length;a+=2){const l=t?r[a]+(r[a+1]||""):r[a];s.push([l,o]),o+=r[a].length,o+=((n=r[a+1])==null?void 0:n.length)||0}return s}const It={light:"#333333",dark:"#bbbbbb"},Ot={light:"#fffffe",dark:"#1e1e1e"},Mt="__shiki_resolved";function we(e){var t,n,r,o,s;if(e!=null&&e[Mt])return e;const a={...e};a.tokenColors&&!a.settings&&(a.settings=a.tokenColors,delete a.tokenColors),a.type||(a.type="dark"),a.colorReplacements={...a.colorReplacements},a.settings||(a.settings=[]);let{bg:l,fg:i}=a;if(!l||!i){const d=a.settings?a.settings.find(g=>!g.name&&!g.scope):void 0;(t=d?.settings)!=null&&t.foreground&&(i=d.settings.foreground),(n=d?.settings)!=null&&n.background&&(l=d.settings.background),!i&&(r=a?.colors)!=null&&r["editor.foreground"]&&(i=a.colors["editor.foreground"]),!l&&(o=a?.colors)!=null&&o["editor.background"]&&(l=a.colors["editor.background"]),i||(i=a.type==="light"?It.light:It.dark),l||(l=a.type==="light"?Ot.light:Ot.dark),a.fg=i,a.bg=l}a.settings[0]&&a.settings[0].settings&&!a.settings[0].scope||a.settings.unshift({settings:{foreground:a.fg,background:a.bg}});let c=0;const h=new Map;function u(d){var g;if(h.has(d))return h.get(d);c+=1;const f=`#${c.toString(16).padStart(8,"0").toLowerCase()}`;return(g=a.colorReplacements)!=null&&g[`#${f}`]?u(d):(h.set(d,f),f)}a.settings=a.settings.map(d=>{var g,f;const _=((g=d.settings)==null?void 0:g.foreground)&&!d.settings.foreground.startsWith("#"),S=((f=d.settings)==null?void 0:f.background)&&!d.settings.background.startsWith("#");if(!_&&!S)return d;const b={...d,settings:{...d.settings}};if(_){const y=u(d.settings.foreground);a.colorReplacements[y]=d.settings.foreground,b.settings.foreground=y}if(S){const y=u(d.settings.background);a.colorReplacements[y]=d.settings.background,b.settings.background=y}return b});for(const d of Object.keys(a.colors||{}))if((d==="editor.foreground"||d==="editor.background"||d.startsWith("terminal.ansi"))&&!((s=a.colors[d])!=null&&s.startsWith("#"))){const g=u(a.colors[d]);a.colorReplacements[g]=a.colors[d],a.colors[d]=g}return Object.defineProperty(a,Mt,{enumerable:!1,writable:!1,value:!0}),a}async function Bt(e){return[...new Set((await Promise.all(e.filter(t=>!qe(t)).map(async t=>await Ue(t).then(n=>Array.isArray(n)?n:[n])))).flat())]}async function Gt(e){return(await Promise.all(e.map(async t=>ze(t)?null:we(await Ue(t))))).filter(t=>!!t)}function $t(e,t){if(!t)return e;if(t[e]){const n=new Set([e]);for(;t[e];){if(e=t[e],n.has(e))throw new C(`Circular alias \`${[...n].join(" -> ")} -> ${e}\``);n.add(e)}}return e}var br=class extends fr{constructor(e,t,n,r={}){super(e),p(this,"_resolver"),p(this,"_themes"),p(this,"_langs"),p(this,"_alias"),p(this,"_resolvedThemes",new Map),p(this,"_resolvedGrammars",new Map),p(this,"_langMap",new Map),p(this,"_langGraph",new Map),p(this,"_textmateThemeCache",new WeakMap),p(this,"_loadedThemesCache",null),p(this,"_loadedLanguagesCache",null),this._resolver=e,this._themes=t,this._langs=n,this._alias=r,this._themes.map(o=>this.loadTheme(o)),this.loadLanguages(this._langs)}getTheme(e){return typeof e=="string"?this._resolvedThemes.get(e):this.loadTheme(e)}loadTheme(e){const t=we(e);return t.name&&(this._resolvedThemes.set(t.name,t),this._loadedThemesCache=null),t}getLoadedThemes(){return this._loadedThemesCache||(this._loadedThemesCache=[...this._resolvedThemes.keys()]),this._loadedThemesCache}setTheme(e){let t=this._textmateThemeCache.get(e);t||(t=ye.createFromRawTheme(e),this._textmateThemeCache.set(e,t)),this._syncRegistry.setTheme(t)}getGrammar(e){return e=$t(e,this._alias),this._resolvedGrammars.get(e)}loadLanguage(e){var t,n,r,o;if(this.getGrammar(e.name))return;const s=new Set([...this._langMap.values()].filter(i=>{var c;return(c=i.embeddedLangsLazy)==null?void 0:c.includes(e.name)}));this._resolver.addLanguage(e);const a={balancedBracketSelectors:e.balancedBracketSelectors||["*"],unbalancedBracketSelectors:e.unbalancedBracketSelectors||[]};this._syncRegistry._rawGrammars.set(e.scopeName,e);const l=this.loadGrammarWithConfiguration(e.scopeName,1,a);if(l.name=e.name,this._resolvedGrammars.set(e.name,l),e.aliases&&e.aliases.forEach(i=>{this._alias[i]=e.name}),this._loadedLanguagesCache=null,s.size)for(const i of s)this._resolvedGrammars.delete(i.name),this._loadedLanguagesCache=null,(n=(t=this._syncRegistry)==null?void 0:t._injectionGrammars)==null||n.delete(i.scopeName),(o=(r=this._syncRegistry)==null?void 0:r._grammars)==null||o.delete(i.scopeName),this.loadLanguage(this._langMap.get(i.name))}dispose(){super.dispose(),this._resolvedThemes.clear(),this._resolvedGrammars.clear(),this._langMap.clear(),this._langGraph.clear(),this._loadedThemesCache=null}loadLanguages(e){for(const r of e)this.resolveEmbeddedLanguages(r);const t=[...this._langGraph.entries()],n=t.filter(([r,o])=>!o);if(n.length){const r=t.filter(([o,s])=>{var a;return s?(a=s.embeddedLanguages||s.embeddedLangs)==null?void 0:a.some(l=>n.map(([i])=>i).includes(l)):!1}).filter(o=>!n.includes(o));throw new C(`Missing languages ${n.map(([o])=>`\`${o}\``).join(", ")}, required by ${r.map(([o])=>`\`${o}\``).join(", ")}`)}for(const[r,o]of t)this._resolver.addLanguage(o);for(const[r,o]of t)this.loadLanguage(o)}getLoadedLanguages(){return this._loadedLanguagesCache||(this._loadedLanguagesCache=[...n