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

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 (40) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +32 -30
  4. package/dist/ansi-codes.d.mts +1 -1
  5. package/dist/colorize.browser.d.mts +1 -1
  6. package/dist/colorize.server.d.mts +1 -1
  7. package/dist/css-code.d.mts +1 -1
  8. package/dist/gradient.cjs +9 -7
  9. package/dist/gradient.mjs +9 -7
  10. package/dist/index.browser.d.mts +5 -5
  11. package/dist/index.browser.mjs +1 -1
  12. package/dist/index.server.cjs +24 -15
  13. package/dist/index.server.d.cts +2 -2
  14. package/dist/index.server.d.mts +5 -5
  15. package/dist/index.server.d.ts +2 -2
  16. package/dist/index.server.mjs +1 -1
  17. package/dist/packem_shared/{Colorize-Ca9CXTcj.mjs → Colorize-BQ-Wlgs0.js} +9 -13
  18. package/dist/packem_shared/{Colorize-BenP3bFn.mjs → Colorize-rJUN0RFg.js} +24 -15
  19. package/dist/packem_shared/{GradientBuilder-DTnSGyYW.mjs → GradientBuilder-CkX4Imo9.mjs} +36 -39
  20. package/dist/packem_shared/{GradientBuilder-BXOgJeHi.cjs → GradientBuilder-DRrwebdU.cjs} +36 -39
  21. package/dist/packem_shared/{colorize.server-BA3gZZXz.cjs → colorize.server-CwTmhs0e.cjs} +14 -9
  22. package/dist/packem_shared/{colorize.server-ry9FZNfG.mjs → colorize.server-YxoHIDUp.mjs} +14 -9
  23. package/dist/packem_shared/convertHexToRgb-51-edHxE.cjs +21 -0
  24. package/dist/packem_shared/convertHexToRgb-BZwJEiMZ.mjs +17 -0
  25. package/dist/template.cjs +15 -7
  26. package/dist/template.mjs +15 -7
  27. package/dist/types.d.cts +3 -3
  28. package/dist/types.d.mts +3 -3
  29. package/dist/types.d.ts +3 -3
  30. package/dist/util/clamp.d.cts +1 -1
  31. package/dist/util/clamp.d.mts +1 -1
  32. package/dist/util/clamp.d.ts +1 -1
  33. package/dist/util/convert-hex-to-rgb.d.cts +1 -15
  34. package/dist/util/convert-hex-to-rgb.d.mts +1 -15
  35. package/dist/util/convert-hex-to-rgb.d.ts +1 -15
  36. package/dist/utils.cjs +1 -1
  37. package/dist/utils.mjs +1 -1
  38. package/package.json +4 -4
  39. package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +0 -13
  40. package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +0 -17
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-CwTmhs0e.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,16 +44,24 @@ 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);
53
54
  if (!Number.isNaN(number)) {
54
55
  results.push(number);
55
56
  } else if (matches = STRING_REGEX.exec(chunk)) {
56
- results.push(matches[2].replace(ESCAPE_REGEX, (_, escape, character) => escape ? unescape(escape) : character));
57
+ results.push(
58
+ matches[2].replaceAll(ESCAPE_REGEX, (_, escape, character) => {
59
+ if (escape) {
60
+ return unescape(escape);
61
+ }
62
+ return character;
63
+ })
64
+ );
57
65
  } else {
58
66
  throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
59
67
  }
@@ -85,7 +93,7 @@ const buildStyle = (colorize, styles) => {
85
93
  const enabled = {};
86
94
  for (const layer of styles) {
87
95
  for (const style of layer.styles) {
88
- enabled[style[0]] = layer.inverse ? null : style.slice(1);
96
+ enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
89
97
  }
90
98
  }
91
99
  let current = colorize;
@@ -129,7 +137,7 @@ const makeTemplate = (colorize) => (string) => {
129
137
  );
130
138
  chunks.push(chunk.join(""));
131
139
  if (styles.length > 0) {
132
- throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
140
+ throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
133
141
  }
134
142
  return chunks.join("");
135
143
  };
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-YxoHIDUp.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,16 +40,24 @@ 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);
49
50
  if (!Number.isNaN(number)) {
50
51
  results.push(number);
51
52
  } else if (matches = STRING_REGEX.exec(chunk)) {
52
- results.push(matches[2].replace(ESCAPE_REGEX, (_, escape, character) => escape ? unescape(escape) : character));
53
+ results.push(
54
+ matches[2].replaceAll(ESCAPE_REGEX, (_, escape, character) => {
55
+ if (escape) {
56
+ return unescape(escape);
57
+ }
58
+ return character;
59
+ })
60
+ );
53
61
  } else {
54
62
  throw new Error(`Invalid template style argument: ${chunk} (in style '${name}')`);
55
63
  }
@@ -81,7 +89,7 @@ const buildStyle = (colorize, styles) => {
81
89
  const enabled = {};
82
90
  for (const layer of styles) {
83
91
  for (const style of layer.styles) {
84
- enabled[style[0]] = layer.inverse ? null : style.slice(1);
92
+ enabled[style[0]] = layer.inverse ? void 0 : style.slice(1);
85
93
  }
86
94
  }
87
95
  let current = colorize;
@@ -125,7 +133,7 @@ const makeTemplate = (colorize) => (string) => {
125
133
  );
126
134
  chunks.push(chunk.join(""));
127
135
  if (styles.length > 0) {
128
- throw new Error(`template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
136
+ throw new Error(`template literal is missing ${String(styles.length)} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`);
129
137
  }
130
138
  return chunks.join("");
131
139
  };
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.mts";
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.1",
3
+ "version": "2.0.0-alpha.10",
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,10 @@
165
165
  "LICENSE.md"
166
166
  ],
167
167
  "dependencies": {
168
- "@visulima/is-ansi-color-supported": "3.0.0-alpha.1"
168
+ "@visulima/is-ansi-color-supported": "3.0.0-alpha.10"
169
169
  },
170
170
  "engines": {
171
- "node": ">=22.13 <=25.x"
171
+ "node": "^22.14.0 || >=24.10.0"
172
172
  },
173
173
  "os": [
174
174
  "darwin",
@@ -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;