@visulima/colorize 1.4.26 → 1.4.27
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 +24 -0
- package/README.md +208 -12
- package/dist/gradient.cjs +60 -3
- package/dist/gradient.mjs +54 -3
- package/dist/index.browser.mjs +63 -1
- package/dist/index.server.cjs +249 -2
- package/dist/index.server.mjs +63 -1
- package/dist/packem_shared/Colorize-BenP3bFn.mjs +241 -0
- package/dist/packem_shared/Colorize-Ca9CXTcj.mjs +413 -0
- package/dist/packem_shared/GradientBuilder-Ba4Teq6P.mjs +487 -0
- package/dist/packem_shared/GradientBuilder-DjJK22kP.cjs +491 -0
- package/dist/packem_shared/colorize.server-BA3gZZXz.cjs +193 -0
- package/dist/packem_shared/colorize.server-ry9FZNfG.mjs +191 -0
- package/dist/packem_shared/convertHexToRgb-CWdAm2kE.mjs +13 -0
- package/dist/packem_shared/convertHexToRgb-DvkHBM3-.cjs +17 -0
- package/dist/packem_shared/rgbToAnsi256-BdS0fomP.mjs +41 -0
- package/dist/packem_shared/rgbToAnsi256-DL8eajTz.cjs +47 -0
- package/dist/template.cjs +144 -2
- package/dist/template.mjs +138 -2
- package/dist/utils.cjs +13 -1
- package/dist/utils.mjs +2 -1
- package/package.json +2 -2
- package/dist/packem_shared/Colorize-BHcGWJJ0.mjs +0 -1
- package/dist/packem_shared/Colorize-CFUl2AHz.mjs +0 -2
- package/dist/packem_shared/GradientBuilder-D6w_X2D1.cjs +0 -1
- package/dist/packem_shared/GradientBuilder-DnPdd2Cf.mjs +0 -1
- package/dist/packem_shared/colorize.server-BX0i6nN6.cjs +0 -2
- package/dist/packem_shared/colorize.server-BkwhBIE0.mjs +0 -2
- package/dist/packem_shared/convertHexToRgb-BEnfEytq.cjs +0 -1
- package/dist/packem_shared/convertHexToRgb-DGcGUKnj.mjs +0 -1
- package/dist/packem_shared/rgbToAnsi256--f09kvlF.cjs +0 -1
- package/dist/packem_shared/rgbToAnsi256-YETEPW8R.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## @visulima/colorize [1.4.27](https://github.com/visulima/visulima/compare/@visulima/colorize@1.4.26...@visulima/colorize@1.4.27) (2025-11-07)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
6
|
+
|
|
7
|
+
### Documentation
|
|
8
|
+
|
|
9
|
+
* enhance README with browser compatibility, edge case handling, and performance comparisons for Colorize ([432193f](https://github.com/visulima/visulima/commit/432193f455918ce51e0e2ec6aab7ac357c337736))
|
|
10
|
+
|
|
11
|
+
### Miscellaneous Chores
|
|
12
|
+
|
|
13
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
14
|
+
* update package.json files and pnpm-lock.yaml ([95d9f5b](https://github.com/visulima/visulima/commit/95d9f5b607105d05a006deadb4379e89f06dfe99))
|
|
15
|
+
|
|
16
|
+
### Tests
|
|
17
|
+
|
|
18
|
+
* update expected output for Colorize function in integration test ([1e316e9](https://github.com/visulima/visulima/commit/1e316e96e591d69d5c8d45513b32bb572dc2c438))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Dependencies
|
|
22
|
+
|
|
23
|
+
* **@visulima/is-ansi-color-supported:** upgraded to 2.3.3
|
|
24
|
+
|
|
1
25
|
## @visulima/colorize [1.4.26](https://github.com/visulima/visulima/compare/@visulima/colorize@1.4.25...@visulima/colorize@1.4.26) (2025-11-05)
|
|
2
26
|
|
|
3
27
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -563,24 +563,218 @@ Since Chrome 69 (every chrome based browser), ANSI escape codes are natively sup
|
|
|
563
563
|
|
|
564
564
|
For other browsers (like firefox) we use the console style syntax command `%c`.
|
|
565
565
|
|
|
566
|
+
### Browser Compatibility for ANSI Codes
|
|
567
|
+
|
|
568
|
+
| Browser | Version | Colors Supported |
|
|
569
|
+
| ----------- | --------- | ---------------- |
|
|
570
|
+
| **Chrome** | **v69+** | TrueColor (16M) |
|
|
571
|
+
| **Safari** | **v10+** | TrueColor (16M) |
|
|
572
|
+
| **Edge** | **v79+** | TrueColor (16M) |
|
|
573
|
+
| **Opera** | **v56+** | TrueColor (16M) |
|
|
574
|
+
| **Brave** | **v1.0+** | TrueColor (16M) |
|
|
575
|
+
| **Vivaldi** | **v2.0+** | TrueColor (16M) |
|
|
576
|
+
|
|
577
|
+
> [!WARNING]
|
|
578
|
+
> **Firefox** doesn't natively support ANSI codes in the developer console. Colorize automatically falls back to `%c` syntax for Firefox.
|
|
579
|
+
|
|
566
580
|
## Windows
|
|
567
581
|
|
|
568
582
|
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of cmd.exe.
|
|
569
583
|
|
|
584
|
+
## Edge Cases: Handling Input Arguments
|
|
585
|
+
|
|
586
|
+
Colorize ensures consistent and predictable behavior for edge-case inputs, making it reliable for production use.
|
|
587
|
+
|
|
588
|
+
### Handling falsy arguments
|
|
589
|
+
|
|
590
|
+
```typescript
|
|
591
|
+
import colorize, { red } from "@visulima/colorize";
|
|
592
|
+
|
|
593
|
+
colorize.red(); // ✅ Returns empty string ''
|
|
594
|
+
colorize.red(undefined); // ✅ Returns empty string ''
|
|
595
|
+
colorize.red(null); // ✅ Returns empty string ''
|
|
596
|
+
colorize.red(""); // ✅ Returns empty string ''
|
|
597
|
+
colorize.reset(); // ✅ Returns reset ANSI code '\x1b[0m'
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
This reliable handling prevents unexpected output when working with variables that might be `undefined`, `null`, or empty strings.
|
|
601
|
+
|
|
602
|
+
## Which One Should You Use?
|
|
603
|
+
|
|
604
|
+
### Quick Decision Guide
|
|
605
|
+
|
|
606
|
+
- **Need basic 16 colors only?** Both Colorize and `styleText()` work, but Colorize is **~100x faster** and supports more environments.
|
|
607
|
+
- **Need truecolor (hex/rgb), 256 colors, or browser support?** Use **Colorize** - `styleText()` doesn't support these.
|
|
608
|
+
- **Need nested template strings or chained syntax?** Use **Colorize** - `styleText()` requires verbose nested calls.
|
|
609
|
+
- **Only targeting Node.js 22+ and want zero dependencies?** `styleText()` works, but consider the performance and feature trade-offs.
|
|
610
|
+
|
|
611
|
+
### Checklist
|
|
612
|
+
|
|
613
|
+
- Does support for **ESM** or **CJS** matter?
|
|
614
|
+
- ✅ Colorize: `ESM` and `CJS`
|
|
615
|
+
- ❌ styleText: Node.js only
|
|
616
|
+
|
|
617
|
+
- Does **browser compatibility** matter?
|
|
618
|
+
- ✅ Colorize: Works in Chromium-based browsers and Safari
|
|
619
|
+
- ❌ styleText: Node.js only
|
|
620
|
+
|
|
621
|
+
- Does **performance** matter? (e.g., high-frequency logging)
|
|
622
|
+
- ✅ Colorize: **~100x faster** than styleText
|
|
623
|
+
- ❌ styleText: Significantly slower
|
|
624
|
+
|
|
625
|
+
- Does support for **[ANSI 256 colors](#256-colors)** or **[Truecolor](#truecolor)** with [fallback](#fallback) matter?
|
|
626
|
+
- ✅ Colorize: Full support with automatic fallback
|
|
627
|
+
- ❌ styleText: Limited to 16 colors only
|
|
628
|
+
|
|
629
|
+
- Does handling **[edge cases](#edge-cases-handling-input-arguments)** (undefined, null, empty strings) matter?
|
|
630
|
+
- ✅ Colorize: Reliable handling of all edge cases
|
|
631
|
+
- ⚠️ styleText: Behavior varies by Node.js version
|
|
632
|
+
|
|
633
|
+
- Does keeping your code **clean and readable** matter?
|
|
634
|
+
- ✅ Colorize: [Default and named import](#named-import), [chained syntax](#chained-syntax), [nested template strings](#nested-syntax)
|
|
635
|
+
- ❌ styleText: Verbose nested calls, no chaining
|
|
636
|
+
|
|
637
|
+
- Does **TypeScript** support and IDE autocomplete matter?
|
|
638
|
+
- ✅ Colorize: Full TypeScript support with autocomplete
|
|
639
|
+
- ⚠️ styleText: Basic TypeScript support
|
|
640
|
+
|
|
641
|
+
## Library Maintenance Status
|
|
642
|
+
|
|
643
|
+
As of 2025, here's the maintenance status of popular ANSI color libraries:
|
|
644
|
+
|
|
645
|
+
- ✅ **@visulima/colorize**: Actively maintained
|
|
646
|
+
- ✅ **ansis**: Actively maintained
|
|
647
|
+
- ✅ **chalk**: Actively maintained
|
|
648
|
+
- ✅ **picocolors**: Actively maintained
|
|
649
|
+
- ⚠️ **colorette**: Last updated 2+ years ago
|
|
650
|
+
- ⚠️ **ansi-colors**: Last updated 3+ years ago
|
|
651
|
+
- ⚠️ **kleur**: Last updated 3+ years ago
|
|
652
|
+
- ⚠️ **colors.js**: Last updated 2+ years ago
|
|
653
|
+
- ⚠️ **cli-color**: Last updated 1+ year ago
|
|
654
|
+
- ⚠️ **colors-cli**: Last updated 1+ year ago
|
|
655
|
+
|
|
656
|
+
Colorize is actively maintained and regularly updated with new features, bug fixes, and performance improvements.
|
|
657
|
+
|
|
658
|
+
## Colorize vs `util.styleText()`
|
|
659
|
+
|
|
660
|
+
Since **Node.js v22**, the built-in [`util.styleText()`](https://nodejs.org/api/util.html#utilstyletextformat-text-options) function has been officially introduced, supporting [standard modifiers](https://nodejs.org/api/util.html#modifiers) - the basic 16 colors and styles.
|
|
661
|
+
|
|
662
|
+
### Where it works
|
|
663
|
+
|
|
664
|
+
**Colorize**
|
|
665
|
+
|
|
666
|
+
✅ Works on **Node.js v20.19+**\
|
|
667
|
+
✅ Works in Chromium-based browsers and Safari (useful for shared utils)\
|
|
668
|
+
✅ Works in **Deno** and **Next.JS** runtimes\
|
|
669
|
+
⚠️ **Firefox DevTools** don't render ANSI escape sequences.
|
|
670
|
+
|
|
671
|
+
**styleText**
|
|
672
|
+
|
|
673
|
+
✅ Native since **Node.js v22+**\
|
|
674
|
+
❌ Node only - it doesn't work in browsers or other runtimes
|
|
675
|
+
|
|
676
|
+
### Performance
|
|
677
|
+
|
|
678
|
+
In practical benchmarks, `styleText()` is dramatically slower, **~100x slower** than Colorize:
|
|
679
|
+
|
|
680
|
+
```js
|
|
681
|
+
styleText("red", "text"); // 579.832 ops/sec
|
|
682
|
+
colorize.red("text"); // 59.646.465 ops/sec
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
See the [benchmark](./__bench__/README.md) for detailed performance comparisons.
|
|
686
|
+
|
|
687
|
+
### Color support detection
|
|
688
|
+
|
|
689
|
+
**Colorize**
|
|
690
|
+
|
|
691
|
+
- Detects terminal, TTY, CI, or browser color capability and automatically falls back to the supported level (truecolor → 256 → 16 → no color).
|
|
692
|
+
- Supports common flags and environment variables:\
|
|
693
|
+
`NO_COLOR`, `FORCE_COLOR`, `COLORTERM`, `--no-color`, `--color`.
|
|
694
|
+
|
|
695
|
+
**styleText**
|
|
696
|
+
|
|
697
|
+
- Detects terminal color support automatically.
|
|
698
|
+
- Supports only environment variables:\
|
|
699
|
+
`NO_COLOR`, `FORCE_COLOR`, `NODE_DISABLE_COLORS`.
|
|
700
|
+
|
|
701
|
+
### Simple styling
|
|
702
|
+
|
|
703
|
+
**Colorize** has a compact and elegant syntax:
|
|
704
|
+
|
|
705
|
+
```typescript
|
|
706
|
+
import colorize, { green } from "@visulima/colorize";
|
|
707
|
+
|
|
708
|
+
console.log(colorize.green("Success!"));
|
|
709
|
+
// or even shorter using named import
|
|
710
|
+
console.log(green`Success!`);
|
|
711
|
+
console.log(green.bold`Success!`);
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
The same example with **styleText** is more verbose:
|
|
715
|
+
|
|
716
|
+
```js
|
|
717
|
+
const { styleText } = require("node:util");
|
|
718
|
+
|
|
719
|
+
console.log(styleText("green", "Success!"));
|
|
720
|
+
console.log(styleText(["green", "bold"], "Success!"));
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### Nested styling
|
|
724
|
+
|
|
725
|
+
**Colorize** keeps your code short and readable:
|
|
726
|
+
|
|
727
|
+
```typescript
|
|
728
|
+
import { red, cyan } from "@visulima/colorize";
|
|
729
|
+
|
|
730
|
+
console.log(red`Error: ${cyan.bold`file.js`} not found!`);
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
Using **styleText** becomes awkward and verbose for nested or combined styles:
|
|
734
|
+
|
|
735
|
+
```js
|
|
736
|
+
const { styleText } = require("node:util");
|
|
737
|
+
|
|
738
|
+
console.log(styleText("red", `Error: ${styleText(["cyan", "bold"], "file.js")} not found!`));
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
### Truecolor
|
|
742
|
+
|
|
743
|
+
**Colorize**
|
|
744
|
+
|
|
745
|
+
- Supports 16-color, 256-color, and truecolor output.
|
|
746
|
+
- Truecolor methods `hex()` and `rgb()`:
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
console.log(colorize.hex("#ffa500")("orange text"));
|
|
750
|
+
console.log(colorize.rgb(255, 165, 0)("orange text"));
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
**styleText**
|
|
754
|
+
|
|
755
|
+
- Limited to the 16 ANSI colors and standard styles.
|
|
756
|
+
- No support for hex, rgb, or truecolor.
|
|
757
|
+
|
|
758
|
+
### TypeScript & IDE support
|
|
759
|
+
|
|
760
|
+
**Colorize** includes `d.ts` type definitions for seamless **TypeScript** integration.\
|
|
761
|
+
Color names, methods, and style chains are fully typed, enabling **autocomplete** and **type checking** in IDEs like VS Code.
|
|
762
|
+
|
|
570
763
|
## Comparison of most popular libraries
|
|
571
764
|
|
|
572
|
-
| Library<br>**\*\***\_\_**\*\***<br> - name<br> - named import
|
|
573
|
-
|
|
|
574
|
-
| [`@visulima/colorize`][npm-url]<br><nobr>`✅ named import`</nobr>
|
|
575
|
-
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr>
|
|
576
|
-
| [`ansis`][ansis]<br><nobr>`✅ named import`</nobr>
|
|
577
|
-
| [`chalk`][chalk]<br><nobr>`❌ named import`</nobr>
|
|
578
|
-
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr>
|
|
579
|
-
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr>
|
|
580
|
-
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr>
|
|
581
|
-
| [`colors.js`][colors.js]<br><nobr>`❌ named import`</nobr>
|
|
582
|
-
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr>
|
|
583
|
-
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr>
|
|
765
|
+
| 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 |
|
|
766
|
+
| :-------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------- | :----------------------------------------: | :----------------: | :------------: | :---------------: | :------------------------: | :---------: | :------------------------------------------------------: | ---------------------------------- |
|
|
767
|
+
| [`@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 |
|
|
768
|
+
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` | ❌ |
|
|
769
|
+
| [`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 |
|
|
770
|
+
| [`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 |
|
|
771
|
+
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` | 16 colors<br>no color |
|
|
772
|
+
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color |
|
|
773
|
+
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr> |  | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` | no color |
|
|
774
|
+
| [`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 |
|
|
775
|
+
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` | no color |
|
|
776
|
+
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr> |  | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color |
|
|
777
|
+
| [`util.styleText()`][styleText]<br><nobr>`❌ named import`</nobr><br><nobr>`Node ≥ 22`</nobr> | Built-in | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❓ | `NO_COLOR`<br>`FORCE_COLOR`<br>`NODE_DISABLE_COLORS` | no color |
|
|
584
778
|
|
|
585
779
|
> **Note**
|
|
586
780
|
>
|
|
@@ -614,6 +808,7 @@ If you're on Windows, do yourself a favor and use [Windows Terminal](https://git
|
|
|
614
808
|
> - [`@visulima/colorize`][npm-url]: `hex()` `rgb()`
|
|
615
809
|
> - [`ansis`][ansis]: `hex()` `rgb()`
|
|
616
810
|
> - [`chalk`][chalk]: `hex()` `rgb()`
|
|
811
|
+
> - [`util.styleText()`][styleText]: Not supported (limited to 16 colors)
|
|
617
812
|
>
|
|
618
813
|
> **Chained syntax**\
|
|
619
814
|
> `lib.red.bold('text')`
|
|
@@ -745,3 +940,4 @@ The visulima colorize is open-sourced software licensed under the [MIT][license-
|
|
|
745
940
|
[chalk]: https://github.com/chalk/chalk
|
|
746
941
|
[chalk-template]: https://github.com/chalk/chalk-template
|
|
747
942
|
[ansis]: https://github.com/webdiscus/ansis
|
|
943
|
+
[styleText]: https://nodejs.org/api/util.html#utilstyletextformat-text-options
|
package/dist/gradient.cjs
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const colorize_server = require('./packem_shared/colorize.server-BA3gZZXz.cjs');
|
|
6
|
+
const GradientBuilder = require('./packem_shared/GradientBuilder-DjJK22kP.cjs');
|
|
7
|
+
|
|
8
|
+
const colorize = new colorize_server.Colorize();
|
|
9
|
+
const forbiddenChars = /\s/g;
|
|
10
|
+
const gradient = (stops, options) => {
|
|
11
|
+
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
12
|
+
let builder = new GradientBuilder.GradientBuilder(colorize, stops);
|
|
13
|
+
if (options?.loop) {
|
|
14
|
+
builder = builder.loop();
|
|
15
|
+
} else if (options?.reverse) {
|
|
16
|
+
builder = builder.reverse();
|
|
17
|
+
}
|
|
18
|
+
return (string_) => {
|
|
19
|
+
const colorsCount = Math.max(string_.replaceAll(forbiddenChars, "").length, builder.stops.length);
|
|
20
|
+
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
21
|
+
let result = "";
|
|
22
|
+
for (const s of string_) {
|
|
23
|
+
if (forbiddenChars.test(s)) {
|
|
24
|
+
result += s;
|
|
25
|
+
} else {
|
|
26
|
+
const color = colors.shift();
|
|
27
|
+
result += color(s);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const multilineGradient = (stops, options) => {
|
|
34
|
+
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
35
|
+
let builder = new GradientBuilder.GradientBuilder(colorize, stops);
|
|
36
|
+
if (options?.loop) {
|
|
37
|
+
builder = builder.loop();
|
|
38
|
+
} else if (options?.reverse) {
|
|
39
|
+
builder = builder.reverse();
|
|
40
|
+
}
|
|
41
|
+
return (string_) => {
|
|
42
|
+
const lines = string_.split("\n");
|
|
43
|
+
const colorsCount = Reflect.apply(Math.max, null, [...lines.map((l) => l.length), builder.stops.length]);
|
|
44
|
+
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
45
|
+
const results = [];
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
const lineColors = [...colors];
|
|
48
|
+
let lineResult = "";
|
|
49
|
+
for (const l of line) {
|
|
50
|
+
lineResult += forbiddenChars.test(l) ? l : lineColors.shift()(l);
|
|
51
|
+
}
|
|
52
|
+
results.push(lineResult);
|
|
53
|
+
}
|
|
54
|
+
return results.join("\n");
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.GradientBuilder = GradientBuilder.GradientBuilder;
|
|
59
|
+
exports.gradient = gradient;
|
|
60
|
+
exports.multilineGradient = multilineGradient;
|
package/dist/gradient.mjs
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { C as Colorize } from './packem_shared/colorize.server-ry9FZNfG.mjs';
|
|
2
|
+
import { GradientBuilder } from './packem_shared/GradientBuilder-Ba4Teq6P.mjs';
|
|
3
|
+
|
|
4
|
+
const colorize = new Colorize();
|
|
5
|
+
const forbiddenChars = /\s/g;
|
|
6
|
+
const gradient = (stops, options) => {
|
|
7
|
+
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
8
|
+
let builder = new GradientBuilder(colorize, stops);
|
|
9
|
+
if (options?.loop) {
|
|
10
|
+
builder = builder.loop();
|
|
11
|
+
} else if (options?.reverse) {
|
|
12
|
+
builder = builder.reverse();
|
|
13
|
+
}
|
|
14
|
+
return (string_) => {
|
|
15
|
+
const colorsCount = Math.max(string_.replaceAll(forbiddenChars, "").length, builder.stops.length);
|
|
16
|
+
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
17
|
+
let result = "";
|
|
18
|
+
for (const s of string_) {
|
|
19
|
+
if (forbiddenChars.test(s)) {
|
|
20
|
+
result += s;
|
|
21
|
+
} else {
|
|
22
|
+
const color = colors.shift();
|
|
23
|
+
result += color(s);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const multilineGradient = (stops, options) => {
|
|
30
|
+
const { hsvSpin = "short", interpolation = "rgb" } = options ?? {};
|
|
31
|
+
let builder = new GradientBuilder(colorize, stops);
|
|
32
|
+
if (options?.loop) {
|
|
33
|
+
builder = builder.loop();
|
|
34
|
+
} else if (options?.reverse) {
|
|
35
|
+
builder = builder.reverse();
|
|
36
|
+
}
|
|
37
|
+
return (string_) => {
|
|
38
|
+
const lines = string_.split("\n");
|
|
39
|
+
const colorsCount = Reflect.apply(Math.max, null, [...lines.map((l) => l.length), builder.stops.length]);
|
|
40
|
+
const colors = interpolation === "rgb" ? builder.rgb(colorsCount) : builder.hsv(colorsCount, hsvSpin);
|
|
41
|
+
const results = [];
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
const lineColors = [...colors];
|
|
44
|
+
let lineResult = "";
|
|
45
|
+
for (const l of line) {
|
|
46
|
+
lineResult += forbiddenChars.test(l) ? l : lineColors.shift()(l);
|
|
47
|
+
}
|
|
48
|
+
results.push(lineResult);
|
|
49
|
+
}
|
|
50
|
+
return results.join("\n");
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { GradientBuilder, gradient, multilineGradient };
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
-
import
|
|
1
|
+
import WebColorize from './packem_shared/Colorize-Ca9CXTcj.mjs';
|
|
2
|
+
|
|
3
|
+
const colorize = new WebColorize();
|
|
4
|
+
const {
|
|
5
|
+
ansi256,
|
|
6
|
+
bg,
|
|
7
|
+
bgAnsi256,
|
|
8
|
+
bgBlack,
|
|
9
|
+
bgBlackBright,
|
|
10
|
+
bgBlue,
|
|
11
|
+
bgBlueBright,
|
|
12
|
+
bgCyan,
|
|
13
|
+
bgCyanBright,
|
|
14
|
+
bgGray,
|
|
15
|
+
bgGreen,
|
|
16
|
+
bgGreenBright,
|
|
17
|
+
bgGrey,
|
|
18
|
+
bgHex,
|
|
19
|
+
bgMagenta,
|
|
20
|
+
bgMagentaBright,
|
|
21
|
+
bgRed,
|
|
22
|
+
bgRedBright,
|
|
23
|
+
bgRgb,
|
|
24
|
+
bgWhite,
|
|
25
|
+
bgWhiteBright,
|
|
26
|
+
bgYellow,
|
|
27
|
+
bgYellowBright,
|
|
28
|
+
black,
|
|
29
|
+
blackBright,
|
|
30
|
+
blue,
|
|
31
|
+
blueBright,
|
|
32
|
+
bold,
|
|
33
|
+
cyan,
|
|
34
|
+
cyanBright,
|
|
35
|
+
dim,
|
|
36
|
+
fg,
|
|
37
|
+
gray,
|
|
38
|
+
green,
|
|
39
|
+
greenBright,
|
|
40
|
+
grey,
|
|
41
|
+
hex,
|
|
42
|
+
hidden,
|
|
43
|
+
inverse,
|
|
44
|
+
italic,
|
|
45
|
+
magenta,
|
|
46
|
+
magentaBright,
|
|
47
|
+
overline,
|
|
48
|
+
red,
|
|
49
|
+
redBright,
|
|
50
|
+
reset,
|
|
51
|
+
rgb,
|
|
52
|
+
strike,
|
|
53
|
+
strikethrough,
|
|
54
|
+
strip,
|
|
55
|
+
underline,
|
|
56
|
+
visible,
|
|
57
|
+
white,
|
|
58
|
+
whiteBright,
|
|
59
|
+
yellow,
|
|
60
|
+
yellowBright
|
|
61
|
+
} = colorize;
|
|
62
|
+
|
|
63
|
+
export { WebColorize as Colorize, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGreen, bgGreenBright, bgGrey, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, colorize as default, dim, fg, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, strip, underline, visible, white, whiteBright, yellow, yellowBright };
|