hextimator 0.6.0 → 0.8.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 +29 -1
- package/README.md +7 -4
- package/dist/{HextimatePaletteBuilder-BH1jrzj7.d.ts → HextimatePaletteBuilder-CNjOKwbY.d.ts} +47 -3
- package/dist/{chunk-QQZBI4SO.js → chunk-KFH2N7CF.js} +51 -12
- package/dist/{chunk-KFR2LTS2.js → chunk-NTF3K3U3.js} +4 -4
- package/dist/cli.js +60 -16
- package/dist/{index-Cd9eX-1l.d.ts → index-kecVj5cB.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -2
- package/llms.txt +6 -4
- package/package.json +3 -1
- package/tailwind-inverted.css +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
##
|
|
1
|
+
## Unreleased
|
|
2
|
+
|
|
3
|
+
- Adds optional `keyPrefix` on `HextimateFormatOptions` for flat `as: "object"` and `as: "json"` output (CLI: `--key-prefix`). Use `keyPrefix: "--"` when you want CSS custom property names as object keys without using stylesheet output.
|
|
4
|
+
|
|
5
|
+
## 0.7.0 (Latest)
|
|
6
|
+
|
|
7
|
+
- Adds an opt-in `invertedVariants: true` format option that emits an -inverted copy of every token holding the opposite mode's value, plus a companion hextimator/tailwind-inverted.css so utilities like `bg-surface-inverted` just work.
|
|
8
|
+
|
|
9
|
+
- Renamed `ThemeAdjustments.lightness` → `baseLightness` to disambiguate it from the _relative_ `lightness` offset used by `addToken({ from, lightness })`. Same word was doing two different jobs (absolute theme anchor vs. relative offset), which made the API confusing.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before (0.6)
|
|
13
|
+
hextimate(color).style({
|
|
14
|
+
light: { lightness: 0.7 },
|
|
15
|
+
dark: { lightness: 0.6 },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// After (0.7)
|
|
19
|
+
hextimate(color).style({
|
|
20
|
+
light: { baseLightness: 0.7 },
|
|
21
|
+
dark: { baseLightness: 0.6 },
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The old `lightness` field still works as a deprecated alias and emits a one-time `console.warn`.
|
|
26
|
+
|
|
27
|
+
Migration checklist: [migration.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md).
|
|
28
|
+
|
|
29
|
+
## 0.6.0
|
|
2
30
|
|
|
3
31
|
- [#114](https://github.com/fgrgic/hextimator/pull/114) **Breaking**. Uses `surface` instead of `base` for the background tokens (e.g. `base-strong` → `surface-strong`). This avoids a class-name collision with Tailwind's built-in text-base font-size utility and makes the token name match its semantic purpose (the surface behind your content).
|
|
4
32
|
|
package/README.md
CHANGED
|
@@ -175,12 +175,12 @@ Both options use internal names (before any `roleNames`/`variantNames` remapping
|
|
|
175
175
|
|
|
176
176
|
All formats return `{ light: { ... }, dark: { ... } }`.
|
|
177
177
|
|
|
178
|
-
- **`"object"`** (default) — plain keys: `accent`, `accent-strong`, …
|
|
178
|
+
- **`"object"`** (default) — plain keys: `accent`, `accent-strong`, … Optional **`keyPrefix: "--"`** gives `--accent`, `--accent-strong`, … when you need CSS-style names without stylesheet output.
|
|
179
179
|
- **`"css"`** — CSS custom properties: `--accent`, `--accent-strong`, …
|
|
180
180
|
- **`"tailwind"`** — nested tokens: `{ accent: { DEFAULT, strong, … } }`
|
|
181
181
|
- **`"tailwind-css"`** — `@theme` block with `--color-accent`, `--color-accent-strong`, …
|
|
182
182
|
- **`"scss"`** — SCSS variables: `$accent`, `$accent-strong`, …
|
|
183
|
-
- **`"json"`** — JSON string of the plain object
|
|
183
|
+
- **`"json"`** — JSON string of the plain object (supports **`keyPrefix`** the same way as **`object`**)
|
|
184
184
|
|
|
185
185
|
### Color value formats
|
|
186
186
|
|
|
@@ -262,16 +262,19 @@ Does not match **preset-only** token names (e.g. shadcn); use the CLI to generat
|
|
|
262
262
|
|
|
263
263
|
## Documentation
|
|
264
264
|
|
|
265
|
-
- [
|
|
265
|
+
- [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — style and format options reference
|
|
266
266
|
- [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) — `addRole`, `addVariant`, `addToken`
|
|
267
267
|
- [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md) — drop-in configs for shadcn/ui, or create your own
|
|
268
268
|
- [Multiple themes](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/multiple-themes.md) — dynamic theming and `.fork()`
|
|
269
|
-
- [Customization](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/customization.md) — style and format options reference
|
|
270
269
|
- [Color vision deficiency](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/color-vision-deficiency.md) — simulate and adapt for CVD
|
|
271
270
|
- [React](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md) — hook, `HextimatorStyle`, provider, scoped themes, dark mode
|
|
272
271
|
- [Tailwind CSS v4](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/tailwind.md) — setup and usage with Tailwind
|
|
273
272
|
- [Real-world examples](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/examples.md) — shadcn/ui, Stripe, Slack configurations
|
|
274
273
|
|
|
274
|
+
### For migrating from previous versions
|
|
275
|
+
|
|
276
|
+
- [Migration guide](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md) — breaking changes by version
|
|
277
|
+
|
|
275
278
|
## Contributing
|
|
276
279
|
|
|
277
280
|
Issues and PRs are welcome at [github.com/fgrgic/hextimator](https://github.com/fgrgic/hextimator/issues).
|
package/dist/{HextimatePaletteBuilder-BH1jrzj7.d.ts → HextimatePaletteBuilder-CNjOKwbY.d.ts}
RENAMED
|
@@ -75,10 +75,19 @@ type ColorInput = HexString | CSSColorString | ColorTuple | Color | number;
|
|
|
75
75
|
*/
|
|
76
76
|
interface ThemeAdjustments {
|
|
77
77
|
/**
|
|
78
|
-
* Absolute OKLCH lightness for this theme (0–1).
|
|
78
|
+
* Absolute OKLCH lightness anchor for this theme's accent color (0–1).
|
|
79
|
+
*
|
|
80
|
+
* This is the *baseline* the palette is generated around — distinct from
|
|
81
|
+
* the *relative* `lightness` offsets used by `addToken({ from, lightness })`.
|
|
79
82
|
*
|
|
80
83
|
* Default: 0.7 for light, 0.6 for dark.
|
|
81
84
|
*/
|
|
85
|
+
baseLightness?: number;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Renamed to `baseLightness` in 0.7.0 to disambiguate it from
|
|
88
|
+
* the relative `lightness` offset used by `addToken({ from, lightness })`.
|
|
89
|
+
* Still works as a fallback. Will be removed in a future release.
|
|
90
|
+
*/
|
|
82
91
|
lightness?: number;
|
|
83
92
|
/**
|
|
84
93
|
* Maximum chroma for accent/semantic colors in this theme.
|
|
@@ -248,9 +257,19 @@ interface HextimateFormatOptions {
|
|
|
248
257
|
* Use "_" for "surface_strong", "/" for "surface/strong", etc.
|
|
249
258
|
*/
|
|
250
259
|
separator?: string;
|
|
260
|
+
/**
|
|
261
|
+
* String prepended to every flat token key in `as: "object"` and `as: "json"`.
|
|
262
|
+
* Use `"--"` for CSS custom property names (`"--surface"`, `"--accent-strong"`).
|
|
263
|
+
*
|
|
264
|
+
* Ignored for `scss` (`$` prefix), nested `tailwind`, and stylesheet outputs
|
|
265
|
+
* (`css`, `tailwind-css` already declare variables with `--`).
|
|
266
|
+
*
|
|
267
|
+
* Default: `""` (no prefix).
|
|
268
|
+
*/
|
|
269
|
+
keyPrefix?: string;
|
|
251
270
|
/**
|
|
252
271
|
* Output format.
|
|
253
|
-
* - "object" (default): { surface: "#f2eee8", "surface-strong": "#d4cfc8", ...}
|
|
272
|
+
* - "object" (default): { surface: "#f2eee8", "surface-strong": "#d4cfc8", ...} or with keyPrefix "--": { "--surface": "...", "--surface-strong": "..." }
|
|
254
273
|
* - "css": ready-to-paste CSS stylesheet string with `:root {}` and a dark-mode wrapper
|
|
255
274
|
* - "tailwind": { surface: { DEFAULT: "#f2eee8", strong: "#d4cfc8", weak: "#faf8f6" } }
|
|
256
275
|
* - "scss": { $surface: "#f2eee8", $surface-strong: "#d4cfc8", ...}
|
|
@@ -306,6 +325,30 @@ interface HextimateFormatOptions {
|
|
|
306
325
|
* Example: `['strong', 'weak']` removes those variants from all roles.
|
|
307
326
|
*/
|
|
308
327
|
excludeVariants?: string[];
|
|
328
|
+
/**
|
|
329
|
+
* Emit an extra `-inverted` copy of every token whose value is the
|
|
330
|
+
* opposite mode's value (light tokens get dark values, dark tokens get
|
|
331
|
+
* light values). Inverted tokens flip with the active mode, just like
|
|
332
|
+
* regular tokens.
|
|
333
|
+
*
|
|
334
|
+
* Use for sections that intentionally contrast with the surrounding
|
|
335
|
+
* theme: testimonials, alternating stripes, hero callouts, "spotlight"
|
|
336
|
+
* panels. One class (`bg-surface-inverted`) flips both ways.
|
|
337
|
+
*
|
|
338
|
+
* For "always this mode" sections, compose with the dark-mode variant:
|
|
339
|
+
* - Always dark: `bg-surface-inverted dark:bg-surface`
|
|
340
|
+
* - Always light: `bg-surface dark:bg-surface-inverted`
|
|
341
|
+
*
|
|
342
|
+
* Example output (flat keys):
|
|
343
|
+
* - `accent-inverted`, `accent-strong-inverted`, `accent-foreground-inverted`
|
|
344
|
+
*
|
|
345
|
+
* Tailwind users need to pair this with the companion stylesheet:
|
|
346
|
+
* `@import "hextimator/tailwind-inverted.css";` to get utilities like
|
|
347
|
+
* `bg-accent-inverted`, `text-accent-foreground-inverted`.
|
|
348
|
+
*
|
|
349
|
+
* Default: `false`.
|
|
350
|
+
*/
|
|
351
|
+
invertedVariants?: boolean;
|
|
309
352
|
}
|
|
310
353
|
/**
|
|
311
354
|
* Combined options for the convenience API.
|
|
@@ -537,7 +580,7 @@ declare class HextimatePaletteBuilder {
|
|
|
537
580
|
* When a preset has been applied, its format options are used as defaults.
|
|
538
581
|
* Any options passed here override the preset's defaults.
|
|
539
582
|
*
|
|
540
|
-
* @param options Format options controlling output shape (`as`), color serialization (`colors`), role/variant renaming, and
|
|
583
|
+
* @param options Format options controlling output shape (`as`), color serialization (`colors`), role/variant renaming, separator, and optional flat-key `keyPrefix`.
|
|
541
584
|
*/
|
|
542
585
|
format(options: HextimateFormatOptions & {
|
|
543
586
|
as: 'tailwind';
|
|
@@ -552,6 +595,7 @@ declare class HextimatePaletteBuilder {
|
|
|
552
595
|
as: 'object' | 'scss';
|
|
553
596
|
}): HextimateResult<FlatTokenMap>;
|
|
554
597
|
format(options?: HextimateFormatOptions): HextimateResult | string;
|
|
598
|
+
private buildInvertedEntries;
|
|
555
599
|
private applyRole;
|
|
556
600
|
private applyVariant;
|
|
557
601
|
private applyToken;
|
|
@@ -856,16 +856,22 @@ function buildTokenEntries(palette, options) {
|
|
|
856
856
|
}
|
|
857
857
|
return entries;
|
|
858
858
|
}
|
|
859
|
+
function withInvertedSuffix(entry, sep) {
|
|
860
|
+
if (entry.isDefault && entry.variant === "DEFAULT") {
|
|
861
|
+
return { ...entry, isDefault: false, variant: "inverted" };
|
|
862
|
+
}
|
|
863
|
+
return { ...entry, variant: `${entry.variant}${sep}inverted` };
|
|
864
|
+
}
|
|
859
865
|
|
|
860
866
|
// src/format/formatters.ts
|
|
861
867
|
function toFlatKey(entry, sep) {
|
|
862
868
|
if (entry.isDefault && entry.variant === "DEFAULT") return entry.role;
|
|
863
869
|
return `${entry.role}${sep}${entry.variant}`;
|
|
864
870
|
}
|
|
865
|
-
function formatObject(entries, sep) {
|
|
871
|
+
function formatObject(entries, sep, keyPrefix = "") {
|
|
866
872
|
const result = {};
|
|
867
873
|
for (const entry of entries) {
|
|
868
|
-
result[toFlatKey(entry, sep)] = entry.value;
|
|
874
|
+
result[`${keyPrefix}${toFlatKey(entry, sep)}`] = entry.value;
|
|
869
875
|
}
|
|
870
876
|
return result;
|
|
871
877
|
}
|
|
@@ -884,8 +890,8 @@ function formatTailwind(entries) {
|
|
|
884
890
|
}
|
|
885
891
|
return result;
|
|
886
892
|
}
|
|
887
|
-
function formatJSON(entries, sep) {
|
|
888
|
-
return JSON.stringify(formatObject(entries, sep), null, 2);
|
|
893
|
+
function formatJSON(entries, sep, keyPrefix = "") {
|
|
894
|
+
return JSON.stringify(formatObject(entries, sep, keyPrefix), null, 2);
|
|
889
895
|
}
|
|
890
896
|
function declsFromEntries(entries, sep, prefix, indent) {
|
|
891
897
|
return entries.map((e) => `${indent}${prefix}${toFlatKey(e, sep)}: ${e.value};`).join("\n");
|
|
@@ -944,15 +950,16 @@ function format(palette, options, standaloneTokens) {
|
|
|
944
950
|
const entries = buildTokenEntries(palette, options);
|
|
945
951
|
if (standaloneTokens) entries.push(...standaloneTokens);
|
|
946
952
|
const sep = options?.separator ?? "-";
|
|
953
|
+
const keyPrefix = options?.keyPrefix ?? "";
|
|
947
954
|
switch (options?.as) {
|
|
948
955
|
case "scss":
|
|
949
956
|
return formatSCSS(entries, sep);
|
|
950
957
|
case "tailwind":
|
|
951
958
|
return formatTailwind(entries);
|
|
952
959
|
case "json":
|
|
953
|
-
return formatJSON(entries, sep);
|
|
960
|
+
return formatJSON(entries, sep, keyPrefix);
|
|
954
961
|
default:
|
|
955
|
-
return formatObject(entries, sep);
|
|
962
|
+
return formatObject(entries, sep, keyPrefix);
|
|
956
963
|
}
|
|
957
964
|
}
|
|
958
965
|
function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, darkStandalone) {
|
|
@@ -1164,11 +1171,19 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1164
1171
|
}
|
|
1165
1172
|
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
|
|
1166
1173
|
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1174
|
+
var warnedLegacyLightness = false;
|
|
1167
1175
|
function resolveThemeLightness(themeType, options) {
|
|
1168
1176
|
const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
|
|
1169
1177
|
const range = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
|
|
1170
|
-
|
|
1171
|
-
|
|
1178
|
+
const value = themeAdjustments?.baseLightness ?? themeAdjustments?.lightness;
|
|
1179
|
+
if (themeAdjustments?.baseLightness === void 0 && themeAdjustments?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
|
|
1180
|
+
warnedLegacyLightness = true;
|
|
1181
|
+
console.warn(
|
|
1182
|
+
"[hextimator] `style({ light/dark: { lightness } })` is deprecated. Rename to `baseLightness` to disambiguate from the relative `lightness` offset used by `addToken({ from, lightness })`. Will be removed in a future release."
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
if (value !== void 0) {
|
|
1186
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1172
1187
|
}
|
|
1173
1188
|
return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
|
|
1174
1189
|
}
|
|
@@ -1751,18 +1766,42 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1751
1766
|
this.darkPalette,
|
|
1752
1767
|
colorFormat
|
|
1753
1768
|
);
|
|
1769
|
+
const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(mergedOptions, lightTokens, darkTokens) : { lightBlock: [], darkBlock: [] };
|
|
1754
1770
|
if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
|
|
1755
1771
|
return formatStylesheet(
|
|
1756
1772
|
this.lightPalette,
|
|
1757
1773
|
this.darkPalette,
|
|
1758
1774
|
mergedOptions,
|
|
1759
|
-
lightTokens,
|
|
1760
|
-
darkTokens
|
|
1775
|
+
[...lightTokens, ...inverted.lightBlock],
|
|
1776
|
+
[...darkTokens, ...inverted.darkBlock]
|
|
1761
1777
|
);
|
|
1762
1778
|
}
|
|
1763
1779
|
return {
|
|
1764
|
-
light: format(this.lightPalette, mergedOptions,
|
|
1765
|
-
|
|
1780
|
+
light: format(this.lightPalette, mergedOptions, [
|
|
1781
|
+
...lightTokens,
|
|
1782
|
+
...inverted.lightBlock
|
|
1783
|
+
]),
|
|
1784
|
+
dark: format(this.darkPalette, mergedOptions, [
|
|
1785
|
+
...darkTokens,
|
|
1786
|
+
...inverted.darkBlock
|
|
1787
|
+
])
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
buildInvertedEntries(options, lightStandalone, darkStandalone) {
|
|
1791
|
+
const sep = options.separator ?? "-";
|
|
1792
|
+
const lightBase = buildTokenEntries(this.lightPalette, options);
|
|
1793
|
+
const darkBase = buildTokenEntries(this.darkPalette, options);
|
|
1794
|
+
return {
|
|
1795
|
+
// Light block carries dark values under -inverted suffix.
|
|
1796
|
+
lightBlock: [
|
|
1797
|
+
...darkBase.map((e) => withInvertedSuffix(e, sep)),
|
|
1798
|
+
...darkStandalone.map((e) => withInvertedSuffix(e, sep))
|
|
1799
|
+
],
|
|
1800
|
+
// Dark block carries light values under -inverted suffix.
|
|
1801
|
+
darkBlock: [
|
|
1802
|
+
...lightBase.map((e) => withInvertedSuffix(e, sep)),
|
|
1803
|
+
...lightStandalone.map((e) => withInvertedSuffix(e, sep))
|
|
1804
|
+
]
|
|
1766
1805
|
};
|
|
1767
1806
|
}
|
|
1768
1807
|
applyRole(name, color) {
|
|
@@ -18,8 +18,8 @@ __export(presets_exports, {
|
|
|
18
18
|
// src/presets/bold.ts
|
|
19
19
|
var bold = {
|
|
20
20
|
style: {
|
|
21
|
-
light: {
|
|
22
|
-
dark: {
|
|
21
|
+
light: { baseLightness: 0.5 },
|
|
22
|
+
dark: { baseLightness: 0.8 },
|
|
23
23
|
surfaceMaxChroma: 0.06,
|
|
24
24
|
foregroundMaxChroma: 0.02
|
|
25
25
|
}
|
|
@@ -164,8 +164,8 @@ var tinted = {
|
|
|
164
164
|
// src/presets/vibrant.ts
|
|
165
165
|
var vibrant = {
|
|
166
166
|
style: {
|
|
167
|
-
light: { maxChroma: 0.2,
|
|
168
|
-
dark: { maxChroma: 0.18,
|
|
167
|
+
light: { maxChroma: 0.2, baseLightness: 0.6 },
|
|
168
|
+
dark: { maxChroma: 0.18, baseLightness: 0.65 },
|
|
169
169
|
hueShift: 5,
|
|
170
170
|
surfaceHueShift: 180,
|
|
171
171
|
surfaceMaxChroma: 0.08
|
package/dist/cli.js
CHANGED
|
@@ -864,16 +864,22 @@ function buildTokenEntries(palette, options) {
|
|
|
864
864
|
}
|
|
865
865
|
return entries;
|
|
866
866
|
}
|
|
867
|
+
function withInvertedSuffix(entry, sep) {
|
|
868
|
+
if (entry.isDefault && entry.variant === "DEFAULT") {
|
|
869
|
+
return { ...entry, isDefault: false, variant: "inverted" };
|
|
870
|
+
}
|
|
871
|
+
return { ...entry, variant: `${entry.variant}${sep}inverted` };
|
|
872
|
+
}
|
|
867
873
|
|
|
868
874
|
// src/format/formatters.ts
|
|
869
875
|
function toFlatKey(entry, sep) {
|
|
870
876
|
if (entry.isDefault && entry.variant === "DEFAULT") return entry.role;
|
|
871
877
|
return `${entry.role}${sep}${entry.variant}`;
|
|
872
878
|
}
|
|
873
|
-
function formatObject(entries, sep) {
|
|
879
|
+
function formatObject(entries, sep, keyPrefix = "") {
|
|
874
880
|
const result = {};
|
|
875
881
|
for (const entry of entries) {
|
|
876
|
-
result[toFlatKey(entry, sep)] = entry.value;
|
|
882
|
+
result[`${keyPrefix}${toFlatKey(entry, sep)}`] = entry.value;
|
|
877
883
|
}
|
|
878
884
|
return result;
|
|
879
885
|
}
|
|
@@ -892,8 +898,8 @@ function formatTailwind(entries) {
|
|
|
892
898
|
}
|
|
893
899
|
return result;
|
|
894
900
|
}
|
|
895
|
-
function formatJSON(entries, sep) {
|
|
896
|
-
return JSON.stringify(formatObject(entries, sep), null, 2);
|
|
901
|
+
function formatJSON(entries, sep, keyPrefix = "") {
|
|
902
|
+
return JSON.stringify(formatObject(entries, sep, keyPrefix), null, 2);
|
|
897
903
|
}
|
|
898
904
|
function declsFromEntries(entries, sep, prefix, indent) {
|
|
899
905
|
return entries.map((e) => `${indent}${prefix}${toFlatKey(e, sep)}: ${e.value};`).join("\n");
|
|
@@ -952,15 +958,16 @@ function format(palette, options, standaloneTokens) {
|
|
|
952
958
|
const entries = buildTokenEntries(palette, options);
|
|
953
959
|
if (standaloneTokens) entries.push(...standaloneTokens);
|
|
954
960
|
const sep = options?.separator ?? "-";
|
|
961
|
+
const keyPrefix = options?.keyPrefix ?? "";
|
|
955
962
|
switch (options?.as) {
|
|
956
963
|
case "scss":
|
|
957
964
|
return formatSCSS(entries, sep);
|
|
958
965
|
case "tailwind":
|
|
959
966
|
return formatTailwind(entries);
|
|
960
967
|
case "json":
|
|
961
|
-
return formatJSON(entries, sep);
|
|
968
|
+
return formatJSON(entries, sep, keyPrefix);
|
|
962
969
|
default:
|
|
963
|
-
return formatObject(entries, sep);
|
|
970
|
+
return formatObject(entries, sep, keyPrefix);
|
|
964
971
|
}
|
|
965
972
|
}
|
|
966
973
|
function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, darkStandalone) {
|
|
@@ -1172,11 +1179,19 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1172
1179
|
}
|
|
1173
1180
|
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
|
|
1174
1181
|
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1182
|
+
var warnedLegacyLightness = false;
|
|
1175
1183
|
function resolveThemeLightness(themeType, options) {
|
|
1176
1184
|
const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
|
|
1177
1185
|
const range = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
|
|
1178
|
-
|
|
1179
|
-
|
|
1186
|
+
const value = themeAdjustments?.baseLightness ?? themeAdjustments?.lightness;
|
|
1187
|
+
if (themeAdjustments?.baseLightness === void 0 && themeAdjustments?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
|
|
1188
|
+
warnedLegacyLightness = true;
|
|
1189
|
+
console.warn(
|
|
1190
|
+
"[hextimator] `style({ light/dark: { lightness } })` is deprecated. Rename to `baseLightness` to disambiguate from the relative `lightness` offset used by `addToken({ from, lightness })`. Will be removed in a future release."
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
if (value !== void 0) {
|
|
1194
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1180
1195
|
}
|
|
1181
1196
|
return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
|
|
1182
1197
|
}
|
|
@@ -1759,18 +1774,42 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1759
1774
|
this.darkPalette,
|
|
1760
1775
|
colorFormat
|
|
1761
1776
|
);
|
|
1777
|
+
const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(mergedOptions, lightTokens, darkTokens) : { lightBlock: [], darkBlock: [] };
|
|
1762
1778
|
if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
|
|
1763
1779
|
return formatStylesheet(
|
|
1764
1780
|
this.lightPalette,
|
|
1765
1781
|
this.darkPalette,
|
|
1766
1782
|
mergedOptions,
|
|
1767
|
-
lightTokens,
|
|
1768
|
-
darkTokens
|
|
1783
|
+
[...lightTokens, ...inverted.lightBlock],
|
|
1784
|
+
[...darkTokens, ...inverted.darkBlock]
|
|
1769
1785
|
);
|
|
1770
1786
|
}
|
|
1771
1787
|
return {
|
|
1772
|
-
light: format(this.lightPalette, mergedOptions,
|
|
1773
|
-
|
|
1788
|
+
light: format(this.lightPalette, mergedOptions, [
|
|
1789
|
+
...lightTokens,
|
|
1790
|
+
...inverted.lightBlock
|
|
1791
|
+
]),
|
|
1792
|
+
dark: format(this.darkPalette, mergedOptions, [
|
|
1793
|
+
...darkTokens,
|
|
1794
|
+
...inverted.darkBlock
|
|
1795
|
+
])
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
buildInvertedEntries(options, lightStandalone, darkStandalone) {
|
|
1799
|
+
const sep = options.separator ?? "-";
|
|
1800
|
+
const lightBase = buildTokenEntries(this.lightPalette, options);
|
|
1801
|
+
const darkBase = buildTokenEntries(this.darkPalette, options);
|
|
1802
|
+
return {
|
|
1803
|
+
// Light block carries dark values under -inverted suffix.
|
|
1804
|
+
lightBlock: [
|
|
1805
|
+
...darkBase.map((e) => withInvertedSuffix(e, sep)),
|
|
1806
|
+
...darkStandalone.map((e) => withInvertedSuffix(e, sep))
|
|
1807
|
+
],
|
|
1808
|
+
// Dark block carries light values under -inverted suffix.
|
|
1809
|
+
darkBlock: [
|
|
1810
|
+
...lightBase.map((e) => withInvertedSuffix(e, sep)),
|
|
1811
|
+
...lightStandalone.map((e) => withInvertedSuffix(e, sep))
|
|
1812
|
+
]
|
|
1774
1813
|
};
|
|
1775
1814
|
}
|
|
1776
1815
|
applyRole(name, color) {
|
|
@@ -2238,8 +2277,8 @@ var tinted = {
|
|
|
2238
2277
|
// src/presets/vibrant.ts
|
|
2239
2278
|
var vibrant = {
|
|
2240
2279
|
style: {
|
|
2241
|
-
light: { maxChroma: 0.2,
|
|
2242
|
-
dark: { maxChroma: 0.18,
|
|
2280
|
+
light: { maxChroma: 0.2, baseLightness: 0.6 },
|
|
2281
|
+
dark: { maxChroma: 0.18, baseLightness: 0.65 },
|
|
2243
2282
|
hueShift: 5,
|
|
2244
2283
|
surfaceHueShift: 180,
|
|
2245
2284
|
surfaceMaxChroma: 0.08
|
|
@@ -2301,6 +2340,7 @@ Format options:
|
|
|
2301
2340
|
--dark-mode <strategy> media | class | data-attribute | off (css/tailwind-css only, default: media)
|
|
2302
2341
|
--selector <css> Root selector for css output (default: :root)
|
|
2303
2342
|
--separator <char> Token separator (default: -)
|
|
2343
|
+
--key-prefix <str> Prepend to keys (object/json only); use -- for CSS vars (default: empty)
|
|
2304
2344
|
--exclude-role <name> Omit a role from output (repeatable)
|
|
2305
2345
|
--exclude-variant <name> Omit a variant from output (repeatable)
|
|
2306
2346
|
|
|
@@ -2360,6 +2400,7 @@ function run() {
|
|
|
2360
2400
|
"dark-mode": { type: "string" },
|
|
2361
2401
|
selector: { type: "string" },
|
|
2362
2402
|
separator: { type: "string" },
|
|
2403
|
+
"key-prefix": { type: "string" },
|
|
2363
2404
|
"exclude-role": { type: "string", multiple: true },
|
|
2364
2405
|
"exclude-variant": { type: "string", multiple: true },
|
|
2365
2406
|
"surface-color": { type: "string" },
|
|
@@ -2412,14 +2453,14 @@ function run() {
|
|
|
2412
2453
|
if (values["light-lightness"] || values["light-max-chroma"]) {
|
|
2413
2454
|
styleOptions.light = {};
|
|
2414
2455
|
if (values["light-lightness"])
|
|
2415
|
-
styleOptions.light.
|
|
2456
|
+
styleOptions.light.baseLightness = Number(values["light-lightness"]);
|
|
2416
2457
|
if (values["light-max-chroma"])
|
|
2417
2458
|
styleOptions.light.maxChroma = Number(values["light-max-chroma"]);
|
|
2418
2459
|
}
|
|
2419
2460
|
if (values["dark-lightness"] || values["dark-max-chroma"]) {
|
|
2420
2461
|
styleOptions.dark = {};
|
|
2421
2462
|
if (values["dark-lightness"])
|
|
2422
|
-
styleOptions.dark.
|
|
2463
|
+
styleOptions.dark.baseLightness = Number(values["dark-lightness"]);
|
|
2423
2464
|
if (values["dark-max-chroma"])
|
|
2424
2465
|
styleOptions.dark.maxChroma = Number(values["dark-max-chroma"]);
|
|
2425
2466
|
}
|
|
@@ -2528,6 +2569,9 @@ function run() {
|
|
|
2528
2569
|
} else if (!hasPreset) {
|
|
2529
2570
|
formatOptions.separator = "-";
|
|
2530
2571
|
}
|
|
2572
|
+
if (values["key-prefix"] !== void 0) {
|
|
2573
|
+
formatOptions.keyPrefix = values["key-prefix"];
|
|
2574
|
+
}
|
|
2531
2575
|
if (values["exclude-role"]?.length) {
|
|
2532
2576
|
formatOptions.excludeRoles = values["exclude-role"];
|
|
2533
2577
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as Color, a as CVDType, O as OKLCH, b as ColorSpace, c as ColorInSpace, d as ColorInput, H as HextimatePaletteBuilder } from './HextimatePaletteBuilder-
|
|
2
|
-
export { D as DerivedToken, F as FlatTokenMap, e as FormatResult, f as HextimateFormatOptions, g as HextimateOptions, h as HextimatePreset, i as HextimateResult, j as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-
|
|
3
|
-
export { i as presets } from './index-
|
|
1
|
+
import { C as Color, a as CVDType, O as OKLCH, b as ColorSpace, c as ColorInSpace, d as ColorInput, H as HextimatePaletteBuilder } from './HextimatePaletteBuilder-CNjOKwbY.js';
|
|
2
|
+
export { D as DerivedToken, F as FlatTokenMap, e as FormatResult, f as HextimateFormatOptions, g as HextimateOptions, h as HextimatePreset, i as HextimateResult, j as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, k as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-CNjOKwbY.js';
|
|
3
|
+
export { i as presets } from './index-kecVj5cB.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Daltonize a color for a specific type of color vision deficiency (CVD).
|
|
@@ -80,7 +80,7 @@ declare class HextimateError extends Error {
|
|
|
80
80
|
* @example
|
|
81
81
|
* // Extended: add roles and variants before formatting
|
|
82
82
|
* const theme = hextimate('#ff6600')
|
|
83
|
-
* .style({ light: {
|
|
83
|
+
* .style({ light: { baseLightness: 0.5 }, dark: { baseLightness: 0.65, maxChroma: 0.1 } })
|
|
84
84
|
* .addRole('cta', '#ee2244')
|
|
85
85
|
* .addVariant('hover', { from: 'strong' })
|
|
86
86
|
* .format({ as: 'tailwind' });
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
hextimate,
|
|
7
7
|
parse,
|
|
8
8
|
simulateColor
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-KFH2N7CF.js";
|
|
10
10
|
import {
|
|
11
11
|
presets_exports
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NTF3K3U3.js";
|
|
13
13
|
export {
|
|
14
14
|
HextimateError,
|
|
15
15
|
HextimatePaletteBuilder,
|
package/dist/presets.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { b as bold, m as mui, a as muted, s as shadcn, t as tinted, v as vibrant } from './index-
|
|
2
|
-
export { h as HextimatePreset } from './HextimatePaletteBuilder-
|
|
1
|
+
export { b as bold, m as mui, a as muted, s as shadcn, t as tinted, v as vibrant } from './index-kecVj5cB.js';
|
|
2
|
+
export { h as HextimatePreset } from './HextimatePaletteBuilder-CNjOKwbY.js';
|
package/dist/presets.js
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as HextimateStyleOptions, h as HextimatePreset, H as HextimatePaletteBuilder, i as HextimateResult, F as FlatTokenMap, f as HextimateFormatOptions } from './HextimatePaletteBuilder-
|
|
1
|
+
import { j as HextimateStyleOptions, h as HextimatePreset, H as HextimatePaletteBuilder, i as HextimateResult, F as FlatTokenMap, f as HextimateFormatOptions } from './HextimatePaletteBuilder-CNjOKwbY.js';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { PropsWithChildren, RefObject, CSSProperties, ReactNode } from 'react';
|
|
4
4
|
|
package/dist/react.js
CHANGED
package/llms.txt
CHANGED
|
@@ -57,18 +57,19 @@ 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
|
+
| `keyPrefix` | `string` — prepended to each key (`object` / `json` only); e.g. `"--"` for CSS vars | `""` |
|
|
60
61
|
| `darkMode` | `"media"`, `"class"`, `"data-attribute"`, `false` (stylesheet outputs only) | `"media"` |
|
|
61
62
|
| `selector` | `string` — root selector for `as: "css"` | `":root"` |
|
|
62
63
|
| `excludeRoles` | `string[]` — role keys to omit entirely from output (by internal name, before `roleNames`) | `[]` |
|
|
63
64
|
| `excludeVariants` | `string[]` — variant keys to omit from every role's output (by internal name, before `variantNames`) | `[]` |
|
|
64
65
|
|
|
65
66
|
Output shape depends on `as`:
|
|
66
|
-
- `"object"` → `{ light, dark }` flat maps: `{ accent: "#...", "accent-strong": "#..." }`
|
|
67
|
+
- `"object"` → `{ light, dark }` flat maps: `{ accent: "#...", "accent-strong": "#..." }` (with `keyPrefix: "--"`: `{ "--accent": "...", "--accent-strong": "..." }`)
|
|
67
68
|
- `"css"` → `string` — ready-to-paste CSS stylesheet with `:root {}` and a dark-mode wrapper
|
|
68
69
|
- `"tailwind"` → `{ light, dark }` nested maps: `{ accent: { DEFAULT: "#...", strong: "#..." } }`
|
|
69
70
|
- `"tailwind-css"` → `string` — Tailwind v4 stylesheet: single `@theme { --color-accent: #...; }` block plus dark overrides
|
|
70
71
|
- `"scss"` → `{ light, dark }` flat maps: `{ "$accent": "#...", "$accent-strong": "#..." }`
|
|
71
|
-
- `"json"` → `{ light, dark }` JSON strings
|
|
72
|
+
- `"json"` → `{ light, dark }` JSON strings (`keyPrefix` applies like `"object"`)
|
|
72
73
|
|
|
73
74
|
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]"`).
|
|
74
75
|
|
|
@@ -83,8 +84,8 @@ Pick the dark wrapper with `darkMode`: `"media"` (default) wraps dark tokens in
|
|
|
83
84
|
| `semanticColorRanges` | `{ positive?: [start,end], ... }` | greens, reds, ambers | Hue ranges for semantic detection |
|
|
84
85
|
| `surfaceMaxChroma` | number | `0.01` | Max chroma for surface colors |
|
|
85
86
|
| `foregroundMaxChroma` | number | `0.01` | Max chroma for foreground colors |
|
|
86
|
-
| `light` | `{
|
|
87
|
-
| `dark` | `{
|
|
87
|
+
| `light` | `{ baseLightness?, maxChroma? }` | `{ baseLightness: 0.7 }` | Light theme adjustments. `baseLightness` is the absolute OKLCH anchor for the accent (distinct from the relative `lightness` offset on derived tokens) |
|
|
88
|
+
| `dark` | `{ baseLightness?, maxChroma? }` | `{ baseLightness: 0.6 }` | Dark theme adjustments |
|
|
88
89
|
| `minContrastRatio` | `"AAA"`, `"AA"`, or number | `"AAA"` | WCAG contrast target (AAA=7, AA=4.5) |
|
|
89
90
|
| `hueShift` | degrees | `0` | Per-variant hue rotation |
|
|
90
91
|
|
|
@@ -298,6 +299,7 @@ Both commands are identical. Use whichever you prefer.
|
|
|
298
299
|
| `-t, --theme` | `light`, `dark`, `both` (ignored for `css`/`tailwind-css` — both always combine into one string) | `both` |
|
|
299
300
|
| `-p, --preset` | Apply preset (repeatable, applied in order): `shadcn`, `mui`, `muted`, `vibrant`, `tinted` | — |
|
|
300
301
|
| `--separator` | Token separator between role and variant | `-` |
|
|
302
|
+
| `--key-prefix` | Prepend to keys (`object` / `json` only); pass `--` for CSS custom properties | empty |
|
|
301
303
|
| `--dark-mode` | `media`, `class`, `data-attribute`, `false` (stylesheet outputs only) | `media` |
|
|
302
304
|
| `--selector` | Root selector for `--format css` | `:root` |
|
|
303
305
|
| `--exclude-role` | Omit a role from output by internal name (repeatable) | — |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hextimator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Runtime theming for multi-tenant apps: per-tenant branded themes from a single brand color, with WCAG contrast guarantees.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"runtime-theming",
|
|
@@ -63,11 +63,13 @@
|
|
|
63
63
|
},
|
|
64
64
|
"./cli": "./dist/cli.js",
|
|
65
65
|
"./tailwind.css": "./tailwind.css",
|
|
66
|
+
"./tailwind-inverted.css": "./tailwind-inverted.css",
|
|
66
67
|
"./fallback.css": "./fallback.css"
|
|
67
68
|
},
|
|
68
69
|
"files": [
|
|
69
70
|
"dist",
|
|
70
71
|
"tailwind.css",
|
|
72
|
+
"tailwind-inverted.css",
|
|
71
73
|
"fallback.css",
|
|
72
74
|
"llms.txt",
|
|
73
75
|
"CHANGELOG.md"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@theme inline {
|
|
2
|
+
--color-accent-inverted: var(--accent-inverted);
|
|
3
|
+
--color-accent-strong-inverted: var(--accent-strong-inverted);
|
|
4
|
+
--color-accent-weak-inverted: var(--accent-weak-inverted);
|
|
5
|
+
--color-accent-foreground-inverted: var(--accent-foreground-inverted);
|
|
6
|
+
--color-surface-inverted: var(--surface-inverted);
|
|
7
|
+
--color-surface-strong-inverted: var(--surface-strong-inverted);
|
|
8
|
+
--color-surface-weak-inverted: var(--surface-weak-inverted);
|
|
9
|
+
--color-surface-foreground-inverted: var(--surface-foreground-inverted);
|
|
10
|
+
--color-positive-inverted: var(--positive-inverted);
|
|
11
|
+
--color-positive-strong-inverted: var(--positive-strong-inverted);
|
|
12
|
+
--color-positive-weak-inverted: var(--positive-weak-inverted);
|
|
13
|
+
--color-positive-foreground-inverted: var(--positive-foreground-inverted);
|
|
14
|
+
--color-negative-inverted: var(--negative-inverted);
|
|
15
|
+
--color-negative-strong-inverted: var(--negative-strong-inverted);
|
|
16
|
+
--color-negative-weak-inverted: var(--negative-weak-inverted);
|
|
17
|
+
--color-negative-foreground-inverted: var(--negative-foreground-inverted);
|
|
18
|
+
--color-warning-inverted: var(--warning-inverted);
|
|
19
|
+
--color-warning-strong-inverted: var(--warning-strong-inverted);
|
|
20
|
+
--color-warning-weak-inverted: var(--warning-weak-inverted);
|
|
21
|
+
--color-warning-foreground-inverted: var(--warning-foreground-inverted);
|
|
22
|
+
}
|