@visulima/colorize 1.3.2 → 1.4.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/CHANGELOG.md +15 -0
- package/README.md +93 -42
- package/dist/gradient.cjs +6 -6
- package/dist/gradient.cjs.map +1 -1
- package/dist/gradient.js +4 -4
- package/dist/gradient.js.map +1 -1
- package/dist/index.server.cjs +4 -4
- package/dist/index.server.cjs.map +1 -1
- package/dist/index.server.js +3 -3
- package/dist/index.server.js.map +1 -1
- package/dist/template.cjs +6 -6
- package/dist/template.cjs.map +1 -1
- package/dist/template.js +4 -4
- package/dist/template.js.map +1 -1
- package/dist/utils.cjs +10 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +9 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/package.json +20 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## @visulima/colorize [1.4.0](https://github.com/visulima/visulima/compare/@visulima/colorize@1.3.3...@visulima/colorize@1.4.0) (2024-04-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add detection of color spaces support: TrueColor, 256 colors, 16 colors, no color ([#391](https://github.com/visulima/visulima/issues/391)) ([f35525c](https://github.com/visulima/visulima/commit/f35525c2a23558405408977745dd59aba9c58a3f))
|
|
7
|
+
|
|
8
|
+
## @visulima/colorize [1.3.3](https://github.com/visulima/visulima/compare/@visulima/colorize@1.3.2...@visulima/colorize@1.3.3) (2024-04-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* **@visulima/is-ansi-color-supported:** upgraded to 2.2.0
|
|
15
|
+
|
|
1
16
|
## @visulima/colorize [1.3.2](https://github.com/visulima/visulima/compare/@visulima/colorize@1.3.1...@visulima/colorize@1.3.2) (2024-04-09)
|
|
2
17
|
|
|
3
18
|
|
package/README.md
CHANGED
|
@@ -33,7 +33,19 @@ For instance, you can use `green` to make `` green`Hello World!` `` pop, `` red`
|
|
|
33
33
|
## Why Colorize?
|
|
34
34
|
|
|
35
35
|
- Supports both **ESM** and **CommonJS**
|
|
36
|
-
-
|
|
36
|
+
- **TypeScript** support out of the box
|
|
37
|
+
- Supports **Deno**, **Next.JS** runtimes and **Browser** (not only chrome) (currently multi nesting is not supported)
|
|
38
|
+
- [Standard API](#base-colors) compatible with **Chalk**, switch from **Chalk** to **Colorize** without changing your code
|
|
39
|
+
|
|
40
|
+
```diff
|
|
41
|
+
- import chalk from 'chalk';
|
|
42
|
+
+ import chalk, { red } from '@visulima/colorize';
|
|
43
|
+
|
|
44
|
+
chalk.red.bold('Error!'); // <- Chalk like syntax works fine with Colorize
|
|
45
|
+
red.bold('Error!'); // <- the same result with Colorize
|
|
46
|
+
red.bold`Error!`; // <- the same result with Colorize
|
|
47
|
+
```
|
|
48
|
+
|
|
37
49
|
- Default import
|
|
38
50
|
- `import colorize from '@visulima/colorize'` or `const colorize = require('@visulima/colorize')`
|
|
39
51
|
- [Named import](#named-import)
|
|
@@ -42,17 +54,19 @@ For instance, you can use `green` to make `` green`Hello World!` `` pop, `` red`
|
|
|
42
54
|
- [Template literals](#template-literals) `` red`text` ``
|
|
43
55
|
- String styling with [tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates), see [template-literals](#tagged-template-literals)
|
|
44
56
|
- [Nested **template strings**](#nested-syntax) `` red`R ${green`G`} R` ``
|
|
45
|
-
- [ANSI
|
|
57
|
+
- [Base ANSI styles](#base-colors) `dim` **`bold`** _`italic`_ <u>`underline`</u> <s>`strikethrough`</s>
|
|
58
|
+
- [Base ANSI 16 colors](#base-colors) `` red`Error!` `` `` redBright`Error!` `` `` bgRed`Error!` `` `` bgRedBright`Error!` ``
|
|
59
|
+
- [ANSI 256 colors](#256-colors) and [TrueColor](#truecolor) (**RGB**, **HEX**) `` rgb(224, 17, 95)`Ruby` ``, `` hex('#96C')`Amethyst` ``
|
|
60
|
+
- [TrueColor](#truecolor) (**RGB**, **HEX**) `` rgb(224, 17, 95)`Ruby` ``, `` hex('#96C')`Amethyst` ``
|
|
61
|
+
- [Fallback](#fallback) to supported [color space](#color-support): TrueColor → 256 colors → 16 colors → no colors
|
|
46
62
|
- [ANSI codes](#escape-codes) as `open` and `close` property for each style `` `Hello ${red.open}World${red.close}!` ``
|
|
47
63
|
- [Strip ANSI codes](#strip) method `colorize.strip()`
|
|
48
64
|
- [Correct style break](#new-line) at the `end of line` when used `\n` in string
|
|
49
65
|
- Supports the [environment variables](#cli-vars) `NO_COLOR` `FORCE_COLOR` and flags `--no-color` `--color`
|
|
50
|
-
- Supports **Deno**, **Next.JS** runtimes and **Browser** (not only chrome) (currently multi nesting is not supported)
|
|
51
66
|
- Expressive API
|
|
52
67
|
- Doesn't extend `String.prototype`
|
|
53
68
|
- Up to **x3 faster** than **chalk**, [see benchmarks](#benchmark)
|
|
54
69
|
- **Auto detects** color support
|
|
55
|
-
- **TypeScript** support out of the box
|
|
56
70
|
- Clean and focused
|
|
57
71
|
- [String Gradient´s](#gradient)
|
|
58
72
|
|
|
@@ -167,31 +181,6 @@ if (typeof navigator !== "undefined" && typeof window !== "undefined" && !consol
|
|
|
167
181
|
}
|
|
168
182
|
```
|
|
169
183
|
|
|
170
|
-
### API
|
|
171
|
-
|
|
172
|
-
Colors and styles have standard names used by many popular libraries, such
|
|
173
|
-
as [chalk][chalk], [colorette][colorette], [kleur][kleur].
|
|
174
|
-
|
|
175
|
-
| Foreground colors | Background colors | Styles |
|
|
176
|
-
| :-------------------- | :------------------------ | ----------------------------------------------------------------------- |
|
|
177
|
-
| `black` | `bgBlack` | `dim` |
|
|
178
|
-
| `red` | `bgRed` | **`bold`** |
|
|
179
|
-
| `green` | `bgGreen` | _`italic`_ |
|
|
180
|
-
| `yellow` | `bgYellow` | <u>`underline`</u> |
|
|
181
|
-
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) |
|
|
182
|
-
| `magenta` | `bgMagenta` | <s>`doubleUnderline`</s> (_not included, because not widely supported_) |
|
|
183
|
-
| `cyan` | `bgCyan` | <s>`overline`</s> (_not included, because not widely supported_) |
|
|
184
|
-
| `white` | `bgWhite` | <s>`frame`</s> (_not included, because not widely supported_) |
|
|
185
|
-
| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | <s>`encircle`</s> (_not included, because not widely supported_) |
|
|
186
|
-
| `blackBright` | `bgBlackBright` | `inverse` |
|
|
187
|
-
| `redBright` | `bgRedBright` | `visible` |
|
|
188
|
-
| `greenBright` | `bgGreenBright` | `hidden` |
|
|
189
|
-
| `yellowBright` | `bgYellowBright` | `reset` |
|
|
190
|
-
| `blueBright` | `bgBlueBright` | |
|
|
191
|
-
| `magentaBright` | `bgMagentaBright` | |
|
|
192
|
-
| `cyanBright` | `bgCyanBright` | |
|
|
193
|
-
| `whiteBright` | `bgWhiteBright` | |
|
|
194
|
-
|
|
195
184
|
### Named import
|
|
196
185
|
|
|
197
186
|
The `@visulima/colorize` supports both the `default import` and `named import`.
|
|
@@ -346,7 +335,7 @@ Multiline nested template strings:
|
|
|
346
335
|
```typescript
|
|
347
336
|
import { red, green, hex, visible, inverse } from "@visulima/colorize";
|
|
348
337
|
|
|
349
|
-
// defined a
|
|
338
|
+
// defined a TrueColor as the constant
|
|
350
339
|
const orange = hex("#FFAB40");
|
|
351
340
|
|
|
352
341
|
// normal colors
|
|
@@ -367,6 +356,32 @@ DISK: ${orange`${(disk.used / disk.total) * 100}%`}
|
|
|
367
356
|
Output:\
|
|
368
357
|

|
|
369
358
|
|
|
359
|
+
<a id="base-colors" name="base-colors"></a>
|
|
360
|
+
## Base ANSI 16 colors and styles
|
|
361
|
+
|
|
362
|
+
Colors and styles have standard names used by many popular libraries, such
|
|
363
|
+
as [chalk][chalk], [colorette][colorette], [kleur][kleur].
|
|
364
|
+
|
|
365
|
+
| Foreground colors | Background colors | Styles |
|
|
366
|
+
| :-------------------- | :------------------------ | ----------------------------------------------------------------------- |
|
|
367
|
+
| `black` | `bgBlack` | `dim` |
|
|
368
|
+
| `red` | `bgRed` | **`bold`** |
|
|
369
|
+
| `green` | `bgGreen` | _`italic`_ |
|
|
370
|
+
| `yellow` | `bgYellow` | <u>`underline`</u> |
|
|
371
|
+
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) |
|
|
372
|
+
| `magenta` | `bgMagenta` | <s>`doubleUnderline`</s> (_not included, because not widely supported_) |
|
|
373
|
+
| `cyan` | `bgCyan` | <s>`overline`</s> (_not included, because not widely supported_) |
|
|
374
|
+
| `white` | `bgWhite` | <s>`frame`</s> (_not included, because not widely supported_) |
|
|
375
|
+
| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | <s>`encircle`</s> (_not included, because not widely supported_) |
|
|
376
|
+
| `blackBright` | `bgBlackBright` | `inverse` |
|
|
377
|
+
| `redBright` | `bgRedBright` | `visible` |
|
|
378
|
+
| `greenBright` | `bgGreenBright` | `hidden` |
|
|
379
|
+
| `yellowBright` | `bgYellowBright` | `reset` |
|
|
380
|
+
| `blueBright` | `bgBlueBright` | |
|
|
381
|
+
| `magentaBright` | `bgMagentaBright` | |
|
|
382
|
+
| `cyanBright` | `bgCyanBright` | |
|
|
383
|
+
| `whiteBright` | `bgWhiteBright` | |
|
|
384
|
+
|
|
370
385
|
## ANSI 256 colors
|
|
371
386
|
|
|
372
387
|
The pre-defined set of 256 colors.
|
|
@@ -395,6 +410,34 @@ Background function: `bgAnsi256(code)` has short alias `bg(code)`
|
|
|
395
410
|
|
|
396
411
|
See [ANSI color codes](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
|
|
397
412
|
|
|
413
|
+
### Fallback
|
|
414
|
+
|
|
415
|
+
If a terminal supports only 16 colors then ANSI 256 colors will be interpolated into base 16 colors.
|
|
416
|
+
|
|
417
|
+
#### Usage Example
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
import { bold, ansi256, fg, bgAnsi256, bg } from "@visulima/colorize";
|
|
421
|
+
|
|
422
|
+
// foreground color
|
|
423
|
+
ansi256(96)`Bright Cyan`;
|
|
424
|
+
fg(96)`Bright Cyan`; // alias for ansi256
|
|
425
|
+
|
|
426
|
+
// background color
|
|
427
|
+
bgAnsi256(105)`Bright Magenta`;
|
|
428
|
+
bg(105)`Bright Magenta`; // alias for bgAnsi256
|
|
429
|
+
|
|
430
|
+
// function is chainable
|
|
431
|
+
ansi256(96).bold`bold Bright Cyan`;
|
|
432
|
+
|
|
433
|
+
// function is avaliable in each style
|
|
434
|
+
bold.ansi256(96).underline`bold underline Bright Cyan`;
|
|
435
|
+
|
|
436
|
+
// you can combine the functions and styles in any order
|
|
437
|
+
bgAnsi256(105).ansi256(96)`cyan text on magenta background`;
|
|
438
|
+
bg(105).fg(96)`cyan text on magenta background`;
|
|
439
|
+
```
|
|
440
|
+
|
|
398
441
|
```typescript
|
|
399
442
|
import { bold, ansi256, fg, bgAnsi256, bg } from "@visulima/colorize";
|
|
400
443
|
|
|
@@ -441,6 +484,14 @@ bgRgb(224, 17, 95)`Ruby`;
|
|
|
441
484
|
bold.hex("#E0115F").bgHex("#96C")`ruby bold text on amethyst background`;
|
|
442
485
|
```
|
|
443
486
|
|
|
487
|
+
## Fallback
|
|
488
|
+
|
|
489
|
+
If a terminal does not support ANSI colors, the library will automatically fall back to the next supported color space.
|
|
490
|
+
|
|
491
|
+
> TrueColor —> 256 colors —> 16 colors —> no colors (black & white)
|
|
492
|
+
|
|
493
|
+
If you use the `hex()`, `rgb()` or `ansis256()` functions in a terminal not supported TrueColor or 256 colors, then colors will be interpolated.
|
|
494
|
+
|
|
444
495
|
<!--
|
|
445
496
|
Copy of a readme example from https://github.com/webdiscus/ansis
|
|
446
497
|
|
|
@@ -517,18 +568,18 @@ If you're on Windows, do yourself a favor and use [Windows Terminal](https://git
|
|
|
517
568
|
|
|
518
569
|
## Comparison of most popular libraries
|
|
519
570
|
|
|
520
|
-
| Library<br>**\*\***\_\_**\*\***<br> - name<br> - named import | Code size | Naming colors | ANSI 256<br>colors | True-<br>color | Chained<br>syntax | Nested<br>template strings | New<br>Line |
|
|
521
|
-
| :---------------------------------------------------------------- | :----------------------------------------------------------------------------- | :----------------------------------------: | :----------------: | :------------: | :---------------: | :------------------------: | :---------: | :------------------------------------------------------: |
|
|
522
|
-
| [`@visulima/colorize`][npm-url]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
523
|
-
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` |
|
|
524
|
-
| [`ansis`][ansis]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
525
|
-
| [`chalk`][chalk]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
526
|
-
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` |
|
|
527
|
-
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
528
|
-
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr> |  | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` |
|
|
529
|
-
| [`colors.js`][colors.js]<br><nobr>`❌ named import`</nobr> |  | <nobr>_non-standard_</nobr><br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
530
|
-
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` |
|
|
531
|
-
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` |
|
|
571
|
+
| Library<br>**\*\***\_\_**\*\***<br> - name<br> - named import | Code size | Naming colors | ANSI 256<br>colors | True-<br>color | Chained<br>syntax | Nested<br>template strings | New<br>Line | Supports<br>CLI params<br>ENV vars | Fallbacks |
|
|
572
|
+
| :---------------------------------------------------------------- | :----------------------------------------------------------------------------- | :----------------------------------------: | :----------------: | :------------: | :---------------: | :------------------------: | :---------: | :------------------------------------------------------: | ---------------------------------- |
|
|
573
|
+
| [`@visulima/colorize`][npm-url]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color |
|
|
574
|
+
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` | ❌ |
|
|
575
|
+
| [`ansis`][ansis]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color |
|
|
576
|
+
| [`chalk`][chalk]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color |
|
|
577
|
+
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` | 16 colors<br>no color |
|
|
578
|
+
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color |
|
|
579
|
+
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr> |  | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` | no color |
|
|
580
|
+
| [`colors.js`][colors.js]<br><nobr>`❌ named import`</nobr> |  | <nobr>_non-standard_</nobr><br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color |
|
|
581
|
+
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` | no color |
|
|
582
|
+
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color |
|
|
532
583
|
|
|
533
584
|
> **Note**
|
|
534
585
|
>
|
package/dist/gradient.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var isAnsiColorSupported = require('@visulima/is-ansi-color-supported');
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
`)&&(n=n.replace(/(\r*\n)/g,
|
|
7
|
-
`),u=Reflect.apply(Math.max,null,[...i.map(b=>b.length),
|
|
5
|
+
function B({onlyFirst:r=!1}={}){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(e,r?void 0:"g")}var h=(r,e,o)=>e>r?e:r>o?o:r;var S=r=>{let[,e]=/([a-f\d]{3,6})/i.exec(r)??[],o=e?e.length:0;if(o===3)e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2];else if(o!==6)return [0,0,0];let n=Number.parseInt(e,16);return [n>>16&255,n>>8&255,n&255]};var v=(r,e,o)=>r===e&&e===o?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/51)+6*Math.round(e/51)+Math.round(o/51),R=r=>{let e,o,n;if(r<8)return 30+r;if(r<16)return 90+(r-8);if(r>=232)e=o=n=((r-232)*10+8)/255;else {r-=16;let i=r%36;e=Math.floor(r/36)/5,o=Math.floor(i/6)/5,n=i%6/5;}let t=Math.max(e,o,n)*2;if(t===0)return 30;let s=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(e));return t===2?s+60:s},G=(r,e,o)=>R(v(r,e,o));var c=39,m=49,T=isAnsiColorSupported.isStdoutColorSupported(),Z={close:"",open:""},l=T>0?(r,e)=>({close:"\x1B["+e+"m",open:"\x1B["+r+"m"}):()=>Z,L=r=>(e,o,n)=>r(v(Number(e),Number(o),Number(n))),E=r=>e=>{let[o,n,t]=S(e);return r(o,n,t)},A=r=>l("38;5;"+r,c),O=r=>l("48;5;"+r,m),x=(r,e,o)=>l("38;2;"+r+";"+e+";"+o,c),k=(r,e,o)=>l("48;2;"+r+";"+e+";"+o,m);T===1?(A=r=>l(R(Number(r)),c),O=r=>l(R(Number(r))+10,m),x=(r,e,o)=>l(G(Number(r),Number(e),Number(o)),c),k=(r,e,o)=>l(G(Number(r),Number(e),Number(o))+10,m)):T===2&&(x=L(A),k=L(O));var M={bold:l(1,22),dim:l(2,22),hidden:l(8,28),inverse:l(7,27),italic:l(3,23),overline:l(53,55),reset:l(0,0),strike:l(9,29),strikethrough:l(9,29),underline:l(4,24),visible:Z},z={bgBlack:l(40,m),bgBlackBright:l(100,m),bgBlue:l(44,m),bgBlueBright:l(104,m),bgCyan:l(46,m),bgCyanBright:l(106,m),bgGray:l(100,m),bgGreen:l(42,m),bgGreenBright:l(102,m),bgGrey:l(100,m),bgMagenta:l(45,m),bgMagentaBright:l(105,m),bgRed:l(41,m),bgRedBright:l(101,m),bgWhite:l(47,m),bgWhiteBright:l(107,m),bgYellow:l(43,m),bgYellowBright:l(103,m),black:l(30,c),blackBright:l(90,c),blue:l(34,c),blueBright:l(94,c),cyan:l(36,c),cyanBright:l(96,c),gray:l(90,c),green:l(32,c),greenBright:l(92,c),grey:l(90,c),magenta:l(35,c),magentaBright:l(95,c),red:l(31,c),redBright:l(91,c),white:l(37,c),whiteBright:l(97,c),yellow:l(33,c),yellowBright:l(93,c)},H={bg:r=>O(h(r,0,255)),bgHex:E(k),bgRgb:(r,e,o)=>k(h(r,0,255),h(e,0,255),h(o,0,255)),fg:r=>A(h(r,0,255)),hex:E(x),rgb:(r,e,o)=>x(h(r,0,255),h(e,0,255),h(o,0,255))};var F=(r,e,o)=>{if(e==="")return r;let n=r.indexOf(e);if(n<0)return r;let t=e.length,s=0,i="";for(;~n;)i+=r.slice(s,n)+o,s=n+t,n=r.indexOf(e,s);return i+r.slice(s)};var d={},N=null,Q=(r,e,o)=>{if(!r)return "";let n=r.raw==null?r+"":String.raw(r,...e);if(n.includes("\x1B"))for(let t=o;t;t=t.props)n=F(n,t.close,t.open);return n.includes(`
|
|
6
|
+
`)&&(n=n.replace(/(\r*\n)/g,o.closeStack+"$1"+o.openStack)),o.openStack+n+o.closeStack},I=({props:r},{close:e,open:o})=>{let n=(r?.openStack??"")+o,t=e+(r?.closeStack??""),s=(i,...u)=>Q(i,u,s.props);return Object.setPrototypeOf(s,N),s.props={close:e,closeStack:t,open:o,openStack:n,props:r},s.open=n,s.close=t,s},U=function(){let r=e=>e+"";r.strip=e=>e.replaceAll(B(),"");for(let e in z)d[e]={get(){let o=I(this,z[e]);return Object.defineProperty(this,e,{value:o}),o}};for(let e in M)d[e]={get(){let o=I(this,M[e]);return Object.defineProperty(this,e,{value:o}),o}};return N=Object.defineProperties({},d),Object.setPrototypeOf(r,N),r};for(let r in H)d[r]={get(){return (...e)=>I(this,H[r](...e))}};d.ansi256=d.fg;d.bgAnsi256=d.bg;var W=U;var D={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};var P=(r,e)=>{let o=r.length;if(e=Number.parseInt(e.toString(),10),Number.isNaN(e)||e<2)throw new Error("Invalid number of steps (< 2)");if(e<o)throw new Error("Number of steps cannot be inferior to number of stops");let n=[];for(let s=1;s<o;s++){let i=(e-1)*(r[s].position-r[s-1].position);n.push(Math.max(1,Math.round(i)));}let t=1;for(let s=o-1;s--;)t+=n[s];for(;t!==e;)if(t<e){let s=Math.min(...n);n[n.indexOf(s)]++,t++;}else {let s=Math.max(...n);n[n.indexOf(s)]--,t--;}return n};var X=(r,e,o)=>{let n=0,t=0,s=0,i=Math.floor(r/60),u=r/60-i,a=o*(1-e),p=o*(1-u*e),b=o*(1-(1-u)*e);return i%6===0?(n=o,t=b,s=a):i%6===1?(n=p,t=o,s=a):i%6===2?(n=a,t=o,s=b):i%6===3?(n=a,t=p,s=o):i%6===4?(n=b,t=a,s=o):i%6===5&&(n=o,t=a,s=p),{b:Math.round(s*255),g:Math.round(t*255),r:Math.round(n*255)}};var j=({b:r,g:e,r:o})=>{let n,t,s,i=0,u=0;o/=255,e/=255,r/=255;let a=Math.max(o,e,r),p=a-Math.min(o,e,r),b=g=>(a-g)/6/p+1/2;return p!==0&&(u=p/a,n=b(o),t=b(e),s=b(r),a===o?i=s-t:a===e?i=.3333333333333333+n-s:a===r&&(i=.6666666666666666+t-n),i<0?i+=1:i>1&&(i-=1)),{h:i*360,s:u,v:a}};var _={b:256,g:256,r:256},ee={h:360,s:1,v:1},Y=(r,e,o)=>{let n={};for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=o===0?0:(e[t]-r[t])/o);return n},$=(r,e,o,n)=>{let t={};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=r[s]*o+e[s],t[s]=t[s]<0?t[s]+n[s]:n[s]===1?t[s]:t[s]%n[s]);return t},w=(r,e,o)=>{let n={b:r.color[2],g:r.color[1],r:r.color[0]},t={b:e.color[2],g:e.color[1],r:e.color[0]},s=Y(n,t,o),i=[{...n}];for(let u=1;u<o;u++){let a=$(s,n,u,_);i.push({b:Math.floor(a.b),g:Math.floor(a.g),r:Math.floor(a.r)});}return i},V=(r,e,o,n)=>{let t=j({b:r.color[2],g:r.color[1],r:r.color[0]}),s=j({b:e.color[2],g:e.color[1],r:e.color[0]});if(t.s===0||s.s===0)return w(r,e,o);let i;if(typeof n=="boolean")i=n;else {let b=t.h<s.h&&s.h-t.h<180||t.h>s.h&&t.h-s.h>180;i=n==="long"&&b||n==="short"&&!b;}let u=Y(t,s,o),a=[{b:r.color[2],g:r.color[1],r:r.color[0]}],p;t.h<=s.h&&!i||t.h>=s.h&&i?p=s.h-t.h:i?p=360-s.h+t.h:p=360-t.h+s.h,u.h=(-1)**(i?1:0)*Math.abs(p)/o;for(let b=1;b<o;b++){let g=$(u,t,b,ee);a.push(X(g.h,g.s,g.v));}return a};var C=class r{#e;stops;constructor(e,o){if(this.#e=e,this.stops=[],o.length<2)throw new Error("Invalid number of stops (< 2)");let n=o[0].position!==void 0,t=o.length,s=-1,i=!1;for(let[u,a]of o.entries()){let p={},b=a.position!==void 0;if(n!==b)throw new Error("Cannot mix positioned and non-positioned color stops");if(b){let g=a,y=g.color!==void 0;if(!y&&(i||u===0||u===t-1))throw new Error("Cannot define two consecutive position-only stops");i=!y;let f;if(y&&(Array.isArray(g.color)?f=g.color:typeof g.color=="string"?f=g.color.includes("#")?S(g.color):D[g.color]:g.color.r!==void 0&&g.color.g!==void 0&&g.color.b&&(f=[g.color.r,g.color.g,g.color.b])),p={color:f,colorLess:!y,position:g.position},p.position<0||p.position>1)throw new Error("Color stops positions must be between 0 and 1");if(p.position<s)throw new Error("Color stops positions are not ordered");s=p.position;}else if(Array.isArray(a))p={color:a,position:u/(t-1)};else if(typeof a=="string")p={color:a.includes("#")?S(a):D[a],position:u/(t-1)};else if(a.r!==void 0&&a.g!==void 0&&a.b!==void 0)p={color:[a.r,a.g,a.b],position:u/(t-1)};else throw new Error("Invalid color stop");this.stops.push(p);}this.stops[0].position!==0&&(this.stops.unshift({color:this.stops[0].color,position:0}),t++),this.stops[t-1].position!==1&&this.stops.push({color:this.stops[t-1].color,position:1});}reverse(){let e=[];for(let o of this.stops){let n={...o};n.position=1-o.position,e.push(n);}return new r(this.#e,e.reverse())}loop(){let e=[],o=[];for(let n of this.stops)e.push({color:n.color,position:(n.position||0)/2});for(let n of this.stops.slice(0,-1))o.push({color:n.color,position:1-(n.position||0)/2});return new r(this.#e,[...e,...o.reverse()])}rgb(e){let o=P(this.stops,e),n=[];this.stops.forEach((t,s)=>{if(t.colorLess){let i=w(this.stops[s-1],this.stops[s+1],2);t.color=[i[1].r,i[1].g,i[1].b];}});for(let t=0,s=this.stops.length;t<s-1;t++){let i=w(this.stops[t],this.stops[t+1],o[t]);n.splice(n.length,0,...i.map(u=>this.#e.rgb(u.r,u.g,u.b)));}return n.push(this.#e.rgb(...this.stops.at(-1).color)),n}hsv(e,o=!1){let n=P(this.stops,e),t=[];this.stops.forEach((s,i)=>{if(s.colorLess){let u=V(this.stops[i-1],this.stops[i+1],2,o);s.color=[u[1].r,u[1].g,u[1].b];}});for(let s=0,i=this.stops.length;s<i-1;s++){let u=V(this.stops[s],this.stops[s+1],n[s],o);t.splice(t.length,0,...u.map(a=>this.#e.rgb(a.r,a.g,a.b)));}return t.push(this.#e.rgb(...this.stops.at(-1).color)),t}};var J=new W,q=/\s/g,Ae=(r,e)=>{let{hsvSpin:o="short",interpolation:n="rgb"}=e??{},t=new C(J,r);return e?.loop?t=t.loop():e?.reverse&&(t=t.reverse()),s=>{let i=Math.max(s.replaceAll(q,"").length,t.stops.length),u=n==="rgb"?t.rgb(i):t.hsv(i,o),a="";for(let p of s)if(q.test(p))a+=p;else {let b=u.shift();a+=b(p);}return a}},Oe=(r,e)=>{let{hsvSpin:o="short",interpolation:n="rgb"}=e??{},t=new C(J,r);return e?.loop?t=t.loop():e?.reverse&&(t=t.reverse()),s=>{let i=s.split(`
|
|
7
|
+
`),u=Reflect.apply(Math.max,null,[...i.map(b=>b.length),t.stops.length]),a=n==="rgb"?t.rgb(u):t.hsv(u,o),p=[];for(let b of i){let g=[...a],y="";for(let f of b)y+=q.test(f)?f:g.shift()(f);p.push(y);}return p.join(`
|
|
8
8
|
`)}};
|
|
9
9
|
|
|
10
|
-
exports.GradientBuilder =
|
|
11
|
-
exports.gradient =
|
|
12
|
-
exports.multilineGradient =
|
|
10
|
+
exports.GradientBuilder = C;
|
|
11
|
+
exports.gradient = Ae;
|
|
12
|
+
exports.multilineGradient = Oe;
|
|
13
13
|
//# sourceMappingURL=out.js.map
|
|
14
14
|
//# sourceMappingURL=gradient.cjs.map
|