ansi-styles 5.1.0 → 5.2.0
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/index.js +51 -42
- package/package.json +1 -1
- package/readme.md +3 -3
package/index.js
CHANGED
@@ -101,49 +101,58 @@ function assembleStyles() {
|
|
101
101
|
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
102
102
|
|
103
103
|
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
104
|
+
Object.defineProperties(styles, {
|
105
|
+
rgbToAnsi256: {
|
106
|
+
value: (red, green, blue) => {
|
107
|
+
// We use the extended greyscale palette here, with the exception of
|
108
|
+
// black and white. normal palette only has 4 greyscale shades.
|
109
|
+
if (red === green && green === blue) {
|
110
|
+
if (red < 8) {
|
111
|
+
return 16;
|
112
|
+
}
|
113
|
+
|
114
|
+
if (red > 248) {
|
115
|
+
return 231;
|
116
|
+
}
|
117
|
+
|
118
|
+
return Math.round(((red - 8) / 247) * 24) + 232;
|
119
|
+
}
|
120
|
+
|
121
|
+
return 16 +
|
122
|
+
(36 * Math.round(red / 255 * 5)) +
|
123
|
+
(6 * Math.round(green / 255 * 5)) +
|
124
|
+
Math.round(blue / 255 * 5);
|
125
|
+
},
|
126
|
+
enumerable: false
|
127
|
+
},
|
128
|
+
hexToRgb: {
|
129
|
+
value: hex => {
|
130
|
+
const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
|
131
|
+
if (!matches) {
|
132
|
+
return [0, 0, 0];
|
133
|
+
}
|
134
|
+
|
135
|
+
let {colorString} = matches.groups;
|
136
|
+
|
137
|
+
if (colorString.length === 3) {
|
138
|
+
colorString = colorString.split('').map(character => character + character).join('');
|
139
|
+
}
|
140
|
+
|
141
|
+
const integer = Number.parseInt(colorString, 16);
|
142
|
+
|
143
|
+
return [
|
144
|
+
(integer >> 16) & 0xFF,
|
145
|
+
(integer >> 8) & 0xFF,
|
146
|
+
integer & 0xFF
|
147
|
+
];
|
148
|
+
},
|
149
|
+
enumerable: false
|
150
|
+
},
|
151
|
+
hexToAnsi256: {
|
152
|
+
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
153
|
+
enumerable: false
|
135
154
|
}
|
136
|
-
|
137
|
-
const integer = Number.parseInt(colorString, 16);
|
138
|
-
|
139
|
-
return [
|
140
|
-
(integer >> 16) & 0xFF,
|
141
|
-
(integer >> 8) & 0xFF,
|
142
|
-
integer & 0xFF
|
143
|
-
];
|
144
|
-
};
|
145
|
-
|
146
|
-
styles.hexToAnsi256 = hex => styles.rgbToAnsi256(...styles.hexToRgb(hex));
|
155
|
+
});
|
147
156
|
|
148
157
|
return styles;
|
149
158
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -20,9 +20,9 @@ const style = require('ansi-styles');
|
|
20
20
|
console.log(`${style.green.open}Hello world!${style.green.close}`);
|
21
21
|
|
22
22
|
|
23
|
-
// Color conversion between
|
24
|
-
// NOTE:
|
25
|
-
// may be degraded to fit
|
23
|
+
// Color conversion between 256/truecolor
|
24
|
+
// NOTE: When converting from truecolor to 256 colors, the original color
|
25
|
+
// may be degraded to fit the new color palette. This means terminals
|
26
26
|
// that do not support 16 million colors will best-match the
|
27
27
|
// original color.
|
28
28
|
console.log(`${style.color.ansi256(style.rgbToAnsi256(199, 20, 250))}Hello World${style.color.close}`)
|