@visulima/colorize 2.0.0-alpha.10 → 2.0.0-alpha.11

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 (99) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/gradient.cjs +3 -62
  3. package/dist/gradient.d.cts +21 -12
  4. package/dist/gradient.d.mts +21 -12
  5. package/dist/gradient.d.ts +21 -12
  6. package/dist/gradient.mjs +3 -56
  7. package/dist/index.browser.d.mts +203 -60
  8. package/dist/index.browser.d.ts +204 -0
  9. package/dist/index.browser.mjs +1 -61
  10. package/dist/index.server.cjs +2 -255
  11. package/dist/index.server.d.cts +12 -6
  12. package/dist/index.server.d.mts +203 -60
  13. package/dist/index.server.d.ts +12 -6
  14. package/dist/index.server.mjs +1 -61
  15. package/dist/packem_shared/Colorize-BUAQi0t0.js +2 -0
  16. package/dist/packem_shared/Colorize-i0NybjSp.js +1 -0
  17. package/dist/packem_shared/GradientBuilder-CudosKb8.cjs +1 -0
  18. package/dist/packem_shared/GradientBuilder-Du8WSL23.mjs +1 -0
  19. package/dist/packem_shared/colorize.server-BkQZGeaS.mjs +2 -0
  20. package/dist/packem_shared/colorize.server-Dn-gV0MN.cjs +2 -0
  21. package/dist/packem_shared/convertHexToRgb-CJNE3k_E.mjs +1 -0
  22. package/dist/packem_shared/convertHexToRgb-Dvalc5FD.cjs +1 -0
  23. package/dist/packem_shared/rgbToAnsi256--f09kvlF.cjs +1 -0
  24. package/dist/packem_shared/rgbToAnsi256-YETEPW8R.mjs +1 -0
  25. package/dist/packem_shared/types.d-bhP-2hCu.d.cts +154 -0
  26. package/dist/packem_shared/types.d-bhP-2hCu.d.mts +154 -0
  27. package/dist/packem_shared/types.d-bhP-2hCu.d.ts +154 -0
  28. package/dist/template.cjs +2 -152
  29. package/dist/template.d.cts +10 -4
  30. package/dist/template.d.mts +4 -4
  31. package/dist/template.d.ts +10 -4
  32. package/dist/template.mjs +2 -146
  33. package/dist/utils.cjs +1 -13
  34. package/dist/utils.d.cts +13 -2
  35. package/dist/utils.d.mts +13 -2
  36. package/dist/utils.d.ts +13 -2
  37. package/dist/utils.mjs +1 -2
  38. package/package.json +47 -47
  39. package/dist/ansi-codes.d.cts +0 -18
  40. package/dist/ansi-codes.d.mts +0 -18
  41. package/dist/ansi-codes.d.ts +0 -18
  42. package/dist/colorize.browser.d.mts +0 -3
  43. package/dist/colorize.server.d.cts +0 -10
  44. package/dist/colorize.server.d.mts +0 -10
  45. package/dist/colorize.server.d.ts +0 -10
  46. package/dist/css-code.d.mts +0 -11
  47. package/dist/gradient/gradient-builder.d.cts +0 -10
  48. package/dist/gradient/gradient-builder.d.mts +0 -10
  49. package/dist/gradient/gradient-builder.d.ts +0 -10
  50. package/dist/gradient/util/color-names.d.cts +0 -2
  51. package/dist/gradient/util/color-names.d.mts +0 -2
  52. package/dist/gradient/util/color-names.d.ts +0 -2
  53. package/dist/gradient/util/compute.d.cts +0 -2
  54. package/dist/gradient/util/compute.d.mts +0 -2
  55. package/dist/gradient/util/compute.d.ts +0 -2
  56. package/dist/gradient/util/hsv-to-rgb.d.cts +0 -5
  57. package/dist/gradient/util/hsv-to-rgb.d.mts +0 -5
  58. package/dist/gradient/util/hsv-to-rgb.d.ts +0 -5
  59. package/dist/gradient/util/interpolate.d.cts +0 -3
  60. package/dist/gradient/util/interpolate.d.mts +0 -3
  61. package/dist/gradient/util/interpolate.d.ts +0 -3
  62. package/dist/gradient/util/rgb-to-hsv.d.cts +0 -9
  63. package/dist/gradient/util/rgb-to-hsv.d.mts +0 -9
  64. package/dist/gradient/util/rgb-to-hsv.d.ts +0 -9
  65. package/dist/packem_shared/Colorize-BQ-Wlgs0.js +0 -409
  66. package/dist/packem_shared/Colorize-rJUN0RFg.js +0 -250
  67. package/dist/packem_shared/GradientBuilder-CkX4Imo9.mjs +0 -483
  68. package/dist/packem_shared/GradientBuilder-DRrwebdU.cjs +0 -487
  69. package/dist/packem_shared/colorize.server-CwTmhs0e.cjs +0 -198
  70. package/dist/packem_shared/colorize.server-YxoHIDUp.mjs +0 -196
  71. package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +0 -21
  72. package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +0 -17
  73. package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +0 -41
  74. package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +0 -47
  75. package/dist/template/make-colorize-template.d.cts +0 -9
  76. package/dist/template/make-colorize-template.d.mts +0 -9
  77. package/dist/template/make-colorize-template.d.ts +0 -9
  78. package/dist/template/make-template.d.cts +0 -10
  79. package/dist/template/make-template.d.mts +0 -10
  80. package/dist/template/make-template.d.ts +0 -10
  81. package/dist/types.d.cts +0 -174
  82. package/dist/types.d.mts +0 -174
  83. package/dist/types.d.ts +0 -174
  84. package/dist/util/ansi-code-hex-map.d.mts +0 -8
  85. package/dist/util/clamp.d.cts +0 -12
  86. package/dist/util/clamp.d.mts +0 -12
  87. package/dist/util/clamp.d.ts +0 -12
  88. package/dist/util/convert-hex-to-rgb.d.cts +0 -8
  89. package/dist/util/convert-hex-to-rgb.d.mts +0 -8
  90. package/dist/util/convert-hex-to-rgb.d.ts +0 -8
  91. package/dist/util/convert-rgb-to-ansi.d.cts +0 -18
  92. package/dist/util/convert-rgb-to-ansi.d.mts +0 -18
  93. package/dist/util/convert-rgb-to-ansi.d.ts +0 -18
  94. package/dist/util/string-replace-all.d.cts +0 -12
  95. package/dist/util/string-replace-all.d.mts +0 -12
  96. package/dist/util/string-replace-all.d.ts +0 -12
  97. package/dist/util/unescape.d.cts +0 -9
  98. package/dist/util/unescape.d.mts +0 -9
  99. package/dist/util/unescape.d.ts +0 -9
@@ -0,0 +1,204 @@
1
+ type ColorValueHex = `#${string}`;
2
+ 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} color
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
+ /** <b>Bold</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} color
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
+ /** <i>Italic</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} string
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
+ /**
139
+ * Base ANSI Styles
140
+ */
141
+ type AnsiStyles = "bold" | "dim" | "hidden" | "inverse" | "italic" | "overline" | "reset" | "strike" | "strikethrough" | "underline" | "visible";
142
+ /**
143
+ * Base ANSI Colors
144
+ */
145
+ 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";
146
+ declare const WebColorize: new () => ColorizeType;
147
+ declare const colorize: ColorizeType;
148
+ declare const ansi256: (code: number) => ColorizeType;
149
+ declare const bg: (code: number) => ColorizeType;
150
+ declare const bgAnsi256: (code: number) => ColorizeType;
151
+ declare const bgHex: (color: ColorValueHex) => ColorizeType;
152
+ declare const bgRgb: (red: number, green: number, blue: number) => ColorizeType;
153
+ declare const fg: (code: number) => ColorizeType;
154
+ declare const hex: (color: ColorValueHex) => ColorizeType;
155
+ declare const rgb: (red: number, green: number, blue: number) => ColorizeType;
156
+ declare const strip: (string: string) => string;
157
+ declare const bgBlack: ColorizeType;
158
+ declare const bgBlackBright: ColorizeType;
159
+ declare const bgBlue: ColorizeType;
160
+ declare const bgBlueBright: ColorizeType;
161
+ declare const bgCyan: ColorizeType;
162
+ declare const bgCyanBright: ColorizeType;
163
+ declare const bgGray: ColorizeType;
164
+ declare const bgGreen: ColorizeType;
165
+ declare const bgGreenBright: ColorizeType;
166
+ declare const bgGrey: ColorizeType;
167
+ declare const bgMagenta: ColorizeType;
168
+ declare const bgMagentaBright: ColorizeType;
169
+ declare const bgRed: ColorizeType;
170
+ declare const bgRedBright: ColorizeType;
171
+ declare const bgWhite: ColorizeType;
172
+ declare const bgWhiteBright: ColorizeType;
173
+ declare const bgYellow: ColorizeType;
174
+ declare const bgYellowBright: ColorizeType;
175
+ declare const black: ColorizeType;
176
+ declare const blackBright: ColorizeType;
177
+ declare const blue: ColorizeType;
178
+ declare const blueBright: ColorizeType;
179
+ declare const bold: ColorizeType;
180
+ declare const cyan: ColorizeType;
181
+ declare const cyanBright: ColorizeType;
182
+ declare const dim: ColorizeType;
183
+ declare const gray: ColorizeType;
184
+ declare const green: ColorizeType;
185
+ declare const greenBright: ColorizeType;
186
+ declare const grey: ColorizeType;
187
+ declare const hidden: ColorizeType;
188
+ declare const inverse: ColorizeType;
189
+ declare const italic: ColorizeType;
190
+ declare const magenta: ColorizeType;
191
+ declare const magentaBright: ColorizeType;
192
+ declare const overline: ColorizeType;
193
+ declare const red: ColorizeType;
194
+ declare const redBright: ColorizeType;
195
+ declare const reset: ColorizeType;
196
+ declare const strike: ColorizeType;
197
+ declare const strikethrough: ColorizeType;
198
+ declare const underline: ColorizeType;
199
+ declare const visible: ColorizeType;
200
+ declare const white: ColorizeType;
201
+ declare const whiteBright: ColorizeType;
202
+ declare const yellow: ColorizeType;
203
+ declare const yellowBright: ColorizeType;
204
+ export { type AnsiColors, type AnsiStyles, WebColorize as Colorize, type ColorizeType, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, colorize as default, dim, fg, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, strip, underline, visible, white, whiteBright, yellow, yellowBright };
@@ -1,61 +1 @@
1
- import WebColorize from './packem_shared/Colorize-BQ-Wlgs0.js';
2
-
3
- const colorize = new WebColorize();
4
- const ansi256 = colorize.ansi256;
5
- const bg = colorize.bg;
6
- const bgAnsi256 = colorize.bgAnsi256;
7
- const bgHex = colorize.bgHex;
8
- const bgRgb = colorize.bgRgb;
9
- const fg = colorize.fg;
10
- const hex = colorize.hex;
11
- const rgb = colorize.rgb;
12
- const strip = colorize.strip;
13
- const bgBlack = colorize.bgBlack;
14
- const bgBlackBright = colorize.bgBlackBright;
15
- const bgBlue = colorize.bgBlue;
16
- const bgBlueBright = colorize.bgBlueBright;
17
- const bgCyan = colorize.bgCyan;
18
- const bgCyanBright = colorize.bgCyanBright;
19
- const bgGray = colorize.bgGray;
20
- const bgGreen = colorize.bgGreen;
21
- const bgGreenBright = colorize.bgGreenBright;
22
- const bgGrey = colorize.bgGrey;
23
- const bgMagenta = colorize.bgMagenta;
24
- const bgMagentaBright = colorize.bgMagentaBright;
25
- const bgRed = colorize.bgRed;
26
- const bgRedBright = colorize.bgRedBright;
27
- const bgWhite = colorize.bgWhite;
28
- const bgWhiteBright = colorize.bgWhiteBright;
29
- const bgYellow = colorize.bgYellow;
30
- const bgYellowBright = colorize.bgYellowBright;
31
- const black = colorize.black;
32
- const blackBright = colorize.blackBright;
33
- const blue = colorize.blue;
34
- const blueBright = colorize.blueBright;
35
- const bold = colorize.bold;
36
- const cyan = colorize.cyan;
37
- const cyanBright = colorize.cyanBright;
38
- const dim = colorize.dim;
39
- const gray = colorize.gray;
40
- const green = colorize.green;
41
- const greenBright = colorize.greenBright;
42
- const grey = colorize.grey;
43
- const hidden = colorize.hidden;
44
- const inverse = colorize.inverse;
45
- const italic = colorize.italic;
46
- const magenta = colorize.magenta;
47
- const magentaBright = colorize.magentaBright;
48
- const overline = colorize.overline;
49
- const red = colorize.red;
50
- const redBright = colorize.redBright;
51
- const reset = colorize.reset;
52
- const strike = colorize.strike;
53
- const strikethrough = colorize.strikethrough;
54
- const underline = colorize.underline;
55
- const visible = colorize.visible;
56
- const white = colorize.white;
57
- const whiteBright = colorize.whiteBright;
58
- const yellow = colorize.yellow;
59
- const yellowBright = colorize.yellowBright;
60
-
61
- export { WebColorize as Colorize, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, colorize as default, dim, fg, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, strip, underline, visible, white, whiteBright, yellow, yellowBright };
1
+ import e from"./packem_shared/Colorize-i0NybjSp.js";const g=new e,i=g.ansi256,t=g.bg,b=g.bgAnsi256,h=g.bgHex,l=g.bgRgb,a=g.fg,n=g.hex,B=g.rgb,o=g.strip,s=g.bgBlack,y=g.bgBlackBright,d=g.bgBlue,c=g.bgBlueBright,u=g.bgCyan,w=g.bgCyanBright,k=g.bgGray,m=g.bgGreen,G=g.bgGreenBright,v=g.bgGrey,R=g.bgMagenta,x=g.bgMagentaBright,C=g.bgRed,f=g.bgRedBright,p=g.bgWhite,M=g.bgWhiteBright,W=g.bgYellow,Y=g.bgYellowBright,A=g.black,H=g.blackBright,j=g.blue,z=g.blueBright,q=g.bold,D=g.cyan,E=g.cyanBright,F=g.dim,I=g.gray,J=g.green,K=g.greenBright,L=g.grey,N=g.hidden,O=g.inverse,P=g.italic,Q=g.magenta,S=g.magentaBright,T=g.overline,U=g.red,V=g.redBright,X=g.reset,Z=g.strike,_=g.strikethrough,$=g.underline,gg=g.visible,eg=g.white,rg=g.whiteBright,ig=g.yellow,tg=g.yellowBright;export{e as Colorize,i as ansi256,t as bg,b as bgAnsi256,s as bgBlack,y as bgBlackBright,d as bgBlue,c as bgBlueBright,u as bgCyan,w as bgCyanBright,k as bgGray,m as bgGreen,G as bgGreenBright,v as bgGrey,h as bgHex,R as bgMagenta,x as bgMagentaBright,C as bgRed,f as bgRedBright,l as bgRgb,p as bgWhite,M as bgWhiteBright,W as bgYellow,Y as bgYellowBright,A as black,H as blackBright,j as blue,z as blueBright,q as bold,D as cyan,E as cyanBright,g as default,F as dim,a as fg,I as gray,J as green,K as greenBright,L as grey,n as hex,N as hidden,O as inverse,P as italic,Q as magenta,S as magentaBright,T as overline,U as red,V as redBright,X as reset,B as rgb,Z as strike,_ as strikethrough,o as strip,$ as underline,gg as visible,eg as white,rg as whiteBright,ig as yellow,tg as yellowBright};
@@ -1,255 +1,2 @@
1
- 'use strict';
2
-
3
- const isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
4
-
5
- function ansiRegex({ onlyFirst = false } = {}) {
6
- const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
7
- const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
8
- const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
9
- const pattern = `${osc}|${csi}`;
10
- return new RegExp(pattern, onlyFirst ? void 0 : "g");
11
- }
12
-
13
- const clamp = (number_, min, max) => {
14
- if (min > number_) {
15
- return min;
16
- }
17
- return Math.min(number_, max);
18
- };
19
-
20
- const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
21
- const convertHexToRgb = (hex) => {
22
- let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
23
- const colorLength = color ? color.length : 0;
24
- if (colorLength === 3) {
25
- const c0 = color.charAt(0);
26
- const c1 = color.charAt(1);
27
- const c2 = color.charAt(2);
28
- color = c0 + c0 + c1 + c1 + c2 + c2;
29
- } else if (colorLength !== 6) {
30
- return [0, 0, 0];
31
- }
32
- const colorNumber = Number.parseInt(color, 16);
33
- return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
34
- };
35
-
36
- const rgbToAnsi256 = (r, g, b) => {
37
- if (r === g && g === b) {
38
- if (r < 8) {
39
- return 16;
40
- }
41
- if (r > 248) {
42
- return 231;
43
- }
44
- return Math.round((r - 8) / 247 * 24) + 232;
45
- }
46
- return 16 + 36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
47
- };
48
- const ansi256To16 = (code) => {
49
- let r;
50
- let g;
51
- let b;
52
- if (code < 8) {
53
- return 30 + code;
54
- }
55
- if (code < 16) {
56
- return 90 + (code - 8);
57
- }
58
- if (code >= 232) {
59
- r = g = b = ((code - 232) * 10 + 8) / 255;
60
- } else {
61
- code -= 16;
62
- const remainder = code % 36;
63
- r = Math.floor(code / 36) / 5;
64
- g = Math.floor(remainder / 6) / 5;
65
- b = remainder % 6 / 5;
66
- }
67
- const value = Math.max(r, g, b) * 2;
68
- if (value === 0) {
69
- return 30;
70
- }
71
- const code16 = 30 + (Math.round(b) << 2 | Math.round(g) << 1 | Math.round(r));
72
- return value === 2 ? code16 + 60 : code16;
73
- };
74
- const rgbToAnsi16 = (r, g, b) => ansi256To16(rgbToAnsi256(r, g, b));
75
-
76
- const closeCode = 39;
77
- const bgCloseCode = 49;
78
- const bgOffset = 10;
79
- const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
80
- const mono = { close: "", open: "" };
81
- const esc = supportedColor > 0 ? (open, close) => {
82
- return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
83
- } : () => mono;
84
- const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
85
- const createHexFunction = (function_) => (hex) => {
86
- const [r, g, b] = convertHexToRgb(hex);
87
- return function_(r, g, b);
88
- };
89
- let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
90
- let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
91
- let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
92
- let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
93
- if (supportedColor === 1) {
94
- createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
95
- createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
96
- createRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)), closeCode);
97
- createBgRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)) + bgOffset, bgCloseCode);
98
- } else if (supportedColor === 2) {
99
- createRgb = createRgbFunction(createAnsi256);
100
- createBgRgb = createRgbFunction(createBgAnsi256);
101
- }
102
- const baseStyles = {
103
- // 21 isn't widely supported and 22 does the same thing
104
- bold: esc(1, 22),
105
- dim: esc(2, 22),
106
- hidden: esc(8, 28),
107
- inverse: esc(7, 27),
108
- italic: esc(3, 23),
109
- overline: esc(53, 55),
110
- reset: esc(0, 0),
111
- strike: esc(9, 29),
112
- // alias for strikethrough
113
- strikethrough: esc(9, 29),
114
- underline: esc(4, 24),
115
- visible: mono
116
- };
117
- const baseColors = {
118
- bgBlack: esc(40, bgCloseCode),
119
- bgBlackBright: esc(100, bgCloseCode),
120
- bgBlue: esc(44, bgCloseCode),
121
- bgBlueBright: esc(104, bgCloseCode),
122
- bgCyan: esc(46, bgCloseCode),
123
- bgCyanBright: esc(106, bgCloseCode),
124
- bgGray: esc(100, bgCloseCode),
125
- // US spelling alias for bgBlackBright
126
- bgGreen: esc(42, bgCloseCode),
127
- bgGreenBright: esc(102, bgCloseCode),
128
- bgGrey: esc(100, bgCloseCode),
129
- // UK spelling alias for bgBlackBright
130
- bgMagenta: esc(45, bgCloseCode),
131
- bgMagentaBright: esc(105, bgCloseCode),
132
- bgRed: esc(41, bgCloseCode),
133
- bgRedBright: esc(101, bgCloseCode),
134
- bgWhite: esc(47, bgCloseCode),
135
- bgWhiteBright: esc(107, bgCloseCode),
136
- bgYellow: esc(43, bgCloseCode),
137
- bgYellowBright: esc(103, bgCloseCode),
138
- black: esc(30, closeCode),
139
- blackBright: esc(90, closeCode),
140
- blue: esc(34, closeCode),
141
- blueBright: esc(94, closeCode),
142
- cyan: esc(36, closeCode),
143
- cyanBright: esc(96, closeCode),
144
- gray: esc(90, closeCode),
145
- // US spelling alias for blackBright
146
- green: esc(32, closeCode),
147
- greenBright: esc(92, closeCode),
148
- grey: esc(90, closeCode),
149
- // UK spelling alias for blackBright
150
- magenta: esc(35, closeCode),
151
- magentaBright: esc(95, closeCode),
152
- red: esc(31, closeCode),
153
- redBright: esc(91, closeCode),
154
- white: esc(37, closeCode),
155
- whiteBright: esc(97, closeCode),
156
- yellow: esc(33, closeCode),
157
- yellowBright: esc(93, closeCode)
158
- };
159
- const styleMethods = {
160
- bg: (code) => createBgAnsi256(clamp(code, 0, 255)),
161
- bgHex: createHexFunction(createBgRgb),
162
- bgRgb: (r, g, b) => createBgRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)),
163
- fg: (code) => createAnsi256(clamp(code, 0, 255)),
164
- hex: createHexFunction(createRgb),
165
- rgb: (r, g, b) => createRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255))
166
- };
167
-
168
- const stringReplaceAll = (string_, searchValue, replaceValue) => {
169
- if (searchValue === "") {
170
- return string_;
171
- }
172
- let pos = string_.indexOf(searchValue);
173
- if (pos < 0) {
174
- return string_;
175
- }
176
- const substringLength = searchValue.length;
177
- let lastPos = 0;
178
- let result = "";
179
- while (~pos) {
180
- result += string_.slice(lastPos, pos) + replaceValue;
181
- lastPos = pos + substringLength;
182
- pos = string_.indexOf(searchValue, lastPos);
183
- }
184
- return result + string_.slice(lastPos);
185
- };
186
-
187
- const styles = {};
188
- let stylePrototype = null;
189
- const wrapText = (strings, values, properties) => {
190
- if (!strings) {
191
- return "";
192
- }
193
- let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
194
- if (string.includes("\x1B")) {
195
- for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
196
- string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
197
- }
198
- }
199
- if (string.includes("\n")) {
200
- string = string.replace(/(\r*\n)/g, `${properties.closeStack}$1${properties.openStack}`);
201
- }
202
- return properties.openStack + string + properties.closeStack;
203
- };
204
- const createStyle = ({ props }, { close, open }) => {
205
- const openStack = (props?.openStack ?? "") + open;
206
- const closeStack = close + (props?.closeStack ?? "");
207
- const style = (strings, ...values) => wrapText(strings, values, style.props);
208
- Object.setPrototypeOf(style, stylePrototype);
209
- style.props = { close, closeStack, open, openStack, props };
210
- style.open = openStack;
211
- style.close = closeStack;
212
- return style;
213
- };
214
- const Colorize = function() {
215
- const self = (string_) => String(string_);
216
- self.strip = (value) => value.replaceAll(ansiRegex(), "");
217
- for (const name in baseColors) {
218
- styles[name] = {
219
- get() {
220
- const style = createStyle(this, baseColors[name]);
221
- Object.defineProperty(this, name, { value: style });
222
- return style;
223
- }
224
- };
225
- }
226
- for (const name in baseStyles) {
227
- styles[name] = {
228
- get() {
229
- const style = createStyle(this, baseStyles[name]);
230
- Object.defineProperty(this, name, { value: style });
231
- return style;
232
- }
233
- };
234
- }
235
- stylePrototype = Object.defineProperties({}, styles);
236
- Object.setPrototypeOf(self, stylePrototype);
237
- return self;
238
- };
239
- for (const name in styleMethods) {
240
- styles[name] = {
241
- get() {
242
- return (...arguments_) => (
243
- // @ts-expect-error: TODO: fix typing of `arguments_`
244
- createStyle(this, styleMethods[name](...arguments_))
245
- );
246
- }
247
- };
248
- }
249
- styles.ansi256 = styles.fg;
250
- styles.bgAnsi256 = styles.bg;
251
-
252
- const colorize = new Colorize();
253
- colorize.Colorize = Colorize;
254
-
255
- module.exports = colorize;
1
+ "use strict";var F=Object.defineProperty;var u=(e,r)=>F(e,"name",{value:r,configurable:!0});const q=require("@visulima/is-ansi-color-supported");var z=Object.defineProperty,W=u((e,r)=>z(e,"name",{value:r,configurable:!0}),"e$2");function N({onlyFirst:e=!1}={}){const r="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(r,e?void 0:"g")}u(N,"t$1");W(N,"ansiRegex");var Y=Object.defineProperty,D=u((e,r)=>Y(e,"name",{value:r,configurable:!0}),"n$1");const b=D((e,r,n)=>r>e?r:Math.min(e,n),"clamp");var E=Object.defineProperty,I=u((e,r)=>E(e,"name",{value:r,configurable:!0}),"a$1");const Z=/([a-f\d]{3,6})/i,J=I(e=>{let[,r]=Z.exec(e)??[];const n=r?r.length:0;if(n===3){const c=r.charAt(0),g=r.charAt(1),l=r.charAt(2);r=c+c+g+g+l+l}else if(n!==6)return[0,0,0];const o=Number.parseInt(r,16);return[o>>16&255,o>>8&255,o&255]},"convertHexToRgb");var K=Object.defineProperty,A=u((e,r)=>K(e,"name",{value:r,configurable:!0}),"e$1");const w=A((e,r,n)=>e===r&&r===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/51)+6*Math.round(r/51)+Math.round(n/51),"rgbToAnsi256"),B=A(e=>{let r,n,o;if(e<8)return 30+e;if(e<16)return 90+(e-8);if(e>=232)r=n=o=((e-232)*10+8)/255;else{e-=16;const l=e%36;r=Math.floor(e/36)/5,n=Math.floor(l/6)/5,o=l%6/5}const c=Math.max(r,n,o)*2;if(c===0)return 30;const g=30+(Math.round(o)<<2|Math.round(n)<<1|Math.round(r));return c===2?g+60:g},"ansi256To16"),x=A((e,r,n)=>B(w(e,r,n)),"rgbToAnsi16");var L=Object.defineProperty,s=u((e,r)=>L(e,"name",{value:r,configurable:!0}),"b");const i=39,a=49,O=10,m=q.isStdoutColorSupported(),T={close:"",open:""},t=m>0?(e,r)=>({close:`\x1B[${String(r)}m`,open:`\x1B[${String(e)}m`}):()=>T,R=s(e=>(r,n,o)=>e(w(Number(r),Number(n),Number(o))),"createRgbFunction"),k=s(e=>r=>{const[n,o,c]=J(r);return e(n,o,c)},"createHexFunction");let v=s(e=>t(`38;5;${String(e)}`,i),"createAnsi256"),S=s(e=>t(`48;5;${String(e)}`,a),"createBgAnsi256"),h=s((e,r,n)=>t(`38;2;${String(e)};${String(r)};${String(n)}`,i),"createRgb"),d=s((e,r,n)=>t(`48;2;${String(e)};${String(r)};${String(n)}`,a),"createBgRgb");m===1?(v=s(e=>t(B(Number(e)),i),"createAnsi256"),S=s(e=>t(B(Number(e))+O,a),"createBgAnsi256"),h=s((e,r,n)=>t(x(Number(e),Number(r),Number(n)),i),"createRgb"),d=s((e,r,n)=>t(x(Number(e),Number(r),Number(n))+O,a),"createBgRgb")):m===2&&(h=R(v),d=R(S));const M={bold:t(1,22),dim:t(2,22),hidden:t(8,28),inverse:t(7,27),italic:t(3,23),overline:t(53,55),reset:t(0,0),strike:t(9,29),strikethrough:t(9,29),underline:t(4,24),visible:T},P={bgBlack:t(40,a),bgBlackBright:t(100,a),bgBlue:t(44,a),bgBlueBright:t(104,a),bgCyan:t(46,a),bgCyanBright:t(106,a),bgGray:t(100,a),bgGreen:t(42,a),bgGreenBright:t(102,a),bgGrey:t(100,a),bgMagenta:t(45,a),bgMagentaBright:t(105,a),bgRed:t(41,a),bgRedBright:t(101,a),bgWhite:t(47,a),bgWhiteBright:t(107,a),bgYellow:t(43,a),bgYellowBright:t(103,a),black:t(30,i),blackBright:t(90,i),blue:t(34,i),blueBright:t(94,i),cyan:t(36,i),cyanBright:t(96,i),gray:t(90,i),green:t(32,i),greenBright:t(92,i),grey:t(90,i),magenta:t(35,i),magentaBright:t(95,i),red:t(31,i),redBright:t(91,i),white:t(37,i),whiteBright:t(97,i),yellow:t(33,i),yellowBright:t(93,i)},j={bg:s(e=>S(b(e,0,255)),"bg"),bgHex:k(d),bgRgb:s((e,r,n)=>d(b(e,0,255),b(r,0,255),b(n,0,255)),"bgRgb"),fg:s(e=>v(b(e,0,255)),"fg"),hex:k(h),rgb:s((e,r,n)=>h(b(e,0,255),b(r,0,255),b(n,0,255)),"rgb")};var Q=Object.defineProperty,U=u((e,r)=>Q(e,"name",{value:r,configurable:!0}),"s");const V=U((e,r,n)=>{if(r==="")return e;let o=e.indexOf(r);if(o<0)return e;const c=r.length;let g=0,l="";for(;~o;)l+=e.slice(g,o)+n,g=o+c,o=e.indexOf(r,g);return l+e.slice(g)},"stringReplaceAll");var X=Object.defineProperty,p=u((e,r)=>X(e,"name",{value:r,configurable:!0}),"a");const f={};let y=null;const _=p((e,r,n)=>{if(!e)return"";let o;if(e.raw===void 0?o=String(e):o=String.raw(e,...r),o.includes("\x1B"))for(let c=n;c;c=c.props)o=V(o,c.close,c.open);return o.includes(`
2
+ `)&&(o=o.replace(/(\r*\n)/g,`${n.closeStack}$1${n.openStack}`)),n.openStack+o+n.closeStack},"wrapText"),$=p(({props:e},{close:r,open:n})=>{const o=(e?.openStack??"")+n,c=r+(e?.closeStack??""),g=p((l,...H)=>_(l,H,g.props),"style");return Object.setPrototypeOf(g,y),g.props={close:r,closeStack:c,open:n,openStack:o,props:e},g.open=o,g.close=c,g},"createStyle"),C=p(function(){const e=p(r=>String(r),"self");e.strip=r=>r.replaceAll(N(),"");for(const r in P)f[r]={get(){const n=$(this,P[r]);return Object.defineProperty(this,r,{value:n}),n}};for(const r in M)f[r]={get(){const n=$(this,M[r]);return Object.defineProperty(this,r,{value:n}),n}};return y=Object.defineProperties({},f),Object.setPrototypeOf(e,y),e},"Colorize");for(const e in j)f[e]={get(){return(...r)=>$(this,j[e](...r))}};f.ansi256=f.fg;f.bgAnsi256=f.bg;const G=new C;G.Colorize=C;module.exports=G;
@@ -1,8 +1,14 @@
1
- import ColorizeImpl from "./colorize.d.cts";
2
- import type { ColorizeType } from "./types.d.cts";
3
- type ColorizeTypeWithColorize = ColorizeType & {
4
- Colorize: typeof ColorizeImpl;
1
+ // @ts-ignore
2
+ colorize;
3
+ export type { AnsiColors, AnsiStyles, ColorizeType };
4
+ declare namespace colorize {
5
+ export type ColorValueHex = `#${string}`;
6
+ export const Colorize: new () => ColorizeType;
7
+ export type ColorizeTypeWithColorize = ColorizeType & {
8
+ Colorize: typeof Colorize;
5
9
  };
6
- declare const colorize: ColorizeTypeWithColorize;
10
+ export const colorize: ColorizeTypeWithColorize;
11
+ import _default = colorize;
12
+ export { _default as default };
13
+ }
7
14
  export = colorize;
8
- export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.cts";