hextimator 0.10.1 → 0.11.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 +18 -0
- package/README.md +43 -229
- package/dist/{chunk-64DBUA5U.js → chunk-TF34PRUI.js} +1 -1
- package/dist/cli.js +14 -3
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/llms.txt +115 -488
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 0.11.0
|
|
2
|
+
|
|
3
|
+
### Minor Changes
|
|
4
|
+
|
|
5
|
+
- [#142](https://github.com/fgrgic/hextimator/pull/142) [`95875bf`](https://github.com/fgrgic/hextimator/commit/95875bf4889c2120626cad00cfe54c6ea8f6b9dc) Thanks [@fgrgic](https://github.com/fgrgic)! - Widens the default POSITIVE_RANGE to be [120, 180].
|
|
6
|
+
|
|
7
|
+
The previous range was to limiting so you could get an accent color that is green, and a positive color that is a whole other green that doesn't match.
|
|
8
|
+
|
|
9
|
+
Technically it changes the algorithm so it's a breaking change, but it's a minor change that should improve the color generation algorithm.
|
|
10
|
+
|
|
11
|
+
If you find your themes look worse, limit your positive range to the previous [120, 160].
|
|
12
|
+
|
|
13
|
+
## 0.10.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#139](https://github.com/fgrgic/hextimator/pull/139) [`6f12682`](https://github.com/fgrgic/hextimator/commit/6f12682dd2e1223a4b51b4b54d3a036dce04a41f) Thanks [@fgrgic](https://github.com/fgrgic)! - fixes 'bold' preset not being exported to the cli
|
|
18
|
+
|
|
1
19
|
## 0.10.1
|
|
2
20
|
|
|
3
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -6,274 +6,88 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
Per-tenant themes from a single
|
|
9
|
+
Per-tenant themes from a single brand color: Runtime theming for B2B2C and white-label apps.
|
|
10
10
|
|
|
11
11
|
Your customers pick a brand color. Your app looks good. Every time. No per-customer design reviews, no manual tuning, no edge cases where "that shade of yellow" breaks your UI.
|
|
12
12
|
|
|
13
|
-
Ship multi-tenant apps without the design overhead:
|
|
14
|
-
|
|
15
|
-
- **Every color just works**. Perceptually uniform colors with OKLCH means that electric blue looks as balanced as muted olive.
|
|
16
|
-
- **Accessible by default**. Every foreground meets AAA contrast against its background, light and dark mode included.
|
|
17
|
-
|
|
18
13
|
Try it in the playground: **[hextimator.com](https://hextimator.com)**
|
|
19
14
|
|
|
20
15
|
## Why `hextimator` exists
|
|
21
16
|
|
|
22
|
-
You
|
|
23
|
-
|
|
24
|
-
1. **Let customers pick any hex.** It works until a partner's _legal-pad yellow_ renders your buttons unreadable, and their _cheeto dust tangerine_ toast makes it indistinguishable from a warning.
|
|
25
|
-
2. **Constrain them to a curated palette.** Now you need to tell a paying customer that their brand color isn't allowed. Or spend hours adjusting all the other colors by hand to make the theme somewhat work.
|
|
26
|
-
|
|
27
|
-
Hextimator is option 3. One color in, whole theme out. You get accent, semantic roles, light/dark palette, every foreground guaranteed to meet WCAG contrast against its background. Every time. Even for that yellow.
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { hextimate } from "hextimator";
|
|
31
|
-
|
|
32
|
-
const tenantTheme = hextimate(tenant.brandColor).format({ as: "css" });
|
|
33
|
-
|
|
34
|
-
document.getElementById("tenant-theme").textContent = tenantTheme;
|
|
35
|
-
```
|
|
17
|
+
You are shipping a B2B, B2B2C, or white-label app. Every tenant brings their own brand color. The options today are:
|
|
36
18
|
|
|
37
|
-
|
|
19
|
+
- **Let them pick any hex**. Now legal-pad yellow buttons become unreadable; cheeto tangerine toasts look identical to your warning state.
|
|
20
|
+
- **Curate a palette**. Now you are telling a paying customer their brand color is not allowed.
|
|
38
21
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
```jsx
|
|
42
|
-
<HextimatorProvider defaultColor={tenant.brandColor}>
|
|
43
|
-
<App />
|
|
44
|
-
</HextimatorProvider>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
See full React integration guide [here](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md).
|
|
22
|
+
hextimator is option three. **One color in, whole theme out.** Light and dark. Semantic roles and surfaces. Foregrounds tuned against their backgrounds for WCAG contrast by default (AAA targets unless you opt down). Even for yellow.
|
|
48
23
|
|
|
49
24
|
## Installation
|
|
50
25
|
|
|
51
|
-
Add to your project:
|
|
52
|
-
|
|
53
26
|
```bash
|
|
54
27
|
npm i hextimator
|
|
55
28
|
```
|
|
56
29
|
|
|
57
|
-
**
|
|
58
|
-
make sure to include
|
|
30
|
+
**Tailwind v4:** import `hextimator/tailwind.css` in your CSS entry (see [Tailwind](docs/tailwind.md)).
|
|
59
31
|
|
|
60
|
-
|
|
61
|
-
@import "hextimator/tailwind.css";
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
in your `index.css`
|
|
65
|
-
|
|
66
|
-
## Quick start
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
npm install hextimator
|
|
70
|
-
```
|
|
32
|
+
## 30-second integration
|
|
71
33
|
|
|
72
|
-
```
|
|
34
|
+
```ts
|
|
73
35
|
import { hextimate } from "hextimator";
|
|
74
36
|
|
|
75
|
-
const
|
|
76
|
-
// theme.light / theme.dark each contain your full theme tokens
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Multi-tenant app with React
|
|
80
|
-
|
|
81
|
-
```jsx
|
|
82
|
-
<HextimatorProvider defaultColor={tenant.brandColor}>
|
|
83
|
-
<App />
|
|
84
|
-
</HextimatorProvider>
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
See full React integration guide [here](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md).
|
|
88
|
-
|
|
89
|
-
### With presets
|
|
90
|
-
|
|
91
|
-
Presets are partial or full themes. You can chain them together, [extend them](#extending-presets), or not use them at all. They provide a starting point: whether for a specific framework or a particular style:
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import { hextimate, presets } from "hextimator";
|
|
95
|
-
|
|
96
|
-
// shadcn/ui tokens
|
|
97
|
-
const theme = hextimate("#0FF1CE").preset(presets.shadcn).format();
|
|
98
|
-
|
|
99
|
-
// muted palette
|
|
100
|
-
const theme = hextimate("#0FF1CE").preset(presets.muted).format();
|
|
101
|
-
|
|
102
|
-
// muted shadcn theme
|
|
103
|
-
const theme = hextimate("#0FF1CE")
|
|
104
|
-
.preset(presets.shadcn)
|
|
105
|
-
.preset(presets.muted)
|
|
106
|
-
.format();
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Presets are applied sequentially (last wins for conflicts) and you can override anything in `.format()`:
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
const theme = hextimate("#BADA55")
|
|
113
|
-
.preset(presets.muted)
|
|
114
|
-
.preset(presets.shadcn)
|
|
115
|
-
.format({ colors: "hsl-raw" }); // override preset's oklch default
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Extending presets
|
|
119
|
-
|
|
120
|
-
Presets can bring their own **`style`** (contrast, chroma, and other generation options). **`.style(partial)`** after **`.preset()`** layers your tweaks on top—options merge along the chain, so you can refine a preset’s look for your product without forking the preset object:
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
const theme = hextimate("#DEC0DE")
|
|
124
|
-
.preset(presets.tinted) // e.g. sets a looser surfaceMaxChroma
|
|
125
|
-
.style({ surfaceMaxChroma: 0.01 }) // tighten further for this app
|
|
126
|
-
.preset(presets.shadcn)
|
|
127
|
-
.format();
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
See [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md) for the full list, chaining details, and how to create your own.
|
|
131
|
-
|
|
132
|
-
## Two-step API: generate, then format
|
|
133
|
-
|
|
134
|
-
hextimator separates **palette generation** (color math) from **formatting** (output shape). This lets you extend the palette before choosing how to serialize it.
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
const theme = hextimate("#0FF5E7").format({ as: "css", colors: "oklch" });
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Palette options with `.style()`
|
|
141
|
-
|
|
142
|
-
**`hextimate` only takes the color.** Everything that steers generation—contrast rules, chroma caps, hue tweaks, light/dark tweaks, and the rest—goes on **`.style(partial)`**. Call it once or stack several calls; each merges into the current options (later wins on the same keys).
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
hextimate("#FACADE")
|
|
146
|
-
.style({ minContrastRatio: "AA", surfaceMaxChroma: 0.02 })
|
|
147
|
-
.format();
|
|
37
|
+
const css = hextimate("#C0FFEE").format({ as: "css" });
|
|
148
38
|
```
|
|
149
39
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
### Filtering output
|
|
153
|
-
|
|
154
|
-
Use `excludeRoles` and `excludeVariants` in `.format()` (or in a preset's `format` field) to drop tokens you don't need:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
// Drop the caution role and the strong/weak variants entirely
|
|
158
|
-
hextimate("#F11732").format({
|
|
159
|
-
excludeRoles: ["caution"],
|
|
160
|
-
excludeVariants: ["strong", "weak"],
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Useful in custom presets to keep output tight
|
|
164
|
-
const myPreset: HextimatePreset = {
|
|
165
|
-
format: {
|
|
166
|
-
excludeRoles: ["caution"],
|
|
167
|
-
excludeVariants: ["weak"],
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Both options use internal names (before any `roleNames`/`variantNames` remapping).
|
|
173
|
-
|
|
174
|
-
### Output formats
|
|
175
|
-
|
|
176
|
-
All formats return `{ light: { ... }, dark: { ... } }`.
|
|
177
|
-
|
|
178
|
-
- **`"object"`** (default) — plain keys: `accent`, `accent-strong`, … Optional **`keyPrefix: "--"`** gives `--accent`, `--accent-strong`, … when you need CSS-style names without stylesheet output.
|
|
179
|
-
- **`"css"`** — CSS custom properties: `--accent`, `--accent-strong`, …
|
|
180
|
-
- **`"tailwind"`** — nested tokens: `{ accent: { DEFAULT, strong, … } }`
|
|
181
|
-
- **`"tailwind-css"`** — `@theme` block with `--color-accent`, `--color-accent-strong`, …
|
|
182
|
-
- **`"scss"`** — SCSS variables: `$accent`, `$accent-strong`, …
|
|
183
|
-
- **`"json"`** — JSON string of the plain object (supports **`keyPrefix`** the same way as **`object`**)
|
|
40
|
+
`hextimate` turns one color into theme output. After that you decide how it ships: inline `<style>`, a `.css` file, a template partial, an edge cache, or something else. Prefer tokens over a stylesheet: `format({ as: 'object' })`
|
|
184
41
|
|
|
185
|
-
|
|
42
|
+
Pure computation; no DOM. SSR-friendly by default.
|
|
186
43
|
|
|
187
|
-
|
|
188
|
-
| ----------------- | ------------------------------------ |
|
|
189
|
-
| `"hex"` (default) | `"#6a5acd"` |
|
|
190
|
-
| `"oklch"` | `"oklch(0.54 0.18 276)"` |
|
|
191
|
-
| `"oklch-raw"` | `"0.54 0.18 276"` |
|
|
192
|
-
| `"rgb"` | `"rgb(106, 90, 205)"` |
|
|
193
|
-
| `"rgb-raw"` | `"106 90 205"` |
|
|
194
|
-
| `"hsl"` | `"hsl(248, 53%, 58%)"` |
|
|
195
|
-
| `"hsl-raw"` | `"248 53% 58%"` |
|
|
196
|
-
| `"p3"` | `"color(display-p3 0.39 0.34 0.79)"` |
|
|
197
|
-
| `"p3-raw"` | `"0.39 0.34 0.79"` |
|
|
44
|
+
### React (SSR-safe)
|
|
198
45
|
|
|
199
|
-
|
|
46
|
+
```tsx
|
|
47
|
+
import { HextimatorStyle } from "hextimator/react";
|
|
200
48
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
> **Note on alpha**: Alpha values are intentionally ignored — `rgba(255, 0, 0, 0.5)` is treated as fully opaque `rgb(255, 0, 0)`. Alpha tokens undermine accessibility guarantees because contrast ratios depend on the background, which hextimator does not control. You can always add an opacity modifier later if you wish (e.g. `accent-weak/20` in tailwind).
|
|
204
|
-
|
|
205
|
-
Before `.format()` you can still chain **`addRole` / `addVariant` / `addToken`**, **`.preset()`**, **`.fork()`**, **`.simulate()` / `.adaptFor()`**, and anything else in [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) or [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md).
|
|
206
|
-
|
|
207
|
-
## How it works
|
|
208
|
-
|
|
209
|
-
1. **Parse** any color input into a normalized `Color` object.
|
|
210
|
-
2. **Convert** to OKLCH (perceptual color space) so lightness and chroma adjustments look uniform across hues.
|
|
211
|
-
3. **Generate** accent, surface, and semantic color scales — each with DEFAULT, strong, weak, and foreground variants.
|
|
212
|
-
4. **Gamut-map** back to sRGB via binary-search chroma reduction (preserves lightness and hue).
|
|
213
|
-
5. **Format** into your chosen output (CSS vars, Tailwind, SCSS, JSON, or plain object).
|
|
214
|
-
|
|
215
|
-
## Utilities
|
|
216
|
-
|
|
217
|
-
hextimator also exports its parsing and conversion functions for standalone use:
|
|
218
|
-
|
|
219
|
-
```typescript
|
|
220
|
-
import { parseColor, convertColor } from "hextimator";
|
|
221
|
-
|
|
222
|
-
const color = parseColor("rgb(255, 102, 102)");
|
|
223
|
-
const oklch = convertColor(color, "oklch");
|
|
49
|
+
<HextimatorStyle color={"#0FF1CE"} />;
|
|
224
50
|
```
|
|
225
51
|
|
|
226
|
-
|
|
52
|
+
Place it in your layout `<head>`. It renders a `<style>` node during server render (no `useEffect`, no FOUC from missing variables when paired with static HTML). Full API and dark-mode strategies: [React](docs/react.md).
|
|
227
53
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
```sh
|
|
231
|
-
npx hextimate "#ff6677";
|
|
232
|
-
```
|
|
54
|
+
### CLI (and AI agents)
|
|
233
55
|
|
|
234
|
-
|
|
56
|
+
Stable entry point for tooling: same engine as the library, flags for presets and format.
|
|
235
57
|
|
|
58
|
+
```bash
|
|
59
|
+
npx hextimator '#BADA55' --preset shadcn # framework-shaped tokens
|
|
60
|
+
npx hextimator '#BADA55' --preset muted # style preset
|
|
61
|
+
npx hextimator '#BADA55' --preset vibrant
|
|
62
|
+
npx hextimator '#BADA55' --preset bold
|
|
236
63
|
```
|
|
237
|
-
npx hextimate -h
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
> Note: `hextimate` and `hextimator` are the same CLI; pick whichever you like typing.
|
|
241
|
-
|
|
242
|
-
## React
|
|
243
|
-
|
|
244
|
-
Import from `hextimator/react`:
|
|
245
64
|
|
|
246
|
-
|
|
247
|
-
- **`useHextimator`** or **`HextimatorStyle`** — simpler surface, no context: emit CSS only (hook uses `document.head` or `target`; component renders `<style>`, optional **`selector`** for scoping, handy for SSR/RSC).
|
|
248
|
-
- **`HextimatorScope`** — subtree theming and nested context; **inherits** custom shape from the parent **`builder`** via **`fork()`**.
|
|
65
|
+
## What is in every theme
|
|
249
66
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
@import "hextimator/fallback.css";
|
|
258
|
-
@import "hextimator/tailwind.css";
|
|
259
|
-
```
|
|
67
|
+
| Role | Variants |
|
|
68
|
+
| -------- | --------------------------------- |
|
|
69
|
+
| surface | DEFAULT, strong, weak, foreground |
|
|
70
|
+
| accent | DEFAULT, strong, weak, foreground |
|
|
71
|
+
| positive | DEFAULT, strong, weak, foreground |
|
|
72
|
+
| negative | DEFAULT, strong, weak, foreground |
|
|
73
|
+
| caution | DEFAULT, strong, weak, foreground |
|
|
260
74
|
|
|
261
|
-
|
|
75
|
+
Plus **`brand-exact`** (your input color, unmodified) and **`brand-exact-foreground`**.
|
|
262
76
|
|
|
263
|
-
##
|
|
77
|
+
## Customization and reference
|
|
264
78
|
|
|
265
|
-
- [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md)
|
|
266
|
-
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md)
|
|
267
|
-
- [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md)
|
|
268
|
-
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md)
|
|
269
|
-
- [
|
|
270
|
-
- [
|
|
271
|
-
- [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md) — setup and usage with Tailwind
|
|
272
|
-
- [Real-world examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md) — shadcn/ui, Stripe, Slack configurations
|
|
79
|
+
- [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md): style and format options reference
|
|
80
|
+
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md): `addRole`, `addVariant`, `addToken`
|
|
81
|
+
- [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md): drop-in configs for shadcn/ui, or create your own
|
|
82
|
+
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md): dynamic theming and `.fork()`
|
|
83
|
+
- [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md): hook, `HextimatorStyle`, provider, scoped themes, dark mode
|
|
84
|
+
- [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md): setup and usage with Tailwind
|
|
273
85
|
|
|
274
|
-
###
|
|
86
|
+
### Also
|
|
275
87
|
|
|
276
|
-
- [
|
|
88
|
+
- [Color vision deficiency](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/color-vision-deficiency.md)
|
|
89
|
+
- [Examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md)
|
|
90
|
+
- [Migration](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md)
|
|
277
91
|
|
|
278
92
|
## Contributing
|
|
279
93
|
|
|
@@ -1526,7 +1526,7 @@ function generateAccent(accent, themeType, options) {
|
|
|
1526
1526
|
}
|
|
1527
1527
|
|
|
1528
1528
|
// src/generate/generateSemanticColors.ts
|
|
1529
|
-
var POSITIVE_RANGE = [120,
|
|
1529
|
+
var POSITIVE_RANGE = [120, 180];
|
|
1530
1530
|
var NEGATIVE_RANGE = [5, 30];
|
|
1531
1531
|
var CAUTION_RANGE = [45, 70];
|
|
1532
1532
|
function generateSemanticColors(color, themeType, options) {
|
package/dist/cli.js
CHANGED
|
@@ -1534,7 +1534,7 @@ function generateAccent(accent, themeType, options) {
|
|
|
1534
1534
|
}
|
|
1535
1535
|
|
|
1536
1536
|
// src/generate/generateSemanticColors.ts
|
|
1537
|
-
var POSITIVE_RANGE = [120,
|
|
1537
|
+
var POSITIVE_RANGE = [120, 180];
|
|
1538
1538
|
var NEGATIVE_RANGE = [5, 30];
|
|
1539
1539
|
var CAUTION_RANGE = [45, 70];
|
|
1540
1540
|
function generateSemanticColors(color, themeType, options) {
|
|
@@ -2393,6 +2393,16 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2393
2393
|
}
|
|
2394
2394
|
};
|
|
2395
2395
|
|
|
2396
|
+
// src/presets/bold.ts
|
|
2397
|
+
var bold = {
|
|
2398
|
+
style: {
|
|
2399
|
+
light: { baseLightness: 0.5 },
|
|
2400
|
+
dark: { baseLightness: 0.8 },
|
|
2401
|
+
surfaceMaxChroma: 0.06,
|
|
2402
|
+
foregroundMaxChroma: 0.02
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
|
|
2396
2406
|
// src/presets/mui.ts
|
|
2397
2407
|
var mui = {
|
|
2398
2408
|
roles: [
|
|
@@ -2574,7 +2584,8 @@ var AVAILABLE_PRESETS = {
|
|
|
2574
2584
|
mui,
|
|
2575
2585
|
muted,
|
|
2576
2586
|
vibrant,
|
|
2577
|
-
tinted
|
|
2587
|
+
tinted,
|
|
2588
|
+
bold
|
|
2578
2589
|
};
|
|
2579
2590
|
var HELP = `
|
|
2580
2591
|
hextimator <color> [options]
|
|
@@ -2587,7 +2598,7 @@ Arguments:
|
|
|
2587
2598
|
Presets:
|
|
2588
2599
|
-p, --preset <name> Apply a preset (repeatable, applied in order):
|
|
2589
2600
|
Framework: shadcn, mui
|
|
2590
|
-
Style: muted, vibrant, tinted
|
|
2601
|
+
Style: muted, vibrant, tinted, bold
|
|
2591
2602
|
|
|
2592
2603
|
Format options:
|
|
2593
2604
|
-f, --format <type> css | object | tailwind | tailwind-css | scss | json (default: css)
|
package/dist/index.js
CHANGED
package/dist/react.js
CHANGED
package/llms.txt
CHANGED
|
@@ -1,493 +1,157 @@
|
|
|
1
1
|
# hextimator
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> One brand color in. A complete, accessible light + dark theme out.
|
|
4
|
+
> Use it programmatically (`hextimate(color)`) or via CLI (`npx hextimator`).
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Generates palettes in **OKLCH** for perceptually even contrast; outputs map to sRGB with gamut mapping. WCAG contrast targets are configurable (`AAA` default).
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
npm install hextimator
|
|
9
|
-
```
|
|
8
|
+
## Pick a path
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
- **Got a color, want a stylesheet?** - CLI (section 1)
|
|
11
|
+
- **Got a color, want JSON / programmatic access?** - Library (section 2)
|
|
12
|
+
- **Building a React app?** - React (section 3)
|
|
13
|
+
- **Need a specific framework's tokens?** - Presets (section 4)
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
import { hextimate } from "hextimator";
|
|
15
|
+
## 1. CLI
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npx hextimator <color> [--preset <name>]... [-f|--format <as>] [-c|--colors <space>] [-o|--output <path>]
|
|
19
|
+
# alias:
|
|
20
|
+
npx hextimate <color> [same options]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Quote hex colors in the shell (`'#6366f1'`).
|
|
24
|
+
|
|
25
|
+
### Common flags
|
|
26
|
+
|
|
27
|
+
| Flag | Meaning | Default |
|
|
28
|
+
|------|---------|---------|
|
|
29
|
+
| `-p`, `--preset` | Preset name, **repeatable** in order (`muted` then `shadcn`, etc.) | - |
|
|
30
|
+
| `-f`, `--format` | `css`, `object`, `tailwind`, `tailwind-css`, `scss`, `json` | `css` |
|
|
31
|
+
| `-c`, `--colors` | `hex`, `rgb`, `hsl`, `oklch`, `p3` (+ `-raw` variants) | `hex` |
|
|
32
|
+
| `-t`, `--theme` | `light`, `dark`, `both` (ignored for `css` / `tailwind-css`) | `both` |
|
|
33
|
+
| `-o`, `--output` | Write file instead of stdout | stdout |
|
|
34
|
+
| `--dark-mode` | `media`, `class`, `data-attribute`, `off` (stylesheet formats only) | `media` |
|
|
35
|
+
| `--selector` | Root selector for CSS output | `:root` |
|
|
36
|
+
| `--separator` | Between role and variant in token names | `-` |
|
|
37
|
+
| `--key-prefix` | For `object` / `json`; use `--` for CSS-like keys | (empty) |
|
|
38
|
+
| `--exclude-role`, `--exclude-variant` | Omit by internal name (repeatable) | - |
|
|
39
|
+
| `--min-contrast` | `AAA`, `AA`, or number | `AAA` |
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
const css = hextimate("#6A5ACD").format({ as: "css", colors: "oklch" });
|
|
22
|
-
// → ":root { --accent: oklch(...); ... }\n@media (prefers-color-scheme: dark) { :root { ... } }"
|
|
23
|
-
```
|
|
41
|
+
### Style / semantics (CLI mirrors library `style`)
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### `hextimate(color)`
|
|
28
|
-
|
|
29
|
-
Creates a palette builder from any color input.
|
|
30
|
-
|
|
31
|
-
- `color`: `string` (hex, CSS function), `[r, g, b]` tuple, `number` (0xFF6666), or a `Color` object
|
|
32
|
-
- Returns: `HextimatePaletteBuilder` (chainable)
|
|
33
|
-
- Throws: `HextimateError` on invalid input
|
|
34
|
-
|
|
35
|
-
Tune how the palette is built with `.style(partial)` (`HextimateStyleOptions`, see table below). Presets may include a `style` field; later `.style()` calls merge on top.
|
|
36
|
-
|
|
37
|
-
### Builder methods (all return `this`, chainable)
|
|
38
|
-
|
|
39
|
-
| Method | Description |
|
|
40
|
-
|---|---|
|
|
41
|
-
| `.addRole(name, color)` | Add a new color role with DEFAULT, strong, weak, foreground variants |
|
|
42
|
-
| `.addVariant(name, placement)` | Add a lightness step to every role. `placement`: `{ from: "strong" }`, `{ from: "weak" }`, or `{ between: ["DEFAULT", "weak"] }` |
|
|
43
|
-
| `.addToken(name, value)` | Add a standalone derived token. `value`: a color, `{ from: "role.variant", emphasis?, lightness?, chroma?, hue? }`, or `{ light: ..., dark: ... }` for per-theme values. `emphasis` is theme-aware (positive = more contrast, negative = softer) |
|
|
44
|
-
| `.preset(preset)` | Apply a preset (chainable -- call multiple times to layer style + framework presets). Preset format defaults are overridden by `.format()` options |
|
|
45
|
-
| `.style(partial)` | Merge style options into the builder, regenerate palettes, and replay recorded operations |
|
|
46
|
-
| `.simulate(cvdType, severity?)` | Simulate color vision deficiency. Types: `protanopia`, `deuteranopia`, `tritanopia`, `achromatopsia` |
|
|
47
|
-
| `.adaptFor(cvdType, severity?)` | Optimize palette for a CVD type (use instead of simulate for actual accessibility) |
|
|
48
|
-
| `.fork(color?)` | Clone builder with optional new accent color. Chain `.style()` on the fork to change style options. Original unchanged |
|
|
49
|
-
| `.format(options?)` | Output the palette (see format options) |
|
|
50
|
-
|
|
51
|
-
### `.format(options?)` → `{ light: FormatResult, dark: FormatResult }` or `string`
|
|
52
|
-
|
|
53
|
-
| Option | Values | Default |
|
|
54
|
-
|---|---|---|
|
|
55
|
-
| `as` | `"object"`, `"css"`, `"tailwind"`, `"tailwind-css"`, `"scss"`, `"json"` | `"object"` |
|
|
56
|
-
| `colors` | `"hex"`, `"rgb"`, `"rgb-raw"`, `"hsl"`, `"hsl-raw"`, `"oklch"`, `"oklch-raw"`, `"p3"`, `"p3-raw"` | `"hex"` |
|
|
57
|
-
| `roleNames` | `Record<string, string>` — rename roles in output keys | built-in names |
|
|
58
|
-
| `variantNames` | `Record<string, string>` — rename variant suffixes | built-in names |
|
|
59
|
-
| `separator` | `string` — between role and variant in keys | `"-"` |
|
|
60
|
-
| `keyPrefix` | `string` — prepended to each key (`object` / `json` only); e.g. `"--"` for CSS vars | `""` |
|
|
61
|
-
| `darkMode` | `"media"`, `"class"`, `"data-attribute"`, `false` (stylesheet outputs only) | `"media"` |
|
|
62
|
-
| `selector` | `string` — root selector for `as: "css"` | `":root"` |
|
|
63
|
-
| `excludeRoles` | `string[]` — role keys to omit entirely from output (by internal name, before `roleNames`) | `[]` |
|
|
64
|
-
| `excludeVariants` | `string[]` — variant keys to omit from every role's output (by internal name, before `variantNames`) | `[]` |
|
|
65
|
-
|
|
66
|
-
Output shape depends on `as`:
|
|
67
|
-
- `"object"` → `{ light, dark }` flat maps: `{ accent: "#...", "accent-strong": "#..." }` (with `keyPrefix: "--"`: `{ "--accent": "...", "--accent-strong": "..." }`)
|
|
68
|
-
- `"css"` → `string` — ready-to-paste CSS stylesheet with `:root {}` and a dark-mode wrapper
|
|
69
|
-
- `"tailwind"` → `{ light, dark }` nested maps: `{ accent: { DEFAULT: "#...", strong: "#..." } }`
|
|
70
|
-
- `"tailwind-css"` → `string` — Tailwind v4 stylesheet: single `@theme { --color-accent: #...; }` block plus dark overrides
|
|
71
|
-
- `"scss"` → `{ light, dark }` flat maps: `{ "$accent": "#...", "$accent-strong": "#..." }`
|
|
72
|
-
- `"json"` → `{ light, dark }` JSON strings (`keyPrefix` applies like `"object"`)
|
|
73
|
-
|
|
74
|
-
Pick the dark wrapper with `darkMode`: `"media"` (default) wraps dark tokens in `@media (prefers-color-scheme: dark)`; `"class"` uses `.dark`; `"data-attribute"` uses `[data-theme="dark"]`; `false` omits dark entirely. For `as: "css"`, change the root selector with `selector` (e.g. `selector: "[data-theme]"`).
|
|
75
|
-
|
|
76
|
-
### Style options (`HextimateStyleOptions`)
|
|
77
|
-
|
|
78
|
-
| Option | Type | Default | Description |
|
|
79
|
-
|---|---|---|---|
|
|
80
|
-
| `surfaceColor` | color input | auto-derived | Override surface/neutral baseline color |
|
|
81
|
-
| `surfaceHueShift` | degrees | `0` | Rotate surface hue relative to accent. Ignored if `surfaceColor` set |
|
|
82
|
-
| `invertDarkModeSurfaceAccent` | boolean | `false` | Swap surface/accent hues in dark mode. Useful when the accent should become the background in dark mode. Requires `surfaceColor` |
|
|
83
|
-
| `semanticColors` | `{ positive?, negative?, caution? }` | auto | Override semantic colors (green/red/amber) |
|
|
84
|
-
| `semanticColorRanges` | `{ positive?: [start,end], ... }` | `positive: [120,160]`, `negative: [5,30]`, `caution: [45,70]` | OKLCH hue degree arcs for picking semantic bases (clockwise; `[350,10]` wraps) |
|
|
85
|
-
| `surfaceMaxChroma` | number | `0.01` | Max chroma for surface colors |
|
|
86
|
-
| `foregroundMaxChroma` | number | `0.01` | Max chroma for foreground colors |
|
|
87
|
-
| `light` | `{ baseLightness?, maxChroma? }` | **0.10.0+:** input OKLCH `l` (clamped). **≤0.9.x:** implicit `0.7` when omitted. | Light theme adjustments. `baseLightness` is the absolute OKLCH anchor for the accent when set; otherwise the default above applies (distinct from the relative `lightness` offset on derived tokens) |
|
|
88
|
-
| `dark` | `{ baseLightness?, maxChroma? }` | Same seed as light (**0.10.0+**) or implicit `0.6` (**≤0.9.x**) when omitted unless `dark.baseLightness` is set | Dark theme adjustments |
|
|
89
|
-
| `minContrastRatio` | `"AAA"`, `"AA"`, or number | `"AAA"` | WCAG contrast target (AAA=7, AA=4.5) |
|
|
90
|
-
| `hueShift` | degrees | `0` | Per-variant hue rotation |
|
|
91
|
-
|
|
92
|
-
### Default palette structure
|
|
93
|
-
|
|
94
|
-
Every palette includes 5 roles x 4 variants + 2 brand tokens = 22 tokens:
|
|
95
|
-
|
|
96
|
-
- Roles: `surface`, `accent`, `positive`, `negative`, `caution`
|
|
97
|
-
- Variants: `DEFAULT` (no suffix), `strong`, `weak`, `foreground`
|
|
98
|
-
- Brand tokens: `brand-exact` (the exact input color, unmodified), `brand-exact-foreground` (best-contrast foreground for that color)
|
|
99
|
-
|
|
100
|
-
Token keys: `accent`, `accent-strong`, `accent-weak`, `accent-foreground`, `surface`, `surface-strong`, ..., `brand-exact`, `brand-exact-foreground`
|
|
101
|
-
|
|
102
|
-
### Presets
|
|
103
|
-
|
|
104
|
-
Presets are predefined configurations -- for a specific framework or a particular style. They can be chained by calling `.preset()` multiple times. Applied sequentially: later presets override earlier ones for conflicting keys. Call `.style()` after `.preset()` to override overlapping style keys.
|
|
105
|
-
|
|
106
|
-
**Available presets:**
|
|
107
|
-
|
|
108
|
-
| Preset | Type | Description |
|
|
109
|
-
|---|---|---|
|
|
110
|
-
| `shadcn` | Framework | shadcn/ui tokens: --background, --primary, --destructive, --ring, etc. `as: "css"`, `colors: "oklch"` |
|
|
111
|
-
| `mui` | Framework | MUI theme: primary/secondary/error with main/light/dark/contrastText. `as: "object"`, `colors: "hex"` |
|
|
112
|
-
| `muted` | Style | Desaturated, restrained. Low chroma across the board |
|
|
113
|
-
| `vibrant` | Style | High saturation, complementary tinted neutrals, slight hue shift |
|
|
114
|
-
| `tinted` | Style | Neutrals pick up the accent hue for a cohesive feel |
|
|
43
|
+
`--surface-color`, `--surface-hue-shift`, `--hue-shift`, `--surface-max-chroma`, `--fg-max-chroma`, `--light-lightness`, `--light-base-lightness-range`, `--light-max-chroma`, `--dark-lightness`, `--dark-base-lightness-range`, `--dark-max-chroma`, `--base-lightness-range`, `--invert-dark` (needs `--surface-color`), `--positive`, `--negative`, `--caution`.
|
|
115
44
|
|
|
116
|
-
|
|
117
|
-
import { hextimate, presets } from "hextimator";
|
|
45
|
+
### CVD (optional)
|
|
118
46
|
|
|
119
|
-
|
|
120
|
-
const theme = hextimate("#6366F1")
|
|
121
|
-
.preset(presets.shadcn)
|
|
122
|
-
.format();
|
|
123
|
-
|
|
124
|
-
// Style + framework preset
|
|
125
|
-
const theme = hextimate("#6366F1")
|
|
126
|
-
.preset(presets.muted)
|
|
127
|
-
.preset(presets.shadcn)
|
|
128
|
-
.format();
|
|
129
|
-
|
|
130
|
-
// Override preset defaults:
|
|
131
|
-
const theme = hextimate("#6366F1")
|
|
132
|
-
.preset(presets.muted)
|
|
133
|
-
.preset(presets.shadcn)
|
|
134
|
-
.format({ colors: "hsl-raw" });
|
|
135
|
-
```
|
|
47
|
+
`--simulate <protanopia|deuteranopia|tritanopia|achromatopsia>`, `--adapt <same>`, `--cvd-severity 0..1`.
|
|
136
48
|
|
|
137
|
-
|
|
138
|
-
- Preset `style` / `.style()`: nested keys `light`, `dark`, `semanticColors`, `semanticColorRanges` shallow-merge per key; other keys overwrite (later wins)
|
|
139
|
-
- Roles, variants, tokens: concatenated (additive)
|
|
140
|
-
- Format options: deep-merged (roleNames/variantNames merged individually)
|
|
49
|
+
### Custom roles / variants
|
|
141
50
|
|
|
142
|
-
|
|
51
|
+
- `--role name=#RRGGBB` (repeatable)
|
|
52
|
+
- `--variant name:from:edge` or `name:between:a,b` (repeatable)
|
|
143
53
|
|
|
144
|
-
|
|
54
|
+
### Examples
|
|
145
55
|
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
interface HextimatePreset {
|
|
154
|
-
style?: HextimateStyleOptions; // contrast, lightness, chroma, hue shifts
|
|
155
|
-
roles?: Array<{ name: string; color: ColorInput | DerivedToken }>;
|
|
156
|
-
variants?: Array<{ name: string; placement: VariantPlacement }>;
|
|
157
|
-
tokens?: Array<{ name: string; value: TokenValue }>;
|
|
158
|
-
format?: HextimateFormatOptions; // default format options, overridable in .format()
|
|
159
|
-
}
|
|
56
|
+
```bash
|
|
57
|
+
npx hextimator '#6366f1'
|
|
58
|
+
npx hextimator '#6366f1' -f css -c oklch -o theme.css
|
|
59
|
+
npx hextimator '#6366f1' --preset shadcn
|
|
60
|
+
npx hextimator '#6366f1' --preset muted --preset shadcn
|
|
61
|
+
npx hextimator '#22aa44' --role cta=#ee2244 --variant hover:from:strong -o out.css
|
|
160
62
|
```
|
|
161
63
|
|
|
162
|
-
|
|
163
|
-
- A raw color: `"#FF6600"`, `[255, 102, 102]`, etc.
|
|
164
|
-
- A derived reference: `{ from: "role.variant", emphasis?, lightness?, chroma?, hue? }`
|
|
165
|
-
- Per-theme: `{ light: DerivedToken | ColorInput, dark: DerivedToken | ColorInput }`
|
|
166
|
-
|
|
167
|
-
**`from` syntax**: `"role"` resolves to the DEFAULT variant, `"role.variant"` to a specific one. Valid built-in references: `surface`, `surface.strong`, `surface.weak`, `surface.foreground`, `accent`, `accent.strong`, etc. Custom roles/tokens added earlier in the preset can also be referenced.
|
|
64
|
+
## 2. Library
|
|
168
65
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
**`roleNames` / `variantNames`** in format options remap output keys. This is how you match another framework's naming. For example, `roleNames: { surface: "background", accent: "primary" }` turns `surface-strong` into `background-strong` and `accent` into `primary` in the output. `variantNames: { DEFAULT: "main", foreground: "contrastText" }` turns `accent` (DEFAULT) into `primary-main` and `accent-foreground` into `primary-contrastText`.
|
|
172
|
-
|
|
173
|
-
**Role colors** can be derived from other roles: `{ from: "accent", hue: 180 }` creates a role whose hue is rotated 180 degrees from the accent.
|
|
174
|
-
|
|
175
|
-
**Example - custom preset for a design system with "bg", "brand", and "danger" tokens:**
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
const myPreset: HextimatePreset = {
|
|
179
|
-
roles: [
|
|
180
|
-
// Add an "info" role not in the default palette
|
|
181
|
-
{ name: "info", color: "#0288d1" },
|
|
182
|
-
// Derive a secondary role by rotating the accent hue
|
|
183
|
-
{ name: "secondary", color: { from: "accent", hue: 180 } },
|
|
184
|
-
],
|
|
185
|
-
variants: [
|
|
186
|
-
{ name: "muted", placement: { from: "weak" } },
|
|
187
|
-
{ name: "emphasis", placement: { from: "strong" } },
|
|
188
|
-
],
|
|
189
|
-
tokens: [
|
|
190
|
-
// Canvas tokens derived from surface
|
|
191
|
-
{ name: "canvas", value: { from: "surface" } },
|
|
192
|
-
{ name: "canvas-raised", value: { from: "surface", emphasis: -0.025 } },
|
|
193
|
-
{ name: "canvas-overlay", value: { from: "surface", emphasis: -0.05 } },
|
|
194
|
-
|
|
195
|
-
// Text with varying prominence
|
|
196
|
-
{ name: "text-primary", value: { from: "surface.foreground" } },
|
|
197
|
-
{ name: "text-secondary", value: { from: "surface.foreground", emphasis: -0.2 } },
|
|
198
|
-
{ name: "text-disabled", value: { from: "surface.foreground", emphasis: -0.4 } },
|
|
199
|
-
|
|
200
|
-
// Border that adjusts direction per theme
|
|
201
|
-
{ name: "border", value: { from: "surface", emphasis: 0.12 } },
|
|
202
|
-
|
|
203
|
-
// Per-theme token when emphasis alone isn't enough
|
|
204
|
-
{
|
|
205
|
-
name: "divider",
|
|
206
|
-
value: {
|
|
207
|
-
light: { from: "surface.weak", lightness: -0.08 },
|
|
208
|
-
dark: { from: "surface.weak", lightness: +0.08 },
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
format: {
|
|
213
|
-
as: "css",
|
|
214
|
-
colors: "hex",
|
|
215
|
-
roleNames: {
|
|
216
|
-
surface: "bg",
|
|
217
|
-
accent: "brand",
|
|
218
|
-
negative: "danger",
|
|
219
|
-
positive: "success",
|
|
220
|
-
},
|
|
221
|
-
variantNames: {
|
|
222
|
-
DEFAULT: "", // no suffix for the default variant
|
|
223
|
-
strong: "bold",
|
|
224
|
-
weak: "subtle",
|
|
225
|
-
foreground: "on", // e.g. --brand-on
|
|
226
|
-
},
|
|
227
|
-
separator: "-",
|
|
228
|
-
},
|
|
229
|
-
};
|
|
66
|
+
```bash
|
|
67
|
+
npm install hextimator
|
|
230
68
|
```
|
|
231
69
|
|
|
232
|
-
Usage:
|
|
233
|
-
|
|
234
70
|
```typescript
|
|
235
71
|
import { hextimate } from "hextimator";
|
|
236
72
|
|
|
237
|
-
const
|
|
238
|
-
//
|
|
239
|
-
const asScss = hextimate("#6366F1").preset(myPreset).format({ as: "scss" });
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
**How to build a preset for an existing app's theme:**
|
|
243
|
-
|
|
244
|
-
1. List the app's theme tokens (e.g. from its CSS variables or theme config)
|
|
245
|
-
2. Map each token to a hextimator source: which built-in role/variant is it closest to?
|
|
246
|
-
3. Use `roleNames`/`variantNames` to rename the 20 built-in tokens to match the app's naming
|
|
247
|
-
4. Use `tokens` for any extra tokens not covered by the built-in 5x4 grid, deriving them with `from` + `emphasis`/`lightness`/`chroma`/`hue` offsets
|
|
248
|
-
5. Use `roles` if the app has color categories beyond surface/accent/positive/negative/caution
|
|
249
|
-
6. Set `format` defaults to match what the app expects (CSS vars, object, etc.)
|
|
250
|
-
|
|
251
|
-
### Standalone tokens with per-theme values
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
hextimate("#6366F1")
|
|
255
|
-
.addToken("border", {
|
|
256
|
-
light: { from: "surface.weak", lightness: -0.08 },
|
|
257
|
-
dark: { from: "surface.weak", lightness: +0.08 },
|
|
258
|
-
})
|
|
259
|
-
.addToken("ring", { from: "accent" })
|
|
260
|
-
.format({ as: "css" });
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### Utility exports
|
|
73
|
+
const tokens = hextimate("#6366f1").format();
|
|
74
|
+
// { light: { accent, "accent-strong", ... }, dark: { ... } }
|
|
264
75
|
|
|
265
|
-
|
|
266
|
-
import { parseColor, convertColor } from "hextimator";
|
|
267
|
-
|
|
268
|
-
const color = parseColor("rgb(255, 102, 102)"); // → Color object (sRGB)
|
|
269
|
-
const oklch = convertColor(color, "oklch"); // → OKLCH object
|
|
76
|
+
const sheet = hextimate("#6366f1").format({ as: "css", colors: "oklch" });
|
|
270
77
|
```
|
|
271
78
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### Color input formats
|
|
79
|
+
### Builder (chainable)
|
|
275
80
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
81
|
+
| Call | Role |
|
|
82
|
+
|------|------|
|
|
83
|
+
| `.preset(p)` | Apply preset(s); call multiple times, later wins on conflicts |
|
|
84
|
+
| `.style(partial)` | Merge `HextimateStyleOptions` (contrast, surfaces, semantics, etc.) |
|
|
85
|
+
| `.addRole(name, color)` | New role with default / strong / weak / foreground |
|
|
86
|
+
| `.addVariant(name, placement)` | Extra lightness step on every role |
|
|
87
|
+
| `.addToken(name, value)` | Standalone derived token |
|
|
88
|
+
| `.fork(color?)` | Clone for another brand / tenant |
|
|
89
|
+
| `.simulate(cvdType, severity?)` | CVD preview |
|
|
90
|
+
| `.adaptFor(cvdType, severity?)` | Optimize palette for a CVD type |
|
|
91
|
+
| `.format(opts?)` | Output |
|
|
286
92
|
|
|
287
|
-
|
|
93
|
+
### `.format` highlights
|
|
288
94
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
Both commands are identical. Use whichever you prefer.
|
|
298
|
-
|
|
299
|
-
| Flag | Description | Default |
|
|
300
|
-
|---|---|---|
|
|
301
|
-
| `-f, --format` | `css`, `object`, `tailwind`, `tailwind-css`, `scss`, `json` | `css` |
|
|
302
|
-
| `-c, --colors` | `hex`, `rgb`, `rgb-raw`, `hsl`, `hsl-raw`, `oklch`, `oklch-raw`, `p3`, `p3-raw` | `hex` |
|
|
303
|
-
| `-t, --theme` | `light`, `dark`, `both` (ignored for `css`/`tailwind-css` — both always combine into one string) | `both` |
|
|
304
|
-
| `-p, --preset` | Apply preset (repeatable, applied in order): `shadcn`, `mui`, `muted`, `vibrant`, `tinted` | — |
|
|
305
|
-
| `--separator` | Token separator between role and variant | `-` |
|
|
306
|
-
| `--key-prefix` | Prepend to keys (`object` / `json` only); pass `--` for CSS custom properties | empty |
|
|
307
|
-
| `--dark-mode` | `media`, `class`, `data-attribute`, `false` (stylesheet outputs only) | `media` |
|
|
308
|
-
| `--selector` | Root selector for `--format css` | `:root` |
|
|
309
|
-
| `--exclude-role` | Omit a role from output by internal name (repeatable) | — |
|
|
310
|
-
| `--exclude-variant` | Omit a variant from output by internal name (repeatable) | — |
|
|
311
|
-
| `--surface-color` | Override surface color | — |
|
|
312
|
-
| `--surface-hue-shift` | Degrees | `0` |
|
|
313
|
-
| `--hue-shift` | Per-variant hue shift | `0` |
|
|
314
|
-
| `--surface-max-chroma` | Max chroma for surface | `0.01` |
|
|
315
|
-
| `--fg-max-chroma` | Max chroma for foreground | `0.01` |
|
|
316
|
-
| `--light-lightness` | Sets `light.baseLightness` | Omit: **0.10.0+** derives from input OKLCH `l`; **≤0.9.x** `0.7` |
|
|
317
|
-
| `--light-base-lightness-range` | Sets `light.baseLightnessRange` as `min,max` (OKLCH 0–1) | default light `0.4,0.9` |
|
|
318
|
-
| `--base-lightness-range` | Sets top-level `baseLightnessRange` for both themes (`min,max`) | per-theme defaults or overridden by `--light-*` / `--dark-*` |
|
|
319
|
-
| `--light-max-chroma` | Light theme max chroma | — |
|
|
320
|
-
| `--dark-lightness` | Sets `dark.baseLightness` | Omit: **0.10.0+** derives from input OKLCH `l`; **≤0.9.x** `0.6` |
|
|
321
|
-
| `--dark-base-lightness-range` | Sets `dark.baseLightnessRange` as `min,max` (OKLCH 0–1) | default dark `0.2,0.8` |
|
|
322
|
-
| `--dark-max-chroma` | Dark theme max chroma | — |
|
|
323
|
-
| `--min-contrast` | `AAA`, `AA`, or number | `AAA` |
|
|
324
|
-
| `--invert-dark` | Swap surface/accent hues in dark mode (requires --surface-color) | — |
|
|
325
|
-
| `--positive` | Override positive/success color | auto |
|
|
326
|
-
| `--negative` | Override negative/error color | auto |
|
|
327
|
-
| `--caution` | Override caution color | auto |
|
|
328
|
-
| `--simulate` | Simulate CVD: `protanopia`, `deuteranopia`, `tritanopia`, `achromatopsia` | — |
|
|
329
|
-
| `--adapt` | Adapt palette for CVD type | — |
|
|
330
|
-
| `--cvd-severity` | CVD severity 0-1 | `1` |
|
|
331
|
-
| `--role <name>=<color>` | Add custom role (repeatable) | — |
|
|
332
|
-
| `--variant <spec>` | Add variant: `name:from:edge` or `name:between:a,b` (repeatable) | — |
|
|
333
|
-
| `-o, --output <path>` | Write to file instead of stdout | stdout |
|
|
95
|
+
| `as` | Result |
|
|
96
|
+
|------|--------|
|
|
97
|
+
| `object` | `{ light, dark }` flat maps |
|
|
98
|
+
| `css` | Single stylesheet string |
|
|
99
|
+
| `tailwind` | Nested `{ role: { DEFAULT, strong, ... } }` per side |
|
|
100
|
+
| `tailwind-css` | Tailwind v4 `@theme` string |
|
|
101
|
+
| `scss` / `json` | As named |
|
|
334
102
|
|
|
335
|
-
|
|
336
|
-
# Generate CSS palette
|
|
337
|
-
npx hextimator "#6A5ACD" --format css --colors oklch
|
|
103
|
+
`colors`, `darkMode` (`"media"` \| `"class"` \| `"data-attribute"` \| `false`), `selector`, `roleNames`, `variantNames`, `separator`, `keyPrefix`, `excludeRoles`, `excludeVariants` match the CLI conceptually.
|
|
338
104
|
|
|
339
|
-
|
|
340
|
-
npx hextimator "#6366F1" --preset shadcn
|
|
105
|
+
### Default token grid
|
|
341
106
|
|
|
342
|
-
|
|
343
|
-
npx hextimator "#6366F1" --preset muted --preset shadcn
|
|
107
|
+
Roles: `surface`, `accent`, `positive`, `negative`, `caution`. Variants: default (no suffix), `strong`, `weak`, `foreground`. Plus `brand-exact` and `brand-exact-foreground`.
|
|
344
108
|
|
|
345
|
-
|
|
346
|
-
npx hextimator "#6A5ACD" --surface-color "#FEBA5D" --invert-dark
|
|
109
|
+
### Utilities
|
|
347
110
|
|
|
348
|
-
|
|
349
|
-
npx hextimator "#22aa44" --role cta=#ee2244 --variant hover:from:strong -o theme.css
|
|
111
|
+
`parseColor`, `convertColor`, `simulateColor`, `daltonizeColor` are exported from `hextimator`.
|
|
350
112
|
|
|
351
|
-
|
|
352
|
-
npx hextimator "#ff6600" --simulate deuteranopia
|
|
113
|
+
### Color inputs
|
|
353
114
|
|
|
354
|
-
|
|
355
|
-
npx hextimator "#ff6600" --adapt deuteranopia --cvd-severity 0.8
|
|
356
|
-
```
|
|
115
|
+
Hex (with or without `#`), CSS `rgb` / `hsl`, `[r,g,b]` tuple, numeric `0xRRGGBB`. Alpha ignored.
|
|
357
116
|
|
|
358
|
-
## React
|
|
117
|
+
## 3. React
|
|
359
118
|
|
|
360
119
|
```typescript
|
|
361
120
|
import { useHextimator } from "hextimator/react";
|
|
121
|
+
import { hextimate, presets } from "hextimator";
|
|
362
122
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
Dark mode strategies:
|
|
370
|
-
- `{ type: "media" }` (default) -- uses `prefers-color-scheme` media query
|
|
371
|
-
- `{ type: "class", className?: string }` -- toggles on a CSS class (default: `"dark"`)
|
|
372
|
-
- `{ type: "data", attribute?: string }` -- toggles on a data attribute (default: `"data-theme"`)
|
|
373
|
-
- `{ type: "media-or-class", className?: string }` -- media query with class override
|
|
374
|
-
- `false` -- disable dark mode entirely
|
|
375
|
-
|
|
376
|
-
Hook options:
|
|
377
|
-
|
|
378
|
-
| Option | Type | Description |
|
|
379
|
-
|---|---|---|
|
|
380
|
-
| `style` | `HextimateStyleOptions` | Palette style options |
|
|
381
|
-
| `presets` | `HextimatePreset[]` | Presets to apply in order (style + framework) |
|
|
382
|
-
| `format` | `Omit<HextimateFormatOptions, "as">` | Format options (output is always CSS vars) |
|
|
383
|
-
| `configure` | `(builder: HextimatePaletteBuilder) => void` | Customize the builder (add roles, tokens, etc.) |
|
|
384
|
-
| `darkMode` | `DarkModeStrategy` | Dark mode strategy (see above) |
|
|
385
|
-
| `cssPrefix` | `string` | Prefix for all CSS variable names |
|
|
386
|
-
| `target` | `RefObject<HTMLElement>` | Inject variables into a specific element instead of `:root` |
|
|
387
|
-
|
|
388
|
-
### Provider
|
|
389
|
-
|
|
390
|
-
For app-wide theming with dynamic color changes:
|
|
391
|
-
|
|
392
|
-
```typescript
|
|
393
|
-
import { HextimatorProvider, useHextimatorTheme } from "hextimator/react";
|
|
394
|
-
|
|
395
|
-
<HextimatorProvider
|
|
396
|
-
defaultColor="#6A5ACD" // string OR { light: "#...", dark: "#..." }
|
|
397
|
-
defaultMode="system" // "light" | "dark" | "system"
|
|
398
|
-
onColorChange={(next) => persist(next)} // fires on every color change
|
|
399
|
-
onModePreferenceChange={(mode) => persist(mode)}
|
|
400
|
-
style={styleOpts}
|
|
401
|
-
presets={[presets.muted, presets.shadcn]}
|
|
402
|
-
format={formatOpts}
|
|
403
|
-
darkMode={{ type: "class" }}
|
|
404
|
-
cssPrefix="app"
|
|
405
|
-
target={containerRef}
|
|
406
|
-
>
|
|
407
|
-
<App />
|
|
408
|
-
</HextimatorProvider>
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
**Per-mode colors:** pass `defaultColor={{ light: "#FF6600", dark: "#0088FF" }}` to use a different brand color per mode. Both palettes are built and stitched in CSS, so `@media (prefers-color-scheme: dark)` always serves the dark palette correctly. When `light === dark` (default for a string), only one palette is built.
|
|
412
|
-
|
|
413
|
-
**Persistence:** `onColorChange` and `onModePreferenceChange` always fire on user-driven updates. Wire them to localStorage / cookies / etc. Restore by reading once on mount and passing the result to `defaultColor` / `defaultMode`. For forced overrides (URL-driven, server push), remount with `key={color}`.
|
|
414
|
-
|
|
415
|
-
**FOUC:** the provider injects CSS in `useEffect` (after first paint). To avoid flash on SPAs, read storage synchronously in a lazy initializer so `defaultColor` is already correct on the first render. For SSR (Next.js, Remix), persist in a cookie and render `<HextimatorStyle>` server-side in the layout `<head>`.
|
|
416
|
-
|
|
417
|
-
`useHextimatorTheme()` returns:
|
|
418
|
-
|
|
419
|
-
| Property | Type | Description |
|
|
420
|
-
|---|---|---|
|
|
421
|
-
| `color` | `string` | Color active for the resolved mode (= `lightColor` in light, `darkColor` in dark) |
|
|
422
|
-
| `setColor` | `(color: string) => void` | Sets BOTH `lightColor` and `darkColor` (one-color-in, whole-theme-out) |
|
|
423
|
-
| `lightColor` | `string` | Color used to generate the light-mode palette |
|
|
424
|
-
| `setLightColor` | `(color: string) => void` | Update only the light-mode color |
|
|
425
|
-
| `darkColor` | `string` | Color used to generate the dark-mode palette |
|
|
426
|
-
| `setDarkColor` | `(color: string) => void` | Update only the dark-mode color |
|
|
427
|
-
| `palette` | `HextimateResult` | The generated `{ light, dark }` palette (light from `lightColor`, dark from `darkColor`) |
|
|
428
|
-
| `mode` | `"light" \| "dark"` | Resolved color mode (accounts for OS preference) |
|
|
429
|
-
| `modePreference` | `"light" \| "dark" \| "system"` | Raw preference before resolution |
|
|
430
|
-
| `setMode` | `(mode: ModePreference) => void` | Change mode preference |
|
|
431
|
-
| `style` | `HextimateStyleOptions \| undefined` | Current style options |
|
|
432
|
-
| `setStyle` | `(opts) => void` | Update style options |
|
|
433
|
-
| `presets` | `HextimatePreset[] \| undefined` | Current presets |
|
|
434
|
-
| `setPresets` | `(presets) => void` | Update presets (triggers re-generation) |
|
|
435
|
-
| `configure` | `((builder) => void) \| undefined` | Current builder configure function |
|
|
436
|
-
| `setConfigure` | `(fn) => void` | Update the configure callback |
|
|
437
|
-
|
|
438
|
-
### `HextimatorStyle`
|
|
439
|
-
|
|
440
|
-
Declarative alternative to `useHextimator`. Renders a `<style>` element with CSS variables directly in the tree -- works during SSR/RSC (no `useEffect`). Optional `selector` for per-subtree scoping via CSS cascade.
|
|
441
|
-
|
|
442
|
-
```tsx
|
|
443
|
-
import { HextimatorStyle } from "hextimator/react";
|
|
444
|
-
|
|
445
|
-
// Global theme (SSR-safe)
|
|
446
|
-
<HextimatorStyle color="#ff6600" darkMode={{ type: "class" }} />
|
|
447
|
-
|
|
448
|
-
// Scoped to a specific subtree
|
|
449
|
-
<div className="card-a">
|
|
450
|
-
<HextimatorStyle color="#ff0066" selector=".card-a" />
|
|
451
|
-
...
|
|
452
|
-
</div>
|
|
123
|
+
useHextimator("#6366f1", {
|
|
124
|
+
presets: [presets.muted, presets.shadcn],
|
|
125
|
+
darkMode: { type: "class" }, // optional: media | class | data | media-or-class | false
|
|
126
|
+
});
|
|
453
127
|
```
|
|
454
128
|
|
|
455
|
-
|
|
129
|
+
For app-wide state and palette switching: `HextimatorProvider`, `useHextimatorTheme` from `hextimator/react`.
|
|
456
130
|
|
|
457
|
-
|
|
131
|
+
**SSR:** `HextimatorStyle` injects `<style>` without waiting for effects; use optional `selector` to scope.
|
|
458
132
|
|
|
459
|
-
Subtree
|
|
133
|
+
**Subtree themes:** `HextimatorScope` inherits shape from parent via `fork()` when nested.
|
|
460
134
|
|
|
461
|
-
|
|
462
|
-
import { HextimatorProvider, HextimatorScope } from "hextimator/react";
|
|
135
|
+
React options align with `.style()`, `.preset()` / `presets[]`, `.format()` (output is CSS variables).
|
|
463
136
|
|
|
464
|
-
|
|
465
|
-
defaultColor="#ff6600"
|
|
466
|
-
presets={[presets.shadcn]}
|
|
467
|
-
darkMode={{ type: "class" }}
|
|
468
|
-
configure={(b) => b.addRole("cta", "#ff0066")}
|
|
469
|
-
>
|
|
470
|
-
<App>
|
|
471
|
-
{/* Inherits shadcn preset + cta role, just swaps color */}
|
|
472
|
-
<HextimatorScope defaultColor="#0066ff" darkMode={{ type: "class" }}>
|
|
473
|
-
<Card />
|
|
474
|
-
</HextimatorScope>
|
|
475
|
-
</App>
|
|
476
|
-
</HextimatorProvider>
|
|
477
|
-
```
|
|
137
|
+
## 4. Presets
|
|
478
138
|
|
|
479
|
-
|
|
139
|
+
Import: `import { hextimate, presets } from "hextimator"`.
|
|
480
140
|
|
|
481
|
-
|
|
141
|
+
| Name | Kind | Notes |
|
|
142
|
+
|------|------|--------|
|
|
143
|
+
| `shadcn` | Framework | shadcn/ui-style CSS variables; pairs well with `as: "css"`, `colors: "oklch"` |
|
|
144
|
+
| `mui` | Framework | MUI-shaped token tree; often `colors: "hex"` |
|
|
145
|
+
| `muted` | Style | Lower chroma |
|
|
146
|
+
| `vibrant` | Style | Higher chroma / complementary neutrals |
|
|
147
|
+
| `tinted` | Style | Neutrals follow accent hue |
|
|
148
|
+
| `bold` | Style | Stronger accents, higher chroma on neutrals |
|
|
482
149
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
```css
|
|
486
|
-
@import "hextimator/fallback.css";
|
|
487
|
-
@import "hextimator/tailwind.css"; /* if using Tailwind */
|
|
150
|
+
```typescript
|
|
151
|
+
hextimate("#6366f1").preset(presets.muted).preset(presets.shadcn).format();
|
|
488
152
|
```
|
|
489
153
|
|
|
490
|
-
|
|
154
|
+
Custom presets are plain objects (`style`, `roles`, `variants`, `tokens`, `format`); see repo docs linked below.
|
|
491
155
|
|
|
492
156
|
## Tailwind CSS v4
|
|
493
157
|
|
|
@@ -496,59 +160,22 @@ Does not cover preset-only token names (e.g. shadcn's `--ring`). Use the CLI to
|
|
|
496
160
|
@import "hextimator/tailwind.css";
|
|
497
161
|
```
|
|
498
162
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
## Common recipes
|
|
502
|
-
|
|
503
|
-
### Inverted dark mode (accent as background)
|
|
504
|
-
|
|
505
|
-
```typescript
|
|
506
|
-
const theme = hextimate("#52FE8C")
|
|
507
|
-
.style({
|
|
508
|
-
surfaceColor: "#FEBA5D",
|
|
509
|
-
invertDarkModeSurfaceAccent: true,
|
|
510
|
-
})
|
|
511
|
-
.format({ as: "css" });
|
|
512
|
-
// Dark mode uses the accent hue as background, surface hue as accent
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
### shadcn/ui theme
|
|
516
|
-
|
|
517
|
-
```typescript
|
|
518
|
-
import { hextimate, presets } from "hextimator";
|
|
519
|
-
|
|
520
|
-
hextimate("#6366F1")
|
|
521
|
-
.preset(presets.shadcn)
|
|
522
|
-
.format();
|
|
523
|
-
// Generates all shadcn/ui tokens with proper naming
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
### Multi-tenant with `.fork()`
|
|
163
|
+
Registers utilities for built-in token names (`bg-accent`, etc.). Custom or preset-only names may need CLI-generated CSS.
|
|
527
164
|
|
|
528
|
-
|
|
529
|
-
const builder = hextimate("#52FE8C")
|
|
530
|
-
.style({ surfaceColor: "#FEBA5D" })
|
|
531
|
-
.addRole("banner", "#ff006e")
|
|
532
|
-
.addVariant("hover", { from: "strong" });
|
|
165
|
+
## Fallback before JS
|
|
533
166
|
|
|
534
|
-
|
|
535
|
-
|
|
167
|
+
```css
|
|
168
|
+
@import "hextimator/fallback.css";
|
|
536
169
|
```
|
|
537
170
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
```typescript
|
|
541
|
-
const normalTheme = hextimate("#ff6600");
|
|
542
|
-
const adaptedTheme = normalTheme.fork().adaptFor("deuteranopia");
|
|
543
|
-
const preview = normalTheme.fork().simulate("deuteranopia");
|
|
544
|
-
```
|
|
171
|
+
Neutral placeholders for **default** `hextimate()` variable names only. Does not cover preset-specific names (generate those with the CLI).
|
|
545
172
|
|
|
546
|
-
##
|
|
173
|
+
## Full reference (optional)
|
|
547
174
|
|
|
548
|
-
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md)
|
|
549
|
-
- [Customization
|
|
550
|
-
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md)
|
|
551
|
-
- [Color vision deficiency](https://github.com/fgrgic/hextimator/
|
|
552
|
-
- [React
|
|
553
|
-
- [Tailwind
|
|
554
|
-
- [
|
|
175
|
+
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md)
|
|
176
|
+
- [Customization (style & format)](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md)
|
|
177
|
+
- [Multiple themes / fork](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md)
|
|
178
|
+
- [Color vision deficiency](https://github.com/fgrgic/hextimator/docs/color-vision-deficiency.md)
|
|
179
|
+
- [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md)
|
|
180
|
+
- [Tailwind](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md)
|
|
181
|
+
- [Examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md)
|
package/package.json
CHANGED