hextimator 0.1.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 +2 -0
- package/LICENSE.md +7 -0
- package/README.md +137 -0
- package/dist/HextimatePaletteBuilder-BzrgFryu.d.mts +540 -0
- package/dist/HextimatePaletteBuilder-BzrgFryu.d.ts +540 -0
- package/dist/chunk-MBVLFPTG.js +2142 -0
- package/dist/cli.js +2395 -0
- package/dist/index.d.mts +168 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +20 -0
- package/dist/react.d.mts +132 -0
- package/dist/react.d.ts +132 -0
- package/dist/react.js +245 -0
- package/llms.txt +289 -0
- package/package.json +81 -0
- package/tailwind.css +22 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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.mjs';
|
|
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.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Daltonize a color for a specific type of color vision deficiency (CVD).
|
|
6
|
+
*
|
|
7
|
+
* Daltonization attempts to preserve the appearance of the color by redistributing the error from the CVD simulation into the channels that the person can still perceive.
|
|
8
|
+
*
|
|
9
|
+
* Note that daltonization is not a perfect solution and may not work well for all colors or all types of CVD.
|
|
10
|
+
* It is intended as a tool for improving accessibility,
|
|
11
|
+
* but should be used with caution and tested with real users whenever possible.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @param color The color to daltonize.
|
|
15
|
+
* @param type The type of color vision deficiency to daltonize for (e.g. "protanopia", "deuteranopia", "tritanopia", "achromatopsia").
|
|
16
|
+
* @param severity The severity of the color vision deficiency to daltonize for, on a scale from 0 (no deficiency) to 1 (complete deficiency). Default is 1.
|
|
17
|
+
* @returns The daltonized color in OKLCH color space.
|
|
18
|
+
*/
|
|
19
|
+
declare function daltonizeColor(color: Color, type: CVDType, severity?: number): OKLCH;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Simulate how a color would appear to someone with a specific type of color vision deficiency (CVD).
|
|
23
|
+
*/
|
|
24
|
+
declare function simulateColor(color: Color, type: CVDType, severity?: number): OKLCH;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* Convert a Color to a target color space.
|
|
29
|
+
*
|
|
30
|
+
* This function supports conversion between any two color spaces
|
|
31
|
+
* for which a conversion path is defined in the `conversions` table.
|
|
32
|
+
* If a direct conversion is not available, it will attempt to find
|
|
33
|
+
* a path through intermediate color spaces.
|
|
34
|
+
*
|
|
35
|
+
* If no path exists, an error is thrown.
|
|
36
|
+
*
|
|
37
|
+
* @param color The input color, in any supported color space.
|
|
38
|
+
* @param to The target color space to convert to.
|
|
39
|
+
* @returns The converted color, in the target color space.
|
|
40
|
+
*
|
|
41
|
+
* @throws If the conversion is not supported (e.g. if there is no defined conversion path between the input and target color spaces).
|
|
42
|
+
*/
|
|
43
|
+
declare function convert<S extends ColorSpace>(color: Color, to: S): ColorInSpace<S>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parse a ColorInput into a Color.
|
|
47
|
+
*
|
|
48
|
+
* If the input is already a Color, it will be returned as is.
|
|
49
|
+
* If the input is a number, it will be parsed as a numeric hex value.
|
|
50
|
+
* If the input is a string, it will be parsed as a hex value, CSS function, or comma separated values.
|
|
51
|
+
* If the input is a tuple, it will be parsed as a color tuple.
|
|
52
|
+
* If the input is a CSS function string, it will be parsed as a CSS function.
|
|
53
|
+
* If the input is a comma separated values string, it will be parsed as a comma separated values.
|
|
54
|
+
*
|
|
55
|
+
* **Alpha is always set to 1.** Transparent inputs like `rgba(255,0,0,0.5)` are treated as
|
|
56
|
+
* fully opaque. This is intentional: alpha tokens break WCAG contrast guarantees because
|
|
57
|
+
* contrast ratios depend on whatever is rendered behind the element, which hextimator cannot
|
|
58
|
+
* know at generation time.
|
|
59
|
+
*
|
|
60
|
+
* @param input ColorInput
|
|
61
|
+
* @param assumeSpace color space to assume. If not provided, the color space will be inferred from the input, and default to 'srgb' if ambiguous
|
|
62
|
+
* @returns Color or throws a ColorParseError if parsing fails
|
|
63
|
+
*/
|
|
64
|
+
declare function parse(input: ColorInput, assumeSpace?: ColorSpace): Color;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Demo preset that exercises every `HextimatePreset` capability:
|
|
68
|
+
* generation options, extra roles, extra variants, standalone tokens,
|
|
69
|
+
* and format defaults.
|
|
70
|
+
*
|
|
71
|
+
* Use this as a reference when building your own presets.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* import { hextimate, presets } from 'hextimator';
|
|
75
|
+
*
|
|
76
|
+
* const theme = hextimate('#e63946').preset(presets.demo).format();
|
|
77
|
+
*
|
|
78
|
+
* // Override any preset default:
|
|
79
|
+
* const theme = hextimate('#e63946', { minContrastRatio: 'AAA' })
|
|
80
|
+
* .preset(presets.demo)
|
|
81
|
+
* .format({ colors: 'rgb' });
|
|
82
|
+
*/
|
|
83
|
+
declare const demo: HextimatePreset;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Preset for Material UI (MUI) projects.
|
|
87
|
+
*
|
|
88
|
+
* Generates palette tokens matching MUI's theme structure:
|
|
89
|
+
* `primary`, `secondary`, `error`, `warning`, `info`, `success` —
|
|
90
|
+
* each with `main`, `light`, `dark`, and `contrastText` variants.
|
|
91
|
+
*
|
|
92
|
+
* Also generates `background` (`default`, `paper`), `text` (`primary`,
|
|
93
|
+
* `secondary`, `disabled`), `divider`, and `action` tokens.
|
|
94
|
+
*
|
|
95
|
+
* Defaults to `object` format for use with `createTheme()`. Override with
|
|
96
|
+
* `.format({ as: 'css' })` for MUI's CSS variables mode.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* import { hextimate, presets } from 'hextimator';
|
|
100
|
+
* import { createTheme } from '@mui/material/styles';
|
|
101
|
+
*
|
|
102
|
+
* const palette = hextimate('#6366F1')
|
|
103
|
+
* .preset(presets.mui)
|
|
104
|
+
* .format();
|
|
105
|
+
*
|
|
106
|
+
* const theme = createTheme({ palette: palette.light });
|
|
107
|
+
*/
|
|
108
|
+
declare const mui: HextimatePreset;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Preset for shadcn/ui projects.
|
|
112
|
+
*
|
|
113
|
+
* Generates all CSS variables that shadcn/ui components expect:
|
|
114
|
+
* `--background`, `--foreground`, `--primary`, `--secondary`, `--muted`,
|
|
115
|
+
* `--accent`, `--destructive`, `--card`, `--popover`, `--border`, `--input`, `--ring`,
|
|
116
|
+
* plus their `-foreground` counterparts.
|
|
117
|
+
*
|
|
118
|
+
* Also includes hextimator's bonus scale variants (`--primary-strong`, `--primary-weak`, etc.)
|
|
119
|
+
* which you can optionally use beyond what shadcn requires.
|
|
120
|
+
*
|
|
121
|
+
* Defaults to `oklch` color format (modern shadcn). Override with
|
|
122
|
+
* `.format({ colors: 'hsl-raw' })` for older shadcn setups.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* import { hextimate, presets } from 'hextimator';
|
|
126
|
+
*
|
|
127
|
+
* const theme = hextimate('#6366F1')
|
|
128
|
+
* .preset(presets.shadcn)
|
|
129
|
+
* .format();
|
|
130
|
+
*
|
|
131
|
+
* // Use with React hook:
|
|
132
|
+
* const palette = useHextimator('#6366F1', {
|
|
133
|
+
* configure: (b) => b.preset(presets.shadcn),
|
|
134
|
+
* });
|
|
135
|
+
*/
|
|
136
|
+
declare const shadcn: HextimatePreset;
|
|
137
|
+
|
|
138
|
+
declare const index_HextimatePreset: typeof HextimatePreset;
|
|
139
|
+
declare const index_demo: typeof demo;
|
|
140
|
+
declare const index_mui: typeof mui;
|
|
141
|
+
declare const index_shadcn: typeof shadcn;
|
|
142
|
+
declare namespace index {
|
|
143
|
+
export { index_HextimatePreset as HextimatePreset, index_demo as demo, index_mui as mui, index_shadcn as shadcn };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Thrown when `hextimate()` fails to parse or generate a palette from the given input. */
|
|
147
|
+
declare class HextimateError extends Error {
|
|
148
|
+
readonly input: ColorInput;
|
|
149
|
+
constructor(input: ColorInput, message?: string);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a palette builder from an accent/brand color.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Two-step API: generate, then format
|
|
156
|
+
* const theme = hextimate('#ff6600')
|
|
157
|
+
* .format({ as: 'css', colors: 'oklch' });
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Extended: add roles and variants before formatting
|
|
161
|
+
* const theme = hextimate('#ff6600', { light: { lightness: 0.5 }, dark: { lightness: 0.65, maxChroma: 0.1 } })
|
|
162
|
+
* .addRole('cta', '#ee2244')
|
|
163
|
+
* .addVariant('hover', { from: 'strong' })
|
|
164
|
+
* .format({ as: 'tailwind' });
|
|
165
|
+
*/
|
|
166
|
+
declare function hextimate(color: ColorInput, options?: HextimateGenerationOptions): HextimatePaletteBuilder;
|
|
167
|
+
|
|
168
|
+
export { CVDType, HextimateError, HextimateGenerationOptions, HextimatePaletteBuilder, HextimatePreset, convert as convertColor, daltonizeColor, hextimate, parse as parseColor, index as presets, simulateColor };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Daltonize a color for a specific type of color vision deficiency (CVD).
|
|
6
|
+
*
|
|
7
|
+
* Daltonization attempts to preserve the appearance of the color by redistributing the error from the CVD simulation into the channels that the person can still perceive.
|
|
8
|
+
*
|
|
9
|
+
* Note that daltonization is not a perfect solution and may not work well for all colors or all types of CVD.
|
|
10
|
+
* It is intended as a tool for improving accessibility,
|
|
11
|
+
* but should be used with caution and tested with real users whenever possible.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @param color The color to daltonize.
|
|
15
|
+
* @param type The type of color vision deficiency to daltonize for (e.g. "protanopia", "deuteranopia", "tritanopia", "achromatopsia").
|
|
16
|
+
* @param severity The severity of the color vision deficiency to daltonize for, on a scale from 0 (no deficiency) to 1 (complete deficiency). Default is 1.
|
|
17
|
+
* @returns The daltonized color in OKLCH color space.
|
|
18
|
+
*/
|
|
19
|
+
declare function daltonizeColor(color: Color, type: CVDType, severity?: number): OKLCH;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Simulate how a color would appear to someone with a specific type of color vision deficiency (CVD).
|
|
23
|
+
*/
|
|
24
|
+
declare function simulateColor(color: Color, type: CVDType, severity?: number): OKLCH;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* Convert a Color to a target color space.
|
|
29
|
+
*
|
|
30
|
+
* This function supports conversion between any two color spaces
|
|
31
|
+
* for which a conversion path is defined in the `conversions` table.
|
|
32
|
+
* If a direct conversion is not available, it will attempt to find
|
|
33
|
+
* a path through intermediate color spaces.
|
|
34
|
+
*
|
|
35
|
+
* If no path exists, an error is thrown.
|
|
36
|
+
*
|
|
37
|
+
* @param color The input color, in any supported color space.
|
|
38
|
+
* @param to The target color space to convert to.
|
|
39
|
+
* @returns The converted color, in the target color space.
|
|
40
|
+
*
|
|
41
|
+
* @throws If the conversion is not supported (e.g. if there is no defined conversion path between the input and target color spaces).
|
|
42
|
+
*/
|
|
43
|
+
declare function convert<S extends ColorSpace>(color: Color, to: S): ColorInSpace<S>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parse a ColorInput into a Color.
|
|
47
|
+
*
|
|
48
|
+
* If the input is already a Color, it will be returned as is.
|
|
49
|
+
* If the input is a number, it will be parsed as a numeric hex value.
|
|
50
|
+
* If the input is a string, it will be parsed as a hex value, CSS function, or comma separated values.
|
|
51
|
+
* If the input is a tuple, it will be parsed as a color tuple.
|
|
52
|
+
* If the input is a CSS function string, it will be parsed as a CSS function.
|
|
53
|
+
* If the input is a comma separated values string, it will be parsed as a comma separated values.
|
|
54
|
+
*
|
|
55
|
+
* **Alpha is always set to 1.** Transparent inputs like `rgba(255,0,0,0.5)` are treated as
|
|
56
|
+
* fully opaque. This is intentional: alpha tokens break WCAG contrast guarantees because
|
|
57
|
+
* contrast ratios depend on whatever is rendered behind the element, which hextimator cannot
|
|
58
|
+
* know at generation time.
|
|
59
|
+
*
|
|
60
|
+
* @param input ColorInput
|
|
61
|
+
* @param assumeSpace color space to assume. If not provided, the color space will be inferred from the input, and default to 'srgb' if ambiguous
|
|
62
|
+
* @returns Color or throws a ColorParseError if parsing fails
|
|
63
|
+
*/
|
|
64
|
+
declare function parse(input: ColorInput, assumeSpace?: ColorSpace): Color;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Demo preset that exercises every `HextimatePreset` capability:
|
|
68
|
+
* generation options, extra roles, extra variants, standalone tokens,
|
|
69
|
+
* and format defaults.
|
|
70
|
+
*
|
|
71
|
+
* Use this as a reference when building your own presets.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* import { hextimate, presets } from 'hextimator';
|
|
75
|
+
*
|
|
76
|
+
* const theme = hextimate('#e63946').preset(presets.demo).format();
|
|
77
|
+
*
|
|
78
|
+
* // Override any preset default:
|
|
79
|
+
* const theme = hextimate('#e63946', { minContrastRatio: 'AAA' })
|
|
80
|
+
* .preset(presets.demo)
|
|
81
|
+
* .format({ colors: 'rgb' });
|
|
82
|
+
*/
|
|
83
|
+
declare const demo: HextimatePreset;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Preset for Material UI (MUI) projects.
|
|
87
|
+
*
|
|
88
|
+
* Generates palette tokens matching MUI's theme structure:
|
|
89
|
+
* `primary`, `secondary`, `error`, `warning`, `info`, `success` —
|
|
90
|
+
* each with `main`, `light`, `dark`, and `contrastText` variants.
|
|
91
|
+
*
|
|
92
|
+
* Also generates `background` (`default`, `paper`), `text` (`primary`,
|
|
93
|
+
* `secondary`, `disabled`), `divider`, and `action` tokens.
|
|
94
|
+
*
|
|
95
|
+
* Defaults to `object` format for use with `createTheme()`. Override with
|
|
96
|
+
* `.format({ as: 'css' })` for MUI's CSS variables mode.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* import { hextimate, presets } from 'hextimator';
|
|
100
|
+
* import { createTheme } from '@mui/material/styles';
|
|
101
|
+
*
|
|
102
|
+
* const palette = hextimate('#6366F1')
|
|
103
|
+
* .preset(presets.mui)
|
|
104
|
+
* .format();
|
|
105
|
+
*
|
|
106
|
+
* const theme = createTheme({ palette: palette.light });
|
|
107
|
+
*/
|
|
108
|
+
declare const mui: HextimatePreset;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Preset for shadcn/ui projects.
|
|
112
|
+
*
|
|
113
|
+
* Generates all CSS variables that shadcn/ui components expect:
|
|
114
|
+
* `--background`, `--foreground`, `--primary`, `--secondary`, `--muted`,
|
|
115
|
+
* `--accent`, `--destructive`, `--card`, `--popover`, `--border`, `--input`, `--ring`,
|
|
116
|
+
* plus their `-foreground` counterparts.
|
|
117
|
+
*
|
|
118
|
+
* Also includes hextimator's bonus scale variants (`--primary-strong`, `--primary-weak`, etc.)
|
|
119
|
+
* which you can optionally use beyond what shadcn requires.
|
|
120
|
+
*
|
|
121
|
+
* Defaults to `oklch` color format (modern shadcn). Override with
|
|
122
|
+
* `.format({ colors: 'hsl-raw' })` for older shadcn setups.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* import { hextimate, presets } from 'hextimator';
|
|
126
|
+
*
|
|
127
|
+
* const theme = hextimate('#6366F1')
|
|
128
|
+
* .preset(presets.shadcn)
|
|
129
|
+
* .format();
|
|
130
|
+
*
|
|
131
|
+
* // Use with React hook:
|
|
132
|
+
* const palette = useHextimator('#6366F1', {
|
|
133
|
+
* configure: (b) => b.preset(presets.shadcn),
|
|
134
|
+
* });
|
|
135
|
+
*/
|
|
136
|
+
declare const shadcn: HextimatePreset;
|
|
137
|
+
|
|
138
|
+
declare const index_HextimatePreset: typeof HextimatePreset;
|
|
139
|
+
declare const index_demo: typeof demo;
|
|
140
|
+
declare const index_mui: typeof mui;
|
|
141
|
+
declare const index_shadcn: typeof shadcn;
|
|
142
|
+
declare namespace index {
|
|
143
|
+
export { index_HextimatePreset as HextimatePreset, index_demo as demo, index_mui as mui, index_shadcn as shadcn };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Thrown when `hextimate()` fails to parse or generate a palette from the given input. */
|
|
147
|
+
declare class HextimateError extends Error {
|
|
148
|
+
readonly input: ColorInput;
|
|
149
|
+
constructor(input: ColorInput, message?: string);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a palette builder from an accent/brand color.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Two-step API: generate, then format
|
|
156
|
+
* const theme = hextimate('#ff6600')
|
|
157
|
+
* .format({ as: 'css', colors: 'oklch' });
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Extended: add roles and variants before formatting
|
|
161
|
+
* const theme = hextimate('#ff6600', { light: { lightness: 0.5 }, dark: { lightness: 0.65, maxChroma: 0.1 } })
|
|
162
|
+
* .addRole('cta', '#ee2244')
|
|
163
|
+
* .addVariant('hover', { from: 'strong' })
|
|
164
|
+
* .format({ as: 'tailwind' });
|
|
165
|
+
*/
|
|
166
|
+
declare function hextimate(color: ColorInput, options?: HextimateGenerationOptions): HextimatePaletteBuilder;
|
|
167
|
+
|
|
168
|
+
export { CVDType, HextimateError, HextimateGenerationOptions, HextimatePaletteBuilder, HextimatePreset, convert as convertColor, daltonizeColor, hextimate, parse as parseColor, index as presets, simulateColor };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HextimateError,
|
|
3
|
+
HextimatePaletteBuilder,
|
|
4
|
+
convert,
|
|
5
|
+
daltonizeColor,
|
|
6
|
+
hextimate,
|
|
7
|
+
parse,
|
|
8
|
+
presets_exports,
|
|
9
|
+
simulateColor
|
|
10
|
+
} from "./chunk-MBVLFPTG.js";
|
|
11
|
+
export {
|
|
12
|
+
HextimateError,
|
|
13
|
+
HextimatePaletteBuilder,
|
|
14
|
+
convert as convertColor,
|
|
15
|
+
daltonizeColor,
|
|
16
|
+
hextimate,
|
|
17
|
+
parse as parseColor,
|
|
18
|
+
presets_exports as presets,
|
|
19
|
+
simulateColor
|
|
20
|
+
};
|
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
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.mjs';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
|
+
|
|
5
|
+
type DarkModeStrategy = {
|
|
6
|
+
type: 'class';
|
|
7
|
+
className?: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'data';
|
|
10
|
+
attribute?: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'media';
|
|
13
|
+
} | {
|
|
14
|
+
type: 'media-or-class';
|
|
15
|
+
className?: string;
|
|
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
|
+
type ModePreference = 'light' | 'dark' | 'system';
|
|
54
|
+
type ResolvedMode = 'light' | 'dark';
|
|
55
|
+
/**
|
|
56
|
+
* Props for the `HextimatorProvider` component, which manages the state of a Hextimator-generated color palette and injects corresponding CSS variables into the document.
|
|
57
|
+
* - `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).
|
|
59
|
+
* - `format`: Initial options for how the generated palette is formatted (e.g., output format).
|
|
60
|
+
* - `configure`: An initial callback to further customize the palette builder before formatting.
|
|
61
|
+
* - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
|
|
62
|
+
* - `cssPrefix`: A prefix to apply to all generated CSS variable names.
|
|
63
|
+
* - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
|
|
64
|
+
*/
|
|
65
|
+
interface HextimatorProviderProps {
|
|
66
|
+
defaultColor: string;
|
|
67
|
+
defaultMode?: ModePreference;
|
|
68
|
+
generation?: HextimateGenerationOptions;
|
|
69
|
+
format?: Omit<HextimateFormatOptions, 'as'>;
|
|
70
|
+
configure?: (builder: HextimatePaletteBuilder) => void;
|
|
71
|
+
darkMode?: DarkModeStrategy;
|
|
72
|
+
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;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
* A React context provider that manages the state of
|
|
90
|
+
* a Hextimator-generated color palette and injects corresponding CSS variables into the document.
|
|
91
|
+
* It allows child components to access and update the
|
|
92
|
+
* base color, generation options, and configuration callback, automatically
|
|
93
|
+
* regenerating the palette and updating CSS variables as needed.
|
|
94
|
+
|
|
95
|
+
* The Provider accepts props for the default color, generation options, formatting options,
|
|
96
|
+
* dark mode strategy, CSS variable prefix, and an optional target element for CSS variable injection.
|
|
97
|
+
* It uses the `useHextimator` hook to generate the palette and handles the injection of CSS variables based on the current state.
|
|
98
|
+
*
|
|
99
|
+
* Example usage:
|
|
100
|
+
* ```tsx
|
|
101
|
+
* <HextimatorProvider defaultColor="#ff6600" generation={{ minContrastRatio: 'AA' }} darkMode={{ type: 'class', className: 'dark' }} cssPrefix="--myapp-">
|
|
102
|
+
* <App />
|
|
103
|
+
* </HextimatorProvider>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function HextimatorProvider({ children, defaultColor, defaultMode: initialMode, generation: initialGeneration, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
|
|
107
|
+
/**
|
|
108
|
+
* Provides access to the current Hextimator palette and theme state from the nearest `HextimatorProvider`.
|
|
109
|
+
*
|
|
110
|
+
* Returned properties:
|
|
111
|
+
* - `color` / `setColor` — the current base color.
|
|
112
|
+
* - `mode` — the resolved color mode (`'light'` or `'dark'`), accounting for OS preference when set to `'system'`.
|
|
113
|
+
* - `modePreference` — the raw preference (`'light'`, `'dark'`, or `'system'`).
|
|
114
|
+
* - `setMode` — update the mode preference. Pass `'system'` to follow the OS.
|
|
115
|
+
* - `generation` / `setGeneration` — palette generation options.
|
|
116
|
+
* - `configure` / `setConfigure` — builder configuration callback.
|
|
117
|
+
* - `palette` — the generated `HextimateResult`.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* const { mode, setMode } = useHextimatorTheme();
|
|
122
|
+
*
|
|
123
|
+
* <button onClick={() => setMode(mode === 'dark' ? 'light' : 'dark')}>
|
|
124
|
+
* Toggle dark mode
|
|
125
|
+
* </button>
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @throws If used outside of a `HextimatorProvider`.
|
|
129
|
+
*/
|
|
130
|
+
declare function useHextimatorTheme(): HextimatorContextValue;
|
|
131
|
+
|
|
132
|
+
export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
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';
|
|
4
|
+
|
|
5
|
+
type DarkModeStrategy = {
|
|
6
|
+
type: 'class';
|
|
7
|
+
className?: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'data';
|
|
10
|
+
attribute?: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'media';
|
|
13
|
+
} | {
|
|
14
|
+
type: 'media-or-class';
|
|
15
|
+
className?: string;
|
|
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
|
+
type ModePreference = 'light' | 'dark' | 'system';
|
|
54
|
+
type ResolvedMode = 'light' | 'dark';
|
|
55
|
+
/**
|
|
56
|
+
* Props for the `HextimatorProvider` component, which manages the state of a Hextimator-generated color palette and injects corresponding CSS variables into the document.
|
|
57
|
+
* - `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).
|
|
59
|
+
* - `format`: Initial options for how the generated palette is formatted (e.g., output format).
|
|
60
|
+
* - `configure`: An initial callback to further customize the palette builder before formatting.
|
|
61
|
+
* - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
|
|
62
|
+
* - `cssPrefix`: A prefix to apply to all generated CSS variable names.
|
|
63
|
+
* - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
|
|
64
|
+
*/
|
|
65
|
+
interface HextimatorProviderProps {
|
|
66
|
+
defaultColor: string;
|
|
67
|
+
defaultMode?: ModePreference;
|
|
68
|
+
generation?: HextimateGenerationOptions;
|
|
69
|
+
format?: Omit<HextimateFormatOptions, 'as'>;
|
|
70
|
+
configure?: (builder: HextimatePaletteBuilder) => void;
|
|
71
|
+
darkMode?: DarkModeStrategy;
|
|
72
|
+
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;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
* A React context provider that manages the state of
|
|
90
|
+
* a Hextimator-generated color palette and injects corresponding CSS variables into the document.
|
|
91
|
+
* It allows child components to access and update the
|
|
92
|
+
* base color, generation options, and configuration callback, automatically
|
|
93
|
+
* regenerating the palette and updating CSS variables as needed.
|
|
94
|
+
|
|
95
|
+
* The Provider accepts props for the default color, generation options, formatting options,
|
|
96
|
+
* dark mode strategy, CSS variable prefix, and an optional target element for CSS variable injection.
|
|
97
|
+
* It uses the `useHextimator` hook to generate the palette and handles the injection of CSS variables based on the current state.
|
|
98
|
+
*
|
|
99
|
+
* Example usage:
|
|
100
|
+
* ```tsx
|
|
101
|
+
* <HextimatorProvider defaultColor="#ff6600" generation={{ minContrastRatio: 'AA' }} darkMode={{ type: 'class', className: 'dark' }} cssPrefix="--myapp-">
|
|
102
|
+
* <App />
|
|
103
|
+
* </HextimatorProvider>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function HextimatorProvider({ children, defaultColor, defaultMode: initialMode, generation: initialGeneration, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
|
|
107
|
+
/**
|
|
108
|
+
* Provides access to the current Hextimator palette and theme state from the nearest `HextimatorProvider`.
|
|
109
|
+
*
|
|
110
|
+
* Returned properties:
|
|
111
|
+
* - `color` / `setColor` — the current base color.
|
|
112
|
+
* - `mode` — the resolved color mode (`'light'` or `'dark'`), accounting for OS preference when set to `'system'`.
|
|
113
|
+
* - `modePreference` — the raw preference (`'light'`, `'dark'`, or `'system'`).
|
|
114
|
+
* - `setMode` — update the mode preference. Pass `'system'` to follow the OS.
|
|
115
|
+
* - `generation` / `setGeneration` — palette generation options.
|
|
116
|
+
* - `configure` / `setConfigure` — builder configuration callback.
|
|
117
|
+
* - `palette` — the generated `HextimateResult`.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* const { mode, setMode } = useHextimatorTheme();
|
|
122
|
+
*
|
|
123
|
+
* <button onClick={() => setMode(mode === 'dark' ? 'light' : 'dark')}>
|
|
124
|
+
* Toggle dark mode
|
|
125
|
+
* </button>
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @throws If used outside of a `HextimatorProvider`.
|
|
129
|
+
*/
|
|
130
|
+
declare function useHextimatorTheme(): HextimatorContextValue;
|
|
131
|
+
|
|
132
|
+
export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };
|