@visulima/colorize 1.4.26 → 1.4.28

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +208 -12
  3. package/dist/ansi-codes.d.cts +18 -0
  4. package/dist/ansi-codes.d.mts +18 -0
  5. package/dist/ansi-codes.d.ts +18 -0
  6. package/dist/colorize.browser.d.mts +3 -0
  7. package/dist/colorize.server.d.cts +10 -0
  8. package/dist/colorize.server.d.mts +10 -0
  9. package/dist/colorize.server.d.ts +10 -0
  10. package/dist/css-code.d.mts +11 -0
  11. package/dist/gradient/gradient-builder.d.cts +10 -0
  12. package/dist/gradient/gradient-builder.d.mts +10 -0
  13. package/dist/gradient/gradient-builder.d.ts +10 -0
  14. package/dist/gradient/util/color-names.d.cts +2 -0
  15. package/dist/gradient/util/color-names.d.mts +2 -0
  16. package/dist/gradient/util/color-names.d.ts +2 -0
  17. package/dist/gradient/util/compute.d.cts +2 -0
  18. package/dist/gradient/util/compute.d.mts +2 -0
  19. package/dist/gradient/util/compute.d.ts +2 -0
  20. package/dist/gradient/util/hsv-to-rgb.d.cts +5 -0
  21. package/dist/gradient/util/hsv-to-rgb.d.mts +5 -0
  22. package/dist/gradient/util/hsv-to-rgb.d.ts +5 -0
  23. package/dist/gradient/util/interpolate.d.cts +3 -0
  24. package/dist/gradient/util/interpolate.d.mts +3 -0
  25. package/dist/gradient/util/interpolate.d.ts +3 -0
  26. package/dist/gradient/util/rgb-to-hsv.d.cts +9 -0
  27. package/dist/gradient/util/rgb-to-hsv.d.mts +9 -0
  28. package/dist/gradient/util/rgb-to-hsv.d.ts +9 -0
  29. package/dist/gradient.cjs +60 -3
  30. package/dist/gradient.d.cts +4 -16
  31. package/dist/gradient.d.mts +4 -16
  32. package/dist/gradient.d.ts +4 -16
  33. package/dist/gradient.mjs +54 -3
  34. package/dist/index.browser.d.mts +60 -64
  35. package/dist/index.browser.mjs +61 -1
  36. package/dist/index.server.cjs +246 -2
  37. package/dist/index.server.d.cts +7 -73
  38. package/dist/index.server.d.mts +60 -64
  39. package/dist/index.server.d.ts +8 -65
  40. package/dist/index.server.mjs +61 -1
  41. package/dist/packem_shared/Colorize-BenP3bFn.mjs +241 -0
  42. package/dist/packem_shared/Colorize-Ca9CXTcj.mjs +413 -0
  43. package/dist/packem_shared/GradientBuilder-Ba4Teq6P.mjs +487 -0
  44. package/dist/packem_shared/GradientBuilder-DjJK22kP.cjs +491 -0
  45. package/dist/packem_shared/colorize.server-BA3gZZXz.cjs +193 -0
  46. package/dist/packem_shared/colorize.server-ry9FZNfG.mjs +191 -0
  47. package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +13 -0
  48. package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +17 -0
  49. package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +41 -0
  50. package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +47 -0
  51. package/dist/template/make-colorize-template.d.cts +9 -0
  52. package/dist/template/make-colorize-template.d.mts +9 -0
  53. package/dist/template/make-colorize-template.d.ts +9 -0
  54. package/dist/template/make-template.d.cts +10 -0
  55. package/dist/template/make-template.d.mts +10 -0
  56. package/dist/template/make-template.d.ts +10 -0
  57. package/dist/template.cjs +144 -2
  58. package/dist/template.d.cts +5 -11
  59. package/dist/template.d.mts +5 -7
  60. package/dist/template.d.ts +5 -11
  61. package/dist/template.mjs +138 -2
  62. package/dist/types.d.cts +174 -0
  63. package/dist/types.d.mts +174 -0
  64. package/dist/types.d.ts +174 -0
  65. package/dist/util/ansi-code-hex-map.d.mts +8 -0
  66. package/dist/util/clamp.d.cts +12 -0
  67. package/dist/util/clamp.d.mts +12 -0
  68. package/dist/util/clamp.d.ts +12 -0
  69. package/dist/util/convert-hex-to-rgb.d.cts +22 -0
  70. package/dist/util/convert-hex-to-rgb.d.mts +22 -0
  71. package/dist/util/convert-hex-to-rgb.d.ts +22 -0
  72. package/dist/util/convert-rgb-to-ansi.d.cts +18 -0
  73. package/dist/util/convert-rgb-to-ansi.d.mts +18 -0
  74. package/dist/util/convert-rgb-to-ansi.d.ts +18 -0
  75. package/dist/util/string-replace-all.d.cts +12 -0
  76. package/dist/util/string-replace-all.d.mts +12 -0
  77. package/dist/util/string-replace-all.d.ts +12 -0
  78. package/dist/util/unescape.d.cts +9 -0
  79. package/dist/util/unescape.d.mts +9 -0
  80. package/dist/util/unescape.d.ts +9 -0
  81. package/dist/utils.cjs +13 -1
  82. package/dist/utils.d.cts +2 -9
  83. package/dist/utils.d.mts +2 -9
  84. package/dist/utils.d.ts +2 -9
  85. package/dist/utils.mjs +2 -1
  86. package/package.json +2 -2
  87. package/dist/index.browser.d.ts +0 -65
  88. package/dist/packem_shared/Colorize-BHcGWJJ0.mjs +0 -1
  89. package/dist/packem_shared/Colorize-CFUl2AHz.mjs +0 -2
  90. package/dist/packem_shared/GradientBuilder-D6w_X2D1.cjs +0 -1
  91. package/dist/packem_shared/GradientBuilder-DnPdd2Cf.mjs +0 -1
  92. package/dist/packem_shared/colorize.server-BX0i6nN6.cjs +0 -2
  93. package/dist/packem_shared/colorize.server-BkwhBIE0.mjs +0 -2
  94. package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +0 -1
  95. package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +0 -1
  96. package/dist/packem_shared/rgbToAnsi256--f09kvlF.cjs +0 -1
  97. package/dist/packem_shared/rgbToAnsi256-YETEPW8R.mjs +0 -1
  98. package/dist/packem_shared/types-CuuGv4d0.d.cts +0 -81
  99. package/dist/packem_shared/types-CuuGv4d0.d.mts +0 -81
  100. package/dist/packem_shared/types-CuuGv4d0.d.ts +0 -81
  101. package/dist/packem_shared/types-M28Oe2t1.d.mts +0 -67
  102. package/dist/packem_shared/types-M28Oe2t1.d.ts +0 -67
package/dist/template.mjs CHANGED
@@ -1,2 +1,138 @@
1
- var y=Object.defineProperty;var i=(e,t)=>y(e,"name",{value:t,configurable:!0});import{m as x}from"./packem_shared/colorize.server-BkwhBIE0.mjs";import{convertHexToRgb as m}from"./packem_shared/convertHexToRgb-DGcGUKnj.mjs";var T=Object.defineProperty,j=i((e,t)=>T(e,"name",{value:t,configurable:!0}),"n");const d=j(e=>(t,...r)=>{if(!Array.isArray(t)||!Array.isArray(t.raw))throw new TypeError("A tagged template literal must be provided");const a=[t.raw[0]];for(let n=1;n<t.raw.length;n++)a.push(String(r[n-1]).replaceAll(/[{}\\]/g,String.raw`\$&`),String(t.raw[n]));return e(a.join(""))},"makeColorizeTemplate");var A=Object.defineProperty,$=i((e,t)=>A(e,"name",{value:t,configurable:!0}),"e");const k=new Map([["0","\0"],["\\","\\"],["a","\x07"],["b","\b"],["e","\x1B"],["f","\f"],["n",`
2
- `],["r","\r"],["t"," "],["v","\v"]]),b=$(e=>{const t=e.startsWith("u"),r=e[1]==="{";return t&&!r&&e.length===5||e.startsWith("x")&&e.length===3?String.fromCodePoint(Number.parseInt(e.slice(1),16)):t&&r?String.fromCodePoint(Number.parseInt(e.slice(2,-1),16)):k.get(e)??e},"unescape");var S=Object.defineProperty,u=i((e,t)=>S(e,"name",{value:t,configurable:!0}),"u");const E=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi,g=/(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi,N=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,P=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi,O=u((e,t)=>{const r=[],a=t.trim().split(/\s*,\s*/);let n;for(const s of a){const o=Number(s);if(!Number.isNaN(o))r.push(o);else if(n=N.exec(s))r.push(n[2].replace(P,(f,l,p)=>l?b(l):p));else throw new Error(`Invalid template style argument: ${s} (in style '${e}')`)}return r},"parseArguments"),C=u(e=>{g.lastIndex=0;const t=[];let r;for(;(r=g.exec(e))!==null;){const a=r[1];r[2]?t.push([a,...O(a,r[2])]):r[3]||r[4]?(r[3]&&t.push(["rgb",...m(r[3])]),r[4]&&t.push(["bgRgb",...m(r[4])])):t.push([a])}return t},"parseStyle"),h=u((e,t)=>{const r={};for(const n of t)for(const s of n.styles)r[s[0]]=n.inverse?null:s.slice(1);let a=e;for(const[n,s]of Object.entries(r))if(Array.isArray(s)){if(!(n in a))throw new Error(`Unknown style: ${n}`);a=s.length>0?a[n](...s):a[n]}return a},"buildStyle"),w=u(e=>t=>{const r=[],a=[];let n=[];if(t.replaceAll(E,(s,o,f,l,p,v)=>{if(o)n.push(b(o));else if(l){const c=n.join("");n=[],a.push(r.length===0?c:h(e,r)(c)),r.push({inverse:f,styles:C(l)})}else if(p){if(r.length===0)throw new Error("Found extraneous } in template literal");a.push(h(e,r)(n.join(""))),n=[],r.pop()}else n.push(v)}),a.push(n.join("")),r.length>0)throw new Error(`template literal is missing ${r.length} closing bracket${r.length===1?"":"s"} (\`}\`)`);return a.join("")},"makeTemplate");var I=Object.defineProperty,z=i((e,t)=>I(e,"name",{value:t,configurable:!0}),"o");const R=new x,M=z(e=>d(w(e)),"makeTaggedTemplate"),W=w(R),U=d(W);export{U as default,M as makeTaggedTemplate,W as template};
1
+ import { C as Colorize } from './packem_shared/colorize.server-ry9FZNfG.mjs';
2
+ import { convertHexToRgb } from './packem_shared/convertHexToRgb-CWdAm2kE.mjs';
3
+
4
+ const makeColorizeTemplate = (template) => (firstString, ...arguments_) => {
5
+ if (!Array.isArray(firstString) || !Array.isArray(firstString.raw)) {
6
+ throw new TypeError("A tagged template literal must be provided");
7
+ }
8
+ const parts = [firstString.raw[0]];
9
+ for (let index = 1; index < firstString.raw.length; index++) {
10
+ parts.push(String(arguments_[index - 1]).replaceAll(/[{}\\]/g, String.raw`\$&`), String(firstString.raw[index]));
11
+ }
12
+ return template(parts.join(""));
13
+ };
14
+
15
+ const ESCAPES = /* @__PURE__ */ new Map([
16
+ ["0", "\0"],
17
+ ["\\", "\\"],
18
+ ["a", "\x07"],
19
+ ["b", "\b"],
20
+ ["e", "\x1B"],
21
+ ["f", "\f"],
22
+ ["n", "\n"],
23
+ ["r", "\r"],
24
+ ["t", " "],
25
+ ["v", "\v"]
26
+ ]);
27
+ const unescape = (c) => {
28
+ const u = c.startsWith("u");
29
+ const bracket = c[1] === "{";
30
+ if (u && !bracket && c.length === 5 || c.startsWith("x") && c.length === 3) {
31
+ return String.fromCodePoint(Number.parseInt(c.slice(1), 16));
32
+ }
33
+ if (u && bracket) {
34
+ return String.fromCodePoint(Number.parseInt(c.slice(2, -1), 16));
35
+ }
36
+ return ESCAPES.get(c) ?? c;
37
+ };
38
+
39
+ const TEMPLATE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi;
40
+ const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
41
+ const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
42
+ const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
43
+ const parseArguments = (name, value) => {
44
+ const results = [];
45
+ const chunks = value.trim().split(/\s*,\s*/);
46
+ let matches;
47
+ for (const chunk of chunks) {
48
+ const number = Number(chunk);
49
+ if (!Number.isNaN(number)) {
50
+ results.push(number);
51
+ } else if (matches = STRING_REGEX.exec(chunk)) {
52
+ results.push(matches[2].replace(ESCAPE_REGEX, (_, escape, character) => escape ? unescape(escape) : character));
53
+ } else {
54
+ throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
55
+ }
56
+ }
57
+ return results;
58
+ };
59
+ const parseStyle = (style) => {
60
+ STYLE_REGEX.lastIndex = 0;
61
+ const results = [];
62
+ let matches;
63
+ while ((matches = STYLE_REGEX.exec(style)) !== null) {
64
+ const name = matches[1];
65
+ if (matches[2]) {
66
+ results.push([name, ...parseArguments(name, matches[2])]);
67
+ } else if (matches[3] || matches[4]) {
68
+ if (matches[3]) {
69
+ results.push(["rgb", ...convertHexToRgb(matches[3])]);
70
+ }
71
+ if (matches[4]) {
72
+ results.push(["bgRgb", ...convertHexToRgb(matches[4])]);
73
+ }
74
+ } else {
75
+ results.push([name]);
76
+ }
77
+ }
78
+ return results;
79
+ };
80
+ const buildStyle = (colorize, styles) => {
81
+ const enabled = {};
82
+ for (const layer of styles) {
83
+ for (const style of layer.styles) {
84
+ enabled[style[0]] = layer.inverse ? null : style.slice(1);
85
+ }
86
+ }
87
+ let current = colorize;
88
+ for (const [styleName, enabledStyles] of Object.entries(enabled)) {
89
+ if (!Array.isArray(enabledStyles)) {
90
+ continue;
91
+ }
92
+ if (!(styleName in current)) {
93
+ throw new Error(`Unknown style: ${styleName}`);
94
+ }
95
+ current = enabledStyles.length > 0 ? current[styleName](...enabledStyles) : current[styleName];
96
+ }
97
+ return current;
98
+ };
99
+ const makeTemplate = (colorize) => (string) => {
100
+ const styles = [];
101
+ const chunks = [];
102
+ let chunk = [];
103
+ string.replaceAll(
104
+ TEMPLATE_REGEX,
105
+ // @ts-expect-error - TS doesn't understand that the regex args are defined
106
+ (_, escapeCharacter, inverse, style, close, character) => {
107
+ if (escapeCharacter) {
108
+ chunk.push(unescape(escapeCharacter));
109
+ } else if (style) {
110
+ const joinedChunk = chunk.join("");
111
+ chunk = [];
112
+ chunks.push(styles.length === 0 ? joinedChunk : buildStyle(colorize, styles)(joinedChunk));
113
+ styles.push({ inverse, styles: parseStyle(style) });
114
+ } else if (close) {
115
+ if (styles.length === 0) {
116
+ throw new Error("Found extraneous } in template literal");
117
+ }
118
+ chunks.push(buildStyle(colorize, styles)(chunk.join("")));
119
+ chunk = [];
120
+ styles.pop();
121
+ } else {
122
+ chunk.push(character);
123
+ }
124
+ }
125
+ );
126
+ chunks.push(chunk.join(""));
127
+ if (styles.length > 0) {
128
+ throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
129
+ }
130
+ return chunks.join("");
131
+ };
132
+
133
+ const colorize = new Colorize();
134
+ const makeTaggedTemplate = (instance) => makeColorizeTemplate(makeTemplate(instance));
135
+ const template = makeTemplate(colorize);
136
+ const templateFunction = makeColorizeTemplate(template);
137
+
138
+ export { templateFunction as default, makeTaggedTemplate, template };
@@ -0,0 +1,174 @@
1
+ export type ColorValueHex = `#${string}`;
2
+ export interface ColorizeType {
3
+ /**
4
+ * Return styled string.
5
+ * @param {string | TemplateStringsArray} string
6
+ */
7
+ (string: number | string): string;
8
+ (string: TemplateStringsArray, ...parameters: string[]): string;
9
+ /**
10
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for foreground color.
11
+ *
12
+ * Code ranges:
13
+ * ```
14
+ * 0 - 7: standard colors
15
+ * 8 - 15: high intensity colors
16
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
17
+ * 232 - 255: grayscale from black to white in 24 steps
18
+ * ```
19
+ * @param {number} code in range [0, 255].
20
+ */
21
+ ansi256: (code: number) => this;
22
+ /**
23
+ * Alias for bgAnsi256.
24
+ * @param {number} code in range [0, 255].
25
+ */
26
+ bg: (code: number) => this;
27
+ /**
28
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for background color.
29
+ *
30
+ * Code ranges:
31
+ * ```
32
+ * 0 - 7: standard colors
33
+ * 8 - 15: high intensity colors
34
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
35
+ * 232 - 255: grayscale from black to white in 24 steps
36
+ * ```
37
+ * @param {number} code in range [0, 255].
38
+ */
39
+ bgAnsi256: (code: number) => this;
40
+ readonly bgBlack: this;
41
+ readonly bgBlackBright: this;
42
+ readonly bgBlue: this;
43
+ readonly bgBlueBright: this;
44
+ readonly bgCyan: this;
45
+ readonly bgCyanBright: this;
46
+ readonly bgGray: this;
47
+ readonly bgGreen: this;
48
+ readonly bgGreenBright: this;
49
+ readonly bgGrey: this;
50
+ /**
51
+ * Set HEX value for background color.
52
+ * @param {string} hex
53
+ */
54
+ bgHex: (color: ColorValueHex) => this;
55
+ readonly bgMagenta: this;
56
+ readonly bgMagentaBright: this;
57
+ readonly bgRed: this;
58
+ readonly bgRedBright: this;
59
+ /**
60
+ * Set RGB values for background color.
61
+ * @param {number} red The red value, in range [0, 255].
62
+ * @param {number} green The green value, in range [0, 255].
63
+ * @param {number} blue The blue value, in range [0, 255].
64
+ */
65
+ bgRgb: (red: number, green: number, blue: number) => this;
66
+ readonly bgWhite: this;
67
+ readonly bgWhiteBright: this;
68
+ readonly bgYellow: this;
69
+ readonly bgYellowBright: this;
70
+ readonly black: this;
71
+ readonly blackBright: this;
72
+ readonly blue: this;
73
+ readonly blueBright: this;
74
+ /** &lt;b>Bold&lt;/b> style (high intensity). */
75
+ readonly bold: this;
76
+ /** The ANSI escape sequences for ending the current style. */
77
+ readonly close: string;
78
+ readonly cyan: this;
79
+ readonly cyanBright: this;
80
+ /** Faint style (low intensity or dim). */
81
+ readonly dim: this;
82
+ /**
83
+ * Alias for ansi256.
84
+ * @param {number} code in range [0, 255].
85
+ */
86
+ fg: (code: number) => this;
87
+ readonly gray: this;
88
+ readonly green: this;
89
+ readonly greenBright: this;
90
+ readonly grey: this;
91
+ /**
92
+ * Set HEX value for foreground color.
93
+ * @param {string} hex
94
+ */
95
+ hex: (color: ColorValueHex) => this;
96
+ /** Print the invisible text. */
97
+ readonly hidden: this;
98
+ /** Invert background and foreground colors. */
99
+ readonly inverse: this;
100
+ /** &lt;i>Italic&lt;/i> style. (Not widely supported) */
101
+ readonly italic: this;
102
+ readonly magenta: this;
103
+ readonly magentaBright: this;
104
+ /** The ANSI escape sequences for starting the current style. */
105
+ readonly open: string;
106
+ /** O̅v̅e̅r̅l̅i̅n̅e̅ style. (Not widely supported) */
107
+ readonly overline: this;
108
+ readonly red: this;
109
+ readonly redBright: this;
110
+ /** Reset the current style. */
111
+ readonly reset: this;
112
+ /**
113
+ * Set RGB values for foreground color.
114
+ * @param {number} red The red value, in range [0, 255].
115
+ * @param {number} green The green value, in range [0, 255].
116
+ * @param {number} blue The blue value, in range [0, 255].
117
+ */
118
+ rgb: (red: number, green: number, blue: number) => this;
119
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) The alias for `strikethrough`. */
120
+ readonly strike: this;
121
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) */
122
+ readonly strikethrough: this;
123
+ /**
124
+ * Remove ANSI styling codes.
125
+ * @param {string} str
126
+ * @returns {string}
127
+ */
128
+ strip: (string: string) => string;
129
+ /** U̲n̲d̲e̲r̲l̲i̲n̲e̲ style. (Not widely supported) */
130
+ readonly underline: this;
131
+ /** Print visible text without ANSI styling. */
132
+ readonly visible: this;
133
+ readonly white: this;
134
+ readonly whiteBright: this;
135
+ readonly yellow: this;
136
+ readonly yellowBright: this;
137
+ }
138
+ export type ColorData = {
139
+ close: string;
140
+ open: string;
141
+ };
142
+ /**
143
+ * Base ANSI Styles
144
+ */
145
+ export type AnsiStyles = "bold" | "dim" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strike" | "strikethrough" | "underline" | "visible";
146
+ /**
147
+ * Base ANSI Colors
148
+ */
149
+ export type AnsiColors = "bgBlack" | "bgBlackBright" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgGrey" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright" | "black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright";
150
+ export type CssColorName = "aliceblue" | "antiquewhite" | "aqua" | "aquamarine" | "azure" | "beige" | "bisque" | "black" | "blanchedalmond" | "blue" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | "darkorchid" | "darkred" | "darksalmon" | "darkseagreen" | "darkslateblue" | "darkslategray" | "darkslategrey" | "darkturquoise" | "darkviolet" | "deeppink" | "deepskyblue" | "dimgray" | "dimgrey" | "dodgerblue" | "firebrick" | "floralwhite" | "forestgreen" | "fuchsia" | "gainsboro" | "ghostwhite" | "gold" | "goldenrod" | "gray" | "green" | "greenyellow" | "grey" | "honeydew" | "hotpink" | "indianred" | "indigo" | "ivory" | "khaki" | "lavender" | "lavenderblush" | "lawngreen" | "lemonchiffon" | "lightblue" | "lightcoral" | "lightcyan" | "lightgoldenrodyellow" | "lightgray" | "lightgreen" | "lightgrey" | "lightpink" | "lightsalmon" | "lightseagreen" | "lightskyblue" | "lightslategray" | "lightslategrey" | "lightsteelblue" | "lightyellow" | "lime" | "limegreen" | "linen" | "magenta" | "maroon" | "mediumaquamarine" | "mediumblue" | "mediumorchid" | "mediumpurple" | "mediumseagreen" | "mediumslateblue" | "mediumspringgreen" | "mediumturquoise" | "mediumvioletred" | "midnightblue" | "mintcream" | "mistyrose" | "moccasin" | "navajowhite" | "navy" | "oldlace" | "olive" | "olivedrab" | "orange" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "rebeccapurple" | "red" | "rosybrown" | "royalblue" | "saddlebrown" | "salmon" | "sandybrown" | "seagreen" | "seashell" | "sienna" | "silver" | "skyblue" | "slateblue" | "slategray" | "slategrey" | "snow" | "springgreen" | "steelblue" | "tan" | "teal" | "thistle" | "tomato" | "turquoise" | "violet" | "wheat" | "white" | "whitesmoke" | "yellow" | "yellowgreen";
151
+ export type CssColorCodes = {
152
+ [key in CssColorName]: [number, number, number];
153
+ };
154
+ export type StopInput = {
155
+ color?: ColorValueHex | CssColorName | RGB | [number, number, number];
156
+ colorLess?: boolean;
157
+ position: number;
158
+ };
159
+ export type StopOutput = {
160
+ color: [number, number, number] | undefined;
161
+ colorLess?: boolean;
162
+ position: number;
163
+ };
164
+ export type RGB = {
165
+ b: number;
166
+ g: number;
167
+ r: number;
168
+ };
169
+ export type HSVA = {
170
+ a?: number;
171
+ h: number;
172
+ s: number;
173
+ v: number;
174
+ };
@@ -0,0 +1,174 @@
1
+ export type ColorValueHex = `#${string}`;
2
+ export interface ColorizeType {
3
+ /**
4
+ * Return styled string.
5
+ * @param {string | TemplateStringsArray} string
6
+ */
7
+ (string: number | string): string;
8
+ (string: TemplateStringsArray, ...parameters: string[]): string;
9
+ /**
10
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for foreground color.
11
+ *
12
+ * Code ranges:
13
+ * ```
14
+ * 0 - 7: standard colors
15
+ * 8 - 15: high intensity colors
16
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
17
+ * 232 - 255: grayscale from black to white in 24 steps
18
+ * ```
19
+ * @param {number} code in range [0, 255].
20
+ */
21
+ ansi256: (code: number) => this;
22
+ /**
23
+ * Alias for bgAnsi256.
24
+ * @param {number} code in range [0, 255].
25
+ */
26
+ bg: (code: number) => this;
27
+ /**
28
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for background color.
29
+ *
30
+ * Code ranges:
31
+ * ```
32
+ * 0 - 7: standard colors
33
+ * 8 - 15: high intensity colors
34
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
35
+ * 232 - 255: grayscale from black to white in 24 steps
36
+ * ```
37
+ * @param {number} code in range [0, 255].
38
+ */
39
+ bgAnsi256: (code: number) => this;
40
+ readonly bgBlack: this;
41
+ readonly bgBlackBright: this;
42
+ readonly bgBlue: this;
43
+ readonly bgBlueBright: this;
44
+ readonly bgCyan: this;
45
+ readonly bgCyanBright: this;
46
+ readonly bgGray: this;
47
+ readonly bgGreen: this;
48
+ readonly bgGreenBright: this;
49
+ readonly bgGrey: this;
50
+ /**
51
+ * Set HEX value for background color.
52
+ * @param {string} hex
53
+ */
54
+ bgHex: (color: ColorValueHex) => this;
55
+ readonly bgMagenta: this;
56
+ readonly bgMagentaBright: this;
57
+ readonly bgRed: this;
58
+ readonly bgRedBright: this;
59
+ /**
60
+ * Set RGB values for background color.
61
+ * @param {number} red The red value, in range [0, 255].
62
+ * @param {number} green The green value, in range [0, 255].
63
+ * @param {number} blue The blue value, in range [0, 255].
64
+ */
65
+ bgRgb: (red: number, green: number, blue: number) => this;
66
+ readonly bgWhite: this;
67
+ readonly bgWhiteBright: this;
68
+ readonly bgYellow: this;
69
+ readonly bgYellowBright: this;
70
+ readonly black: this;
71
+ readonly blackBright: this;
72
+ readonly blue: this;
73
+ readonly blueBright: this;
74
+ /** &lt;b>Bold&lt;/b> style (high intensity). */
75
+ readonly bold: this;
76
+ /** The ANSI escape sequences for ending the current style. */
77
+ readonly close: string;
78
+ readonly cyan: this;
79
+ readonly cyanBright: this;
80
+ /** Faint style (low intensity or dim). */
81
+ readonly dim: this;
82
+ /**
83
+ * Alias for ansi256.
84
+ * @param {number} code in range [0, 255].
85
+ */
86
+ fg: (code: number) => this;
87
+ readonly gray: this;
88
+ readonly green: this;
89
+ readonly greenBright: this;
90
+ readonly grey: this;
91
+ /**
92
+ * Set HEX value for foreground color.
93
+ * @param {string} hex
94
+ */
95
+ hex: (color: ColorValueHex) => this;
96
+ /** Print the invisible text. */
97
+ readonly hidden: this;
98
+ /** Invert background and foreground colors. */
99
+ readonly inverse: this;
100
+ /** &lt;i>Italic&lt;/i> style. (Not widely supported) */
101
+ readonly italic: this;
102
+ readonly magenta: this;
103
+ readonly magentaBright: this;
104
+ /** The ANSI escape sequences for starting the current style. */
105
+ readonly open: string;
106
+ /** O̅v̅e̅r̅l̅i̅n̅e̅ style. (Not widely supported) */
107
+ readonly overline: this;
108
+ readonly red: this;
109
+ readonly redBright: this;
110
+ /** Reset the current style. */
111
+ readonly reset: this;
112
+ /**
113
+ * Set RGB values for foreground color.
114
+ * @param {number} red The red value, in range [0, 255].
115
+ * @param {number} green The green value, in range [0, 255].
116
+ * @param {number} blue The blue value, in range [0, 255].
117
+ */
118
+ rgb: (red: number, green: number, blue: number) => this;
119
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) The alias for `strikethrough`. */
120
+ readonly strike: this;
121
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) */
122
+ readonly strikethrough: this;
123
+ /**
124
+ * Remove ANSI styling codes.
125
+ * @param {string} str
126
+ * @returns {string}
127
+ */
128
+ strip: (string: string) => string;
129
+ /** U̲n̲d̲e̲r̲l̲i̲n̲e̲ style. (Not widely supported) */
130
+ readonly underline: this;
131
+ /** Print visible text without ANSI styling. */
132
+ readonly visible: this;
133
+ readonly white: this;
134
+ readonly whiteBright: this;
135
+ readonly yellow: this;
136
+ readonly yellowBright: this;
137
+ }
138
+ export type ColorData = {
139
+ close: string;
140
+ open: string;
141
+ };
142
+ /**
143
+ * Base ANSI Styles
144
+ */
145
+ export type AnsiStyles = "bold" | "dim" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strike" | "strikethrough" | "underline" | "visible";
146
+ /**
147
+ * Base ANSI Colors
148
+ */
149
+ export type AnsiColors = "bgBlack" | "bgBlackBright" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgGrey" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright" | "black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright";
150
+ export type CssColorName = "aliceblue" | "antiquewhite" | "aqua" | "aquamarine" | "azure" | "beige" | "bisque" | "black" | "blanchedalmond" | "blue" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | "darkorchid" | "darkred" | "darksalmon" | "darkseagreen" | "darkslateblue" | "darkslategray" | "darkslategrey" | "darkturquoise" | "darkviolet" | "deeppink" | "deepskyblue" | "dimgray" | "dimgrey" | "dodgerblue" | "firebrick" | "floralwhite" | "forestgreen" | "fuchsia" | "gainsboro" | "ghostwhite" | "gold" | "goldenrod" | "gray" | "green" | "greenyellow" | "grey" | "honeydew" | "hotpink" | "indianred" | "indigo" | "ivory" | "khaki" | "lavender" | "lavenderblush" | "lawngreen" | "lemonchiffon" | "lightblue" | "lightcoral" | "lightcyan" | "lightgoldenrodyellow" | "lightgray" | "lightgreen" | "lightgrey" | "lightpink" | "lightsalmon" | "lightseagreen" | "lightskyblue" | "lightslategray" | "lightslategrey" | "lightsteelblue" | "lightyellow" | "lime" | "limegreen" | "linen" | "magenta" | "maroon" | "mediumaquamarine" | "mediumblue" | "mediumorchid" | "mediumpurple" | "mediumseagreen" | "mediumslateblue" | "mediumspringgreen" | "mediumturquoise" | "mediumvioletred" | "midnightblue" | "mintcream" | "mistyrose" | "moccasin" | "navajowhite" | "navy" | "oldlace" | "olive" | "olivedrab" | "orange" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "rebeccapurple" | "red" | "rosybrown" | "royalblue" | "saddlebrown" | "salmon" | "sandybrown" | "seagreen" | "seashell" | "sienna" | "silver" | "skyblue" | "slateblue" | "slategray" | "slategrey" | "snow" | "springgreen" | "steelblue" | "tan" | "teal" | "thistle" | "tomato" | "turquoise" | "violet" | "wheat" | "white" | "whitesmoke" | "yellow" | "yellowgreen";
151
+ export type CssColorCodes = {
152
+ [key in CssColorName]: [number, number, number];
153
+ };
154
+ export type StopInput = {
155
+ color?: ColorValueHex | CssColorName | RGB | [number, number, number];
156
+ colorLess?: boolean;
157
+ position: number;
158
+ };
159
+ export type StopOutput = {
160
+ color: [number, number, number] | undefined;
161
+ colorLess?: boolean;
162
+ position: number;
163
+ };
164
+ export type RGB = {
165
+ b: number;
166
+ g: number;
167
+ r: number;
168
+ };
169
+ export type HSVA = {
170
+ a?: number;
171
+ h: number;
172
+ s: number;
173
+ v: number;
174
+ };
@@ -0,0 +1,174 @@
1
+ export type ColorValueHex = `#${string}`;
2
+ export interface ColorizeType {
3
+ /**
4
+ * Return styled string.
5
+ * @param {string | TemplateStringsArray} string
6
+ */
7
+ (string: number | string): string;
8
+ (string: TemplateStringsArray, ...parameters: string[]): string;
9
+ /**
10
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for foreground color.
11
+ *
12
+ * Code ranges:
13
+ * ```
14
+ * 0 - 7: standard colors
15
+ * 8 - 15: high intensity colors
16
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
17
+ * 232 - 255: grayscale from black to white in 24 steps
18
+ * ```
19
+ * @param {number} code in range [0, 255].
20
+ */
21
+ ansi256: (code: number) => this;
22
+ /**
23
+ * Alias for bgAnsi256.
24
+ * @param {number} code in range [0, 255].
25
+ */
26
+ bg: (code: number) => this;
27
+ /**
28
+ * Set [256-color ANSI code](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) for background color.
29
+ *
30
+ * Code ranges:
31
+ * ```
32
+ * 0 - 7: standard colors
33
+ * 8 - 15: high intensity colors
34
+ * 16 - 231: 6 × 6 × 6 cube (216 colors)
35
+ * 232 - 255: grayscale from black to white in 24 steps
36
+ * ```
37
+ * @param {number} code in range [0, 255].
38
+ */
39
+ bgAnsi256: (code: number) => this;
40
+ readonly bgBlack: this;
41
+ readonly bgBlackBright: this;
42
+ readonly bgBlue: this;
43
+ readonly bgBlueBright: this;
44
+ readonly bgCyan: this;
45
+ readonly bgCyanBright: this;
46
+ readonly bgGray: this;
47
+ readonly bgGreen: this;
48
+ readonly bgGreenBright: this;
49
+ readonly bgGrey: this;
50
+ /**
51
+ * Set HEX value for background color.
52
+ * @param {string} hex
53
+ */
54
+ bgHex: (color: ColorValueHex) => this;
55
+ readonly bgMagenta: this;
56
+ readonly bgMagentaBright: this;
57
+ readonly bgRed: this;
58
+ readonly bgRedBright: this;
59
+ /**
60
+ * Set RGB values for background color.
61
+ * @param {number} red The red value, in range [0, 255].
62
+ * @param {number} green The green value, in range [0, 255].
63
+ * @param {number} blue The blue value, in range [0, 255].
64
+ */
65
+ bgRgb: (red: number, green: number, blue: number) => this;
66
+ readonly bgWhite: this;
67
+ readonly bgWhiteBright: this;
68
+ readonly bgYellow: this;
69
+ readonly bgYellowBright: this;
70
+ readonly black: this;
71
+ readonly blackBright: this;
72
+ readonly blue: this;
73
+ readonly blueBright: this;
74
+ /** &lt;b>Bold&lt;/b> style (high intensity). */
75
+ readonly bold: this;
76
+ /** The ANSI escape sequences for ending the current style. */
77
+ readonly close: string;
78
+ readonly cyan: this;
79
+ readonly cyanBright: this;
80
+ /** Faint style (low intensity or dim). */
81
+ readonly dim: this;
82
+ /**
83
+ * Alias for ansi256.
84
+ * @param {number} code in range [0, 255].
85
+ */
86
+ fg: (code: number) => this;
87
+ readonly gray: this;
88
+ readonly green: this;
89
+ readonly greenBright: this;
90
+ readonly grey: this;
91
+ /**
92
+ * Set HEX value for foreground color.
93
+ * @param {string} hex
94
+ */
95
+ hex: (color: ColorValueHex) => this;
96
+ /** Print the invisible text. */
97
+ readonly hidden: this;
98
+ /** Invert background and foreground colors. */
99
+ readonly inverse: this;
100
+ /** &lt;i>Italic&lt;/i> style. (Not widely supported) */
101
+ readonly italic: this;
102
+ readonly magenta: this;
103
+ readonly magentaBright: this;
104
+ /** The ANSI escape sequences for starting the current style. */
105
+ readonly open: string;
106
+ /** O̅v̅e̅r̅l̅i̅n̅e̅ style. (Not widely supported) */
107
+ readonly overline: this;
108
+ readonly red: this;
109
+ readonly redBright: this;
110
+ /** Reset the current style. */
111
+ readonly reset: this;
112
+ /**
113
+ * Set RGB values for foreground color.
114
+ * @param {number} red The red value, in range [0, 255].
115
+ * @param {number} green The green value, in range [0, 255].
116
+ * @param {number} blue The blue value, in range [0, 255].
117
+ */
118
+ rgb: (red: number, green: number, blue: number) => this;
119
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) The alias for `strikethrough`. */
120
+ readonly strike: this;
121
+ /** S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶ style. (Not widely supported) */
122
+ readonly strikethrough: this;
123
+ /**
124
+ * Remove ANSI styling codes.
125
+ * @param {string} str
126
+ * @returns {string}
127
+ */
128
+ strip: (string: string) => string;
129
+ /** U̲n̲d̲e̲r̲l̲i̲n̲e̲ style. (Not widely supported) */
130
+ readonly underline: this;
131
+ /** Print visible text without ANSI styling. */
132
+ readonly visible: this;
133
+ readonly white: this;
134
+ readonly whiteBright: this;
135
+ readonly yellow: this;
136
+ readonly yellowBright: this;
137
+ }
138
+ export type ColorData = {
139
+ close: string;
140
+ open: string;
141
+ };
142
+ /**
143
+ * Base ANSI Styles
144
+ */
145
+ export type AnsiStyles = "bold" | "dim" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strike" | "strikethrough" | "underline" | "visible";
146
+ /**
147
+ * Base ANSI Colors
148
+ */
149
+ export type AnsiColors = "bgBlack" | "bgBlackBright" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgGrey" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright" | "black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright";
150
+ export type CssColorName = "aliceblue" | "antiquewhite" | "aqua" | "aquamarine" | "azure" | "beige" | "bisque" | "black" | "blanchedalmond" | "blue" | "blueviolet" | "brown" | "burlywood" | "cadetblue" | "chartreuse" | "chocolate" | "coral" | "cornflowerblue" | "cornsilk" | "crimson" | "cyan" | "darkblue" | "darkcyan" | "darkgoldenrod" | "darkgray" | "darkgreen" | "darkgrey" | "darkkhaki" | "darkmagenta" | "darkolivegreen" | "darkorange" | "darkorchid" | "darkred" | "darksalmon" | "darkseagreen" | "darkslateblue" | "darkslategray" | "darkslategrey" | "darkturquoise" | "darkviolet" | "deeppink" | "deepskyblue" | "dimgray" | "dimgrey" | "dodgerblue" | "firebrick" | "floralwhite" | "forestgreen" | "fuchsia" | "gainsboro" | "ghostwhite" | "gold" | "goldenrod" | "gray" | "green" | "greenyellow" | "grey" | "honeydew" | "hotpink" | "indianred" | "indigo" | "ivory" | "khaki" | "lavender" | "lavenderblush" | "lawngreen" | "lemonchiffon" | "lightblue" | "lightcoral" | "lightcyan" | "lightgoldenrodyellow" | "lightgray" | "lightgreen" | "lightgrey" | "lightpink" | "lightsalmon" | "lightseagreen" | "lightskyblue" | "lightslategray" | "lightslategrey" | "lightsteelblue" | "lightyellow" | "lime" | "limegreen" | "linen" | "magenta" | "maroon" | "mediumaquamarine" | "mediumblue" | "mediumorchid" | "mediumpurple" | "mediumseagreen" | "mediumslateblue" | "mediumspringgreen" | "mediumturquoise" | "mediumvioletred" | "midnightblue" | "mintcream" | "mistyrose" | "moccasin" | "navajowhite" | "navy" | "oldlace" | "olive" | "olivedrab" | "orange" | "orangered" | "orchid" | "palegoldenrod" | "palegreen" | "paleturquoise" | "palevioletred" | "papayawhip" | "peachpuff" | "peru" | "pink" | "plum" | "powderblue" | "purple" | "rebeccapurple" | "red" | "rosybrown" | "royalblue" | "saddlebrown" | "salmon" | "sandybrown" | "seagreen" | "seashell" | "sienna" | "silver" | "skyblue" | "slateblue" | "slategray" | "slategrey" | "snow" | "springgreen" | "steelblue" | "tan" | "teal" | "thistle" | "tomato" | "turquoise" | "violet" | "wheat" | "white" | "whitesmoke" | "yellow" | "yellowgreen";
151
+ export type CssColorCodes = {
152
+ [key in CssColorName]: [number, number, number];
153
+ };
154
+ export type StopInput = {
155
+ color?: ColorValueHex | CssColorName | RGB | [number, number, number];
156
+ colorLess?: boolean;
157
+ position: number;
158
+ };
159
+ export type StopOutput = {
160
+ color: [number, number, number] | undefined;
161
+ colorLess?: boolean;
162
+ position: number;
163
+ };
164
+ export type RGB = {
165
+ b: number;
166
+ g: number;
167
+ r: number;
168
+ };
169
+ export type HSVA = {
170
+ a?: number;
171
+ h: number;
172
+ s: number;
173
+ v: number;
174
+ };