hextimator 0.4.0 → 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 +24 -1
- package/dist/{HextimatePaletteBuilder-xqJwP_G2.d.ts → HextimatePaletteBuilder-C8I05ZmB.d.ts} +28 -5
- package/dist/{chunk-2OMHLWID.js → chunk-HCVIQY7G.js} +81 -23
- package/dist/cli.js +105 -25
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.d.ts +3 -3
- package/dist/react.js +10 -12
- package/llms.txt +16 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
## 0.
|
|
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
|
|
2
25
|
|
|
3
26
|
- [#106](https://github.com/fgrgic/hextimator/pull/106): add per-theme color for React
|
|
4
27
|
- React provider and scope now accept per-mode brand colors (`defaultColor: string | { light, dark }`)
|
package/dist/{HextimatePaletteBuilder-xqJwP_G2.d.ts → HextimatePaletteBuilder-C8I05ZmB.d.ts}
RENAMED
|
@@ -251,13 +251,33 @@ interface HextimateFormatOptions {
|
|
|
251
251
|
/**
|
|
252
252
|
* Output format.
|
|
253
253
|
* - "object" (default): { base: "#f2eee8", "base-strong": "#d4cfc8", ...}
|
|
254
|
-
* - "css": {
|
|
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":
|
|
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'
|
|
546
|
+
as: 'json';
|
|
527
547
|
}): HextimateResult<string>;
|
|
528
548
|
format(options: HextimateFormatOptions & {
|
|
529
|
-
as: '
|
|
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
|
|
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 (
|
|
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-
|
|
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-
|
|
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
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as HextimateStyleOptions, H as HextimatePreset, e as HextimatePaletteBuilder, i as HextimateResult,
|
|
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
|
|
|
@@ -49,8 +49,8 @@ interface HextimatorContextValue {
|
|
|
49
49
|
setPresets: (presets: HextimatePreset[] | undefined) => void;
|
|
50
50
|
configure: ((builder: HextimatePaletteBuilder) => void) | undefined;
|
|
51
51
|
setConfigure: (fn: ((builder: HextimatePaletteBuilder) => void) | undefined) => void;
|
|
52
|
-
/** Generated `{ light, dark }` palette. */
|
|
53
|
-
palette: HextimateResult
|
|
52
|
+
/** Generated `{ light, dark }` palette as flat token maps (e.g. `{ base: '#...', 'base-strong': '#...' }`). */
|
|
53
|
+
palette: HextimateResult<FlatTokenMap>;
|
|
54
54
|
/** Underlying palette builder. Nested scopes fork from it. */
|
|
55
55
|
builder: HextimatePaletteBuilder;
|
|
56
56
|
}
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
hextimate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HCVIQY7G.js";
|
|
4
4
|
|
|
5
5
|
// src/react/hextimator-provider.tsx
|
|
6
6
|
import {
|
|
@@ -20,7 +20,7 @@ var HextimatorContext = createContext(
|
|
|
20
20
|
function buildStyleContent(palette, darkMode, cssPrefix, selector = ":root") {
|
|
21
21
|
const lightEntries = Object.entries(palette.light);
|
|
22
22
|
const darkEntries = Object.entries(palette.dark);
|
|
23
|
-
const toVars = (entries, lineIndent) => entries.map(([key, value]) => `${lineIndent}${cssPrefix}
|
|
23
|
+
const toVars = (entries, lineIndent) => entries.map(([key, value]) => `${lineIndent}${cssPrefix}--${key}: ${value};`).join("\n");
|
|
24
24
|
const lightVars = toVars(lightEntries, " ");
|
|
25
25
|
const darkVars = toVars(darkEntries, " ");
|
|
26
26
|
const darkVarsInMediaInner = toVars(darkEntries, " ");
|
|
@@ -86,12 +86,10 @@ ${darkVars}
|
|
|
86
86
|
}
|
|
87
87
|
function buildTargetedVars(palette, darkMode, cssPrefix) {
|
|
88
88
|
const prefixEntries = (entries) => entries.map(
|
|
89
|
-
([key, value]) => [`${cssPrefix}
|
|
89
|
+
([key, value]) => [`${cssPrefix}--${key}`, value]
|
|
90
90
|
);
|
|
91
91
|
return {
|
|
92
|
-
light: prefixEntries(
|
|
93
|
-
Object.entries(palette.light)
|
|
94
|
-
),
|
|
92
|
+
light: prefixEntries(Object.entries(palette.light)),
|
|
95
93
|
dark: darkMode !== false ? prefixEntries(Object.entries(palette.dark)) : []
|
|
96
94
|
};
|
|
97
95
|
}
|
|
@@ -263,12 +261,12 @@ function HextimatorProvider({
|
|
|
263
261
|
const palette = useMemo(() => {
|
|
264
262
|
const lightResult = lightBuilder.format({
|
|
265
263
|
...stable?.format,
|
|
266
|
-
as: "
|
|
264
|
+
as: "object"
|
|
267
265
|
});
|
|
268
266
|
if (darkBuilder === lightBuilder) return lightResult;
|
|
269
267
|
const darkResult = darkBuilder.format({
|
|
270
268
|
...stable?.format,
|
|
271
|
-
as: "
|
|
269
|
+
as: "object"
|
|
272
270
|
});
|
|
273
271
|
return { light: lightResult.light, dark: darkResult.dark };
|
|
274
272
|
}, [lightBuilder, darkBuilder, stable?.format]);
|
|
@@ -426,12 +424,12 @@ function HextimatorScope({
|
|
|
426
424
|
const palette = useMemo2(() => {
|
|
427
425
|
const lightResult = lightBuilder.format({
|
|
428
426
|
...stable?.format,
|
|
429
|
-
as: "
|
|
427
|
+
as: "object"
|
|
430
428
|
});
|
|
431
429
|
if (darkBuilder === lightBuilder) return lightResult;
|
|
432
430
|
const darkResult = darkBuilder.format({
|
|
433
431
|
...stable?.format,
|
|
434
|
-
as: "
|
|
432
|
+
as: "object"
|
|
435
433
|
});
|
|
436
434
|
return { light: lightResult.light, dark: darkResult.dark };
|
|
437
435
|
}, [lightBuilder, darkBuilder, stable?.format]);
|
|
@@ -531,7 +529,7 @@ function HextimatorStyle({
|
|
|
531
529
|
configure?.(builder);
|
|
532
530
|
const palette = builder.format({
|
|
533
531
|
...stable?.format,
|
|
534
|
-
as: "
|
|
532
|
+
as: "object"
|
|
535
533
|
});
|
|
536
534
|
return buildStyleContent(
|
|
537
535
|
palette,
|
|
@@ -559,7 +557,7 @@ function useHextimator(color, options) {
|
|
|
559
557
|
configure?.(builder);
|
|
560
558
|
return builder.format({
|
|
561
559
|
...stable?.format,
|
|
562
|
-
as: "
|
|
560
|
+
as: "object"
|
|
563
561
|
});
|
|
564
562
|
}, [color, stable?.style, presets, stable?.format, configure]);
|
|
565
563
|
const darkMode = stable?.darkMode ?? { type: "media" };
|
package/llms.txt
CHANGED
|
@@ -17,9 +17,9 @@ import { hextimate } from "hextimator";
|
|
|
17
17
|
const theme = hextimate("#6A5ACD").format();
|
|
18
18
|
// → { light: { accent: "#6a5acd", "accent-strong": "...", ... }, dark: { ... } }
|
|
19
19
|
|
|
20
|
-
// With format options
|
|
20
|
+
// With format options — `as: "css"` returns a ready-to-paste stylesheet string
|
|
21
21
|
const css = hextimate("#6A5ACD").format({ as: "css", colors: "oklch" });
|
|
22
|
-
// →
|
|
22
|
+
// → ":root { --accent: oklch(...); ... }\n@media (prefers-color-scheme: dark) { :root { ... } }"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## API
|
|
@@ -48,7 +48,7 @@ Tune how the palette is built with `.style(partial)` (`HextimateStyleOptions`, s
|
|
|
48
48
|
| `.fork(color?)` | Clone builder with optional new accent color. Chain `.style()` on the fork to change style options. Original unchanged |
|
|
49
49
|
| `.format(options?)` | Output the palette (see format options) |
|
|
50
50
|
|
|
51
|
-
### `.format(options?)` → `{ light: FormatResult, dark: FormatResult }`
|
|
51
|
+
### `.format(options?)` → `{ light: FormatResult, dark: FormatResult }` or `string`
|
|
52
52
|
|
|
53
53
|
| Option | Values | Default |
|
|
54
54
|
|---|---|---|
|
|
@@ -57,16 +57,20 @@ Tune how the palette is built with `.style(partial)` (`HextimateStyleOptions`, s
|
|
|
57
57
|
| `roleNames` | `Record<string, string>` — rename roles in output keys | built-in names |
|
|
58
58
|
| `variantNames` | `Record<string, string>` — rename variant suffixes | built-in names |
|
|
59
59
|
| `separator` | `string` — between role and variant in keys | `"-"` |
|
|
60
|
+
| `darkMode` | `"media"`, `"class"`, `"data-attribute"`, `false` (stylesheet outputs only) | `"media"` |
|
|
61
|
+
| `selector` | `string` — root selector for `as: "css"` | `":root"` |
|
|
60
62
|
| `excludeRoles` | `string[]` — role keys to omit entirely from output (by internal name, before `roleNames`) | `[]` |
|
|
61
63
|
| `excludeVariants` | `string[]` — variant keys to omit from every role's output (by internal name, before `variantNames`) | `[]` |
|
|
62
64
|
|
|
63
65
|
Output shape depends on `as`:
|
|
64
|
-
- `"object"` → `
|
|
65
|
-
- `"css"` → `
|
|
66
|
-
- `"tailwind"` → nested
|
|
67
|
-
- `"tailwind-css"` → string: `@theme { --color-accent: #...; }`
|
|
68
|
-
- `"scss"` → `
|
|
69
|
-
- `"json"` → JSON
|
|
66
|
+
- `"object"` → `{ light, dark }` flat maps: `{ accent: "#...", "accent-strong": "#..." }`
|
|
67
|
+
- `"css"` → `string` — ready-to-paste CSS stylesheet with `:root {}` and a dark-mode wrapper
|
|
68
|
+
- `"tailwind"` → `{ light, dark }` nested maps: `{ accent: { DEFAULT: "#...", strong: "#..." } }`
|
|
69
|
+
- `"tailwind-css"` → `string` — Tailwind v4 stylesheet: single `@theme { --color-accent: #...; }` block plus dark overrides
|
|
70
|
+
- `"scss"` → `{ light, dark }` flat maps: `{ "$accent": "#...", "$accent-strong": "#..." }`
|
|
71
|
+
- `"json"` → `{ light, dark }` JSON strings
|
|
72
|
+
|
|
73
|
+
Pick the dark wrapper with `darkMode`: `"media"` (default) wraps dark tokens in `@media (prefers-color-scheme: dark)`; `"class"` uses `.dark`; `"data-attribute"` uses `[data-theme="dark"]`; `false` omits dark entirely. For `as: "css"`, change the root selector with `selector` (e.g. `selector: "[data-theme]"`).
|
|
70
74
|
|
|
71
75
|
### Style options (`HextimateStyleOptions`)
|
|
72
76
|
|
|
@@ -291,9 +295,11 @@ Both commands are identical. Use whichever you prefer.
|
|
|
291
295
|
|---|---|---|
|
|
292
296
|
| `-f, --format` | `css`, `object`, `tailwind`, `tailwind-css`, `scss`, `json` | `css` |
|
|
293
297
|
| `-c, --colors` | `hex`, `rgb`, `rgb-raw`, `hsl`, `hsl-raw`, `oklch`, `oklch-raw`, `p3`, `p3-raw` | `hex` |
|
|
294
|
-
| `-t, --theme` | `light`, `dark`, `both` | `both` |
|
|
298
|
+
| `-t, --theme` | `light`, `dark`, `both` (ignored for `css`/`tailwind-css` — both always combine into one string) | `both` |
|
|
295
299
|
| `-p, --preset` | Apply preset (repeatable, applied in order): `shadcn`, `mui`, `muted`, `vibrant`, `tinted` | — |
|
|
296
300
|
| `--separator` | Token separator between role and variant | `-` |
|
|
301
|
+
| `--dark-mode` | `media`, `class`, `data-attribute`, `false` (stylesheet outputs only) | `media` |
|
|
302
|
+
| `--selector` | Root selector for `--format css` | `:root` |
|
|
297
303
|
| `--exclude-role` | Omit a role from output by internal name (repeatable) | — |
|
|
298
304
|
| `--exclude-variant` | Omit a variant from output by internal name (repeatable) | — |
|
|
299
305
|
| `--base-color` | Override base color | — |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hextimator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Generate perceptually uniform color palettes with light/dark themes and WCAG contrast guarantees from a single brand color. Outputs CSS vars, Tailwind, SCSS, or JSON.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"color",
|