tinky 1.2.0 → 1.2.2
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cliBoxes from "cli-boxes";
|
|
2
|
-
import
|
|
2
|
+
import ansis from "ansis";
|
|
3
3
|
import { colorize } from "../utils/colorize.js";
|
|
4
4
|
/**
|
|
5
5
|
* Renders the border for a DOM node.
|
|
@@ -38,7 +38,7 @@ export const renderBorder = (x, y, node, output) => {
|
|
|
38
38
|
(showRightBorder ? box.topRight : ""), topBorderColor, "foreground")
|
|
39
39
|
: undefined;
|
|
40
40
|
if (showTopBorder && dimTopBorderColor) {
|
|
41
|
-
topBorder =
|
|
41
|
+
topBorder = ansis.dim(topBorder);
|
|
42
42
|
}
|
|
43
43
|
let verticalBorderHeight = height;
|
|
44
44
|
if (showTopBorder) {
|
|
@@ -49,11 +49,11 @@ export const renderBorder = (x, y, node, output) => {
|
|
|
49
49
|
}
|
|
50
50
|
let leftBorder = (colorize(box.left, leftBorderColor, "foreground") + "\n").repeat(verticalBorderHeight);
|
|
51
51
|
if (dimLeftBorderColor) {
|
|
52
|
-
leftBorder =
|
|
52
|
+
leftBorder = ansis.dim(leftBorder);
|
|
53
53
|
}
|
|
54
54
|
let rightBorder = (colorize(box.right, rightBorderColor, "foreground") + "\n").repeat(verticalBorderHeight);
|
|
55
55
|
if (dimRightBorderColor) {
|
|
56
|
-
rightBorder =
|
|
56
|
+
rightBorder = ansis.dim(rightBorder);
|
|
57
57
|
}
|
|
58
58
|
let bottomBorder = showBottomBorder
|
|
59
59
|
? colorize((showLeftBorder ? box.bottomLeft : "") +
|
|
@@ -61,7 +61,7 @@ export const renderBorder = (x, y, node, output) => {
|
|
|
61
61
|
(showRightBorder ? box.bottomRight : ""), bottomBorderColor, "foreground")
|
|
62
62
|
: undefined;
|
|
63
63
|
if (showBottomBorder && dimBottomBorderColor) {
|
|
64
|
-
bottomBorder =
|
|
64
|
+
bottomBorder = ansis.dim(bottomBorder);
|
|
65
65
|
}
|
|
66
66
|
const offsetY = showTopBorder ? 1 : 0;
|
|
67
67
|
if (topBorder) {
|
package/lib/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { useFocusManager, type FocusManager, } from "./hooks/use-focus-manager.j
|
|
|
21
21
|
export { useIsScreenReaderEnabled } from "./hooks/use-is-screen-reader-enabled.js";
|
|
22
22
|
export { measureElement } from "./utils/measure-element.js";
|
|
23
23
|
export { type Dimension } from "./utils/dimension.js";
|
|
24
|
+
export { type ForegroundColorName } from "./utils/colorize.js";
|
|
24
25
|
export { applyTextStyles, type TextStyles } from "./utils/apply-text-styles.js";
|
|
25
26
|
export { type DOMElement, type DOMNode, type DOMNodeAttribute, type ElementNames, type NodeNames, type TextName, type TextNode, type TinkyNode, } from "./core/dom.js";
|
|
26
27
|
export { type Styles } from "./core/styles.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type ForegroundColorName } from "chalk";
|
|
2
1
|
import { type LiteralUnion } from "type-fest";
|
|
2
|
+
import { type ForegroundColorName } from "./colorize.js";
|
|
3
3
|
/**
|
|
4
4
|
* Common text styling props used by components like Text and Separator.
|
|
5
5
|
*/
|
|
6
6
|
export interface TextStyles {
|
|
7
7
|
/**
|
|
8
|
-
* Change text color. Tinky uses
|
|
8
|
+
* Change text color. Tinky uses Ansis under the hood, so all its functionality
|
|
9
9
|
* is supported.
|
|
10
10
|
*/
|
|
11
11
|
readonly color?: LiteralUnion<ForegroundColorName, string>;
|
|
@@ -39,7 +39,7 @@ export interface TextStyles {
|
|
|
39
39
|
readonly inverse?: boolean;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Applies text styles (color, bold, etc.) to a string using
|
|
42
|
+
* Applies text styles (color, bold, etc.) to a string using Ansis.
|
|
43
43
|
*
|
|
44
44
|
* @param text - The text to apply styles to.
|
|
45
45
|
* @param styles - The styles to apply.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ansis from "ansis";
|
|
2
2
|
import { colorize } from "./colorize.js";
|
|
3
3
|
/**
|
|
4
|
-
* Applies text styles (color, bold, etc.) to a string using
|
|
4
|
+
* Applies text styles (color, bold, etc.) to a string using Ansis.
|
|
5
5
|
*
|
|
6
6
|
* @param text - The text to apply styles to.
|
|
7
7
|
* @param styles - The styles to apply.
|
|
@@ -9,7 +9,7 @@ import { colorize } from "./colorize.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export const applyTextStyles = (text, styles) => {
|
|
11
11
|
if (styles.dimColor) {
|
|
12
|
-
text =
|
|
12
|
+
text = ansis.dim(text);
|
|
13
13
|
}
|
|
14
14
|
if (styles.color) {
|
|
15
15
|
text = colorize(text, styles.color, "foreground");
|
|
@@ -18,19 +18,19 @@ export const applyTextStyles = (text, styles) => {
|
|
|
18
18
|
text = colorize(text, styles.backgroundColor, "background");
|
|
19
19
|
}
|
|
20
20
|
if (styles.bold) {
|
|
21
|
-
text =
|
|
21
|
+
text = ansis.bold(text);
|
|
22
22
|
}
|
|
23
23
|
if (styles.italic) {
|
|
24
|
-
text =
|
|
24
|
+
text = ansis.italic(text);
|
|
25
25
|
}
|
|
26
26
|
if (styles.underline) {
|
|
27
|
-
text =
|
|
27
|
+
text = ansis.underline(text);
|
|
28
28
|
}
|
|
29
29
|
if (styles.strikethrough) {
|
|
30
|
-
text =
|
|
30
|
+
text = ansis.strikethrough(text);
|
|
31
31
|
}
|
|
32
32
|
if (styles.inverse) {
|
|
33
|
-
text =
|
|
33
|
+
text = ansis.inverse(text);
|
|
34
34
|
}
|
|
35
35
|
return text;
|
|
36
36
|
};
|
package/lib/utils/colorize.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported foreground color names.
|
|
3
|
+
*/
|
|
4
|
+
export type ForegroundColorName = "black" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright";
|
|
5
|
+
/**
|
|
6
|
+
* Supported background color names.
|
|
7
|
+
*/
|
|
8
|
+
export type BackgroundColorName = "bgBlack" | "bgBlue" | "bgBlueBright" | "bgCyan" | "bgCyanBright" | "bgGray" | "bgGreen" | "bgGreenBright" | "bgMagenta" | "bgMagentaBright" | "bgRed" | "bgRedBright" | "bgWhite" | "bgWhiteBright" | "bgYellow" | "bgYellowBright";
|
|
1
9
|
/**
|
|
2
10
|
* Type representing the target of the color application (foreground or
|
|
3
11
|
* background).
|
|
4
12
|
*/
|
|
5
13
|
type ColorType = "foreground" | "background";
|
|
6
14
|
/**
|
|
7
|
-
* Applies a color to a string using
|
|
15
|
+
* Applies a color to a string using Ansis.
|
|
8
16
|
* Supports named colors, hex codes, RGB values, and ANSI-256 color codes.
|
|
9
17
|
*
|
|
10
18
|
* @param str - The string to colorize.
|
package/lib/utils/colorize.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ansis from "ansis";
|
|
2
2
|
const rgbRegex = /^rgb\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/;
|
|
3
3
|
const ansiRegex = /^ansi256\(\s?(\d+)\s?\)$/;
|
|
4
4
|
const isNamedColor = (color) => {
|
|
5
|
-
return color in
|
|
5
|
+
return color in ansis;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* Applies a color to a string using
|
|
8
|
+
* Applies a color to a string using Ansis.
|
|
9
9
|
* Supports named colors, hex codes, RGB values, and ANSI-256 color codes.
|
|
10
10
|
*
|
|
11
11
|
* @param str - The string to colorize.
|
|
@@ -19,15 +19,15 @@ export const colorize = (str, color, type) => {
|
|
|
19
19
|
}
|
|
20
20
|
if (isNamedColor(color)) {
|
|
21
21
|
if (type === "foreground") {
|
|
22
|
-
return
|
|
22
|
+
return ansis[color](str);
|
|
23
23
|
}
|
|
24
24
|
const methodName = `bg${color.charAt(0).toUpperCase() + color.slice(1)}`;
|
|
25
|
-
return
|
|
25
|
+
return ansis[methodName](str);
|
|
26
26
|
}
|
|
27
27
|
if (color.startsWith("#")) {
|
|
28
28
|
return type === "foreground"
|
|
29
|
-
?
|
|
30
|
-
:
|
|
29
|
+
? ansis.hex(color)(str)
|
|
30
|
+
: ansis.bgHex(color)(str);
|
|
31
31
|
}
|
|
32
32
|
if (color.startsWith("ansi256")) {
|
|
33
33
|
const matches = ansiRegex.exec(color);
|
|
@@ -35,9 +35,7 @@ export const colorize = (str, color, type) => {
|
|
|
35
35
|
return str;
|
|
36
36
|
}
|
|
37
37
|
const value = Number(matches[1]);
|
|
38
|
-
return type === "foreground"
|
|
39
|
-
? chalk.ansi256(value)(str)
|
|
40
|
-
: chalk.bgAnsi256(value)(str);
|
|
38
|
+
return type === "foreground" ? ansis.fg(value)(str) : ansis.bg(value)(str);
|
|
41
39
|
}
|
|
42
40
|
if (color.startsWith("rgb")) {
|
|
43
41
|
const matches = rgbRegex.exec(color);
|
|
@@ -48,8 +46,8 @@ export const colorize = (str, color, type) => {
|
|
|
48
46
|
const secondValue = Number(matches[2]);
|
|
49
47
|
const thirdValue = Number(matches[3]);
|
|
50
48
|
return type === "foreground"
|
|
51
|
-
?
|
|
52
|
-
:
|
|
49
|
+
? ansis.rgb(firstValue, secondValue, thirdValue)(str)
|
|
50
|
+
: ansis.bgRgb(firstValue, secondValue, thirdValue)(str);
|
|
53
51
|
}
|
|
54
52
|
return str;
|
|
55
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinky",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "React for CLIs, re-imagined with the Taffy engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@alcalzone/ansi-tokenize": "^0.2.3",
|
|
43
43
|
"ansi-escapes": "^7.2.0",
|
|
44
44
|
"ansi-styles": "^6.2.3",
|
|
45
|
+
"ansis": "^4.2.0",
|
|
45
46
|
"auto-bind": "^5.0.1",
|
|
46
|
-
"chalk": "^5.6.2",
|
|
47
47
|
"cli-boxes": "^4.0.1",
|
|
48
48
|
"cli-truncate": "^5.1.1",
|
|
49
49
|
"code-excerpt": "^4.0.0",
|
|
@@ -70,9 +70,11 @@
|
|
|
70
70
|
"@commitlint/cli": "^20.3.0",
|
|
71
71
|
"@commitlint/config-conventional": "^20.3.0",
|
|
72
72
|
"@semantic-release/changelog": "^6.0.3",
|
|
73
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
73
74
|
"@semantic-release/git": "^10.0.1",
|
|
74
|
-
"@semantic-release/github": "^12.0.
|
|
75
|
+
"@semantic-release/github": "^12.0.2",
|
|
75
76
|
"@semantic-release/npm": "^13.1.3",
|
|
77
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
76
78
|
"@sinonjs/fake-timers": "^15.1.0",
|
|
77
79
|
"@types/bun": "^1.3.6",
|
|
78
80
|
"@types/react-reconciler": "^0.32.3",
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"@types/stack-utils": "^2.0.3",
|
|
81
83
|
"@types/ws": "^8.18.1",
|
|
82
84
|
"boxen": "^8.0.1",
|
|
85
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
83
86
|
"delay": "^7.0.0",
|
|
84
87
|
"eslint": "^9.39.2",
|
|
85
88
|
"eslint-plugin-react": "^7.37.5",
|