Changeset 0c6b92a for imaps-frontend/node_modules/ansi-styles/index.js
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/ansi-styles/index.js
rd565449 r0c6b92a 1 1 'use strict'; 2 const colorConvert = require('color-convert');3 2 4 const wrapAnsi16 = (fn, offset) => function (){5 const code = fn .apply(colorConvert, arguments);3 const wrapAnsi16 = (fn, offset) => (...args) => { 4 const code = fn(...args); 6 5 return `\u001B[${code + offset}m`; 7 6 }; 8 7 9 const wrapAnsi256 = (fn, offset) => function (){10 const code = fn .apply(colorConvert, arguments);8 const wrapAnsi256 = (fn, offset) => (...args) => { 9 const code = fn(...args); 11 10 return `\u001B[${38 + offset};5;${code}m`; 12 11 }; 13 12 14 const wrapAnsi16m = (fn, offset) => function (){15 const rgb = fn .apply(colorConvert, arguments);13 const wrapAnsi16m = (fn, offset) => (...args) => { 14 const rgb = fn(...args); 16 15 return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; 16 }; 17 18 const ansi2ansi = n => n; 19 const rgb2rgb = (r, g, b) => [r, g, b]; 20 21 const setLazyProperty = (object, property, get) => { 22 Object.defineProperty(object, property, { 23 get: () => { 24 const value = get(); 25 26 Object.defineProperty(object, property, { 27 value, 28 enumerable: true, 29 configurable: true 30 }); 31 32 return value; 33 }, 34 enumerable: true, 35 configurable: true 36 }); 37 }; 38 39 /** @type {typeof import('color-convert')} */ 40 let colorConvert; 41 const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => { 42 if (colorConvert === undefined) { 43 colorConvert = require('color-convert'); 44 } 45 46 const offset = isBackground ? 10 : 0; 47 const styles = {}; 48 49 for (const [sourceSpace, suite] of Object.entries(colorConvert)) { 50 const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace; 51 if (sourceSpace === targetSpace) { 52 styles[name] = wrap(identity, offset); 53 } else if (typeof suite === 'object') { 54 styles[name] = wrap(suite[targetSpace], offset); 55 } 56 } 57 58 return styles; 17 59 }; 18 60 … … 40 82 cyan: [36, 39], 41 83 white: [37, 39], 42 gray: [90, 39],43 84 44 85 // Bright color 86 blackBright: [90, 39], 45 87 redBright: [91, 39], 46 88 greenBright: [92, 39], … … 73 115 }; 74 116 75 // Fix humans 76 styles.color.grey = styles.color.gray; 117 // Alias bright black as gray (and grey) 118 styles.color.gray = styles.color.blackBright; 119 styles.bgColor.bgGray = styles.bgColor.bgBlackBright; 120 styles.color.grey = styles.color.blackBright; 121 styles.bgColor.bgGrey = styles.bgColor.bgBlackBright; 77 122 78 for (const groupName of Object.keys(styles)) { 79 const group = styles[groupName]; 80 81 for (const styleName of Object.keys(group)) { 82 const style = group[styleName]; 83 123 for (const [groupName, group] of Object.entries(styles)) { 124 for (const [styleName, style] of Object.entries(group)) { 84 125 styles[styleName] = { 85 126 open: `\u001B[${style[0]}m`, … … 96 137 enumerable: false 97 138 }); 98 99 Object.defineProperty(styles, 'codes', {100 value: codes,101 enumerable: false102 });103 139 } 104 140 105 const ansi2ansi = n => n; 106 const rgb2rgb = (r, g, b) => [r, g, b]; 141 Object.defineProperty(styles, 'codes', { 142 value: codes, 143 enumerable: false 144 }); 107 145 108 146 styles.color.close = '\u001B[39m'; 109 147 styles.bgColor.close = '\u001B[49m'; 110 148 111 styles.color.ansi = { 112 ansi: wrapAnsi16(ansi2ansi, 0) 113 }; 114 styles.color.ansi256 = { 115 ansi256: wrapAnsi256(ansi2ansi, 0) 116 }; 117 styles.color.ansi16m = { 118 rgb: wrapAnsi16m(rgb2rgb, 0) 119 }; 120 121 styles.bgColor.ansi = { 122 ansi: wrapAnsi16(ansi2ansi, 10) 123 }; 124 styles.bgColor.ansi256 = { 125 ansi256: wrapAnsi256(ansi2ansi, 10) 126 }; 127 styles.bgColor.ansi16m = { 128 rgb: wrapAnsi16m(rgb2rgb, 10) 129 }; 130 131 for (let key of Object.keys(colorConvert)) { 132 if (typeof colorConvert[key] !== 'object') { 133 continue; 134 } 135 136 const suite = colorConvert[key]; 137 138 if (key === 'ansi16') { 139 key = 'ansi'; 140 } 141 142 if ('ansi16' in suite) { 143 styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0); 144 styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10); 145 } 146 147 if ('ansi256' in suite) { 148 styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0); 149 styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10); 150 } 151 152 if ('rgb' in suite) { 153 styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0); 154 styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10); 155 } 156 } 149 setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false)); 150 setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false)); 151 setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false)); 152 setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true)); 153 setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true)); 154 setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true)); 157 155 158 156 return styles;
Note:
See TracChangeset
for help on using the changeset viewer.