hextimator 0.3.2 → 0.5.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,4 +1,33 @@
1
- ## Latest (0.3.2)
1
+ ## 0.5.0 (Latest)
2
+
3
+ - [#108](https://github.com/fgrgic/hextimator/pull/106) **Breaking.** `.format({ as: "css" })` and `.format({ as: "tailwind-css" })` now return a ready-to-paste stylesheet **string** instead of a `{ light, dark }` map of CSS variable objects. Both themes are combined into one output and wrapped for dark mode according to the new `darkMode` option.
4
+
5
+ ```ts
6
+ // Before (0.4)
7
+ const { light, dark } = hextimate("#6A5ACD").format({ as: "css" });
8
+ // light = { "--accent": "#...", ... }
9
+ // you had to hand-build ":root {} @media {}" yourself
10
+
11
+ // After (0.5)
12
+ const css = hextimate("#6A5ACD").format({ as: "css" });
13
+ // css = ":root { --accent: #...; ... }\n@media (prefers-color-scheme: dark) { :root { ... } }"
14
+ ```
15
+
16
+ - New format options for stylesheet outputs:
17
+ - `darkMode`: `"media"` (default) | `"class"` | `"data-attribute"` | `false`
18
+ - `selector`: root selector for `as: "css"` (default `":root"`); ignored for `as: "tailwind-css"` (always `@theme`)
19
+ - New CLI flags mirroring the options: `--dark-mode <strategy>` and `--selector <css>`. The `--theme` flag is ignored for `css`/`tailwind-css` outputs (both themes always combine into one string).
20
+ - React integration unchanged.
21
+
22
+ Migration checklist: [migrating-from-0.4.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migrating-from-0.4.md).
23
+
24
+ ## 0.4.0
25
+
26
+ - [#106](https://github.com/fgrgic/hextimator/pull/106): add per-theme color for React
27
+ - React provider and scope now accept per-mode brand colors (`defaultColor: string | { light, dark }`)
28
+ - expose `onColorChange` / `onModePreferenceChange` callbacks for persistence.
29
+
30
+ ## 0.3.2
2
31
 
3
32
  - [#99](https://github.com/fgrgic/hextimator/pull/99): Adds option to chain presets. Presets are merged, last added wins if both touch the same tokens.
4
33
  - For example: `hextimate("#ff6677").preset(shadcn).preset(muted);`
@@ -251,13 +251,33 @@ interface HextimateFormatOptions {
251
251
  /**
252
252
  * Output format.
253
253
  * - "object" (default): { base: "#f2eee8", "base-strong": "#d4cfc8", ...}
254
- * - "css": { "--base": "#f2eee8", "--base-strong": "#d4cfc8", ...}
254
+ * - "css": ready-to-paste CSS stylesheet string with `:root {}` and a dark-mode wrapper
255
255
  * - "tailwind": { base: { DEFAULT: "#f2eee8", strong: "#d4cfc8", weak: "#faf8f6" } }
256
256
  * - "scss": { $base: "#f2eee8", $base-strong: "#d4cfc8", ...}
257
257
  * - "json": '{ "base": "#f2eee8", "base-strong": "#d4cfc8", ...}'
258
- * - "tailwind-css": '@theme { --color-base: #f2eee8; --color-base-strong: #d4cfc8; ... }'
258
+ * - "tailwind-css": Tailwind v4 stylesheet string with a single `@theme { ... }` block and dark-mode overrides
259
+ *
260
+ * Stylesheet outputs (`css`, `tailwind-css`) combine light + dark into one
261
+ * string. Use `darkMode` to pick the strategy and `selector` (for `css`) to
262
+ * change the root selector.
259
263
  */
260
264
  as?: 'object' | 'css' | 'tailwind' | 'tailwind-css' | 'scss' | 'json';
265
+ /**
266
+ * Dark-mode strategy for stylesheet outputs (`as: 'css'`, `as: 'tailwind-css'`).
267
+ * Ignored for every other output format.
268
+ *
269
+ * - `'media'` (default): wraps dark tokens in `@media (prefers-color-scheme: dark)`
270
+ * - `'class'`: dark tokens apply under `.dark` (and descendants)
271
+ * - `'data-attribute'`: dark tokens apply under `[data-theme="dark"]`
272
+ * - `false`: omit dark tokens entirely (light-only output)
273
+ */
274
+ darkMode?: 'media' | 'class' | 'data-attribute' | false;
275
+ /**
276
+ * Selector for the root rule in `as: 'css'` output. Default: `':root'`.
277
+ *
278
+ * Ignored for `as: 'tailwind-css'` (Tailwind v4's `@theme` is always root-scoped).
279
+ */
280
+ selector?: string;
261
281
  /**
262
282
  * How color values are serialized in the output.
263
283
  *
@@ -523,12 +543,15 @@ declare class HextimatePaletteBuilder {
523
543
  as: 'tailwind';
524
544
  }): HextimateResult<NestedTokenMap>;
525
545
  format(options: HextimateFormatOptions & {
526
- as: 'json' | 'tailwind-css';
546
+ as: 'json';
527
547
  }): HextimateResult<string>;
528
548
  format(options: HextimateFormatOptions & {
529
- as: 'object' | 'css' | 'scss';
549
+ as: 'css' | 'tailwind-css';
550
+ }): string;
551
+ format(options: HextimateFormatOptions & {
552
+ as: 'object' | 'scss';
530
553
  }): HextimateResult<FlatTokenMap>;
531
- format(options?: HextimateFormatOptions): HextimateResult;
554
+ format(options?: HextimateFormatOptions): HextimateResult | string;
532
555
  private applyRole;
533
556
  private applyVariant;
534
557
  private applyToken;
@@ -875,13 +875,6 @@ function formatObject(entries, sep) {
875
875
  }
876
876
  return result;
877
877
  }
878
- function formatCSS(entries, sep) {
879
- const result = {};
880
- for (const entry of entries) {
881
- result[`--${toFlatKey(entry, sep)}`] = entry.value;
882
- }
883
- return result;
884
- }
885
878
  function formatSCSS(entries, sep) {
886
879
  const result = {};
887
880
  for (const entry of entries) {
@@ -897,41 +890,97 @@ function formatTailwind(entries) {
897
890
  }
898
891
  return result;
899
892
  }
900
- function formatTailwindCSS(entries, sep) {
901
- const lines = entries.map((entry) => {
902
- const key = toFlatKey(entry, sep);
903
- return ` --color-${key}: ${entry.value};`;
904
- });
905
- return `@theme {
906
- ${lines.join("\n")}
907
- }`;
908
- }
909
893
  function formatJSON(entries, sep) {
910
894
  return JSON.stringify(formatObject(entries, sep), null, 2);
911
895
  }
896
+ function declsFromEntries(entries, sep, prefix, indent) {
897
+ return entries.map((e) => `${indent}${prefix}${toFlatKey(e, sep)}: ${e.value};`).join("\n");
898
+ }
899
+ function darkSelectorFor(mode) {
900
+ return mode === "class" ? ".dark" : '[data-theme="dark"]';
901
+ }
902
+ function formatCSSStylesheet(lightEntries, darkEntries, sep, opts = {}) {
903
+ const selector = opts.selector ?? ":root";
904
+ const darkMode = opts.darkMode ?? "media";
905
+ const lightBlock = `${selector} {
906
+ ${declsFromEntries(lightEntries, sep, "--", " ")}
907
+ }`;
908
+ if (darkMode === false) return lightBlock;
909
+ if (darkMode === "media") {
910
+ const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
911
+ return `${lightBlock}
912
+ @media (prefers-color-scheme: dark) {
913
+ ${selector} {
914
+ ${darkInner}
915
+ }
916
+ }`;
917
+ }
918
+ const darkSel = darkSelectorFor(darkMode);
919
+ const darkBlock = `${darkSel} {
920
+ ${declsFromEntries(darkEntries, sep, "--", " ")}
921
+ }`;
922
+ return `${lightBlock}
923
+ ${darkBlock}`;
924
+ }
925
+ function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
926
+ const darkMode = opts.darkMode ?? "media";
927
+ const theme = `@theme {
928
+ ${declsFromEntries(lightEntries, sep, "--color-", " ")}
929
+ }`;
930
+ if (darkMode === false) return theme;
931
+ if (darkMode === "media") {
932
+ const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
933
+ return `${theme}
934
+ @media (prefers-color-scheme: dark) {
935
+ :root {
936
+ ${darkInner}
937
+ }
938
+ }`;
939
+ }
940
+ const darkSel = darkSelectorFor(darkMode);
941
+ const darkBlock = `${darkSel} {
942
+ ${declsFromEntries(darkEntries, sep, "--color-", " ")}
943
+ }`;
944
+ return `${theme}
945
+ ${darkBlock}`;
946
+ }
912
947
 
913
948
  // src/format/format.ts
914
949
  function format(palette, options, standaloneTokens) {
915
950
  const entries = buildTokenEntries(palette, options);
916
- if (standaloneTokens) {
917
- entries.push(...standaloneTokens);
918
- }
951
+ if (standaloneTokens) entries.push(...standaloneTokens);
919
952
  const sep = options?.separator ?? "-";
920
953
  switch (options?.as) {
921
- case "css":
922
- return formatCSS(entries, sep);
923
954
  case "scss":
924
955
  return formatSCSS(entries, sep);
925
956
  case "tailwind":
926
957
  return formatTailwind(entries);
927
- case "tailwind-css":
928
- return formatTailwindCSS(entries, sep);
929
958
  case "json":
930
959
  return formatJSON(entries, sep);
931
960
  default:
932
961
  return formatObject(entries, sep);
933
962
  }
934
963
  }
964
+ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, darkStandalone) {
965
+ const lightEntries = buildTokenEntries(lightPalette, options);
966
+ if (lightStandalone) lightEntries.push(...lightStandalone);
967
+ const darkEntries = buildTokenEntries(darkPalette, options);
968
+ if (darkStandalone) darkEntries.push(...darkStandalone);
969
+ const sep = options?.separator ?? "-";
970
+ const stylesheetOpts = {
971
+ selector: options?.selector,
972
+ darkMode: options?.darkMode
973
+ };
974
+ if (options?.as === "tailwind-css") {
975
+ return formatTailwindStylesheet(
976
+ lightEntries,
977
+ darkEntries,
978
+ sep,
979
+ stylesheetOpts
980
+ );
981
+ }
982
+ return formatCSSStylesheet(lightEntries, darkEntries, sep, stylesheetOpts);
983
+ }
935
984
 
936
985
  // src/generate/consts.ts
937
986
  var DEFAULT_LIGHT_THEME_LIGHTNESS = 0.7;
@@ -1705,6 +1754,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1705
1754
  this.darkPalette,
1706
1755
  colorFormat
1707
1756
  );
1757
+ if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
1758
+ return formatStylesheet(
1759
+ this.lightPalette,
1760
+ this.darkPalette,
1761
+ mergedOptions,
1762
+ lightTokens,
1763
+ darkTokens
1764
+ );
1765
+ }
1708
1766
  return {
1709
1767
  light: format(this.lightPalette, mergedOptions, lightTokens),
1710
1768
  dark: format(this.darkPalette, mergedOptions, darkTokens)
package/dist/cli.js CHANGED
@@ -877,13 +877,6 @@ function formatObject(entries, sep) {
877
877
  }
878
878
  return result;
879
879
  }
880
- function formatCSS(entries, sep) {
881
- const result = {};
882
- for (const entry of entries) {
883
- result[`--${toFlatKey(entry, sep)}`] = entry.value;
884
- }
885
- return result;
886
- }
887
880
  function formatSCSS(entries, sep) {
888
881
  const result = {};
889
882
  for (const entry of entries) {
@@ -899,41 +892,97 @@ function formatTailwind(entries) {
899
892
  }
900
893
  return result;
901
894
  }
902
- function formatTailwindCSS(entries, sep) {
903
- const lines = entries.map((entry) => {
904
- const key = toFlatKey(entry, sep);
905
- return ` --color-${key}: ${entry.value};`;
906
- });
907
- return `@theme {
908
- ${lines.join("\n")}
909
- }`;
910
- }
911
895
  function formatJSON(entries, sep) {
912
896
  return JSON.stringify(formatObject(entries, sep), null, 2);
913
897
  }
898
+ function declsFromEntries(entries, sep, prefix, indent) {
899
+ return entries.map((e) => `${indent}${prefix}${toFlatKey(e, sep)}: ${e.value};`).join("\n");
900
+ }
901
+ function darkSelectorFor(mode) {
902
+ return mode === "class" ? ".dark" : '[data-theme="dark"]';
903
+ }
904
+ function formatCSSStylesheet(lightEntries, darkEntries, sep, opts = {}) {
905
+ const selector = opts.selector ?? ":root";
906
+ const darkMode = opts.darkMode ?? "media";
907
+ const lightBlock = `${selector} {
908
+ ${declsFromEntries(lightEntries, sep, "--", " ")}
909
+ }`;
910
+ if (darkMode === false) return lightBlock;
911
+ if (darkMode === "media") {
912
+ const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
913
+ return `${lightBlock}
914
+ @media (prefers-color-scheme: dark) {
915
+ ${selector} {
916
+ ${darkInner}
917
+ }
918
+ }`;
919
+ }
920
+ const darkSel = darkSelectorFor(darkMode);
921
+ const darkBlock = `${darkSel} {
922
+ ${declsFromEntries(darkEntries, sep, "--", " ")}
923
+ }`;
924
+ return `${lightBlock}
925
+ ${darkBlock}`;
926
+ }
927
+ function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
928
+ const darkMode = opts.darkMode ?? "media";
929
+ const theme = `@theme {
930
+ ${declsFromEntries(lightEntries, sep, "--color-", " ")}
931
+ }`;
932
+ if (darkMode === false) return theme;
933
+ if (darkMode === "media") {
934
+ const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
935
+ return `${theme}
936
+ @media (prefers-color-scheme: dark) {
937
+ :root {
938
+ ${darkInner}
939
+ }
940
+ }`;
941
+ }
942
+ const darkSel = darkSelectorFor(darkMode);
943
+ const darkBlock = `${darkSel} {
944
+ ${declsFromEntries(darkEntries, sep, "--color-", " ")}
945
+ }`;
946
+ return `${theme}
947
+ ${darkBlock}`;
948
+ }
914
949
 
915
950
  // src/format/format.ts
916
951
  function format(palette, options, standaloneTokens) {
917
952
  const entries = buildTokenEntries(palette, options);
918
- if (standaloneTokens) {
919
- entries.push(...standaloneTokens);
920
- }
953
+ if (standaloneTokens) entries.push(...standaloneTokens);
921
954
  const sep = options?.separator ?? "-";
922
955
  switch (options?.as) {
923
- case "css":
924
- return formatCSS(entries, sep);
925
956
  case "scss":
926
957
  return formatSCSS(entries, sep);
927
958
  case "tailwind":
928
959
  return formatTailwind(entries);
929
- case "tailwind-css":
930
- return formatTailwindCSS(entries, sep);
931
960
  case "json":
932
961
  return formatJSON(entries, sep);
933
962
  default:
934
963
  return formatObject(entries, sep);
935
964
  }
936
965
  }
966
+ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, darkStandalone) {
967
+ const lightEntries = buildTokenEntries(lightPalette, options);
968
+ if (lightStandalone) lightEntries.push(...lightStandalone);
969
+ const darkEntries = buildTokenEntries(darkPalette, options);
970
+ if (darkStandalone) darkEntries.push(...darkStandalone);
971
+ const sep = options?.separator ?? "-";
972
+ const stylesheetOpts = {
973
+ selector: options?.selector,
974
+ darkMode: options?.darkMode
975
+ };
976
+ if (options?.as === "tailwind-css") {
977
+ return formatTailwindStylesheet(
978
+ lightEntries,
979
+ darkEntries,
980
+ sep,
981
+ stylesheetOpts
982
+ );
983
+ }
984
+ return formatCSSStylesheet(lightEntries, darkEntries, sep, stylesheetOpts);
985
+ }
937
986
 
938
987
  // src/generate/consts.ts
939
988
  var DEFAULT_LIGHT_THEME_LIGHTNESS = 0.7;
@@ -1707,6 +1756,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1707
1756
  this.darkPalette,
1708
1757
  colorFormat
1709
1758
  );
1759
+ if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
1760
+ return formatStylesheet(
1761
+ this.lightPalette,
1762
+ this.darkPalette,
1763
+ mergedOptions,
1764
+ lightTokens,
1765
+ darkTokens
1766
+ );
1767
+ }
1710
1768
  return {
1711
1769
  light: format(this.lightPalette, mergedOptions, lightTokens),
1712
1770
  dark: format(this.darkPalette, mergedOptions, darkTokens)
@@ -2234,7 +2292,9 @@ Presets:
2234
2292
  Format options:
2235
2293
  -f, --format <type> css | object | tailwind | tailwind-css | scss | json (default: css)
2236
2294
  -c, --colors <type> hex | rgb | hsl | oklch | p3 and -raw variants (default: hex)
2237
- -t, --theme <type> light | dark | both (default: both)
2295
+ -t, --theme <type> light | dark | both (ignored for css/tailwind-css) (default: both)
2296
+ --dark-mode <strategy> media | class | data-attribute | off (css/tailwind-css only, default: media)
2297
+ --selector <css> Root selector for css output (default: :root)
2238
2298
  --separator <char> Token separator (default: -)
2239
2299
  --exclude-role <name> Omit a role from output (repeatable)
2240
2300
  --exclude-variant <name> Omit a variant from output (repeatable)
@@ -2292,6 +2352,8 @@ function run() {
2292
2352
  format: { type: "string", short: "f" },
2293
2353
  colors: { type: "string", short: "c" },
2294
2354
  theme: { type: "string", short: "t", default: "both" },
2355
+ "dark-mode": { type: "string" },
2356
+ selector: { type: "string" },
2295
2357
  separator: { type: "string" },
2296
2358
  "exclude-role": { type: "string", multiple: true },
2297
2359
  "exclude-variant": { type: "string", multiple: true },
@@ -2466,10 +2528,28 @@ function run() {
2466
2528
  if (values["exclude-variant"]?.length) {
2467
2529
  formatOptions.excludeVariants = values["exclude-variant"];
2468
2530
  }
2531
+ if (values["dark-mode"]) {
2532
+ const dm = values["dark-mode"];
2533
+ if (dm === "off" || dm === "false") {
2534
+ formatOptions.darkMode = false;
2535
+ } else if (dm === "media" || dm === "class" || dm === "data-attribute") {
2536
+ formatOptions.darkMode = dm;
2537
+ } else {
2538
+ console.error(
2539
+ `Error: invalid --dark-mode "${dm}". Expected: media | class | data-attribute | off`
2540
+ );
2541
+ process.exit(1);
2542
+ }
2543
+ }
2544
+ if (values.selector) {
2545
+ formatOptions.selector = values.selector;
2546
+ }
2469
2547
  const result = builder.format(formatOptions);
2470
2548
  const themeFilter = values.theme;
2471
2549
  let output;
2472
- if (themeFilter === "light") {
2550
+ if (typeof result === "string") {
2551
+ output = result;
2552
+ } else if (themeFilter === "light") {
2473
2553
  output = serialize(result.light);
2474
2554
  } else if (themeFilter === "dark") {
2475
2555
  output = serialize(result.dark);
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 HextimatePaletteBuilder } from './HextimatePaletteBuilder-xqJwP_G2.js';
2
- export { D as DerivedToken, F as FlatTokenMap, f as FormatResult, g as HextimateFormatOptions, h as HextimateOptions, i as HextimateResult, j as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-xqJwP_G2.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 HextimatePaletteBuilder } from './HextimatePaletteBuilder-C8I05ZmB.js';
2
+ export { D as DerivedToken, F as FlatTokenMap, f as FormatResult, g as HextimateFormatOptions, h as HextimateOptions, i as HextimateResult, j as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-C8I05ZmB.js';
3
3
 
4
4
  /**
5
5
  * Daltonize a color for a specific type of color vision deficiency (CVD).
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  parse,
8
8
  presets_exports,
9
9
  simulateColor
10
- } from "./chunk-2OMHLWID.js";
10
+ } from "./chunk-HCVIQY7G.js";
11
11
  export {
12
12
  HextimateError,
13
13
  HextimatePaletteBuilder,
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
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
+ import { j as HextimateStyleOptions, H as HextimatePreset, e as HextimatePaletteBuilder, i as HextimateResult, F as FlatTokenMap, g as HextimateFormatOptions } from './HextimatePaletteBuilder-C8I05ZmB.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import { PropsWithChildren, RefObject, CSSProperties, ReactNode } from 'react';
4
4
 
@@ -16,11 +16,31 @@ type DarkModeStrategy = {
16
16
  } | false;
17
17
  type ModePreference = 'light' | 'dark' | 'system';
18
18
  type ResolvedMode = 'light' | 'dark';
19
+ /** A single color (used for both modes) or a per-mode pair. */
20
+ type ColorInputProp = string | {
21
+ light: string;
22
+ dark: string;
23
+ };
24
+ /** A per-mode color pair. */
25
+ interface ModeColors {
26
+ light: string;
27
+ dark: string;
28
+ }
19
29
 
20
30
  interface HextimatorContextValue {
31
+ /** Active brand color for the current mode. */
21
32
  color: string;
33
+ /** Set the brand color for both modes at once. */
22
34
  setColor: (color: string) => void;
35
+ /** Brand color used in light mode. */
36
+ lightColor: string;
37
+ setLightColor: (color: string) => void;
38
+ /** Brand color used in dark mode. */
39
+ darkColor: string;
40
+ setDarkColor: (color: string) => void;
41
+ /** Resolved mode (`'light'` or `'dark'`). */
23
42
  mode: ResolvedMode;
43
+ /** Raw preference (`'light'`, `'dark'`, or `'system'`). */
24
44
  modePreference: ModePreference;
25
45
  setMode: (mode: ModePreference) => void;
26
46
  style: HextimateStyleOptions | undefined;
@@ -29,28 +49,21 @@ interface HextimatorContextValue {
29
49
  setPresets: (presets: HextimatePreset[] | undefined) => void;
30
50
  configure: ((builder: HextimatePaletteBuilder) => void) | undefined;
31
51
  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
- */
52
+ /** Generated `{ light, dark }` palette as flat token maps (e.g. `{ base: '#...', 'base-strong': '#...' }`). */
53
+ palette: HextimateResult<FlatTokenMap>;
54
+ /** Underlying palette builder. Nested scopes fork from it. */
38
55
  builder: HextimatePaletteBuilder;
39
56
  }
40
57
 
41
- /**
42
- * Props for the `HextimatorProvider` component, which manages the state of a Hextimator-generated color palette and injects corresponding CSS variables into the document.
43
- * - `defaultColor`: The initial base color to generate the palette from.
44
- * - `style`: Initial options for how the palette is generated (e.g., light/dark settings, contrast requirements).
45
- * - `format`: Initial options for how the generated palette is formatted (e.g., output format).
46
- * - `configure`: An initial callback to further customize the palette builder before formatting.
47
- * - `darkMode`: Strategy for handling dark mode variants in CSS variable injection.
48
- * - `cssPrefix`: A prefix to apply to all generated CSS variable names.
49
- * - `target`: An optional ref to a specific DOM element where CSS variables should be injected instead of the document root.
50
- */
51
58
  interface HextimatorProviderProps {
52
- defaultColor: string;
59
+ /** Brand color. String sets the same color for both modes; object sets a different color for each mode. */
60
+ defaultColor: ColorInputProp;
61
+ /** Called when the color changes. */
62
+ onColorChange?: (next: ModeColors) => void;
63
+ /** Initial mode. Defaults to `'system'`. */
53
64
  defaultMode?: ModePreference;
65
+ /** Called when the mode changes. */
66
+ onModePreferenceChange?: (mode: ModePreference) => void;
54
67
  style?: HextimateStyleOptions;
55
68
  presets?: HextimatePreset[];
56
69
  format?: Omit<HextimateFormatOptions, 'as'>;
@@ -60,49 +73,21 @@ interface HextimatorProviderProps {
60
73
  target?: RefObject<HTMLElement | null>;
61
74
  }
62
75
  /**
76
+ * Provides a hextimator theme to its children.
63
77
  *
64
- * A React context provider that manages the state of
65
- * a Hextimator-generated color palette and injects corresponding CSS variables into the document.
66
- * It allows child components to access and update the
67
- * base color, style options, and configuration callback, automatically
68
- * regenerating the palette and updating CSS variables as needed.
69
-
70
- * The Provider accepts props for the default color, style options, formatting options,
71
- * dark mode strategy, CSS variable prefix, and an optional target element for CSS variable injection.
72
- * It uses the `useHextimator` hook to generate the palette and handles the injection of CSS variables based on the current state.
73
- *
74
- * Example usage:
78
+ * @example
75
79
  * ```tsx
76
- * <HextimatorProvider defaultColor="#ff6600" style={{ minContrastRatio: 'AA' }} darkMode={{ type: 'class', className: 'dark' }} cssPrefix="--myapp-">
77
- * <App />
80
+ * <HextimatorProvider defaultColor="#ff6600">
81
+ * <App />
78
82
  * </HextimatorProvider>
79
83
  * ```
80
84
  */
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;
85
+ declare function HextimatorProvider({ children, defaultColor, onColorChange, defaultMode: initialMode, onModePreferenceChange, style: initialStyle, presets: initialPresets, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, target, }: PropsWithChildren<HextimatorProviderProps>): react_jsx_runtime.JSX.Element;
82
86
 
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
87
  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
- */
88
+ /** Brand color for this subtree. String sets the same color for both modes; object sets a different color for each mode. */
89
+ defaultColor: ColorInputProp;
90
+ /** When true, ignores any parent provider/scope and builds the theme from scratch. */
106
91
  isolated?: boolean;
107
92
  style?: HextimateStyleOptions;
108
93
  presets?: HextimatePreset[];
@@ -111,40 +96,19 @@ interface HextimatorScopeProps {
111
96
  darkMode?: DarkModeStrategy;
112
97
  cssPrefix?: string;
113
98
  className?: string;
114
- /** Inline styles for the scope wrapper element (not palette options; use `style` for those). */
99
+ /** Inline styles for the wrapper `<div>`. */
115
100
  wrapperStyle?: CSSProperties;
116
101
  children?: ReactNode;
117
102
  }
118
103
  /**
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.
104
+ * Themes a single subtree with its own brand color. Inherits the shape (roles,
105
+ * variants, presets) of any parent provider or scope unless `isolated` is set.
129
106
  *
130
107
  * @example
131
108
  * ```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>
109
+ * <HextimatorScope defaultColor="#0066ff">
110
+ * <Card />
111
+ * </HextimatorScope>
148
112
  * ```
149
113
  */
150
114
  declare function HextimatorScope({ defaultColor, isolated, style: initialStyle, presets: initialPresets, format: formatOpts, configure: initialConfigure, darkMode, cssPrefix, className, wrapperStyle, children, }: HextimatorScopeProps): react_jsx_runtime.JSX.Element;
@@ -235,24 +199,12 @@ interface UseHextimatorOptions {
235
199
  declare function useHextimator(color: string, options?: UseHextimatorOptions): HextimateResult<FlatTokenMap>;
236
200
 
237
201
  /**
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.
242
- *
243
- * Returned properties:
244
- * - `color` / `setColor` — the current base color for this scope or provider.
245
- * - `mode` — the resolved color mode (`'light'` or `'dark'`), accounting for OS preference when set to `'system'`.
246
- * - `modePreference` — the raw preference (`'light'`, `'dark'`, or `'system'`).
247
- * - `setMode` — update the mode preference. Pass `'system'` to follow the OS.
248
- * - `style` / `setStyle` — palette style options.
249
- * - `configure` / `setConfigure` — builder configuration callback.
250
- * - `palette` — the generated `HextimateResult`.
202
+ * Reads the current theme from the nearest `HextimatorProvider` or
203
+ * `HextimatorScope`. See `HextimatorContextValue` for the returned fields.
251
204
  *
252
205
  * @example
253
206
  * ```tsx
254
207
  * const { mode, setMode } = useHextimatorTheme();
255
- *
256
208
  * <button onClick={() => setMode(mode === 'dark' ? 'light' : 'dark')}>
257
209
  * Toggle dark mode
258
210
  * </button>
@@ -262,4 +214,4 @@ declare function useHextimator(color: string, options?: UseHextimatorOptions): H
262
214
  */
263
215
  declare function useHextimatorTheme(): HextimatorContextValue;
264
216
 
265
- export { type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, HextimatorScope, type HextimatorScopeProps, HextimatorStyle, type HextimatorStyleProps, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };
217
+ export { type ColorInputProp, type HextimatorContextValue, HextimatorProvider, type HextimatorProviderProps, HextimatorScope, type HextimatorScopeProps, HextimatorStyle, type HextimatorStyleProps, type ModeColors, type ModePreference, type ResolvedMode, type UseHextimatorOptions, useHextimator, useHextimatorTheme };