hextimator 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,23 @@
1
+ ## 0.10.0
2
+
3
+ ### Minor Changes
4
+
5
+ - [#127](https://github.com/fgrgic/hextimator/pull/127) [`d0bbf5a`](https://github.com/fgrgic/hextimator/commit/d0bbf5a41ba303c18228057baf9b4ba6dfb016cd) Thanks [@fgrgic](https://github.com/fgrgic)! - - **Breaking.**: Lightness of the theme is derived from the input color's lightness by default. To pin down exact lightness, provide `light.baseLightness`, and/or `dark.baseLIghtness`
6
+
7
+ - Exposes `baseLightnessRange` at the top level and under `light` / `dark` to bound OKLCH **L** for accent and semantic anchors. Defaults: light `[0.4, 0.9]`, dark `[0.2, 0.8]`. CLI: `--base-lightness-range`, `--light-base-lightness-range`, `--dark-base-lightness-range`.
8
+
9
+ - `HextimateStyleOptions` now **extends** `ThemeAdjustments` so shared knobs are declared once; `light` / `dark` use the same shape.
10
+
11
+ - [#126](https://github.com/fgrgic/hextimator/pull/126) [`57ed74a`](https://github.com/fgrgic/hextimator/commit/57ed74af8c1c8d0640d97b4a4318cd02a6fe93f7) Thanks [@fgrgic](https://github.com/fgrgic)! - **Breaking.** Renames built-in semantic role **`warning`** → **`caution`**.
12
+
13
+ Migration checklist: [migration.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md) (section _0.9.x → 0.10.0_).
14
+
1
15
  ## 0.9.0 (Latest)
2
16
 
3
17
  - Widens default semantic hue ranges (`positive` [120,160], `negative` [5,30], `warning` [45,70] OKLCH arcs). Themes using library defaults may get different semantic scales.
4
18
 
19
+ Migration note: [migration.md](https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md) (section _0.8.x → 0.9.0_).
20
+
5
21
  ## 0.8.0
6
22
 
7
23
  - 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.
package/README.md CHANGED
@@ -154,16 +154,16 @@ Preset **`style`** plus **`.style()`** on the builder is covered in [Extending p
154
154
  Use `excludeRoles` and `excludeVariants` in `.format()` (or in a preset's `format` field) to drop tokens you don't need:
155
155
 
156
156
  ```typescript
157
- // Drop the warning role and the strong/weak variants entirely
157
+ // Drop the caution role and the strong/weak variants entirely
158
158
  hextimate("#F11732").format({
159
- excludeRoles: ["warning"],
159
+ excludeRoles: ["caution"],
160
160
  excludeVariants: ["strong", "weak"],
161
161
  });
162
162
 
163
163
  // Useful in custom presets to keep output tight
164
164
  const myPreset: HextimatePreset = {
165
165
  format: {
166
- excludeRoles: ["warning"],
166
+ excludeRoles: ["caution"],
167
167
  excludeVariants: ["weak"],
168
168
  },
169
169
  };
@@ -71,16 +71,17 @@ type ColorTuple = readonly [number, number, number, number?];
71
71
  */
72
72
  type ColorInput = HexString | CSSColorString | ColorTuple | Color | number;
73
73
  /**
74
- * Per-theme adjustments for lightness and chroma.
74
+ * Modifiers to the generation process. Used by {@link HextimateStyleOptions} for
75
+ * global or per-theme (dark/light) settings
75
76
  */
76
77
  interface ThemeAdjustments {
77
78
  /**
78
- * Absolute OKLCH lightness anchor for this theme's accent color (0–1).
79
+ * Absolute OKLCH lightness anchor for accent fills (0–1). Distinct from
80
+ * the relative `lightness` offsets used by `addToken({ from, lightness })`.
79
81
  *
80
- * This is the *baseline* the palette is generated around — distinct from
81
- * the *relative* `lightness` offsets used by `addToken({ from, lightness })`.
82
- *
83
- * Default: 0.7 for light, 0.6 for dark.
82
+ * If omitted, seed from the brand color's OKLCH **L**, clamped via
83
+ * `baseLightnessRange` (per theme object, then top-level, then built-ins:
84
+ * light `[0.4, 0.9]`, dark `[0.2, 0.8]`).
84
85
  */
85
86
  baseLightness?: number;
86
87
  /**
@@ -90,129 +91,70 @@ interface ThemeAdjustments {
90
91
  */
91
92
  lightness?: number;
92
93
  /**
93
- * Maximum chroma for accent/semantic colors in this theme.
94
- * Colors with higher chroma will be clamped to this value.
94
+ * Max chroma for accent and semantic fills in scope. Higher chroma is clamped.
95
95
  */
96
96
  maxChroma?: number;
97
97
  /**
98
- * Minimum WCAG contrast ratio for this theme.
99
- * Overrides the global `minContrastRatio` for this theme only.
100
- *
101
- * - `"AAA"` → 7
102
- * - `"AA"` → 4.5
103
- * - any number → exact ratio
98
+ * OKLCH **L** bounds `[min, max]` (0–1) for `baseLightness` and input-derived anchors.
99
+ * Top-level: use one tuple for both themes unless `light` / `dark` set their own.
100
+ */
101
+ baseLightnessRange?: readonly [number, number];
102
+ /**
103
+ * Minimum contrast between non-foreground variants and foreground.
104
+ * `"AAA"` → 7, `"AA"` → 4.5, or a number.
104
105
  */
105
106
  minContrastRatio?: 'AAA' | 'AA' | number;
106
107
  /**
107
- * Maximum chroma for the surface colors (surface, strong, weak) in this theme.
108
- * Overrides the global `surfaceMaxChroma` for this theme only.
108
+ * Max chroma for surface (`surface`, `strong`, `weak`). Default `0.01`.
109
109
  */
110
110
  surfaceMaxChroma?: number;
111
111
  /**
112
- * Maximum chroma for foreground colors in this theme.
113
- * Overrides the global `foregroundMaxChroma` for this theme only.
112
+ * Max chroma for foreground variants (e.g. `accent-foreground`). Default `0.01`.
114
113
  */
115
114
  foregroundMaxChroma?: number;
116
- }
117
- /**
118
- * Options that control how the palette is generated from the input color.
119
- */
120
- interface HextimateStyleOptions {
121
115
  /**
122
- * Preferred surface color for dark and light mode.
123
- * It will be used as a baseline to generate the rest of surface colors (strong, weak).
124
- * If not provided, it will be derived from the main input color with very low chroma.
125
- *
126
- * Takes precedence over `surfaceHueShift` when both are set.
116
+ * Surface baseline. Top-level: both themes unless `light.surfaceColor` / `dark.surfaceColor`.
117
+ * Omitted: derived from the brand color with low chroma.
127
118
  */
128
119
  surfaceColor?: ColorInput;
129
120
  /**
130
- * Rotate the surface color's hue relative to the accent color (in degrees).
131
- *
132
- * Examples: 180 for complementary, 30 for analogous, -30 for the other direction.
133
- *
134
- * Ignored when an explicit `surfaceColor` is provided.
135
- *
136
- * Default: 0 (same hue as the accent).
121
+ * Rotate surface hue vs accent (degrees). Ignored when `surfaceColor` is set for that scope.
137
122
  */
138
123
  surfaceHueShift?: number;
139
124
  /**
140
- * Semantic colors to use for the theme
141
- * If not provided, they will be generated from the provided main color,
142
- * and the semantic color ranges.
125
+ * Per-variant hue shift on accent and semantic scales. Strong-side shifts toward higher hue,
126
+ * weak-side toward lower; each step stacks. Clamped to `360 / (totalVariants + 1)`.
143
127
  */
128
+ hueShift?: number;
129
+ /** Semantic role overrides; nested maps merge per slot with the top-level map. */
144
130
  semanticColors?: {
145
131
  positive?: ColorInput;
146
132
  negative?: ColorInput;
147
- warning?: ColorInput;
133
+ caution?: ColorInput;
148
134
  };
149
135
  /**
150
- * Invert the hue used for the accent color in dark mode.
151
- * Uses surface hue as accent, and accent hue as surface.
152
- * Only has effect if `surfaceColor` is provided alongside the main accent color
153
- *
154
- * Default: false.
155
- */
156
- invertDarkModeSurfaceAccent?: boolean;
157
- /**
158
- * Degree ranges for the semantic colors.
159
- * Determines where to look for "green", "red", "yellow" in the color space.
160
- * If not provided, the default ranges will be used:
161
- * - positive: [120, 160] greens
162
- * - negative: [5, 30] reds
163
- * - warning: [45, 70] ambers
136
+ * OKLCH hue arcs for semantic discovery. Defaults: positive [120,160], negative [5,30], caution [45,70].
164
137
  */
165
138
  semanticColorRanges?: {
166
139
  positive?: [number, number];
167
140
  negative?: [number, number];
168
- warning?: [number, number];
141
+ caution?: [number, number];
169
142
  };
143
+ }
144
+ /**
145
+ * Options that control how the palette is generated from the input color.
146
+ *
147
+ * Inherits {@link ThemeAdjustments} as global defaults; set `light` / `dark`
148
+ * to override per theme.
149
+ */
150
+ interface HextimateStyleOptions extends ThemeAdjustments {
170
151
  /**
171
- * Maximum chroma for the surface colors (surface, strong, weak).
172
- * Higher values will produce more colorful surface colors, lower values will produce more gray surface colors.
173
- *
174
- * Default: 0.01.
175
- */
176
- surfaceMaxChroma?: number;
177
- /**
178
- * Maximum chroma for all the foreground colors (e.g. surface-accent-foreground)
179
- * Higher values will produce more colorful foreground colors, lower values will produce more gray foreground colors.
180
- *
181
- * Default: 0.01.
182
- */
183
- foregroundMaxChroma?: number;
184
- /**
185
- * Per-theme adjustments for the light theme.
152
+ * In dark mode: surface hue becomes accent and accent hue becomes surface.
153
+ * Requires a `surfaceColor` on the invert path (top-level or `dark`).
186
154
  */
155
+ invertDarkModeSurfaceAccent?: boolean;
187
156
  light?: ThemeAdjustments;
188
- /**
189
- * Per-theme adjustments for the dark theme.
190
- */
191
157
  dark?: ThemeAdjustments;
192
- /**
193
- * Minimum WCAG contrast ratio between non-foreground variants and the
194
- * foreground variant.
195
- *
196
- * - `"AAA"` (default) → 7
197
- * - `"AA"` → 4.5
198
- * - any number → exact ratio (e.g. 3 for large text)
199
- */
200
- minContrastRatio?: 'AAA' | 'AA' | number;
201
- /**
202
- * Shift the hue (in degrees) from variant to variant.
203
- *
204
- * - Positive value: strong-side variants shift toward higher hues,
205
- * weak-side variants shift toward lower hues.
206
- * - Negative value: flips the direction.
207
- * - Each successive variant on a side shifts by an additional step
208
- * (e.g. hueShift: 5 → strong +5°, stronger +10°, weak −5°, weaker −10°).
209
- *
210
- * Clamped to `360 / (totalVariants + 1)` so the palette never wraps
211
- * past a full rotation.
212
- *
213
- * Default: 0 (no hue shift).
214
- */
215
- hueShift?: number;
216
158
  }
217
159
  /**
218
160
  * Options that affect output formatting (serialization)
@@ -227,7 +169,7 @@ interface HextimateFormatOptions {
227
169
  * - accent: "button"
228
170
  * - positive: "success"
229
171
  * - negative: "error"
230
- * - warning: "warning"
172
+ * - caution: "caution"
231
173
  *
232
174
  * If not provided, the default role names will be used.
233
175
  * The default role names are:
@@ -235,7 +177,7 @@ interface HextimateFormatOptions {
235
177
  * - accent: "accent"
236
178
  * - positive: "positive"
237
179
  * - negative: "negative"
238
- * - warning: "warning"
180
+ * - caution: "caution"
239
181
  */
240
182
  roleNames?: Record<string, string>;
241
183
  /**
@@ -315,7 +257,7 @@ interface HextimateFormatOptions {
315
257
  * Role keys to omit from the output entirely.
316
258
  * Uses the internal role name (before any `roleNames` remapping).
317
259
  *
318
- * Example: `['warning']` removes the warning scale from the output.
260
+ * Example: `['caution']` removes the caution scale from the output.
319
261
  */
320
262
  excludeRoles?: string[];
321
263
  /**
@@ -350,11 +292,6 @@ interface HextimateFormatOptions {
350
292
  */
351
293
  invertedVariants?: boolean;
352
294
  }
353
- /**
354
- * Combined options for the convenience API.
355
- * Allows passing both style and format options in one call.
356
- */
357
- type HextimateOptions = HextimateStyleOptions & HextimateFormatOptions;
358
295
  /** How color values are serialized in the output (e.g. "hex", "rgb", "oklch", "hsl", "p3", and their "-raw" variants). */
359
296
  type ColorFormat = 'hex' | 'hsl' | 'hsl-raw' | 'oklch' | 'oklch-raw' | 'p3' | 'p3-raw' | 'rgb' | 'rgb-raw';
360
297
 
@@ -620,4 +557,4 @@ declare class HextimatePaletteBuilder {
620
557
  private resolvedOptions;
621
558
  }
622
559
 
623
- 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 };
560
+ 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 HextimatePreset as g, type HextimateResult as h, type HextimateStyleOptions as i, type TokenValue as j };
@@ -67,7 +67,8 @@ var mui = {
67
67
  roleNames: {
68
68
  accent: "primary",
69
69
  negative: "error",
70
- positive: "success"
70
+ positive: "success",
71
+ caution: "warning"
71
72
  },
72
73
  variantNames: {
73
74
  DEFAULT: "main",
@@ -147,7 +148,7 @@ var shadcn = {
147
148
  variantNames: {
148
149
  foreground: "foreground"
149
150
  },
150
- excludeRoles: ["warning"],
151
+ excludeRoles: ["caution"],
151
152
  excludeVariants: ["strong", "weak"]
152
153
  }
153
154
  };