@visulima/colorize 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +32 -0
- package/dist/gradient.cjs +9 -7
- package/dist/gradient.d.cts +2 -2
- package/dist/gradient.d.mts +2 -2
- package/dist/gradient.d.ts +2 -2
- package/dist/gradient.mjs +9 -7
- package/dist/index.browser.d.mts +2 -2
- package/dist/index.browser.mjs +1 -1
- package/dist/index.server.cjs +26 -16
- package/dist/index.server.d.cts +2 -2
- package/dist/index.server.d.mts +2 -2
- package/dist/index.server.d.ts +2 -2
- package/dist/index.server.mjs +1 -1
- package/dist/packem_shared/{Colorize-Ca9CXTcj.js → Colorize-BQ-Wlgs0.js} +9 -13
- package/dist/packem_shared/{Colorize-BenP3bFn.js → Colorize-q7kOM0WA.js} +26 -16
- package/dist/packem_shared/{GradientBuilder-DTnSGyYW.mjs → GradientBuilder-CkX4Imo9.mjs} +36 -39
- package/dist/packem_shared/{GradientBuilder-BXOgJeHi.cjs → GradientBuilder-DRrwebdU.cjs} +36 -39
- package/dist/packem_shared/{colorize.server-ry9FZNfG.mjs → colorize.server-DeZHO6IN.mjs} +15 -10
- package/dist/packem_shared/{colorize.server-BA3gZZXz.cjs → colorize.server-XetY_pdz.cjs} +15 -10
- package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +21 -0
- package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +17 -0
- package/dist/packem_shared/{rgbToAnsi256-BdS0fomP.mjs → rgbToAnsi256-Bca58HoN.mjs} +2 -1
- package/dist/packem_shared/{rgbToAnsi256-DL8eajTz.cjs → rgbToAnsi256-C3-josZP.cjs} +2 -1
- package/dist/template/make-template.d.cts +1 -1
- package/dist/template/make-template.d.mts +1 -1
- package/dist/template/make-template.d.ts +1 -1
- package/dist/template.cjs +19 -8
- package/dist/template.d.cts +1 -1
- package/dist/template.d.mts +1 -1
- package/dist/template.d.ts +1 -1
- package/dist/template.mjs +19 -8
- package/dist/types.d.cts +3 -3
- package/dist/types.d.mts +3 -3
- package/dist/types.d.ts +3 -3
- package/dist/util/clamp.d.cts +1 -1
- package/dist/util/clamp.d.mts +1 -1
- package/dist/util/clamp.d.ts +1 -1
- package/dist/util/convert-hex-to-rgb.d.cts +1 -15
- package/dist/util/convert-hex-to-rgb.d.mts +1 -15
- package/dist/util/convert-hex-to-rgb.d.ts +1 -15
- package/dist/utils.cjs +2 -2
- package/dist/utils.mjs +2 -2
- package/package.json +2 -4
- package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +0 -13
- package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +0 -17
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
|
|
5
|
-
const convertHexToRgb = require('./convertHexToRgb-
|
|
5
|
+
const convertHexToRgb = require('./convertHexToRgb-51-edHxE.cjs');
|
|
6
6
|
|
|
7
7
|
const colorNames = {
|
|
8
8
|
aliceblue: [240, 248, 255],
|
|
@@ -165,23 +165,25 @@ const computeSubSteps = (stops, steps) => {
|
|
|
165
165
|
throw new Error("Number of steps cannot be inferior to number of stops");
|
|
166
166
|
}
|
|
167
167
|
const substeps = [];
|
|
168
|
-
for (let index = 1; index < l; index
|
|
168
|
+
for (let index = 1; index < l; index += 1) {
|
|
169
169
|
const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
|
|
170
170
|
substeps.push(Math.max(1, Math.round(step)));
|
|
171
171
|
}
|
|
172
172
|
let totalSubsteps = 1;
|
|
173
|
-
for (let n = l -
|
|
173
|
+
for (let n = l - 2; n >= 0; n -= 1) {
|
|
174
174
|
totalSubsteps += substeps[n];
|
|
175
175
|
}
|
|
176
176
|
while (totalSubsteps !== steps) {
|
|
177
177
|
if (totalSubsteps < steps) {
|
|
178
178
|
const min = Math.min(...substeps);
|
|
179
|
-
substeps
|
|
180
|
-
|
|
179
|
+
const minIndex = substeps.indexOf(min);
|
|
180
|
+
substeps[minIndex] = substeps[minIndex] + 1;
|
|
181
|
+
totalSubsteps += 1;
|
|
181
182
|
} else {
|
|
182
183
|
const max = Math.max(...substeps);
|
|
183
|
-
substeps
|
|
184
|
-
|
|
184
|
+
const maxIndex = substeps.indexOf(max);
|
|
185
|
+
substeps[maxIndex] = substeps[maxIndex] - 1;
|
|
186
|
+
totalSubsteps -= 1;
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
return substeps;
|
|
@@ -266,7 +268,7 @@ const HSV_MAX = { h: 360, s: 1, v: 1 };
|
|
|
266
268
|
const calculateStepSize = (start, end, steps) => {
|
|
267
269
|
const step = {};
|
|
268
270
|
for (const k in start) {
|
|
269
|
-
if (Object.
|
|
271
|
+
if (Object.hasOwn(start, k)) {
|
|
270
272
|
step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
|
|
271
273
|
}
|
|
272
274
|
}
|
|
@@ -275,21 +277,14 @@ const calculateStepSize = (start, end, steps) => {
|
|
|
275
277
|
const interpolate = (step, start, index, max) => {
|
|
276
278
|
const color = {};
|
|
277
279
|
for (const k in start) {
|
|
278
|
-
if (Object.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
287
|
-
color[k]
|
|
288
|
-
) : (
|
|
289
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
290
|
-
color[k] % max[k]
|
|
291
|
-
)
|
|
292
|
-
);
|
|
280
|
+
if (Object.hasOwn(start, k)) {
|
|
281
|
+
let value = step[k] * index + start[k];
|
|
282
|
+
if (value < 0) {
|
|
283
|
+
value += max[k];
|
|
284
|
+
} else if (max[k] !== 1) {
|
|
285
|
+
value %= max[k];
|
|
286
|
+
}
|
|
287
|
+
color[k] = value;
|
|
293
288
|
}
|
|
294
289
|
}
|
|
295
290
|
return color;
|
|
@@ -299,7 +294,7 @@ const interpolateRgb = (stop1, stop2, steps) => {
|
|
|
299
294
|
const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
|
|
300
295
|
const step = calculateStepSize(start, end, steps);
|
|
301
296
|
const gradient = [{ ...start }];
|
|
302
|
-
for (let index = 1; index < steps; index
|
|
297
|
+
for (let index = 1; index < steps; index += 1) {
|
|
303
298
|
const color = interpolate(step, start, index, RGBA_MAX);
|
|
304
299
|
gradient.push({
|
|
305
300
|
b: Math.floor(color.b),
|
|
@@ -339,7 +334,7 @@ const interpolateHsv = (stop1, stop2, steps, mode) => {
|
|
|
339
334
|
diff = 360 - start.h + end.h;
|
|
340
335
|
}
|
|
341
336
|
step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
|
|
342
|
-
for (let index = 1; index < steps; index
|
|
337
|
+
for (let index = 1; index < steps; index += 1) {
|
|
343
338
|
const color = interpolate(step, start, index, HSV_MAX);
|
|
344
339
|
gradient.push(hsvToRgb(color.h, color.s, color.v));
|
|
345
340
|
}
|
|
@@ -361,7 +356,7 @@ class GradientBuilder {
|
|
|
361
356
|
let p = -1;
|
|
362
357
|
let lastColorLess = false;
|
|
363
358
|
for (const [index, stop_] of stops.entries()) {
|
|
364
|
-
let stop
|
|
359
|
+
let stop;
|
|
365
360
|
const hasPosition = stop_.position !== void 0;
|
|
366
361
|
if (havingPositions !== hasPosition) {
|
|
367
362
|
throw new Error("Cannot mix positioned and non-positioned color stops");
|
|
@@ -379,7 +374,7 @@ class GradientBuilder {
|
|
|
379
374
|
color = stopInput.color;
|
|
380
375
|
} else if (typeof stopInput.color === "string") {
|
|
381
376
|
color = stopInput.color.includes("#") ? convertHexToRgb.convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
|
|
382
|
-
} else if (stopInput.color
|
|
377
|
+
} else if (stopInput.color && "r" in stopInput.color && "g" in stopInput.color && "b" in stopInput.color) {
|
|
383
378
|
color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
|
|
384
379
|
}
|
|
385
380
|
}
|
|
@@ -404,7 +399,7 @@ class GradientBuilder {
|
|
|
404
399
|
color: stop_.includes("#") ? convertHexToRgb.convertHexToRgb(stop_) : colorNames[stop_],
|
|
405
400
|
position: index / (l - 1)
|
|
406
401
|
};
|
|
407
|
-
} else if (stop_
|
|
402
|
+
} else if (stop_?.r !== void 0 && stop_?.g !== void 0 && stop_?.b !== void 0) {
|
|
408
403
|
stop = {
|
|
409
404
|
color: [stop_.r, stop_.g, stop_.b],
|
|
410
405
|
position: index / (l - 1)
|
|
@@ -414,16 +409,18 @@ class GradientBuilder {
|
|
|
414
409
|
}
|
|
415
410
|
this.stops.push(stop);
|
|
416
411
|
}
|
|
417
|
-
|
|
412
|
+
const firstStop = this.stops[0];
|
|
413
|
+
if (firstStop.position !== 0) {
|
|
418
414
|
this.stops.unshift({
|
|
419
|
-
color:
|
|
415
|
+
color: firstStop.color,
|
|
420
416
|
position: 0
|
|
421
417
|
});
|
|
422
|
-
l
|
|
418
|
+
l += 1;
|
|
423
419
|
}
|
|
424
|
-
|
|
420
|
+
const lastStop = this.stops[l - 1];
|
|
421
|
+
if (lastStop.position !== 1) {
|
|
425
422
|
this.stops.push({
|
|
426
|
-
color:
|
|
423
|
+
color: lastStop.color,
|
|
427
424
|
position: 1
|
|
428
425
|
});
|
|
429
426
|
}
|
|
@@ -431,10 +428,10 @@ class GradientBuilder {
|
|
|
431
428
|
reverse() {
|
|
432
429
|
const stops = [];
|
|
433
430
|
for (const stop of this.stops) {
|
|
434
|
-
const
|
|
435
|
-
stops.push(
|
|
431
|
+
const reversedStop = { ...stop, position: 1 - stop.position };
|
|
432
|
+
stops.push(reversedStop);
|
|
436
433
|
}
|
|
437
|
-
return new GradientBuilder(this.#colorize, stops.
|
|
434
|
+
return new GradientBuilder(this.#colorize, stops.toReversed());
|
|
438
435
|
}
|
|
439
436
|
loop() {
|
|
440
437
|
const stops1 = [];
|
|
@@ -451,7 +448,7 @@ class GradientBuilder {
|
|
|
451
448
|
position: 1 - (stop.position || 0) / 2
|
|
452
449
|
});
|
|
453
450
|
}
|
|
454
|
-
return new GradientBuilder(this.#colorize, [...stops1, ...stops2.
|
|
451
|
+
return new GradientBuilder(this.#colorize, [...stops1, ...stops2.toReversed()]);
|
|
455
452
|
}
|
|
456
453
|
rgb(steps) {
|
|
457
454
|
const subSteps = computeSubSteps(this.stops, steps);
|
|
@@ -462,7 +459,7 @@ class GradientBuilder {
|
|
|
462
459
|
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
463
460
|
}
|
|
464
461
|
});
|
|
465
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index
|
|
462
|
+
for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
|
|
466
463
|
const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
|
|
467
464
|
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
468
465
|
}
|
|
@@ -478,7 +475,7 @@ class GradientBuilder {
|
|
|
478
475
|
stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
|
|
479
476
|
}
|
|
480
477
|
});
|
|
481
|
-
for (let index = 0, l = this.stops.length; index < l - 1; index
|
|
478
|
+
for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
|
|
482
479
|
const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
|
|
483
480
|
gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
|
|
484
481
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
|
|
2
|
-
import { convertHexToRgb } from './convertHexToRgb-
|
|
3
|
-
import { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './rgbToAnsi256-
|
|
2
|
+
import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
|
|
3
|
+
import { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './rgbToAnsi256-Bca58HoN.mjs';
|
|
4
4
|
|
|
5
5
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
6
6
|
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
@@ -10,7 +10,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
|
|
|
10
10
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const clamp = (number_, min, max) =>
|
|
13
|
+
const clamp = (number_, min, max) => {
|
|
14
|
+
if (min > number_) {
|
|
15
|
+
return min;
|
|
16
|
+
}
|
|
17
|
+
return Math.min(number_, max);
|
|
18
|
+
};
|
|
14
19
|
|
|
15
20
|
const closeCode = 39;
|
|
16
21
|
const bgCloseCode = 49;
|
|
@@ -18,17 +23,17 @@ const bgOffset = 10;
|
|
|
18
23
|
const supportedColor = isStdoutColorSupported();
|
|
19
24
|
const mono = { close: "", open: "" };
|
|
20
25
|
const esc = supportedColor > 0 ? (open, close) => {
|
|
21
|
-
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
26
|
+
return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
|
|
22
27
|
} : () => mono;
|
|
23
28
|
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
24
29
|
const createHexFunction = (function_) => (hex) => {
|
|
25
30
|
const [r, g, b] = convertHexToRgb(hex);
|
|
26
31
|
return function_(r, g, b);
|
|
27
32
|
};
|
|
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);
|
|
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);
|
|
32
37
|
if (supportedColor === 1) {
|
|
33
38
|
createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
|
|
34
39
|
createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
@@ -129,7 +134,7 @@ const wrapText = (strings, values, properties) => {
|
|
|
129
134
|
if (!strings) {
|
|
130
135
|
return "";
|
|
131
136
|
}
|
|
132
|
-
let string = strings.raw
|
|
137
|
+
let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
|
|
133
138
|
if (string.includes("\x1B")) {
|
|
134
139
|
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
135
140
|
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
@@ -151,7 +156,7 @@ const createStyle = ({ props }, { close, open }) => {
|
|
|
151
156
|
return style;
|
|
152
157
|
};
|
|
153
158
|
const Colorize = function() {
|
|
154
|
-
const self = (string_) =>
|
|
159
|
+
const self = (string_) => String(string_);
|
|
155
160
|
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
156
161
|
for (const name in baseColors) {
|
|
157
162
|
styles[name] = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
|
|
4
|
-
const convertHexToRgb = require('./convertHexToRgb-
|
|
5
|
-
const rgbToAnsi256 = require('./rgbToAnsi256-
|
|
4
|
+
const convertHexToRgb = require('./convertHexToRgb-51-edHxE.cjs');
|
|
5
|
+
const rgbToAnsi256 = require('./rgbToAnsi256-C3-josZP.cjs');
|
|
6
6
|
|
|
7
7
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
8
8
|
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
@@ -12,7 +12,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
|
|
|
12
12
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const clamp = (number_, min, max) =>
|
|
15
|
+
const clamp = (number_, min, max) => {
|
|
16
|
+
if (min > number_) {
|
|
17
|
+
return min;
|
|
18
|
+
}
|
|
19
|
+
return Math.min(number_, max);
|
|
20
|
+
};
|
|
16
21
|
|
|
17
22
|
const closeCode = 39;
|
|
18
23
|
const bgCloseCode = 49;
|
|
@@ -20,17 +25,17 @@ const bgOffset = 10;
|
|
|
20
25
|
const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
|
|
21
26
|
const mono = { close: "", open: "" };
|
|
22
27
|
const esc = supportedColor > 0 ? (open, close) => {
|
|
23
|
-
return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
|
|
28
|
+
return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
|
|
24
29
|
} : () => mono;
|
|
25
30
|
const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256.rgbToAnsi256(Number(r), Number(g), Number(b)));
|
|
26
31
|
const createHexFunction = (function_) => (hex) => {
|
|
27
32
|
const [r, g, b] = convertHexToRgb.convertHexToRgb(hex);
|
|
28
33
|
return function_(r, g, b);
|
|
29
34
|
};
|
|
30
|
-
let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
|
|
31
|
-
let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
|
|
32
|
-
let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
|
|
33
|
-
let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
|
|
35
|
+
let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
|
|
36
|
+
let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
|
|
37
|
+
let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
|
|
38
|
+
let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
|
|
34
39
|
if (supportedColor === 1) {
|
|
35
40
|
createAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)), closeCode);
|
|
36
41
|
createBgAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)) + bgOffset, bgCloseCode);
|
|
@@ -131,7 +136,7 @@ const wrapText = (strings, values, properties) => {
|
|
|
131
136
|
if (!strings) {
|
|
132
137
|
return "";
|
|
133
138
|
}
|
|
134
|
-
let string = strings.raw
|
|
139
|
+
let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
|
|
135
140
|
if (string.includes("\x1B")) {
|
|
136
141
|
for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
|
|
137
142
|
string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
|
|
@@ -153,7 +158,7 @@ const createStyle = ({ props }, { close, open }) => {
|
|
|
153
158
|
return style;
|
|
154
159
|
};
|
|
155
160
|
const Colorize = function() {
|
|
156
|
-
const self = (string_) =>
|
|
161
|
+
const self = (string_) => String(string_);
|
|
157
162
|
self.strip = (value) => value.replaceAll(ansiRegex(), "");
|
|
158
163
|
for (const name in baseColors) {
|
|
159
164
|
styles[name] = {
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 };
|
|
@@ -8,7 +8,8 @@ const rgbToAnsi256 = (r, g, b) => {
|
|
|
8
8
|
}
|
|
9
9
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
10
10
|
}
|
|
11
|
-
return 16 +
|
|
11
|
+
return 16 + // r / 255 * 5 => r / 51
|
|
12
|
+
36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
12
13
|
};
|
|
13
14
|
const ansi256To16 = (code) => {
|
|
14
15
|
let r;
|
|
@@ -12,7 +12,8 @@ const rgbToAnsi256 = (r, g, b) => {
|
|
|
12
12
|
}
|
|
13
13
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
14
14
|
}
|
|
15
|
-
return 16 +
|
|
15
|
+
return 16 + // r / 255 * 5 => r / 51
|
|
16
|
+
36 * Math.round(r / 51) + 6 * Math.round(g / 51) + Math.round(b / 51);
|
|
16
17
|
};
|
|
17
18
|
const ansi256To16 = (code) => {
|
|
18
19
|
let r;
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
8
|
*/
|
|
9
9
|
import type { ColorizeType } from "../types.d.cts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
|
10
|
+
export declare const makeTemplate: (colorize: ColorizeType) => ((string: string) => string);
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
8
|
*/
|
|
9
9
|
import type { ColorizeType } from "../types.d.mts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
|
10
|
+
export declare const makeTemplate: (colorize: ColorizeType) => ((string: string) => string);
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
8
8
|
*/
|
|
9
9
|
import type { ColorizeType } from "../types.d.ts";
|
|
10
|
-
export declare const makeTemplate: (colorize: ColorizeType) => (string: string) => string;
|
|
10
|
+
export declare const makeTemplate: (colorize: ColorizeType) => ((string: string) => string);
|
package/dist/template.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
|
|
5
|
-
const colorize_server = require('./packem_shared/colorize.server-
|
|
6
|
-
const convertHexToRgb = require('./packem_shared/convertHexToRgb-
|
|
5
|
+
const colorize_server = require('./packem_shared/colorize.server-XetY_pdz.cjs');
|
|
6
|
+
const convertHexToRgb = require('./packem_shared/convertHexToRgb-51-edHxE.cjs');
|
|
7
7
|
|
|
8
8
|
const makeColorizeTemplate = (template) => (firstString, ...arguments_) => {
|
|
9
9
|
if (!Array.isArray(firstString) || !Array.isArray(firstString.raw)) {
|
|
10
10
|
throw new TypeError("A tagged template literal must be provided");
|
|
11
11
|
}
|
|
12
12
|
const parts = [firstString.raw[0]];
|
|
13
|
-
for (let index = 1; index < firstString.raw.length; index
|
|
13
|
+
for (let index = 1; index < firstString.raw.length; index += 1) {
|
|
14
14
|
parts.push(String(arguments_[index - 1]).replaceAll(/[{}\\]/g, String.raw`\$&`), String(firstString.raw[index]));
|
|
15
15
|
}
|
|
16
16
|
return template(parts.join(""));
|
|
@@ -40,20 +40,31 @@ const unescape = (c) => {
|
|
|
40
40
|
return ESCAPES.get(c) ?? c;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
const TEMPLATE_REGEX =
|
|
43
|
+
const TEMPLATE_REGEX = (
|
|
44
|
+
// eslint-disable-next-line regexp/no-lazy-ends,regexp/no-dupe-disjunctions,sonarjs/regex-complexity
|
|
45
|
+
/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi
|
|
46
|
+
);
|
|
44
47
|
const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
|
|
45
48
|
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
46
49
|
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
50
|
+
const CHUNK_SPLIT_REGEX = /\s*,\s*/;
|
|
47
51
|
const parseArguments = (name, value) => {
|
|
48
52
|
const results = [];
|
|
49
|
-
const chunks = value.trim().split(
|
|
53
|
+
const chunks = value.trim().split(CHUNK_SPLIT_REGEX);
|
|
50
54
|
let matches;
|
|
51
55
|
for (const chunk of chunks) {
|
|
52
56
|
const number = Number(chunk);
|
|
53
57
|
if (!Number.isNaN(number)) {
|
|
54
58
|
results.push(number);
|
|
55
59
|
} else if (matches = STRING_REGEX.exec(chunk)) {
|
|
56
|
-
results.push(
|
|
60
|
+
results.push(
|
|
61
|
+
matches[2].replaceAll(ESCAPE_REGEX, (_, escape, character) => {
|
|
62
|
+
if (escape) {
|
|
63
|
+
return unescape(escape);
|
|
64
|
+
}
|
|
65
|
+
return character;
|
|
66
|
+
})
|
|
67
|
+
);
|
|
57
68
|
} else {
|
|
58
69
|
throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
|
|
59
70
|
}
|
|
@@ -85,7 +96,7 @@ const buildStyle = (colorize, styles) => {
|
|
|
85
96
|
const enabled = {};
|
|
86
97
|
for (const layer of styles) {
|
|
87
98
|
for (const style of layer.styles) {
|
|
88
|
-
enabled[style[0]] = layer.inverse ?
|
|
99
|
+
enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
let current = colorize;
|
|
@@ -129,7 +140,7 @@ const makeTemplate = (colorize) => (string) => {
|
|
|
129
140
|
);
|
|
130
141
|
chunks.push(chunk.join(""));
|
|
131
142
|
if (styles.length > 0) {
|
|
132
|
-
throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
|
|
143
|
+
throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
|
|
133
144
|
}
|
|
134
145
|
return chunks.join("");
|
|
135
146
|
};
|
package/dist/template.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ColorizeType } from "./types.d.cts";
|
|
2
|
-
export declare const makeTaggedTemplate: (instance: ColorizeType) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
2
|
+
export declare const makeTaggedTemplate: (instance: ColorizeType) => ((firstString: TemplateStringsArray, ...arguments_: any[]) => string);
|
|
3
3
|
export declare const template: (string: string) => string;
|
|
4
4
|
declare const templateFunction: (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
5
5
|
export = templateFunction;
|
package/dist/template.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ColorizeType } from "./types.d.mts";
|
|
2
|
-
export declare const makeTaggedTemplate: (instance: ColorizeType) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
2
|
+
export declare const makeTaggedTemplate: (instance: ColorizeType) => ((firstString: TemplateStringsArray, ...arguments_: any[]) => string);
|
|
3
3
|
export declare const template: (string: string) => string;
|
|
4
4
|
declare const templateFunction: (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
5
5
|
export default templateFunction;
|
package/dist/template.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ColorizeType } from "./types.d.ts";
|
|
2
|
-
export declare const makeTaggedTemplate: (instance: ColorizeType) => (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
2
|
+
export declare const makeTaggedTemplate: (instance: ColorizeType) => ((firstString: TemplateStringsArray, ...arguments_: any[]) => string);
|
|
3
3
|
export declare const template: (string: string) => string;
|
|
4
4
|
declare const templateFunction: (firstString: TemplateStringsArray, ...arguments_: any[]) => string;
|
|
5
5
|
export = templateFunction;
|
package/dist/template.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { C as Colorize } from './packem_shared/colorize.server-
|
|
2
|
-
import { convertHexToRgb } from './packem_shared/convertHexToRgb-
|
|
1
|
+
import { C as Colorize } from './packem_shared/colorize.server-DeZHO6IN.mjs';
|
|
2
|
+
import { convertHexToRgb } from './packem_shared/convertHexToRgb-BZwJEiMZ.mjs';
|
|
3
3
|
|
|
4
4
|
const makeColorizeTemplate = (template) => (firstString, ...arguments_) => {
|
|
5
5
|
if (!Array.isArray(firstString) || !Array.isArray(firstString.raw)) {
|
|
6
6
|
throw new TypeError("A tagged template literal must be provided");
|
|
7
7
|
}
|
|
8
8
|
const parts = [firstString.raw[0]];
|
|
9
|
-
for (let index = 1; index < firstString.raw.length; index
|
|
9
|
+
for (let index = 1; index < firstString.raw.length; index += 1) {
|
|
10
10
|
parts.push(String(arguments_[index - 1]).replaceAll(/[{}\\]/g, String.raw`\$&`), String(firstString.raw[index]));
|
|
11
11
|
}
|
|
12
12
|
return template(parts.join(""));
|
|
@@ -36,20 +36,31 @@ const unescape = (c) => {
|
|
|
36
36
|
return ESCAPES.get(c) ?? c;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const TEMPLATE_REGEX =
|
|
39
|
+
const TEMPLATE_REGEX = (
|
|
40
|
+
// eslint-disable-next-line regexp/no-lazy-ends,regexp/no-dupe-disjunctions,sonarjs/regex-complexity
|
|
41
|
+
/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi
|
|
42
|
+
);
|
|
40
43
|
const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
|
|
41
44
|
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
42
45
|
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
46
|
+
const CHUNK_SPLIT_REGEX = /\s*,\s*/;
|
|
43
47
|
const parseArguments = (name, value) => {
|
|
44
48
|
const results = [];
|
|
45
|
-
const chunks = value.trim().split(
|
|
49
|
+
const chunks = value.trim().split(CHUNK_SPLIT_REGEX);
|
|
46
50
|
let matches;
|
|
47
51
|
for (const chunk of chunks) {
|
|
48
52
|
const number = Number(chunk);
|
|
49
53
|
if (!Number.isNaN(number)) {
|
|
50
54
|
results.push(number);
|
|
51
55
|
} else if (matches = STRING_REGEX.exec(chunk)) {
|
|
52
|
-
results.push(
|
|
56
|
+
results.push(
|
|
57
|
+
matches[2].replaceAll(ESCAPE_REGEX, (_, escape, character) => {
|
|
58
|
+
if (escape) {
|
|
59
|
+
return unescape(escape);
|
|
60
|
+
}
|
|
61
|
+
return character;
|
|
62
|
+
})
|
|
63
|
+
);
|
|
53
64
|
} else {
|
|
54
65
|
throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
|
|
55
66
|
}
|
|
@@ -81,7 +92,7 @@ const buildStyle = (colorize, styles) => {
|
|
|
81
92
|
const enabled = {};
|
|
82
93
|
for (const layer of styles) {
|
|
83
94
|
for (const style of layer.styles) {
|
|
84
|
-
enabled[style[0]] = layer.inverse ?
|
|
95
|
+
enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
let current = colorize;
|
|
@@ -125,7 +136,7 @@ const makeTemplate = (colorize) => (string) => {
|
|
|
125
136
|
);
|
|
126
137
|
chunks.push(chunk.join(""));
|
|
127
138
|
if (styles.length > 0) {
|
|
128
|
-
throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
|
|
139
|
+
throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
|
|
129
140
|
}
|
|
130
141
|
return chunks.join("");
|
|
131
142
|
};
|
package/dist/types.d.cts
CHANGED
|
@@ -49,7 +49,7 @@ export interface ColorizeType {
|
|
|
49
49
|
readonly bgGrey: this;
|
|
50
50
|
/**
|
|
51
51
|
* Set HEX value for background color.
|
|
52
|
-
* @param {string}
|
|
52
|
+
* @param {string} color
|
|
53
53
|
*/
|
|
54
54
|
bgHex: (color: ColorValueHex) => this;
|
|
55
55
|
readonly bgMagenta: this;
|
|
@@ -90,7 +90,7 @@ export interface ColorizeType {
|
|
|
90
90
|
readonly grey: this;
|
|
91
91
|
/**
|
|
92
92
|
* Set HEX value for foreground color.
|
|
93
|
-
* @param {string}
|
|
93
|
+
* @param {string} color
|
|
94
94
|
*/
|
|
95
95
|
hex: (color: ColorValueHex) => this;
|
|
96
96
|
/** Print the invisible text. */
|
|
@@ -122,7 +122,7 @@ export interface ColorizeType {
|
|
|
122
122
|
readonly strikethrough: this;
|
|
123
123
|
/**
|
|
124
124
|
* Remove ANSI styling codes.
|
|
125
|
-
* @param {string}
|
|
125
|
+
* @param {string} string
|
|
126
126
|
* @returns {string}
|
|
127
127
|
*/
|
|
128
128
|
strip: (string: string) => string;
|
package/dist/types.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ export interface ColorizeType {
|
|
|
49
49
|
readonly bgGrey: this;
|
|
50
50
|
/**
|
|
51
51
|
* Set HEX value for background color.
|
|
52
|
-
* @param {string}
|
|
52
|
+
* @param {string} color
|
|
53
53
|
*/
|
|
54
54
|
bgHex: (color: ColorValueHex) => this;
|
|
55
55
|
readonly bgMagenta: this;
|
|
@@ -90,7 +90,7 @@ export interface ColorizeType {
|
|
|
90
90
|
readonly grey: this;
|
|
91
91
|
/**
|
|
92
92
|
* Set HEX value for foreground color.
|
|
93
|
-
* @param {string}
|
|
93
|
+
* @param {string} color
|
|
94
94
|
*/
|
|
95
95
|
hex: (color: ColorValueHex) => this;
|
|
96
96
|
/** Print the invisible text. */
|
|
@@ -122,7 +122,7 @@ export interface ColorizeType {
|
|
|
122
122
|
readonly strikethrough: this;
|
|
123
123
|
/**
|
|
124
124
|
* Remove ANSI styling codes.
|
|
125
|
-
* @param {string}
|
|
125
|
+
* @param {string} string
|
|
126
126
|
* @returns {string}
|
|
127
127
|
*/
|
|
128
128
|
strip: (string: string) => string;
|
package/dist/types.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export interface ColorizeType {
|
|
|
49
49
|
readonly bgGrey: this;
|
|
50
50
|
/**
|
|
51
51
|
* Set HEX value for background color.
|
|
52
|
-
* @param {string}
|
|
52
|
+
* @param {string} color
|
|
53
53
|
*/
|
|
54
54
|
bgHex: (color: ColorValueHex) => this;
|
|
55
55
|
readonly bgMagenta: this;
|
|
@@ -90,7 +90,7 @@ export interface ColorizeType {
|
|
|
90
90
|
readonly grey: this;
|
|
91
91
|
/**
|
|
92
92
|
* Set HEX value for foreground color.
|
|
93
|
-
* @param {string}
|
|
93
|
+
* @param {string} color
|
|
94
94
|
*/
|
|
95
95
|
hex: (color: ColorValueHex) => this;
|
|
96
96
|
/** Print the invisible text. */
|
|
@@ -122,7 +122,7 @@ export interface ColorizeType {
|
|
|
122
122
|
readonly strikethrough: this;
|
|
123
123
|
/**
|
|
124
124
|
* Remove ANSI styling codes.
|
|
125
|
-
* @param {string}
|
|
125
|
+
* @param {string} string
|
|
126
126
|
* @returns {string}
|
|
127
127
|
*/
|
|
128
128
|
strip: (string: string) => string;
|
package/dist/util/clamp.d.cts
CHANGED
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Clamp a number within the inclusive range specified by min and max.
|
|
10
|
-
*
|
|
10
|
+
* The ternary operator is a tick quicker than Math.min(Math.max(num, min), max).
|
|
11
11
|
*/
|
|
12
12
|
export declare const clamp: (number_: number, min: number, max: number) => number;
|