@remotex-labs/xansi
Version:
A lightweight ANSI utility library for styling terminal output
3 lines (2 loc) • 2.98 kB
JavaScript
;var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var i in e)u(r,i,{get:e[i],enumerable:!0})},S=(r,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of $(e))!T.call(r,t)&&t!==i&&u(r,t,{get:()=>e[t],enumerable:!(n=w(e,t))||n.enumerable});return r};var k=r=>S(u({},"__esModule",{value:!0}),r);var v={};A(v,{xterm:()=>x});module.exports=k(v);var d={dim:[2,22],bold:[1,22],reset:[0,0],hidden:[8,28],inverse:[7,27]},f={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]},h={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 m={...d,...f,...h},g="\x1B[",a="m";function p(r,e){let i=r.length;if(i===0)return e;if(i===1)return`${g}${r[0][0]}${a}${e}${g}${r[0][1]}${a}`;let n=new Array(i),t=new Array(i);for(let o=0;o<i;o++)t[o]=`${g}${r[o][0]}${a}`,n[i-o-1]=`${g}${r[o][1]}${a}`;return t.concat(e,n).join("")}function l(r,e,i,n){if(typeof e!="number"||typeof i!="number"||typeof n!="number")throw new Error(`RGB values must be numbers, received: r=${typeof e}, g=${typeof i}, b=${typeof n}`);let t=r==="fg"?38:48,o=r==="fg"?39:49;return[`${t};2;${e};${i};${n}`,o]}function C(r){let e=r.replace(/^#/,"").toLowerCase();if(!/^([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(e))throw new Error(`Invalid hex color format: "${r}". Expected 3 or 6 hex digits.`);if(e.length===3){let o=parseInt(e[0]+e[0],16),b=parseInt(e[1]+e[1],16),y=parseInt(e[2]+e[2],16);return[o,b,y]}let i=parseInt(e.slice(0,2),16),n=parseInt(e.slice(2,4),16),t=parseInt(e.slice(4,6),16);return[i,n,t]}function s(r=[]){let e=(...n)=>{if(Array.isArray(n[0])&&"raw"in n[0]){let[t,...o]=n,b=t.reduce((y,B,c)=>y+B+(c<o.length?String(o[c]??""):""),"");return p(r,b)}return p(r,n.join(""))},i={rgb:(n,t,o)=>s([...r,l("fg",n,t,o)]),bgRgb:(n,t,o)=>s([...r,l("bg",n,t,o)]),hex:n=>s([...r,l("fg",...C(n))]),bgHex:n=>s([...r,l("bg",...C(n))])};return new Proxy(e,{get(n,t){if(typeof t!="string")throw new Error(`Invalid property: ${String(t)}`);return t in m?s([...r,m[t]]):t in i?i[t]:Reflect.get(n,t)}})}var x=s();0&&(module.exports={xterm});
//# sourceMappingURL=xterm.component.js.map