hextimator 0.1.1 → 0.2.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/dist/react.js CHANGED
@@ -2,36 +2,79 @@ import {
2
2
  hextimate
3
3
  } from "./chunk-MBVLFPTG.js";
4
4
 
5
- // src/react.tsx
5
+ // src/react/hextimator-provider.tsx
6
6
  import {
7
- createContext,
8
7
  useCallback,
9
- useContext,
10
- useEffect,
11
- useMemo,
12
- useRef,
13
- useState,
14
- useSyncExternalStore
8
+ useEffect as useEffect2,
9
+ useMemo as useMemo2,
10
+ useState
15
11
  } from "react";
16
- import { jsx } from "react/jsx-runtime";
17
- function buildStyleContent(palette, darkMode, cssPrefix) {
12
+
13
+ // src/react/context.ts
14
+ import { createContext } from "react";
15
+ var HextimatorContext = createContext(
16
+ null
17
+ );
18
+
19
+ // src/react/mode.ts
20
+ import { useSyncExternalStore } from "react";
21
+ var darkQuery = typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)") : null;
22
+ function useOsPrefersDark() {
23
+ return useSyncExternalStore(
24
+ (cb) => {
25
+ if (!darkQuery) return () => {
26
+ };
27
+ darkQuery.addEventListener("change", cb);
28
+ return () => darkQuery.removeEventListener("change", cb);
29
+ },
30
+ () => darkQuery?.matches ?? false,
31
+ () => false
32
+ );
33
+ }
34
+ function applyModeToDOM(mode, darkMode) {
35
+ if (typeof document === "undefined") return;
36
+ if (darkMode === false || darkMode.type === "media") return;
37
+ const root = document.documentElement;
38
+ if (darkMode.type === "data") {
39
+ const attr = darkMode.attribute ?? "data-theme";
40
+ if (mode) {
41
+ root.setAttribute(attr, mode);
42
+ } else {
43
+ root.removeAttribute(attr);
44
+ }
45
+ return;
46
+ }
47
+ const cls = darkMode.className ?? "dark";
48
+ const lightCls = cls === "dark" ? "light" : `not-${cls}`;
49
+ root.classList.remove(cls, lightCls);
50
+ if (mode) {
51
+ root.classList.add(mode === "dark" ? cls : lightCls);
52
+ }
53
+ }
54
+
55
+ // src/react/use-hextimator.ts
56
+ import { useEffect, useMemo } from "react";
57
+
58
+ // src/react/css.ts
59
+ function buildStyleContent(palette, darkMode, cssPrefix, selector = ":root") {
18
60
  const lightEntries = Object.entries(palette.light);
19
61
  const darkEntries = Object.entries(palette.dark);
20
62
  const toVars = (entries) => entries.map(([key, value]) => `${cssPrefix}${key}: ${value};`).join("\n ");
21
63
  const lightVars = toVars(lightEntries);
22
64
  const darkVars = toVars(darkEntries);
65
+ const isRoot = selector === ":root";
23
66
  if (darkMode === false) {
24
- return `:root {
67
+ return `${selector} {
25
68
  ${lightVars}
26
69
  }`;
27
70
  }
28
71
  if (darkMode.type === "media") {
29
72
  return [
30
- `:root {
73
+ `${selector} {
31
74
  ${lightVars}
32
75
  }`,
33
76
  `@media (prefers-color-scheme: dark) {
34
- :root {
77
+ ${selector} {
35
78
  ${darkVars}
36
79
  }
37
80
  }`
@@ -40,36 +83,41 @@ function buildStyleContent(palette, darkMode, cssPrefix) {
40
83
  if (darkMode.type === "media-or-class") {
41
84
  const cls = darkMode.className ?? "dark";
42
85
  const lightCls = cls === "dark" ? "light" : `not-${cls}`;
86
+ const darkClassSelector = isRoot ? `:root.${cls}` : `:root.${cls} ${selector}`;
87
+ const mediaDarkSelector = isRoot ? `:root:not(.${lightCls})` : `:root:not(.${lightCls}) ${selector}`;
43
88
  return [
44
- `:root {
89
+ `${selector} {
45
90
  ${lightVars}
46
91
  }`,
47
92
  `@media (prefers-color-scheme: dark) {
48
- :root:not(.${lightCls}) {
93
+ ${mediaDarkSelector} {
49
94
  ${darkVars}
50
95
  }
51
96
  }`,
52
- `:root.${cls} {
97
+ `${darkClassSelector} {
53
98
  ${darkVars}
54
99
  }`
55
100
  ].join("\n");
56
101
  }
57
102
  if (darkMode.type === "class") {
58
103
  const cls = darkMode.className ?? "dark";
59
- return [`:root {
104
+ const darkSelector2 = isRoot ? `.${cls}` : `.${cls} ${selector}`;
105
+ return [
106
+ `${selector} {
60
107
  ${lightVars}
61
- }`, `.${cls} {
108
+ }`,
109
+ `${darkSelector2} {
62
110
  ${darkVars}
63
- }`].join(
64
- "\n"
65
- );
111
+ }`
112
+ ].join("\n");
66
113
  }
67
114
  const attr = darkMode.attribute ?? "data-theme";
115
+ const darkSelector = isRoot ? `[${attr}="dark"]` : `[${attr}="dark"] ${selector}`;
68
116
  return [
69
- `:root {
117
+ `${selector} {
70
118
  ${lightVars}
71
119
  }`,
72
- `[${attr}="dark"] {
120
+ `${darkSelector} {
73
121
  ${darkVars}
74
122
  }`
75
123
  ].join("\n");
@@ -85,6 +133,9 @@ function buildTargetedVars(palette, darkMode, cssPrefix) {
85
133
  dark: darkMode !== false ? prefixEntries(Object.entries(palette.dark)) : []
86
134
  };
87
135
  }
136
+
137
+ // src/react/use-stable-options.ts
138
+ import { useRef } from "react";
88
139
  function useStableOptions(options) {
89
140
  const ref = useRef(options);
90
141
  const serialized = JSON.stringify({
@@ -103,6 +154,8 @@ function useStableOptions(options) {
103
154
  }
104
155
  return ref.current;
105
156
  }
157
+
158
+ // src/react/use-hextimator.ts
106
159
  function useHextimator(color, options) {
107
160
  const stable = useStableOptions(options);
108
161
  const configure = options?.configure;
@@ -140,40 +193,9 @@ function useHextimator(color, options) {
140
193
  }, [palette, darkMode, cssPrefix, target]);
141
194
  return palette;
142
195
  }
143
- var darkQuery = typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)") : null;
144
- function useOsPrefersDark() {
145
- return useSyncExternalStore(
146
- (cb) => {
147
- if (!darkQuery) return () => {
148
- };
149
- darkQuery.addEventListener("change", cb);
150
- return () => darkQuery.removeEventListener("change", cb);
151
- },
152
- () => darkQuery?.matches ?? false,
153
- () => false
154
- );
155
- }
156
- function applyModeToDOM(mode, darkMode) {
157
- if (typeof document === "undefined") return;
158
- if (darkMode === false || darkMode.type === "media") return;
159
- const root = document.documentElement;
160
- if (darkMode.type === "data") {
161
- const attr = darkMode.attribute ?? "data-theme";
162
- if (mode) {
163
- root.setAttribute(attr, mode);
164
- } else {
165
- root.removeAttribute(attr);
166
- }
167
- return;
168
- }
169
- const cls = darkMode.className ?? "dark";
170
- const lightCls = cls === "dark" ? "light" : `not-${cls}`;
171
- root.classList.remove(cls, lightCls);
172
- if (mode) {
173
- root.classList.add(mode === "dark" ? cls : lightCls);
174
- }
175
- }
176
- var HextimatorContext = createContext(null);
196
+
197
+ // src/react/hextimator-provider.tsx
198
+ import { jsx } from "react/jsx-runtime";
177
199
  function HextimatorProvider({
178
200
  children,
179
201
  defaultColor,
@@ -192,7 +214,7 @@ function HextimatorProvider({
192
214
  const osDark = useOsPrefersDark();
193
215
  const mode = modePreference === "system" ? osDark ? "dark" : "light" : modePreference;
194
216
  const resolvedDarkMode = darkMode ?? { type: "media" };
195
- useEffect(() => {
217
+ useEffect2(() => {
196
218
  applyModeToDOM(
197
219
  modePreference === "system" ? null : modePreference,
198
220
  resolvedDarkMode
@@ -212,7 +234,12 @@ function HextimatorProvider({
212
234
  cssPrefix,
213
235
  target
214
236
  });
215
- const value = useMemo(
237
+ const builder = useMemo2(() => {
238
+ const b = hextimate(color, generation);
239
+ configure?.(b);
240
+ return b;
241
+ }, [color, generation, configure]);
242
+ const value = useMemo2(
216
243
  () => ({
217
244
  color,
218
245
  setColor,
@@ -223,23 +250,170 @@ function HextimatorProvider({
223
250
  setGeneration,
224
251
  configure,
225
252
  setConfigure,
226
- palette
253
+ palette,
254
+ builder
227
255
  }),
228
- [color, mode, modePreference, generation, configure, setConfigure, palette]
256
+ [
257
+ color,
258
+ mode,
259
+ modePreference,
260
+ generation,
261
+ configure,
262
+ setConfigure,
263
+ palette,
264
+ builder
265
+ ]
229
266
  );
230
267
  return /* @__PURE__ */ jsx(HextimatorContext.Provider, { value, children });
231
268
  }
269
+
270
+ // src/react/hextimator-scope.tsx
271
+ import {
272
+ useCallback as useCallback2,
273
+ useContext,
274
+ useId,
275
+ useMemo as useMemo3,
276
+ useState as useState2
277
+ } from "react";
278
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
279
+ function HextimatorScope({
280
+ defaultColor,
281
+ generation: initialGeneration,
282
+ format: formatOpts,
283
+ configure: initialConfigure,
284
+ darkMode,
285
+ cssPrefix,
286
+ className,
287
+ style,
288
+ children
289
+ }) {
290
+ const id = useId();
291
+ const selector = `[data-hextimator-scope="${id}"]`;
292
+ const [color, setColor] = useState2(defaultColor);
293
+ const [generation, setGeneration] = useState2(initialGeneration);
294
+ const [configure, setConfigureState] = useState2(() => initialConfigure);
295
+ const setConfigure = useCallback2(
296
+ (fn) => {
297
+ setConfigureState(() => fn);
298
+ },
299
+ []
300
+ );
301
+ const parent = useContext(HextimatorContext);
302
+ const stable = useStableOptions({
303
+ generation,
304
+ format: formatOpts,
305
+ darkMode,
306
+ cssPrefix
307
+ });
308
+ const builder = useMemo3(() => {
309
+ const b = parent?.builder ? parent.builder.fork(color, stable?.generation) : hextimate(color, stable?.generation);
310
+ configure?.(b);
311
+ return b;
312
+ }, [parent?.builder, color, stable, configure]);
313
+ const palette = useMemo3(
314
+ () => builder.format({
315
+ ...stable?.format,
316
+ as: "css"
317
+ }),
318
+ [builder, stable]
319
+ );
320
+ const css = useMemo3(
321
+ () => buildStyleContent(
322
+ palette,
323
+ stable?.darkMode ?? { type: "media" },
324
+ stable?.cssPrefix ?? "",
325
+ selector
326
+ ),
327
+ [palette, stable, selector]
328
+ );
329
+ const osDark = useOsPrefersDark();
330
+ const noopSetMode = useCallback2(() => {
331
+ }, []);
332
+ const mode = parent?.mode ?? (osDark ? "dark" : "light");
333
+ const modePreference = parent?.modePreference ?? "system";
334
+ const setMode = parent?.setMode ?? noopSetMode;
335
+ const value = useMemo3(
336
+ () => ({
337
+ color,
338
+ setColor,
339
+ mode,
340
+ modePreference,
341
+ setMode,
342
+ generation,
343
+ setGeneration,
344
+ configure,
345
+ setConfigure,
346
+ palette,
347
+ builder
348
+ }),
349
+ [
350
+ color,
351
+ mode,
352
+ modePreference,
353
+ setMode,
354
+ generation,
355
+ configure,
356
+ setConfigure,
357
+ palette,
358
+ builder
359
+ ]
360
+ );
361
+ return /* @__PURE__ */ jsx2(HextimatorContext.Provider, { value, children: /* @__PURE__ */ jsxs("div", { "data-hextimator-scope": id, className, style, children: [
362
+ /* @__PURE__ */ jsx2("style", { "data-hextimator": "", children: css }),
363
+ children
364
+ ] }) });
365
+ }
366
+
367
+ // src/react/hextimator-style.tsx
368
+ import { useMemo as useMemo4 } from "react";
369
+ import { jsx as jsx3 } from "react/jsx-runtime";
370
+ function HextimatorStyle({
371
+ color,
372
+ generation,
373
+ format: formatOpts,
374
+ configure,
375
+ darkMode,
376
+ cssPrefix,
377
+ selector
378
+ }) {
379
+ const stable = useStableOptions({
380
+ generation,
381
+ format: formatOpts,
382
+ darkMode,
383
+ cssPrefix
384
+ });
385
+ const css = useMemo4(() => {
386
+ const builder = hextimate(color, stable?.generation);
387
+ configure?.(builder);
388
+ const palette = builder.format({
389
+ ...stable?.format,
390
+ as: "css"
391
+ });
392
+ return buildStyleContent(
393
+ palette,
394
+ stable?.darkMode ?? { type: "media" },
395
+ stable?.cssPrefix ?? "",
396
+ selector
397
+ );
398
+ }, [color, stable, configure, selector]);
399
+ return /* @__PURE__ */ jsx3("style", { "data-hextimator": "", children: css });
400
+ }
401
+
402
+ // src/react/use-hextimator-theme.ts
403
+ import { useContext as useContext2 } from "react";
232
404
  function useHextimatorTheme() {
233
- const ctx = useContext(HextimatorContext);
405
+ const ctx = useContext2(HextimatorContext);
234
406
  if (!ctx) {
235
407
  throw new Error(
236
- "useHextimatorTheme must be used within a <HextimatorProvider>"
408
+ "useHextimatorTheme must be used within a <HextimatorProvider> or <HextimatorScope>"
237
409
  );
238
410
  }
239
411
  return ctx;
240
412
  }
241
413
  export {
242
414
  HextimatorProvider,
415
+ HextimatorScope,
416
+ HextimatorStyle,
243
417
  useHextimator,
244
418
  useHextimatorTheme
245
419
  };
package/fallback.css ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Neutral placeholder theme for the pre-JavaScript paint (and before Hextimator injects CSS).
3
+ * Same token names as default hextimate() + hextimator/tailwind.css. Dark mode matches
4
+ * useHextimator / HextimatorStyle with darkMode: { type: "media-or-class" } (also fine for
5
+ * { type: "media" } when :root has no .light class).
6
+ *
7
+ * Does not include tokens from presets (e.g. shadcn). For those, generate CSS with the CLI
8
+ * and ship it alongside this file or instead of it.
9
+ *
10
+ * Regenerated at package build time (see package.json "build").
11
+ */
12
+
13
+ :root {
14
+ --base: #f5f5f5;
15
+ --base-strong: #fcfcfc;
16
+ --base-weak: #ebebeb;
17
+ --base-foreground: #030303;
18
+ --accent: #aeaeae;
19
+ --accent-strong: #989898;
20
+ --accent-weak: #cecece;
21
+ --accent-foreground: #030303;
22
+ --positive: #aeaeae;
23
+ --positive-strong: #989898;
24
+ --positive-weak: #cecece;
25
+ --positive-foreground: #030303;
26
+ --negative: #aeaeae;
27
+ --negative-strong: #989898;
28
+ --negative-weak: #cecece;
29
+ --negative-foreground: #030303;
30
+ --warning: #aeaeae;
31
+ --warning-strong: #989898;
32
+ --warning-weak: #cecece;
33
+ --warning-foreground: #030303;
34
+ --brand-exact: #737373;
35
+ --brand-exact-foreground: #f5f5f5;
36
+ }
37
+ @media (prefers-color-scheme: dark) {
38
+ :root:not(.light) {
39
+ --base: #161616;
40
+ --base-strong: #030303;
41
+ --base-weak: #2e2e2e;
42
+ --base-foreground: #f5f5f5;
43
+ --accent: #a8a8a8;
44
+ --accent-strong: #b7b7b7;
45
+ --accent-weak: #989898;
46
+ --accent-foreground: #030303;
47
+ --positive: #a8a8a8;
48
+ --positive-strong: #b7b7b7;
49
+ --positive-weak: #989898;
50
+ --positive-foreground: #030303;
51
+ --negative: #a8a8a8;
52
+ --negative-strong: #b7b7b7;
53
+ --negative-weak: #989898;
54
+ --negative-foreground: #030303;
55
+ --warning: #a8a8a8;
56
+ --warning-strong: #b7b7b7;
57
+ --warning-weak: #989898;
58
+ --warning-foreground: #030303;
59
+ --brand-exact: #737373;
60
+ --brand-exact-foreground: #f5f5f5;
61
+ }
62
+ }
63
+ :root.dark {
64
+ --base: #161616;
65
+ --base-strong: #030303;
66
+ --base-weak: #2e2e2e;
67
+ --base-foreground: #f5f5f5;
68
+ --accent: #a8a8a8;
69
+ --accent-strong: #b7b7b7;
70
+ --accent-weak: #989898;
71
+ --accent-foreground: #030303;
72
+ --positive: #a8a8a8;
73
+ --positive-strong: #b7b7b7;
74
+ --positive-weak: #989898;
75
+ --positive-foreground: #030303;
76
+ --negative: #a8a8a8;
77
+ --negative-strong: #b7b7b7;
78
+ --negative-weak: #989898;
79
+ --negative-foreground: #030303;
80
+ --warning: #a8a8a8;
81
+ --warning-strong: #b7b7b7;
82
+ --warning-weak: #989898;
83
+ --warning-foreground: #030303;
84
+ --brand-exact: #737373;
85
+ --brand-exact-foreground: #f5f5f5;
86
+ }
package/llms.txt CHANGED
@@ -82,12 +82,13 @@ Output shape depends on `as`:
82
82
 
83
83
  ### Default palette structure
84
84
 
85
- Every palette includes 5 roles × 4 variants = 20 tokens:
85
+ Every palette includes 5 roles x 4 variants + 2 brand tokens = 22 tokens:
86
86
 
87
87
  - Roles: `base`, `accent`, `positive`, `negative`, `warning`
88
88
  - Variants: `DEFAULT` (no suffix), `strong`, `weak`, `foreground`
89
+ - Brand tokens: `brand-exact` (the exact input color, unmodified), `brand-exact-foreground` (best-contrast foreground for that color)
89
90
 
90
- Token keys: `accent`, `accent-strong`, `accent-weak`, `accent-foreground`, `base`, `base-strong`, ...
91
+ Token keys: `accent`, `accent-strong`, `accent-weak`, `accent-foreground`, `base`, `base-strong`, ..., `brand-exact`, `brand-exact-foreground`
91
92
 
92
93
  ### Presets
93
94
 
@@ -106,6 +107,111 @@ const theme = hextimate("#6366F1")
106
107
 
107
108
  The shadcn preset adds tokens like foreground, card, popover, secondary, muted, border, input, ring, and renames roles (base→background, accent→primary, negative→destructive, positive→success).
108
109
 
110
+ ### Creating presets
111
+
112
+ A preset is a plain `HextimatePreset` object with optional fields for `generation`, `roles`, `variants`, `tokens`, and `format`. It configures the builder the same way chained methods would, but as a reusable data object.
113
+
114
+ ```typescript
115
+ import type { HextimatePreset } from "hextimator";
116
+ ```
117
+
118
+ **Interface:**
119
+
120
+ ```typescript
121
+ interface HextimatePreset {
122
+ generation?: HextimateGenerationOptions; // contrast, lightness, chroma, hue shifts
123
+ roles?: Array<{ name: string; color: ColorInput | DerivedToken }>;
124
+ variants?: Array<{ name: string; placement: VariantPlacement }>;
125
+ tokens?: Array<{ name: string; value: TokenValue }>;
126
+ format?: HextimateFormatOptions; // default format options, overridable in .format()
127
+ }
128
+ ```
129
+
130
+ **Token values** can be:
131
+ - A raw color: `"#FF6600"`, `[255, 102, 102]`, etc.
132
+ - A derived reference: `{ from: "role.variant", emphasis?, lightness?, chroma?, hue? }`
133
+ - Per-theme: `{ light: DerivedToken | ColorInput, dark: DerivedToken | ColorInput }`
134
+
135
+ **`from` syntax**: `"role"` resolves to the DEFAULT variant, `"role.variant"` to a specific one. Valid built-in references: `base`, `base.strong`, `base.weak`, `base.foreground`, `accent`, `accent.strong`, etc. Custom roles/tokens added earlier in the preset can also be referenced.
136
+
137
+ **`emphasis`** is theme-aware contrast adjustment. Positive values push the color *away* from the background (more contrast), negative values pull it *toward* the background (softer). The direction flips automatically between light and dark themes, so `emphasis: 0.12` always means "slightly more visible than the source" regardless of theme. Use this instead of per-theme `lightness` splits when you just want "a bit more/less contrast."
138
+
139
+ **`roleNames` / `variantNames`** in format options remap output keys. This is how you match another framework's naming. For example, `roleNames: { base: "background", accent: "primary" }` turns `base-strong` into `background-strong` and `accent` into `primary` in the output. `variantNames: { DEFAULT: "main", foreground: "contrastText" }` turns `accent` (DEFAULT) into `primary-main` and `accent-foreground` into `primary-contrastText`.
140
+
141
+ **Role colors** can be derived from other roles: `{ from: "accent", hue: 180 }` creates a role whose hue is rotated 180 degrees from the accent.
142
+
143
+ **Example - custom preset for a design system with "surface", "brand", and "danger" tokens:**
144
+
145
+ ```typescript
146
+ const myPreset: HextimatePreset = {
147
+ roles: [
148
+ // Add an "info" role not in the default palette
149
+ { name: "info", color: "#0288d1" },
150
+ // Derive a secondary role by rotating the accent hue
151
+ { name: "secondary", color: { from: "accent", hue: 180 } },
152
+ ],
153
+ tokens: [
154
+ // Surface tokens derived from base
155
+ { name: "surface", value: { from: "base" } },
156
+ { name: "surface-raised", value: { from: "base", emphasis: -0.025 } },
157
+ { name: "surface-overlay", value: { from: "base", emphasis: -0.05 } },
158
+
159
+ // Text with varying prominence
160
+ { name: "text-primary", value: { from: "base.foreground" } },
161
+ { name: "text-secondary", value: { from: "base.foreground", emphasis: -0.2 } },
162
+ { name: "text-disabled", value: { from: "base.foreground", emphasis: -0.4 } },
163
+
164
+ // Border that adjusts direction per theme
165
+ { name: "border", value: { from: "base", emphasis: 0.12 } },
166
+
167
+ // Per-theme token when emphasis alone isn't enough
168
+ {
169
+ name: "divider",
170
+ value: {
171
+ light: { from: "base.weak", lightness: -0.08 },
172
+ dark: { from: "base.weak", lightness: +0.08 },
173
+ },
174
+ },
175
+ ],
176
+ format: {
177
+ as: "css",
178
+ colors: "hex",
179
+ roleNames: {
180
+ base: "surface",
181
+ accent: "brand",
182
+ negative: "danger",
183
+ positive: "success",
184
+ },
185
+ variantNames: {
186
+ DEFAULT: "", // no suffix for the base variant
187
+ strong: "bold",
188
+ weak: "subtle",
189
+ foreground: "on", // e.g. --brand-on
190
+ },
191
+ separator: "-",
192
+ },
193
+ };
194
+ ```
195
+
196
+ Usage:
197
+
198
+ ```typescript
199
+ import { hextimate } from "hextimator";
200
+
201
+ const theme = hextimate("#6366F1").preset(myPreset).format();
202
+ // .format() options override preset defaults:
203
+ const asScss = hextimate("#6366F1").preset(myPreset).format({ as: "scss" });
204
+ ```
205
+
206
+ **How to build a preset for an existing app's theme:**
207
+
208
+ 1. List the app's theme tokens (e.g. from its CSS variables or theme config)
209
+ 2. Map each token to a hextimator source: which built-in role/variant is it closest to?
210
+ 3. Use `roleNames`/`variantNames` to rename the 20 built-in tokens to match the app's naming
211
+ 4. Use `tokens` for any extra tokens not covered by the built-in 5x4 grid, deriving them with `from` + `emphasis`/`lightness`/`chroma`/`hue` offsets
212
+ 5. Use `roles` if the app has color categories beyond base/accent/positive/negative/warning
213
+ 6. Set `format` defaults to match what the app expects (CSS vars, object, etc.)
214
+
109
215
  ### Standalone tokens with per-theme values
110
216
 
111
217
  ```typescript
@@ -148,8 +254,12 @@ Alpha is always ignored (forced to 1) to preserve contrast guarantees.
148
254
 
149
255
  ```bash
150
256
  npx hextimator <color> [options]
257
+ # or the shorter alias:
258
+ npx hextimate <color> [options]
151
259
  ```
152
260
 
261
+ Both commands are identical. Use whichever you prefer.
262
+
153
263
  | Flag | Description | Default |
154
264
  |---|---|---|
155
265
  | `-f, --format` | `css`, `object`, `tailwind`, `tailwind-css`, `scss`, `json` | `css` |
@@ -209,24 +319,60 @@ function App() {
209
319
  }
210
320
  ```
211
321
 
212
- Dark mode strategies: `{ type: "media" }` (default), `{ type: "class" }`, `{ type: "data" }`, or `false`.
322
+ Dark mode strategies:
323
+ - `{ type: "media" }` (default) -- uses `prefers-color-scheme` media query
324
+ - `{ type: "class", className?: string }` -- toggles on a CSS class (default: `"dark"`)
325
+ - `{ type: "data", attribute?: string }` -- toggles on a data attribute (default: `"data-theme"`)
326
+ - `{ type: "media-or-class", className?: string }` -- media query with class override
327
+ - `false` -- disable dark mode entirely
328
+
329
+ Hook options:
330
+
331
+ | Option | Type | Description |
332
+ |---|---|---|
333
+ | `generation` | `HextimateGenerationOptions` | Palette generation options |
334
+ | `format` | `Omit<HextimateFormatOptions, "as">` | Format options (output is always CSS vars) |
335
+ | `configure` | `(builder: HextimatePaletteBuilder) => void` | Customize the builder (add roles, tokens, presets) |
336
+ | `darkMode` | `DarkModeStrategy` | Dark mode strategy (see above) |
337
+ | `cssPrefix` | `string` | Prefix for all CSS variable names |
338
+ | `target` | `RefObject<HTMLElement>` | Inject variables into a specific element instead of `:root` |
213
339
 
214
- Options: `generation`, `format`, `configure` (access builder), `darkMode`, `cssPrefix`, `target` (ref for scoped theming).
340
+ ### Provider
215
341
 
216
- Provider for app-wide theming:
342
+ For app-wide theming with dynamic color changes:
217
343
 
218
344
  ```typescript
219
345
  import { HextimatorProvider, useHextimatorTheme } from "hextimator/react";
220
346
 
221
- // Wrap app
222
- <HextimatorProvider defaultColor="#6A5ACD">
347
+ <HextimatorProvider
348
+ defaultColor="#6A5ACD"
349
+ defaultMode="system" // "light" | "dark" | "system"
350
+ generation={generationOpts}
351
+ format={formatOpts}
352
+ configure={(b) => b.preset(presets.shadcn)}
353
+ darkMode={{ type: "class" }}
354
+ cssPrefix="app"
355
+ target={containerRef}
356
+ >
223
357
  <App />
224
358
  </HextimatorProvider>
225
-
226
- // In children — setColor triggers re-generation
227
- const { color, setColor, palette } = useHextimatorTheme();
228
359
  ```
229
360
 
361
+ `useHextimatorTheme()` returns:
362
+
363
+ | Property | Type | Description |
364
+ |---|---|---|
365
+ | `color` | `string` | Current input color |
366
+ | `setColor` | `(color: string) => void` | Change the input color (triggers re-generation) |
367
+ | `palette` | `HextimateResult` | The generated `{ light, dark }` palette |
368
+ | `mode` | `"light" \| "dark"` | Resolved color mode (accounts for OS preference) |
369
+ | `modePreference` | `"light" \| "dark" \| "system"` | Raw preference before resolution |
370
+ | `setMode` | `(mode: ModePreference) => void` | Change mode preference |
371
+ | `generation` | `HextimateGenerationOptions \| undefined` | Current generation options |
372
+ | `setGeneration` | `(opts) => void` | Update generation options |
373
+ | `configure` | `((builder) => void) \| undefined` | Current builder configure function |
374
+ | `setConfigure` | `(fn) => void` | Update the configure callback |
375
+
230
376
  ## Tailwind CSS v4
231
377
 
232
378
  ```css
@@ -234,7 +380,7 @@ const { color, setColor, palette } = useHextimatorTheme();
234
380
  @import "hextimator/tailwind.css";
235
381
  ```
236
382
 
237
- This registers all 20 built-in tokens as Tailwind utilities (`bg-accent`, `text-base-foreground`, etc.).
383
+ This registers all built-in tokens as Tailwind utilities (`bg-accent`, `text-base-foreground`, etc.).
238
384
 
239
385
  ## Common recipes
240
386