@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.
- package/CHANGELOG.md +20 -0
- package/dist/gradient.cjs +3 -62
- package/dist/gradient.d.cts +21 -12
- package/dist/gradient.d.mts +21 -12
- package/dist/gradient.d.ts +21 -12
- package/dist/gradient.mjs +3 -56
- package/dist/index.browser.d.mts +203 -60
- package/dist/index.browser.d.ts +204 -0
- package/dist/index.browser.mjs +1 -61
- package/dist/index.server.cjs +2 -255
- package/dist/index.server.d.cts +12 -6
- package/dist/index.server.d.mts +203 -60
- package/dist/index.server.d.ts +12 -6
- package/dist/index.server.mjs +1 -61
- package/dist/packem_shared/Colorize-BUAQi0t0.js +2 -0
- package/dist/packem_shared/Colorize-i0NybjSp.js +1 -0
- package/dist/packem_shared/GradientBuilder-CudosKb8.cjs +1 -0
- package/dist/packem_shared/GradientBuilder-Du8WSL23.mjs +1 -0
- package/dist/packem_shared/colorize.server-BkQZGeaS.mjs +2 -0
- package/dist/packem_shared/colorize.server-Dn-gV0MN.cjs +2 -0
- package/dist/packem_shared/convertHexToRgb-CJNE3k_E.mjs +1 -0
- package/dist/packem_shared/convertHexToRgb-Dvalc5FD.cjs +1 -0
- package/dist/packem_shared/rgbToAnsi256--f09kvlF.cjs +1 -0
- package/dist/packem_shared/rgbToAnsi256-YETEPW8R.mjs +1 -0
- package/dist/packem_shared/types.d-bhP-2hCu.d.cts +154 -0
- package/dist/packem_shared/types.d-bhP-2hCu.d.mts +154 -0
- package/dist/packem_shared/types.d-bhP-2hCu.d.ts +154 -0
- package/dist/template.cjs +2 -152
- package/dist/template.d.cts +10 -4
- package/dist/template.d.mts +4 -4
- package/dist/template.d.ts +10 -4
- package/dist/template.mjs +2 -146
- package/dist/utils.cjs +1 -13
- package/dist/utils.d.cts +13 -2
- package/dist/utils.d.mts +13 -2
- package/dist/utils.d.ts +13 -2
- package/dist/utils.mjs +1 -2
- package/package.json +47 -47
- package/dist/ansi-codes.d.cts +0 -18
- package/dist/ansi-codes.d.mts +0 -18
- package/dist/ansi-codes.d.ts +0 -18
- package/dist/colorize.browser.d.mts +0 -3
- package/dist/colorize.server.d.cts +0 -10
- package/dist/colorize.server.d.mts +0 -10
- package/dist/colorize.server.d.ts +0 -10
- package/dist/css-code.d.mts +0 -11
- package/dist/gradient/gradient-builder.d.cts +0 -10
- package/dist/gradient/gradient-builder.d.mts +0 -10
- package/dist/gradient/gradient-builder.d.ts +0 -10
- package/dist/gradient/util/color-names.d.cts +0 -2
- package/dist/gradient/util/color-names.d.mts +0 -2
- package/dist/gradient/util/color-names.d.ts +0 -2
- package/dist/gradient/util/compute.d.cts +0 -2
- package/dist/gradient/util/compute.d.mts +0 -2
- package/dist/gradient/util/compute.d.ts +0 -2
- package/dist/gradient/util/hsv-to-rgb.d.cts +0 -5
- package/dist/gradient/util/hsv-to-rgb.d.mts +0 -5
- package/dist/gradient/util/hsv-to-rgb.d.ts +0 -5
- package/dist/gradient/util/interpolate.d.cts +0 -3
- package/dist/gradient/util/interpolate.d.mts +0 -3
- package/dist/gradient/util/interpolate.d.ts +0 -3
- package/dist/gradient/util/rgb-to-hsv.d.cts +0 -9
- package/dist/gradient/util/rgb-to-hsv.d.mts +0 -9
- package/dist/gradient/util/rgb-to-hsv.d.ts +0 -9
- package/dist/packem_shared/Colorize-BQ-Wlgs0.js +0 -409
- package/dist/packem_shared/Colorize-rJUN0RFg.js +0 -250
- package/dist/packem_shared/GradientBuilder-CkX4Imo9.mjs +0 -483
- package/dist/packem_shared/GradientBuilder-DRrwebdU.cjs +0 -487
- package/dist/packem_shared/colorize.server-CwTmhs0e.cjs +0 -198
- package/dist/packem_shared/colorize.server-YxoHIDUp.mjs +0 -196
- package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +0 -21
- package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +0 -17
- package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +0 -41
- package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +0 -47
- package/dist/template/make-colorize-template.d.cts +0 -9
- package/dist/template/make-colorize-template.d.mts +0 -9
- package/dist/template/make-colorize-template.d.ts +0 -9
- package/dist/template/make-template.d.cts +0 -10
- package/dist/template/make-template.d.mts +0 -10
- package/dist/template/make-template.d.ts +0 -10
- package/dist/types.d.cts +0 -174
- package/dist/types.d.mts +0 -174
- package/dist/types.d.ts +0 -174
- package/dist/util/ansi-code-hex-map.d.mts +0 -8
- package/dist/util/clamp.d.cts +0 -12
- package/dist/util/clamp.d.mts +0 -12
- package/dist/util/clamp.d.ts +0 -12
- package/dist/util/convert-hex-to-rgb.d.cts +0 -8
- package/dist/util/convert-hex-to-rgb.d.mts +0 -8
- package/dist/util/convert-hex-to-rgb.d.ts +0 -8
- package/dist/util/convert-rgb-to-ansi.d.cts +0 -18
- package/dist/util/convert-rgb-to-ansi.d.mts +0 -18
- package/dist/util/convert-rgb-to-ansi.d.ts +0 -18
- package/dist/util/string-replace-all.d.cts +0 -12
- package/dist/util/string-replace-all.d.mts +0 -12
- package/dist/util/string-replace-all.d.ts +0 -12
- package/dist/util/unescape.d.cts +0 -9
- package/dist/util/unescape.d.mts +0 -9
- package/dist/util/unescape.d.ts +0 -9
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
|
|
2
|
-
import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
|
|
3
|
-
import { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './rgbToAnsi256-BdS0fomP.mjs';
|
|
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 closeCode = 39;
|
|
21
|
-
const bgCloseCode = 49;
|
|
22
|
-
const bgOffset = 10;
|
|
23
|
-
const supportedColor = isStdoutColorSupported();
|
|
24
|
-
const mono = { close: "", open: "" };
|
|
25
|
-
const esc = supportedColor > 0 ? (open, close) => {
|
|
26
|
-
return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
|
|
27
|
-
} : () => mono;
|
|
28
|
-
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
29
|
-
const createHexFunction = (function_) => (hex) => {
|
|
30
|
-
const [r, g, b] = convertHexToRgb(hex);
|
|
31
|
-
return function_(r, g, b);
|
|
32
|
-
};
|
|
33
|
-
let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
|
|
34
|
-
let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
|
|
35
|
-
let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
|
|
36
|
-
let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
|
|
37
|
-
if (supportedColor === 1) {
|
|
38
|
-
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
39
|
-
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
40
|
-
createRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)), closeCode);
|
|
41
|
-
createBgRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)) + bgOffset, bgCloseCode);
|
|
42
|
-
} else if (supportedColor === 2) {
|
|
43
|
-
createRgb = createRgbFunction(createAnsi256);
|
|
44
|
-
createBgRgb = createRgbFunction(createBgAnsi256);
|
|
45
|
-
}
|
|
46
|
-
const baseStyles = {
|
|
47
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
48
|
-
bold: esc(1, 22),
|
|
49
|
-
dim: esc(2, 22),
|
|
50
|
-
hidden: esc(8, 28),
|
|
51
|
-
inverse: esc(7, 27),
|
|
52
|
-
italic: esc(3, 23),
|
|
53
|
-
overline: esc(53, 55),
|
|
54
|
-
reset: esc(0, 0),
|
|
55
|
-
strike: esc(9, 29),
|
|
56
|
-
// alias for strikethrough
|
|
57
|
-
strikethrough: esc(9, 29),
|
|
58
|
-
underline: esc(4, 24),
|
|
59
|
-
visible: mono
|
|
60
|
-
};
|
|
61
|
-
const baseColors = {
|
|
62
|
-
bgBlack: esc(40, bgCloseCode),
|
|
63
|
-
bgBlackBright: esc(100, bgCloseCode),
|
|
64
|
-
bgBlue: esc(44, bgCloseCode),
|
|
65
|
-
bgBlueBright: esc(104, bgCloseCode),
|
|
66
|
-
bgCyan: esc(46, bgCloseCode),
|
|
67
|
-
bgCyanBright: esc(106, bgCloseCode),
|
|
68
|
-
bgGray: esc(100, bgCloseCode),
|
|
69
|
-
// US spelling alias for bgBlackBright
|
|
70
|
-
bgGreen: esc(42, bgCloseCode),
|
|
71
|
-
bgGreenBright: esc(102, bgCloseCode),
|
|
72
|
-
bgGrey: esc(100, bgCloseCode),
|
|
73
|
-
// UK spelling alias for bgBlackBright
|
|
74
|
-
bgMagenta: esc(45, bgCloseCode),
|
|
75
|
-
bgMagentaBright: esc(105, bgCloseCode),
|
|
76
|
-
bgRed: esc(41, bgCloseCode),
|
|
77
|
-
bgRedBright: esc(101, bgCloseCode),
|
|
78
|
-
bgWhite: esc(47, bgCloseCode),
|
|
79
|
-
bgWhiteBright: esc(107, bgCloseCode),
|
|
80
|
-
bgYellow: esc(43, bgCloseCode),
|
|
81
|
-
bgYellowBright: esc(103, bgCloseCode),
|
|
82
|
-
black: esc(30, closeCode),
|
|
83
|
-
blackBright: esc(90, closeCode),
|
|
84
|
-
blue: esc(34, closeCode),
|
|
85
|
-
blueBright: esc(94, closeCode),
|
|
86
|
-
cyan: esc(36, closeCode),
|
|
87
|
-
cyanBright: esc(96, closeCode),
|
|
88
|
-
gray: esc(90, closeCode),
|
|
89
|
-
// US spelling alias for blackBright
|
|
90
|
-
green: esc(32, closeCode),
|
|
91
|
-
greenBright: esc(92, closeCode),
|
|
92
|
-
grey: esc(90, closeCode),
|
|
93
|
-
// UK spelling alias for blackBright
|
|
94
|
-
magenta: esc(35, closeCode),
|
|
95
|
-
magentaBright: esc(95, closeCode),
|
|
96
|
-
red: esc(31, closeCode),
|
|
97
|
-
redBright: esc(91, closeCode),
|
|
98
|
-
white: esc(37, closeCode),
|
|
99
|
-
whiteBright: esc(97, closeCode),
|
|
100
|
-
yellow: esc(33, closeCode),
|
|
101
|
-
yellowBright: esc(93, closeCode)
|
|
102
|
-
};
|
|
103
|
-
const styleMethods = {
|
|
104
|
-
bg: (code) => createBgAnsi256(clamp(code, 0, 255)),
|
|
105
|
-
bgHex: createHexFunction(createBgRgb),
|
|
106
|
-
bgRgb: (r, g, b) => createBgRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)),
|
|
107
|
-
fg: (code) => createAnsi256(clamp(code, 0, 255)),
|
|
108
|
-
hex: createHexFunction(createRgb),
|
|
109
|
-
rgb: (r, g, b) => createRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255))
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const stringReplaceAll = (string_, searchValue, replaceValue) => {
|
|
113
|
-
if (searchValue === "") {
|
|
114
|
-
return string_;
|
|
115
|
-
}
|
|
116
|
-
let pos = string_.indexOf(searchValue);
|
|
117
|
-
if (pos < 0) {
|
|
118
|
-
return string_;
|
|
119
|
-
}
|
|
120
|
-
const substringLength = searchValue.length;
|
|
121
|
-
let lastPos = 0;
|
|
122
|
-
let result = "";
|
|
123
|
-
while (~pos) {
|
|
124
|
-
result += string_.slice(lastPos, pos) + replaceValue;
|
|
125
|
-
lastPos = pos + substringLength;
|
|
126
|
-
pos = string_.indexOf(searchValue, lastPos);
|
|
127
|
-
}
|
|
128
|
-
return result + string_.slice(lastPos);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const styles = {};
|
|
132
|
-
let stylePrototype = null;
|
|
133
|
-
const wrapText = (strings, values, properties) => {
|
|
134
|
-
if (!strings) {
|
|
135
|
-
return "";
|
|
136
|
-
}
|
|
137
|
-
let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
|
|
138
|
-
if (string.includes("\x1B")) {
|
|
139
|
-
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
140
|
-
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (string.includes("\n")) {
|
|
144
|
-
string = string.replace(/(\r*\n)/g, `${properties.closeStack}$1${properties.openStack}`);
|
|
145
|
-
}
|
|
146
|
-
return properties.openStack + string + properties.closeStack;
|
|
147
|
-
};
|
|
148
|
-
const createStyle = ({ props }, { close, open }) => {
|
|
149
|
-
const openStack = (props?.openStack ?? "") + open;
|
|
150
|
-
const closeStack = close + (props?.closeStack ?? "");
|
|
151
|
-
const style = (strings, ...values) => wrapText(strings, values, style.props);
|
|
152
|
-
Object.setPrototypeOf(style, stylePrototype);
|
|
153
|
-
style.props = { close, closeStack, open, openStack, props };
|
|
154
|
-
style.open = openStack;
|
|
155
|
-
style.close = closeStack;
|
|
156
|
-
return style;
|
|
157
|
-
};
|
|
158
|
-
const Colorize = function() {
|
|
159
|
-
const self = (string_) => String(string_);
|
|
160
|
-
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
161
|
-
for (const name in baseColors) {
|
|
162
|
-
styles[name] = {
|
|
163
|
-
get() {
|
|
164
|
-
const style = createStyle(this, baseColors[name]);
|
|
165
|
-
Object.defineProperty(this, name, { value: style });
|
|
166
|
-
return style;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
for (const name in baseStyles) {
|
|
171
|
-
styles[name] = {
|
|
172
|
-
get() {
|
|
173
|
-
const style = createStyle(this, baseStyles[name]);
|
|
174
|
-
Object.defineProperty(this, name, { value: style });
|
|
175
|
-
return style;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
stylePrototype = Object.defineProperties({}, styles);
|
|
180
|
-
Object.setPrototypeOf(self, stylePrototype);
|
|
181
|
-
return self;
|
|
182
|
-
};
|
|
183
|
-
for (const name in styleMethods) {
|
|
184
|
-
styles[name] = {
|
|
185
|
-
get() {
|
|
186
|
-
return (...arguments_) => (
|
|
187
|
-
// @ts-expect-error: TODO: fix typing of `arguments_`
|
|
188
|
-
createStyle(this, styleMethods[name](...arguments_))
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
styles.ansi256 = styles.fg;
|
|
194
|
-
styles.bgAnsi256 = styles.bg;
|
|
195
|
-
|
|
196
|
-
export { Colorize as C };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
|
|
6
|
-
const convertHexToRgb = (hex) => {
|
|
7
|
-
let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
|
|
8
|
-
const colorLength = color ? color.length : 0;
|
|
9
|
-
if (colorLength === 3) {
|
|
10
|
-
const c0 = color.charAt(0);
|
|
11
|
-
const c1 = color.charAt(1);
|
|
12
|
-
const c2 = color.charAt(2);
|
|
13
|
-
color = c0 + c0 + c1 + c1 + c2 + c2;
|
|
14
|
-
} else if (colorLength !== 6) {
|
|
15
|
-
return [0, 0, 0];
|
|
16
|
-
}
|
|
17
|
-
const colorNumber = Number.parseInt(color, 16);
|
|
18
|
-
return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
exports.convertHexToRgb = convertHexToRgb;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
|
|
2
|
-
const convertHexToRgb = (hex) => {
|
|
3
|
-
let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
|
|
4
|
-
const colorLength = color ? color.length : 0;
|
|
5
|
-
if (colorLength === 3) {
|
|
6
|
-
const c0 = color.charAt(0);
|
|
7
|
-
const c1 = color.charAt(1);
|
|
8
|
-
const c2 = color.charAt(2);
|
|
9
|
-
color = c0 + c0 + c1 + c1 + c2 + c2;
|
|
10
|
-
} else if (colorLength !== 6) {
|
|
11
|
-
return [0, 0, 0];
|
|
12
|
-
}
|
|
13
|
-
const colorNumber = Number.parseInt(color, 16);
|
|
14
|
-
return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { convertHexToRgb };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const rgbToAnsi256 = (r, g, b) => {
|
|
2
|
-
if (r === g && g === b) {
|
|
3
|
-
if (r < 8) {
|
|
4
|
-
return 16;
|
|
5
|
-
}
|
|
6
|
-
if (r > 248) {
|
|
7
|
-
return 231;
|
|
8
|
-
}
|
|
9
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
10
|
-
}
|
|
11
|
-
return 16 + 36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
12
|
-
};
|
|
13
|
-
const ansi256To16 = (code) => {
|
|
14
|
-
let r;
|
|
15
|
-
let g;
|
|
16
|
-
let b;
|
|
17
|
-
if (code < 8) {
|
|
18
|
-
return 30 + code;
|
|
19
|
-
}
|
|
20
|
-
if (code < 16) {
|
|
21
|
-
return 90 + (code - 8);
|
|
22
|
-
}
|
|
23
|
-
if (code >= 232) {
|
|
24
|
-
r = g = b = ((code - 232) * 10 + 8) / 255;
|
|
25
|
-
} else {
|
|
26
|
-
code -= 16;
|
|
27
|
-
const remainder = code % 36;
|
|
28
|
-
r = Math.floor(code / 36) / 5;
|
|
29
|
-
g = Math.floor(remainder / 6) / 5;
|
|
30
|
-
b = remainder % 6 / 5;
|
|
31
|
-
}
|
|
32
|
-
const value = Math.max(r, g, b) * 2;
|
|
33
|
-
if (value === 0) {
|
|
34
|
-
return 30;
|
|
35
|
-
}
|
|
36
|
-
const code16 = 30 + (Math.round(b) << 2 | Math.round(g) << 1 | Math.round(r));
|
|
37
|
-
return value === 2 ? code16 + 60 : code16;
|
|
38
|
-
};
|
|
39
|
-
const rgbToAnsi16 = (r, g, b) => ansi256To16(rgbToAnsi256(r, g, b));
|
|
40
|
-
|
|
41
|
-
export { ansi256To16, rgbToAnsi16, rgbToAnsi256 };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const rgbToAnsi256 = (r, g, b) => {
|
|
6
|
-
if (r === g && g === b) {
|
|
7
|
-
if (r < 8) {
|
|
8
|
-
return 16;
|
|
9
|
-
}
|
|
10
|
-
if (r > 248) {
|
|
11
|
-
return 231;
|
|
12
|
-
}
|
|
13
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
14
|
-
}
|
|
15
|
-
return 16 + 36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
16
|
-
};
|
|
17
|
-
const ansi256To16 = (code) => {
|
|
18
|
-
let r;
|
|
19
|
-
let g;
|
|
20
|
-
let b;
|
|
21
|
-
if (code < 8) {
|
|
22
|
-
return 30 + code;
|
|
23
|
-
}
|
|
24
|
-
if (code < 16) {
|
|
25
|
-
return 90 + (code - 8);
|
|
26
|
-
}
|
|
27
|
-
if (code >= 232) {
|
|
28
|
-
r = g = b = ((code - 232) * 10 + 8) / 255;
|
|
29
|
-
} else {
|
|
30
|
-
code -= 16;
|
|
31
|
-
const remainder = code % 36;
|
|
32
|
-
r = Math.floor(code / 36) / 5;
|
|
33
|
-
g = Math.floor(remainder / 6) / 5;
|
|
34
|
-
b = remainder % 6 / 5;
|
|
35
|
-
}
|
|
36
|
-
const value = Math.max(r, g, b) * 2;
|
|
37
|
-
if (value === 0) {
|
|
38
|
-
return 30;
|
|
39
|
-
}
|
|
40
|
-
const code16 = 30 + (Math.round(b) << 2 | Math.round(g) << 1 | Math.round(r));
|
|
41
|
-
return value === 2 ? code16 + 60 : code16;
|
|
42
|
-
};
|
|
43
|
-
const rgbToAnsi16 = (r, g, b) => ansi256To16(rgbToAnsi256(r, g, b));
|
|
44
|
-
|
|
45
|
-
exports.ansi256To16 = ansi256To16;
|
|
46
|
-
exports.rgbToAnsi16 = rgbToAnsi16;
|
|
47
|
-
exports.rgbToAnsi256 = rgbToAnsi256;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
export declare const makeColorizeTemplate: (template: (text: string) => string) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
export declare const makeColorizeTemplate: (template: (text: string) => string) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
export declare const makeColorizeTemplate: (template: (text: string) => string) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
import type { ColorizeType } from "../types.d.cts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
import type { ColorizeType } from "../types.d.mts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified copy of https://github.com/chalk/chalk-template/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* MIT License
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Josh Junon
|
|
7
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
|
-
*/
|
|
9
|
-
import type { ColorizeType } from "../types.d.ts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
package/dist/types.d.cts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
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} 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
|
-
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
|
-
};
|