hextimator 0.4.0 → 0.5.1

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,31 @@
1
- ## 0.4.0 (Latest)
1
+ ## 0.5.1 (Latest)
2
+
3
+ - [#110](https://github.com/fgrgic/hextimator/pull/110): Add ./presets as a dedicated subpath export so `import { tinted } from 'hextimator/presets'` works
4
+
5
+ ## 0.5.0
6
+
7
+ - [#108](https://github.com/fgrgic/hextimator/pull/108) **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.
8
+
9
+ ```ts
10
+ // Before (0.4)
11
+ const { light, dark } = hextimate("#6A5ACD").format({ as: "css" });
12
+ // light = { "--accent": "#...", ... }
13
+ // you had to hand-build ":root {} @media {}" yourself
14
+
15
+ // After (0.5)
16
+ const css = hextimate("#6A5ACD").format({ as: "css" });
17
+ // css = ":root { --accent: #...; ... }\n@media (prefers-color-scheme: dark) { :root { ... } }"
18
+ ```
19
+
20
+ - New format options for stylesheet outputs:
21
+ - `darkMode`: `"media"` (default) | `"class"` | `"data-attribute"` | `false`
22
+ - `selector`: root selector for `as: "css"` (default `":root"`); ignored for `as: "tailwind-css"` (always `@theme`)
23
+ - 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).
24
+ - React integration unchanged.
25
+
26
+ Migration checklist: [migrating-from-0.4.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migrating-from-0.4.md).
27
+
28
+ ## 0.4.0
2
29
 
3
30
  - [#106](https://github.com/fgrgic/hextimator/pull/106): add per-theme color for React
4
31
  - React provider and scope now accept per-mode brand colors (`defaultColor: string | { light, dark }`)
package/README.md CHANGED
@@ -6,15 +6,45 @@
6
6
  </picture>
7
7
  </p>
8
8
 
9
- One color in, whole theme out.
9
+ Per-tenant themes from a single one brand color: Runtime theming for B2B2C and white-label apps.
10
10
 
11
- Your customers pick a brand color. Your app looks good. Every time. No manual tuning, no edge cases where "that shade of yellow" breaks your UI.
11
+ Your customers pick a brand color. Your app looks good. Every time. No per-customer design reviews, no manual tuning, no edge cases where "that shade of yellow" breaks your UI.
12
12
 
13
- - **Ship multi-tenant apps without the design overhead** — generate per-tenant branded themes at runtime from a single input color. No design review per customer.
14
- - **Every color just works** — perceptually uniform colors with OKLCH means that electric blue looks as balanced as muted olive.
15
- - **Accessible by default** — every foreground meets AAA contrast against its background, light and dark mode included.
13
+ Ship multi-tenant apps without the design overhead:
16
14
 
17
- **[hextimator.com](https://hextimator.com)** — try it in the playground.
15
+ - **Every color just works**. Perceptually uniform colors with OKLCH means that electric blue looks as balanced as muted olive.
16
+ - **Accessible by default**. Every foreground meets AAA contrast against its background, light and dark mode included.
17
+
18
+ Try it in the playground: **[hextimator.com](https://hextimator.com)**
19
+
20
+ ## Why `hextimator` exists
21
+
22
+ You're building a B2B, a B2B2C, or a white-label app. Every tenant wants their own brand color in the app. The options today are:
23
+
24
+ 1. **Let customers pick any hex.** It works until a partner's _legal-pad yellow_ renders your buttons unreadable, and their _cheeto dust tangerine_ toast makes it indistinguishable from a warning.
25
+ 2. **Constrain them to a curated palette.** Now you need to tell a paying customer that their brand color isn't allowed. Or spend hours adjusting all the other colors by hand to make the theme somewhat work.
26
+
27
+ Hextimator is option 3. One color in, whole theme out. You get accent, semantic roles, light/dark palette, every foreground guaranteed to meet WCAG contrast against its background. Every time. Even for that yellow.
28
+
29
+ ```ts
30
+ import { hextimate } from "hextimator";
31
+
32
+ const tenantTheme = hextimate(tenant.brandColor).format({ as: "css" });
33
+
34
+ document.getElementById("tenant-theme").textContent = tenantTheme;
35
+ ```
36
+
37
+ That's the integration. Swap the color, the theme regenerates at runtime, and the UI stays readable.
38
+
39
+ Using React? Even easier:
40
+
41
+ ```jsx
42
+ <HextimatorProvider defaultColor={tenant.brandColor}>
43
+ <App />
44
+ </HextimatorProvider>
45
+ ```
46
+
47
+ See full React integration guide [here](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md).
18
48
 
19
49
  ## Installation
20
50
 
@@ -24,20 +54,38 @@ Add to your project:
24
54
  npm i hextimator
25
55
  ```
26
56
 
27
- Or quickly get a one-off theme:
57
+ **Using tailwind?**
58
+ make sure to include
28
59
 
29
- ```bash
30
- npx hextimator "#C0FFEE"
60
+ ```css
61
+ @import "hextimator/tailwind.css";
31
62
  ```
32
63
 
64
+ in your `index.css`
65
+
33
66
  ## Quick start
34
67
 
68
+ ```bash
69
+ npm install hextimator
70
+ ```
71
+
35
72
  ```typescript
36
73
  import { hextimate } from "hextimator";
37
74
 
38
- const theme = hextimate("#C0FFEE").format();
75
+ const theme = hextimate("#6A5ACD").format();
76
+ // theme.light / theme.dark each contain your full theme tokens
39
77
  ```
40
78
 
79
+ ### Multi-tenant app with React
80
+
81
+ ```jsx
82
+ <HextimatorProvider defaultColor={tenant.brandColor}>
83
+ <App />
84
+ </HextimatorProvider>
85
+ ```
86
+
87
+ See full React integration guide [here](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/react.md).
88
+
41
89
  ### With presets
42
90
 
43
91
  Presets are partial or full themes. You can chain them together, [extend them](#extending-presets), or not use them at all. They provide a starting point: whether for a specific framework or a particular style:
@@ -116,7 +164,7 @@ hextimate("#F11732").format({
116
164
  const myPreset: HextimatePreset = {
117
165
  format: {
118
166
  excludeRoles: ["warning"],
119
- excludeVariants: ["strong", "weak"],
167
+ excludeVariants: ["weak"],
120
168
  },
121
169
  };
122
170
  ```
@@ -152,7 +200,7 @@ All formats return `{ light: { ... }, dark: { ... } }`.
152
200
 
153
201
  Besides hex, **`hextimate`** accepts CSS color strings, RGB tuples, and numeric `0xRRGGBB`—anything **`parseColor`** understands.
154
202
 
155
- > **Note on alpha**: Alpha values are intentionally ignored — `rgba(255, 0, 0, 0.5)` is treated as fully opaque `rgb(255, 0, 0)`. Alpha tokens undermine accessibility guarantees because contrast ratios depend on the background, which hextimator does not control.
203
+ > **Note on alpha**: Alpha values are intentionally ignored — `rgba(255, 0, 0, 0.5)` is treated as fully opaque `rgb(255, 0, 0)`. Alpha tokens undermine accessibility guarantees because contrast ratios depend on the background, which hextimator does not control. You can always add an opacity modifier later if you wish (e.g. `base-accent-weak/20` in tailwind).
156
204
 
157
205
  Before `.format()` you can still chain **`addRole` / `addVariant` / `addToken`**, **`.preset()`**, **`.fork()`**, **`.simulate()` / `.adaptFor()`**, and anything else in [Extending the palette](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/extending-the-palette.md) or [Presets](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/presets.md).
158
206
 
@@ -175,6 +223,22 @@ const color = parseColor("rgb(255, 102, 102)");
175
223
  const oklch = convertColor(color, "oklch");
176
224
  ```
177
225
 
226
+ ## CLI
227
+
228
+ Quickly get one-off themes from the terminal:
229
+
230
+ ```sh
231
+ npx hextimate "#ff6677";
232
+ ```
233
+
234
+ Get the full help running:
235
+
236
+ ```
237
+ npx hextimate -h
238
+ ```
239
+
240
+ > Note: `hextimate` and `hextimator` are the same CLI; pick whichever you like typing.
241
+
178
242
  ## React
179
243
 
180
244
  Import from `hextimator/react`:
@@ -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;
@@ -553,4 +576,4 @@ declare class HextimatePaletteBuilder {
553
576
  private resolvedOptions;
554
577
  }
555
578
 
556
- export { type Color as C, type DerivedToken as D, type FlatTokenMap as F, type HextimatePreset as H, type NestedTokenMap as N, type OKLCH as O, type ThemeAdjustments as T, type VariantPlacement as V, type CVDType as a, type ColorSpace as b, type ColorInSpace as c, type ColorInput as d, HextimatePaletteBuilder as e, type FormatResult as f, type HextimateFormatOptions as g, type HextimateOptions as h, type HextimateResult as i, type HextimateStyleOptions as j, type TokenValue as k };
579
+ export { type Color as C, type DerivedToken as D, type FlatTokenMap as F, HextimatePaletteBuilder as H, type NestedTokenMap as N, type OKLCH as O, type ThemeAdjustments as T, type VariantPlacement as V, type CVDType as a, type ColorSpace as b, type ColorInSpace as c, type ColorInput as d, type FormatResult as e, type HextimateFormatOptions as f, type HextimateOptions as g, type HextimatePreset as h, type HextimateResult as i, type HextimateStyleOptions as j, type TokenValue as k };
@@ -0,0 +1,183 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/presets/index.ts
8
+ var presets_exports = {};
9
+ __export(presets_exports, {
10
+ bold: () => bold,
11
+ mui: () => mui,
12
+ muted: () => muted,
13
+ shadcn: () => shadcn,
14
+ tinted: () => tinted,
15
+ vibrant: () => vibrant
16
+ });
17
+
18
+ // src/presets/bold.ts
19
+ var bold = {
20
+ style: {
21
+ light: { lightness: 0.5 },
22
+ dark: { lightness: 0.8 },
23
+ baseMaxChroma: 0.06,
24
+ foregroundMaxChroma: 0.02
25
+ }
26
+ };
27
+
28
+ // src/presets/mui.ts
29
+ var mui = {
30
+ roles: [
31
+ { name: "info", color: "#0288d1" },
32
+ { name: "secondary", color: { from: "accent", hue: 180 } }
33
+ ],
34
+ tokens: [
35
+ // background
36
+ { name: "background-default", value: { from: "base" } },
37
+ {
38
+ name: "background-paper",
39
+ value: { from: "base", emphasis: -0.025 }
40
+ },
41
+ // text
42
+ { name: "text-primary", value: { from: "base.foreground" } },
43
+ {
44
+ name: "text-secondary",
45
+ value: { from: "base.foreground", emphasis: -0.2 }
46
+ },
47
+ {
48
+ name: "text-disabled",
49
+ value: { from: "base.foreground", emphasis: -0.4 }
50
+ },
51
+ // divider
52
+ { name: "divider", value: { from: "base", emphasis: 0.12 } },
53
+ // action tokens
54
+ { name: "action-hover", value: { from: "base", emphasis: 0.04 } },
55
+ { name: "action-selected", value: { from: "base", emphasis: 0.08 } },
56
+ { name: "action-disabled", value: { from: "base", emphasis: 0.15 } },
57
+ {
58
+ name: "action-disabledBackground",
59
+ value: { from: "base", emphasis: 0.06 }
60
+ },
61
+ { name: "action-focus", value: { from: "base", emphasis: 0.06 } }
62
+ ],
63
+ format: {
64
+ as: "object",
65
+ colors: "hex",
66
+ separator: "-",
67
+ roleNames: {
68
+ accent: "primary",
69
+ negative: "error",
70
+ positive: "success"
71
+ },
72
+ variantNames: {
73
+ DEFAULT: "main",
74
+ weak: "light",
75
+ strong: "dark",
76
+ foreground: "contrastText"
77
+ },
78
+ excludeRoles: ["base"]
79
+ }
80
+ };
81
+
82
+ // src/presets/muted.ts
83
+ var muted = {
84
+ style: {
85
+ light: { maxChroma: 0.08 },
86
+ dark: { maxChroma: 0.07 },
87
+ baseMaxChroma: 5e-3,
88
+ foregroundMaxChroma: 5e-3
89
+ }
90
+ };
91
+
92
+ // src/presets/shadcn.ts
93
+ var shadcn = {
94
+ tokens: [
95
+ // shadcn uses bare --foreground (not --background-foreground)
96
+ { name: "foreground", value: { from: "base.foreground" } },
97
+ // card / popover — same as background
98
+ { name: "card", value: { from: "base" } },
99
+ { name: "card-foreground", value: { from: "base.foreground" } },
100
+ { name: "popover", value: { from: "base" } },
101
+ { name: "popover-foreground", value: { from: "base.foreground" } },
102
+ // secondary — subtle contrast from background
103
+ { name: "secondary", value: { from: "base" } },
104
+ { name: "secondary-foreground", value: { from: "base.foreground" } },
105
+ // muted — similar to secondary, but with dimmer foreground
106
+ { name: "muted", value: { from: "base" } },
107
+ {
108
+ name: "muted-foreground",
109
+ value: {
110
+ from: "base.foreground",
111
+ emphasis: -0.25
112
+ }
113
+ },
114
+ // accent (shadcn meaning: subtle hover highlight, not the brand color)
115
+ { name: "accent", value: { from: "base" } },
116
+ { name: "accent-foreground", value: { from: "base.foreground" } },
117
+ // border / input
118
+ {
119
+ name: "border",
120
+ value: { from: "base", emphasis: 0.8 }
121
+ },
122
+ {
123
+ name: "input",
124
+ value: {
125
+ from: "base",
126
+ emphasis: 0.8
127
+ }
128
+ },
129
+ // ring — uses the brand/primary color
130
+ { name: "ring", value: { from: "accent" } },
131
+ // chart tokens colors use brand/priamry color
132
+ { name: "chart-1", value: { from: "accent" } },
133
+ { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
134
+ { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
135
+ { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
136
+ { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
137
+ ],
138
+ format: {
139
+ as: "css",
140
+ colors: "oklch",
141
+ roleNames: {
142
+ base: "background",
143
+ accent: "primary",
144
+ negative: "destructive",
145
+ positive: "success"
146
+ },
147
+ variantNames: {
148
+ foreground: "foreground"
149
+ },
150
+ excludeRoles: ["warning"],
151
+ excludeVariants: ["strong", "weak"]
152
+ }
153
+ };
154
+
155
+ // src/presets/tinted.ts
156
+ var tinted = {
157
+ style: {
158
+ baseMaxChroma: 0.05,
159
+ baseHueShift: 0,
160
+ foregroundMaxChroma: 0.015
161
+ }
162
+ };
163
+
164
+ // src/presets/vibrant.ts
165
+ var vibrant = {
166
+ style: {
167
+ light: { maxChroma: 0.2, lightness: 0.6 },
168
+ dark: { maxChroma: 0.18, lightness: 0.65 },
169
+ hueShift: 5,
170
+ baseHueShift: 180,
171
+ baseMaxChroma: 0.08
172
+ }
173
+ };
174
+
175
+ export {
176
+ bold,
177
+ mui,
178
+ muted,
179
+ shadcn,
180
+ tinted,
181
+ vibrant,
182
+ presets_exports
183
+ };