hextimator 0.1.2 → 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 CHANGED
@@ -1,9 +1,45 @@
1
+ ## Not Released (0.3.0)
2
+
3
+ - [#99](https://github.com/fgrgic/hextimator/pull/99): Adds option to chain presets. Presets are merged, last added wins if both touch the same tokens.
4
+ - For example: `hextimate("#ff6677").preset(shadcn).preset(muted);`
5
+ - It also works with cli: `npx hextimate "#ff6677" -p shadcn -p vibrant`
6
+
7
+ - [#100](https://github.com/fgrgic/hextimator/pull/100): Adds `excludeRoles` and `excludeVariants` to `HextimateFormatOptions`, allowing presets and `.format()` calls to suppress auto-generated roles or variants they don't need. Also available in the CLI as `--exclude-role` and `--exclude-variant` (both repeatable). Applied to the `shadcn` and `mui` built-in presets to clean up their default output.
8
+
9
+ - [#101](https://github.com/fgrgic/hextimator/pull/101): **Breaking.** Palette tuning moves to `.style(partial)` on the builder instead of extra arguments on `hextimate` or `fork`. Presets and types use `style` instead of `generation`. In React the hook and provider follow that; `HextimatorScope` takes `wrapperStyle` for the wrapper div so `style` stays palette options.
10
+
11
+ ```ts
12
+ hextimate(c, o) → hextimate(c).style(o)
13
+ base.fork(c2, o) → base.fork(c2).style(o)
14
+ base.fork(o) → base.fork().style(o)
15
+ preset.generation → preset.style
16
+ HextimateGenerationOptions → HextimateStyleOptions
17
+ ```
18
+
19
+ ```tsx
20
+ <HextimatorProvider generation={o} /> → <HextimatorProvider style={o} />
21
+ useHextimatorTheme().setGeneration → useHextimatorTheme().setStyle
22
+ <HextimatorScope style={s} /> → <HextimatorScope wrapperStyle={s} />
23
+ ```
24
+
25
+ Migration checklist: [migrating-from-0.2.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migrating-from-0.2.md).
26
+
27
+ ## 0.2.0
28
+
29
+ - [#94](https://github.com/fgrgic/hextimator/pull/94): Adds scoped themes to React implementation. See [react.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) for more details:
30
+ - **`HextimatorStyle`**: renders theme CSS as a `<style>` in the tree (no `document.head` / `useEffect`); same options as the hook; optional `selector` for cascade scoping.
31
+ - **`HextimatorScope`**: `data-hextimator-scope` wrapper: Inherits palette shape from parent via **`builder.fork(color)`** (scope `style` merges with `.style()`); optional scope `configure` runs on top.
32
+ - [#95](https://github.com/fgrgic/hextimator/pull/95): Adds a `fallback.css` file that can be imported to have a theme before the JS loads. You could always manually do this, but this import provides an easier way to do so.
33
+
1
34
  ## 0.1.2
35
+
2
36
  - Add more context to `llms.txt`
3
37
  - Add `brand-exact` and `brand-exact-foreground` to `tailwind.css` file
4
38
 
5
39
  ## 0.1.1
40
+
6
41
  - Add `./cli` export for programmatic CLI access and `npx hextimate` shim
7
42
 
8
43
  ## 0.1.0
44
+
9
45
  - initial release
package/README.md CHANGED
@@ -10,8 +10,8 @@ One color in, whole theme out.
10
10
 
11
11
  Your customers pick a brand color. Your app looks good. Every time. No manual tuning, no edge cases where "that shade of yellow" breaks your UI.
12
12
 
13
- - **Ship white-labeling without the design overhead** — generate per-tenant branded themes at runtime from a single input color. No design review per customer.
14
- - **Every color just works** — perceptually uniform color science (OKLCH) means electric blue looks as balanced as muted olive. No hue gets special treatment.
13
+ - **Ship multi-tenant apps without the design overhead** — generate per-tenant branded themes at runtime from a single input color. No design review per customer.
14
+ - **Every color just works** — perceptually uniform colors with OKLCH means that electric blue looks as balanced as muted olive.
15
15
  - **Accessible by default** — every foreground meets AAA contrast against its background, light and dark mode included.
16
16
 
17
17
  **[hextimator.com](https://hextimator.com)** — try it in the playground.
@@ -27,7 +27,7 @@ npm i hextimator
27
27
  Or quickly get a one-off theme:
28
28
 
29
29
  ```bash
30
- npx hextimator "#ff6677"
30
+ npx hextimator "#C0FFEE"
31
31
  ```
32
32
 
33
33
  ## Quick start
@@ -35,41 +35,94 @@ npx hextimator "#ff6677"
35
35
  ```typescript
36
36
  import { hextimate } from "hextimator";
37
37
 
38
- const theme = hextimate("#6A5ACD").format();
38
+ const theme = hextimate("#C0FFEE").format();
39
39
  ```
40
40
 
41
- ### With a preset
41
+ ### With presets
42
42
 
43
- Presets configure hextimator for a specific framework in one call:
43
+ 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:
44
44
 
45
45
  ```typescript
46
46
  import { hextimate, presets } from "hextimator";
47
47
 
48
- // shadcn/ui — generates --background, --primary, --destructive, etc.
49
- const theme = hextimate("#6366F1")
48
+ // shadcn/ui tokens
49
+ const theme = hextimate("#0FF1CE").preset(presets.shadcn).format();
50
+
51
+ // muted palette
52
+ const theme = hextimate("#0FF1CE").preset(presets.muted).format();
53
+
54
+ // muted shadcn theme
55
+ const theme = hextimate("#0FF1CE")
50
56
  .preset(presets.shadcn)
57
+ .preset(presets.muted)
51
58
  .format();
52
59
  ```
53
60
 
54
- Presets set sensible defaults but you can override anything in `.format()`:
61
+ Presets are applied sequentially (last wins for conflicts) and you can override anything in `.format()`:
55
62
 
56
63
  ```typescript
57
- const theme = hextimate("#6366F1")
64
+ const theme = hextimate("#BADA55")
65
+ .preset(presets.muted)
58
66
  .preset(presets.shadcn)
59
- .format({ colors: "hsl-raw" }); // older shadcn format
67
+ .format({ colors: "hsl-raw" }); // override preset's oklch default
68
+ ```
69
+
70
+ ### Extending presets
71
+
72
+ 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:
73
+
74
+ ```typescript
75
+ const theme = hextimate("#DEC0DE")
76
+ .preset(presets.tinted) // e.g. sets a looser baseMaxChroma
77
+ .style({ baseMaxChroma: 0.01 }) // tighten further for this app
78
+ .preset(presets.shadcn)
79
+ .format();
60
80
  ```
61
81
 
62
- See [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md) for the full list and how to create your own.
82
+ 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.
63
83
 
64
84
  ## Two-step API: generate, then format
65
85
 
66
86
  hextimator separates **palette generation** (color math) from **formatting** (output shape). This lets you extend the palette before choosing how to serialize it.
67
87
 
68
88
  ```typescript
69
- const theme = hextimate("#6A5ACD")
70
- .format({ as: "css", colors: "oklch" });
89
+ const theme = hextimate("#0FF5E7").format({ as: "css", colors: "oklch" });
90
+ ```
91
+
92
+ ### Palette options with `.style()`
93
+
94
+ **`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).
95
+
96
+ ```typescript
97
+ hextimate("#FACADE")
98
+ .style({ minContrastRatio: "AA", baseMaxChroma: 0.02 })
99
+ .format();
100
+ ```
101
+
102
+ Preset **`style`** plus **`.style()`** on the builder is covered in [Extending presets](#extending-presets) above. For every option you can pass, see [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md). To reuse the same chain with another accent or options, see [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md) (`.fork()` + `.style()`).
103
+
104
+ ### Filtering output
105
+
106
+ Use `excludeRoles` and `excludeVariants` in `.format()` (or in a preset's `format` field) to drop tokens you don't need:
107
+
108
+ ```typescript
109
+ // Drop the warning role and the strong/weak variants entirely
110
+ hextimate("#F11732").format({
111
+ excludeRoles: ["warning"],
112
+ excludeVariants: ["strong", "weak"],
113
+ });
114
+
115
+ // Useful in custom presets to keep output tight
116
+ const myPreset: HextimatePreset = {
117
+ format: {
118
+ excludeRoles: ["warning"],
119
+ excludeVariants: ["strong", "weak"],
120
+ },
121
+ };
71
122
  ```
72
123
 
124
+ Both options use internal names (before any `roleNames`/`variantNames` remapping).
125
+
73
126
  ### Output formats
74
127
 
75
128
  All formats return `{ light: { ... }, dark: { ... } }`.
@@ -83,29 +136,26 @@ All formats return `{ light: { ... }, dark: { ... } }`.
83
136
 
84
137
  ### Color value formats
85
138
 
86
- | `colors` | Example output |
87
- |---|---|
88
- | `"hex"` (default) | `"#6a5acd"` |
89
- | `"oklch"` | `"oklch(0.54 0.18 276)"` |
90
- | `"oklch-raw"` | `"0.54 0.18 276"` |
91
- | `"rgb"` | `"rgb(106, 90, 205)"` |
92
- | `"rgb-raw"` | `"106 90 205"` |
93
- | `"hsl"` | `"hsl(248, 53%, 58%)"` |
94
- | `"hsl-raw"` | `"248 53% 58%"` |
95
- | `"p3"` | `"color(display-p3 0.39 0.34 0.79)"` |
96
- | `"p3-raw"` | `"0.39 0.34 0.79"` |
139
+ | `colors` | Example output |
140
+ | ----------------- | ------------------------------------ |
141
+ | `"hex"` (default) | `"#6a5acd"` |
142
+ | `"oklch"` | `"oklch(0.54 0.18 276)"` |
143
+ | `"oklch-raw"` | `"0.54 0.18 276"` |
144
+ | `"rgb"` | `"rgb(106, 90, 205)"` |
145
+ | `"rgb-raw"` | `"106 90 205"` |
146
+ | `"hsl"` | `"hsl(248, 53%, 58%)"` |
147
+ | `"hsl-raw"` | `"248 53% 58%"` |
148
+ | `"p3"` | `"color(display-p3 0.39 0.34 0.79)"` |
149
+ | `"p3-raw"` | `"0.39 0.34 0.79"` |
97
150
 
98
151
  ### Flexible input
99
152
 
100
- ```typescript
101
- hextimate("#FF6666"); // hex string
102
- hextimate("rgb(255, 102, 102)"); // CSS function
103
- hextimate([255, 102, 102]); // RGB tuple
104
- hextimate(0xff6666); // numeric hex
105
- ```
153
+ Besides hex, **`hextimate`** accepts CSS color strings, RGB tuples, and numeric `0xRRGGBB`—anything **`parseColor`** understands.
106
154
 
107
155
  > **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.
108
156
 
157
+ 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).
158
+
109
159
  ## How it works
110
160
 
111
161
  1. **Parse** any color input into a normalized `Color` object.
@@ -125,14 +175,36 @@ const color = parseColor("rgb(255, 102, 102)");
125
175
  const oklch = convertColor(color, "oklch");
126
176
  ```
127
177
 
178
+ ## React
179
+
180
+ Import from `hextimator/react`:
181
+
182
+ - **`HextimatorProvider`** and **`useHextimatorTheme()`** — context for color, dark mode, palette, and builder configuration; the provider injects CSS via `useHextimator` internally.
183
+ - **`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).
184
+ - **`HextimatorScope`** — subtree theming and nested context; **inherits** custom shape from the parent **`builder`** via **`fork()`**.
185
+
186
+ See **[React (full guide)](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md)** for dark mode strategies, examples, and API tables.
187
+
188
+ ### `fallback.css`
189
+
190
+ Pre-JS placeholder: neutral values for the same variables as default `hextimate()` (and `hextimator/tailwind.css`). Use in **client-rendered** apps so the first paint is not missing `--accent`, `--base`, etc. before your bundle runs; runtime theme CSS then replaces them. Import **before** `tailwind.css` if you use it.
191
+
192
+ ```css
193
+ @import "hextimator/fallback.css";
194
+ @import "hextimator/tailwind.css";
195
+ ```
196
+
197
+ Does not match **preset-only** token names (e.g. shadcn); use the CLI to generate a static file for those.
198
+
128
199
  ## Documentation
129
200
 
201
+ - [Migrating from 0.2.x](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migrating-from-0.2.md) — breaking changes for 0.3.0
130
202
  - [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) — `addRole`, `addVariant`, `addToken`
131
203
  - [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md) — drop-in configs for shadcn/ui, or create your own
132
204
  - [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md) — dynamic theming and `.fork()`
133
- - [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — generation and format options reference
205
+ - [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — style and format options reference
134
206
  - [Color vision deficiency](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/color-vision-deficiency.md) — simulate and adapt for CVD
135
- - [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — `useHextimator` hook, provider, dark mode strategies
207
+ - [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — hook, `HextimatorStyle`, provider, scoped themes, dark mode
136
208
  - [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md) — setup and usage with Tailwind
137
209
  - [Real-world examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md) — shadcn/ui, Stripe, Slack configurations
138
210
 
@@ -106,9 +106,9 @@ interface ThemeAdjustments {
106
106
  foregroundMaxChroma?: number;
107
107
  }
108
108
  /**
109
- * Options that affect color generation (the math)
109
+ * Options that control how the palette is generated from the input color.
110
110
  */
111
- interface HextimateGenerationOptions {
111
+ interface HextimateStyleOptions {
112
112
  /**
113
113
  * Preferred base color for dark and light mode.
114
114
  * It will be used as a baseline to generate the rest of base colors (strong, weak).
@@ -272,12 +272,26 @@ interface HextimateFormatOptions {
272
272
  * - "rgb-raw" → "242 238 232"
273
273
  */
274
274
  colors?: ColorFormat;
275
+ /**
276
+ * Role keys to omit from the output entirely.
277
+ * Uses the internal role name (before any `roleNames` remapping).
278
+ *
279
+ * Example: `['warning']` removes the warning scale from the output.
280
+ */
281
+ excludeRoles?: string[];
282
+ /**
283
+ * Variant keys to omit from every role's output.
284
+ * Uses the internal variant name (before any `variantNames` remapping).
285
+ *
286
+ * Example: `['strong', 'weak']` removes those variants from all roles.
287
+ */
288
+ excludeVariants?: string[];
275
289
  }
276
290
  /**
277
291
  * Combined options for the convenience API.
278
- * Allows passing both generation and format options in one call.
292
+ * Allows passing both style and format options in one call.
279
293
  */
280
- type HextimateOptions = HextimateGenerationOptions & HextimateFormatOptions;
294
+ type HextimateOptions = HextimateStyleOptions & HextimateFormatOptions;
281
295
  /** How color values are serialized in the output (e.g. "hex", "rgb", "oklch", "hsl", "p3", and their "-raw" variants). */
282
296
  type ColorFormat = 'hex' | 'hsl' | 'hsl-raw' | 'oklch' | 'oklch-raw' | 'p3' | 'p3-raw' | 'rgb' | 'rgb-raw';
283
297
 
@@ -301,8 +315,8 @@ type FormatResult = FlatTokenMap | NestedTokenMap | string;
301
315
  * .format();
302
316
  */
303
317
  interface HextimatePreset {
304
- /** Generation options (contrast, hue shifts, lightness, chroma). Applied before roles/variants/tokens. */
305
- generation?: HextimateGenerationOptions;
318
+ /** Style options (contrast, hue shifts, lightness, chroma). Applied before roles/variants/tokens. */
319
+ style?: HextimateStyleOptions;
306
320
  /** Extra roles to add to the palette (each generates DEFAULT, strong, weak, foreground variants). */
307
321
  roles?: Array<{
308
322
  name: string;
@@ -374,25 +388,26 @@ type TokenValue = ColorInput | DerivedToken | {
374
388
  light: DerivedToken | ColorInput;
375
389
  dark: DerivedToken | ColorInput;
376
390
  };
377
- /**
378
- * Palette builder.
379
- *
380
- * Supports adding roles, variants, and standalone tokens, as well as simulating and adapting for CVD.
381
- * All operations are recorded and replayed in order on fork, ensuring consistent results.
382
- * The internal palette is stored in a raw form with OKLCH color objects, allowing for precise adjustments and transformations.
383
- */
384
391
  declare class HextimatePaletteBuilder {
385
392
  private lightPalette;
386
393
  private darkPalette;
387
394
  private readonly inputColor;
388
- private readonly options;
395
+ private options;
389
396
  private readonly operations;
390
397
  private readonly standaloneTokens;
391
398
  private readonly weakSideVariants;
392
399
  private readonly strongSideVariants;
393
400
  private readonly betweenVariants;
394
401
  private presetFormatDefaults?;
395
- constructor(color: Color, options?: HextimateGenerationOptions);
402
+ constructor(color: Color);
403
+ /**
404
+ * Merges style options into the builder and regenerates the base palettes,
405
+ * then replays recorded operations so roles and variants reflect the new style.
406
+ */
407
+ style(partial: Partial<HextimateStyleOptions>): this;
408
+ private seedOptionsForFork;
409
+ private rebuildFromOperations;
410
+ private replayOperationInPlace;
396
411
  /**
397
412
  * Adds a custom role with given name and color.
398
413
  * The color is expanded into a full scale and added to both light and dark palettes.
@@ -450,6 +465,13 @@ declare class HextimatePaletteBuilder {
450
465
  * .format({ colors: 'hsl-raw' });
451
466
  */
452
467
  preset(preset: HextimatePreset): this;
468
+ /**
469
+ * Records a preset in the operation log and applies roles, variants, tokens, and format.
470
+ * Does not merge `preset.style` — used when replaying onto a builder whose `this.options` already reflect merged style.
471
+ */
472
+ private recordPresetWithoutStyleMerge;
473
+ /** Roles, variants, tokens, and format only — `this.options` and base palettes are already correct. */
474
+ private applyPresetRolesTokensFormat;
453
475
  /**
454
476
  *
455
477
  * Simulates how the palette would look for a given type and severity of CVD.
@@ -483,18 +505,12 @@ declare class HextimatePaletteBuilder {
483
505
  */
484
506
  adaptFor(type: CVDType, severity?: number): this;
485
507
  /**
486
- * Creates a new builder instance with the same operations history, allowing you to generate a related palette with a different base color or options.
487
- *
488
- * e.g. `fork('#ff6677')` creates a new builder with the same
489
- * roles, variants, tokens, and adjustments, but based on a different input color.
490
- *
491
- * `fork({ light: { lightness: 0.8 } })` creates a new builder with the same color but different light theme adjustments.
508
+ * Creates a new builder instance with the same operations history, optionally from a different base color.
509
+ * To change style options on the fork, chain `.style()` after `.fork()`.
492
510
  *
493
- * @param colorOrOptions Either a new base color for the palette, or an object with new generation options to override (e.g. light/dark adjustments, hue shift, contrast ratio).
494
- * @param maybeOptions If the first argument is a color, this can be an optional second argument with generation options to override.
495
- * @returns A new builder instance with the same operations history but different base color and/or options.
511
+ * @param color Optional new accent/brand color. If omitted, the fork uses the same color as this builder.
496
512
  */
497
- fork(colorOrOptions?: ColorInput | Partial<HextimateGenerationOptions>, maybeOptions?: Partial<HextimateGenerationOptions>): HextimatePaletteBuilder;
513
+ fork(color?: ColorInput): HextimatePaletteBuilder;
498
514
  /**
499
515
  * Serializes the palette into the chosen output format.
500
516
  *
@@ -537,4 +553,4 @@ declare class HextimatePaletteBuilder {
537
553
  private resolvedOptions;
538
554
  }
539
555
 
540
- export { type Color as C, type DerivedToken as D, type FlatTokenMap as F, type HextimatePreset as H, type NestedTokenMap as N, type OKLCH as O, type ThemeAdjustments as T, type VariantPlacement as V, type CVDType as a, type ColorSpace as b, type ColorInSpace as c, type ColorInput as d, type HextimateGenerationOptions as e, HextimatePaletteBuilder as f, type FormatResult as g, type HextimateFormatOptions as h, type HextimateOptions as i, type HextimateResult as j, type TokenValue as k };
556
+ export { type Color as C, type DerivedToken as D, type FlatTokenMap as F, type HextimatePreset as H, type NestedTokenMap as N, type OKLCH as O, type ThemeAdjustments as T, type VariantPlacement as V, type CVDType as a, type ColorSpace as b, type ColorInSpace as c, type ColorInput as d, HextimatePaletteBuilder as e, type FormatResult as f, type HextimateFormatOptions as g, type HextimateOptions as h, type HextimateResult as i, type HextimateStyleOptions as j, type TokenValue as k };