enterprise-ansi-styles-v7 7.0.0 → 7.1.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 +119 -44
- package/package.json +8 -2
package/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const aura = require("aura3")
|
|
2
|
+
const $Object = require("es-object-atoms")
|
|
3
|
+
const _false = require("false-value")
|
|
4
|
+
const equal = require("@10xly/strict-equals")
|
|
5
|
+
const getIntrinsic = require("es-intrinsic-cache")
|
|
6
|
+
|
|
7
|
+
const parseInt = getIntrinsic("%Number.parseInt%")
|
|
2
8
|
|
|
3
9
|
const ZERO = require("@positive-numbers/zero")
|
|
4
10
|
const ONE = require("@positive-numbers/one")
|
|
@@ -128,16 +134,23 @@ const ansiStyles = assembleStyles()
|
|
|
128
134
|
|
|
129
135
|
module.exports = ansiStyles
|
|
130
136
|
|
|
131
|
-
const modifierNames = module.exports.modifierNames = Object.keys(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
137
|
+
const modifierNames = (module.exports.modifierNames = $Object.keys(
|
|
138
|
+
styles.modifier
|
|
139
|
+
))
|
|
140
|
+
const foregroundColorNames = (module.exports.foregroundColorNames =
|
|
141
|
+
$Object.keys(styles.color))
|
|
142
|
+
const backgroundColorNames = (module.exports.backgroundColorNames =
|
|
143
|
+
$Object.keys(styles.bgColor))
|
|
144
|
+
const colorNames = (module.exports.colorNames = [
|
|
145
|
+
...foregroundColorNames,
|
|
146
|
+
...backgroundColorNames,
|
|
147
|
+
])
|
|
135
148
|
|
|
136
149
|
function assembleStyles() {
|
|
137
|
-
const codes = new Map
|
|
150
|
+
const codes = require("construct-new")({ target: getIntrinsic("Map") })
|
|
138
151
|
|
|
139
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
140
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
152
|
+
for (const [groupName, group] of $Object.entries(styles)) {
|
|
153
|
+
for (const [styleName, style] of $Object.entries(group)) {
|
|
141
154
|
styles[styleName] = {
|
|
142
155
|
open: `\u001B[${style[ZERO]}m`,
|
|
143
156
|
close: `\u001B[${style[ONE]}m`,
|
|
@@ -148,15 +161,15 @@ function assembleStyles() {
|
|
|
148
161
|
codes.set(style[ZERO], style[ONE])
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
Object.defineProperty(styles, groupName, {
|
|
164
|
+
$Object.defineProperty(styles, groupName, {
|
|
152
165
|
value: group,
|
|
153
|
-
enumerable:
|
|
166
|
+
enumerable: _false(),
|
|
154
167
|
})
|
|
155
168
|
}
|
|
156
169
|
|
|
157
|
-
Object.defineProperty(styles, "codes", {
|
|
170
|
+
$Object.defineProperty(styles, "codes", {
|
|
158
171
|
value: codes,
|
|
159
|
-
enumerable:
|
|
172
|
+
enumerable: _false(),
|
|
160
173
|
})
|
|
161
174
|
|
|
162
175
|
styles.color.close = `\u001B[${THIRTY_NINE}m`
|
|
@@ -169,10 +182,10 @@ function assembleStyles() {
|
|
|
169
182
|
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET)
|
|
170
183
|
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET)
|
|
171
184
|
|
|
172
|
-
Object.defineProperties(styles, {
|
|
185
|
+
$Object.defineProperties(styles, {
|
|
173
186
|
rgbToAnsi256: {
|
|
174
187
|
value(red, green, blue) {
|
|
175
|
-
if (red
|
|
188
|
+
if (aura.and(equal(red, green), equal(green, blue))) {
|
|
176
189
|
if (red < EIGHT) {
|
|
177
190
|
return SIXTEEN
|
|
178
191
|
}
|
|
@@ -181,42 +194,89 @@ function assembleStyles() {
|
|
|
181
194
|
return aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_ONE))
|
|
182
195
|
}
|
|
183
196
|
|
|
184
|
-
return
|
|
197
|
+
return aura.add(
|
|
198
|
+
aura.round(
|
|
199
|
+
aura.multiply(
|
|
200
|
+
aura.divide(
|
|
201
|
+
aura.subtract(red, EIGHT),
|
|
202
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FORTY_SEVEN))
|
|
203
|
+
),
|
|
204
|
+
TWENTY_FOUR
|
|
205
|
+
)
|
|
206
|
+
),
|
|
207
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))
|
|
208
|
+
)
|
|
185
209
|
}
|
|
186
210
|
|
|
187
|
-
return (
|
|
188
|
-
|
|
189
|
-
aura.add(
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
return aura.add(
|
|
212
|
+
SIXTEEN,
|
|
213
|
+
aura.add(
|
|
214
|
+
aura.multiply(
|
|
215
|
+
THIRTY_SIX,
|
|
216
|
+
aura.round(
|
|
217
|
+
aura.multiply(
|
|
218
|
+
aura.divide(
|
|
219
|
+
red,
|
|
220
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))
|
|
221
|
+
),
|
|
222
|
+
FIVE
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
),
|
|
226
|
+
aura.add(
|
|
227
|
+
aura.multiply(
|
|
228
|
+
SIX,
|
|
229
|
+
aura.round(
|
|
230
|
+
aura.multiply(
|
|
231
|
+
aura.divide(
|
|
232
|
+
green,
|
|
233
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))
|
|
234
|
+
),
|
|
235
|
+
FIVE
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
),
|
|
239
|
+
aura.round(
|
|
240
|
+
aura.multiply(
|
|
241
|
+
aura.divide(
|
|
242
|
+
blue,
|
|
243
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))
|
|
244
|
+
),
|
|
245
|
+
FIVE
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
)
|
|
192
250
|
)
|
|
193
251
|
},
|
|
194
|
-
enumerable:
|
|
252
|
+
enumerable: _false(),
|
|
195
253
|
},
|
|
196
254
|
hexToRgb: {
|
|
197
255
|
value(hex) {
|
|
198
256
|
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(SIXTEEN))
|
|
199
|
-
if (
|
|
257
|
+
if (aura.not(matches)) {
|
|
200
258
|
return [ZERO, ZERO, ZERO]
|
|
201
259
|
}
|
|
202
260
|
|
|
203
261
|
let [colorString] = matches
|
|
204
262
|
|
|
205
|
-
if (colorString.length
|
|
263
|
+
if (equal(colorString.length, THREE)) {
|
|
206
264
|
colorString = [...colorString]
|
|
207
265
|
.map((character) => character + character)
|
|
208
|
-
.join("")
|
|
266
|
+
.join(require("empty-string"))
|
|
209
267
|
}
|
|
210
268
|
|
|
211
|
-
const integer =
|
|
269
|
+
const integer = parseInt(colorString, SIXTEEN)
|
|
212
270
|
|
|
213
271
|
return [
|
|
214
|
-
(integer >> SIXTEEN) &
|
|
215
|
-
|
|
272
|
+
(integer >> SIXTEEN) &
|
|
273
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
|
|
274
|
+
(integer >> EIGHT) &
|
|
275
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
|
|
216
276
|
integer & aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
|
|
217
277
|
]
|
|
218
278
|
},
|
|
219
|
-
enumerable:
|
|
279
|
+
enumerable: _false(),
|
|
220
280
|
},
|
|
221
281
|
ansi256ToAnsi: {
|
|
222
282
|
value(code) {
|
|
@@ -225,7 +285,7 @@ function assembleStyles() {
|
|
|
225
285
|
}
|
|
226
286
|
|
|
227
287
|
if (code < SIXTEEN) {
|
|
228
|
-
return aura.add(NINETY,
|
|
288
|
+
return aura.add(NINETY, code - EIGHT)
|
|
229
289
|
}
|
|
230
290
|
|
|
231
291
|
let red
|
|
@@ -233,47 +293,62 @@ function assembleStyles() {
|
|
|
233
293
|
let blue
|
|
234
294
|
|
|
235
295
|
if (code >= aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))) {
|
|
236
|
-
red =
|
|
296
|
+
red = aura.divide(
|
|
297
|
+
aura.add(
|
|
298
|
+
aura.multiply(
|
|
299
|
+
aura.subtract(
|
|
300
|
+
code,
|
|
301
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))
|
|
302
|
+
),
|
|
303
|
+
TEN
|
|
304
|
+
),
|
|
305
|
+
EIGHT
|
|
306
|
+
),
|
|
307
|
+
aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))
|
|
308
|
+
)
|
|
237
309
|
green = red
|
|
238
310
|
blue = red
|
|
239
311
|
} else {
|
|
240
|
-
code
|
|
312
|
+
code = subtract(code, SIXTEEN)
|
|
241
313
|
|
|
242
|
-
const remainder = code
|
|
314
|
+
const remainder = aura.modulo(code, THIRTY_SIX)
|
|
243
315
|
|
|
244
|
-
red =
|
|
245
|
-
green =
|
|
246
|
-
blue = (remainder
|
|
316
|
+
red = aura.divide(aura.floor(aura.divide(code, THIRTY_SIX)), FIVE)
|
|
317
|
+
green = aura.divide(aura.floor(aura.divide(remainder, SIX)), FIVE)
|
|
318
|
+
blue = aura.divide(aura.modulo(remainder, SIX), FIVE)
|
|
247
319
|
}
|
|
248
320
|
|
|
249
|
-
const value = aura.multiply(
|
|
321
|
+
const value = aura.multiply(aura.max(red, green, blue), TWO)
|
|
250
322
|
|
|
251
|
-
if (value
|
|
323
|
+
if (equal(value, ZERO)) {
|
|
252
324
|
return THIRTY
|
|
253
325
|
}
|
|
254
326
|
|
|
255
|
-
let result =
|
|
256
|
-
|
|
257
|
-
(
|
|
327
|
+
let result = aura.add(
|
|
328
|
+
THIRTY,
|
|
329
|
+
(aura.round(blue) << TWO) |
|
|
330
|
+
(aura.round(green) << ONE) |
|
|
331
|
+
aura.round(red)
|
|
332
|
+
)
|
|
258
333
|
|
|
259
|
-
if (value
|
|
334
|
+
if (equal(value, TWO)) {
|
|
260
335
|
result = aura.add(result, SIXTY)
|
|
261
336
|
}
|
|
262
337
|
|
|
263
338
|
return result
|
|
264
339
|
},
|
|
265
|
-
enumerable:
|
|
340
|
+
enumerable: _false(),
|
|
266
341
|
},
|
|
267
342
|
rgbToAnsi: {
|
|
268
343
|
value: (red, green, blue) =>
|
|
269
344
|
styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
270
|
-
enumerable:
|
|
345
|
+
enumerable: _false(),
|
|
271
346
|
},
|
|
272
347
|
hexToAnsi: {
|
|
273
348
|
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
274
|
-
enumerable:
|
|
349
|
+
enumerable: _false(),
|
|
275
350
|
},
|
|
276
351
|
})
|
|
277
352
|
|
|
278
353
|
return styles
|
|
279
|
-
}
|
|
354
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "enterprise-ansi-styles-v7",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "ANSI escape codes for styling strings in the terminal.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"asp",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"test": "node test"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
29
30
|
"@positive-numbers/eight": "^3.0.0",
|
|
30
31
|
"@positive-numbers/fifty-five": "^3.0.0",
|
|
31
32
|
"@positive-numbers/fifty-three": "^3.0.0",
|
|
@@ -76,7 +77,12 @@
|
|
|
76
77
|
"@positive-numbers/twenty-two": "^3.0.0",
|
|
77
78
|
"@positive-numbers/two": "^3.0.0",
|
|
78
79
|
"@positive-numbers/zero": "^3.0.0",
|
|
79
|
-
"aura3": "^1.0.3-enterprise.stable"
|
|
80
|
+
"aura3": "^1.0.3-enterprise.stable",
|
|
81
|
+
"construct-new": "^2.0.4",
|
|
82
|
+
"empty-string": "^1.1.1",
|
|
83
|
+
"es-intrinsic-cache": "^1.0.1",
|
|
84
|
+
"es-object-atoms": "^1.1.1",
|
|
85
|
+
"false-value": "^2.0.6"
|
|
80
86
|
},
|
|
81
87
|
"devDependencies": {
|
|
82
88
|
"inquirer": "^13.1.0"
|