import{E as w,I as j,F as g}from"./index-b6Lfsnr6.js";var A=class I{constructor(t){this._ruleStack=t}get ruleStack(){return this._ruleStack}clone(){return new I(this._ruleStack)}equals(t){return!(!t||!(t instanceof I)||t!==this||t._ruleStack!==this._ruleStack)}};function f(e){if(Array.isArray(e)&&(e=e[0]),!!e)return e=(e.charCodeAt(0)===35?e.slice(1):e).toLowerCase(),(e.length===3||e.length===4)&&(e=e.split("").map(t=>t+t).join("")),e}function v(e){let t="rules"in e?e.rules:void 0;if(!t){t=[];const u=e.settings||e.tokenColors;for(const{scope:a,settings:{foreground:l,background:c,fontStyle:k}={}}of u){if(!l&&!c&&!k)continue;const p=Array.isArray(a)?a:a?[a]:[],T=b(k),m=f(l),L=f(c);t.push(...p.map(y=>({token:y,foreground:m,background:L,fontStyle:T})))}}const o=Object.fromEntries(Object.entries(e.colors||{}).map(([u,a])=>[u,`#${f(a)}`]));return{base:e.type==="light"?"vs":"vs-dark",inherit:!1,colors:o,rules:t}}function D(e,t,o={}){const u=new Map,a=e.getLoadedThemes();for(const r of a){const n=v(e.getTheme(r));u.set(r,n),t.editor.defineTheme(r,n)}const l=[],c=new Map,k=t.editor.setTheme.bind(t.editor);t.editor.setTheme=r=>{const n=e.setTheme(r),i=u.get(r);l.length=n.colorMap.length;for(let s=0;s<n.colorMap.length;s++)l[s]=n.colorMap[s];c.clear(),i==null||i.rules.forEach(s=>{const h=f(s.foreground);if(!h)return;const d=F(h,b(s.fontStyle));c.has(d)||c.set(d,s.token)}),k(r)};const p=t.editor.create;t.editor.create=(r,n,i)=>(n!=null&&n.theme&&t.editor.setTheme(n.theme),p(r,n,i)),t.editor.setTheme(a[0]);function T(r,n){const i=F(r,x(n));return c.get(i)}const{tokenizeMaxLineLength:m=2e4,tokenizeTimeLimit:L=500}=o,y=new Set(t.languages.getLanguages().map(r=>r.id));for(const r of e.getLoadedLanguages())y.has(r)&&t.languages.setTokensProvider(r,{getInitialState(){return new A(j)},tokenize(n,i){if(n.length>=m)return{endState:i,tokens:[{startIndex:0,scopes:""}]};const s=e.getLanguage(r).tokenizeLine2(n,i.ruleStack,L);s.stoppedEarly&&console.warn(`Time limit reached when tokenizing line: ${n.substring(0,100)}`);const h=s.tokens.length/2,d=[];for(let S=0;S<h;S++){const _=s.tokens[2*S],z=s.tokens[2*S+1],M=f(l[w.getForeground(z)]||""),C=w.getFontStyle(z),E=M&&T(M,C)||"";d.push({startIndex:_,scopes:E})}return{endState:new A(s.ruleStack),tokens:d}}})}function x(e){if(e<=g.None)return"";const t=[];return e&g.Italic&&t.push("italic"),e&g.Bold&&t.push("bold"),e&g.Underline&&t.push("underline"),e&g.Strikethrough&&t.push("strikethrough"),t.join(" ")}const B=["italic","bold","underline","strikethrough"],O={"line-through":"strikethrough"};function b(e){if(!e)return"";const t=new Set(e.split(/[\s,]+/).map(o=>o.trim().toLowerCase()).map(o=>O[o]||o).filter(Boolean));return B.filter(o=>t.has(o)).join(" ")}function F(e,t){return t?`${e}|${t}`:e}export{D as shikiToMonaco,v as textmateThemeToMonacoTheme};
