hextimator 0.2.0 → 0.3.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 +31 -2
- package/README.md +83 -32
- package/dist/{HextimatePaletteBuilder-BOuHKcVE.d.ts → HextimatePaletteBuilder-xqJwP_G2.d.ts} +42 -26
- package/dist/{chunk-MBVLFPTG.js → chunk-2OMHLWID.js} +183 -88
- package/dist/cli.js +220 -120
- package/dist/index.d.ts +23 -26
- package/dist/index.js +1 -1
- package/dist/react.d.ts +33 -19
- package/dist/react.js +93 -46
- package/fallback.css +68 -80
- package/llms.txt +113 -21
- package/package.json +3 -3
package/llms.txt
CHANGED
|
@@ -24,15 +24,16 @@ const css = hextimate("#6A5ACD").format({ as: "css", colors: "oklch" });
|
|
|
24
24
|
|
|
25
25
|
## API
|
|
26
26
|
|
|
27
|
-
### `hextimate(color
|
|
27
|
+
### `hextimate(color)`
|
|
28
28
|
|
|
29
29
|
Creates a palette builder from any color input.
|
|
30
30
|
|
|
31
31
|
- `color`: `string` (hex, CSS function), `[r, g, b]` tuple, `number` (0xFF6666), or a `Color` object
|
|
32
|
-
- `options`: `HextimateGenerationOptions` (see below)
|
|
33
32
|
- Returns: `HextimatePaletteBuilder` (chainable)
|
|
34
33
|
- Throws: `HextimateError` on invalid input
|
|
35
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
|
+
|
|
36
37
|
### Builder methods (all return `this`, chainable)
|
|
37
38
|
|
|
38
39
|
| Method | Description |
|
|
@@ -40,10 +41,11 @@ Creates a palette builder from any color input.
|
|
|
40
41
|
| `.addRole(name, color)` | Add a new color role with DEFAULT, strong, weak, foreground variants |
|
|
41
42
|
| `.addVariant(name, placement)` | Add a lightness step to every role. `placement`: `{ from: "strong" }`, `{ from: "weak" }`, or `{ between: ["DEFAULT", "weak"] }` |
|
|
42
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) |
|
|
43
|
-
| `.preset(preset)` | Apply a
|
|
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 base palettes, and replay recorded operations |
|
|
44
46
|
| `.simulate(cvdType, severity?)` | Simulate color vision deficiency. Types: `protanopia`, `deuteranopia`, `tritanopia`, `achromatopsia` |
|
|
45
47
|
| `.adaptFor(cvdType, severity?)` | Optimize palette for a CVD type (use instead of simulate for actual accessibility) |
|
|
46
|
-
| `.fork(color
|
|
48
|
+
| `.fork(color?)` | Clone builder with optional new accent color. Chain `.style()` on the fork to change style options. Original unchanged |
|
|
47
49
|
| `.format(options?)` | Output the palette (see format options) |
|
|
48
50
|
|
|
49
51
|
### `.format(options?)` → `{ light: FormatResult, dark: FormatResult }`
|
|
@@ -55,6 +57,8 @@ Creates a palette builder from any color input.
|
|
|
55
57
|
| `roleNames` | `Record<string, string>` — rename roles in output keys | built-in names |
|
|
56
58
|
| `variantNames` | `Record<string, string>` — rename variant suffixes | built-in names |
|
|
57
59
|
| `separator` | `string` — between role and variant in keys | `"-"` |
|
|
60
|
+
| `excludeRoles` | `string[]` — role keys to omit entirely from output (by internal name, before `roleNames`) | `[]` |
|
|
61
|
+
| `excludeVariants` | `string[]` — variant keys to omit from every role's output (by internal name, before `variantNames`) | `[]` |
|
|
58
62
|
|
|
59
63
|
Output shape depends on `as`:
|
|
60
64
|
- `"object"` → `Record<string, string>` flat map: `{ accent: "#...", "accent-strong": "#..." }`
|
|
@@ -64,7 +68,7 @@ Output shape depends on `as`:
|
|
|
64
68
|
- `"scss"` → `Record<string, string>` flat map: `{ "$accent": "#...", "$accent-strong": "#..." }`
|
|
65
69
|
- `"json"` → JSON string
|
|
66
70
|
|
|
67
|
-
###
|
|
71
|
+
### Style options (`HextimateStyleOptions`)
|
|
68
72
|
|
|
69
73
|
| Option | Type | Default | Description |
|
|
70
74
|
|---|---|---|---|
|
|
@@ -92,24 +96,47 @@ Token keys: `accent`, `accent-strong`, `accent-weak`, `accent-foreground`, `base
|
|
|
92
96
|
|
|
93
97
|
### Presets
|
|
94
98
|
|
|
99
|
+
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.
|
|
100
|
+
|
|
101
|
+
**Available presets:**
|
|
102
|
+
|
|
103
|
+
| Preset | Type | Description |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `shadcn` | Framework | shadcn/ui tokens: --background, --primary, --destructive, --ring, etc. `as: "css"`, `colors: "oklch"` |
|
|
106
|
+
| `mui` | Framework | MUI theme: primary/secondary/error with main/light/dark/contrastText. `as: "object"`, `colors: "hex"` |
|
|
107
|
+
| `muted` | Style | Desaturated, restrained. Low chroma across the board |
|
|
108
|
+
| `vibrant` | Style | High saturation, complementary tinted neutrals, slight hue shift |
|
|
109
|
+
| `tinted` | Style | Neutrals pick up the accent hue for a cohesive feel |
|
|
110
|
+
|
|
95
111
|
```typescript
|
|
96
112
|
import { hextimate, presets } from "hextimator";
|
|
97
113
|
|
|
114
|
+
// Framework preset
|
|
115
|
+
const theme = hextimate("#6366F1")
|
|
116
|
+
.preset(presets.shadcn)
|
|
117
|
+
.format();
|
|
118
|
+
|
|
119
|
+
// Style + framework preset
|
|
98
120
|
const theme = hextimate("#6366F1")
|
|
121
|
+
.preset(presets.muted)
|
|
99
122
|
.preset(presets.shadcn)
|
|
100
123
|
.format();
|
|
101
124
|
|
|
102
125
|
// Override preset defaults:
|
|
103
126
|
const theme = hextimate("#6366F1")
|
|
127
|
+
.preset(presets.muted)
|
|
104
128
|
.preset(presets.shadcn)
|
|
105
129
|
.format({ colors: "hsl-raw" });
|
|
106
130
|
```
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
**Chaining merge rules:**
|
|
133
|
+
- Preset `style` / `.style()`: nested keys `light`, `dark`, `semanticColors`, `semanticColorRanges` shallow-merge per key; other keys overwrite (later wins)
|
|
134
|
+
- Roles, variants, tokens: concatenated (additive)
|
|
135
|
+
- Format options: deep-merged (roleNames/variantNames merged individually)
|
|
109
136
|
|
|
110
137
|
### Creating presets
|
|
111
138
|
|
|
112
|
-
A preset is a plain `HextimatePreset` object with optional fields for `
|
|
139
|
+
A preset is a plain `HextimatePreset` object with optional fields for `style`, `roles`, `variants`, `tokens`, and `format`. It configures the builder the same way chained methods would, but as a reusable data object.
|
|
113
140
|
|
|
114
141
|
```typescript
|
|
115
142
|
import type { HextimatePreset } from "hextimator";
|
|
@@ -119,7 +146,7 @@ import type { HextimatePreset } from "hextimator";
|
|
|
119
146
|
|
|
120
147
|
```typescript
|
|
121
148
|
interface HextimatePreset {
|
|
122
|
-
|
|
149
|
+
style?: HextimateStyleOptions; // contrast, lightness, chroma, hue shifts
|
|
123
150
|
roles?: Array<{ name: string; color: ColorInput | DerivedToken }>;
|
|
124
151
|
variants?: Array<{ name: string; placement: VariantPlacement }>;
|
|
125
152
|
tokens?: Array<{ name: string; value: TokenValue }>;
|
|
@@ -265,8 +292,10 @@ Both commands are identical. Use whichever you prefer.
|
|
|
265
292
|
| `-f, --format` | `css`, `object`, `tailwind`, `tailwind-css`, `scss`, `json` | `css` |
|
|
266
293
|
| `-c, --colors` | `hex`, `rgb`, `rgb-raw`, `hsl`, `hsl-raw`, `oklch`, `oklch-raw`, `p3`, `p3-raw` | `hex` |
|
|
267
294
|
| `-t, --theme` | `light`, `dark`, `both` | `both` |
|
|
268
|
-
| `-p, --preset` | Apply preset (
|
|
295
|
+
| `-p, --preset` | Apply preset (repeatable, applied in order): `shadcn`, `mui`, `muted`, `vibrant`, `tinted` | — |
|
|
269
296
|
| `--separator` | Token separator between role and variant | `-` |
|
|
297
|
+
| `--exclude-role` | Omit a role from output by internal name (repeatable) | — |
|
|
298
|
+
| `--exclude-variant` | Omit a variant from output by internal name (repeatable) | — |
|
|
270
299
|
| `--base-color` | Override base color | — |
|
|
271
300
|
| `--base-hue-shift` | Degrees | `0` |
|
|
272
301
|
| `--hue-shift` | Per-variant hue shift | `0` |
|
|
@@ -295,6 +324,9 @@ npx hextimator "#6A5ACD" --format css --colors oklch
|
|
|
295
324
|
# shadcn/ui preset
|
|
296
325
|
npx hextimator "#6366F1" --preset shadcn
|
|
297
326
|
|
|
327
|
+
# Chained presets: muted style + shadcn framework
|
|
328
|
+
npx hextimator "#6366F1" --preset muted --preset shadcn
|
|
329
|
+
|
|
298
330
|
# Invert base/accent in dark mode
|
|
299
331
|
npx hextimator "#6A5ACD" --base-color "#FEBA5D" --invert-dark
|
|
300
332
|
|
|
@@ -330,9 +362,10 @@ Hook options:
|
|
|
330
362
|
|
|
331
363
|
| Option | Type | Description |
|
|
332
364
|
|---|---|---|
|
|
333
|
-
| `
|
|
365
|
+
| `style` | `HextimateStyleOptions` | Palette style options |
|
|
366
|
+
| `presets` | `HextimatePreset[]` | Presets to apply in order (style + framework) |
|
|
334
367
|
| `format` | `Omit<HextimateFormatOptions, "as">` | Format options (output is always CSS vars) |
|
|
335
|
-
| `configure` | `(builder: HextimatePaletteBuilder) => void` | Customize the builder (add roles, tokens,
|
|
368
|
+
| `configure` | `(builder: HextimatePaletteBuilder) => void` | Customize the builder (add roles, tokens, etc.) |
|
|
336
369
|
| `darkMode` | `DarkModeStrategy` | Dark mode strategy (see above) |
|
|
337
370
|
| `cssPrefix` | `string` | Prefix for all CSS variable names |
|
|
338
371
|
| `target` | `RefObject<HTMLElement>` | Inject variables into a specific element instead of `:root` |
|
|
@@ -347,9 +380,9 @@ import { HextimatorProvider, useHextimatorTheme } from "hextimator/react";
|
|
|
347
380
|
<HextimatorProvider
|
|
348
381
|
defaultColor="#6A5ACD"
|
|
349
382
|
defaultMode="system" // "light" | "dark" | "system"
|
|
350
|
-
|
|
383
|
+
style={styleOpts}
|
|
384
|
+
presets={[presets.muted, presets.shadcn]}
|
|
351
385
|
format={formatOpts}
|
|
352
|
-
configure={(b) => b.preset(presets.shadcn)}
|
|
353
386
|
darkMode={{ type: "class" }}
|
|
354
387
|
cssPrefix="app"
|
|
355
388
|
target={containerRef}
|
|
@@ -368,11 +401,67 @@ import { HextimatorProvider, useHextimatorTheme } from "hextimator/react";
|
|
|
368
401
|
| `mode` | `"light" \| "dark"` | Resolved color mode (accounts for OS preference) |
|
|
369
402
|
| `modePreference` | `"light" \| "dark" \| "system"` | Raw preference before resolution |
|
|
370
403
|
| `setMode` | `(mode: ModePreference) => void` | Change mode preference |
|
|
371
|
-
| `
|
|
372
|
-
| `
|
|
404
|
+
| `style` | `HextimateStyleOptions \| undefined` | Current style options |
|
|
405
|
+
| `setStyle` | `(opts) => void` | Update style options |
|
|
406
|
+
| `presets` | `HextimatePreset[] \| undefined` | Current presets |
|
|
407
|
+
| `setPresets` | `(presets) => void` | Update presets (triggers re-generation) |
|
|
373
408
|
| `configure` | `((builder) => void) \| undefined` | Current builder configure function |
|
|
374
409
|
| `setConfigure` | `(fn) => void` | Update the configure callback |
|
|
375
410
|
|
|
411
|
+
### `HextimatorStyle`
|
|
412
|
+
|
|
413
|
+
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.
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
import { HextimatorStyle } from "hextimator/react";
|
|
417
|
+
|
|
418
|
+
// Global theme (SSR-safe)
|
|
419
|
+
<HextimatorStyle color="#ff6600" darkMode={{ type: "class" }} />
|
|
420
|
+
|
|
421
|
+
// Scoped to a specific subtree
|
|
422
|
+
<div className="card-a">
|
|
423
|
+
<HextimatorStyle color="#ff0066" selector=".card-a" />
|
|
424
|
+
...
|
|
425
|
+
</div>
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Props: same as `useHextimator` options, plus `selector?: string` (defaults to `:root`).
|
|
429
|
+
|
|
430
|
+
### `HextimatorScope`
|
|
431
|
+
|
|
432
|
+
Subtree theming with automatic shape inheritance. Wraps children in a scoped `<div>` with its own `<style>`. When nested inside a `HextimatorProvider` or another `HextimatorScope`, it inherits all custom roles, variants, tokens, and presets from the parent via `builder.fork()` -- you only need to pass the new color.
|
|
433
|
+
|
|
434
|
+
```tsx
|
|
435
|
+
import { HextimatorProvider, HextimatorScope } from "hextimator/react";
|
|
436
|
+
|
|
437
|
+
<HextimatorProvider
|
|
438
|
+
defaultColor="#ff6600"
|
|
439
|
+
presets={[presets.shadcn]}
|
|
440
|
+
darkMode={{ type: "class" }}
|
|
441
|
+
configure={(b) => b.addRole("cta", "#ff0066")}
|
|
442
|
+
>
|
|
443
|
+
<App>
|
|
444
|
+
{/* Inherits shadcn preset + cta role, just swaps color */}
|
|
445
|
+
<HextimatorScope defaultColor="#0066ff" darkMode={{ type: "class" }}>
|
|
446
|
+
<Card />
|
|
447
|
+
</HextimatorScope>
|
|
448
|
+
</App>
|
|
449
|
+
</HextimatorProvider>
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Props: `defaultColor`, `style?`, `presets?`, `format?`, `configure?`, `darkMode?`, `cssPrefix?`, `className?`, `wrapperStyle?` (inline styles for the scope element).
|
|
453
|
+
|
|
454
|
+
## `fallback.css`
|
|
455
|
+
|
|
456
|
+
Pre-JS placeholder: neutral values for the same variables as default `hextimate()` output. Use in client-rendered apps so the first paint has `--accent`, `--base`, etc. before the bundle runs. Runtime theme CSS then replaces them.
|
|
457
|
+
|
|
458
|
+
```css
|
|
459
|
+
@import "hextimator/fallback.css";
|
|
460
|
+
@import "hextimator/tailwind.css"; /* if using Tailwind */
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
Does not cover preset-only token names (e.g. shadcn's `--ring`). Use the CLI to generate a static file for those.
|
|
464
|
+
|
|
376
465
|
## Tailwind CSS v4
|
|
377
466
|
|
|
378
467
|
```css
|
|
@@ -387,10 +476,12 @@ This registers all built-in tokens as Tailwind utilities (`bg-accent`, `text-bas
|
|
|
387
476
|
### Inverted dark mode (accent as background)
|
|
388
477
|
|
|
389
478
|
```typescript
|
|
390
|
-
const theme = hextimate("#52FE8C"
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
479
|
+
const theme = hextimate("#52FE8C")
|
|
480
|
+
.style({
|
|
481
|
+
baseColor: "#FEBA5D",
|
|
482
|
+
invertDarkModeBaseAccent: true,
|
|
483
|
+
})
|
|
484
|
+
.format({ as: "css" });
|
|
394
485
|
// Dark mode uses the accent hue as background, base hue as accent
|
|
395
486
|
```
|
|
396
487
|
|
|
@@ -408,7 +499,8 @@ hextimate("#6366F1")
|
|
|
408
499
|
### Multi-tenant with `.fork()`
|
|
409
500
|
|
|
410
501
|
```typescript
|
|
411
|
-
const base = hextimate("#52FE8C"
|
|
502
|
+
const base = hextimate("#52FE8C")
|
|
503
|
+
.style({ baseColor: "#FEBA5D" })
|
|
412
504
|
.addRole("banner", "#ff006e")
|
|
413
505
|
.addVariant("hover", { from: "strong" });
|
|
414
506
|
|
|
@@ -427,7 +519,7 @@ const preview = normalTheme.fork().simulate("deuteranopia");
|
|
|
427
519
|
## Optional
|
|
428
520
|
|
|
429
521
|
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md): addRole, addVariant, addToken in depth
|
|
430
|
-
- [Customization reference](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md): all
|
|
522
|
+
- [Customization reference](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md): all style and format options
|
|
431
523
|
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md): .fork() and dynamic theming
|
|
432
524
|
- [Color vision deficiency](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/color-vision-deficiency.md): simulate and adaptFor
|
|
433
525
|
- [React docs](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md): hook, provider, dark mode strategies
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hextimator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Generate perceptually uniform color palettes with light/dark themes and WCAG contrast guarantees from a single brand color. Outputs CSS vars, Tailwind, SCSS, or JSON.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/react": "^19.2.7",
|
|
81
81
|
"@types/react-dom": "^19.2.3",
|
|
82
|
-
"react": "19.2.
|
|
83
|
-
"react-dom": "^19.2.
|
|
82
|
+
"react": "^19.2.0",
|
|
83
|
+
"react-dom": "^19.2.0",
|
|
84
84
|
"tsup": "^8.0.0",
|
|
85
85
|
"typescript": "^5.0.0"
|
|
86
86
|
}
|