@remotex-labs/xansi
Version:
A lightweight ANSI utility library for styling terminal output
3 lines (2 loc) • 2.5 kB
JavaScript
var c={dim:[2,22],bold:[1,22],reset:[0,0],hidden:[8,28],inverse:[7,27]},d={red:[31,39],gray:[90,39],blue:[34,39],cyan:[36,39],black:[30,39],white:[37,39],green:[32,39],yellow:[33,39],magenta:[35,39],redBright:[91,39],blueBright:[94,39],cyanBright:[96,39],whiteBright:[97,39],greenBright:[92,39],blackBright:[90,39],yellowBright:[93,39],magentaBright:[95,39],darkGray:["38;5;238",39],lightGray:["38;5;252",39],lightCoral:["38;5;203",39],oliveGreen:["38;5;149",39],deepOrange:["38;5;166",39],brightPink:["38;5;197",39],lightOrange:["38;5;215",39],burntOrange:["38;5;208",39],lightYellow:["38;5;230",39],canaryYellow:["38;5;227",39],lightGoldenrodYellow:["38;5;221",39]},f={bgRed:[41,49],bgBlue:[44,49],bgCyan:[46,49],bgGray:[100,49],bgBlack:[40,49],bgGreen:[42,49],bgWhite:[47,49],bgYellow:[43,49],bgMagenta:[45,49],bgRedBright:[101,49],bgBlueBright:[104,49],bgCyanBright:[106,49],bgBlackBright:[100,49],bgWhiteBright:[107,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgMagentaBright:[105,49]};var h={...c,...d,...f},g="\x1B[",a="m";function m(t,r){let o=t.length;if(o===0)return r;if(o===1)return`${g}${t[0][0]}${a}${r}${g}${t[0][1]}${a}`;let e=new Array(o),n=new Array(o);for(let i=0;i<o;i++)n[i]=`${g}${t[i][0]}${a}`,e[o-i-1]=`${g}${t[i][1]}${a}`;return n.concat(r,e).join("")}function l(t,r,o,e){if(typeof r!="number"||typeof o!="number"||typeof e!="number")throw new Error(`RGB values must be numbers, received: r=${typeof r}, g=${typeof o}, b=${typeof e}`);let n=t==="fg"?38:48,i=t==="fg"?39:49;return[`${n};2;${r};${o};${e}`,i]}function p(t){let r=t.replace(/^#/,"").toLowerCase();if(!/^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(r))throw new Error(`Invalid hex color format: "${t}". Expected 3 or 6 hex digits.`);if(r.length===3){let i=parseInt(r[0]+r[0],16),b=parseInt(r[1]+r[1],16),y=parseInt(r[2]+r[2],16);return[i,b,y]}let o=parseInt(r.slice(0,2),16),e=parseInt(r.slice(2,4),16),n=parseInt(r.slice(4,6),16);return[o,e,n]}function s(t=[]){let r=(...e)=>{if(Array.isArray(e[0])&&"raw"in e[0]){let[n,...i]=e,b=n.reduce((y,C,u)=>y+C+(u<i.length?String(i[u]??""):""),"");return m(t,b)}return m(t,e.join(""))},o={rgb:(e,n,i)=>s([...t,l("fg",e,n,i)]),bgRgb:(e,n,i)=>s([...t,l("bg",e,n,i)]),hex:e=>s([...t,l("fg",...p(e))]),bgHex:e=>s([...t,l("bg",...p(e))])};return new Proxy(r,{get(e,n){if(typeof n!="string")throw new Error(`Invalid property: ${String(n)}`);return n in h?s([...t,h[n]]):n in o?o[n]:Reflect.get(e,n)}})}var $=s();export{$ as xterm};
//# sourceMappingURL=xterm.component.js.map