hextimator 0.1.2 → 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 +7 -0
- package/README.md +22 -1
- package/dist/react.d.ts +174 -55
- package/dist/react.js +237 -63
- package/fallback.css +86 -0
- package/package.json +9 -4
- package/dist/HextimatePaletteBuilder-BOuHKcVE.d.mts +0 -540
- package/dist/index.d.mts +0 -168
- package/dist/react.d.mts +0 -132
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## 0.1.2
|
|
2
9
|
- Add more context to `llms.txt`
|
|
3
10
|
- Add `brand-exact` and `brand-exact-foreground` to `tailwind.css` file
|
package/README.md
CHANGED
|
@@ -125,6 +125,27 @@ const color = parseColor("rgb(255, 102, 102)");
|
|
|
125
125
|
const oklch = convertColor(color, "oklch");
|
|
126
126
|
```
|
|
127
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
|
+
|
|
128
149
|
## Documentation
|
|
129
150
|
|
|
130
151
|
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) — `addRole`, `addVariant`, `addToken`
|
|
@@ -132,7 +153,7 @@ const oklch = convertColor(color, "oklch");
|
|
|
132
153
|
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md) — dynamic theming and `.fork()`
|
|
133
154
|
- [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — generation and format options reference
|
|
134
155
|
- [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) —
|
|
156
|
+
- [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — hook, `HextimatorStyle`, provider, scoped themes, dark mode
|
|
136
157
|
- [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md) — setup and usage with Tailwind
|
|
137
158
|
- [Real-world examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md) — shadcn/ui, Stripe, Slack configurations
|
|
138
159
|
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import { e as HextimateGenerationOptions, f as HextimatePaletteBuilder, j as HextimateResult, h as HextimateFormatOptions, F as FlatTokenMap } from './HextimatePaletteBuilder-BOuHKcVE.js';
|
|
3
|
-
import
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
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?:
|
|
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
|
|
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 };
|