@visulima/colorize 1.4.25 → 1.4.27
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 +41 -1
- package/README.md +208 -12
- package/dist/gradient.cjs +60 -3
- package/dist/gradient.mjs +54 -3
- package/dist/index.browser.mjs +63 -1
- package/dist/index.server.cjs +249 -2
- package/dist/index.server.mjs +63 -1
- package/dist/packem_shared/Colorize-BenP3bFn.mjs +241 -0
- package/dist/packem_shared/Colorize-Ca9CXTcj.mjs +413 -0
- package/dist/packem_shared/GradientBuilder-Ba4Teq6P.mjs +487 -0
- package/dist/packem_shared/GradientBuilder-DjJK22kP.cjs +491 -0
- package/dist/packem_shared/colorize.server-BA3gZZXz.cjs +193 -0
- package/dist/packem_shared/colorize.server-ry9FZNfG.mjs +191 -0
- package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +13 -0
- package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +17 -0
- package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +41 -0
- package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +47 -0
- package/dist/template.cjs +144 -2
- package/dist/template.mjs +138 -2
- package/dist/utils.cjs +13 -1
- package/dist/utils.mjs +2 -1
- package/package.json +2 -2
- package/dist/packem_shared/Colorize-Bn8gI3ME.mjs +0 -1
- package/dist/packem_shared/Colorize-CfIXnDUD.mjs +0 -2
- package/dist/packem_shared/GradientBuilder-C2IS34v_.cjs +0 -1
- package/dist/packem_shared/GradientBuilder-I_j6wpvU.mjs +0 -1
- package/dist/packem_shared/ansi256To16--f09kvlF.cjs +0 -1
- package/dist/packem_shared/ansi256To16-YETEPW8R.mjs +0 -1
- package/dist/packem_shared/colorize.server-9hV-s1hY.mjs +0 -2
- package/dist/packem_shared/colorize.server-B0BWdm8_.cjs +0 -2
- package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +0 -1
- package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
|
|
2
|
+
import { convertHexToRgb } from './convertHexToRgb-CWdAm2kE.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) => min > number_ ? min : Math.min(number_, max);
|
|
14
|
+
|
|
15
|
+
const closeCode = 39;
|
|
16
|
+
const bgCloseCode = 49;
|
|
17
|
+
const bgOffset = 10;
|
|
18
|
+
const supportedColor = isStdoutColorSupported();
|
|
19
|
+
const mono = { close: "", open: "" };
|
|
20
|
+
const esc = supportedColor > 0 ? (open, close) => {
|
|
21
|
+
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
22
|
+
} : () => mono;
|
|
23
|
+
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
24
|
+
const createHexFunction = (function_) => (hex) => {
|
|
25
|
+
const [r, g, b] = convertHexToRgb(hex);
|
|
26
|
+
return function_(r, g, b);
|
|
27
|
+
};
|
|
28
|
+
let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
|
|
29
|
+
let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
|
|
30
|
+
let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
|
|
31
|
+
let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
|
|
32
|
+
if (supportedColor === 1) {
|
|
33
|
+
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
34
|
+
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
35
|
+
createRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)), closeCode);
|
|
36
|
+
createBgRgb = (r, g, b) => esc(rgbToAnsi16(Number(r), Number(g), Number(b)) + bgOffset, bgCloseCode);
|
|
37
|
+
} else if (supportedColor === 2) {
|
|
38
|
+
createRgb = createRgbFunction(createAnsi256);
|
|
39
|
+
createBgRgb = createRgbFunction(createBgAnsi256);
|
|
40
|
+
}
|
|
41
|
+
const baseStyles = {
|
|
42
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
43
|
+
bold: esc(1, 22),
|
|
44
|
+
dim: esc(2, 22),
|
|
45
|
+
hidden: esc(8, 28),
|
|
46
|
+
inverse: esc(7, 27),
|
|
47
|
+
italic: esc(3, 23),
|
|
48
|
+
overline: esc(53, 55),
|
|
49
|
+
reset: esc(0, 0),
|
|
50
|
+
strike: esc(9, 29),
|
|
51
|
+
// alias for strikethrough
|
|
52
|
+
strikethrough: esc(9, 29),
|
|
53
|
+
underline: esc(4, 24),
|
|
54
|
+
visible: mono
|
|
55
|
+
};
|
|
56
|
+
const baseColors = {
|
|
57
|
+
bgBlack: esc(40, bgCloseCode),
|
|
58
|
+
bgBlackBright: esc(100, bgCloseCode),
|
|
59
|
+
bgBlue: esc(44, bgCloseCode),
|
|
60
|
+
bgBlueBright: esc(104, bgCloseCode),
|
|
61
|
+
bgCyan: esc(46, bgCloseCode),
|
|
62
|
+
bgCyanBright: esc(106, bgCloseCode),
|
|
63
|
+
bgGray: esc(100, bgCloseCode),
|
|
64
|
+
// US spelling alias for bgBlackBright
|
|
65
|
+
bgGreen: esc(42, bgCloseCode),
|
|
66
|
+
bgGreenBright: esc(102, bgCloseCode),
|
|
67
|
+
bgGrey: esc(100, bgCloseCode),
|
|
68
|
+
// UK spelling alias for bgBlackBright
|
|
69
|
+
bgMagenta: esc(45, bgCloseCode),
|
|
70
|
+
bgMagentaBright: esc(105, bgCloseCode),
|
|
71
|
+
bgRed: esc(41, bgCloseCode),
|
|
72
|
+
bgRedBright: esc(101, bgCloseCode),
|
|
73
|
+
bgWhite: esc(47, bgCloseCode),
|
|
74
|
+
bgWhiteBright: esc(107, bgCloseCode),
|
|
75
|
+
bgYellow: esc(43, bgCloseCode),
|
|
76
|
+
bgYellowBright: esc(103, bgCloseCode),
|
|
77
|
+
black: esc(30, closeCode),
|
|
78
|
+
blackBright: esc(90, closeCode),
|
|
79
|
+
blue: esc(34, closeCode),
|
|
80
|
+
blueBright: esc(94, closeCode),
|
|
81
|
+
cyan: esc(36, closeCode),
|
|
82
|
+
cyanBright: esc(96, closeCode),
|
|
83
|
+
gray: esc(90, closeCode),
|
|
84
|
+
// US spelling alias for blackBright
|
|
85
|
+
green: esc(32, closeCode),
|
|
86
|
+
greenBright: esc(92, closeCode),
|
|
87
|
+
grey: esc(90, closeCode),
|
|
88
|
+
// UK spelling alias for blackBright
|
|
89
|
+
magenta: esc(35, closeCode),
|
|
90
|
+
magentaBright: esc(95, closeCode),
|
|
91
|
+
red: esc(31, closeCode),
|
|
92
|
+
redBright: esc(91, closeCode),
|
|
93
|
+
white: esc(37, closeCode),
|
|
94
|
+
whiteBright: esc(97, closeCode),
|
|
95
|
+
yellow: esc(33, closeCode),
|
|
96
|
+
yellowBright: esc(93, closeCode)
|
|
97
|
+
};
|
|
98
|
+
const styleMethods = {
|
|
99
|
+
bg: (code) => createBgAnsi256(clamp(code, 0, 255)),
|
|
100
|
+
bgHex: createHexFunction(createBgRgb),
|
|
101
|
+
bgRgb: (r, g, b) => createBgRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255)),
|
|
102
|
+
fg: (code) => createAnsi256(clamp(code, 0, 255)),
|
|
103
|
+
hex: createHexFunction(createRgb),
|
|
104
|
+
rgb: (r, g, b) => createRgb(clamp(r, 0, 255), clamp(g, 0, 255), clamp(b, 0, 255))
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const stringReplaceAll = (string_, searchValue, replaceValue) => {
|
|
108
|
+
if (searchValue === "") {
|
|
109
|
+
return string_;
|
|
110
|
+
}
|
|
111
|
+
let pos = string_.indexOf(searchValue);
|
|
112
|
+
if (pos < 0) {
|
|
113
|
+
return string_;
|
|
114
|
+
}
|
|
115
|
+
const substringLength = searchValue.length;
|
|
116
|
+
let lastPos = 0;
|
|
117
|
+
let result = "";
|
|
118
|
+
while (~pos) {
|
|
119
|
+
result += string_.slice(lastPos, pos) + replaceValue;
|
|
120
|
+
lastPos = pos + substringLength;
|
|
121
|
+
pos = string_.indexOf(searchValue, lastPos);
|
|
122
|
+
}
|
|
123
|
+
return result + string_.slice(lastPos);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const styles = {};
|
|
127
|
+
let stylePrototype = null;
|
|
128
|
+
const wrapText = (strings, values, properties) => {
|
|
129
|
+
if (!strings) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
|
|
133
|
+
if (string.includes("\x1B")) {
|
|
134
|
+
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
135
|
+
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (string.includes("\n")) {
|
|
139
|
+
string = string.replace(/(\r*\n)/g, `${properties.closeStack}$1${properties.openStack}`);
|
|
140
|
+
}
|
|
141
|
+
return properties.openStack + string + properties.closeStack;
|
|
142
|
+
};
|
|
143
|
+
const createStyle = ({ props }, { close, open }) => {
|
|
144
|
+
const openStack = (props?.openStack ?? "") + open;
|
|
145
|
+
const closeStack = close + (props?.closeStack ?? "");
|
|
146
|
+
const style = (strings, ...values) => wrapText(strings, values, style.props);
|
|
147
|
+
Object.setPrototypeOf(style, stylePrototype);
|
|
148
|
+
style.props = { close, closeStack, open, openStack, props };
|
|
149
|
+
style.open = openStack;
|
|
150
|
+
style.close = closeStack;
|
|
151
|
+
return style;
|
|
152
|
+
};
|
|
153
|
+
const Colorize = function() {
|
|
154
|
+
const self = (string_) => `${string_}`;
|
|
155
|
+
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
156
|
+
for (const name in baseColors) {
|
|
157
|
+
styles[name] = {
|
|
158
|
+
get() {
|
|
159
|
+
const style = createStyle(this, baseColors[name]);
|
|
160
|
+
Object.defineProperty(this, name, { value: style });
|
|
161
|
+
return style;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
for (const name in baseStyles) {
|
|
166
|
+
styles[name] = {
|
|
167
|
+
get() {
|
|
168
|
+
const style = createStyle(this, baseStyles[name]);
|
|
169
|
+
Object.defineProperty(this, name, { value: style });
|
|
170
|
+
return style;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
stylePrototype = Object.defineProperties({}, styles);
|
|
175
|
+
Object.setPrototypeOf(self, stylePrototype);
|
|
176
|
+
return self;
|
|
177
|
+
};
|
|
178
|
+
for (const name in styleMethods) {
|
|
179
|
+
styles[name] = {
|
|
180
|
+
get() {
|
|
181
|
+
return (...arguments_) => (
|
|
182
|
+
// @ts-expect-error: TODO: fix typing of `arguments_`
|
|
183
|
+
createStyle(this, styleMethods[name](...arguments_))
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
styles.ansi256 = styles.fg;
|
|
189
|
+
styles.bgAnsi256 = styles.bg;
|
|
190
|
+
|
|
191
|
+
export { Colorize as C };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const convertHexToRgb = (hex) => {
|
|
2
|
+
let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
|
|
3
|
+
const length_ = color ? color.length : 0;
|
|
4
|
+
if (length_ === 3) {
|
|
5
|
+
color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
|
|
6
|
+
} else if (length_ !== 6) {
|
|
7
|
+
return [0, 0, 0];
|
|
8
|
+
}
|
|
9
|
+
const number_ = Number.parseInt(color, 16);
|
|
10
|
+
return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { convertHexToRgb };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const convertHexToRgb = (hex) => {
|
|
6
|
+
let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
|
|
7
|
+
const length_ = color ? color.length : 0;
|
|
8
|
+
if (length_ === 3) {
|
|
9
|
+
color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
|
|
10
|
+
} else if (length_ !== 6) {
|
|
11
|
+
return [0, 0, 0];
|
|
12
|
+
}
|
|
13
|
+
const number_ = Number.parseInt(color, 16);
|
|
14
|
+
return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.convertHexToRgb = convertHexToRgb;
|
|
@@ -0,0 +1,41 @@
|
|
|
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 };
|
|
@@ -0,0 +1,47 @@
|
|
|
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;
|
package/dist/template.cjs
CHANGED
|
@@ -1,2 +1,144 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const colorize_server = require('./packem_shared/colorize.server-BA3gZZXz.cjs');
|
|
6
|
+
const convertHexToRgb = require('./packem_shared/convertHexToRgb-DvkHBM3-.cjs');
|
|
7
|
+
|
|
8
|
+
const makeColorizeTemplate = (template) => (firstString, ...arguments_) => {
|
|
9
|
+
if (!Array.isArray(firstString) || !Array.isArray(firstString.raw)) {
|
|
10
|
+
throw new TypeError("A tagged template literal must be provided");
|
|
11
|
+
}
|
|
12
|
+
const parts = [firstString.raw[0]];
|
|
13
|
+
for (let index = 1; index < firstString.raw.length; index++) {
|
|
14
|
+
parts.push(String(arguments_[index - 1]).replaceAll(/[{}\\]/g, String.raw`\$&`), String(firstString.raw[index]));
|
|
15
|
+
}
|
|
16
|
+
return template(parts.join(""));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ESCAPES = /* @__PURE__ */ new Map([
|
|
20
|
+
["0", "\0"],
|
|
21
|
+
["\\", "\\"],
|
|
22
|
+
["a", "\x07"],
|
|
23
|
+
["b", "\b"],
|
|
24
|
+
["e", "\x1B"],
|
|
25
|
+
["f", "\f"],
|
|
26
|
+
["n", "\n"],
|
|
27
|
+
["r", "\r"],
|
|
28
|
+
["t", " "],
|
|
29
|
+
["v", "\v"]
|
|
30
|
+
]);
|
|
31
|
+
const unescape = (c) => {
|
|
32
|
+
const u = c.startsWith("u");
|
|
33
|
+
const bracket = c[1] === "{";
|
|
34
|
+
if (u && !bracket && c.length === 5 || c.startsWith("x") && c.length === 3) {
|
|
35
|
+
return String.fromCodePoint(Number.parseInt(c.slice(1), 16));
|
|
36
|
+
}
|
|
37
|
+
if (u && bracket) {
|
|
38
|
+
return String.fromCodePoint(Number.parseInt(c.slice(2, -1), 16));
|
|
39
|
+
}
|
|
40
|
+
return ESCAPES.get(c) ?? c;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
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;
|
|
44
|
+
const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
|
|
45
|
+
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
46
|
+
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
47
|
+
const parseArguments = (name, value) => {
|
|
48
|
+
const results = [];
|
|
49
|
+
const chunks = value.trim().split(/\s*,\s*/);
|
|
50
|
+
let matches;
|
|
51
|
+
for (const chunk of chunks) {
|
|
52
|
+
const number = Number(chunk);
|
|
53
|
+
if (!Number.isNaN(number)) {
|
|
54
|
+
results.push(number);
|
|
55
|
+
} else if (matches = STRING_REGEX.exec(chunk)) {
|
|
56
|
+
results.push(matches[2].replace(ESCAPE_REGEX, (_, escape, character) => escape ? unescape(escape) : character));
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return results;
|
|
62
|
+
};
|
|
63
|
+
const parseStyle = (style) => {
|
|
64
|
+
STYLE_REGEX.lastIndex = 0;
|
|
65
|
+
const results = [];
|
|
66
|
+
let matches;
|
|
67
|
+
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
68
|
+
const name = matches[1];
|
|
69
|
+
if (matches[2]) {
|
|
70
|
+
results.push([name, ...parseArguments(name, matches[2])]);
|
|
71
|
+
} else if (matches[3] || matches[4]) {
|
|
72
|
+
if (matches[3]) {
|
|
73
|
+
results.push(["rgb", ...convertHexToRgb.convertHexToRgb(matches[3])]);
|
|
74
|
+
}
|
|
75
|
+
if (matches[4]) {
|
|
76
|
+
results.push(["bgRgb", ...convertHexToRgb.convertHexToRgb(matches[4])]);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
results.push([name]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return results;
|
|
83
|
+
};
|
|
84
|
+
const buildStyle = (colorize, styles) => {
|
|
85
|
+
const enabled = {};
|
|
86
|
+
for (const layer of styles) {
|
|
87
|
+
for (const style of layer.styles) {
|
|
88
|
+
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let current = colorize;
|
|
92
|
+
for (const [styleName, enabledStyles] of Object.entries(enabled)) {
|
|
93
|
+
if (!Array.isArray(enabledStyles)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!(styleName in current)) {
|
|
97
|
+
throw new Error(`Unknown style: ${styleName}`);
|
|
98
|
+
}
|
|
99
|
+
current = enabledStyles.length > 0 ? current[styleName](...enabledStyles) : current[styleName];
|
|
100
|
+
}
|
|
101
|
+
return current;
|
|
102
|
+
};
|
|
103
|
+
const makeTemplate = (colorize) => (string) => {
|
|
104
|
+
const styles = [];
|
|
105
|
+
const chunks = [];
|
|
106
|
+
let chunk = [];
|
|
107
|
+
string.replaceAll(
|
|
108
|
+
TEMPLATE_REGEX,
|
|
109
|
+
// @ts-expect-error - TS doesn't understand that the regex args are defined
|
|
110
|
+
(_, escapeCharacter, inverse, style, close, character) => {
|
|
111
|
+
if (escapeCharacter) {
|
|
112
|
+
chunk.push(unescape(escapeCharacter));
|
|
113
|
+
} else if (style) {
|
|
114
|
+
const joinedChunk = chunk.join("");
|
|
115
|
+
chunk = [];
|
|
116
|
+
chunks.push(styles.length === 0 ? joinedChunk : buildStyle(colorize, styles)(joinedChunk));
|
|
117
|
+
styles.push({ inverse, styles: parseStyle(style) });
|
|
118
|
+
} else if (close) {
|
|
119
|
+
if (styles.length === 0) {
|
|
120
|
+
throw new Error("Found extraneous } in template literal");
|
|
121
|
+
}
|
|
122
|
+
chunks.push(buildStyle(colorize, styles)(chunk.join("")));
|
|
123
|
+
chunk = [];
|
|
124
|
+
styles.pop();
|
|
125
|
+
} else {
|
|
126
|
+
chunk.push(character);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
chunks.push(chunk.join(""));
|
|
131
|
+
if (styles.length > 0) {
|
|
132
|
+
throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
|
|
133
|
+
}
|
|
134
|
+
return chunks.join("");
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const colorize = new colorize_server.Colorize();
|
|
138
|
+
const makeTaggedTemplate = (instance) => makeColorizeTemplate(makeTemplate(instance));
|
|
139
|
+
const template = makeTemplate(colorize);
|
|
140
|
+
const template$1 = makeColorizeTemplate(template);
|
|
141
|
+
|
|
142
|
+
module.exports = template$1;
|
|
143
|
+
module.exports.makeTaggedTemplate = makeTaggedTemplate;
|
|
144
|
+
module.exports.template = template;
|
package/dist/template.mjs
CHANGED
|
@@ -1,2 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 template$1 = makeColorizeTemplate(template);
|
|
137
|
+
|
|
138
|
+
export { template$1 as default, makeTaggedTemplate, template };
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const convertHexToRgb = require('./packem_shared/convertHexToRgb-DvkHBM3-.cjs');
|
|
6
|
+
const rgbToAnsi256 = require('./packem_shared/rgbToAnsi256-DL8eajTz.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.convertHexToRgb = convertHexToRgb.convertHexToRgb;
|
|
11
|
+
exports.ansi256To16 = rgbToAnsi256.ansi256To16;
|
|
12
|
+
exports.rgbToAnsi16 = rgbToAnsi256.rgbToAnsi16;
|
|
13
|
+
exports.rgbToAnsi256 = rgbToAnsi256.rgbToAnsi256;
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { convertHexToRgb } from './packem_shared/convertHexToRgb-CWdAm2kE.mjs';
|
|
2
|
+
export { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './packem_shared/rgbToAnsi256-BdS0fomP.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/colorize",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.27",
|
|
4
4
|
"description": "Terminal and Console string styling done right.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"256",
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"LICENSE.md"
|
|
166
166
|
],
|
|
167
167
|
"dependencies": {
|
|
168
|
-
"@visulima/is-ansi-color-supported": "2.3.
|
|
168
|
+
"@visulima/is-ansi-color-supported": "2.3.3"
|
|
169
169
|
},
|
|
170
170
|
"engines": {
|
|
171
171
|
"node": ">=18.0.0 <=25.x"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var $=Object.defineProperty;var i=(f,o)=>$(f,"name",{value:o,configurable:!0});const h={0:"#000",1:"#800",2:"#080",3:"#880",4:"#008",5:"#808",6:"#088",7:"#ccc",8:"#444",9:"#f00",10:"#0f0",11:"#ff0",12:"#00f",13:"#f0f",14:"#0ff",15:"#fff",16:"#000",17:"#00005f",18:"#000087",19:"#0000af",20:"#0000d7",21:"#0000ff",22:"#005f00",23:"#005f5f",24:"#005f87",25:"#005faf",26:"#005fd7",27:"#005fff",28:"#008700",29:"#00875f",30:"#008787",31:"#0087af",32:"#0087d7",33:"#0087ff",34:"#00af00",35:"#00af5f",36:"#00af87",37:"#00afaf",38:"#00afd7",39:"#00afff",40:"#00d700",41:"#00d75f",42:"#00d787",43:"#00d7af",44:"#00d7d7",45:"#00d7ff",46:"#00ff00",47:"#00ff5f",48:"#00ff87",49:"#00ffaf",50:"#00ffd7",51:"#00ffff",52:"#5f0000",53:"#5f005f",54:"#5f0087",55:"#5f00af",56:"#5f00d7",57:"#5f00ff",58:"#5f5f00",59:"#5f5f5f",60:"#5f5f87",61:"#5f5faf",62:"#5f5fd7",63:"#5f5fff",64:"#5f8700",65:"#5f875f",66:"#5f8787",67:"#5f87af",68:"#5f87d7",69:"#5f87ff",70:"#5faf00",71:"#5faf5f",72:"#5faf87",73:"#5fafaf",74:"#5fafd7",75:"#5fafff",76:"#5fd700",77:"#5fd75f",78:"#5fd787",79:"#5fd7af",80:"#5fd7d7",81:"#5fd7ff",82:"#5fff00",83:"#5fff5f",84:"#5fff87",85:"#5fffaf",86:"#5fffd7",87:"#5fffff",88:"#870000",89:"#87005f",90:"#870087",91:"#8700af",92:"#8700d7",93:"#8700ff",94:"#875f00",95:"#875f5f",96:"#875f87",97:"#875faf",98:"#875fd7",99:"#875fff",100:"#878700",101:"#87875f",102:"#878787",103:"#8787af",104:"#8787d7",105:"#8787ff",106:"#87af00",107:"#87af5f",108:"#87af87",109:"#87afaf",110:"#87afd7",111:"#87afff",112:"#87d700",113:"#87d75f",114:"#87d787",115:"#87d7af",116:"#87d7d7",117:"#87d7ff",118:"#87ff00",119:"#87ff5f",120:"#87ff87",121:"#87ffaf",122:"#87ffd7",123:"#87ffff",124:"#af0000",125:"#af005f",126:"#af0087",127:"#af00af",128:"#af00d7",129:"#af00ff",130:"#af5f00",131:"#af5f5f",132:"#af5f87",133:"#af5faf",134:"#af5fd7",135:"#af5fff",136:"#af8700",137:"#af875f",138:"#af8787",139:"#af87af",140:"#af87d7",141:"#af87ff",142:"#afaf00",143:"#afaf5f",144:"#afaf87",145:"#afafaf",146:"#afafd7",147:"#afafff",148:"#afd700",149:"#afd75f",150:"#afd787",151:"#afd7af",152:"#afd7d7",153:"#afd7ff",154:"#afff00",155:"#afff5f",156:"#afff87",157:"#afffaf",158:"#afffd7",159:"#afffff",160:"#d70000",161:"#d7005f",162:"#d70087",163:"#d700af",164:"#d700d7",165:"#d700ff",166:"#d75f00",167:"#d75f5f",168:"#d75f87",169:"#d75faf",170:"#d75fd7",171:"#d75fff",172:"#d78700",173:"#d7875f",174:"#d78787",175:"#d787af",176:"#d787d7",177:"#d787ff",178:"#d7af00",179:"#d7af5f",180:"#d7af87",181:"#d7afaf",182:"#d7afd7",183:"#d7afff",184:"#d7d700",185:"#d7d75f",186:"#d7d787",187:"#d7d7af",188:"#d7d7d7",189:"#d7d7ff",190:"#d7ff00",191:"#d7ff5f",192:"#d7ff87",193:"#d7ffaf",194:"#d7ffd7",195:"#d7ffff",196:"#ff0000",197:"#ff005f",198:"#ff0087",199:"#ff00af",200:"#ff00d7",201:"#ff00ff",202:"#ff5f00",203:"#ff5f5f",204:"#ff5f87",205:"#ff5faf",206:"#ff5fd7",207:"#ff5fff",208:"#ff8700",209:"#ff875f",210:"#ff8787",211:"#ff87af",212:"#ff87d7",213:"#ff87ff",214:"#ffaf00",215:"#ffaf5f",216:"#ffaf87",217:"#ffafaf",218:"#ffafd7",219:"#ffafff",220:"#ffd700",221:"#ffd75f",222:"#ffd787",223:"#ffd7af",224:"#ffd7d7",225:"#ffd7ff",226:"#ffff00",227:"#ffff5f",228:"#ffff87",229:"#ffffaf",230:"#ffffd7",231:"#ffffff",232:"#080808",233:"#121212",234:"#1c1c1c",235:"#262626",236:"#303030",237:"#3a3a3a",238:"#444444",239:"#4e4e4e",240:"#585858",241:"#626262",242:"#6c6c6c",243:"#767676",244:"#808080",245:"#8a8a8a",246:"#949494",247:"#9e9e9e",248:"#a8a8a8",249:"#b2b2b2",250:"#bcbcbc",251:"#c6c6c6",252:"#d0d0d0",253:"#dadada",254:"#e4e4e4",255:"#eeeeee"};var v=Object.defineProperty,l=i((f,o)=>v(f,"name",{value:o,configurable:!0}),"r");const k={bold:"font-weight: bold;",dim:"opacity: 0.5;",hidden:"visibility: hidden;",inverse:"background-color: currentColor; color: background-color;",italic:"font-style: italic;",overline:"text-decoration: overline;",reset:"color: inherit",strike:"text-decoration: line-through;",strikethrough:"text-decoration: line-through;",underline:"text-decoration: underline;",visible:"opacity: 0;"},y={bgBlack:"background-color: black; color: white;",bgBlackBright:"background-color: #666; color: white;",bgBlue:"background-color: blue; color: white;",bgBlueBright:"background-color: #55f; color: white;",bgCyan:"background-color: cyan; color: black;",bgCyanBright:"background-color: #5ff; color: black;",bgGray:"background-color: #666; color: white;",bgGreen:"background-color: green; color: white;",bgGreenBright:"background-color: #5f5; color: white;",bgGrey:"background-color: #666; color: white;",bgMagenta:"background-color: magenta; color: white;",bgMagentaBright:"background-color: #f5f; color: white;",bgRed:"background-color: red; color: white;",bgRedBright:"background-color: #f55; color: white;",bgWhite:"background-color: white; color: black;",bgWhiteBright:"background-color: #eee; color: black;",bgYellow:"background-color: yellow; color: black;",bgYellowBright:"background-color: #ff5; color: black;",black:"color: black;",blackBright:"color: #666;",blue:"color: blue;",blueBright:"color: #55f;",cyan:"color: cyan;",cyanBright:"color: #5ff;",gray:"color: #666;",green:"color: green;",greenBright:"color: #5f5;",grey:"color: #666;",magenta:"color: magenta;",magentaBright:"color: #f5f;",red:"color: red;",redBright:"color: #f55;",white:"color: white;",whiteBright:"color: #eee;",yellow:"color: yellow;",yellowBright:"color: #ff5;"},p={bg:l(f=>`background-color: ${h[f]};`,"bg"),bgHex:l(f=>`background-color: ${f};`,"bgHex"),bgRgb:l((f,o,r)=>`background-color: rgb(${f},${o},${r});`,"bgRgb"),fg:l(f=>`color: ${h[f]};`,"fg"),hex:l(f=>`color:${f};`,"hex"),rgb:l((f,o,r)=>`color: rgb(${f},${o},${r});`,"rgb")};var m=Object.defineProperty,n=i((f,o)=>m(f,"name",{value:o,configurable:!0}),"a");const c={};let b=null;const w=n(f=>{const o={};return f.replace(/(?<=^|;)\s*([^:]+)\s*:\s*([^;]+)\s*/g,(r,e,a)=>(o[e]=a,a)),o},"cssStringToObject"),s=n(({props:f},o)=>{let r=o;if(f?.cssStack){const a=w(o),d=w(f.cssStack);for(const t in d)a[t]===void 0&&(a[t]=d[t]);r=`${JSON.stringify(a).replace(/["{}]/g,"").replace(/,/g,";")};`}const e=n((a,...d)=>{if(!a)return[];if(typeof a=="string"&&a.includes("%c")){const g=a.match(/(?<=,).*;/g);return[`%c${a.replace(/,.*;/g,"")}`,e.css,...g??[]]}if(typeof a=="number"||typeof a=="string")return[`%c${a}`,e.css];if(a.raw!==null&&Array.isArray(d)&&d.length>0){const g=String.raw(a,...d),B=g.match(/(?<=,).*;/g);return[`%c${g.replace(/,.*;/g,"")}`,e.css,...(B??[]).join("").split(",").filter(Boolean)]}const[t,...u]=a;return u.unshift(e.css),[`${`${t}`.includes("%c")?"":"%c"}${t}`,u.join("")]},"style");return Object.setPrototypeOf(e,b),e.props={css:o,cssStack:r,props:f},e.css=r,e},"createStyle"),j=n(function(){const f=n(o=>`${o}`,"self");f.strip=o=>o;for(const o in y)c[o]={get(){const r=s(this,y[o]);return Object.defineProperty(this,o,{value:r}),r}};for(const o in k)c[o]={get(){const r=s(this,k[o]);return Object.defineProperty(this,o,{value:r}),r}};return b=Object.defineProperties({},c),Object.setPrototypeOf(f,b),f},"WebColorize");for(const f in p)c[f]={get(){return(...o)=>s(this,p[f](...o))}};c.ansi256=c.fg;c.bgAnsi256=c.bg;export{j as default};
|