import e from"ansi-regex";import{css as n,unsafeCSS as o,html as t}from"lit";import{MemoryCache as c}from"../memory-cache.js";let s;const a=[{name:"bold",code:1,escapes:[21,22],style:"font-weight: bold"},{name:"dim",code:2,escapes:[21,22],style:"opacity: 0.5"},{name:"italic",code:3,escapes:[23],style:"font-style: italic"},{name:"underline",code:4,escapes:[24],style:"text-decoration: underline"},{name:"inverse",code:7,escapes:[27]},{name:"hidden",code:8,escapes:[28],style:"display: none"},{name:"strikethrough",code:9,escapes:[29],style:"text-decoration: line-through;"}],r=[{name:"black",code:30},{name:"red",code:31},{name:"green",code:32},{name:"yellow",code:33},{name:"blue",code:34},{name:"magenta",code:35},{name:"cyan",code:36},{name:"white",code:37},{name:"bright-black",code:90},{name:"bright-red",code:91},{name:"bright-green",code:92},{name:"bright-yellow",code:93},{name:"bright-blue",code:94},{name:"bright-magenta",code:95},{name:"bright-cyan",code:96},{name:"bright-white",code:97}],i=new Map;function l(n){return n.replace(e(),"")}function d(e){null==s&&(s=new m);return s.parse(e).map((e=>{if(0===e.styles.length)return e.text;const n=e.styles.map((e=>`ansi-${e}`)).join(" ");return t`<span class=${n}>${e.text}</span>`}))}a.forEach((e=>{i.set(e.name,{...e,type:"effect"})})),r.forEach((e=>{const n=`text-${e.name}`,o=`bg-${e.name}`,t=e.code,c=e.code+10;i.set(n,{name:n,code:t,escapes:[39],type:"color"}),i.set(o,{name:o,code:c,escapes:[49],type:"color"})}));const h=[n`.ansi-reset{background-color:var(--cc-color-ansi-background);color:var(--cc-color-ansi-foreground);font-style:normal;font-weight:400;opacity:1;text-decoration:none}.ansi-inverse{background-color:var(--cc-color-ansi-foreground);color:var(--cc-color-ansi-background)}`,...[...a.map((e=>null!=e.style?`.ansi-${e.name} {${e.style};}`:null)).filter((e=>null!=e)),...r.map((e=>{const n=e.name,o=`var(--cc-color-ansi-${n})`;return`\n          .ansi-text-${n} {\n            color: ${o};\n          }\n          .ansi-text-${n}.ansi-inverse {\n            background-color: ${o} !important;\n          }\n          .ansi-bg-${n} {\n            background-color: ${o};\n          }\n          .ansi-bg-${n}.ansi-inverse {\n            color: ${o} !important;\n          }`}))].map(o)];class m{constructor(){this.codeToStyle=new Map,this.escapeCodes=new Map,this.cache=new c((e=>this._doParse(e)),1e3),this._init()}_init(){const e=new Map,n=(n,o,t)=>{const c=u(o);this.codeToStyle.set(c,n),t.forEach((o=>{const t=u(o);p(this.escapeCodes,t,n),p(e,t,c)})),p(this.escapeCodes,u(""),n),p(this.escapeCodes,u(0),n)};i.forEach((e=>{n(e.name,e.code,e.escapes)}));for(const n of e.values())n.forEach((e=>{n.forEach((n=>{e!==n&&p(this.escapeCodes,e,this.codeToStyle.get(n))}))}))}parse(e){return this.cache.get(e)}_doParse(n){const o=[];let t=n;const c=[];let s=e().exec(t);for(;null!=s;){s.index>0&&o.push({styles:c.slice(0),text:t.substring(0,s.index)});(a=s[0],a.slice(2,a.length-1)).split(";").map((e=>u(e))).forEach((e=>{this.escapeCodes.get(e)?.forEach((e=>{g(c,e)})),this.codeToStyle.has(e)&&c.push(this.codeToStyle.get(e))})),t=t.substring(s.index+s[0].length),s=e().exec(t)}var a;return t.length>0&&o.push({styles:c,text:t}),o}}function p(e,n,o){e.has(n)||e.set(n,new Set),e.get(n).add(o)}function g(e,n){const o=e.indexOf(n);o>=0&&e.splice(o,1)}function u(e){return`[${e}m`}export{h as ansiStyles,d as ansiToLit,l as stripAnsi};
//# sourceMappingURL=ansi.js.map
