hextimator 0.1.1 → 0.2.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,5 +1,16 @@
1
+ ## 0.2.0
2
+ - [#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:
3
+ - **`HextimatorStyle`**: renders theme CSS as a `<style>` in the tree (no `document.head` / `useEffect`); same options as the hook; optional `selector` for cascade scoping.
4
+ - **`HextimatorScope`**: `data-hextimator-scope` wrapper: Inherits palette shape from parent via **`builder.fork(color, generation)`**; optional scope `configure` runs on top.
5
+ - [#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.
6
+
7
+
8
+ ## 0.1.2
9
+ - Add more context to `llms.txt`
10
+ - Add `brand-exact` and `brand-exact-foreground` to `tailwind.css` file
11
+
1
12
  ## 0.1.1
2
13
  - Add `./cli` export for programmatic CLI access and `npx hextimate` shim
3
14
 
4
15
  ## 0.1.0
5
- - initial release
16
+ - initial release
package/README.md CHANGED
@@ -6,11 +6,15 @@
6
6
  </picture>
7
7
  </p>
8
8
 
9
- One brand color in, full accessible theme out.
9
+ One color in, whole theme out.
10
10
 
11
- - Input: any single color. Output: complete light + dark theme with accessibility guarantees (AAA contrast by default).
12
- - Works at runtime — built for multi-tenant apps that need per-brand themes on the fly.
13
- - Perceptually uniform (OKLCH) — blue and yellow palettes look equally balanced, unlike HSL-based generators.
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
+
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.
15
+ - **Accessible by default** — every foreground meets AAA contrast against its background, light and dark mode included.
16
+
17
+ **[hextimator.com](https://hextimator.com)** — try it in the playground.
14
18
 
15
19
  ## Installation
16
20
 
@@ -121,6 +125,27 @@ const color = parseColor("rgb(255, 102, 102)");
121
125
  const oklch = convertColor(color, "oklch");
122
126
  ```
123
127
 
128
+ ## React
129
+
130
+ Import from `hextimator/react`:
131
+
132
+ - **`HextimatorProvider`** and **`useHextimatorTheme()`** — context for color, dark mode, palette, and builder configuration; the provider injects CSS via `useHextimator` internally.
133
+ - **`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).
134
+ - **`HextimatorScope`** — subtree theming and nested context; **inherits** custom shape from the parent **`builder`** via **`fork()`**.
135
+
136
+ See **[React (full guide)](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md)** for dark mode strategies, examples, and API tables.
137
+
138
+ ### `fallback.css`
139
+
140
+ 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.
141
+
142
+ ```css
143
+ @import "hextimator/fallback.css";
144
+ @import "hextimator/tailwind.css";
145
+ ```
146
+
147
+ Does not match **preset-only** token names (e.g. shadcn); use the CLI to generate a static file for those.
148
+
124
149
  ## Documentation
125
150
 
126
151
  - [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) — `addRole`, `addVariant`, `addToken`
@@ -128,7 +153,7 @@ const oklch = convertColor(color, "oklch");
128
153
  - [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md) — dynamic theming and `.fork()`
129
154
  - [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — generation and format options reference
130
155
  - [Color vision deficiency](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/color-vision-deficiency.md) — simulate and adapt for CVD
131
- - [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — `useHextimator` hook, provider, dark mode strategies
156
+ - [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — hook, `HextimatorStyle`, provider, scoped themes, dark mode
132
157
  - [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md) — setup and usage with Tailwind
133
158
  - [Real-world examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md) — shadcn/ui, Stripe, Slack configurations
134
159
 
@@ -149,9 +149,9 @@ interface HextimateGenerationOptions {
149
149
  * Degree ranges for the semantic colors.
150
150
  * Determines where to look for "green", "red", "yellow" in the color space.
151
151
  * If not provided, the default ranges will be used:
152
- * - positive: [90, 150] greens
153
- * - negative: [345, 15] reds
154
- * - warning: [35, 55] ambers
152
+ * - positive: [135, 160] greens
153
+ * - negative: [5, 25] reds
154
+ * - warning: [45, 65] ambers
155
155
  */
156
156
  semanticColorRanges?: {
157
157
  positive?: [number, number];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Color, a as CVDType, O as OKLCH, b as ColorSpace, c as ColorInSpace, d as ColorInput, H as HextimatePreset, e as HextimateGenerationOptions, f as HextimatePaletteBuilder } from './HextimatePaletteBuilder-BzrgFryu.js';
2
- export { D as DerivedToken, F as FlatTokenMap, g as FormatResult, h as HextimateFormatOptions, i as HextimateOptions, j as HextimateResult, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-BzrgFryu.js';
1
+ import { C as Color, a as CVDType, O as OKLCH, b as ColorSpace, c as ColorInSpace, d as ColorInput, H as HextimatePreset, e as HextimateGenerationOptions, f as HextimatePaletteBuilder } from './HextimatePaletteBuilder-BOuHKcVE.js';
2
+ export { D as DerivedToken, F as FlatTokenMap, g as FormatResult, h as HextimateFormatOptions, i as HextimateOptions, j as HextimateResult, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-BOuHKcVE.js';
3
3
 
4
4
  /**
5
5
  * Daltonize a color for a specific type of color vision deficiency (CVD).
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { e as HextimateGenerationOptions, f as HextimatePaletteBuilder, j as HextimateResult, h as HextimateFormatOptions, F as FlatTokenMap } from './HextimatePaletteBuilder-BOuHKcVE.js';
1
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { e as HextimateGenerationOptions, f as HextimatePaletteBuilder, j as HextimateResult, h as HextimateFormatOptions, F as FlatTokenMap } from './HextimatePaletteBuilder-BzrgFryu.js';
3
- import { PropsWithChildren } from 'react';
3
+ import { PropsWithChildren, RefObject, CSSProperties, ReactNode } from 'react';
4
4
 
5
5
  type DarkModeStrategy = {
6
6
  type: 'class';
@@ -14,44 +14,28 @@ type DarkModeStrategy = {
14
14
  type: 'media-or-class';
15
15
  className?: string;
16
16
  } | false;
17
- /**
18
- * Options for the `useHextimator` hook, which generates a color palette and injects CSS variables based on a given color and configuration.
19
- * - `generation`: Options for how the palette is generated (e.g., light/dark settings, contrast requirements).
20
- * - `format`: Options for how the generated palette is formatted (e.g., output format).
21
- * - `configure`: A callback to further customize the palette builder before formatting.
22
- * - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
23
- * - `cssPrefix`: A prefix to apply to all generated CSS variable names.
24
- * - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
25
- *
26
- */
27
- interface UseHextimatorOptions {
28
- generation?: HextimateGenerationOptions;
29
- format?: Omit<HextimateFormatOptions, 'as'>;
30
- configure?: (builder: HextimatePaletteBuilder) => void;
31
- darkMode?: DarkModeStrategy;
32
- cssPrefix?: string;
33
- target?: React.RefObject<HTMLElement | null>;
34
- }
35
- /**
36
- * Generates a color palette based on the provided color and options,
37
- * and injects CSS variables into the document for use in styling.
38
- * The palette is regenerated whenever the input color or relevant options change.
39
- *
40
- * Example usage:
41
- * ```tsx
42
- * const palette = useHextimator('#ff6600', {
43
- * generation: { minContrastRatio: 'AA' },
44
- * darkMode: { type: 'class', className: 'dark' },
45
- * cssPrefix: '--myapp-',
46
- * });
47
- * ```
48
- *
49
- * @param color - The base color to generate the palette from.
50
- * @param options - Configuration options for palette generation, formatting, and CSS variable injection.
51
- */
52
- declare function useHextimator(color: string, options?: UseHextimatorOptions): HextimateResult<FlatTokenMap>;
53
17
  type ModePreference = 'light' | 'dark' | 'system';
54
18
  type ResolvedMode = 'light' | 'dark';
19
+
20
+ interface HextimatorContextValue {
21
+ color: string;
22
+ setColor: (color: string) => void;
23
+ mode: ResolvedMode;
24
+ modePreference: ModePreference;
25
+ setMode: (mode: ModePreference) => void;
26
+ generation: HextimateGenerationOptions | undefined;
27
+ setGeneration: (opts: HextimateGenerationOptions | undefined) => void;
28
+ configure: ((builder: HextimatePaletteBuilder) => void) | undefined;
29
+ setConfigure: (fn: ((builder: HextimatePaletteBuilder) => void) | undefined) => void;
30
+ palette: HextimateResult;
31
+ /**
32
+ * The palette builder backing this provider or scope. Nested
33
+ * `HextimatorScope`s fork from this builder so they inherit any custom
34
+ * roles, variants, tokens, or presets without re-declaring them.
35
+ */
36
+ builder: HextimatePaletteBuilder;
37
+ }
38
+
55
39
  /**
56
40
  * Props for the `HextimatorProvider` component, which manages the state of a Hextimator-generated color palette and injects corresponding CSS variables into the document.
57
41
  * - `defaultColor`: The initial base color to generate the palette from.
@@ -70,19 +54,7 @@ interface HextimatorProviderProps {
70
54
  configure?: (builder: HextimatePaletteBuilder) => void;
71
55
  darkMode?: DarkModeStrategy;
72
56
  cssPrefix?: string;
73
- target?: React.RefObject<HTMLElement | null>;
74
- }
75
- interface HextimatorContextValue {
76
- color: string;
77
- setColor: (color: string) => void;
78
- mode: ResolvedMode;
79
- modePreference: ModePreference;
80
- setMode: (mode: ModePreference) => void;
81
- generation: HextimateGenerationOptions | undefined;
82
- setGeneration: (opts: HextimateGenerationOptions | undefined) => void;
83
- configure: ((builder: HextimatePaletteBuilder) => void) | undefined;
84
- setConfigure: (fn: ((builder: HextimatePaletteBuilder) => void) | undefined) => void;
85
- palette: HextimateResult;
57
+ target?: RefObject<HTMLElement | null>;
86
58
  }
87
59
  /**
88
60
  *
@@ -104,11 +76,158 @@ interface HextimatorContextValue {
104
76
  * ```
105
77
  */
106
78
  declare function HextimatorProvider({ children, defaultColor, defaultMode: initialMode, generation: initialGeneration, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
79
+
80
+ /**
81
+ * Props for `HextimatorScope`, a wrapper that creates a scoped theme for its
82
+ * descendants via CSS cascade and React context.
83
+ *
84
+ * Unlike `HextimatorProvider` (which themes the whole document root),
85
+ * `HextimatorScope` themes only its subtree. Scopes can nest freely, and the
86
+ * nearest `HextimatorScope` or `HextimatorProvider` wins for
87
+ * `useHextimatorTheme()`.
88
+ *
89
+ * Mode (light/dark) is inherited from the nearest parent context when present,
90
+ * so a scope automatically follows the app's global dark-mode toggle. If you
91
+ * pass `darkMode` explicitly, make sure it matches the strategy your root
92
+ * `HextimatorProvider` uses (class, data, media, etc.) so the dark selectors
93
+ * line up.
94
+ */
95
+ interface HextimatorScopeProps {
96
+ defaultColor: string;
97
+ generation?: HextimateGenerationOptions;
98
+ format?: Omit<HextimateFormatOptions, 'as'>;
99
+ configure?: (builder: HextimatePaletteBuilder) => void;
100
+ darkMode?: DarkModeStrategy;
101
+ cssPrefix?: string;
102
+ className?: string;
103
+ style?: CSSProperties;
104
+ children?: ReactNode;
105
+ }
106
+ /**
107
+ * Scoped theme wrapper. Auto-generates a unique selector via `useId()`, wraps
108
+ * children in a `<div data-hextimator-scope={id}>`, and emits a scoped
109
+ * `<style>` with the generated palette. Also pushes a nested
110
+ * `HextimatorContext` so `useHextimatorTheme()` called from inside the wrapper
111
+ * returns the scope's palette and color state, not the root provider's.
112
+ *
113
+ * When nested inside a `HextimatorProvider` or another `HextimatorScope`, the
114
+ * scope inherits all custom roles, variants, tokens, and presets from its
115
+ * parent by forking the parent's builder — so you only pass the new color.
116
+ * Any per-scope `configure` callback is applied on top of the inherited shape.
117
+ *
118
+ * @example
119
+ * ```tsx
120
+ * // Root provider defines the theme shape once
121
+ * <HextimatorProvider
122
+ * defaultColor="#ff6600"
123
+ * darkMode={{ type: 'class' }}
124
+ * configure={(b) => b
125
+ * .addRole('cta', '#ff0066')
126
+ * .addVariant('hover', { from: 'strong' })
127
+ * }
128
+ * >
129
+ * <App>
130
+ * // Scope inherits cta + hover, just swaps the base color
131
+ * <HextimatorScope defaultColor="#0066ff" darkMode={{ type: 'class' }}>
132
+ * <Card />
133
+ * </HextimatorScope>
134
+ * </App>
135
+ * </HextimatorProvider>
136
+ * ```
137
+ */
138
+ declare function HextimatorScope({ defaultColor, generation: initialGeneration, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, className, style, children, }: HextimatorScopeProps): react_jsx_runtime.JSX.Element;
139
+
140
+ /**
141
+ * Props for the `HextimatorStyle` component, a declarative alternative to
142
+ * `useHextimator` that renders a `<style>` element with the generated CSS
143
+ * variables directly into React's tree.
144
+ *
145
+ * Unlike the hook, this works during SSR/RSC (no `useEffect`, no manual
146
+ * cleanup), and supports scoping the palette to a specific selector so
147
+ * multiple subtrees can carry different themes via CSS cascade.
148
+ *
149
+ * - `color`: The base color to generate the palette from.
150
+ * - `generation`: Options for how the palette is generated.
151
+ * - `format`: Options for how the generated palette is formatted.
152
+ * - `configure`: A callback to further customize the palette builder before formatting.
153
+ * - `darkMode`: Strategy for handling dark mode variants.
154
+ * - `cssPrefix`: A prefix applied to all generated CSS variable names.
155
+ * - `selector`: CSS selector the variables are scoped to. Defaults to `:root`.
156
+ */
157
+ interface HextimatorStyleProps {
158
+ color: string;
159
+ generation?: HextimateGenerationOptions;
160
+ format?: Omit<HextimateFormatOptions, 'as'>;
161
+ configure?: (builder: HextimatePaletteBuilder) => void;
162
+ darkMode?: DarkModeStrategy;
163
+ cssPrefix?: string;
164
+ selector?: string;
165
+ }
166
+ /**
167
+ * Declarative alternative to `useHextimator`. Renders a `<style>` element
168
+ * carrying the generated CSS variables, so the palette works during SSR/RSC
169
+ * and can be scoped to any selector for per-subtree theming.
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * // Global theme (equivalent to the hook, but SSR-safe)
174
+ * <HextimatorStyle color="#ff6600" darkMode={{ type: 'class' }} />
175
+ *
176
+ * // Per-subtree theme via CSS cascade
177
+ * <div className="card-a">
178
+ * <HextimatorStyle color="#ff0066" selector=".card-a" />
179
+ * ...
180
+ * </div>
181
+ * ```
182
+ */
183
+ declare function HextimatorStyle({ color, generation, format: formatOpts, configure, darkMode, cssPrefix, selector, }: HextimatorStyleProps): react_jsx_runtime.JSX.Element;
184
+
185
+ /**
186
+ * Options for the `useHextimator` hook, which generates a color palette and injects CSS variables based on a given color and configuration.
187
+ * - `generation`: Options for how the palette is generated (e.g., light/dark settings, contrast requirements).
188
+ * - `format`: Options for how the generated palette is formatted (e.g., output format).
189
+ * - `configure`: A callback to further customize the palette builder before formatting.
190
+ * - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
191
+ * - `cssPrefix`: A prefix to apply to all generated CSS variable names.
192
+ * - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
193
+ *
194
+ */
195
+ interface UseHextimatorOptions {
196
+ generation?: HextimateGenerationOptions;
197
+ format?: Omit<HextimateFormatOptions, 'as'>;
198
+ configure?: (builder: HextimatePaletteBuilder) => void;
199
+ darkMode?: DarkModeStrategy;
200
+ cssPrefix?: string;
201
+ target?: RefObject<HTMLElement | null>;
202
+ }
203
+
204
+ /**
205
+ * Generates a color palette based on the provided color and options,
206
+ * and injects CSS variables into the document for use in styling.
207
+ * The palette is regenerated whenever the input color or relevant options change.
208
+ *
209
+ * Example usage:
210
+ * ```tsx
211
+ * const palette = useHextimator('#ff6600', {
212
+ * generation: { minContrastRatio: 'AA' },
213
+ * darkMode: { type: 'class', className: 'dark' },
214
+ * cssPrefix: '--myapp-',
215
+ * });
216
+ * ```
217
+ *
218
+ * @param color - The base color to generate the palette from.
219
+ * @param options - Configuration options for palette generation, formatting, and CSS variable injection.
220
+ */
221
+ declare function useHextimator(color: string, options?: UseHextimatorOptions): HextimateResult<FlatTokenMap>;
222
+
107
223
  /**
108
- * Provides access to the current Hextimator palette and theme state from the nearest `HextimatorProvider`.
224
+ * Provides access to the current Hextimator palette and theme state from the
225
+ * nearest `HextimatorProvider` or `HextimatorScope`. When called from inside a
226
+ * `HextimatorScope`, returns the scope's palette and `color`/`setColor` state;
227
+ * `mode` and `setMode` are inherited from the nearest enclosing provider.
109
228
  *
110
229
  * Returned properties:
111
- * - `color` / `setColor` — the current base color.
230
+ * - `color` / `setColor` — the current base color for this scope or provider.
112
231
  * - `mode` — the resolved color mode (`'light'` or `'dark'`), accounting for OS preference when set to `'system'`.
113
232
  * - `modePreference` — the raw preference (`'light'`, `'dark'`, or `'system'`).
114
233
  * - `setMode` — update the mode preference. Pass `'system'` to follow the OS.
@@ -125,8 +244,8 @@ declare function HextimatorProvider({ children, defaultColor, defaultMode: initi
125
244
  * </button>
126
245
  * ```
127
246
  *
128
- * @throws If used outside of a `HextimatorProvider`.
247
+ * @throws If used outside of a `HextimatorProvider` or `HextimatorScope`.
129
248
  */
130
249
  declare function useHextimatorTheme(): HextimatorContextValue;
131
250
 
132
- export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };
251
+ export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, HextimatorScope, type HextimatorScopeProps, HextimatorStyle, type HextimatorStyleProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };