auto-theme-js 1.0.0 â 1.0.2
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/README.md +311 -0
- package/dist/AutoTheme.d.ts +45 -17
- package/dist/AutoTheme.js +29 -30
- package/package.json +27 -3
package/README.md
CHANGED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# AutoThemeJS
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/auto-theme-js)
|
|
4
|
+
[](https://www.npmjs.com/package/auto-theme-js)
|
|
5
|
+
[](https://github.com/GustavoLGregorio/auto-theme-js/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/GustavoLGregorio/auto-theme-js/stargazers)
|
|
7
|
+
[](https://github.com/GustavoLGregorio/auto-theme-js/issues)
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://auto-theme-js.vercel.app/" target="_blank"><strong>ð Live Demo</strong></a> âĒ
|
|
11
|
+
<a href="https://www.npmjs.com/package/auto-theme-js"><strong>ðĶ npm</strong></a> âĒ
|
|
12
|
+
<a href="https://github.com/GustavoLGregorio/auto-theme-js"><strong>ðŧ GitHub</strong></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
Generate beautiful, harmonious color palettes from a single base color. AutoThemeJS creates complete design system color schemes with primary, secondary, tertiary, accent, and neutral color variants across 11 shade levels (50-950), similar to Tailwind CSS color scales.
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="demo/img/demo_screenshot.png" alt="AutoThemeJS Demo Screenshot" width="800" />
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
## âĻ Features
|
|
22
|
+
|
|
23
|
+
- ðĻ **Single Color Input** - Generate a complete color palette from just one color
|
|
24
|
+
- ð **Color Harmony** - Automatically creates harmonious color relationships (analogous, complementary)
|
|
25
|
+
- ð **11 Shade Levels** - Each color includes shades from 50 (lightest) to 950 (darkest)
|
|
26
|
+
- ð **Multiple Color Formats** - Support for HEX, RGB, HSL, OKLCH, and OKLAB
|
|
27
|
+
- ðū **Serialization** - Serialize and deserialize themes for storage or transfer
|
|
28
|
+
- ð·ïļ **Versioning** - Built-in version tracking for stored themes
|
|
29
|
+
- ðŠķ **Lightweight** - Zero dependencies, pure TypeScript
|
|
30
|
+
- ðĶ **TypeScript Ready** - Full type definitions included
|
|
31
|
+
|
|
32
|
+
## ðĶ Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install auto-theme-js
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
yarn add auto-theme-js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add auto-theme-js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## ð Quick Start
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import { AutoTheme } from 'auto-theme-js';
|
|
50
|
+
|
|
51
|
+
// Create a theme from a hex color
|
|
52
|
+
const theme = new AutoTheme('#8a00bd', 'hex', 'hex', '50', '950');
|
|
53
|
+
|
|
54
|
+
// Access colors
|
|
55
|
+
console.log(theme.primary['500']); // Primary color at shade 500
|
|
56
|
+
console.log(theme.secondary['300']); // Secondary (analogous +30°) at shade 300
|
|
57
|
+
console.log(theme.tertiary['700']); // Tertiary (analogous -30°) at shade 700
|
|
58
|
+
console.log(theme.accent['500']); // Accent (complementary) at shade 500
|
|
59
|
+
console.log(theme.neutral['900']); // Neutral (desaturated) at shade 900
|
|
60
|
+
|
|
61
|
+
// Check version (useful for stored themes)
|
|
62
|
+
console.log(theme.version); // e.g., 'V1'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## ð API Reference
|
|
66
|
+
|
|
67
|
+
### Constructor
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
new AutoTheme(color, inputType?, outputType?, minShade?, maxShade?)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Parameter | Type | Default | Description |
|
|
74
|
+
|-----------|------|---------|-------------|
|
|
75
|
+
| `color` | `Color` | required | The base color to generate the theme from |
|
|
76
|
+
| `inputType` | `ColorType` | `'hex'` | Input color format: `'hex'`, `'rgb'`, `'hsl'`, `'oklch'`, `'oklab'` |
|
|
77
|
+
| `outputType` | `ColorType` | `'hex'` | Output color format for all generated colors |
|
|
78
|
+
| `minShade` | `Shade` | `'50'` | Minimum shade to generate |
|
|
79
|
+
| `maxShade` | `Shade` | `'900'` | Maximum shade to generate |
|
|
80
|
+
|
|
81
|
+
### Theme Properties
|
|
82
|
+
|
|
83
|
+
Each `AutoTheme` instance contains five color groups plus metadata:
|
|
84
|
+
|
|
85
|
+
| Property | Description | Hue Rotation |
|
|
86
|
+
|----------|-------------|--------------|
|
|
87
|
+
| `primary` | Base color | 0° |
|
|
88
|
+
| `secondary` | Analogous color | +30° |
|
|
89
|
+
| `tertiary` | Analogous color | -30° |
|
|
90
|
+
| `accent` | Complementary color | +180° |
|
|
91
|
+
| `neutral` | Desaturated base | 0° (10% chroma) |
|
|
92
|
+
| `version` | Library version | - |
|
|
93
|
+
| `colorType` | Output color format | - |
|
|
94
|
+
| `baseColor` | Original input color | - |
|
|
95
|
+
|
|
96
|
+
### Shade Levels
|
|
97
|
+
|
|
98
|
+
Each color group contains shades from `50` to `950`:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- `50` - Lightest (97% lightness)
|
|
105
|
+
- `500` - Base (55% lightness)
|
|
106
|
+
- `950` - Darkest (8% lightness)
|
|
107
|
+
|
|
108
|
+
### Color Formats
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
type ColorType = 'hex' | 'rgb' | 'hsl' | 'oklch' | 'oklab';
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Supported formats:**
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
// HEX
|
|
118
|
+
'#8a00bd'
|
|
119
|
+
'#8a00bdff' // alpha not supported yet in v1, so avoid transparency
|
|
120
|
+
|
|
121
|
+
// RGB
|
|
122
|
+
'rgba(138, 0, 189, 1)'
|
|
123
|
+
|
|
124
|
+
// HSL
|
|
125
|
+
'hsla(284, 100%, 37%, 1)'
|
|
126
|
+
|
|
127
|
+
// OKLCH
|
|
128
|
+
'oklch(45.2% 0.234 303.4deg / 1)'
|
|
129
|
+
|
|
130
|
+
// OKLAB
|
|
131
|
+
'oklab(45.2% 0.123 -0.098 / 1)'
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## ðū Serialization & Deserialization
|
|
135
|
+
|
|
136
|
+
AutoThemeJS provides built-in methods to serialize themes for storage (localStorage, databases, etc.) and deserialize them back.
|
|
137
|
+
|
|
138
|
+
### Serialize
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
import { AutoTheme } from 'auto-theme-js';
|
|
142
|
+
|
|
143
|
+
const theme = new AutoTheme('#8a00bd', 'hex', 'hex', '50', '950');
|
|
144
|
+
|
|
145
|
+
// Serialize the theme to a string
|
|
146
|
+
const serialized = AutoTheme.serialize(theme);
|
|
147
|
+
console.log(serialized);
|
|
148
|
+
// Output: "version:1.0.2|colorType:hex|baseColor:#8a00bd||primary:{50:#faf5ff|...}||..."
|
|
149
|
+
|
|
150
|
+
// Store it
|
|
151
|
+
localStorage.setItem('userTheme', serialized);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Deserialize
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
// Retrieve from storage
|
|
158
|
+
const serialized = localStorage.getItem('userTheme');
|
|
159
|
+
|
|
160
|
+
// Deserialize back to a theme object
|
|
161
|
+
const theme = AutoTheme.deserialize(serialized);
|
|
162
|
+
|
|
163
|
+
// Use the theme
|
|
164
|
+
console.log(theme.primary['500']); // #8a00bd
|
|
165
|
+
console.log(theme.colorType); // 'hex'
|
|
166
|
+
console.log(theme.baseColor); // '#8a00bd'
|
|
167
|
+
console.log(theme.version); // '1.0.2'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Version Checking
|
|
171
|
+
|
|
172
|
+
The `version` property allows you to handle breaking changes when loading stored themes:
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
const theme = AutoTheme.deserialize(serialized);
|
|
176
|
+
|
|
177
|
+
// Check if theme was created with a compatible version
|
|
178
|
+
if (theme.version !== AutoTheme.VERSION) {
|
|
179
|
+
console.log('Theme was created with a different version, consider regenerating');
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Custom Escape Character
|
|
184
|
+
|
|
185
|
+
If your color values might contain the default delimiter (`|`), you can specify a custom escape character:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Serialize with custom delimiter
|
|
189
|
+
const serialized = AutoTheme.serialize(theme, '*');
|
|
190
|
+
|
|
191
|
+
// Deserialize with the same delimiter
|
|
192
|
+
const theme = AutoTheme.deserialize(serialized, '*');
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## ðŊ Usage Examples
|
|
196
|
+
|
|
197
|
+
### Dynamic Theme Application
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
import { AutoTheme } from 'auto-theme-js';
|
|
201
|
+
|
|
202
|
+
function applyTheme(baseColor) {
|
|
203
|
+
const theme = new AutoTheme(baseColor, 'hex', 'hex', '50', '950');
|
|
204
|
+
const root = document.documentElement;
|
|
205
|
+
|
|
206
|
+
// Apply CSS custom properties
|
|
207
|
+
const properties = ['primary', 'secondary', 'tertiary', 'accent', 'neutral'];
|
|
208
|
+
const shades = ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900', '950'];
|
|
209
|
+
|
|
210
|
+
for (const prop of properties) {
|
|
211
|
+
for (const shade of shades) {
|
|
212
|
+
root.style.setProperty(`--color-${prop}-${shade}`, theme[prop][shade]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Apply a purple theme
|
|
218
|
+
applyTheme('#8a00bd');
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### React Integration
|
|
222
|
+
|
|
223
|
+
```jsx
|
|
224
|
+
import { AutoTheme } from 'auto-theme-js';
|
|
225
|
+
import { useState, useEffect } from 'react';
|
|
226
|
+
|
|
227
|
+
function ThemeProvider({ children, baseColor }) {
|
|
228
|
+
const [theme, setTheme] = useState(null);
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
const newTheme = new AutoTheme(baseColor, 'hex', 'hex', '50', '950');
|
|
232
|
+
setTheme(newTheme);
|
|
233
|
+
|
|
234
|
+
// Apply to CSS variables
|
|
235
|
+
const root = document.documentElement;
|
|
236
|
+
root.style.setProperty('--primary-500', newTheme.primary['500']);
|
|
237
|
+
root.style.setProperty('--accent-500', newTheme.accent['500']);
|
|
238
|
+
// ... more variables
|
|
239
|
+
}, [baseColor]);
|
|
240
|
+
|
|
241
|
+
return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>;
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Different Output Formats
|
|
246
|
+
|
|
247
|
+
```javascript
|
|
248
|
+
// Output as RGB
|
|
249
|
+
const rgbTheme = new AutoTheme('#8a00bd', 'hex', 'rgb', '50', '950');
|
|
250
|
+
console.log(rgbTheme.primary['500']); // 'rgba(138, 0, 189, 1)'
|
|
251
|
+
|
|
252
|
+
// Output as HSL
|
|
253
|
+
const hslTheme = new AutoTheme('#8a00bd', 'hex', 'hsl', '50', '950');
|
|
254
|
+
console.log(hslTheme.primary['500']); // 'hsla(284, 100%, 37%, 1)'
|
|
255
|
+
|
|
256
|
+
// Output as OKLCH (perceptually uniform)
|
|
257
|
+
const oklchTheme = new AutoTheme('#8a00bd', 'hex', 'oklch', '50', '950');
|
|
258
|
+
console.log(oklchTheme.primary['500']); // 'oklch(45.2% 0.234 303.4deg / 1)'
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Limited Shade Range
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
// Generate only shades 400-700 for a more focused palette
|
|
265
|
+
const limitedTheme = new AutoTheme('#8a00bd', 'hex', 'hex', '400', '700');
|
|
266
|
+
|
|
267
|
+
console.log(limitedTheme.primary['400']); // â
Available
|
|
268
|
+
console.log(limitedTheme.primary['500']); // â
Available
|
|
269
|
+
console.log(limitedTheme.primary['50']); // â undefined (not in range)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## ð§ TypeScript Support
|
|
273
|
+
|
|
274
|
+
AutoThemeJS is written in TypeScript and includes full type definitions:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
import { AutoTheme, Color, ColorType, Shade, ThemeProperties, Theme } from 'auto-theme-js';
|
|
278
|
+
|
|
279
|
+
const color: Color = '#8a00bd';
|
|
280
|
+
const theme: AutoTheme = new AutoTheme(color, 'hex', 'hex', '50', '950');
|
|
281
|
+
|
|
282
|
+
// Type-safe access
|
|
283
|
+
const primaryColor: Color = theme.primary['500'];
|
|
284
|
+
const shade: Shade = '500';
|
|
285
|
+
const property: ThemeProperties = 'primary';
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## ðĪ Contributing
|
|
289
|
+
|
|
290
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
291
|
+
|
|
292
|
+
1. Fork the repository
|
|
293
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
294
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
295
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
296
|
+
5. Open a Pull Request
|
|
297
|
+
|
|
298
|
+
## ð License
|
|
299
|
+
|
|
300
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
301
|
+
|
|
302
|
+
## ð Links
|
|
303
|
+
|
|
304
|
+
- [Live Demo](https://auto-theme-js.vercel.app/)
|
|
305
|
+
- [npm Package](https://www.npmjs.com/package/auto-theme-js)
|
|
306
|
+
- [GitHub Repository](https://github.com/GustavoLGregorio/auto-theme-js)
|
|
307
|
+
- [Report Issues](https://github.com/GustavoLGregorio/auto-theme-js/issues)
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
Made with âĪïļ by [Gustavo L. Gregorio](https://github.com/GustavoLGregorio)
|
package/dist/AutoTheme.d.ts
CHANGED
|
@@ -1,30 +1,58 @@
|
|
|
1
|
-
type
|
|
1
|
+
type ColorType = "hex" | "hsl" | "rgb" | "oklab" | "oklch";
|
|
2
2
|
type ColorHEX = `#${string}`;
|
|
3
3
|
type ColorRGB = `rgba(${number}, ${number}, ${number}, ${number})`;
|
|
4
4
|
type ColorHSL = `hsla(${number}, ${number}%, ${number}%, ${number})`;
|
|
5
5
|
type ColorOKLAB = `oklab(${number}% ${number} ${number} / ${number})`;
|
|
6
6
|
type ColorOKLCH = `oklch(${number}% ${number} ${number}deg / ${number})`;
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
7
|
+
/** A type for CSS-based color patterns */
|
|
8
|
+
export type Color = ColorHEX | ColorRGB | ColorHSL | ColorOKLAB | ColorOKLCH;
|
|
9
|
+
/** Object color properties */
|
|
10
|
+
export type ThemeProperties = "primary" | "secondary" | "tertiary" | "accent" | "neutral";
|
|
11
|
+
/** Shading values. 50 is the brighthest and 900 the darkest */
|
|
12
|
+
export type Shade = "50" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | "950";
|
|
13
|
+
type ShadeColor = Partial<Record<Shade, Color>>;
|
|
14
|
+
type ThemePropertiesShades = Record<ThemeProperties, ShadeColor>;
|
|
15
|
+
/** A type for the object theme. When deserialized, this is the object type that is returned */
|
|
16
|
+
export type Theme = Partial<ThemePropertiesShades> & {
|
|
17
|
+
version: string;
|
|
18
|
+
colorType: ColorType;
|
|
15
19
|
baseColor: Color;
|
|
16
20
|
};
|
|
17
|
-
|
|
21
|
+
/** A class that creates themes using a single color input and handles operations such as:
|
|
22
|
+
* color conversion, custom serialization and deserialization.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AutoTheme implements Theme {
|
|
18
25
|
#private;
|
|
19
|
-
|
|
26
|
+
static VERSION: string;
|
|
27
|
+
version: string;
|
|
28
|
+
colorType: ColorType;
|
|
20
29
|
baseColor: Color;
|
|
21
|
-
primary:
|
|
22
|
-
secondary:
|
|
23
|
-
tertiary:
|
|
24
|
-
accent:
|
|
25
|
-
neutral:
|
|
26
|
-
|
|
30
|
+
primary: {};
|
|
31
|
+
secondary: {};
|
|
32
|
+
tertiary: {};
|
|
33
|
+
accent: {};
|
|
34
|
+
neutral: {};
|
|
35
|
+
/**
|
|
36
|
+
* @param color The base color used to create the theme
|
|
37
|
+
* @param inputType The input type of the base color
|
|
38
|
+
* @param outputType The ouput of the color properties and serialization
|
|
39
|
+
* @param minShade The minimum value on the shade range (50 is the brighthest)
|
|
40
|
+
* @param maxShade The maximum value on the shade range (950 is the darkest)
|
|
41
|
+
*/
|
|
42
|
+
constructor(color: Color, inputType?: ColorType, outputType?: ColorType, minShade?: Shade, maxShade?: Shade);
|
|
43
|
+
/**
|
|
44
|
+
* A static method to create custom serialized strings containing the theme
|
|
45
|
+
* @param autoThemeObject The object that will be serialized
|
|
46
|
+
* @param escapeChar An optional custom escape character (needs to be used the same in de deserialization method). Use with caution. Defaults to "|"
|
|
47
|
+
* @returns A string containing a theme. Single escape character indicates simple properties, double escape characters indicates objects
|
|
48
|
+
*/
|
|
27
49
|
static serialize(autoThemeObject: AutoTheme, escapeChar?: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* A static method to deserialize a previously serialized theme object
|
|
52
|
+
* @param serializedTheme The serialized object string that will be deserialized
|
|
53
|
+
* @param escapeChar An optional escape character that is expected after using a specific escape character during the serialization process. Defaults to "|"
|
|
54
|
+
* @returns A theme object ready to be used
|
|
55
|
+
*/
|
|
28
56
|
static deserialize(serializedTheme: string, escapeChar?: string): Theme;
|
|
29
57
|
}
|
|
30
58
|
export {};
|
package/dist/AutoTheme.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
/** A class that creates themes using a single color input and handles operations such as:
|
|
2
|
+
* color conversion, custom serialization and deserialization.
|
|
3
|
+
*/
|
|
1
4
|
export class AutoTheme {
|
|
5
|
+
static VERSION = "V1";
|
|
6
|
+
version = AutoTheme.VERSION;
|
|
2
7
|
colorType;
|
|
3
8
|
baseColor;
|
|
4
9
|
primary = {};
|
|
@@ -6,12 +11,18 @@ export class AutoTheme {
|
|
|
6
11
|
tertiary = {};
|
|
7
12
|
accent = {};
|
|
8
13
|
neutral = {};
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @param color The base color used to create the theme
|
|
16
|
+
* @param inputType The input type of the base color
|
|
17
|
+
* @param outputType The ouput of the color properties and serialization
|
|
18
|
+
* @param minShade The minimum value on the shade range (50 is the brighthest)
|
|
19
|
+
* @param maxShade The maximum value on the shade range (950 is the darkest)
|
|
20
|
+
*/
|
|
21
|
+
constructor(color, inputType = "hex", outputType = "hex", minShade = "50", maxShade = "900") {
|
|
10
22
|
this.colorType = outputType;
|
|
11
|
-
// Convert baseColor to the selected output type
|
|
12
23
|
const parsedColor = AutoTheme.#parseToOKLCH(color, inputType);
|
|
13
24
|
this.baseColor = AutoTheme.#oklchToColor(parsedColor, outputType);
|
|
14
|
-
this.#addColors(color, inputType,
|
|
25
|
+
this.#addColors(color, inputType, minShade, maxShade);
|
|
15
26
|
}
|
|
16
27
|
#addColors(color, inputType, shadeMin, shadeMax) {
|
|
17
28
|
const keys = [
|
|
@@ -32,6 +43,7 @@ export class AutoTheme {
|
|
|
32
43
|
"700",
|
|
33
44
|
"800",
|
|
34
45
|
"900",
|
|
46
|
+
"950",
|
|
35
47
|
];
|
|
36
48
|
// Parse base color to OKLCH using the input type
|
|
37
49
|
const baseOKLCH = AutoTheme.#parseToOKLCH(color, inputType);
|
|
@@ -49,7 +61,7 @@ export class AutoTheme {
|
|
|
49
61
|
neutral: 0,
|
|
50
62
|
};
|
|
51
63
|
// Lightness mapping for shades (Tailwind-like distribution)
|
|
52
|
-
// 50 = very light, 500 = base,
|
|
64
|
+
// 50 = very light, 500 = base, 950 = very dark
|
|
53
65
|
const lightnessMap = {
|
|
54
66
|
"50": 97,
|
|
55
67
|
"100": 94,
|
|
@@ -61,6 +73,7 @@ export class AutoTheme {
|
|
|
61
73
|
"700": 35,
|
|
62
74
|
"800": 25,
|
|
63
75
|
"900": 15,
|
|
76
|
+
"950": 8,
|
|
64
77
|
};
|
|
65
78
|
// Filter shades within range
|
|
66
79
|
const minIndex = shades.indexOf(shadeMin);
|
|
@@ -317,8 +330,13 @@ export class AutoTheme {
|
|
|
317
330
|
return `oklab(${oklch.l.toFixed(1)}% ${a.toFixed(3)} ${b.toFixed(3)} / ${oklch.a})`;
|
|
318
331
|
}
|
|
319
332
|
// #endregion color_conversion
|
|
320
|
-
// ...existing code for serialize, deserialize...
|
|
321
333
|
// #region serialization
|
|
334
|
+
/**
|
|
335
|
+
* A static method to create custom serialized strings containing the theme
|
|
336
|
+
* @param autoThemeObject The object that will be serialized
|
|
337
|
+
* @param escapeChar An optional custom escape character (needs to be used the same in de deserialization method). Use with caution. Defaults to "|"
|
|
338
|
+
* @returns A string containing a theme. Single escape character indicates simple properties, double escape characters indicates objects
|
|
339
|
+
*/
|
|
322
340
|
static serialize(autoThemeObject, escapeChar = "|") {
|
|
323
341
|
if (!(autoThemeObject instanceof AutoTheme))
|
|
324
342
|
throw new Error("Object is not a AutoTheme instance");
|
|
@@ -350,6 +368,12 @@ export class AutoTheme {
|
|
|
350
368
|
serialized = serialized.substring(0, serialized.length - 1);
|
|
351
369
|
return serialized.trim();
|
|
352
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* A static method to deserialize a previously serialized theme object
|
|
373
|
+
* @param serializedTheme The serialized object string that will be deserialized
|
|
374
|
+
* @param escapeChar An optional escape character that is expected after using a specific escape character during the serialization process. Defaults to "|"
|
|
375
|
+
* @returns A theme object ready to be used
|
|
376
|
+
*/
|
|
353
377
|
static deserialize(serializedTheme, escapeChar = "|") {
|
|
354
378
|
if (!serializedTheme)
|
|
355
379
|
throw new Error("Serialized Theme was not passed as a parameter");
|
|
@@ -382,26 +406,6 @@ export class AutoTheme {
|
|
|
382
406
|
}
|
|
383
407
|
// #endregion serialization
|
|
384
408
|
// #region private_methods
|
|
385
|
-
static #addColorGroups(theme) {
|
|
386
|
-
const groups = [
|
|
387
|
-
"analogous",
|
|
388
|
-
"monochromatic",
|
|
389
|
-
"triad",
|
|
390
|
-
"complementary",
|
|
391
|
-
"splitComplementary",
|
|
392
|
-
"square",
|
|
393
|
-
"compound",
|
|
394
|
-
"shades",
|
|
395
|
-
];
|
|
396
|
-
for (const group of groups) {
|
|
397
|
-
Object.defineProperty(theme, group, {
|
|
398
|
-
value: {},
|
|
399
|
-
writable: true,
|
|
400
|
-
enumerable: true,
|
|
401
|
-
configurable: true,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
409
|
static #addColorProperty(theme, key, value) {
|
|
406
410
|
Object.defineProperty(theme, key, {
|
|
407
411
|
value: value,
|
|
@@ -418,9 +422,4 @@ export class AutoTheme {
|
|
|
418
422
|
writable: true,
|
|
419
423
|
});
|
|
420
424
|
}
|
|
421
|
-
static #forPropColorArrays(themeProp, keys, colors) {
|
|
422
|
-
for (let i = 0; i < keys.length; ++i) {
|
|
423
|
-
AutoTheme.#addColorProperty(themeProp, keys[i], colors[i]);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
425
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-theme-js",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Generate beautiful, harmonious color palettes from a single base color. Create complete design system color schemes with primary, secondary, tertiary, accent, and neutral variants across 11 shade levels.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Gustavo L. Gregorio",
|
|
7
7
|
"main": "dist/AutoTheme.js",
|
|
@@ -9,6 +9,31 @@
|
|
|
9
9
|
"build:lin": "clear; tsc; npx ts-add-js-extension --dir=dist",
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"color",
|
|
14
|
+
"colors",
|
|
15
|
+
"palette",
|
|
16
|
+
"theme",
|
|
17
|
+
"theming",
|
|
18
|
+
"color-palette",
|
|
19
|
+
"color-scheme",
|
|
20
|
+
"design-system",
|
|
21
|
+
"tailwind",
|
|
22
|
+
"css",
|
|
23
|
+
"hex",
|
|
24
|
+
"rgb",
|
|
25
|
+
"hsl",
|
|
26
|
+
"oklch",
|
|
27
|
+
"oklab",
|
|
28
|
+
"color-harmony",
|
|
29
|
+
"complementary",
|
|
30
|
+
"analogous",
|
|
31
|
+
"generator",
|
|
32
|
+
"ui",
|
|
33
|
+
"design",
|
|
34
|
+
"frontend",
|
|
35
|
+
"typescript"
|
|
36
|
+
],
|
|
12
37
|
"homepage": "https://github.com/GustavoLGregorio/auto-theme-js#readme",
|
|
13
38
|
"bugs": {
|
|
14
39
|
"url": "https://github.com/GustavoLGregorio/auto-theme-js/issues"
|
|
@@ -28,7 +53,6 @@
|
|
|
28
53
|
}
|
|
29
54
|
},
|
|
30
55
|
"dependencies": {
|
|
31
|
-
"die-statement": "^1.0.3",
|
|
32
56
|
"ts-add-js-extension": "^1.6.6"
|
|
33
57
|
}
|
|
34
58
|
}
|