@visulima/colorize 2.0.0-alpha.6 → 2.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/gradient.cjs +9 -7
  3. package/dist/gradient.mjs +9 -7
  4. package/dist/index.browser.d.mts +2 -2
  5. package/dist/index.browser.mjs +1 -1
  6. package/dist/index.server.cjs +18 -14
  7. package/dist/index.server.d.cts +2 -2
  8. package/dist/index.server.d.mts +2 -2
  9. package/dist/index.server.d.ts +2 -2
  10. package/dist/index.server.mjs +1 -1
  11. package/dist/packem_shared/{Colorize-Ca9CXTcj.js → Colorize-BQ-Wlgs0.js} +9 -13
  12. package/dist/packem_shared/{Colorize-BenP3bFn.js → Colorize-ByTph984.js} +18 -14
  13. package/dist/packem_shared/{GradientBuilder-DTnSGyYW.mjs → GradientBuilder-CkX4Imo9.mjs} +36 -39
  14. package/dist/packem_shared/{GradientBuilder-BXOgJeHi.cjs → GradientBuilder-DRrwebdU.cjs} +36 -39
  15. package/dist/packem_shared/{colorize.server-BA3gZZXz.cjs → colorize.server-BFVt4Z2R.cjs} +8 -8
  16. package/dist/packem_shared/{colorize.server-ry9FZNfG.mjs → colorize.server-BVtbrTcf.mjs} +8 -8
  17. package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +21 -0
  18. package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +17 -0
  19. package/dist/template.cjs +7 -6
  20. package/dist/template.mjs +7 -6
  21. package/dist/types.d.cts +3 -3
  22. package/dist/types.d.mts +3 -3
  23. package/dist/types.d.ts +3 -3
  24. package/dist/util/clamp.d.cts +1 -1
  25. package/dist/util/clamp.d.mts +1 -1
  26. package/dist/util/clamp.d.ts +1 -1
  27. package/dist/util/convert-hex-to-rgb.d.cts +1 -15
  28. package/dist/util/convert-hex-to-rgb.d.mts +1 -15
  29. package/dist/util/convert-hex-to-rgb.d.ts +1 -15
  30. package/dist/utils.cjs +1 -1
  31. package/dist/utils.mjs +1 -1
  32. package/package.json +3 -5
  33. package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +0 -13
  34. package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +0 -17
package/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ ## @visulima/colorize [2.0.0-alpha.8](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.7...@visulima/colorize@2.0.0-alpha.8) (2026-04-08)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **colorize:** properly fix eslint errors in code ([c9941a4](https://github.com/visulima/visulima/commit/c9941a42e04570c7a4f39e4f65424b507a58352d))
6
+ * resolve failing tests across multiple packages ([2b4b6f0](https://github.com/visulima/visulima/commit/2b4b6f04169b60fdc4cf77b293015436a272c0fb))
7
+
8
+ ### Miscellaneous Chores
9
+
10
+ * apply linting and formatting fixes across packages ([5d150a5](https://github.com/visulima/visulima/commit/5d150a578f9ce861c791843c683deeb849b774a9))
11
+ * **colorize:** add tsconfig.eslint.json for type-aware linting ([0a2b596](https://github.com/visulima/visulima/commit/0a2b596b74df932cf492400029ecdaf572b8f474))
12
+ * **colorize:** apply prettier formatting ([f572dc4](https://github.com/visulima/visulima/commit/f572dc47f1398070adc5d4879d9f99870fe71760))
13
+ * **colorize:** migrate .prettierrc.cjs to prettier.config.js ([6d84ecc](https://github.com/visulima/visulima/commit/6d84eccbfba7ff59fd7463ef973b80d50d85f464))
14
+ * **terminal:** remove empty dependency objects from package.json ([562c704](https://github.com/visulima/visulima/commit/562c704e5d90aa2d13eae942ebbdcfeb787c2b46))
15
+
16
+
17
+ ### Dependencies
18
+
19
+ * **@visulima/is-ansi-color-supported:** upgraded to 3.0.0-alpha.8
20
+
21
+ ## @visulima/colorize [2.0.0-alpha.7](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.6...@visulima/colorize@2.0.0-alpha.7) (2026-03-26)
22
+
23
+ ### Features
24
+
25
+ * **web:** auto-generate packages page from workspace metadata ([623e520](https://github.com/visulima/visulima/commit/623e5207693a7fe720f5f2f179593a3654c880e3))
26
+
27
+ ### Miscellaneous Chores
28
+
29
+ * update homepage URLs to visulima.com/packages/ format ([be42968](https://github.com/visulima/visulima/commit/be42968129df85fb074224435e33135ff44cab91))
30
+
31
+
32
+ ### Dependencies
33
+
34
+ * **@visulima/is-ansi-color-supported:** upgraded to 3.0.0-alpha.7
35
+
1
36
  ## @visulima/colorize [2.0.0-alpha.6](https://github.com/visulima/visulima/compare/@visulima/colorize@2.0.0-alpha.5...@visulima/colorize@2.0.0-alpha.6) (2026-03-26)
2
37
 
3
38
  ### Bug Fixes
package/dist/gradient.cjs CHANGED
@@ -2,11 +2,12 @@
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-BA3gZZXz.cjs');
6
- const GradientBuilder = require('./packem_shared/GradientBuilder-BXOgJeHi.cjs');
5
+ const colorize_server = require('./packem_shared/colorize.server-BFVt4Z2R.cjs');
6
+ const GradientBuilder = require('./packem_shared/GradientBuilder-DRrwebdU.cjs');
7
7
 
8
8
  const colorize = new colorize_server.Colorize();
9
- const forbiddenChars = /\s/g;
9
+ const WHITESPACE_GLOBAL = /\s/g;
10
+ const WHITESPACE_TEST = /\s/;
10
11
  const gradient = (stops, options) => {
11
12
  const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
12
13
  let builder = new GradientBuilder.GradientBuilder(colorize, stops);
@@ -16,11 +17,12 @@ const gradient = (stops, options) => {
16
17
  builder = builder.reverse();
17
18
  }
18
19
  return (string_) => {
19
- const colorsCount = Math.max(string_.replaceAll(forbiddenChars, "").length, builder.stops.length);
20
+ const stripped = string_.replaceAll(WHITESPACE_GLOBAL, "");
21
+ const colorsCount = Math.max(stripped.length, builder.stops.length);
20
22
  const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
21
23
  let result = "";
22
24
  for (const s of string_) {
23
- if (forbiddenChars.test(s)) {
25
+ if (WHITESPACE_TEST.test(s)) {
24
26
  result += s;
25
27
  } else {
26
28
  const color = colors.shift();
@@ -40,14 +42,14 @@ const multilineGradient = (stops, options) => {
40
42
  }
41
43
  return (string_) => {
42
44
  const lines = string_.split("\n");
43
- const colorsCount = Reflect.apply(Math.max, null, [...lines.map((l) => l.length), builder.stops.length]);
45
+ const colorsCount = Reflect.apply(Math.max, void 0, [...lines.map((l) => l.length), builder.stops.length]);
44
46
  const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
45
47
  const results = [];
46
48
  for (const line of lines) {
47
49
  const lineColors = [...colors];
48
50
  let lineResult = "";
49
51
  for (const l of line) {
50
- lineResult += forbiddenChars.test(l) ? l : lineColors.shift()(l);
52
+ lineResult += WHITESPACE_TEST.test(l) ? l : lineColors.shift()(l);
51
53
  }
52
54
  results.push(lineResult);
53
55
  }
package/dist/gradient.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { C as Colorize } from './packem_shared/colorize.server-ry9FZNfG.mjs';
2
- import { GradientBuilder } from './packem_shared/GradientBuilder-DTnSGyYW.mjs';
1
+ import { C as Colorize } from './packem_shared/colorize.server-BVtbrTcf.mjs';
2
+ import { GradientBuilder } from './packem_shared/GradientBuilder-CkX4Imo9.mjs';
3
3
 
4
4
  const colorize = new Colorize();
5
- const forbiddenChars = /\s/g;
5
+ const WHITESPACE_GLOBAL = /\s/g;
6
+ const WHITESPACE_TEST = /\s/;
6
7
  const gradient = (stops, options) => {
7
8
  const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
8
9
  let builder = new GradientBuilder(colorize, stops);
@@ -12,11 +13,12 @@ const gradient = (stops, options) => {
12
13
  builder = builder.reverse();
13
14
  }
14
15
  return (string_) => {
15
- const colorsCount = Math.max(string_.replaceAll(forbiddenChars, "").length, builder.stops.length);
16
+ const stripped = string_.replaceAll(WHITESPACE_GLOBAL, "");
17
+ const colorsCount = Math.max(stripped.length, builder.stops.length);
16
18
  const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
17
19
  let result = "";
18
20
  for (const s of string_) {
19
- if (forbiddenChars.test(s)) {
21
+ if (WHITESPACE_TEST.test(s)) {
20
22
  result += s;
21
23
  } else {
22
24
  const color = colors.shift();
@@ -36,14 +38,14 @@ const multilineGradient = (stops, options) => {
36
38
  }
37
39
  return (string_) => {
38
40
  const lines = string_.split("\n");
39
- const colorsCount = Reflect.apply(Math.max, null, [...lines.map((l) => l.length), builder.stops.length]);
41
+ const colorsCount = Reflect.apply(Math.max, void 0, [...lines.map((l) => l.length), builder.stops.length]);
40
42
  const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
41
43
  const results = [];
42
44
  for (const line of lines) {
43
45
  const lineColors = [...colors];
44
46
  let lineResult = "";
45
47
  for (const l of line) {
46
- lineResult += forbiddenChars.test(l) ? l : lineColors.shift()(l);
48
+ lineResult += WHITESPACE_TEST.test(l) ? l : lineColors.shift()(l);
47
49
  }
48
50
  results.push(lineResult);
49
51
  }
@@ -1,6 +1,6 @@
1
1
  import type { ColorizeType, ColorValueHex } from "./types.d.ts";
2
- declare const _default: ColorizeType;
3
- export default _default;
2
+ declare const colorize: ColorizeType;
3
+ export default colorize;
4
4
  export declare const ansi256: (code: number) => ColorizeType;
5
5
  export declare const bg: (code: number) => ColorizeType;
6
6
  export declare const bgAnsi256: (code: number) => ColorizeType;
@@ -1,4 +1,4 @@
1
- import WebColorize from './packem_shared/Colorize-Ca9CXTcj.js';
1
+ import WebColorize from './packem_shared/Colorize-BQ-Wlgs0.js';
2
2
 
3
3
  const colorize = new WebColorize();
4
4
  const ansi256 = colorize.ansi256;
@@ -12,16 +12,20 @@ function ansiRegex({ onlyFirst = false } = {}) {
12
12
 
13
13
  const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
14
14
 
15
+ const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
15
16
  const convertHexToRgb = (hex) => {
16
- let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
17
- const length_ = color ? color.length : 0;
18
- if (length_ === 3) {
19
- color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
20
- } else if (length_ !== 6) {
17
+ let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
18
+ const colorLength = color ? color.length : 0;
19
+ if (colorLength === 3) {
20
+ const c0 = color.charAt(0);
21
+ const c1 = color.charAt(1);
22
+ const c2 = color.charAt(2);
23
+ color = c0 + c0 + c1 + c1 + c2 + c2;
24
+ } else if (colorLength !== 6) {
21
25
  return [0, 0, 0];
22
26
  }
23
- const number_ = Number.parseInt(color, 16);
24
- return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
27
+ const colorNumber = Number.parseInt(color, 16);
28
+ return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
25
29
  };
26
30
 
27
31
  const rgbToAnsi256 = (r, g, b) => {
@@ -70,17 +74,17 @@ const bgOffset = 10;
70
74
  const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
71
75
  const mono = { close: "", open: "" };
72
76
  const esc = supportedColor > 0 ? (open, close) => {
73
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
77
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
74
78
  } : () => mono;
75
79
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
76
80
  const createHexFunction = (function_) => (hex) => {
77
81
  const [r, g, b] = convertHexToRgb(hex);
78
82
  return function_(r, g, b);
79
83
  };
80
- let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
81
- let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
82
- let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
83
- let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
84
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
85
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
86
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
87
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
84
88
  if (supportedColor === 1) {
85
89
  createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
86
90
  createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -181,7 +185,7 @@ const wrapText = (strings, values, properties) => {
181
185
  if (!strings) {
182
186
  return "";
183
187
  }
184
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
188
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
185
189
  if (string.includes("\x1B")) {
186
190
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
187
191
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -203,7 +207,7 @@ const createStyle = ({ props }, { close, open }) => {
203
207
  return style;
204
208
  };
205
209
  const Colorize = function() {
206
- const self = (string_) => `${string_}`;
210
+ const self = (string_) => String(string_);
207
211
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
208
212
  for (const name in baseColors) {
209
213
  styles[name] = {
@@ -3,6 +3,6 @@ import type { ColorizeType } from "./types.d.cts";
3
3
  type ColorizeTypeWithColorize = ColorizeType & {
4
4
  Colorize: typeof ColorizeImpl;
5
5
  };
6
- declare const _default: ColorizeTypeWithColorize;
7
- export = _default;
6
+ declare const colorize: ColorizeTypeWithColorize;
7
+ export = colorize;
8
8
  export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.cts";
@@ -1,6 +1,6 @@
1
1
  import type { ColorizeType, ColorValueHex } from "./types.d.ts";
2
- declare const _default: ColorizeType;
3
- export default _default;
2
+ declare const colorize: ColorizeType;
3
+ export default colorize;
4
4
  export declare const ansi256: (code: number) => ColorizeType;
5
5
  export declare const bg: (code: number) => ColorizeType;
6
6
  export declare const bgAnsi256: (code: number) => ColorizeType;
@@ -3,6 +3,6 @@ import type { ColorizeType } from "./types.d.ts";
3
3
  type ColorizeTypeWithColorize = ColorizeType & {
4
4
  Colorize: typeof ColorizeImpl;
5
5
  };
6
- declare const _default: ColorizeTypeWithColorize;
7
- export = _default;
6
+ declare const colorize: ColorizeTypeWithColorize;
7
+ export = colorize;
8
8
  export type { AnsiColors, AnsiStyles, ColorizeType } from "./types.d.ts";
@@ -1,4 +1,4 @@
1
- import Colorize from './packem_shared/Colorize-BenP3bFn.js';
1
+ import Colorize from './packem_shared/Colorize-ByTph984.js';
2
2
 
3
3
  const colorize = new Colorize();
4
4
  const ansi256 = colorize.ansi256;
@@ -313,14 +313,12 @@ const baseColors = {
313
313
  yellowBright: "color: #ff5;"
314
314
  };
315
315
  const styleMethods = {
316
- // eslint-disable-next-line security/detect-object-injection
317
- bg: (code) => `background-color: ${ansiCodeHexMap[code]};`,
316
+ bg: (code) => `background-color: ${ansiCodeHexMap[code] ?? ""};`,
318
317
  bgHex: (hex) => `background-color: ${hex};`,
319
- bgRgb: (r, g, b) => `background-color: rgb(${r},${g},${b});`,
320
- // eslint-disable-next-line security/detect-object-injection
321
- fg: (code) => `color: ${ansiCodeHexMap[code]};`,
318
+ bgRgb: (r, g, b) => `background-color: rgb(${String(r)},${String(g)},${String(b)});`,
319
+ fg: (code) => `color: ${ansiCodeHexMap[code] ?? ""};`,
322
320
  hex: (hex) => `color:${hex};`,
323
- rgb: (r, g, b) => `color: rgb(${r},${g},${b});`
321
+ rgb: (r, g, b) => `color: rgb(${String(r)},${String(g)},${String(b)});`
324
322
  };
325
323
 
326
324
  const styles = {};
@@ -339,9 +337,7 @@ const createStyle = ({ props }, css) => {
339
337
  const cssObject = cssStringToObject(css);
340
338
  const propertiesCssObject = cssStringToObject(props.cssStack);
341
339
  for (const key in propertiesCssObject) {
342
- if (cssObject[key] === void 0) {
343
- cssObject[key] = propertiesCssObject[key];
344
- }
340
+ cssObject[key] ??= propertiesCssObject[key];
345
341
  }
346
342
  cssStack = `${JSON.stringify(cssObject).replace(/["{}]/g, "").replace(/,/g, ";")};`;
347
343
  }
@@ -355,9 +351,9 @@ const createStyle = ({ props }, css) => {
355
351
  return [`%c${inputWithoutStyles}`, style.css, ...collectedStyles ?? []];
356
352
  }
357
353
  if (typeof input === "number" || typeof input === "string") {
358
- return [`%c${input}`, style.css];
354
+ return [`%c${String(input)}`, style.css];
359
355
  }
360
- if (input.raw !== null && Array.isArray(values) && values.length > 0) {
356
+ if (input.raw !== void 0 && Array.isArray(values) && values.length > 0) {
361
357
  const rawString = String.raw(input, ...values);
362
358
  const collectedStyles = rawString.match(/(?<=,).*;/g);
363
359
  const inputWithoutStyles = rawString.replace(/,.*;/g, "");
@@ -365,7 +361,7 @@ const createStyle = ({ props }, css) => {
365
361
  }
366
362
  const [first, ...rest] = input;
367
363
  rest.unshift(style.css);
368
- return [`${`${first}`.includes("%c") ? "" : "%c"}${first}`, rest.join("")];
364
+ return [`${String(first).includes("%c") ? "" : "%c"}${String(first)}`, rest.join("")];
369
365
  };
370
366
  Object.setPrototypeOf(style, stylePrototype);
371
367
  style.props = { css, cssStack, props };
@@ -373,7 +369,7 @@ const createStyle = ({ props }, css) => {
373
369
  return style;
374
370
  };
375
371
  const WebColorize = function() {
376
- const self = (string_) => `${string_}`;
372
+ const self = (string_) => String(string_);
377
373
  self.strip = (value) => value;
378
374
  for (const name in baseColors) {
379
375
  styles[name] = {
@@ -10,16 +10,20 @@ function ansiRegex({ onlyFirst = false } = {}) {
10
10
 
11
11
  const clamp = (number_, min, max) => min > number_ ? min : Math.min(number_, max);
12
12
 
13
+ const HEX_COLOR_REGEX = /([a-f\d]{3,6})/i;
13
14
  const convertHexToRgb = (hex) => {
14
- let [, color] = /([a-f\d]{3,6})/i.exec(hex) ?? [];
15
- const length_ = color ? color.length : 0;
16
- if (length_ === 3) {
17
- color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
18
- } else if (length_ !== 6) {
15
+ let [, color] = HEX_COLOR_REGEX.exec(hex) ?? [];
16
+ const colorLength = color ? color.length : 0;
17
+ if (colorLength === 3) {
18
+ const c0 = color.charAt(0);
19
+ const c1 = color.charAt(1);
20
+ const c2 = color.charAt(2);
21
+ color = c0 + c0 + c1 + c1 + c2 + c2;
22
+ } else if (colorLength !== 6) {
19
23
  return [0, 0, 0];
20
24
  }
21
- const number_ = Number.parseInt(color, 16);
22
- return [number_ >> 16 & 255, number_ >> 8 & 255, number_ & 255];
25
+ const colorNumber = Number.parseInt(color, 16);
26
+ return [colorNumber >> 16 & 255, colorNumber >> 8 & 255, colorNumber & 255];
23
27
  };
24
28
 
25
29
  const rgbToAnsi256 = (r, g, b) => {
@@ -68,17 +72,17 @@ const bgOffset = 10;
68
72
  const supportedColor = isStdoutColorSupported();
69
73
  const mono = { close: "", open: "" };
70
74
  const esc = supportedColor > 0 ? (open, close) => {
71
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
75
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
72
76
  } : () => mono;
73
77
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
74
78
  const createHexFunction = (function_) => (hex) => {
75
79
  const [r, g, b] = convertHexToRgb(hex);
76
80
  return function_(r, g, b);
77
81
  };
78
- let createAnsi256 = (code) => esc(`38;5;${code}`, closeCode);
79
- let createBgAnsi256 = (code) => esc(`48;5;${code}`, bgCloseCode);
80
- let createRgb = (r, g, b) => esc(`38;2;${r};${g};${b}`, closeCode);
81
- let createBgRgb = (r, g, b) => esc(`48;2;${r};${g};${b}`, bgCloseCode);
82
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
83
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
84
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
85
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
82
86
  if (supportedColor === 1) {
83
87
  createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
84
88
  createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -179,7 +183,7 @@ const wrapText = (strings, values, properties) => {
179
183
  if (!strings) {
180
184
  return "";
181
185
  }
182
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
186
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
183
187
  if (string.includes("\x1B")) {
184
188
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
185
189
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -201,7 +205,7 @@ const createStyle = ({ props }, { close, open }) => {
201
205
  return style;
202
206
  };
203
207
  const Colorize = function() {
204
- const self = (string_) => `${string_}`;
208
+ const self = (string_) => String(string_);
205
209
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
206
210
  for (const name in baseColors) {
207
211
  styles[name] = {
@@ -1,4 +1,4 @@
1
- import { convertHexToRgb } from './convertHexToRgb-CWdAm2kE.mjs';
1
+ import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
2
2
 
3
3
  const colorNames = {
4
4
  aliceblue: [240, 248, 255],
@@ -161,23 +161,25 @@ const computeSubSteps = (stops, steps) => {
161
161
  throw new Error("Number of steps cannot be inferior to number of stops");
162
162
  }
163
163
  const substeps = [];
164
- for (let index = 1; index < l; index++) {
164
+ for (let index = 1; index < l; index += 1) {
165
165
  const step = (steps - 1) * (stops[index].position - stops[index - 1].position);
166
166
  substeps.push(Math.max(1, Math.round(step)));
167
167
  }
168
168
  let totalSubsteps = 1;
169
- for (let n = l - 1; n--; ) {
169
+ for (let n = l - 2; n >= 0; n -= 1) {
170
170
  totalSubsteps += substeps[n];
171
171
  }
172
172
  while (totalSubsteps !== steps) {
173
173
  if (totalSubsteps < steps) {
174
174
  const min = Math.min(...substeps);
175
- substeps[substeps.indexOf(min)]++;
176
- totalSubsteps++;
175
+ const minIndex = substeps.indexOf(min);
176
+ substeps[minIndex] = substeps[minIndex] + 1;
177
+ totalSubsteps += 1;
177
178
  } else {
178
179
  const max = Math.max(...substeps);
179
- substeps[substeps.indexOf(max)]--;
180
- totalSubsteps--;
180
+ const maxIndex = substeps.indexOf(max);
181
+ substeps[maxIndex] = substeps[maxIndex] - 1;
182
+ totalSubsteps -= 1;
181
183
  }
182
184
  }
183
185
  return substeps;
@@ -262,7 +264,7 @@ const HSV_MAX = { h: 360, s: 1, v: 1 };
262
264
  const calculateStepSize = (start, end, steps) => {
263
265
  const step = {};
264
266
  for (const k in start) {
265
- if (Object.prototype.hasOwnProperty.call(start, k)) {
267
+ if (Object.hasOwn(start, k)) {
266
268
  step[k] = steps === 0 ? 0 : (end[k] - start[k]) / steps;
267
269
  }
268
270
  }
@@ -271,21 +273,14 @@ const calculateStepSize = (start, end, steps) => {
271
273
  const interpolate = (step, start, index, max) => {
272
274
  const color = {};
273
275
  for (const k in start) {
274
- if (Object.prototype.hasOwnProperty.call(start, k)) {
275
- color[k] = step[k] * index + start[k];
276
- color[k] = color[k] < 0 ? (
277
- // eslint-disable-next-line security/detect-object-injection
278
- color[k] + max[k]
279
- ) : (
280
- // eslint-disable-next-line security/detect-object-injection
281
- max[k] === 1 ? (
282
- // eslint-disable-next-line security/detect-object-injection
283
- color[k]
284
- ) : (
285
- // eslint-disable-next-line security/detect-object-injection
286
- color[k] % max[k]
287
- )
288
- );
276
+ if (Object.hasOwn(start, k)) {
277
+ let value = step[k] * index + start[k];
278
+ if (value < 0) {
279
+ value += max[k];
280
+ } else if (max[k] !== 1) {
281
+ value %= max[k];
282
+ }
283
+ color[k] = value;
289
284
  }
290
285
  }
291
286
  return color;
@@ -295,7 +290,7 @@ const interpolateRgb = (stop1, stop2, steps) => {
295
290
  const end = { b: stop2.color[2], g: stop2.color[1], r: stop2.color[0] };
296
291
  const step = calculateStepSize(start, end, steps);
297
292
  const gradient = [{ ...start }];
298
- for (let index = 1; index < steps; index++) {
293
+ for (let index = 1; index < steps; index += 1) {
299
294
  const color = interpolate(step, start, index, RGBA_MAX);
300
295
  gradient.push({
301
296
  b: Math.floor(color.b),
@@ -335,7 +330,7 @@ const interpolateHsv = (stop1, stop2, steps, mode) => {
335
330
  diff = 360 - start.h + end.h;
336
331
  }
337
332
  step.h = (-1) ** (trigonometric ? 1 : 0) * Math.abs(diff) / steps;
338
- for (let index = 1; index < steps; index++) {
333
+ for (let index = 1; index < steps; index += 1) {
339
334
  const color = interpolate(step, start, index, HSV_MAX);
340
335
  gradient.push(hsvToRgb(color.h, color.s, color.v));
341
336
  }
@@ -357,7 +352,7 @@ class GradientBuilder {
357
352
  let p = -1;
358
353
  let lastColorLess = false;
359
354
  for (const [index, stop_] of stops.entries()) {
360
- let stop = {};
355
+ let stop;
361
356
  const hasPosition = stop_.position !== void 0;
362
357
  if (havingPositions !== hasPosition) {
363
358
  throw new Error("Cannot mix positioned and non-positioned color stops");
@@ -375,7 +370,7 @@ class GradientBuilder {
375
370
  color = stopInput.color;
376
371
  } else if (typeof stopInput.color === "string") {
377
372
  color = stopInput.color.includes("#") ? convertHexToRgb(stopInput.color) : colorNames[stopInput.color];
378
- } else if (stopInput.color.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
373
+ } else if (stopInput.color && "r" in stopInput.color && "g" in stopInput.color && "b" in stopInput.color) {
379
374
  color = [stopInput.color.r, stopInput.color.g, stopInput.color.b];
380
375
  }
381
376
  }
@@ -400,7 +395,7 @@ class GradientBuilder {
400
395
  color: stop_.includes("#") ? convertHexToRgb(stop_) : colorNames[stop_],
401
396
  position: index / (l - 1)
402
397
  };
403
- } else if (stop_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
398
+ } else if (stop_?.r !== void 0 && stop_?.g !== void 0 && stop_?.b !== void 0) {
404
399
  stop = {
405
400
  color: [stop_.r, stop_.g, stop_.b],
406
401
  position: index / (l - 1)
@@ -410,16 +405,18 @@ class GradientBuilder {
410
405
  }
411
406
  this.stops.push(stop);
412
407
  }
413
- if (this.stops[0].position !== 0) {
408
+ const firstStop = this.stops[0];
409
+ if (firstStop.position !== 0) {
414
410
  this.stops.unshift({
415
- color: this.stops[0].color,
411
+ color: firstStop.color,
416
412
  position: 0
417
413
  });
418
- l++;
414
+ l += 1;
419
415
  }
420
- if (this.stops[l - 1].position !== 1) {
416
+ const lastStop = this.stops[l - 1];
417
+ if (lastStop.position !== 1) {
421
418
  this.stops.push({
422
- color: this.stops[l - 1].color,
419
+ color: lastStop.color,
423
420
  position: 1
424
421
  });
425
422
  }
@@ -427,10 +424,10 @@ class GradientBuilder {
427
424
  reverse() {
428
425
  const stops = [];
429
426
  for (const stop of this.stops) {
430
- const stop_ = { ...stop, position: 1 - stop.position };
431
- stops.push(stop_);
427
+ const reversedStop = { ...stop, position: 1 - stop.position };
428
+ stops.push(reversedStop);
432
429
  }
433
- return new GradientBuilder(this.#colorize, stops.reverse());
430
+ return new GradientBuilder(this.#colorize, stops.toReversed());
434
431
  }
435
432
  loop() {
436
433
  const stops1 = [];
@@ -447,7 +444,7 @@ class GradientBuilder {
447
444
  position: 1 - (stop.position || 0) / 2
448
445
  });
449
446
  }
450
- return new GradientBuilder(this.#colorize, [...stops1, ...stops2.reverse()]);
447
+ return new GradientBuilder(this.#colorize, [...stops1, ...stops2.toReversed()]);
451
448
  }
452
449
  rgb(steps) {
453
450
  const subSteps = computeSubSteps(this.stops, steps);
@@ -458,7 +455,7 @@ class GradientBuilder {
458
455
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
459
456
  }
460
457
  });
461
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
458
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
462
459
  const rgbs = interpolateRgb(this.stops[index], this.stops[index + 1], subSteps[index]);
463
460
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
464
461
  }
@@ -474,7 +471,7 @@ class GradientBuilder {
474
471
  stop.color = [rgbs[1].r, rgbs[1].g, rgbs[1].b];
475
472
  }
476
473
  });
477
- for (let index = 0, l = this.stops.length; index < l - 1; index++) {
474
+ for (let index = 0, l = this.stops.length; index < l - 1; index += 1) {
478
475
  const rgbs = interpolateHsv(this.stops[index], this.stops[index + 1], subSteps[index], mode);
479
476
  gradient.splice(gradient.length, 0, ...rgbs.map((rgb) => this.#colorize.rgb(rgb.r, rgb.g, rgb.b)));
480
477
  }
@@ -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-DvkHBM3-.cjs');
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 - 1; n--; ) {
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[substeps.indexOf(min)]++;
180
- totalSubsteps++;
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[substeps.indexOf(max)]--;
184
- totalSubsteps--;
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.prototype.hasOwnProperty.call(start, k)) {
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.prototype.hasOwnProperty.call(start, k)) {
279
- color[k] = step[k] * index + start[k];
280
- color[k] = color[k] < 0 ? (
281
- // eslint-disable-next-line security/detect-object-injection
282
- color[k] + max[k]
283
- ) : (
284
- // eslint-disable-next-line security/detect-object-injection
285
- max[k] === 1 ? (
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.r !== void 0 && stopInput.color.g !== void 0 && stopInput.color.b) {
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_.r !== void 0 && stop_.g !== void 0 && stop_.b !== void 0) {
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
- if (this.stops[0].position !== 0) {
412
+ const firstStop = this.stops[0];
413
+ if (firstStop.position !== 0) {
418
414
  this.stops.unshift({
419
- color: this.stops[0].color,
415
+ color: firstStop.color,
420
416
  position: 0
421
417
  });
422
- l++;
418
+ l += 1;
423
419
  }
424
- if (this.stops[l - 1].position !== 1) {
420
+ const lastStop = this.stops[l - 1];
421
+ if (lastStop.position !== 1) {
425
422
  this.stops.push({
426
- color: this.stops[l - 1].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 stop_ = { ...stop, position: 1 - stop.position };
435
- stops.push(stop_);
431
+ const reversedStop = { ...stop, position: 1 - stop.position };
432
+ stops.push(reversedStop);
436
433
  }
437
- return new GradientBuilder(this.#colorize, stops.reverse());
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.reverse()]);
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,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
4
- const convertHexToRgb = require('./convertHexToRgb-DvkHBM3-.cjs');
4
+ const convertHexToRgb = require('./convertHexToRgb-51-edHxE.cjs');
5
5
  const rgbToAnsi256 = require('./rgbToAnsi256-DL8eajTz.cjs');
6
6
 
7
7
  function ansiRegex({ onlyFirst = false } = {}) {
@@ -20,17 +20,17 @@ const bgOffset = 10;
20
20
  const supportedColor = isAnsiColorSupported.isStdoutColorSupported();
21
21
  const mono = { close: "", open: "" };
22
22
  const esc = supportedColor > 0 ? (open, close) => {
23
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
23
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
24
24
  } : () => mono;
25
25
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256.rgbToAnsi256(Number(r), Number(g), Number(b)));
26
26
  const createHexFunction = (function_) => (hex) => {
27
27
  const [r, g, b] = convertHexToRgb.convertHexToRgb(hex);
28
28
  return function_(r, g, b);
29
29
  };
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);
30
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
31
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
32
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
33
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
34
34
  if (supportedColor === 1) {
35
35
  createAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)), closeCode);
36
36
  createBgAnsi256 = (code) => esc(rgbToAnsi256.ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -131,7 +131,7 @@ const wrapText = (strings, values, properties) => {
131
131
  if (!strings) {
132
132
  return "";
133
133
  }
134
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
134
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
135
135
  if (string.includes("\x1B")) {
136
136
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
137
137
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -153,7 +153,7 @@ const createStyle = ({ props }, { close, open }) => {
153
153
  return style;
154
154
  };
155
155
  const Colorize = function() {
156
- const self = (string_) => `${string_}`;
156
+ const self = (string_) => String(string_);
157
157
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
158
158
  for (const name in baseColors) {
159
159
  styles[name] = {
@@ -1,5 +1,5 @@
1
1
  import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported';
2
- import { convertHexToRgb } from './convertHexToRgb-CWdAm2kE.mjs';
2
+ import { convertHexToRgb } from './convertHexToRgb-BZwJEiMZ.mjs';
3
3
  import { ansi256To16, rgbToAnsi16, rgbToAnsi256 } from './rgbToAnsi256-BdS0fomP.mjs';
4
4
 
5
5
  function ansiRegex({ onlyFirst = false } = {}) {
@@ -18,17 +18,17 @@ const bgOffset = 10;
18
18
  const supportedColor = isStdoutColorSupported();
19
19
  const mono = { close: "", open: "" };
20
20
  const esc = supportedColor > 0 ? (open, close) => {
21
- return { close: `\x1B[${close}m`, open: `\x1B[${open}m` };
21
+ return { close: `\x1B[${String(close)}m`, open: `\x1B[${String(open)}m` };
22
22
  } : () => mono;
23
23
  const createRgbFunction = (function_) => (r, g, b) => function_(rgbToAnsi256(Number(r), Number(g), Number(b)));
24
24
  const createHexFunction = (function_) => (hex) => {
25
25
  const [r, g, b] = convertHexToRgb(hex);
26
26
  return function_(r, g, b);
27
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);
28
+ let createAnsi256 = (code) => esc(`38;5;${String(code)}`, closeCode);
29
+ let createBgAnsi256 = (code) => esc(`48;5;${String(code)}`, bgCloseCode);
30
+ let createRgb = (r, g, b) => esc(`38;2;${String(r)};${String(g)};${String(b)}`, closeCode);
31
+ let createBgRgb = (r, g, b) => esc(`48;2;${String(r)};${String(g)};${String(b)}`, bgCloseCode);
32
32
  if (supportedColor === 1) {
33
33
  createAnsi256 = (code) => esc(ansi256To16(Number(code)), closeCode);
34
34
  createBgAnsi256 = (code) => esc(ansi256To16(Number(code)) + bgOffset, bgCloseCode);
@@ -129,7 +129,7 @@ const wrapText = (strings, values, properties) => {
129
129
  if (!strings) {
130
130
  return "";
131
131
  }
132
- let string = strings.raw == void 0 ? `${strings}` : String.raw(strings, ...values);
132
+ let string = strings.raw === void 0 ? String(strings) : String.raw(strings, ...values);
133
133
  if (string.includes("\x1B")) {
134
134
  for (let currentProperties = properties; currentProperties; currentProperties = currentProperties.props) {
135
135
  string = stringReplaceAll(string, currentProperties.close, currentProperties.open);
@@ -151,7 +151,7 @@ const createStyle = ({ props }, { close, open }) => {
151
151
  return style;
152
152
  };
153
153
  const Colorize = function() {
154
- const self = (string_) => `${string_}`;
154
+ const self = (string_) => String(string_);
155
155
  self.strip = (value) => value.replaceAll(ansiRegex(), "");
156
156
  for (const name in baseColors) {
157
157
  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 };
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-BA3gZZXz.cjs');
6
- const convertHexToRgb = require('./packem_shared/convertHexToRgb-DvkHBM3-.cjs');
5
+ const colorize_server = require('./packem_shared/colorize.server-BFVt4Z2R.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(""));
@@ -44,9 +44,10 @@ const TEMPLATE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)
44
44
  const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
45
45
  const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
46
46
  const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
47
+ const CHUNK_SPLIT_REGEX = /\s*,\s*/;
47
48
  const parseArguments = (name, value) => {
48
49
  const results = [];
49
- const chunks = value.trim().split(/\s*,\s*/);
50
+ const chunks = value.trim().split(CHUNK_SPLIT_REGEX);
50
51
  let matches;
51
52
  for (const chunk of chunks) {
52
53
  const number = Number(chunk);
@@ -85,7 +86,7 @@ const buildStyle = (colorize, styles) => {
85
86
  const enabled = {};
86
87
  for (const layer of styles) {
87
88
  for (const style of layer.styles) {
88
- enabled[style[0]] = layer.inverse ? null : style.slice(1);
89
+ enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
89
90
  }
90
91
  }
91
92
  let current = colorize;
@@ -129,7 +130,7 @@ const makeTemplate = (colorize) => (string) => {
129
130
  );
130
131
  chunks.push(chunk.join(""));
131
132
  if (styles.length > 0) {
132
- throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
133
+ throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
133
134
  }
134
135
  return chunks.join("");
135
136
  };
package/dist/template.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { C as Colorize } from './packem_shared/colorize.server-ry9FZNfG.mjs';
2
- import { convertHexToRgb } from './packem_shared/convertHexToRgb-CWdAm2kE.mjs';
1
+ import { C as Colorize } from './packem_shared/colorize.server-BVtbrTcf.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(""));
@@ -40,9 +40,10 @@ const TEMPLATE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)
40
40
  const STYLE_REGEX = /(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi;
41
41
  const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
42
42
  const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
43
+ const CHUNK_SPLIT_REGEX = /\s*,\s*/;
43
44
  const parseArguments = (name, value) => {
44
45
  const results = [];
45
- const chunks = value.trim().split(/\s*,\s*/);
46
+ const chunks = value.trim().split(CHUNK_SPLIT_REGEX);
46
47
  let matches;
47
48
  for (const chunk of chunks) {
48
49
  const number = Number(chunk);
@@ -81,7 +82,7 @@ const buildStyle = (colorize, styles) => {
81
82
  const enabled = {};
82
83
  for (const layer of styles) {
83
84
  for (const style of layer.styles) {
84
- enabled[style[0]] = layer.inverse ? null : style.slice(1);
85
+ enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
85
86
  }
86
87
  }
87
88
  let current = colorize;
@@ -125,7 +126,7 @@ const makeTemplate = (colorize) => (string) => {
125
126
  );
126
127
  chunks.push(chunk.join(""));
127
128
  if (styles.length > 0) {
128
- throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
129
+ throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
129
130
  }
130
131
  return chunks.join("");
131
132
  };
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} hex
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} hex
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} str
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} hex
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} hex
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} str
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} hex
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} hex
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} str
125
+ * @param {string} string
126
126
  * @returns {string}
127
127
  */
128
128
  strip: (string: string) => string;
@@ -7,6 +7,6 @@
7
7
  */
8
8
  /**
9
9
  * Clamp a number within the inclusive range specified by min and max.
10
- * @note: The ternary operator is a tick quicker than Math.min(Math.max(num, min), max).
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;
@@ -7,6 +7,6 @@
7
7
  */
8
8
  /**
9
9
  * Clamp a number within the inclusive range specified by min and max.
10
- * @note: The ternary operator is a tick quicker than Math.min(Math.max(num, min), max).
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;
@@ -7,6 +7,6 @@
7
7
  */
8
8
  /**
9
9
  * Clamp a number within the inclusive range specified by min and max.
10
- * @note: The ternary operator is a tick quicker than Math.min(Math.max(num, min), max).
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;
@@ -5,18 +5,4 @@
5
5
  *
6
6
  * Copyright (c) 2023, webdiscus
7
7
  */
8
- import type { ColorValueHex } from "../types.d.cts";
9
- /**
10
- * Convert hex color string to RGB values.
11
- *
12
- * A hexadecimal color code can be 3 or 6 digits with an optional "#" prefix.
13
- *
14
- * The 3 digits specifies an RGB doublet data as a fully opaque color.
15
- * For example, "#123" specifies the color that is represented by "#112233".
16
- *
17
- * The 6 digits specifies a fully opaque color.
18
- * For example, "#112233".
19
- * @param {string} hex A string that contains the hexadecimal RGB color representation.
20
- * @returns {[number, number, number]} The red, green, blue values in range [0, 255] .
21
- */
22
- export declare const convertHexToRgb: (hex: ColorValueHex | string) => [number, number, number];
8
+ export declare const convertHexToRgb: (hex: string) => [number, number, number];
@@ -5,18 +5,4 @@
5
5
  *
6
6
  * Copyright (c) 2023, webdiscus
7
7
  */
8
- import type { ColorValueHex } from "../types.d.ts";
9
- /**
10
- * Convert hex color string to RGB values.
11
- *
12
- * A hexadecimal color code can be 3 or 6 digits with an optional "#" prefix.
13
- *
14
- * The 3 digits specifies an RGB doublet data as a fully opaque color.
15
- * For example, "#123" specifies the color that is represented by "#112233".
16
- *
17
- * The 6 digits specifies a fully opaque color.
18
- * For example, "#112233".
19
- * @param {string} hex A string that contains the hexadecimal RGB color representation.
20
- * @returns {[number, number, number]} The red, green, blue values in range [0, 255] .
21
- */
22
- export declare const convertHexToRgb: (hex: ColorValueHex | string) => [number, number, number];
8
+ export declare const convertHexToRgb: (hex: string) => [number, number, number];
@@ -5,18 +5,4 @@
5
5
  *
6
6
  * Copyright (c) 2023, webdiscus
7
7
  */
8
- import type { ColorValueHex } from "../types.d.ts";
9
- /**
10
- * Convert hex color string to RGB values.
11
- *
12
- * A hexadecimal color code can be 3 or 6 digits with an optional "#" prefix.
13
- *
14
- * The 3 digits specifies an RGB doublet data as a fully opaque color.
15
- * For example, "#123" specifies the color that is represented by "#112233".
16
- *
17
- * The 6 digits specifies a fully opaque color.
18
- * For example, "#112233".
19
- * @param {string} hex A string that contains the hexadecimal RGB color representation.
20
- * @returns {[number, number, number]} The red, green, blue values in range [0, 255] .
21
- */
22
- export declare const convertHexToRgb: (hex: ColorValueHex | string) => [number, number, number];
8
+ export declare const convertHexToRgb: (hex: string) => [number, number, number];
package/dist/utils.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
- const convertHexToRgb = require('./packem_shared/convertHexToRgb-DvkHBM3-.cjs');
5
+ const convertHexToRgb = require('./packem_shared/convertHexToRgb-51-edHxE.cjs');
6
6
  const rgbToAnsi256 = require('./packem_shared/rgbToAnsi256-DL8eajTz.cjs');
7
7
 
8
8
 
package/dist/utils.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export { convertHexToRgb } from './packem_shared/convertHexToRgb-CWdAm2kE.mjs';
1
+ export { convertHexToRgb } from './packem_shared/convertHexToRgb-BZwJEiMZ.mjs';
2
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": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "Terminal and Console string styling done right.",
5
5
  "keywords": [
6
6
  "256",
@@ -55,7 +55,7 @@
55
55
  "xterm",
56
56
  "yellow"
57
57
  ],
58
- "homepage": "https://www.visulima.com/docs/package/colorize",
58
+ "homepage": "https://visulima.com/packages/colorize/",
59
59
  "repository": {
60
60
  "type": "git",
61
61
  "url": "git+https://github.com/visulima/visulima.git",
@@ -165,10 +165,8 @@
165
165
  "LICENSE.md"
166
166
  ],
167
167
  "dependencies": {
168
- "@visulima/is-ansi-color-supported": "3.0.0-alpha.6"
168
+ "@visulima/is-ansi-color-supported": "3.0.0-alpha.8"
169
169
  },
170
- "peerDependencies": {},
171
- "optionalDependencies": {},
172
170
  "engines": {
173
171
  "node": ">=22.13 <=25.x"
174
172
  },
@@ -1,13 +0,0 @@
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 };
@@ -1,17 +0,0 @@
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;