summaryrefslogtreecommitdiff
path: root/node_modules/ansi-styles/index.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 16:27:06 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 16:27:06 +0800
commit2db6defc0b555d93d2363ba6c6dfa19df7dc7c11 (patch)
treea92c596973b150bbd1723b55facf38e0ab6258d8 /node_modules/ansi-styles/index.js
parent6dce4e2e8ed35a26af389b7ab388113381350444 (diff)
update
Diffstat (limited to 'node_modules/ansi-styles/index.js')
-rw-r--r--node_modules/ansi-styles/index.js136
1 files changed, 69 insertions, 67 deletions
diff --git a/node_modules/ansi-styles/index.js b/node_modules/ansi-styles/index.js
index 5d82581a..90a871c4 100644
--- a/node_modules/ansi-styles/index.js
+++ b/node_modules/ansi-styles/index.js
@@ -1,63 +1,21 @@
'use strict';
+const colorConvert = require('color-convert');
-const wrapAnsi16 = (fn, offset) => (...args) => {
- const code = fn(...args);
+const wrapAnsi16 = (fn, offset) => function () {
+ const code = fn.apply(colorConvert, arguments);
return `\u001B[${code + offset}m`;
};
-const wrapAnsi256 = (fn, offset) => (...args) => {
- const code = fn(...args);
+const wrapAnsi256 = (fn, offset) => function () {
+ const code = fn.apply(colorConvert, arguments);
return `\u001B[${38 + offset};5;${code}m`;
};
-const wrapAnsi16m = (fn, offset) => (...args) => {
- const rgb = fn(...args);
+const wrapAnsi16m = (fn, offset) => function () {
+ const rgb = fn.apply(colorConvert, arguments);
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
};
-const ansi2ansi = n => n;
-const rgb2rgb = (r, g, b) => [r, g, b];
-
-const setLazyProperty = (object, property, get) => {
- Object.defineProperty(object, property, {
- get: () => {
- const value = get();
-
- Object.defineProperty(object, property, {
- value,
- enumerable: true,
- configurable: true
- });
-
- return value;
- },
- enumerable: true,
- configurable: true
- });
-};
-
-/** @type {typeof import('color-convert')} */
-let colorConvert;
-const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
- if (colorConvert === undefined) {
- colorConvert = require('color-convert');
- }
-
- const offset = isBackground ? 10 : 0;
- const styles = {};
-
- for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
- const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
- if (sourceSpace === targetSpace) {
- styles[name] = wrap(identity, offset);
- } else if (typeof suite === 'object') {
- styles[name] = wrap(suite[targetSpace], offset);
- }
- }
-
- return styles;
-};
-
function assembleStyles() {
const codes = new Map();
const styles = {
@@ -81,9 +39,9 @@ function assembleStyles() {
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
+ gray: [90, 39],
// Bright color
- blackBright: [90, 39],
redBright: [91, 39],
greenBright: [92, 39],
yellowBright: [93, 39],
@@ -114,14 +72,15 @@ function assembleStyles() {
}
};
- // Alias bright black as gray (and grey)
- styles.color.gray = styles.color.blackBright;
- styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
- styles.color.grey = styles.color.blackBright;
- styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
+ // Fix humans
+ styles.color.grey = styles.color.gray;
+
+ for (const groupName of Object.keys(styles)) {
+ const group = styles[groupName];
+
+ for (const styleName of Object.keys(group)) {
+ const style = group[styleName];
- for (const [groupName, group] of Object.entries(styles)) {
- for (const [styleName, style] of Object.entries(group)) {
styles[styleName] = {
open: `\u001B[${style[0]}m`,
close: `\u001B[${style[1]}m`
@@ -136,22 +95,65 @@ function assembleStyles() {
value: group,
enumerable: false
});
+
+ Object.defineProperty(styles, 'codes', {
+ value: codes,
+ enumerable: false
+ });
}
- Object.defineProperty(styles, 'codes', {
- value: codes,
- enumerable: false
- });
+ const ansi2ansi = n => n;
+ const rgb2rgb = (r, g, b) => [r, g, b];
styles.color.close = '\u001B[39m';
styles.bgColor.close = '\u001B[49m';
- setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
- setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
- setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
- setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
- setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
- setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
+ styles.color.ansi = {
+ ansi: wrapAnsi16(ansi2ansi, 0)
+ };
+ styles.color.ansi256 = {
+ ansi256: wrapAnsi256(ansi2ansi, 0)
+ };
+ styles.color.ansi16m = {
+ rgb: wrapAnsi16m(rgb2rgb, 0)
+ };
+
+ styles.bgColor.ansi = {
+ ansi: wrapAnsi16(ansi2ansi, 10)
+ };
+ styles.bgColor.ansi256 = {
+ ansi256: wrapAnsi256(ansi2ansi, 10)
+ };
+ styles.bgColor.ansi16m = {
+ rgb: wrapAnsi16m(rgb2rgb, 10)
+ };
+
+ for (let key of Object.keys(colorConvert)) {
+ if (typeof colorConvert[key] !== 'object') {
+ continue;
+ }
+
+ const suite = colorConvert[key];
+
+ if (key === 'ansi16') {
+ key = 'ansi';
+ }
+
+ if ('ansi16' in suite) {
+ styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
+ styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
+ }
+
+ if ('ansi256' in suite) {
+ styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
+ styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
+ }
+
+ if ('rgb' in suite) {
+ styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
+ styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
+ }
+ }
return styles;
}