termark 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,115 @@
1
+ //#region src/__internal/styling.d.ts
2
+ /**
3
+ * Built-in styles.
4
+ */
5
+ declare const BUILT_INS: {
6
+ readonly reset: readonly [0, 0];
7
+ readonly bold: readonly [1, 22];
8
+ readonly dim: readonly [2, 22];
9
+ readonly italic: readonly [3, 23];
10
+ readonly underline: readonly [4, 24];
11
+ readonly blink: readonly [5, 25];
12
+ readonly inverse: readonly [7, 27];
13
+ readonly overline: readonly [53, 55];
14
+ readonly hidden: readonly [8, 28];
15
+ readonly strike: readonly [9, 29];
16
+ readonly black: readonly [30, 39];
17
+ readonly red: readonly [31, 39];
18
+ readonly green: readonly [32, 39];
19
+ readonly yellow: readonly [33, 39];
20
+ readonly blue: readonly [34, 39];
21
+ readonly magenta: readonly [35, 39];
22
+ readonly cyan: readonly [36, 39];
23
+ readonly white: readonly [37, 39];
24
+ readonly bgBlack: readonly [40, 49];
25
+ readonly bgRed: readonly [41, 49];
26
+ readonly bgGreen: readonly [42, 49];
27
+ readonly bgYellow: readonly [43, 49];
28
+ readonly bgBlue: readonly [44, 49];
29
+ readonly bgMagenta: readonly [45, 49];
30
+ readonly bgCyan: readonly [46, 49];
31
+ readonly bgWhite: readonly [47, 49];
32
+ readonly brightBlack: readonly [90, 39];
33
+ readonly grey: readonly [90, 39];
34
+ readonly gray: readonly [90, 39];
35
+ readonly brightRed: readonly [91, 39];
36
+ readonly brightGreen: readonly [92, 39];
37
+ readonly brightYellow: readonly [93, 39];
38
+ readonly brightBlue: readonly [94, 39];
39
+ readonly brightMagenta: readonly [95, 39];
40
+ readonly brightCyan: readonly [96, 39];
41
+ readonly brightWhite: readonly [97, 39];
42
+ readonly bgBrightBlack: readonly [100, 49];
43
+ readonly bgGrey: readonly [100, 49];
44
+ readonly bgGray: readonly [100, 49];
45
+ readonly bgBrightRed: readonly [101, 49];
46
+ readonly bgBrightGreen: readonly [102, 49];
47
+ readonly bgBrightYellow: readonly [103, 49];
48
+ readonly bgBrightBlue: readonly [104, 49];
49
+ readonly bgBrightMagenta: readonly [105, 49];
50
+ readonly bgBrightCyan: readonly [106, 49];
51
+ readonly bgBrightWhite: readonly [107, 49];
52
+ };
53
+ /**
54
+ * Styles for the borders of {@linkcode box}.
55
+ */
56
+ declare const BOX_BORDERS: {
57
+ readonly sharp: {
58
+ readonly tl: "┌";
59
+ readonly tr: "┐";
60
+ readonly bl: "└";
61
+ readonly br: "┘";
62
+ readonly h: "─";
63
+ readonly v: "│";
64
+ };
65
+ readonly rounded: {
66
+ readonly tl: "╭";
67
+ readonly tr: "╮";
68
+ readonly bl: "╰";
69
+ readonly br: "╯";
70
+ readonly h: "─";
71
+ readonly v: "│";
72
+ };
73
+ readonly double: {
74
+ readonly tl: "╔";
75
+ readonly tr: "╗";
76
+ readonly bl: "╚";
77
+ readonly br: "╝";
78
+ readonly h: "═";
79
+ readonly v: "║";
80
+ };
81
+ readonly heavy: {
82
+ readonly tl: "┏";
83
+ readonly tr: "┓";
84
+ readonly bl: "┗";
85
+ readonly br: "┛";
86
+ readonly h: "━";
87
+ readonly v: "┃";
88
+ };
89
+ readonly dashed: {
90
+ readonly tl: "┌";
91
+ readonly tr: "┐";
92
+ readonly bl: "└";
93
+ readonly br: "┘";
94
+ readonly h: "⹀";
95
+ readonly v: "╎";
96
+ };
97
+ readonly dotted: {
98
+ readonly tl: "┌";
99
+ readonly tr: "┐";
100
+ readonly bl: "└";
101
+ readonly br: "┘";
102
+ readonly h: "╌";
103
+ readonly v: "┊";
104
+ };
105
+ readonly ascii: {
106
+ readonly tl: "+";
107
+ readonly tr: "+";
108
+ readonly bl: "+";
109
+ readonly br: "+";
110
+ readonly h: "-";
111
+ readonly v: "|";
112
+ };
113
+ };
114
+ //#endregion
115
+ export { BOX_BORDERS, BUILT_INS };
@@ -0,0 +1 @@
1
+ import{formatForNesting as e,toFormatter as t}from"./format.mjs";import{getColourLevel as n,hasNoColour as r}from"./env.mjs";import{clamp as i,hexColourRegex as a,interpolate as o}from"./util.mjs";import{ansi256To4bit as s,hexToRgb as c,rgbToAnsi256 as l}from"./conversion.mjs";const u={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],overline:[53,55],hidden:[8,28],strike:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],brightBlack:[90,39],grey:[90,39],gray:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBrightBlack:[100,49],bgGrey:[100,49],bgGray:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49]},d={sharp:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},heavy:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},dashed:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`⹀`,v:`╎`},dotted:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`╌`,v:`┊`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`,h:`-`,v:`|`}};function f(e,r){let i;if(n()===3){let n=e.join(`;`);i=t(r===`fg`?`38;2;${n}`:`48;2;${n}`)}else if(n()===2){let n=l(e);i=t(r===`fg`?`38;5;${n}`:`48;5;${n}`)}else{let n=s(l(e));i=t(r===`fg`?n:n+10)}return i}function p(a,o){if(r()||n()===0)return e=>e;let s=f(a.map(e=>i(e,0,255)),o),c=t(o===`fg`?39:49);return t=>e(t,s,c)}function m(e,t){return a.test(e)?p(c(e),t):e=>e}function h(e,i){return r()||n()===0||e.length===0?e=>e:e.length===1?e.every(e=>typeof e==`string`)?m(e[0],i):p(e[0],i):n=>{let r=e.every(e=>typeof e==`string`)?e.map(e=>c(e)):e,a=r.length,s=Math.min(n.length/(a-1)),l=``,u=t(i===`fg`?39:49);for(let e=0;e<n.length;e++){let t=Math.min(Math.floor(e/s),a-2),c=e%s/s,d=r[t],p=r[t+1],[m,h,g]=o(d,p,c),_=f([m,h,g],i);l+=`${_}${n[e]}${u}`}return l}}function g(a,o){if(r()||n()===0)return e=>e;let c=i(a,0,255),l;if(n()>=2)l=t(o===`fg`?`38;5;${c}`:`48;5;${c}`);else{let e=s(c);l=t(o===`fg`?e:e+10)}let u=t(o===`fg`?39:49);return t=>e(t,l,u)}export{g as $ansi256,h as $gradient,m as $hex,p as $rgb,d as BOX_BORDERS,u as BUILT_INS};
@@ -0,0 +1 @@
1
+ const e=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function t(e,t,n){return Math.min(Math.max(e,t),n)}function n(e,t,n){return[Math.round(e[0]+n*(t[0]-e[0])),Math.round(e[1]+n*(t[1]-e[1])),Math.round(e[2]+n*(t[2]-e[2]))]}exports.clamp=t,exports.hexColourRegex=e,exports.interpolate=n;
@@ -0,0 +1 @@
1
+ const e=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function t(e,t,n){return Math.min(Math.max(e,t),n)}function n(e,t,n){return[Math.round(e[0]+n*(t[0]-e[0])),Math.round(e[1]+n*(t[1]-e[1])),Math.round(e[2]+n*(t[2]-e[2]))]}export{t as clamp,e as hexColourRegex,n as interpolate};
package/dist/index.cjs CHANGED
@@ -1 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=()=>!process.env.NO_COLOR,r=()=>{const e=process.env.COLORTERM;return{is16bit:!!e&&(e.includes("ansi")&&!e.includes("256")),is256:!!e&&e.includes("ansi256"),isTrueColor:!!e&&(e.includes("truecolor")||e.includes("24bit"))}};function t(r,t,i){if("color"===i&&!e())return e=>e.toString();const o=`[${r}m`,s=`[${t}m`;return e=>{const r=e.toString().trim();return-1===r.indexOf(s)?`${o}${r}${s}`:`${o}${r.replaceAll(s,s+o)}${s}`}}function i(e,r,t){return[Math.round(e[0]+t*(r[0]-e[0])),Math.round(e[1]+t*(r[1]-e[1])),Math.round(e[2]+t*(r[2]-e[2]))]}function o(e,r,t){if("number"!=typeof e)throw new TypeError(`Parameter ${JSON.stringify(e)} must be a finite number, which it currently isn't!`);return Math.min(Math.max(e,r),t)}class s{constructor(){this.areColorsEnabled=e(),this.is8bitEnabled=r().is256,this.is24bitEnabled=r().isTrueColor,this.reset=t(0,0,"format"),this.bold=t(1,22,"format"),this.dim=t(2,22,"format"),this.italic=t(3,23,"format"),this.underline=t(4,24,"format"),this.blink=t(5,25,"format"),this.inverse=t(7,27,"format"),this.overline=t(53,55,"format"),this.hidden=t(8,28,"format"),this.strike=t(9,29,"format"),this.black=t(30,39,"color"),this.red=t(31,39,"color"),this.green=t(32,39,"color"),this.yellow=t(33,39,"color"),this.blue=t(34,39,"color"),this.magenta=t(35,39,"color"),this.cyan=t(36,39,"color"),this.white=t(37,39,"color"),this.blackBright=t(90,39,"color"),this.redBright=t(91,39,"color"),this.greenBright=t(92,39,"color"),this.yellowBright=t(93,39,"color"),this.blueBright=t(94,39,"color"),this.magentaBright=t(95,39,"color"),this.cyanBright=t(96,39,"color"),this.whiteBright=t(97,39,"color"),this.bgBlack=t(40,49,"color"),this.bgRed=t(41,49,"color"),this.bgGreen=t(42,49,"color"),this.bgYellow=t(43,49,"color"),this.bgBlue=t(44,49,"color"),this.bgMagenta=t(45,49,"color"),this.bgCyan=t(46,49,"color"),this.bgWhite=t(47,49,"color"),this.bgBlackBright=t(100,49,"color"),this.bgRedBright=t(101,49,"color"),this.bgGreenBright=t(102,49,"color"),this.bgYellowBright=t(103,49,"color"),this.bgBlueBright=t(104,49,"color"),this.bgMagentaBright=t(105,49,"color"),this.bgCyanBright=t(106,49,"color"),this.bgWhiteBright=t(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(i,s){if(!r().is256||!e())return e=>e.toString();s=o(s,0,255);return t("text"===i?`38;5;${s}`:`48;5;${s}`,"text"===i?39:49,"color")}rgb(e,...i){if(!r().isTrueColor)return e=>e.toString();let s,n,l;Array.isArray(i[0])?(s=o(i[0][0],0,255),n=o(i[0][1],0,255),l=o(i[0][2],0,255)):(s=o(i[0],0,255),n=o(i[1],0,255),l=o(i[2],0,255));return t("text"===e?`38;2;${s};${n};${l}`:`48;2;${s};${n};${l}`,"text"===e?39:49,"color")}gradient(t,o){if(!e()||!r().isTrueColor)return e=>e.toString();const s="text"===t?"[38;2;":"[48;2;",n="text"===t?"":"";return e=>{const r=e.toString().trim(),t=o.length,l=Math.min(r.length/(t-1));let g="";for(let e=0;e<r.length;e++){const c=Math.min(Math.floor(e/l),t-2),a=e%l/l,h=i(o[c],o[c+1],a);g+=`${s}${h[0]};${h[1]};${h[2]}m${r[e]}${n}`}return g}}success(e,r=""){console.info(`${s.successPrefix} ${r}${s.init.green(e)}`)}info(e,r=""){console.info(`${s.infoPrefix} ${r}${s.init.blue(e)}`)}warn(e,r=""){console.warn(`${s.warnPrefix} ${r}${s.init.yellow(e)}`)}error(e,r=""){console.error(`${s.errorPrefix} ${r}${s.init.red(e)}`)}custom(e,r,i){return t(e,r,"asColor"===i?"color":"format")}static createTheme(...e){const r=[];return e.forEach(e=>r.push(e)),e=>{const t=e.toString();return r.reduce((e,r)=>r(e),t)}}static createLogger(e){var r,t,i,o,n,l,g,c;const a=void 0===(null===(r=e.success)||void 0===r?void 0:r.prefix)||""===e.success.prefix?s.successPrefix:!1===e.success.prefix?"":e.success.prefix,h=void 0===(null===(t=e.info)||void 0===t?void 0:t.prefix)||""===e.info.prefix?s.infoPrefix:!1===e.info.prefix?"":e.info.prefix,b=void 0===(null===(i=e.warn)||void 0===i?void 0:i.prefix)||""===e.warn.prefix?s.warnPrefix:!1===e.warn.prefix?"":e.warn.prefix,x=void 0===(null===(o=e.error)||void 0===o?void 0:o.prefix)||""===e.error.prefix?s.errorPrefix:!1===e.error.prefix?"":e.error.prefix,u=s.createTheme(...e.default),d=s.createTheme(...void 0!==(null===(n=e.success)||void 0===n?void 0:n.styles)&&0!==e.success.styles.length?e.success.styles:[s.init.green]),p=s.createTheme(...void 0!==(null===(l=e.info)||void 0===l?void 0:l.styles)&&0!==e.info.styles.length?e.info.styles:[s.init.blue]),f=s.createTheme(...void 0!==(null===(g=e.warn)||void 0===g?void 0:g.styles)&&0!==e.warn.styles.length?e.warn.styles:[s.init.yellow]),B=s.createTheme(...void 0!==(null===(c=e.error)||void 0===c?void 0:c.styles)&&0!==e.error.styles.length?e.error.styles:[s.init.red]);return{log(e,r=""){console.log(`${r}${u(e)}`)},success(e,r=""){console.info(`${a?a+" ":""}${r}${d(e)}`)},info(e,r=""){console.info(`${h?h+" ":""}${r}${p(e)}`)},warn(e,r=""){console.info(`${b?b+" ":""}${r}${f(e)}`)},error(e,r=""){console.info(`${x?x+" ":""}${r}${B(e)}`)}}}}s.termarkInstance=s,s.successPrefix=s.init.green(s.init.bold("[✓]")),s.infoPrefix=s.init.blue(s.init.bold("[i]")),s.warnPrefix=s.init.yellow(s.init.bold("[!]")),s.errorPrefix=s.init.red(s.init.bold("[X]"));const n=s.init,{areColorsEnabled:l,is8bitEnabled:g,is24bitEnabled:c,reset:a,bold:h,dim:b,italic:x,underline:u,blink:d,inverse:p,overline:f,hidden:B,strike:m,black:$,red:w,green:y,yellow:v,blue:k,magenta:C,cyan:M,white:T,blackBright:P,redBright:E,greenBright:R,yellowBright:O,blueBright:S,magentaBright:G,cyanBright:W,whiteBright:Y,bgBlack:L,bgRed:A,bgGreen:_,bgYellow:I,bgBlue:N,bgMagenta:j,bgCyan:J,bgWhite:X,bgBlackBright:q,bgRedBright:z,bgGreenBright:D,bgYellowBright:F,bgBlueBright:H,bgMagentaBright:K,bgCyanBright:Q,bgWhiteBright:U,ansi256:V,rgb:Z,gradient:ee,success:re,info:te,warn:ie,error:oe,custom:se}=n,{createTheme:ne,createLogger:le}=s;exports.Termark=s,exports.ansi256=V,exports.areColorsEnabled=l,exports.bgBlack=L,exports.bgBlackBright=q,exports.bgBlue=N,exports.bgBlueBright=H,exports.bgCyan=J,exports.bgCyanBright=Q,exports.bgGreen=_,exports.bgGreenBright=D,exports.bgMagenta=j,exports.bgMagentaBright=K,exports.bgRed=A,exports.bgRedBright=z,exports.bgWhite=X,exports.bgWhiteBright=U,exports.bgYellow=I,exports.bgYellowBright=F,exports.black=$,exports.blackBright=P,exports.blink=d,exports.blue=k,exports.blueBright=S,exports.bold=h,exports.createLogger=le,exports.createTheme=ne,exports.custom=se,exports.cyan=M,exports.cyanBright=W,exports.default=n,exports.dim=b,exports.error=oe,exports.gradient=ee,exports.green=y,exports.greenBright=R,exports.hidden=B,exports.info=te,exports.inverse=p,exports.is24bitEnabled=c,exports.is8bitEnabled=g,exports.italic=x,exports.magenta=C,exports.magentaBright=G,exports.overline=f,exports.red=w,exports.redBright=E,exports.reset=a,exports.rgb=Z,exports.strike=m,exports.success=re,exports.underline=u,exports.warn=ie,exports.white=T,exports.whiteBright=Y,exports.yellow=v,exports.yellowBright=O;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./__internal/env.cjs`),t=require(`./__internal/styling.cjs`),n=require(`./__internal/impl.cjs`),r=require(`./utilities.cjs`),i=n.createProxy(new n.TermarkImpl);function a(...e){let t={};for(let n of e)Object.assign(t,n(i));return n.createProxy(new n.TermarkImpl,t)}function o(e,n={}){let{kind:i=`sharp`,style:a=e=>e,padding:o=1,margin:s=0}=n,c=t.BOX_BORDERS[i],l=Math.floor(o/4),u=Math.floor(s/4),d=e.split(`
2
+ `),f=d.map(e=>r.stripAnsi(e).length),p=Math.max(...f),m=c.tl+c.h.repeat(p+o*2)+c.tr,h=c.bl+c.h.repeat(p+o*2)+c.br,g=` `.repeat(s),_=`
3
+ `.repeat(u),v=g+a(m)+g,y=g+a(h)+g,b=g+a(c.v),x=a(c.v)+g;return`${_}${v}\n${d.map(e=>{let t=r.stripAnsi(e),n=e+` `.repeat(p-t.length),i=b+` `.repeat(o*2+t.length)+x,a=l===0?``:`${i}\n`.repeat(l),s=l===0?``:`\n${i}`.repeat(l),c=` `.repeat(o);return`${a}${b}${c}${n}${c}${x}${s}`}).join(`
4
+ `)}\n${y}${_}`}function s(e,t){let n={};for(let t in e){let r=e[t];n[t]=i.hex(r)}if(t)for(let t in e){let r=e[t],a=`bg${t.slice(0,1).toUpperCase()}${t.slice(1)}`;n[a]=i.hex(r)}return a(()=>({...n}))}exports.ansiLowerCase=r.ansiLowerCase,exports.ansiUpperCase=r.ansiUpperCase,exports.areColoursSupported=r.areColoursSupported,exports.box=o,exports.extend=a,exports.fmt=i,exports.fromColObject=s,exports.getColourLevel=e.getColourLevel,exports.hasNoColour=e.hasNoColour,exports.stripAnsi=r.stripAnsi,exports.supports=r.supports,exports.supportsAtMost=r.supportsAtMost,exports.transformPreserveAnsi=r.transformPreserveAnsi;
@@ -0,0 +1 @@
1
+ export type * from './index.d.mts'
@@ -0,0 +1,161 @@
1
+ import { ANSICode, BoxOptions, BuiltIn, ColourLevel, ColourObject, FromColObjectReturn, LinkFn, MiscellaneousFns, ParamStyling, RGB, StyleElement, StyleFn, TermarkAPI, TermarkToJSONReturn, Terminator } from "./types.mjs";
2
+ import { getColourLevel, hasNoColour } from "./__internal/env.mjs";
3
+ import { ansiLowerCase, ansiUpperCase, areColoursSupported, stripAnsi, supports, supportsAtMost, transformPreserveAnsi } from "./utilities.mjs";
4
+
5
+ //#region src/index.d.ts
6
+ /**
7
+ * Style some text for terminal output.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { fmt } from "termark";
12
+ *
13
+ * const styled = fmt.bold.green.italic("Text");
14
+ *
15
+ * console.log(styled);
16
+ * // => "Text" printed in bold, green (if colours are supported/enabled), and italic.
17
+ * ```
18
+ *
19
+ * Each member of the chain can be called by passing a string, or can be accessed to apply further styling.
20
+ * Use `.text()` to finally terminate the styling.
21
+ *
22
+ * @example Terminating the chain with `.text()`
23
+ * ```ts
24
+ * import { fmt } from "termark";
25
+ *
26
+ * const styled = fmt.underline.bgBlue.black.text("Text");
27
+ *
28
+ * console.log(styled);
29
+ * // => "Text" printed in black with a blue background (for both: if colours are supported/enabled) and underlined.
30
+ * ```
31
+ *
32
+ * `.text()` is primarily for methods such as `hex`, `rgb`, or `gradient`, that would be inconvenient to use without it.
33
+ *
34
+ * @example `.text()` on `hex` vs. not using `.text()`
35
+ * ```ts
36
+ * import { fmt } from "termark";
37
+ *
38
+ * const custom = fmt.hex("#ffa500").text("orange");
39
+ *
40
+ * // Not using `.text()` is also possible, but less elegant:
41
+ *
42
+ * const withoutTextCall = fmt.hex("#80b3ff")("Text");
43
+ * ```
44
+ */
45
+ declare const fmt: TermarkAPI;
46
+ /**
47
+ * Extend the functionality of Termark with custom methods.
48
+ *
49
+ * > **Note:** Methods created this way can be called as the last item in the chain only.
50
+ *
51
+ * @example Creating a `shout` method
52
+ * ```ts
53
+ * import { extend, ansiUpperCase } from "termark";
54
+ *
55
+ * const myLib = extend((base) => ({
56
+ * shout: (str) => base.bold.red(ansiUpperCase(str)),
57
+ * }));
58
+ *
59
+ * console.log(
60
+ * myLib.shout("this text is red, bold, and uppercase!"),
61
+ * myLib.italic.shout("works in the chain, too!")
62
+ * );
63
+ * ```
64
+ *
65
+ * > **Note:** Methods that transform text instead of merely style it need to use {@linkcode transformAnsi} or a
66
+ * function derived from it to work with nesting properly.
67
+ *
68
+ * @example Creating a custom colour method
69
+ * ```ts
70
+ * import { extend } from "termark";
71
+ *
72
+ * const myLib = extend((base) => ({
73
+ * orange: (str) => base.hex("#ffa500").text(str),
74
+ * }));
75
+ *
76
+ * console.log(
77
+ * myLib.orange("This is orange text"),
78
+ * myLib.bold.italic.orange("Bold, italic and orange text")
79
+ * );
80
+ * ```
81
+ *
82
+ * @param factories An array of functions returning custom methods that can be accessed from the return-value of
83
+ * `extend`.
84
+ */
85
+ declare function extend<M extends Record<string, StyleFn>>(...factories: ((base: TermarkAPI) => M)[]): TermarkAPI<M>;
86
+ /**
87
+ * Create a box around some text.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { box } from "termark";
92
+ *
93
+ * const boxed = box("This text will be in a box")
94
+ *
95
+ * console.log(boxed);
96
+ *
97
+ * // Returned:
98
+ * // ┌────────────────────────────┐
99
+ * // │ This text will be in a box │
100
+ * // └────────────────────────────┘
101
+ * ```
102
+ *
103
+ * @param text The text within the box.
104
+ * @param options Configuration options.
105
+ */
106
+ declare function box(text: string, options?: BoxOptions): string;
107
+ /**
108
+ * Generate colour-styling from an object literal. This primarily exists for use with
109
+ * [`css-color-names`](https://github.com/bahamas10/css-color-names).
110
+ *
111
+ * Because this function uses {@linkcode extend} under the hood, colour methods created this way must be called as the
112
+ * last one in the chain.
113
+ *
114
+ * @example Using `css-color-names`
115
+ * ```ts
116
+ * import cssColours from "css-color-names";
117
+ * import { fromColObject } from "termark";
118
+ *
119
+ * const css = fromColObject(cssColours);
120
+ *
121
+ * console.log(
122
+ * css.lemonchiffron("This text uses a CSS colour!"),
123
+ * css.bold.aliceblue("Works with other styles")
124
+ * );
125
+ * ```
126
+ *
127
+ * @example Enabling background colours
128
+ * ```ts
129
+ * import cssColours from "css-color-names";
130
+ * import { fromColObject } from "termark";
131
+ *
132
+ * const cssWithBg = fromColObject(cssColours, true);
133
+ * ```
134
+ *
135
+ * @example Using [`color-names`](https://github.com/meodai/color-names)
136
+ * ```ts
137
+ * import { colornames } from "color-name-list";
138
+ * import { fromColObject } from "termark";
139
+ *
140
+ * const mapped = colornames.reduce((acc, { name, hex }) => {
141
+ * acc[name] = hex;
142
+ * return acc;
143
+ * }, {});
144
+ *
145
+ * const colours = fromColObject(mapped);
146
+ *
147
+ * console.log(
148
+ * colours["100 Mph"]("This colour is from color-names"),
149
+ * colours.italic.Alaska("...")
150
+ * );
151
+ * ```
152
+ *
153
+ * @param obj An object whose keys are colour names (which will be used as the method name) and whose values are
154
+ * hex colour codes.
155
+ * @param generateBg Whether to generate background styling for all supplied colours. These will have the format
156
+ * `bgColourName` where `ColourName` is the original name of the colour, capitalized. This name is not formatted,
157
+ * so a name like `100 Mph` will retain its spaces.
158
+ */
159
+ declare function fromColObject<R extends ColourObject, GenBg extends boolean | undefined = undefined>(obj: R, generateBg?: GenBg): TermarkAPI<FromColObjectReturn<R, GenBg>>;
160
+ //#endregion
161
+ export { ANSICode, BoxOptions, BuiltIn, ColourLevel, ColourObject, FromColObjectReturn, LinkFn, MiscellaneousFns, ParamStyling, RGB, StyleElement, StyleFn, TermarkAPI, TermarkToJSONReturn, Terminator, ansiLowerCase, ansiUpperCase, areColoursSupported, box, extend, fmt, fromColObject, getColourLevel, hasNoColour, stripAnsi, supports, supportsAtMost, transformPreserveAnsi };
package/dist/index.mjs CHANGED
@@ -1 +1,4 @@
1
- const r=()=>!process.env.NO_COLOR,e=()=>{const r=process.env.COLORTERM;return{is16bit:!!r&&(r.includes("ansi")&&!r.includes("256")),is256:!!r&&r.includes("ansi256"),isTrueColor:!!r&&(r.includes("truecolor")||r.includes("24bit"))}};function i(e,i,t){if("color"===t&&!r())return r=>r.toString();const o=`[${e}m`,n=`[${i}m`;return r=>{const e=r.toString().trim();return-1===e.indexOf(n)?`${o}${e}${n}`:`${o}${e.replaceAll(n,n+o)}${n}`}}function t(r,e,i){return[Math.round(r[0]+i*(e[0]-r[0])),Math.round(r[1]+i*(e[1]-r[1])),Math.round(r[2]+i*(e[2]-r[2]))]}function o(r,e,i){if("number"!=typeof r)throw new TypeError(`Parameter ${JSON.stringify(r)} must be a finite number, which it currently isn't!`);return Math.min(Math.max(r,e),i)}class n{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=e().is256,this.is24bitEnabled=e().isTrueColor,this.reset=i(0,0,"format"),this.bold=i(1,22,"format"),this.dim=i(2,22,"format"),this.italic=i(3,23,"format"),this.underline=i(4,24,"format"),this.blink=i(5,25,"format"),this.inverse=i(7,27,"format"),this.overline=i(53,55,"format"),this.hidden=i(8,28,"format"),this.strike=i(9,29,"format"),this.black=i(30,39,"color"),this.red=i(31,39,"color"),this.green=i(32,39,"color"),this.yellow=i(33,39,"color"),this.blue=i(34,39,"color"),this.magenta=i(35,39,"color"),this.cyan=i(36,39,"color"),this.white=i(37,39,"color"),this.blackBright=i(90,39,"color"),this.redBright=i(91,39,"color"),this.greenBright=i(92,39,"color"),this.yellowBright=i(93,39,"color"),this.blueBright=i(94,39,"color"),this.magentaBright=i(95,39,"color"),this.cyanBright=i(96,39,"color"),this.whiteBright=i(97,39,"color"),this.bgBlack=i(40,49,"color"),this.bgRed=i(41,49,"color"),this.bgGreen=i(42,49,"color"),this.bgYellow=i(43,49,"color"),this.bgBlue=i(44,49,"color"),this.bgMagenta=i(45,49,"color"),this.bgCyan=i(46,49,"color"),this.bgWhite=i(47,49,"color"),this.bgBlackBright=i(100,49,"color"),this.bgRedBright=i(101,49,"color"),this.bgGreenBright=i(102,49,"color"),this.bgYellowBright=i(103,49,"color"),this.bgBlueBright=i(104,49,"color"),this.bgMagentaBright=i(105,49,"color"),this.bgCyanBright=i(106,49,"color"),this.bgWhiteBright=i(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(t,n){if(!e().is256||!r())return r=>r.toString();n=o(n,0,255);return i("text"===t?`38;5;${n}`:`48;5;${n}`,"text"===t?39:49,"color")}rgb(r,...t){if(!e().isTrueColor)return r=>r.toString();let n,s,l;Array.isArray(t[0])?(n=o(t[0][0],0,255),s=o(t[0][1],0,255),l=o(t[0][2],0,255)):(n=o(t[0],0,255),s=o(t[1],0,255),l=o(t[2],0,255));return i("text"===r?`38;2;${n};${s};${l}`:`48;2;${n};${s};${l}`,"text"===r?39:49,"color")}gradient(i,o){if(!r()||!e().isTrueColor)return r=>r.toString();const n="text"===i?"[38;2;":"[48;2;",s="text"===i?"":"";return r=>{const e=r.toString().trim(),i=o.length,l=Math.min(e.length/(i-1));let c="";for(let r=0;r<e.length;r++){const h=Math.min(Math.floor(r/l),i-2),a=r%l/l,g=t(o[h],o[h+1],a);c+=`${n}${g[0]};${g[1]};${g[2]}m${e[r]}${s}`}return c}}success(r,e=""){console.info(`${n.successPrefix} ${e}${n.init.green(r)}`)}info(r,e=""){console.info(`${n.infoPrefix} ${e}${n.init.blue(r)}`)}warn(r,e=""){console.warn(`${n.warnPrefix} ${e}${n.init.yellow(r)}`)}error(r,e=""){console.error(`${n.errorPrefix} ${e}${n.init.red(r)}`)}custom(r,e,t){return i(r,e,"asColor"===t?"color":"format")}static createTheme(...r){const e=[];return r.forEach(r=>e.push(r)),r=>{const i=r.toString();return e.reduce((r,e)=>e(r),i)}}static createLogger(r){var e,i,t,o,s,l,c,h;const a=void 0===(null===(e=r.success)||void 0===e?void 0:e.prefix)||""===r.success.prefix?n.successPrefix:!1===r.success.prefix?"":r.success.prefix,g=void 0===(null===(i=r.info)||void 0===i?void 0:i.prefix)||""===r.info.prefix?n.infoPrefix:!1===r.info.prefix?"":r.info.prefix,u=void 0===(null===(t=r.warn)||void 0===t?void 0:t.prefix)||""===r.warn.prefix?n.warnPrefix:!1===r.warn.prefix?"":r.warn.prefix,f=void 0===(null===(o=r.error)||void 0===o?void 0:o.prefix)||""===r.error.prefix?n.errorPrefix:!1===r.error.prefix?"":r.error.prefix,d=n.createTheme(...r.default),b=n.createTheme(...void 0!==(null===(s=r.success)||void 0===s?void 0:s.styles)&&0!==r.success.styles.length?r.success.styles:[n.init.green]),$=n.createTheme(...void 0!==(null===(l=r.info)||void 0===l?void 0:l.styles)&&0!==r.info.styles.length?r.info.styles:[n.init.blue]),m=n.createTheme(...void 0!==(null===(c=r.warn)||void 0===c?void 0:c.styles)&&0!==r.warn.styles.length?r.warn.styles:[n.init.yellow]),B=n.createTheme(...void 0!==(null===(h=r.error)||void 0===h?void 0:h.styles)&&0!==r.error.styles.length?r.error.styles:[n.init.red]);return{log(r,e=""){console.log(`${e}${d(r)}`)},success(r,e=""){console.info(`${a?a+" ":""}${e}${b(r)}`)},info(r,e=""){console.info(`${g?g+" ":""}${e}${$(r)}`)},warn(r,e=""){console.info(`${u?u+" ":""}${e}${m(r)}`)},error(r,e=""){console.info(`${f?f+" ":""}${e}${B(r)}`)}}}}n.termarkInstance=n,n.successPrefix=n.init.green(n.init.bold("[✓]")),n.infoPrefix=n.init.blue(n.init.bold("[i]")),n.warnPrefix=n.init.yellow(n.init.bold("[!]")),n.errorPrefix=n.init.red(n.init.bold("[X]"));const s=n.init,{areColorsEnabled:l,is8bitEnabled:c,is24bitEnabled:h,reset:a,bold:g,dim:u,italic:f,underline:d,blink:b,inverse:$,overline:m,hidden:B,strike:x,black:w,red:y,green:v,yellow:p,blue:k,magenta:C,cyan:M,white:P,blackBright:T,redBright:E,greenBright:S,yellowBright:O,blueBright:R,magentaBright:G,cyanBright:L,whiteBright:W,bgBlack:Y,bgRed:A,bgGreen:I,bgYellow:N,bgBlue:J,bgMagenta:X,bgCyan:_,bgWhite:j,bgBlackBright:q,bgRedBright:z,bgGreenBright:D,bgYellowBright:F,bgBlueBright:H,bgMagentaBright:K,bgCyanBright:Q,bgWhiteBright:U,ansi256:V,rgb:Z,gradient:rr,success:er,info:ir,warn:tr,error:or,custom:nr}=s,{createTheme:sr,createLogger:lr}=n;export{n as Termark,V as ansi256,l as areColorsEnabled,Y as bgBlack,q as bgBlackBright,J as bgBlue,H as bgBlueBright,_ as bgCyan,Q as bgCyanBright,I as bgGreen,D as bgGreenBright,X as bgMagenta,K as bgMagentaBright,A as bgRed,z as bgRedBright,j as bgWhite,U as bgWhiteBright,N as bgYellow,F as bgYellowBright,w as black,T as blackBright,b as blink,k as blue,R as blueBright,g as bold,lr as createLogger,sr as createTheme,nr as custom,M as cyan,L as cyanBright,s as default,u as dim,or as error,rr as gradient,v as green,S as greenBright,B as hidden,ir as info,$ as inverse,h as is24bitEnabled,c as is8bitEnabled,f as italic,C as magenta,G as magentaBright,m as overline,y as red,E as redBright,a as reset,Z as rgb,x as strike,er as success,d as underline,tr as warn,P as white,W as whiteBright,p as yellow,O as yellowBright};
1
+ import{getColourLevel as e,hasNoColour as t}from"./__internal/env.mjs";import{BOX_BORDERS as n}from"./__internal/styling.mjs";import{TermarkImpl as r,createProxy as i}from"./__internal/impl.mjs";import{ansiLowerCase as a,ansiUpperCase as o,areColoursSupported as s,stripAnsi as c,supports as l,supportsAtMost as u,transformPreserveAnsi as d}from"./utilities.mjs";const f=i(new r);function p(...e){let t={};for(let n of e)Object.assign(t,n(f));return i(new r,t)}function m(e,t={}){let{kind:r=`sharp`,style:i=e=>e,padding:a=1,margin:o=0}=t,s=n[r],l=Math.floor(a/4),u=Math.floor(o/4),d=e.split(`
2
+ `),f=d.map(e=>c(e).length),p=Math.max(...f),m=s.tl+s.h.repeat(p+a*2)+s.tr,h=s.bl+s.h.repeat(p+a*2)+s.br,g=` `.repeat(o),_=`
3
+ `.repeat(u),v=g+i(m)+g,y=g+i(h)+g,b=g+i(s.v),x=i(s.v)+g;return`${_}${v}\n${d.map(e=>{let t=c(e),n=e+` `.repeat(p-t.length),r=b+` `.repeat(a*2+t.length)+x,i=l===0?``:`${r}\n`.repeat(l),o=l===0?``:`\n${r}`.repeat(l),s=` `.repeat(a);return`${i}${b}${s}${n}${s}${x}${o}`}).join(`
4
+ `)}\n${y}${_}`}function h(e,t){let n={};for(let t in e){let r=e[t];n[t]=f.hex(r)}if(t)for(let t in e){let r=e[t],i=`bg${t.slice(0,1).toUpperCase()}${t.slice(1)}`;n[i]=f.hex(r)}return p(()=>({...n}))}export{a as ansiLowerCase,o as ansiUpperCase,s as areColoursSupported,m as box,p as extend,f as fmt,h as fromColObject,e as getColourLevel,t as hasNoColour,c as stripAnsi,l as supports,u as supportsAtMost,d as transformPreserveAnsi};
@@ -0,0 +1,279 @@
1
+ import { BOX_BORDERS, BUILT_INS } from "./__internal/styling.mjs";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * Array with red, green, and blue colour values.
6
+ */
7
+ type RGB = [number, number, number];
8
+ /**
9
+ * A number representing the supported colour level.
10
+ *
11
+ * - `0` — No colours, just black-and-white text.
12
+ * - `1` — Basic 4-bit (16) colours.
13
+ * - `2` — 8-bit (256) colours.
14
+ * - `3` — 24-bit (16m; `truecolor`) colours.
15
+ */
16
+ type ColourLevel = 0 | 1 | 2 | 3;
17
+ /**
18
+ * How an ANSI code (e.g., the code for making text bold) can be represented.
19
+ *
20
+ * `string | number` allow single numbers such as `21`, but also complex codes like `38;5;203`, which are
21
+ * not representable by a number alone.
22
+ */
23
+ type ANSICode = string | number;
24
+ interface TermarkToJSONReturn {
25
+ text: string;
26
+ openingCodes: string[];
27
+ closingCodes: string[];
28
+ }
29
+ type StyleFn = (str: string) => string;
30
+ interface StyleElement {
31
+ open: string;
32
+ close: string;
33
+ }
34
+ /**
35
+ * Base built-in methods like `red` or `bold`.
36
+ */
37
+ type BuiltIn = keyof typeof BUILT_INS;
38
+ /**
39
+ * Methods that terminate a styling sequence.
40
+ */
41
+ interface Terminator {
42
+ /**
43
+ * Return a string that has been styled. Useful for methods like `hex` or `gradient`.
44
+ *
45
+ * @param str An input string.
46
+ */
47
+ text(str: string): string;
48
+ }
49
+ /**
50
+ * Styling functions that take parameters.
51
+ */
52
+ interface ParamStyling {
53
+ /**
54
+ * Colour some text using a hex colour code.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { fmt } from "termark";
59
+ *
60
+ * const customHex = fmt.hex("#338cd1").text("Text");
61
+ * ```
62
+ *
63
+ * @example Without leading hash (`#`)
64
+ * ```ts
65
+ * import { fmt } from "termark";
66
+ *
67
+ * const customHex = fmt.hex("008330").text("Text");
68
+ * ```
69
+ *
70
+ * @param code A hex colour code.
71
+ */
72
+ hex(code: string): TermarkAPI;
73
+ /**
74
+ * Colour some text using red, green, and blue colour values.
75
+ *
76
+ * Each passed value is clamped so that values less than `0` are treated as `0` and values greater than `255` are
77
+ * treated as `255`.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { fmt } from "termark";
82
+ *
83
+ * const rgbString = fmt.rgb([128, 5, 243]).text("Text");
84
+ * ```
85
+ *
86
+ * @param colours An array of red, green, and blue colour values.
87
+ */
88
+ rgb(colours: RGB): TermarkAPI;
89
+ /**
90
+ * Make some text have a gradient.
91
+ *
92
+ * @example With hex colour codes
93
+ * ```ts
94
+ * import { fmt } from "termark";
95
+ *
96
+ * const textWithGradient = fmt.gradient("#80b3ff", "#338cd1").text("Text");
97
+ * ```
98
+ *
99
+ * @example With RGB values
100
+ * ```ts
101
+ * import { fmt } from "termark";
102
+ *
103
+ * const textWithGradient = fmt.gradient([128, 179, 255], [51, 140, 209]).text("Text");
104
+ * ```
105
+ *
106
+ * @param colours Colours for the gradient, either as hex colour codes or as RGB tuples (arrays).
107
+ */
108
+ gradient(...colours: string[] | RGB[]): TermarkAPI;
109
+ /**
110
+ * Use an ANSI number code to apply a specific colour to some text.
111
+ *
112
+ * This value is clamped so that values less than `0` are treated as `0` while values greater than `255` are treated
113
+ * as `255`.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { fmt } from "termark";
118
+ *
119
+ * const ansi = fmt.fg(57).text("Text");
120
+ * ```
121
+ *
122
+ * @param code An ANSI code for 8-bit colours.
123
+ *
124
+ * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
125
+ */
126
+ fg(code: number): TermarkAPI;
127
+ /**
128
+ * Colour the background of some text using a hex colour code.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * import { fmt } from "termark";
133
+ *
134
+ * const customHex = fmt.bgHex("#338cd1").text("Text");
135
+ * ```
136
+ *
137
+ * @example Without leading hash (`#`)
138
+ * ```ts
139
+ * import { fmt } from "termark";
140
+ *
141
+ * const customHex = fmt.bgHex("008330").text("Text");
142
+ * ```
143
+ *
144
+ * @param code A hex colour code.
145
+ */
146
+ bgHex(code: string): TermarkAPI;
147
+ /**
148
+ * Colour the background of some text using red, green, and blue colour values.
149
+ *
150
+ * Each passed value is clamped so that values less than `0` are treated as `0` and values greater than `255` are
151
+ * treated as `255`.
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { fmt } from "termark";
156
+ *
157
+ * const rgbString = fmt.bgRgb([128, 5, 243]).text("Text");
158
+ * ```
159
+ *
160
+ * @param colours An array of red, green, and blue colour values.
161
+ */
162
+ bgRgb(colours: RGB): TermarkAPI;
163
+ /**
164
+ * Make the background of some text have a gradient.
165
+ *
166
+ * @example With hex colour codes
167
+ * ```ts
168
+ * import { fmt } from "termark";
169
+ *
170
+ * const textWithGradient = fmt.bgGradient("#80b3ff", "#338cd1").text("Text");
171
+ * ```
172
+ *
173
+ * @example With RGB values
174
+ * ```ts
175
+ * import { fmt } from "termark";
176
+ *
177
+ * const textWithGradient = fmt.bgGradient([128, 179, 255], [51, 140, 209]).text("Text");
178
+ * ```
179
+ *
180
+ * @param colours Colours for the gradient, either as hex colour codes or as RGB tuples (arrays).
181
+ */
182
+ bgGradient(...colours: string[] | RGB[]): TermarkAPI;
183
+ /**
184
+ * Use an ANSI number code to apply a specific colour to the background of some text.
185
+ *
186
+ * This value is clamped so that values less than `0` are treated as `0` while values greater than `255` are treated
187
+ * as `255`.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * import { fmt } from "termark";
192
+ *
193
+ * const ansi = fmt.bg(57).text("Text");
194
+ * ```
195
+ *
196
+ * @param code An ANSI code for 8-bit colours.
197
+ *
198
+ * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
199
+ */
200
+ bg(code: number): TermarkAPI;
201
+ }
202
+ type LinkFn = (url: string, text?: string) => string;
203
+ /**
204
+ * Miscellaneous features that don't fit other category.
205
+ */
206
+ interface MiscellaneousFns {
207
+ /**
208
+ * Construct an OSC 8 hyperlink by specifying a URL and optionally text to display.
209
+ *
210
+ * `link` acts as a style chain terminator and is called as the last element of such a chain.
211
+ *
212
+ * [OSC 8](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) may not be supported in all terminal
213
+ * environments. See ["OSC 8 adoption in terminal emulators"](https://github.com/Alhadis/OSC8-Adoption/) for a list
214
+ * of terminals that support OSC 8 hyperlinks. In terminals where OSC 8 hyperlinks aren't supported, the URL will
215
+ * be shown as-is, along with the display text (if one was provided).
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * import { fmt } from "termark";
220
+ *
221
+ * const plainLink = fmt.link("https://q-file.com");
222
+ *
223
+ * const styledLink = fmt.red.underline.link("https://q-file.com", "Website");
224
+ * ```
225
+ *
226
+ * @param url A URL to some resource, which can be a webpage (`http://`, `https://`), a local file (`file://`), an
227
+ * email address (`mailto:`), an FTP connection (`ftp://`), etc.
228
+ * @param text An optional text to display. If omitted, `url` will be displayed.
229
+ *
230
+ * @see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
231
+ * @see https://notes.billmill.org/programming/bash/Hyperlink_escape_codes.html
232
+ */
233
+ link: LinkFn;
234
+ }
235
+ /**
236
+ * The API provided by Termark, including all built-in functions as well as user-created extensions.
237
+ */
238
+ type TermarkAPI<Ext extends Record<string, any> = {}> = { [K in BuiltIn]: TermarkAPI<Ext> } & Ext & StyleFn & Terminator & ParamStyling & MiscellaneousFns;
239
+ /**
240
+ * Configuration options for {@linkcode box}.
241
+ */
242
+ interface BoxOptions {
243
+ /**
244
+ * @default "sharp"
245
+ */
246
+ kind?: keyof typeof BOX_BORDERS;
247
+ /**
248
+ * Styling to apply to the border such as making it blue.
249
+ *
250
+ * @default (str) => str
251
+ */
252
+ style?: StyleFn;
253
+ /**
254
+ * Padding to apply. Top-bottom padding will always be a quarter of left-right padding (that is, top-bottom padding
255
+ * will increase by one for every four padding units).
256
+ *
257
+ * @default 0
258
+ */
259
+ padding?: number;
260
+ /**
261
+ * Spacing around the box. Top-bottom margin will always be a quarter of left-right margin (that is, top-bottom
262
+ * margin will increase by one for every four margin units).
263
+ *
264
+ * @default 0
265
+ */
266
+ margin?: number;
267
+ }
268
+ /**
269
+ * Object type to be passed into {@linkcode fromColObject}.
270
+ *
271
+ * Represents an object literal whose keys are colour names and whose values are hex colour codes.
272
+ */
273
+ type ColourObject = Record<string, string>;
274
+ /**
275
+ * The return-value of {@linkcode fromColObject}.
276
+ */
277
+ type FromColObjectReturn<R extends ColourObject, GenBg extends boolean | undefined> = { [K in keyof R as K | (GenBg extends true ? `bg${Capitalize<K & string>}` : never)]: StyleFn };
278
+ //#endregion
279
+ export { ANSICode, BoxOptions, BuiltIn, ColourLevel, ColourObject, FromColObjectReturn, LinkFn, MiscellaneousFns, ParamStyling, RGB, StyleElement, StyleFn, TermarkAPI, TermarkToJSONReturn, Terminator };
@@ -0,0 +1 @@
1
+ const e=require(`./__internal/env.cjs`);function t(){return e.getColourLevel()!==0}function n(t){return e.getColourLevel()>=t}function r(t){return e.getColourLevel()<=t}function i(e){return t=>{let n=/(\u{001B}\[[0-9;]*[A-PRZ])|(.+?)/giu,r=``;for(let i of t.matchAll(n)){let t=i[0];r+=t.charCodeAt(0)===27?t:e(t)}return r}}const a=i(e=>e.toUpperCase()),o=i(e=>e.toLowerCase());function s(e){return e.replace(/\u{001B}\[[0-9;]*m/gu,``)}exports.ansiLowerCase=o,exports.ansiUpperCase=a,exports.areColoursSupported=t,exports.stripAnsi=s,exports.supports=n,exports.supportsAtMost=r,exports.transformPreserveAnsi=i;