text-to-gradient 0.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/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jurij Tokarski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# text-to-gradient
|
|
2
|
+
|
|
3
|
+
Generate deterministic mesh gradients from any string. Same text = same gradient. Zero dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install text-to-gradient
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { fromText } from "text-to-gradient";
|
|
15
|
+
|
|
16
|
+
// Default — text drives everything
|
|
17
|
+
const g = fromText("john@example.com");
|
|
18
|
+
g.css; // ready-to-use CSS string
|
|
19
|
+
g.style; // { backgroundColor, backgroundImage } for inline styles
|
|
20
|
+
g.layers; // raw layer data for custom rendering
|
|
21
|
+
|
|
22
|
+
// Same text, different look
|
|
23
|
+
fromText("john@example.com", { base: "#0a0a0a" }); // dark background
|
|
24
|
+
fromText("john@example.com", { layers: 4 }); // fewer blobs
|
|
25
|
+
fromText("john@example.com", { shape: "circle" }); // circles only
|
|
26
|
+
fromText("john@example.com", { opacity: [0.3, 0.6] }); // softer
|
|
27
|
+
fromText("john@example.com", { size: [60, 90] }); // bigger blobs
|
|
28
|
+
fromText("john@example.com", { angle: 45 }); // base gradient angle
|
|
29
|
+
fromText("john@example.com", { palette: 2 }); // force a palette
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Same text + same options = always the same gradient. Different options = different result from the same text.
|
|
33
|
+
|
|
34
|
+
### Manual control
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { fromPoints } from "text-to-gradient";
|
|
38
|
+
|
|
39
|
+
fromPoints([
|
|
40
|
+
{ color: [255, 0, 0], position: "50% 50%" },
|
|
41
|
+
{ color: [0, 0, 255], position: "0% 100%", shape: "circle", opacity: 0.5, size: 70 },
|
|
42
|
+
], { base: "#111", angle: 90 });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Helpers
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { textHash, rgbToHex, hexToRgb } from "text-to-gradient";
|
|
49
|
+
|
|
50
|
+
textHash("hello"); // deterministic 32-bit integer
|
|
51
|
+
rgbToHex([255, 20, 147]); // "#ff1493"
|
|
52
|
+
hexToRgb("#ff1493"); // [255, 20, 147]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
### `fromText(text, options?) → GradientResult`
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|--------|------|---------|-------------|
|
|
61
|
+
| `base` | `string` | derived | Background color (hex) |
|
|
62
|
+
| `layers` | `number` | 6-10 | Number of radial layers (1-15) |
|
|
63
|
+
| `shape` | `"circle" \| "ellipse"` | mixed | Shape for radial layers |
|
|
64
|
+
| `opacity` | `[min, max]` | `[0.7, 1.0]` | Opacity range |
|
|
65
|
+
| `size` | `[min, max]` | `[45, 80]` | Size range (%) |
|
|
66
|
+
| `angle` | `number` | `135` | Base gradient angle (deg) |
|
|
67
|
+
| `palette` | `number` | derived | Force palette index (0-5) |
|
|
68
|
+
|
|
69
|
+
### `fromPoints(points, options?) → GradientResult`
|
|
70
|
+
|
|
71
|
+
Full manual control. Each point: `{ color, position, shape?, opacity?, size? }`.
|
|
72
|
+
|
|
73
|
+
### `GradientResult`
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
{
|
|
77
|
+
css: string; // background-color + background-image
|
|
78
|
+
style: { // for React/inline styles
|
|
79
|
+
backgroundColor: string;
|
|
80
|
+
backgroundImage: string;
|
|
81
|
+
};
|
|
82
|
+
backgroundColor: string;
|
|
83
|
+
layers: GradientLayer[];
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## About
|
|
88
|
+
|
|
89
|
+
Built and maintained by [Jurij Tokarski](https://varstatt.com/jurij) from [Varstatt](https://varstatt.com). MIT licensed.
|
|
90
|
+
|
|
91
|
+
- [Docs](https://varstatt.github.io/text-to-gradient/)
|
|
92
|
+
- [Examples](https://varstatt.com/toolkit/text-gradient)
|
|
93
|
+
- [GitHub](https://github.com/varstatt/text-to-gradient)
|
|
94
|
+
- [npm](https://www.npmjs.com/package/text-to-gradient)
|
|
95
|
+
- [Issues](https://github.com/varstatt/text-to-gradient/issues)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* text-to-gradient
|
|
3
|
+
*
|
|
4
|
+
* Generate deterministic mesh gradients from any string.
|
|
5
|
+
* Same text + same options = same gradient. Every time.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { fromText } from "text-to-gradient";
|
|
10
|
+
*
|
|
11
|
+
* // Default — text drives everything
|
|
12
|
+
* const g = fromText("john@example.com");
|
|
13
|
+
* g.css; // ready-to-use CSS string
|
|
14
|
+
* g.style; // { backgroundColor, backgroundImage } for inline styles
|
|
15
|
+
* g.layers; // raw layer data for custom rendering
|
|
16
|
+
*
|
|
17
|
+
* // Override specific properties — text still drives randomness
|
|
18
|
+
* fromText("john@example.com", { base: "#0a0a0a" });
|
|
19
|
+
* fromText("john@example.com", { layers: 4 });
|
|
20
|
+
* fromText("john@example.com", { shape: "circle" });
|
|
21
|
+
* fromText("john@example.com", { opacity: [0.3, 0.6] });
|
|
22
|
+
* fromText("john@example.com", { size: [60, 90] });
|
|
23
|
+
* fromText("john@example.com", { angle: 45 });
|
|
24
|
+
* fromText("john@example.com", { palette: 2 });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export interface GradientOptions {
|
|
28
|
+
/** Background color override (hex). Default: derived from text. */
|
|
29
|
+
base?: string;
|
|
30
|
+
/** Number of radial gradient layers (1-15). Default: 6-10, derived from text. */
|
|
31
|
+
layers?: number;
|
|
32
|
+
/** Shape for radial layers. Default: mixed circle/ellipse, derived from text. */
|
|
33
|
+
shape?: "circle" | "ellipse";
|
|
34
|
+
/** Opacity range [min, max] for radial layers (0-1). Default: [0.7, 1.0]. */
|
|
35
|
+
opacity?: [number, number];
|
|
36
|
+
/** Size range [min, max] as percentage (1-100). Default: [45, 80]. */
|
|
37
|
+
size?: [number, number];
|
|
38
|
+
/** Base linear gradient angle in degrees. Default: 135. */
|
|
39
|
+
angle?: number;
|
|
40
|
+
/** Force a specific palette index (0-5). Default: derived from text. */
|
|
41
|
+
palette?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface GradientLayer {
|
|
44
|
+
type: "linear" | "radial";
|
|
45
|
+
css: string;
|
|
46
|
+
color: [number, number, number];
|
|
47
|
+
opacity: number;
|
|
48
|
+
/** Position as "x% y%" — only for radial layers. */
|
|
49
|
+
position?: string;
|
|
50
|
+
/** Shape — only for radial layers. */
|
|
51
|
+
shape?: "circle" | "ellipse";
|
|
52
|
+
/** Size as percentage — only for radial layers. */
|
|
53
|
+
size?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface GradientResult {
|
|
56
|
+
/** Full CSS string (background-color + background-image). */
|
|
57
|
+
css: string;
|
|
58
|
+
/** Inline style object: { backgroundColor, backgroundImage }. */
|
|
59
|
+
style: {
|
|
60
|
+
backgroundColor: string;
|
|
61
|
+
backgroundImage: string;
|
|
62
|
+
};
|
|
63
|
+
/** Background color hex. */
|
|
64
|
+
backgroundColor: string;
|
|
65
|
+
/** Individual gradient layers for custom rendering. */
|
|
66
|
+
layers: GradientLayer[];
|
|
67
|
+
}
|
|
68
|
+
export interface GradientPoint {
|
|
69
|
+
color: [number, number, number];
|
|
70
|
+
position: string;
|
|
71
|
+
shape?: "circle" | "ellipse";
|
|
72
|
+
opacity?: number;
|
|
73
|
+
size?: number;
|
|
74
|
+
}
|
|
75
|
+
export declare function textHash(str: string): number;
|
|
76
|
+
export declare function rgbToHex(rgb: [number, number, number]): string;
|
|
77
|
+
export declare function hexToRgb(hex: string): [number, number, number];
|
|
78
|
+
/**
|
|
79
|
+
* Generate a deterministic gradient from text.
|
|
80
|
+
* Same text + same options = same result every time.
|
|
81
|
+
*/
|
|
82
|
+
export declare function fromText(text: string, options?: GradientOptions): GradientResult;
|
|
83
|
+
/**
|
|
84
|
+
* Build a gradient from explicit points (full manual control).
|
|
85
|
+
*/
|
|
86
|
+
export declare function fromPoints(points: GradientPoint[], options?: {
|
|
87
|
+
base?: string;
|
|
88
|
+
angle?: number;
|
|
89
|
+
}): GradientResult;
|
|
90
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC7B,6EAA6E;IAC7E,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,sEAAsE;IACtE,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC7B,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,KAAK,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5D,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAuID,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO5C;AAOD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAE9D;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAS9D;AAmCD;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAqEhB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,aAAa,EAAE,EACvB,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9C,cAAc,CA4ChB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* text-to-gradient
|
|
4
|
+
*
|
|
5
|
+
* Generate deterministic mesh gradients from any string.
|
|
6
|
+
* Same text + same options = same gradient. Every time.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { fromText } from "text-to-gradient";
|
|
11
|
+
*
|
|
12
|
+
* // Default — text drives everything
|
|
13
|
+
* const g = fromText("john@example.com");
|
|
14
|
+
* g.css; // ready-to-use CSS string
|
|
15
|
+
* g.style; // { backgroundColor, backgroundImage } for inline styles
|
|
16
|
+
* g.layers; // raw layer data for custom rendering
|
|
17
|
+
*
|
|
18
|
+
* // Override specific properties — text still drives randomness
|
|
19
|
+
* fromText("john@example.com", { base: "#0a0a0a" });
|
|
20
|
+
* fromText("john@example.com", { layers: 4 });
|
|
21
|
+
* fromText("john@example.com", { shape: "circle" });
|
|
22
|
+
* fromText("john@example.com", { opacity: [0.3, 0.6] });
|
|
23
|
+
* fromText("john@example.com", { size: [60, 90] });
|
|
24
|
+
* fromText("john@example.com", { angle: 45 });
|
|
25
|
+
* fromText("john@example.com", { palette: 2 });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.textHash = textHash;
|
|
30
|
+
exports.rgbToHex = rgbToHex;
|
|
31
|
+
exports.hexToRgb = hexToRgb;
|
|
32
|
+
exports.fromText = fromText;
|
|
33
|
+
exports.fromPoints = fromPoints;
|
|
34
|
+
// ---- Constants ----
|
|
35
|
+
const PALETTES = [
|
|
36
|
+
// Neon
|
|
37
|
+
[
|
|
38
|
+
[255, 20, 147],
|
|
39
|
+
[0, 255, 255],
|
|
40
|
+
[50, 205, 50],
|
|
41
|
+
[255, 69, 0],
|
|
42
|
+
[138, 43, 226],
|
|
43
|
+
[255, 215, 0],
|
|
44
|
+
[30, 144, 255],
|
|
45
|
+
[255, 105, 180],
|
|
46
|
+
[0, 250, 154],
|
|
47
|
+
[255, 140, 0],
|
|
48
|
+
[186, 85, 211],
|
|
49
|
+
[0, 191, 255],
|
|
50
|
+
],
|
|
51
|
+
// Cosmic
|
|
52
|
+
[
|
|
53
|
+
[220, 20, 60],
|
|
54
|
+
[64, 224, 208],
|
|
55
|
+
[255, 99, 71],
|
|
56
|
+
[138, 43, 226],
|
|
57
|
+
[255, 215, 0],
|
|
58
|
+
[32, 178, 170],
|
|
59
|
+
[255, 105, 180],
|
|
60
|
+
[75, 0, 130],
|
|
61
|
+
[255, 140, 0],
|
|
62
|
+
[50, 205, 50],
|
|
63
|
+
[255, 20, 147],
|
|
64
|
+
[0, 206, 209],
|
|
65
|
+
],
|
|
66
|
+
// Prismatic
|
|
67
|
+
[
|
|
68
|
+
[255, 0, 127],
|
|
69
|
+
[255, 127, 0],
|
|
70
|
+
[127, 255, 0],
|
|
71
|
+
[0, 255, 127],
|
|
72
|
+
[0, 127, 255],
|
|
73
|
+
[127, 0, 255],
|
|
74
|
+
[255, 69, 0],
|
|
75
|
+
[50, 205, 50],
|
|
76
|
+
[30, 144, 255],
|
|
77
|
+
[255, 20, 147],
|
|
78
|
+
[138, 43, 226],
|
|
79
|
+
[255, 215, 0],
|
|
80
|
+
],
|
|
81
|
+
// Tropical
|
|
82
|
+
[
|
|
83
|
+
[255, 20, 147],
|
|
84
|
+
[0, 191, 255],
|
|
85
|
+
[50, 205, 50],
|
|
86
|
+
[255, 140, 0],
|
|
87
|
+
[255, 69, 0],
|
|
88
|
+
[138, 43, 226],
|
|
89
|
+
[255, 215, 0],
|
|
90
|
+
[32, 178, 170],
|
|
91
|
+
[255, 105, 180],
|
|
92
|
+
[154, 205, 50],
|
|
93
|
+
[255, 99, 71],
|
|
94
|
+
[64, 224, 208],
|
|
95
|
+
],
|
|
96
|
+
// Cyber
|
|
97
|
+
[
|
|
98
|
+
[0, 255, 255],
|
|
99
|
+
[255, 20, 147],
|
|
100
|
+
[50, 205, 50],
|
|
101
|
+
[255, 215, 0],
|
|
102
|
+
[138, 43, 226],
|
|
103
|
+
[255, 69, 0],
|
|
104
|
+
[0, 191, 255],
|
|
105
|
+
[255, 105, 180],
|
|
106
|
+
[30, 144, 255],
|
|
107
|
+
[255, 140, 0],
|
|
108
|
+
[186, 85, 211],
|
|
109
|
+
[0, 250, 154],
|
|
110
|
+
],
|
|
111
|
+
// Electric
|
|
112
|
+
[
|
|
113
|
+
[255, 0, 128],
|
|
114
|
+
[128, 255, 0],
|
|
115
|
+
[0, 128, 255],
|
|
116
|
+
[255, 128, 0],
|
|
117
|
+
[128, 0, 255],
|
|
118
|
+
[0, 255, 128],
|
|
119
|
+
[255, 69, 0],
|
|
120
|
+
[50, 205, 50],
|
|
121
|
+
[30, 144, 255],
|
|
122
|
+
[255, 20, 147],
|
|
123
|
+
[138, 43, 226],
|
|
124
|
+
[255, 215, 0],
|
|
125
|
+
],
|
|
126
|
+
];
|
|
127
|
+
const POSITIONS = [
|
|
128
|
+
"0% 0%",
|
|
129
|
+
"100% 0%",
|
|
130
|
+
"100% 100%",
|
|
131
|
+
"0% 100%",
|
|
132
|
+
"50% 0%",
|
|
133
|
+
"100% 50%",
|
|
134
|
+
"50% 100%",
|
|
135
|
+
"0% 50%",
|
|
136
|
+
"50% 50%",
|
|
137
|
+
"40% 40%",
|
|
138
|
+
"60% 60%",
|
|
139
|
+
"45% 55%",
|
|
140
|
+
"55% 45%",
|
|
141
|
+
"25% 25%",
|
|
142
|
+
"75% 75%",
|
|
143
|
+
"25% 75%",
|
|
144
|
+
"75% 25%",
|
|
145
|
+
"15% 35%",
|
|
146
|
+
"85% 65%",
|
|
147
|
+
"35% 15%",
|
|
148
|
+
"65% 85%",
|
|
149
|
+
"10% 90%",
|
|
150
|
+
"90% 10%",
|
|
151
|
+
"20% 80%",
|
|
152
|
+
"80% 20%",
|
|
153
|
+
"30% 60%",
|
|
154
|
+
"70% 40%",
|
|
155
|
+
"40% 20%",
|
|
156
|
+
"60% 80%",
|
|
157
|
+
"5% 95%",
|
|
158
|
+
"95% 5%",
|
|
159
|
+
];
|
|
160
|
+
const SHAPES = ["circle", "ellipse"];
|
|
161
|
+
// ---- Internal helpers ----
|
|
162
|
+
function textHash(str) {
|
|
163
|
+
if (!str || str.length === 0)
|
|
164
|
+
return 0;
|
|
165
|
+
let hash = 0;
|
|
166
|
+
for (let i = 0; i < str.length; i++) {
|
|
167
|
+
hash = (hash * 31 + str.charCodeAt(i)) >>> 0;
|
|
168
|
+
}
|
|
169
|
+
return hash;
|
|
170
|
+
}
|
|
171
|
+
function seededRandom(seed) {
|
|
172
|
+
const x = Math.sin(seed) * 10000;
|
|
173
|
+
return x - Math.floor(x);
|
|
174
|
+
}
|
|
175
|
+
function rgbToHex(rgb) {
|
|
176
|
+
return `#${rgb.map((c) => c.toString(16).padStart(2, "0")).join("")}`;
|
|
177
|
+
}
|
|
178
|
+
function hexToRgb(hex) {
|
|
179
|
+
let h = hex.replace(/^#/, "");
|
|
180
|
+
if (h.length === 3)
|
|
181
|
+
h = h
|
|
182
|
+
.split("")
|
|
183
|
+
.map((c) => c + c)
|
|
184
|
+
.join("");
|
|
185
|
+
const n = Number.parseInt(h, 16);
|
|
186
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
187
|
+
}
|
|
188
|
+
function filterPalette(palette, hash) {
|
|
189
|
+
const themeSeed = hash % 1000;
|
|
190
|
+
if (themeSeed < 500) {
|
|
191
|
+
return palette.filter((_, i) => [0, 1, 2, 3, 4, 5, 8, 9].includes(i));
|
|
192
|
+
}
|
|
193
|
+
if (themeSeed >= 750) {
|
|
194
|
+
return palette.filter((_, i) => [2, 3, 4, 5, 6, 7, 10, 11].includes(i));
|
|
195
|
+
}
|
|
196
|
+
return palette;
|
|
197
|
+
}
|
|
198
|
+
function clamp(val, min, max) {
|
|
199
|
+
return Math.min(max, Math.max(min, val));
|
|
200
|
+
}
|
|
201
|
+
function buildResult(bgColor, layerList) {
|
|
202
|
+
const cssLayers = layerList.map((l) => l.css).join(",\n ");
|
|
203
|
+
const css = `background-color: ${bgColor};\nbackground-image:\n ${cssLayers};`;
|
|
204
|
+
const style = {
|
|
205
|
+
backgroundColor: bgColor,
|
|
206
|
+
backgroundImage: layerList.map((l) => l.css).join(", "),
|
|
207
|
+
};
|
|
208
|
+
return { css, style, backgroundColor: bgColor, layers: layerList };
|
|
209
|
+
}
|
|
210
|
+
// ---- Public API ----
|
|
211
|
+
/**
|
|
212
|
+
* Generate a deterministic gradient from text.
|
|
213
|
+
* Same text + same options = same result every time.
|
|
214
|
+
*/
|
|
215
|
+
function fromText(text, options = {}) {
|
|
216
|
+
const hash = textHash(text);
|
|
217
|
+
const paletteIdx = options.palette !== undefined
|
|
218
|
+
? clamp(options.palette, 0, PALETTES.length - 1)
|
|
219
|
+
: hash % PALETTES.length;
|
|
220
|
+
const palette = PALETTES[paletteIdx];
|
|
221
|
+
const filtered = filterPalette(palette, hash);
|
|
222
|
+
const numLayers = options.layers !== undefined
|
|
223
|
+
? clamp(options.layers, 1, 15)
|
|
224
|
+
: 6 + (hash % 5);
|
|
225
|
+
const angle = options.angle ?? 135;
|
|
226
|
+
const [opMin, opMax] = options.opacity ?? [0.7, 1.0];
|
|
227
|
+
const [szMin, szMax] = options.size ?? [45, 80];
|
|
228
|
+
// Base linear gradient layer
|
|
229
|
+
const baseIdx = Math.floor(seededRandom(hash + 1000) * filtered.length);
|
|
230
|
+
const baseColor = filtered[baseIdx];
|
|
231
|
+
const baseCss = `linear-gradient(${angle}deg, rgba(${baseColor[0]},${baseColor[1]},${baseColor[2]},0.4) 0%, rgba(${baseColor[0]},${baseColor[1]},${baseColor[2]},0.2) 100%)`;
|
|
232
|
+
const layers = [
|
|
233
|
+
{ type: "linear", css: baseCss, color: baseColor, opacity: 0.4 },
|
|
234
|
+
];
|
|
235
|
+
// Radial gradient layers
|
|
236
|
+
for (let i = 0; i < numLayers; i++) {
|
|
237
|
+
const seed = hash + i * 1000;
|
|
238
|
+
const colorIdx = Math.floor(seededRandom(seed) * filtered.length);
|
|
239
|
+
const rgb = filtered[colorIdx];
|
|
240
|
+
const posIdx = Math.floor(seededRandom(seed + 100) * POSITIONS.length);
|
|
241
|
+
const position = POSITIONS[posIdx];
|
|
242
|
+
const shapeVal = options.shape ??
|
|
243
|
+
SHAPES[Math.floor(seededRandom(seed + 200) * SHAPES.length)];
|
|
244
|
+
const opacity = Number.parseFloat((opMin + seededRandom(seed + 300) * (opMax - opMin)).toFixed(2));
|
|
245
|
+
const size = Math.round(szMin + seededRandom(seed + 400) * (szMax - szMin));
|
|
246
|
+
const radialCss = `radial-gradient(${shapeVal} at ${position}, rgba(${rgb[0]},${rgb[1]},${rgb[2]},${opacity}) 0%, transparent ${size}%)`;
|
|
247
|
+
layers.push({
|
|
248
|
+
type: "radial",
|
|
249
|
+
css: radialCss,
|
|
250
|
+
color: rgb,
|
|
251
|
+
opacity,
|
|
252
|
+
position,
|
|
253
|
+
shape: shapeVal,
|
|
254
|
+
size,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
// Background color
|
|
258
|
+
let bgColor;
|
|
259
|
+
if (options.base) {
|
|
260
|
+
bgColor = options.base;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const fallbackIdx = Math.floor(seededRandom(hash + 5000) * filtered.length);
|
|
264
|
+
const fallbackRgb = filtered[fallbackIdx];
|
|
265
|
+
bgColor = rgbToHex(fallbackRgb.map((c) => Math.round(c * 0.1)));
|
|
266
|
+
}
|
|
267
|
+
return buildResult(bgColor, layers);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Build a gradient from explicit points (full manual control).
|
|
271
|
+
*/
|
|
272
|
+
function fromPoints(points, options = {}) {
|
|
273
|
+
const angle = options.angle ?? 135;
|
|
274
|
+
const layers = [];
|
|
275
|
+
if (points.length > 0) {
|
|
276
|
+
const first = points[0];
|
|
277
|
+
const baseCss = `linear-gradient(${angle}deg, rgba(${first.color[0]},${first.color[1]},${first.color[2]},0.4) 0%, rgba(${first.color[0]},${first.color[1]},${first.color[2]},0.2) 100%)`;
|
|
278
|
+
layers.push({
|
|
279
|
+
type: "linear",
|
|
280
|
+
css: baseCss,
|
|
281
|
+
color: first.color,
|
|
282
|
+
opacity: 0.4,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
for (const pt of points) {
|
|
286
|
+
const shape = pt.shape ?? "ellipse";
|
|
287
|
+
const opacity = pt.opacity ?? 0.8;
|
|
288
|
+
const size = pt.size ?? 60;
|
|
289
|
+
const radialCss = `radial-gradient(${shape} at ${pt.position}, rgba(${pt.color[0]},${pt.color[1]},${pt.color[2]},${opacity}) 0%, transparent ${size}%)`;
|
|
290
|
+
layers.push({
|
|
291
|
+
type: "radial",
|
|
292
|
+
css: radialCss,
|
|
293
|
+
color: pt.color,
|
|
294
|
+
opacity,
|
|
295
|
+
position: pt.position,
|
|
296
|
+
shape,
|
|
297
|
+
size,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const bgColor = options.base ??
|
|
301
|
+
(points.length > 0
|
|
302
|
+
? rgbToHex(points[0].color.map((c) => Math.round(c * 0.1)))
|
|
303
|
+
: "#0a0a0a");
|
|
304
|
+
return buildResult(bgColor, layers);
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AA0LH,4BAOC;AAOD,4BAEC;AAED,4BASC;AAuCD,4BAwEC;AAKD,gCA+CC;AAnUD,sBAAsB;AAEtB,MAAM,QAAQ,GAAiC;IAC7C,OAAO;IACP;QACE,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC;QACd,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;QACb,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;QACZ,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC;QACd,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QACb,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC;QACd,CAAC,GAAG,EAAE,GAAG,E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E,QAAQ;YACd,GAAG,EAAE,SAAS;YACd,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,OAAO;YACP,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,KAAK;YACL,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GACX,OAAO,CAAC,IAAI;QACZ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAChB,CAAC,CAAC,QAAQ,CACN,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAI7C,CACF;YACH,CAAC,CAAC,SAAS,CAAC,CAAC;IAEjB,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "text-to-gradient",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate deterministic mesh gradients from any string. Same text = same gradient.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gradient",
|
|
7
|
+
"mesh-gradient",
|
|
8
|
+
"avatar",
|
|
9
|
+
"generative",
|
|
10
|
+
"deterministic",
|
|
11
|
+
"hash",
|
|
12
|
+
"color",
|
|
13
|
+
"css",
|
|
14
|
+
"background"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/varstatt/text-to-gradient.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/varstatt/text-to-gradient#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/varstatt/text-to-gradient/issues"
|
|
23
|
+
},
|
|
24
|
+
"author": "Jurij Tokarski <jurij@varstatt.com>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"require": "./dist/index.js",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"provenance": true
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "jest --modulePaths=src",
|
|
50
|
+
"test:coverage": "jest --modulePaths=src --coverage",
|
|
51
|
+
"test:watch": "jest --modulePaths=src --watch",
|
|
52
|
+
"lint": "biome check src/",
|
|
53
|
+
"format": "biome check --write src/",
|
|
54
|
+
"prepack": "npm run build"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@biomejs/biome": "^2.0.0",
|
|
59
|
+
"@types/jest": "^30.0.0",
|
|
60
|
+
"@types/node": "^22.0.0",
|
|
61
|
+
"jest": "^30.0.0",
|
|
62
|
+
"ts-jest": "^29.4.0",
|
|
63
|
+
"typescript": "^5.8.0"
|
|
64
|
+
}
|
|
65
|
+
}
|