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/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { j as HextimateStyleOptions, H as HextimatePreset, e as HextimatePaletteBuilder, i as HextimateResult, g as HextimateFormatOptions, F as FlatTokenMap } from './HextimatePaletteBuilder-xqJwP_G2.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-BOuHKcVE.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,48 +14,34 @@ 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
+ style: HextimateStyleOptions | undefined;
27
+ setStyle: (opts: HextimateStyleOptions | undefined) => void;
28
+ presets: HextimatePreset[] | undefined;
29
+ setPresets: (presets: HextimatePreset[] | undefined) => void;
30
+ configure: ((builder: HextimatePaletteBuilder) => void) | undefined;
31
+ setConfigure: (fn: ((builder: HextimatePaletteBuilder) => void) | undefined) => void;
32
+ palette: HextimateResult;
33
+ /**
34
+ * The palette builder backing this provider or scope. Nested
35
+ * `HextimatorScope`s fork from this builder so they inherit any custom
36
+ * roles, variants, tokens, or presets without re-declaring them.
37
+ */
38
+ builder: HextimatePaletteBuilder;
39
+ }
40
+
55
41
  /**
56
42
  * Props for the `HextimatorProvider` component, which manages the state of a Hextimator-generated color palette and injects corresponding CSS variables into the document.
57
43
  * - `defaultColor`: The initial base color to generate the palette from.
58
- * - `generation`: Initial options for how the palette is generated (e.g., light/dark settings, contrast requirements).
44
+ * - `style`: Initial options for how the palette is generated (e.g., light/dark settings, contrast requirements).
59
45
  * - `format`: Initial options for how the generated palette is formatted (e.g., output format).
60
46
  * - `configure`: An initial callback to further customize the palette builder before formatting.
61
47
  * - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
@@ -65,54 +51,201 @@ type ResolvedMode = 'light' | 'dark';
65
51
  interface HextimatorProviderProps {
66
52
  defaultColor: string;
67
53
  defaultMode?: ModePreference;
68
- generation?: HextimateGenerationOptions;
54
+ style?: HextimateStyleOptions;
55
+ presets?: HextimatePreset[];
69
56
  format?: Omit<HextimateFormatOptions, 'as'>;
70
57
  configure?: (builder: HextimatePaletteBuilder) => void;
71
58
  darkMode?: DarkModeStrategy;
72
59
  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;
60
+ target?: RefObject<HTMLElement | null>;
86
61
  }
87
62
  /**
88
63
  *
89
64
  * A React context provider that manages the state of
90
65
  * a Hextimator-generated color palette and injects corresponding CSS variables into the document.
91
66
  * It allows child components to access and update the
92
- * base color, generation options, and configuration callback, automatically
67
+ * base color, style options, and configuration callback, automatically
93
68
  * regenerating the palette and updating CSS variables as needed.
94
69
 
95
- * The Provider accepts props for the default color, generation options, formatting options,
70
+ * The Provider accepts props for the default color, style options, formatting options,
96
71
  * dark mode strategy, CSS variable prefix, and an optional target element for CSS variable injection.
97
72
  * It uses the `useHextimator` hook to generate the palette and handles the injection of CSS variables based on the current state.
98
73
  *
99
74
  * Example usage:
100
75
  * ```tsx
101
- * <HextimatorProvider defaultColor="#ff6600" generation={{ minContrastRatio: 'AA' }} darkMode={{ type: 'class', className: 'dark' }} cssPrefix="--myapp-">
76
+ * <HextimatorProvider defaultColor="#ff6600" style={{ minContrastRatio: 'AA' }} darkMode={{ type: 'class', className: 'dark' }} cssPrefix="--myapp-">
102
77
  * <App />
103
78
  * </HextimatorProvider>
104
79
  * ```
105
80
  */
106
- declare function HextimatorProvider({ children, defaultColor, defaultMode: initialMode, generation: initialGeneration, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
81
+ declare function HextimatorProvider({ children, defaultColor, defaultMode: initialMode, style: initialStyle, presets: initialPresets, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
82
+
83
+ /**
84
+ * Props for `HextimatorScope`, a wrapper that creates a scoped theme for its
85
+ * descendants via CSS cascade and React context.
86
+ *
87
+ * Unlike `HextimatorProvider` (which themes the whole document root),
88
+ * `HextimatorScope` themes only its subtree. Scopes can nest freely, and the
89
+ * nearest `HextimatorScope` or `HextimatorProvider` wins for
90
+ * `useHextimatorTheme()`.
91
+ *
92
+ * Mode (light/dark) is inherited from the nearest parent context when present,
93
+ * so a scope automatically follows the app's global dark-mode toggle. If you
94
+ * pass `darkMode` explicitly, make sure it matches the strategy your root
95
+ * `HextimatorProvider` uses (class, data, media, etc.) so the dark selectors
96
+ * line up.
97
+ */
98
+ interface HextimatorScopeProps {
99
+ defaultColor: string;
100
+ /**
101
+ * When true, builds from this scope's color and options only (via
102
+ * `hextimate`), without forking the parent builder. Use for previews or
103
+ * widgets where each scope must match exactly its presets and must not
104
+ * inherit parent roles, variants, or preset merges.
105
+ */
106
+ isolated?: boolean;
107
+ style?: HextimateStyleOptions;
108
+ presets?: HextimatePreset[];
109
+ format?: Omit<HextimateFormatOptions, 'as'>;
110
+ configure?: (builder: HextimatePaletteBuilder) => void;
111
+ darkMode?: DarkModeStrategy;
112
+ cssPrefix?: string;
113
+ className?: string;
114
+ /** Inline styles for the scope wrapper element (not palette options; use `style` for those). */
115
+ wrapperStyle?: CSSProperties;
116
+ children?: ReactNode;
117
+ }
118
+ /**
119
+ * Scoped theme wrapper. Auto-generates a unique selector via `useId()`, wraps
120
+ * children in a `<div data-hextimator-scope={id}>`, and emits a scoped
121
+ * `<style>` with the generated palette. Also pushes a nested
122
+ * `HextimatorContext` so `useHextimatorTheme()` called from inside the wrapper
123
+ * returns the scope's palette and color state, not the root provider's.
124
+ *
125
+ * When nested inside a `HextimatorProvider` or another `HextimatorScope`, the
126
+ * scope inherits all custom roles, variants, tokens, and presets from its
127
+ * parent by forking the parent's builder — so you only pass the new color.
128
+ * Any per-scope `configure` callback is applied on top of the inherited shape.
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * // Root provider defines the theme shape once
133
+ * <HextimatorProvider
134
+ * defaultColor="#ff6600"
135
+ * darkMode={{ type: 'class' }}
136
+ * configure={(b) => b
137
+ * .addRole('cta', '#ff0066')
138
+ * .addVariant('hover', { from: 'strong' })
139
+ * }
140
+ * >
141
+ * <App>
142
+ * // Scope inherits cta + hover, just swaps the base color
143
+ * <HextimatorScope defaultColor="#0066ff" darkMode={{ type: 'class' }}>
144
+ * <Card />
145
+ * </HextimatorScope>
146
+ * </App>
147
+ * </HextimatorProvider>
148
+ * ```
149
+ */
150
+ declare function HextimatorScope({ defaultColor, isolated, style: initialStyle, presets: initialPresets, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, className, wrapperStyle, children, }: HextimatorScopeProps): react_jsx_runtime.JSX.Element;
151
+
152
+ /**
153
+ * Props for the `HextimatorStyle` component, a declarative alternative to
154
+ * `useHextimator` that renders a `<style>` element with the generated CSS
155
+ * variables directly into React's tree.
156
+ *
157
+ * Unlike the hook, this works during SSR/RSC (no `useEffect`, no manual
158
+ * cleanup), and supports scoping the palette to a specific selector so
159
+ * multiple subtrees can carry different themes via CSS cascade.
160
+ *
161
+ * - `color`: The base color to generate the palette from.
162
+ * - `style`: Options for how the palette is generated.
163
+ * - `format`: Options for how the generated palette is formatted.
164
+ * - `configure`: A callback to further customize the palette builder before formatting.
165
+ * - `darkMode`: Strategy for handling dark mode variants.
166
+ * - `cssPrefix`: A prefix applied to all generated CSS variable names.
167
+ * - `selector`: CSS selector the variables are scoped to. Defaults to `:root`.
168
+ */
169
+ interface HextimatorStyleProps {
170
+ color: string;
171
+ style?: HextimateStyleOptions;
172
+ presets?: HextimatePreset[];
173
+ format?: Omit<HextimateFormatOptions, 'as'>;
174
+ configure?: (builder: HextimatePaletteBuilder) => void;
175
+ darkMode?: DarkModeStrategy;
176
+ cssPrefix?: string;
177
+ selector?: string;
178
+ }
179
+ /**
180
+ * Declarative alternative to `useHextimator`. Renders a `<style>` element
181
+ * carrying the generated CSS variables, so the palette works during SSR/RSC
182
+ * and can be scoped to any selector for per-subtree theming.
183
+ *
184
+ * @example
185
+ * ```tsx
186
+ * // Global theme (equivalent to the hook, but SSR-safe)
187
+ * <HextimatorStyle color="#ff6600" darkMode={{ type: 'class' }} />
188
+ *
189
+ * // Per-subtree theme via CSS cascade
190
+ * <div className="card-a">
191
+ * <HextimatorStyle color="#ff0066" selector=".card-a" />
192
+ * ...
193
+ * </div>
194
+ * ```
195
+ */
196
+ declare function HextimatorStyle({ color, style: styleOptions, presets, format: formatOpts, configure, darkMode, cssPrefix, selector, }: HextimatorStyleProps): react_jsx_runtime.JSX.Element;
197
+
198
+ /**
199
+ * Options for the `useHextimator` hook, which generates a color palette and injects CSS variables based on a given color and configuration.
200
+ * - `style`: Options for how the palette is generated (e.g., light/dark settings, contrast requirements).
201
+ * - `format`: Options for how the generated palette is formatted (e.g., output format).
202
+ * - `configure`: A callback to further customize the palette builder before formatting.
203
+ * - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
204
+ * - `cssPrefix`: A prefix to apply to all generated CSS variable names.
205
+ * - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
206
+ *
207
+ */
208
+ interface UseHextimatorOptions {
209
+ style?: HextimateStyleOptions;
210
+ presets?: HextimatePreset[];
211
+ format?: Omit<HextimateFormatOptions, 'as'>;
212
+ configure?: (builder: HextimatePaletteBuilder) => void;
213
+ darkMode?: DarkModeStrategy;
214
+ cssPrefix?: string;
215
+ target?: RefObject<HTMLElement | null>;
216
+ }
217
+
218
+ /**
219
+ * Generates a color palette based on the provided color and options,
220
+ * and injects CSS variables into the document for use in styling.
221
+ * The palette is regenerated whenever the input color or relevant options change.
222
+ *
223
+ * Example usage:
224
+ * ```tsx
225
+ * const palette = useHextimator('#ff6600', {
226
+ * style: { minContrastRatio: 'AA' },
227
+ * darkMode: { type: 'class', className: 'dark' },
228
+ * cssPrefix: '--myapp-',
229
+ * });
230
+ * ```
231
+ *
232
+ * @param color - The base color to generate the palette from.
233
+ * @param options - Configuration options for palette generation, formatting, and CSS variable injection.
234
+ */
235
+ declare function useHextimator(color: string, options?: UseHextimatorOptions): HextimateResult<FlatTokenMap>;
236
+
107
237
  /**
108
- * Provides access to the current Hextimator palette and theme state from the nearest `HextimatorProvider`.
238
+ * Provides access to the current Hextimator palette and theme state from the
239
+ * nearest `HextimatorProvider` or `HextimatorScope`. When called from inside a
240
+ * `HextimatorScope`, returns the scope's palette and `color`/`setColor` state;
241
+ * `mode` and `setMode` are inherited from the nearest enclosing provider.
109
242
  *
110
243
  * Returned properties:
111
- * - `color` / `setColor` — the current base color.
244
+ * - `color` / `setColor` — the current base color for this scope or provider.
112
245
  * - `mode` — the resolved color mode (`'light'` or `'dark'`), accounting for OS preference when set to `'system'`.
113
246
  * - `modePreference` — the raw preference (`'light'`, `'dark'`, or `'system'`).
114
247
  * - `setMode` — update the mode preference. Pass `'system'` to follow the OS.
115
- * - `generation` / `setGeneration` — palette generation options.
248
+ * - `style` / `setStyle` — palette style options.
116
249
  * - `configure` / `setConfigure` — builder configuration callback.
117
250
  * - `palette` — the generated `HextimateResult`.
118
251
  *
@@ -125,8 +258,8 @@ declare function HextimatorProvider({ children, defaultColor, defaultMode: initi
125
258
  * </button>
126
259
  * ```
127
260
  *
128
- * @throws If used outside of a `HextimatorProvider`.
261
+ * @throws If used outside of a `HextimatorProvider` or `HextimatorScope`.
129
262
  */
130
263
  declare function useHextimatorTheme(): HextimatorContextValue;
131
264
 
132
- export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };
265
+ export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, HextimatorScope, type HextimatorScopeProps, HextimatorStyle, type HextimatorStyleProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };